kyle-editor 1.0.3 → 1.0.5
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/README.md +36 -7
- package/dist/keditor.cjs +1 -1
- package/dist/keditor.es.js +1 -1
- package/dist/keditor.umd.js +1 -1
- package/dist/keditor.umd.min.js +483 -0
- package/imgs/img.png +0 -0
- package/imgs/img_1.png +0 -0
- package/imgs/img_2.png +0 -0
- package/imgs/img_3.png +0 -0
- package/package.json +8 -5
package/README.md
CHANGED
|
@@ -2,10 +2,15 @@
|
|
|
2
2
|
|
|
3
3
|
轻量、美观的**微信公众号风格富文本编辑器**。纯前端实现,无任何后端依赖:图片/视频走**分片上传**(并发、重试、取消、秒传、断点续传),随时切换 **HTML 源码模式**查看或改写产物。支持 `<script>` 直接引入与 Vue 3 安装集成。
|
|
4
4
|
|
|
5
|
-
- 体积:`dist/keditor.umd.js` 约 209 KB(gzip 55 KB),零运行时依赖,样式随 JS 注入
|
|
5
|
+
- 体积:`dist/keditor.umd.min.js` 约 139 KB(gzip 43 KB),未压缩版 209 KB(gzip 55 KB),零运行时依赖,样式随 JS 注入
|
|
6
6
|
- 版式:677px 正文版心、17px/1.75 行距,与公众号观感一致;**宽屏下版心自动生长**,两侧留白恒定,不会留出一大块空白
|
|
7
7
|
- 安全:标签/属性白名单净化,拦截 `on*`、`javascript:`、`script/iframe`
|
|
8
8
|
|
|
9
|
+

|
|
10
|
+

|
|
11
|
+

|
|
12
|
+

