@andares/pdeditor 0.4.1 → 0.5.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 +359 -79
- package/dist/core.d.ts +68 -13
- package/dist/element-auto.cjs +46 -0
- package/dist/element-auto.d.ts +1 -0
- package/dist/element-auto.js +868 -0
- package/dist/element.cjs +46 -0
- package/dist/element.d.ts +43 -0
- package/dist/element.js +867 -0
- package/dist/highlighters.d.ts +1 -1
- package/dist/index.cjs +16 -16
- package/dist/index.d.ts +9 -2
- package/dist/index.js +864 -774
- package/dist/inline.d.ts +4 -23
- package/dist/pd-highlight.d.ts +1 -1
- package/dist/pd.cjs +14 -14
- package/dist/pd.d.ts +2 -2
- package/dist/pd.js +436 -352
- package/dist/plugins.d.ts +14 -2
- package/dist/react.cjs +46 -0
- package/dist/react.d.ts +30 -0
- package/dist/react.js +937 -0
- package/package.json +51 -11
- package/dist/index.cjs.map +0 -1
- package/dist/index.js.map +0 -1
- package/dist/pd.cjs.map +0 -1
- package/dist/pd.js.map +0 -1
package/dist/pd.js
CHANGED
|
@@ -1,338 +1,423 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
1
|
+
import { hasLiteralColon as me, matchKeyValue as be, findKeyValueSeparator as ve, splitInlineCode as De } from "@andares/pdfoundation";
|
|
2
|
+
import { format as Qe, jsonToPdText as Ue, pdToJsonText as et } from "@andares/pdfoundation";
|
|
3
|
+
function Fe(i, o, { signal: s, edges: e } = {}) {
|
|
4
|
+
let l, r = null;
|
|
5
|
+
const u = e != null && e.includes("leading"), p = e == null || e.includes("trailing"), b = () => {
|
|
6
|
+
r !== null && (i.apply(l, r), l = void 0, r = null);
|
|
7
|
+
}, w = () => {
|
|
8
|
+
p && b(), $();
|
|
8
9
|
};
|
|
9
|
-
let
|
|
10
|
-
const
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
},
|
|
14
|
-
},
|
|
15
|
-
|
|
16
|
-
},
|
|
17
|
-
|
|
18
|
-
},
|
|
19
|
-
|
|
20
|
-
},
|
|
21
|
-
if (
|
|
22
|
-
|
|
23
|
-
const
|
|
24
|
-
|
|
10
|
+
let v = null;
|
|
11
|
+
const E = () => {
|
|
12
|
+
v != null && clearTimeout(v), v = setTimeout(() => {
|
|
13
|
+
v = null, w();
|
|
14
|
+
}, o);
|
|
15
|
+
}, S = () => {
|
|
16
|
+
v !== null && (clearTimeout(v), v = null);
|
|
17
|
+
}, $ = () => {
|
|
18
|
+
S(), l = void 0, r = null;
|
|
19
|
+
}, y = () => {
|
|
20
|
+
b();
|
|
21
|
+
}, L = function(...d) {
|
|
22
|
+
if (s != null && s.aborted) return;
|
|
23
|
+
l = this, r = d;
|
|
24
|
+
const h = v == null;
|
|
25
|
+
E(), u && h && b();
|
|
25
26
|
};
|
|
26
|
-
return
|
|
27
|
+
return L.schedule = E, L.cancel = $, L.flush = y, s == null || s.addEventListener("abort", $, { once: !0 }), L;
|
|
27
28
|
}
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
return e.length === 0 ? q : (n) => e.reduce((t, i, o) => i(t, { html: o > 0 }), n);
|
|
29
|
+
function Z(i, o) {
|
|
30
|
+
const s = i, e = s.key.toLowerCase(), l = o.split("+"), r = l.slice(0, -1), u = l[l.length - 1];
|
|
31
|
+
return !(e !== u || r.includes("shift") !== s.shiftKey || r.includes("ctrl") !== s.ctrlKey || r.includes("alt") !== s.altKey || r.includes("meta") !== s.metaKey);
|
|
32
32
|
}
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
if (this.root = e instanceof Node ? e : document.querySelector(e), !this.root) throw new Error(`element with "${e}" selector is not exist`);
|
|
37
|
-
const t = { value: "", styles: {}, plugins: [], highlighter: q }, { highlighters: i, ...o } = n;
|
|
38
|
-
this.options = { ...t, ...o, highlighter: i ? D(i) : t.highlighter }, this.options.value = this.options.value == null ? "" : String(this.options.value), this.init();
|
|
39
|
-
}
|
|
40
|
-
init() {
|
|
41
|
-
this.textarea = document.createElement("textarea"), this.textarea.setAttribute("spellcheck", "false"), this.textarea.setAttribute("autocapitalize", "off"), this.textarea.setAttribute("autocorrect", "off"), this.textarea.setAttribute("autocomplete", "off"), this.pre = document.createElement("pre");
|
|
42
|
-
const e = Object.keys(A).concat(Object.keys(this.options.styles)).concat(["paddingLeft"]);
|
|
43
|
-
this.initialRootStyles = {};
|
|
44
|
-
const n = this.root.style;
|
|
45
|
-
e.forEach((t) => {
|
|
46
|
-
this.initialRootStyles[t] = n[t] || "";
|
|
47
|
-
}), Object.assign(this.root.style, A, this.options.styles), Object.assign(this.textarea.style, J), Object.assign(this.pre.style, G), this.basePaddingLeft = this.root.style.paddingLeft || "", this.root.appendChild(this.textarea), this.root.appendChild(this.pre), this.addTextareaEvents(), this.update({ value: this.options.value }), this.updateLines();
|
|
48
|
-
}
|
|
49
|
-
addTextareaEvents() {
|
|
50
|
-
this.handleEvent = (e) => {
|
|
51
|
-
if (e.type === "keydown" && this.textarea.readOnly) return;
|
|
52
|
-
const n = e;
|
|
53
|
-
if (n.isComposing || n.keyCode === 229) return;
|
|
54
|
-
const t = (function(i, o) {
|
|
55
|
-
const { value: a, selectionStart: c, selectionEnd: l } = o.target;
|
|
56
|
-
return i.reduce((f, h) => ({ ...f, ...h(f, o) }), { value: a, selectionStart: c, selectionEnd: l });
|
|
57
|
-
})(this.options.plugins, e);
|
|
58
|
-
this.update(t);
|
|
59
|
-
}, this.textarea.addEventListener("input", this.handleEvent), this.textarea.addEventListener("keydown", this.handleEvent), this.textarea.addEventListener("compositionend", this.handleEvent);
|
|
60
|
-
}
|
|
61
|
-
update(e) {
|
|
62
|
-
if (!this.textarea) return;
|
|
63
|
-
let { value: n, selectionStart: t, selectionEnd: i } = e;
|
|
64
|
-
n != null && (n = String(n), t == null && (t = this.textarea.selectionStart), i == null && (i = this.textarea.selectionEnd), this.textarea.value !== n && (this.textarea.value = n)), t != null && (this.textarea.selectionStart = t), i != null && (this.textarea.selectionEnd = i), n !== this.value && n != null && (this.value = n, this.render(), this.updateCallback && this.updateCallback(n));
|
|
65
|
-
}
|
|
66
|
-
updateOptions(e) {
|
|
67
|
-
if (!this.textarea) return;
|
|
68
|
-
const { highlighters: n, ...t } = e;
|
|
69
|
-
if (this.options = { ...this.options, ...t, highlighter: n ? D(n) : this.options.highlighter }, e.styles) {
|
|
70
|
-
const i = this.root.style;
|
|
71
|
-
Object.keys(e.styles).forEach((o) => {
|
|
72
|
-
o in this.initialRootStyles || (this.initialRootStyles[o] = i[o] || "");
|
|
73
|
-
}), Object.assign(this.root.style, e.styles), ("paddingLeft" in e.styles || "padding" in e.styles) && (this.basePaddingLeft = this.root.style.paddingLeft || "");
|
|
74
|
-
}
|
|
75
|
-
this.lines && !this.options.lineNumbers && (T(this.lines), this.lines = null, this.root.style.paddingLeft = this.basePaddingLeft), e.value != null && this.update({ value: e.value }), this.render();
|
|
76
|
-
}
|
|
77
|
-
render() {
|
|
78
|
-
const e = this.options.highlighter(this.value);
|
|
79
|
-
this.pre.innerHTML = e + "<br/>", this.updateLines();
|
|
80
|
-
}
|
|
81
|
-
updateLines() {
|
|
82
|
-
if (!this.options.lineNumbers) return;
|
|
83
|
-
this.lines || (this.lines = document.createElement("pre"), this.root.appendChild(this.lines), Object.assign(this.lines.style, Q));
|
|
84
|
-
const e = this.value.split(`
|
|
85
|
-
`), n = e.length.toString().length;
|
|
86
|
-
this.root.style.paddingLeft = `${n + 1}ch`, this.lines.innerHTML = e.map((t, i) => `${`<span class="yace-line" style="position: absolute; opacity: .3; left: 0; width: ${n}ch; text-align: right">${1 + i}</span>`}${`<span style="color: transparent; pointer-events: none">${B(t)}</span>`}`).join(`
|
|
33
|
+
function ye(i, o) {
|
|
34
|
+
var l;
|
|
35
|
+
const e = i.slice(0, o).split(`
|
|
87
36
|
`);
|
|
88
|
-
}
|
|
89
|
-
destroy() {
|
|
90
|
-
this.textarea && (this.textarea.removeEventListener("input", this.handleEvent), this.textarea.removeEventListener("keydown", this.handleEvent), this.textarea.removeEventListener("compositionend", this.handleEvent), T(this.textarea), T(this.pre), T(this.lines), Object.assign(this.root.style, this.initialRootStyles), Object.assign(this, { textarea: null, pre: null, lines: null, updateCallback: null, handleEvent: null, initialRootStyles: null, options: null, root: null }));
|
|
91
|
-
}
|
|
92
|
-
onUpdate(e) {
|
|
93
|
-
this.updateCallback = e;
|
|
94
|
-
}
|
|
37
|
+
return { line: e.length - 1, col: ((l = e[e.length - 1]) == null ? void 0 : l.length) ?? 0 };
|
|
95
38
|
}
|
|
96
|
-
function
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
return
|
|
101
|
-
}
|
|
102
|
-
function K(s, e) {
|
|
103
|
-
const n = s, t = n.key.toLowerCase(), i = e.split("+"), o = i.slice(0, -1), a = i[i.length - 1];
|
|
104
|
-
return !(t !== a || o.includes("shift") !== n.shiftKey || o.includes("ctrl") !== n.ctrlKey || o.includes("alt") !== n.altKey || o.includes("meta") !== n.metaKey);
|
|
105
|
-
}
|
|
106
|
-
function M(s, e) {
|
|
107
|
-
var i;
|
|
108
|
-
const t = s.slice(0, e).split(`
|
|
109
|
-
`);
|
|
110
|
-
return { line: t.length - 1, col: ((i = t[t.length - 1]) == null ? void 0 : i.length) ?? 0 };
|
|
111
|
-
}
|
|
112
|
-
function O(s, e, n) {
|
|
113
|
-
var i;
|
|
114
|
-
let t = 0;
|
|
115
|
-
for (let o = 0; o < e; o++) t += (((i = s[o]) == null ? void 0 : i.length) ?? 0) + 1;
|
|
116
|
-
return t + n;
|
|
39
|
+
function O(i, o, s) {
|
|
40
|
+
var l;
|
|
41
|
+
let e = 0;
|
|
42
|
+
for (let r = 0; r < o; r++) e += (((l = i[r]) == null ? void 0 : l.length) ?? 0) + 1;
|
|
43
|
+
return e + s;
|
|
117
44
|
}
|
|
118
|
-
function
|
|
119
|
-
return (
|
|
120
|
-
var
|
|
121
|
-
if (
|
|
122
|
-
const { value:
|
|
123
|
-
`).pop() ?? "",
|
|
124
|
-
|
|
125
|
-
const
|
|
126
|
-
${
|
|
45
|
+
function Le() {
|
|
46
|
+
return (i, o) => {
|
|
47
|
+
var w;
|
|
48
|
+
if (o.type !== "keydown" || !Z(o, "enter")) return;
|
|
49
|
+
const { value: s, selectionStart: e, selectionEnd: l } = i, r = s.slice(0, e).split(`
|
|
50
|
+
`).pop() ?? "", u = ((w = /^\s*/.exec(r)) == null ? void 0 : w[0]) ?? "";
|
|
51
|
+
o.preventDefault();
|
|
52
|
+
const p = /^(\s*)-(?=[ ]|$)/.test(r), b = `
|
|
53
|
+
${u}${p ? "- " : ""}`;
|
|
127
54
|
return {
|
|
128
|
-
value:
|
|
129
|
-
selectionStart:
|
|
130
|
-
selectionEnd:
|
|
55
|
+
value: s.slice(0, e) + b + s.slice(l),
|
|
56
|
+
selectionStart: e + b.length,
|
|
57
|
+
selectionEnd: e + b.length
|
|
131
58
|
};
|
|
132
59
|
};
|
|
133
60
|
}
|
|
134
|
-
function
|
|
135
|
-
return /^(\s*)-(
|
|
61
|
+
function Pe(i) {
|
|
62
|
+
return /^(\s*)-(?=[ ]|$)/.test(i);
|
|
136
63
|
}
|
|
137
|
-
function
|
|
138
|
-
return
|
|
64
|
+
function xe(i, o) {
|
|
65
|
+
return i.startsWith(o) ? o.length : i.startsWith(" ") ? 1 : 0;
|
|
139
66
|
}
|
|
140
|
-
function
|
|
141
|
-
return (
|
|
142
|
-
if (
|
|
143
|
-
const { value:
|
|
144
|
-
`),
|
|
145
|
-
`).length - 1,
|
|
146
|
-
`).length - 1,
|
|
147
|
-
if (
|
|
148
|
-
|
|
149
|
-
const
|
|
150
|
-
(
|
|
151
|
-
),
|
|
67
|
+
function Ee(i) {
|
|
68
|
+
return (o, s) => {
|
|
69
|
+
if (s.type !== "keydown") return;
|
|
70
|
+
const { value: e, selectionStart: l, selectionEnd: r } = o, u = e.split(`
|
|
71
|
+
`), p = e.slice(0, l).split(`
|
|
72
|
+
`).length - 1, b = e.slice(0, r).split(`
|
|
73
|
+
`).length - 1, w = ye(e, l), v = ye(e, r);
|
|
74
|
+
if (Z(s, "shift+tab")) {
|
|
75
|
+
s.preventDefault();
|
|
76
|
+
const E = u.map(
|
|
77
|
+
(d, h) => h >= p && h <= b ? d.slice(xe(d, i)) : d
|
|
78
|
+
), S = E.join(`
|
|
152
79
|
`);
|
|
153
|
-
if (
|
|
154
|
-
const
|
|
155
|
-
const
|
|
156
|
-
return { line:
|
|
157
|
-
},
|
|
80
|
+
if (S === e) return;
|
|
81
|
+
const $ = (d) => {
|
|
82
|
+
const h = xe(u[d.line] ?? "", i);
|
|
83
|
+
return { line: d.line, col: Math.max(0, d.col - h) };
|
|
84
|
+
}, y = $(w), L = $(v);
|
|
158
85
|
return {
|
|
159
|
-
value:
|
|
160
|
-
selectionStart: O(
|
|
161
|
-
selectionEnd: O(
|
|
86
|
+
value: S,
|
|
87
|
+
selectionStart: O(E, y.line, y.col),
|
|
88
|
+
selectionEnd: O(E, L.line, L.col)
|
|
162
89
|
};
|
|
163
90
|
}
|
|
164
|
-
if (
|
|
165
|
-
|
|
166
|
-
const
|
|
167
|
-
if (
|
|
168
|
-
const
|
|
169
|
-
(x,
|
|
170
|
-
),
|
|
171
|
-
`),
|
|
172
|
-
const
|
|
91
|
+
if (Z(s, "tab")) {
|
|
92
|
+
s.preventDefault();
|
|
93
|
+
const E = u.map((y, L) => ({ l: y, i: L })).filter(({ i: y }) => y >= p && y <= b);
|
|
94
|
+
if (E.length > 0 && E.every(({ l: y }) => Pe(y)) || l !== r) {
|
|
95
|
+
const y = u.map(
|
|
96
|
+
(x, g) => g >= p && g <= b && x !== "" ? i + x : x
|
|
97
|
+
), L = y.join(`
|
|
98
|
+
`), d = (x) => {
|
|
99
|
+
const g = u[x.line] ?? "", Q = x.line >= p && x.line <= b;
|
|
173
100
|
return {
|
|
174
101
|
line: x.line,
|
|
175
|
-
col:
|
|
102
|
+
col: Q && g !== "" ? x.col + i.length : x.col
|
|
176
103
|
};
|
|
177
|
-
},
|
|
104
|
+
}, h = d(w), n = d(v);
|
|
178
105
|
return {
|
|
179
|
-
value:
|
|
180
|
-
selectionStart: O(
|
|
181
|
-
selectionEnd: O(
|
|
106
|
+
value: L,
|
|
107
|
+
selectionStart: O(y, h.line, h.col),
|
|
108
|
+
selectionEnd: O(y, n.line, n.col)
|
|
182
109
|
};
|
|
183
110
|
}
|
|
184
|
-
const
|
|
111
|
+
const $ = l + i.length;
|
|
185
112
|
return {
|
|
186
|
-
value:
|
|
187
|
-
selectionStart:
|
|
188
|
-
selectionEnd:
|
|
113
|
+
value: e.slice(0, l) + i + e.slice(r),
|
|
114
|
+
selectionStart: $,
|
|
115
|
+
selectionEnd: $
|
|
189
116
|
};
|
|
190
117
|
}
|
|
191
118
|
};
|
|
192
119
|
}
|
|
193
|
-
function
|
|
194
|
-
return
|
|
120
|
+
function ze(i) {
|
|
121
|
+
return i.replace(/&/g, "&").replace(/</g, "<").replace(/>/g, ">").replace(/"/g, """).replace(/'/g, "'");
|
|
195
122
|
}
|
|
196
|
-
function
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
for (; t < n && s.charCodeAt(t) === e.charCodeAt(t); ) t++;
|
|
200
|
-
return t;
|
|
123
|
+
function F(i) {
|
|
124
|
+
return i.replace(/\r\n?/g, `
|
|
125
|
+
`);
|
|
201
126
|
}
|
|
202
|
-
function
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
127
|
+
function Be(i, o) {
|
|
128
|
+
const s = document.createRange();
|
|
129
|
+
s.selectNodeContents(i), i.replaceChildren(s.createContextualFragment(o));
|
|
130
|
+
}
|
|
131
|
+
function He(i, o) {
|
|
132
|
+
const s = Math.min(i.length, o.length);
|
|
133
|
+
let e = 0;
|
|
134
|
+
for (; e < s && i.charCodeAt(e) === o.charCodeAt(e); ) e++;
|
|
135
|
+
return e;
|
|
136
|
+
}
|
|
137
|
+
const Ke = /* @__PURE__ */ new Set([
|
|
138
|
+
"padding",
|
|
139
|
+
"paddingTop",
|
|
140
|
+
"paddingRight",
|
|
141
|
+
"paddingBottom",
|
|
142
|
+
"paddingLeft"
|
|
143
|
+
]);
|
|
144
|
+
function Se(i) {
|
|
145
|
+
var e;
|
|
146
|
+
const o = {
|
|
147
|
+
top: "0px",
|
|
148
|
+
right: "0px",
|
|
149
|
+
bottom: "0px",
|
|
150
|
+
left: "0px"
|
|
151
|
+
}, s = (e = i.padding) == null ? void 0 : e.trim();
|
|
152
|
+
if (s) {
|
|
153
|
+
const l = s.split(/\s+/);
|
|
154
|
+
if (l.length === 1) {
|
|
155
|
+
const r = l[0] ?? "0px";
|
|
156
|
+
o.top = o.right = o.bottom = o.left = r;
|
|
157
|
+
} else l.length === 2 ? (o.top = o.bottom = l[0] ?? "0px", o.right = o.left = l[1] ?? "0px") : l.length === 3 ? (o.top = l[0] ?? "0px", o.right = o.left = l[1] ?? "0px", o.bottom = l[2] ?? "0px") : (o.top = l[0] ?? "0px", o.right = l[1] ?? "0px", o.bottom = l[2] ?? "0px", o.left = l[3] ?? "0px");
|
|
158
|
+
}
|
|
159
|
+
return i.paddingTop && (o.top = i.paddingTop), i.paddingRight && (o.right = i.paddingRight), i.paddingBottom && (o.bottom = i.paddingBottom), i.paddingLeft && (o.left = i.paddingLeft), o;
|
|
160
|
+
}
|
|
161
|
+
function Ie(i) {
|
|
162
|
+
return i.startsWith("--") ? i : i.replace(/[A-Z]/g, (o) => `-${o.toLowerCase()}`);
|
|
163
|
+
}
|
|
164
|
+
const $e = "position:relative;display:block;box-sizing:border-box;width:100%;height:auto;max-height:inherit;overflow:hidden;text-align:start;margin:0;border:0;font-family:var(--pd-font-family,inherit);font-size:var(--pd-font-size,inherit);line-height:var(--pd-line-height,1.5);letter-spacing:var(--pd-letter-spacing,inherit);color:var(--pd-color,inherit);background:var(--pd-background,transparent);tab-size:4;font-variant-ligatures:none;font-kerning:normal;", ke = "position:absolute;left:0;top:0;width:100%;height:100%;box-sizing:border-box;margin:0;border:0;outline:none;resize:none;background:transparent;-webkit-text-fill-color:transparent;caret-color:var(--pd-caret-color,currentColor);overflow:auto;scrollbar-gutter:stable;white-space:pre-wrap;overflow-wrap:break-word;word-break:normal;font:inherit;line-height:inherit;letter-spacing:inherit;tab-size:inherit;z-index:2;", Ce = "position:relative;left:auto;top:auto;width:100%;height:auto;box-sizing:border-box;margin:0;border:0;overflow:hidden;scrollbar-gutter:stable;pointer-events:none;user-select:none;white-space:pre-wrap;overflow-wrap:break-word;word-break:normal;font:inherit;line-height:inherit;letter-spacing:inherit;tab-size:inherit;color:inherit;z-index:1;", Oe = "position:absolute;left:0;top:0;width:100%;height:100%;box-sizing:border-box;margin:0;border:0;overflow:hidden;scrollbar-gutter:stable;pointer-events:none;user-select:none;white-space:pre-wrap;overflow-wrap:break-word;word-break:normal;font:inherit;line-height:inherit;letter-spacing:inherit;tab-size:inherit;color:inherit;z-index:0;", we = "position:absolute;left:0;top:0;width:100%;height:100%;box-sizing:border-box;margin:0;border:0;overflow:hidden;scrollbar-gutter:stable;pointer-events:none;user-select:none;white-space:pre-wrap;overflow-wrap:break-word;word-break:normal;font:inherit;line-height:inherit;letter-spacing:inherit;tab-size:inherit;color:inherit;opacity:var(--pd-placeholder-opacity,0.5);z-index:1;";
|
|
165
|
+
function V(i, o, s, e, l = {}) {
|
|
166
|
+
const r = document.createElement(i);
|
|
167
|
+
r.className = o, r.setAttribute("part", s), r.style.cssText = e;
|
|
168
|
+
for (const [u, p] of Object.entries(l)) r.setAttribute(u, p);
|
|
169
|
+
return r;
|
|
170
|
+
}
|
|
171
|
+
function Ve(i, o, s) {
|
|
172
|
+
let e = { ...o }, l = e.language ?? "pd", r = F(e.value ?? ""), u = r, p = !1, b = !1, w = !1, v = e.lineNumbers ?? !1, E = q(), S = "", $ = !1, y = 0, L = null;
|
|
173
|
+
const d = V("div", "pd-root", "root", $e), h = V("pre", "pd-highlight", "highlight", Ce, {
|
|
174
|
+
"aria-hidden": "true"
|
|
175
|
+
}), n = V("textarea", "pd-input", "input", ke), x = V("div", "pd-placeholder", "placeholder", we, {
|
|
176
|
+
"aria-hidden": "true"
|
|
222
177
|
});
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
}
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
const I = te(d.value, r.value);
|
|
245
|
-
d.selStart = I, d.selEnd = I;
|
|
178
|
+
let g = null;
|
|
179
|
+
n.spellcheck = e.spellcheck ?? !1, n.setAttribute("autocapitalize", "off"), n.setAttribute("autocorrect", "off"), n.setAttribute("autocomplete", "off"), n.setAttribute("wrap", "soft"), n.value = r, n.readOnly = e.readOnly ?? !1, n.disabled = e.disabled ?? !1, ((t) => {
|
|
180
|
+
t !== void 0 && t >= 0 ? n.maxLength = t : n.removeAttribute("maxlength");
|
|
181
|
+
})(e.maxLength), e.dir && (n.dir = e.dir), K(), d.appendChild(h), d.appendChild(x), d.appendChild(n), i.appendChild(d), H(), G(), T(), _();
|
|
182
|
+
function M() {
|
|
183
|
+
p || (h.scrollTop = n.scrollTop, h.scrollLeft = n.scrollLeft, g && (g.scrollTop = n.scrollTop, g.scrollLeft = n.scrollLeft));
|
|
184
|
+
}
|
|
185
|
+
function Re() {
|
|
186
|
+
if (typeof getComputedStyle != "function") return 0;
|
|
187
|
+
const t = getComputedStyle(i), a = Number.parseFloat(t.paddingTop) || 0, c = Number.parseFloat(t.paddingBottom) || 0;
|
|
188
|
+
return Math.max(0, i.clientHeight - a - c);
|
|
189
|
+
}
|
|
190
|
+
function j() {
|
|
191
|
+
$ ? (h.style.position = "absolute", h.style.left = "0", h.style.top = "0", h.style.height = "100%") : (h.style.position = "relative", h.style.left = "auto", h.style.top = "auto", h.style.height = "auto");
|
|
192
|
+
}
|
|
193
|
+
function _() {
|
|
194
|
+
if (p) return;
|
|
195
|
+
const t = Re(), a = h.scrollHeight;
|
|
196
|
+
if (!$) {
|
|
197
|
+
t > 0 && a > t + 1 && ($ = !0, j(), d.style.height = `${t}px`, M());
|
|
198
|
+
return;
|
|
246
199
|
}
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
const d = l.selectionStart, v = l.selectionEnd;
|
|
251
|
-
k({ value: r, selStart: d, selEnd: v });
|
|
252
|
-
}, $ = (r) => {
|
|
253
|
-
const d = r.selStart >= 0 ? r.selStart : r.value.length, v = r.selEnd >= 0 ? r.selEnd : r.value.length;
|
|
254
|
-
o = !0, c.update({
|
|
255
|
-
value: r.value,
|
|
256
|
-
selectionStart: d,
|
|
257
|
-
selectionEnd: v
|
|
258
|
-
}), l.value === r.value && l.setSelectionRange(d, v), o = !1;
|
|
259
|
-
}, j = (r) => {
|
|
260
|
-
const d = r.ctrlKey || r.metaKey, v = r.key.toLowerCase();
|
|
261
|
-
if (!d || v !== "z" && v !== "y") return;
|
|
262
|
-
if (v === "y" || v === "z" && r.shiftKey) {
|
|
263
|
-
if (k.flush(), p.length === 0) return;
|
|
264
|
-
r.preventDefault();
|
|
265
|
-
const C = p.pop();
|
|
266
|
-
C !== void 0 && (u.push(C), g(), $(C));
|
|
267
|
-
} else {
|
|
268
|
-
if (k.flush(), u.length <= 1) return;
|
|
269
|
-
r.preventDefault();
|
|
270
|
-
const C = u.pop();
|
|
271
|
-
C !== void 0 && p.push(C);
|
|
272
|
-
const P = u.at(-1);
|
|
273
|
-
P !== void 0 && $(P);
|
|
200
|
+
if (t <= 0 || a <= t + 1) {
|
|
201
|
+
$ = !1, j(), d.style.height = "", n.scrollTop = 0;
|
|
202
|
+
return;
|
|
274
203
|
}
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
204
|
+
const c = Number.parseFloat(d.style.height) || 0;
|
|
205
|
+
Math.abs(c - t) > 0.5 && (d.style.height = `${t}px`), M();
|
|
206
|
+
}
|
|
207
|
+
function U() {
|
|
208
|
+
if (!y) {
|
|
209
|
+
if (typeof requestAnimationFrame != "function") {
|
|
210
|
+
_();
|
|
211
|
+
return;
|
|
212
|
+
}
|
|
213
|
+
y = requestAnimationFrame(() => {
|
|
214
|
+
y = 0, _();
|
|
215
|
+
});
|
|
216
|
+
}
|
|
217
|
+
}
|
|
218
|
+
typeof ResizeObserver < "u" && (L = new ResizeObserver(() => U()), L.observe(i), L.observe(d));
|
|
219
|
+
const ee = () => M(), Me = (t, a, c) => {
|
|
220
|
+
var f;
|
|
221
|
+
r = t, u = t, W({ value: t, selStart: a, selEnd: c }), (f = e.onValueChange) == null || f.call(e, t);
|
|
222
|
+
}, te = (t) => {
|
|
223
|
+
if (p) return;
|
|
224
|
+
const a = F(n.value);
|
|
225
|
+
if (b || t != null && t.isComposing) {
|
|
226
|
+
r = a, T();
|
|
227
|
+
return;
|
|
228
|
+
}
|
|
229
|
+
a !== r && (r = a, T()), a !== u && Me(a, n.selectionStart, n.selectionEnd);
|
|
230
|
+
}, ne = () => {
|
|
231
|
+
b = !0;
|
|
232
|
+
}, ie = () => {
|
|
233
|
+
b = !1;
|
|
234
|
+
const t = F(n.value);
|
|
235
|
+
t !== r && (r = t, T());
|
|
236
|
+
}, Ne = Math.max(0, e.historyLimit ?? 5), re = Math.max(0, e.historyDebounce ?? 1e3), C = [
|
|
237
|
+
{ value: r, selStart: -1, selEnd: -1 }
|
|
238
|
+
], D = [], oe = () => {
|
|
239
|
+
C.length > Ne + 1 && C.splice(1, 1);
|
|
240
|
+
}, le = (t) => {
|
|
241
|
+
const a = C[0];
|
|
242
|
+
if (a !== void 0 && a.selStart < 0 && a.value !== t.value) {
|
|
243
|
+
const f = He(a.value, t.value);
|
|
244
|
+
a.selStart = f, a.selEnd = f;
|
|
245
|
+
}
|
|
246
|
+
const c = C.at(-1);
|
|
247
|
+
c !== void 0 && c.value === t.value || (D.length = 0, C.push(t), oe());
|
|
248
|
+
}, P = Fe(le, re), W = (t) => {
|
|
249
|
+
re === 0 ? le(t) : P(t);
|
|
250
|
+
}, se = (t) => {
|
|
251
|
+
var f;
|
|
252
|
+
const a = t.selStart >= 0 ? t.selStart : Math.min(t.value.length, n.selectionStart), c = t.selEnd >= 0 ? t.selEnd : a;
|
|
253
|
+
r = t.value, u = t.value, n.value = t.value, n.setSelectionRange(
|
|
254
|
+
Math.max(0, Math.min(a, t.value.length)),
|
|
255
|
+
Math.max(0, Math.min(c, t.value.length))
|
|
256
|
+
), T(), M(), (f = e.onValueChange) == null || f.call(e, t.value);
|
|
257
|
+
}, ae = () => {
|
|
258
|
+
if (P.flush(), C.length <= 1) return !1;
|
|
259
|
+
const t = C.pop();
|
|
260
|
+
t !== void 0 && D.push(t);
|
|
261
|
+
const a = C.at(-1);
|
|
262
|
+
return a !== void 0 && se(a), !0;
|
|
263
|
+
}, ce = () => {
|
|
264
|
+
if (P.flush(), D.length === 0) return !1;
|
|
265
|
+
const t = D.pop();
|
|
266
|
+
return t === void 0 ? !1 : (C.push(t), oe(), se(t), !0);
|
|
267
|
+
}, ue = (t) => {
|
|
268
|
+
var A;
|
|
269
|
+
if (p || t.isComposing || b || n.readOnly || n.disabled) return;
|
|
270
|
+
const a = t.ctrlKey || t.metaKey, c = t.key.toLowerCase();
|
|
271
|
+
if (a && (c === "z" || c === "y")) {
|
|
272
|
+
t.preventDefault(), c === "y" || c === "z" && t.shiftKey ? ce() : ae();
|
|
273
|
+
return;
|
|
274
|
+
}
|
|
275
|
+
if (c === "escape") {
|
|
276
|
+
(e.tabBehavior ?? "indent") === "indent" && (w = !0);
|
|
277
|
+
return;
|
|
278
|
+
}
|
|
279
|
+
if (c === "tab" && (e.tabBehavior ?? "indent") === "focus") return;
|
|
280
|
+
if (c === "tab" && w) {
|
|
281
|
+
w = !1;
|
|
282
|
+
return;
|
|
283
|
+
}
|
|
284
|
+
const f = {
|
|
285
|
+
value: r,
|
|
286
|
+
selectionStart: n.selectionStart,
|
|
287
|
+
selectionEnd: n.selectionEnd
|
|
288
|
+
};
|
|
289
|
+
let m = f;
|
|
290
|
+
for (const N of X) {
|
|
291
|
+
const z = N(m, t);
|
|
292
|
+
z && (m = { ...m, ...z });
|
|
293
|
+
}
|
|
294
|
+
(m.value !== f.value || m.selectionStart !== f.selectionStart || m.selectionEnd !== f.selectionEnd) && (t.preventDefault(), r = m.value, n.value = m.value, n.setSelectionRange(m.selectionStart, m.selectionEnd), u = m.value, T(), W({
|
|
295
|
+
value: m.value,
|
|
296
|
+
selStart: m.selectionStart,
|
|
297
|
+
selEnd: m.selectionEnd
|
|
298
|
+
}), (A = e.onValueChange) == null || A.call(e, m.value), M());
|
|
299
|
+
}, de = () => d.classList.add("pd-focused"), fe = () => d.classList.remove("pd-focused");
|
|
300
|
+
n.addEventListener("input", te), n.addEventListener("compositionstart", ne), n.addEventListener("compositionend", ie), n.addEventListener("scroll", ee, { passive: !0 }), n.addEventListener("keydown", ue), n.addEventListener("focus", de), n.addEventListener("blur", fe);
|
|
301
|
+
function q() {
|
|
302
|
+
return e.highlight ? (t) => {
|
|
303
|
+
var a;
|
|
304
|
+
return ((a = e.highlight) == null ? void 0 : a.call(e, t, l)) ?? "";
|
|
305
|
+
} : s(l);
|
|
306
|
+
}
|
|
307
|
+
function T() {
|
|
308
|
+
if (p) return;
|
|
309
|
+
const t = e.highlightThreshold ?? 1e5, a = r.length > t ? ze(r) : E(r);
|
|
310
|
+
Be(h, `${a}<br/>`), v && pe(), G(), L || U();
|
|
311
|
+
}
|
|
312
|
+
function pe() {
|
|
313
|
+
if (!v) return;
|
|
314
|
+
g || (g = document.createElement("pre"), g.className = "pd-lines", g.setAttribute("part", "gutter"), g.setAttribute("aria-hidden", "true"), d.insertBefore(g, x));
|
|
315
|
+
const t = r.split(`
|
|
316
|
+
`), c = `${String(t.length).length + 1}ch`, f = Se(e.styles ?? {}), m = `position:absolute;inset-inline-start:${f.left};width:${c};text-align:end;opacity:var(--pd-gutter-opacity,0.35);color:var(--pd-gutter-color,inherit)`, A = document.createDocumentFragment();
|
|
317
|
+
t.forEach((N, z) => {
|
|
318
|
+
const I = document.createElement("span");
|
|
319
|
+
I.className = "pd-ln", I.style.cssText = m, I.textContent = String(z + 1);
|
|
320
|
+
const Y = document.createElement("span");
|
|
321
|
+
Y.style.color = "transparent", Y.textContent = N, A.append(I, Y), z < t.length - 1 && A.append(document.createTextNode(`
|
|
322
|
+
`));
|
|
323
|
+
}), A.append(document.createElement("br")), g.replaceChildren(A), c !== S && (S = c, H(), g.style.cssText = ge(f));
|
|
324
|
+
}
|
|
325
|
+
function G() {
|
|
326
|
+
const t = e.placeholder ?? "";
|
|
327
|
+
x.textContent = t, x.style.display = t && r.length === 0 ? "block" : "none", t ? n.setAttribute("aria-placeholder", t) : n.removeAttribute("aria-placeholder");
|
|
328
|
+
}
|
|
329
|
+
function he(t) {
|
|
330
|
+
const a = S ? `calc(${t.left} + ${S})` : t.left;
|
|
331
|
+
return `padding:${t.top} ${t.right} ${t.bottom} ${a};`;
|
|
332
|
+
}
|
|
333
|
+
function J(t, a) {
|
|
334
|
+
return a + he(t);
|
|
335
|
+
}
|
|
336
|
+
function ge(t) {
|
|
337
|
+
return Oe + he(t);
|
|
338
|
+
}
|
|
339
|
+
function H() {
|
|
340
|
+
const t = e.styles ?? {}, a = Se(t), c = Object.entries(t).filter(([f]) => !Ke.has(f)).map(([f, m]) => `${Ie(f)}:${m};`).join("");
|
|
341
|
+
d.style.cssText = $e + c, h.style.cssText = J(a, Ce), n.style.cssText = J(a, ke), x.style.cssText = J(a, we), g && (g.style.cssText = ge(a)), j(), e.dir && (d.dir = e.dir, n.dir = e.dir, h.dir = e.dir, x.dir = e.dir, g && (g.dir = e.dir));
|
|
342
|
+
}
|
|
343
|
+
function K() {
|
|
344
|
+
e.ariaLabel ? n.setAttribute("aria-label", e.ariaLabel) : n.removeAttribute("aria-label"), e.ariaLabelledby ? n.setAttribute("aria-labelledby", e.ariaLabelledby) : n.removeAttribute("aria-labelledby"), e.ariaDescribedby ? n.setAttribute("aria-describedby", e.ariaDescribedby) : n.removeAttribute("aria-describedby"), e.readOnly ? n.setAttribute("aria-readonly", "true") : n.removeAttribute("aria-readonly"), e.disabled ? n.setAttribute("aria-disabled", "true") : n.removeAttribute("aria-disabled");
|
|
345
|
+
}
|
|
346
|
+
v && pe();
|
|
347
|
+
const X = [Le(), Ee(e.indentUnit ?? " ")];
|
|
348
|
+
return {
|
|
349
|
+
setValue(t, a) {
|
|
350
|
+
if (p || b) return;
|
|
351
|
+
let c = F(t);
|
|
352
|
+
e.maxLength !== void 0 && e.maxLength >= 0 && (c = c.slice(0, e.maxLength)), P.cancel(), r = c, u = c, n.value = c, n.setSelectionRange(c.length, c.length), ((a == null ? void 0 : a.resetHistory) ?? !0) && (C.length = 0, C.push({ value: c, selStart: -1, selEnd: -1 }), D.length = 0), T(), M();
|
|
279
353
|
},
|
|
280
354
|
getValue() {
|
|
281
|
-
return
|
|
355
|
+
return r;
|
|
282
356
|
},
|
|
283
|
-
setLanguage(
|
|
284
|
-
t =
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
357
|
+
setLanguage(t) {
|
|
358
|
+
l = t, e = { ...e, language: t }, E = q(), T();
|
|
359
|
+
},
|
|
360
|
+
setPlaceholder(t) {
|
|
361
|
+
e = { ...e, placeholder: t }, G();
|
|
362
|
+
},
|
|
363
|
+
setReadOnly(t) {
|
|
364
|
+
e = { ...e, readOnly: t }, n.readOnly = t, K();
|
|
365
|
+
},
|
|
366
|
+
setDisabled(t) {
|
|
367
|
+
e = { ...e, disabled: t }, n.disabled = t, K();
|
|
368
|
+
},
|
|
369
|
+
setLineNumbers(t) {
|
|
370
|
+
v !== t && (v = t, !t && g && (g.remove(), g = null, S = ""), H(), T());
|
|
371
|
+
},
|
|
372
|
+
update(t) {
|
|
373
|
+
p || (e = { ...e, ...t }, t.indentUnit !== void 0 && X.splice(0, X.length, Le(), Ee(t.indentUnit)), t.language !== void 0 && (l = t.language), ("highlight" in t || t.language !== void 0) && (E = q()), t.lineNumbers !== void 0 && (v = t.lineNumbers, !v && g && (g.remove(), g = null, S = "")), t.value !== void 0 && (r = F(t.value), u = r, n.value = r, C.length = 0, C.push({ value: r, selStart: -1, selEnd: -1 }), D.length = 0), t.readOnly !== void 0 && (n.readOnly = t.readOnly), t.disabled !== void 0 && (n.disabled = t.disabled), t.maxLength !== void 0 && (t.maxLength >= 0 ? n.maxLength = t.maxLength : n.removeAttribute("maxlength")), t.spellcheck !== void 0 && (n.spellcheck = t.spellcheck), t.dir !== void 0 && (n.dir = t.dir), K(), H(), T(), M());
|
|
374
|
+
},
|
|
375
|
+
focus() {
|
|
376
|
+
n.focus();
|
|
377
|
+
},
|
|
378
|
+
blur() {
|
|
379
|
+
n.blur();
|
|
380
|
+
},
|
|
381
|
+
undo() {
|
|
382
|
+
ae();
|
|
383
|
+
},
|
|
384
|
+
redo() {
|
|
385
|
+
ce();
|
|
386
|
+
},
|
|
387
|
+
insertText(t) {
|
|
388
|
+
var N;
|
|
389
|
+
if (p || n.readOnly || n.disabled) return;
|
|
390
|
+
const a = n.selectionStart, c = n.selectionEnd;
|
|
391
|
+
let f = F(t);
|
|
392
|
+
if (e.maxLength !== void 0 && e.maxLength >= 0) {
|
|
393
|
+
const z = e.maxLength - (r.length - (c - a));
|
|
394
|
+
if (z <= 0) return;
|
|
395
|
+
f.length > z && (f = f.slice(0, z));
|
|
396
|
+
}
|
|
397
|
+
const m = r.slice(0, a) + f + r.slice(c);
|
|
398
|
+
r = m, u = m, n.value = m;
|
|
399
|
+
const A = a + f.length;
|
|
400
|
+
n.setSelectionRange(A, A), T(), W({ value: m, selStart: A, selEnd: A }), (N = e.onValueChange) == null || N.call(e, m), M();
|
|
401
|
+
},
|
|
402
|
+
getSelection() {
|
|
403
|
+
return { start: n.selectionStart, end: n.selectionEnd };
|
|
404
|
+
},
|
|
405
|
+
setSelection(t, a = t) {
|
|
406
|
+
const c = (f) => Math.max(0, Math.min(r.length, Number.isFinite(f) ? f : 0));
|
|
407
|
+
n.setSelectionRange(c(t), c(a));
|
|
292
408
|
},
|
|
293
409
|
destroy() {
|
|
294
|
-
|
|
410
|
+
p || (p = !0, P.cancel(), L == null || L.disconnect(), y && typeof cancelAnimationFrame == "function" && cancelAnimationFrame(y), n.removeEventListener("input", te), n.removeEventListener("compositionstart", ne), n.removeEventListener("compositionend", ie), n.removeEventListener("scroll", ee), n.removeEventListener("keydown", ue), n.removeEventListener("focus", de), n.removeEventListener("blur", fe), d.remove());
|
|
295
411
|
},
|
|
296
|
-
textarea:
|
|
412
|
+
textarea: n,
|
|
413
|
+
root: d,
|
|
414
|
+
pre: h
|
|
297
415
|
};
|
|
298
416
|
}
|
|
299
|
-
function
|
|
300
|
-
|
|
301
|
-
let n = "", t = !1;
|
|
302
|
-
for (const i of s)
|
|
303
|
-
i === "`" ? t ? (e.push({ code: !0, seg: n + "`" }), n = "", t = !1) : (n && e.push({ code: !1, seg: n }), n = "`", t = !0) : n += i;
|
|
304
|
-
return n && e.push({ code: !1, seg: n }), e;
|
|
305
|
-
}
|
|
306
|
-
function R(s) {
|
|
307
|
-
for (const { code: e, seg: n } of H(s))
|
|
308
|
-
if (!e && (n.includes(":-") || n.includes(":-")))
|
|
309
|
-
return !0;
|
|
310
|
-
return !1;
|
|
311
|
-
}
|
|
312
|
-
function z(s) {
|
|
313
|
-
let e = 0;
|
|
314
|
-
for (const { code: n, seg: t } of H(s)) {
|
|
315
|
-
if (!n) {
|
|
316
|
-
const i = t.indexOf(":");
|
|
317
|
-
if (i !== -1) return e + i;
|
|
318
|
-
}
|
|
319
|
-
e += t.length;
|
|
320
|
-
}
|
|
321
|
-
return -1;
|
|
322
|
-
}
|
|
323
|
-
function N(s) {
|
|
324
|
-
if (R(s)) return null;
|
|
325
|
-
const e = z(s);
|
|
326
|
-
if (e <= 0) return null;
|
|
327
|
-
const n = s.slice(0, e), t = s.slice(e + 1);
|
|
328
|
-
if (/\s$/.test(n) || t !== "" && !/^\s/.test(t)) return null;
|
|
329
|
-
const i = t.trim();
|
|
330
|
-
return { key: n.trim(), value: i === "" ? void 0 : i };
|
|
331
|
-
}
|
|
332
|
-
function m(s) {
|
|
333
|
-
return s.replace(/&/g, "&").replace(/</g, "<").replace(/>/g, ">").replace(/"/g, """);
|
|
417
|
+
function k(i) {
|
|
418
|
+
return i.replace(/&/g, "&").replace(/</g, "<").replace(/>/g, ">").replace(/"/g, """);
|
|
334
419
|
}
|
|
335
|
-
const
|
|
420
|
+
const R = {
|
|
336
421
|
key: "pd-key",
|
|
337
422
|
keyPunct: "pd-key-punct",
|
|
338
423
|
item: "pd-item",
|
|
@@ -342,84 +427,83 @@ const L = {
|
|
|
342
427
|
inlineCode: "pd-inline-code",
|
|
343
428
|
fence: "pd-fence"
|
|
344
429
|
};
|
|
345
|
-
function
|
|
346
|
-
return `<span class="${
|
|
430
|
+
function je(i) {
|
|
431
|
+
return `<span class="${R.inlineCode}">${k(i)}</span>`;
|
|
347
432
|
}
|
|
348
|
-
const
|
|
349
|
-
function
|
|
350
|
-
let
|
|
351
|
-
|
|
352
|
-
let
|
|
353
|
-
for (; (
|
|
354
|
-
const
|
|
355
|
-
|
|
433
|
+
const Ae = /(?:^|\s):([^\s-][^\s]*)(?=\s|$)/g;
|
|
434
|
+
function _e(i) {
|
|
435
|
+
let o = "", s = 0;
|
|
436
|
+
Ae.lastIndex = 0;
|
|
437
|
+
let e;
|
|
438
|
+
for (; (e = Ae.exec(i)) !== null; ) {
|
|
439
|
+
const l = /^\s/.test(e[0]) ? 1 : 0, r = e.index + l;
|
|
440
|
+
o += k(i.slice(s, r)), o += `<span class="${R.ref}">${k(i.slice(r, e.index + e[0].length))}</span>`, s = e.index + e[0].length;
|
|
356
441
|
}
|
|
357
|
-
return
|
|
442
|
+
return o += k(i.slice(s)), o;
|
|
358
443
|
}
|
|
359
|
-
function
|
|
360
|
-
let
|
|
361
|
-
for (const { code:
|
|
362
|
-
|
|
363
|
-
return
|
|
444
|
+
function B(i) {
|
|
445
|
+
let o = "";
|
|
446
|
+
for (const { code: s, seg: e } of De(i))
|
|
447
|
+
o += s ? je(e) : _e(e);
|
|
448
|
+
return o;
|
|
364
449
|
}
|
|
365
|
-
function
|
|
366
|
-
const
|
|
367
|
-
return `${
|
|
450
|
+
function Te(i, o, s, e) {
|
|
451
|
+
const l = `<span class="${R.key}">${B(s)}</span>`, r = `<span class="${R.keyPunct}">:</span>`;
|
|
452
|
+
return `${i}${o}${l}${r}${B(e)}`;
|
|
368
453
|
}
|
|
369
|
-
function
|
|
370
|
-
const
|
|
371
|
-
if (/^\/\/!pd(?:\s+[^\s]+)?$/.test(
|
|
372
|
-
const
|
|
373
|
-
return `${
|
|
454
|
+
function We(i) {
|
|
455
|
+
const o = i.trim();
|
|
456
|
+
if (/^\/\/!pd(?:\s+[^\s]+)?$/.test(o)) {
|
|
457
|
+
const e = /^(\s*)(\/\/!pd)(\s*.*)$/.exec(i), l = (e == null ? void 0 : e[1]) ?? "", r = (e == null ? void 0 : e[2]) ?? "//!pd", u = (e == null ? void 0 : e[3]) ?? "";
|
|
458
|
+
return `${k(l)}<span class="${R.section}">${k(r)}</span>${B(u)}`;
|
|
374
459
|
}
|
|
375
|
-
if (
|
|
376
|
-
return `<span class="${
|
|
377
|
-
const
|
|
378
|
-
if (
|
|
379
|
-
const
|
|
380
|
-
if (!
|
|
381
|
-
const
|
|
382
|
-
return `${
|
|
460
|
+
if (o === "---")
|
|
461
|
+
return `<span class="${R.sep}">${k(i)}</span>`;
|
|
462
|
+
const s = /^(\s*)(-)(?=[ ]|$)/.exec(i);
|
|
463
|
+
if (s) {
|
|
464
|
+
const e = k(s[1] ?? ""), l = (s[1] ?? "").length + 1, r = i.slice(l), u = r.trimStart(), p = r.slice(0, r.length - u.length), b = `<span class="${R.item}">-</span>`;
|
|
465
|
+
if (!me(u) && be(u)) {
|
|
466
|
+
const v = ve(u), E = u.slice(0, v), S = u.slice(v + 1);
|
|
467
|
+
return `${e}${b}${k(p)}${Te("", "", E, S)}`;
|
|
383
468
|
}
|
|
384
|
-
return `${
|
|
469
|
+
return `${e}${b}${k(p)}${B(u)}`;
|
|
385
470
|
}
|
|
386
|
-
if (!
|
|
387
|
-
const
|
|
388
|
-
return
|
|
471
|
+
if (!me(o) && be(o)) {
|
|
472
|
+
const l = i.length - i.trimStart().length, r = i.slice(l), u = ve(r), p = r.slice(0, u).trim(), b = r.slice(u + 1);
|
|
473
|
+
return Te(k(i.slice(0, l)), "", p, b);
|
|
389
474
|
}
|
|
390
|
-
return
|
|
475
|
+
return B(i);
|
|
391
476
|
}
|
|
392
|
-
function
|
|
393
|
-
const
|
|
477
|
+
function qe(i) {
|
|
478
|
+
const o = i.split(`
|
|
394
479
|
`);
|
|
395
|
-
let
|
|
396
|
-
const
|
|
397
|
-
for (const
|
|
398
|
-
const
|
|
399
|
-
if (
|
|
400
|
-
|
|
480
|
+
let s = !1;
|
|
481
|
+
const e = [];
|
|
482
|
+
for (const l of o) {
|
|
483
|
+
const r = l.trimStart();
|
|
484
|
+
if (s) {
|
|
485
|
+
r.startsWith("```") ? (s = !1, e.push(`<span class="${R.fence}">${k(l)}</span>`)) : e.push(k(l));
|
|
401
486
|
continue;
|
|
402
487
|
}
|
|
403
|
-
if (
|
|
404
|
-
|
|
488
|
+
if (r.startsWith("```")) {
|
|
489
|
+
s = !0, e.push(`<span class="${R.fence}">${k(l)}</span>`);
|
|
405
490
|
continue;
|
|
406
491
|
}
|
|
407
|
-
|
|
492
|
+
e.push(We(l));
|
|
408
493
|
}
|
|
409
|
-
return
|
|
494
|
+
return e.join(`
|
|
410
495
|
`);
|
|
411
496
|
}
|
|
412
|
-
function
|
|
413
|
-
return (
|
|
497
|
+
function Ge(i) {
|
|
498
|
+
return (o) => i === "pd" ? qe(o) : ze(o);
|
|
414
499
|
}
|
|
415
|
-
function
|
|
416
|
-
return
|
|
500
|
+
function Xe(i, o = {}) {
|
|
501
|
+
return Ve(i, o, Ge);
|
|
417
502
|
}
|
|
418
503
|
export {
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
504
|
+
Xe as createPdEditor,
|
|
505
|
+
Qe as format,
|
|
506
|
+
qe as highlightPd,
|
|
507
|
+
Ue as jsonToPdText,
|
|
508
|
+
et as pdToJsonText
|
|
424
509
|
};
|
|
425
|
-
//# sourceMappingURL=pd.js.map
|