aden-editor-vue 0.1.5 → 0.1.6

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
@@ -41,6 +41,8 @@ const content = ref('<p>欢迎使用 AdenEditor</p>');
41
41
 
42
42
  默认工具栏和样式会自动加载。未传 `options` 时,文字编辑、列表、引用、表格等内置功能仍可直接使用;无需单独导入 CSS,也无需自己处理创建、挂载和卸载。
43
43
 
44
+ 从 Word 复制的 Office HTML 会以可编辑的富文本片段导入,尽量保留 Word 的段落、表格、内联格式和可安全转换的样式;这不是嵌入 Word 文档。Word 剪贴板若只提供本机临时图片路径、没有提供图片文件数据,浏览器无法读取该路径,编辑器会提示重新复制图片或配置 `uploadImage`。
45
+
44
46
  ## 保存内容
45
47
 
46
48
  `v-model` 的值是 HTML,适合接入常见的 HTML 内容字段。若需保存完整编辑器文档结构,可通过组件 `ref` 获取 JSON:
package/dist/index.cjs CHANGED
@@ -224,6 +224,9 @@ function normalizeBlockAttrs(type, raw) {
224
224
  case "language":
225
225
  if (/^[a-zA-Z0-9_+-]{1,32}$/.test(String(value))) clean.language = String(value);
226
226
  break;
227
+ case "htmlContent":
228
+ clean.htmlContent = String(value).slice(0, 2e6).replace(/<(script|iframe|object|embed|form|input|button|style|link|meta|base)\b[^>]*>[\s\S]*?<\/\1\s*>/gi, "").replace(/<(script|iframe|object|embed|form|input|button|style|link|meta|base)\b[^>]*\/?\s*>/gi, "").replace(/\s+on[a-z]+\s*=\s*(?:"[^"]*"|'[^']*'|[^\s>]+)/gi, "").replace(/(href|src)\s*=\s*(["'])\s*javascript:[\s\S]*?\2/gi, '$1="#"');
229
+ break;
227
230
  case "ratio": {
228
231
  const n = Number(value);
229
232
  if (Number.isFinite(n) && n > 0 && n <= 10) clean.ratio = n;
@@ -338,6 +341,7 @@ var init_schema = __esm({
338
341
  isTextBlock: false,
339
342
  allowedAttrs: ["align", "tableWidth", "bordered", "headerRow", "headerCol"]
340
343
  },
344
+ html_fragment: { isTextBlock: true, allowedAttrs: ["htmlContent"] },
341
345
  todo_item: { isTextBlock: true, allowedAttrs: ["checked", "indent"] },
342
346
  attachment: {
343
347
  isTextBlock: false,
@@ -1069,7 +1073,7 @@ function wrapMarks(text, marks) {
1069
1073
  return out;
1070
1074
  }
1071
1075
  function blockToHtml(block) {
1072
- var _a, _b, _c, _d, _e;
1076
+ var _a, _b, _c, _d, _e, _f;
1073
1077
  const attrs = block.attrs && typeof block.attrs === "object" ? block.attrs : {};
1074
1078
  const content = Array.isArray(block.content) ? block.content : [];
1075
1079
  const inner = content.filter((n) => n && typeof n.text === "string").map((n) => wrapMarks(n.text, Array.isArray(n.marks) ? n.marks : [])).join("");
@@ -1112,13 +1116,15 @@ function blockToHtml(block) {
1112
1116
  }
1113
1117
  case "table":
1114
1118
  return tableToHtml(block);
1119
+ case "html_fragment":
1120
+ return String((_d = attrs.htmlContent) != null ? _d : "");
1115
1121
  case "todo_item": {
1116
1122
  const checked = attrs.checked ? ' data-checked="true"' : "";
1117
1123
  return `<ul class="aden-todo-list"><li${checked}>${inner}</li></ul>`;
1118
1124
  }
1119
1125
  case "attachment": {
1120
- const name = String((_d = attrs.fileName) != null ? _d : "\u9644\u4EF6");
1121
- const url = sanitizeUrl(String((_e = attrs.fileUrl) != null ? _e : ""), "media");
1126
+ const name = String((_e = attrs.fileName) != null ? _e : "\u9644\u4EF6");
1127
+ const url = sanitizeUrl(String((_f = attrs.fileUrl) != null ? _f : ""), "media");
1122
1128
  const size = Number(attrs.fileSize) || 0;
1123
1129
  const sizeAttr = size ? ` data-size="${size}"` : "";
1124
1130
  if (!url) return `<p>[\u9644\u4EF6] ${escapeHtml(name)}</p>`;
@@ -2570,6 +2576,28 @@ function pasteHtml(editor, html) {
2570
2576
  "paste"
2571
2577
  );
2572
2578
  }
2579
+ function pasteHtmlFragment(editor, html, plainText = "") {
2580
+ if (!html) return;
2581
+ const state = editor.getState();
2582
+ const { blockId, offset } = state.selection.anchor;
2583
+ const idx = indexOfBlock(state.doc, blockId);
2584
+ const cur = state.doc.blocks[idx];
2585
+ if (!cur) return;
2586
+ const [left, right] = splitAt(cur, offset);
2587
+ const blocks = state.doc.blocks.slice();
2588
+ const fragment = createBlock("html_fragment", { htmlContent: html }, plainText ? [{ type: "text", text: plainText, marks: [] }] : []);
2589
+ const tailBlock = { ...cur, id: genId(), content: normalizeContent(right) };
2590
+ blocks[idx] = { ...cur, content: normalizeContent(left) };
2591
+ blocks.splice(idx + 1, 0, fragment, tailBlock);
2592
+ editor.commit(
2593
+ () => ({
2594
+ ...state,
2595
+ doc: { ...state.doc, blocks },
2596
+ selection: { anchor: { blockId: fragment.id, offset: 0 }, head: { blockId: fragment.id, offset: 0 } }
2597
+ }),
2598
+ "paste"
2599
+ );
2600
+ }
2573
2601
  var MAX_INDENT;
2574
2602
  var init_commands = __esm({
2575
2603
  "packages/core/src/command/commands.ts"() {
@@ -2945,6 +2973,7 @@ __export2(src_exports, {
2945
2973
  normalizeKey: () => normalizeKey,
2946
2974
  normalizeTable: () => normalizeTable,
2947
2975
  pasteHtml: () => pasteHtml,
2976
+ pasteHtmlFragment: () => pasteHtmlFragment,
2948
2977
  pastePlainText: () => pastePlainText,
2949
2978
  reconcileMarks: () => reconcileMarks,
2950
2979
  removeAttachment: () => removeAttachment,
@@ -3921,6 +3950,9 @@ var EDITOR_CSS = `
3921
3950
 
3922
3951
  /* \u6BB5\u843D */
3923
3952
  .aden-editor .aden-block-paragraph { margin-bottom: 6px; }
3953
+ .aden-editor .aden-block-html_fragment { display: block; margin: 0; padding: 0; }
3954
+ .aden-editor .aden-imported-html { display: block; width: 100%; min-width: 0; overflow-x: auto; }
3955
+ .aden-editor .aden-imported-html img { max-width: 100%; height: auto; }
3924
3956
 
3925
3957
  /* \u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550
3926
3958
  \u6807\u9898\uFF1A\u516D\u7EA7\u7684\u5B57\u53F7/\u884C\u9AD8/\u95F4\u8DDD\u68AF\u5EA6
@@ -5834,6 +5866,220 @@ function marksFromStyle(el) {
5834
5866
  function sanitizeHrefForDom(href) {
5835
5867
  return sanitizeUrl(href, "link");
5836
5868
  }
5869
+ init_src();
5870
+ var ALLOWED_TAGS = /* @__PURE__ */ new Set([
5871
+ "a",
5872
+ "b",
5873
+ "blockquote",
5874
+ "br",
5875
+ "caption",
5876
+ "code",
5877
+ "col",
5878
+ "colgroup",
5879
+ "dd",
5880
+ "del",
5881
+ "div",
5882
+ "dl",
5883
+ "dt",
5884
+ "em",
5885
+ "figcaption",
5886
+ "figure",
5887
+ "h1",
5888
+ "h2",
5889
+ "h3",
5890
+ "h4",
5891
+ "h5",
5892
+ "h6",
5893
+ "hr",
5894
+ "i",
5895
+ "img",
5896
+ "li",
5897
+ "ol",
5898
+ "p",
5899
+ "pre",
5900
+ "s",
5901
+ "small",
5902
+ "span",
5903
+ "strong",
5904
+ "sub",
5905
+ "sup",
5906
+ "table",
5907
+ "tbody",
5908
+ "td",
5909
+ "tfoot",
5910
+ "th",
5911
+ "thead",
5912
+ "tr",
5913
+ "u",
5914
+ "ul"
5915
+ ]);
5916
+ var DROP_CONTENT_TAGS = /* @__PURE__ */ new Set(["script", "style", "iframe", "object", "embed", "form", "input", "button", "meta", "link", "base", "svg", "math"]);
5917
+ var STYLE_PROPERTIES = /* @__PURE__ */ new Set([
5918
+ "background",
5919
+ "background-color",
5920
+ "border",
5921
+ "border-bottom",
5922
+ "border-bottom-color",
5923
+ "border-bottom-style",
5924
+ "border-bottom-width",
5925
+ "border-collapse",
5926
+ "border-color",
5927
+ "border-left",
5928
+ "border-left-color",
5929
+ "border-left-style",
5930
+ "border-left-width",
5931
+ "border-right",
5932
+ "border-right-color",
5933
+ "border-right-style",
5934
+ "border-right-width",
5935
+ "border-spacing",
5936
+ "border-style",
5937
+ "border-top",
5938
+ "border-top-color",
5939
+ "border-top-style",
5940
+ "border-top-width",
5941
+ "border-width",
5942
+ "color",
5943
+ "direction",
5944
+ "display",
5945
+ "font-family",
5946
+ "font-size",
5947
+ "font-style",
5948
+ "font-variant",
5949
+ "font-weight",
5950
+ "height",
5951
+ "line-height",
5952
+ "list-style-type",
5953
+ "margin",
5954
+ "margin-bottom",
5955
+ "margin-left",
5956
+ "margin-right",
5957
+ "margin-top",
5958
+ "padding",
5959
+ "padding-bottom",
5960
+ "padding-left",
5961
+ "padding-right",
5962
+ "padding-top",
5963
+ "page-break-after",
5964
+ "page-break-before",
5965
+ "text-align",
5966
+ "text-decoration",
5967
+ "text-indent",
5968
+ "text-transform",
5969
+ "vertical-align",
5970
+ "white-space",
5971
+ "width"
5972
+ ]);
5973
+ function sanitizeWordHtml(input) {
5974
+ var _a, _b, _c;
5975
+ const source = input.slice(0, 2e6);
5976
+ const template = document.createElement("template");
5977
+ template.innerHTML = source;
5978
+ inlineOfficeStyles(template.content);
5979
+ for (const element of Array.from(template.content.querySelectorAll("*"))) {
5980
+ const rawTag = element.tagName.toLowerCase();
5981
+ const tag = rawTag.includes(":") ? rawTag.split(":").pop() : rawTag;
5982
+ if (DROP_CONTENT_TAGS.has(tag)) {
5983
+ element.remove();
5984
+ continue;
5985
+ }
5986
+ if (tag === "imagedata") {
5987
+ const image = document.createElement("img");
5988
+ image.setAttribute("data-aden-missing-image", "true");
5989
+ const src = (_b = (_a = element.getAttribute("src")) != null ? _a : element.getAttribute("o:href")) != null ? _b : "";
5990
+ const safeSrc = sanitizeUrl(src, "media");
5991
+ if (safeSrc) image.src = safeSrc;
5992
+ element.replaceWith(image);
5993
+ continue;
5994
+ }
5995
+ if (!ALLOWED_TAGS.has(tag)) {
5996
+ element.replaceWith(...Array.from(element.childNodes));
5997
+ continue;
5998
+ }
5999
+ if (rawTag !== tag) {
6000
+ const replacement = document.createElement(tag);
6001
+ for (const attribute of Array.from(element.attributes)) replacement.setAttribute(attribute.name, attribute.value);
6002
+ replacement.append(...Array.from(element.childNodes));
6003
+ element.replaceWith(replacement);
6004
+ continue;
6005
+ }
6006
+ for (const attribute of Array.from(element.attributes)) {
6007
+ const name = attribute.name.toLowerCase();
6008
+ if (name.startsWith("on") || name === "srcset" || name === "srcdoc" || name === "class" || name === "id" || name.startsWith("data-") && name !== "data-aden-missing-image") {
6009
+ if (name !== "data-aden-missing-image") element.removeAttribute(attribute.name);
6010
+ continue;
6011
+ }
6012
+ if (name === "style") {
6013
+ const clean = sanitizeInlineStyle(attribute.value);
6014
+ if (clean) element.setAttribute("style", clean);
6015
+ else element.removeAttribute("style");
6016
+ continue;
6017
+ }
6018
+ if (name === "src") {
6019
+ const safe = sanitizeUrl(attribute.value, "media");
6020
+ if (safe) element.setAttribute("src", safe);
6021
+ else {
6022
+ element.removeAttribute("src");
6023
+ if (tag === "img") element.setAttribute("data-aden-missing-image", "true");
6024
+ }
6025
+ continue;
6026
+ }
6027
+ if (name === "href") {
6028
+ const safe = sanitizeUrl(attribute.value, "link");
6029
+ if (safe) element.setAttribute("href", safe);
6030
+ else element.removeAttribute("href");
6031
+ continue;
6032
+ }
6033
+ if (!["alt", "title", "width", "height", "colspan", "rowspan", "align", "valign", "bgcolor", "scope", "start", "type", "dir", "lang", "data-aden-missing-image"].includes(name)) {
6034
+ element.removeAttribute(attribute.name);
6035
+ }
6036
+ }
6037
+ if (tag === "a" && element.getAttribute("target") === "_blank") element.setAttribute("rel", "noopener noreferrer");
6038
+ if (tag === "img" && element.hasAttribute("data-aden-missing-image") && !element.hasAttribute("alt")) {
6039
+ element.setAttribute("alt", "Word \u56FE\u7247\u672A\u80FD\u4ECE\u526A\u8D34\u677F\u8BFB\u53D6");
6040
+ }
6041
+ }
6042
+ const missingImages = template.content.querySelectorAll("img[data-aden-missing-image]").length;
6043
+ return { html: template.innerHTML, text: (_c = template.content.textContent) != null ? _c : "", missingImages };
6044
+ }
6045
+ function inlineOfficeStyles(root) {
6046
+ var _a, _b;
6047
+ const styleElements = Array.from(root.querySelectorAll("style"));
6048
+ for (const styleElement of styleElements) {
6049
+ const css = (_a = styleElement.textContent) != null ? _a : "";
6050
+ const rules = /([^{}]+)\{([^{}]*)\}/g;
6051
+ let rule;
6052
+ while (rule = rules.exec(css)) {
6053
+ const declarations = sanitizeInlineStyle(rule[2]);
6054
+ if (!declarations) continue;
6055
+ for (const rawSelector of rule[1].split(",")) {
6056
+ const selector = rawSelector.trim();
6057
+ if (!/^(?:[a-z][\w-]*)?(?:\.[\w-]+)+$/i.test(selector)) continue;
6058
+ try {
6059
+ for (const element of Array.from(root.querySelectorAll(selector))) {
6060
+ const current = (_b = element.getAttribute("style")) != null ? _b : "";
6061
+ element.setAttribute("style", sanitizeInlineStyle(`${declarations};${current}`));
6062
+ }
6063
+ } catch {
6064
+ }
6065
+ }
6066
+ }
6067
+ styleElement.remove();
6068
+ }
6069
+ }
6070
+ function sanitizeInlineStyle(raw) {
6071
+ const declarations = [];
6072
+ for (const declaration of raw.split(";")) {
6073
+ const separator = declaration.indexOf(":");
6074
+ if (separator < 1) continue;
6075
+ const property = declaration.slice(0, separator).trim().toLowerCase();
6076
+ const value = sanitizeStyleValue(declaration.slice(separator + 1));
6077
+ if (!STYLE_PROPERTIES.has(property) || !value || /url\s*\(|expression\s*\(|javascript:|[{}<>]/i.test(value)) continue;
6078
+ if (property === "display" && !/^(inline|inline-block|block|table|table-row|table-cell|table-caption|table-row-group|table-header-group|table-footer-group|list-item)$/i.test(value)) continue;
6079
+ declarations.push(`${property}:${value}`);
6080
+ }
6081
+ return declarations.join(";");
6082
+ }
5837
6083
  function parseBlockContent(el) {
5838
6084
  const content = [];
5839
6085
  const walk = (node, marks) => {
@@ -5868,6 +6114,16 @@ function parseBlockEl(el, base) {
5868
6114
  if (type === "divider" || type === "image" || type === "video" || type === "table") {
5869
6115
  return base;
5870
6116
  }
6117
+ if (type === "html_fragment") {
6118
+ const content = el.querySelector(".aden-imported-html");
6119
+ if (!content) return base;
6120
+ const safe = sanitizeWordHtml(content.innerHTML);
6121
+ return {
6122
+ ...base,
6123
+ attrs: { ...base.attrs, htmlContent: safe.html },
6124
+ content: parseBlockContent(content)
6125
+ };
6126
+ }
5871
6127
  if (type === "code_block") {
5872
6128
  const text = (_b = el.textContent) != null ? _b : "";
5873
6129
  return { ...base, content: text ? [{ type: "text", text, marks: [] }] : [] };
@@ -6977,7 +7233,7 @@ function blockSignature(block) {
6977
7233
  return JSON.stringify([block.type, block.attrs, block.content, (_a = block.table) != null ? _a : null]);
6978
7234
  }
6979
7235
  function createBlockEl(block, ctx) {
6980
- var _a, _b, _c, _d, _e, _f, _g, _h;
7236
+ var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j;
6981
7237
  const el = document.createElement("div");
6982
7238
  el.setAttribute("data-block-id", block.id);
6983
7239
  el.setAttribute("data-block-type", block.type);
@@ -7049,6 +7305,14 @@ function createBlockEl(block, ctx) {
7049
7305
  );
7050
7306
  return el;
7051
7307
  }
7308
+ case "html_fragment": {
7309
+ const content = document.createElement("div");
7310
+ content.className = "aden-imported-html";
7311
+ content.contentEditable = ctx.readonly ? "false" : "true";
7312
+ content.innerHTML = sanitizeWordHtml(String((_j = (_i = block.attrs) == null ? void 0 : _i.htmlContent) != null ? _j : "")).html;
7313
+ el.appendChild(content);
7314
+ return el;
7315
+ }
7052
7316
  case "code_block":
7053
7317
  el.appendChild(renderCodeBlock(block));
7054
7318
  return el;
@@ -7599,6 +7863,27 @@ var ImageController = class {
7599
7863
  if (this.destroyed || this.opts.isReadonly()) return;
7600
7864
  await this.startReplacementUpload(blockId, file);
7601
7865
  }
7866
+ /** Import an image embedded in Office clipboard HTML as an upload or durable data URL. */
7867
+ async importClipboardFile(file) {
7868
+ var _a, _b, _c;
7869
+ const check = validateFile(file, {
7870
+ accept: (_a = this.opts.accept) != null ? _a : DEFAULT_ACCEPT,
7871
+ maxSize: (_b = this.opts.maxSize) != null ? _b : 10 * 1024 * 1024,
7872
+ label: "\u56FE\u7247"
7873
+ });
7874
+ if (!check.ok) throw new Error(check.message);
7875
+ try {
7876
+ const rawUrl = await ((_c = this.opts.upload) != null ? _c : fileToDataUrl)(file);
7877
+ const url = this.opts.upload ? sanitizePersistentMediaUrl(rawUrl) : sanitizeUrl(rawUrl, "media");
7878
+ if (!url) throw new Error("\u4E0A\u4F20\u63A5\u53E3\u672A\u8FD4\u56DE\u53EF\u8BBF\u95EE\u7684\u56FE\u7247\u5730\u5740");
7879
+ return url;
7880
+ } catch (error) {
7881
+ const cause = (error == null ? void 0 : error.message) || "\u672A\u77E5\u9519\u8BEF";
7882
+ const message = this.opts.upload ? `Word \u56FE\u7247\u4E0A\u4F20\u5931\u8D25\uFF1A${cause}\u3002\u8BF7\u68C0\u67E5 uploadImage \u63A5\u53E3\u914D\u7F6E` : `Word \u56FE\u7247\u8BFB\u53D6\u5931\u8D25\uFF1A${cause}\u3002\u8BF7\u914D\u7F6E uploadImage \u56FE\u7247\u4E0A\u4F20\u63A5\u53E3\u540E\u91CD\u8BD5`;
7883
+ showToast(message, 6500);
7884
+ throw new Error(message);
7885
+ }
7886
+ }
7602
7887
  /** 替换指定图片块(网络地址)。 */
7603
7888
  replaceWithUrl(blockId, url) {
7604
7889
  if (this.destroyed || this.opts.isReadonly()) return false;
@@ -9396,6 +9681,11 @@ var WebAdapter = class {
9396
9681
  knownFiles.add(key);
9397
9682
  images.push(file);
9398
9683
  }
9684
+ if (isOfficeClipboardHtml(pasteHtml2)) {
9685
+ e.preventDefault();
9686
+ void this.pasteOfficeHtml(pasteHtml2, images);
9687
+ return;
9688
+ }
9399
9689
  if (images.length) {
9400
9690
  e.preventDefault();
9401
9691
  const existingImageIds2 = new Set(
@@ -9911,6 +10201,35 @@ var WebAdapter = class {
9911
10201
  cur = cur.nextElementSibling;
9912
10202
  }
9913
10203
  }
10204
+ async pasteOfficeHtml(html, files) {
10205
+ const template = document.createElement("template");
10206
+ let safe = sanitizeWordHtml(html);
10207
+ template.innerHTML = safe.html;
10208
+ const imageEls = Array.from(template.content.querySelectorAll("img[data-aden-missing-image]"));
10209
+ for (let i = 0; i < Math.min(imageEls.length, files.length); i += 1) {
10210
+ try {
10211
+ imageEls[i].src = await this.imageCtrl.importClipboardFile(files[i]);
10212
+ imageEls[i].removeAttribute("data-aden-missing-image");
10213
+ } catch {
10214
+ }
10215
+ }
10216
+ if (imageEls.length === 0 && !template.content.querySelector("img")) {
10217
+ for (const file of files) {
10218
+ try {
10219
+ const image = document.createElement("img");
10220
+ image.src = await this.imageCtrl.importClipboardFile(file);
10221
+ image.alt = file.name || "Word \u56FE\u7247";
10222
+ template.content.appendChild(image);
10223
+ } catch {
10224
+ }
10225
+ }
10226
+ }
10227
+ if (safe.missingImages > files.length) {
10228
+ showToast("Word \u5185\u5BB9\u4E2D\u6709\u56FE\u7247\u672A\u80FD\u4ECE\u526A\u8D34\u677F\u8BFB\u53D6\u3002\u8BF7\u91CD\u65B0\u590D\u5236\u56FE\u7247\uFF0C\u6216\u914D\u7F6E uploadImage \u4E0A\u4F20\u63A5\u53E3\u540E\u518D\u8BD5\u3002", 6500);
10229
+ }
10230
+ safe = sanitizeWordHtml(template.innerHTML);
10231
+ this.runCommand((cmd) => cmd.pasteHtmlFragment(this.editor, safe.html, safe.text));
10232
+ }
9914
10233
  // =========================================================================
9915
10234
  // 表格
9916
10235
  // =========================================================================
@@ -10441,6 +10760,9 @@ var WebAdapter = class {
10441
10760
  function countNonWhitespace(text) {
10442
10761
  return text.replace(/\s/g, "").length;
10443
10762
  }
10763
+ function isOfficeClipboardHtml(html) {
10764
+ return /mso-[\w-]+|class=["'][^"']*\bMso\w*|Microsoft Word|urn:schemas-microsoft-com|w:worddocument|v:(?:shape|imagedata)|StartFragment/i.test(html);
10765
+ }
10444
10766
  function truncateTextAtLimit(text, remaining) {
10445
10767
  let used = 0;
10446
10768
  let result = "";