@likec4/core 1.47.0 → 1.48.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 (181) hide show
  1. package/LICENSE +1 -1
  2. package/dist/_chunks/Builder.view-element.mjs +3284 -0
  3. package/dist/_chunks/LikeC4Model.d.mts +1287 -0
  4. package/dist/_chunks/LikeC4Styles.mjs +691 -0
  5. package/dist/_chunks/RichText.d.mts +84 -0
  6. package/dist/_chunks/RichText.mjs +148 -0
  7. package/dist/_chunks/_aux.d.mts +289 -0
  8. package/dist/_chunks/_aux.mjs +18 -0
  9. package/dist/_chunks/_types.d.mts +781 -0
  10. package/dist/_chunks/_types2.d.mts +38 -0
  11. package/dist/_chunks/assignTagColors.mjs +24 -0
  12. package/dist/_chunks/calcDriftsFromSnapshot.mjs +379 -0
  13. package/dist/_chunks/connection.mjs +0 -0
  14. package/dist/_chunks/const.d.mts +43 -0
  15. package/dist/_chunks/const.mjs +33 -0
  16. package/dist/_chunks/expression-model.d.mts +192 -0
  17. package/dist/_chunks/expression-model.mjs +103 -0
  18. package/dist/_chunks/expression.d.mts +347 -0
  19. package/dist/_chunks/expression.mjs +107 -0
  20. package/dist/_chunks/find.d.mts +82 -0
  21. package/dist/_chunks/find.mjs +646 -0
  22. package/dist/_chunks/find2.d.mts +78 -0
  23. package/dist/_chunks/find2.mjs +287 -0
  24. package/dist/_chunks/fqnRef.d.mts +58 -0
  25. package/dist/_chunks/fqnRef.mjs +41 -0
  26. package/dist/_chunks/geometry.mjs +335 -0
  27. package/dist/_chunks/index.d.mts +169 -0
  28. package/dist/_chunks/index2.d.mts +937 -0
  29. package/dist/_chunks/index3.d.mts +146 -0
  30. package/dist/_chunks/index4.d.mts +62 -0
  31. package/dist/_chunks/index5.d.mts +42 -0
  32. package/dist/_chunks/index6.d.mts +43 -0
  33. package/dist/{shared/core.OtRNdMxy.d.mts → _chunks/index7.d.mts} +113 -197
  34. package/dist/_chunks/index8.d.mts +144 -0
  35. package/dist/_chunks/invariant.mjs +18 -0
  36. package/dist/_chunks/iterable.mjs +146 -0
  37. package/dist/_chunks/libs/@mantine/colors-generator.mjs +3416 -0
  38. package/dist/_chunks/libs/@ungap/structured-clone.mjs +213 -0
  39. package/dist/_chunks/libs/bail.mjs +14 -0
  40. package/dist/_chunks/libs/ccount.mjs +25 -0
  41. package/dist/_chunks/libs/character-entities-html4.mjs +263 -0
  42. package/dist/_chunks/libs/character-entities-legacy.mjs +117 -0
  43. package/dist/_chunks/libs/character-entities.mjs +2136 -0
  44. package/dist/_chunks/libs/comma-separated-tokens.mjs +18 -0
  45. package/dist/_chunks/libs/decode-named-character-reference.mjs +21 -0
  46. package/dist/_chunks/libs/defu.mjs +42 -0
  47. package/dist/_chunks/libs/devlop.mjs +5 -0
  48. package/dist/_chunks/libs/escape-string-regexp.mjs +8 -0
  49. package/dist/_chunks/libs/extend.mjs +77 -0
  50. package/dist/_chunks/libs/graphology-dag.mjs +703 -0
  51. package/dist/_chunks/libs/graphology-types.d.mts +601 -0
  52. package/dist/_chunks/libs/graphology.d.mts +6 -0
  53. package/dist/_chunks/libs/graphology.mjs +4565 -0
  54. package/dist/_chunks/libs/hast-util-sanitize.mjs +863 -0
  55. package/dist/_chunks/libs/hast-util-to-html.mjs +2696 -0
  56. package/dist/_chunks/libs/is-plain-obj.mjs +9 -0
  57. package/dist/_chunks/libs/longest-streak.mjs +30 -0
  58. package/dist/_chunks/libs/markdown-table.mjs +290 -0
  59. package/dist/_chunks/libs/mdast-util-find-and-replace.mjs +653 -0
  60. package/dist/_chunks/libs/mdast-util-from-markdown.mjs +8522 -0
  61. package/dist/_chunks/libs/mdast-util-gfm.mjs +2393 -0
  62. package/dist/_chunks/libs/mdast-util-to-hast.mjs +1803 -0
  63. package/dist/_chunks/libs/micromark-extension-gfm.mjs +2243 -0
  64. package/dist/_chunks/libs/mnemonist.d.mts +254 -0
  65. package/dist/_chunks/libs/mnemonist.mjs +1978 -0
  66. package/dist/_chunks/libs/natural-compare-lite.mjs +42 -0
  67. package/dist/_chunks/libs/rehype-sanitize.mjs +29 -0
  68. package/dist/_chunks/libs/rehype-stringify.mjs +34 -0
  69. package/dist/_chunks/libs/remark-gfm.mjs +36 -0
  70. package/dist/_chunks/libs/remark-github-blockquote-alert.mjs +100 -0
  71. package/dist/_chunks/libs/remark-parse.mjs +39 -0
  72. package/dist/_chunks/libs/remark-rehype.mjs +171 -0
  73. package/dist/_chunks/libs/remeda.mjs +702 -0
  74. package/dist/_chunks/libs/trough.mjs +158 -0
  75. package/dist/_chunks/libs/unified.mjs +2212 -0
  76. package/dist/_chunks/mnemonist.d.mts +1 -0
  77. package/dist/_chunks/mnemonist.mjs +0 -0
  78. package/dist/_chunks/model.mjs +1898 -0
  79. package/dist/_chunks/model2.mjs +0 -0
  80. package/dist/_chunks/relationships-view.mjs +132 -0
  81. package/dist/_chunks/rolldown-runtime.mjs +42 -0
  82. package/dist/{shared/core.C_3y3eqV.d.mts → _chunks/scalar.d.mts} +13 -43
  83. package/dist/_chunks/scalar.mjs +84 -0
  84. package/dist/_chunks/utils.mjs +483 -0
  85. package/dist/builder/index.d.mts +11 -775
  86. package/dist/builder/index.mjs +631 -1022
  87. package/dist/compute-view/index.d.mts +85 -56
  88. package/dist/compute-view/index.mjs +247 -214
  89. package/dist/compute-view/relationships-view/index.d.mts +16 -51
  90. package/dist/compute-view/relationships-view/index.mjs +6 -184
  91. package/dist/geometry/index.d.mts +2 -109
  92. package/dist/geometry/index.mjs +2 -327
  93. package/dist/index.d.mts +18 -20
  94. package/dist/index.mjs +27 -18
  95. package/dist/model/connection/deployment/index.d.mts +12 -15
  96. package/dist/model/connection/deployment/index.mjs +9 -2
  97. package/dist/model/connection/index.d.mts +14 -75
  98. package/dist/model/connection/index.mjs +10 -3
  99. package/dist/model/connection/model/index.d.mts +12 -15
  100. package/dist/model/connection/model/index.mjs +8 -2
  101. package/dist/model/index.d.mts +15 -57
  102. package/dist/model/index.mjs +11 -4
  103. package/dist/styles/index.d.mts +9 -117
  104. package/dist/styles/index.mjs +26 -59
  105. package/dist/types/RichText.d.mts +3 -0
  106. package/dist/types/RichText.mjs +7 -0
  107. package/dist/types/_aux.d.mts +3 -4
  108. package/dist/types/_aux.mjs +2 -7
  109. package/dist/types/expression-model.d.mts +6 -190
  110. package/dist/types/expression-model.mjs +6 -108
  111. package/dist/types/expression.d.mts +5 -6
  112. package/dist/types/expression.mjs +6 -112
  113. package/dist/types/fqnRef.d.mts +4 -60
  114. package/dist/types/fqnRef.mjs +6 -44
  115. package/dist/types/index.d.mts +9 -47
  116. package/dist/types/index.mjs +14 -16
  117. package/dist/types/scalar.d.mts +2 -2
  118. package/dist/types/scalar.mjs +7 -4
  119. package/dist/utils/graphology/index.d.mts +2 -1864
  120. package/dist/utils/graphology/index.mjs +3 -1
  121. package/dist/utils/index.d.mts +11 -124
  122. package/dist/utils/index.mjs +16 -43
  123. package/dist/utils/iterable/index.d.mts +9 -132
  124. package/dist/utils/iterable/index.mjs +2 -61
  125. package/dist/utils/mnemonist.d.mts +2 -0
  126. package/dist/utils/mnemonist.mjs +12 -0
  127. package/package.json +17 -22
  128. package/compute-view/relationships/package.json +0 -4
  129. package/dist/shared/core.3ZhnKAlZ.mjs +0 -106
  130. package/dist/shared/core.78IWAHAE.mjs +0 -332
  131. package/dist/shared/core.B85MJLTf.mjs +0 -5
  132. package/dist/shared/core.BFd1lU9R.mjs +0 -29
  133. package/dist/shared/core.BKlholso.mjs +0 -3
  134. package/dist/shared/core.BNN-3vPH.mjs +0 -1255
  135. package/dist/shared/core.BPGOjone.d.mts +0 -46
  136. package/dist/shared/core.BP_QHEXs.mjs +0 -785
  137. package/dist/shared/core.BbE4y-yl.mjs +0 -177
  138. package/dist/shared/core.Bdy3hhTc.mjs +0 -28382
  139. package/dist/shared/core.BfCKSW-g.d.mts +0 -1266
  140. package/dist/shared/core.BhNcrwzK.mjs +0 -7
  141. package/dist/shared/core.BkVA6gjl.mjs +0 -5
  142. package/dist/shared/core.BoYfZOBm.mjs +0 -3
  143. package/dist/shared/core.BsSXS-_R.mjs +0 -7
  144. package/dist/shared/core.C3JowhaZ.mjs +0 -32
  145. package/dist/shared/core.C4x8aaWa.mjs +0 -27
  146. package/dist/shared/core.CAgYpDtM.d.mts +0 -98
  147. package/dist/shared/core.CHf8VEa3.mjs +0 -1206
  148. package/dist/shared/core.CLSZtnFh.mjs +0 -69
  149. package/dist/shared/core.CbT8JVYL.mjs +0 -5
  150. package/dist/shared/core.CdNCAwq7.mjs +0 -176
  151. package/dist/shared/core.CmGY9blO.mjs +0 -6717
  152. package/dist/shared/core.CmPXpJ8l.mjs +0 -21
  153. package/dist/shared/core.Coi_LOUZ.mjs +0 -7
  154. package/dist/shared/core.CqAJJpK_.mjs +0 -3
  155. package/dist/shared/core.CywrQs86.d.mts +0 -31
  156. package/dist/shared/core.D00YbOhQ.d.mts +0 -300
  157. package/dist/shared/core.D0WZutNd.mjs +0 -94
  158. package/dist/shared/core.D4npX2q8.mjs +0 -18
  159. package/dist/shared/core.DB0Ue5Wx.d.mts +0 -70
  160. package/dist/shared/core.DC5IAaDT.d.mts +0 -334
  161. package/dist/shared/core.DE9qzhn8.d.mts +0 -83
  162. package/dist/shared/core.DGcIbsj4.mjs +0 -3946
  163. package/dist/shared/core.DH7TXqXf.mjs +0 -136
  164. package/dist/shared/core.DKhRkHRN.d.mts +0 -41
  165. package/dist/shared/core.DRJma0Ol.mjs +0 -22
  166. package/dist/shared/core.DU5SRqNF.mjs +0 -2209
  167. package/dist/shared/core.DXhDWKFZ.d.mts +0 -3
  168. package/dist/shared/core.DbfO90vF.mjs +0 -434
  169. package/dist/shared/core.DcS-0zys.mjs +0 -10
  170. package/dist/shared/core.Dh119QSP.mjs +0 -4995
  171. package/dist/shared/core.DjcWextK.mjs +0 -1371
  172. package/dist/shared/core.Dojz4bvg.d.mts +0 -504
  173. package/dist/shared/core.FZ305VYd.mjs +0 -21
  174. package/dist/shared/core.RfnaEmgA.mjs +0 -7
  175. package/dist/shared/core.btEq3i3f.mjs +0 -300
  176. package/dist/shared/core.oSV6SRfk.mjs +0 -13
  177. package/dist/shared/core.om36dXXW.mjs +0 -41
  178. package/dist/shared/core.osFs8tU7.d.mts +0 -466
  179. package/dist/shared/core.q10OP9oJ.mjs +0 -5
  180. package/dist/shared/core.tpvDGvdC.d.mts +0 -87
  181. package/dist/shared/core.uFk_o9X6.mjs +0 -13
