thunderous 0.6.4 → 1.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.cjs +734 -1053
- package/dist/index.d.cts +699 -91
- package/dist/index.d.ts +699 -91
- package/dist/index.js +730 -1052
- package/package.json +10 -16
package/dist/index.js
CHANGED
@@ -1,18 +1,452 @@
|
|
1
|
-
// src/
|
2
|
-
|
3
|
-
|
4
|
-
|
1
|
+
// vendor/@webcomponents/scoped-custom-element-registry/src/scoped-custom-element-registry.js
|
2
|
+
if (typeof window !== "undefined") {
|
3
|
+
if (!ShadowRoot.prototype.createElement) {
|
4
|
+
const NativeHTMLElement = window.HTMLElement;
|
5
|
+
const nativeDefine = window.customElements.define;
|
6
|
+
const nativeGet = window.customElements.get;
|
7
|
+
const nativeRegistry = window.customElements;
|
8
|
+
const definitionForElement = /* @__PURE__ */ new WeakMap();
|
9
|
+
const pendingRegistryForElement = /* @__PURE__ */ new WeakMap();
|
10
|
+
const globalDefinitionForConstructor = /* @__PURE__ */ new WeakMap();
|
11
|
+
const scopeForElement = /* @__PURE__ */ new WeakMap();
|
12
|
+
window.CustomElementRegistry = class {
|
13
|
+
constructor() {
|
14
|
+
this._definitionsByTag = /* @__PURE__ */ new Map();
|
15
|
+
this._definitionsByClass = /* @__PURE__ */ new Map();
|
16
|
+
this._whenDefinedPromises = /* @__PURE__ */ new Map();
|
17
|
+
this._awaitingUpgrade = /* @__PURE__ */ new Map();
|
18
|
+
}
|
19
|
+
define(tagName, elementClass) {
|
20
|
+
tagName = tagName.toLowerCase();
|
21
|
+
if (this._getDefinition(tagName) !== void 0) {
|
22
|
+
throw new DOMException(
|
23
|
+
`Failed to execute 'define' on 'CustomElementRegistry': the name "${tagName}" has already been used with this registry`
|
24
|
+
);
|
25
|
+
}
|
26
|
+
if (this._definitionsByClass.get(elementClass) !== void 0) {
|
27
|
+
throw new DOMException(
|
28
|
+
`Failed to execute 'define' on 'CustomElementRegistry': this constructor has already been used with this registry`
|
29
|
+
);
|
30
|
+
}
|
31
|
+
const attributeChangedCallback = elementClass.prototype.attributeChangedCallback;
|
32
|
+
const observedAttributes = new Set(elementClass.observedAttributes || []);
|
33
|
+
patchAttributes(
|
34
|
+
elementClass,
|
35
|
+
observedAttributes,
|
36
|
+
attributeChangedCallback
|
37
|
+
);
|
38
|
+
const definition = {
|
39
|
+
elementClass,
|
40
|
+
connectedCallback: elementClass.prototype.connectedCallback,
|
41
|
+
disconnectedCallback: elementClass.prototype.disconnectedCallback,
|
42
|
+
adoptedCallback: elementClass.prototype.adoptedCallback,
|
43
|
+
attributeChangedCallback,
|
44
|
+
"formAssociated": elementClass["formAssociated"],
|
45
|
+
"formAssociatedCallback": elementClass.prototype["formAssociatedCallback"],
|
46
|
+
"formDisabledCallback": elementClass.prototype["formDisabledCallback"],
|
47
|
+
"formResetCallback": elementClass.prototype["formResetCallback"],
|
48
|
+
"formStateRestoreCallback": elementClass.prototype["formStateRestoreCallback"],
|
49
|
+
observedAttributes
|
50
|
+
};
|
51
|
+
this._definitionsByTag.set(tagName, definition);
|
52
|
+
this._definitionsByClass.set(elementClass, definition);
|
53
|
+
let standInClass = nativeGet.call(nativeRegistry, tagName);
|
54
|
+
if (!standInClass) {
|
55
|
+
standInClass = createStandInElement(tagName);
|
56
|
+
nativeDefine.call(nativeRegistry, tagName, standInClass);
|
57
|
+
}
|
58
|
+
if (this === window.customElements) {
|
59
|
+
globalDefinitionForConstructor.set(elementClass, definition);
|
60
|
+
definition.standInClass = standInClass;
|
61
|
+
}
|
62
|
+
const awaiting = this._awaitingUpgrade.get(tagName);
|
63
|
+
if (awaiting) {
|
64
|
+
this._awaitingUpgrade.delete(tagName);
|
65
|
+
for (const element of awaiting) {
|
66
|
+
pendingRegistryForElement.delete(element);
|
67
|
+
customize(element, definition, true);
|
68
|
+
}
|
69
|
+
}
|
70
|
+
const info = this._whenDefinedPromises.get(tagName);
|
71
|
+
if (info !== void 0) {
|
72
|
+
info.resolve(elementClass);
|
73
|
+
this._whenDefinedPromises.delete(tagName);
|
74
|
+
}
|
75
|
+
return elementClass;
|
76
|
+
}
|
77
|
+
upgrade() {
|
78
|
+
creationContext.push(this);
|
79
|
+
nativeRegistry.upgrade.apply(nativeRegistry, arguments);
|
80
|
+
creationContext.pop();
|
81
|
+
}
|
82
|
+
get(tagName) {
|
83
|
+
const definition = this._definitionsByTag.get(tagName);
|
84
|
+
return definition?.elementClass;
|
85
|
+
}
|
86
|
+
_getDefinition(tagName) {
|
87
|
+
return this._definitionsByTag.get(tagName);
|
88
|
+
}
|
89
|
+
whenDefined(tagName) {
|
90
|
+
const definition = this._getDefinition(tagName);
|
91
|
+
if (definition !== void 0) {
|
92
|
+
return Promise.resolve(definition.elementClass);
|
93
|
+
}
|
94
|
+
let info = this._whenDefinedPromises.get(tagName);
|
95
|
+
if (info === void 0) {
|
96
|
+
info = {};
|
97
|
+
info.promise = new Promise((r) => info.resolve = r);
|
98
|
+
this._whenDefinedPromises.set(tagName, info);
|
99
|
+
}
|
100
|
+
return info.promise;
|
101
|
+
}
|
102
|
+
_upgradeWhenDefined(element, tagName, shouldUpgrade) {
|
103
|
+
let awaiting = this._awaitingUpgrade.get(tagName);
|
104
|
+
if (!awaiting) {
|
105
|
+
this._awaitingUpgrade.set(tagName, awaiting = /* @__PURE__ */ new Set());
|
106
|
+
}
|
107
|
+
if (shouldUpgrade) {
|
108
|
+
awaiting.add(element);
|
109
|
+
} else {
|
110
|
+
awaiting.delete(element);
|
111
|
+
}
|
112
|
+
}
|
113
|
+
};
|
114
|
+
let upgradingInstance;
|
115
|
+
window.HTMLElement = function HTMLElement2() {
|
116
|
+
let instance = upgradingInstance;
|
117
|
+
if (instance) {
|
118
|
+
upgradingInstance = void 0;
|
119
|
+
return instance;
|
120
|
+
}
|
121
|
+
const definition = globalDefinitionForConstructor.get(this.constructor);
|
122
|
+
if (!definition) {
|
123
|
+
throw new TypeError(
|
124
|
+
"Illegal constructor (custom element class must be registered with global customElements registry to be newable)"
|
125
|
+
);
|
126
|
+
}
|
127
|
+
instance = Reflect.construct(
|
128
|
+
NativeHTMLElement,
|
129
|
+
[],
|
130
|
+
definition.standInClass
|
131
|
+
);
|
132
|
+
Object.setPrototypeOf(instance, this.constructor.prototype);
|
133
|
+
definitionForElement.set(instance, definition);
|
134
|
+
return instance;
|
135
|
+
};
|
136
|
+
window.HTMLElement.prototype = NativeHTMLElement.prototype;
|
137
|
+
const isValidScope = (node) => node === document || node instanceof ShadowRoot;
|
138
|
+
const registryForNode = (node) => {
|
139
|
+
let scope = node.getRootNode();
|
140
|
+
if (!isValidScope(scope)) {
|
141
|
+
const context = creationContext[creationContext.length - 1];
|
142
|
+
if (context instanceof CustomElementRegistry) {
|
143
|
+
return context;
|
144
|
+
}
|
145
|
+
scope = context.getRootNode();
|
146
|
+
if (!isValidScope(scope)) {
|
147
|
+
scope = scopeForElement.get(scope)?.getRootNode() || document;
|
148
|
+
}
|
149
|
+
}
|
150
|
+
return scope.customElements;
|
151
|
+
};
|
152
|
+
const createStandInElement = (tagName) => {
|
153
|
+
return class ScopedCustomElementBase {
|
154
|
+
static get ["formAssociated"]() {
|
155
|
+
return true;
|
156
|
+
}
|
157
|
+
constructor() {
|
158
|
+
const instance = Reflect.construct(
|
159
|
+
NativeHTMLElement,
|
160
|
+
[],
|
161
|
+
this.constructor
|
162
|
+
);
|
163
|
+
Object.setPrototypeOf(instance, HTMLElement.prototype);
|
164
|
+
const registry = registryForNode(instance) || window.customElements;
|
165
|
+
const definition = registry._getDefinition(tagName);
|
166
|
+
if (definition) {
|
167
|
+
customize(instance, definition);
|
168
|
+
} else {
|
169
|
+
pendingRegistryForElement.set(instance, registry);
|
170
|
+
}
|
171
|
+
return instance;
|
172
|
+
}
|
173
|
+
connectedCallback() {
|
174
|
+
const definition = definitionForElement.get(this);
|
175
|
+
if (definition) {
|
176
|
+
definition.connectedCallback && definition.connectedCallback.apply(this, arguments);
|
177
|
+
} else {
|
178
|
+
pendingRegistryForElement.get(this)._upgradeWhenDefined(this, tagName, true);
|
179
|
+
}
|
180
|
+
}
|
181
|
+
disconnectedCallback() {
|
182
|
+
const definition = definitionForElement.get(this);
|
183
|
+
if (definition) {
|
184
|
+
definition.disconnectedCallback && definition.disconnectedCallback.apply(this, arguments);
|
185
|
+
} else {
|
186
|
+
pendingRegistryForElement.get(this)._upgradeWhenDefined(this, tagName, false);
|
187
|
+
}
|
188
|
+
}
|
189
|
+
adoptedCallback() {
|
190
|
+
const definition = definitionForElement.get(this);
|
191
|
+
definition?.adoptedCallback?.apply(this, arguments);
|
192
|
+
}
|
193
|
+
// Form-associated custom elements lifecycle methods
|
194
|
+
["formAssociatedCallback"]() {
|
195
|
+
const definition = definitionForElement.get(this);
|
196
|
+
if (definition && definition["formAssociated"]) {
|
197
|
+
definition?.["formAssociatedCallback"]?.apply(this, arguments);
|
198
|
+
}
|
199
|
+
}
|
200
|
+
["formDisabledCallback"]() {
|
201
|
+
const definition = definitionForElement.get(this);
|
202
|
+
if (definition?.["formAssociated"]) {
|
203
|
+
definition?.["formDisabledCallback"]?.apply(this, arguments);
|
204
|
+
}
|
205
|
+
}
|
206
|
+
["formResetCallback"]() {
|
207
|
+
const definition = definitionForElement.get(this);
|
208
|
+
if (definition?.["formAssociated"]) {
|
209
|
+
definition?.["formResetCallback"]?.apply(this, arguments);
|
210
|
+
}
|
211
|
+
}
|
212
|
+
["formStateRestoreCallback"]() {
|
213
|
+
const definition = definitionForElement.get(this);
|
214
|
+
if (definition?.["formAssociated"]) {
|
215
|
+
definition?.["formStateRestoreCallback"]?.apply(this, arguments);
|
216
|
+
}
|
217
|
+
}
|
218
|
+
// no attributeChangedCallback or observedAttributes since these
|
219
|
+
// are simulated via setAttribute/removeAttribute patches
|
220
|
+
};
|
221
|
+
};
|
222
|
+
const patchAttributes = (elementClass, observedAttributes, attributeChangedCallback) => {
|
223
|
+
if (observedAttributes.size === 0 || attributeChangedCallback === void 0) {
|
224
|
+
return;
|
225
|
+
}
|
226
|
+
const setAttribute = elementClass.prototype.setAttribute;
|
227
|
+
if (setAttribute) {
|
228
|
+
elementClass.prototype.setAttribute = function(n, value) {
|
229
|
+
const name = n.toLowerCase();
|
230
|
+
if (observedAttributes.has(name)) {
|
231
|
+
const old = this.getAttribute(name);
|
232
|
+
setAttribute.call(this, name, value);
|
233
|
+
attributeChangedCallback.call(this, name, old, value);
|
234
|
+
} else {
|
235
|
+
setAttribute.call(this, name, value);
|
236
|
+
}
|
237
|
+
};
|
238
|
+
}
|
239
|
+
const removeAttribute = elementClass.prototype.removeAttribute;
|
240
|
+
if (removeAttribute) {
|
241
|
+
elementClass.prototype.removeAttribute = function(n) {
|
242
|
+
const name = n.toLowerCase();
|
243
|
+
if (observedAttributes.has(name)) {
|
244
|
+
const old = this.getAttribute(name);
|
245
|
+
removeAttribute.call(this, name);
|
246
|
+
attributeChangedCallback.call(this, name, old, null);
|
247
|
+
} else {
|
248
|
+
removeAttribute.call(this, name);
|
249
|
+
}
|
250
|
+
};
|
251
|
+
}
|
252
|
+
const toggleAttribute = elementClass.prototype.toggleAttribute;
|
253
|
+
if (toggleAttribute) {
|
254
|
+
elementClass.prototype.toggleAttribute = function(n, force) {
|
255
|
+
const name = n.toLowerCase();
|
256
|
+
if (observedAttributes.has(name)) {
|
257
|
+
const old = this.getAttribute(name);
|
258
|
+
toggleAttribute.call(this, name, force);
|
259
|
+
const newValue = this.getAttribute(name);
|
260
|
+
attributeChangedCallback.call(this, name, old, newValue);
|
261
|
+
} else {
|
262
|
+
toggleAttribute.call(this, name, force);
|
263
|
+
}
|
264
|
+
};
|
265
|
+
}
|
266
|
+
};
|
267
|
+
const patchHTMLElement = (elementClass) => {
|
268
|
+
const parentClass = Object.getPrototypeOf(elementClass);
|
269
|
+
if (parentClass !== window.HTMLElement) {
|
270
|
+
if (parentClass === NativeHTMLElement) {
|
271
|
+
return Object.setPrototypeOf(elementClass, window.HTMLElement);
|
272
|
+
}
|
273
|
+
return patchHTMLElement(parentClass);
|
274
|
+
}
|
275
|
+
};
|
276
|
+
const customize = (instance, definition, isUpgrade = false) => {
|
277
|
+
Object.setPrototypeOf(instance, definition.elementClass.prototype);
|
278
|
+
definitionForElement.set(instance, definition);
|
279
|
+
upgradingInstance = instance;
|
280
|
+
try {
|
281
|
+
new definition.elementClass();
|
282
|
+
} catch (_) {
|
283
|
+
patchHTMLElement(definition.elementClass);
|
284
|
+
new definition.elementClass();
|
285
|
+
}
|
286
|
+
if (definition.attributeChangedCallback) {
|
287
|
+
definition.observedAttributes.forEach((attr) => {
|
288
|
+
if (instance.hasAttribute(attr)) {
|
289
|
+
definition.attributeChangedCallback.call(
|
290
|
+
instance,
|
291
|
+
attr,
|
292
|
+
null,
|
293
|
+
instance.getAttribute(attr)
|
294
|
+
);
|
295
|
+
}
|
296
|
+
});
|
297
|
+
}
|
298
|
+
if (isUpgrade && definition.connectedCallback && instance.isConnected) {
|
299
|
+
definition.connectedCallback.call(instance);
|
300
|
+
}
|
301
|
+
};
|
302
|
+
const nativeAttachShadow = Element.prototype.attachShadow;
|
303
|
+
Element.prototype.attachShadow = function(init) {
|
304
|
+
const shadowRoot = nativeAttachShadow.apply(this, arguments);
|
305
|
+
if (init.customElements) {
|
306
|
+
shadowRoot.customElements = init.customElements;
|
307
|
+
}
|
308
|
+
return shadowRoot;
|
309
|
+
};
|
310
|
+
let creationContext = [document];
|
311
|
+
const installScopedCreationMethod = (ctor, method, from = void 0) => {
|
312
|
+
const native = (from ? Object.getPrototypeOf(from) : ctor.prototype)[method];
|
313
|
+
ctor.prototype[method] = function() {
|
314
|
+
creationContext.push(this);
|
315
|
+
const ret = native.apply(from || this, arguments);
|
316
|
+
if (ret !== void 0) {
|
317
|
+
scopeForElement.set(ret, this);
|
318
|
+
}
|
319
|
+
creationContext.pop();
|
320
|
+
return ret;
|
321
|
+
};
|
322
|
+
};
|
323
|
+
installScopedCreationMethod(ShadowRoot, "createElement", document);
|
324
|
+
installScopedCreationMethod(ShadowRoot, "importNode", document);
|
325
|
+
installScopedCreationMethod(Element, "insertAdjacentHTML");
|
326
|
+
installScopedCreationMethod(Node, "appendChild");
|
327
|
+
installScopedCreationMethod(Element, "append");
|
328
|
+
const installScopedCreationSetter = (ctor, name) => {
|
329
|
+
const descriptor = Object.getOwnPropertyDescriptor(ctor.prototype, name);
|
330
|
+
Object.defineProperty(ctor.prototype, name, {
|
331
|
+
...descriptor,
|
332
|
+
set(value) {
|
333
|
+
creationContext.push(this);
|
334
|
+
descriptor.set.call(this, value);
|
335
|
+
creationContext.pop();
|
336
|
+
}
|
337
|
+
});
|
338
|
+
};
|
339
|
+
installScopedCreationSetter(Element, "innerHTML");
|
340
|
+
installScopedCreationSetter(ShadowRoot, "innerHTML");
|
341
|
+
Object.defineProperty(window, "customElements", {
|
342
|
+
value: new CustomElementRegistry(),
|
343
|
+
configurable: true,
|
344
|
+
writable: true
|
345
|
+
});
|
346
|
+
if (!!window["ElementInternals"] && !!window["ElementInternals"].prototype["setFormValue"]) {
|
347
|
+
const internalsToHostMap = /* @__PURE__ */ new WeakMap();
|
348
|
+
const attachInternals = HTMLElement.prototype["attachInternals"];
|
349
|
+
const methods = [
|
350
|
+
"setFormValue",
|
351
|
+
"setValidity",
|
352
|
+
"checkValidity",
|
353
|
+
"reportValidity"
|
354
|
+
];
|
355
|
+
HTMLElement.prototype["attachInternals"] = function(...args) {
|
356
|
+
const internals = attachInternals.call(this, ...args);
|
357
|
+
internalsToHostMap.set(internals, this);
|
358
|
+
return internals;
|
359
|
+
};
|
360
|
+
methods.forEach((method) => {
|
361
|
+
const proto = window["ElementInternals"].prototype;
|
362
|
+
const originalMethod = proto[method];
|
363
|
+
proto[method] = function(...args) {
|
364
|
+
const host = internalsToHostMap.get(this);
|
365
|
+
const definition = definitionForElement.get(host);
|
366
|
+
if (definition["formAssociated"] === true) {
|
367
|
+
return originalMethod?.call(this, ...args);
|
368
|
+
} else {
|
369
|
+
throw new DOMException(
|
370
|
+
`Failed to execute ${originalMethod} on 'ElementInternals': The target element is not a form-associated custom element.`
|
371
|
+
);
|
372
|
+
}
|
373
|
+
};
|
374
|
+
});
|
375
|
+
class RadioNodeList extends Array {
|
376
|
+
constructor(elements) {
|
377
|
+
super(...elements);
|
378
|
+
this._elements = elements;
|
379
|
+
}
|
380
|
+
get ["value"]() {
|
381
|
+
return this._elements.find((element) => element["checked"] === true)?.value || "";
|
382
|
+
}
|
383
|
+
}
|
384
|
+
class HTMLFormControlsCollection {
|
385
|
+
constructor(elements) {
|
386
|
+
const entries = /* @__PURE__ */ new Map();
|
387
|
+
elements.forEach((element, index) => {
|
388
|
+
const name = element.getAttribute("name");
|
389
|
+
const nameReference = entries.get(name) || [];
|
390
|
+
this[+index] = element;
|
391
|
+
nameReference.push(element);
|
392
|
+
entries.set(name, nameReference);
|
393
|
+
});
|
394
|
+
this["length"] = elements.length;
|
395
|
+
entries.forEach((value, key) => {
|
396
|
+
if (!value) return;
|
397
|
+
if (value.length === 1) {
|
398
|
+
this[key] = value[0];
|
399
|
+
} else {
|
400
|
+
this[key] = new RadioNodeList(value);
|
401
|
+
}
|
402
|
+
});
|
403
|
+
}
|
404
|
+
["namedItem"](key) {
|
405
|
+
return this[key];
|
406
|
+
}
|
407
|
+
}
|
408
|
+
const formElementsDescriptor = Object.getOwnPropertyDescriptor(
|
409
|
+
HTMLFormElement.prototype,
|
410
|
+
"elements"
|
411
|
+
);
|
412
|
+
Object.defineProperty(HTMLFormElement.prototype, "elements", {
|
413
|
+
get: function() {
|
414
|
+
const nativeElements = formElementsDescriptor.get.call(this, []);
|
415
|
+
const include = [];
|
416
|
+
for (const element of nativeElements) {
|
417
|
+
const definition = definitionForElement.get(element);
|
418
|
+
if (!definition || definition["formAssociated"] === true) {
|
419
|
+
include.push(element);
|
420
|
+
}
|
421
|
+
}
|
422
|
+
return new HTMLFormControlsCollection(include);
|
423
|
+
}
|
424
|
+
});
|
425
|
+
}
|
426
|
+
}
|
427
|
+
class TrackableCustomElementRegistry extends window.CustomElementRegistry {
|
428
|
+
__tagNames = /* @__PURE__ */ new Set();
|
429
|
+
define(tagName, constructor, options) {
|
430
|
+
super.define(tagName, constructor, options);
|
431
|
+
this.__tagNames.add(tagName);
|
432
|
+
}
|
433
|
+
}
|
434
|
+
window.CustomElementRegistry = TrackableCustomElementRegistry;
|
435
|
+
}
|
436
|
+
|
437
|
+
// src/constants.ts
|
438
|
+
var DEFAULT_RENDER_OPTIONS = {
|
439
|
+
formAssociated: false,
|
440
|
+
observedAttributes: [],
|
441
|
+
attributesAsProperties: [],
|
442
|
+
attachShadow: true,
|
443
|
+
shadowRootOptions: {
|
444
|
+
mode: "closed",
|
445
|
+
delegatesFocus: false,
|
446
|
+
clonable: false,
|
447
|
+
serializable: false,
|
448
|
+
slotAssignment: "named"
|
5
449
|
}
|
6
|
-
};
|
7
|
-
var parseFragment = (htmlStr) => {
|
8
|
-
const range = document.createRange();
|
9
|
-
range.selectNode(document.body);
|
10
|
-
return range.createContextualFragment(htmlStr);
|
11
|
-
};
|
12
|
-
var setInnerHTML = (element, html3) => {
|
13
|
-
clearHTML(element);
|
14
|
-
const fragment = typeof html3 === "string" ? parseFragment(html3) : html3;
|
15
|
-
element.append(fragment);
|
16
450
|
};
|
17
451
|
|
18
452
|
// src/signals.ts
|
@@ -26,8 +460,8 @@ var createSignal = (initVal, options) => {
|
|
26
460
|
if (subscriber !== null) {
|
27
461
|
subscribers.add(subscriber);
|
28
462
|
}
|
29
|
-
if (options?.debugMode || getterOptions?.debugMode) {
|
30
|
-
|
463
|
+
if (options?.debugMode === true || getterOptions?.debugMode === true) {
|
464
|
+
queueMicrotask(() => {
|
31
465
|
let label = "anonymous signal";
|
32
466
|
if (options?.label !== void 0) {
|
33
467
|
label = `(${options.label})`;
|
@@ -52,7 +486,7 @@ var createSignal = (initVal, options) => {
|
|
52
486
|
}
|
53
487
|
if (!isBatchingUpdates) {
|
54
488
|
isBatchingUpdates = true;
|
55
|
-
|
489
|
+
queueMicrotask(() => {
|
56
490
|
for (const fn of updateQueue) {
|
57
491
|
try {
|
58
492
|
fn();
|
@@ -60,7 +494,7 @@ var createSignal = (initVal, options) => {
|
|
60
494
|
console.error("Error in subscriber:", { error, oldValue, newValue, fn });
|
61
495
|
}
|
62
496
|
}
|
63
|
-
if (options?.debugMode || setterOptions?.debugMode) {
|
497
|
+
if (options?.debugMode === true || setterOptions?.debugMode === true) {
|
64
498
|
let label = "anonymous signal";
|
65
499
|
if (options?.label !== void 0) {
|
66
500
|
label = `(${options.label})`;
|
@@ -100,973 +534,150 @@ var createEffect = (fn) => {
|
|
100
534
|
subscriber = null;
|
101
535
|
};
|
102
536
|
|
103
|
-
//
|
104
|
-
var
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
var {
|
117
|
-
apply,
|
118
|
-
construct
|
119
|
-
} = typeof Reflect !== "undefined" && Reflect;
|
120
|
-
if (!freeze) {
|
121
|
-
freeze = function freeze2(x) {
|
122
|
-
return x;
|
123
|
-
};
|
124
|
-
}
|
125
|
-
if (!seal) {
|
126
|
-
seal = function seal2(x) {
|
127
|
-
return x;
|
128
|
-
};
|
129
|
-
}
|
130
|
-
if (!apply) {
|
131
|
-
apply = function apply2(fun, thisValue, args) {
|
132
|
-
return fun.apply(thisValue, args);
|
133
|
-
};
|
134
|
-
}
|
135
|
-
if (!construct) {
|
136
|
-
construct = function construct2(Func, args) {
|
137
|
-
return new Func(...args);
|
138
|
-
};
|
139
|
-
}
|
140
|
-
var arrayForEach = unapply(Array.prototype.forEach);
|
141
|
-
var arrayPop = unapply(Array.prototype.pop);
|
142
|
-
var arrayPush = unapply(Array.prototype.push);
|
143
|
-
var stringToLowerCase = unapply(String.prototype.toLowerCase);
|
144
|
-
var stringToString = unapply(String.prototype.toString);
|
145
|
-
var stringMatch = unapply(String.prototype.match);
|
146
|
-
var stringReplace = unapply(String.prototype.replace);
|
147
|
-
var stringIndexOf = unapply(String.prototype.indexOf);
|
148
|
-
var stringTrim = unapply(String.prototype.trim);
|
149
|
-
var objectHasOwnProperty = unapply(Object.prototype.hasOwnProperty);
|
150
|
-
var regExpTest = unapply(RegExp.prototype.test);
|
151
|
-
var typeErrorCreate = unconstruct(TypeError);
|
152
|
-
function unapply(func) {
|
153
|
-
return function(thisArg) {
|
154
|
-
for (var _len = arguments.length, args = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
|
155
|
-
args[_key - 1] = arguments[_key];
|
156
|
-
}
|
157
|
-
return apply(func, thisArg, args);
|
158
|
-
};
|
159
|
-
}
|
160
|
-
function unconstruct(func) {
|
161
|
-
return function() {
|
162
|
-
for (var _len2 = arguments.length, args = new Array(_len2), _key2 = 0; _key2 < _len2; _key2++) {
|
163
|
-
args[_key2] = arguments[_key2];
|
164
|
-
}
|
165
|
-
return construct(func, args);
|
166
|
-
};
|
167
|
-
}
|
168
|
-
function addToSet(set, array) {
|
169
|
-
let transformCaseFunc = arguments.length > 2 && arguments[2] !== void 0 ? arguments[2] : stringToLowerCase;
|
170
|
-
if (setPrototypeOf) {
|
171
|
-
setPrototypeOf(set, null);
|
172
|
-
}
|
173
|
-
let l = array.length;
|
174
|
-
while (l--) {
|
175
|
-
let element = array[l];
|
176
|
-
if (typeof element === "string") {
|
177
|
-
const lcElement = transformCaseFunc(element);
|
178
|
-
if (lcElement !== element) {
|
179
|
-
if (!isFrozen(array)) {
|
180
|
-
array[l] = lcElement;
|
181
|
-
}
|
182
|
-
element = lcElement;
|
183
|
-
}
|
184
|
-
}
|
185
|
-
set[element] = true;
|
186
|
-
}
|
187
|
-
return set;
|
188
|
-
}
|
189
|
-
function cleanArray(array) {
|
190
|
-
for (let index = 0; index < array.length; index++) {
|
191
|
-
const isPropertyExist = objectHasOwnProperty(array, index);
|
192
|
-
if (!isPropertyExist) {
|
193
|
-
array[index] = null;
|
194
|
-
}
|
195
|
-
}
|
196
|
-
return array;
|
197
|
-
}
|
198
|
-
function clone(object) {
|
199
|
-
const newObject = create(null);
|
200
|
-
for (const [property, value] of entries(object)) {
|
201
|
-
const isPropertyExist = objectHasOwnProperty(object, property);
|
202
|
-
if (isPropertyExist) {
|
203
|
-
if (Array.isArray(value)) {
|
204
|
-
newObject[property] = cleanArray(value);
|
205
|
-
} else if (value && typeof value === "object" && value.constructor === Object) {
|
206
|
-
newObject[property] = clone(value);
|
207
|
-
} else {
|
208
|
-
newObject[property] = value;
|
209
|
-
}
|
210
|
-
}
|
537
|
+
// src/utilities.ts
|
538
|
+
var NOOP = () => void 0;
|
539
|
+
|
540
|
+
// src/server-side.ts
|
541
|
+
var isServer = typeof window === "undefined";
|
542
|
+
var serverDefineFns = /* @__PURE__ */ new Set();
|
543
|
+
var onServerDefine = (fn) => {
|
544
|
+
serverDefineFns.add(fn);
|
545
|
+
};
|
546
|
+
var serverDefine = ({ tagName, serverRender, options, scopedRegistry, parentRegistry }) => {
|
547
|
+
if (parentRegistry !== void 0) {
|
548
|
+
parentRegistry.__serverRenderOpts.set(tagName, { serverRender, ...options });
|
549
|
+
if (parentRegistry.scoped) return;
|
211
550
|
}
|
212
|
-
|
213
|
-
|
214
|
-
|
215
|
-
|
216
|
-
|
217
|
-
|
218
|
-
|
219
|
-
|
220
|
-
|
221
|
-
|
222
|
-
|
551
|
+
for (const fn of serverDefineFns) {
|
552
|
+
let result = serverRender(getServerRenderArgs(tagName));
|
553
|
+
result = wrapTemplate({
|
554
|
+
tagName,
|
555
|
+
serverRender,
|
556
|
+
options
|
557
|
+
});
|
558
|
+
if (scopedRegistry !== void 0) {
|
559
|
+
for (const [scopedTagName, scopedRenderOptions] of scopedRegistry.__serverRenderOpts) {
|
560
|
+
const { serverRender: serverRender2, ...scopedOptions } = scopedRenderOptions;
|
561
|
+
let template = serverRender2(getServerRenderArgs(scopedTagName, scopedRegistry));
|
562
|
+
template = wrapTemplate({
|
563
|
+
tagName: scopedTagName,
|
564
|
+
serverRender: serverRender2,
|
565
|
+
options: scopedOptions
|
566
|
+
});
|
567
|
+
result = insertTemplates(scopedTagName, template, result);
|
223
568
|
}
|
224
569
|
}
|
225
|
-
|
226
|
-
}
|
227
|
-
function fallbackValue() {
|
228
|
-
return null;
|
570
|
+
fn(tagName, result);
|
229
571
|
}
|
230
|
-
return fallbackValue;
|
231
|
-
}
|
232
|
-
var html$1 = freeze(["a", "abbr", "acronym", "address", "area", "article", "aside", "audio", "b", "bdi", "bdo", "big", "blink", "blockquote", "body", "br", "button", "canvas", "caption", "center", "cite", "code", "col", "colgroup", "content", "data", "datalist", "dd", "decorator", "del", "details", "dfn", "dialog", "dir", "div", "dl", "dt", "element", "em", "fieldset", "figcaption", "figure", "font", "footer", "form", "h1", "h2", "h3", "h4", "h5", "h6", "head", "header", "hgroup", "hr", "html", "i", "img", "input", "ins", "kbd", "label", "legend", "li", "main", "map", "mark", "marquee", "menu", "menuitem", "meter", "nav", "nobr", "ol", "optgroup", "option", "output", "p", "picture", "pre", "progress", "q", "rp", "rt", "ruby", "s", "samp", "section", "select", "shadow", "small", "source", "spacer", "span", "strike", "strong", "style", "sub", "summary", "sup", "table", "tbody", "td", "template", "textarea", "tfoot", "th", "thead", "time", "tr", "track", "tt", "u", "ul", "var", "video", "wbr"]);
|
233
|
-
var svg$1 = freeze(["svg", "a", "altglyph", "altglyphdef", "altglyphitem", "animatecolor", "animatemotion", "animatetransform", "circle", "clippath", "defs", "desc", "ellipse", "filter", "font", "g", "glyph", "glyphref", "hkern", "image", "line", "lineargradient", "marker", "mask", "metadata", "mpath", "path", "pattern", "polygon", "polyline", "radialgradient", "rect", "stop", "style", "switch", "symbol", "text", "textpath", "title", "tref", "tspan", "view", "vkern"]);
|
234
|
-
var svgFilters = freeze(["feBlend", "feColorMatrix", "feComponentTransfer", "feComposite", "feConvolveMatrix", "feDiffuseLighting", "feDisplacementMap", "feDistantLight", "feDropShadow", "feFlood", "feFuncA", "feFuncB", "feFuncG", "feFuncR", "feGaussianBlur", "feImage", "feMerge", "feMergeNode", "feMorphology", "feOffset", "fePointLight", "feSpecularLighting", "feSpotLight", "feTile", "feTurbulence"]);
|
235
|
-
var svgDisallowed = freeze(["animate", "color-profile", "cursor", "discard", "font-face", "font-face-format", "font-face-name", "font-face-src", "font-face-uri", "foreignobject", "hatch", "hatchpath", "mesh", "meshgradient", "meshpatch", "meshrow", "missing-glyph", "script", "set", "solidcolor", "unknown", "use"]);
|
236
|
-
var mathMl$1 = freeze(["math", "menclose", "merror", "mfenced", "mfrac", "mglyph", "mi", "mlabeledtr", "mmultiscripts", "mn", "mo", "mover", "mpadded", "mphantom", "mroot", "mrow", "ms", "mspace", "msqrt", "mstyle", "msub", "msup", "msubsup", "mtable", "mtd", "mtext", "mtr", "munder", "munderover", "mprescripts"]);
|
237
|
-
var mathMlDisallowed = freeze(["maction", "maligngroup", "malignmark", "mlongdiv", "mscarries", "mscarry", "msgroup", "mstack", "msline", "msrow", "semantics", "annotation", "annotation-xml", "mprescripts", "none"]);
|
238
|
-
var text = freeze(["#text"]);
|
239
|
-
var html = freeze(["accept", "action", "align", "alt", "autocapitalize", "autocomplete", "autopictureinpicture", "autoplay", "background", "bgcolor", "border", "capture", "cellpadding", "cellspacing", "checked", "cite", "class", "clear", "color", "cols", "colspan", "controls", "controlslist", "coords", "crossorigin", "datetime", "decoding", "default", "dir", "disabled", "disablepictureinpicture", "disableremoteplayback", "download", "draggable", "enctype", "enterkeyhint", "face", "for", "headers", "height", "hidden", "high", "href", "hreflang", "id", "inputmode", "integrity", "ismap", "kind", "label", "lang", "list", "loading", "loop", "low", "max", "maxlength", "media", "method", "min", "minlength", "multiple", "muted", "name", "nonce", "noshade", "novalidate", "nowrap", "open", "optimum", "pattern", "placeholder", "playsinline", "popover", "popovertarget", "popovertargetaction", "poster", "preload", "pubdate", "radiogroup", "readonly", "rel", "required", "rev", "reversed", "role", "rows", "rowspan", "spellcheck", "scope", "selected", "shape", "size", "sizes", "span", "srclang", "start", "src", "srcset", "step", "style", "summary", "tabindex", "title", "translate", "type", "usemap", "valign", "value", "width", "wrap", "xmlns", "slot"]);
|
240
|
-
var svg = freeze(["accent-height", "accumulate", "additive", "alignment-baseline", "amplitude", "ascent", "attributename", "attributetype", "azimuth", "basefrequency", "baseline-shift", "begin", "bias", "by", "class", "clip", "clippathunits", "clip-path", "clip-rule", "color", "color-interpolation", "color-interpolation-filters", "color-profile", "color-rendering", "cx", "cy", "d", "dx", "dy", "diffuseconstant", "direction", "display", "divisor", "dur", "edgemode", "elevation", "end", "exponent", "fill", "fill-opacity", "fill-rule", "filter", "filterunits", "flood-color", "flood-opacity", "font-family", "font-size", "font-size-adjust", "font-stretch", "font-style", "font-variant", "font-weight", "fx", "fy", "g1", "g2", "glyph-name", "glyphref", "gradientunits", "gradienttransform", "height", "href", "id", "image-rendering", "in", "in2", "intercept", "k", "k1", "k2", "k3", "k4", "kerning", "keypoints", "keysplines", "keytimes", "lang", "lengthadjust", "letter-spacing", "kernelmatrix", "kernelunitlength", "lighting-color", "local", "marker-end", "marker-mid", "marker-start", "markerheight", "markerunits", "markerwidth", "maskcontentunits", "maskunits", "max", "mask", "media", "method", "mode", "min", "name", "numoctaves", "offset", "operator", "opacity", "order", "orient", "orientation", "origin", "overflow", "paint-order", "path", "pathlength", "patterncontentunits", "patterntransform", "patternunits", "points", "preservealpha", "preserveaspectratio", "primitiveunits", "r", "rx", "ry", "radius", "refx", "refy", "repeatcount", "repeatdur", "restart", "result", "rotate", "scale", "seed", "shape-rendering", "slope", "specularconstant", "specularexponent", "spreadmethod", "startoffset", "stddeviation", "stitchtiles", "stop-color", "stop-opacity", "stroke-dasharray", "stroke-dashoffset", "stroke-linecap", "stroke-linejoin", "stroke-miterlimit", "stroke-opacity", "stroke", "stroke-width", "style", "surfacescale", "systemlanguage", "tabindex", "tablevalues", "targetx", "targety", "transform", "transform-origin", "text-anchor", "text-decoration", "text-rendering", "textlength", "type", "u1", "u2", "unicode", "values", "viewbox", "visibility", "version", "vert-adv-y", "vert-origin-x", "vert-origin-y", "width", "word-spacing", "wrap", "writing-mode", "xchannelselector", "ychannelselector", "x", "x1", "x2", "xmlns", "y", "y1", "y2", "z", "zoomandpan"]);
|
241
|
-
var mathMl = freeze(["accent", "accentunder", "align", "bevelled", "close", "columnsalign", "columnlines", "columnspan", "denomalign", "depth", "dir", "display", "displaystyle", "encoding", "fence", "frame", "height", "href", "id", "largeop", "length", "linethickness", "lspace", "lquote", "mathbackground", "mathcolor", "mathsize", "mathvariant", "maxsize", "minsize", "movablelimits", "notation", "numalign", "open", "rowalign", "rowlines", "rowspacing", "rowspan", "rspace", "rquote", "scriptlevel", "scriptminsize", "scriptsizemultiplier", "selection", "separator", "separators", "stretchy", "subscriptshift", "supscriptshift", "symmetric", "voffset", "width", "xmlns"]);
|
242
|
-
var xml = freeze(["xlink:href", "xml:id", "xlink:title", "xml:space", "xmlns:xlink"]);
|
243
|
-
var MUSTACHE_EXPR = seal(/\{\{[\w\W]*|[\w\W]*\}\}/gm);
|
244
|
-
var ERB_EXPR = seal(/<%[\w\W]*|[\w\W]*%>/gm);
|
245
|
-
var TMPLIT_EXPR = seal(/\${[\w\W]*}/gm);
|
246
|
-
var DATA_ATTR = seal(/^data-[\-\w.\u00B7-\uFFFF]/);
|
247
|
-
var ARIA_ATTR = seal(/^aria-[\-\w]+$/);
|
248
|
-
var IS_ALLOWED_URI = seal(
|
249
|
-
/^(?:(?:(?:f|ht)tps?|mailto|tel|callto|sms|cid|xmpp):|[^a-z]|[a-z+.\-]+(?:[^a-z+.\-:]|$))/i
|
250
|
-
// eslint-disable-line no-useless-escape
|
251
|
-
);
|
252
|
-
var IS_SCRIPT_OR_DATA = seal(/^(?:\w+script|data):/i);
|
253
|
-
var ATTR_WHITESPACE = seal(
|
254
|
-
/[\u0000-\u0020\u00A0\u1680\u180E\u2000-\u2029\u205F\u3000]/g
|
255
|
-
// eslint-disable-line no-control-regex
|
256
|
-
);
|
257
|
-
var DOCTYPE_NAME = seal(/^html$/i);
|
258
|
-
var CUSTOM_ELEMENT = seal(/^[a-z][.\w]*(-[.\w]+)+$/i);
|
259
|
-
var EXPRESSIONS = /* @__PURE__ */ Object.freeze({
|
260
|
-
__proto__: null,
|
261
|
-
ARIA_ATTR,
|
262
|
-
ATTR_WHITESPACE,
|
263
|
-
CUSTOM_ELEMENT,
|
264
|
-
DATA_ATTR,
|
265
|
-
DOCTYPE_NAME,
|
266
|
-
ERB_EXPR,
|
267
|
-
IS_ALLOWED_URI,
|
268
|
-
IS_SCRIPT_OR_DATA,
|
269
|
-
MUSTACHE_EXPR,
|
270
|
-
TMPLIT_EXPR
|
271
|
-
});
|
272
|
-
var NODE_TYPE = {
|
273
|
-
element: 1,
|
274
|
-
attribute: 2,
|
275
|
-
text: 3,
|
276
|
-
cdataSection: 4,
|
277
|
-
entityReference: 5,
|
278
|
-
// Deprecated
|
279
|
-
entityNode: 6,
|
280
|
-
// Deprecated
|
281
|
-
progressingInstruction: 7,
|
282
|
-
comment: 8,
|
283
|
-
document: 9,
|
284
|
-
documentType: 10,
|
285
|
-
documentFragment: 11,
|
286
|
-
notation: 12
|
287
|
-
// Deprecated
|
288
572
|
};
|
289
|
-
var
|
290
|
-
|
291
|
-
|
292
|
-
|
293
|
-
|
294
|
-
|
295
|
-
}
|
296
|
-
let suffix = null;
|
297
|
-
const ATTR_NAME = "data-tt-policy-suffix";
|
298
|
-
if (purifyHostElement && purifyHostElement.hasAttribute(ATTR_NAME)) {
|
299
|
-
suffix = purifyHostElement.getAttribute(ATTR_NAME);
|
300
|
-
}
|
301
|
-
const policyName = "dompurify" + (suffix ? "#" + suffix : "");
|
302
|
-
try {
|
303
|
-
return trustedTypes.createPolicy(policyName, {
|
304
|
-
createHTML(html3) {
|
305
|
-
return html3;
|
306
|
-
},
|
307
|
-
createScriptURL(scriptUrl) {
|
308
|
-
return scriptUrl;
|
573
|
+
var serverCss = /* @__PURE__ */ new Map();
|
574
|
+
var getServerRenderArgs = (tagName, registry) => ({
|
575
|
+
get elementRef() {
|
576
|
+
return new Proxy({}, {
|
577
|
+
get: () => {
|
578
|
+
throw new Error("The `elementRef` property is not available on the server.");
|
309
579
|
}
|
310
580
|
});
|
311
|
-
}
|
312
|
-
|
313
|
-
return
|
314
|
-
|
315
|
-
|
316
|
-
function createDOMPurify() {
|
317
|
-
let window2 = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : getGlobal();
|
318
|
-
const DOMPurify = (root) => createDOMPurify(root);
|
319
|
-
DOMPurify.version = "3.2.1";
|
320
|
-
DOMPurify.removed = [];
|
321
|
-
if (!window2 || !window2.document || window2.document.nodeType !== NODE_TYPE.document) {
|
322
|
-
DOMPurify.isSupported = false;
|
323
|
-
return DOMPurify;
|
324
|
-
}
|
325
|
-
let {
|
326
|
-
document: document2
|
327
|
-
} = window2;
|
328
|
-
const originalDocument = document2;
|
329
|
-
const currentScript = originalDocument.currentScript;
|
330
|
-
const {
|
331
|
-
DocumentFragment: DocumentFragment2,
|
332
|
-
HTMLTemplateElement,
|
333
|
-
Node,
|
334
|
-
Element: Element2,
|
335
|
-
NodeFilter,
|
336
|
-
NamedNodeMap = window2.NamedNodeMap || window2.MozNamedAttrMap,
|
337
|
-
HTMLFormElement,
|
338
|
-
DOMParser,
|
339
|
-
trustedTypes
|
340
|
-
} = window2;
|
341
|
-
const ElementPrototype = Element2.prototype;
|
342
|
-
const cloneNode = lookupGetter(ElementPrototype, "cloneNode");
|
343
|
-
const remove = lookupGetter(ElementPrototype, "remove");
|
344
|
-
const getNextSibling = lookupGetter(ElementPrototype, "nextSibling");
|
345
|
-
const getChildNodes = lookupGetter(ElementPrototype, "childNodes");
|
346
|
-
const getParentNode = lookupGetter(ElementPrototype, "parentNode");
|
347
|
-
if (typeof HTMLTemplateElement === "function") {
|
348
|
-
const template = document2.createElement("template");
|
349
|
-
if (template.content && template.content.ownerDocument) {
|
350
|
-
document2 = template.content.ownerDocument;
|
351
|
-
}
|
352
|
-
}
|
353
|
-
let trustedTypesPolicy;
|
354
|
-
let emptyHTML = "";
|
355
|
-
const {
|
356
|
-
implementation,
|
357
|
-
createNodeIterator,
|
358
|
-
createDocumentFragment,
|
359
|
-
getElementsByTagName
|
360
|
-
} = document2;
|
361
|
-
const {
|
362
|
-
importNode
|
363
|
-
} = originalDocument;
|
364
|
-
let hooks = {};
|
365
|
-
DOMPurify.isSupported = typeof entries === "function" && typeof getParentNode === "function" && implementation && implementation.createHTMLDocument !== void 0;
|
366
|
-
const {
|
367
|
-
MUSTACHE_EXPR: MUSTACHE_EXPR2,
|
368
|
-
ERB_EXPR: ERB_EXPR2,
|
369
|
-
TMPLIT_EXPR: TMPLIT_EXPR2,
|
370
|
-
DATA_ATTR: DATA_ATTR2,
|
371
|
-
ARIA_ATTR: ARIA_ATTR2,
|
372
|
-
IS_SCRIPT_OR_DATA: IS_SCRIPT_OR_DATA2,
|
373
|
-
ATTR_WHITESPACE: ATTR_WHITESPACE2,
|
374
|
-
CUSTOM_ELEMENT: CUSTOM_ELEMENT2
|
375
|
-
} = EXPRESSIONS;
|
376
|
-
let {
|
377
|
-
IS_ALLOWED_URI: IS_ALLOWED_URI$1
|
378
|
-
} = EXPRESSIONS;
|
379
|
-
let ALLOWED_TAGS = null;
|
380
|
-
const DEFAULT_ALLOWED_TAGS = addToSet({}, [...html$1, ...svg$1, ...svgFilters, ...mathMl$1, ...text]);
|
381
|
-
let ALLOWED_ATTR = null;
|
382
|
-
const DEFAULT_ALLOWED_ATTR = addToSet({}, [...html, ...svg, ...mathMl, ...xml]);
|
383
|
-
let CUSTOM_ELEMENT_HANDLING = Object.seal(create(null, {
|
384
|
-
tagNameCheck: {
|
385
|
-
writable: true,
|
386
|
-
configurable: false,
|
387
|
-
enumerable: true,
|
388
|
-
value: null
|
389
|
-
},
|
390
|
-
attributeNameCheck: {
|
391
|
-
writable: true,
|
392
|
-
configurable: false,
|
393
|
-
enumerable: true,
|
394
|
-
value: null
|
395
|
-
},
|
396
|
-
allowCustomizedBuiltInElements: {
|
397
|
-
writable: true,
|
398
|
-
configurable: false,
|
399
|
-
enumerable: true,
|
400
|
-
value: false
|
401
|
-
}
|
402
|
-
}));
|
403
|
-
let FORBID_TAGS = null;
|
404
|
-
let FORBID_ATTR = null;
|
405
|
-
let ALLOW_ARIA_ATTR = true;
|
406
|
-
let ALLOW_DATA_ATTR = true;
|
407
|
-
let ALLOW_UNKNOWN_PROTOCOLS = false;
|
408
|
-
let ALLOW_SELF_CLOSE_IN_ATTR = true;
|
409
|
-
let SAFE_FOR_TEMPLATES = false;
|
410
|
-
let SAFE_FOR_XML = true;
|
411
|
-
let WHOLE_DOCUMENT = false;
|
412
|
-
let SET_CONFIG = false;
|
413
|
-
let FORCE_BODY = false;
|
414
|
-
let RETURN_DOM = false;
|
415
|
-
let RETURN_DOM_FRAGMENT = false;
|
416
|
-
let RETURN_TRUSTED_TYPE = false;
|
417
|
-
let SANITIZE_DOM = true;
|
418
|
-
let SANITIZE_NAMED_PROPS = false;
|
419
|
-
const SANITIZE_NAMED_PROPS_PREFIX = "user-content-";
|
420
|
-
let KEEP_CONTENT = true;
|
421
|
-
let IN_PLACE = false;
|
422
|
-
let USE_PROFILES = {};
|
423
|
-
let FORBID_CONTENTS = null;
|
424
|
-
const DEFAULT_FORBID_CONTENTS = addToSet({}, ["annotation-xml", "audio", "colgroup", "desc", "foreignobject", "head", "iframe", "math", "mi", "mn", "mo", "ms", "mtext", "noembed", "noframes", "noscript", "plaintext", "script", "style", "svg", "template", "thead", "title", "video", "xmp"]);
|
425
|
-
let DATA_URI_TAGS = null;
|
426
|
-
const DEFAULT_DATA_URI_TAGS = addToSet({}, ["audio", "video", "img", "source", "image", "track"]);
|
427
|
-
let URI_SAFE_ATTRIBUTES = null;
|
428
|
-
const DEFAULT_URI_SAFE_ATTRIBUTES = addToSet({}, ["alt", "class", "for", "id", "label", "name", "pattern", "placeholder", "role", "summary", "title", "value", "style", "xmlns"]);
|
429
|
-
const MATHML_NAMESPACE = "http://www.w3.org/1998/Math/MathML";
|
430
|
-
const SVG_NAMESPACE = "http://www.w3.org/2000/svg";
|
431
|
-
const HTML_NAMESPACE = "http://www.w3.org/1999/xhtml";
|
432
|
-
let NAMESPACE = HTML_NAMESPACE;
|
433
|
-
let IS_EMPTY_INPUT = false;
|
434
|
-
let ALLOWED_NAMESPACES = null;
|
435
|
-
const DEFAULT_ALLOWED_NAMESPACES = addToSet({}, [MATHML_NAMESPACE, SVG_NAMESPACE, HTML_NAMESPACE], stringToString);
|
436
|
-
let MATHML_TEXT_INTEGRATION_POINTS = addToSet({}, ["mi", "mo", "mn", "ms", "mtext"]);
|
437
|
-
let HTML_INTEGRATION_POINTS = addToSet({}, ["annotation-xml"]);
|
438
|
-
const COMMON_SVG_AND_HTML_ELEMENTS = addToSet({}, ["title", "style", "font", "a", "script"]);
|
439
|
-
let PARSER_MEDIA_TYPE = null;
|
440
|
-
const SUPPORTED_PARSER_MEDIA_TYPES = ["application/xhtml+xml", "text/html"];
|
441
|
-
const DEFAULT_PARSER_MEDIA_TYPE = "text/html";
|
442
|
-
let transformCaseFunc = null;
|
443
|
-
let CONFIG = null;
|
444
|
-
const formElement = document2.createElement("form");
|
445
|
-
const isRegexOrFunction = function isRegexOrFunction2(testValue) {
|
446
|
-
return testValue instanceof RegExp || testValue instanceof Function;
|
447
|
-
};
|
448
|
-
const _parseConfig = function _parseConfig2() {
|
449
|
-
let cfg = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : {};
|
450
|
-
if (CONFIG && CONFIG === cfg) {
|
451
|
-
return;
|
452
|
-
}
|
453
|
-
if (!cfg || typeof cfg !== "object") {
|
454
|
-
cfg = {};
|
455
|
-
}
|
456
|
-
cfg = clone(cfg);
|
457
|
-
PARSER_MEDIA_TYPE = // eslint-disable-next-line unicorn/prefer-includes
|
458
|
-
SUPPORTED_PARSER_MEDIA_TYPES.indexOf(cfg.PARSER_MEDIA_TYPE) === -1 ? DEFAULT_PARSER_MEDIA_TYPE : cfg.PARSER_MEDIA_TYPE;
|
459
|
-
transformCaseFunc = PARSER_MEDIA_TYPE === "application/xhtml+xml" ? stringToString : stringToLowerCase;
|
460
|
-
ALLOWED_TAGS = objectHasOwnProperty(cfg, "ALLOWED_TAGS") ? addToSet({}, cfg.ALLOWED_TAGS, transformCaseFunc) : DEFAULT_ALLOWED_TAGS;
|
461
|
-
ALLOWED_ATTR = objectHasOwnProperty(cfg, "ALLOWED_ATTR") ? addToSet({}, cfg.ALLOWED_ATTR, transformCaseFunc) : DEFAULT_ALLOWED_ATTR;
|
462
|
-
ALLOWED_NAMESPACES = objectHasOwnProperty(cfg, "ALLOWED_NAMESPACES") ? addToSet({}, cfg.ALLOWED_NAMESPACES, stringToString) : DEFAULT_ALLOWED_NAMESPACES;
|
463
|
-
URI_SAFE_ATTRIBUTES = objectHasOwnProperty(cfg, "ADD_URI_SAFE_ATTR") ? addToSet(clone(DEFAULT_URI_SAFE_ATTRIBUTES), cfg.ADD_URI_SAFE_ATTR, transformCaseFunc) : DEFAULT_URI_SAFE_ATTRIBUTES;
|
464
|
-
DATA_URI_TAGS = objectHasOwnProperty(cfg, "ADD_DATA_URI_TAGS") ? addToSet(clone(DEFAULT_DATA_URI_TAGS), cfg.ADD_DATA_URI_TAGS, transformCaseFunc) : DEFAULT_DATA_URI_TAGS;
|
465
|
-
FORBID_CONTENTS = objectHasOwnProperty(cfg, "FORBID_CONTENTS") ? addToSet({}, cfg.FORBID_CONTENTS, transformCaseFunc) : DEFAULT_FORBID_CONTENTS;
|
466
|
-
FORBID_TAGS = objectHasOwnProperty(cfg, "FORBID_TAGS") ? addToSet({}, cfg.FORBID_TAGS, transformCaseFunc) : {};
|
467
|
-
FORBID_ATTR = objectHasOwnProperty(cfg, "FORBID_ATTR") ? addToSet({}, cfg.FORBID_ATTR, transformCaseFunc) : {};
|
468
|
-
USE_PROFILES = objectHasOwnProperty(cfg, "USE_PROFILES") ? cfg.USE_PROFILES : false;
|
469
|
-
ALLOW_ARIA_ATTR = cfg.ALLOW_ARIA_ATTR !== false;
|
470
|
-
ALLOW_DATA_ATTR = cfg.ALLOW_DATA_ATTR !== false;
|
471
|
-
ALLOW_UNKNOWN_PROTOCOLS = cfg.ALLOW_UNKNOWN_PROTOCOLS || false;
|
472
|
-
ALLOW_SELF_CLOSE_IN_ATTR = cfg.ALLOW_SELF_CLOSE_IN_ATTR !== false;
|
473
|
-
SAFE_FOR_TEMPLATES = cfg.SAFE_FOR_TEMPLATES || false;
|
474
|
-
SAFE_FOR_XML = cfg.SAFE_FOR_XML !== false;
|
475
|
-
WHOLE_DOCUMENT = cfg.WHOLE_DOCUMENT || false;
|
476
|
-
RETURN_DOM = cfg.RETURN_DOM || false;
|
477
|
-
RETURN_DOM_FRAGMENT = cfg.RETURN_DOM_FRAGMENT || false;
|
478
|
-
RETURN_TRUSTED_TYPE = cfg.RETURN_TRUSTED_TYPE || false;
|
479
|
-
FORCE_BODY = cfg.FORCE_BODY || false;
|
480
|
-
SANITIZE_DOM = cfg.SANITIZE_DOM !== false;
|
481
|
-
SANITIZE_NAMED_PROPS = cfg.SANITIZE_NAMED_PROPS || false;
|
482
|
-
KEEP_CONTENT = cfg.KEEP_CONTENT !== false;
|
483
|
-
IN_PLACE = cfg.IN_PLACE || false;
|
484
|
-
IS_ALLOWED_URI$1 = cfg.ALLOWED_URI_REGEXP || IS_ALLOWED_URI;
|
485
|
-
NAMESPACE = cfg.NAMESPACE || HTML_NAMESPACE;
|
486
|
-
MATHML_TEXT_INTEGRATION_POINTS = cfg.MATHML_TEXT_INTEGRATION_POINTS || MATHML_TEXT_INTEGRATION_POINTS;
|
487
|
-
HTML_INTEGRATION_POINTS = cfg.HTML_INTEGRATION_POINTS || HTML_INTEGRATION_POINTS;
|
488
|
-
CUSTOM_ELEMENT_HANDLING = cfg.CUSTOM_ELEMENT_HANDLING || {};
|
489
|
-
if (cfg.CUSTOM_ELEMENT_HANDLING && isRegexOrFunction(cfg.CUSTOM_ELEMENT_HANDLING.tagNameCheck)) {
|
490
|
-
CUSTOM_ELEMENT_HANDLING.tagNameCheck = cfg.CUSTOM_ELEMENT_HANDLING.tagNameCheck;
|
491
|
-
}
|
492
|
-
if (cfg.CUSTOM_ELEMENT_HANDLING && isRegexOrFunction(cfg.CUSTOM_ELEMENT_HANDLING.attributeNameCheck)) {
|
493
|
-
CUSTOM_ELEMENT_HANDLING.attributeNameCheck = cfg.CUSTOM_ELEMENT_HANDLING.attributeNameCheck;
|
494
|
-
}
|
495
|
-
if (cfg.CUSTOM_ELEMENT_HANDLING && typeof cfg.CUSTOM_ELEMENT_HANDLING.allowCustomizedBuiltInElements === "boolean") {
|
496
|
-
CUSTOM_ELEMENT_HANDLING.allowCustomizedBuiltInElements = cfg.CUSTOM_ELEMENT_HANDLING.allowCustomizedBuiltInElements;
|
497
|
-
}
|
498
|
-
if (SAFE_FOR_TEMPLATES) {
|
499
|
-
ALLOW_DATA_ATTR = false;
|
500
|
-
}
|
501
|
-
if (RETURN_DOM_FRAGMENT) {
|
502
|
-
RETURN_DOM = true;
|
503
|
-
}
|
504
|
-
if (USE_PROFILES) {
|
505
|
-
ALLOWED_TAGS = addToSet({}, text);
|
506
|
-
ALLOWED_ATTR = [];
|
507
|
-
if (USE_PROFILES.html === true) {
|
508
|
-
addToSet(ALLOWED_TAGS, html$1);
|
509
|
-
addToSet(ALLOWED_ATTR, html);
|
510
|
-
}
|
511
|
-
if (USE_PROFILES.svg === true) {
|
512
|
-
addToSet(ALLOWED_TAGS, svg$1);
|
513
|
-
addToSet(ALLOWED_ATTR, svg);
|
514
|
-
addToSet(ALLOWED_ATTR, xml);
|
515
|
-
}
|
516
|
-
if (USE_PROFILES.svgFilters === true) {
|
517
|
-
addToSet(ALLOWED_TAGS, svgFilters);
|
518
|
-
addToSet(ALLOWED_ATTR, svg);
|
519
|
-
addToSet(ALLOWED_ATTR, xml);
|
581
|
+
},
|
582
|
+
get root() {
|
583
|
+
return new Proxy({}, {
|
584
|
+
get: () => {
|
585
|
+
throw new Error("The `root` property is not available on the server.");
|
520
586
|
}
|
521
|
-
if (USE_PROFILES.mathMl === true) {
|
522
|
-
addToSet(ALLOWED_TAGS, mathMl$1);
|
523
|
-
addToSet(ALLOWED_ATTR, mathMl);
|
524
|
-
addToSet(ALLOWED_ATTR, xml);
|
525
|
-
}
|
526
|
-
}
|
527
|
-
if (cfg.ADD_TAGS) {
|
528
|
-
if (ALLOWED_TAGS === DEFAULT_ALLOWED_TAGS) {
|
529
|
-
ALLOWED_TAGS = clone(ALLOWED_TAGS);
|
530
|
-
}
|
531
|
-
addToSet(ALLOWED_TAGS, cfg.ADD_TAGS, transformCaseFunc);
|
532
|
-
}
|
533
|
-
if (cfg.ADD_ATTR) {
|
534
|
-
if (ALLOWED_ATTR === DEFAULT_ALLOWED_ATTR) {
|
535
|
-
ALLOWED_ATTR = clone(ALLOWED_ATTR);
|
536
|
-
}
|
537
|
-
addToSet(ALLOWED_ATTR, cfg.ADD_ATTR, transformCaseFunc);
|
538
|
-
}
|
539
|
-
if (cfg.ADD_URI_SAFE_ATTR) {
|
540
|
-
addToSet(URI_SAFE_ATTRIBUTES, cfg.ADD_URI_SAFE_ATTR, transformCaseFunc);
|
541
|
-
}
|
542
|
-
if (cfg.FORBID_CONTENTS) {
|
543
|
-
if (FORBID_CONTENTS === DEFAULT_FORBID_CONTENTS) {
|
544
|
-
FORBID_CONTENTS = clone(FORBID_CONTENTS);
|
545
|
-
}
|
546
|
-
addToSet(FORBID_CONTENTS, cfg.FORBID_CONTENTS, transformCaseFunc);
|
547
|
-
}
|
548
|
-
if (KEEP_CONTENT) {
|
549
|
-
ALLOWED_TAGS["#text"] = true;
|
550
|
-
}
|
551
|
-
if (WHOLE_DOCUMENT) {
|
552
|
-
addToSet(ALLOWED_TAGS, ["html", "head", "body"]);
|
553
|
-
}
|
554
|
-
if (ALLOWED_TAGS.table) {
|
555
|
-
addToSet(ALLOWED_TAGS, ["tbody"]);
|
556
|
-
delete FORBID_TAGS.tbody;
|
557
|
-
}
|
558
|
-
if (cfg.TRUSTED_TYPES_POLICY) {
|
559
|
-
if (typeof cfg.TRUSTED_TYPES_POLICY.createHTML !== "function") {
|
560
|
-
throw typeErrorCreate('TRUSTED_TYPES_POLICY configuration option must provide a "createHTML" hook.');
|
561
|
-
}
|
562
|
-
if (typeof cfg.TRUSTED_TYPES_POLICY.createScriptURL !== "function") {
|
563
|
-
throw typeErrorCreate('TRUSTED_TYPES_POLICY configuration option must provide a "createScriptURL" hook.');
|
564
|
-
}
|
565
|
-
trustedTypesPolicy = cfg.TRUSTED_TYPES_POLICY;
|
566
|
-
emptyHTML = trustedTypesPolicy.createHTML("");
|
567
|
-
} else {
|
568
|
-
if (trustedTypesPolicy === void 0) {
|
569
|
-
trustedTypesPolicy = _createTrustedTypesPolicy(trustedTypes, currentScript);
|
570
|
-
}
|
571
|
-
if (trustedTypesPolicy !== null && typeof emptyHTML === "string") {
|
572
|
-
emptyHTML = trustedTypesPolicy.createHTML("");
|
573
|
-
}
|
574
|
-
}
|
575
|
-
if (freeze) {
|
576
|
-
freeze(cfg);
|
577
|
-
}
|
578
|
-
CONFIG = cfg;
|
579
|
-
};
|
580
|
-
const ALL_SVG_TAGS = addToSet({}, [...svg$1, ...svgFilters, ...svgDisallowed]);
|
581
|
-
const ALL_MATHML_TAGS = addToSet({}, [...mathMl$1, ...mathMlDisallowed]);
|
582
|
-
const _checkValidNamespace = function _checkValidNamespace2(element) {
|
583
|
-
let parent = getParentNode(element);
|
584
|
-
if (!parent || !parent.tagName) {
|
585
|
-
parent = {
|
586
|
-
namespaceURI: NAMESPACE,
|
587
|
-
tagName: "template"
|
588
|
-
};
|
589
|
-
}
|
590
|
-
const tagName = stringToLowerCase(element.tagName);
|
591
|
-
const parentTagName = stringToLowerCase(parent.tagName);
|
592
|
-
if (!ALLOWED_NAMESPACES[element.namespaceURI]) {
|
593
|
-
return false;
|
594
|
-
}
|
595
|
-
if (element.namespaceURI === SVG_NAMESPACE) {
|
596
|
-
if (parent.namespaceURI === HTML_NAMESPACE) {
|
597
|
-
return tagName === "svg";
|
598
|
-
}
|
599
|
-
if (parent.namespaceURI === MATHML_NAMESPACE) {
|
600
|
-
return tagName === "svg" && (parentTagName === "annotation-xml" || MATHML_TEXT_INTEGRATION_POINTS[parentTagName]);
|
601
|
-
}
|
602
|
-
return Boolean(ALL_SVG_TAGS[tagName]);
|
603
|
-
}
|
604
|
-
if (element.namespaceURI === MATHML_NAMESPACE) {
|
605
|
-
if (parent.namespaceURI === HTML_NAMESPACE) {
|
606
|
-
return tagName === "math";
|
607
|
-
}
|
608
|
-
if (parent.namespaceURI === SVG_NAMESPACE) {
|
609
|
-
return tagName === "math" && HTML_INTEGRATION_POINTS[parentTagName];
|
610
|
-
}
|
611
|
-
return Boolean(ALL_MATHML_TAGS[tagName]);
|
612
|
-
}
|
613
|
-
if (element.namespaceURI === HTML_NAMESPACE) {
|
614
|
-
if (parent.namespaceURI === SVG_NAMESPACE && !HTML_INTEGRATION_POINTS[parentTagName]) {
|
615
|
-
return false;
|
616
|
-
}
|
617
|
-
if (parent.namespaceURI === MATHML_NAMESPACE && !MATHML_TEXT_INTEGRATION_POINTS[parentTagName]) {
|
618
|
-
return false;
|
619
|
-
}
|
620
|
-
return !ALL_MATHML_TAGS[tagName] && (COMMON_SVG_AND_HTML_ELEMENTS[tagName] || !ALL_SVG_TAGS[tagName]);
|
621
|
-
}
|
622
|
-
if (PARSER_MEDIA_TYPE === "application/xhtml+xml" && ALLOWED_NAMESPACES[element.namespaceURI]) {
|
623
|
-
return true;
|
624
|
-
}
|
625
|
-
return false;
|
626
|
-
};
|
627
|
-
const _forceRemove = function _forceRemove2(node) {
|
628
|
-
arrayPush(DOMPurify.removed, {
|
629
|
-
element: node
|
630
587
|
});
|
631
|
-
|
632
|
-
|
633
|
-
|
634
|
-
|
635
|
-
|
636
|
-
};
|
637
|
-
const _removeAttribute = function _removeAttribute2(name, element) {
|
638
|
-
try {
|
639
|
-
arrayPush(DOMPurify.removed, {
|
640
|
-
attribute: element.getAttributeNode(name),
|
641
|
-
from: element
|
642
|
-
});
|
643
|
-
} catch (_) {
|
644
|
-
arrayPush(DOMPurify.removed, {
|
645
|
-
attribute: null,
|
646
|
-
from: element
|
647
|
-
});
|
648
|
-
}
|
649
|
-
element.removeAttribute(name);
|
650
|
-
if (name === "is" && !ALLOWED_ATTR[name]) {
|
651
|
-
if (RETURN_DOM || RETURN_DOM_FRAGMENT) {
|
652
|
-
try {
|
653
|
-
_forceRemove(element);
|
654
|
-
} catch (_) {
|
655
|
-
}
|
656
|
-
} else {
|
657
|
-
try {
|
658
|
-
element.setAttribute(name, "");
|
659
|
-
} catch (_) {
|
660
|
-
}
|
661
|
-
}
|
662
|
-
}
|
663
|
-
};
|
664
|
-
const _initDocument = function _initDocument2(dirty) {
|
665
|
-
let doc = null;
|
666
|
-
let leadingWhitespace = null;
|
667
|
-
if (FORCE_BODY) {
|
668
|
-
dirty = "<remove></remove>" + dirty;
|
669
|
-
} else {
|
670
|
-
const matches = stringMatch(dirty, /^[\r\n\t ]+/);
|
671
|
-
leadingWhitespace = matches && matches[0];
|
672
|
-
}
|
673
|
-
if (PARSER_MEDIA_TYPE === "application/xhtml+xml" && NAMESPACE === HTML_NAMESPACE) {
|
674
|
-
dirty = '<html xmlns="http://www.w3.org/1999/xhtml"><head></head><body>' + dirty + "</body></html>";
|
675
|
-
}
|
676
|
-
const dirtyPayload = trustedTypesPolicy ? trustedTypesPolicy.createHTML(dirty) : dirty;
|
677
|
-
if (NAMESPACE === HTML_NAMESPACE) {
|
678
|
-
try {
|
679
|
-
doc = new DOMParser().parseFromString(dirtyPayload, PARSER_MEDIA_TYPE);
|
680
|
-
} catch (_) {
|
588
|
+
},
|
589
|
+
get internals() {
|
590
|
+
return new Proxy({}, {
|
591
|
+
get: () => {
|
592
|
+
throw new Error("The `internals` property is not available on the server.");
|
681
593
|
}
|
682
|
-
}
|
683
|
-
if (!doc || !doc.documentElement) {
|
684
|
-
doc = implementation.createDocument(NAMESPACE, "template", null);
|
685
|
-
try {
|
686
|
-
doc.documentElement.innerHTML = IS_EMPTY_INPUT ? emptyHTML : dirtyPayload;
|
687
|
-
} catch (_) {
|
688
|
-
}
|
689
|
-
}
|
690
|
-
const body = doc.body || doc.documentElement;
|
691
|
-
if (dirty && leadingWhitespace) {
|
692
|
-
body.insertBefore(document2.createTextNode(leadingWhitespace), body.childNodes[0] || null);
|
693
|
-
}
|
694
|
-
if (NAMESPACE === HTML_NAMESPACE) {
|
695
|
-
return getElementsByTagName.call(doc, WHOLE_DOCUMENT ? "html" : "body")[0];
|
696
|
-
}
|
697
|
-
return WHOLE_DOCUMENT ? doc.documentElement : body;
|
698
|
-
};
|
699
|
-
const _createNodeIterator = function _createNodeIterator2(root) {
|
700
|
-
return createNodeIterator.call(
|
701
|
-
root.ownerDocument || root,
|
702
|
-
root,
|
703
|
-
// eslint-disable-next-line no-bitwise
|
704
|
-
NodeFilter.SHOW_ELEMENT | NodeFilter.SHOW_COMMENT | NodeFilter.SHOW_TEXT | NodeFilter.SHOW_PROCESSING_INSTRUCTION | NodeFilter.SHOW_CDATA_SECTION,
|
705
|
-
null
|
706
|
-
);
|
707
|
-
};
|
708
|
-
const _isClobbered = function _isClobbered2(element) {
|
709
|
-
return element instanceof HTMLFormElement && (typeof element.nodeName !== "string" || typeof element.textContent !== "string" || typeof element.removeChild !== "function" || !(element.attributes instanceof NamedNodeMap) || typeof element.removeAttribute !== "function" || typeof element.setAttribute !== "function" || typeof element.namespaceURI !== "string" || typeof element.insertBefore !== "function" || typeof element.hasChildNodes !== "function");
|
710
|
-
};
|
711
|
-
const _isNode = function _isNode2(value) {
|
712
|
-
return typeof Node === "function" && value instanceof Node;
|
713
|
-
};
|
714
|
-
function _executeHook(entryPoint, currentNode, data) {
|
715
|
-
if (!hooks[entryPoint]) {
|
716
|
-
return;
|
717
|
-
}
|
718
|
-
arrayForEach(hooks[entryPoint], (hook) => {
|
719
|
-
hook.call(DOMPurify, currentNode, data, CONFIG);
|
720
594
|
});
|
595
|
+
},
|
596
|
+
attributeChangedCallback: NOOP,
|
597
|
+
connectedCallback: NOOP,
|
598
|
+
disconnectedCallback: NOOP,
|
599
|
+
adoptedCallback: NOOP,
|
600
|
+
formDisabledCallback: NOOP,
|
601
|
+
formResetCallback: NOOP,
|
602
|
+
formStateRestoreCallback: NOOP,
|
603
|
+
formAssociatedCallback: NOOP,
|
604
|
+
clientOnlyCallback: NOOP,
|
605
|
+
customCallback: () => `{{callback:unavailable-on-server}}`,
|
606
|
+
attrSignals: new Proxy({}, { get: (_, attr) => createSignal(`{{attr:${String(attr)}}}`) }),
|
607
|
+
propSignals: new Proxy({}, { get: () => createSignal(null) }),
|
608
|
+
refs: {},
|
609
|
+
// @ts-expect-error // this will be a string for SSR, but this is true for internal cases only.
|
610
|
+
// The end user will see the public type, which is either a CSSStyleSheet or HTMLStyleElement.
|
611
|
+
adoptStyleSheet: (cssStr) => {
|
612
|
+
const _serverCss = registry !== void 0 ? registry.__serverCss : serverCss;
|
613
|
+
const cssArr = _serverCss.get(tagName) ?? [];
|
614
|
+
cssArr.push(cssStr);
|
615
|
+
_serverCss.set(tagName, cssArr);
|
721
616
|
}
|
722
|
-
|
723
|
-
|
724
|
-
|
725
|
-
|
726
|
-
|
727
|
-
|
728
|
-
|
729
|
-
|
730
|
-
|
731
|
-
|
732
|
-
|
617
|
+
});
|
618
|
+
var wrapTemplate = ({ tagName, serverRender, options }) => {
|
619
|
+
const { registry } = options.shadowRootOptions;
|
620
|
+
const scopedRegistry = registry !== void 0 && "scoped" in registry ? registry : void 0;
|
621
|
+
const initialRenderString = serverRender(getServerRenderArgs(tagName, scopedRegistry));
|
622
|
+
const _serverCss = scopedRegistry?.__serverCss ?? serverCss;
|
623
|
+
const cssRenderString = (_serverCss.get(tagName) ?? []).map((cssStr) => `<style>${cssStr}</style>`).join("");
|
624
|
+
const finalScopedRenderString = options.attachShadow ? (
|
625
|
+
/* html */
|
626
|
+
`
|
627
|
+
<template
|
628
|
+
shadowrootmode="${options.shadowRootOptions.mode}"
|
629
|
+
shadowrootdelegatesfocus="${options.shadowRootOptions.delegatesFocus}"
|
630
|
+
shadowrootclonable="${options.shadowRootOptions.clonable}"
|
631
|
+
shadowrootserializable="${options.shadowRootOptions.serializable}"
|
632
|
+
>
|
633
|
+
${cssRenderString + initialRenderString}
|
634
|
+
</template>
|
635
|
+
`
|
636
|
+
) : cssRenderString + initialRenderString;
|
637
|
+
return finalScopedRenderString;
|
638
|
+
};
|
639
|
+
var insertTemplates = (tagName, template, inputString) => {
|
640
|
+
return inputString.replace(new RegExp(`(<s*${tagName}([^>]*)>)`, "gm"), ($1, _, $3) => {
|
641
|
+
const attrs = $3.split(/(?<=")\s+/).filter((attr) => attr.trim() !== "").map((attr) => {
|
642
|
+
const [_key, _value] = attr.split("=");
|
643
|
+
const key = _key.trim();
|
644
|
+
const value = _value?.replace(/"/g, "") ?? "";
|
645
|
+
return [key, value];
|
733
646
|
});
|
734
|
-
|
735
|
-
|
736
|
-
|
737
|
-
}
|
738
|
-
if (currentNode.nodeType === NODE_TYPE.progressingInstruction) {
|
739
|
-
_forceRemove(currentNode);
|
740
|
-
return true;
|
741
|
-
}
|
742
|
-
if (SAFE_FOR_XML && currentNode.nodeType === NODE_TYPE.comment && regExpTest(/<[/\w]/g, currentNode.data)) {
|
743
|
-
_forceRemove(currentNode);
|
744
|
-
return true;
|
745
|
-
}
|
746
|
-
if (!ALLOWED_TAGS[tagName] || FORBID_TAGS[tagName]) {
|
747
|
-
if (!FORBID_TAGS[tagName] && _isBasicCustomElement(tagName)) {
|
748
|
-
if (CUSTOM_ELEMENT_HANDLING.tagNameCheck instanceof RegExp && regExpTest(CUSTOM_ELEMENT_HANDLING.tagNameCheck, tagName)) {
|
749
|
-
return false;
|
750
|
-
}
|
751
|
-
if (CUSTOM_ELEMENT_HANDLING.tagNameCheck instanceof Function && CUSTOM_ELEMENT_HANDLING.tagNameCheck(tagName)) {
|
752
|
-
return false;
|
753
|
-
}
|
754
|
-
}
|
755
|
-
if (KEEP_CONTENT && !FORBID_CONTENTS[tagName]) {
|
756
|
-
const parentNode = getParentNode(currentNode) || currentNode.parentNode;
|
757
|
-
const childNodes = getChildNodes(currentNode) || currentNode.childNodes;
|
758
|
-
if (childNodes && parentNode) {
|
759
|
-
const childCount = childNodes.length;
|
760
|
-
for (let i = childCount - 1; i >= 0; --i) {
|
761
|
-
const childClone = cloneNode(childNodes[i], true);
|
762
|
-
childClone.__removalCount = (currentNode.__removalCount || 0) + 1;
|
763
|
-
parentNode.insertBefore(childClone, getNextSibling(currentNode));
|
764
|
-
}
|
765
|
-
}
|
766
|
-
}
|
767
|
-
_forceRemove(currentNode);
|
768
|
-
return true;
|
769
|
-
}
|
770
|
-
if (currentNode instanceof Element2 && !_checkValidNamespace(currentNode)) {
|
771
|
-
_forceRemove(currentNode);
|
772
|
-
return true;
|
773
|
-
}
|
774
|
-
if ((tagName === "noscript" || tagName === "noembed" || tagName === "noframes") && regExpTest(/<\/no(script|embed|frames)/i, currentNode.innerHTML)) {
|
775
|
-
_forceRemove(currentNode);
|
776
|
-
return true;
|
777
|
-
}
|
778
|
-
if (SAFE_FOR_TEMPLATES && currentNode.nodeType === NODE_TYPE.text) {
|
779
|
-
content = currentNode.textContent;
|
780
|
-
arrayForEach([MUSTACHE_EXPR2, ERB_EXPR2, TMPLIT_EXPR2], (expr) => {
|
781
|
-
content = stringReplace(content, expr, " ");
|
782
|
-
});
|
783
|
-
if (currentNode.textContent !== content) {
|
784
|
-
arrayPush(DOMPurify.removed, {
|
785
|
-
element: currentNode.cloneNode()
|
786
|
-
});
|
787
|
-
currentNode.textContent = content;
|
788
|
-
}
|
789
|
-
}
|
790
|
-
_executeHook("afterSanitizeElements", currentNode, null);
|
791
|
-
return false;
|
792
|
-
};
|
793
|
-
const _isValidAttribute = function _isValidAttribute2(lcTag, lcName, value) {
|
794
|
-
if (SANITIZE_DOM && (lcName === "id" || lcName === "name") && (value in document2 || value in formElement)) {
|
795
|
-
return false;
|
796
|
-
}
|
797
|
-
if (ALLOW_DATA_ATTR && !FORBID_ATTR[lcName] && regExpTest(DATA_ATTR2, lcName)) ;
|
798
|
-
else if (ALLOW_ARIA_ATTR && regExpTest(ARIA_ATTR2, lcName)) ;
|
799
|
-
else if (!ALLOWED_ATTR[lcName] || FORBID_ATTR[lcName]) {
|
800
|
-
if (
|
801
|
-
// First condition does a very basic check if a) it's basically a valid custom element tagname AND
|
802
|
-
// b) if the tagName passes whatever the user has configured for CUSTOM_ELEMENT_HANDLING.tagNameCheck
|
803
|
-
// and c) if the attribute name passes whatever the user has configured for CUSTOM_ELEMENT_HANDLING.attributeNameCheck
|
804
|
-
_isBasicCustomElement(lcTag) && (CUSTOM_ELEMENT_HANDLING.tagNameCheck instanceof RegExp && regExpTest(CUSTOM_ELEMENT_HANDLING.tagNameCheck, lcTag) || CUSTOM_ELEMENT_HANDLING.tagNameCheck instanceof Function && CUSTOM_ELEMENT_HANDLING.tagNameCheck(lcTag)) && (CUSTOM_ELEMENT_HANDLING.attributeNameCheck instanceof RegExp && regExpTest(CUSTOM_ELEMENT_HANDLING.attributeNameCheck, lcName) || CUSTOM_ELEMENT_HANDLING.attributeNameCheck instanceof Function && CUSTOM_ELEMENT_HANDLING.attributeNameCheck(lcName)) || // Alternative, second condition checks if it's an `is`-attribute, AND
|
805
|
-
// the value passes whatever the user has configured for CUSTOM_ELEMENT_HANDLING.tagNameCheck
|
806
|
-
lcName === "is" && CUSTOM_ELEMENT_HANDLING.allowCustomizedBuiltInElements && (CUSTOM_ELEMENT_HANDLING.tagNameCheck instanceof RegExp && regExpTest(CUSTOM_ELEMENT_HANDLING.tagNameCheck, value) || CUSTOM_ELEMENT_HANDLING.tagNameCheck instanceof Function && CUSTOM_ELEMENT_HANDLING.tagNameCheck(value))
|
807
|
-
) ;
|
808
|
-
else {
|
809
|
-
return false;
|
810
|
-
}
|
811
|
-
} else if (URI_SAFE_ATTRIBUTES[lcName]) ;
|
812
|
-
else if (regExpTest(IS_ALLOWED_URI$1, stringReplace(value, ATTR_WHITESPACE2, ""))) ;
|
813
|
-
else if ((lcName === "src" || lcName === "xlink:href" || lcName === "href") && lcTag !== "script" && stringIndexOf(value, "data:") === 0 && DATA_URI_TAGS[lcTag]) ;
|
814
|
-
else if (ALLOW_UNKNOWN_PROTOCOLS && !regExpTest(IS_SCRIPT_OR_DATA2, stringReplace(value, ATTR_WHITESPACE2, ""))) ;
|
815
|
-
else if (value) {
|
816
|
-
return false;
|
817
|
-
} else ;
|
818
|
-
return true;
|
819
|
-
};
|
820
|
-
const _isBasicCustomElement = function _isBasicCustomElement2(tagName) {
|
821
|
-
return tagName !== "annotation-xml" && stringMatch(tagName, CUSTOM_ELEMENT2);
|
822
|
-
};
|
823
|
-
const _sanitizeAttributes = function _sanitizeAttributes2(currentNode) {
|
824
|
-
_executeHook("beforeSanitizeAttributes", currentNode, null);
|
825
|
-
const {
|
826
|
-
attributes
|
827
|
-
} = currentNode;
|
828
|
-
if (!attributes) {
|
829
|
-
return;
|
830
|
-
}
|
831
|
-
const hookEvent = {
|
832
|
-
attrName: "",
|
833
|
-
attrValue: "",
|
834
|
-
keepAttr: true,
|
835
|
-
allowedAttributes: ALLOWED_ATTR,
|
836
|
-
forceKeepAttr: void 0
|
837
|
-
};
|
838
|
-
let l = attributes.length;
|
839
|
-
while (l--) {
|
840
|
-
const attr = attributes[l];
|
841
|
-
const {
|
842
|
-
name,
|
843
|
-
namespaceURI,
|
844
|
-
value: attrValue
|
845
|
-
} = attr;
|
846
|
-
const lcName = transformCaseFunc(name);
|
847
|
-
let value = name === "value" ? attrValue : stringTrim(attrValue);
|
848
|
-
hookEvent.attrName = lcName;
|
849
|
-
hookEvent.attrValue = value;
|
850
|
-
hookEvent.keepAttr = true;
|
851
|
-
hookEvent.forceKeepAttr = void 0;
|
852
|
-
_executeHook("uponSanitizeAttribute", currentNode, hookEvent);
|
853
|
-
value = hookEvent.attrValue;
|
854
|
-
if (SANITIZE_NAMED_PROPS && (lcName === "id" || lcName === "name")) {
|
855
|
-
_removeAttribute(name, currentNode);
|
856
|
-
value = SANITIZE_NAMED_PROPS_PREFIX + value;
|
857
|
-
}
|
858
|
-
if (SAFE_FOR_XML && regExpTest(/((--!?|])>)|<\/(style|title)/i, value)) {
|
859
|
-
_removeAttribute(name, currentNode);
|
860
|
-
continue;
|
861
|
-
}
|
862
|
-
if (hookEvent.forceKeepAttr) {
|
863
|
-
continue;
|
864
|
-
}
|
865
|
-
_removeAttribute(name, currentNode);
|
866
|
-
if (!hookEvent.keepAttr) {
|
867
|
-
continue;
|
868
|
-
}
|
869
|
-
if (!ALLOW_SELF_CLOSE_IN_ATTR && regExpTest(/\/>/i, value)) {
|
870
|
-
_removeAttribute(name, currentNode);
|
871
|
-
continue;
|
872
|
-
}
|
873
|
-
if (SAFE_FOR_TEMPLATES) {
|
874
|
-
arrayForEach([MUSTACHE_EXPR2, ERB_EXPR2, TMPLIT_EXPR2], (expr) => {
|
875
|
-
value = stringReplace(value, expr, " ");
|
876
|
-
});
|
877
|
-
}
|
878
|
-
const lcTag = transformCaseFunc(currentNode.nodeName);
|
879
|
-
if (!_isValidAttribute(lcTag, lcName, value)) {
|
880
|
-
continue;
|
881
|
-
}
|
882
|
-
if (trustedTypesPolicy && typeof trustedTypes === "object" && typeof trustedTypes.getAttributeType === "function") {
|
883
|
-
if (namespaceURI) ;
|
884
|
-
else {
|
885
|
-
switch (trustedTypes.getAttributeType(lcTag, lcName)) {
|
886
|
-
case "TrustedHTML": {
|
887
|
-
value = trustedTypesPolicy.createHTML(value);
|
888
|
-
break;
|
889
|
-
}
|
890
|
-
case "TrustedScriptURL": {
|
891
|
-
value = trustedTypesPolicy.createScriptURL(value);
|
892
|
-
break;
|
893
|
-
}
|
894
|
-
}
|
895
|
-
}
|
896
|
-
}
|
897
|
-
try {
|
898
|
-
if (namespaceURI) {
|
899
|
-
currentNode.setAttributeNS(namespaceURI, name, value);
|
900
|
-
} else {
|
901
|
-
currentNode.setAttribute(name, value);
|
902
|
-
}
|
903
|
-
if (_isClobbered(currentNode)) {
|
904
|
-
_forceRemove(currentNode);
|
905
|
-
} else {
|
906
|
-
arrayPop(DOMPurify.removed);
|
907
|
-
}
|
908
|
-
} catch (_) {
|
909
|
-
}
|
910
|
-
}
|
911
|
-
_executeHook("afterSanitizeAttributes", currentNode, null);
|
912
|
-
};
|
913
|
-
const _sanitizeShadowDOM = function _sanitizeShadowDOM2(fragment) {
|
914
|
-
let shadowNode = null;
|
915
|
-
const shadowIterator = _createNodeIterator(fragment);
|
916
|
-
_executeHook("beforeSanitizeShadowDOM", fragment, null);
|
917
|
-
while (shadowNode = shadowIterator.nextNode()) {
|
918
|
-
_executeHook("uponSanitizeShadowNode", shadowNode, null);
|
919
|
-
if (_sanitizeElements(shadowNode)) {
|
920
|
-
continue;
|
921
|
-
}
|
922
|
-
if (shadowNode.content instanceof DocumentFragment2) {
|
923
|
-
_sanitizeShadowDOM2(shadowNode.content);
|
924
|
-
}
|
925
|
-
_sanitizeAttributes(shadowNode);
|
926
|
-
}
|
927
|
-
_executeHook("afterSanitizeShadowDOM", fragment, null);
|
928
|
-
};
|
929
|
-
DOMPurify.sanitize = function(dirty) {
|
930
|
-
let cfg = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : {};
|
931
|
-
let body = null;
|
932
|
-
let importedNode = null;
|
933
|
-
let currentNode = null;
|
934
|
-
let returnNode = null;
|
935
|
-
IS_EMPTY_INPUT = !dirty;
|
936
|
-
if (IS_EMPTY_INPUT) {
|
937
|
-
dirty = "<!-->";
|
938
|
-
}
|
939
|
-
if (typeof dirty !== "string" && !_isNode(dirty)) {
|
940
|
-
if (typeof dirty.toString === "function") {
|
941
|
-
dirty = dirty.toString();
|
942
|
-
if (typeof dirty !== "string") {
|
943
|
-
throw typeErrorCreate("dirty is not a string, aborting");
|
944
|
-
}
|
945
|
-
} else {
|
946
|
-
throw typeErrorCreate("toString is not a function");
|
947
|
-
}
|
948
|
-
}
|
949
|
-
if (!DOMPurify.isSupported) {
|
950
|
-
return dirty;
|
951
|
-
}
|
952
|
-
if (!SET_CONFIG) {
|
953
|
-
_parseConfig(cfg);
|
647
|
+
let scopedResult = template;
|
648
|
+
for (const [key, value] of attrs) {
|
649
|
+
scopedResult = scopedResult.replace(new RegExp(`{{attr:${key}}}`, "gm"), value);
|
954
650
|
}
|
955
|
-
|
956
|
-
|
957
|
-
|
958
|
-
|
959
|
-
|
960
|
-
|
961
|
-
const tagName = transformCaseFunc(dirty.nodeName);
|
962
|
-
if (!ALLOWED_TAGS[tagName] || FORBID_TAGS[tagName]) {
|
963
|
-
throw typeErrorCreate("root node is forbidden and cannot be sanitized in-place");
|
964
|
-
}
|
965
|
-
}
|
966
|
-
} else if (dirty instanceof Node) {
|
967
|
-
body = _initDocument("<!---->");
|
968
|
-
importedNode = body.ownerDocument.importNode(dirty, true);
|
969
|
-
if (importedNode.nodeType === NODE_TYPE.element && importedNode.nodeName === "BODY") {
|
970
|
-
body = importedNode;
|
971
|
-
} else if (importedNode.nodeName === "HTML") {
|
972
|
-
body = importedNode;
|
973
|
-
} else {
|
974
|
-
body.appendChild(importedNode);
|
975
|
-
}
|
976
|
-
} else {
|
977
|
-
if (!RETURN_DOM && !SAFE_FOR_TEMPLATES && !WHOLE_DOCUMENT && // eslint-disable-next-line unicorn/prefer-includes
|
978
|
-
dirty.indexOf("<") === -1) {
|
979
|
-
return trustedTypesPolicy && RETURN_TRUSTED_TYPE ? trustedTypesPolicy.createHTML(dirty) : dirty;
|
980
|
-
}
|
981
|
-
body = _initDocument(dirty);
|
982
|
-
if (!body) {
|
983
|
-
return RETURN_DOM ? null : RETURN_TRUSTED_TYPE ? emptyHTML : "";
|
984
|
-
}
|
985
|
-
}
|
986
|
-
if (body && FORCE_BODY) {
|
987
|
-
_forceRemove(body.firstChild);
|
988
|
-
}
|
989
|
-
const nodeIterator = _createNodeIterator(IN_PLACE ? dirty : body);
|
990
|
-
while (currentNode = nodeIterator.nextNode()) {
|
991
|
-
if (_sanitizeElements(currentNode)) {
|
992
|
-
continue;
|
993
|
-
}
|
994
|
-
if (currentNode.content instanceof DocumentFragment2) {
|
995
|
-
_sanitizeShadowDOM(currentNode.content);
|
996
|
-
}
|
997
|
-
_sanitizeAttributes(currentNode);
|
998
|
-
}
|
999
|
-
if (IN_PLACE) {
|
1000
|
-
return dirty;
|
1001
|
-
}
|
1002
|
-
if (RETURN_DOM) {
|
1003
|
-
if (RETURN_DOM_FRAGMENT) {
|
1004
|
-
returnNode = createDocumentFragment.call(body.ownerDocument);
|
1005
|
-
while (body.firstChild) {
|
1006
|
-
returnNode.appendChild(body.firstChild);
|
1007
|
-
}
|
1008
|
-
} else {
|
1009
|
-
returnNode = body;
|
1010
|
-
}
|
1011
|
-
if (ALLOWED_ATTR.shadowroot || ALLOWED_ATTR.shadowrootmode) {
|
1012
|
-
returnNode = importNode.call(originalDocument, returnNode, true);
|
1013
|
-
}
|
1014
|
-
return returnNode;
|
1015
|
-
}
|
1016
|
-
let serializedHTML = WHOLE_DOCUMENT ? body.outerHTML : body.innerHTML;
|
1017
|
-
if (WHOLE_DOCUMENT && ALLOWED_TAGS["!doctype"] && body.ownerDocument && body.ownerDocument.doctype && body.ownerDocument.doctype.name && regExpTest(DOCTYPE_NAME, body.ownerDocument.doctype.name)) {
|
1018
|
-
serializedHTML = "<!DOCTYPE " + body.ownerDocument.doctype.name + ">\n" + serializedHTML;
|
1019
|
-
}
|
1020
|
-
if (SAFE_FOR_TEMPLATES) {
|
1021
|
-
arrayForEach([MUSTACHE_EXPR2, ERB_EXPR2, TMPLIT_EXPR2], (expr) => {
|
1022
|
-
serializedHTML = stringReplace(serializedHTML, expr, " ");
|
1023
|
-
});
|
1024
|
-
}
|
1025
|
-
return trustedTypesPolicy && RETURN_TRUSTED_TYPE ? trustedTypesPolicy.createHTML(serializedHTML) : serializedHTML;
|
1026
|
-
};
|
1027
|
-
DOMPurify.setConfig = function() {
|
1028
|
-
let cfg = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : {};
|
1029
|
-
_parseConfig(cfg);
|
1030
|
-
SET_CONFIG = true;
|
1031
|
-
};
|
1032
|
-
DOMPurify.clearConfig = function() {
|
1033
|
-
CONFIG = null;
|
1034
|
-
SET_CONFIG = false;
|
1035
|
-
};
|
1036
|
-
DOMPurify.isValidAttribute = function(tag, attr, value) {
|
1037
|
-
if (!CONFIG) {
|
1038
|
-
_parseConfig({});
|
1039
|
-
}
|
1040
|
-
const lcTag = transformCaseFunc(tag);
|
1041
|
-
const lcName = transformCaseFunc(attr);
|
1042
|
-
return _isValidAttribute(lcTag, lcName, value);
|
1043
|
-
};
|
1044
|
-
DOMPurify.addHook = function(entryPoint, hookFunction) {
|
1045
|
-
if (typeof hookFunction !== "function") {
|
1046
|
-
return;
|
1047
|
-
}
|
1048
|
-
hooks[entryPoint] = hooks[entryPoint] || [];
|
1049
|
-
arrayPush(hooks[entryPoint], hookFunction);
|
1050
|
-
};
|
1051
|
-
DOMPurify.removeHook = function(entryPoint) {
|
1052
|
-
if (hooks[entryPoint]) {
|
1053
|
-
return arrayPop(hooks[entryPoint]);
|
1054
|
-
}
|
1055
|
-
};
|
1056
|
-
DOMPurify.removeHooks = function(entryPoint) {
|
1057
|
-
if (hooks[entryPoint]) {
|
1058
|
-
hooks[entryPoint] = [];
|
1059
|
-
}
|
1060
|
-
};
|
1061
|
-
DOMPurify.removeAllHooks = function() {
|
1062
|
-
hooks = {};
|
1063
|
-
};
|
1064
|
-
return DOMPurify;
|
1065
|
-
}
|
1066
|
-
var purify = createDOMPurify();
|
651
|
+
return $1 + scopedResult;
|
652
|
+
});
|
653
|
+
};
|
654
|
+
var clientOnlyCallback = (fn) => {
|
655
|
+
if (!isServer) return fn();
|
656
|
+
};
|
1067
657
|
|
1068
658
|
// src/render.ts
|
1069
|
-
var
|
659
|
+
var clearHTML = (element) => {
|
660
|
+
while (element.childNodes.length > 0) {
|
661
|
+
element.childNodes[0].remove();
|
662
|
+
}
|
663
|
+
};
|
664
|
+
var parseFragment = (htmlStr) => {
|
665
|
+
const range = document.createRange();
|
666
|
+
range.selectNode(document.body);
|
667
|
+
return range.createContextualFragment(htmlStr);
|
668
|
+
};
|
669
|
+
var setInnerHTML = (element, html2) => {
|
670
|
+
clearHTML(element);
|
671
|
+
const fragment = typeof html2 === "string" ? parseFragment(html2) : html2;
|
672
|
+
element.append(fragment);
|
673
|
+
};
|
674
|
+
var logValueError = (value) => {
|
675
|
+
console.error(
|
676
|
+
"An invalid value was passed to a template function. Non-primitive values are not supported.\n\nValue:\n",
|
677
|
+
value
|
678
|
+
);
|
679
|
+
};
|
680
|
+
var html = (strings, ...values) => {
|
1070
681
|
let innerHTML = "";
|
1071
682
|
const signalMap = /* @__PURE__ */ new Map();
|
1072
683
|
strings.forEach((string, i) => {
|
@@ -1074,11 +685,17 @@ var html2 = (strings, ...values) => {
|
|
1074
685
|
if (typeof value === "function") {
|
1075
686
|
const uniqueKey = crypto.randomUUID();
|
1076
687
|
signalMap.set(uniqueKey, value);
|
1077
|
-
value = `{{signal:${uniqueKey}}}`;
|
688
|
+
value = isServer ? value() : `{{signal:${uniqueKey}}}`;
|
689
|
+
}
|
690
|
+
if (typeof value === "object" && value !== null) {
|
691
|
+
logValueError(value);
|
692
|
+
value = "";
|
1078
693
|
}
|
1079
694
|
innerHTML += string + String(value);
|
1080
695
|
});
|
1081
|
-
|
696
|
+
if (isServer) {
|
697
|
+
return innerHTML;
|
698
|
+
}
|
1082
699
|
const fragment = parseFragment(innerHTML);
|
1083
700
|
const callbackBindingRegex = /(\{\{callback:.+\}\})/;
|
1084
701
|
const signalBindingRegex = /(\{\{signal:.+\}\})/;
|
@@ -1086,10 +703,10 @@ var html2 = (strings, ...values) => {
|
|
1086
703
|
for (const child of element.childNodes) {
|
1087
704
|
if (child instanceof Text && signalBindingRegex.test(child.data)) {
|
1088
705
|
const textList = child.data.split(signalBindingRegex);
|
1089
|
-
textList.forEach((
|
1090
|
-
const uniqueKey =
|
1091
|
-
const signal = uniqueKey !==
|
1092
|
-
const newValue = signal !== void 0 ? signal() :
|
706
|
+
textList.forEach((text, i) => {
|
707
|
+
const uniqueKey = text.replace(/\{\{signal:(.+)\}\}/, "$1");
|
708
|
+
const signal = uniqueKey !== text ? signalMap.get(uniqueKey) : void 0;
|
709
|
+
const newValue = signal !== void 0 ? signal() : text;
|
1093
710
|
const newNode = (() => {
|
1094
711
|
if (typeof newValue === "string") return new Text(newValue);
|
1095
712
|
if (newValue instanceof DocumentFragment) return newValue;
|
@@ -1114,12 +731,12 @@ var html2 = (strings, ...values) => {
|
|
1114
731
|
createEffect(() => {
|
1115
732
|
let newText = "";
|
1116
733
|
let hasNull = false;
|
1117
|
-
for (const
|
1118
|
-
const uniqueKey =
|
1119
|
-
const signal = uniqueKey !==
|
1120
|
-
const value = signal !== void 0 ? signal() :
|
734
|
+
for (const text of textList) {
|
735
|
+
const uniqueKey = text.replace(/\{\{signal:(.+)\}\}/, "$1");
|
736
|
+
const signal = uniqueKey !== text ? signalMap.get(uniqueKey) : void 0;
|
737
|
+
const value = signal !== void 0 ? signal() : text;
|
1121
738
|
if (value === null) hasNull = true;
|
1122
|
-
newText += value;
|
739
|
+
newText += String(value);
|
1123
740
|
}
|
1124
741
|
if (hasNull && newText === "null") {
|
1125
742
|
child.removeAttribute(attr.name);
|
@@ -1157,23 +774,31 @@ var css = (strings, ...values) => {
|
|
1157
774
|
if (typeof value === "function") {
|
1158
775
|
const uniqueKey = crypto.randomUUID();
|
1159
776
|
signalMap.set(uniqueKey, value);
|
1160
|
-
value = `{{signal:${uniqueKey}}}`;
|
777
|
+
value = isServer ? value() : `{{signal:${uniqueKey}}}`;
|
778
|
+
}
|
779
|
+
if (typeof value === "object" && value !== null) {
|
780
|
+
logValueError(value);
|
781
|
+
value = "";
|
1161
782
|
}
|
1162
783
|
cssText += string + String(value);
|
1163
784
|
});
|
1164
|
-
|
785
|
+
if (isServer) {
|
786
|
+
return cssText;
|
787
|
+
}
|
788
|
+
const stylesheet = adoptedStylesSupported ? new CSSStyleSheet() : document.createElement("style");
|
1165
789
|
const textList = cssText.split(signalBindingRegex);
|
1166
790
|
createEffect(() => {
|
1167
791
|
const newCSSTextList = [];
|
1168
|
-
for (const
|
1169
|
-
const uniqueKey =
|
1170
|
-
const signal = uniqueKey !==
|
1171
|
-
const
|
792
|
+
for (const text of textList) {
|
793
|
+
const uniqueKey = text.replace(/\{\{signal:(.+)\}\}/, "$1");
|
794
|
+
const signal = uniqueKey !== text ? signalMap.get(uniqueKey) : null;
|
795
|
+
const newValue = signal !== null ? signal() : text;
|
796
|
+
const newText = String(newValue);
|
1172
797
|
newCSSTextList.push(newText);
|
1173
798
|
}
|
1174
799
|
const newCSSText = newCSSTextList.join("");
|
1175
800
|
if (isCSSStyleSheet(stylesheet)) {
|
1176
|
-
stylesheet.replace(newCSSText);
|
801
|
+
stylesheet.replace(newCSSText).catch(console.error);
|
1177
802
|
} else {
|
1178
803
|
stylesheet.textContent = newCSSText;
|
1179
804
|
}
|
@@ -1182,42 +807,63 @@ var css = (strings, ...values) => {
|
|
1182
807
|
};
|
1183
808
|
|
1184
809
|
// src/custom-element.ts
|
1185
|
-
var DEFAULT_RENDER_OPTIONS = {
|
1186
|
-
formAssociated: false,
|
1187
|
-
observedAttributes: [],
|
1188
|
-
attributesAsProperties: [],
|
1189
|
-
attachShadow: true,
|
1190
|
-
shadowRootOptions: {
|
1191
|
-
mode: "closed"
|
1192
|
-
}
|
1193
|
-
};
|
1194
|
-
if (typeof window !== "undefined") {
|
1195
|
-
class TrackableCustomElementRegistry extends window.CustomElementRegistry {
|
1196
|
-
__tagNames = /* @__PURE__ */ new Set();
|
1197
|
-
define(tagName, constructor) {
|
1198
|
-
super.define(tagName, constructor);
|
1199
|
-
this.__tagNames.add(tagName);
|
1200
|
-
}
|
1201
|
-
}
|
1202
|
-
window.CustomElementRegistry = TrackableCustomElementRegistry;
|
1203
|
-
}
|
1204
|
-
var getPropName = (attrName) => attrName.replace(/^([A-Z]+)/, (_, letter) => letter.toLowerCase()).replace(/(-|_| )([a-zA-Z])/g, (_, letter) => letter.toUpperCase());
|
1205
810
|
var customElement = (render, options) => {
|
811
|
+
const _options = { ...DEFAULT_RENDER_OPTIONS, ...options };
|
1206
812
|
const {
|
1207
813
|
formAssociated,
|
1208
814
|
observedAttributes: _observedAttributes,
|
1209
815
|
attributesAsProperties,
|
1210
816
|
attachShadow,
|
1211
817
|
shadowRootOptions: _shadowRootOptions
|
1212
|
-
} =
|
818
|
+
} = _options;
|
1213
819
|
const shadowRootOptions = { ...DEFAULT_RENDER_OPTIONS.shadowRootOptions, ..._shadowRootOptions };
|
820
|
+
const allOptions = { ..._options, shadowRootOptions };
|
821
|
+
if (isServer) {
|
822
|
+
const serverRender = render;
|
823
|
+
let _tagName2;
|
824
|
+
let _registry2;
|
825
|
+
const scopedRegistry = (() => {
|
826
|
+
if (shadowRootOptions.registry !== void 0 && "scoped" in shadowRootOptions.registry && shadowRootOptions.registry.scoped) {
|
827
|
+
return shadowRootOptions.registry;
|
828
|
+
}
|
829
|
+
})();
|
830
|
+
return {
|
831
|
+
define(tagName) {
|
832
|
+
_tagName2 = tagName;
|
833
|
+
serverDefine({
|
834
|
+
tagName,
|
835
|
+
serverRender,
|
836
|
+
options: allOptions,
|
837
|
+
scopedRegistry,
|
838
|
+
parentRegistry: _registry2
|
839
|
+
});
|
840
|
+
return this;
|
841
|
+
},
|
842
|
+
register(registry) {
|
843
|
+
if (_tagName2 !== void 0 && "eject" in registry && registry.scoped) {
|
844
|
+
console.error("Must call `register()` before `define()` for scoped registries.");
|
845
|
+
return this;
|
846
|
+
}
|
847
|
+
if ("eject" in registry) {
|
848
|
+
_registry2 = registry;
|
849
|
+
} else {
|
850
|
+
console.error("Registry must be created with `createRegistry()` for SSR.");
|
851
|
+
}
|
852
|
+
return this;
|
853
|
+
},
|
854
|
+
eject() {
|
855
|
+
throw new Error("Cannot eject a custom element on the server.");
|
856
|
+
}
|
857
|
+
};
|
858
|
+
}
|
1214
859
|
shadowRootOptions.registry = shadowRootOptions.customElements = shadowRootOptions.registry instanceof CustomElementRegistry ? shadowRootOptions.registry : shadowRootOptions.registry?.eject();
|
1215
860
|
const observedAttributesSet = new Set(_observedAttributes);
|
1216
861
|
const attributesAsPropertiesMap = /* @__PURE__ */ new Map();
|
1217
862
|
for (const [attrName, coerce] of attributesAsProperties) {
|
1218
863
|
observedAttributesSet.add(attrName);
|
1219
864
|
attributesAsPropertiesMap.set(attrName, {
|
1220
|
-
|
865
|
+
// convert kebab-case attribute names to camelCase property names
|
866
|
+
prop: attrName.replace(/^([A-Z]+)/, (_, letter) => letter.toLowerCase()).replace(/(-|_| )([a-zA-Z])/g, (_, letter) => letter.toUpperCase()),
|
1221
867
|
coerce,
|
1222
868
|
value: null
|
1223
869
|
});
|
@@ -1235,6 +881,7 @@ var customElement = (render, options) => {
|
|
1235
881
|
#formDisabledCallbackFns = /* @__PURE__ */ new Set();
|
1236
882
|
#formResetCallbackFns = /* @__PURE__ */ new Set();
|
1237
883
|
#formStateRestoreCallbackFns = /* @__PURE__ */ new Set();
|
884
|
+
#clientOnlyCallbackFns = /* @__PURE__ */ new Set();
|
1238
885
|
__customCallbackFns = /* @__PURE__ */ new Map();
|
1239
886
|
#shadowRoot = attachShadow ? this.attachShadow(shadowRootOptions) : null;
|
1240
887
|
#internals = this.attachInternals();
|
@@ -1244,8 +891,7 @@ var customElement = (render, options) => {
|
|
1244
891
|
if (mutation.type !== "attributes" || attrName === null) continue;
|
1245
892
|
if (!(attrName in this.#attrSignals)) this.#attrSignals[attrName] = createSignal(null);
|
1246
893
|
const [getter, setter] = this.#attrSignals[attrName];
|
1247
|
-
const
|
1248
|
-
const oldValue = _oldValue === null ? null : _oldValue;
|
894
|
+
const oldValue = getter();
|
1249
895
|
const newValue = this.getAttribute(attrName);
|
1250
896
|
setter(newValue);
|
1251
897
|
for (const fn of this.#attributeChangedFns) {
|
@@ -1267,6 +913,7 @@ var customElement = (render, options) => {
|
|
1267
913
|
formDisabledCallback: (fn) => this.#formDisabledCallbackFns.add(fn),
|
1268
914
|
formResetCallback: (fn) => this.#formResetCallbackFns.add(fn),
|
1269
915
|
formStateRestoreCallback: (fn) => this.#formStateRestoreCallbackFns.add(fn),
|
916
|
+
clientOnlyCallback: (fn) => this.#clientOnlyCallbackFns.add(fn),
|
1270
917
|
customCallback: (fn) => {
|
1271
918
|
const key = crypto.randomUUID();
|
1272
919
|
this.__customCallbackFns.set(key, fn);
|
@@ -1355,7 +1002,7 @@ You must set an initial value before calling a property signal's getter.
|
|
1355
1002
|
tempContainer.append(fragment.cloneNode(true));
|
1356
1003
|
const fragmentContent = tempContainer.innerHTML;
|
1357
1004
|
root.innerHTML = fragmentContent;
|
1358
|
-
if (registry
|
1005
|
+
if (registry?.__tagNames !== void 0) {
|
1359
1006
|
for (const tagName of registry.__tagNames) {
|
1360
1007
|
const upgradedElements = root.querySelectorAll(tagName);
|
1361
1008
|
const nonUpgradedElements = fragment.querySelectorAll(tagName);
|
@@ -1365,6 +1012,9 @@ You must set an initial value before calling a property signal's getter.
|
|
1365
1012
|
});
|
1366
1013
|
}
|
1367
1014
|
}
|
1015
|
+
for (const fn of this.#clientOnlyCallbackFns) {
|
1016
|
+
fn();
|
1017
|
+
}
|
1368
1018
|
setInnerHTML(root, fragment);
|
1369
1019
|
}
|
1370
1020
|
static get formAssociated() {
|
@@ -1461,78 +1111,106 @@ You must set an initial value before calling a property signal's getter.
|
|
1461
1111
|
}
|
1462
1112
|
}
|
1463
1113
|
}
|
1464
|
-
let _tagName
|
1465
|
-
let _registry
|
1466
|
-
let _registered = false;
|
1467
|
-
const register = () => {
|
1468
|
-
if (_tagName === null || _registry === null || _registered) return;
|
1469
|
-
_registry.register(_tagName, CustomElement);
|
1470
|
-
_registry.register(_tagName, elementResult);
|
1471
|
-
_registered = true;
|
1472
|
-
};
|
1114
|
+
let _tagName;
|
1115
|
+
let _registry;
|
1473
1116
|
const elementResult = {
|
1474
|
-
define(tagName) {
|
1475
|
-
const registry = _registry
|
1476
|
-
|
1117
|
+
define(tagName, options2) {
|
1118
|
+
const registry = _registry ?? customElements;
|
1119
|
+
const nativeRegistry = "eject" in registry ? registry.eject() : registry;
|
1120
|
+
if (nativeRegistry.get(tagName) !== void 0) {
|
1477
1121
|
console.warn(`Custom element "${tagName}" was already defined. Skipping...`);
|
1478
1122
|
return this;
|
1479
1123
|
}
|
1480
|
-
registry.define(tagName, CustomElement);
|
1124
|
+
registry.define(tagName, CustomElement, options2);
|
1481
1125
|
_tagName = tagName;
|
1482
|
-
register();
|
1483
1126
|
return this;
|
1484
1127
|
},
|
1485
1128
|
register(registry) {
|
1486
|
-
if (_tagName !==
|
1129
|
+
if (_tagName !== void 0 && "eject" in registry && registry.scoped) {
|
1487
1130
|
console.error("Must call `register()` before `define()` for scoped registries.");
|
1488
1131
|
return this;
|
1489
1132
|
}
|
1490
1133
|
_registry = registry;
|
1491
|
-
register();
|
1492
1134
|
return this;
|
1493
1135
|
},
|
1494
1136
|
eject: () => CustomElement
|
1495
1137
|
};
|
1496
1138
|
return elementResult;
|
1497
1139
|
};
|
1140
|
+
|
1141
|
+
// src/registry.ts
|
1498
1142
|
var createRegistry = (args) => {
|
1499
1143
|
const { scoped = false } = args ?? {};
|
1500
|
-
const
|
1501
|
-
const
|
1502
|
-
|
1503
|
-
|
1504
|
-
|
1505
|
-
|
1506
|
-
console.error(
|
1507
|
-
"Scoped custom element registries are not supported in this environment. Please install `@webcomponents/scoped-custom-element-registry` to use this feature."
|
1508
|
-
);
|
1509
|
-
return customElements;
|
1510
|
-
}
|
1144
|
+
const customElementMap = /* @__PURE__ */ new Map();
|
1145
|
+
const customElementTags = /* @__PURE__ */ new Set();
|
1146
|
+
const nativeRegistry = (() => {
|
1147
|
+
if (isServer) return;
|
1148
|
+
if (scoped) return new CustomElementRegistry();
|
1149
|
+
return customElements;
|
1511
1150
|
})();
|
1512
1151
|
return {
|
1513
|
-
|
1514
|
-
|
1515
|
-
|
1516
|
-
|
1152
|
+
__serverCss: /* @__PURE__ */ new Map(),
|
1153
|
+
__serverRenderOpts: /* @__PURE__ */ new Map(),
|
1154
|
+
define(tagName, ElementResult, options) {
|
1155
|
+
const isResult = "eject" in ElementResult;
|
1156
|
+
if (isServer) {
|
1157
|
+
if (isResult) ElementResult.register(this).define(tagName, options);
|
1158
|
+
return this;
|
1159
|
+
}
|
1160
|
+
const CustomElement = isResult ? ElementResult.eject() : ElementResult;
|
1161
|
+
if (customElementMap.has(CustomElement)) {
|
1162
|
+
console.warn(`Custom element class "${CustomElement.constructor.name}" was already defined. Skipping...`);
|
1163
|
+
return this;
|
1164
|
+
}
|
1165
|
+
if (customElementTags.has(tagName)) {
|
1166
|
+
console.warn(`Custom element tag name "${tagName}" was already defined. Skipping...`);
|
1167
|
+
return this;
|
1168
|
+
}
|
1169
|
+
customElementMap.set(CustomElement, tagName.toUpperCase());
|
1170
|
+
customElementTags.add(tagName);
|
1171
|
+
if (CustomElement === void 0) {
|
1172
|
+
console.error(`Custom element class for tag name "${tagName}" was not found. You must register it first.`);
|
1173
|
+
return this;
|
1174
|
+
}
|
1175
|
+
nativeRegistry?.define(tagName, CustomElement, options);
|
1176
|
+
return this;
|
1177
|
+
},
|
1178
|
+
getTagName: (ElementResult) => {
|
1179
|
+
const CustomElement = "eject" in ElementResult ? ElementResult.eject() : ElementResult;
|
1180
|
+
return customElementMap.get(CustomElement);
|
1181
|
+
},
|
1182
|
+
getAllTagNames: () => Array.from(customElementTags),
|
1183
|
+
eject: () => {
|
1184
|
+
if (nativeRegistry === void 0) {
|
1185
|
+
throw new Error("Cannot eject a registry on the server.");
|
1517
1186
|
}
|
1518
|
-
|
1187
|
+
return nativeRegistry;
|
1519
1188
|
},
|
1520
|
-
getTagName: (element) => registryResult.get(element),
|
1521
|
-
eject: () => registry,
|
1522
1189
|
scoped
|
1523
1190
|
};
|
1524
1191
|
};
|
1525
1192
|
export {
|
1193
|
+
clientOnlyCallback,
|
1526
1194
|
createEffect,
|
1527
1195
|
createRegistry,
|
1528
1196
|
createSignal,
|
1529
1197
|
css,
|
1530
1198
|
customElement,
|
1531
1199
|
derived,
|
1532
|
-
|
1200
|
+
html,
|
1201
|
+
insertTemplates,
|
1202
|
+
onServerDefine
|
1533
1203
|
};
|
1534
|
-
|
1535
|
-
|
1536
|
-
|
1537
|
-
|
1538
|
-
|
1204
|
+
/**
|
1205
|
+
* @license
|
1206
|
+
* Copyright (c) 2020 The Polymer Project Authors. All rights reserved.
|
1207
|
+
* This code may only be used under the BSD style license found at
|
1208
|
+
* http://polymer.github.io/LICENSE.txt
|
1209
|
+
* The complete set of authors may be found at
|
1210
|
+
* http://polymer.github.io/AUTHORS.txt
|
1211
|
+
* The complete set of contributors may be found at
|
1212
|
+
* http://polymer.github.io/CONTRIBUTORS.txt
|
1213
|
+
* Code distributed by Google as part of the polymer project is also
|
1214
|
+
* subject to an additional IP rights grant found at
|
1215
|
+
* http://polymer.github.io/PATENTS.txt
|
1216
|
+
*/
|