|
|
13
|
+
|
|
9
14
|
## 功能
|
|
10
15
|
|
|
11
16
|
| 分类 | 能力 |
|
|
@@ -28,7 +33,9 @@ npm install kyle-editor vue@^3
|
|
|
28
33
|
或直接用 CDN(无需安装):
|
|
29
34
|
|
|
30
35
|
```html
|
|
31
|
-
|
|
36
|
+
<!-- unpkg / jsdelivr 默认入口就是压缩版,下面两种写法等价 -->
|
|
37
|
+
<script src="https://unpkg.com/kyle-editor"></script>
|
|
38
|
+
<script src="https://unpkg.com/kyle-editor/dist/keditor.umd.min.js"></script>
|
|
32
39
|
```
|
|
33
40
|
|
|
34
41
|
> 零运行时依赖;样式随 JS 注入,**不需要额外引入 CSS**。Vue 是可选 peerDependency,只用核心 API 的项目不会被强制安装。
|
|
@@ -39,8 +46,9 @@ npm install kyle-editor vue@^3
|
|
|
39
46
|
|
|
40
47
|
```html
|
|
41
48
|
<div id="editor"></div>
|
|
42
|
-
<script src="https://unpkg.com/kyle-editor/dist/keditor.umd.js"></script>
|
|
43
|
-
<!-- 本地开发时也可用相对路径:<script src="dist/keditor.umd.js"></script>
|
|
49
|
+
<script src="https://unpkg.com/kyle-editor/dist/keditor.umd.min.js"></script>
|
|
50
|
+
<!-- 本地开发时也可用相对路径:<script src="dist/keditor.umd.min.js"></script>
|
|
51
|
+
调试想看未压缩代码就换成 dist/keditor.umd.js(全局变量、API 完全一致) -->
|
|
44
52
|
<script>
|
|
45
53
|
const editor = KEditor.create('#editor', {
|
|
46
54
|
placeholder: '开始撰写内容,支持拖拽 / 粘贴图片与视频…',
|
|
@@ -273,17 +281,38 @@ editor.paperOptions() // { width, mode, gap, maxWidth }
|
|
|
273
281
|
|
|
274
282
|
```bash
|
|
275
283
|
npm install
|
|
276
|
-
npm run build # 产出 dist/(es + cjs + umd,含 Vue 版本)
|
|
284
|
+
npm run build # 产出 dist/(es + cjs + umd + umd.min,含 Vue 版本)
|
|
285
|
+
npm run build:min # 只重建压缩版 dist/keditor.umd.min.js
|
|
277
286
|
npm run dev # 静态服务 http://127.0.0.1:5178
|
|
278
287
|
```
|
|
279
288
|
|
|
289
|
+
### 构建产物
|
|
290
|
+
|
|
291
|
+
| 文件 | 用途 | 体积 |
|
|
292
|
+
| --- | --- | --- |
|
|
293
|
+
| `dist/keditor.umd.min.js` | **CDN / `<script>` 默认入口**(`unpkg`、`jsdelivr` 均指向它) | 139 KB / gzip 43 KB |
|
|
294
|
+
| `dist/keditor.umd.js` | 同上但未压缩,便于断点调试 | 209 KB / gzip 55 KB |
|
|
295
|
+
| `dist/keditor.es.js` | ESM(`exports.import`,打包器走这个) | 199 KB |
|
|
296
|
+
| `dist/keditor.cjs` | CommonJS(`exports.require`) | 200 KB |
|
|
297
|
+
| `dist/keditor-vue.{es,cjs,umd}.js` | Vue 组件/插件,外部化 `vue` 与本包 | 各约 4 KB |
|
|
298
|
+
|
|
299
|
+
两份 UMD 产物由 `vite.config.core.js`(未压缩)与 `vite.config.min.js`(`minify: 'esbuild'`)从同一入口分别构建,全局变量都是 `window.KEditor`,API 完全一致。
|
|
300
|
+
|
|
280
301
|
## 验证
|
|
281
302
|
|
|
282
303
|
```bash
|
|
283
|
-
npm run
|
|
284
|
-
|
|
304
|
+
npm run dev & # 先启动静态服务(测试页面走 http://127.0.0.1:5178)
|
|
305
|
+
|
|
306
|
+
npm run verify # build + 冒烟(未压缩) + 冒烟(压缩) + 页面检查 + 类型 + 发布配置
|
|
307
|
+
npm test # 171 项冒烟,跑 dist/keditor.umd.js
|
|
308
|
+
npm run test:min # 同一套 171 项冒烟,跑 dist/keditor.umd.min.js
|
|
309
|
+
npm run test:pages # demo / 首页零控制台错误 + 真实交互探针
|
|
310
|
+
npm run test:install # npm pack → 隔离安装 → 校验包内入口与压缩产物等价性
|
|
311
|
+
npm run test:visual # 20 张关键状态截图(test/screenshots/)
|
|
285
312
|
```
|
|
286
313
|
|
|
314
|
+
> `test` 与 `test:min` 复用同一个 `test/smoke.html`,靠 `?bundle=min` 切换被测产物 —— 压缩版任何行为差异都会在这里暴露;`test:install` 还会对比两份 UMD 的导出清单,防止 minify 丢导出。
|
|
315
|
+
|
|
287
316
|
## 已知限制
|
|
288
317
|
|
|
289
318
|
- 依赖浏览器 `contenteditable` + `document.execCommand`(主流浏览器均支持,Chrome/Safari/Edge/Firefox 已验证);不兼容 IE。
|
package/dist/keditor.cjs
CHANGED
package/dist/keditor.es.js
CHANGED
package/dist/keditor.umd.js
CHANGED
|
@@ -0,0 +1,483 @@
|
|
|
1
|
+
(function(b,D){typeof exports=="object"&&typeof module<"u"?D(exports):typeof define=="function"&&define.amd?define(["exports"],D):(b=typeof globalThis<"u"?globalThis:b||self,D(b.KEditor={}))})(this,function(b){"use strict";const D=`
|
|
2
|
+
.ke, .ke * { box-sizing: border-box; }
|
|
3
|
+
.ke {
|
|
4
|
+
--ke-primary: #07c160;
|
|
5
|
+
--ke-primary-weak: #eafaf1;
|
|
6
|
+
--ke-text: #3f3f3f;
|
|
7
|
+
--ke-muted: #8a8f99;
|
|
8
|
+
--ke-line: #e6e8eb;
|
|
9
|
+
--ke-line-weak: #f0f1f3;
|
|
10
|
+
--ke-bg: #f6f7f9;
|
|
11
|
+
--ke-radius: 10px;
|
|
12
|
+
--ke-paper: 677px;
|
|
13
|
+
--ke-paper-gap: 24px;
|
|
14
|
+
--ke-shadow: 0 1px 2px rgba(16, 24, 40, .04), 0 8px 24px rgba(16, 24, 40, .06);
|
|
15
|
+
font-family: -apple-system, BlinkMacSystemFont, 'PingFang SC', 'Hiragino Sans GB', 'Microsoft YaHei', 'Helvetica Neue', Helvetica, Arial, sans-serif;
|
|
16
|
+
color: var(--ke-text);
|
|
17
|
+
background: var(--ke-bg);
|
|
18
|
+
position: relative;
|
|
19
|
+
border: 1px solid var(--ke-line);
|
|
20
|
+
border-radius: var(--ke-radius);
|
|
21
|
+
overflow: hidden;
|
|
22
|
+
display: flex;
|
|
23
|
+
flex-direction: column;
|
|
24
|
+
font-size: 14px;
|
|
25
|
+
-webkit-font-smoothing: antialiased;
|
|
26
|
+
}
|
|
27
|
+
.ke[hidden] { display: none; }
|
|
28
|
+
.ke-is-fullscreen { position: fixed; inset: 0; z-index: 9998; border-radius: 0; }
|
|
29
|
+
|
|
30
|
+
/* ---------------- Toolbar ---------------- */
|
|
31
|
+
.ke-tb {
|
|
32
|
+
position: sticky; top: 0; z-index: 5;
|
|
33
|
+
display: flex; align-items: center; gap: 2px; flex-wrap: nowrap;
|
|
34
|
+
padding: 6px 10px 5px;
|
|
35
|
+
background: #fff;
|
|
36
|
+
border-bottom: 1px solid var(--ke-line);
|
|
37
|
+
overflow-x: auto;
|
|
38
|
+
overflow-y: hidden;
|
|
39
|
+
overscroll-behavior-x: contain;
|
|
40
|
+
-webkit-overflow-scrolling: touch;
|
|
41
|
+
/* 滚动条常显:静止时也能一眼看出「还有更多工具」 */
|
|
42
|
+
scrollbar-width: thin;
|
|
43
|
+
scrollbar-color: rgba(16, 24, 40, .28) rgba(16, 24, 40, .05);
|
|
44
|
+
}
|
|
45
|
+
.ke-tb::-webkit-scrollbar { height: 7px; }
|
|
46
|
+
.ke-tb::-webkit-scrollbar-track { background: rgba(16, 24, 40, .06); border-radius: 4px; }
|
|
47
|
+
.ke-tb::-webkit-scrollbar-thumb { background: rgba(16, 24, 40, .34); border-radius: 4px; }
|
|
48
|
+
.ke-tb:hover::-webkit-scrollbar-thumb { background: rgba(16, 24, 40, .48); }
|
|
49
|
+
.ke-tb::-webkit-scrollbar-thumb:active { background: var(--ke-primary); }
|
|
50
|
+
.ke-tb-group { display: flex; align-items: center; gap: 2px; flex: none; }
|
|
51
|
+
.ke-tb-sep { width: 1px; height: 18px; background: var(--ke-line); margin: 0 6px; flex: none; }
|
|
52
|
+
.ke-tb-tail {
|
|
53
|
+
position: sticky; right: 0; margin-left: auto; display: flex; align-items: center; gap: 4px;
|
|
54
|
+
flex: none; padding: 0 2px 0 12px; background: #fff;
|
|
55
|
+
box-shadow: none; transition: box-shadow .2s;
|
|
56
|
+
}
|
|
57
|
+
/* 仅当右侧仍有被尾部遮住的工具时才显示,让阴影成为「可继续滑动」的信号 */
|
|
58
|
+
.ke.ke-tb-can-r .ke-tb-tail { box-shadow: -16px 0 14px -10px rgba(16, 24, 40, .55); }
|
|
59
|
+
/* 尾部左缘渐隐:明确表达「还有工具滑到这块底下」 */
|
|
60
|
+
.ke-tb-tail::before {
|
|
61
|
+
content: ''; position: absolute; top: 0; bottom: 0; right: 100%; width: 30px;
|
|
62
|
+
background: linear-gradient(to left, rgba(255, 255, 255, .99) 18%, rgba(255, 255, 255, 0));
|
|
63
|
+
opacity: 0; transition: opacity .2s; pointer-events: none;
|
|
64
|
+
}
|
|
65
|
+
.ke.ke-tb-can-r .ke-tb-tail::before { opacity: 1; }
|
|
66
|
+
/* 遮住工具栏右侧 padding 区域,避免滚动内容从尾部后面露出 */
|
|
67
|
+
.ke-tb-tail::after { content: ''; position: absolute; top: 0; bottom: 0; right: -16px; width: 18px; background: #fff; }
|
|
68
|
+
|
|
69
|
+
/* ------- 可滑动提示:左侧渐隐 + 拖拽手势 + 首次引导气泡 ------- */
|
|
70
|
+
/* 高度避开底部 7px 滚动条,否则会把滚动条左端涂白 */
|
|
71
|
+
.ke-tb-fades { position: absolute; left: 0; right: 0; top: 0; height: calc(var(--ke-tb-h, 44px) - 8px); z-index: 6; pointer-events: none; overflow: hidden; }
|
|
72
|
+
.ke-tb-fade { position: absolute; top: 0; bottom: 0; width: 34px; opacity: 0; transition: opacity .2s; }
|
|
73
|
+
.ke-tb-fade-l { left: 0; background: linear-gradient(to right, rgba(255, 255, 255, .99) 26%, rgba(255, 255, 255, 0)); }
|
|
74
|
+
.ke.ke-tb-can-l .ke-tb-fade-l { opacity: 1; }
|
|
75
|
+
@media (hover: hover) and (pointer: fine) {
|
|
76
|
+
.ke.ke-tb-scrollable .ke-tb { cursor: grab; }
|
|
77
|
+
.ke.ke-tb-dragging .ke-tb, .ke.ke-tb-dragging .ke-tb .ke-btn { cursor: grabbing; }
|
|
78
|
+
}
|
|
79
|
+
.ke.ke-tb-dragging { user-select: none; -webkit-user-select: none; }
|
|
80
|
+
.ke-tb-hint {
|
|
81
|
+
position: absolute; left: 50%; top: calc(var(--ke-tb-h, 44px) + 9px); z-index: 7;
|
|
82
|
+
transform: translateX(-50%);
|
|
83
|
+
display: inline-flex; align-items: center; gap: 7px;
|
|
84
|
+
padding: 7px 13px; border-radius: 999px;
|
|
85
|
+
background: rgba(31, 35, 41, .94); color: #fff;
|
|
86
|
+
font-size: 12.5px; line-height: 1; white-space: nowrap; letter-spacing: .2px;
|
|
87
|
+
box-shadow: 0 6px 20px rgba(16, 24, 40, .26);
|
|
88
|
+
pointer-events: none;
|
|
89
|
+
animation: ke-hint-in .3s cubic-bezier(.22, 1, .36, 1) both;
|
|
90
|
+
}
|
|
91
|
+
.ke-tb-hint::before {
|
|
92
|
+
content: ''; position: absolute; top: -5px; left: 50%; margin-left: -5px;
|
|
93
|
+
border: 5px solid transparent; border-top: 0; border-bottom-color: rgba(31, 35, 41, .94);
|
|
94
|
+
}
|
|
95
|
+
.ke-tb-hint-ico { display: flex; color: #7ee2a8; animation: ke-hint-slide 1.15s ease-in-out infinite; }
|
|
96
|
+
.ke-tb-hint-ico svg { width: 15px; height: 15px; display: block; }
|
|
97
|
+
.ke-tb-hint.ke-is-out { animation: ke-hint-out .24s ease-in both; }
|
|
98
|
+
@keyframes ke-hint-in {
|
|
99
|
+
from { opacity: 0; transform: translateX(-50%) translateY(-8px) scale(.96); }
|
|
100
|
+
to { opacity: 1; transform: translateX(-50%) translateY(0) scale(1); }
|
|
101
|
+
}
|
|
102
|
+
@keyframes ke-hint-out {
|
|
103
|
+
to { opacity: 0; transform: translateX(-50%) translateY(-8px) scale(.96); }
|
|
104
|
+
}
|
|
105
|
+
@keyframes ke-hint-slide {
|
|
106
|
+
0%, 100% { transform: translateX(-2.5px); }
|
|
107
|
+
50% { transform: translateX(2.5px); }
|
|
108
|
+
}
|
|
109
|
+
.ke-btn {
|
|
110
|
+
position: relative; flex: none;
|
|
111
|
+
height: 30px; min-width: 30px; padding: 0 6px;
|
|
112
|
+
display: inline-flex; align-items: center; justify-content: center; gap: 4px;
|
|
113
|
+
border: 0; border-radius: 6px; background: transparent; color: #4b5158;
|
|
114
|
+
cursor: pointer; font-size: 13px; line-height: 1; transition: background .15s, color .15s;
|
|
115
|
+
}
|
|
116
|
+
.ke-btn:hover { background: #f2f3f5; color: #1f2329; }
|
|
117
|
+
.ke-btn:active { background: #e9eaec; }
|
|
118
|
+
.ke-btn.ke-is-active { background: var(--ke-primary-weak); color: var(--ke-primary); }
|
|
119
|
+
.ke-btn.ke-is-open { background: #eef0f2; color: #1f2329; }
|
|
120
|
+
.ke-btn-label { padding: 0 6px 0 8px; gap: 2px; min-width: 56px; justify-content: flex-start; }
|
|
121
|
+
.ke-btn-text { font-size: 12.5px; letter-spacing: .2px; }
|
|
122
|
+
.ke-btn:disabled { opacity: .38; cursor: not-allowed; }
|
|
123
|
+
.ke-btn:focus-visible { outline: 2px solid var(--ke-primary); outline-offset: 1px; }
|
|
124
|
+
.ke-ico { width: 17px; height: 17px; display: block; }
|
|
125
|
+
.ke-glyph { font-size: 14px; font-weight: 600; }
|
|
126
|
+
.ke-glyph-i { font-style: italic; font-family: Georgia, 'Times New Roman', serif; }
|
|
127
|
+
.ke-glyph-u { text-decoration: underline; }
|
|
128
|
+
.ke-glyph-s { text-decoration: line-through; }
|
|
129
|
+
.ke-glyph-h { font-weight: 700; font-size: 13px; }
|
|
130
|
+
.ke-dot { position: absolute; left: 4px; right: 4px; bottom: 3px; height: 3px; border-radius: 2px; background: var(--ke-fore, #1f2329); }
|
|
131
|
+
.ke-dot-bg { left: 3px; right: 3px; bottom: 2.5px; height: 4px; border-radius: 2px; background: var(--ke-back, #f6c344); }
|
|
132
|
+
.ke-glyph-a { font-size: 15px; font-weight: 700; letter-spacing: 0; line-height: 1; margin-bottom: 3px; }
|
|
133
|
+
.ke-glyph-hl { position: relative; margin-bottom: 0; padding: 0 3px; }
|
|
134
|
+
.ke-glyph-hl::before { content: ''; position: absolute; left: 0; right: 0; bottom: 0; height: 11px; border-radius: 2px; background: var(--ke-back, #f6c344); }
|
|
135
|
+
.ke-glyph-hl > span { position: relative; z-index: 1; }
|
|
136
|
+
.ke-btn[data-k-pop] .ke-caret { width: 11px; height: 11px; opacity: .5; margin-left: -1px; }
|
|
137
|
+
.ke-select {
|
|
138
|
+
height: 30px; border: 1px solid transparent; border-radius: 6px; background: transparent;
|
|
139
|
+
color: #4b5158; font-size: 13px; padding: 0 4px; cursor: pointer; max-width: 92px;
|
|
140
|
+
}
|
|
141
|
+
.ke-select:hover { background: #f2f3f5; }
|
|
142
|
+
.ke-select:focus { outline: none; border-color: var(--ke-primary); }
|
|
143
|
+
|
|
144
|
+
/* ---------------- Popover ---------------- */
|
|
145
|
+
.ke-pop {
|
|
146
|
+
position: absolute; z-index: 40; min-width: 236px; padding: 0;
|
|
147
|
+
background: #fff; border: 1px solid rgba(31, 35, 41, .07); border-radius: 12px;
|
|
148
|
+
box-shadow: 0 2px 4px rgba(16, 24, 40, .04), 0 12px 32px rgba(16, 24, 40, .14);
|
|
149
|
+
font-size: 13px; color: var(--ke-text); overflow: hidden;
|
|
150
|
+
}
|
|
151
|
+
.ke-pop[hidden] { display: none; }
|
|
152
|
+
.ke-pop-in { animation: ke-pop-in .16s cubic-bezier(.22, 1, .36, 1); }
|
|
153
|
+
@keyframes ke-pop-in { from { opacity: 0; transform: translateY(-6px) scale(.985); } }
|
|
154
|
+
.ke-panel { padding: 12px 14px 14px; }
|
|
155
|
+
.ke-panel-wide { min-width: 268px; }
|
|
156
|
+
.ke-panel-head { display: flex; align-items: center; gap: 8px; margin: -12px -14px 12px; padding: 10px 14px; background: #f8f9fb; border-bottom: 1px solid var(--ke-line-weak); }
|
|
157
|
+
.ke-panel-title { font-size: 13px; font-weight: 600; color: #1f2329; }
|
|
158
|
+
.ke-panel-note { margin-left: auto; font-size: 12px; color: var(--ke-muted); }
|
|
159
|
+
.ke-panel-reset { margin-left: auto; height: 22px; padding: 0 8px; border: 1px solid var(--ke-line); border-radius: 11px; background: #fff; color: #6b7280; font-size: 12px; cursor: pointer; }
|
|
160
|
+
.ke-panel-reset:hover { border-color: var(--ke-primary); color: var(--ke-primary); }
|
|
161
|
+
.ke-panel-sect { margin: 10px 0 6px; font-size: 11px; color: #a2a8b3; letter-spacing: .3px; }
|
|
162
|
+
.ke-panel-sect:first-of-type { margin-top: 0; }
|
|
163
|
+
.ke-panel-divider { height: 1px; background: var(--ke-line-weak); margin: 12px -14px 10px; }
|
|
164
|
+
.ke-panel-hint { font-size: 11.5px; color: #a2a8b3; line-height: 1.5; }
|
|
165
|
+
.ke-panel-foot { display: flex; align-items: center; gap: 8px; margin-top: 10px; }
|
|
166
|
+
|
|
167
|
+
.ke-sw-grid { display: grid; grid-template-columns: repeat(8, 1fr); gap: 6px; }
|
|
168
|
+
.ke-sw {
|
|
169
|
+
position: relative; width: 100%; aspect-ratio: 1 / 1; min-width: 22px; padding: 0;
|
|
170
|
+
border: 1px solid rgba(0, 0, 0, .07); border-radius: 6px; cursor: pointer;
|
|
171
|
+
transition: transform .12s ease, box-shadow .12s ease;
|
|
172
|
+
}
|
|
173
|
+
.ke-sw:hover { transform: translateY(-1px) scale(1.08); box-shadow: 0 2px 6px rgba(16, 24, 40, .18); z-index: 1; }
|
|
174
|
+
.ke-sw.ke-is-active { box-shadow: 0 0 0 2px #fff, 0 0 0 3.5px var(--ke-primary); }
|
|
175
|
+
.ke-sw-check { position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; pointer-events: none; }
|
|
176
|
+
.ke-sw-check .ke-ico { width: 13px; height: 13px; filter: drop-shadow(0 1px 1px rgba(0, 0, 0, .35)); }
|
|
177
|
+
.ke-sw-picker { width: 30px; height: 30px; padding: 0; border: 1px solid var(--ke-line); border-radius: 7px; background: #fff; cursor: pointer; flex: none; }
|
|
178
|
+
.ke-sw-picker::-webkit-color-swatch-wrapper { padding: 3px; }
|
|
179
|
+
.ke-sw-picker::-webkit-color-swatch { border: 0; border-radius: 4px; }
|
|
180
|
+
.ke-sw-hex { flex: 1; font-family: 'SFMono-Regular', Consolas, Menlo, monospace; text-transform: uppercase; }
|
|
181
|
+
|
|
182
|
+
.ke-hd-row {
|
|
183
|
+
display: flex; flex-direction: column; align-items: stretch; gap: 2px; width: 100%;
|
|
184
|
+
padding: 8px 10px; margin-bottom: 4px; border: 1px solid transparent; border-radius: 8px;
|
|
185
|
+
background: #fff; cursor: pointer; text-align: left; transition: background .14s, border-color .14s;
|
|
186
|
+
}
|
|
187
|
+
.ke-hd-row:last-child { margin-bottom: 0; }
|
|
188
|
+
.ke-hd-row:hover { background: #f7f8fa; }
|
|
189
|
+
.ke-hd-row.ke-is-active { border-color: var(--ke-primary); background: var(--ke-primary-weak); }
|
|
190
|
+
.ke-hd-sample { display: block; color: #1f2329; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; line-height: 1.35; }
|
|
191
|
+
.ke-hd-meta { display: flex; align-items: baseline; gap: 6px; font-size: 11.5px; color: #a2a8b3; }
|
|
192
|
+
.ke-hd-label { color: #6b7280; }
|
|
193
|
+
.ke-hd-row .s-body { font-size: 15px; }
|
|
194
|
+
.ke-hd-row .s-h1 { font-size: 21px; font-weight: 700; }
|
|
195
|
+
.ke-hd-row .s-h2 { font-size: 18px; font-weight: 700; }
|
|
196
|
+
.ke-hd-row .s-h3 { font-size: 16px; font-weight: 600; }
|
|
197
|
+
|
|
198
|
+
.ke-size-grid { display: grid; grid-template-columns: repeat(6, 1fr); gap: 6px; }
|
|
199
|
+
.ke-size-cell { height: 32px; border: 1px solid var(--ke-line); border-radius: 7px; background: #fff; color: #4b5158; cursor: pointer; }
|
|
200
|
+
.ke-size-cell:hover { border-color: var(--ke-primary); color: var(--ke-primary); background: var(--ke-primary-weak); }
|
|
201
|
+
.ke-size-cell.ke-is-active { border-color: var(--ke-primary); background: var(--ke-primary); color: #fff; }
|
|
202
|
+
|
|
203
|
+
/* -------- 自定义下拉按钮 -------- */
|
|
204
|
+
.ke-btn-custom .ke-btn-text { max-width: 96px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
|
|
205
|
+
.ke-btn-custom.ke-has-value { color: var(--ke-primary); }
|
|
206
|
+
.ke-panel-icon { margin-left: auto; width: 22px; height: 22px; padding: 0; border: 1px solid var(--ke-line); border-radius: 50%; background: #fff; color: #6b7280; cursor: pointer; display: inline-flex; align-items: center; justify-content: center; }
|
|
207
|
+
.ke-panel-icon:hover { border-color: var(--ke-primary); color: var(--ke-primary); }
|
|
208
|
+
.ke-panel-icon .ke-ico { width: 13px; height: 13px; }
|
|
209
|
+
.ke-panel-icon + .ke-panel-note { margin-left: 8px; }
|
|
210
|
+
|
|
211
|
+
.ke-panel-select .ke-sel-search { margin-bottom: 8px; }
|
|
212
|
+
.ke-sel-body { max-height: 268px; overflow-y: auto; overscroll-behavior: contain; margin: 0 -4px; padding: 0 4px; }
|
|
213
|
+
.ke-sel-row {
|
|
214
|
+
display: flex; align-items: center; gap: 8px; width: 100%;
|
|
215
|
+
padding: 7px 9px; margin-bottom: 3px; border: 1px solid transparent; border-radius: 8px;
|
|
216
|
+
background: #fff; cursor: pointer; text-align: left; transition: background .14s, border-color .14s;
|
|
217
|
+
}
|
|
218
|
+
.ke-sel-row:last-child { margin-bottom: 0; }
|
|
219
|
+
.ke-sel-row:hover:not(:disabled) { background: #f7f8fa; }
|
|
220
|
+
.ke-sel-row:disabled { cursor: not-allowed; opacity: .45; }
|
|
221
|
+
.ke-sel-row.ke-is-active { border-color: var(--ke-primary); background: var(--ke-primary-weak); }
|
|
222
|
+
.ke-sel-main { display: flex; flex-direction: column; gap: 1px; min-width: 0; flex: 1; }
|
|
223
|
+
.ke-sel-label { color: #1f2329; font-size: 13.5px; line-height: 1.4; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
|
|
224
|
+
.ke-sel-row.ke-is-active .ke-sel-label { color: var(--ke-primary); font-weight: 600; }
|
|
225
|
+
.ke-sel-desc { color: #a2a8b3; font-size: 11.5px; line-height: 1.45; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
|
|
226
|
+
.ke-sel-link { display: inline-flex; align-items: center; gap: 3px; color: #2f6fed; font-size: 11px; }
|
|
227
|
+
.ke-sel-link .ke-ico { width: 11px; height: 11px; flex: none; }
|
|
228
|
+
.ke-sel-link i { font-style: normal; opacity: .8; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 150px; }
|
|
229
|
+
.ke-sel-check { flex: none; width: 16px; height: 16px; color: var(--ke-primary); }
|
|
230
|
+
.ke-sel-check .ke-ico { width: 16px; height: 16px; }
|
|
231
|
+
|
|
232
|
+
.ke-sel-loading { display: flex; align-items: center; gap: 8px; padding: 4px 2px 10px; color: #6b7280; font-size: 12.5px; }
|
|
233
|
+
.ke-sel-loading .ke-spinner { width: 14px; height: 14px; }
|
|
234
|
+
.ke-sel-skel { height: 34px; margin-bottom: 6px; border-radius: 8px; background: linear-gradient(90deg, #f2f3f5 25%, #e9ebef 37%, #f2f3f5 63%); background-size: 400% 100%; animation: ke-skel 1.3s ease infinite; }
|
|
235
|
+
@keyframes ke-skel { from { background-position: 100% 50%; } to { background-position: 0 50%; } }
|
|
236
|
+
.ke-sel-tip { display: flex; flex-direction: column; align-items: center; gap: 10px; padding: 22px 12px; text-align: center; }
|
|
237
|
+
.ke-sel-tip-text { color: #a2a8b3; font-size: 12.5px; line-height: 1.6; word-break: break-all; }
|
|
238
|
+
.ke-sel-tip .ke-btn-primary { align-self: center; }
|
|
239
|
+
|
|
240
|
+
.ke-tabs { display: flex; gap: 4px; margin: -12px -14px 12px; padding: 0 14px; background: #f8f9fb; border-bottom: 1px solid var(--ke-line-weak); }
|
|
241
|
+
.ke-tab { height: 34px; padding: 0 4px; margin-right: 10px; border: 0; border-bottom: 2px solid transparent; background: transparent; color: #6b7280; font-size: 13px; cursor: pointer; }
|
|
242
|
+
.ke-tab:hover { color: #1f2329; }
|
|
243
|
+
.ke-tab.ke-is-active { color: var(--ke-primary); border-bottom-color: var(--ke-primary); font-weight: 600; }
|
|
244
|
+
.ke-tab-body[hidden] { display: none; }
|
|
245
|
+
.ke-drop {
|
|
246
|
+
display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 6px;
|
|
247
|
+
padding: 20px 14px; border: 1.5px dashed #d6dade; border-radius: 10px; background: #fbfcfd;
|
|
248
|
+
color: var(--ke-muted); cursor: pointer; text-align: center; transition: border-color .14s, background .14s;
|
|
249
|
+
}
|
|
250
|
+
.ke-drop:hover, .ke-drop.ke-is-over { border-color: var(--ke-primary); background: var(--ke-primary-weak); }
|
|
251
|
+
.ke-drop-ico .ke-ico { width: 24px; height: 24px; color: var(--ke-primary); }
|
|
252
|
+
.ke-drop-title { font-size: 13px; color: #4b5158; }
|
|
253
|
+
.ke-drop-sub { font-size: 11.5px; color: #a2a8b3; }
|
|
254
|
+
.ke-field { display: flex; align-items: center; gap: 8px; margin-bottom: 8px; }
|
|
255
|
+
.ke-field-label { flex: none; width: 34px; font-size: 12px; color: var(--ke-muted); }
|
|
256
|
+
.ke-check { display: flex; align-items: center; gap: 6px; font-size: 12px; color: #4b5158; margin-bottom: 4px; }
|
|
257
|
+
.ke-link-status { min-height: 18px; font-size: 11.5px; color: #a2a8b3; }
|
|
258
|
+
.ke-link-status.ke-is-checking { color: #2f6fed; }
|
|
259
|
+
.ke-link-status.ke-is-ok { color: var(--ke-primary); }
|
|
260
|
+
.ke-link-status.ke-is-bad { color: #ed8936; }
|
|
261
|
+
|
|
262
|
+
.ke-input, .ke-textarea {
|
|
263
|
+
width: 100%; height: 32px; padding: 0 10px; border: 1px solid var(--ke-line); border-radius: 7px;
|
|
264
|
+
font-size: 13px; color: var(--ke-text); background: #fff; transition: border-color .14s, box-shadow .14s;
|
|
265
|
+
}
|
|
266
|
+
.ke-input:focus, .ke-textarea:focus { outline: none; border-color: var(--ke-primary); box-shadow: 0 0 0 3px rgba(7, 193, 96, .12); }
|
|
267
|
+
.ke-input.ke-is-invalid { border-color: #e53e3e; box-shadow: 0 0 0 3px rgba(229, 62, 62, .12); }
|
|
268
|
+
.ke-textarea { height: auto; padding: 8px 10px; resize: vertical; font-family: inherit; line-height: 1.6; }
|
|
269
|
+
.ke-btn-primary { height: 32px; padding: 0 16px; border-radius: 7px; background: var(--ke-primary); color: #fff; font-size: 13px; border: 0; cursor: pointer; flex: none; }
|
|
270
|
+
.ke-btn-primary:hover { background: #06b35a; }
|
|
271
|
+
.ke-btn-primary:disabled { opacity: .45; cursor: progress; }
|
|
272
|
+
.ke-btn-ghost { height: 32px; padding: 0 14px; border-radius: 7px; background: #fff; border: 1px solid var(--ke-line); color: #4b5158; font-size: 13px; cursor: pointer; flex: none; }
|
|
273
|
+
.ke-btn-ghost:hover { border-color: #cfd3d8; color: #1f2329; }
|
|
274
|
+
.ke-table-grid { display: grid; gap: 3px; }
|
|
275
|
+
.ke-table-cell { width: 18px; height: 18px; border: 1px solid #d6dade; border-radius: 3px; transition: background .1s; }
|
|
276
|
+
.ke-table-cell.ke-is-on { background: var(--ke-primary-weak); border-color: var(--ke-primary); }
|
|
277
|
+
|
|
278
|
+
/* ---------------- Paper / Content ---------------- */
|
|
279
|
+
.ke-main { flex: 1; min-height: 0; display: flex; flex-direction: column; position: relative; }
|
|
280
|
+
.ke-scroll { flex: 1; min-height: 0; overflow-y: auto; padding: 22px 18px 28px; background: var(--ke-bg); scrollbar-width: thin; }
|
|
281
|
+
.ke-paper {
|
|
282
|
+
width: min(100%, calc(var(--ke-paper) + 64px)); margin: 0 auto; background: #fff;
|
|
283
|
+
border-radius: 8px; box-shadow: var(--ke-shadow); padding: 32px;
|
|
284
|
+
min-height: var(--ke-min-height, 320px);
|
|
285
|
+
}
|
|
286
|
+
/* 宽屏:版心随容器生长,两侧留白恒定为 --ke-paper-gap,不再随屏宽放大 */
|
|
287
|
+
.ke-paper.ke-is-fluid {
|
|
288
|
+
width: min(100%, max(calc(var(--ke-paper) + 64px), calc(100% - var(--ke-paper-gap) * 2)));
|
|
289
|
+
max-width: var(--ke-paper-max, none);
|
|
290
|
+
}
|
|
291
|
+
.ke-content { outline: none; font-size: 17px; line-height: 1.75; color: var(--ke-text); word-break: break-word; }
|
|
292
|
+
.ke-content:empty::before,
|
|
293
|
+
.ke-content[data-placeholder].ke-is-empty::before {
|
|
294
|
+
content: attr(data-placeholder); color: #b8bec7; pointer-events: none;
|
|
295
|
+
}
|
|
296
|
+
.ke-content > *:first-child { margin-top: 0; }
|
|
297
|
+
.ke-content p { margin: 0 0 16px; }
|
|
298
|
+
.ke-content h1, .ke-content h2, .ke-content h3, .ke-content h4, .ke-content h5, .ke-content h6 {
|
|
299
|
+
margin: 24px 0 12px; font-weight: 600; line-height: 1.4; color: #1f2329;
|
|
300
|
+
}
|
|
301
|
+
.ke-content h1 { font-size: 22px; } .ke-content h2 { font-size: 20px; } .ke-content h3 { font-size: 18px; }
|
|
302
|
+
.ke-content h4, .ke-content h5, .ke-content h6 { font-size: 17px; }
|
|
303
|
+
.ke-content ul, .ke-content ol { margin: 0 0 16px; padding-left: 26px; }
|
|
304
|
+
.ke-content li { margin: 4px 0; }
|
|
305
|
+
.ke-content blockquote {
|
|
306
|
+
margin: 0 0 16px; padding: 2px 16px; border-left: 3px solid var(--ke-primary);
|
|
307
|
+
background: #f8f9fa; color: #6b7280; border-radius: 0 4px 4px 0;
|
|
308
|
+
}
|
|
309
|
+
.ke-content a { color: #576b95; text-decoration: none; border-bottom: 1px solid rgba(87,107,149,.35); }
|
|
310
|
+
.ke-content hr { border: 0; border-top: 1px solid var(--ke-line); margin: 24px 0; }
|
|
311
|
+
.ke-content code { background: #f2f3f5; border-radius: 4px; padding: 2px 6px; font-size: 14px; font-family: 'SFMono-Regular', Consolas, Menlo, monospace; color: #c7254e; }
|
|
312
|
+
.ke-content pre {
|
|
313
|
+
background: #282c34; color: #e6e6e6; padding: 14px 16px; border-radius: 8px; overflow-x: auto;
|
|
314
|
+
font-size: 13px; line-height: 1.7; margin: 0 0 16px; font-family: 'SFMono-Regular', Consolas, Menlo, monospace;
|
|
315
|
+
}
|
|
316
|
+
.ke-content pre code { background: none; color: inherit; padding: 0; font-size: inherit; }
|
|
317
|
+
.ke-content img, .ke-content video { max-width: 100%; height: auto; display: block; }
|
|
318
|
+
.ke-content figure { margin: 0 0 16px; }
|
|
319
|
+
.ke-content figcaption { font-size: 13px; color: var(--ke-muted); text-align: center; margin-top: 6px; }
|
|
320
|
+
.ke-content table { border-collapse: collapse; width: 100%; margin: 0 0 16px; font-size: 15px; }
|
|
321
|
+
.ke-content th, .ke-content td { border: 1px solid #dfe2e6; padding: 8px 10px; min-width: 40px; }
|
|
322
|
+
.ke-content th { background: #f6f7f9; font-weight: 600; }
|
|
323
|
+
.ke-content section { margin: 0 0 16px; }
|
|
324
|
+
.ke-content .ke-is-selected-media { outline: 2px solid var(--ke-primary); outline-offset: 2px; border-radius: 4px; }
|
|
325
|
+
|
|
326
|
+
/* 上传中的媒体占位 */
|
|
327
|
+
.ke-media-box { position: relative; margin: 0 0 16px; }
|
|
328
|
+
.ke-media-holder {
|
|
329
|
+
border: 1px dashed #cdd3da; border-radius: 8px; background: #fafbfc; color: var(--ke-muted);
|
|
330
|
+
display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 8px;
|
|
331
|
+
min-height: 120px; padding: 16px; font-size: 13px; text-align: center;
|
|
332
|
+
}
|
|
333
|
+
.ke-media-holder img { max-width: 100%; max-height: 260px; border-radius: 6px; opacity: .9; }
|
|
334
|
+
.ke-media-name { max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
|
|
335
|
+
.ke-progress { width: 100%; height: 6px; border-radius: 3px; background: #eceef1; overflow: hidden; }
|
|
336
|
+
.ke-progress i { display: block; height: 100%; width: 0; background: var(--ke-primary); border-radius: 3px; transition: width .2s ease; }
|
|
337
|
+
.ke-media-meta { display: flex; align-items: center; gap: 10px; width: 100%; }
|
|
338
|
+
.ke-media-pct { color: var(--ke-primary); font-weight: 600; min-width: 40px; text-align: right; }
|
|
339
|
+
.ke-media-error { color: #e53e3e; }
|
|
340
|
+
.ke-media-retry { border: 1px solid var(--ke-line); background: #fff; border-radius: 6px; padding: 4px 12px; cursor: pointer; font-size: 12px; color: #4b5158; }
|
|
341
|
+
.ke-media-retry:hover { border-color: var(--ke-primary); color: var(--ke-primary); }
|
|
342
|
+
.ke-media-cancel { border: 0; background: transparent; color: var(--ke-muted); cursor: pointer; font-size: 12px; }
|
|
343
|
+
.ke-spinner { width: 18px; height: 18px; border: 2px solid #dfe3e8; border-top-color: var(--ke-primary); border-radius: 50%; animation: ke-spin .8s linear infinite; }
|
|
344
|
+
@keyframes ke-spin { to { transform: rotate(360deg); } }
|
|
345
|
+
|
|
346
|
+
/* 视频卡片 */
|
|
347
|
+
.ke-video-card {
|
|
348
|
+
position: relative; border: 1px solid var(--ke-line); border-radius: 10px; background: #0f1115;
|
|
349
|
+
color: #e6e8eb; padding: 12px 14px; margin: 0 0 16px; display: flex; align-items: center; gap: 12px;
|
|
350
|
+
}
|
|
351
|
+
.ke-video-card video { width: 100%; border-radius: 6px; display: block; }
|
|
352
|
+
.ke-video-card .ke-video-body { flex: 1; min-width: 0; }
|
|
353
|
+
.ke-video-head { display: flex; align-items: center; gap: 8px; font-size: 13px; }
|
|
354
|
+
.ke-video-size { color: var(--ke-muted); font-size: 12px; }
|
|
355
|
+
.ke-video-remove { border: 0; background: transparent; color: #9aa2ad; cursor: pointer; padding: 4px; border-radius: 6px; }
|
|
356
|
+
.ke-video-remove:hover { color: #e53e3e; background: rgba(255,255,255,.06); }
|
|
357
|
+
.ke-inline-video video { border-radius: 8px; }
|
|
358
|
+
|
|
359
|
+
/* ---------------- Status bar ---------------- */
|
|
360
|
+
.ke-status {
|
|
361
|
+
display: flex; align-items: center; gap: 12px; padding: 6px 12px;
|
|
362
|
+
background: #fff; border-top: 1px solid var(--ke-line); font-size: 12px; color: var(--ke-muted);
|
|
363
|
+
}
|
|
364
|
+
.ke-status b { color: var(--ke-primary); font-weight: 600; }
|
|
365
|
+
.ke-status-hint { margin-left: 8px; }
|
|
366
|
+
.ke-status-tail { margin-left: auto; display: flex; align-items: center; gap: 4px; }
|
|
367
|
+
.ke-chip { display: inline-flex; align-items: center; gap: 4px; height: 24px; padding: 0 8px; border-radius: 12px; background: #f2f3f5; color: #4b5158; font-size: 12px; }
|
|
368
|
+
.ke-chip[hidden] { display: none; }
|
|
369
|
+
.ke-chip.ke-is-busy { background: var(--ke-primary-weak); color: var(--ke-primary); }
|
|
370
|
+
|
|
371
|
+
/* ---------------- Source mode ---------------- */
|
|
372
|
+
.ke-source { display: flex; flex-direction: column; flex: 1; min-height: 0; background: #1b1f27; }
|
|
373
|
+
.ke-source[hidden] { display: none; }
|
|
374
|
+
.ke-source-bar { display: flex; align-items: center; gap: 8px; padding: 8px 12px; background: #232833; color: #aeb6c2; font-size: 12px; }
|
|
375
|
+
.ke-source-title { font-weight: 600; color: #dfe4ea; }
|
|
376
|
+
.ke-source-bar .ke-btn { color: #aeb6c2; }
|
|
377
|
+
.ke-source-bar .ke-btn:hover { background: rgba(255,255,255,.08); color: #fff; }
|
|
378
|
+
.ke-source-tail { margin-left: auto; display: flex; gap: 8px; align-items: center; }
|
|
379
|
+
.ke-source-code {
|
|
380
|
+
flex: 1; min-height: 240px; margin: 0; padding: 16px 18px; overflow: auto;
|
|
381
|
+
color: #e6edf3; background: #1b1f27; font-size: 12.5px; line-height: 1.7; tab-size: 2;
|
|
382
|
+
font-family: 'SFMono-Regular', Consolas, Menlo, Monaco, monospace; white-space: pre-wrap;
|
|
383
|
+
word-break: break-all; outline: none; caret-color: #4ade80;
|
|
384
|
+
}
|
|
385
|
+
.ke-source-code[data-k-tag] { }
|
|
386
|
+
.ke-source-tip { color: #7d8794; }
|
|
387
|
+
.ke-source-actions button { height: 28px; padding: 0 12px; border-radius: 6px; border: 1px solid #39424f; background: transparent; color: #cfd6de; font-size: 12px; cursor: pointer; }
|
|
388
|
+
.ke-source-actions button:hover { border-color: var(--ke-primary); color: #fff; }
|
|
389
|
+
.ke-source-actions .ke-apply { background: var(--ke-primary); border-color: var(--ke-primary); color: #fff; }
|
|
390
|
+
|
|
391
|
+
/* ---------------- Bubble (图片/视频工具条) ---------------- */
|
|
392
|
+
.ke-bubble {
|
|
393
|
+
position: absolute; z-index: 30; display: flex; align-items: center; gap: 2px; padding: 4px;
|
|
394
|
+
background: rgba(28, 32, 38, .94); border-radius: 8px; box-shadow: 0 6px 20px rgba(0,0,0,.22);
|
|
395
|
+
color: #fff; transform: translate(-50%, -100%); white-space: nowrap;
|
|
396
|
+
}
|
|
397
|
+
.ke-bubble.ke-is-below { transform: translate(-50%, 0); }
|
|
398
|
+
.ke-bubble[hidden] { display: none; }
|
|
399
|
+
.ke-bubble button { height: 28px; min-width: 28px; padding: 0 8px; border: 0; border-radius: 6px; background: transparent; color: #e6e8eb; cursor: pointer; font-size: 12px; display: inline-flex; align-items: center; gap: 4px; }
|
|
400
|
+
.ke-bubble button:hover { background: rgba(255,255,255,.14); }
|
|
401
|
+
.ke-bubble button.ke-is-active { background: var(--ke-primary); color: #fff; }
|
|
402
|
+
.ke-bubble .ke-sep { width: 1px; height: 16px; background: rgba(255,255,255,.18); margin: 0 3px; }
|
|
403
|
+
|
|
404
|
+
/* ---------------- 图片缩放把手(鼠标拖动调大小) ---------------- */
|
|
405
|
+
.ke-img-resize {
|
|
406
|
+
position: absolute; z-index: 31; width: 18px; height: 18px; border-radius: 5px;
|
|
407
|
+
background: #fff; border: 2px solid var(--ke-primary); color: var(--ke-primary);
|
|
408
|
+
cursor: nwse-resize; box-shadow: 0 1px 5px rgba(0,0,0,.25);
|
|
409
|
+
display: flex; align-items: center; justify-content: center;
|
|
410
|
+
touch-action: none; transition: transform .12s ease, background .12s ease, color .12s ease;
|
|
411
|
+
}
|
|
412
|
+
.ke-img-resize svg { width: 10px; height: 10px; display: block; }
|
|
413
|
+
.ke-img-resize:hover { transform: scale(1.12); background: var(--ke-primary); color: #fff; }
|
|
414
|
+
.ke-img-resize[hidden] { display: none; }
|
|
415
|
+
.ke-img-resize-tip {
|
|
416
|
+
position: absolute; z-index: 32; transform: translate(-50%, -100%);
|
|
417
|
+
background: rgba(28,32,38,.9); color: #fff; font-size: 12px; line-height: 1;
|
|
418
|
+
padding: 5px 8px; border-radius: 6px; pointer-events: none; white-space: nowrap;
|
|
419
|
+
}
|
|
420
|
+
.ke-img-resize-tip[hidden] { display: none; }
|
|
421
|
+
|
|
422
|
+
/* ---------------- Drop zone / Toast / Lightbox ---------------- */
|
|
423
|
+
.ke-dropzone {
|
|
424
|
+
position: absolute; inset: 0; z-index: 20; display: none; align-items: center; justify-content: center;
|
|
425
|
+
background: rgba(7, 193, 96, .08); backdrop-filter: blur(1px); border: 2px dashed var(--ke-primary);
|
|
426
|
+
border-radius: var(--ke-radius); color: var(--ke-primary); font-size: 15px; font-weight: 600; pointer-events: none;
|
|
427
|
+
}
|
|
428
|
+
.ke-is-dragover .ke-dropzone { display: flex; }
|
|
429
|
+
.ke-toasts { position: fixed; top: 24px; left: 50%; transform: translateX(-50%); z-index: 10000; display: flex; flex-direction: column; gap: 8px; align-items: center; }
|
|
430
|
+
.ke-toast {
|
|
431
|
+
padding: 8px 16px; border-radius: 8px; background: rgba(28,32,38,.92); color: #fff; font-size: 13px;
|
|
432
|
+
box-shadow: 0 6px 20px rgba(0,0,0,.18); animation: ke-in .18s ease;
|
|
433
|
+
}
|
|
434
|
+
.ke-toast.ke-is-error { background: rgba(229, 62, 62, .95); }
|
|
435
|
+
.ke-toast.ke-is-warn { background: rgba(237, 137, 27, .95); }
|
|
436
|
+
@keyframes ke-in { from { opacity: 0; transform: translateY(-6px); } }
|
|
437
|
+
.ke-lightbox {
|
|
438
|
+
position: fixed; inset: 0; z-index: 10001; background: rgba(0,0,0,.86); display: flex;
|
|
439
|
+
align-items: center; justify-content: center; cursor: zoom-out; animation: ke-in .18s ease;
|
|
440
|
+
}
|
|
441
|
+
.ke-lightbox img { max-width: 92vw; max-height: 92vh; border-radius: 4px; }
|
|
442
|
+
.ke-lightbox-close { position: absolute; top: 18px; right: 22px; color: #fff; background: transparent; border: 0; cursor: pointer; }
|
|
443
|
+
|
|
444
|
+
/* ---------------- Preview overlay ---------------- */
|
|
445
|
+
.ke-preview { position: absolute; inset: 0; z-index: 25; background: #f2f3f5; display: flex; flex-direction: column; }
|
|
446
|
+
.ke-preview[hidden] { display: none; }
|
|
447
|
+
.ke-preview-bar { display: flex; align-items: center; gap: 8px; padding: 8px 12px; background: #fff; border-bottom: 1px solid var(--ke-line); font-size: 12px; color: var(--ke-muted); }
|
|
448
|
+
.ke-preview-body { flex: 1; overflow: auto; padding: 20px; }
|
|
449
|
+
.ke-preview-frame { margin: 0 auto; background: #fff; border-radius: 10px; box-shadow: var(--ke-shadow); padding: 22px 20px; transition: width .2s ease; }
|
|
450
|
+
.ke-preview-frame .ke-content { font-size: 17px; line-height: 1.75; color: var(--ke-text); }
|
|
451
|
+
.ke-preview-frame { min-height: 120px; }
|
|
452
|
+
|
|
453
|
+
/* ---------------- ReadOnly / disabled ---------------- */
|
|
454
|
+
.ke-is-readonly .ke-tb .ke-btn, .ke-is-readonly .ke-tb .ke-select { pointer-events: none; opacity: .45; }
|
|
455
|
+
.ke-is-readonly .ke-content { cursor: default; }
|
|
456
|
+
/* 源码模式下正文类按钮置灰,仅保留源码/预览/全屏 */
|
|
457
|
+
.ke-is-source .ke-tb .ke-btn:not([data-k-item="source"]):not([data-k-item="preview"]):not([data-k-item="fullscreen"]),
|
|
458
|
+
.ke-is-source .ke-tb .ke-btn-label { pointer-events: none; opacity: .35; }
|
|
459
|
+
.ke-is-source .ke-tb .ke-tb-sep { opacity: .4; }
|
|
460
|
+
.ke-btn[data-k-item="source"].ke-is-active { background: var(--ke-primary); color: #fff; }
|
|
461
|
+
.ke-btn[data-k-item="source"].ke-is-active:hover { background: #06b35a; }
|
|
462
|
+
|
|
463
|
+
/* ---------------- Mobile ---------------- */
|
|
464
|
+
@media (max-width: 640px) {
|
|
465
|
+
.ke-tb { padding: 4px 6px; gap: 0; }
|
|
466
|
+
.ke-btn, .ke-select { height: 28px; min-width: 28px; }
|
|
467
|
+
.ke-tb-sep { margin: 0 2px; }
|
|
468
|
+
.ke-scroll { padding: 12px 8px 18px; }
|
|
469
|
+
.ke-paper { padding: 16px 14px; border-radius: 6px; }
|
|
470
|
+
.ke-content { font-size: 16px; }
|
|
471
|
+
.ke-status { padding: 5px 8px; gap: 6px; }
|
|
472
|
+
.ke-status-hint { display: none; }
|
|
473
|
+
}
|
|
474
|
+
@media (prefers-reduced-motion: reduce) {
|
|
475
|
+
.ke * { animation-duration: .01ms !important; transition-duration: .01ms !important; }
|
|
476
|
+
}
|
|
477
|
+
`;let ve=!1;function it(){if(ve||typeof document>"u")return;const o=document.createElement("style");o.setAttribute("data-keditor-style",""),o.textContent=D,document.head.appendChild(o),ve=!0}const ie=(o="k")=>`${o}${Date.now().toString(36)}${Math.random().toString(36).slice(2,7)}`;function ot(o,e=300){let t=null;const i=(...n)=>{clearTimeout(t),t=setTimeout(()=>o(...n),e)};return i.cancel=()=>clearTimeout(t),i.flush=(...n)=>{clearTimeout(t),o(...n)},i}const I=(o,e,t)=>Math.min(Math.max(o,e),t);function R(o){if(!o&&o!==0)return"-";const e=["B","KB","MB","GB"];let t=0,i=o;for(;i>=1024&&t<e.length-1;)i/=1024,t+=1;return`${i.toFixed(i>=10||t===0?0:1)}${e[t]}`}function l(o,e={},t=[]){let i="div",n="";const r=String(o).split(".");i=r[0]||"div",n=r.slice(1).join(" ");const s=document.createElement(i);n&&(s.className=n);for(const[c,d]of Object.entries(e||{}))d==null||d===!1||(c==="class"?s.className=`${s.className} ${d}`.trim():c==="style"&&typeof d=="object"?Object.assign(s.style,d):c==="html"?s.innerHTML=d:c==="text"?s.textContent=d:c==="dataset"?Object.assign(s.dataset,d):c.startsWith("on")&&typeof d=="function"?s.addEventListener(c.slice(2).toLowerCase(),d):s.setAttribute(c,d===!0?"":String(d)));const a=Array.isArray(t)?t:[t];for(const c of a)c==null||c===!1||s.appendChild(typeof c=="string"||typeof c=="number"?document.createTextNode(String(c)):c);return s}function oe(o){if(!o)return"left";const e=o.style.marginLeft,t=o.style.marginRight;return e==="auto"&&t==="auto"?"center":e==="auto"?"right":"left"}function ne(o,e){o&&(o.style.maxWidth="100%",e==="center"?(o.style.marginLeft="auto",o.style.marginRight="auto"):e==="right"?(o.style.marginLeft="auto",o.style.marginRight="0"):(o.style.marginLeft="0",o.style.marginRight="auto"))}const T=o=>`<svg class="ke-ico" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.8" stroke-linecap="round" stroke-linejoin="round"><path d="${o}"/></svg>`,nt={undo:'<svg class="ke-ico" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.8" stroke-linecap="round" stroke-linejoin="round"><path d="M9 14 4 9l5-5"/><path d="M4 9h10a5 5 0 0 1 0 10h-3"/></svg>',redo:'<svg class="ke-ico" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.8" stroke-linecap="round" stroke-linejoin="round"><path d="m15 14 5-5-5-5"/><path d="M20 9H10a5 5 0 0 0 0 10h3"/></svg>',bold:'<svg class="ke-ico" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M7 5h6.5a3.5 3.5 0 0 1 0 7H7zM7 12h7.5a3.5 3.5 0 0 1 0 7H7z"/></svg>',italic:'<svg class="ke-ico" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.8" stroke-linecap="round"><path d="M15 5h-5M14 19H9M14.5 5 10 19"/></svg>',underline:'<svg class="ke-ico" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.8" stroke-linecap="round"><path d="M7 4v8a5 5 0 0 0 10 0V4M5 20h14"/></svg>',strike:'<svg class="ke-ico" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.8" stroke-linecap="round"><path d="M4 12h16M16.5 7A4.5 4.5 0 0 0 12 5c-2.2 0-3.6 1-4.2 2.4M7.5 17A4.5 4.5 0 0 0 12 19c2.3 0 3.9-1.1 4.4-2.8"/></svg>',foreColor:'<svg class="ke-ico" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.8" stroke-linecap="round" stroke-linejoin="round"><path d="M5 17 9.5 5 14 17M6.8 13h5.9"/><rect x="4" y="19.5" width="11" height="2.2" rx="1" fill="currentColor" stroke="none"/></svg>',backColor:'<svg class="ke-ico" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.8" stroke-linecap="round" stroke-linejoin="round"><path d="M8 20 4 16l7.5-7.5a2 2 0 0 1 2.8 0l3.2 3.2a2 2 0 0 1 0 2.8L13 20z" /><path d="M10 8.5 15.5 14"/></svg>',alignLeft:T("M4 6h16M4 12h10M4 18h13"),alignCenter:T("M4 6h16M7 12h10M5.5 18h13"),alignRight:T("M4 6h16M10 12h10M7 18h13"),alignJustify:T("M4 6h16M4 12h16M4 18h16"),ul:'<svg class="ke-ico" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.8" stroke-linecap="round"><path d="M8 6h12M8 12h12M8 18h12"/><circle cx="4.5" cy="6" r="1.2" fill="currentColor" stroke="none"/><circle cx="4.5" cy="12" r="1.2" fill="currentColor" stroke="none"/><circle cx="4.5" cy="18" r="1.2" fill="currentColor" stroke="none"/></svg>',ol:'<svg class="ke-ico" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.8" stroke-linecap="round"><path d="M9 6h11M9 12h11M9 18h11"/><text x="1.6" y="8.2" font-size="7" font-family="inherit" fill="currentColor" stroke="none">1</text><text x="1.6" y="14.4" font-size="7" font-family="inherit" fill="currentColor" stroke="none">2</text><text x="1.6" y="20.6" font-size="7" font-family="inherit" fill="currentColor" stroke="none">3</text></svg>',quote:'<svg class="ke-ico" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.8" stroke-linecap="round"><path d="M5 5v14"/><path d="M10 8h9M10 12h9M10 16h5"/></svg>',link:'<svg class="ke-ico" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.8" stroke-linecap="round" stroke-linejoin="round"><path d="M10 13a5 5 0 0 0 7.54.54l3-3a5 5 0 0 0-7.07-7.07l-1.72 1.71"/><path d="M14 11a5 5 0 0 0-7.54-.54l-3 3a5 5 0 0 0 7.07 7.07l1.71-1.71"/></svg>',unlink:'<svg class="ke-ico" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.8" stroke-linecap="round"><path d="M9 14 4.5 18.5M14.5 5.5 19 10"/><path d="M10.5 13.5a4 4 0 0 0 5.6 0l2.4-2.4a4 4 0 0 0-5.6-5.6"/><path d="M13.5 10.5a4 4 0 0 0-5.6 0l-2.4 2.4a4 4 0 0 0 5.6 5.6"/><path d="m3 3 18 18"/></svg>',image:'<svg class="ke-ico" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.8" stroke-linecap="round" stroke-linejoin="round"><rect x="3" y="4.5" width="18" height="15" rx="2.5"/><circle cx="8.5" cy="10" r="1.6"/><path d="m4 18 5-5 3.5 3.5L17 12l3 3"/></svg>',video:'<svg class="ke-ico" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.8" stroke-linecap="round" stroke-linejoin="round"><rect x="3" y="5" width="18" height="14" rx="2.5"/><path d="m10.5 9 4.5 3-4.5 3z"/></svg>',table:'<svg class="ke-ico" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.8" stroke-linecap="round" stroke-linejoin="round"><rect x="3" y="5" width="18" height="14" rx="2"/><path d="M3 10h18M3 15h18M9 5v14M15 5v14"/></svg>',code:T("m9 7-5 5 5 5M15 7l5 5-5 5"),hr:'<svg class="ke-ico" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.8" stroke-linecap="round"><path d="M4 12h16" stroke-width="2.4"/><path d="M6 7h12M6 17h12" opacity=".45"/></svg>',clear:'<svg class="ke-ico" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.8" stroke-linecap="round" stroke-linejoin="round"><path d="M8 20 4 16l8-8 4 4-8 8z" /><path d="M12 8 16 4l4 4-4 4M6 20h12"/></svg>',source:T("m8 7-5 5 5 5M16 7l5 5-5 5M13.5 4l-3 16"),preview:'<svg class="ke-ico" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.8" stroke-linecap="round" stroke-linejoin="round"><path d="M2.5 12S6 5.5 12 5.5 21.5 12 21.5 12 18 18.5 12 18.5 2.5 12 2.5 12Z"/><circle cx="12" cy="12" r="3"/></svg>',trash:'<svg class="ke-ico" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.8" stroke-linecap="round" stroke-linejoin="round"><path d="M4 7h16M9.5 7V4.5h5V7M6.5 7l1 13h9l1-13"/></svg>',close:T("m6 6 12 12M18 6 6 18"),copy:'<svg class="ke-ico" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.8" stroke-linecap="round" stroke-linejoin="round"><rect x="9" y="9" width="11" height="11" rx="2"/><path d="M15 5H6a2 2 0 0 0-2 2v9"/></svg>',format:T("M4 6h10M4 12h16M4 18h7M18 4v6m0 0 2.5-2.5M18 10l-2.5-2.5"),check:T("m5 13 4 4L19 7"),checkLight:'<svg class="ke-ico" viewBox="0 0 24 24" fill="none" stroke="#fff" stroke-width="2.6" stroke-linecap="round" stroke-linejoin="round"><path d="m5 13 4 4L19 7"/></svg>',plus:T("M12 5v14M5 12h14"),minus:T("M5 12h14"),upload:'<svg class="ke-ico" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.8" stroke-linecap="round" stroke-linejoin="round"><path d="M12 16V4m0 0-4 4m4-4 4 4"/><path d="M4 15v3a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2v-3"/></svg>',retry:'<svg class="ke-ico" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.8" stroke-linecap="round" stroke-linejoin="round"><path d="M20 12a8 8 0 1 1-3-6.2"/><path d="M20 4v5h-5"/></svg>',rounded:'<svg class="ke-ico" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.8" stroke-linecap="round" stroke-linejoin="round"><rect x="4" y="4" width="16" height="16" rx="6"/></svg>',expand:'<svg class="ke-ico" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.8" stroke-linecap="round" stroke-linejoin="round"><path d="M4 9V4h5M20 9V4h-5M4 15v5h5M20 15v5h-5"/></svg>',compress:'<svg class="ke-ico" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.8" stroke-linecap="round" stroke-linejoin="round"><path d="M9 4v5H4M15 4v5h5M9 20v-5H4M15 20v-5h5"/></svg>'};function M(o){return nt[o]||""}const re=[["#07c160","微信绿"],["#2f6fed","科技蓝"],["#7c3aed","极光紫"],["#d53880","品红"],["#e53e3e","中国红"],["#ed8936","暮橙"],["#f6c344","明黄"],["#0f766e","松石绿"]],rt=[["#1f2329","墨黑"],["#6b7280","深灰"],["#b8bec7","浅灰"],["#f2f3f5","云灰"],["#ffffff","纯白"],["#c00000","深红"],["#ff0000","正红"],["#ffc000","琥珀"],["#ffff00","柠黄"],["#00b050","草绿"],["#00b0f0","天蓝"],["#0070c0","海蓝"],["#7030a0","葡萄紫"],["#ff69b4","桃花粉"]],we=[["#fef08a","柠檬底"],["#dcfce7","薄荷底"],["#e0f2fe","天空底"],["#ede9fe","薰衣底"],["#ffe4e6","樱花底"],["#fff4e6","奶茶底"],["#f2f3f5","纸张灰"],["#1f2329","夜墨"]],se=/^#([0-9a-f]{3}|[0-9a-f]{6})$/i;class st{constructor(e){this.root=e,this.el=l("div.ke-pop",{hidden:!0}),this.anchor=null,this.onClose=null,e.appendChild(this.el),this.el.addEventListener("mousedown",t=>{/^(input|textarea|select)$/i.test(t.target.tagName)||t.preventDefault()}),this.docHandler=t=>{var i,n;this.el.hidden||this.el.contains(t.target)||(n=(i=t.target).closest)!=null&&n.call(i,".ke-btn[data-k-pop]")||this.close()},document.addEventListener("mousedown",this.docHandler,!0),this.keyHandler=t=>{t.key==="Escape"&&this.close()},document.addEventListener("keydown",this.keyHandler)}open(e,t,{align:i="start",onClose:n}={}){var u;this.el.textContent="";const r=t(k=>this.el.appendChild(k));r&&this.el.appendChild(r),this.el.hidden=!1,this.anchor=e,this.onClose=n;const s=this.root.getBoundingClientRect(),a=e.getBoundingClientRect(),c=this.el.getBoundingClientRect();let d=a.left-s.left;i==="center"&&(d=a.left-s.left+a.width/2-c.width/2),i==="end"&&(d=a.right-s.left-c.width),d=Math.max(8,Math.min(d,s.width-c.width-8));let h=a.top-s.top+a.height+8;h+c.height>s.height-8&&a.top-s.top-c.height-8>0&&(h=a.top-s.top-c.height-8),this.el.style.left=`${d}px`,this.el.style.top=`${h}px`,this.el.classList.remove("ke-pop-in"),this.el.offsetWidth,this.el.classList.add("ke-pop-in");const p=[...this.el.querySelectorAll("[data-k-autofocus]")].find(k=>k.offsetParent!==null);(u=p==null?void 0:p.focus)==null||u.call(p)}close(){if(this.el.hidden)return;this.el.hidden=!0,this.el.classList.remove("ke-pop-in"),this.el.textContent="",this.anchor=null;const e=this.onClose;this.onClose=null,e==null||e()}get isOpen(){return!this.el.hidden}destroy(){document.removeEventListener("mousedown",this.docHandler,!0),document.removeEventListener("keydown",this.keyHandler),this.el.remove()}}function O(o,e){const t=l("div.ke-panel-head",{},[l("span.ke-panel-title",{text:o})]);return e&&t.appendChild(e),l("div.ke-panel",{},[t])}function q(o){return l("div.ke-panel-sect",{text:o})}function Ce(){return l("div.ke-panel-divider")}function at({title:o,kind:e,colors:t,value:i,recents:n=[],onPick:r,onClear:s}){const a=e==="bg",c=l("button.ke-panel-reset",{type:"button",title:a?"清除高亮":"恢复默认文字色",text:a?"清除高亮":"恢复默认",onclick:()=>s?s():r(null)}),d=O(o,c);return n.length&&(d.appendChild(q("最近使用")),d.appendChild(U(n.slice(0,8),i,r))),a?(d.appendChild(q("推荐底色")),d.appendChild(U(we.map(([h,p])=>[h,p]),i,r)),d.appendChild(q("主题颜色")),d.appendChild(U(re,i,r))):(d.appendChild(q("主题颜色")),d.appendChild(U(re,i,r)),d.appendChild(q("标准颜色")),d.appendChild(U(rt,i,r))),d.appendChild(Ce()),d.appendChild(lt(i,r)),d}function U(o,e,t){const i=l("div.ke-sw-grid");return o.forEach(([n,r])=>{const s=l("button.ke-sw",{type:"button",title:`${r} ${n}`,"aria-label":r,style:{background:n}});e&&se.test(e)&&n.toLowerCase()===String(e).toLowerCase()&&(s.classList.add("ke-is-active"),s.appendChild(l("span.ke-sw-check",{html:M("checkLight")}))),s.addEventListener("click",()=>t(n)),i.appendChild(s)}),i}function lt(o,e){const t=se.test(o||"")?o:"#07c160",i=l("input.ke-sw-picker",{type:"color",value:t,title:"自定义颜色"}),n=l("input.ke-input.ke-sw-hex",{type:"text",value:t,placeholder:"#000000",maxlength:7}),r=l("button.ke-btn-primary",{type:"button",text:"应用"}),s=()=>{const a=n.value.trim(),c=a.startsWith("#")?a:`#${a}`;if(!se.test(c)){n.classList.add("ke-is-invalid");return}n.classList.remove("ke-is-invalid"),e(c)};return i.addEventListener("input",()=>{n.value=i.value}),i.addEventListener("change",s),r.addEventListener("click",s),n.addEventListener("keydown",a=>{a.key==="Enter"&&(a.preventDefault(),s())}),l("div.ke-panel-foot",{},[i,n,r])}function ct(o,{value:e,onPick:t}){const i=O("段落样式");return i.classList.add("ke-panel-wide"),o.forEach(n=>{const r=l("button.ke-hd-row",{type:"button",dataset:{kValue:n.value},onclick:()=>t(n.value)},[l("span.ke-hd-sample",{class:n.sampleClass||"",text:n.sample||n.label}),l("span.ke-hd-meta",{},[l("span.ke-hd-label",{text:n.label}),l("span.ke-hd-desc",{text:n.desc})])]);n.value===e&&r.classList.add("ke-is-active"),i.appendChild(r)}),i}function dt(o,{value:e,onPick:t}){const i=O("字号",l("span.ke-panel-note",{text:e?`${e}px`:"默认 17px"}));i.classList.add("ke-panel-wide");const n=l("div.ke-size-grid");return o.forEach(r=>{const s=l("button.ke-size-cell",{type:"button",text:String(r),onclick:()=>t(r)});s.style.fontSize=`${Math.min(20,10+r/6)}px`,Number(e)===r&&s.classList.add("ke-is-active"),n.appendChild(s)}),i.appendChild(n),i.appendChild(Ce()),i.appendChild(l("div.ke-panel-hint",{text:"仅作用于选中的文字;未选中时对新输入的文字生效"})),i}re.map(o=>o[0]),we.map(o=>o[0]);function ht(o,{cols:e=10,rows:t=8}={}){const i=O("插入表格",l("span.ke-panel-note",{text:"最大 10×8"})),n=l("div.ke-table-grid",{style:{gridTemplateColumns:`repeat(${e}, 18px)`}}),r=[];for(let c=0;c<t;c+=1)for(let d=0;d<e;d+=1){const h=l("span.ke-table-cell");h.dataset.r=String(c),h.dataset.c=String(d),r.push(h),n.appendChild(h)}i.appendChild(n);const s=l("div.ke-panel-hint",{text:"1 列 × 1 行"});i.appendChild(s);const a=(c,d)=>{r.forEach(h=>{const p=Number(h.dataset.r)<=c&&Number(h.dataset.c)<=d;h.classList.toggle("ke-is-on",p)}),s.textContent=`${d+1} 列 × ${c+1} 行`};return n.addEventListener("mousemove",c=>{const d=c.target.closest(".ke-table-cell");d&&a(Number(d.dataset.r),Number(d.dataset.c))}),n.addEventListener("click",c=>{const d=c.target.closest(".ke-table-cell");d&&o(Number(d.dataset.c)+1,Number(d.dataset.r)+1)}),n.addEventListener("mouseenter",()=>a(0,0)),a(0,0),i}function pt(o,{onFiles:e,onUrl:t,multiple:i,hint:n,maxText:r}){const s=o==="image",a=O(s?"插入图片":"插入视频");a.classList.add("ke-panel-wide","ke-panel-media");const c=l("div.ke-tab-body"),d=l("div.ke-tab-body",{hidden:!0}),h=l("div.ke-drop",{},[l("span.ke-drop-ico",{html:M("upload")}),l("div.ke-drop-title",{text:s?"点击选择图片,或拖拽到此处":"点击选择视频,或拖拽到此处"}),l("div.ke-drop-sub",{text:[r,n].filter(Boolean).join(" · ")})]),p=l("button.ke-btn-primary",{type:"button",text:s?"选择图片":"选择视频",onclick:()=>e(null)});h.addEventListener("click",()=>e(null)),h.addEventListener("dragover",m=>{m.preventDefault(),h.classList.add("ke-is-over")}),h.addEventListener("dragleave",()=>h.classList.remove("ke-is-over")),h.addEventListener("drop",m=>{var x,g;m.preventDefault(),h.classList.remove("ke-is-over"),(g=(x=m.dataTransfer)==null?void 0:x.files)!=null&&g.length&&e(m.dataTransfer.files)}),c.append(h,l("div.ke-panel-foot",{},[p,l("span.ke-panel-hint",{text:i?"可一次插入多张":"单文件大文件将自动分片上传"})]));const u=l("input.ke-input",{type:"url",placeholder:s?"https://example.com/photo.jpg":"https://example.com/video.mp4","data-k-autofocus":""}),k=l("input.ke-input",{type:"text",placeholder:s?"图片描述(可选,作为 alt)":"视频标题(可选)"}),f=l("div.ke-link-status",{text:"粘贴链接后自动校验可访问性"}),y=l("button.ke-btn-primary",{type:"button",text:"插入",disabled:!0});let v=null,C=0;const S=()=>{C+=1;const m=C;clearTimeout(v);const x=W(u.value);if(y.disabled=!x,f.className="ke-link-status",!x){f.textContent="请输入 http(s) 开头的链接";return}f.className="ke-link-status ke-is-checking",f.textContent="正在校验…",v=setTimeout(()=>ut(o,x,g=>{m===C&&(g?(f.className="ke-link-status ke-is-ok",f.textContent=s?"图片可访问 ✓":"视频可播放 ✓"):(f.className="ke-link-status ke-is-bad",f.textContent="未能自动加载(可能限制热链),不阻塞插入,发布前请自行确认"))}),350)};u.addEventListener("input",S),u.addEventListener("paste",()=>setTimeout(S,0));const A=()=>{const m=W(u.value);if(!m){u.classList.add("ke-is-invalid"),u.focus();return}t({url:m,name:k.value.trim()})};y.addEventListener("click",A),d.addEventListener("keydown",m=>{m.key==="Enter"&&(m.preventDefault(),A())}),d.append(l("div.ke-field",{},[l("span.ke-field-label",{text:"地址"}),u]),l("div.ke-field",{},[l("span.ke-field-label",{text:s?"描述":"标题"}),k]),f,l("div.ke-panel-foot",{},[y,l("span.ke-panel-hint",{text:"外链由源站提供,不占用上传配额"})]));const H=l("div.ke-tabs",{},[l("button.ke-tab",{type:"button",text:"本地上传"}),l("button.ke-tab",{type:"button",text:"网络链接"})]),E=m=>{[...H.children].forEach((x,g)=>x.classList.toggle("ke-is-active",g===m)),c.hidden=m!==0,d.hidden=m!==1,m===1&&u.focus()};return H.children[0].addEventListener("click",()=>E(0)),H.children[1].addEventListener("click",()=>E(1)),E(0),a.append(H,c,d),a}function ut(o,e,t){let i=!1;const n=r=>{i||(i=!0,t(r))};try{if(o==="image"){const r=new Image;r.onload=()=>n(!0),r.onerror=()=>n(!1),r.referrerPolicy="no-referrer",r.src=e}else{const r=document.createElement("video");r.preload="metadata",r.muted=!0,r.onloadedmetadata=()=>n(r.videoHeight>0||r.duration>0||Number.isFinite(r.duration)),r.onerror=()=>n(!1),r.src=e}}catch{n(!1)}}function ft({url:o="",text:e="",target:t=!1,onSubmit:i,onCancel:n,onRemove:r}){const s=l("input.ke-input",{type:"url",placeholder:"https://mp.weixin.qq.com/...",value:o,"data-k-autofocus":""}),a=l("input.ke-input",{type:"text",placeholder:"链接文字(留空使用 URL)",value:e}),c=l("input",{type:"checkbox"});c.checked=!!t;const d=O(o?"编辑链接":"插入链接");d.classList.add("ke-panel-wide");const h=l("div",{},[l("div.ke-field",{},[l("span.ke-field-label",{text:"文字"}),a]),l("div.ke-field",{},[l("span.ke-field-label",{text:"地址"}),s]),l("label.ke-check",{},[c,"新窗口打开"]),l("div.ke-panel-foot",{},[r?l("button.ke-btn-ghost",{type:"button",text:"移除链接",style:{marginRight:"auto",color:"#e53e3e"},onclick:r}):null,l("button.ke-btn-ghost",{type:"button",text:"取消",onclick:n}),l("button.ke-btn-primary",{type:"button",text:"确定",onclick:()=>p()})])]),p=()=>{const u=W(s.value);if(!u){s.classList.add("ke-is-invalid"),s.focus();return}i({url:u,text:a.value.trim(),target:c.checked})};return h.addEventListener("keydown",u=>{u.key==="Enter"&&(u.preventDefault(),p())}),d.appendChild(h),d}function mt(o){try{return new URL(o,window.location.href).host}catch{return String(o).slice(0,40)}}function kt({title:o,note:e,searchable:t,width:i,remote:n,value:r,load:s,reload:a,linkOf:c,onPick:d,emptyText:h}){const p=O(o);p.classList.add("ke-panel-wide","ke-panel-select"),i&&(p.style.width=`${Math.min(420,Math.max(200,Number(i)))}px`);const u=p.querySelector(".ke-panel-head"),k=l("span.ke-panel-note",{text:e||""});n&&u.appendChild(l("button.ke-panel-icon",{type:"button",title:"重新加载数据",html:M("retry"),onclick:()=>E(a||s,!0)})),u.appendChild(k);const f=l("div.ke-sel-body");p.appendChild(f);let y=[],v="",C=0;if(t){const m=l("input.ke-input.ke-sel-search",{type:"search",placeholder:"搜索…","data-k-autofocus":""});m.addEventListener("input",()=>{v=m.value.trim().toLowerCase(),A()}),p.insertBefore(m,f)}function S(m,x){if(f.textContent="",f.dataset.state=m,m==="loading"){for(let g=0;g<3;g+=1)f.appendChild(l("div.ke-sel-skel"));f.insertBefore(l("div.ke-sel-loading",{},[l("span.ke-spinner"),"数据加载中…"]),f.firstChild)}else m==="error"?f.appendChild(l("div.ke-sel-tip",{},[l("span.ke-sel-tip-text",{text:x||"数据加载失败"}),l("button.ke-btn-primary",{type:"button",text:"重试",onclick:()=>E(a||s,!0)})])):f.appendChild(l("div.ke-sel-tip",{},[l("span.ke-sel-tip-text",{text:x||h||"暂无数据"})]))}function A(){const m=v?y.filter(g=>`${g.label} ${g.desc} ${g.value} ${g.group}`.toLowerCase().includes(v)):y;if(k.textContent=e||(v?`${m.length} / ${y.length} 项`:`${y.length} 项`),f.textContent="",delete f.dataset.state,!m.length){S("empty",v?`没有匹配「${v}」的选项`:h||"暂无数据");return}let x=null;m.forEach(g=>{g.group&&g.group!==x&&(x=g.group,f.appendChild(l("div.ke-panel-sect",{text:x}))),f.appendChild(H(g))})}function H(m){const x=c?c(m):null,g=l("button.ke-sel-row",{type:"button",disabled:m.disabled||void 0,dataset:{kValue:m.value},title:m.disabled?"该项不可用":x&&x.mode==="open"?`打开 ${x.url}`:x?`插入链接:${x.url}`:m.title||"",onclick:()=>{m.disabled||d(m)}});return g.appendChild(l("span.ke-sel-main",{},[l("span.ke-sel-label",{text:m.label}),m.desc?l("span.ke-sel-desc",{text:m.desc}):null,x?l("span.ke-sel-link",{html:`${M("link")}<i>${mt(x.url)}</i>`}):null])),r&&String(r)===String(m.value)&&(g.classList.add("ke-is-active"),g.appendChild(l("span.ke-sel-check",{html:M("check")}))),x&&g.classList.add("ke-has-link"),g}function E(m,x){C+=1;const g=C;S("loading"),Promise.resolve().then(()=>m({force:x})).then($=>{g!==C||!p.isConnected||(y=Array.isArray($)?$:[],y.length?A():S("empty"))}).catch($=>{g!==C||!p.isConnected||S("error",$&&$.message?$.message:"数据加载失败")})}return E(s),p}function W(o){const e=String(o||"").trim();return e?/^(https?:|mailto:|tel:|#|\/)/i.test(e)?e:/^[\w-]+(\.[\w-]+)+/.test(e)?`https://${e}`:"":""}const Se=new Set(["p","div","section","blockquote","ul","ol","li","table","thead","tbody","tfoot","tr","td","th","figure","figcaption","pre","h1","h2","h3","h4","h5","h6","hr","video"]);function ae(o,{indent:e=" "}={}){if(!o)return"";const i=new DOMParser().parseFromString(`<div>${o}</div>`,"text/html").body.firstChild,n=[],r=(a,c)=>{const d=c.replace(/\s+/g," ").trim();if(!d)return;const h=n[n.length-1];h&&h.depth===a&&h.inlineRun?h.text+=` ${d}`:n.push({depth:a,text:e.repeat(a)+d,inlineRun:!0})},s=(a,c)=>{[...a.childNodes].forEach(h=>{if(h.nodeType===3){const f=h.textContent.trim();f&&r(c,f);return}if(h.nodeType!==1)return;const p=h.tagName.toLowerCase();if(!Se.has(p)){r(c,h.outerHTML);return}if(![...h.querySelectorAll("*")].some(f=>Se.has(f.tagName.toLowerCase()))||(p==="tr"||p==="figure"||p==="video")){n.push({depth:c,text:e.repeat(c)+gt(h.outerHTML),inlineRun:!1});return}n.push({depth:c,text:e.repeat(c)+bt(h),inlineRun:!1}),s(h,c+1),n.push({depth:c,text:e.repeat(c)+`</${p}>`,inlineRun:!1})})};return s(i,0),n.map(a=>a.text).join(`
|
|
478
|
+
`).replace(/\n{3,}/g,`
|
|
479
|
+
|
|
480
|
+
`)}function gt(o){return o.replace(/\n\s+/g," ").replace(/\s{2,}/g," ").trim()}function bt(o){const e=[...o.attributes].map(t=>`${t.name}="${(t.value||"").replace(/"/g,""")}"`);return`<${o.tagName.toLowerCase()}${e.length?` ${e.join(" ")}`:""}>`}class xt{constructor(e){this.editor=e,this.open=!1,this.el=l("div.ke-source",{hidden:!0},[l("div.ke-source-bar",{},[l("span.ke-source-title",{text:"HTML 源码"}),l("span.ke-source-tip",{text:"可直接编辑,点击「应用」或退出源码模式即生效"}),l("span.ke-source-tail",{},[l("button.ke-btn",{type:"button",title:"格式化",html:M("format")+"<span>格式化</span>",onclick:()=>this.format()}),l("button.ke-btn",{type:"button",title:"复制全部",html:M("copy")+"<span>复制</span>",onclick:()=>this.copy()}),l("button.ke-btn",{type:"button",title:"应用修改",html:M("check")+"<span>应用</span>",onclick:()=>this.apply()}),l("button.ke-btn",{type:"button",title:"退出源码模式",html:M("close"),onclick:()=>e.exitSource()})])]),(this.code=l("pre.ke-source-code",{contenteditable:"true",spellcheck:"false",autocapitalize:"off",autocomplete:"off",wrap:"off"}),this.code.addEventListener("keydown",t=>{t.key==="Tab"&&(t.preventDefault(),document.execCommand("insertText",!1," ")),(t.ctrlKey||t.metaKey)&&t.key.toLowerCase()==="s"&&(t.preventDefault(),this.apply()),t.stopPropagation()}),this.code)])}get value(){return this.code.textContent}set value(e){this.code.textContent=e,this.code.scrollTop=0}show(e){this.value=ae(e),this.el.hidden=!1,this.open=!0,this.editor.scrollEl.hidden=!0}hide(){this.el.hidden=!0,this.open=!1,this.editor.scrollEl.hidden=!1}format(){this.value=ae(this.value),this.editor.toast.show("已格式化")}async copy(){var t;const e=this.value;try{(t=navigator.clipboard)!=null&&t.writeText?await navigator.clipboard.writeText(e):(this.code.focus(),document.execCommand("selectAll"),document.execCommand("copy")),this.editor.toast.show("源码已复制到剪贴板")}catch{this.editor.toast.error("复制失败,请手动选择复制")}}apply({silent:e=!1}={}){const t=this.value;try{return this.editor.setContent(t,{sanitize:!0,silent:!1}),e||this.editor.toast.show("源码已应用"),!0}catch(i){return this.editor.toast.error(`源码解析失败:${i.message}`),!1}}destroy(){this.el.remove()}}const le=[{key:"mobile",label:"手机",width:375},{key:"pad",label:"平板",width:540},{key:"pc",label:"电脑",width:677}];class yt{constructor(e){this.editor=e,this.device="pc",this.el=l("div.ke-preview",{hidden:!0},[l("div.ke-preview-bar",{},[l("span",{text:"预览"}),l("span.ke-source-tip",{text:"仅用于查看排版效果,内容不可编辑"}),l("span.ke-status-tail",{},le.map(t=>l("button.ke-btn",{type:"button","data-k-device":t.key,text:t.label,onclick:()=>this.setDevice(t.key)})).concat([l("span.ke-tb-sep"),l("button.ke-btn",{type:"button",title:"关闭预览",html:M("close"),onclick:()=>e.closePreview()})]))]),(this.body=l("div.ke-preview-body",{},[l("div.ke-preview-frame",{style:{maxWidth:"677px"}},[l("div.ke-content.ke-preview-content")])]),this.frame=this.body.firstChild,this.content=this.frame.firstChild,this.body)])}setDevice(e){this.device=e;const t=le.find(i=>i.key===e)||le[2];this.frame.style.maxWidth=`${t.width}px`,this.frame.style.width=e==="mobile"?`${t.width}px`:"100%",this.el.querySelectorAll("[data-k-device]").forEach(i=>i.classList.toggle("ke-is-active",i.dataset.kDevice===e))}show(e){this.content.innerHTML=e,this.el.hidden=!1,this.setDevice(this.device)}hide(){this.el.hidden=!0,this.content.innerHTML=""}destroy(){this.el.remove()}}class vt{constructor(e=null){this.owner=e,this.el=null}show(e,t="",i=2600){if(typeof document>"u")return;this.el||(this.el=l("div.ke-toasts"),document.body.appendChild(this.el));const n=l(`span.ke-toast${t?`.ke-is-${t}`:""}`,{text:e});this.el.appendChild(n),setTimeout(()=>{n.style.opacity="0",n.style.transition="opacity .2s",setTimeout(()=>n.remove(),220)},i)}error(e){this.show(e,"error",3600)}warn(e){this.show(e,"warn",3e3)}ok(e){this.show(e,"ok",2200)}destroy(){this.el&&!this.el.childElementCount&&this.el.remove(),this.el=null}}function J(o,e=document){const t=l("div.ke-lightbox",{tabindex:"-1"},[l("img",{src:o,alt:""})]),i=()=>{t.remove(),document.removeEventListener("keydown",n)},n=r=>{r.key==="Escape"&&i()};return t.addEventListener("click",i),document.addEventListener("keydown",n),e.body.appendChild(t),i}class wt{constructor(e){this.editor=e,this.node=null,this.el=l("div.ke-bubble",{hidden:!0,contenteditable:"false"}),e.el.appendChild(this.el),this.el.addEventListener("mousedown",t=>t.preventDefault()),this.el.addEventListener("click",t=>this.onClick(t)),this.replaceInput=l("input",{type:"file",style:{display:"none"}}),this.replaceInput.addEventListener("change",()=>{var i;const t=(i=this.replaceInput.files)==null?void 0:i[0];this.replaceInput.value="",t&&this.node&&this.editor.media.replaceNode(this.node,t)}),e.el.appendChild(this.replaceInput),this.resizeEl=l("div.ke-img-resize",{hidden:!0,"aria-label":"拖动缩放图片",title:"拖动缩放图片",html:'<svg viewBox="0 0 10 10"><path d="M7 1 L9 3 M4 4 L6 6 M1 7 L3 9" stroke="currentColor" stroke-width="1.6" stroke-linecap="round"/></svg>'}),this.resizeTip=l("div.ke-img-resize-tip",{hidden:!0}),this.resizeEl.addEventListener("pointerdown",t=>this.onResizePointerDown(t)),e.el.appendChild(this.resizeEl),e.el.appendChild(this.resizeTip)}show(e){this.node=e;const t=e.dataset.kMedia==="video"?"video":"image";this.el.textContent="";const i=t==="image"?this.imageActions(e):this.videoActions(e);for(const n of i)n&&this.el.appendChild(n);this.el.hidden=!1,t==="image"&&this.attachResize(),this.position()}hide(){this.el.hidden=!0,this.detachResize(),this.node=null}attachResize(){var e;(e=this.node)!=null&&e.querySelector("img")&&(this.resizeEl.hidden=!1,this.positionHandle())}detachResize(){this.resizeEl.hidden=!0,this.resizeTip.hidden=!0}position(){if(!this.node||(this.positionHandle(),this.el.hidden))return;const e=this.editor.el.getBoundingClientRect(),t=this.node.getBoundingClientRect(),i=this.editor.scrollEl.getBoundingClientRect();if(!t.height&&!t.width)return this.hide();if(t.bottom<i.top||t.top>i.bottom)return this.hide();const n=this.el.getBoundingClientRect(),r=t.left-e.left+t.width/2,a=t.top-e.top<n.height+18,c=a?t.bottom-e.top+10:t.top-e.top-10;this.el.classList.toggle("ke-is-below",a);const d=n.width/2;this.el.style.left=`${Math.min(Math.max(r,d+8),Math.max(d+8,e.width-d-8))}px`,this.el.style.top=`${Math.max(6,c)}px`}positionHandle(){const e=this.node;if(!e||this.resizeEl.hidden)return;const t=e.querySelector("img");if(!t)return;const i=this.editor.el.getBoundingClientRect(),n=t.getBoundingClientRect();if(!n.width&&!n.height)return;const r=18,s=6;this.resizeEl.style.left=`${n.right-i.left-r-s}px`,this.resizeEl.style.top=`${n.bottom-i.top-r-s}px`}updateResizeTip(e){var n;if(this.resizeTip.hidden||!this.node)return;this.resizeTip.textContent=`${Math.round(e)}%`;const t=this.editor.el.getBoundingClientRect(),i=((n=this.node.querySelector("img"))==null?void 0:n.getBoundingClientRect())||this.node.getBoundingClientRect();this.resizeTip.style.left=`${i.left-t.left+i.width/2}px`,this.resizeTip.style.top=`${i.top-t.top-10}px`}onResizePointerDown(e){var d;if(e.button!=null&&e.button!==0)return;const t=(d=this.node)==null?void 0:d.querySelector("img");if(!t)return;e.preventDefault(),e.stopPropagation();const n=this.node.getBoundingClientRect().width,r=Ee(Et(t,n),15,100),s=e.clientX;this.el.hidden=!0,this.resizeTip.hidden=!1,this.updateResizeTip(r);try{this.resizeEl.setPointerCapture(e.pointerId)}catch{}const a=h=>{const p=h.clientX-s,u=n?p/n*100:0,k=Ee(Math.round(r+u),15,100);t.style.width=`${k}%`,t.style.maxWidth="100%",this.updateResizeTip(k),this.positionHandle()},c=()=>{this.resizeEl.removeEventListener("pointermove",a),this.resizeEl.removeEventListener("pointerup",c),this.resizeEl.removeEventListener("pointercancel",c),this.resizeTip.hidden=!0,this.editor.commitHistory(),this.editor.refreshStatus(),this.el.hidden=!1,this.position()};this.resizeEl.addEventListener("pointermove",a),this.resizeEl.addEventListener("pointerup",c),this.resizeEl.addEventListener("pointercancel",c)}imageActions(e){const t=e.querySelector("img"),i=oe(t),n=t&&parseFloat(getComputedStyle(t).borderRadius)>0,r=a=>{ne(t,a),this.editor.commitHistory(),this.position()},s=a=>{t.style.width=a,ne(t,oe(t)),this.editor.commitHistory(),this.position()};return[B("alignLeft","左对齐",()=>r("left"),i==="left"),B("alignCenter","居中",()=>r("center"),i==="center"),B("alignRight","右对齐",()=>r("right"),i==="right"),V(),_("30%","宽度 30%",()=>s("30%")),_("60%","宽度 60%",()=>s("60%")),_("100%","宽度 100%",()=>s("100%")),V(),B("rounded","圆角",()=>Ct(t,e),n),B("preview","查看大图",()=>St(t)),B("upload","替换图片",()=>this.pick("image")),V(),B("trash","删除",()=>this.remove())]}videoActions(){return[_("小","窄版",()=>this.setVideoWidth("60%")),_("大","宽版",()=>this.setVideoWidth("100%")),V(),B("upload","替换视频",()=>this.pick("video")),V(),B("trash","删除",()=>this.remove())]}pick(e){this.replaceInput.accept=e==="image"?this.editor.options.imageAccept:this.editor.options.videoAccept,this.replaceInput.click()}setVideoWidth(e){this.node&&(this.node.style.width=e,this.editor.commitHistory(),this.position())}remove(){if(!this.node)return;const e=this.editor.media.taskFromNode(this.node);if(e)this.editor.media.remove(e);else{const t=this.node.nextElementSibling;this.node.remove(),t&&this.editor.focus(),this.editor.commitHistory()}this.hide(),this.editor.refreshStatus()}onClick(){}destroy(){this.el.remove(),this.replaceInput.remove(),this.resizeEl.remove(),this.resizeTip.remove()}}function B(o,e,t,i=!1){const n=l("button",{type:"button",title:e,html:M(o)});return i&&n.classList.add("ke-is-active"),n.addEventListener("click",t),n}function _(o,e,t){const i=l("button",{type:"button",title:e,text:o});return i.addEventListener("click",t),i}const V=()=>l("span.ke-sep");function Ct(o,e){if(!o)return;const t=parseFloat(getComputedStyle(o).borderRadius)>0;o.style.borderRadius=t?"0":"10px",e.dispatchEvent(new Event("change",{bubbles:!0}))}function St(o){o&&J(o.src)}function Ee(o,e,t){return Math.min(t,Math.max(e,o))}function Et(o,e){var i,n;if(!e)return 100;const t=(n=(i=o==null?void 0:o.style)==null?void 0:i.width)==null?void 0:n.match(/^([\d.]+)%$/);return t?parseFloat(t[1]):o.getBoundingClientRect().width/e*100}const Lt=new Set(["a","abbr","b","blockquote","br","code","col","colgroup","dd","del","div","dl","dt","em","figcaption","figure","font","h1","h2","h3","h4","h5","h6","hr","i","img","ins","kbd","li","mark","ol","p","pre","s","samp","section","small","span","strong","sub","sup","table","tbody","td","tfoot","th","thead","tr","u","ul","video","source"]),Mt=new Set(["style","class"]),zt={A:["href","title","target","rel"],IMG:["src","alt","title","width","height"],VIDEO:["src","poster","controls","loop","muted","playsinline","preload","width","height"],SOURCE:["src","type"],FONT:["size","color"],TD:["colspan","rowspan"],TH:["colspan","rowspan"],OL:["start"],LI:["value"]},Tt=["data-k-","data-keditor-"],At=/^(?:https?:|mailto:|tel:|blob:|\/|#|\.{1,2}\/|[^:]*$)/i,Ht=/^data:image\/(?:png|jpe?g|gif|webp|svg\+xml);/i;function Y(o){if(!o)return!1;const e=String(o).trim().replace(/\s+/g,"");return/^(javascript|vbscript|file|about):/i.test(e)?!1:e.startsWith("data:")?Ht.test(e):At.test(e)}function Bt(o){const e=[];for(const t of String(o).split(";")){const i=t.indexOf(":");if(i<0)continue;const n=t.slice(0,i).trim().toLowerCase(),r=t.slice(i+1).trim();!n||!r||/^[a-z-]+$/.test(n)&&(n.startsWith("mso-")||n.startsWith("-mso-")||/expression|javascript:|behavior:|url\(\s*['"]?\s*(javascript|data):/i.test(r)||e.push(`${n}:${r}`))}return e.join(";")}function $t(o){return String(o).split(/\s+/).filter(e=>/^[\w-]+$/.test(e)&&!/^(script|javascript)/i.test(e)).join(" ")}function Rt(o,e,t){const i=e.toLowerCase();return i.startsWith("on")?!1:Mt.has(i)||Tt.some(r=>i.startsWith(r))?!0:(zt[o]||[]).includes(i)}function K(o,{allowEmpty:e=!1}={}){if(!o)return e?"":"<p><br></p>";const i=new DOMParser().parseFromString(`<div>${o}</div>`,"text/html").body.firstChild;Le(i);const n=i.innerHTML.trim();return!n&&!e?"<p><br></p>":n}function Le(o){const e=Array.from(o.childNodes);for(const t of e){if(t.nodeType===8){t.remove();continue}if(t.nodeType===3)continue;if(t.nodeType!==1){t.remove();continue}const i=t.tagName;if(!Lt.has(i.toLowerCase())){if(i==="SCRIPT"||i==="STYLE"||i==="IFRAME"||i==="OBJECT"||i==="EMBED"||i==="FORM"||i==="LINK"||i==="META"){t.remove();continue}const n=t.parentNode;for(;t.firstChild;)n.insertBefore(t.firstChild,t);n.removeChild(t);continue}for(const n of Array.from(t.attributes)){if(!Rt(i,n.name,n.value)){t.removeAttribute(n.name);continue}const r=n.name.toLowerCase();if(r==="style")t.setAttribute("style",Bt(n.value));else if(r==="class"){const s=$t(n.value);s?t.setAttribute("class",s):t.removeAttribute("class")}else(r==="href"||r==="src"||r==="poster")&&(Y(n.value)||t.removeAttribute(n.name))}i==="A"&&t.getAttribute("target")==="_blank"&&t.setAttribute("rel","noopener noreferrer"),(t.getAttribute("href")===""||!t.getAttribute("href"))&&i==="A"&&t.removeAttribute("href"),Le(t)}}const Ot={1:10,2:13,3:16,4:18,5:24,6:32,7:48};function Me(o){return/urn:schemas-microsoft-com|class=["']?Mso|ProgID|w:val=/i.test(o)}function ze(o){const e=new DOMParser().parseFromString(`<div>${o}</div>`,"text/html"),t=e.body.firstChild;return t.querySelectorAll("*").forEach(i=>{const n=i.tagName.toLowerCase();if(n.startsWith("o:")||n.startsWith("w:")||n==="style"||n==="script"||n==="link"||n==="meta"){i.remove();return}if(n==="img"){const r=Number(i.getAttribute("width")||0),s=Number(i.getAttribute("height")||0);(r&&r<=3||s&&s<=3)&&i.remove();return}if(n==="font"){const r=Ot[Number(i.getAttribute("size"))],s=e.createElement("span"),a=[];for(r&&a.push(`font-size:${r}px`),i.color&&a.push(`color:${i.color}`),a.length&&s.setAttribute("style",a.join(";"));i.firstChild;)s.appendChild(i.firstChild);i.replaceWith(s);return}for(const r of Array.from(i.attributes)){const s=r.name.toLowerCase();(s.startsWith("mso-")||s==="class"||s.startsWith("_")||s.startsWith("w:")||s.startsWith("o:")||s==="lang"||s==="dir")&&i.removeAttribute(r.name)}}),t.innerHTML}function ce(o){return String(o).replace(/[&<>"']/g,e=>({"&":"&","<":"<",">":">",'"':""","'":"'"})[e])}function Te(o){const e=new DOMParser().parseFromString(`<div>${o}</div>`,"text/html");return e.body.querySelectorAll("style,script").forEach(t=>t.remove()),e.body.innerHTML=e.body.innerHTML.replace(/<\/(p|div|h[1-6]|li|blockquote|pre|tr)>/gi,`
|
|
481
|
+
`),e.body.textContent.replace(/\u00a0/g," ").replace(/\n{3,}/g,`
|
|
482
|
+
|
|
483
|
+
`).trim()}const Pt=1e4;function Ae(o){if(Array.isArray(o))return o;if(!o||typeof o!="object")return[];for(const e of["items","list","data","rows","records","result"]){const t=o[e];if(Array.isArray(t))return t;if(t&&typeof t=="object"){const i=Ae(t);if(i.length)return i}}return[]}function Z(o,e){for(const t of e){const i=o[t];if(i!=null)return i}}function Nt(o,e){if(o==null)return null;if(typeof o=="string"||typeof o=="number"){const n=String(o);return{value:n,label:n,desc:"",url:"",group:"",html:"",disabled:!1,raw:o}}if(typeof o!="object")return null;const t=Z(o,["value","id","key","val","code"]),i=Z(o,["label","text","name","title"]);return{value:String(t===void 0?e:t),label:String(i===void 0||i===""?t===void 0?e:t:i),desc:String(Z(o,["desc","description","sub","subtitle","tip"])??""),url:String(Z(o,["url","href","link","jumpUrl","jump"])??""),group:String(o.group??""),html:String(o.html??""),disabled:!!o.disabled,raw:o}}function G(o){return Ae(o).map(Nt).filter(Boolean)}function de(o={}){const e=o.position!==void 0?o.position:o.at,t=n=>Math.max(0,Math.floor(Number(n))),i=n=>typeof n=="object"&&n?n.before||n.after:n;if(typeof e=="number"&&Number.isFinite(e))return t(e);if(typeof e=="string"&&e){const n=e.toLowerCase();return n==="start"||n==="begin"||n==="first"?"start":n==="end"||n==="last"||n==="main"?"end":n==="tail"||n===":tail"||n==="right"?"tail":{before:e}}if(e&&typeof e=="object"){if(e.before)return{before:String(i(e))};if(e.after)return{after:String(i(e))}}return typeof o.index=="number"&&Number.isFinite(o.index)?t(o.index):o.before?{before:String(o.before)}:o.after?{after:String(o.after)}:null}function He(o){if(!o||typeof o!="object")return null;const e=String(o.name||"").trim();return e?{name:e,position:de(o),type:o.type==="button"?"button":"select",title:o.title||o.text||e,text:o.text||"",placeholder:o.placeholder||o.text||"请选择",icon:o.icon||"",width:Number(o.width)>0?Number(o.width):0,searchable:!!o.searchable,note:o.note?String(o.note):"",emptyText:o.emptyText?String(o.emptyText):"",cache:o.cache!==!1,keepValue:o.keepValue!==!1,multiple:!1,options:o.options??null,load:typeof o.load=="function"?o.load:null,url:o.url?String(o.url):"",fetchOptions:o.fetchOptions&&typeof o.fetchOptions=="object"?o.fetchOptions:{},pick:typeof o.pick=="function"?o.pick:null,link:o.link??null,insert:o.insert===void 0?"auto":o.insert,onSelect:typeof o.onSelect=="function"?o.onSelect:null,onClick:typeof o.onClick=="function"?o.onClick:null,active:typeof o.active=="function"?o.active:null,enabled:typeof o.enabled=="function"?o.enabled:null}:null}function Be(o){return Array.isArray(o)?o.map(He).filter(Boolean):[]}function jt(){return{items:null,loaded:!1,loading:null,value:null,controller:null,error:"",gen:0,external:!1}}async function Ft(o,e,t){return o.load?G(await o.load(e)):o.url?G(await Dt(o,e,t)):G(o.options)}async function Dt(o,e,t){var c;const i=o.fetchOptions,n=i.fetch||(typeof fetch=="function"?fetch.bind(globalThis):null);if(!n)throw new Error("当前环境无 fetch,请改用 load 函数提供数据");(c=t.controller)==null||c.abort();const r=typeof AbortController=="function"?new AbortController:null;t.controller=r;const s=Number(i.timeout)>0?Number(i.timeout):Pt,a=setTimeout(()=>r==null?void 0:r.abort(),s);try{const d=await n(o.url,{method:i.method||"GET",headers:i.headers,body:i.body,credentials:i.credentials,signal:r?r.signal:void 0});if(!d||d.ok===!1)throw new Error(`接口返回 ${d&&d.status?d.status:"异常"}`);const h=i.parser?await i.parser(d):await d.json();return o.pick?o.pick(h,e):h}catch(d){throw d&&d.name==="AbortError"?new Error(`请求超时(${s}ms)或被取消`):d}finally{clearTimeout(a),t.controller===r&&(t.controller=null)}}function It(o,e,t,{force:i=!1}={}){if(!i&&t.external&&t.items||!i&&o.cache&&t.items)return Promise.resolve(t.items);if(!i&&t.loading)return t.loading;const n=t.gen,r=Ft(o,e,t).then(s=>n!==t.gen?t.items:(t.items=s,t.loaded=!0,t.error="",s)).catch(s=>{if(n!==t.gen)return t.items;throw t.error=s&&s.message?s.message:String(s),s}).finally(()=>{t.loading===r&&(t.loading=null)});return t.loading=r,r}function qt(o,e){return o.gen+=1,o.items=G(e),o.loaded=!0,o.error="",o.external=!0,he(o),o.loading=null,o.items}function he(o){var e;(e=o.controller)==null||e.abort(),o.controller=null}function pe(o,e){return String(o).replace(/\{(\w+)\}/g,(t,i)=>{if(e[i]!==void 0&&e[i]!==null)return String(e[i]);const n=e.raw&&e.raw[i];return n==null?t:String(n)})}function ue(o,e,t){return typeof o=="function"?o(e,t):o}function $e(o,e,t){const i=o.link;let n=null;if(typeof i=="function"?n=i(e,t):typeof i=="string"?n={url:i}:i&&typeof i=="object"?n=i:(i===!0||e.url)&&(n={url:e.url}),!n)return null;typeof n=="string"&&(n={url:n});const r=W(pe(String(ue(n.url,e,t)??""),e));if(!r||!Y(r))return null;const s=ue(n.text,e,t),a=ue(n.title,e,t),c=n.mode==="open"?"open":"insert",d=n.target==="_self"||n.target===!1?"_self":"_blank";return{mode:c,url:r,text:s==null||s===""?e.label:pe(String(s),e),target:d,title:a?pe(String(a),e):""}}function Re(o,e){o.commands.insertHTML(ce(e))}async function Ut(o,e,t,i){o.restoreSelection();const n=$e(e,i,o),r={editor:o,item:i,link:n,insertLink:d=>Oe(o,{...n,...d}),insertHtml:d=>o.commands.insertHTML(String(d)),insertText:d=>Re(o,d),open:(d,h)=>Pe(d||n&&n.url,h||n&&n.target)};let s="none",a=!1;e.onSelect&&(a=await e.onSelect(i,r)===!1),a||(s=Wt(o,e,i,n)),e.keepValue&&(t.value=i);const c={name:e.name,item:i,link:n,action:s,editor:o};return o.emit("customselect",c),c}function Wt(o,e,t,i){const n=e.insert;return n===!1||n==="none"?"none":i&&i.mode==="open"?(Pe(i.url,i.target),"open"):n==="link"||n==="auto"&&i?i?(Oe(o,i),"link"):"none":n==="html"||n==="auto"&&t.html?t.html?(o.commands.insertHTML(t.html),"html"):"none":(Re(o,t.label),"text")}function Oe(o,e){o.commands.createLink({url:e.url,text:e.text,target:e.target!=="_self"})}function Pe(o,e="_blank"){!o||!Y(o)||(e==="_self"?window.location.href=o:window.open(o,"_blank","noopener,noreferrer"))}const fe='<svg class="ke-caret" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2.2" stroke-linecap="round" stroke-linejoin="round"><path d="m6 9 6 6 6-6"/></svg>',Ne="keditor.toolbarScrollHint",_t='<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2.1" stroke-linecap="round" stroke-linejoin="round"><path d="M8 7 4 12l4 5"/><path d="M16 7l4 5-4 5"/><path d="M4 12h16"/></svg>',me=[{value:"p",label:"正文",desc:"默认段落 · 17px,正文内容都用它",sample:"正文示例文字",sampleClass:"s-body"},{value:"h1",label:"标题一",desc:"大标题 · 22px 加粗,全文主标题(建议只用一次)",sample:"标题一示例",sampleClass:"s-h1"},{value:"h2",label:"标题二",desc:"章节标题 · 20px 加粗,划分小节",sample:"标题二示例",sampleClass:"s-h2"},{value:"h3",label:"标题三",desc:"小标题 · 18px 加粗,章节内的层级",sample:"标题三示例",sampleClass:"s-h3"}],Vt=[12,14,15,16,17,18,20,22,24,28,32],Q=["undo","redo","|","heading","fontsize","|","bold","italic","underline","strike","|","foreColor","backColor","|","alignLeft","alignCenter","alignRight","alignJustify","|","ul","ol","quote","|","link","image","video","table","code","hr","clear",":tail","source","fullscreen"],je={undo:{icon:"undo",title:"撤销 (⌘/Ctrl+Z)",run:o=>o.undo(),active:o=>!!o.canUndo,enabled:o=>o.canUndo},redo:{icon:"redo",title:"重做 (⌘/Ctrl+Shift+Z)",run:o=>o.redo(),active:o=>!!o.canRedo,enabled:o=>o.canRedo},bold:{glyph:["B","ke-glyph"],title:"加粗 (⌘/Ctrl+B)",cmd:"bold",active:o=>o.bold},italic:{glyph:["I","ke-glyph ke-glyph-i"],title:"斜体 (⌘/Ctrl+I)",cmd:"italic",active:o=>o.italic},underline:{glyph:["U","ke-glyph ke-glyph-u"],title:"下划线 (⌘/Ctrl+U)",cmd:"underline",active:o=>o.underline},strike:{glyph:["S","ke-glyph ke-glyph-s"],title:"删除线",cmd:"strike",active:o=>o.strikeThrough},alignLeft:{icon:"alignLeft",title:"左对齐",run:o=>o.commands.setAlign("left"),active:o=>o.align==="left"},alignCenter:{icon:"alignCenter",title:"居中",run:o=>o.commands.setAlign("center"),active:o=>o.align==="center"},alignRight:{icon:"alignRight",title:"右对齐",run:o=>o.commands.setAlign("right"),active:o=>o.align==="right"},alignJustify:{icon:"alignJustify",title:"两端对齐",run:o=>o.commands.setAlign("justify"),active:o=>o.align==="justify"},ul:{icon:"ul",title:"无序列表",run:o=>o.commands.toggleList("unordered"),active:o=>o.ul},ol:{icon:"ol",title:"有序列表",run:o=>o.commands.toggleList("ordered"),active:o=>o.ol},quote:{icon:"quote",title:"引用",run:o=>o.commands.toggleBlockquote(),active:o=>o.block==="blockquote"},link:{icon:"link",title:"插入链接",run:o=>o.toolbar.openLink(),active:o=>o.link,toggles:!0},image:{icon:"image",title:"图片(本地上传 / 网络链接)",run:o=>o.toolbar.openMedia("image"),toggles:!0},video:{icon:"video",title:"视频(本地上传 / 网络链接,支持分片上传)",run:o=>o.toolbar.openMedia("video"),toggles:!0},table:{icon:"table",title:"插入表格",run:o=>o.toolbar.openTable(),toggles:!0},code:{icon:"code",title:"代码块",run:o=>o.commands.insertCodeBlock()},hr:{icon:"hr",title:"分割线",run:o=>o.commands.insertDivider()},clear:{icon:"clear",title:"清除格式",run:o=>o.commands.clearFormat()},source:{icon:"source",title:"查看 / 编辑 HTML 源码(⌘/Ctrl+Shift+K)",text:"源码",run:o=>o.toggleSource(),active:o=>o.source},preview:{icon:"preview",title:"预览效果(手机 / 平板 / 电脑宽度)",text:"预览",run:o=>o.togglePreview(),active:o=>o.preview},fullscreen:{icon:"expand",title:"全屏编辑",text:"全屏",run:o=>o.toggleFullscreen(),active:o=>o.fullscreen},foreColor:{pop:"fore",title:"字体颜色",toggles:!0,swatch:"fore"},backColor:{pop:"back",title:"背景高亮色",toggles:!0,swatch:"back"}};class Kt{constructor(e,t=Q,i=[]){this.editor=e,this.buttons=new Map,this.custom=new Map,this.colorState={foreColor:"#3f3f3f",backColor:"#f6c344"},this.recent={foreColor:[],backColor:[]},this.el=e.tbEl;for(const n of i)this.registerCustom(n);this.build(t),this.setupScrollHints()}build(e){const t=l("div.ke-tb-group");this.el.appendChild(t),this.groupEl=t,this.tailEl=null;const i=()=>this.tailEl||t;for(const n of e){if(n==="|"){i().appendChild(l("span.ke-tb-sep"));continue}if(n===":tail"){this.tailEl=l("div.ke-tb-tail"),this.el.appendChild(this.tailEl);continue}if(this.custom.has(n)){const s=this.custom.get(n);s.button=this.buildCustomButton(s),i().appendChild(s.button);continue}if(n==="heading"){i().appendChild(this.buildHeading());continue}if(n==="fontsize"){i().appendChild(this.buildFontSize());continue}const r=je[n];r&&i().appendChild(this.buildButton(n,r))}for(const[n,r]of this.custom)r.button||(r.button=this.buildCustomButton(r),this.insertButton(r.button,r.spec.position))}buildButton(e,t){const i=l("button.ke-btn",{type:"button",title:t.title,"data-k-item":e,onclick:n=>{var r;n.preventDefault(),t.pop?this.toggleColor(e,i):t.cmd?this.editor.commands.toggleMark(t.cmd):(r=t.run)==null||r.call(t,this.editor),t.toggles||this.editor.popover.close()}});if(t.icon&&(i.innerHTML=M(t.icon)),t.text&&i.appendChild(l("span.ke-btn-text",{text:t.text})),t.glyph){const[n,r]=t.glyph;i.appendChild(l("span",{class:r,text:n}))}if(t.swatch){const n=t.swatch==="fore"?this.colorState.foreColor:this.colorState.backColor,r=l("span",{class:t.swatch==="fore"?"ke-glyph ke-glyph-a":"ke-glyph ke-glyph-a ke-glyph-hl"});r.appendChild(l("span",{text:"A"})),i.appendChild(r),t.swatch==="fore"&&i.appendChild(l("span",{class:"ke-dot"})),this.paintButton(i,t.swatch,n),i.dataset.kPop=t.swatch==="fore"?"foreColor":"backColor"}return t.toggles&&!t.swatch&&(i.dataset.kPop=e),this.buttons.set(e,i),i}paintButton(e,t,i){!e||!i||e.style.setProperty(t==="fore"?"--ke-fore":"--ke-back",i)}openPop(e,t,i={}){this.editor.saveSelection(),this.editor.popover.open(e,t,{align:"start",...i,onClose:()=>{var n;e.classList.remove("ke-is-open"),(n=i.onClose)==null||n.call(i)}}),e.classList.add("ke-is-open")}togglePop(e,t,i,n={}){const r=this.editor.popover;if(r.isOpen&&r.anchor===t){r.close();return}this.openPop(t,i,n)}buildHeading(){const e=me[0],t=l("button.ke-btn.ke-btn-label",{type:"button",title:"段落样式:正文 / 标题一 / 标题二 / 标题三","data-k-item":"heading",dataset:{kPop:"heading"},onclick:i=>{i.preventDefault(),this.togglePop("heading",t,()=>ct(me,{value:this.editor.getState().block,onPick:n=>{this.editor.restoreSelection(),this.editor.commands.setHeading(n),this.editor.popover.close(),this.editor.refresh()}}))}});return t.innerHTML=`<span class="ke-btn-text">${e.label}</span>${fe}`,this.headingEl=t,this.buttons.set("heading",t),t}buildFontSize(){const e=l("button.ke-btn.ke-btn-label",{type:"button",title:"字号","data-k-item":"fontsize",dataset:{kPop:"fontsize"},onclick:t=>{t.preventDefault(),this.togglePop("fontsize",e,()=>dt(Vt,{value:this.editor.getState().fontSize,onPick:i=>{this.editor.restoreSelection(),this.editor.commands.setFontSize(Number(i)),this.editor.popover.close(),this.editor.refresh()}}))}});return e.innerHTML=`<span class="ke-btn-text">字号</span>${fe}`,this.fontSizeEl=e,this.buttons.set("fontsize",e),e}registerCustom(e){const t=He(e);if(!t)return null;const i=this.custom.get(t.name),n={spec:t,rt:i?i.rt:jt(),button:i?i.button:null};return this.custom.set(t.name,n),n}buildCustomButton(e){const{spec:t}=e,i=t.type==="select",n=l("button.ke-btn",{type:"button",class:i?"ke-btn-label ke-btn-custom":"ke-btn-custom",title:t.title,"data-k-item":t.name,dataset:{kPop:t.name,kCustom:t.name},onclick:r=>{r.preventDefault(),i?this.openCustom(t.name):this.runCustomButton(t)}});return t.icon&&(n.innerHTML=/</.test(t.icon)?t.icon:M(t.icon)),i?(n.appendChild(l("span.ke-btn-text",{text:t.text||t.placeholder})),n.insertAdjacentHTML("beforeend",fe)):t.text&&n.appendChild(l("span.ke-btn-text",{text:t.text})),this.syncCustomLabel(t.name,n),n}syncCustomLabel(e,t){const i=this.custom.get(e),n=t||(i==null?void 0:i.button);if(!i||!n)return;const{spec:r,rt:s}=i;if(r.type!=="select")return;const a=n.querySelector(".ke-btn-text");if(!a)return;const c=s.value;a.textContent=c?c.label:r.text||r.placeholder,n.title=c?`${r.title}:${c.label}`:r.title,n.classList.toggle("ke-has-value",!!c)}openCustom(e){const t=this.custom.get(e);if(!t)return;this.revealButton(t.button);const{spec:i,rt:n}=t,r=!!(i.load||i.url),s=({force:a}={})=>It(i,this.editor,n,{force:a});this.togglePop(e,t.button,()=>kt({title:i.title,note:i.note||"",searchable:i.searchable,width:i.width,remote:r,value:n.value?n.value.value:"",emptyText:i.emptyText,load:s,reload:s,linkOf:a=>$e(i,a,this.editor),onPick:a=>this.pickCustom(e,a)}))}async pickCustom(e,t){const i=this.custom.get(e);if(i){this.editor.popover.close();try{await Ut(this.editor,i.spec,i.rt,t)}catch(n){this.editor.reportError("custombutton",n)}this.syncCustomLabel(e),this.editor.refresh()}}async runCustomButton(e){this.editor.popover.close();try{e.onClick&&await e.onClick({editor:this.editor,name:e.name}),this.editor.emit("customclick",{name:e.name,editor:this.editor})}catch(t){this.editor.reportError("custombutton",t)}this.editor.refresh()}addButton(e,t={}){var r;const i=this.registerCustom(e);if(!i)return null;i.button&&i.button.remove(),i.button=this.buildCustomButton(i);const n=t.at!==void 0?t.at:de(t)??i.spec.position;return this.insertButton(i.button,n,{withSep:n==null}),this.revealButton(i.button),(r=this.syncScrollHints)==null||r.call(this),i.button}buttonNodes(){const e=[];for(const t of[this.groupEl,this.tailEl])if(t)for(const i of t.children)i.dataset&&i.dataset.kItem&&e.push(i);return e}slotOf(e){const t={parent:this.groupEl||this.el,ref:null};if(e==="tail")return{parent:this.tailEl||this.groupEl||this.el,ref:null};if(e==null||e==="end")return t;if(e==="start"){const a=this.buttonNodes()[0];return a?{parent:a.parentElement,ref:a}:t}const i=this.buttonNodes();if(typeof e=="number"){const a=i[Math.max(0,Math.floor(e))];if(a)return{parent:a.parentElement,ref:a};const c=i[i.length-1];return c?{parent:c.parentElement,ref:null}:t}const n=!!(e&&typeof e=="object"&&e.after),r=typeof e=="string"?e:String((n?e.after:e.before)||""),s=i.find(a=>a.dataset.kItem===r);return s?{parent:s.parentElement,ref:n?s.nextElementSibling||null:s}:t}insertButton(e,t,{withSep:i}={}){const{parent:n,ref:r}=this.slotOf(t);!n||!e||(i&&!r&&n.appendChild(l("span.ke-tb-sep")),n.insertBefore(e,r||null))}moveButton(e,t){var n,r;const i=this.buttonNodes().find(s=>s.dataset.kItem===String(e));return i?(i.remove(),this.insertButton(i,t===void 0?((n=this.custom.get(String(e)))==null?void 0:n.spec.position)??null:t),this.revealButton(i),(r=this.syncScrollHints)==null||r.call(this),!0):!1}revealButton(e){const t=this.el;if(!t||!e||!e.isConnected)return;const i=t.scrollWidth-t.clientWidth;if(i<=1)return;const n=this.tailEl?this.tailEl.offsetWidth:0,r=e.offsetLeft,s=r+e.offsetWidth,a=t.scrollLeft+t.clientWidth-n;s>a-4?t.scrollLeft=Math.min(i,s-t.clientWidth+n+10):r<t.scrollLeft+4&&(t.scrollLeft=Math.max(0,r-10))}removeButton(e){var r,s,a,c;const t=this.custom.get(e);if(!t)return!1;he(t.rt),this.editor.popover.anchor===t.button&&this.editor.popover.close();const i=(r=t.button)==null?void 0:r.previousElementSibling,n=(s=t.button)==null?void 0:s.nextElementSibling;return(a=t.button)==null||a.remove(),i&&i.classList.contains("ke-tb-sep")&&(!n||n.classList.contains("ke-tb-sep"))&&i.remove(),this.buttons.delete(e),this.custom.delete(e),(c=this.syncScrollHints)==null||c.call(this),!0}setButtonOptions(e,t){const i=this.custom.get(e);if(!i)return null;const n=qt(i.rt,t);return this.editor.popover.isOpen&&this.editor.popover.anchor===i.button&&(this.editor.popover.close(),this.openCustom(e)),n}getButtonValue(e){const t=this.custom.get(e);return t?t.rt.value:null}setButtonValue(e,t){const i=this.custom.get(e);if(!i)return null;const r=(i.rt.items||[]).find(s=>String(s.value)===String(t))||null;return i.rt.value=r,this.syncCustomLabel(e),r}toggleColor(e,t){const i=e==="foreColor"?"fore":"back";this.togglePop(e,t,()=>at({title:i==="fore"?"字体颜色":"背景高亮色",kind:i,value:this.colorState[e],recents:this.recent[e],onPick:n=>this.applyColor(e,i,n,t),onClear:()=>this.applyColor(e,i,null,t)}),{onClose:()=>t.classList.remove("ke-is-active")})}applyColor(e,t,i,n){this.editor.restoreSelection(),i&&(this.colorState[e]=i,this.recent[e]=[i,...this.recent[e].filter(r=>r.toLowerCase()!==i.toLowerCase())].slice(0,8),this.paintButton(n,t,i)),this.editor.commands.setColor(t,i),this.editor.popover.close()}openTable(){const e=this.buttons.get("table");this.togglePop("table",e,()=>ht((t,i)=>{this.editor.restoreSelection(),this.editor.commands.insertTable(t,i),this.editor.popover.close()}))}openLink(){const e=this.buttons.get("link"),t=this.editor.getState(),i=t.linkUrl;this.togglePop("link",e,()=>ft({url:i||"",text:i?"":t.selectionText||"",target:i?t.linkTarget:!0,onCancel:()=>this.editor.popover.close(),onRemove:i?()=>{this.editor.restoreSelection(),this.editor.commands.removeLink(),this.editor.popover.close()}:null,onSubmit:({url:n,text:r,target:s})=>{this.editor.restoreSelection(),this.editor.commands.createLink({url:W(n),text:r,target:s}),this.editor.popover.close()}}))}openMedia(e){const t=this.buttons.get(e),i=this.editor,n=i.options;this.togglePop(e,t,()=>pt(e,{multiple:e==="image",maxText:`${e==="image"?"图片":"视频"}上限 ${Gt(e==="image"?n.maxImageSize:n.maxVideoSize)}`,hint:e==="image"?"支持 PNG / JPG / GIF / WebP / SVG":"支持 MP4 / MOV / WebM,大文件自动分片",onFiles:r=>{i.popover.close(),r&&r.length?i.media.addFiles([...r]):i.media.pickFiles(e)},onUrl:({url:r,name:s})=>{i.popover.close(),i.restoreSelection(),i.media.insertFromUrl(e,r,s)}}))}refresh(e){var t;for(const[i,n]of this.buttons){const r=je[i];if(!r)continue;const s=((t=r.active)==null?void 0:t.call(r,e))||!1;(n.dataset.kPop||!r.pop)&&n.classList.toggle("ke-is-active",s),r.enabled&&(n.disabled=!r.enabled(e))}for(const[i,n]of this.custom){const{spec:r,button:s}=n;s&&(r.active&&s.classList.toggle("ke-is-active",!!r.active(e,this.editor)),r.enabled&&(s.disabled=!r.enabled(e,this.editor)),r.type==="select"&&this.syncCustomLabel(i))}if(this.headingEl){const i=me.find(r=>r.value===e.block),n=this.headingEl.querySelector(".ke-btn-text");n&&(n.textContent=i?i.label:"正文"),this.headingEl.title=i?`${i.label}:${i.desc}`:"段落样式"}if(this.fontSizeEl){const i=this.fontSizeEl.querySelector(".ke-btn-text");i&&(i.textContent=e.fontSize?`${e.fontSize}px`:"字号")}if(e.linkUrl){const i=this.buttons.get("link");i==null||i.classList.add("ke-is-active")}}setupScrollHints(){const e=this.el,t=this.editor.el;e.isConnected&&(this.scrollFades=l("div.ke-tb-fades",{"aria-hidden":"true"},[l("i.ke-tb-fade ke-tb-fade-l")]),e.insertAdjacentElement("afterend",this.scrollFades),this.syncScrollHints=()=>{if(!e.isConnected||!t.isConnected)return;const i=e.scrollWidth-e.clientWidth,n=i>1,r=e.scrollLeft;t.classList.toggle("ke-tb-scrollable",n),t.classList.toggle("ke-tb-can-l",n&&r>1),t.classList.toggle("ke-tb-can-r",n&&r<i-1),t.style.setProperty("--ke-tb-h",`${e.offsetHeight}px`),n&&!this.hintSettled&&this.showScrollHint()},this.onTbScroll=()=>{this.syncScrollHints(),this.hideScrollHint()},e.addEventListener("scroll",this.onTbScroll,{passive:!0}),typeof ResizeObserver<"u"&&(this.tbRO=new ResizeObserver(()=>this.syncScrollHints()),this.tbRO.observe(e)),this.onTbPointerDown=i=>{this.hideScrollHint(),this.startDragScroll(i)},e.addEventListener("pointerdown",this.onTbPointerDown),requestAnimationFrame(this.syncScrollHints))}startDragScroll(e){const t=this.el,i=this.editor.el;if(e.button!==0||e.pointerType!=="mouse"||t.scrollWidth<=t.clientWidth+1||e.target.closest("input, textarea, select"))return;const n=e.clientX,r=t.scrollLeft;let s=!1;const a=d=>{var p;const h=d.clientX-n;if(!s){if(Math.abs(h)<5)return;s=!0;try{t.setPointerCapture(e.pointerId)}catch{}i.classList.add("ke-tb-dragging"),(p=this.editor.popover)==null||p.close()}d.preventDefault(),t.scrollLeft=r-h},c=()=>{if(t.removeEventListener("pointermove",a),t.removeEventListener("pointerup",c),t.removeEventListener("pointercancel",c),i.classList.remove("ke-tb-dragging"),!s)return;try{t.releasePointerCapture(e.pointerId)}catch{}const d=u=>{u.preventDefault(),u.stopPropagation(),h()},h=()=>{clearTimeout(p),t.removeEventListener("click",d,!0)},p=setTimeout(h,400);t.addEventListener("click",d,!0)};t.addEventListener("pointermove",a),t.addEventListener("pointerup",c),t.addEventListener("pointercancel",c)}showScrollHint(){this.hintSettled=!0;let e=!1;try{e=localStorage.getItem(Ne)==="1"}catch{}e||(this.hintEl=l("div.ke-tb-hint",{"aria-hidden":"true"},[l("span.ke-tb-hint-ico",{html:_t}),l("span",{text:"工具栏可左右滑动"})]),this.editor.el.appendChild(this.hintEl),this.hintTimer=setTimeout(()=>this.hideScrollHint(),3800))}hideScrollHint(){this.hintTimer&&(clearTimeout(this.hintTimer),this.hintTimer=null);const e=this.hintEl;if(e){this.hintEl=null;try{localStorage.setItem(Ne,"1")}catch{}e.classList.add("ke-is-out"),setTimeout(()=>e.remove(),260)}}destroy(){var i,n,r;const e=this.el;this.tbRO&&(this.tbRO.disconnect(),this.tbRO=null),this.hintTimer&&(clearTimeout(this.hintTimer),this.hintTimer=null),this.onTbScroll&&e.removeEventListener("scroll",this.onTbScroll),this.onTbPointerDown&&e.removeEventListener("pointerdown",this.onTbPointerDown);for(const s of this.custom.values())he(s.rt);this.custom.clear(),(i=this.scrollFades)==null||i.remove(),(n=this.hintEl)==null||n.remove(),this.scrollFades=null,this.hintEl=null;const t=(r=this.editor)==null?void 0:r.el;t&&(t.classList.remove("ke-tb-scrollable","ke-tb-can-l","ke-tb-can-r","ke-tb-dragging"),t.style.removeProperty("--ke-tb-h")),e.innerHTML="",this.buttons.clear()}}function Gt(o){if(!o)return"不限";const e=o/1024/1024;return e>=1?`${Math.round(e)}MB`:`${Math.round(o/1024)}KB`}function z(o){const e=window.getSelection();if(!e||e.rangeCount===0)return null;const t=e.getRangeAt(0);return o.contains(t.commonAncestorContainer)?t:null}function Fe(o){const e=window.getSelection();if(!e||e.rangeCount===0)return null;const t=e.getRangeAt(0);if(!o.contains(t.startContainer))return null;let i=0;return document.createTreeWalker(o,NodeFilter.SHOW_TEXT,{acceptNode(s){return s===t.startContainer?NodeFilter.FILTER_ACCEPT:(i+=s.textContent.length,NodeFilter.FILTER_SKIP)}}).nextNode()?i+t.startOffset:t.startContainer===o?0:null}function Xt(o,e){if(e==null)return;const t=window.getSelection();let i=Math.max(0,e);const n=document.createTreeWalker(o,NodeFilter.SHOW_TEXT);let r=n.nextNode(),s=null;for(;r;){const a=r.textContent.length;if(i<=a){try{t.setBaseAndExtent(r,i,r,i)}catch{}return}i-=a,s=r,r=n.nextNode()}if(s)try{t.setBaseAndExtent(s,s.textContent.length,s,s.textContent.length)}catch{}}function P(o,e,{inline:t=!1,selectAfter:i=!0}={}){o.focus();const n=z(o);if(!n)return o.appendChild(e),ee(o),e;if(n.collapsed||n.deleteContents(),t)n.insertNode(e);else{const a=N(n.startContainer,o);!a||a===o?o.appendChild(e):a.after(e)}const r=document.createRange();r.setStartAfter(e),r.collapse(!0);const s=window.getSelection();return s.removeAllRanges(),s.addRange(r),ee(o),i&&s.rangeCount===0&&o.focus(),e}function ee(o){const e=o.lastElementChild;if(!e){o.appendChild(document.createElement("p"));return}if(/^(IMG|VIDEO|IFRAME)$/.test(e.tagName)||e.dataset.kmedia!==void 0){const t=document.createElement("p");t.appendChild(document.createElement("br")),o.appendChild(t)}}function N(o,e){let t=o;for(;t&&t!==e;){if(t.nodeType===1&&/^(P|DIV|H[1-6]|LI|BLOCKQUOTE|PRE|SECTION|TD|TH)$/.test(t.tagName))return t;t=t.parentNode}return null}class Jt{constructor(e){this.editor=e,this.root=e.root}exec(e,t=null){this.editor.focus(),document.execCommand("styleWithCSS",!1,!0),document.execCommand("defaultParagraphSeparator",!1,"p");const i=document.execCommand(e,!1,t);return this.editor.afterEdit(),i}queryState(e){try{return document.queryCommandState(e)}catch{return!1}}queryValue(e){try{return document.queryCommandValue(e)}catch{return""}}hasSelection(){const e=z(this.root);return!!(e&&!e.collapsed)}toggleMark(e){const i={bold:"bold",italic:"italic",underline:"underline",strike:"strikeThrough"}[e];i&&(this.exec(i),this.root.querySelectorAll('span[style=""]').forEach(n=>n.replaceWith(...n.childNodes)))}setFontSize(e){this.editor.focus(),document.execCommand("styleWithCSS",!1,!1);const t=`__ke_fs_${ie()}__`;this.root.setAttribute("data-ke-marker",t),document.execCommand("fontSize",!1,"7"),this.root.removeAttribute("data-ke-marker"),this.root.querySelectorAll('font[size="7"]').forEach(i=>{const n=document.createElement("span");for(n.style.fontSize=`${e}px`;i.firstChild;)n.appendChild(i.firstChild);i.replaceWith(n)}),this.root.querySelectorAll("span").forEach(i=>{/xx-large/i.test(i.style.fontSize)&&(i.style.fontSize=`${e}px`)}),document.execCommand("styleWithCSS",!1,!0),this.editor.afterEdit()}setColor(e,t){this.editor.focus(),document.execCommand("styleWithCSS",!1,!0),t||(t=e==="fore"?"#3f3f3f":"transparent"),document.execCommand(e==="fore"?"foreColor":"hiliteColor",!1,t)||document.execCommand(e==="fore"?"foreColor":"backColor",!1,t),e==="back"&&t==="transparent"&&this.root.querySelectorAll('[style*="background-color"]').forEach(n=>{/background-color:\s*transparent|rgba\(0, 0, 0, 0\)/i.test(n.getAttribute("style")||"")&&(n.style.backgroundColor="",n.getAttribute("style").trim()||n.replaceWith(...n.childNodes))}),this.editor.afterEdit()}setAlign(e){var c,d;const t=(c=this.editor.bubble)==null?void 0:c.node;if(t&&((d=t.dataset)==null?void 0:d.kMedia)==="image"&&e!=="justify"){const h=t.querySelector("img");if(h){ne(h,e),this.editor.commitHistory(),this.editor.bubble.position();return}}const n={left:"justifyLeft",center:"justifyCenter",right:"justifyRight",justify:"justifyFull"}[e];if(!n)return;this.editor.focus();const r=z(this.root),s=N((r==null?void 0:r.commonAncestorContainer)||this.root,this.root);document.execCommand("styleWithCSS",!1,!0),document.execCommand(n);const a=s||this.root.firstElementChild;a&&/^(FIGURE|DIV|VIDEO)/.test(a.tagName||"")&&(a.style.textAlign=e),this.editor.afterEdit()}toggleList(e){this.exec(e==="ordered"?"insertOrderedList":"insertUnorderedList")}setHeading(e){const t=e?`<${e}>`:"<p>";this.exec("formatBlock",t)}toggleBlockquote(){const e=z(this.root),t=N((e==null?void 0:e.commonAncestorContainer)||this.root,this.root);t&&t.tagName==="BLOCKQUOTE"?this.exec("formatBlock","<p>"):this.exec("formatBlock","<blockquote>")}createLink({url:e,text:t="",target:i=!1}){var a,c;this.editor.focus();const n=z(this.root),r=n&&!n.collapsed,s=t||(r?n.toString():e);if(r)document.execCommand("createLink",!1,e),(c=(a=n.commonAncestorContainer.parentElement)==null?void 0:a.closest)==null||c.call(a,"a"),this.root.querySelectorAll(`a[href="${Zt(e)}"]`).forEach(d=>{i?(d.setAttribute("target","_blank"),d.setAttribute("rel","noopener noreferrer")):d.removeAttribute("target")});else{const d=l("a",{href:e},[s]);i&&(d.setAttribute("target","_blank"),d.setAttribute("rel","noopener noreferrer")),P(this.root,d,{inline:!0})}this.editor.afterEdit()}removeLink(){const e=z(this.root);Yt(e,this.root).forEach(i=>i.replaceWith(...i.childNodes)),this.editor.afterEdit()}insertTable(e,t){const i=document.createElement("table"),n=document.createElement("tbody");for(let r=0;r<t;r+=1){const s=document.createElement("tr");for(let a=0;a<e;a+=1){const c=document.createElement(r===0?"th":"td");c.innerHTML="<br>",s.appendChild(c)}n.appendChild(s)}i.appendChild(n),P(this.root,i),this.exec("insertHTML",""),this.editor.afterEdit()}insertCodeBlock(e=""){const t=document.createElement("pre"),i=document.createElement("code");i.textContent=e||"// 在这里输入代码",t.appendChild(i),P(this.root,t),this.editor.afterEdit()}insertDivider(){const e=document.createElement("hr");P(this.root,e),this.editor.afterEdit()}insertHTML(e,{clean:t=!0}={}){const i=t?K(e):e;this.editor.focus();const n=z(this.root);if(n){n.deleteContents();const r=document.createElement("div");r.innerHTML=i;const s=document.createDocumentFragment();for(;r.firstChild;)s.appendChild(r.firstChild);const a=s.lastChild;if(n.insertNode(s),a){const c=document.createRange();c.setStartAfter(a.nodeType===3?a:a.lastChild||a),c.collapse(!0);const d=window.getSelection();d.removeAllRanges(),d.addRange(c)}}else this.root.insertAdjacentHTML("beforeend",i);this.editor.afterEdit()}clearFormat(){if(this.editor.focus(),this.hasSelection()){document.execCommand("removeFormat"),document.execCommand("unlink");const e=z(this.root),t=N(e==null?void 0:e.commonAncestorContainer,this.root);t&&/^(H[1-6]|BLOCKQUOTE|PRE)$/.test(t.tagName)&&this.exec("formatBlock","<p>"),this.stripInlineStylesInRange(e)}else{const e=z(this.root),t=N((e==null?void 0:e.commonAncestorContainer)||this.root,this.root);if(t){const i=t.innerHTML,n=document.createElement("p");n.innerHTML=K(i,{allowEmpty:!0}),n.innerHTML=n.innerHTML.replace(/<(?!br|img)[^>]+>/gi,""),t.replaceWith(n)}}this.editor.afterEdit()}stripInlineStylesInRange(e){if(!e)return;const t=[],i=document.createTreeWalker(e.commonAncestorContainer,NodeFilter.SHOW_ELEMENT);let n=i.currentNode;for(;n;)e.intersectsNode(n)&&n.nodeType===1&&t.push(n),n=i.nextNode();t.forEach(r=>{r!==this.root&&(r.removeAttribute("style"),/^(SPAN|FONT)$/.test(r.tagName)&&!r.attributes.length&&r.replaceWith(...r.childNodes))})}currentBlock(){var i;const e=z(this.root),t=N((e==null?void 0:e.commonAncestorContainer)||this.root,this.root);return((i=t==null?void 0:t.tagName)==null?void 0:i.toLowerCase())||"p"}currentFontSize(){const e=z(this.root);if(!e)return"";let t=e.startContainer;for(;t&&t!==this.root;){if(t.nodeType===1&&t.style.fontSize)return t.style.fontSize.replace("px","");t=t.parentNode}return""}}function Yt(o,e){var s,a,c;if(!o)return[];const t=new Set;let n=o.startContainer.nodeType===1&&((a=(s=o.startContainer).querySelector)==null?void 0:a.call(s,"a"))||o.startContainer;for(;n&&n!==e;)n.tagName==="A"&&t.add(n),n=n.parentNode;try{(c=o.querySelectorAll)==null||c.call(o,"a").forEach(d=>t.add(d))}catch{}const r=o.commonAncestorContainer;return r.nodeType===1&&r.querySelectorAll("a").forEach(d=>o.intersectsNode(d)?t.add(d):null),[...t]}function Zt(o){var e;return(e=window.CSS)!=null&&e.escape?CSS.escape(o):String(o).replace(/["\\]/g,"\\$&")}class Qt{constructor(e,{limit:t=60,delay:i=400}={}){this.root=e,this.limit=t,this.delay=i,this.stack=[],this.index=-1,this.timer=null,this.locked=!1,this.lastHtml=e.innerHTML}snapshot(e=!1){clearTimeout(this.timer);const t=()=>{const i=this.root.innerHTML;if(i===this.lastHtml)return;this.lastHtml=i;const n={html:i,offset:Fe(this.root)};this.stack=this.stack.slice(0,this.index+1),this.stack.push(n),this.stack.length>this.limit&&this.stack.shift(),this.index=this.stack.length-1};e?t():this.timer=setTimeout(t,this.delay)}flush(){clearTimeout(this.timer),this.snapshot(!0)}apply(e,t){this.locked=!0,this.root.innerHTML=e,this.lastHtml=e,t!=null&&Xt(this.root,t),this.locked=!1}canUndo(){return this.index>0}canRedo(){return this.index>=0&&this.index<this.stack.length-1}undo(){if(!this.canUndo())return!1;clearTimeout(this.timer),this.index-=1;const e=this.stack[this.index];return this.apply(e.html,this.currentOffset(e,"undo")),this.lastHtml=e.html,!0}redo(){if(!this.canRedo())return!1;const e=this.stack[this.index+1];return this.index+=1,this.apply(e.html,this.currentOffset(e,"redo")),this.lastHtml=e.html,!0}currentOffset(e){const t=Fe(this.root);return e.offset}reset(e){clearTimeout(this.timer),this.stack=[{html:e,offset:0}],this.index=0,this.lastHtml=e}destroy(){clearTimeout(this.timer),this.stack=[]}}const ei=/\.(jpe?g|png|gif|webp|bmp|svg|avif)$/i,ti=/\.(mp4|mov|webm|m4v|ogv|avi|mkv)$/i;class ii{constructor(e){this.editor=e,this.options=e.options,this.tasks=new Map,this.input=null}kindOf(e){const t=String(e.type||""),i=String(e.name||"");return t.startsWith("image/")||ei.test(i)?"image":t.startsWith("video/")||ti.test(i)?"video":null}check(e,t){if(!t)return`不支持的文件类型:${e.name||"剪贴板内容"}`;const i=t==="image"?this.options.maxImageSize:this.options.maxVideoSize;return i&&e.size>i?`${e.name} 超出大小限制(${R(i)})`:null}pickFiles(e){this.input||(this.input=l("input",{type:"file",multiple:!0,style:{display:"none"}}),this.input.addEventListener("change",()=>{const t=[...this.input.files||[]];this.input.value="",this.addFiles(t)}),document.body.appendChild(this.input)),this.input.accept=e==="image"?this.options.imageAccept:this.options.videoAccept,this.input.multiple=e==="image",this.input.click()}async addFiles(e){const t=[];for(const i of e){const n=this.kindOf(i),r=this.check(i,n);r?this.editor.toast.warn(r):t.push({file:i,kind:n})}for(const i of t)await this.upload(i.file,i.kind);return t.length}async upload(e,t){const i=t==="image"?this.createImageHolder():this.createVideoHolder();this.editor.focus(),P(this.editor.root,i);const n={id:i.dataset.kId,file:e,kind:t,holder:i,ctrl:new AbortController,previewUrl:URL.createObjectURL(e)};this.tasks.set(n.id,n),this.decorateHolder(n);const r=i.querySelector("[data-k-preview]");return r&&(r.src=n.previewUrl),this.runUpload(n)}async runUpload(e){const t=this.editor,{holder:i,file:n,kind:r}=e;t.emit("uploadstart",{file:n,kind:r}),t.refreshStatus();let s=n;try{r==="image"&&(s=await Ie(n,this.options.image));const a=await t.uploader.upload(s,{signal:e.ctrl.signal,onProgress:(d,h)=>this.updateProgress(i,d,h,s,e)}),c=typeof a=="string"?{url:a}:a;if(!(c!=null&&c.url))throw new Error("上传结果缺少 url");return this.finish(e,{...c,size:s.size}),t.emit("uploaddone",{file:n,kind:r,url:c.url}),c}catch(a){return(a==null?void 0:a.name)==="AbortError"?(this.remove(e),t.emit("uploadcancel",{file:n,kind:r}),null):(this.fail(e,a),t.emit("uploaderror",{file:n,kind:r,error:a}),t.toast.error((a==null?void 0:a.message)||"上传失败"),null)}finally{ee(t.root),t.commitHistory(),t.refreshStatus()}}createImageHolder(){const e=l("figure",{"data-k-media":"image","data-k-id":ie("m"),"data-k-state":"uploading",contenteditable:"false"}),t=l("div.ke-media-holder",{},[l("img",{"data-k-preview":"",alt:"",style:{display:"none"}}),l("div.ke-media-name",{text:"图片上传中…"}),De()]);return t.appendChild(this.actionRow()),e.appendChild(t),e}createVideoHolder(){const e=l("div.ke-video-card",{"data-k-media":"video","data-k-id":ie("m"),"data-k-state":"uploading",contenteditable:"false"}),t=l("div.ke-video-body",{},[l("div.ke-video-head",{},[l("span",{text:"视频上传中…"}),l("span.ke-video-size",{text:""})]),De()]);return t.appendChild(this.actionRow()),e.appendChild(t),e}actionRow(){const e=this;return l("div",{"data-k-actions":"",style:{display:"flex",alignItems:"center",gap:"8px",width:"100%",marginTop:"2px"},onclick:t=>{const i=t.target.closest("[data-k-id]"),n=i&&e.tasks.get(i.dataset.kId);n&&(t.target.matches(".ke-media-cancel")?(n.ctrl.abort(),e.remove(n)):t.target.matches(".ke-media-retry")&&(n.ctrl=new AbortController,e.resetHolder(n),e.runUpload(n)))}},[l("button.ke-media-cancel",{type:"button",text:"取消"})])}decorateHolder(e){const{holder:t,file:i}=e,n=t.querySelector(".ke-media-name");n&&(n.textContent=`${i.name||"未命名"}(${R(i.size)})`);const r=t.querySelector(".ke-video-size");r&&(r.textContent=R(i.size));const s=t.querySelector(".ke-video-head span");s&&e.kind==="video"&&(s.textContent=`${i.name||"视频"} 上传中…`)}resetHolder(e){const t=e.holder;t.dataset.kState="uploading";const i=t.querySelector(".ke-progress i");i&&(i.style.width="0%",i.style.background="");const n=t.querySelector(".ke-media-pct");n&&(n.textContent="0%");const r=t.querySelector("[data-k-actions]");r&&(r.innerHTML='<button class="ke-media-cancel" type="button">取消</button>'),this.decorateHolder(e)}updateProgress(e,t,i,n,r){const s=Math.max(0,Math.min(100,Math.round((t||0)*100))),a=e.querySelector(".ke-progress i");a&&(a.style.width=`${s}%`);const c=e.querySelector(".ke-media-pct");c&&(c.textContent=`${s}%`),r&&this.editor.emit("uploadprogress",{file:r.file,kind:r.kind,percent:s,info:i});const d=e.querySelector(".ke-media-meta");if(!d)return;let h=d.querySelector("[data-k-chunks]");h||(h=l("span",{"data-k-chunks":"",style:{color:"#8a8f99",fontSize:"12px"}}),d.insertBefore(h,d.firstChild)),(i==null?void 0:i.chunks)>1?h.textContent=`${i.chunks} 片 · ${R(i.loaded)}/${R(i.total||n.size)}`:i!=null&&i.speed&&(h.textContent=`${R(i.speed)}/s`)}finish(e,t){const{holder:i,kind:n,file:r}=e,s=t.url;if(i.dataset.kState="done",i.dataset.kUrl=s,i.innerHTML="",n==="image"){const a=l("img",{src:s,alt:oi(r),"data-k-name":r.name||"",draggable:"false"});a.addEventListener("dblclick",()=>J(a.src)),i.appendChild(a)}else{const a=l("video",{src:s,controls:"",playsinline:"",preload:"metadata","data-k-name":r.name||""}),c=l("div.ke-video-body",{},[l("div.ke-video-head",{},[l("span",{text:r.name||"视频"}),l("span.ke-video-size",{text:R(t.size||r.size)})]),a]);i.appendChild(c)}e.previewUrl&&URL.revokeObjectURL(e.previewUrl),this.tasks.delete(e.id),this.editor.refreshStatus()}fail(e,t){const i=e.holder;i.dataset.kState="error";const n=i.querySelector(".ke-progress i");n&&(n.style.background="#e53e3e");const r=i.querySelector("[data-k-actions]");r&&(r.innerHTML="",r.appendChild(l("span.ke-media-error",{text:(t==null?void 0:t.message)||"上传失败",style:{marginRight:"auto",fontSize:"12px"}})),r.appendChild(l("button.ke-media-retry",{type:"button",text:"重试"})),r.appendChild(l("button.ke-media-cancel",{type:"button",text:"移除"})))}remove(e){var t;(t=e.holder)==null||t.remove(),e.previewUrl&&URL.revokeObjectURL(e.previewUrl),this.tasks.delete(e.id),ee(this.editor.root),this.editor.refreshStatus()}taskFromNode(e){var i;const t=(i=e==null?void 0:e.closest)==null?void 0:i.call(e,"[data-k-id]");return t?this.tasks.get(t.dataset.kId):null}cancelAll(){for(const e of[...this.tasks.values()])e.ctrl.abort(),this.remove(e)}insertFromUrl(e,t,i=""){const n=e==="image"?this.insertImageUrl(t,i):this.insertVideoUrl(t,i||"网络视频");return this.editor.toast.ok(e==="image"?"已插入网络图片":"已插入网络视频"),this.editor.emit("insertmedia",{kind:e,url:t,node:n}),n}insertImageUrl(e,t=""){const i=l("img",{src:e,alt:t||"",draggable:"false"});i.addEventListener("dblclick",()=>J(i.src));const n=l("figure",{"data-k-media":"image","data-k-state":"done","data-k-url":e,contenteditable:"false"},[i]);return P(this.editor.root,n),this.editor.commitHistory(),n}insertVideoUrl(e,t="视频"){const i=l("video",{src:e,controls:"",playsinline:"",preload:"metadata"}),n=l("div.ke-video-card",{"data-k-media":"video","data-k-state":"done","data-k-url":e,contenteditable:"false"},[l("div.ke-video-body",{},[l("div.ke-video-head",{},[l("span",{text:t})]),i])]);return P(this.editor.root,n),this.editor.commitHistory(),n}destroy(){var e;this.cancelAll(),(e=this.input)==null||e.remove(),this.input=null}}function oi(o){return String(o.name||"").replace(/\.[^.]+$/,"")}function De(){return l("div.ke-media-meta",{},[l("div.ke-progress",{},[l("i",{style:{width:"0%"}})]),l("span.ke-media-pct",{text:"0%"})])}async function Ie(o,e={}){var s,a;const t=e==null?void 0:e.compress;if(!t||!/^image\/(jpeg|jpg|png|webp)$/i.test(o.type))return o;const{maxWidth:i=1440,quality:n=.85,minSize:r=300*1024}=typeof t=="object"?t:{};if(o.size<r)return o;try{const c=await createImageBitmap(o);if(c.width<=i)return(s=c.close)==null||s.call(c),o;const d=document.createElement("canvas");d.width=i,d.height=Math.round(c.height*i/c.width),d.getContext("2d").drawImage(c,0,0,d.width,d.height),(a=c.close)==null||a.call(c);const h=await new Promise(p=>d.toBlob(p,"image/jpeg",n));return!h||h.size>=o.size?o:new File([h],String(o.name).replace(/\.\w+$/,".jpg"),{type:"image/jpeg",lastModified:o.lastModified})}catch{return o}}function ke(o){return`${Ue(o.size)}-${ni(o.lastModified)}-${ri(o.name)}`}async function qe(o){var a;if(!((a=globalThis.crypto)!=null&&a.subtle))return ke(o);const e=256*1024,t=[o.slice(0,e)];o.size>e&&t.push(o.slice(o.size-e));const i=new Uint8Array(t.reduce((c,d)=>c+d.size,0));let n=0;for(const c of t){const d=new Uint8Array(await c.arrayBuffer());i.set(d,n),n+=d.length}const r=await crypto.subtle.digest("SHA-256",i);return`${Array.from(new Uint8Array(r)).map(c=>c.toString(16).padStart(2,"0")).join("").slice(0,24)}-${Ue(o.size)}`}const Ue=o=>Number(o).toString(16),ni=o=>Number(o||0).toString(16),ri=o=>String(o).replace(/[^\w.-]/g,"").slice(0,24);function si(o="fast"){return o==="strong"||o==="sha256"?qe:typeof o=="function"?o:async e=>ke(e)}const ai=1024*1024;class j{constructor(e,t={}){if(!e||typeof e.put!="function")throw new Error("[KEditor] uploader 需要提供 put() 方法,参见 docs/upload-adapter.md");this.adapter=e,this.chunkSize=Math.max(64*1024,t.chunkSize||ai),this.concurrency=Math.max(1,t.concurrency||3),this.retries=t.retries===void 0?2:Math.max(0,t.retries),this.retryDelay=t.retryDelay??600,this.fingerprint=si(t.fingerprint||"fast"),this.slice=t.slice}async upload(e,t={}){var x,g,$,Qe,et,tt;const{onProgress:i,onChunk:n,signal:r}=t;if(this.adapter.simple)return this.uploadSimple(e,t);const s=Math.max(1,Math.ceil(e.size/this.chunkSize)),a={name:e.name||"blob",size:e.size,type:e.type||ci(e.name),lastModified:e.lastModified||0,fingerprint:await this.fingerprint(e),chunkSize:this.chunkSize,totalChunks:s},c=await((g=(x=this.adapter).init)==null?void 0:g.call(x,a,{signal:r}))||{};if(c.url)return i==null||i(1,{percent:100,loaded:e.size,total:e.size,chunks:s,instant:!0}),{url:c.url,instant:!0,chunks:0,size:e.size,name:a.name,key:c.key};const d=c.uploadId||a.fingerprint,h=new Set((c.uploadedChunks||c.uploaded||[]).map(Number));let p=0;for(const w of h)p+=Math.min(this.chunkSize,e.size-w*this.chunkSize);const u=[];for(let w=0;w<s;w+=1)h.has(w)||u.push(w);const k=new Array(s);let f=h.size;const y=Date.now(),v=()=>{const w=(Date.now()-y)/1e3;i==null||i(e.size?p/e.size:1,{percent:Math.min(100,Math.round(p/Math.max(1,e.size)*100)),loaded:p,total:e.size,chunks:s,uploadedChunks:f,speed:w>0?p/w:0})};v();let C=0,S=null;const A=async()=>{for(;C<u.length;){if(r!=null&&r.aborted)throw new DOMException("已取消上传","AbortError");const w=u[C++],te=this.slice?this.slice(e,w,this.chunkSize):e.slice(w*this.chunkSize,(w+1)*this.chunkSize);let ye=0;for(;;)try{const L=await this.adapter.put({uploadId:d,index:w,total:s,chunkSize:this.chunkSize,blob:te,file:e,meta:a,signal:r,size:te.size});L!=null&&L.url&&(k[w]=L),p+=te.size,f+=1,n==null||n({index:w,total:s,size:te.size}),v();break}catch(L){if((L==null?void 0:L.name)==="AbortError")throw L;if(ye+=1,ye>this.retries)throw S=L,new Error(`分片 ${w+1}/${s} 上传失败:${(L==null?void 0:L.message)||L}`);await li(this.retryDelay*ye,r)}}},H=Array.from({length:Math.max(1,Math.min(this.concurrency,u.length))},A);try{await Promise.all(H)}catch(w){throw await((Qe=($=this.adapter).abort)==null?void 0:Qe.call($,{uploadId:d,meta:a,error:w}).catch(()=>{})),w}if(S)throw S;const E=await((tt=(et=this.adapter).complete)==null?void 0:tt.call(et,{uploadId:d,meta:a,total:s,uploaded:f,chunkResults:k,file:e}))||{},m=E.url;if(!m)throw new Error("[KEditor] uploader.complete() 未返回 url");return{url:m,chunks:s,size:e.size,name:a.name,key:E.key,poster:E.poster,duration:E.duration,raw:E}}async uploadSimple(e,t={}){const{onProgress:i,signal:n}=t,r=Date.now(),s=await this.adapter.upload(e,{signal:n,onProgress:(c,d)=>{const h=d?c/d:0,p=(Date.now()-r)/1e3;i==null||i(h,{percent:Math.round(h*100),loaded:c,total:d||e.size,chunks:1,uploadedChunks:h>=1?1:0,speed:p>0?c/p:0})}}),a=typeof s=="string"?s:s==null?void 0:s.url;if(!a)throw new Error("[KEditor] uploader.upload() 未返回 url");return{url:a,chunks:1,size:e.size,name:e.name,key:typeof s=="object"?s.key:void 0,raw:s}}destroy(){var e,t;(t=(e=this.adapter).destroy)==null||t.call(e)}}const li=(o,e)=>new Promise((t,i)=>{const n=setTimeout(()=>{e==null||e.removeEventListener("abort",r),t()},o),r=()=>{clearTimeout(n),i(new DOMException("已取消上传","AbortError"))};e==null||e.addEventListener("abort",r,{once:!0})});function ci(o=""){var i;const e=(i=String(o).split(".").pop())==null?void 0:i.toLowerCase();return{jpg:"image/jpeg",jpeg:"image/jpeg",png:"image/png",gif:"image/gif",webp:"image/webp",svg:"image/svg+xml",mp4:"video/mp4",mov:"video/quicktime",webm:"video/webm",m4v:"video/x-m4v"}[e]||"application/octet-stream"}function We(o){return{simple:!0,async upload(e,t={}){const i=await o(di(e),t);return typeof i=="string"?{url:i}:i}}}function di(o,e="blob",t=o.type){return o instanceof File?o:new File([o],e,{type:t})}const ge=o=>new Promise(e=>setTimeout(e,o)),hi=(o,e=.4)=>o*(1-e+Math.random()*e*2);function _e(o={}){const{latency:e=160,speed:t=12,onEvent:i=null,reuseObjectUrl:n=!0,failFirstChunk:r=!1}=o,s=new Map,a=new Map,c=new Map;let d=r;const h=(p,u)=>i==null?void 0:i(p,{...u,at:Date.now()});return{name:"mock",async init(p){h("init",p),await ge(120);const u=s.get(p.fingerprint);if(u)return h("instant",{name:p.name,url:u.url}),{url:u.url,key:p.fingerprint,instant:!0};const k=a.get(p.fingerprint)||new Set;return a.set(p.fingerprint,k),{uploadId:p.fingerprint,uploadedChunks:[...k]}},async put({uploadId:p,index:u,total:k,size:f,blob:y}){if(d&&u===0){d=!1,h("chunk-error",{index:u,total:k,message:"mock: 模拟首个分片网络异常"});const S=new Error("mock: 模拟首个分片网络异常");throw S.retryable=!0,S}const v=Math.max(40,hi(e+f/(t*1024/8)/8,.35));await ge(v);const C=a.get(p)||new Set;return C.add(u),a.set(p,C),h("chunk",{index:u,total:k,size:f,blobSize:y==null?void 0:y.size}),{etag:`${p}-${u}`}},async complete({uploadId:p,meta:u,file:k}){await ge(140);let f=c.get(u.fingerprint);if(!f||!n){const y=k instanceof File?k:new File([k],u.name,{type:u.type});f=URL.createObjectURL(y),c.set(u.fingerprint,f)}return s.set(u.fingerprint,{url:f,name:u.name,size:u.size,type:u.type}),a.delete(p),h("complete",{name:u.name,url:f,chunks:u.totalChunks,size:u.size}),{url:f,key:u.fingerprint}},async abort({uploadId:p}){h("abort",{uploadId:p})},list:()=>[...s.entries()].map(([p,u])=>({key:p,...u})),reset:()=>{s.clear(),a.clear()}}}function Ve(o={}){const{initUrl:e,chunkUrl:t,completeUrl:i,abortUrl:n,mode:r="raw",fieldName:s="file",headers:a={},withCredentials:c=!1,parse:d=k=>(k==null?void 0:k.data)||k||{},chunkUrlFor:h}=o,p=()=>typeof a=="function"?a()||{}:a||{},u=async(k,f={})=>{const y=await fetch(k,{credentials:c?"include":"same-origin",...f});if(!y.ok)throw new Error(`HTTP ${y.status} ${y.statusText}`);const v=await y.text();if(!v)return{};try{return d(JSON.parse(v))}catch{throw new Error(`服务端返回非 JSON 数据:${v.slice(0,80)}`)}};return{name:"http",async init(k,{signal:f}){if(!e)throw new Error("[KEditor] httpAdapter 缺少 initUrl");return u(e,{method:"POST",signal:f,headers:{"Content-Type":"application/json",...p()},body:JSON.stringify({fileName:k.name,fileSize:k.size,fileType:k.type,lastModified:k.lastModified,identifier:k.fingerprint,chunkSize:k.chunkSize,totalChunks:k.totalChunks})})},async put({uploadId:k,index:f,total:y,blob:v,meta:C,signal:S}){if(!t)throw new Error("[KEditor] httpAdapter 缺少 chunkUrl");const A=typeof h=="function"?h({uploadId:k,index:f}):t;if(r==="formdata"){const m=new FormData;return m.append(s,v,`${C.name}.part${f}`),m.append("uploadId",k),m.append("identifier",C.fingerprint),m.append("index",String(f)),m.append("total",String(y)),m.append("filename",C.name),u(A,{method:"POST",body:m,signal:S,headers:p()})}const H=A.includes("?")?"&":"?",E=`${A}${H}uploadId=${encodeURIComponent(k)}&index=${f}&total=${y}&filename=${encodeURIComponent(C.name)}`;return u(E,{method:"PUT",body:v,signal:S,headers:{"Content-Type":"application/octet-stream","X-Chunk-Index":String(f),...p()}})},async complete({uploadId:k,meta:f,total:y}){if(!i)throw new Error("[KEditor] httpAdapter 缺少 completeUrl");return u(i,{method:"POST",headers:{"Content-Type":"application/json",...p()},body:JSON.stringify({uploadId:k,identifier:f.fingerprint,fileName:f.name,fileSize:f.size,fileType:f.type,chunkSize:f.chunkSize,totalChunks:y})})},async abort({uploadId:k}){n&&await u(n,{method:"POST",headers:{"Content-Type":"application/json",...p()},body:JSON.stringify({uploadId:k})}).catch(()=>{})}}}function Ke(o="mock",e={}){if(o instanceof j)return o;if(typeof o=="function"&&!o.put)return new j(We(o),e);if(o&&typeof o=="object"&&!(o instanceof j)){if(typeof o.put=="function"||typeof o.upload=="function")return new j(o,{...e,...Ge(o)});if(o.type==="http")return new j(Ve(o),{...e,...Ge(o)})}return new j(_e(typeof o=="object"?o:{}),e)}const Ge=o=>{const e={};for(const t of["chunkSize","concurrency","retries","fingerprint"])o[t]!==void 0&&(e[t]=o[t]);return e};function pi(o){o.root.addEventListener("paste",async e=>{if(o.readOnly||!o.options.paste.enabled)return;const t=e.clipboardData;if(!t)return;e.preventDefault();const i=ui(t);if(i.length){o.options.paste.uploadFiles?(await o.media.addFiles(i),o.toast.show(`已上传 ${i.length} 个文件`)):o.toast.warn("当前配置不允许粘贴上传文件");return}const n=t.getData("text/html"),r=t.getData("text/plain");if(n&&o.options.paste.clean){let s=Me(n)?ze(n):n;s=K(s,{allowEmpty:!0}),o.options.paste.localizeImages&&(s=await ki(o,s)),o.commands.insertHTML(s,{clean:!1}),Me(n)&&o.toast.show("已清理 Word/WPS 格式")}else if(r){const s=r.split(/\r?\n/).map(a=>`<p>${ce(a)||"<br>"}</p>`).join("");o.commands.insertHTML(s,{clean:!1})}})}function ui(o){var t,i;const e=[];if((t=o.items)!=null&&t.length){for(const n of o.items)if(n.kind==="file"){const r=n.getAsFile();r&&e.push(Xe(r,e.length))}}return!e.length&&((i=o.files)!=null&&i.length)&&e.push(...Array.from(o.files).map((n,r)=>Xe(n,r))),e}function Xe(o,e){if(o.name&&o.name!=="image.png")return o;const t=(o.type.split("/")[1]||"png").replace("jpeg","jpg").replace("+xml",""),i=new Date().toISOString().slice(11,19).replace(/:/g,"");return new File([o],`pasted-${i}-${e}.${t}`,{type:o.type,lastModified:o.lastModified})}function fi(o){const e=o.root;let t=0;const i=n=>{var r;return Array.from(((r=n.dataTransfer)==null?void 0:r.types)||[]).includes("Files")};e.addEventListener("dragenter",n=>{!i(n)||o.readOnly||(n.preventDefault(),t+=1,o.el.classList.add("ke-is-dragover"))}),e.addEventListener("dragover",n=>{!i(n)||o.readOnly||(n.preventDefault(),n.dataTransfer.dropEffect="copy")}),e.addEventListener("dragleave",n=>{i(n)&&(t=Math.max(0,t-1),t===0&&o.el.classList.remove("ke-is-dragover"))}),e.addEventListener("drop",async n=>{if(!i(n)||o.readOnly)return;n.preventDefault(),t=0,o.el.classList.remove("ke-is-dragover"),mi(o,n);const r=[...n.dataTransfer.files||[]];if(r.length&&o.options.paste.uploadFiles){const s=await o.media.addFiles(r);s&&o.toast.show(`已上传 ${s} 个文件`)}})}function mi(o,e){let t=null;if(document.caretRangeFromPoint)t=document.caretRangeFromPoint(e.clientX,e.clientY);else if(document.caretPositionFromPoint){const i=document.caretPositionFromPoint(e.clientX,e.clientY);i&&(t=document.createRange(),t.setStart(i.offsetNode,i.offset),t.collapse(!0))}if(t&&o.root.contains(t.commonAncestorContainer)){const i=window.getSelection();i.removeAllRanges(),i.addRange(t)}else o.focus()}async function ki(o,e){const t=new DOMParser().parseFromString(`<div>${e}</div>`,"text/html"),i=[...t.body.querySelectorAll("img")].filter(n=>/^https?:/i.test(n.getAttribute("src")||""));for(const n of i)try{const r=await fetch(n.src,{mode:"cors"});if(!r.ok)continue;const s=await r.blob(),a=new File([s],n.alt||`remote-${Date.now()}.jpg`,{type:s.type||"image/jpeg"}),c=await o.media.upload(a,"image");n.remove(),c!=null&&c.url&&o.toast.show("外链图片已本地化")}catch{}return t.body.innerHTML.trim()}const Je=1024,be=1024*Je,F={value:"",placeholder:"开始撰写内容,支持拖拽 / 粘贴图片与视频…",height:460,minHeight:320,primaryColor:"#07c160",paperWidth:677,paperMode:"fluid",paperGap:24,paperMaxWidth:0,toolbar:Q,customButtons:[],hideToolbar:!1,hideStatusbar:!1,readOnly:!1,autofocus:!1,maxLength:0,wordCount:!0,sanitize:!0,historyLimit:60,uploader:"mock",upload:{chunkSize:be,concurrency:3,retries:2,fingerprint:"fast"},image:{compress:{maxWidth:1440,quality:.85,minSize:300*Je}},maxImageSize:20*be,maxVideoSize:512*be,imageAccept:"image/png,image/jpeg,image/gif,image/webp,image/bmp,image/svg+xml,image/avif",videoAccept:"video/mp4,video/quicktime,video/webm,video/x-m4v,video/ogg",paste:{enabled:!0,clean:!0,uploadFiles:!0,localizeImages:!1},onChange:null,onReady:null,onError:null,onUpload:null,beforeUpload:null,toolbarFloat:!1};let gi=0;class X{constructor(e,t={}){it(),this.options=yi(t),this.id=`ke-${gi+=1}`,this.el=xi(e,this.id),this.el.__keditor__=this;const i=this.el.innerHTML;this.emitters=new Map,this.domListeners=[],this.destroyed=!1,this.sourceMode=!1,this.previewMode=!1,this.fullscreen=!1,this.readOnly=!1,this.buildDOM(),this.toast=new vt,this.popover=new st(this.el),this.commands=new Jt(this),this.uploader=Ke(this.options.uploader,this.options.upload),this.media=bi(this),this.history=new Qt(this.root,{limit:this.options.historyLimit}),this.toolbar=new Kt(this,this.options.toolbar,this.options.customButtons),this.source=new xt(this),this.previewPanel=new yt(this),this.bubble=new wt(this),this.mainEl.append(this.source.el,this.previewPanel.el),this.applyTheme(),this.setContent(this.options.value||i,{sanitize:this.options.sanitize,silent:!0}),this.bindEvents(),this.setReadOnly(this.options.readOnly),this.refresh(),this.refreshStatus(),this.history.reset(this.root.innerHTML),queueMicrotask(()=>{var n,r;this.destroyed||(this.emit("ready",{editor:this}),(r=(n=this.options).onReady)==null||r.call(n,this),this.options.autofocus&&this.focus())})}buildDOM(){this.el.classList.add("ke"),this.el.id=this.el.id||this.id,this.el.innerHTML="",this.tbEl=l("div.ke-tb",{role:"toolbar","aria-label":"编辑器工具栏"}),this.scrollEl=l("div.ke-scroll"),this.paperEl=l("div.ke-paper"),this.root=l("div.ke-content",{contenteditable:this.readOnly?"false":"true",role:"textbox","aria-multiline":"true",spellcheck:"false","data-placeholder":this.options.placeholder,"data-ke-root":""}),this.root.style.minHeight=`${this.options.minHeight}px`,this.paperEl.appendChild(this.root),this.scrollEl.appendChild(this.paperEl),this.mainEl=l("div.ke-main",{},[this.scrollEl]),this.statusEl=Ci(this),this.dropzoneEl=l("div.ke-dropzone",{},[l("span",{text:"松开即可上传(分片传输)"})]),this.options.hideToolbar||this.el.appendChild(this.tbEl),this.el.appendChild(this.mainEl),this.options.hideStatusbar||this.el.appendChild(this.statusEl),this.el.appendChild(this.dropzoneEl),this.options.height&&(this.scrollEl.style.height=`${this.options.height}px`,this.scrollEl.style.maxHeight=`${this.options.height}px`),this.paperEl.style.setProperty("--ke-min-height",`${this.options.minHeight}px`),this.applyPaper()}applyPaper(){const{paperWidth:e,paperMode:t,paperGap:i,paperMaxWidth:n}=this.options;this.paperEl.style.setProperty("--ke-paper",`${e}px`),this.paperEl.style.setProperty("--ke-paper-gap",`${i}px`),n>0?this.paperEl.style.setProperty("--ke-paper-max",`${n}px`):this.paperEl.style.removeProperty("--ke-paper-max"),this.paperEl.classList.toggle("ke-is-fluid",t!=="fixed")}setPaper(e={}){return e.width!==void 0&&(this.options.paperWidth=I(Number(e.width)||0,200,8e3)),e.mode!==void 0&&(this.options.paperMode=e.mode==="fixed"?"fixed":"fluid"),e.gap!==void 0&&(this.options.paperGap=I(Number(e.gap)||0,0,600)),e.maxWidth!==void 0&&(this.options.paperMaxWidth=Math.max(0,Number(e.maxWidth)||0)),this.applyPaper(),{...this.paperOptions()}}paperOptions(){const{paperWidth:e,paperMode:t,paperGap:i,paperMaxWidth:n}=this.options;return{width:e,mode:t,gap:i,maxWidth:n}}applyTheme(){this.options.primaryColor&&this.el.style.setProperty("--ke-primary",this.options.primaryColor)}bindEvents(){const e=ot(()=>this.emitChange(),160);this.bind(this.root,"input",()=>{this.history.snapshot(),this.refreshStatus(),this.togglePlaceholder(),e(),this.enforceMaxLength()}),this.bind(this.root,"keydown",t=>this.handleKeydown(t)),this.bind(this.root,"blur",()=>{this.history.flush(),this.el.classList.remove("ke-is-focus"),this.emit("blur")}),this.bind(this.root,"focus",()=>{this.el.classList.add("ke-is-focus"),this.emit("focus")}),this.bind(this.root,"click",t=>this.handleContentClick(t)),this.bind(this.root,"dblclick",t=>{const i=t.target.closest("img");i&&this.root.contains(i)&&J(i.src)}),pi(this),fi(this),this.selectionHandler=()=>{!this.root.contains(document.activeElement)&&document.activeElement!==this.root||(this.refresh(),this.syncBubble())},document.addEventListener("selectionchange",this.selectionHandler),this.scrollHandler=()=>this.bubble.position(),this.bind(this.scrollEl,"scroll",this.scrollHandler),window.addEventListener("resize",this.scrollHandler)}bind(e,t,i){return e.addEventListener(t,i),this.domListeners.push({node:e,type:t,handler:i}),i}handleKeydown(e){const t=e.metaKey||e.ctrlKey,i=e.key.toLowerCase();if(t&&i==="z"){e.preventDefault(),e.shiftKey?this.redo():this.undo();return}if(t&&i==="y"){e.preventDefault(),this.redo();return}if(t&&["b","i","u"].includes(i)){e.preventDefault(),this.commands.toggleMark({b:"bold",i:"italic",u:"underline"}[i]),this.refresh();return}if(t&&e.shiftKey&&i==="k"){e.preventDefault(),this.toggleSource();return}if(t&&i==="k"){e.preventDefault(),this.toolbar.openLink();return}if(t&&i==="s"){e.preventDefault(),this.emit("save",{html:this.getHTML()});return}if(e.key==="Escape"){this.popover.close(),this.bubble.hide(),this.previewMode&&this.closePreview();return}(e.key==="Backspace"||e.key==="Delete")&&this.bubble.node&&(e.preventDefault(),this.bubble.remove())}handleContentClick(e){const t=e.target.closest("[data-k-media]");if(t&&this.root.contains(t)){this.selectMedia(t);return}this.clearMediaSelection(),this.bubble.hide()}selectMedia(e){this.clearMediaSelection(),e.classList.add("ke-is-selected-media"),this.bubble.show(e),this.refreshStatus()}clearMediaSelection(){this.root.querySelectorAll(".ke-is-selected-media").forEach(e=>e.classList.remove("ke-is-selected-media")),this.bubble.hide()}syncBubble(){!this.bubble.node||!this.root.contains(this.bubble.node)?this.bubble.hide():this.bubble.position()}getState(){var a,c,d;const e=z(this.root),t=N((e==null?void 0:e.commonAncestorContainer)||this.root,this.root),i=e?Si(e,this.root):null,n=(a=this.bubble)==null?void 0:a.node,r=n&&((c=n.dataset)==null?void 0:c.kMedia)==="image"?n.querySelector("img"):null,s=r?oe(r):Ei(e,t);return{bold:this.queryState("bold"),italic:this.queryState("italic"),underline:this.queryState("underline"),strikeThrough:this.queryState("strikeThrough"),ul:this.queryState("insertUnorderedList"),ol:this.queryState("insertOrderedList"),align:s,block:((d=t==null?void 0:t.tagName)==null?void 0:d.toLowerCase())||"p",fontSize:this.commands.currentFontSize(),linkUrl:i?i.getAttribute("href"):"",linkTarget:i?i.getAttribute("target")==="_blank":!1,selectionText:e?e.toString():"",canUndo:this.history.canUndo(),canRedo:this.history.canRedo(),source:this.sourceMode,preview:this.previewMode,fullscreen:this.fullscreen,readOnly:this.readOnly}}queryState(e){var t;if(!this.root.contains(((t=window.getSelection())==null?void 0:t.anchorNode)||null))return!1;try{return document.queryCommandState(e)}catch{return!1}}refresh(){if(!this.destroyed)try{this.toolbar.refresh(this.getState())}catch{}}refreshStatus(){const e=this.statusApi;e&&e.update(this.counts())}counts(){const e=Te(this.root.innerHTML);return{chars:e.replace(/\s/g,"").length,words:Li(e),images:this.root.querySelectorAll("img").length,videos:this.root.querySelectorAll('[data-k-media="video"] video, video').length,uploading:this.media?this.media.tasks.size:0}}togglePlaceholder(){const e=!this.root.textContent.trim()&&!this.root.querySelector("img,video,hr,table,iframe");this.root.classList.toggle("ke-is-empty",e)}enforceMaxLength(){var i,n;const e=this.options.maxLength;if(!e)return;const{chars:t}=this.counts();t>e?(this.toast.warn(`已超过建议字数 ${e}`),(i=this.statusEl)==null||i.classList.add("ke-is-over")):(n=this.statusEl)==null||n.classList.remove("ke-is-over")}getHTML({clean:e=!0}={}){const t=this.root.innerHTML;return e?Ze(t):t}getText(){return Te(this.root.innerHTML)}getJSON(){return{html:this.getHTML(),text:this.getText(),counts:this.counts()}}setContent(e,{sanitize:t=this.options.sanitize,silent:i=!1}={}){const n=K(e||"<p><br></p>",{allowEmpty:!0});return this.root.innerHTML=n||"<p><br></p>",this.afterEdit({silent:i}),i||this.history.snapshot(!0),this.togglePlaceholder(),this}appendHTML(e){const t=document.createRange();t.selectNodeContents(this.root),t.collapse(!1);const i=window.getSelection();return i.removeAllRanges(),i.addRange(t),this.commands.insertHTML(e),this}clear(){return this.media.cancelAll(),this.setContent("<p><br></p>"),this.focus(),this}afterEdit({silent:e=!1}={}){this.history.snapshot(),this.refreshStatus(),this.togglePlaceholder(),e||this.emitChange()}commitHistory(){this.history.snapshot(!0),this.refreshStatus(),this.emitChange()}emitChange(){var e,t;this.emit("change",{html:this.getHTML(),text:this.getText()}),(t=(e=this.options).onChange)==null||t.call(e,this.getHTML(),this)}focus(){if(this.readOnly||this.sourceMode)return this.sourceMode&&this.source.code.focus(),this;this.root.focus();const e=window.getSelection();if(!e||e.rangeCount===0||!this.root.contains(e.anchorNode)){const t=document.createRange(),i=this.root.firstElementChild||this.root;t.selectNodeContents(i),t.collapse(!1),e.removeAllRanges(),e.addRange(t)}return this}blur(){return this.root.blur(),this}saveSelection(){const e=z(this.root);return this.savedRange=e?e.cloneRange():null,this}restoreSelection(){this.root.focus();const e=window.getSelection();return this.savedRange&&this.root.contains(this.savedRange.startContainer)&&this.root.contains(this.savedRange.endContainer)?(e.removeAllRanges(),e.addRange(this.savedRange),this):this.focus()}setReadOnly(e){return this.readOnly=!!e,this.root.setAttribute("contenteditable",this.readOnly?"false":"true"),this.el.classList.toggle("ke-is-readonly",this.readOnly),this.refresh(),this}undo(){return this.history.flush(),this.history.undo()?(this.afterEdit({silent:!1}),this.refresh(),this):(this.toast.show("没有可撤销的操作"),this)}redo(){return this.history.redo()?(this.afterEdit(),this.refresh(),this):(this.toast.show("没有可重做的操作"),this)}upload(e,t=this.media.kindOf(e)){if(!t)throw new Error("[KEditor] 不支持的文件类型");return this.media.upload(e,t)}insertImage(e,t=""){return this.media.insertImageUrl(e,t)}insertVideo(e,t="视频"){return this.media.insertVideoUrl(e,t)}cancelUploads(){return this.media.cancelAll(),this}addButton(e,t){return this.toolbar.addButton(e,t)}moveButton(e,t){return this.toolbar.moveButton(e,t)}removeButton(e){return this.toolbar.removeButton(e)}setButtonOptions(e,t){return this.toolbar.setButtonOptions(e,t)}getButtonValue(e){return this.toolbar.getButtonValue(e)}setButtonValue(e,t){return this.toolbar.setButtonValue(e,t)}reportError(e,t){var r,s,a;const i=t&&t.message?t.message:String(t),n={type:e,error:t instanceof Error?t:new Error(i),message:i};return(r=this.toast)==null||r.error(i),this.emit("error",n),(a=(s=this.options).onError)==null||a.call(s,n),this}toggleSource(){return this.sourceMode?this.exitSource():this.enterSource(),this.sourceMode}enterSource(){this.sourceMode||(this.history.flush(),this.sourceMode=!0,this.el.classList.add("ke-is-source"),this.clearMediaSelection(),this.source.show(this.getHTML({clean:!0})),this.previewPanel.hide(),this.previewMode=!1,this.refresh(),this.emit("sourcechange",{mode:"source"}))}exitSource(){this.sourceMode&&(this.source.apply({silent:!0}),this.sourceMode=!1,this.el.classList.remove("ke-is-source"),this.source.hide(),this.focus(),this.refresh(),this.emit("sourcechange",{mode:"visual"}))}togglePreview(){return this.previewMode?this.closePreview():this.openPreview(),this.previewMode}openPreview(){this.previewMode=!0,this.previewPanel.show(Mi(this.getHTML())),this.refresh()}closePreview(){this.previewMode=!1,this.previewPanel.hide(),this.refresh()}toggleFullscreen(){return this.fullscreen=!this.fullscreen,this.el.classList.toggle("ke-is-fullscreen",this.fullscreen),document.body.style.overflow=this.fullscreen?"hidden":"",this.refresh(),this.fullscreen}on(e,t){return this.addListener(e,t)}off(e,t){return this.removeListener(e,t)}emit(e,t={}){var n,r,s,a;const i=this.emitters.get(e)||[];for(const c of i)try{c(t)}catch(d){(r=(n=this.options).onError)==null||r.call(n,d)}return e.startsWith("upload")&&((a=(s=this.options).onUpload)==null||a.call(s,{stage:e,...t})),this}addListener(e,t){return this.emitters.has(e)||this.emitters.set(e,[]),this.emitters.get(e).push(t),()=>this.removeListener(e,t)}removeListener(e,t){const i=this.emitters.get(e)||[],n=i.indexOf(t);return n>=0&&i.splice(n,1),this}get element(){return this.root}get editorElement(){return this.el}destroy(){if(!this.destroyed){this.destroyed=!0,this.media.destroy(),this.history.destroy(),this.popover.destroy(),this.source.destroy(),this.previewPanel.destroy(),this.bubble.destroy(),this.toolbar.destroy(),this.toast.destroy();for(const{node:e,type:t,handler:i}of this.domListeners)e.removeEventListener(t,i);document.removeEventListener("selectionchange",this.selectionHandler),this.scrollEl.removeEventListener("scroll",this.scrollHandler),window.removeEventListener("resize",this.scrollHandler),this.fullscreen&&(document.body.style.overflow=""),this.el.__keditor__===this&&(this.el.__keditor__=null),this.el.innerHTML="",this.el.classList.remove("ke","ke-is-fullscreen","ke-is-readonly"),this.el.removeAttribute("style"),this.emitters.clear()}}static create(e,t){return new X(e,t)}}function bi(o){const e=new ii(o),t=e.upload.bind(e);return e.upload=async(i,n)=>{const r=o.options.beforeUpload;let s=i;return r&&(s=await r(i,n),s===!1)?null:t(s,n)},e.replaceNode=async(i,n)=>{const r=i.dataset.kMedia==="video"?"video":"image",s=document.createRange();s.setStartBefore(i),s.collapse(!0);const a=window.getSelection();a.removeAllRanges(),a.addRange(s);const c=await e.upload(n,r);return i.remove(),o.commitHistory(),c},e}function xi(o,e){if(typeof o=="string"){const t=document.querySelector(o);if(!t)throw new Error(`[KEditor] 找不到挂载节点:${o}`);return t}if(o instanceof HTMLElement)return o;if((o==null?void 0:o.$el)instanceof HTMLElement)return o.$el;throw new Error(`[KEditor] 无效的挂载目标(${typeof o})`)}function yi(o){const e={...F,...o};return e.image={...F.image,...o.image||{}},e.paste={...F.paste,...o.paste||{}},e.upload={...F.upload,...o.upload||{}},e.customButtons=Be(o.customButtons),Array.isArray(o.toolbar)&&(e.toolbar=o.toolbar),o.toolbar===!1&&(e.toolbar=[]),o.toolbar===!0&&(e.toolbar=Q),e.customButtons.length&&o.toolbar!==!1&&(e.toolbar=wi(e.toolbar,e.customButtons)),e.height=I(e.height??460,0,4e3),e.paperWidth=I(Number(e.paperWidth)||F.paperWidth,200,8e3),e.paperMode=e.paperMode==="fixed"?"fixed":"fluid",e.paperGap=Number.isFinite(Number(e.paperGap))?I(Number(e.paperGap),0,600):F.paperGap,e.paperMaxWidth=Math.max(0,Number(e.paperMaxWidth)||0),e}const vi=o=>o!=="|"&&o!==":tail";function wi(o,e){const t=[...o],i=[];for(const n of e)if(!t.includes(n.name)){if(n.position==null){i.push(n.name);continue}t.splice(Ye(t,n.position),0,n.name)}return i.length&&t.splice(Ye(t,null),0,"|",...i),t}function Ye(o,e){const t=(()=>{const s=o.indexOf(":tail");return s<0?o.length:s})();if(e==null||e==="end")return t;if(e==="start")return 0;if(e==="tail")return o.length;if(typeof e=="number"){let s=0;for(let a=0;a<o.length;a++)if(vi(o[a])){if(s===Math.max(0,Math.floor(e)))return a;s++}return t}const i=!!(e&&typeof e=="object"&&e.after),n=String(typeof e=="string"?e:(i?e.after:e.before)||""),r=o.indexOf(n);return r<0?t:i?r+1:r}function Ci(o){const e=l("b",{text:"0"}),t=l("b",{text:"0"}),i=l("b",{text:"0"}),n=l("b",{text:"0"}),r=l("span.ke-chip",{hidden:!0}),s=l("span.ke-status-hint",{text:"支持拖拽 / 粘贴上传,Ctrl/⌘ + S 保存"}),a=l("span.ke-status-tail"),c=l("div.ke-status",{},[l("span",{},["字数 ",e," · ",t," 词"]),l("span",{},["图片 ",i," · 视频 ",n]),r,s,a]),d={update:h=>{e.textContent=String(h.chars),t.textContent=String(h.words),i.textContent=String(h.images),n.textContent=String(h.videos),h.uploading>0?(r.hidden=!1,r.className="ke-chip ke-is-busy",r.textContent=`${h.uploading} 个上传进行中`):r.hidden=!0},addExtra:h=>a.appendChild(h)};return o.statusApi=d,o.options.wordCount||(c.style.display="none"),c}function Si(o,e){var n;let t=o==null?void 0:o.commonAncestorContainer;if(!t||!e.contains(t))return null;t.nodeType===3&&(t=t.parentElement);const i=(n=t==null?void 0:t.closest)==null?void 0:n.call(t,"a");return i&&e.contains(i)?i:null}function Ei(o,e){var n,r;const t=e||(o==null?void 0:o.commonAncestorContainer),i=[t,t==null?void 0:t.parentElement].filter(s=>s&&s.nodeType===1);for(const s of i){const a=(n=s.style)==null?void 0:n.textAlign;if(a)return a==="-webkit-justify"?"justify":a;const c=(r=s.getAttribute)==null?void 0:r.call(s,"align");if(c)return c}try{if(document.queryCommandState("justifyCenter"))return"center";if(document.queryCommandState("justifyRight"))return"right";if(document.queryCommandState("justifyFull"))return"justify"}catch{}return"left"}function Li(o){const e=(o.match(/[\u4e00-\u9fa5\u3040-\u30ff]/g)||[]).length,t=(o.match(/[a-zA-Z0-9'’-]+/g)||[]).length;return e+t}function Ze(o){const t=new DOMParser().parseFromString(`<div>${o}</div>`,"text/html").body.firstChild;return t.querySelectorAll("[contenteditable]").forEach(i=>i.removeAttribute("contenteditable")),t.querySelectorAll("[data-k-id]").forEach(i=>i.removeAttribute("data-k-id")),t.querySelectorAll("[data-k-state]").forEach(i=>i.removeAttribute("data-k-state")),t.querySelectorAll("[data-ke-marker]").forEach(i=>i.removeAttribute("data-ke-marker")),t.querySelectorAll("[data-placeholder]").forEach(i=>i.removeAttribute("data-placeholder")),t.querySelectorAll(".ke-is-selected-media").forEach(i=>i.classList.remove("ke-is-selected-media")),t.querySelectorAll('[data-k-state="uploading"], [data-k-state="error"]').forEach(i=>i.remove()),t.innerHTML.trim()}function Mi(o){const t=new DOMParser().parseFromString(`<div>${o}</div>`,"text/html").body.firstChild;return t.querySelectorAll("[data-k-media]").forEach(i=>{i.removeAttribute("data-k-media"),i.removeAttribute("data-k-url")}),t.innerHTML}const zi="1.0.5";function xe(o,e={}){return new X(o,e)}const Ti=xe;function Ai(o,e={}){const t=typeof o=="string"?document.querySelector(o):o;return t!=null&&t.__keditor__&&t.__keditor__.destroy(),xe(t,e)}b.ChunkUploader=j,b.DEFAULT_TOOLBAR=Q,b.KEditor=X,b.cleanWordHtml=ze,b.create=xe,b.createUploader=Ke,b.default=X,b.defaults=F,b.escapeHtml=ce,b.exportHtml=Ze,b.fastFingerprint=ke,b.formatHtml=ae,b.httpAdapter=Ve,b.isSafeUrl=Y,b.maybeCompress=Ie,b.mockAdapter=_e,b.mount=Ti,b.normalizeCustomButtons=Be,b.normalizeItems=G,b.normalizePosition=de,b.replace=Ai,b.sanitizeHtml=K,b.simpleAdapter=We,b.strongFingerprint=qe,b.version=zi,Object.defineProperties(b,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}})});
|
package/imgs/img.png
ADDED
|
Binary file
|
package/imgs/img_1.png
ADDED
|
Binary file
|
package/imgs/img_2.png
ADDED
|
Binary file
|
package/imgs/img_3.png
ADDED
|
Binary file
|
package/package.json
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "kyle-editor",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.5",
|
|
4
4
|
"description": "轻量、美观的微信公众号风格富文本编辑器(纯前端,支持图片/视频分片上传、HTML 源码模式),可通过 <script> 引入或作为 Vue 3 组件安装。",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/keditor.cjs",
|
|
7
7
|
"module": "./dist/keditor.es.js",
|
|
8
|
-
"unpkg": "./dist/keditor.umd.js",
|
|
9
|
-
"jsdelivr": "./dist/keditor.umd.js",
|
|
8
|
+
"unpkg": "./dist/keditor.umd.min.js",
|
|
9
|
+
"jsdelivr": "./dist/keditor.umd.min.js",
|
|
10
10
|
"types": "./types/index.d.ts",
|
|
11
11
|
"exports": {
|
|
12
12
|
".": {
|
|
@@ -25,6 +25,7 @@
|
|
|
25
25
|
"files": [
|
|
26
26
|
"dist",
|
|
27
27
|
"types",
|
|
28
|
+
"imgs",
|
|
28
29
|
"README.md",
|
|
29
30
|
"LICENSE"
|
|
30
31
|
],
|
|
@@ -32,16 +33,18 @@
|
|
|
32
33
|
"node": ">=16"
|
|
33
34
|
},
|
|
34
35
|
"scripts": {
|
|
35
|
-
"build": "vite build --config vite.config.core.js && vite build --config vite.config.vue.js",
|
|
36
|
+
"build": "vite build --config vite.config.core.js && vite build --config vite.config.vue.js && vite build --config vite.config.min.js",
|
|
37
|
+
"build:min": "vite build --config vite.config.min.js",
|
|
36
38
|
"dev": "python3 -m http.server 5178 --bind 127.0.0.1",
|
|
37
39
|
"test": "node test/run-headless.mjs",
|
|
40
|
+
"test:min": "node test/run-headless.mjs \"http://127.0.0.1:5178/test/smoke.html?bundle=min\"",
|
|
38
41
|
"test:pages": "node test/check-page.mjs",
|
|
39
42
|
"test:types": "node test/check-types.mjs",
|
|
40
43
|
"test:package": "node test/check-package.mjs",
|
|
41
44
|
"test:install": "node test/check-install.mjs",
|
|
42
45
|
"test:visual": "node test/shoot.mjs rich,uploading,bubble,resize,align,source,preview,color,heading,media,link,custom,customload,customerr,posbtn,wide,widefix,scroll,scroll2,http://127.0.0.1:5178/demo/vue.html",
|
|
43
46
|
"clean": "rm -rf dist",
|
|
44
|
-
"verify": "npm run build && npm test && npm run test:pages && npm run test:types && npm run test:package",
|
|
47
|
+
"verify": "npm run build && npm test && npm run test:min && npm run test:pages && npm run test:types && npm run test:package",
|
|
45
48
|
"pack:check": "npm run build && npm run test:package && npm pack --dry-run",
|
|
46
49
|
"prerelease": "npm run verify && npm run test:install",
|
|
47
50
|
"release": "npm publish --access public --registry=https://registry.npmjs.org",
|