@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.
- package/LICENSE +21 -0
- package/README.md +177 -0
- package/dist/TextEditTool/index.d.ts +17 -0
- package/dist/TextEditTool/index.d.ts.map +1 -0
- package/dist/TextEditTool/index.js +138 -0
- package/dist/TextEditTool/utils.d.ts +8 -0
- package/dist/TextEditTool/utils.d.ts.map +1 -0
- package/dist/TextEditTool/utils.js +173 -0
- package/dist/TextEditor.d.ts +27 -0
- package/dist/TextEditor.d.ts.map +1 -0
- package/dist/TextEditor.js +166 -0
- package/dist/esm/TextEditTool/index.d.ts +17 -0
- package/dist/esm/TextEditTool/index.d.ts.map +1 -0
- package/dist/esm/TextEditTool/index.js +135 -0
- package/dist/esm/TextEditTool/utils.d.ts +8 -0
- package/dist/esm/TextEditTool/utils.d.ts.map +1 -0
- package/dist/esm/TextEditTool/utils.js +165 -0
- package/dist/esm/TextEditor.d.ts +27 -0
- package/dist/esm/TextEditor.d.ts.map +1 -0
- package/dist/esm/TextEditor.js +163 -0
- package/dist/esm/fonts/font.d.ts +17 -0
- package/dist/esm/fonts/font.d.ts.map +1 -0
- package/dist/esm/fonts/font.js +68 -0
- package/dist/esm/fonts/utils.d.ts +9 -0
- package/dist/esm/fonts/utils.d.ts.map +1 -0
- package/dist/esm/fonts/utils.js +170 -0
- package/dist/esm/index.d.ts +7 -0
- package/dist/esm/index.d.ts.map +1 -0
- package/dist/esm/utils.d.ts +3 -0
- package/dist/esm/utils.d.ts.map +1 -0
- package/dist/esm/utils.js +284 -0
- package/dist/fonts/font.d.ts +17 -0
- package/dist/fonts/font.d.ts.map +1 -0
- package/dist/fonts/font.js +72 -0
- package/dist/fonts/utils.d.ts +9 -0
- package/dist/fonts/utils.d.ts.map +1 -0
- package/dist/fonts/utils.js +180 -0
- package/dist/index.d.ts +7 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.esm.js +79 -0
- package/dist/index.js +92 -0
- package/dist/utils.d.ts +3 -0
- package/dist/utils.d.ts.map +1 -0
- package/dist/utils.js +289 -0
- package/package.json +55 -0
- package/src/TextEditTool/index.ts +145 -0
- package/src/TextEditTool/utils.ts +216 -0
- package/src/TextEditor.ts +200 -0
- package/src/fonts/font.ts +86 -0
- package/src/fonts/utils.ts +232 -0
- package/src/index.ts +92 -0
- package/src/utils.ts +331 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2024 chenyomi
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,177 @@
|
|
|
1
|
+
# Leafer HTMLText Editor
|
|
2
|
+
|
|
3
|
+
一个用于 Leafer UI 的富文本编辑器插件,集成了 Quill 编辑器,支持 HTML 文本编辑和样式控制。
|
|
4
|
+
|
|
5
|
+
## 特性
|
|
6
|
+
|
|
7
|
+
- ✅ 基于 Quill 的富文本编辑
|
|
8
|
+
- ✅ 支持多种字体和样式
|
|
9
|
+
- ✅ 文本对齐、列表、上下标等功能
|
|
10
|
+
- ✅ 完全独立,无外部项目依赖
|
|
11
|
+
- ✅ TypeScript 支持
|
|
12
|
+
- ✅ 轻量级,无 Vue/React 等框架依赖
|
|
13
|
+
|
|
14
|
+
## 安装
|
|
15
|
+
|
|
16
|
+
```bash
|
|
17
|
+
npm install leafer-htmltext-editor
|
|
18
|
+
```
|
|
19
|
+
|
|
20
|
+
或使用 yarn:
|
|
21
|
+
|
|
22
|
+
```bash
|
|
23
|
+
yarn add leafer-htmltext-editor
|
|
24
|
+
```
|
|
25
|
+
|
|
26
|
+
## 使用方法
|
|
27
|
+
|
|
28
|
+
### 基本使用
|
|
29
|
+
|
|
30
|
+
```typescript
|
|
31
|
+
import { initTextEditorQuill, TextEditor } from 'leafer-htmltext-editor';
|
|
32
|
+
import { App } from '@leafer-ui/core';
|
|
33
|
+
import { Editor } from '@leafer-in/editor';
|
|
34
|
+
|
|
35
|
+
// 1. 初始化 Quill 编辑器
|
|
36
|
+
const quill = initTextEditorQuill();
|
|
37
|
+
|
|
38
|
+
// 2. 创建 Leafer 应用
|
|
39
|
+
const app = new App({
|
|
40
|
+
view: window,
|
|
41
|
+
tree: {},
|
|
42
|
+
editor: {}
|
|
43
|
+
});
|
|
44
|
+
|
|
45
|
+
// 3. 创建编辑器
|
|
46
|
+
const editor = new Editor({ app });
|
|
47
|
+
|
|
48
|
+
// 现在可以使用文本编辑功能了
|
|
49
|
+
```
|
|
50
|
+
|
|
51
|
+
### 字体管理
|
|
52
|
+
|
|
53
|
+
```typescript
|
|
54
|
+
import { fontManager, defaultFonts } from 'leafer-htmltext-editor';
|
|
55
|
+
|
|
56
|
+
// 获取所有可用字体
|
|
57
|
+
const fonts = fontManager.getFontList();
|
|
58
|
+
console.log('Available fonts:', fonts);
|
|
59
|
+
|
|
60
|
+
// 获取默认字体列表
|
|
61
|
+
console.log('Default fonts:', defaultFonts);
|
|
62
|
+
```
|
|
63
|
+
|
|
64
|
+
### 文本样式更新
|
|
65
|
+
|
|
66
|
+
```typescript
|
|
67
|
+
import { updataHtmlText, setHTMLText } from 'leafer-htmltext-editor';
|
|
68
|
+
|
|
69
|
+
// 更新文本样式
|
|
70
|
+
updataHtmlText(textElement);
|
|
71
|
+
|
|
72
|
+
// 设置特定属性
|
|
73
|
+
setHTMLText('fontSize', 20, null, editor, true);
|
|
74
|
+
setHTMLText('align', 'center', null, editor, true);
|
|
75
|
+
```
|
|
76
|
+
|
|
77
|
+
## API 文档
|
|
78
|
+
|
|
79
|
+
### initTextEditorQuill(container?: HTMLElement)
|
|
80
|
+
|
|
81
|
+
初始化 Quill 文本编辑器。
|
|
82
|
+
|
|
83
|
+
**参数:**
|
|
84
|
+
- `container` (可选): 容器元素
|
|
85
|
+
|
|
86
|
+
**返回:**
|
|
87
|
+
- Quill 实例
|
|
88
|
+
|
|
89
|
+
### TextEditor
|
|
90
|
+
|
|
91
|
+
文本编辑器类,继承自 `InnerEditor`。
|
|
92
|
+
|
|
93
|
+
**静态属性:**
|
|
94
|
+
- `TextEditor.quill`: 全局 Quill 实例
|
|
95
|
+
|
|
96
|
+
### updataHtmlText(e?, base64font?, fontObj?)
|
|
97
|
+
|
|
98
|
+
更新文本元素的 HTML 样式。
|
|
99
|
+
|
|
100
|
+
**参数:**
|
|
101
|
+
- `e`: 文本元素
|
|
102
|
+
- `base64font` (可选): Base64 编码的字体
|
|
103
|
+
- `fontObj` (可选): 字体对象
|
|
104
|
+
|
|
105
|
+
### setHTMLText(key, value?, base64font?, editor?, isInnerEditor?)
|
|
106
|
+
|
|
107
|
+
设置 HTML 文本的属性。
|
|
108
|
+
|
|
109
|
+
**参数:**
|
|
110
|
+
- `key`: 属性键(如 'fontSize', 'font', 'color' 等)
|
|
111
|
+
- `value` (可选): 属性值
|
|
112
|
+
- `base64font` (可选): Base64 编码的字体
|
|
113
|
+
- `editor` (可选): 编辑器实例
|
|
114
|
+
- `isInnerEditor` (可选): 是否为内部编辑器
|
|
115
|
+
|
|
116
|
+
### FontManager
|
|
117
|
+
|
|
118
|
+
字体管理类。
|
|
119
|
+
|
|
120
|
+
**方法:**
|
|
121
|
+
- `getFontList()`: 获取字体列表
|
|
122
|
+
- `getSkipLoadFonts()`: 获取跳过加载的字体
|
|
123
|
+
- `getLoadFonts()`: 获取需要加载的字体
|
|
124
|
+
|
|
125
|
+
## 依赖
|
|
126
|
+
|
|
127
|
+
本包依赖以下 peer dependencies:
|
|
128
|
+
|
|
129
|
+
- `@leafer-ui/core` >= 1.0.0
|
|
130
|
+
- `@leafer-in/editor` >= 1.0.0
|
|
131
|
+
- `@leafer-in/interface` >= 1.0.0
|
|
132
|
+
- `@leafer-in/html` >= 1.0.0
|
|
133
|
+
- `leafer-ui` >= 1.0.0
|
|
134
|
+
- `quill` >= 2.0.0
|
|
135
|
+
|
|
136
|
+
请确保在你的项目中安装了这些依赖。
|
|
137
|
+
|
|
138
|
+
## 支持的字体
|
|
139
|
+
|
|
140
|
+
默认支持以下字体:
|
|
141
|
+
|
|
142
|
+
- Roboto, Roboto Mono
|
|
143
|
+
- Inter, Open Sans, Montserrat
|
|
144
|
+
- Lato, Poppins, Arimo
|
|
145
|
+
- Merriweather, Playfair Display
|
|
146
|
+
- Noto Sans (多语言支持)
|
|
147
|
+
- 中文字体(简体、繁体)
|
|
148
|
+
- 日文、韩文字体
|
|
149
|
+
|
|
150
|
+
## 开发
|
|
151
|
+
|
|
152
|
+
```bash
|
|
153
|
+
# 克隆仓库
|
|
154
|
+
git clone https://github.com/yourusername/leafer-htmltext-editor.git
|
|
155
|
+
|
|
156
|
+
# 安装依赖
|
|
157
|
+
npm install
|
|
158
|
+
|
|
159
|
+
# 构建
|
|
160
|
+
npm run build
|
|
161
|
+
```
|
|
162
|
+
|
|
163
|
+
## 许可证
|
|
164
|
+
|
|
165
|
+
MIT
|
|
166
|
+
|
|
167
|
+
## 作者
|
|
168
|
+
|
|
169
|
+
chenyomi
|
|
170
|
+
|
|
171
|
+
## 贡献
|
|
172
|
+
|
|
173
|
+
欢迎提交 Issue 和 Pull Request!
|
|
174
|
+
|
|
175
|
+
## 变更日志
|
|
176
|
+
|
|
177
|
+
查看 [CHANGELOG.md](CHANGELOG.md) 了解版本更新信息。
|
|
@@ -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,138 @@
|
|
|
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 __metadata = (this && this.__metadata) || function (k, v) {
|
|
9
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
10
|
+
};
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.TextEditTool = void 0;
|
|
13
|
+
const leafer_ui_1 = require("leafer-ui");
|
|
14
|
+
const editor_1 = require("@leafer-in/editor");
|
|
15
|
+
const utils_1 = require("../utils");
|
|
16
|
+
const TextEditor_1 = require("../TextEditor");
|
|
17
|
+
function debounce(func, wait) {
|
|
18
|
+
let timeout = null;
|
|
19
|
+
return function (...args) {
|
|
20
|
+
if (timeout)
|
|
21
|
+
clearTimeout(timeout);
|
|
22
|
+
timeout = setTimeout(() => func.apply(this, args), wait);
|
|
23
|
+
};
|
|
24
|
+
}
|
|
25
|
+
let TextEditTool = class TextEditTool extends editor_1.EditTool {
|
|
26
|
+
get tag() {
|
|
27
|
+
return 'TextEditTool';
|
|
28
|
+
}
|
|
29
|
+
constructor(editor) {
|
|
30
|
+
super(editor);
|
|
31
|
+
this.quill = null;
|
|
32
|
+
this._dragRAF = null;
|
|
33
|
+
this.isUpdatingPoints = false;
|
|
34
|
+
this.curveAmount = 0;
|
|
35
|
+
this.eventIds = [];
|
|
36
|
+
this.updateBoxDebounced = debounce((text) => {
|
|
37
|
+
(0, utils_1.updataHtmlText)(text);
|
|
38
|
+
}, 300);
|
|
39
|
+
}
|
|
40
|
+
addEvent() {
|
|
41
|
+
if (!this.editor?.element)
|
|
42
|
+
return;
|
|
43
|
+
const text = this.editor.element.findOne('HTMLText');
|
|
44
|
+
if (!text)
|
|
45
|
+
return;
|
|
46
|
+
const { scaleX, scaleY } = text.worldTransform;
|
|
47
|
+
const zoomScale = Math.max(Math.abs(scaleX), Math.abs(scaleY));
|
|
48
|
+
const div = document.querySelector('#textInnerEditor');
|
|
49
|
+
if (!div)
|
|
50
|
+
return;
|
|
51
|
+
const { style } = div;
|
|
52
|
+
this.eventIds = [
|
|
53
|
+
this.editor.on_(editor_1.EditorScaleEvent.SCALE, (e) => {
|
|
54
|
+
if (!text.data)
|
|
55
|
+
text.data = {};
|
|
56
|
+
if (!text.data.canChangeBox) {
|
|
57
|
+
text.data.canChangeBox = true;
|
|
58
|
+
}
|
|
59
|
+
if (text.data.canChangeBox && text.parent) {
|
|
60
|
+
const parentWidth = text.parent.width;
|
|
61
|
+
if (parentWidth !== undefined) {
|
|
62
|
+
style.width = parentWidth * zoomScale + 'px';
|
|
63
|
+
style.height = 'auto';
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
this.updateBoxDebounced(text);
|
|
67
|
+
}),
|
|
68
|
+
this.editor.on_(leafer_ui_1.PointerEvent.DOUBLE_TAP, () => {
|
|
69
|
+
if (!text.parent?.locked) {
|
|
70
|
+
this.editor.openInnerEditor(text, true);
|
|
71
|
+
}
|
|
72
|
+
})
|
|
73
|
+
];
|
|
74
|
+
}
|
|
75
|
+
onLoad() {
|
|
76
|
+
if (!this.editor?.element)
|
|
77
|
+
return;
|
|
78
|
+
const text = this.editor.element.findOne('HTMLText');
|
|
79
|
+
if (!text)
|
|
80
|
+
return;
|
|
81
|
+
const { scaleX, scaleY } = text.worldTransform;
|
|
82
|
+
const zoomScale = Math.max(Math.abs(scaleX), Math.abs(scaleY));
|
|
83
|
+
this.addEvent();
|
|
84
|
+
this.editBox.add(this.view);
|
|
85
|
+
this.quill = TextEditor_1.TextEditor.quill;
|
|
86
|
+
if (this.quill && text.text) {
|
|
87
|
+
this.quill.clipboard.dangerouslyPasteHTML(text.text);
|
|
88
|
+
}
|
|
89
|
+
const div = document.querySelector('#textInnerEditor');
|
|
90
|
+
if (!div)
|
|
91
|
+
return;
|
|
92
|
+
const { style } = div;
|
|
93
|
+
if (text.data?.canChangeBox && text.parent) {
|
|
94
|
+
const parentWidth = text.parent.width;
|
|
95
|
+
const parentHeight = text.parent.height;
|
|
96
|
+
if (parentWidth !== undefined) {
|
|
97
|
+
style.width = parentWidth * zoomScale + 'px';
|
|
98
|
+
}
|
|
99
|
+
if (parentHeight !== undefined) {
|
|
100
|
+
style.height = parentHeight * zoomScale + 'px';
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
else {
|
|
104
|
+
style.width = 'auto';
|
|
105
|
+
style.height = 'auto';
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
updateChangeBoxBound(text) {
|
|
109
|
+
if (text && text.__layout?.boxBounds) {
|
|
110
|
+
text.set({
|
|
111
|
+
width: text.__layout.boxBounds.width,
|
|
112
|
+
height: text.__layout.boxBounds.height
|
|
113
|
+
});
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
onUpdate() {
|
|
117
|
+
if (!this.editor?.element)
|
|
118
|
+
return;
|
|
119
|
+
const text = this.editor.element.findOne('HTMLText');
|
|
120
|
+
if (!text)
|
|
121
|
+
return;
|
|
122
|
+
const el = this.editor.element;
|
|
123
|
+
console.log('文本bound更新');
|
|
124
|
+
if (this.curveAmount === text.curveAmount)
|
|
125
|
+
return;
|
|
126
|
+
if (this.isUpdatingPoints)
|
|
127
|
+
return;
|
|
128
|
+
}
|
|
129
|
+
onUnload() {
|
|
130
|
+
this.editor.off_(this.eventIds);
|
|
131
|
+
}
|
|
132
|
+
onDestroy() { }
|
|
133
|
+
};
|
|
134
|
+
exports.TextEditTool = TextEditTool;
|
|
135
|
+
exports.TextEditTool = TextEditTool = __decorate([
|
|
136
|
+
(0, editor_1.registerEditTool)(),
|
|
137
|
+
__metadata("design:paramtypes", [Object])
|
|
138
|
+
], 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,173 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.subscriptMapVal = exports.superscriptMapVal = exports.handleShowCurve = void 0;
|
|
4
|
+
exports.getArcRadius = getArcRadius;
|
|
5
|
+
exports.toSuperscript = toSuperscript;
|
|
6
|
+
exports.toSubscript = toSubscript;
|
|
7
|
+
exports.toNormal = toNormal;
|
|
8
|
+
const leafer_ui_1 = require("leafer-ui");
|
|
9
|
+
const html_1 = require("@leafer-in/html");
|
|
10
|
+
function getArcRadius(fontSize, curveAmount) {
|
|
11
|
+
if (curveAmount === 0)
|
|
12
|
+
return Infinity;
|
|
13
|
+
const theta = (330 * fontSize * 72) / 96;
|
|
14
|
+
const radius = theta / Math.abs(curveAmount);
|
|
15
|
+
return radius;
|
|
16
|
+
}
|
|
17
|
+
const handleShowCurve = (element, op) => {
|
|
18
|
+
const box = element.findOne('Box');
|
|
19
|
+
box && element.remove(box);
|
|
20
|
+
const text = element.findOne('HTMLText');
|
|
21
|
+
const { boxBounds, x, y } = text;
|
|
22
|
+
const { width } = boxBounds;
|
|
23
|
+
if (!text.curveAmount) {
|
|
24
|
+
text.opacity = 1;
|
|
25
|
+
text.visible = true;
|
|
26
|
+
return;
|
|
27
|
+
}
|
|
28
|
+
text.text = text.text.replace(/\u200B/g, '').replace(/<br\s*\/?>/gi, '\n');
|
|
29
|
+
text.opacity = 0;
|
|
30
|
+
const radius = getArcRadius(text.fontSize, text.curveAmount);
|
|
31
|
+
const C = 2 * Math.PI * radius;
|
|
32
|
+
const dis = text.text.length + 2;
|
|
33
|
+
const tW = width / dis;
|
|
34
|
+
let startW = 0;
|
|
35
|
+
if (C > tW * text.text.length) {
|
|
36
|
+
startW = (C - tW * text.text.length) / 2;
|
|
37
|
+
}
|
|
38
|
+
const startWPr = (startW * 360) / C;
|
|
39
|
+
const group = new leafer_ui_1.Box({
|
|
40
|
+
x: 0,
|
|
41
|
+
y: 0,
|
|
42
|
+
editable: false,
|
|
43
|
+
resizeChildren: true
|
|
44
|
+
});
|
|
45
|
+
let path;
|
|
46
|
+
const offsetK = text.fontSize * text.lineHeight.value || 0;
|
|
47
|
+
const offsetY = text.curveAmount > 0 ? radius + offsetK : -radius;
|
|
48
|
+
if (text.curveAmount > 0) {
|
|
49
|
+
path = `G ${x + width / 2} ${offsetY} ${radius} ${radius} 90 ${startWPr} ${360 - startWPr} 0`;
|
|
50
|
+
}
|
|
51
|
+
else {
|
|
52
|
+
const a = 180 - startWPr;
|
|
53
|
+
path = `G ${x + width / 2} ${offsetY} ${radius} ${radius} 90 ${a} ${-a} 1`;
|
|
54
|
+
}
|
|
55
|
+
const pathLine = new leafer_ui_1.Path({
|
|
56
|
+
x: 0,
|
|
57
|
+
y: 0,
|
|
58
|
+
motionPath: true,
|
|
59
|
+
editable: false,
|
|
60
|
+
path: path
|
|
61
|
+
});
|
|
62
|
+
group.add(pathLine);
|
|
63
|
+
group.set({
|
|
64
|
+
opacity: op ? 0.2 : 1
|
|
65
|
+
});
|
|
66
|
+
Array.from(text.text).forEach((ch, i) => {
|
|
67
|
+
const str = new html_1.HTMLText({
|
|
68
|
+
text: ch,
|
|
69
|
+
around: text.curveAmount > 0 ? 'bottom' : 'top',
|
|
70
|
+
fontSize: text.fontSize,
|
|
71
|
+
fontFamily: text.fontFamily,
|
|
72
|
+
fontWeight: text.fontWeight,
|
|
73
|
+
motion: i * tW + tW / 2,
|
|
74
|
+
textDecoration: text.textDecoration,
|
|
75
|
+
textCase: text.textCase,
|
|
76
|
+
textAlign: text.textAlign,
|
|
77
|
+
motionRotation: text.curveAmount > 0 ? 3 : -2,
|
|
78
|
+
fill: text.fill
|
|
79
|
+
});
|
|
80
|
+
group.add(str);
|
|
81
|
+
});
|
|
82
|
+
element.add(group);
|
|
83
|
+
};
|
|
84
|
+
exports.handleShowCurve = handleShowCurve;
|
|
85
|
+
const baseSuperscript = {
|
|
86
|
+
'0': '⁰', '1': '¹', '2': '²', '3': '³', '4': '⁴', '5': '⁵', '6': '⁶', '7': '⁷', '8': '⁸', '9': '⁹',
|
|
87
|
+
a: 'ᵃ', b: 'ᵇ', c: 'ᶜ', d: 'ᵈ', e: 'ᵉ', f: 'ᶠ', g: 'ᵍ', h: 'ʰ', i: 'ⁱ', j: 'ʲ', k: 'ᵏ',
|
|
88
|
+
l: 'ˡ', m: 'ᵐ', n: 'ⁿ', o: 'ᵒ', p: 'ᵖ', r: 'ʳ', s: 'ˢ', t: 'ᵗ', u: 'ᵘ', v: 'ᵛ', w: 'ʷ',
|
|
89
|
+
x: 'ˣ', y: 'ʸ', z: 'ᶻ',
|
|
90
|
+
A: 'ᴬ', B: 'ᴮ', D: 'ᴰ', E: 'ᴱ', G: 'ᴳ', H: 'ᴴ', I: 'ᴵ', J: 'ᴶ', K: 'ᴷ', L: 'ᴸ', M: 'ᴹ',
|
|
91
|
+
N: 'ᴺ', O: 'ᴼ', P: 'ᴾ', R: 'ᴿ', T: 'ᵀ', U: 'ᵁ', W: 'ᵂ',
|
|
92
|
+
'+': '⁺', '-': '⁻', '=': '⁼', '(': '⁽', ')': '⁾'
|
|
93
|
+
};
|
|
94
|
+
const baseSubscript = {
|
|
95
|
+
'0': '₀', '1': '₁', '2': '₂', '3': '₃', '4': '₄', '5': '₅', '6': '₆', '7': '₇', '8': '₈', '9': '₉',
|
|
96
|
+
a: 'ₐ', e: 'ₑ', h: 'ₕ', i: 'ᵢ', j: 'ⱼ', k: 'ₖ', l: 'ₗ', m: 'ₘ', n: 'ₙ', o: 'ₒ', p: 'ₚ',
|
|
97
|
+
r: 'ᵣ', s: 'ₛ', t: 'ₜ', u: 'ᵤ', v: 'ᵥ', x: 'ₓ',
|
|
98
|
+
'+': '₊', '-': '₋', '=': '₌', '(': '₍', ')': '₎',
|
|
99
|
+
'β': 'ᵦ', 'γ': 'ᵧ', 'ρ': 'ᵨ', 'φ': 'ᵩ', 'χ': 'ᵪ'
|
|
100
|
+
};
|
|
101
|
+
function invertMap(map) {
|
|
102
|
+
const inv = {};
|
|
103
|
+
for (const k in map) {
|
|
104
|
+
inv[map[k]] = map[k];
|
|
105
|
+
}
|
|
106
|
+
return inv;
|
|
107
|
+
}
|
|
108
|
+
const knownSupers = invertMap(baseSuperscript);
|
|
109
|
+
const knownSubs = invertMap(baseSubscript);
|
|
110
|
+
function buildSuperscriptMap(baseSup, baseSub) {
|
|
111
|
+
const out = {};
|
|
112
|
+
for (const k in baseSup)
|
|
113
|
+
out[k] = baseSup[k];
|
|
114
|
+
for (const base in baseSub) {
|
|
115
|
+
const subChar = baseSub[base];
|
|
116
|
+
if (base in baseSup)
|
|
117
|
+
out[subChar] = baseSup[base];
|
|
118
|
+
}
|
|
119
|
+
for (const supChar in knownSupers)
|
|
120
|
+
out[supChar] = supChar;
|
|
121
|
+
return out;
|
|
122
|
+
}
|
|
123
|
+
function buildSubscriptMap(baseSup, baseSub) {
|
|
124
|
+
const out = {};
|
|
125
|
+
for (const k in baseSub)
|
|
126
|
+
out[k] = baseSub[k];
|
|
127
|
+
for (const base in baseSup) {
|
|
128
|
+
const supChar = baseSup[base];
|
|
129
|
+
if (base in baseSub)
|
|
130
|
+
out[supChar] = baseSub[base];
|
|
131
|
+
}
|
|
132
|
+
for (const subChar in knownSubs)
|
|
133
|
+
out[subChar] = subChar;
|
|
134
|
+
return out;
|
|
135
|
+
}
|
|
136
|
+
const superscriptMap = buildSuperscriptMap(baseSuperscript, baseSubscript);
|
|
137
|
+
const subscriptMap = buildSubscriptMap(baseSuperscript, baseSubscript);
|
|
138
|
+
function toSuperscript(input) {
|
|
139
|
+
let out = '';
|
|
140
|
+
for (const ch of input) {
|
|
141
|
+
out += superscriptMap[ch] ?? ch;
|
|
142
|
+
}
|
|
143
|
+
return out;
|
|
144
|
+
}
|
|
145
|
+
function toSubscript(input) {
|
|
146
|
+
let out = '';
|
|
147
|
+
for (const ch of input) {
|
|
148
|
+
out += subscriptMap[ch] ?? ch;
|
|
149
|
+
}
|
|
150
|
+
return out;
|
|
151
|
+
}
|
|
152
|
+
exports.superscriptMapVal = Object.values(superscriptMap);
|
|
153
|
+
exports.subscriptMapVal = Object.values(subscriptMap);
|
|
154
|
+
function buildNormalMap(baseSup, baseSub) {
|
|
155
|
+
const normal = {};
|
|
156
|
+
for (const base in baseSup) {
|
|
157
|
+
const supChar = baseSup[base];
|
|
158
|
+
normal[supChar] = base;
|
|
159
|
+
}
|
|
160
|
+
for (const base in baseSub) {
|
|
161
|
+
const subChar = baseSub[base];
|
|
162
|
+
normal[subChar] = base;
|
|
163
|
+
}
|
|
164
|
+
return normal;
|
|
165
|
+
}
|
|
166
|
+
const normalMap = buildNormalMap(baseSuperscript, baseSubscript);
|
|
167
|
+
function toNormal(input) {
|
|
168
|
+
let out = '';
|
|
169
|
+
for (const ch of input) {
|
|
170
|
+
out += normalMap[ch] ?? ch;
|
|
171
|
+
}
|
|
172
|
+
return out;
|
|
173
|
+
}
|
|
@@ -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"}
|