@chenyomi/leafer-htmltext-editor 1.0.8 → 1.0.10

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 (56) hide show
  1. package/dist/index.cjs +4 -0
  2. package/dist/index.cjs.map +1 -0
  3. package/dist/index.d.mts +64 -0
  4. package/dist/index.d.ts +51 -5
  5. package/dist/index.mjs +4 -0
  6. package/dist/index.mjs.map +1 -0
  7. package/package.json +16 -8
  8. package/dist/TextEditTool/index.d.ts +0 -17
  9. package/dist/TextEditTool/index.d.ts.map +0 -1
  10. package/dist/TextEditTool/index.js +0 -113
  11. package/dist/TextEditTool/utils.d.ts +0 -8
  12. package/dist/TextEditTool/utils.d.ts.map +0 -1
  13. package/dist/TextEditTool/utils.js +0 -256
  14. package/dist/TextEditor.d.ts +0 -30
  15. package/dist/TextEditor.d.ts.map +0 -1
  16. package/dist/TextEditor.js +0 -169
  17. package/dist/esm/TextEditTool/index.d.ts +0 -17
  18. package/dist/esm/TextEditTool/index.d.ts.map +0 -1
  19. package/dist/esm/TextEditTool/index.js +0 -110
  20. package/dist/esm/TextEditTool/utils.d.ts +0 -8
  21. package/dist/esm/TextEditTool/utils.d.ts.map +0 -1
  22. package/dist/esm/TextEditTool/utils.js +0 -248
  23. package/dist/esm/TextEditor.d.ts +0 -30
  24. package/dist/esm/TextEditor.d.ts.map +0 -1
  25. package/dist/esm/TextEditor.js +0 -166
  26. package/dist/esm/fonts/font.d.ts +0 -17
  27. package/dist/esm/fonts/font.d.ts.map +0 -1
  28. package/dist/esm/fonts/font.js +0 -68
  29. package/dist/esm/fonts/utils.d.ts +0 -9
  30. package/dist/esm/fonts/utils.d.ts.map +0 -1
  31. package/dist/esm/fonts/utils.js +0 -170
  32. package/dist/esm/index.d.ts +0 -18
  33. package/dist/esm/index.d.ts.map +0 -1
  34. package/dist/esm/utils.d.ts +0 -3
  35. package/dist/esm/utils.d.ts.map +0 -1
  36. package/dist/esm/utils.js +0 -266
  37. package/dist/fonts/font.d.ts +0 -17
  38. package/dist/fonts/font.d.ts.map +0 -1
  39. package/dist/fonts/font.js +0 -72
  40. package/dist/fonts/utils.d.ts +0 -9
  41. package/dist/fonts/utils.d.ts.map +0 -1
  42. package/dist/fonts/utils.js +0 -180
  43. package/dist/index.d.ts.map +0 -1
  44. package/dist/index.esm.js +0 -140
  45. package/dist/index.js +0 -178
  46. package/dist/utils.d.ts +0 -3
  47. package/dist/utils.d.ts.map +0 -1
  48. package/dist/utils.js +0 -271
  49. package/src/TextEditTool/index.ts +0 -132
  50. package/src/TextEditTool/utils.ts +0 -288
  51. package/src/TextEditor.ts +0 -213
  52. package/src/fonts/font.ts +0 -86
  53. package/src/fonts/utils.ts +0 -232
  54. package/src/htmltext-editor.css +0 -103
  55. package/src/index.ts +0 -163
  56. package/src/utils.ts +0 -294
