@chenyomi/leafer-htmltext-editor 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (52) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +177 -0
  3. package/dist/TextEditTool/index.d.ts +17 -0
  4. package/dist/TextEditTool/index.d.ts.map +1 -0
  5. package/dist/TextEditTool/index.js +138 -0
  6. package/dist/TextEditTool/utils.d.ts +8 -0
  7. package/dist/TextEditTool/utils.d.ts.map +1 -0
  8. package/dist/TextEditTool/utils.js +173 -0
  9. package/dist/TextEditor.d.ts +27 -0
  10. package/dist/TextEditor.d.ts.map +1 -0
  11. package/dist/TextEditor.js +166 -0
  12. package/dist/esm/TextEditTool/index.d.ts +17 -0
  13. package/dist/esm/TextEditTool/index.d.ts.map +1 -0
  14. package/dist/esm/TextEditTool/index.js +135 -0
  15. package/dist/esm/TextEditTool/utils.d.ts +8 -0
  16. package/dist/esm/TextEditTool/utils.d.ts.map +1 -0
  17. package/dist/esm/TextEditTool/utils.js +165 -0
  18. package/dist/esm/TextEditor.d.ts +27 -0
  19. package/dist/esm/TextEditor.d.ts.map +1 -0
  20. package/dist/esm/TextEditor.js +163 -0
  21. package/dist/esm/fonts/font.d.ts +17 -0
  22. package/dist/esm/fonts/font.d.ts.map +1 -0
  23. package/dist/esm/fonts/font.js +68 -0
  24. package/dist/esm/fonts/utils.d.ts +9 -0
  25. package/dist/esm/fonts/utils.d.ts.map +1 -0
  26. package/dist/esm/fonts/utils.js +170 -0
  27. package/dist/esm/index.d.ts +7 -0
  28. package/dist/esm/index.d.ts.map +1 -0
  29. package/dist/esm/utils.d.ts +3 -0
  30. package/dist/esm/utils.d.ts.map +1 -0
  31. package/dist/esm/utils.js +284 -0
  32. package/dist/fonts/font.d.ts +17 -0
  33. package/dist/fonts/font.d.ts.map +1 -0
  34. package/dist/fonts/font.js +72 -0
  35. package/dist/fonts/utils.d.ts +9 -0
  36. package/dist/fonts/utils.d.ts.map +1 -0
  37. package/dist/fonts/utils.js +180 -0
  38. package/dist/index.d.ts +7 -0
  39. package/dist/index.d.ts.map +1 -0
  40. package/dist/index.esm.js +79 -0
  41. package/dist/index.js +92 -0
  42. package/dist/utils.d.ts +3 -0
  43. package/dist/utils.d.ts.map +1 -0
  44. package/dist/utils.js +289 -0
  45. package/package.json +55 -0
  46. package/src/TextEditTool/index.ts +145 -0
  47. package/src/TextEditTool/utils.ts +216 -0
  48. package/src/TextEditor.ts +200 -0
  49. package/src/fonts/font.ts +86 -0
  50. package/src/fonts/utils.ts +232 -0
  51. package/src/index.ts +92 -0
  52. package/src/utils.ts +331 -0
