kyle-editor 1.0.10 → 1.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -3,7 +3,7 @@
3
3
  轻量、美观的**微信公众号风格富文本编辑器**。纯前端实现,无任何后端依赖:图片/视频走**上传(普通整包 + 大文件分片)**(并发、重试、取消、秒传、断点续传),**代码块可选 20 种语言并语法高亮**,**一键导入 Markdown 文件/文本转成可编辑 HTML**,随时切换 **HTML 源码模式**查看或改写产物。支持 `<script>` 直接引入与 Vue 3 安装集成。
4
4
 
5
5
  - 体积:`dist/keditor.umd.min.js` 约 192 KB(gzip 61 KB),未压缩版 300 KB(gzip 78 KB),零运行时依赖(含内置高亮器与 Markdown 转换器),样式随 JS 注入
6
- - 版式:677px 正文版心、17px/1.75 行距,与公众号观感一致;**宽屏下版心自动生长**,两侧留白恒定,不会留出一大块空白
6
+ - 版式:677px 正文版心、14px/1.75 行距,与公众号观感一致;**宽屏下版心自动生长**,两侧留白恒定,不会留出一大块空白
7
7
  - 安全:标签/属性白名单净化,拦截 `on*`、`javascript:`、`script/iframe`
8
8
 
9
9
  ## 文档地址
@@ -13,7 +13,7 @@
13
13
 
14
14
  | 分类 | 能力 |
15
15
  |------|------|
16
- | 排版 | 段落样式面板(正文/标题一/标题二/标题三,带真实字号预览与用途说明)、字号面板(12–32px)、字体颜色与背景高亮(主题色 + 标准色 + 最近使用 + 自定义取色)、粗斜下删、四种对齐、有序/无序列表、引用、表格(网格选择)、代码块(**20 种语言可选 + 语法高亮**)、分割线、链接、清除格式 |
16
+ | 排版 | 段落样式面板(正文/标题一/标题二/标题三,带真实字号预览与用途说明)、字号面板(12–32px,默认选中正文基准 14px)、字体颜色与背景高亮(主题色 + 标准色 + 最近使用 + 自定义取色)、粗斜下删、四种对齐、有序/无序列表、引用、表格(网格选择)、代码块(**20 种语言可选 + 语法高亮**)、分割线、链接、清除格式 |
17
17
  | 媒体 | 图片/视频**本地上传**(点击、拖拽、粘贴截图)或**直接填网络链接**插入(自动校验可访问性);上传进度与速度、取消、失败重试、多图多选、大图自动压缩、双击看原图、气泡工具条(对齐/宽度/圆角/替换/删除)、**选中图片后拖拽右下角把手实时缩放** |
18
18
  | 上传 | **普通上传与分片上传各自独立配置**:`uploader`(整个文件一次请求)+ `chunkUploader`(切片并发,只需一个接口,响应里 `url` 非空即成功);`upload.mode` 可选 `auto`(按体积自动选,默认 5MB 阀值)/ `normal` / `chunk`,`chunkSize / concurrency / retries / fingerprint` 可配;内置 mock、simple 适配器,也可自定义 `upload/put` 适配器 |
19
19
  | 源码 | 工具栏右侧常驻「源码」按钮(`⌘/Ctrl+Shift+K`),进入后正文按钮置灰;格式化缩进、复制、直接编辑并应用(回填自动净化) |
@@ -320,6 +320,17 @@ editor.moveButton('hr', 0) // 移到第一位
320
320
  - **加载态**:面板自动显示 spinner + 骨架屏;**失败**时显示错误文案与「重试」按钮;**空数据**可用 `emptyText` 自定义提示
321
321
  - **在编辑器外部拿数据**(Vue / React 里自己请求):`editor.setButtonOptions('column', list)`
322
322
 
323
+ ### 面板展示(宽度与长内容)
324
+
325
+ ```js
326
+ { name: 'column', width: 360 } // 固定面板宽度;不写默认 300px(钳制在 200–420)
327
+ ```
328
+
329
+ - 下拉面板**宽度固定**,不会随选项文字长短忽宽忽窄
330
+ - 宽度还会被编辑器宽度兜住:上限 `min(编辑器宽, 窗口宽) - 16px`,窄容器 / 移动端不会被 `overflow: hidden` 裁掉右侧内容
331
+ - 选项文字过长时**不做省略号截断**,改在列表内**横向滚动**查看完整内容(长链接 token 同理)
332
+ - 面板标题过长:单行省略,鼠标悬停显示全文;右上角说明文字(`note`)优先完整显示
333
+
323
334
  ### 跳转链接配置
324
335
 