@@ -1,110 +0,0 @@
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 { EditTool, EditorScaleEvent, registerEditTool, } from "@leafer-in/editor";
11
- import { PointerEvent } from "leafer-ui";
12
- import { quillManager } from "../";
13
- import { updataHtmlText } from "../utils";
14
- console.log('初始化文本外部编辑插件');
15
- let TextEditTool = class TextEditTool extends EditTool {
16
- get tag() {
17
- return "TextEditTool";
18
- }
19
- constructor(editor) {
20
- super(editor);
21
- this.quill = null;
22
- this.isUpdatingPoints = false;
23
- this.curveAmount = 0;
24
- this.eventIds = [];
25
- this.updateBoxDebounced = this.debounce((text) => {
26
- updataHtmlText(text);
27
- }, 300);
28
- }
29
- debounce(func, wait) {
30
- let timeout = null;
31
- return ((...args) => {
32
- if (timeout !== null) {
33
- window.clearTimeout(timeout);
34
- }
35
- timeout = window.setTimeout(() => func.apply(this, args), wait);
36
- });
37
- }
38
- addEvent() {
39
- const { editor } = quillManager.getCanvas();
40
- const text = editor._target.findOne("HTMLText");
41
- const { scaleX, scaleY } = text.worldTransform;
42
- const zoomScale = Math.max(Math.abs(scaleX), Math.abs(scaleY));
43
- const div = document.querySelector("#textInnerEditor");
44
- const { style } = div;
45
- this.eventIds = [
46
- editor.on_(EditorScaleEvent.SCALE, (e) => {
47
- if (!text.data.canChangeBox) {
48
- text.data.canChangeBox = true;
49
- }
50
- if (text.data.canChangeBox) {
51
- style.width = text.parent.width * zoomScale + "px";
52
- style.height = "auto";
53
- }
54
- this.updateBoxDebounced(text);
55
- }),
56
- editor.on_(PointerEvent.DOUBLE_TAP, () => {
57
- if (!text.parent.locked) {
58
- editor.openInnerEditor(text, true);
59
- }
60
- }),
61
- ];
62
- }
63
- onLoad() {
64
- const { editor } = quillManager.getCanvas();
65
- console.log(editor.target, 123);
66
- const text = editor.target.findOne("HTMLText");
67
- const { scaleX, scaleY } = text.worldTransform;
68
- const zoomScale = Math.max(Math.abs(scaleX), Math.abs(scaleY));
69
- this.addEvent();
70
- this.quill = quillManager.getQuill();
71
- this.quill.clipboard.dangerouslyPasteHTML(text.text);
72
- const div = document.querySelector("#textInnerEditor");
73
- const { style } = div;
74
- if (text.data.canChangeBox) {
75
- style.width = text.parent.width * zoomScale + "px";
76
- style.height = text.parent.height * zoomScale + "px";
77
- }
78
- else {
79
- style.width = "auto";
80
- style.height = "auto";
81
- }
82
- }
83
- updateChangeBoxBound(text) {
84
- text &&
85
- text.set({
86
- width: text.__layout.boxBounds.width,
87
- height: text.__layout.boxBounds.height,
88
- });
89
- }
90
- onUpdate() {
91
- const { editor } = quillManager.getCanvas();
92
- const text = editor._target.findOne("HTMLText");
93
- const el = editor._target;
94
- console.log("文本bound更新");
95
- if (this.curveAmount == text.curveAmount)
96
- return;
97
- if (this.isUpdatingPoints)
98
- return;
99
- }
100
- onUnload() {
101
- const { editor } = quillManager.getCanvas();
102
- editor.off_(this.eventIds);
103
- }
104
- onDestroy() { }
105
- };
106
- TextEditTool = __decorate([
107
- registerEditTool(),
108
- __metadata("design:paramtypes", [Object])
109
- ], TextEditTool);
110
- export { TextEditTool };
@@ -1,8 +0,0 @@
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
@@ -1 +0,0 @@
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;AAgKD,wBAAgB,aAAa,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,CAMnD;AAED,wBAAgB,WAAW,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,CAMjD;AAED,eAAO,MAAM,iBAAiB,UAAgC,CAAA;AAE9D,eAAO,MAAM,eAAe,UAA8B,CAAA;AAuB1D,wBAAgB,QAAQ,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,CAM9C"}
@@ -1,248 +0,0 @@
1
- import { HTMLText } from '@leafer-in/html';
2
- import { Box, Path } from 'leafer-ui';
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': '⁰',
79
- '1': '¹',
80
- '2': '²',
81
- '3': '³',
82
- '4': '⁴',
83
- '5': '⁵',
84
- '6': '⁶',
85
- '7': '⁷',
86
- '8': '⁸',
87
- '9': '⁹',
88
- a: 'ᵃ',
89
- b: 'ᵇ',
90
- c: 'ᶜ',
91
- d: 'ᵈ',
92
- e: 'ᵉ',
93
- f: 'ᶠ',
94
- g: 'ᵍ',
95
- h: 'ʰ',
96
- i: 'ⁱ',
97
- j: 'ʲ',
98
- k: 'ᵏ',
99
- l: 'ˡ',
100
- m: 'ᵐ',
101
- n: 'ⁿ',
102
- o: 'ᵒ',
103
- p: 'ᵖ',
104
- r: 'ʳ',
105
- s: 'ˢ',
106
- t: 'ᵗ',
107
- u: 'ᵘ',
108
- v: 'ᵛ',
109
- w: 'ʷ',
110
- x: 'ˣ',
111
- y: 'ʸ',
112
- z: 'ᶻ',
113
- A: 'ᴬ',
114
- B: 'ᴮ',
115
- D: 'ᴰ',
116
- E: 'ᴱ',
117
- G: 'ᴳ',
118
- H: 'ᴴ',
119
- I: 'ᴵ',
120
- J: 'ᴶ',
121
- K: 'ᴷ',
122
- L: 'ᴸ',
123
- M: 'ᴹ',
124
- N: 'ᴺ',
125
- O: 'ᴼ',
126
- P: 'ᴾ',
127
- R: 'ᴿ',
128
- T: 'ᵀ',
129
- U: 'ᵁ',
130
- W: 'ᵂ',
131
- '+': '⁺',
132
- '-': '⁻',
133
- '=': '⁼',
134
- '(': '⁽',
135
- ')': '⁾'
136
- };
137
- const baseSubscript = {
138
- '0': '₀',
139
- '1': '₁',
140
- '2': '₂',
141
- '3': '₃',
142
- '4': '₄',
143
- '5': '₅',
144
- '6': '₆',
145
- '7': '₇',
146
- '8': '₈',
147
- '9': '₉',
148
- a: 'ₐ',
149
- e: 'ₑ',
150
- h: 'ₕ',
151
- i: 'ᵢ',
152
- j: 'ⱼ',
153
- k: 'ₖ',
154
- l: 'ₗ',
155
- m: 'ₘ',
156
- n: 'ₙ',
157
- o: 'ₒ',
158
- p: 'ₚ',
159
- r: 'ᵣ',
160
- s: 'ₛ',
161
- t: 'ₜ',
162
- u: 'ᵤ',
163
- v: 'ᵥ',
164
- x: 'ₓ',
165
- '+': '₊',
166
- '-': '₋',
167
- '=': '₌',
168
- '(': '₍',
169
- ')': '₎',
170
- β: 'ᵦ',
171
- γ: 'ᵧ',
172
- ρ: 'ᵨ',
173
- φ: 'ᵩ',
174
- χ: 'ᵪ'
175
- };
176
- function invertMap(map) {
177
- const inv = {};
178
- for (const k in map) {
179
- inv[map[k]] = map[k];
180
- }
181
- return inv;
182
- }
183
- const knownSupers = invertMap(baseSuperscript);
184
- const knownSubs = invertMap(baseSubscript);
185
- function buildSuperscriptMap(baseSup, baseSub) {
186
- const out = {};
187
- for (const k in baseSup)
188
- out[k] = baseSup[k];
189
- for (const base in baseSub) {
190
- const subChar = baseSub[base];
191
- if (base in baseSup)
192
- out[subChar] = baseSup[base];
193
- }
194
- for (const supChar in knownSupers)
195
- out[supChar] = supChar;
196
- return out;
197
- }
198
- function buildSubscriptMap(baseSup, baseSub) {
199
- const out = {};
200
- for (const k in baseSub)
201
- out[k] = baseSub[k];
202
- for (const base in baseSup) {
203
- const supChar = baseSup[base];
204
- if (base in baseSub)
205
- out[supChar] = baseSub[base];
206
- }
207
- for (const subChar in knownSubs)
208
- out[subChar] = subChar;
209
- return out;
210
- }
211
- const superscriptMap = buildSuperscriptMap(baseSuperscript, baseSubscript);
212
- const subscriptMap = buildSubscriptMap(baseSuperscript, baseSubscript);
213
- export function toSuperscript(input) {
214
- let out = '';
215
- for (const ch of input) {
216
- out += superscriptMap[ch] ?? ch;
217
- }
218
- return out;
219
- }
220
- export function toSubscript(input) {
221
- let out = '';
222
- for (const ch of input) {
223
- out += subscriptMap[ch] ?? ch;
224
- }
225
- return out;
226
- }
227
- export const superscriptMapVal = Object.values(superscriptMap);
228
- export const subscriptMapVal = Object.values(subscriptMap);
229
- function buildNormalMap(baseSup, baseSub) {
230
- const normal = {};
231
- for (const base in baseSup) {
232
- const supChar = baseSup[base];
233
- normal[supChar] = base;
234
- }
235
- for (const base in baseSub) {
236
- const subChar = baseSub[base];
237
- normal[subChar] = base;
238
- }
239
- return normal;
240
- }
241
- const normalMap = buildNormalMap(baseSuperscript, baseSubscript);
242
- export function toNormal(input) {
243
- let out = '';
244
- for (const ch of input) {
245
- out += normalMap[ch] ?? ch;
246
- }
247
- return out;
248
- }
@@ -1,30 +0,0 @@
1
- import { InnerEditor } from "@leafer-in/editor";
2
- export declare class TextEditor extends InnerEditor {
3
- get tag(): string;
4
- editTarget: any;
5
- editDom: any;
6
- config: {
7
- selectAll: boolean;
8
- };
9
- eventIds: any[];
10
- protected selectText: {
11
- start: number;
12
- end: number;
13
- text: string;
14
- } | undefined;
15
- protected inBody: boolean | undefined;
16
- protected isHTMLText: boolean | undefined;
17
- protected _keyEvent: boolean | undefined;
18
- quill: any;
19
- isComposing: boolean;
20
- private misspelledWords;
21
- private overlay;
22
- private get isOASystem();
23
- onLoad(): void;
24
- private onSelectionChange;
25
- private onInput;
26
- onUpdate(): void;
27
- private isUpdatingPoints;
28
- onUnload(): void;
29
- }
30
- //# sourceMappingURL=TextEditor.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"TextEditor.d.ts","sourceRoot":"","sources":["../../src/TextEditor.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAuB,MAAM,mBAAmB,CAAC;AAIrE,qBACa,UAAW,SAAQ,WAAW;IACzC,IAAW,GAAG,WAEb;IACc,UAAU,EAAE,GAAG,CAAC;IAExB,OAAO,EAAE,GAAG,CAAC;IACb,MAAM;;MAEX;IAEK,QAAQ,EAAE,GAAG,EAAE,CAAM;IAE5B,SAAS,CAAC,UAAU,EAChB;QAAE,KAAK,EAAE,MAAM,CAAC;QAAC,GAAG,EAAE,MAAM,CAAC;QAAC,IAAI,EAAE,MAAM,CAAA;KAAE,GAC5C,SAAS,CAAa;IAC1B,SAAS,CAAC,MAAM,EAAE,OAAO,GAAG,SAAS,CAAa;IAClD,SAAS,CAAC,UAAU,EAAE,OAAO,GAAG,SAAS,CAAa;IACtD,SAAS,CAAC,SAAS,EAAE,OAAO,GAAG,SAAS,CAAa;IAC9C,KAAK,EAAE,GAAG,CAAQ;IAClB,WAAW,EAAE,OAAO,CAAS;IAGpC,OAAO,CAAC,eAAe,CAIf;IACR,OAAO,CAAC,OAAO,CAA+B;IAG9C,OAAO,KAAK,UAAU,GAErB;IACM,MAAM,IAAI,IAAI;IA4FrB,OAAO,CAAC,iBAAiB,CAEvB;IAEF,OAAO,CAAC,OAAO,CAUb;IAEK,QAAQ;IA0Bf,OAAO,CAAC,gBAAgB,CAAS;IAC1B,QAAQ,IAAI,IAAI;CAsCxB"}
@@ -1,166 +0,0 @@
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
- import { InnerEditor, registerInnerEditor } from "@leafer-in/editor";
8
- import { Matrix, PointerEvent } from "@leafer-ui/core";
9
- import { quillManager } from ".";
10
- import { updataHtmlText } from "./utils";
11
- let TextEditor = class TextEditor extends InnerEditor {
12
- constructor() {
13
- super(...arguments);
14
- this.config = {
15
- selectAll: false,
16
- };
17
- this.eventIds = [];
18
- this.selectText = undefined;
19
- this.inBody = undefined;
20
- this.isHTMLText = undefined;
21
- this._keyEvent = undefined;
22
- this.quill = null;
23
- this.isComposing = false;
24
- this.misspelledWords = [];
25
- this.overlay = null;
26
- this.onSelectionChange = async (e) => {
27
- e && localStorage.setItem("selection-change", JSON.stringify(e));
28
- };
29
- this.onInput = async () => {
30
- const { editDom } = this;
31
- console.log("onInput");
32
- updataHtmlText(this.editTarget);
33
- };
34
- this.isUpdatingPoints = false;
35
- }
36
- get tag() {
37
- return "TextEditor";
38
- }
39
- get isOASystem() {
40
- return window.location.host.includes("oa");
41
- }
42
- onLoad() {
43
- const { editor } = this;
44
- const { config } = editor.app;
45
- const text = this.editTarget;
46
- const { scaleX, scaleY } = text.worldTransform;
47
- const zoomScale = Math.max(Math.abs(scaleX), Math.abs(scaleY));
48
- this.isHTMLText = !(text instanceof Text);
49
- this._keyEvent = config.keyEvent;
50
- config.keyEvent = false;
51
- const div = (this.editDom = document.querySelector("#textInnerEditor"));
52
- const { style } = div;
53
- style.visibility = "visible";
54
- if (text.data.canChangeBox) {
55
- style.width = text.parent.width * zoomScale + "px";
56
- style.height = text.parent.height * zoomScale + "px";
57
- }
58
- else {
59
- style.width = "auto";
60
- style.height = "auto";
61
- }
62
- style.outline = "solid #8499EF";
63
- if (text.data.textData.fontSize) {
64
- console.log(text.data.textData.fontSize);
65
- div.style.fontSize = `${text.data.textData.fontSize}px`;
66
- }
67
- if (text.data.textData.fontFamily) {
68
- div.style.fontFamily = `${text.data.textData.fontFamily}`;
69
- }
70
- if (text.data.textData.lineHeight) {
71
- div.style.lineHeight = text.data.textData.lineHeight;
72
- }
73
- if (text.data.textData.letterSpacing) {
74
- div.style.letterSpacing = `${text.data.textData.letterSpacing}px`;
75
- }
76
- if (text.data.textData.textShadow) {
77
- div.style.textShadow = `${text.data.textData.textShadow}`;
78
- }
79
- else {
80
- div.style.textShadow = "none";
81
- }
82
- if (text.data.textData.alignContent) {
83
- const qlEditor = div.querySelector(".ql-editor");
84
- qlEditor.style.alignContent = `${text.data.textData.alignContent}`;
85
- }
86
- this.quill = quillManager.getQuill();
87
- this.quill.clipboard.dangerouslyPasteHTML(text.text);
88
- if (text.parent.children[0].tag.includes("Shape")) {
89
- style.width = text.parent.width * zoomScale + "px";
90
- style.left = "0px";
91
- this.quill.formatLine(0, this.quill.getLength(), "align", "center");
92
- }
93
- else {
94
- this.quill.setSelection(0, this.quill.getLength() - 1);
95
- }
96
- this.quill.on("text-change", this.onInput);
97
- this.quill.on("selection-change", this.onSelectionChange);
98
- localStorage.removeItem("selection-change");
99
- this.eventIds = [
100
- editor.app.on_(PointerEvent.DOWN, (e) => {
101
- let { target } = e.origin, find = false;
102
- while (target) {
103
- if (target === div)
104
- find = true;
105
- target = target.parentElement;
106
- }
107
- if (!find) {
108
- editor.closeInnerEditor();
109
- editor.cancel();
110
- }
111
- }),
112
- ];
113
- }
114
- onUpdate() {
115
- const { editTarget: text } = this;
116
- const { scaleX, scaleY } = text.worldTransform;
117
- const zoomScale = Math.max(Math.abs(scaleX), Math.abs(scaleY));
118
- let { width, height } = text.parent.__local;
119
- ((width *= zoomScale), (height *= zoomScale));
120
- const { x, y } = this.inBody
121
- ? text.app.clientBounds
122
- : text.app.tree.clientBounds;
123
- const { a, b, c, d, e, f } = new Matrix(text.worldTransform)
124
- .scale(1 / zoomScale)
125
- .translateInner(0, 0);
126
- const { style } = this.editDom;
127
- style.transform = `matrix(${a},${b},${c},${d},${e},${f})`;
128
- style.left = x + "px";
129
- style.top = y + "px";
130
- text.set({
131
- visible: false,
132
- });
133
- }
134
- onUnload() {
135
- const { editTarget: text, editor, editDom: dom } = this;
136
- if (text) {
137
- this.onInput();
138
- if (editor.app)
139
- editor.app.config.keyEvent = this._keyEvent;
140
- editor.off_(this.eventIds);
141
- this.editDom.style.visibility = "hidden";
142
- this.eventIds = [];
143
- }
144
- if (text.parent &&
145
- text.parent.name == "Text" &&
146
- text.parent.children.some((e) => e.tag === "Box")) {
147
- text.parent.findOne("Box").opacity = 1;
148
- text.visible = false;
149
- }
150
- else {
151
- text.set({
152
- visible: true,
153
- });
154
- }
155
- if (this.quill.getLength() === 1 && text.parent.name === "Text") {
156
- text.parent.remove();
157
- }
158
- console.log("onUnload");
159
- this.quill.off("text-change", this.onInput);
160
- this.quill.off("selection-change", this.onSelectionChange);
161
- }
162
- };
163
- TextEditor = __decorate([
164
- registerInnerEditor()
165
- ], TextEditor);
166
- export { TextEditor };
@@ -1,17 +0,0 @@
1
- export declare const defaultFonts: {
2
- code: string;
3
- name: string;
4
- url: string;
5
- }[];
6
- export declare class FontManager {
7
- private fontList;
8
- private skipLoadFonts;
9
- private loadFonts;
10
- constructor();
11
- initFonts(): Promise<any[]>;
12
- getFontList(): any[];
13
- getSkipLoadFonts(): any[];
14
- getLoadFonts(): any[];
15
- }
16
- export declare const fontManager: FontManager;
17
- //# sourceMappingURL=font.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"font.d.ts","sourceRoot":"","sources":["../../../src/fonts/font.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,YAAY;;;;GA2BxB,CAAC;AAMF,qBAAa,WAAW;IACtB,OAAO,CAAC,QAAQ,CAAa;IAC7B,OAAO,CAAC,aAAa,CAAkD;IACvE,OAAO,CAAC,SAAS,CAAuB;;IASlC,SAAS;IA0Bf,WAAW;IAIX,gBAAgB;IAIhB,YAAY;CAGb;AAGD,eAAO,MAAM,WAAW,aAAoB,CAAC"}
@@ -1,68 +0,0 @@
1
- export const defaultFonts = [
2
- { code: 'Roboto', name: `"Roboto", sans-serif`, url: '/fonts/Roboto.woff2' },
3
- { code: 'Roboto Mono', name: `"Roboto Mono", monospace`, url: '/fonts/RobotoMono.woff2' },
4
- { code: 'Inter', name: `"Inter", sans-serif`, url: '/fonts/Inter.woff2' },
5
- { code: 'Open Sans', name: `"Open Sans", sans-serif`, url: '/fonts/OpenSans.woff2' },
6
- { code: 'Montserrat', name: `"Montserrat", sans-serif`, url: '/fonts/Montserrat.woff2' },
7
- { code: 'Roboto Condensed', name: `"Roboto Condensed", sans-serif`, url: '/fonts/RobotoCondensed.woff2' },
8
- { code: 'Arimo', name: `"Arimo", sans-serif`, url: '/fonts/Arimo.woff2' },
9
- { code: 'Noto Sans', name: `"Noto Sans", sans-serif`, url: '/fonts/NotoSans.woff2' },
10
- { code: 'Noto Sans Symbols', name: `"Noto Sans Symbols", sans-serif`, url: '/fonts/NotoSansSymbols.woff2' },
11
- { code: 'Merriweather', name: `"Merriweather", serif`, url: '/fonts/Merriweather.woff2' },
12
- { code: 'Playfair Display', name: `"Playfair Display", serif`, url: '/fonts/PlayfairDisplay.woff2' },
13
- { code: 'Noto Serif', name: `"Noto Serif", serif`, url: '/fonts/NotoSerif.woff2' },
14
- { code: 'Lato', name: `"Lato", sans-serif`, url: '/fonts/Lato.woff2' },
15
- { code: 'Spectral', name: `"Spectral", serif`, url: '/fonts/Spectral.woff2' },
16
- { code: 'Dancing Script', name: `"Dancing Script", cursive`, url: '/fonts/DancingScript.woff2' },
17
- { code: 'Noto Sans Simplified Chinese', name: `"Noto Sans SC", sans-serif`, url: '/fonts/NotoSansSimplifiedChinese.woff2' },
18
- { code: 'Noto Serif Simplified Chinese', name: `"Noto Serif SC", serif`, url: '/fonts/NotoSerifSimplifiedChinese.woff2' },
19
- { code: 'Noto Sans Traditional Chinese', name: `"Noto Sans TC", sans-serif`, url: '/fonts/NotoSansTraditionalChinese.woff2' },
20
- { code: 'Noto Sans Hong Kong', name: `"Noto Sans HK", sans-serif`, url: '/fonts/NotoSansHongKong.woff2' },
21
- { code: 'Noto Serif Traditional Chinese', name: `"Noto Serif TC", serif`, url: '/fonts/NotoSerifTraditionalChinese.woff2' },
22
- { code: 'Noto Serif Hong Kong', name: `"Noto Serif HK", serif`, url: '/fonts/NotoSerifHongKong.woff2' },
23
- { code: 'Noto Sans Japanese', name: `"Noto Sans JP", sans-serif`, url: '/fonts/NotoSansJapanese.woff2' },
24
- { code: 'Noto Sans Korean', name: `"Noto Sans KR", sans-serif`, url: '/fonts/NotoSansKorean.woff2' },
25
- { code: 'Poppins', name: `"Poppins", sans-serif`, url: '/fonts/Poppins.woff2' }
26
- ];
27
- const FONT_KEY = 'OPEN_FONTS';
28
- const FONT_VERSION_KEY = 'OPEN_FONTS_VERSION';
29
- export class FontManager {
30
- constructor() {
31
- this.fontList = [];
32
- this.skipLoadFonts = defaultFonts.map((value) => value.name);
33
- this.loadFonts = defaultFonts;
34
- this.initFonts();
35
- }
36
- async initFonts() {
37
- let list = [];
38
- if (typeof localStorage !== 'undefined') {
39
- if (localStorage.getItem(FONT_VERSION_KEY) !== '1') {
40
- localStorage.removeItem(FONT_KEY);
41
- }
42
- let localFonts = [];
43
- try {
44
- const storedFonts = localStorage.getItem(FONT_KEY);
45
- localFonts = storedFonts ? JSON.parse(storedFonts) : [];
46
- }
47
- catch {
48
- localFonts = [];
49
- localStorage.removeItem(FONT_KEY);
50
- }
51
- if (localFonts.length > 0) {
52
- list.push(...localFonts);
53
- }
54
- }
55
- this.fontList = defaultFonts.concat(list);
56
- return list;
57
- }
58
- getFontList() {
59
- return this.fontList;
60
- }
61
- getSkipLoadFonts() {
62
- return this.skipLoadFonts;
63
- }
64
- getLoadFonts() {
65
- return this.loadFonts;
66
- }
67
- }
68
- export const fontManager = new FontManager();
@@ -1,9 +0,0 @@
1
- export declare function fetchFontAsBase64(url: string): Promise<string>;
2
- export declare function addCustomFonts(fontList?: any): void;
3
- export declare function getCustomFontsStyle(): string;
4
- export declare function addCustomFont(font: any): void;
5
- export declare function batchLoadFont(fontNameList?: any): Promise<void>;
6
- export declare function addCustomFontBase64(font: any): Promise<void>;
7
- export declare function getBase64CustomFontsStyle(): string;
8
- export declare function loadFont(font: string): Promise<void>;
9
- //# sourceMappingURL=utils.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../../src/fonts/utils.ts"],"names":[],"mappings":"AAGA,wBAAsB,iBAAiB,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC,CAsCpE;AAgBD,wBAAgB,cAAc,CAAC,QAAQ,GAAE,GAAQ,QAShD;AAKD,wBAAgB,mBAAmB,WAGlC;AAMD,wBAAgB,aAAa,CAAC,IAAI,EAAE,GAAG,QAgCtC;AAMD,wBAAsB,aAAa,CAAC,YAAY,GAAE,GAAQ,iBAUzD;AAyCD,wBAAsB,mBAAmB,CAAC,IAAI,EAAE,GAAG,iBA6ClD;AAKD,wBAAgB,yBAAyB,WAGxC;AAOD,wBAAsB,QAAQ,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAE1D"}