@andares/pdeditor 0.2.1 → 0.4.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/dist/index.d.ts CHANGED
@@ -1,5 +1,6 @@
1
1
  import { type PdEditorInstance, type PdEditorOptions } from "./core";
2
2
  export type { EditorLang, PdEditorInstance, PdEditorOptions } from "./core";
3
+ export { format, jsonToPdText, pdToJsonText } from "@andares/pdfoundation";
3
4
  /**
4
5
  * Headless 提示词输入框(基于 Yace)——全量入口。
5
6
  * 支持语言:pd(自研 tokenizer)/ md / xml / json / yaml(Prism)。
package/dist/index.js CHANGED
@@ -1,3 +1,4 @@
1
+ import { format as We, jsonToPdText as Ke, pdToJsonText as Ge } from "@andares/pdfoundation";
1
2
  function ye(n, a, { signal: e, edges: t } = {}) {
2
3
  let l, c = null;
3
4
  const v = t != null && t.includes("leading"), o = t == null || t.includes("trailing"), p = () => {
@@ -295,7 +296,7 @@ function Le(n, a, e) {
295
296
  textarea: p
296
297
  };
297
298
  }
298
- function X(n) {
299
+ function J(n) {
299
300
  const a = [];
300
301
  let e = "", t = !1;
301
302
  for (const l of n)
@@ -303,14 +304,14 @@ function X(n) {
303
304
  return e && a.push({ code: !1, seg: e }), a;
304
305
  }
305
306
  function Y(n) {
306
- for (const { code: a, seg: e } of X(n))
307
+ for (const { code: a, seg: e } of J(n))
307
308
  if (!a && (e.includes(":-") || e.includes(":-")))
308
309
  return !0;
309
310
  return !1;
310
311
  }
311
312
  function V(n) {
312
313
  let a = 0;
313
- for (const { code: e, seg: t } of X(n)) {
314
+ for (const { code: e, seg: t } of J(n)) {
314
315
  if (!e) {
315
316
  const l = t.indexOf(":");
316
317
  if (l !== -1) return a + l;
@@ -331,7 +332,7 @@ function se(n) {
331
332
  function C(n) {
332
333
  return n.replace(/&/g, "&amp;").replace(/</g, "&lt;").replace(/>/g, "&gt;").replace(/"/g, "&quot;");
333
334
  }
334
- const T = {
335
+ const P = {
335
336
  key: "pd-key",
336
337
  keyPunct: "pd-key-punct",
337
338
  item: "pd-item",
@@ -342,7 +343,7 @@ const T = {
342
343
  fence: "pd-fence"
343
344
  };
344
345
  function Ce(n) {
345
- return `<span class="${T.inlineCode}">${C(n)}</span>`;
346
+ return `<span class="${P.inlineCode}">${C(n)}</span>`;
346
347
  }
347
348
  const le = /(?:^|\s):([^\s-][^\s]*)(?=\s|$)/g;
348
349
  function _e(n) {
@@ -351,31 +352,31 @@ function _e(n) {
351
352
  let t;
352
353
  for (; (t = le.exec(n)) !== null; ) {
353
354
  const l = /^\s/.test(t[0]) ? 1 : 0, c = t.index + l;
354
- a += C(n.slice(e, c)), a += `<span class="${T.ref}">${C(n.slice(c, t.index + t[0].length))}</span>`, e = t.index + t[0].length;
355
+ a += C(n.slice(e, c)), a += `<span class="${P.ref}">${C(n.slice(c, t.index + t[0].length))}</span>`, e = t.index + t[0].length;
355
356
  }
356
357
  return a += C(n.slice(e)), a;
357
358
  }
358
359
  function D(n) {
359
360
  let a = "";
360
- for (const { code: e, seg: t } of X(n))
361
+ for (const { code: e, seg: t } of J(n))
361
362
  a += e ? Ce(t) : _e(t);
362
363
  return a;
363
364
  }
364
365
  function oe(n, a, e, t) {
365
- const l = `<span class="${T.key}">${D(e)}</span>`, c = `<span class="${T.keyPunct}">:</span>`;
366
+ const l = `<span class="${P.key}">${D(e)}</span>`, c = `<span class="${P.keyPunct}">:</span>`;
366
367
  return `${n}${a}${l}${c}${D(t)}`;
367
368
  }
368
- function Pe(n) {
369
+ function Te(n) {
369
370
  const a = n.trim();
370
371
  if (/^\/\/!pd(?:\s+[^\s]+)?$/.test(a)) {
371
372
  const t = /^(\s*)(\/\/!pd)(\s*.*)$/.exec(n), l = (t == null ? void 0 : t[1]) ?? "", c = (t == null ? void 0 : t[2]) ?? "//!pd", v = (t == null ? void 0 : t[3]) ?? "";
372
- return `${C(l)}<span class="${T.section}">${C(c)}</span>${D(v)}`;
373
+ return `${C(l)}<span class="${P.section}">${C(c)}</span>${D(v)}`;
373
374
  }
374
375
  if (a === "---")
375
- return `<span class="${T.sep}">${C(n)}</span>`;
376
+ return `<span class="${P.sep}">${C(n)}</span>`;
376
377
  const e = /^(\s*)(-)(?=\s|$)/.exec(n);
377
378
  if (e) {
378
- const t = C(e[1] ?? ""), l = (e[1] ?? "").length + 1, c = n.slice(l), v = c.trimStart(), o = c.slice(0, c.length - v.length), p = `<span class="${T.item}">-</span>`;
379
+ const t = C(e[1] ?? ""), l = (e[1] ?? "").length + 1, c = n.slice(l), v = c.trimStart(), o = c.slice(0, c.length - v.length), p = `<span class="${P.item}">-</span>`;
379
380
  if (!Y(v) && se(v)) {
380
381
  const b = V(v), k = v.slice(0, b), $ = v.slice(b + 1);
381
382
  return `${t}${p}${C(o)}${oe("", "", k, $)}`;
@@ -388,7 +389,7 @@ function Pe(n) {
388
389
  }
389
390
  return D(n);
390
391
  }
391
- function Te(n) {
392
+ function Pe(n) {
392
393
  const a = n.split(`
393
394
  `);
394
395
  let e = !1;
@@ -396,14 +397,14 @@ function Te(n) {
396
397
  for (const l of a) {
397
398
  const c = l.trimStart();
398
399
  if (e) {
399
- c.startsWith("```") ? (e = !1, t.push(`<span class="${T.fence}">${C(l)}</span>`)) : t.push(C(l));
400
+ c.startsWith("```") ? (e = !1, t.push(`<span class="${P.fence}">${C(l)}</span>`)) : t.push(C(l));
400
401
  continue;
401
402
  }
402
403
  if (c.startsWith("```")) {
403
- e = !0, t.push(`<span class="${T.fence}">${C(l)}</span>`);
404
+ e = !0, t.push(`<span class="${P.fence}">${C(l)}</span>`);
404
405
  continue;
405
406
  }
406
- t.push(Pe(l));
407
+ t.push(Te(l));
407
408
  }
408
409
  return t.join(`
409
410
  `);
@@ -1037,41 +1038,41 @@ function Re() {
1037
1038
  for (var E = 0; E < h.length; ++E) {
1038
1039
  if (g && g.cause == m + "," + E)
1039
1040
  return;
1040
- var F = h[E], I = F.inside, J = !!F.lookbehind, Q = !!F.greedy, he = F.alias;
1041
+ var F = h[E], I = F.inside, X = !!F.lookbehind, Q = !!F.greedy, he = F.alias;
1041
1042
  if (Q && !F.pattern.global) {
1042
1043
  var fe = F.pattern.toString().match(/[imsuy]*$/)[0];
1043
1044
  F.pattern = RegExp(F.pattern.source, fe + "g");
1044
1045
  }
1045
- for (var ee = F.pattern || F, L = d.next, P = s; L !== r.tail && !(g && P >= g.reach); P += L.value.length, L = L.next) {
1046
- var O = L.value;
1046
+ for (var ee = F.pattern || F, L = d.next, T = s; L !== r.tail && !(g && T >= g.reach); T += L.value.length, L = L.next) {
1047
+ var j = L.value;
1047
1048
  if (r.length > i.length)
1048
1049
  return;
1049
- if (!(O instanceof p)) {
1050
+ if (!(j instanceof p)) {
1050
1051
  var z = 1, _;
1051
1052
  if (Q) {
1052
- if (_ = A(ee, P, i, J), !_ || _.index >= i.length)
1053
+ if (_ = A(ee, T, i, X), !_ || _.index >= i.length)
1053
1054
  break;
1054
- var M = _.index, me = _.index + _[0].length, R = P;
1055
+ var M = _.index, me = _.index + _[0].length, R = T;
1055
1056
  for (R += L.value.length; M >= R; )
1056
1057
  L = L.next, R += L.value.length;
1057
- if (R -= L.value.length, P = R, L.value instanceof p)
1058
+ if (R -= L.value.length, T = R, L.value instanceof p)
1058
1059
  continue;
1059
- for (var j = L; j !== r.tail && (R < me || typeof j.value == "string"); j = j.next)
1060
- z++, R += j.value.length;
1061
- z--, O = i.slice(P, R), _.index -= P;
1062
- } else if (_ = A(ee, 0, O, J), !_)
1060
+ for (var O = L; O !== r.tail && (R < me || typeof O.value == "string"); O = O.next)
1061
+ z++, R += O.value.length;
1062
+ z--, j = i.slice(T, R), _.index -= T;
1063
+ } else if (_ = A(ee, 0, j, X), !_)
1063
1064
  continue;
1064
- var M = _.index, H = _[0], K = O.slice(0, M), te = O.slice(M + H.length), G = P + O.length;
1065
+ var M = _.index, H = _[0], K = j.slice(0, M), te = j.slice(M + H.length), G = T + j.length;
1065
1066
  g && G > g.reach && (g.reach = G);
1066
1067
  var q = L.prev;
1067
- K && (q = $(r, q, K), P += K.length), S(r, q, z);
1068
+ K && (q = $(r, q, K), T += K.length), S(r, q, z);
1068
1069
  var ve = new p(m, I ? o.tokenize(H, I) : H, he, H);
1069
1070
  if (L = $(r, q, ve), te && $(r, L, te), z > 1) {
1070
1071
  var Z = {
1071
1072
  cause: m + "," + E,
1072
1073
  reach: G
1073
1074
  };
1074
- b(i, r, u, L.prev, P, Z), g && Z.reach > g.reach && (g.reach = Z.reach);
1075
+ b(i, r, u, L.prev, T, Z), g && Z.reach > g.reach && (g.reach = Z.reach);
1075
1076
  }
1076
1077
  }
1077
1078
  }
@@ -1571,8 +1572,8 @@ function Re() {
1571
1572
  })();
1572
1573
  })(U)), U.exports;
1573
1574
  }
1574
- var Oe = Re();
1575
- const de = /* @__PURE__ */ Ie(Oe);
1575
+ var je = Re();
1576
+ const de = /* @__PURE__ */ Ie(je);
1576
1577
  Prism.languages.markup = {
1577
1578
  comment: {
1578
1579
  pattern: /<!--(?:(?!<!--)[\s\S])*?-->/,
@@ -2137,7 +2138,7 @@ Prism.languages.webmanifest = Prism.languages.json;
2137
2138
  punctuation: /---|[:[\]{}\-,|>?]|\.\.\./
2138
2139
  }, n.languages.yml = n.languages.yaml;
2139
2140
  })(Prism);
2140
- function je(n, a) {
2141
+ function Oe(n, a) {
2141
2142
  const e = de.languages[a];
2142
2143
  return e ? de.highlight(n, e, a) : De(n);
2143
2144
  }
@@ -2160,15 +2161,18 @@ function ze(n) {
2160
2161
  }
2161
2162
  function Me(n) {
2162
2163
  return (a) => {
2163
- if (n === "pd") return Te(a);
2164
+ if (n === "pd") return Pe(a);
2164
2165
  const e = ze(n);
2165
- return e ? je(a, e) : Ae(a);
2166
+ return e ? Oe(a, e) : Ae(a);
2166
2167
  };
2167
2168
  }
2168
2169
  function He(n, a = {}) {
2169
2170
  return Le(n, a, Me);
2170
2171
  }
2171
2172
  export {
2172
- He as createPdEditor
2173
+ He as createPdEditor,
2174
+ We as format,
2175
+ Ke as jsonToPdText,
2176
+ Ge as pdToJsonText
2173
2177
  };
2174
2178
  //# sourceMappingURL=index.js.map