325
336
  ```js
@@ -539,8 +550,8 @@ npm run dev # 静态服务 http://127.0.0.1:5178
539
550
  npm run dev & # 先启动静态服务(测试页面走 http://127.0.0.1:5178)
540
551
 
541
552
  npm run verify # build + 冒烟(未压缩) + 冒烟(压缩) + 页面检查 + 类型 + 发布配置
542
- npm test # 330 项冒烟,跑 dist/keditor.umd.js
543
- npm run test:min # 同一套 330 项冒烟,跑 dist/keditor.umd.min.js
553
+ npm test # 341 项冒烟,跑 dist/keditor.umd.js
554
+ npm run test:min # 同一套 341 项冒烟,跑 dist/keditor.umd.min.js
544
555
  npm run test:pages # demo / 首页零控制台错误 + 真实交互探针
545
556
  npm run test:install # npm pack → 隔离安装(134 项:Node 26 + 浏览器 108,含 Vue 组件回归)
546
557
  npm run test:visual # 24 张关键状态截图(test/screenshots/)
package/dist/keditor.cjs CHANGED
@@ -1,5 +1,79 @@
1
1
  "use strict";
2
2
  Object.defineProperties(exports, { __esModule: { value: true }, [Symbol.toStringTag]: { value: "Module" } });
3
+ const DEFAULT_FONT_SIZE = 14;
4
+ const uid = (prefix = "k") => `${prefix}${Date.now().toString(36)}${Math.random().toString(36).slice(2, 7)}`;
5
+ function debounce(fn, wait = 300) {
6
+ let timer = null;
7
+ const wrapped = (...args) => {
8
+ clearTimeout(timer);
9
+ timer = setTimeout(() => fn(...args), wait);
10
+ };
11
+ wrapped.cancel = () => clearTimeout(timer);
12
+ wrapped.flush = (...args) => {
13
+ clearTimeout(timer);
14
+ fn(...args);
15
+ };
16
+ return wrapped;
17
+ }
18
+ const clamp$1 = (num, min, max) => Math.min(Math.max(num, min), max);
19
+ function formatSize(bytes) {
20
+ if (!bytes && bytes !== 0) return "-";
21
+ const units = ["B", "KB", "MB", "GB"];
22
+ let i = 0;
23
+ let value = bytes;
24
+ while (value >= 1024 && i < units.length - 1) {
25
+ value /= 1024;
26
+ i += 1;
27
+ }
28
+ return `${value.toFixed(value >= 10 || i === 0 ? 0 : 1)}${units[i]}`;
29
+ }
30
+ function h(spec, attrs = {}, children = []) {
31
+ let tag = "div";
32
+ let className = "";
33
+ const parts = String(spec).split(".");
34
+ tag = parts[0] || "div";
35
+ className = parts.slice(1).join(" ");
36
+ const node = document.createElement(tag);
37
+ if (className) node.className = className;
38
+ for (const [key, val] of Object.entries(attrs || {})) {
39
+ if (val === void 0 || val === null || val === false) continue;
40
+ if (key === "class") node.className = `${node.className} ${val}`.trim();
41
+ else if (key === "style" && typeof val === "object") Object.assign(node.style, val);
42
+ else if (key === "html") node.innerHTML = val;
43
+ else if (key === "text") node.textContent = val;
44
+ else if (key === "dataset") Object.assign(node.dataset, val);
45
+ else if (key.startsWith("on") && typeof val === "function") node.addEventListener(key.slice(2).toLowerCase(), val);
46
+ else node.setAttribute(key, val === true ? "" : String(val));
47
+ }
48
+ const list = Array.isArray(children) ? children : [children];
49
+ for (const child of list) {
50
+ if (child === null || child === void 0 || child === false) continue;
51
+ node.appendChild(typeof child === "string" || typeof child === "number" ? document.createTextNode(String(child)) : child);
52
+ }
53
+ return node;
54
+ }
55
+ function getMediaAlign(img) {
56
+ if (!img) return "left";
57
+ const ml = img.style.marginLeft;
58
+ const mr = img.style.marginRight;
59
+ if (ml === "auto" && mr === "auto") return "center";
60
+ if (ml === "auto") return "right";
61
+ return "left";
62
+ }
63
+ function setMediaAlign(img, align) {
64
+ if (!img) return;
65
+ img.style.maxWidth = "100%";
66
+ if (align === "center") {
67
+ img.style.marginLeft = "auto";
68
+ img.style.marginRight = "auto";
69
+ } else if (align === "right") {
70
+ img.style.marginLeft = "auto";
71
+ img.style.marginRight = "0";
72
+ } else {
73
+ img.style.marginLeft = "0";
74
+ img.style.marginRight = "auto";
75
+ }
76
+ }
3
77
  const CSS$1 = `
4
78
  .ke, .ke * { box-sizing: border-box; }