@@ -0,0 +1,863 @@
1
+ import { t as esm_default } from "./@ungap/structured-clone.mjs";
2
+
3
+ //#region ../../node_modules/.pnpm/unist-util-position@5.0.0/node_modules/unist-util-position/lib/index.js
4
+ /**
5
+ * @typedef {import('unist').Node} Node
6
+ * @typedef {import('unist').Point} Point
7
+ * @typedef {import('unist').Position} Position
8
+ */
9
+ /**
10
+ * @typedef NodeLike
11
+ * @property {string} type
12
+ * @property {PositionLike | null | undefined} [position]
13
+ *
14
+ * @typedef PositionLike
15
+ * @property {PointLike | null | undefined} [start]
16
+ * @property {PointLike | null | undefined} [end]
17
+ *
18
+ * @typedef PointLike
19
+ * @property {number | null | undefined} [line]
20
+ * @property {number | null | undefined} [column]
21
+ * @property {number | null | undefined} [offset]
22
+ */
23
+ /**
24
+ * Get the ending point of `node`.
25
+ *
26
+ * @param node
27
+ * Node.
28
+ * @returns
29
+ * Point.
30
+ */
31
+ const pointEnd = point("end");
32
+ /**
33
+ * Get the starting point of `node`.
34
+ *
35
+ * @param node
36
+ * Node.
37
+ * @returns
38
+ * Point.
39
+ */
40
+ const pointStart = point("start");
41
+ /**
42
+ * Get the positional info of `node`.
43
+ *
44
+ * @param {'end' | 'start'} type
45
+ * Side.
46
+ * @returns
47
+ * Getter.
48
+ */
49
+ function point(type) {
50
+ return point;
51
+ /**
52
+ * Get the point info of `node` at a bound side.
53
+ *
54
+ * @param {Node | NodeLike | null | undefined} [node]
55
+ * @returns {Point | undefined}
56
+ */
57
+ function point(node) {
58
+ const point = node && node.position && node.position[type] || {};
59
+ if (typeof point.line === "number" && point.line > 0 && typeof point.column === "number" && point.column > 0) return {
60
+ line: point.line,
61
+ column: point.column,
62
+ offset: typeof point.offset === "number" && point.offset > -1 ? point.offset : void 0
63
+ };
64
+ }
65
+ }
66
+ /**
67
+ * Get the positional info of `node`.
68
+ *
69
+ * @param {Node | NodeLike | null | undefined} [node]
70
+ * Node.
71
+ * @returns {Position | undefined}
72
+ * Position.
73
+ */
74
+ function position(node) {
75
+ const start = pointStart(node);
76
+ const end = pointEnd(node);
77
+ if (start && end) return {
78
+ start,
79
+ end
80
+ };
81
+ }
82
+
83
+ //#endregion
84
+ //#region ../../node_modules/.pnpm/hast-util-sanitize@5.0.2/node_modules/hast-util-sanitize/lib/schema.js
85
+ /**
86
+ * @import {Schema} from 'hast-util-sanitize'
87
+ */
88
+ const aria = [
89
+ "ariaDescribedBy",
90
+ "ariaLabel",
91
+ "ariaLabelledBy"
92
+ ];
93
+ /**
94
+ * Default schema.
95
+ *
96
+ * Follows GitHub style sanitation.
97
+ *
98
+ * @type {Schema}
99
+ */
100
+ const defaultSchema = {
101
+ ancestors: {
102
+ tbody: ["table"],
103
+ td: ["table"],
104
+ th: ["table"],
105
+ thead: ["table"],
106
+ tfoot: ["table"],
107
+ tr: ["table"]
108
+ },
109
+ attributes: {
110
+ a: [
111
+ ...aria,
112
+ "dataFootnoteBackref",
113
+ "dataFootnoteRef",
114
+ ["className", "data-footnote-backref"],
115
+ "href"
116
+ ],
117
+ blockquote: ["cite"],
118
+ code: [["className", /^language-./]],
119
+ del: ["cite"],
120
+ div: ["itemScope", "itemType"],
121
+ dl: [...aria],
122
+ h2: [["className", "sr-only"]],
123
+ img: [
124
+ ...aria,
125
+ "longDesc",
126
+ "src"
127
+ ],
128
+ input: [["disabled", true], ["type", "checkbox"]],
129
+ ins: ["cite"],
130
+ li: [["className", "task-list-item"]],
131
+ ol: [...aria, ["className", "contains-task-list"]],
132
+ q: ["cite"],
133
+ section: ["dataFootnotes", ["className", "footnotes"]],
134
+ source: ["srcSet"],
135
+ summary: [...aria],
136
+ table: [...aria],
137
+ ul: [...aria, ["className", "contains-task-list"]],
138
+ "*": [
139
+ "abbr",
140
+ "accept",
141
+ "acceptCharset",
142
+ "accessKey",
143
+ "action",
144
+ "align",
145
+ "alt",
146
+ "axis",
147
+ "border",
148
+ "cellPadding",
149
+ "cellSpacing",
150
+ "char",
151
+ "charOff",
152
+ "charSet",
153
+ "checked",
154
+ "clear",
155
+ "colSpan",
156
+ "color",
157
+ "cols",
158
+ "compact",
159
+ "coords",
160
+ "dateTime",
161
+ "dir",
162
+ "encType",
163
+ "frame",
164
+ "hSpace",
165
+ "headers",
166
+ "height",
167
+ "hrefLang",
168
+ "htmlFor",
169
+ "id",
170
+ "isMap",
171
+ "itemProp",
172
+ "label",
173
+ "lang",
174
+ "maxLength",
175
+ "media",
176
+ "method",
177
+ "multiple",
178
+ "name",
179
+ "noHref",
180
+ "noShade",
181
+ "noWrap",
182
+ "open",
183
+ "prompt",
184
+ "readOnly",
185
+ "rev",
186
+ "rowSpan",
187
+ "rows",
188
+ "rules",
189
+ "scope",
190
+ "selected",
191
+ "shape",
192
+ "size",
193
+ "span",
194
+ "start",
195
+ "summary",
196
+ "tabIndex",
197
+ "title",
198
+ "useMap",
199
+ "vAlign",
200
+ "value",
201
+ "width"
202
+ ]
203
+ },
204
+ clobber: [
205
+ "ariaDescribedBy",
206
+ "ariaLabelledBy",
207
+ "id",
208
+ "name"
209
+ ],
210
+ clobberPrefix: "user-content-",
211
+ protocols: {
212
+ cite: ["http", "https"],
213
+ href: [
214
+ "http",
215
+ "https",
216
+ "irc",
217
+ "ircs",
218
+ "mailto",
219
+ "xmpp"
220
+ ],
221
+ longDesc: ["http", "https"],
222
+ src: ["http", "https"]
223
+ },
224
+ required: { input: {
225
+ disabled: true,
226
+ type: "checkbox"
227
+ } },
228
+ strip: ["script"],
229
+ tagNames: [
230
+ "a",
231
+ "b",
232
+ "blockquote",
233
+ "br",
234
+ "code",
235
+ "dd",
236
+ "del",
237
+ "details",
238
+ "div",
239
+ "dl",
240
+ "dt",
241
+ "em",
242
+ "h1",
243
+ "h2",
244
+ "h3",
245
+ "h4",
246
+ "h5",
247
+ "h6",
248
+ "hr",
249
+ "i",
250
+ "img",
251
+ "input",
252
+ "ins",
253
+ "kbd",
254
+ "li",
255
+ "ol",
256
+ "p",
257
+ "picture",
258
+ "pre",
259
+ "q",
260
+ "rp",
261
+ "rt",
262
+ "ruby",
263
+ "s",
264
+ "samp",
265
+ "section",
266
+ "source",
267
+ "span",
268
+ "strike",
269
+ "strong",
270
+ "sub",
271
+ "summary",
272
+ "sup",
273
+ "table",
274
+ "tbody",
275
+ "td",
276
+ "tfoot",
277
+ "th",
278
+ "thead",
279
+ "tr",
280
+ "tt",
281
+ "ul",
282
+ "var"
283
+ ]
284
+ };
285
+
286
+ //#endregion
287
+ //#region ../../node_modules/.pnpm/hast-util-sanitize@5.0.2/node_modules/hast-util-sanitize/lib/index.js
288
+ /**
289
+ * @import {
290
+ * Comment,
291
+ * Doctype,
292
+ * ElementContent,
293
+ * Element,
294
+ * Nodes,
295
+ * Properties,
296
+ * RootContent,
297
+ * Root,
298
+ * Text
299
+ * } from 'hast'
300
+ */
301
+ /**
302
+ * @typedef {[string, ...Array<Exclude<Properties[keyof Properties], Array<any>> | RegExp>] | string} PropertyDefinition
303
+ * Definition for a property.
304
+ *
305
+ * @typedef Schema
306
+ * Schema that defines what nodes and properties are allowed.
307
+ *
308
+ * The default schema is `defaultSchema`, which follows how GitHub cleans.
309
+ * If any top-level key is missing in the given schema, the corresponding
310
+ * value of the default schema is used.
311
+ *
312
+ * To extend the standard schema with a few changes, clone `defaultSchema`
313
+ * like so:
314
+ *
315
+ * ```js
316
+ * import deepmerge from 'deepmerge'
317
+ * import {h} from 'hastscript'
318
+ * import {defaultSchema, sanitize} from 'hast-util-sanitize'
319
+ *
320
+ * // This allows `className` on all elements.
321
+ * const schema = deepmerge(defaultSchema, {attributes: {'*': ['className']}})
322
+ *
323
+ * const tree = sanitize(h('div', {className: ['foo']}), schema)
324
+ *
325
+ * // `tree` still has `className`.
326
+ * console.log(tree)
327
+ * // {
328
+ * // type: 'element',
329
+ * // tagName: 'div',
330
+ * // properties: {className: ['foo']},
331
+ * // children: []
332
+ * // }
333
+ * ```
334
+ * @property {boolean | null | undefined} [allowComments=false]
335
+ * Whether to allow comment nodes (default: `false`).
336
+ *
337
+ * For example:
338
+ *
339
+ * ```js
340
+ * allowComments: true
341
+ * ```
342
+ * @property {boolean | null | undefined} [allowDoctypes=false]
343
+ * Whether to allow doctype nodes (default: `false`).
344
+ *
345
+ * For example:
346
+ *
347
+ * ```js
348
+ * allowDoctypes: true
349
+ * ```
350
+ * @property {Record<string, Array<string>> | null | undefined} [ancestors]
351
+ * Map of tag names to a list of tag names which are required ancestors
352
+ * (default: `defaultSchema.ancestors`).
353
+ *
354
+ * Elements with these tag names will be ignored if they occur outside of one
355
+ * of their allowed parents.
356
+ *
357
+ * For example:
358
+ *
359
+ * ```js
360
+ * ancestors: {
361
+ * tbody: ['table'],
362
+ * // …
363
+ * tr: ['table']
364
+ * }
365
+ * ```
366
+ * @property {Record<string, Array<PropertyDefinition>> | null | undefined} [attributes]
367
+ * Map of tag names to allowed property names (default:
368
+ * `defaultSchema.attributes`).
369
+ *
370
+ * The special key `'*'` as a tag name defines property names allowed on all
371
+ * elements.
372
+ *
373
+ * The special value `'data*'` as a property name can be used to allow all
374
+ * `data` properties.
375
+ *
376
+ * For example:
377
+ *
378
+ * ```js
379
+ * attributes: {
380
+ * 'ariaDescribedBy', 'ariaLabel', 'ariaLabelledBy', …, 'href'
381
+ * // …
382
+ * '*': [
383
+ * 'abbr',
384
+ * 'accept',
385
+ * 'acceptCharset',
386
+ * // …
387
+ * 'vAlign',
388
+ * 'value',
389
+ * 'width'
390
+ * ]
391
+ * }
392
+ * ```
393
+ *
394
+ * Instead of a single string in the array, which allows any property value
395
+ * for the field, you can use an array to allow several values.
396
+ * For example, `input: ['type']` allows `type` set to any value on `input`s.
397
+ * But `input: [['type', 'checkbox', 'radio']]` allows `type` when set to
398
+ * `'checkbox'` or `'radio'`.
399
+ *
400
+ * You can use regexes, so for example `span: [['className', /^hljs-/]]`
401
+ * allows any class that starts with `hljs-` on `span`s.
402
+ *
403
+ * When comma- or space-separated values are used (such as `className`), each
404
+ * value in is checked individually.
405
+ * For example, to allow certain classes on `span`s for syntax highlighting,
406
+ * use `span: [['className', 'number', 'operator', 'token']]`.
407
+ * This will allow `'number'`, `'operator'`, and `'token'` classes, but drop
408
+ * others.
409
+ * @property {Array<string> | null | undefined} [clobber]
410
+ * List of property names that clobber (default: `defaultSchema.clobber`).
411
+ *
412
+ * For example:
413
+ *
414
+ * ```js
415
+ * clobber: ['ariaDescribedBy', 'ariaLabelledBy', 'id', 'name']
416
+ * ```
417
+ * @property {string | null | undefined} [clobberPrefix]
418
+ * Prefix to use before clobbering properties (default:
419
+ * `defaultSchema.clobberPrefix`).
420
+ *
421
+ * For example:
422
+ *
423
+ * ```js
424
+ * clobberPrefix: 'user-content-'
425
+ * ```
426
+ * @property {Record<string, Array<string> | null | undefined> | null | undefined} [protocols]
427
+ * Map of *property names* to allowed protocols (default:
428
+ * `defaultSchema.protocols`).
429
+ *
430
+ * This defines URLs that are always allowed to have local URLs (relative to
431
+ * the current website, such as `this`, `#this`, `/this`, or `?this`), and
432
+ * only allowed to have remote URLs (such as `https://example.com`) if they
433
+ * use a known protocol.
434
+ *
435
+ * For example:
436
+ *
437
+ * ```js
438
+ * protocols: {
439
+ * cite: ['http', 'https'],
440
+ * // …
441
+ * src: ['http', 'https']
442
+ * }
443
+ * ```
444
+ * @property {Record<string, Record<string, Properties[keyof Properties]>> | null | undefined} [required]
445
+ * Map of tag names to required property names with a default value
446
+ * (default: `defaultSchema.required`).
447
+ *
448
+ * This defines properties that must be set.
449
+ * If a field does not exist (after the element was made safe), these will be
450
+ * added with the given value.
451
+ *
452
+ * For example:
453
+ *
454
+ * ```js
455
+ * required: {
456
+ * input: {disabled: true, type: 'checkbox'}
457
+ * }
458
+ * ```
459
+ *
460
+ * > 👉 **Note**: properties are first checked based on `schema.attributes`,
461
+ * > then on `schema.required`.
462
+ * > That means properties could be removed by `attributes` and then added
463
+ * > again with `required`.
464
+ * @property {Array<string> | null | undefined} [strip]
465
+ * List of tag names to strip from the tree (default: `defaultSchema.strip`).
466
+ *
467
+ * By default, unsafe elements (those not in `schema.tagNames`) are replaced
468
+ * by what they contain.
469
+ * This option can drop their contents.
470
+ *
471
+ * For example:
472
+ *
473
+ * ```js
474
+ * strip: ['script']
475
+ * ```
476
+ * @property {Array<string> | null | undefined} [tagNames]
477
+ * List of allowed tag names (default: `defaultSchema.tagNames`).
478
+ *
479
+ * For example:
480
+ *
481
+ * ```js
482
+ * tagNames: [
483
+ * 'a',
484
+ * 'b',
485
+ * // …
486
+ * 'ul',
487
+ * 'var'
488
+ * ]
489
+ * ```
490
+ *
491
+ * @typedef State
492
+ * Info passed around.
493
+ * @property {Readonly<Schema>} schema
494
+ * Schema.
495
+ * @property {Array<string>} stack
496
+ * Tag names of ancestors.
497
+ */
498
+ const own = {}.hasOwnProperty;
499
+ /**
500
+ * Sanitize a tree.
501
+ *
502
+ * @param {Readonly<Nodes>} node
503
+ * Unsafe tree.
504
+ * @param {Readonly<Schema> | null | undefined} [options]
505
+ * Configuration (default: `defaultSchema`).
506
+ * @returns {Nodes}
507
+ * New, safe tree.
508
+ */
509
+ function sanitize(node, options) {
510
+ /** @type {Nodes} */
511
+ let result = {
512
+ type: "root",
513
+ children: []
514
+ };
515
+ const replace = transform({
516
+ schema: options ? {
517
+ ...defaultSchema,
518
+ ...options
519
+ } : defaultSchema,
520
+ stack: []
521
+ }, node);
522
+ if (replace) if (Array.isArray(replace)) if (replace.length === 1) result = replace[0];
523
+ else result.children = replace;
524
+ else result = replace;
525
+ return result;
526
+ }
527
+ /**
528
+ * Sanitize `node`.
529
+ *
530
+ * @param {State} state
531
+ * Info passed around.
532
+ * @param {Readonly<unknown>} node
533
+ * Unsafe node.
534
+ * @returns {Array<ElementContent> | Nodes | undefined}
535
+ * Safe result.
536
+ */
537
+ function transform(state, node) {
538
+ if (node && typeof node === "object") {
539
+ const unsafe = node;
540
+ switch (typeof unsafe.type === "string" ? unsafe.type : "") {
541
+ case "comment": return comment(state, unsafe);
542
+ case "doctype": return doctype(state, unsafe);
543
+ case "element": return element(state, unsafe);
544
+ case "root": return root(state, unsafe);
545
+ case "text": return text(state, unsafe);
546
+ default:
547
+ }
548
+ }
549
+ }
550
+ /**
551
+ * Make a safe comment.
552
+ *
553
+ * @param {State} state
554
+ * Info passed around.
555
+ * @param {Readonly<Record<string, Readonly<unknown>>>} unsafe
556
+ * Unsafe comment-like value.
557
+ * @returns {Comment | undefined}
558
+ * Safe comment (if with `allowComments`).
559
+ */
560
+ function comment(state, unsafe) {
561
+ if (state.schema.allowComments) {
562
+ const result = typeof unsafe.value === "string" ? unsafe.value : "";
563
+ const index = result.indexOf("-->");
564
+ /** @type {Comment} */
565
+ const node = {
566
+ type: "comment",
567
+ value: index < 0 ? result : result.slice(0, index)
568
+ };
569
+ patch(node, unsafe);
570
+ return node;
571
+ }
572
+ }
573
+ /**
574
+ * Make a safe doctype.
575
+ *
576
+ * @param {State} state
577
+ * Info passed around.
578
+ * @param {Readonly<Record<string, Readonly<unknown>>>} unsafe
579
+ * Unsafe doctype-like value.
580
+ * @returns {Doctype | undefined}
581
+ * Safe doctype (if with `allowDoctypes`).
582
+ */
583
+ function doctype(state, unsafe) {
584
+ if (state.schema.allowDoctypes) {
585
+ /** @type {Doctype} */
586
+ const node = { type: "doctype" };
587
+ patch(node, unsafe);
588
+ return node;
589
+ }
590
+ }
591
+ /**
592
+ * Make a safe element.
593
+ *
594
+ * @param {State} state
595
+ * Info passed around.
596
+ * @param {Readonly<Record<string, Readonly<unknown>>>} unsafe
597
+ * Unsafe element-like value.
598
+ * @returns {Array<ElementContent> | Element | undefined}
599
+ * Safe element.
600
+ */
601
+ function element(state, unsafe) {
602
+ const name = typeof unsafe.tagName === "string" ? unsafe.tagName : "";
603
+ state.stack.push(name);
604
+ const content = children(state, unsafe.children);
605
+ const properties_ = properties(state, unsafe.properties);
606
+ state.stack.pop();
607
+ let safeElement = false;
608
+ if (name && name !== "*" && (!state.schema.tagNames || state.schema.tagNames.includes(name))) {
609
+ safeElement = true;
610
+ if (state.schema.ancestors && own.call(state.schema.ancestors, name)) {
611
+ const ancestors = state.schema.ancestors[name];
612
+ let index = -1;
613
+ safeElement = false;
614
+ while (++index < ancestors.length) if (state.stack.includes(ancestors[index])) safeElement = true;
615
+ }
616
+ }
617
+ if (!safeElement) return state.schema.strip && !state.schema.strip.includes(name) ? content : void 0;
618
+ /** @type {Element} */
619
+ const node = {
620
+ type: "element",
621
+ tagName: name,
622
+ properties: properties_,
623
+ children: content
624
+ };
625
+ patch(node, unsafe);
626
+ return node;
627
+ }
628
+ /**
629
+ * Make a safe root.
630
+ *
631
+ * @param {State} state
632
+ * Info passed around.
633
+ * @param {Readonly<Record<string, Readonly<unknown>>>} unsafe
634
+ * Unsafe root-like value.
635
+ * @returns {Root}
636
+ * Safe root.
637
+ */
638
+ function root(state, unsafe) {
639
+ /** @type {Root} */
640
+ const node = {
641
+ type: "root",
642
+ children: children(state, unsafe.children)
643
+ };
644
+ patch(node, unsafe);
645
+ return node;
646
+ }
647
+ /**
648
+ * Make a safe text.
649
+ *
650
+ * @param {State} _
651
+ * Info passed around.
652
+ * @param {Readonly<Record<string, Readonly<unknown>>>} unsafe
653
+ * Unsafe text-like value.
654
+ * @returns {Text}
655
+ * Safe text.
656
+ */
657
+ function text(_, unsafe) {
658
+ /** @type {Text} */
659
+ const node = {
660
+ type: "text",
661
+ value: typeof unsafe.value === "string" ? unsafe.value : ""
662
+ };
663
+ patch(node, unsafe);
664
+ return node;
665
+ }
666
+ /**
667
+ * Make children safe.
668
+ *
669
+ * @param {State} state
670
+ * Info passed around.
671
+ * @param {Readonly<unknown>} children
672
+ * Unsafe value.
673
+ * @returns {Array<Nodes>}
674
+ * Safe children.
675
+ */
676
+ function children(state, children) {
677
+ /** @type {Array<Nodes>} */
678
+ const results = [];
679
+ if (Array.isArray(children)) {
680
+ const childrenUnknown = children;
681
+ let index = -1;
682
+ while (++index < childrenUnknown.length) {
683
+ const value = transform(state, childrenUnknown[index]);
684
+ if (value) if (Array.isArray(value)) results.push(...value);
685
+ else results.push(value);
686
+ }
687
+ }
688
+ return results;
689
+ }
690
+ /**
691
+ * Make element properties safe.
692
+ *
693
+ * @param {State} state
694
+ * Info passed around.
695
+ * @param {Readonly<unknown>} properties
696
+ * Unsafe value.
697
+ * @returns {Properties}
698
+ * Safe value.
699
+ */
700
+ function properties(state, properties) {
701
+ const tagName = state.stack[state.stack.length - 1];
702
+ const attributes = state.schema.attributes;
703
+ const required = state.schema.required;
704
+ const specific = attributes && own.call(attributes, tagName) ? attributes[tagName] : void 0;
705
+ const defaults = attributes && own.call(attributes, "*") ? attributes["*"] : void 0;
706
+ const properties_ = properties && typeof properties === "object" ? properties : {};
707
+ /** @type {Properties} */
708
+ const result = {};
709
+ /** @type {string} */
710
+ let key;
711
+ for (key in properties_) if (own.call(properties_, key)) {
712
+ const unsafe = properties_[key];
713
+ let safe = propertyValue(state, findDefinition(specific, key), key, unsafe);
714
+ if (safe === null || safe === void 0) safe = propertyValue(state, findDefinition(defaults, key), key, unsafe);
715
+ if (safe !== null && safe !== void 0) result[key] = safe;
716
+ }
717
+ if (required && own.call(required, tagName)) {
718
+ const properties = required[tagName];
719
+ for (key in properties) if (own.call(properties, key) && !own.call(result, key)) result[key] = properties[key];
720
+ }
721
+ return result;
722
+ }
723
+ /**
724
+ * Sanitize a property value.
725
+ *
726
+ * @param {State} state
727
+ * Info passed around.
728
+ * @param {Readonly<PropertyDefinition> | undefined} definition
729
+ * Definition.
730
+ * @param {string} key
731
+ * Field name.
732
+ * @param {Readonly<unknown>} value
733
+ * Unsafe value (but an array).
734
+ * @returns {Array<number | string> | boolean | number | string | undefined}
735
+ * Safe value.
736
+ */
737
+ function propertyValue(state, definition, key, value) {
738
+ return definition ? Array.isArray(value) ? propertyValueMany(state, definition, key, value) : propertyValuePrimitive(state, definition, key, value) : void 0;
739
+ }
740
+ /**
741
+ * Sanitize a property value which is a list.
742
+ *
743
+ * @param {State} state
744
+ * Info passed around.
745
+ * @param {Readonly<PropertyDefinition>} definition
746
+ * Definition.
747
+ * @param {string} key
748
+ * Field name.
749
+ * @param {Readonly<Array<Readonly<unknown>>>} values
750
+ * Unsafe value (but an array).
751
+ * @returns {Array<number | string>}
752
+ * Safe value.
753
+ */
754
+ function propertyValueMany(state, definition, key, values) {
755
+ let index = -1;
756
+ /** @type {Array<number | string>} */
757
+ const result = [];
758
+ while (++index < values.length) {
759
+ const value = propertyValuePrimitive(state, definition, key, values[index]);
760
+ if (typeof value === "number" || typeof value === "string") result.push(value);
761
+ }
762
+ return result;
763
+ }
764
+ /**
765
+ * Sanitize a property value which is a primitive.
766
+ *
767
+ * @param {State} state
768
+ * Info passed around.
769
+ * @param {Readonly<PropertyDefinition>} definition
770
+ * Definition.
771
+ * @param {string} key
772
+ * Field name.
773
+ * @param {Readonly<unknown>} value
774
+ * Unsafe value (but not an array).
775
+ * @returns {boolean | number | string | undefined}
776
+ * Safe value.
777
+ */
778
+ function propertyValuePrimitive(state, definition, key, value) {
779
+ if (typeof value !== "boolean" && typeof value !== "number" && typeof value !== "string") return;
780
+ if (!safeProtocol(state, key, value)) return;
781
+ if (typeof definition === "object" && definition.length > 1) {
782
+ let ok = false;
783
+ let index = 0;
784
+ while (++index < definition.length) {
785
+ const allowed = definition[index];
786
+ if (allowed && typeof allowed === "object" && "flags" in allowed) {
787
+ if (allowed.test(String(value))) {
788
+ ok = true;
789
+ break;
790
+ }
791
+ } else if (allowed === value) {
792
+ ok = true;
793
+ break;
794
+ }
795
+ }
796
+ if (!ok) return;
797
+ }
798
+ return state.schema.clobber && state.schema.clobberPrefix && state.schema.clobber.includes(key) ? state.schema.clobberPrefix + value : value;
799
+ }
800
+ /**
801
+ * Check whether `value` is a safe URL.
802
+ *
803
+ * @param {State} state
804
+ * Info passed around.
805
+ * @param {string} key
806
+ * Field name.
807
+ * @param {Readonly<unknown>} value
808
+ * Unsafe value.
809
+ * @returns {boolean}
810
+ * Whether it’s a safe value.
811
+ */
812
+ function safeProtocol(state, key, value) {
813
+ const protocols = state.schema.protocols && own.call(state.schema.protocols, key) ? state.schema.protocols[key] : void 0;
814
+ if (!protocols || protocols.length === 0) return true;
815
+ const url = String(value);
816
+ const colon = url.indexOf(":");
817
+ const questionMark = url.indexOf("?");
818
+ const numberSign = url.indexOf("#");
819
+ const slash = url.indexOf("/");
820
+ if (colon < 0 || slash > -1 && colon > slash || questionMark > -1 && colon > questionMark || numberSign > -1 && colon > numberSign) return true;
821
+ let index = -1;
822
+ while (++index < protocols.length) {
823
+ const protocol = protocols[index];
824
+ if (colon === protocol.length && url.slice(0, protocol.length) === protocol) return true;
825
+ }
826
+ return false;
827
+ }
828
+ /**
829
+ * Add data and position.
830
+ *
831
+ * @param {Nodes} node
832
+ * Node to patch safe data and position on.
833
+ * @param {Readonly<Record<string, Readonly<unknown>>>} unsafe
834
+ * Unsafe node-like value.
835
+ * @returns {undefined}
836
+ * Nothing.
837
+ */
838
+ function patch(node, unsafe) {
839
+ const cleanPosition = position(unsafe);
840
+ if (unsafe.data) node.data = esm_default(unsafe.data);
841
+ if (cleanPosition) node.position = cleanPosition;
842
+ }
843
+ /**
844
+ *
845
+ * @param {Readonly<Array<PropertyDefinition>> | undefined} definitions
846
+ * @param {string} key
847
+ * @returns {Readonly<PropertyDefinition> | undefined}
848
+ */
849
+ function findDefinition(definitions, key) {
850
+ /** @type {PropertyDefinition | undefined} */
851
+ let dataDefault;
852
+ let index = -1;
853
+ if (definitions) while (++index < definitions.length) {
854
+ const entry = definitions[index];
855
+ const name = typeof entry === "string" ? entry : entry[0];
856
+ if (name === key) return entry;
857
+ if (name === "data*") dataDefault = entry;
858
+ }
859
+ if (key.length > 4 && key.slice(0, 4).toLowerCase() === "data") return dataDefault;
860
+ }
861
+
862
+ //#endregion
863
+ export { position as a, pointStart as i, defaultSchema as n, pointEnd as r, sanitize as t };