aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--tsconfig.json3
-rw-r--r--webAO/utils/aoml.js128
-rw-r--r--webAO/utils/aoml.ts133
3 files changed, 135 insertions, 129 deletions
diff --git a/tsconfig.json b/tsconfig.json
index 6e4fb21..c2f6882 100644
--- a/tsconfig.json
+++ b/tsconfig.json
@@ -2,7 +2,8 @@
"compilerOptions": {
"outDir": "./dist",
"allowJs": true,
- "target": "es5"
+ "target": "es5",
+ "downlevelIteration": true
},
"include": ["./webAO/*"]
} \ No newline at end of file
diff --git a/webAO/utils/aoml.js b/webAO/utils/aoml.js
deleted file mode 100644
index 9506fbf..0000000
--- a/webAO/utils/aoml.js
+++ /dev/null
@@ -1,128 +0,0 @@
-import request from "../services/request"
-
-
-const aomlParser = (text) => {
- let parsed = {}
- let currentHeader = ''
- for (const line of text.split(/\r?\n/)) {
- if (line === '') {
- currentHeader = ''
- continue;
- }
- const content = line.split(' = ')
- const contentName = content[0]
- const contentValue = content[1]
- if (currentHeader === '') {
- currentHeader = contentName
- parsed[currentHeader] = {
- color: contentValue
- }
- } else {
- const contentKey = contentName.split('_')[1]
- parsed[currentHeader][contentKey] = contentValue
- }
- }
- return parsed
-}
-
-
-
-
-const mlConfig = (AO_HOST) => {
- const defaultUrl = `${AO_HOST}themes/default/chat_config.ini`
- let aomlParsed = {}
-
- request(defaultUrl).then((data) => {
- aomlParsed = aomlParser(data)
- }
- );
-
- const createIdentifiers = () => {
- const identifiers = new Map()
- for (const [ruleName, value] of Object.entries(aomlParsed)) {
- if (identifiers.has(value.start)) {
- throw new Error()
- }
- else if (value.start && value.end) {
- identifiers.set(value.start, value)
- identifiers.set(value.end, value)
- }
-
-
- }
- return identifiers
- }
- const colorIdentifiers = () => {
- let colorIdentifier = {}
- for (const [ruleName, value] of Object.entries(aomlParsed)) {
- colorIdentifier[value.start] = value.color
- }
- return colorIdentifier
- }
- const applyMarkdown = (text, defaultColor) => {
- const identifiers = createIdentifiers(aomlParsed)
- const startIdentifiers = new Set(identifiers.keys())
- const colorIdentifier = colorIdentifiers()
- const identifierClosingStack = []
-
- const colorStack = [[255, 255, 255]]
- // each value in output will be an html element
- let output = []
- for (const letter of text) {
- let currentSelector = document.createElement('span')
- let letterIdentifier = identifiers.get(letter)
- const lastItem = identifierClosingStack.length
- const closingToLookFor = identifierClosingStack[lastItem-1]
- const keepChar = Number(letterIdentifier?.remove) === 0
-
- if (letter === closingToLookFor) {
- identifierClosingStack.pop()
- if (keepChar) {
- currentSelector.innerHTML = letter
- if (colorStack.length === 1){
- currentSelector.className = `text_${defaultColor}`
- } else {
- const r = colorStack[colorStack.length-1][0]
- const g = colorStack[colorStack.length-1][1]
- const b = colorStack[colorStack.length-1][2]
- const currentColor = `color: rgb(${r},${g},${b});`
- currentSelector.setAttribute('style', currentColor)
- }
- output.push(currentSelector)
- }
- colorStack.pop()
- continue;
- }
- else if (startIdentifiers.has(letter)) {
- identifierClosingStack.push(identifiers.get(letter).end)
- const colors = colorIdentifier[letter].split(',')
- const r = colors[0]
- const g = colors[1]
- const b = colors[2]
- colorStack.push([r,g,b])
- if (keepChar) {
- currentSelector.innerHTML = letter
- }
-
- } else {
- currentSelector.innerHTML = letter
- }
- if (colorStack.length === 1) {
- currentSelector.className = `test_${defaultColor}`
- } else {
- const r = colorStack[colorStack.length-1][0]
- const g = colorStack[colorStack.length-1][1]
- const b = colorStack[colorStack.length-1][2]
- const currentColor = `color: rgb(${r},${g},${b});`
- currentSelector.setAttribute('style', currentColor)
- }
- output.push(currentSelector)
- }
- return output
- }
- return {
- applyMarkdown
- }
-}
-
-export default mlConfig \ No newline at end of file
diff --git a/webAO/utils/aoml.ts b/webAO/utils/aoml.ts
new file mode 100644
index 0000000..898d8fb
--- /dev/null
+++ b/webAO/utils/aoml.ts
@@ -0,0 +1,133 @@
+import request from "../services/request"
+
+interface Aoml {
+ name: string;
+ start: string;
+ end: string;
+ remove: number;
+ talking: number;
+ color: string;
+}
+const aomlParser = (text: string) => {
+ let parsed: {[key: string]: Aoml}= {}
+ let currentHeader = ''
+ for (const line of text.split(/\r?\n/)) {
+ if (line === '') {
+ currentHeader = ''
+ continue;
+ }
+ const content = line.split(' = ')
+ const contentName = content[0]
+ const contentValue = content[1]
+ if (currentHeader === '') {
+ currentHeader = contentName
+ parsed[currentHeader] = {
+ color: contentValue
+ } as Aoml
+ } else {
+ const contentKey = contentName.split('_')[1]
+ parsed[currentHeader][contentKey] = contentValue
+ }
+ }
+ return parsed
+}
+
+
+
+
+const mlConfig = (AO_HOST) => {
+ const defaultUrl = `${AO_HOST}themes/default/chat_config.ini`
+ let aomlParsed: {[key: string]: Aoml} = {}
+
+ request(defaultUrl).then((data) => {
+ aomlParsed = aomlParser(data)
+ }
+ );
+
+ const createIdentifiers = () => {
+ const identifiers = new Map<string, Aoml>()
+ for (const [ruleName, value] of Object.entries(aomlParsed)) {
+ if (identifiers.has(value.start)) {
+ throw new Error()
+ }
+ else if (value.start && value.end) {
+ identifiers.set(value.start, value)
+ identifiers.set(value.end, value)
+ }
+
+
+ }
+ return identifiers
+ }
+ const createStartIdentifiers = () => {
+ const startingIdentifiers = new Set<string>()
+ for (const [ruleName, value] of Object.entries(aomlParsed)) {
+ if (value?.start && value?.end) {
+ startingIdentifiers.add(value.start)
+ }
+ }
+ return startingIdentifiers
+ }
+
+ const applyMarkdown = (text: string, defaultColor: string) => {
+ const identifiers = createIdentifiers()
+ const startIdentifiers = createStartIdentifiers()
+ const closingStack = []
+ const colorStack = []
+ // each value in output will be an html element
+ let output: HTMLSpanElement[] = []
+ for (const letter of text) {
+ let currentSelector = document.createElement('span')
+ let currentIdentifier = identifiers.get(letter)
+ const currentClosingLetter = closingStack[closingStack.length-1]
+ const keepChar = Number(currentIdentifier?.remove) === 0
+ console.log(startIdentifiers)
+ if (startIdentifiers.has(letter)) {
+ const color = identifiers.get(letter).color.split(',')
+ const r = color[0]
+ const g = color[1]
+ const b = color[2]
+ colorStack.push([r,g,b])
+ closingStack.push(currentIdentifier.end)
+ const currentColor = `color: rgb(${r},${g},${b});`
+ currentSelector.setAttribute('style', currentColor)
+ if (keepChar) {
+ currentSelector.innerHTML = letter
+ }
+ } else if (currentClosingLetter === letter) {
+ if (colorStack.length === 0) {
+ currentSelector.className = `test_${defaultColor}`
+ } else {
+ const r = colorStack[colorStack.length-1][0]
+ const g = colorStack[colorStack.length-1][1]
+ const b = colorStack[colorStack.length-1][2]
+ const currentColor = `color: rgb(${r},${g},${b});`
+ currentSelector.setAttribute('style', currentColor)
+ }
+ closingStack.pop()
+ colorStack.pop()
+ if (keepChar) {
+ currentSelector.innerHTML = letter
+ }
+ } else {
+ currentSelector.innerHTML = letter
+ if (colorStack.length === 0) {
+ currentSelector.className = `text_${defaultColor}`
+ } else {
+ const r = colorStack[colorStack.length-1][0]
+ const g = colorStack[colorStack.length-1][1]
+ const b = colorStack[colorStack.length-1][2]
+ const currentColor = `color: rgb(${r},${g},${b});`
+ currentSelector.setAttribute('style', currentColor)
+ }
+ }
+ output.push(currentSelector)
+ }
+ return output
+ }
+ return {
+ applyMarkdown
+ }
+}
+
+export default mlConfig \ No newline at end of file