@openstage/glyph-element 0.2.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.
Files changed (67) hide show
  1. package/THIRD-PARTY-NOTICES.md +1505 -0
  2. package/dist/chunks/bash-Dw1nAEst.js +171 -0
  3. package/dist/chunks/bash-Dw1nAEst.js.map +1 -0
  4. package/dist/chunks/csharp-D8ELXkGi.js +262 -0
  5. package/dist/chunks/csharp-D8ELXkGi.js.map +1 -0
  6. package/dist/chunks/css-DQEU4whB.js +142 -0
  7. package/dist/chunks/css-DQEU4whB.js.map +1 -0
  8. package/dist/chunks/fsharp-D4SqCnMZ.js +242 -0
  9. package/dist/chunks/fsharp-D4SqCnMZ.js.map +1 -0
  10. package/dist/chunks/go-BJIB22rX.js +142 -0
  11. package/dist/chunks/go-BJIB22rX.js.map +1 -0
  12. package/dist/chunks/haskell-eGGgAkgA.js +140 -0
  13. package/dist/chunks/haskell-eGGgAkgA.js.map +1 -0
  14. package/dist/chunks/highlight-core-C0K6BIzZ.js +967 -0
  15. package/dist/chunks/highlight-core-C0K6BIzZ.js.map +1 -0
  16. package/dist/chunks/java-DHPUyZsV.js +171 -0
  17. package/dist/chunks/java-DHPUyZsV.js.map +1 -0
  18. package/dist/chunks/javascript-D_CG8suQ.js +438 -0
  19. package/dist/chunks/javascript-D_CG8suQ.js.map +1 -0
  20. package/dist/chunks/json-BD6qkh12.js +38 -0
  21. package/dist/chunks/json-BD6qkh12.js.map +1 -0
  22. package/dist/chunks/kotlin-C75rnxi-.js +203 -0
  23. package/dist/chunks/kotlin-C75rnxi-.js.map +1 -0
  24. package/dist/chunks/markdown-B6LMDWi1.js +183 -0
  25. package/dist/chunks/markdown-B6LMDWi1.js.map +1 -0
  26. package/dist/chunks/ocaml-CMtC1T-S.js +54 -0
  27. package/dist/chunks/ocaml-CMtC1T-S.js.map +1 -0
  28. package/dist/chunks/prosemirror-dAj0dboi.js +7790 -0
  29. package/dist/chunks/prosemirror-dAj0dboi.js.map +1 -0
  30. package/dist/chunks/python-ny4cvzzX.js +240 -0
  31. package/dist/chunks/python-ny4cvzzX.js.map +1 -0
  32. package/dist/chunks/rolldown-runtime-BE9Pkid1.js +13 -0
  33. package/dist/chunks/rust-8OMNiTht.js +171 -0
  34. package/dist/chunks/rust-8OMNiTht.js.map +1 -0
  35. package/dist/chunks/scala-BB851ZJZ.js +164 -0
  36. package/dist/chunks/scala-BB851ZJZ.js.map +1 -0
  37. package/dist/chunks/sql-CoOMeU5k.js +120 -0
  38. package/dist/chunks/sql-CoOMeU5k.js.map +1 -0
  39. package/dist/chunks/tiptap-Cb4W88fy.js +8527 -0
  40. package/dist/chunks/tiptap-Cb4W88fy.js.map +1 -0
  41. package/dist/chunks/typescript-Dh7IycF2.js +523 -0
  42. package/dist/chunks/typescript-Dh7IycF2.js.map +1 -0
  43. package/dist/chunks/vendor-B82PcruV.js +1799 -0
  44. package/dist/chunks/vendor-B82PcruV.js.map +1 -0
  45. package/dist/chunks/xml-BpsgObpu.js +168 -0
  46. package/dist/chunks/xml-BpsgObpu.js.map +1 -0
  47. package/dist/codeblock-backspace.d.ts +3 -0
  48. package/dist/codeblock-backspace.d.ts.map +1 -0
  49. package/dist/document-conversion.d.ts +29 -0
  50. package/dist/document-conversion.d.ts.map +1 -0
  51. package/dist/editor-element.d.ts +93 -0
  52. package/dist/editor-element.d.ts.map +1 -0
  53. package/dist/glyph-editor-element.js +783 -0
  54. package/dist/glyph-editor-element.js.map +1 -0
  55. package/dist/header.d.ts +18 -0
  56. package/dist/header.d.ts.map +1 -0
  57. package/dist/index.d.ts +62 -0
  58. package/dist/index.d.ts.map +1 -0
  59. package/dist/link-dialog.d.ts +29 -0
  60. package/dist/link-dialog.d.ts.map +1 -0
  61. package/dist/safe-href.d.ts +2 -0
  62. package/dist/safe-href.d.ts.map +1 -0
  63. package/dist/slash-menu.d.ts +22 -0
  64. package/dist/slash-menu.d.ts.map +1 -0
  65. package/dist/styles.d.ts +2 -0
  66. package/dist/styles.d.ts.map +1 -0
  67. package/package.json +52 -0
