@4399ywkf/editor 0.7.0 → 0.8.1
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 +94 -0
- package/dist/{DocView-XQMJUUVK.js → DocView-WEKRSKRU.js} +6 -4
- package/dist/DocView-WEKRSKRU.js.map +1 -0
- package/dist/{chunk-IUDLMN53.js → chunk-SGLNT6Z2.js} +2416 -176
- package/dist/chunk-SGLNT6Z2.js.map +1 -0
- package/dist/chunk-ZY5KLA7T.js +258 -0
- package/dist/chunk-ZY5KLA7T.js.map +1 -0
- package/dist/code-types-Dqmit3xx.d.ts +65 -0
- package/dist/doc-runtime.d.ts +1 -1
- package/dist/doc-runtime.js +7 -1
- package/dist/doc-runtime.js.map +1 -1
- package/dist/doc.d.ts +113 -6
- package/dist/doc.js +2 -1
- package/dist/doc.js.map +1 -1
- package/dist/docx.js +55 -5
- package/dist/docx.js.map +1 -1
- package/dist/index.d.ts +4 -2
- package/dist/index.js +1 -1
- package/dist/index.js.map +1 -1
- package/dist/pdf.d.ts +3 -1
- package/dist/pptx.d.ts +3 -1
- package/dist/{registry-XJFJXtZ_.d.ts → registry-CYKivRDh.d.ts} +7 -1
- package/dist/sheet.d.ts +4 -2
- package/dist/style.css +421 -111
- package/package.json +31 -29
- package/dist/DocView-XQMJUUVK.js.map +0 -1
- package/dist/chunk-IUDLMN53.js.map +0 -1
package/dist/docx.js
CHANGED
|
@@ -1,8 +1,7 @@
|
|
|
1
|
+
import { getCodeBlockTitle } from './chunk-ZY5KLA7T.js';
|
|
1
2
|
import { Node, mergeAttributes, Extension } from '@tiptap/core';
|
|
2
3
|
import { unzipSync, zipSync } from 'fflate';
|
|
3
4
|
|
|
4
|
-
// src/docx/index.ts
|
|
5
|
-
|
|
6
5
|
// src/docx/measure.ts
|
|
7
6
|
function measureContentWidth(dom) {
|
|
8
7
|
const el = dom;
|
|
@@ -1220,7 +1219,26 @@ function serializeDocx(doc, opts = {}) {
|
|
|
1220
1219
|
});
|
|
1221
1220
|
return `${xml}</w:tbl>`;
|
|
1222
1221
|
}
|
|
1223
|
-
function
|
|
1222
|
+
function codeBlock(n) {
|
|
1223
|
+
return `<w:p><w:pPr><w:pStyle w:val="Code"/></w:pPr><w:r><w:rPr><w:rFonts w:ascii="Consolas" w:hAnsi="Consolas"/></w:rPr><w:t xml:space="preserve">${esc(collectText(n))}</w:t></w:r></w:p>`;
|
|
1224
|
+
}
|
|
1225
|
+
function indentPr(indent) {
|
|
1226
|
+
return indent ? `<w:pPr><w:ind w:left="${indent}"/></w:pPr>` : "";
|
|
1227
|
+
}
|
|
1228
|
+
function boldParagraph(text, indent) {
|
|
1229
|
+
return `<w:p>${indentPr(indent)}<w:r><w:rPr><w:b/></w:rPr><w:t xml:space="preserve">${esc(text)}</w:t></w:r></w:p>`;
|
|
1230
|
+
}
|
|
1231
|
+
function apiParamHeader(n, indent) {
|
|
1232
|
+
const a = n.attrs ?? {};
|
|
1233
|
+
const runs = [];
|
|
1234
|
+
if (a.name) runs.push(`<w:r><w:rPr><w:b/></w:rPr><w:t xml:space="preserve">${esc(a.name)}</w:t></w:r>`);
|
|
1235
|
+
if (a.type) runs.push(`<w:r><w:rPr><w:rFonts w:ascii="Consolas" w:hAnsi="Consolas"/></w:rPr><w:t xml:space="preserve"> ${esc(a.type)}</w:t></w:r>`);
|
|
1236
|
+
if (a.required) runs.push(`<w:r><w:t xml:space="preserve"> 必选</w:t></w:r>`);
|
|
1237
|
+
if (a.default != null) runs.push(`<w:r><w:t xml:space="preserve"> 默认值 ${esc(a.default)}</w:t></w:r>`);
|
|
1238
|
+
if (a.summary) runs.push(`<w:r><w:t xml:space="preserve"> | ${esc(a.summary)}</w:t></w:r>`);
|
|
1239
|
+
return `<w:p>${indentPr(indent)}${runs.join("")}</w:p>`;
|
|
1240
|
+
}
|
|
1241
|
+
function blocks(nodes, indent = 0) {
|
|
1224
1242
|
const out = [];
|
|
1225
1243
|
for (const n of nodes) {
|
|
1226
1244
|
switch (n.type) {
|
|
@@ -1228,7 +1246,7 @@ function serializeDocx(doc, opts = {}) {
|
|
|
1228
1246
|
out.push(heading(n));
|
|
1229
1247
|
break;
|
|
1230
1248
|
case "paragraph":
|
|
1231
|
-
out.push(paragraph(n));
|
|
1249
|
+
out.push(paragraph(n, [], indent || void 0));
|
|
1232
1250
|
break;
|
|
1233
1251
|
case "bulletList":
|
|
1234
1252
|
case "orderedList":
|
|
@@ -1241,7 +1259,32 @@ function serializeDocx(doc, opts = {}) {
|
|
|
1241
1259
|
for (const c of n.content ?? []) out.push(paragraph(c, [], 720));
|
|
1242
1260
|
break;
|
|
1243
1261
|
case "codeBlock":
|
|
1244
|
-
out.push(
|
|
1262
|
+
out.push(codeBlock(n));
|
|
1263
|
+
break;
|
|
1264
|
+
case "codeGroup":
|
|
1265
|
+
for (const child of n.content ?? []) {
|
|
1266
|
+
if (child.type !== "codeBlock") {
|
|
1267
|
+
warnings.push(`codeGroup 里出现非代码块节点 "${child.type}",已跳过`);
|
|
1268
|
+
continue;
|
|
1269
|
+
}
|
|
1270
|
+
out.push(`<w:p><w:r><w:rPr><w:b/></w:rPr><w:t xml:space="preserve">${esc(codeLabel(child))}</w:t></w:r></w:p>`);
|
|
1271
|
+
out.push(codeBlock(child));
|
|
1272
|
+
}
|
|
1273
|
+
break;
|
|
1274
|
+
case "details":
|
|
1275
|
+
out.push(boldParagraph(String(n.attrs?.title ?? "") || "详情", indent));
|
|
1276
|
+
out.push(blocks(n.content ?? [], indent));
|
|
1277
|
+
break;
|
|
1278
|
+
case "callout": {
|
|
1279
|
+
const type = String(n.attrs?.type ?? "info");
|
|
1280
|
+
const title = String(n.attrs?.title ?? "") || calloutDefaultTitle(type);
|
|
1281
|
+
out.push(boldParagraph(title, indent));
|
|
1282
|
+
out.push(blocks(n.content ?? [], indent + 720));
|
|
1283
|
+
break;
|
|
1284
|
+
}
|
|
1285
|
+
case "apiParam":
|
|
1286
|
+
out.push(apiParamHeader(n, indent));
|
|
1287
|
+
out.push(blocks(n.content ?? [], indent + 720));
|
|
1245
1288
|
break;
|
|
1246
1289
|
case "horizontalRule":
|
|
1247
1290
|
out.push('<w:p><w:pPr><w:pBdr><w:bottom w:val="single" w:sz="6" w:color="auto"/></w:pBdr></w:pPr></w:p>');
|
|
@@ -1338,6 +1381,13 @@ function cssFontStack(v) {
|
|
|
1338
1381
|
if (!parts.length) return null;
|
|
1339
1382
|
return { ascii: parts[0], eastAsia: parts[parts.length - 1] };
|
|
1340
1383
|
}
|
|
1384
|
+
function calloutDefaultTitle(type) {
|
|
1385
|
+
return { info: "信息", tip: "提示", warning: "注意", danger: "危险" }[type] ?? "信息";
|
|
1386
|
+
}
|
|
1387
|
+
function codeLabel(n) {
|
|
1388
|
+
const attrs = n.attrs ?? {};
|
|
1389
|
+
return getCodeBlockTitle({ language: attrs.language ?? null, label: attrs.label ?? null });
|
|
1390
|
+
}
|
|
1341
1391
|
function collectText(n) {
|
|
1342
1392
|
if (n?.type === "text") return n.text ?? "";
|
|
1343
1393
|
return (n?.content ?? []).map(collectText).join("");
|