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AAK,gCAAgB,CAAC,SAAS,EAAE;gBACjD,GAAG,IAAI,IAAI,CAAC;aACf;iBAAM;gBACH,QAAQ,IAAI,CAAC,IAAI,EAAE;oBACf,KAAK,gCAAgB,CAAC,IAAI;wBACtB,GAAG,IAAI,KAAK,CAAC;wBACb,MAAM;oBACV,KAAK,gCAAgB,CAAC,MAAM;wBACxB,GAAG,IAAI,KAAK,CAAC;wBACb,MAAM;oBACV,KAAK,gCAAgB,CAAC,SAAS;wBAC3B,GAAG,IAAI,KAAK,CAAC;wBACb,MAAM;oBACV,KAAK,gCAAgB,CAAC,KAAK;wBACvB,GAAG,IAAI,UAAU,IAAI,CAAC,KAAK,GAAG,CAAC;wBAC/B,MAAM;iBACb;gBACD,IAAI,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC;gBACpB,QAAQ,IAAI,CAAC,IAAI,EAAE;oBACf,KAAK,gCAAgB,CAAC,IAAI;wBACtB,GAAG,IAAI,MAAM,CAAC;wBACd,MAAM;oBACV,KAAK,gCAAgB,CAAC,MAAM;wBACxB,GAAG,IAAI,MAAM,CAAC;wBACd,MAAM;oBACV,KAAK,gCAAgB,CAAC,SAAS;wBAC3B,GAAG,IAAI,MAAM,CAAC;wBACd,MAAM;oBACV,KAAK,gCAAgB,CAAC,KAAK;wBACvB,GAAG,IAAI,UAAU,CAAC;wBAClB,MAAM;iBACb;aACJ;SACJ;IACL,CAAC;IACD,IAAI,CAAC,KAAK,CAAC,CAAC;IACZ,OAAO,GAAG,CAAC;AACf,CAAC;AA/CD,wDA+CC","file":"","sourceRoot":"/","sourcesContent":["import { DeepReadonly } from \"simba-utils\";\nimport { BoldNode, ColorNode, ItalicNode, LineBreakNode, RichTextNode, RichTextNodeType, TextNode, UnderlineNode } from \"../model/RichTextModel\";\nimport { parseTextWithVariables } from \"./PlotUtils\";\n\nconst slateMarks = [\"bold\", \"italic\", \"underline\", \"color\"];\n\ntype StyleNode = BoldNode | ColorNode | UnderlineNode | ItalicNode;\n\n// export function richNodesFromSlateNodes(nodes: any[]): RichTextNode[] {\n// const singleArray: any[] = [];\n// for (let node of nodes) {\n// for (let txt of node.children) {\n// if (txt.text.length)\n// singleArray.push({ ...txt });\n// }\n// singleArray.push(undefined); // line break\n// }\n// singleArray.pop();\n\n// function maxMarkCount(index: number, mark: string, value: any, maxCount: number) {\n// const start = index + 1;\n// const max = start + maxCount - 1;\n// let i = start;\n// for (; i < singleArray.length && i < max; i++) {\n// if (singleArray[i] && (singleArray[i][mark] != value)) {\n// break;\n// }\n// if (singleArray[i]) singleArray[i][mark] = undefined;\n// }\n// return i - start;\n// }\n\n// function getMarks(index: any, maxCount?: number) {\n// let ret: { mark: StyleNode, count: number }[] = [];\n// let node = singleArray[index];\n// if (!maxCount) maxCount = Number.MAX_VALUE;\n// for (let i = 0; i < slateMarks.length; i++) {\n// let mark = slateMarks[i];\n// if (node[mark]) {\n// let _node = { type: i + 1, children: [] } as StyleNode;\n// if (_node.type === RichTextNodeType.Color) _node.color = node[mark];\n// ret.push({\n// mark: _node,\n// count: maxMarkCount(index, mark, node[mark], maxCount)\n// })\n// }\n// }\n// ret.sort((a, b) => b.count - a.count);\n// return ret;\n// }\n\n// const ret: RichTextNode[] = [];\n\n// function processMarks(index: number, marks: { mark: StyleNode, count: number }[], out: RichTextNode[]) {\n// let node = marks[0].mark;\n// out.push(node);\n// for (let i = 1; i < marks.length; i++) {\n// let node1 = marks[i].mark;\n// node.children!.push(node1);\n// node = node1;\n// }\n// let slateNode = singleArray[index];\n// node.children!.push(slateNode ? { type: RichTextNodeType.Text, text: slateNode.text } : { type: RichTextNodeType.LineBreak });\n// if (marks[0].count == 0) return 0;\n// let j = 0;\n// for (let i = marks.length - 1; i >= 0; i--) {\n// for (; j < marks[i].count; j++) {\n// let idx = index + j + 1;\n// slateNode = singleArray[idx];\n// if (!slateNode) {\n// node.children!.push({ type: RichTextNodeType.LineBreak });\n// continue;\n// }\n// let marks1 = getMarks(idx, marks[i].count - j);\n// if (marks1.length) {\n// j += processMarks(idx, marks1, marks[i].mark.children!);\n// } else {\n// node.children!.push({ type: RichTextNodeType.Text, text: slateNode.text });\n// }\n// }\n// }\n// return marks[0].count;\n// }\n\n// for (let i = 0; i < singleArray.length; i++) {\n// let slateNode = singleArray[i];\n// let marks = getMarks(i);\n// if (marks.length) {\n// i += processMarks(i, marks, ret);\n// } else {\n// let node: TextNode | LineBreakNode = slateNode ? { type: RichTextNodeType.Text, text: slateNode.text } : { type: RichTextNodeType.LineBreak };\n// ret.push(node);\n// }\n// }\n\n// return ret;\n// }\n\n// export function richNodesToSlateNodes(nodes: RichTextNode[]): any[] {\n// let ret: any[] = [{ children: [] }];\n// if (!nodes.length) {\n// ret[0].children.push({ text: \"\" });\n// return ret;\n// }\n// function loop(nodes: RichTextNode[], marks: { type: RichTextNodeType, value: any }[], out: any[]) {\n// for (let node of nodes) {\n// if (node.type === RichTextNodeType.Text) {\n// let txtnode: any = { text: node.text };\n// for (let mark of marks) {\n// txtnode[slateMarks[mark.type - 1]] = mark.value;\n// }\n// out.push(txtnode);\n// } else if (node.type === RichTextNodeType.LineBreak) {\n// out = [];\n// ret.push({ children: out });\n// } else {\n// let mark = {\n// type: node.type,\n// value: node.type === RichTextNodeType.Color ? node.color : true\n// };\n// loop(node.children!, [...marks, mark], out);\n// }\n// }\n// }\n// loop(nodes, [], ret[0].children);\n\n// return ret;\n// }\n\nexport function parseRichNodesWithVariables(nodes: DeepReadonly<RichTextNode[]>): RichTextNode[] {\n let ret: RichTextNode[] = [];\n function loop(nodes: DeepReadonly<RichTextNode[]>, parent?: StyleNode) {\n let container = parent ? parent.children : ret;\n for (let node of nodes) {\n if (node.type === RichTextNodeType.Text) {\n let text = parseTextWithVariables(node.text).parsedText;\n container.push({ ...node, text });\n } else if (node.type === RichTextNodeType.LineBreak) {\n container.push({ ...node });\n } else {\n let newNode = { ...node, children: [] };\n container.push(newNode);\n loop(node.children, newNode);\n }\n }\n }\n loop(nodes);\n return ret;\n}\n\nexport function richNodeTextCount(nodes: DeepReadonly<RichTextNode[]>): number {\n let count = 0;\n\n function loop(nodes: DeepReadonly<RichTextNode[]>) {\n for (let node of nodes) {\n if (node.type === RichTextNodeType.Text) {\n count += node.text.length;\n } else if (node.type !== RichTextNodeType.LineBreak) {\n loop(node.children);\n }\n }\n }\n loop(nodes);\n\n return count;\n}\n\nexport function richNodesWithLengthLimit(nodes: DeepReadonly<RichTextNode[]>, length: number): RichTextNode[] {\n let ret: RichTextNode[] = [];\n let textCount = 0;\n function loop(nodes: DeepReadonly<RichTextNode[]>, parent?: StyleNode) {\n let container = parent ? parent.children : ret;\n for (let node of nodes) {\n if (node.type === RichTextNodeType.Text) {\n let len = node.text.length;\n if (len + textCount > length) {\n container.push({ type: RichTextNodeType.Text, text: node.text.slice(0, length - textCount) });\n textCount = length;\n } else {\n textCount += len;\n container.push({ ...node });\n }\n } else if (node.type === RichTextNodeType.LineBreak) {\n container.push({ ...node });\n } else {\n let newNode = { ...node, children: [] };\n container.push(newNode);\n loop(node.children, newNode);\n }\n if (textCount == length) break;\n }\n }\n loop(nodes);\n return ret;\n}\n\nexport function richNodesToCocosString(nodes: DeepReadonly<RichTextNode[]>, parseVariables = true): string {\n let ret = \"\";\n function loop(nodes: DeepReadonly<RichTextNode[]>) {\n for (let node of nodes) {\n if (node.type === RichTextNodeType.Text) {\n if (parseVariables) {\n ret += parseTextWithVariables(node.text).parsedText;\n } else {\n ret += node.text;\n }\n } else if (node.type === RichTextNodeType.LineBreak) {\n ret += \"\\n\";\n } else {\n switch (node.type) {\n case RichTextNodeType.Bold:\n ret += \"<b>\";\n break;\n case RichTextNodeType.Italic:\n ret += \"<i>\";\n break;\n case RichTextNodeType.Underline:\n ret += \"<u>\";\n break;\n case RichTextNodeType.Color:\n ret += `<color=${node.color}>`;\n break;\n }\n loop(node.children);\n switch (node.type) {\n case RichTextNodeType.Bold:\n ret += \"</b>\";\n break;\n case RichTextNodeType.Italic:\n ret += \"</i>\";\n break;\n case RichTextNodeType.Underline:\n ret += \"</u>\";\n break;\n case RichTextNodeType.Color:\n ret += `</color>`;\n break;\n }\n }\n }\n }\n loop(nodes);\n return ret;\n}"]}