@@ -0,0 +1,783 @@
1
+ import { a as e, i as t, n, o as r, r as i, t as a } from "./chunks/tiptap-Cb4W88fy.js";
2
+ import { t as o } from "./chunks/highlight-core-C0K6BIzZ.js";
3
+ import { a as s, i as c, n as l, o as u, r as d, s as f, t as p } from "./chunks/vendor-B82PcruV.js";
4
+ //#region ../editor-core/dist/brand.js
5
+ var m = { of: (e) => e }, h = () => ({
6
+ type: "doc",
7
+ content: [{ type: "paragraph" }]
8
+ }), g = () => ({
9
+ schemaVersion: 1,
10
+ content: h()
11
+ }), _ = (e) => typeof e == "object" && !!e, v = (e) => {
12
+ if (!_(e) || typeof e.schemaVersion != "number") return !1;
13
+ let t = e.content;
14
+ return _(t) && t.type === "doc" && Array.isArray(t.content);
15
+ }, y = (e) => v(e) ? u.pure(e) : f.pure(/* @__PURE__ */ TypeError("Value is not a valid EditorDocument")), b = (e) => y(e).fold((e) => {
16
+ throw e;
17
+ }, (e) => e), x = /* @__PURE__ */ new Map(), S = (e) => {
18
+ if (e.schemaVersion >= 1) return e.schemaVersion === 1 ? e : {
19
+ ...e,
20
+ schemaVersion: 1
21
+ };
22
+ let t = x.get(e.schemaVersion);
23
+ return S(t ? t(e) : {
24
+ ...e,
25
+ schemaVersion: e.schemaVersion + 1
26
+ });
27
+ }, C = (e) => e.schemaVersion > 1 ? f.pure(/* @__PURE__ */ RangeError(`Document schemaVersion ${e.schemaVersion} is newer than supported 1`)) : u.pure(e), w = (e) => C(e).fold((e) => {
28
+ throw e;
29
+ }, S), T = [
30
+ "bold",
31
+ "italic",
32
+ "link",
33
+ "heading1",
34
+ "heading2",
35
+ "heading3",
36
+ "bulletList",
37
+ "orderedList",
38
+ "blockquote",
39
+ "codeBlock",
40
+ "undo",
41
+ "redo",
42
+ "spacer",
43
+ "codeLanguage",
44
+ "status"
45
+ ], E = {
46
+ background: "--editor-background",
47
+ text: "--editor-text",
48
+ mutedText: "--editor-muted-text",
49
+ border: "--editor-border",
50
+ accent: "--editor-accent",
51
+ selection: "--editor-selection",
52
+ toolbarBackground: "--editor-toolbar-background",
53
+ slashMenuBackground: "--editor-slash-menu-background",
54
+ slashMenuHover: "--editor-slash-menu-hover",
55
+ slashMenuText: "--editor-slash-menu-text",
56
+ codeBackground: "--editor-code-background",
57
+ blockQuoteBorder: "--editor-block-quote-border"
58
+ }, D = (e) => Object.keys(E).reduce((t, n) => {
59
+ let r = e[n];
60
+ return typeof r == "string" ? {
61
+ ...t,
62
+ [E[n]]: r
63
+ } : t;
64
+ }, {}), O = [
65
+ {
66
+ id: m.of("heading-1"),
67
+ label: "Heading 1",
68
+ keywords: ["h1", "title"],
69
+ run: (e) => e.setHeading(1)
70
+ },
71
+ {
72
+ id: m.of("heading-2"),
73
+ label: "Heading 2",
74
+ keywords: ["h2"],
75
+ run: (e) => e.setHeading(2)
76
+ },
77
+ {
78
+ id: m.of("heading-3"),
79
+ label: "Heading 3",
80
+ keywords: ["h3"],
81
+ run: (e) => e.setHeading(3)
82
+ },
83
+ {
84
+ id: m.of("paragraph"),
85
+ label: "Paragraph",
86
+ keywords: ["text", "body"],
87
+ run: (e) => e.setParagraph()
88
+ },
89
+ {
90
+ id: m.of("bullet-list"),
91
+ label: "Bullet list",
92
+ keywords: ["ul", "unordered"],
93
+ run: (e) => e.toggleBulletList()
94
+ },
95
+ {
96
+ id: m.of("numbered-list"),
97
+ label: "Numbered list",
98
+ keywords: ["ol", "ordered"],
99
+ run: (e) => e.toggleOrderedList()
100
+ },
101
+ {
102
+ id: m.of("quote"),
103
+ label: "Quote",
104
+ keywords: ["blockquote"],
105
+ run: (e) => e.toggleBlockquote()
106
+ },
107
+ {
108
+ id: m.of("code-block"),
109
+ label: "Code block",
110
+ keywords: ["pre", "code"],
111
+ run: (e) => e.toggleCodeBlock()
112
+ }
113
+ ], k = (e) => (t) => t.label.toLowerCase().includes(e) || (t.keywords ?? []).some((t) => t.toLowerCase().includes(e)), A = (e) => (t) => {
114
+ let n = e.trim().toLowerCase();
115
+ return n ? t.filter(k(n)) : [...t];
116
+ }, j = [
117
+ {
118
+ id: "bash",
119
+ label: "Bash"
120
+ },
121
+ {
122
+ id: "csharp",
123
+ label: "C#"
124
+ },
125
+ {
126
+ id: "css",
127
+ label: "CSS"
128
+ },
129
+ {
130
+ id: "fsharp",
131
+ label: "F#"
132
+ },
133
+ {
134
+ id: "go",
135
+ label: "Go"
136
+ },
137
+ {
138
+ id: "haskell",
139
+ label: "Haskell"
140
+ },
141
+ {
142
+ id: "java",
143
+ label: "Java"
144
+ },
145
+ {
146
+ id: "javascript",
147
+ label: "JavaScript"
148
+ },
149
+ {
150
+ id: "json",
151
+ label: "JSON"
152
+ },
153
+ {
154
+ id: "kotlin",
155
+ label: "Kotlin"
156
+ },
157
+ {
158
+ id: "markdown",
159
+ label: "Markdown"
160
+ },
161
+ {
162
+ id: "ocaml",
163
+ label: "OCaml"
164
+ },
165
+ {
166
+ id: "python",
167
+ label: "Python"
168
+ },
169
+ {
170
+ id: "rust",
171
+ label: "Rust"
172
+ },
173
+ {
174
+ id: "scala",
175
+ label: "Scala"
176
+ },
177
+ {
178
+ id: "sql",
179
+ label: "SQL"
180
+ },
181
+ {
182
+ id: "typescript",
183
+ label: "TypeScript"
184
+ },
185
+ {
186
+ id: "xml",
187
+ label: "HTML / XML"
188
+ }
189
+ ];
190
+ ((...e) => (t) => e.length > 0 ? {
191
+ type: "text",
192
+ text: t,
193
+ marks: e
194
+ } : {
195
+ type: "text",
196
+ text: t
197
+ })();
198
+ //#endregion
199
+ //#region ../renderer/dist/highlight.js
200
+ var M = {
201
+ bash: () => import("./chunks/bash-Dw1nAEst.js"),
202
+ csharp: () => import("./chunks/csharp-D8ELXkGi.js"),
203
+ css: () => import("./chunks/css-DQEU4whB.js"),
204
+ fsharp: () => import("./chunks/fsharp-D4SqCnMZ.js"),
205
+ go: () => import("./chunks/go-BJIB22rX.js"),
206
+ haskell: () => import("./chunks/haskell-eGGgAkgA.js"),
207
+ java: () => import("./chunks/java-DHPUyZsV.js"),
208
+ javascript: () => import("./chunks/javascript-D_CG8suQ.js"),
209
+ json: () => import("./chunks/json-BD6qkh12.js"),
210
+ kotlin: () => import("./chunks/kotlin-C75rnxi-.js"),
211
+ markdown: () => import("./chunks/markdown-B6LMDWi1.js"),
212
+ ocaml: () => import("./chunks/ocaml-CMtC1T-S.js"),
213
+ python: () => import("./chunks/python-ny4cvzzX.js"),
214
+ rust: () => import("./chunks/rust-8OMNiTht.js"),
215
+ scala: () => import("./chunks/scala-BB851ZJZ.js"),
216
+ sql: () => import("./chunks/sql-CoOMeU5k.js"),
217
+ typescript: () => import("./chunks/typescript-Dh7IycF2.js"),
218
+ xml: () => import("./chunks/xml-BpsgObpu.js")
219
+ }, N = {
220
+ ts: "typescript",
221
+ js: "javascript",
222
+ jsx: "javascript",
223
+ sh: "bash",
224
+ shell: "bash",
225
+ zsh: "bash",
226
+ html: "xml",
227
+ htm: "xml",
228
+ xhtml: "xml",
229
+ svg: "xml",
230
+ cs: "csharp",
231
+ "c#": "csharp",
232
+ fs: "fsharp",
233
+ "f#": "fsharp",
234
+ kt: "kotlin",
235
+ py: "python",
236
+ rs: "rust",
237
+ md: "markdown"
238
+ }, P = o(), F = (e) => {
239
+ let t = e.trim().toLowerCase();
240
+ return N[t] ?? t;
241
+ }, I = /* @__PURE__ */ new Map(), L = (e) => {
242
+ let t = F(e), n = M[t];
243
+ if (!n) return Promise.resolve(!1);
244
+ if (P.registered(t)) return Promise.resolve(!0);
245
+ let r = I.get(t);
246
+ if (r) return r;
247
+ let i = n().then((e) => (P.registered(t) || P.register({ [t]: e.default }), !0)).catch(() => !1);
248
+ return I.set(t, i), i;
249
+ }, R = "\n.hljs { color: var(--glyph-hl-text, #24292e); }\n.hljs-comment, .hljs-quote { color: var(--glyph-hl-comment, #6a737d); font-style: italic; }\n.hljs-keyword, .hljs-selector-tag, .hljs-built_in, .hljs-name, .hljs-tag {\n color: var(--glyph-hl-keyword, #d73a49);\n}\n.hljs-string, .hljs-attr, .hljs-template-tag, .hljs-template-variable,\n.hljs-addition, .hljs-regexp {\n color: var(--glyph-hl-string, #032f62);\n}\n.hljs-number, .hljs-literal, .hljs-boolean {\n color: var(--glyph-hl-number, #005cc5);\n}\n.hljs-title, .hljs-title.function_, .hljs-section, .hljs-selector-id {\n color: var(--glyph-hl-title, #6f42c1);\n}\n.hljs-type, .hljs-class .hljs-title, .hljs-title.class_ {\n color: var(--glyph-hl-type, #e36209);\n}\n.hljs-variable, .hljs-params, .hljs-property {\n color: var(--glyph-hl-variable, #24292e);\n}\n.hljs-symbol, .hljs-bullet, .hljs-link, .hljs-meta, .hljs-attribute {\n color: var(--glyph-hl-meta, #005cc5);\n}\n.hljs-deletion { color: var(--glyph-hl-deletion, #b31d28); }\n.hljs-emphasis { font-style: italic; }\n.hljs-strong { font-weight: 600; }\n", z = (e) => e.content, B = (e) => ({
250
+ schemaVersion: 1,
251
+ content: e && e.type === "doc" && Array.isArray(e.content) ? e : h()
252
+ }), V = /[\u0000-\u0020]+/g, H = (e) => {
253
+ let t = e.replace(V, "");
254
+ return t === "" ? !1 : /^(https?:|mailto:|tel:)/i.test(t) || /^[/#.]/.test(t) || !/^[a-z][a-z0-9+.-]*:/i.test(t);
255
+ }, U = "\n:host {\n --editor-background: #ffffff;\n --editor-text: #111827;\n --editor-muted-text: #6b7280;\n --editor-border: #e5e7eb;\n --editor-accent: #2563eb;\n --editor-selection: #bfdbfe;\n --editor-toolbar-background: #f9fafb;\n --editor-slash-menu-background: #ffffff;\n --editor-slash-menu-hover: #f3f4f6;\n --editor-slash-menu-text: #111827;\n --editor-code-background: #f3f4f6;\n --editor-block-quote-border: #d1d5db;\n --editor-radius: 0.5rem;\n\n display: block;\n position: relative;\n color: var(--editor-text);\n background: var(--editor-background);\n border: 1px solid var(--editor-border);\n border-radius: var(--editor-radius);\n font-family: system-ui, -apple-system, \"Segoe UI\", Roboto, sans-serif;\n}\n\n/* config.bordered === false — hide only the outer frame border. */\n:host(.borderless) {\n border-color: transparent;\n}\n\n.header {\n display: flex;\n flex-wrap: wrap;\n gap: 0.25rem;\n align-items: center;\n padding: 0.5rem;\n background: var(--editor-toolbar-background);\n border-top-left-radius: var(--editor-radius);\n border-top-right-radius: var(--editor-radius);\n}\n\n/* Stay visible while the page scrolls past a long document. */\n.header.floating {\n position: sticky;\n top: 0;\n z-index: 5;\n backdrop-filter: saturate(180%) blur(2px);\n}\n\n.header select {\n font: inherit;\n font-size: 0.85rem;\n padding: 0.2rem 0.35rem;\n border: 1px solid var(--editor-border);\n border-radius: 0.25rem;\n background: var(--editor-background);\n color: var(--editor-text);\n cursor: pointer;\n}\n\n.header select[hidden] {\n display: none;\n}\n\n.header button {\n font: inherit;\n font-size: 0.85rem;\n padding: 0.25rem 0.5rem;\n border: 1px solid transparent;\n border-radius: 0.25rem;\n background: transparent;\n color: var(--editor-text);\n cursor: pointer;\n}\n\n.header button:hover { background: var(--editor-slash-menu-hover); }\n.header button.active { border-color: var(--editor-accent); color: var(--editor-accent); }\n.header .spacer { flex: 1; }\n.header .status { font-size: 0.75rem; color: var(--editor-muted-text); }\n\n.surface { padding: 1rem; }\n\n.ProseMirror { outline: none; min-height: 8rem; line-height: 1.6; }\n.ProseMirror:focus { outline: none; }\n.ProseMirror ::selection { background: var(--editor-selection); }\n\n.ProseMirror p { margin: 0 0 0.75rem; }\n.ProseMirror h1 { font-size: 1.75rem; margin: 1rem 0 0.5rem; }\n.ProseMirror h2 { font-size: 1.4rem; margin: 1rem 0 0.5rem; }\n.ProseMirror h3 { font-size: 1.15rem; margin: 1rem 0 0.5rem; }\n.ProseMirror a { color: var(--editor-accent); text-decoration: underline; }\n.ProseMirror ul, .ProseMirror ol { padding-left: 1.5rem; margin: 0 0 0.75rem; }\n.ProseMirror blockquote {\n margin: 0 0 0.75rem;\n padding-left: 1rem;\n border-left: 3px solid var(--editor-block-quote-border);\n color: var(--editor-muted-text);\n}\n.ProseMirror pre {\n white-space: pre;\n overflow-x: auto;\n padding: 1rem;\n border-radius: 0.5rem;\n background: var(--editor-code-background);\n margin: 0 0 0.75rem;\n}\n.ProseMirror pre code {\n font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;\n font-size: 0.875rem;\n}\n.ProseMirror p.is-editor-empty:first-child::before {\n content: attr(data-placeholder);\n color: var(--editor-muted-text);\n float: left;\n height: 0;\n pointer-events: none;\n}\n\n.slash-menu {\n position: fixed;\n z-index: 1000;\n min-width: 12rem;\n background: var(--editor-slash-menu-background);\n color: var(--editor-slash-menu-text);\n border: 1px solid var(--editor-border);\n border-radius: 0.5rem;\n box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);\n padding: 0.25rem;\n overflow: hidden;\n}\n.slash-menu[hidden] { display: none; }\n.slash-menu button {\n display: block;\n width: 100%;\n text-align: left;\n font: inherit;\n font-size: 0.875rem;\n padding: 0.4rem 0.6rem;\n border: 0;\n border-radius: 0.25rem;\n background: transparent;\n color: inherit;\n cursor: pointer;\n}\n.slash-menu button:hover,\n.slash-menu button.active { background: var(--editor-slash-menu-hover); }\n\n.link-dialog {\n position: fixed;\n z-index: 1001;\n width: min(24rem, calc(100vw - 2rem));\n background: var(--editor-background);\n color: var(--editor-text);\n border: 1px solid var(--editor-border);\n border-radius: 0.5rem;\n box-shadow: 0 10px 30px rgba(0, 0, 0, 0.25);\n padding: 0.85rem;\n}\n.link-dialog[hidden] { display: none; }\n.link-dialog__title {\n margin: 0 0 0.75rem;\n font-size: 1rem;\n font-weight: 600;\n color: var(--editor-text);\n}\n.link-dialog__label {\n display: block;\n font-size: 0.85rem;\n color: var(--editor-muted-text);\n}\n.link-dialog__input {\n display: block;\n width: 100%;\n box-sizing: border-box;\n margin-top: 0.4rem;\n font: inherit;\n padding: 0.45rem 0.55rem;\n border: 1px solid var(--editor-border);\n border-radius: 0.375rem;\n background: var(--editor-background);\n color: var(--editor-text);\n}\n.link-dialog__input:focus {\n outline: 2px solid var(--editor-accent);\n outline-offset: -1px;\n}\n.link-dialog__error {\n margin: 0.5rem 0 0;\n font-size: 0.8rem;\n color: #dc2626;\n}\n.link-dialog__error[hidden] { display: none; }\n.link-dialog__actions {\n display: flex;\n align-items: center;\n gap: 0.5rem;\n margin-top: 0.9rem;\n}\n.link-dialog__spacer { flex: 1; }\n.link-dialog button {\n font: inherit;\n font-size: 0.85rem;\n padding: 0.4rem 0.7rem;\n border: 1px solid var(--editor-border);\n border-radius: 0.375rem;\n background: var(--editor-background);\n color: var(--editor-text);\n cursor: pointer;\n}\n.link-dialog button:hover { background: var(--editor-slash-menu-hover); }\n.link-dialog__save {\n border-color: var(--editor-accent);\n color: var(--editor-accent);\n}\n.link-dialog__remove[hidden] { display: none; }\n", W = r.create({
256
+ name: "codeBlockBackspace",
257
+ addKeyboardShortcuts() {
258
+ let e = (e) => ({ editor: t }) => {
259
+ if (!t.isActive("codeBlock")) return !1;
260
+ let { selection: n } = t.state, { empty: r, from: i, $from: a } = n;
261
+ if (!r) return t.chain().focus().deleteSelection().run();
262
+ let o = i <= a.start(), s = i >= a.end();
263
+ if (e === -1 && o || e === 1 && s) return !1;
264
+ let c = e === -1 ? {
265
+ from: i - 1,
266
+ to: i
267
+ } : {
268
+ from: i,
269
+ to: i + 1
270
+ };
271
+ return t.chain().focus().deleteRange(c).run();
272
+ };
273
+ return {
274
+ Backspace: e(-1),
275
+ Delete: e(1)
276
+ };
277
+ }
278
+ }), G = ({ editor: e, api: t, commands: n, container: r }) => {
279
+ let i = r.ownerDocument.createElement("div");
280
+ i.className = "slash-menu", i.hidden = !0, r.appendChild(i);
281
+ let a = n, o = !1, u = 0, f = [], m = 0, h = null, g = {
282
+ contextElement: e.view.dom,
283
+ getBoundingClientRect: () => {
284
+ let t = e.view.coordsAtPos(e.state.selection.$from.pos);
285
+ return {
286
+ x: t.left,
287
+ y: t.top,
288
+ left: t.left,
289
+ right: t.right,
290
+ top: t.top,
291
+ bottom: t.bottom,
292
+ width: t.right - t.left,
293
+ height: t.bottom - t.top
294
+ };
295
+ }
296
+ }, _ = () => {
297
+ l(g, i, {
298
+ strategy: "fixed",
299
+ placement: "bottom-start",
300
+ middleware: [
301
+ c(4),
302
+ d({ padding: 8 }),
303
+ s({ padding: 8 })
304
+ ]
305
+ }).then(({ x: e, y: t }) => {
306
+ i.style.left = `${Math.round(e)}px`, i.style.top = `${Math.round(t)}px`;
307
+ });
308
+ }, v = () => {
309
+ !o && i.hidden || (o = !1, i.hidden = !0, h?.(), h = null);
310
+ }, y = (n) => {
311
+ let r = f[n];
312
+ r && (e.chain().focus().deleteRange({
313
+ from: u,
314
+ to: e.state.selection.$from.pos
315
+ }).run(), r.run(t), v());
316
+ }, b = () => {
317
+ i.replaceChildren(), f.forEach((e, t) => {
318
+ let n = i.ownerDocument.createElement("button");
319
+ n.type = "button", n.textContent = e.label, t === m && n.classList.add("active"), n.addEventListener("mousedown", (e) => {
320
+ e.preventDefault(), y(t);
321
+ }), i.appendChild(n);
322
+ }), i.hidden = !1, h ? _() : h = p(g, i, _);
323
+ };
324
+ return {
325
+ setCommands: (e) => {
326
+ a = e;
327
+ },
328
+ update: () => {
329
+ let { state: t } = e, { $from: n, empty: r } = t.selection;
330
+ if (!r) return v();
331
+ let i = t.doc.textBetween(n.start(), n.pos, "\n", "\n"), s = /(?:^|\s)\/([\w-]*)$/.exec(i);
332
+ if (!s) return v();
333
+ let c = s[1] ?? "";
334
+ if (u = n.pos - c.length - 1, f = A(c)(a), f.length === 0) return v();
335
+ o = !0, m = 0, b();
336
+ },
337
+ handleKey: (e) => {
338
+ if (!o) return !1;
339
+ let t = (e) => (m = (m + e + f.length) % f.length, b(), !0);
340
+ return e.key === "ArrowDown" ? t(1) : e.key === "ArrowUp" ? t(-1) : e.key === "Enter" ? (y(m), !0) : e.key === "Escape" ? (v(), !0) : !1;
341
+ },
342
+ destroy: () => {
343
+ h?.(), h = null, i.remove();
344
+ }
345
+ };
346
+ }, K = (e) => {
347
+ let t = e.trim();
348
+ return t === "" || /^[a-z][a-z0-9+.-]*:/i.test(t) || /^[/#.]/.test(t) ? t : /^[^\s/]+\.[^\s]+/.test(t) || /^localhost(:\d+)?(\/|$)/i.test(t) ? `https://${t}` : t;
349
+ }, q = ({ container: e, isSafe: t, getAnchorRect: n }) => {
350
+ let r = e.ownerDocument, i = r.createElement("div");
351
+ i.className = "link-dialog", i.hidden = !0, i.setAttribute("role", "dialog"), i.setAttribute("aria-modal", "true");
352
+ let a = r.createElement("p");
353
+ a.className = "link-dialog__title", a.id = "glyph-link-dialog-title", i.setAttribute("aria-labelledby", a.id);
354
+ let o = r.createElement("label");
355
+ o.className = "link-dialog__label", o.textContent = "Link URL";
356
+ let u = r.createElement("input");
357
+ u.type = "text", u.className = "link-dialog__input", u.placeholder = "https://example.com", o.appendChild(u);
358
+ let f = r.createElement("p");
359
+ f.className = "link-dialog__error", f.hidden = !0, f.textContent = "Enter a valid URL (http, https, mailto, tel, or relative).";
360
+ let m = r.createElement("div");
361
+ m.className = "link-dialog__actions";
362
+ let h = r.createElement("button");
363
+ h.type = "button", h.textContent = "Remove", h.className = "link-dialog__remove";
364
+ let g = r.createElement("span");
365
+ g.className = "link-dialog__spacer";
366
+ let _ = r.createElement("button");
367
+ _.type = "button", _.textContent = "Cancel";
368
+ let v = r.createElement("button");
369
+ v.type = "button", v.textContent = "Save", v.className = "link-dialog__save", m.append(h, g, _, v), i.append(a, o, f, m), e.appendChild(i);
370
+ let y = { getBoundingClientRect: () => n() }, b = null, x = () => {}, S = () => {}, C = () => {}, w = 0, T = () => {
371
+ l(y, i, {
372
+ strategy: "fixed",
373
+ placement: "bottom-start",
374
+ middleware: [
375
+ c(6),
376
+ d({ padding: 8 }),
377
+ s({ padding: 8 })
378
+ ]
379
+ }).then(({ x: e, y: t }) => {
380
+ i.style.left = `${Math.round(e)}px`, i.style.top = `${Math.round(t)}px`;
381
+ });
382
+ }, E = () => [
383
+ u,
384
+ h,
385
+ _,
386
+ v
387
+ ].filter((e) => !e.hidden), D = (e) => {
388
+ e.composedPath().includes(i) || O();
389
+ }, O = () => {
390
+ i.hidden || (i.hidden = !0, f.hidden = !0, w += 1, b?.(), b = null, r.removeEventListener("mousedown", D, !0), setTimeout(C, 0));
391
+ }, k = () => {
392
+ let e = K(u.value);
393
+ if (e === "") {
394
+ S(), O();
395
+ return;
396
+ }
397
+ if (!t(e)) {
398
+ f.hidden = !1, u.focus();
399
+ return;
400
+ }
401
+ x(e), O();
402
+ };
403
+ return v.addEventListener("click", k), _.addEventListener("click", O), h.addEventListener("click", () => {
404
+ S(), O();
405
+ }), i.addEventListener("keydown", (e) => {
406
+ if (e.key === "Escape") {
407
+ e.preventDefault(), O();
408
+ return;
409
+ }
410
+ if (e.key === "Enter" && e.target === u) {
411
+ e.preventDefault(), k();
412
+ return;
413
+ }
414
+ if (e.key !== "Tab") return;
415
+ let t = E(), n = t[0], r = t[t.length - 1], a = i.getRootNode().activeElement;
416
+ e.shiftKey && a === n ? (e.preventDefault(), r?.focus()) : !e.shiftKey && a === r && (e.preventDefault(), n?.focus());
417
+ }), {
418
+ open: ({ initial: e, onSubmit: t, onClear: n, restoreFocus: o }) => {
419
+ x = t, S = n, C = o ?? (() => {}), u.value = e, f.hidden = !0;
420
+ let s = e !== "";
421
+ h.hidden = !s, a.textContent = s ? "Edit link" : "Add link", i.hidden = !1, b ? T() : b = p(y, i, T), setTimeout(() => r.addEventListener("mousedown", D, !0), 0);
422
+ let c = ++w;
423
+ setTimeout(() => {
424
+ c !== w || i.hidden || (u.focus(), u.select());
425
+ }, 0);
426
+ },
427
+ destroy: () => {
428
+ b?.(), b = null, r.removeEventListener("mousedown", D, !0), i.remove();
429
+ }
430
+ };
431
+ }, J = (e, t) => e == null ? null : typeof e == "function" ? e(t) : typeof e == "string" ? t.createTextNode(e) : e.cloneNode(!0), Y = ({ editor: e, api: t, container: n, items: r = T, icons: i, floating: a = !0 }) => {
432
+ let o = n.ownerDocument, s = o.createElement("div");
433
+ s.className = a ? "header floating" : "header";
434
+ let c = q({
435
+ container: n,
436
+ isSafe: H,
437
+ getAnchorRect: () => {
438
+ let { from: t, to: n } = e.state.selection, r = e.view.coordsAtPos(t), i = e.view.coordsAtPos(n), a = Math.min(r.left, i.left), o = Math.max(r.right, i.right), s = Math.min(r.top, i.top), c = Math.max(r.bottom, i.bottom);
439
+ return new DOMRect(a, s, o - a, c - s);
440
+ }
441
+ }), l = {
442
+ bold: {
443
+ label: "B",
444
+ title: "Bold",
445
+ run: t.toggleBold,
446
+ isActive: () => e.isActive("bold")
447
+ },
448
+ italic: {
449
+ label: "I",
450
+ title: "Italic",
451
+ run: t.toggleItalic,
452
+ isActive: () => e.isActive("italic")
453
+ },
454
+ link: {
455
+ label: "Link",
456
+ title: "Link",
457
+ run: () => {
458
+ c.open({
459
+ initial: e.getAttributes("link").href ?? "",
460
+ onSubmit: (e) => t.setLink(e),
461
+ onClear: () => e.chain().focus().extendMarkRange("link").unsetLink().run(),
462
+ restoreFocus: () => e.commands.focus()
463
+ });
464
+ },
465
+ isActive: () => e.isActive("link")
466
+ },
467
+ heading1: {
468
+ label: "H1",
469
+ title: "Heading 1",
470
+ run: () => t.setHeading(1),
471
+ isActive: () => e.isActive("heading", { level: 1 })
472
+ },
473
+ heading2: {
474
+ label: "H2",
475
+ title: "Heading 2",
476
+ run: () => t.setHeading(2),
477
+ isActive: () => e.isActive("heading", { level: 2 })
478
+ },
479
+ heading3: {
480
+ label: "H3",
481
+ title: "Heading 3",
482
+ run: () => t.setHeading(3),
483
+ isActive: () => e.isActive("heading", { level: 3 })
484
+ },
485
+ bulletList: {
486
+ label: "• List",
487
+ title: "Bullet list",
488
+ run: t.toggleBulletList,
489
+ isActive: () => e.isActive("bulletList")
490
+ },
491
+ orderedList: {
492
+ label: "1. List",
493
+ title: "Numbered list",
494
+ run: t.toggleOrderedList,
495
+ isActive: () => e.isActive("orderedList")
496
+ },
497
+ blockquote: {
498
+ label: "Quote",
499
+ title: "Quote",
500
+ run: t.toggleBlockquote,
501
+ isActive: () => e.isActive("blockquote")
502
+ },
503
+ codeBlock: {
504
+ label: "Code",
505
+ title: "Code block",
506
+ run: t.toggleCodeBlock,
507
+ isActive: () => e.isActive("codeBlock")
508
+ },
509
+ undo: {
510
+ label: "Undo",
511
+ title: "Undo",
512
+ run: t.undo
513
+ },
514
+ redo: {
515
+ label: "Redo",
516
+ title: "Redo",
517
+ run: t.redo
518
+ }
519
+ }, u = o.createElement("span");
520
+ u.className = "status";
521
+ let d = o.createElement("select");
522
+ d.title = "Code block language", d.hidden = !0;
523
+ let f = o.createElement("option");
524
+ f.value = "", f.textContent = "Plain text", d.appendChild(f), j.forEach(({ id: e, label: t }) => {
525
+ let n = o.createElement("option");
526
+ n.value = e, n.textContent = t, d.appendChild(n);
527
+ }), d.addEventListener("change", () => {
528
+ e.chain().focus().updateAttributes("codeBlock", { language: d.value || null }).run();
529
+ });
530
+ let p = [], m = !1;
531
+ r.forEach((e) => {
532
+ if (e === "spacer") {
533
+ let e = o.createElement("span");
534
+ e.className = "spacer", s.appendChild(e);
535
+ return;
536
+ }
537
+ if (e === "status") {
538
+ s.appendChild(u);
539
+ return;
540
+ }
541
+ if (e === "codeLanguage") {
542
+ s.appendChild(d), m = !0;
543
+ return;
544
+ }
545
+ let t = l[e];
546
+ if (!t) return;
547
+ let n = o.createElement("button");
548
+ n.type = "button";
549
+ let r = J(i?.[e], o);
550
+ r ? n.appendChild(r) : n.textContent = t.label, n.title = t.title, n.setAttribute("aria-label", t.title), n.addEventListener("mousedown", (e) => {
551
+ e.preventDefault(), t.run(), h();
552
+ }), s.appendChild(n), p.push({
553
+ btn: n,
554
+ def: t
555
+ });
556
+ }), n.appendChild(s);
557
+ let h = () => {
558
+ if (p.forEach(({ btn: e, def: t }) => e.classList.toggle("active", t.isActive?.() ?? !1)), m) {
559
+ let t = e.isActive("codeBlock");
560
+ if (d.hidden = !t, t) {
561
+ let t = e.getAttributes("codeBlock").language ?? "";
562
+ d.value !== t && (d.value = t);
563
+ }
564
+ }
565
+ };
566
+ return {
567
+ el: s,
568
+ setStatus: (e) => {
569
+ u.textContent = e;
570
+ },
571
+ sync: h
572
+ };
573
+ }, X = class extends HTMLElement {
574
+ static get observedAttributes() {
575
+ return ["placeholder", "show-header"];
576
+ }
577
+ #e = null;
578
+ #t = null;
579
+ #n = null;
580
+ #r = null;
581
+ #i = "";
582
+ #a = /* @__PURE__ */ new Set();
583
+ #o = !1;
584
+ #s;
585
+ #c = g();
586
+ #l;
587
+ #u = O;
588
+ #d = {
589
+ showHeader: !0,
590
+ enableSlashCommands: !0
591
+ };
592
+ #f;
593
+ constructor() {
594
+ super(), this.#f = this.attachShadow({ mode: "open" });
595
+ }
596
+ get content() {
597
+ return this.getJSON();
598
+ }
599
+ set content(e) {
600
+ this.setContent(e);
601
+ }
602
+ get theme() {
603
+ return this.#l;
604
+ }
605
+ set theme(e) {
606
+ this.#l = e, this.#x();
607
+ }
608
+ get commands() {
609
+ return this.#u;
610
+ }
611
+ set commands(e) {
612
+ this.#u = e ?? O, this.#t?.setCommands(this.#u);
613
+ }
614
+ get config() {
615
+ return this.#d;
616
+ }
617
+ set config(e) {
618
+ this.#d = {
619
+ ...this.#d,
620
+ ...e
621
+ }, this.isConnected && this.#m();
622
+ }
623
+ getJSON = () => this.#e ? B(this.#e.getJSON()) : this.#c;
624
+ setContent = (e) => {
625
+ let t = w(b(e));
626
+ this.#c = t, this.#e?.commands.setContent(z(t), { emitUpdate: !1 }), this.#_();
627
+ };
628
+ focus = () => {
629
+ this.#e?.commands.focus();
630
+ };
631
+ getApi = () => {
632
+ if (!this.#r) throw Error("Editor not initialized");
633
+ return this.#r;
634
+ };
635
+ setStatus = (e) => {
636
+ this.#i = e, this.#n?.setStatus(e);
637
+ };
638
+ connectedCallback() {
639
+ this.#m();
640
+ }
641
+ disconnectedCallback() {
642
+ this.#p();
643
+ }
644
+ attributeChangedCallback() {
645
+ this.isConnected && this.#m();
646
+ }
647
+ #p = () => {
648
+ this.#t?.destroy(), this.#t = null, this.#e?.destroy(), this.#e = null, this.#n = null, this.#r = null;
649
+ };
650
+ #m = () => {
651
+ this.#p(), this.#f.replaceChildren();
652
+ let r = document.createElement("style");
653
+ r.textContent = `${U}\n${R}`, this.#f.appendChild(r);
654
+ let o = document.createElement("div");
655
+ o.className = "editor", this.#f.appendChild(o), this.#s = document.createElement("div"), this.#s.className = "surface";
656
+ let s = document.createElement("div");
657
+ this.#s.appendChild(s);
658
+ let c = this.getAttribute("placeholder") ?? "Write something…";
659
+ this.#e = new e({
660
+ element: s,
661
+ extensions: [
662
+ t.configure({
663
+ codeBlock: !1,
664
+ link: !1,
665
+ strike: !1,
666
+ underline: !1,
667
+ code: !1,
668
+ horizontalRule: !1,
669
+ hardBreak: !1,
670
+ heading: { levels: [
671
+ 1,
672
+ 2,
673
+ 3
674
+ ] }
675
+ }),
676
+ a.configure({ lowlight: P }),
677
+ i.configure({
678
+ openOnClick: !1,
679
+ autolink: !0,
680
+ validate: H
681
+ }),
682
+ n.configure({ placeholder: c }),
683
+ W
684
+ ],
685
+ content: z(this.#c),
686
+ onCreate: () => {
687
+ this.#_(), this.#S("ready", void 0);
688
+ },
689
+ onUpdate: () => {
690
+ this.#t?.update(), this.#n?.sync(), this.#_(), this.#S("content-change", this.getJSON());
691
+ },
692
+ onSelectionUpdate: () => {
693
+ this.#t?.update(), this.#n?.sync(), this.#S("selection-change", void 0);
694
+ },
695
+ onFocus: () => this.#S("focus", void 0),
696
+ onBlur: () => this.#S("blur", void 0)
697
+ });
698
+ let l = this.#b();
699
+ this.#r = l, this.#y() && (this.#n = Y({
700
+ editor: this.#e,
701
+ api: l,
702
+ container: o,
703
+ items: this.#d.toolbar,
704
+ icons: this.#d.icons,
705
+ floating: this.#d.floatingHeader
706
+ }), this.#n.setStatus(this.#i)), o.appendChild(this.#s), this.#d.enableSlashCommands !== !1 && (this.#t = G({
707
+ editor: this.#e,
708
+ api: l,
709
+ commands: this.#u,
710
+ container: this.#s
711
+ }), this.#s.addEventListener("keydown", (e) => {
712
+ this.#t?.handleKey(e) && (e.preventDefault(), e.stopPropagation());
713
+ }, !0)), this.#x(), this.#h();
714
+ };
715
+ #h = () => {
716
+ let e = this.#d.maxHeight;
717
+ e == null || e === "" ? (this.style.removeProperty("max-height"), this.style.removeProperty("overflow-y")) : (this.style.maxHeight = typeof e == "number" ? `${e}px` : e, this.style.overflowY = "auto"), this.classList.toggle("borderless", this.#d.bordered === !1);
718
+ };
719
+ #g = () => {
720
+ if (!this.#e) return [];
721
+ let e = [];
722
+ return this.#e.state.doc.descendants((t, n) => {
723
+ t.type.name === "codeBlock" && t.attrs.language && e.push({
724
+ pos: n,
725
+ attrs: t.attrs
726
+ });
727
+ }), e;
728
+ };
729
+ #_ = () => {
730
+ [...new Set(this.#g().map((e) => String(e.attrs.language)))].filter((e) => !this.#a.has(e)).forEach((e) => {
731
+ this.#a.add(e), L(e).then((e) => {
732
+ e && this.#v();
733
+ });
734
+ });
735
+ };
736
+ #v = () => {
737
+ if (!this.#e) return;
738
+ let e = this.#g();
739
+ if (e.length === 0) return;
740
+ let { state: t, view: n } = this.#e, r = e.reduce((e, t) => e.setNodeMarkup(t.pos, void 0, { ...t.attrs }), t.tr);
741
+ this.#o = !0, n.dispatch(r), this.#o = !1;
742
+ };
743
+ #y = () => this.hasAttribute("show-header") ? this.getAttribute("show-header") !== "false" : this.#d.showHeader !== !1;
744
+ #b = () => {
745
+ let e = () => {
746
+ if (!this.#e) throw Error("Editor not initialized");
747
+ return this.#e;
748
+ };
749
+ return {
750
+ getJSON: this.getJSON,
751
+ setContent: this.setContent,
752
+ focus: this.focus,
753
+ setHeading: (t) => e().chain().focus().toggleHeading({ level: t }).run(),
754
+ setParagraph: () => e().chain().focus().setParagraph().run(),
755
+ toggleBold: () => e().chain().focus().toggleBold().run(),
756
+ toggleItalic: () => e().chain().focus().toggleItalic().run(),
757
+ toggleBulletList: () => e().chain().focus().toggleBulletList().run(),
758
+ toggleOrderedList: () => e().chain().focus().toggleOrderedList().run(),
759
+ toggleBlockquote: () => e().chain().focus().toggleBlockquote().run(),
760
+ toggleCodeBlock: () => e().chain().focus().toggleCodeBlock().run(),
761
+ setLink: (t) => e().chain().focus().extendMarkRange("link").setLink({ href: t }).run(),
762
+ undo: () => e().chain().focus().undo().run(),
763
+ redo: () => e().chain().focus().redo().run()
764
+ };
765
+ };
766
+ #x = () => {
767
+ this.#l && Object.entries(D(this.#l)).forEach(([e, t]) => this.style.setProperty(e, t));
768
+ };
769
+ #S = (e, t) => {
770
+ e === "content-change" && this.#o || this.dispatchEvent(new CustomEvent(e, {
771
+ detail: t,
772
+ bubbles: !0,
773
+ composed: !0
774
+ }));
775
+ };
776
+ }, Z = "glyph-editor", Q = (e = Z) => {
777
+ customElements.get(e) || customElements.define(e, X);
778
+ };
779
+ Q();
780
+ //#endregion
781
+ export { T as DEFAULT_TOOLBAR, X as GlyphEditor, Z as TAG_NAME, Q as defineGlyphEditor };
782
+
783
+ //# sourceMappingURL=glyph-editor-element.js.map