@@ -0,0 +1,166 @@
1
+ "use strict";
2
+ var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
3
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
4
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
5
+ else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
6
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
7
+ };
8
+ var TextEditor_1;
9
+ Object.defineProperty(exports, "__esModule", { value: true });
10
+ exports.TextEditor = void 0;
11
+ const core_1 = require("@leafer-ui/core");
12
+ const editor_1 = require("@leafer-in/editor");
13
+ const utils_1 = require("./utils");
14
+ let TextEditor = TextEditor_1 = class TextEditor extends editor_1.InnerEditor {
15
+ constructor() {
16
+ super(...arguments);
17
+ this.config = {
18
+ selectAll: false,
19
+ };
20
+ this.eventIds = [];
21
+ this.onSelectionChange = async (e) => {
22
+ e && localStorage.setItem("selection-change", JSON.stringify(e));
23
+ };
24
+ this.onInput = async () => {
25
+ (0, utils_1.updataHtmlText)(this.editTarget);
26
+ };
27
+ this.isUpdatingPoints = false;
28
+ }
29
+ get tag() {
30
+ return "TextEditor";
31
+ }
32
+ onLoad() {
33
+ const { editor } = this;
34
+ const { config } = editor.app;
35
+ const text = this.editTarget;
36
+ const { scaleX, scaleY } = text.worldTransform;
37
+ const zoomScale = Math.max(Math.abs(scaleX), Math.abs(scaleY));
38
+ this.quill = TextEditor_1.quill;
39
+ this.isHTMLText = !(text instanceof Text);
40
+ config.keyEvent = false;
41
+ const element = document.querySelector("#textInnerEditor");
42
+ if (!element || !(element instanceof HTMLDivElement)) {
43
+ console.error("Cannot find #textInnerEditor element or it's not a div");
44
+ return;
45
+ }
46
+ const div = (this.editDom = element);
47
+ const { style } = div;
48
+ style.visibility = "visible";
49
+ if (text.data?.canChangeBox &&
50
+ text.parent?.width !== undefined &&
51
+ text.parent?.height !== undefined) {
52
+ style.width = text.parent.width * zoomScale + "px";
53
+ style.height = text.parent.height * zoomScale + "px";
54
+ }
55
+ else {
56
+ style.width = "auto";
57
+ style.height = "auto";
58
+ }
59
+ style.outline = "solid #8499EF";
60
+ if (text.data?.textData?.fontSize) {
61
+ div.style.fontSize = `${text.data.textData.fontSize * zoomScale}px`;
62
+ }
63
+ if (text.data?.textData?.fontFamily) {
64
+ div.style.fontFamily = `${text.data.textData.fontFamily}`;
65
+ }
66
+ if (text.data?.textData?.lineHeight) {
67
+ div.style.lineHeight = text.data.textData.lineHeight;
68
+ }
69
+ if (text.data?.textData?.letterSpacing) {
70
+ div.style.letterSpacing = `${text.data.textData.letterSpacing}px`;
71
+ }
72
+ if (text.data?.textData?.textShadow) {
73
+ div.style.textShadow = `${text.data.textData.textShadow}`;
74
+ }
75
+ else {
76
+ div.style.textShadow = "none";
77
+ }
78
+ if (text.data?.textData?.alignContent) {
79
+ const qlEditor = div.querySelector(".ql-editor");
80
+ if (qlEditor) {
81
+ qlEditor.style.alignContent = `${text.data.textData.alignContent}`;
82
+ }
83
+ }
84
+ if (this.quill) {
85
+ this.quill.clipboard.dangerouslyPasteHTML(text.text);
86
+ if (text.parent?.children?.[0]?.tag?.includes("Shape")) {
87
+ const parentWidth = text.parent.width;
88
+ if (parentWidth !== undefined) {
89
+ style.width = parentWidth * zoomScale + "px";
90
+ style.left = "0px";
91
+ }
92
+ this.quill.formatLine(0, this.quill.getLength(), "align", "center");
93
+ }
94
+ else {
95
+ this.quill.setSelection(0, this.quill.getLength() - 1);
96
+ }
97
+ this.quill.on("text-change", this.onInput);
98
+ this.quill.on("selection-change", this.onSelectionChange);
99
+ }
100
+ localStorage.removeItem("selection-change");
101
+ this.eventIds = [
102
+ editor.app.on_(core_1.PointerEvent.DOWN, (e) => {
103
+ let { target } = e.origin;
104
+ let find = false;
105
+ while (target) {
106
+ if (target === div)
107
+ find = true;
108
+ target = target.parentElement;
109
+ }
110
+ if (!find) {
111
+ editor.closeInnerEditor();
112
+ editor.cancel();
113
+ }
114
+ }),
115
+ ];
116
+ }
117
+ onUpdate() {
118
+ const { editTarget: text } = this;
119
+ if (!text.parent?.__local)
120
+ return;
121
+ const { scaleX, scaleY } = text.worldTransform;
122
+ const zoomScale = Math.max(Math.abs(scaleX), Math.abs(scaleY));
123
+ const local = text.parent.__local;
124
+ let width = local.width || 0;
125
+ let height = local.height || 0;
126
+ width *= zoomScale;
127
+ height *= zoomScale;
128
+ const { x, y } = this.inBody
129
+ ? text.app.clientBounds
130
+ : (text.app.tree?.clientBounds || { x: 0, y: 0 });
131
+ const { a, b, c, d, e, f } = new core_1.Matrix(text.worldTransform)
132
+ .scale(1 / zoomScale)
133
+ .translateInner(0, 0);
134
+ if (this.editDom) {
135
+ const { style } = this.editDom;
136
+ style.transform = `matrix(${a},${b},${c},${d},${e},${f})`;
137
+ style.left = x + "px";
138
+ style.top = y + "px";
139
+ }
140
+ text.set({
141
+ visible: false,
142
+ });
143
+ }
144
+ onUnload() {
145
+ const { editTarget: text, editor, editDom: dom } = this;
146
+ if (text) {
147
+ this.onInput();
148
+ editor.off_(this.eventIds);
149
+ if (this.editDom) {
150
+ this.editDom.style.visibility = "hidden";
151
+ }
152
+ this.eventIds = [];
153
+ }
154
+ text.set({
155
+ visible: true,
156
+ });
157
+ if (this.quill) {
158
+ this.quill.off("text-change", this.onInput);
159
+ this.quill.off("selection-change", this.onSelectionChange);
160
+ }
161
+ }
162
+ };
163
+ exports.TextEditor = TextEditor;
164
+ exports.TextEditor = TextEditor = TextEditor_1 = __decorate([
165
+ (0, editor_1.registerInnerEditor)()
166
+ ], TextEditor);
@@ -0,0 +1,17 @@
1
+ import { EditTool } from '@leafer-in/editor';
2
+ export declare class TextEditTool extends EditTool {
3
+ get tag(): string;
4
+ quill: any;
5
+ private _dragRAF;
6
+ private updateBoxDebounced;
7
+ constructor(editor: any);
8
+ addEvent(): void;
9
+ onLoad(): void;
10
+ private isUpdatingPoints;
11
+ private curveAmount;
12
+ updateChangeBoxBound(text: any): void;
13
+ onUpdate(): void;
14
+ onUnload(): void;
15
+ onDestroy(): void;
16
+ }
17
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/TextEditTool/index.ts"],"names":[],"mappings":"AAQA,OAAO,EAAE,QAAQ,EAA+D,MAAM,mBAAmB,CAAC;AAa1G,qBACa,YAAa,SAAQ,QAAQ;IACxC,IAAW,GAAG,WAEb;IAEM,KAAK,EAAE,GAAG,CAAQ;IACzB,OAAO,CAAC,QAAQ,CAAuB;IACvC,OAAO,CAAC,kBAAkB,CAAsB;gBAEpC,MAAM,EAAE,GAAG;IAQhB,QAAQ,IAAI,IAAI;IAqChB,MAAM,IAAI,IAAI;IAqCrB,OAAO,CAAC,gBAAgB,CAAS;IACjC,OAAO,CAAC,WAAW,CAAK;IAEjB,oBAAoB,CAAC,IAAI,EAAE,GAAG,GAAG,IAAI;IASrC,QAAQ,IAAI,IAAI;IAchB,QAAQ,IAAI,IAAI;IAIhB,SAAS,IAAI,IAAI;CACzB"}
@@ -0,0 +1,135 @@
1
+ var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
2
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
3
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
4
+ else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
5
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
6
+ };
7
+ var __metadata = (this && this.__metadata) || function (k, v) {
8
+ if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
9
+ };
10
+ import { PointerEvent } from 'leafer-ui';
11
+ import { EditTool, registerEditTool, EditorScaleEvent } from '@leafer-in/editor';
12
+ import { updataHtmlText } from '../utils';
13
+ import { TextEditor } from '../TextEditor';
14
+ function debounce(func, wait) {
15
+ let timeout = null;
16
+ return function (...args) {
17
+ if (timeout)
18
+ clearTimeout(timeout);
19
+ timeout = setTimeout(() => func.apply(this, args), wait);
20
+ };
21
+ }
22
+ let TextEditTool = class TextEditTool extends EditTool {
23
+ get tag() {
24
+ return 'TextEditTool';
25
+ }
26
+ constructor(editor) {
27
+ super(editor);
28
+ this.quill = null;
29
+ this._dragRAF = null;
30
+ this.isUpdatingPoints = false;
31
+ this.curveAmount = 0;
32
+ this.eventIds = [];
33
+ this.updateBoxDebounced = debounce((text) => {
34
+ updataHtmlText(text);
35
+ }, 300);
36
+ }
37
+ addEvent() {
38
+ if (!this.editor?.element)
39
+ return;
40
+ const text = this.editor.element.findOne('HTMLText');
41
+ if (!text)
42
+ return;
43
+ const { scaleX, scaleY } = text.worldTransform;
44
+ const zoomScale = Math.max(Math.abs(scaleX), Math.abs(scaleY));
45
+ const div = document.querySelector('#textInnerEditor');
46
+ if (!div)
47
+ return;
48
+ const { style } = div;
49
+ this.eventIds = [
50
+ this.editor.on_(EditorScaleEvent.SCALE, (e) => {
51
+ if (!text.data)
52
+ text.data = {};
53
+ if (!text.data.canChangeBox) {
54
+ text.data.canChangeBox = true;
55
+ }
56
+ if (text.data.canChangeBox && text.parent) {
57
+ const parentWidth = text.parent.width;
58
+ if (parentWidth !== undefined) {
59
+ style.width = parentWidth * zoomScale + 'px';
60
+ style.height = 'auto';
61
+ }
62
+ }
63
+ this.updateBoxDebounced(text);
64
+ }),
65
+ this.editor.on_(PointerEvent.DOUBLE_TAP, () => {
66
+ if (!text.parent?.locked) {
67
+ this.editor.openInnerEditor(text, true);
68
+ }
69
+ })
70
+ ];
71
+ }
72
+ onLoad() {
73
+ if (!this.editor?.element)
74
+ return;
75
+ const text = this.editor.element.findOne('HTMLText');
76
+ if (!text)
77
+ return;
78
+ const { scaleX, scaleY } = text.worldTransform;
79
+ const zoomScale = Math.max(Math.abs(scaleX), Math.abs(scaleY));
80
+ this.addEvent();
81
+ this.editBox.add(this.view);
82
+ this.quill = TextEditor.quill;
83
+ if (this.quill && text.text) {
84
+ this.quill.clipboard.dangerouslyPasteHTML(text.text);
85
+ }
86
+ const div = document.querySelector('#textInnerEditor');
87
+ if (!div)
88
+ return;
89
+ const { style } = div;
90
+ if (text.data?.canChangeBox && text.parent) {
91
+ const parentWidth = text.parent.width;
92
+ const parentHeight = text.parent.height;
93
+ if (parentWidth !== undefined) {
94
+ style.width = parentWidth * zoomScale + 'px';
95
+ }
96
+ if (parentHeight !== undefined) {
97
+ style.height = parentHeight * zoomScale + 'px';
98
+ }
99
+ }
100
+ else {
101
+ style.width = 'auto';
102
+ style.height = 'auto';
103
+ }
104
+ }
105
+ updateChangeBoxBound(text) {
106
+ if (text && text.__layout?.boxBounds) {
107
+ text.set({
108
+ width: text.__layout.boxBounds.width,
109
+ height: text.__layout.boxBounds.height
110
+ });
111
+ }
112
+ }
113
+ onUpdate() {
114
+ if (!this.editor?.element)
115
+ return;
116
+ const text = this.editor.element.findOne('HTMLText');
117
+ if (!text)
118
+ return;
119
+ const el = this.editor.element;
120
+ console.log('文本bound更新');
121
+ if (this.curveAmount === text.curveAmount)
122
+ return;
123
+ if (this.isUpdatingPoints)
124
+ return;
125
+ }
126
+ onUnload() {
127
+ this.editor.off_(this.eventIds);
128
+ }
129
+ onDestroy() { }
130
+ };
131
+ TextEditTool = __decorate([
132
+ registerEditTool(),
133
+ __metadata("design:paramtypes", [Object])
134
+ ], TextEditTool);
135
+ export { TextEditTool };
@@ -0,0 +1,8 @@
1
+ export declare function getArcRadius(fontSize: number, curveAmount: number): number;
2
+ export declare const handleShowCurve: (element: any, op: boolean) => void;
3
+ export declare function toSuperscript(input: string): string;
4
+ export declare function toSubscript(input: string): string;
5
+ export declare const superscriptMapVal: string[];
6
+ export declare const subscriptMapVal: string[];
7
+ export declare function toNormal(input: string): string;
8
+ //# sourceMappingURL=utils.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../../src/TextEditTool/utils.ts"],"names":[],"mappings":"AAEA,wBAAgB,YAAY,CAAC,QAAQ,EAAE,MAAM,EAAE,WAAW,EAAE,MAAM,GAAG,MAAM,CAM1E;AAED,eAAO,MAAM,eAAe,GAAI,SAAS,GAAG,EAAE,IAAI,OAAO,SAsExD,CAAA;AAmFD,wBAAgB,aAAa,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,CAMnD;AAED,wBAAgB,WAAW,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,CAMjD;AAGD,eAAO,MAAM,iBAAiB,UAAgC,CAAA;AAE9D,eAAO,MAAM,eAAe,UAA8B,CAAA;AA0B1D,wBAAgB,QAAQ,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,CAM9C"}
@@ -0,0 +1,165 @@
1
+ import { Box, Path } from 'leafer-ui';
2
+ import { HTMLText } from '@leafer-in/html';
3
+ export function getArcRadius(fontSize, curveAmount) {
4
+ if (curveAmount === 0)
5
+ return Infinity;
6
+ const theta = (330 * fontSize * 72) / 96;
7
+ const radius = theta / Math.abs(curveAmount);
8
+ return radius;
9
+ }
10
+ export const handleShowCurve = (element, op) => {
11
+ const box = element.findOne('Box');
12
+ box && element.remove(box);
13
+ const text = element.findOne('HTMLText');
14
+ const { boxBounds, x, y } = text;
15
+ const { width } = boxBounds;
16
+ if (!text.curveAmount) {
17
+ text.opacity = 1;
18
+ text.visible = true;
19
+ return;
20
+ }
21
+ text.text = text.text.replace(/\u200B/g, '').replace(/<br\s*\/?>/gi, '\n');
22
+ text.opacity = 0;
23
+ const radius = getArcRadius(text.fontSize, text.curveAmount);
24
+ const C = 2 * Math.PI * radius;
25
+ const dis = text.text.length + 2;
26
+ const tW = width / dis;
27
+ let startW = 0;
28
+ if (C > tW * text.text.length) {
29
+ startW = (C - tW * text.text.length) / 2;
30
+ }
31
+ const startWPr = (startW * 360) / C;
32
+ const group = new Box({
33
+ x: 0,
34
+ y: 0,
35
+ editable: false,
36
+ resizeChildren: true
37
+ });
38
+ let path;
39
+ const offsetK = text.fontSize * text.lineHeight.value || 0;
40
+ const offsetY = text.curveAmount > 0 ? radius + offsetK : -radius;
41
+ if (text.curveAmount > 0) {
42
+ path = `G ${x + width / 2} ${offsetY} ${radius} ${radius} 90 ${startWPr} ${360 - startWPr} 0`;
43
+ }
44
+ else {
45
+ const a = 180 - startWPr;
46
+ path = `G ${x + width / 2} ${offsetY} ${radius} ${radius} 90 ${a} ${-a} 1`;
47
+ }
48
+ const pathLine = new Path({
49
+ x: 0,
50
+ y: 0,
51
+ motionPath: true,
52
+ editable: false,
53
+ path: path
54
+ });
55
+ group.add(pathLine);
56
+ group.set({
57
+ opacity: op ? 0.2 : 1
58
+ });
59
+ Array.from(text.text).forEach((ch, i) => {
60
+ const str = new HTMLText({
61
+ text: ch,
62
+ around: text.curveAmount > 0 ? 'bottom' : 'top',
63
+ fontSize: text.fontSize,
64
+ fontFamily: text.fontFamily,
65
+ fontWeight: text.fontWeight,
66
+ motion: i * tW + tW / 2,
67
+ textDecoration: text.textDecoration,
68
+ textCase: text.textCase,
69
+ textAlign: text.textAlign,
70
+ motionRotation: text.curveAmount > 0 ? 3 : -2,
71
+ fill: text.fill
72
+ });
73
+ group.add(str);
74
+ });
75
+ element.add(group);
76
+ };
77
+ const baseSuperscript = {
78
+ '0': '⁰', '1': '¹', '2': '²', '3': '³', '4': '⁴', '5': '⁵', '6': '⁶', '7': '⁷', '8': '⁸', '9': '⁹',
79
+ a: 'ᵃ', b: 'ᵇ', c: 'ᶜ', d: 'ᵈ', e: 'ᵉ', f: 'ᶠ', g: 'ᵍ', h: 'ʰ', i: 'ⁱ', j: 'ʲ', k: 'ᵏ',
80
+ l: 'ˡ', m: 'ᵐ', n: 'ⁿ', o: 'ᵒ', p: 'ᵖ', r: 'ʳ', s: 'ˢ', t: 'ᵗ', u: 'ᵘ', v: 'ᵛ', w: 'ʷ',
81
+ x: 'ˣ', y: 'ʸ', z: 'ᶻ',
82
+ A: 'ᴬ', B: 'ᴮ', D: 'ᴰ', E: 'ᴱ', G: 'ᴳ', H: 'ᴴ', I: 'ᴵ', J: 'ᴶ', K: 'ᴷ', L: 'ᴸ', M: 'ᴹ',
83
+ N: 'ᴺ', O: 'ᴼ', P: 'ᴾ', R: 'ᴿ', T: 'ᵀ', U: 'ᵁ', W: 'ᵂ',
84
+ '+': '⁺', '-': '⁻', '=': '⁼', '(': '⁽', ')': '⁾'
85
+ };
86
+ const baseSubscript = {
87
+ '0': '₀', '1': '₁', '2': '₂', '3': '₃', '4': '₄', '5': '₅', '6': '₆', '7': '₇', '8': '₈', '9': '₉',
88
+ a: 'ₐ', e: 'ₑ', h: 'ₕ', i: 'ᵢ', j: 'ⱼ', k: 'ₖ', l: 'ₗ', m: 'ₘ', n: 'ₙ', o: 'ₒ', p: 'ₚ',
89
+ r: 'ᵣ', s: 'ₛ', t: 'ₜ', u: 'ᵤ', v: 'ᵥ', x: 'ₓ',
90
+ '+': '₊', '-': '₋', '=': '₌', '(': '₍', ')': '₎',
91
+ 'β': 'ᵦ', 'γ': 'ᵧ', 'ρ': 'ᵨ', 'φ': 'ᵩ', 'χ': 'ᵪ'
92
+ };
93
+ function invertMap(map) {
94
+ const inv = {};
95
+ for (const k in map) {
96
+ inv[map[k]] = map[k];
97
+ }
98
+ return inv;
99
+ }
100
+ const knownSupers = invertMap(baseSuperscript);
101
+ const knownSubs = invertMap(baseSubscript);
102
+ function buildSuperscriptMap(baseSup, baseSub) {
103
+ const out = {};
104
+ for (const k in baseSup)
105
+ out[k] = baseSup[k];
106
+ for (const base in baseSub) {
107
+ const subChar = baseSub[base];
108
+ if (base in baseSup)
109
+ out[subChar] = baseSup[base];
110
+ }
111
+ for (const supChar in knownSupers)
112
+ out[supChar] = supChar;
113
+ return out;
114
+ }
115
+ function buildSubscriptMap(baseSup, baseSub) {
116
+ const out = {};
117
+ for (const k in baseSub)
118
+ out[k] = baseSub[k];
119
+ for (const base in baseSup) {
120
+ const supChar = baseSup[base];
121
+ if (base in baseSub)
122
+ out[supChar] = baseSub[base];
123
+ }
124
+ for (const subChar in knownSubs)
125
+ out[subChar] = subChar;
126
+ return out;
127
+ }
128
+ const superscriptMap = buildSuperscriptMap(baseSuperscript, baseSubscript);
129
+ const subscriptMap = buildSubscriptMap(baseSuperscript, baseSubscript);
130
+ export function toSuperscript(input) {
131
+ let out = '';
132
+ for (const ch of input) {
133
+ out += superscriptMap[ch] ?? ch;
134
+ }
135
+ return out;
136
+ }
137
+ export function toSubscript(input) {
138
+ let out = '';
139
+ for (const ch of input) {
140
+ out += subscriptMap[ch] ?? ch;
141
+ }
142
+ return out;
143
+ }
144
+ export const superscriptMapVal = Object.values(superscriptMap);
145
+ export const subscriptMapVal = Object.values(subscriptMap);
146
+ function buildNormalMap(baseSup, baseSub) {
147
+ const normal = {};
148
+ for (const base in baseSup) {
149
+ const supChar = baseSup[base];
150
+ normal[supChar] = base;
151
+ }
152
+ for (const base in baseSub) {
153
+ const subChar = baseSub[base];
154
+ normal[subChar] = base;
155
+ }
156
+ return normal;
157
+ }
158
+ const normalMap = buildNormalMap(baseSuperscript, baseSubscript);
159
+ export function toNormal(input) {
160
+ let out = '';
161
+ for (const ch of input) {
162
+ out += normalMap[ch] ?? ch;
163
+ }
164
+ return out;
165
+ }
@@ -0,0 +1,27 @@
1
+ import { IText, IEventListenerId } from "@leafer-in/interface";
2
+ import { InnerEditor } from "@leafer-in/editor";
3
+ export declare class TextEditor extends InnerEditor {
4
+ static quill: any;
5
+ get tag(): string;
6
+ quill: any;
7
+ editTarget: IText;
8
+ editDom: HTMLDivElement | undefined;
9
+ config: {
10
+ selectAll: boolean;
11
+ };
12
+ eventIds: IEventListenerId[];
13
+ protected selectText: {
14
+ start: number;
15
+ end: number;
16
+ text: string;
17
+ } | undefined;
18
+ protected inBody: boolean | undefined;
19
+ protected isHTMLText: boolean | undefined;
20
+ onLoad(): void;
21
+ private onSelectionChange;
22
+ private onInput;
23
+ onUpdate(): void;
24
+ private isUpdatingPoints;
25
+ onUnload(): void;
26
+ }
27
+ //# sourceMappingURL=TextEditor.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"TextEditor.d.ts","sourceRoot":"","sources":["../../src/TextEditor.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,gBAAgB,EAAE,MAAM,sBAAsB,CAAC;AAE/D,OAAO,EAAE,WAAW,EAAuB,MAAM,mBAAmB,CAAC;AAMrE,qBACa,UAAW,SAAQ,WAAW;IACzC,OAAc,KAAK,EAAE,GAAG,CAAC;IAEzB,IAAW,GAAG,WAEb;IAEM,KAAK,EAAE,GAAG,CAAC;IACH,UAAU,EAAE,KAAK,CAAC;IAE1B,OAAO,EAAE,cAAc,GAAG,SAAS,CAAC;IACpC,MAAM;;MAEX;IAEK,QAAQ,EAAE,gBAAgB,EAAE,CAAM;IAEzC,SAAS,CAAC,UAAU,EAChB;QAAE,KAAK,EAAE,MAAM,CAAC;QAAC,GAAG,EAAE,MAAM,CAAC;QAAC,IAAI,EAAE,MAAM,CAAA;KAAE,GAC5C,SAAS,CAAC;IACd,SAAS,CAAC,MAAM,EAAE,OAAO,GAAG,SAAS,CAAC;IACtC,SAAS,CAAC,UAAU,EAAE,OAAO,GAAG,SAAS,CAAC;IAEnC,MAAM,IAAI,IAAI;IAoGrB,OAAO,CAAC,iBAAiB,CAEvB;IAEF,OAAO,CAAC,OAAO,CAGb;IAEK,QAAQ;IAkCf,OAAO,CAAC,gBAAgB,CAAS;IAE1B,QAAQ,IAAI,IAAI;CAsBxB"}