5
79
  .ke {
@@ -195,7 +269,7 @@ const CSS$1 = `
195
269
  .ke-hd-sample { display: block; color: #1f2329; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; line-height: 1.35; }
196
270
  .ke-hd-meta { display: flex; align-items: baseline; gap: 6px; font-size: 11.5px; color: #a2a8b3; }
197
271
  .ke-hd-label { color: #6b7280; }
198
- .ke-hd-row .s-body { font-size: 15px; }
272
+ .ke-hd-row .s-body { font-size: ${DEFAULT_FONT_SIZE}px; }
199
273
  .ke-hd-row .s-h1 { font-size: 21px; font-weight: 700; }
200
274
  .ke-hd-row .s-h2 { font-size: 18px; font-weight: 700; }
201
275
  .ke-hd-row .s-h3 { font-size: 16px; font-weight: 600; }
@@ -213,7 +287,14 @@ const CSS$1 = `
213
287
  .ke-panel-icon .ke-ico { width: 13px; height: 13px; }
214
288
  .ke-panel-icon + .ke-panel-note { margin-left: 8px; }
215
289
 
290
+ /* 下拉选择面板:宽度固定,内容过长时在面板内横向滚动(否则会被根节点 overflow:hidden 裁掉) */
291
+ .ke-panel-select { width: 300px; box-sizing: border-box; }
292
+ .ke-panel-select .ke-panel-title { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
293
+ .ke-panel-select .ke-panel-note { flex: none; max-width: 55%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
216
294
  .ke-panel-select .ke-sel-search { margin-bottom: 8px; }
295
+ .ke-panel-select .ke-sel-body { overflow: auto; }
296
+ .ke-panel-select .ke-sel-row { width: max-content; min-width: 100%; box-sizing: border-box; }
297
+ .ke-panel-select .ke-sel-label, .ke-panel-select .ke-sel-desc { overflow: visible; text-overflow: clip; }
217
298
  .ke-code-panel .ke-sel-search { margin-bottom: 8px; }
218
299
  .ke-code-list { display: flex; flex-direction: column; max-height: 252px; overflow-y: auto; overscroll-behavior: contain; margin: 0 -4px; padding: 0 4px; }
219
300
  .ke-code-panel .ke-panel-hint { margin-top: 10px; }
@@ -343,7 +424,7 @@ const CSS$1 = `
343
424
  width: min(100%, max(calc(var(--ke-paper) + 64px), calc(100% - var(--ke-paper-gap) * 2)));
344
425
  max-width: var(--ke-paper-max, none);
345
426
  }
346
- .ke-content { outline: none; font-size: 17px; line-height: 1.75; color: var(--ke-text); word-break: break-word; }
427
+ .ke-content { outline: none; font-size: ${DEFAULT_FONT_SIZE}px; line-height: 1.75; color: var(--ke-text); word-break: break-word; }
347
428
  .ke-content:empty::before,
348
429
  .ke-content[data-placeholder].ke-is-empty::before {
349
430
  content: attr(data-placeholder); color: #b8bec7; pointer-events: none;
@@ -363,7 +444,7 @@ const CSS$1 = `
363
444
  }
364
445
  .ke-content a { color: #576b95; text-decoration: none; border-bottom: 1px solid rgba(87,107,149,.35); }
365
446
  .ke-content hr { border: 0; border-top: 1px solid var(--ke-line); margin: 24px 0; }
366
- .ke-content code { background: #f2f3f5; border-radius: 4px; padding: 2px 6px; font-size: 14px; font-family: 'SFMono-Regular', Consolas, Menlo, monospace; color: #c7254e; }
447
+ .ke-content code { background: #f2f3f5; border-radius: 4px; padding: 2px 6px; font-size: ${DEFAULT_FONT_SIZE - 1}px; font-family: 'SFMono-Regular', Consolas, Menlo, monospace; color: #c7254e; }
367
448
  .ke-content pre {
368
449
  position: relative;
369
450
  background: #282c34; color: #e6e6e6; padding: 14px 16px; border-radius: 8px; overflow-x: auto;
@@ -528,7 +609,7 @@ const CSS$1 = `
528
609
  .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); }
529
610
  .ke-preview-body { flex: 1; overflow: auto; padding: 20px; }
530
611
  .ke-preview-frame { margin: 0 auto; background: #fff; border-radius: 10px; box-shadow: var(--ke-shadow); padding: 22px 20px; transition: width .2s ease; }
531
- .ke-preview-frame .ke-content { font-size: 17px; line-height: 1.75; color: var(--ke-text); }
612
+ .ke-preview-frame .ke-content { font-size: ${DEFAULT_FONT_SIZE}px; line-height: 1.75; color: var(--ke-text); }
532
613
  .ke-preview-frame { min-height: 120px; }
533
614
 
534
615
  /* ---------------- ReadOnly / disabled ---------------- */
@@ -565,79 +646,6 @@ function injectStyle() {
565
646
  document.head.appendChild(style);
566
647
  injected = true;
567
648
  }
568
- const uid = (prefix = "k") => `${prefix}${Date.now().toString(36)}${Math.random().toString(36).slice(2, 7)}`;
569
- function debounce(fn, wait = 300) {
570
- let timer = null;
571
- const wrapped = (...args) => {
572
- clearTimeout(timer);
573
- timer = setTimeout(() => fn(...args), wait);
574
- };
575
- wrapped.cancel = () => clearTimeout(timer);
576
- wrapped.flush = (...args) => {
577
- clearTimeout(timer);
578
- fn(...args);
579
- };
580
- return wrapped;
581
- }
582
- const clamp$1 = (num, min, max) => Math.min(Math.max(num, min), max);
583
- function formatSize(bytes) {
584
- if (!bytes && bytes !== 0) return "-";
585
- const units = ["B", "KB", "MB", "GB"];
586
- let i = 0;
587
- let value = bytes;
588
- while (value >= 1024 && i < units.length - 1) {
589
- value /= 1024;
590
- i += 1;
591
- }
592
- return `${value.toFixed(value >= 10 || i === 0 ? 0 : 1)}${units[i]}`;
593
- }
594
- function h(spec, attrs = {}, children = []) {
595
- let tag = "div";
596
- let className = "";
597
- const parts = String(spec).split(".");
598
- tag = parts[0] || "div";
599
- className = parts.slice(1).join(" ");
600
- const node = document.createElement(tag);
601
- if (className) node.className = className;
602
- for (const [key, val] of Object.entries(attrs || {})) {
603
- if (val === void 0 || val === null || val === false) continue;
604
- if (key === "class") node.className = `${node.className} ${val}`.trim();
605
- else if (key === "style" && typeof val === "object") Object.assign(node.style, val);
606
- else if (key === "html") node.innerHTML = val;
607
- else if (key === "text") node.textContent = val;
608
- else if (key === "dataset") Object.assign(node.dataset, val);
609
- else if (key.startsWith("on") && typeof val === "function") node.addEventListener(key.slice(2).toLowerCase(), val);
610
- else node.setAttribute(key, val === true ? "" : String(val));
611
- }
612
- const list = Array.isArray(children) ? children : [children];
613
- for (const child of list) {
614
- if (child === null || child === void 0 || child === false) continue;
615
- node.appendChild(typeof child === "string" || typeof child === "number" ? document.createTextNode(String(child)) : child);
616
- }
617
- return node;
618
- }
619
- function getMediaAlign(img) {
620
- if (!img) return "left";
621
- const ml = img.style.marginLeft;
622
- const mr = img.style.marginRight;
623
- if (ml === "auto" && mr === "auto") return "center";
624
- if (ml === "auto") return "right";
625
- return "left";
626
- }
627
- function setMediaAlign(img, align) {
628
- if (!img) return;
629
- img.style.maxWidth = "100%";
630
- if (align === "center") {
631
- img.style.marginLeft = "auto";
632
- img.style.marginRight = "auto";
633
- } else if (align === "right") {
634
- img.style.marginLeft = "auto";
635
- img.style.marginRight = "0";
636
- } else {
637
- img.style.marginLeft = "0";
638
- img.style.marginRight = "auto";
639
- }
640
- }
641
649
  const S = (d) => `<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="${d}"/></svg>`;
642
650
  const icons = {
643
651
  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>`,
@@ -2525,6 +2533,14 @@ class Popover {
2525
2533
  const box = anchor.getBoundingClientRect();
2526
2534
  const visTop = Math.max(0, -rootBox.top);
2527
2535
  const visBottom = Math.min(rootBox.height, window.innerHeight - rootBox.top);
2536
+ if (rootBox.width > 0) {
2537
+ const limit = Math.max(160, Math.min(rootBox.width, window.innerWidth) - 16);
2538
+ const inner = this.el.firstElementChild;
2539
+ if (inner) {
2540
+ inner.style.removeProperty("max-width");
2541
+ if (inner.getBoundingClientRect().width > limit) inner.style.maxWidth = `${limit}px`;
2542
+ }
2543
+ }
2528
2544
  const popBox = this.el.getBoundingClientRect();
2529
2545
  let left = box.left - rootBox.left;
2530
2546
  if (align === "center") left = box.left - rootBox.left + box.width / 2 - popBox.width / 2;
@@ -2902,18 +2918,19 @@ function headingPanel(items, { value, onPick }) {
2902
2918
  return wrap;
2903
2919
  }
2904
2920
  function fontSizePanel(sizes, { value, onPick }) {
2905
- const wrap = panel("字号", h("span.ke-panel-note", { text: value ? `${value}px` : "默认 17px" }));
2921
+ const current = Number(value) || DEFAULT_FONT_SIZE;
2922
+ const wrap = panel("字号", h("span.ke-panel-note", { text: `${current}px` }));
2906
2923
  wrap.classList.add("ke-panel-wide");
2907
2924
  const grid = h("div.ke-size-grid");
2908
2925
  sizes.forEach((size) => {
2909
2926
  const btn2 = h("button.ke-size-cell", { type: "button", text: String(size), onclick: () => onPick(size) });
2910
2927
  btn2.style.fontSize = `${Math.min(20, 10 + size / 6)}px`;
2911
- if (Number(value) === size) btn2.classList.add("ke-is-active");
2928
+ if (current === size) btn2.classList.add("ke-is-active");
2912
2929
  grid.appendChild(btn2);
2913
2930
  });
2914
2931
  wrap.appendChild(grid);
2915
2932
  wrap.appendChild(divider());
2916
- wrap.appendChild(h("div.ke-panel-hint", { text: "仅作用于选中的文字;未选中时对新输入的文字生效" }));
2933
+ wrap.appendChild(h("div.ke-panel-hint", { text: `当前 ${current}px;仅作用于选中的文字,未选中时对新输入的文字生效` }));
2917
2934
  return wrap;
2918
2935
  }
2919
2936
  ({ text: THEME_COLORS.map((x) => x[0]), bg: BG_COLORS.map((x) => x[0]) });
@@ -3126,8 +3143,10 @@ function hostOf(url) {
3126
3143
  function selectPanel({ title, note, searchable, width, remote, value, load, reload, linkOf, onPick, emptyText }) {
3127
3144
  const wrap = panel(title);
3128
3145
  wrap.classList.add("ke-panel-wide", "ke-panel-select");
3129
- if (width) wrap.style.width = `${Math.min(420, Math.max(200, Number(width)))}px`;
3146
+ if (Number(width) > 0) wrap.style.width = `${Math.min(420, Math.max(200, Number(width)))}px`;
3130
3147
  const head = wrap.querySelector(".ke-panel-head");
3148
+ const titleEl = head.querySelector(".ke-panel-title");
3149
+ if (titleEl) titleEl.title = title;
3131
3150
  const countEl = h("span.ke-panel-note", { text: note || "" });
3132
3151
  if (remote) {
3133
3152
  head.appendChild(h("button.ke-panel-icon", {
@@ -3982,7 +4001,7 @@ const CARET = '<svg class="ke-caret" viewBox="0 0 24 24" fill="none" stroke="cur
3982
4001
  const SCROLL_HINT_KEY = "keditor.toolbarScrollHint";
3983
4002
  const SCROLL_HINT_ICON = '<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>';
3984
4003
  const HEADINGS = [
3985
- { value: "p", label: "正文", desc: "默认段落 · 17px,正文内容都用它", sample: "正文示例文字", sampleClass: "s-body" },
4004
+ { value: "p", label: "正文", desc: `默认段落 · ${DEFAULT_FONT_SIZE}px,正文内容都用它`, sample: "正文示例文字", sampleClass: "s-body" },
3986
4005
  { value: "h1", label: "标题一", desc: "大标题 · 22px 加粗,全文主标题(建议只用一次)", sample: "标题一示例", sampleClass: "s-h1" },
3987
4006
  { value: "h2", label: "标题二", desc: "章节标题 · 20px 加粗,划分小节", sample: "标题二示例", sampleClass: "s-h2" },
3988
4007
  { value: "h3", label: "标题三", desc: "小标题 · 18px 加粗,章节内的层级", sample: "标题三示例", sampleClass: "s-h3" }
@@ -4199,7 +4218,7 @@ class Toolbar {
4199
4218
  onclick: (event) => {
4200
4219
  event.preventDefault();
4201
4220
  this.togglePop("fontsize", button, () => fontSizePanel(FONT_SIZES, {
4202
- value: this.editor.getState().fontSize,
4221
+ value: this.editor.getState().fontSize || DEFAULT_FONT_SIZE,
4203
4222
  onPick: (size) => {
4204
4223
  this.editor.restoreSelection();
4205
4224
  this.editor.commands.setFontSize(Number(size));
@@ -4571,7 +4590,8 @@ class Toolbar {
4571
4590
  }
4572
4591
  if (this.fontSizeEl) {
4573
4592
  const label = this.fontSizeEl.querySelector(".ke-btn-text");
4574
- if (label) label.textContent = state.fontSize ? `${state.fontSize}px` : "字号";
4593
+ if (label) label.textContent = `${state.fontSize || DEFAULT_FONT_SIZE}px`;
4594
+ this.fontSizeEl.title = `字号(当前 ${state.fontSize || DEFAULT_FONT_SIZE}px,默认 ${DEFAULT_FONT_SIZE}px)`;
4575
4595
  }
4576
4596
  if (state.linkUrl) {
4577
4597
  const btn2 = this.buttons.get("link");
@@ -7131,7 +7151,7 @@ function previewHtml(html) {
7131
7151
  });
7132
7152
  return root.innerHTML;
7133
7153
  }
7134
- const version = "1.0.10";
7154
+ const version = "1.1.0";
7135
7155
  function create(target, options = {}) {
7136
7156
  return new KEditor(target, options);
7137
7157
  }
@@ -1,3 +1,77 @@
1
+ const DEFAULT_FONT_SIZE = 14;
2
+ const uid = (prefix = "k") => `${prefix}${Date.now().toString(36)}${Math.random().toString(36).slice(2, 7)}`;
3
+ function debounce(fn, wait = 300) {
4
+ let timer = null;
5
+ const wrapped = (...args) => {
6
+ clearTimeout(timer);
7
+ timer = setTimeout(() => fn(...args), wait);
8
+ };
9
+ wrapped.cancel = () => clearTimeout(timer);
10
+ wrapped.flush = (...args) => {
11
+ clearTimeout(timer);
12
+ fn(...args);
13
+ };
14
+ return wrapped;
15
+ }
16
+ const clamp$1 = (num, min, max) => Math.min(Math.max(num, min), max);
17
+ function formatSize(bytes) {
18
+ if (!bytes && bytes !== 0) return "-";
19
+ const units = ["B", "KB", "MB", "GB"];
20
+ let i = 0;
21
+ let value = bytes;
22
+ while (value >= 1024 && i < units.length - 1) {
23
+ value /= 1024;
24
+ i += 1;
25
+ }
26
+ return `${value.toFixed(value >= 10 || i === 0 ? 0 : 1)}${units[i]}`;
27
+ }
28
+ function h(spec, attrs = {}, children = []) {
29
+ let tag = "div";
30
+ let className = "";
31
+ const parts = String(spec).split(".");
32
+ tag = parts[0] || "div";
33
+ className = parts.slice(1).join(" ");
34
+ const node = document.createElement(tag);
35
+ if (className) node.className = className;
36
+ for (const [key, val] of Object.entries(attrs || {})) {
37
+ if (val === void 0 || val === null || val === false) continue;
38
+ if (key === "class") node.className = `${node.className} ${val}`.trim();
39
+ else if (key === "style" && typeof val === "object") Object.assign(node.style, val);
40
+ else if (key === "html") node.innerHTML = val;
41
+ else if (key === "text") node.textContent = val;
42
+ else if (key === "dataset") Object.assign(node.dataset, val);
43
+ else if (key.startsWith("on") && typeof val === "function") node.addEventListener(key.slice(2).toLowerCase(), val);
44
+ else node.setAttribute(key, val === true ? "" : String(val));
45
+ }
46
+ const list = Array.isArray(children) ? children : [children];
47
+ for (const child of list) {
48
+ if (child === null || child === void 0 || child === false) continue;
49
+ node.appendChild(typeof child === "string" || typeof child === "number" ? document.createTextNode(String(child)) : child);
50
+ }
51
+ return node;
52
+ }
53
+ function getMediaAlign(img) {
54
+ if (!img) return "left";
55
+ const ml = img.style.marginLeft;
56
+ const mr = img.style.marginRight;
57
+ if (ml === "auto" && mr === "auto") return "center";
58
+ if (ml === "auto") return "right";
59
+ return "left";
60
+ }
61
+ function setMediaAlign(img, align) {
62
+ if (!img) return;
63
+ img.style.maxWidth = "100%";
64
+ if (align === "center") {
65
+ img.style.marginLeft = "auto";
66
+ img.style.marginRight = "auto";
67
+ } else if (align === "right") {
68
+ img.style.marginLeft = "auto";
69
+ img.style.marginRight = "0";
70
+ } else {
71
+ img.style.marginLeft = "0";
72
+ img.style.marginRight = "auto";
73
+ }
74
+ }
1
75
  const CSS$1 = `
2
76
  .ke, .ke * { box-sizing: border-box; }
3
77
  .ke {
@@ -193,7 +267,7 @@ const CSS$1 = `
193
267
  .ke-hd-sample { display: block; color: #1f2329; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; line-height: 1.35; }
194
268
  .ke-hd-meta { display: flex; align-items: baseline; gap: 6px; font-size: 11.5px; color: #a2a8b3; }
195
269
  .ke-hd-label { color: #6b7280; }
196
- .ke-hd-row .s-body { font-size: 15px; }
270
+ .ke-hd-row .s-body { font-size: ${DEFAULT_FONT_SIZE}px; }
197
271
  .ke-hd-row .s-h1 { font-size: 21px; font-weight: 700; }
198
272
  .ke-hd-row .s-h2 { font-size: 18px; font-weight: 700; }
199
273
  .ke-hd-row .s-h3 { font-size: 16px; font-weight: 600; }
@@ -211,7 +285,14 @@ const CSS$1 = `
211
285
  .ke-panel-icon .ke-ico { width: 13px; height: 13px; }
212
286
  .ke-panel-icon + .ke-panel-note { margin-left: 8px; }
213
287
 
288
+ /* 下拉选择面板:宽度固定,内容过长时在面板内横向滚动(否则会被根节点 overflow:hidden 裁掉) */
289
+ .ke-panel-select { width: 300px; box-sizing: border-box; }
290
+ .ke-panel-select .ke-panel-title { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
291
+ .ke-panel-select .ke-panel-note { flex: none; max-width: 55%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
214
292
  .ke-panel-select .ke-sel-search { margin-bottom: 8px; }
293
+ .ke-panel-select .ke-sel-body { overflow: auto; }
294
+ .ke-panel-select .ke-sel-row { width: max-content; min-width: 100%; box-sizing: border-box; }
295
+ .ke-panel-select .ke-sel-label, .ke-panel-select .ke-sel-desc { overflow: visible; text-overflow: clip; }
215
296
  .ke-code-panel .ke-sel-search { margin-bottom: 8px; }
216
297
  .ke-code-list { display: flex; flex-direction: column; max-height: 252px; overflow-y: auto; overscroll-behavior: contain; margin: 0 -4px; padding: 0 4px; }
217
298
  .ke-code-panel .ke-panel-hint { margin-top: 10px; }
@@ -341,7 +422,7 @@ const CSS$1 = `
341
422
  width: min(100%, max(calc(var(--ke-paper) + 64px), calc(100% - var(--ke-paper-gap) * 2)));
342
423
  max-width: var(--ke-paper-max, none);
343
424
  }
344
- .ke-content { outline: none; font-size: 17px; line-height: 1.75; color: var(--ke-text); word-break: break-word; }
425
+ .ke-content { outline: none; font-size: ${DEFAULT_FONT_SIZE}px; line-height: 1.75; color: var(--ke-text); word-break: break-word; }
345
426
  .ke-content:empty::before,
346
427
  .ke-content[data-placeholder].ke-is-empty::before {
347
428
  content: attr(data-placeholder); color: #b8bec7; pointer-events: none;
@@ -361,7 +442,7 @@ const CSS$1 = `
361
442
  }
362
443
  .ke-content a { color: #576b95; text-decoration: none; border-bottom: 1px solid rgba(87,107,149,.35); }
363
444
  .ke-content hr { border: 0; border-top: 1px solid var(--ke-line); margin: 24px 0; }
364
- .ke-content code { background: #f2f3f5; border-radius: 4px; padding: 2px 6px; font-size: 14px; font-family: 'SFMono-Regular', Consolas, Menlo, monospace; color: #c7254e; }
445
+ .ke-content code { background: #f2f3f5; border-radius: 4px; padding: 2px 6px; font-size: ${DEFAULT_FONT_SIZE - 1}px; font-family: 'SFMono-Regular', Consolas, Menlo, monospace; color: #c7254e; }
365
446
  .ke-content pre {
366
447
  position: relative;
367
448
  background: #282c34; color: #e6e6e6; padding: 14px 16px; border-radius: 8px; overflow-x: auto;
@@ -526,7 +607,7 @@ const CSS$1 = `
526
607
  .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); }
527
608
  .ke-preview-body { flex: 1; overflow: auto; padding: 20px; }
528
609
  .ke-preview-frame { margin: 0 auto; background: #fff; border-radius: 10px; box-shadow: var(--ke-shadow); padding: 22px 20px; transition: width .2s ease; }
529
- .ke-preview-frame .ke-content { font-size: 17px; line-height: 1.75; color: var(--ke-text); }
610
+ .ke-preview-frame .ke-content { font-size: ${DEFAULT_FONT_SIZE}px; line-height: 1.75; color: var(--ke-text); }
530
611
  .ke-preview-frame { min-height: 120px; }
531
612
 
532
613
  /* ---------------- ReadOnly / disabled ---------------- */
@@ -563,79 +644,6 @@ function injectStyle() {
563
644
  document.head.appendChild(style);
564
645
  injected = true;
565
646
  }
566
- const uid = (prefix = "k") => `${prefix}${Date.now().toString(36)}${Math.random().toString(36).slice(2, 7)}`;
567
- function debounce(fn, wait = 300) {
568
- let timer = null;
569
- const wrapped = (...args) => {
570
- clearTimeout(timer);
571
- timer = setTimeout(() => fn(...args), wait);
572
- };
573
- wrapped.cancel = () => clearTimeout(timer);
574
- wrapped.flush = (...args) => {
575
- clearTimeout(timer);
576
- fn(...args);
577
- };
578
- return wrapped;
579
- }
580
- const clamp$1 = (num, min, max) => Math.min(Math.max(num, min), max);
581
- function formatSize(bytes) {
582
- if (!bytes && bytes !== 0) return "-";
583
- const units = ["B", "KB", "MB", "GB"];
584
- let i = 0;
585
- let value = bytes;
586
- while (value >= 1024 && i < units.length - 1) {
587
- value /= 1024;
588
- i += 1;
589
- }
590
- return `${value.toFixed(value >= 10 || i === 0 ? 0 : 1)}${units[i]}`;
591
- }
592
- function h(spec, attrs = {}, children = []) {
593
- let tag = "div";
594
- let className = "";
595
- const parts = String(spec).split(".");
596
- tag = parts[0] || "div";
597
- className = parts.slice(1).join(" ");
598
- const node = document.createElement(tag);
599
- if (className) node.className = className;
600
- for (const [key, val] of Object.entries(attrs || {})) {
601
- if (val === void 0 || val === null || val === false) continue;
602
- if (key === "class") node.className = `${node.className} ${val}`.trim();
603
- else if (key === "style" && typeof val === "object") Object.assign(node.style, val);
604
- else if (key === "html") node.innerHTML = val;
605
- else if (key === "text") node.textContent = val;
606
- else if (key === "dataset") Object.assign(node.dataset, val);
607
- else if (key.startsWith("on") && typeof val === "function") node.addEventListener(key.slice(2).toLowerCase(), val);
608
- else node.setAttribute(key, val === true ? "" : String(val));
609
- }
610
- const list = Array.isArray(children) ? children : [children];
611
- for (const child of list) {
612
- if (child === null || child === void 0 || child === false) continue;
613
- node.appendChild(typeof child === "string" || typeof child === "number" ? document.createTextNode(String(child)) : child);
614
- }
615
- return node;
616
- }
617
- function getMediaAlign(img) {
618
- if (!img) return "left";
619
- const ml = img.style.marginLeft;
620
- const mr = img.style.marginRight;
621
- if (ml === "auto" && mr === "auto") return "center";
622
- if (ml === "auto") return "right";
623
- return "left";
624
- }
625
- function setMediaAlign(img, align) {
626
- if (!img) return;
627
- img.style.maxWidth = "100%";
628
- if (align === "center") {
629
- img.style.marginLeft = "auto";
630
- img.style.marginRight = "auto";
631
- } else if (align === "right") {
632
- img.style.marginLeft = "auto";
633
- img.style.marginRight = "0";
634
- } else {
635
- img.style.marginLeft = "0";
636
- img.style.marginRight = "auto";
637
- }
638
- }
639
647
  const S = (d) => `<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="${d}"/></svg>`;
640
648
  const icons = {
641
649
  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>`,
@@ -2523,6 +2531,14 @@ class Popover {
2523
2531
  const box = anchor.getBoundingClientRect();
2524
2532
  const visTop = Math.max(0, -rootBox.top);
2525
2533
  const visBottom = Math.min(rootBox.height, window.innerHeight - rootBox.top);
2534
+ if (rootBox.width > 0) {
2535
+ const limit = Math.max(160, Math.min(rootBox.width, window.innerWidth) - 16);
2536
+ const inner = this.el.firstElementChild;
2537
+ if (inner) {
2538
+ inner.style.removeProperty("max-width");
2539
+ if (inner.getBoundingClientRect().width > limit) inner.style.maxWidth = `${limit}px`;
2540
+ }
2541
+ }
2526
2542
  const popBox = this.el.getBoundingClientRect();
2527
2543
  let left = box.left - rootBox.left;
2528
2544
  if (align === "center") left = box.left - rootBox.left + box.width / 2 - popBox.width / 2;
@@ -2900,18 +2916,19 @@ function headingPanel(items, { value, onPick }) {
2900
2916
  return wrap;
2901
2917
  }
2902
2918
  function fontSizePanel(sizes, { value, onPick }) {
2903
- const wrap = panel("字号", h("span.ke-panel-note", { text: value ? `${value}px` : "默认 17px" }));
2919
+ const current = Number(value) || DEFAULT_FONT_SIZE;
2920
+ const wrap = panel("字号", h("span.ke-panel-note", { text: `${current}px` }));
2904
2921
  wrap.classList.add("ke-panel-wide");
2905
2922
  const grid = h("div.ke-size-grid");
2906
2923
  sizes.forEach((size) => {
2907
2924
  const btn2 = h("button.ke-size-cell", { type: "button", text: String(size), onclick: () => onPick(size) });
2908
2925
  btn2.style.fontSize = `${Math.min(20, 10 + size / 6)}px`;
2909
- if (Number(value) === size) btn2.classList.add("ke-is-active");
2926
+ if (current === size) btn2.classList.add("ke-is-active");
2910
2927
  grid.appendChild(btn2);
2911
2928
  });
2912
2929
  wrap.appendChild(grid);
2913
2930
  wrap.appendChild(divider());
2914
- wrap.appendChild(h("div.ke-panel-hint", { text: "仅作用于选中的文字;未选中时对新输入的文字生效" }));
2931
+ wrap.appendChild(h("div.ke-panel-hint", { text: `当前 ${current}px;仅作用于选中的文字,未选中时对新输入的文字生效` }));
2915
2932
  return wrap;
2916
2933
  }
2917
2934
  ({ text: THEME_COLORS.map((x) => x[0]), bg: BG_COLORS.map((x) => x[0]) });
@@ -3124,8 +3141,10 @@ function hostOf(url) {
3124
3141
  function selectPanel({ title, note, searchable, width, remote, value, load, reload, linkOf, onPick, emptyText }) {
3125
3142
  const wrap = panel(title);
3126
3143
  wrap.classList.add("ke-panel-wide", "ke-panel-select");
3127
- if (width) wrap.style.width = `${Math.min(420, Math.max(200, Number(width)))}px`;
3144
+ if (Number(width) > 0) wrap.style.width = `${Math.min(420, Math.max(200, Number(width)))}px`;
3128
3145
  const head = wrap.querySelector(".ke-panel-head");
3146
+ const titleEl = head.querySelector(".ke-panel-title");
3147
+ if (titleEl) titleEl.title = title;
3129
3148
  const countEl = h("span.ke-panel-note", { text: note || "" });
3130
3149
  if (remote) {
3131
3150
  head.appendChild(h("button.ke-panel-icon", {
@@ -3980,7 +3999,7 @@ const CARET = '<svg class="ke-caret" viewBox="0 0 24 24" fill="none" stroke="cur
3980
3999
  const SCROLL_HINT_KEY = "keditor.toolbarScrollHint";
3981
4000
  const SCROLL_HINT_ICON = '<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>';
3982
4001
  const HEADINGS = [
3983
- { value: "p", label: "正文", desc: "默认段落 · 17px,正文内容都用它", sample: "正文示例文字", sampleClass: "s-body" },
4002
+ { value: "p", label: "正文", desc: `默认段落 · ${DEFAULT_FONT_SIZE}px,正文内容都用它`, sample: "正文示例文字", sampleClass: "s-body" },
3984
4003
  { value: "h1", label: "标题一", desc: "大标题 · 22px 加粗,全文主标题(建议只用一次)", sample: "标题一示例", sampleClass: "s-h1" },
3985
4004
  { value: "h2", label: "标题二", desc: "章节标题 · 20px 加粗,划分小节", sample: "标题二示例", sampleClass: "s-h2" },
3986
4005
  { value: "h3", label: "标题三", desc: "小标题 · 18px 加粗,章节内的层级", sample: "标题三示例", sampleClass: "s-h3" }
@@ -4197,7 +4216,7 @@ class Toolbar {
4197
4216
  onclick: (event) => {
4198
4217
  event.preventDefault();
4199
4218
  this.togglePop("fontsize", button, () => fontSizePanel(FONT_SIZES, {
4200
- value: this.editor.getState().fontSize,
4219
+ value: this.editor.getState().fontSize || DEFAULT_FONT_SIZE,
4201
4220
  onPick: (size) => {
4202
4221
  this.editor.restoreSelection();
4203
4222
  this.editor.commands.setFontSize(Number(size));
@@ -4569,7 +4588,8 @@ class Toolbar {
4569
4588
  }
4570
4589
  if (this.fontSizeEl) {
4571
4590
  const label = this.fontSizeEl.querySelector(".ke-btn-text");
4572
- if (label) label.textContent = state.fontSize ? `${state.fontSize}px` : "字号";
4591
+ if (label) label.textContent = `${state.fontSize || DEFAULT_FONT_SIZE}px`;
4592
+ this.fontSizeEl.title = `字号(当前 ${state.fontSize || DEFAULT_FONT_SIZE}px,默认 ${DEFAULT_FONT_SIZE}px)`;
4573
4593
  }
4574
4594
  if (state.linkUrl) {
4575
4595
  const btn2 = this.buttons.get("link");
@@ -7129,7 +7149,7 @@ function previewHtml(html) {
7129
7149
  });
7130
7150
  return root.innerHTML;
7131
7151
  }
7132
- const version = "1.0.10";
7152
+ const version = "1.1.0";
7133
7153
  function create(target, options = {}) {
7134
7154
  return new KEditor(target, options);
7135
7155
  }