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.cjs
CHANGED
@@ -20,31 +20,468 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
|
|
20
20
|
// src/index.ts
|
21
21
|
var src_exports = {};
|
22
22
|
__export(src_exports, {
|
23
|
+
clientOnlyCallback: () => clientOnlyCallback,
|
23
24
|
createEffect: () => createEffect,
|
24
25
|
createRegistry: () => createRegistry,
|
25
26
|
createSignal: () => createSignal,
|
26
27
|
css: () => css,
|
27
28
|
customElement: () => customElement,
|
28
29
|
derived: () => derived,
|
29
|
-
html: () =>
|
30
|
+
html: () => html,
|
31
|
+
insertTemplates: () => insertTemplates,
|
32
|
+
onServerDefine: () => onServerDefine
|
30
33
|
});
|
31
34
|
module.exports = __toCommonJS(src_exports);
|
32
35
|
|
33
|
-
// src/
|
34
|
-
|
35
|
-
|
36
|
-
|
36
|
+
// vendor/@webcomponents/scoped-custom-element-registry/src/scoped-custom-element-registry.js
|
37
|
+
if (typeof window !== "undefined") {
|
38
|
+
if (!ShadowRoot.prototype.createElement) {
|
39
|
+
const NativeHTMLElement = window.HTMLElement;
|
40
|
+
const nativeDefine = window.customElements.define;
|
41
|
+
const nativeGet = window.customElements.get;
|
42
|
+
const nativeRegistry = window.customElements;
|
43
|
+
const definitionForElement = /* @__PURE__ */ new WeakMap();
|
44
|
+
const pendingRegistryForElement = /* @__PURE__ */ new WeakMap();
|
45
|
+
const globalDefinitionForConstructor = /* @__PURE__ */ new WeakMap();
|
46
|
+
const scopeForElement = /* @__PURE__ */ new WeakMap();
|
47
|
+
window.CustomElementRegistry = class {
|
48
|
+
constructor() {
|
49
|
+
this._definitionsByTag = /* @__PURE__ */ new Map();
|
50
|
+
this._definitionsByClass = /* @__PURE__ */ new Map();
|
51
|
+
this._whenDefinedPromises = /* @__PURE__ */ new Map();
|
52
|
+
this._awaitingUpgrade = /* @__PURE__ */ new Map();
|
53
|
+
}
|
54
|
+
define(tagName, elementClass) {
|
55
|
+
tagName = tagName.toLowerCase();
|
56
|
+
if (this._getDefinition(tagName) !== void 0) {
|
57
|
+
throw new DOMException(
|
58
|
+
`Failed to execute 'define' on 'CustomElementRegistry': the name "${tagName}" has already been used with this registry`
|
59
|
+
);
|
60
|
+
}
|
61
|
+
if (this._definitionsByClass.get(elementClass) !== void 0) {
|
62
|
+
throw new DOMException(
|
63
|
+
`Failed to execute 'define' on 'CustomElementRegistry': this constructor has already been used with this registry`
|
64
|
+
);
|
65
|
+
}
|
66
|
+
const attributeChangedCallback = elementClass.prototype.attributeChangedCallback;
|
67
|
+
const observedAttributes = new Set(elementClass.observedAttributes || []);
|
68
|
+
patchAttributes(
|
69
|
+
elementClass,
|
70
|
+
observedAttributes,
|
71
|
+
attributeChangedCallback
|
72
|
+
);
|
73
|
+
const definition = {
|
74
|
+
elementClass,
|
75
|
+
connectedCallback: elementClass.prototype.connectedCallback,
|
76
|
+
disconnectedCallback: elementClass.prototype.disconnectedCallback,
|
77
|
+
adoptedCallback: elementClass.prototype.adoptedCallback,
|
78
|
+
attributeChangedCallback,
|
79
|
+
"formAssociated": elementClass["formAssociated"],
|
80
|
+
"formAssociatedCallback": elementClass.prototype["formAssociatedCallback"],
|
81
|
+
"formDisabledCallback": elementClass.prototype["formDisabledCallback"],
|
82
|
+
"formResetCallback": elementClass.prototype["formResetCallback"],
|
83
|
+
"formStateRestoreCallback": elementClass.prototype["formStateRestoreCallback"],
|
84
|
+
observedAttributes
|
85
|
+
};
|
86
|
+
this._definitionsByTag.set(tagName, definition);
|
87
|
+
this._definitionsByClass.set(elementClass, definition);
|
88
|
+
let standInClass = nativeGet.call(nativeRegistry, tagName);
|
89
|
+
if (!standInClass) {
|
90
|
+
standInClass = createStandInElement(tagName);
|
91
|
+
nativeDefine.call(nativeRegistry, tagName, standInClass);
|
92
|
+
}
|
93
|
+
if (this === window.customElements) {
|
94
|
+
globalDefinitionForConstructor.set(elementClass, definition);
|
95
|
+
definition.standInClass = standInClass;
|
96
|
+
}
|
97
|
+
const awaiting = this._awaitingUpgrade.get(tagName);
|
98
|
+
if (awaiting) {
|
99
|
+
this._awaitingUpgrade.delete(tagName);
|
100
|
+
for (const element of awaiting) {
|
101
|
+
pendingRegistryForElement.delete(element);
|
102
|
+
customize(element, definition, true);
|
103
|
+
}
|
104
|
+
}
|
105
|
+
const info = this._whenDefinedPromises.get(tagName);
|
106
|
+
if (info !== void 0) {
|
107
|
+
info.resolve(elementClass);
|
108
|
+
this._whenDefinedPromises.delete(tagName);
|
109
|
+
}
|
110
|
+
return elementClass;
|
111
|
+
}
|
112
|
+
upgrade() {
|
113
|
+
creationContext.push(this);
|
114
|
+
nativeRegistry.upgrade.apply(nativeRegistry, arguments);
|
115
|
+
creationContext.pop();
|
116
|
+
}
|
117
|
+
get(tagName) {
|
118
|
+
const definition = this._definitionsByTag.get(tagName);
|
119
|
+
return definition?.elementClass;
|
120
|
+
}
|
121
|
+
_getDefinition(tagName) {
|
122
|
+
return this._definitionsByTag.get(tagName);
|
123
|
+
}
|
124
|
+
whenDefined(tagName) {
|
125
|
+
const definition = this._getDefinition(tagName);
|
126
|
+
if (definition !== void 0) {
|
127
|
+
return Promise.resolve(definition.elementClass);
|
128
|
+
}
|
129
|
+
let info = this._whenDefinedPromises.get(tagName);
|
130
|
+
if (info === void 0) {
|
131
|
+
info = {};
|
132
|
+
info.promise = new Promise((r) => info.resolve = r);
|
133
|
+
this._whenDefinedPromises.set(tagName, info);
|
134
|
+
}
|
135
|
+
return info.promise;
|
136
|
+
}
|
137
|
+
_upgradeWhenDefined(element, tagName, shouldUpgrade) {
|
138
|
+
let awaiting = this._awaitingUpgrade.get(tagName);
|
139
|
+
if (!awaiting) {
|
140
|
+
this._awaitingUpgrade.set(tagName, awaiting = /* @__PURE__ */ new Set());
|
141
|
+
}
|
142
|
+
if (shouldUpgrade) {
|
143
|
+
awaiting.add(element);
|
144
|
+
} else {
|
145
|
+
awaiting.delete(element);
|
146
|
+
}
|
147
|
+
}
|
148
|
+
};
|
149
|
+
let upgradingInstance;
|
150
|
+
window.HTMLElement = function HTMLElement2() {
|
151
|
+
let instance = upgradingInstance;
|
152
|
+
if (instance) {
|
153
|
+
upgradingInstance = void 0;
|
154
|
+
return instance;
|
155
|
+
}
|
156
|
+
const definition = globalDefinitionForConstructor.get(this.constructor);
|
157
|
+
if (!definition) {
|
158
|
+
throw new TypeError(
|
159
|
+
"Illegal constructor (custom element class must be registered with global customElements registry to be newable)"
|
160
|
+
);
|
161
|
+
}
|
162
|
+
instance = Reflect.construct(
|
163
|
+
NativeHTMLElement,
|
164
|
+
[],
|
165
|
+
definition.standInClass
|
166
|
+
);
|
167
|
+
Object.setPrototypeOf(instance, this.constructor.prototype);
|
168
|
+
definitionForElement.set(instance, definition);
|
169
|
+
return instance;
|
170
|
+
};
|
171
|
+
window.HTMLElement.prototype = NativeHTMLElement.prototype;
|
172
|
+
const isValidScope = (node) => node === document || node instanceof ShadowRoot;
|
173
|
+
const registryForNode = (node) => {
|
174
|
+
let scope = node.getRootNode();
|
175
|
+
if (!isValidScope(scope)) {
|
176
|
+
const context = creationContext[creationContext.length - 1];
|
177
|
+
if (context instanceof CustomElementRegistry) {
|
178
|
+
return context;
|
179
|
+
}
|
180
|
+
scope = context.getRootNode();
|
181
|
+
if (!isValidScope(scope)) {
|
182
|
+
scope = scopeForElement.get(scope)?.getRootNode() || document;
|
183
|
+
}
|
184
|
+
}
|
185
|
+
return scope.customElements;
|
186
|
+
};
|
187
|
+
const createStandInElement = (tagName) => {
|
188
|
+
return class ScopedCustomElementBase {
|
189
|
+
static get ["formAssociated"]() {
|
190
|
+
return true;
|
191
|
+
}
|
192
|
+
constructor() {
|
193
|
+
const instance = Reflect.construct(
|
194
|
+
NativeHTMLElement,
|
195
|
+
[],
|
196
|
+
this.constructor
|
197
|
+
);
|
198
|
+
Object.setPrototypeOf(instance, HTMLElement.prototype);
|
199
|
+
const registry = registryForNode(instance) || window.customElements;
|
200
|
+
const definition = registry._getDefinition(tagName);
|
201
|
+
if (definition) {
|
202
|
+
customize(instance, definition);
|
203
|
+
} else {
|
204
|
+
pendingRegistryForElement.set(instance, registry);
|
205
|
+
}
|
206
|
+
return instance;
|
207
|
+
}
|
208
|
+
connectedCallback() {
|
209
|
+
const definition = definitionForElement.get(this);
|
210
|
+
if (definition) {
|
211
|
+
definition.connectedCallback && definition.connectedCallback.apply(this, arguments);
|
212
|
+
} else {
|
213
|
+
pendingRegistryForElement.get(this)._upgradeWhenDefined(this, tagName, true);
|
214
|
+
}
|
215
|
+
}
|
216
|
+
disconnectedCallback() {
|
217
|
+
const definition = definitionForElement.get(this);
|
218
|
+
if (definition) {
|
219
|
+
definition.disconnectedCallback && definition.disconnectedCallback.apply(this, arguments);
|
220
|
+
} else {
|
221
|
+
pendingRegistryForElement.get(this)._upgradeWhenDefined(this, tagName, false);
|
222
|
+
}
|
223
|
+
}
|
224
|
+
adoptedCallback() {
|
225
|
+
const definition = definitionForElement.get(this);
|
226
|
+
definition?.adoptedCallback?.apply(this, arguments);
|
227
|
+
}
|
228
|
+
// Form-associated custom elements lifecycle methods
|
229
|
+
["formAssociatedCallback"]() {
|
230
|
+
const definition = definitionForElement.get(this);
|
231
|
+
if (definition && definition["formAssociated"]) {
|
232
|
+
definition?.["formAssociatedCallback"]?.apply(this, arguments);
|
233
|
+
}
|
234
|
+
}
|
235
|
+
["formDisabledCallback"]() {
|
236
|
+
const definition = definitionForElement.get(this);
|
237
|
+
if (definition?.["formAssociated"]) {
|
238
|
+
definition?.["formDisabledCallback"]?.apply(this, arguments);
|
239
|
+
}
|
240
|
+
}
|
241
|
+
["formResetCallback"]() {
|
242
|
+
const definition = definitionForElement.get(this);
|
243
|
+
if (definition?.["formAssociated"]) {
|
244
|
+
definition?.["formResetCallback"]?.apply(this, arguments);
|
245
|
+
}
|
246
|
+
}
|
247
|
+
["formStateRestoreCallback"]() {
|
248
|
+
const definition = definitionForElement.get(this);
|
249
|
+
if (definition?.["formAssociated"]) {
|
250
|
+
definition?.["formStateRestoreCallback"]?.apply(this, arguments);
|
251
|
+
}
|
252
|
+
}
|
253
|
+
// no attributeChangedCallback or observedAttributes since these
|
254
|
+
// are simulated via setAttribute/removeAttribute patches
|
255
|
+
};
|
256
|
+
};
|
257
|
+
const patchAttributes = (elementClass, observedAttributes, attributeChangedCallback) => {
|
258
|
+
if (observedAttributes.size === 0 || attributeChangedCallback === void 0) {
|
259
|
+
return;
|
260
|
+
}
|
261
|
+
const setAttribute = elementClass.prototype.setAttribute;
|
262
|
+
if (setAttribute) {
|
263
|
+
elementClass.prototype.setAttribute = function(n, value) {
|
264
|
+
const name = n.toLowerCase();
|
265
|
+
if (observedAttributes.has(name)) {
|
266
|
+
const old = this.getAttribute(name);
|
267
|
+
setAttribute.call(this, name, value);
|
268
|
+
attributeChangedCallback.call(this, name, old, value);
|
269
|
+
} else {
|
270
|
+
setAttribute.call(this, name, value);
|
271
|
+
}
|
272
|
+
};
|
273
|
+
}
|
274
|
+
const removeAttribute = elementClass.prototype.removeAttribute;
|
275
|
+
if (removeAttribute) {
|
276
|
+
elementClass.prototype.removeAttribute = function(n) {
|
277
|
+
const name = n.toLowerCase();
|
278
|
+
if (observedAttributes.has(name)) {
|
279
|
+
const old = this.getAttribute(name);
|
280
|
+
removeAttribute.call(this, name);
|
281
|
+
attributeChangedCallback.call(this, name, old, null);
|
282
|
+
} else {
|
283
|
+
removeAttribute.call(this, name);
|
284
|
+
}
|
285
|
+
};
|
286
|
+
}
|
287
|
+
const toggleAttribute = elementClass.prototype.toggleAttribute;
|
288
|
+
if (toggleAttribute) {
|
289
|
+
elementClass.prototype.toggleAttribute = function(n, force) {
|
290
|
+
const name = n.toLowerCase();
|
291
|
+
if (observedAttributes.has(name)) {
|
292
|
+
const old = this.getAttribute(name);
|
293
|
+
toggleAttribute.call(this, name, force);
|
294
|
+
const newValue = this.getAttribute(name);
|
295
|
+
attributeChangedCallback.call(this, name, old, newValue);
|
296
|
+
} else {
|
297
|
+
toggleAttribute.call(this, name, force);
|
298
|
+
}
|
299
|
+
};
|
300
|
+
}
|
301
|
+
};
|
302
|
+
const patchHTMLElement = (elementClass) => {
|
303
|
+
const parentClass = Object.getPrototypeOf(elementClass);
|
304
|
+
if (parentClass !== window.HTMLElement) {
|
305
|
+
if (parentClass === NativeHTMLElement) {
|
306
|
+
return Object.setPrototypeOf(elementClass, window.HTMLElement);
|
307
|
+
}
|
308
|
+
return patchHTMLElement(parentClass);
|
309
|
+
}
|
310
|
+
};
|
311
|
+
const customize = (instance, definition, isUpgrade = false) => {
|
312
|
+
Object.setPrototypeOf(instance, definition.elementClass.prototype);
|
313
|
+
definitionForElement.set(instance, definition);
|
314
|
+
upgradingInstance = instance;
|
315
|
+
try {
|
316
|
+
new definition.elementClass();
|
317
|
+
} catch (_) {
|
318
|
+
patchHTMLElement(definition.elementClass);
|
319
|
+
new definition.elementClass();
|
320
|
+
}
|
321
|
+
if (definition.attributeChangedCallback) {
|
322
|
+
definition.observedAttributes.forEach((attr) => {
|
323
|
+
if (instance.hasAttribute(attr)) {
|
324
|
+
definition.attributeChangedCallback.call(
|
325
|
+
instance,
|
326
|
+
attr,
|
327
|
+
null,
|
328
|
+
instance.getAttribute(attr)
|
329
|
+
);
|
330
|
+
}
|
331
|
+
});
|
332
|
+
}
|
333
|
+
if (isUpgrade && definition.connectedCallback && instance.isConnected) {
|
334
|
+
definition.connectedCallback.call(instance);
|
335
|
+
}
|
336
|
+
};
|
337
|
+
const nativeAttachShadow = Element.prototype.attachShadow;
|
338
|
+
Element.prototype.attachShadow = function(init) {
|
339
|
+
const shadowRoot = nativeAttachShadow.apply(this, arguments);
|
340
|
+
if (init.customElements) {
|
341
|
+
shadowRoot.customElements = init.customElements;
|
342
|
+
}
|
343
|
+
return shadowRoot;
|
344
|
+
};
|
345
|
+
let creationContext = [document];
|
346
|
+
const installScopedCreationMethod = (ctor, method, from = void 0) => {
|
347
|
+
const native = (from ? Object.getPrototypeOf(from) : ctor.prototype)[method];
|
348
|
+
ctor.prototype[method] = function() {
|
349
|
+
creationContext.push(this);
|
350
|
+
const ret = native.apply(from || this, arguments);
|
351
|
+
if (ret !== void 0) {
|
352
|
+
scopeForElement.set(ret, this);
|
353
|
+
}
|
354
|
+
creationContext.pop();
|
355
|
+
return ret;
|
356
|
+
};
|
357
|
+
};
|
358
|
+
installScopedCreationMethod(ShadowRoot, "createElement", document);
|
359
|
+
installScopedCreationMethod(ShadowRoot, "importNode", document);
|
360
|
+
installScopedCreationMethod(Element, "insertAdjacentHTML");
|
361
|
+
installScopedCreationMethod(Node, "appendChild");
|
362
|
+
installScopedCreationMethod(Element, "append");
|
363
|
+
const installScopedCreationSetter = (ctor, name) => {
|
364
|
+
const descriptor = Object.getOwnPropertyDescriptor(ctor.prototype, name);
|
365
|
+
Object.defineProperty(ctor.prototype, name, {
|
366
|
+
...descriptor,
|
367
|
+
set(value) {
|
368
|
+
creationContext.push(this);
|
369
|
+
descriptor.set.call(this, value);
|
370
|
+
creationContext.pop();
|
371
|
+
}
|
372
|
+
});
|
373
|
+
};
|
374
|
+
installScopedCreationSetter(Element, "innerHTML");
|
375
|
+
installScopedCreationSetter(ShadowRoot, "innerHTML");
|
376
|
+
Object.defineProperty(window, "customElements", {
|
377
|
+
value: new CustomElementRegistry(),
|
378
|
+
configurable: true,
|
379
|
+
writable: true
|
380
|
+
});
|
381
|
+
if (!!window["ElementInternals"] && !!window["ElementInternals"].prototype["setFormValue"]) {
|
382
|
+
const internalsToHostMap = /* @__PURE__ */ new WeakMap();
|
383
|
+
const attachInternals = HTMLElement.prototype["attachInternals"];
|
384
|
+
const methods = [
|
385
|
+
"setFormValue",
|
386
|
+
"setValidity",
|
387
|
+
"checkValidity",
|
388
|
+
"reportValidity"
|
389
|
+
];
|
390
|
+
HTMLElement.prototype["attachInternals"] = function(...args) {
|
391
|
+
const internals = attachInternals.call(this, ...args);
|
392
|
+
internalsToHostMap.set(internals, this);
|
393
|
+
return internals;
|
394
|
+
};
|
395
|
+
methods.forEach((method) => {
|
396
|
+
const proto = window["ElementInternals"].prototype;
|
397
|
+
const originalMethod = proto[method];
|
398
|
+
proto[method] = function(...args) {
|
399
|
+
const host = internalsToHostMap.get(this);
|
400
|
+
const definition = definitionForElement.get(host);
|
401
|
+
if (definition["formAssociated"] === true) {
|
402
|
+
return originalMethod?.call(this, ...args);
|
403
|
+
} else {
|
404
|
+
throw new DOMException(
|
405
|
+
`Failed to execute ${originalMethod} on 'ElementInternals': The target element is not a form-associated custom element.`
|
406
|
+
);
|
407
|
+
}
|
408
|
+
};
|
409
|
+
});
|
410
|
+
class RadioNodeList extends Array {
|
411
|
+
constructor(elements) {
|
412
|
+
super(...elements);
|
413
|
+
this._elements = elements;
|
414
|
+
}
|
415
|
+
get ["value"]() {
|
416
|
+
return this._elements.find((element) => element["checked"] === true)?.value || "";
|
417
|
+
}
|
418
|
+
}
|
419
|
+
class HTMLFormControlsCollection {
|
420
|
+
constructor(elements) {
|
421
|
+
const entries = /* @__PURE__ */ new Map();
|
422
|
+
elements.forEach((element, index) => {
|
423
|
+
const name = element.getAttribute("name");
|
424
|
+
const nameReference = entries.get(name) || [];
|
425
|
+
this[+index] = element;
|
426
|
+
nameReference.push(element);
|
427
|
+
entries.set(name, nameReference);
|
428
|
+
});
|
429
|
+
this["length"] = elements.length;
|
430
|
+
entries.forEach((value, key) => {
|
431
|
+
if (!value) return;
|
432
|
+
if (value.length === 1) {
|
433
|
+
this[key] = value[0];
|
434
|
+
} else {
|
435
|
+
this[key] = new RadioNodeList(value);
|
436
|
+
}
|
437
|
+
});
|
438
|
+
}
|
439
|
+
["namedItem"](key) {
|
440
|
+
return this[key];
|
441
|
+
}
|
442
|
+
}
|
443
|
+
const formElementsDescriptor = Object.getOwnPropertyDescriptor(
|
444
|
+
HTMLFormElement.prototype,
|
445
|
+
"elements"
|
446
|
+
);
|
447
|
+
Object.defineProperty(HTMLFormElement.prototype, "elements", {
|
448
|
+
get: function() {
|
449
|
+
const nativeElements = formElementsDescriptor.get.call(this, []);
|
450
|
+
const include = [];
|
451
|
+
for (const element of nativeElements) {
|
452
|
+
const definition = definitionForElement.get(element);
|
453
|
+
if (!definition || definition["formAssociated"] === true) {
|
454
|
+
include.push(element);
|
455
|
+
}
|
456
|
+
}
|
457
|
+
return new HTMLFormControlsCollection(include);
|
458
|
+
}
|
459
|
+
});
|
460
|
+
}
|
461
|
+
}
|
462
|
+
class TrackableCustomElementRegistry extends window.CustomElementRegistry {
|
463
|
+
__tagNames = /* @__PURE__ */ new Set();
|
464
|
+
define(tagName, constructor, options) {
|
465
|
+
super.define(tagName, constructor, options);
|
466
|
+
this.__tagNames.add(tagName);
|
467
|
+
}
|
468
|
+
}
|
469
|
+
window.CustomElementRegistry = TrackableCustomElementRegistry;
|
470
|
+
}
|
471
|
+
|
472
|
+
// src/constants.ts
|
473
|
+
var DEFAULT_RENDER_OPTIONS = {
|
474
|
+
formAssociated: false,
|
475
|
+
observedAttributes: [],
|
476
|
+
attributesAsProperties: [],
|
477
|
+
attachShadow: true,
|
478
|
+
shadowRootOptions: {
|
479
|
+
mode: "closed",
|
480
|
+
delegatesFocus: false,
|
481
|
+
clonable: false,
|
482
|
+
serializable: false,
|
483
|
+
slotAssignment: "named"
|
37
484
|
}
|
38
|
-
};
|
39
|
-
var parseFragment = (htmlStr) => {
|
40
|
-
const range = document.createRange();
|
41
|
-
range.selectNode(document.body);
|
42
|
-
return range.createContextualFragment(htmlStr);
|
43
|
-
};
|
44
|
-
var setInnerHTML = (element, html3) => {
|
45
|
-
clearHTML(element);
|
46
|
-
const fragment = typeof html3 === "string" ? parseFragment(html3) : html3;
|
47
|
-
element.append(fragment);
|
48
485
|
};
|
49
486
|
|
50
487
|
// src/signals.ts
|
@@ -58,8 +495,8 @@ var createSignal = (initVal, options) => {
|
|
58
495
|
if (subscriber !== null) {
|
59
496
|
subscribers.add(subscriber);
|
60
497
|
}
|
61
|
-
if (options?.debugMode || getterOptions?.debugMode) {
|
62
|
-
|
498
|
+
if (options?.debugMode === true || getterOptions?.debugMode === true) {
|
499
|
+
queueMicrotask(() => {
|
63
500
|
let label = "anonymous signal";
|
64
501
|
if (options?.label !== void 0) {
|
65
502
|
label = `(${options.label})`;
|
@@ -84,7 +521,7 @@ var createSignal = (initVal, options) => {
|
|
84
521
|
}
|
85
522
|
if (!isBatchingUpdates) {
|
86
523
|
isBatchingUpdates = true;
|
87
|
-
|
524
|
+
queueMicrotask(() => {
|
88
525
|
for (const fn of updateQueue) {
|
89
526
|
try {
|
90
527
|
fn();
|
@@ -92,7 +529,7 @@ var createSignal = (initVal, options) => {
|
|
92
529
|
console.error("Error in subscriber:", { error, oldValue, newValue, fn });
|
93
530
|
}
|
94
531
|
}
|
95
|
-
if (options?.debugMode || setterOptions?.debugMode) {
|
532
|
+
if (options?.debugMode === true || setterOptions?.debugMode === true) {
|
96
533
|
let label = "anonymous signal";
|
97
534
|
if (options?.label !== void 0) {
|
98
535
|
label = `(${options.label})`;
|
@@ -132,973 +569,150 @@ var createEffect = (fn) => {
|
|
132
569
|
subscriber = null;
|
133
570
|
};
|
134
571
|
|
135
|
-
//
|
136
|
-
var
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
var {
|
149
|
-
apply,
|
150
|
-
construct
|
151
|
-
} = typeof Reflect !== "undefined" && Reflect;
|
152
|
-
if (!freeze) {
|
153
|
-
freeze = function freeze2(x) {
|
154
|
-
return x;
|
155
|
-
};
|
156
|
-
}
|
157
|
-
if (!seal) {
|
158
|
-
seal = function seal2(x) {
|
159
|
-
return x;
|
160
|
-
};
|
161
|
-
}
|
162
|
-
if (!apply) {
|
163
|
-
apply = function apply2(fun, thisValue, args) {
|
164
|
-
return fun.apply(thisValue, args);
|
165
|
-
};
|
166
|
-
}
|
167
|
-
if (!construct) {
|
168
|
-
construct = function construct2(Func, args) {
|
169
|
-
return new Func(...args);
|
170
|
-
};
|
171
|
-
}
|
172
|
-
var arrayForEach = unapply(Array.prototype.forEach);
|
173
|
-
var arrayPop = unapply(Array.prototype.pop);
|
174
|
-
var arrayPush = unapply(Array.prototype.push);
|
175
|
-
var stringToLowerCase = unapply(String.prototype.toLowerCase);
|
176
|
-
var stringToString = unapply(String.prototype.toString);
|
177
|
-
var stringMatch = unapply(String.prototype.match);
|
178
|
-
var stringReplace = unapply(String.prototype.replace);
|
179
|
-
var stringIndexOf = unapply(String.prototype.indexOf);
|
180
|
-
var stringTrim = unapply(String.prototype.trim);
|
181
|
-
var objectHasOwnProperty = unapply(Object.prototype.hasOwnProperty);
|
182
|
-
var regExpTest = unapply(RegExp.prototype.test);
|
183
|
-
var typeErrorCreate = unconstruct(TypeError);
|
184
|
-
function unapply(func) {
|
185
|
-
return function(thisArg) {
|
186
|
-
for (var _len = arguments.length, args = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
|
187
|
-
args[_key - 1] = arguments[_key];
|
188
|
-
}
|
189
|
-
return apply(func, thisArg, args);
|
190
|
-
};
|
191
|
-
}
|
192
|
-
function unconstruct(func) {
|
193
|
-
return function() {
|
194
|
-
for (var _len2 = arguments.length, args = new Array(_len2), _key2 = 0; _key2 < _len2; _key2++) {
|
195
|
-
args[_key2] = arguments[_key2];
|
196
|
-
}
|
197
|
-
return construct(func, args);
|
198
|
-
};
|
199
|
-
}
|
200
|
-
function addToSet(set, array) {
|
201
|
-
let transformCaseFunc = arguments.length > 2 && arguments[2] !== void 0 ? arguments[2] : stringToLowerCase;
|
202
|
-
if (setPrototypeOf) {
|
203
|
-
setPrototypeOf(set, null);
|
204
|
-
}
|
205
|
-
let l = array.length;
|
206
|
-
while (l--) {
|
207
|
-
let element = array[l];
|
208
|
-
if (typeof element === "string") {
|
209
|
-
const lcElement = transformCaseFunc(element);
|
210
|
-
if (lcElement !== element) {
|
211
|
-
if (!isFrozen(array)) {
|
212
|
-
array[l] = lcElement;
|
213
|
-
}
|
214
|
-
element = lcElement;
|
215
|
-
}
|
216
|
-
}
|
217
|
-
set[element] = true;
|
218
|
-
}
|
219
|
-
return set;
|
220
|
-
}
|
221
|
-
function cleanArray(array) {
|
222
|
-
for (let index = 0; index < array.length; index++) {
|
223
|
-
const isPropertyExist = objectHasOwnProperty(array, index);
|
224
|
-
if (!isPropertyExist) {
|
225
|
-
array[index] = null;
|
226
|
-
}
|
227
|
-
}
|
228
|
-
return array;
|
229
|
-
}
|
230
|
-
function clone(object) {
|
231
|
-
const newObject = create(null);
|
232
|
-
for (const [property, value] of entries(object)) {
|
233
|
-
const isPropertyExist = objectHasOwnProperty(object, property);
|
234
|
-
if (isPropertyExist) {
|
235
|
-
if (Array.isArray(value)) {
|
236
|
-
newObject[property] = cleanArray(value);
|
237
|
-
} else if (value && typeof value === "object" && value.constructor === Object) {
|
238
|
-
newObject[property] = clone(value);
|
239
|
-
} else {
|
240
|
-
newObject[property] = value;
|
241
|
-
}
|
242
|
-
}
|
572
|
+
// src/utilities.ts
|
573
|
+
var NOOP = () => void 0;
|
574
|
+
|
575
|
+
// src/server-side.ts
|
576
|
+
var isServer = typeof window === "undefined";
|
577
|
+
var serverDefineFns = /* @__PURE__ */ new Set();
|
578
|
+
var onServerDefine = (fn) => {
|
579
|
+
serverDefineFns.add(fn);
|
580
|
+
};
|
581
|
+
var serverDefine = ({ tagName, serverRender, options, scopedRegistry, parentRegistry }) => {
|
582
|
+
if (parentRegistry !== void 0) {
|
583
|
+
parentRegistry.__serverRenderOpts.set(tagName, { serverRender, ...options });
|
584
|
+
if (parentRegistry.scoped) return;
|
243
585
|
}
|
244
|
-
|
245
|
-
|
246
|
-
|
247
|
-
|
248
|
-
|
249
|
-
|
250
|
-
|
251
|
-
|
252
|
-
|
253
|
-
|
254
|
-
|
586
|
+
for (const fn of serverDefineFns) {
|
587
|
+
let result = serverRender(getServerRenderArgs(tagName));
|
588
|
+
result = wrapTemplate({
|
589
|
+
tagName,
|
590
|
+
serverRender,
|
591
|
+
options
|
592
|
+
});
|
593
|
+
if (scopedRegistry !== void 0) {
|
594
|
+
for (const [scopedTagName, scopedRenderOptions] of scopedRegistry.__serverRenderOpts) {
|
595
|
+
const { serverRender: serverRender2, ...scopedOptions } = scopedRenderOptions;
|
596
|
+
let template = serverRender2(getServerRenderArgs(scopedTagName, scopedRegistry));
|
597
|
+
template = wrapTemplate({
|
598
|
+
tagName: scopedTagName,
|
599
|
+
serverRender: serverRender2,
|
600
|
+
options: scopedOptions
|
601
|
+
});
|
602
|
+
result = insertTemplates(scopedTagName, template, result);
|
255
603
|
}
|
256
604
|
}
|
257
|
-
|
258
|
-
}
|
259
|
-
function fallbackValue() {
|
260
|
-
return null;
|
605
|
+
fn(tagName, result);
|
261
606
|
}
|
262
|
-
return fallbackValue;
|
263
|
-
}
|
264
|
-
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"]);
|
265
|
-
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"]);
|
266
|
-
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"]);
|
267
|
-
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"]);
|
268
|
-
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"]);
|
269
|
-
var mathMlDisallowed = freeze(["maction", "maligngroup", "malignmark", "mlongdiv", "mscarries", "mscarry", "msgroup", "mstack", "msline", "msrow", "semantics", "annotation", "annotation-xml", "mprescripts", "none"]);
|
270
|
-
var text = freeze(["#text"]);
|
271
|
-
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"]);
|
272
|
-
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"]);
|
273
|
-
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"]);
|
274
|
-
var xml = freeze(["xlink:href", "xml:id", "xlink:title", "xml:space", "xmlns:xlink"]);
|
275
|
-
var MUSTACHE_EXPR = seal(/\{\{[\w\W]*|[\w\W]*\}\}/gm);
|
276
|
-
var ERB_EXPR = seal(/<%[\w\W]*|[\w\W]*%>/gm);
|
277
|
-
var TMPLIT_EXPR = seal(/\${[\w\W]*}/gm);
|
278
|
-
var DATA_ATTR = seal(/^data-[\-\w.\u00B7-\uFFFF]/);
|
279
|
-
var ARIA_ATTR = seal(/^aria-[\-\w]+$/);
|
280
|
-
var IS_ALLOWED_URI = seal(
|
281
|
-
/^(?:(?:(?:f|ht)tps?|mailto|tel|callto|sms|cid|xmpp):|[^a-z]|[a-z+.\-]+(?:[^a-z+.\-:]|$))/i
|
282
|
-
// eslint-disable-line no-useless-escape
|
283
|
-
);
|
284
|
-
var IS_SCRIPT_OR_DATA = seal(/^(?:\w+script|data):/i);
|
285
|
-
var ATTR_WHITESPACE = seal(
|
286
|
-
/[\u0000-\u0020\u00A0\u1680\u180E\u2000-\u2029\u205F\u3000]/g
|
287
|
-
// eslint-disable-line no-control-regex
|
288
|
-
);
|
289
|
-
var DOCTYPE_NAME = seal(/^html$/i);
|
290
|
-
var CUSTOM_ELEMENT = seal(/^[a-z][.\w]*(-[.\w]+)+$/i);
|
291
|
-
var EXPRESSIONS = /* @__PURE__ */ Object.freeze({
|
292
|
-
__proto__: null,
|
293
|
-
ARIA_ATTR,
|
294
|
-
ATTR_WHITESPACE,
|
295
|
-
CUSTOM_ELEMENT,
|
296
|
-
DATA_ATTR,
|
297
|
-
DOCTYPE_NAME,
|
298
|
-
ERB_EXPR,
|
299
|
-
IS_ALLOWED_URI,
|
300
|
-
IS_SCRIPT_OR_DATA,
|
301
|
-
MUSTACHE_EXPR,
|
302
|
-
TMPLIT_EXPR
|
303
|
-
});
|
304
|
-
var NODE_TYPE = {
|
305
|
-
element: 1,
|
306
|
-
attribute: 2,
|
307
|
-
text: 3,
|
308
|
-
cdataSection: 4,
|
309
|
-
entityReference: 5,
|
310
|
-
// Deprecated
|
311
|
-
entityNode: 6,
|
312
|
-
// Deprecated
|
313
|
-
progressingInstruction: 7,
|
314
|
-
comment: 8,
|
315
|
-
document: 9,
|
316
|
-
documentType: 10,
|
317
|
-
documentFragment: 11,
|
318
|
-
notation: 12
|
319
|
-
// Deprecated
|
320
607
|
};
|
321
|
-
var
|
322
|
-
|
323
|
-
|
324
|
-
|
325
|
-
|
326
|
-
|
327
|
-
}
|
328
|
-
let suffix = null;
|
329
|
-
const ATTR_NAME = "data-tt-policy-suffix";
|
330
|
-
if (purifyHostElement && purifyHostElement.hasAttribute(ATTR_NAME)) {
|
331
|
-
suffix = purifyHostElement.getAttribute(ATTR_NAME);
|
332
|
-
}
|
333
|
-
const policyName = "dompurify" + (suffix ? "#" + suffix : "");
|
334
|
-
try {
|
335
|
-
return trustedTypes.createPolicy(policyName, {
|
336
|
-
createHTML(html3) {
|
337
|
-
return html3;
|
338
|
-
},
|
339
|
-
createScriptURL(scriptUrl) {
|
340
|
-
return scriptUrl;
|
608
|
+
var serverCss = /* @__PURE__ */ new Map();
|
609
|
+
var getServerRenderArgs = (tagName, registry) => ({
|
610
|
+
get elementRef() {
|
611
|
+
return new Proxy({}, {
|
612
|
+
get: () => {
|
613
|
+
throw new Error("The `elementRef` property is not available on the server.");
|
341
614
|
}
|
342
615
|
});
|
343
|
-
}
|
344
|
-
|
345
|
-
return
|
346
|
-
|
347
|
-
|
348
|
-
function createDOMPurify() {
|
349
|
-
let window2 = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : getGlobal();
|
350
|
-
const DOMPurify = (root) => createDOMPurify(root);
|
351
|
-
DOMPurify.version = "3.2.1";
|
352
|
-
DOMPurify.removed = [];
|
353
|
-
if (!window2 || !window2.document || window2.document.nodeType !== NODE_TYPE.document) {
|
354
|
-
DOMPurify.isSupported = false;
|
355
|
-
return DOMPurify;
|
356
|
-
}
|
357
|
-
let {
|
358
|
-
document: document2
|
359
|
-
} = window2;
|
360
|
-
const originalDocument = document2;
|
361
|
-
const currentScript = originalDocument.currentScript;
|
362
|
-
const {
|
363
|
-
DocumentFragment: DocumentFragment2,
|
364
|
-
HTMLTemplateElement,
|
365
|
-
Node,
|
366
|
-
Element: Element2,
|
367
|
-
NodeFilter,
|
368
|
-
NamedNodeMap = window2.NamedNodeMap || window2.MozNamedAttrMap,
|
369
|
-
HTMLFormElement,
|
370
|
-
DOMParser,
|
371
|
-
trustedTypes
|
372
|
-
} = window2;
|
373
|
-
const ElementPrototype = Element2.prototype;
|
374
|
-
const cloneNode = lookupGetter(ElementPrototype, "cloneNode");
|
375
|
-
const remove = lookupGetter(ElementPrototype, "remove");
|
376
|
-
const getNextSibling = lookupGetter(ElementPrototype, "nextSibling");
|
377
|
-
const getChildNodes = lookupGetter(ElementPrototype, "childNodes");
|
378
|
-
const getParentNode = lookupGetter(ElementPrototype, "parentNode");
|
379
|
-
if (typeof HTMLTemplateElement === "function") {
|
380
|
-
const template = document2.createElement("template");
|
381
|
-
if (template.content && template.content.ownerDocument) {
|
382
|
-
document2 = template.content.ownerDocument;
|
383
|
-
}
|
384
|
-
}
|
385
|
-
let trustedTypesPolicy;
|
386
|
-
let emptyHTML = "";
|
387
|
-
const {
|
388
|
-
implementation,
|
389
|
-
createNodeIterator,
|
390
|
-
createDocumentFragment,
|
391
|
-
getElementsByTagName
|
392
|
-
} = document2;
|
393
|
-
const {
|
394
|
-
importNode
|
395
|
-
} = originalDocument;
|
396
|
-
let hooks = {};
|
397
|
-
DOMPurify.isSupported = typeof entries === "function" && typeof getParentNode === "function" && implementation && implementation.createHTMLDocument !== void 0;
|
398
|
-
const {
|
399
|
-
MUSTACHE_EXPR: MUSTACHE_EXPR2,
|
400
|
-
ERB_EXPR: ERB_EXPR2,
|
401
|
-
TMPLIT_EXPR: TMPLIT_EXPR2,
|
402
|
-
DATA_ATTR: DATA_ATTR2,
|
403
|
-
ARIA_ATTR: ARIA_ATTR2,
|
404
|
-
IS_SCRIPT_OR_DATA: IS_SCRIPT_OR_DATA2,
|
405
|
-
ATTR_WHITESPACE: ATTR_WHITESPACE2,
|
406
|
-
CUSTOM_ELEMENT: CUSTOM_ELEMENT2
|
407
|
-
} = EXPRESSIONS;
|
408
|
-
let {
|
409
|
-
IS_ALLOWED_URI: IS_ALLOWED_URI$1
|
410
|
-
} = EXPRESSIONS;
|
411
|
-
let ALLOWED_TAGS = null;
|
412
|
-
const DEFAULT_ALLOWED_TAGS = addToSet({}, [...html$1, ...svg$1, ...svgFilters, ...mathMl$1, ...text]);
|
413
|
-
let ALLOWED_ATTR = null;
|
414
|
-
const DEFAULT_ALLOWED_ATTR = addToSet({}, [...html, ...svg, ...mathMl, ...xml]);
|
415
|
-
let CUSTOM_ELEMENT_HANDLING = Object.seal(create(null, {
|
416
|
-
tagNameCheck: {
|
417
|
-
writable: true,
|
418
|
-
configurable: false,
|
419
|
-
enumerable: true,
|
420
|
-
value: null
|
421
|
-
},
|
422
|
-
attributeNameCheck: {
|
423
|
-
writable: true,
|
424
|
-
configurable: false,
|
425
|
-
enumerable: true,
|
426
|
-
value: null
|
427
|
-
},
|
428
|
-
allowCustomizedBuiltInElements: {
|
429
|
-
writable: true,
|
430
|
-
configurable: false,
|
431
|
-
enumerable: true,
|
432
|
-
value: false
|
433
|
-
}
|
434
|
-
}));
|
435
|
-
let FORBID_TAGS = null;
|
436
|
-
let FORBID_ATTR = null;
|
437
|
-
let ALLOW_ARIA_ATTR = true;
|
438
|
-
let ALLOW_DATA_ATTR = true;
|
439
|
-
let ALLOW_UNKNOWN_PROTOCOLS = false;
|
440
|
-
let ALLOW_SELF_CLOSE_IN_ATTR = true;
|
441
|
-
let SAFE_FOR_TEMPLATES = false;
|
442
|
-
let SAFE_FOR_XML = true;
|
443
|
-
let WHOLE_DOCUMENT = false;
|
444
|
-
let SET_CONFIG = false;
|
445
|
-
let FORCE_BODY = false;
|
446
|
-
let RETURN_DOM = false;
|
447
|
-
let RETURN_DOM_FRAGMENT = false;
|
448
|
-
let RETURN_TRUSTED_TYPE = false;
|
449
|
-
let SANITIZE_DOM = true;
|
450
|
-
let SANITIZE_NAMED_PROPS = false;
|
451
|
-
const SANITIZE_NAMED_PROPS_PREFIX = "user-content-";
|
452
|
-
let KEEP_CONTENT = true;
|
453
|
-
let IN_PLACE = false;
|
454
|
-
let USE_PROFILES = {};
|
455
|
-
let FORBID_CONTENTS = null;
|
456
|
-
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"]);
|
457
|
-
let DATA_URI_TAGS = null;
|
458
|
-
const DEFAULT_DATA_URI_TAGS = addToSet({}, ["audio", "video", "img", "source", "image", "track"]);
|
459
|
-
let URI_SAFE_ATTRIBUTES = null;
|
460
|
-
const DEFAULT_URI_SAFE_ATTRIBUTES = addToSet({}, ["alt", "class", "for", "id", "label", "name", "pattern", "placeholder", "role", "summary", "title", "value", "style", "xmlns"]);
|
461
|
-
const MATHML_NAMESPACE = "http://www.w3.org/1998/Math/MathML";
|
462
|
-
const SVG_NAMESPACE = "http://www.w3.org/2000/svg";
|
463
|
-
const HTML_NAMESPACE = "http://www.w3.org/1999/xhtml";
|
464
|
-
let NAMESPACE = HTML_NAMESPACE;
|
465
|
-
let IS_EMPTY_INPUT = false;
|
466
|
-
let ALLOWED_NAMESPACES = null;
|
467
|
-
const DEFAULT_ALLOWED_NAMESPACES = addToSet({}, [MATHML_NAMESPACE, SVG_NAMESPACE, HTML_NAMESPACE], stringToString);
|
468
|
-
let MATHML_TEXT_INTEGRATION_POINTS = addToSet({}, ["mi", "mo", "mn", "ms", "mtext"]);
|
469
|
-
let HTML_INTEGRATION_POINTS = addToSet({}, ["annotation-xml"]);
|
470
|
-
const COMMON_SVG_AND_HTML_ELEMENTS = addToSet({}, ["title", "style", "font", "a", "script"]);
|
471
|
-
let PARSER_MEDIA_TYPE = null;
|
472
|
-
const SUPPORTED_PARSER_MEDIA_TYPES = ["application/xhtml+xml", "text/html"];
|
473
|
-
const DEFAULT_PARSER_MEDIA_TYPE = "text/html";
|
474
|
-
let transformCaseFunc = null;
|
475
|
-
let CONFIG = null;
|
476
|
-
const formElement = document2.createElement("form");
|
477
|
-
const isRegexOrFunction = function isRegexOrFunction2(testValue) {
|
478
|
-
return testValue instanceof RegExp || testValue instanceof Function;
|
479
|
-
};
|
480
|
-
const _parseConfig = function _parseConfig2() {
|
481
|
-
let cfg = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : {};
|
482
|
-
if (CONFIG && CONFIG === cfg) {
|
483
|
-
return;
|
484
|
-
}
|
485
|
-
if (!cfg || typeof cfg !== "object") {
|
486
|
-
cfg = {};
|
487
|
-
}
|
488
|
-
cfg = clone(cfg);
|
489
|
-
PARSER_MEDIA_TYPE = // eslint-disable-next-line unicorn/prefer-includes
|
490
|
-
SUPPORTED_PARSER_MEDIA_TYPES.indexOf(cfg.PARSER_MEDIA_TYPE) === -1 ? DEFAULT_PARSER_MEDIA_TYPE : cfg.PARSER_MEDIA_TYPE;
|
491
|
-
transformCaseFunc = PARSER_MEDIA_TYPE === "application/xhtml+xml" ? stringToString : stringToLowerCase;
|
492
|
-
ALLOWED_TAGS = objectHasOwnProperty(cfg, "ALLOWED_TAGS") ? addToSet({}, cfg.ALLOWED_TAGS, transformCaseFunc) : DEFAULT_ALLOWED_TAGS;
|
493
|
-
ALLOWED_ATTR = objectHasOwnProperty(cfg, "ALLOWED_ATTR") ? addToSet({}, cfg.ALLOWED_ATTR, transformCaseFunc) : DEFAULT_ALLOWED_ATTR;
|
494
|
-
ALLOWED_NAMESPACES = objectHasOwnProperty(cfg, "ALLOWED_NAMESPACES") ? addToSet({}, cfg.ALLOWED_NAMESPACES, stringToString) : DEFAULT_ALLOWED_NAMESPACES;
|
495
|
-
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;
|
496
|
-
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;
|
497
|
-
FORBID_CONTENTS = objectHasOwnProperty(cfg, "FORBID_CONTENTS") ? addToSet({}, cfg.FORBID_CONTENTS, transformCaseFunc) : DEFAULT_FORBID_CONTENTS;
|
498
|
-
FORBID_TAGS = objectHasOwnProperty(cfg, "FORBID_TAGS") ? addToSet({}, cfg.FORBID_TAGS, transformCaseFunc) : {};
|
499
|
-
FORBID_ATTR = objectHasOwnProperty(cfg, "FORBID_ATTR") ? addToSet({}, cfg.FORBID_ATTR, transformCaseFunc) : {};
|
500
|
-
USE_PROFILES = objectHasOwnProperty(cfg, "USE_PROFILES") ? cfg.USE_PROFILES : false;
|
501
|
-
ALLOW_ARIA_ATTR = cfg.ALLOW_ARIA_ATTR !== false;
|
502
|
-
ALLOW_DATA_ATTR = cfg.ALLOW_DATA_ATTR !== false;
|
503
|
-
ALLOW_UNKNOWN_PROTOCOLS = cfg.ALLOW_UNKNOWN_PROTOCOLS || false;
|
504
|
-
ALLOW_SELF_CLOSE_IN_ATTR = cfg.ALLOW_SELF_CLOSE_IN_ATTR !== false;
|
505
|
-
SAFE_FOR_TEMPLATES = cfg.SAFE_FOR_TEMPLATES || false;
|
506
|
-
SAFE_FOR_XML = cfg.SAFE_FOR_XML !== false;
|
507
|
-
WHOLE_DOCUMENT = cfg.WHOLE_DOCUMENT || false;
|
508
|
-
RETURN_DOM = cfg.RETURN_DOM || false;
|
509
|
-
RETURN_DOM_FRAGMENT = cfg.RETURN_DOM_FRAGMENT || false;
|
510
|
-
RETURN_TRUSTED_TYPE = cfg.RETURN_TRUSTED_TYPE || false;
|
511
|
-
FORCE_BODY = cfg.FORCE_BODY || false;
|
512
|
-
SANITIZE_DOM = cfg.SANITIZE_DOM !== false;
|
513
|
-
SANITIZE_NAMED_PROPS = cfg.SANITIZE_NAMED_PROPS || false;
|
514
|
-
KEEP_CONTENT = cfg.KEEP_CONTENT !== false;
|
515
|
-
IN_PLACE = cfg.IN_PLACE || false;
|
516
|
-
IS_ALLOWED_URI$1 = cfg.ALLOWED_URI_REGEXP || IS_ALLOWED_URI;
|
517
|
-
NAMESPACE = cfg.NAMESPACE || HTML_NAMESPACE;
|
518
|
-
MATHML_TEXT_INTEGRATION_POINTS = cfg.MATHML_TEXT_INTEGRATION_POINTS || MATHML_TEXT_INTEGRATION_POINTS;
|
519
|
-
HTML_INTEGRATION_POINTS = cfg.HTML_INTEGRATION_POINTS || HTML_INTEGRATION_POINTS;
|
520
|
-
CUSTOM_ELEMENT_HANDLING = cfg.CUSTOM_ELEMENT_HANDLING || {};
|
521
|
-
if (cfg.CUSTOM_ELEMENT_HANDLING && isRegexOrFunction(cfg.CUSTOM_ELEMENT_HANDLING.tagNameCheck)) {
|
522
|
-
CUSTOM_ELEMENT_HANDLING.tagNameCheck = cfg.CUSTOM_ELEMENT_HANDLING.tagNameCheck;
|
523
|
-
}
|
524
|
-
if (cfg.CUSTOM_ELEMENT_HANDLING && isRegexOrFunction(cfg.CUSTOM_ELEMENT_HANDLING.attributeNameCheck)) {
|
525
|
-
CUSTOM_ELEMENT_HANDLING.attributeNameCheck = cfg.CUSTOM_ELEMENT_HANDLING.attributeNameCheck;
|
526
|
-
}
|
527
|
-
if (cfg.CUSTOM_ELEMENT_HANDLING && typeof cfg.CUSTOM_ELEMENT_HANDLING.allowCustomizedBuiltInElements === "boolean") {
|
528
|
-
CUSTOM_ELEMENT_HANDLING.allowCustomizedBuiltInElements = cfg.CUSTOM_ELEMENT_HANDLING.allowCustomizedBuiltInElements;
|
529
|
-
}
|
530
|
-
if (SAFE_FOR_TEMPLATES) {
|
531
|
-
ALLOW_DATA_ATTR = false;
|
532
|
-
}
|
533
|
-
if (RETURN_DOM_FRAGMENT) {
|
534
|
-
RETURN_DOM = true;
|
535
|
-
}
|
536
|
-
if (USE_PROFILES) {
|
537
|
-
ALLOWED_TAGS = addToSet({}, text);
|
538
|
-
ALLOWED_ATTR = [];
|
539
|
-
if (USE_PROFILES.html === true) {
|
540
|
-
addToSet(ALLOWED_TAGS, html$1);
|
541
|
-
addToSet(ALLOWED_ATTR, html);
|
542
|
-
}
|
543
|
-
if (USE_PROFILES.svg === true) {
|
544
|
-
addToSet(ALLOWED_TAGS, svg$1);
|
545
|
-
addToSet(ALLOWED_ATTR, svg);
|
546
|
-
addToSet(ALLOWED_ATTR, xml);
|
547
|
-
}
|
548
|
-
if (USE_PROFILES.svgFilters === true) {
|
549
|
-
addToSet(ALLOWED_TAGS, svgFilters);
|
550
|
-
addToSet(ALLOWED_ATTR, svg);
|
551
|
-
addToSet(ALLOWED_ATTR, xml);
|
616
|
+
},
|
617
|
+
get root() {
|
618
|
+
return new Proxy({}, {
|
619
|
+
get: () => {
|
620
|
+
throw new Error("The `root` property is not available on the server.");
|
552
621
|
}
|
553
|
-
if (USE_PROFILES.mathMl === true) {
|
554
|
-
addToSet(ALLOWED_TAGS, mathMl$1);
|
555
|
-
addToSet(ALLOWED_ATTR, mathMl);
|
556
|
-
addToSet(ALLOWED_ATTR, xml);
|
557
|
-
}
|
558
|
-
}
|
559
|
-
if (cfg.ADD_TAGS) {
|
560
|
-
if (ALLOWED_TAGS === DEFAULT_ALLOWED_TAGS) {
|
561
|
-
ALLOWED_TAGS = clone(ALLOWED_TAGS);
|
562
|
-
}
|
563
|
-
addToSet(ALLOWED_TAGS, cfg.ADD_TAGS, transformCaseFunc);
|
564
|
-
}
|
565
|
-
if (cfg.ADD_ATTR) {
|
566
|
-
if (ALLOWED_ATTR === DEFAULT_ALLOWED_ATTR) {
|
567
|
-
ALLOWED_ATTR = clone(ALLOWED_ATTR);
|
568
|
-
}
|
569
|
-
addToSet(ALLOWED_ATTR, cfg.ADD_ATTR, transformCaseFunc);
|
570
|
-
}
|
571
|
-
if (cfg.ADD_URI_SAFE_ATTR) {
|
572
|
-
addToSet(URI_SAFE_ATTRIBUTES, cfg.ADD_URI_SAFE_ATTR, transformCaseFunc);
|
573
|
-
}
|
574
|
-
if (cfg.FORBID_CONTENTS) {
|
575
|
-
if (FORBID_CONTENTS === DEFAULT_FORBID_CONTENTS) {
|
576
|
-
FORBID_CONTENTS = clone(FORBID_CONTENTS);
|
577
|
-
}
|
578
|
-
addToSet(FORBID_CONTENTS, cfg.FORBID_CONTENTS, transformCaseFunc);
|
579
|
-
}
|
580
|
-
if (KEEP_CONTENT) {
|
581
|
-
ALLOWED_TAGS["#text"] = true;
|
582
|
-
}
|
583
|
-
if (WHOLE_DOCUMENT) {
|
584
|
-
addToSet(ALLOWED_TAGS, ["html", "head", "body"]);
|
585
|
-
}
|
586
|
-
if (ALLOWED_TAGS.table) {
|
587
|
-
addToSet(ALLOWED_TAGS, ["tbody"]);
|
588
|
-
delete FORBID_TAGS.tbody;
|
589
|
-
}
|
590
|
-
if (cfg.TRUSTED_TYPES_POLICY) {
|
591
|
-
if (typeof cfg.TRUSTED_TYPES_POLICY.createHTML !== "function") {
|
592
|
-
throw typeErrorCreate('TRUSTED_TYPES_POLICY configuration option must provide a "createHTML" hook.');
|
593
|
-
}
|
594
|
-
if (typeof cfg.TRUSTED_TYPES_POLICY.createScriptURL !== "function") {
|
595
|
-
throw typeErrorCreate('TRUSTED_TYPES_POLICY configuration option must provide a "createScriptURL" hook.');
|
596
|
-
}
|
597
|
-
trustedTypesPolicy = cfg.TRUSTED_TYPES_POLICY;
|
598
|
-
emptyHTML = trustedTypesPolicy.createHTML("");
|
599
|
-
} else {
|
600
|
-
if (trustedTypesPolicy === void 0) {
|
601
|
-
trustedTypesPolicy = _createTrustedTypesPolicy(trustedTypes, currentScript);
|
602
|
-
}
|
603
|
-
if (trustedTypesPolicy !== null && typeof emptyHTML === "string") {
|
604
|
-
emptyHTML = trustedTypesPolicy.createHTML("");
|
605
|
-
}
|
606
|
-
}
|
607
|
-
if (freeze) {
|
608
|
-
freeze(cfg);
|
609
|
-
}
|
610
|
-
CONFIG = cfg;
|
611
|
-
};
|
612
|
-
const ALL_SVG_TAGS = addToSet({}, [...svg$1, ...svgFilters, ...svgDisallowed]);
|
613
|
-
const ALL_MATHML_TAGS = addToSet({}, [...mathMl$1, ...mathMlDisallowed]);
|
614
|
-
const _checkValidNamespace = function _checkValidNamespace2(element) {
|
615
|
-
let parent = getParentNode(element);
|
616
|
-
if (!parent || !parent.tagName) {
|
617
|
-
parent = {
|
618
|
-
namespaceURI: NAMESPACE,
|
619
|
-
tagName: "template"
|
620
|
-
};
|
621
|
-
}
|
622
|
-
const tagName = stringToLowerCase(element.tagName);
|
623
|
-
const parentTagName = stringToLowerCase(parent.tagName);
|
624
|
-
if (!ALLOWED_NAMESPACES[element.namespaceURI]) {
|
625
|
-
return false;
|
626
|
-
}
|
627
|
-
if (element.namespaceURI === SVG_NAMESPACE) {
|
628
|
-
if (parent.namespaceURI === HTML_NAMESPACE) {
|
629
|
-
return tagName === "svg";
|
630
|
-
}
|
631
|
-
if (parent.namespaceURI === MATHML_NAMESPACE) {
|
632
|
-
return tagName === "svg" && (parentTagName === "annotation-xml" || MATHML_TEXT_INTEGRATION_POINTS[parentTagName]);
|
633
|
-
}
|
634
|
-
return Boolean(ALL_SVG_TAGS[tagName]);
|
635
|
-
}
|
636
|
-
if (element.namespaceURI === MATHML_NAMESPACE) {
|
637
|
-
if (parent.namespaceURI === HTML_NAMESPACE) {
|
638
|
-
return tagName === "math";
|
639
|
-
}
|
640
|
-
if (parent.namespaceURI === SVG_NAMESPACE) {
|
641
|
-
return tagName === "math" && HTML_INTEGRATION_POINTS[parentTagName];
|
642
|
-
}
|
643
|
-
return Boolean(ALL_MATHML_TAGS[tagName]);
|
644
|
-
}
|
645
|
-
if (element.namespaceURI === HTML_NAMESPACE) {
|
646
|
-
if (parent.namespaceURI === SVG_NAMESPACE && !HTML_INTEGRATION_POINTS[parentTagName]) {
|
647
|
-
return false;
|
648
|
-
}
|
649
|
-
if (parent.namespaceURI === MATHML_NAMESPACE && !MATHML_TEXT_INTEGRATION_POINTS[parentTagName]) {
|
650
|
-
return false;
|
651
|
-
}
|
652
|
-
return !ALL_MATHML_TAGS[tagName] && (COMMON_SVG_AND_HTML_ELEMENTS[tagName] || !ALL_SVG_TAGS[tagName]);
|
653
|
-
}
|
654
|
-
if (PARSER_MEDIA_TYPE === "application/xhtml+xml" && ALLOWED_NAMESPACES[element.namespaceURI]) {
|
655
|
-
return true;
|
656
|
-
}
|
657
|
-
return false;
|
658
|
-
};
|
659
|
-
const _forceRemove = function _forceRemove2(node) {
|
660
|
-
arrayPush(DOMPurify.removed, {
|
661
|
-
element: node
|
662
622
|
});
|
663
|
-
|
664
|
-
|
665
|
-
|
666
|
-
|
667
|
-
|
668
|
-
};
|
669
|
-
const _removeAttribute = function _removeAttribute2(name, element) {
|
670
|
-
try {
|
671
|
-
arrayPush(DOMPurify.removed, {
|
672
|
-
attribute: element.getAttributeNode(name),
|
673
|
-
from: element
|
674
|
-
});
|
675
|
-
} catch (_) {
|
676
|
-
arrayPush(DOMPurify.removed, {
|
677
|
-
attribute: null,
|
678
|
-
from: element
|
679
|
-
});
|
680
|
-
}
|
681
|
-
element.removeAttribute(name);
|
682
|
-
if (name === "is" && !ALLOWED_ATTR[name]) {
|
683
|
-
if (RETURN_DOM || RETURN_DOM_FRAGMENT) {
|
684
|
-
try {
|
685
|
-
_forceRemove(element);
|
686
|
-
} catch (_) {
|
687
|
-
}
|
688
|
-
} else {
|
689
|
-
try {
|
690
|
-
element.setAttribute(name, "");
|
691
|
-
} catch (_) {
|
692
|
-
}
|
693
|
-
}
|
694
|
-
}
|
695
|
-
};
|
696
|
-
const _initDocument = function _initDocument2(dirty) {
|
697
|
-
let doc = null;
|
698
|
-
let leadingWhitespace = null;
|
699
|
-
if (FORCE_BODY) {
|
700
|
-
dirty = "<remove></remove>" + dirty;
|
701
|
-
} else {
|
702
|
-
const matches = stringMatch(dirty, /^[\r\n\t ]+/);
|
703
|
-
leadingWhitespace = matches && matches[0];
|
704
|
-
}
|
705
|
-
if (PARSER_MEDIA_TYPE === "application/xhtml+xml" && NAMESPACE === HTML_NAMESPACE) {
|
706
|
-
dirty = '<html xmlns="http://www.w3.org/1999/xhtml"><head></head><body>' + dirty + "</body></html>";
|
707
|
-
}
|
708
|
-
const dirtyPayload = trustedTypesPolicy ? trustedTypesPolicy.createHTML(dirty) : dirty;
|
709
|
-
if (NAMESPACE === HTML_NAMESPACE) {
|
710
|
-
try {
|
711
|
-
doc = new DOMParser().parseFromString(dirtyPayload, PARSER_MEDIA_TYPE);
|
712
|
-
} catch (_) {
|
623
|
+
},
|
624
|
+
get internals() {
|
625
|
+
return new Proxy({}, {
|
626
|
+
get: () => {
|
627
|
+
throw new Error("The `internals` property is not available on the server.");
|
713
628
|
}
|
714
|
-
}
|
715
|
-
if (!doc || !doc.documentElement) {
|
716
|
-
doc = implementation.createDocument(NAMESPACE, "template", null);
|
717
|
-
try {
|
718
|
-
doc.documentElement.innerHTML = IS_EMPTY_INPUT ? emptyHTML : dirtyPayload;
|
719
|
-
} catch (_) {
|
720
|
-
}
|
721
|
-
}
|
722
|
-
const body = doc.body || doc.documentElement;
|
723
|
-
if (dirty && leadingWhitespace) {
|
724
|
-
body.insertBefore(document2.createTextNode(leadingWhitespace), body.childNodes[0] || null);
|
725
|
-
}
|
726
|
-
if (NAMESPACE === HTML_NAMESPACE) {
|
727
|
-
return getElementsByTagName.call(doc, WHOLE_DOCUMENT ? "html" : "body")[0];
|
728
|
-
}
|
729
|
-
return WHOLE_DOCUMENT ? doc.documentElement : body;
|
730
|
-
};
|
731
|
-
const _createNodeIterator = function _createNodeIterator2(root) {
|
732
|
-
return createNodeIterator.call(
|
733
|
-
root.ownerDocument || root,
|
734
|
-
root,
|
735
|
-
// eslint-disable-next-line no-bitwise
|
736
|
-
NodeFilter.SHOW_ELEMENT | NodeFilter.SHOW_COMMENT | NodeFilter.SHOW_TEXT | NodeFilter.SHOW_PROCESSING_INSTRUCTION | NodeFilter.SHOW_CDATA_SECTION,
|
737
|
-
null
|
738
|
-
);
|
739
|
-
};
|
740
|
-
const _isClobbered = function _isClobbered2(element) {
|
741
|
-
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");
|
742
|
-
};
|
743
|
-
const _isNode = function _isNode2(value) {
|
744
|
-
return typeof Node === "function" && value instanceof Node;
|
745
|
-
};
|
746
|
-
function _executeHook(entryPoint, currentNode, data) {
|
747
|
-
if (!hooks[entryPoint]) {
|
748
|
-
return;
|
749
|
-
}
|
750
|
-
arrayForEach(hooks[entryPoint], (hook) => {
|
751
|
-
hook.call(DOMPurify, currentNode, data, CONFIG);
|
752
629
|
});
|
630
|
+
},
|
631
|
+
attributeChangedCallback: NOOP,
|
632
|
+
connectedCallback: NOOP,
|
633
|
+
disconnectedCallback: NOOP,
|
634
|
+
adoptedCallback: NOOP,
|
635
|
+
formDisabledCallback: NOOP,
|
636
|
+
formResetCallback: NOOP,
|
637
|
+
formStateRestoreCallback: NOOP,
|
638
|
+
formAssociatedCallback: NOOP,
|
639
|
+
clientOnlyCallback: NOOP,
|
640
|
+
customCallback: () => `{{callback:unavailable-on-server}}`,
|
641
|
+
attrSignals: new Proxy({}, { get: (_, attr) => createSignal(`{{attr:${String(attr)}}}`) }),
|
642
|
+
propSignals: new Proxy({}, { get: () => createSignal(null) }),
|
643
|
+
refs: {},
|
644
|
+
// @ts-expect-error // this will be a string for SSR, but this is true for internal cases only.
|
645
|
+
// The end user will see the public type, which is either a CSSStyleSheet or HTMLStyleElement.
|
646
|
+
adoptStyleSheet: (cssStr) => {
|
647
|
+
const _serverCss = registry !== void 0 ? registry.__serverCss : serverCss;
|
648
|
+
const cssArr = _serverCss.get(tagName) ?? [];
|
649
|
+
cssArr.push(cssStr);
|
650
|
+
_serverCss.set(tagName, cssArr);
|
753
651
|
}
|
754
|
-
|
755
|
-
|
756
|
-
|
757
|
-
|
758
|
-
|
759
|
-
|
760
|
-
|
761
|
-
|
762
|
-
|
763
|
-
|
764
|
-
|
652
|
+
});
|
653
|
+
var wrapTemplate = ({ tagName, serverRender, options }) => {
|
654
|
+
const { registry } = options.shadowRootOptions;
|
655
|
+
const scopedRegistry = registry !== void 0 && "scoped" in registry ? registry : void 0;
|
656
|
+
const initialRenderString = serverRender(getServerRenderArgs(tagName, scopedRegistry));
|
657
|
+
const _serverCss = scopedRegistry?.__serverCss ?? serverCss;
|
658
|
+
const cssRenderString = (_serverCss.get(tagName) ?? []).map((cssStr) => `<style>${cssStr}</style>`).join("");
|
659
|
+
const finalScopedRenderString = options.attachShadow ? (
|
660
|
+
/* html */
|
661
|
+
`
|
662
|
+
<template
|
663
|
+
shadowrootmode="${options.shadowRootOptions.mode}"
|
664
|
+
shadowrootdelegatesfocus="${options.shadowRootOptions.delegatesFocus}"
|
665
|
+
shadowrootclonable="${options.shadowRootOptions.clonable}"
|
666
|
+
shadowrootserializable="${options.shadowRootOptions.serializable}"
|
667
|
+
>
|
668
|
+
${cssRenderString + initialRenderString}
|
669
|
+
</template>
|
670
|
+
`
|
671
|
+
) : cssRenderString + initialRenderString;
|
672
|
+
return finalScopedRenderString;
|
673
|
+
};
|
674
|
+
var insertTemplates = (tagName, template, inputString) => {
|
675
|
+
return inputString.replace(new RegExp(`(<s*${tagName}([^>]*)>)`, "gm"), ($1, _, $3) => {
|
676
|
+
const attrs = $3.split(/(?<=")\s+/).filter((attr) => attr.trim() !== "").map((attr) => {
|
677
|
+
const [_key, _value] = attr.split("=");
|
678
|
+
const key = _key.trim();
|
679
|
+
const value = _value?.replace(/"/g, "") ?? "";
|
680
|
+
return [key, value];
|
765
681
|
});
|
766
|
-
|
767
|
-
|
768
|
-
|
769
|
-
}
|
770
|
-
if (currentNode.nodeType === NODE_TYPE.progressingInstruction) {
|
771
|
-
_forceRemove(currentNode);
|
772
|
-
return true;
|
773
|
-
}
|
774
|
-
if (SAFE_FOR_XML && currentNode.nodeType === NODE_TYPE.comment && regExpTest(/<[/\w]/g, currentNode.data)) {
|
775
|
-
_forceRemove(currentNode);
|
776
|
-
return true;
|
777
|
-
}
|
778
|
-
if (!ALLOWED_TAGS[tagName] || FORBID_TAGS[tagName]) {
|
779
|
-
if (!FORBID_TAGS[tagName] && _isBasicCustomElement(tagName)) {
|
780
|
-
if (CUSTOM_ELEMENT_HANDLING.tagNameCheck instanceof RegExp && regExpTest(CUSTOM_ELEMENT_HANDLING.tagNameCheck, tagName)) {
|
781
|
-
return false;
|
782
|
-
}
|
783
|
-
if (CUSTOM_ELEMENT_HANDLING.tagNameCheck instanceof Function && CUSTOM_ELEMENT_HANDLING.tagNameCheck(tagName)) {
|
784
|
-
return false;
|
785
|
-
}
|
786
|
-
}
|
787
|
-
if (KEEP_CONTENT && !FORBID_CONTENTS[tagName]) {
|
788
|
-
const parentNode = getParentNode(currentNode) || currentNode.parentNode;
|
789
|
-
const childNodes = getChildNodes(currentNode) || currentNode.childNodes;
|
790
|
-
if (childNodes && parentNode) {
|
791
|
-
const childCount = childNodes.length;
|
792
|
-
for (let i = childCount - 1; i >= 0; --i) {
|
793
|
-
const childClone = cloneNode(childNodes[i], true);
|
794
|
-
childClone.__removalCount = (currentNode.__removalCount || 0) + 1;
|
795
|
-
parentNode.insertBefore(childClone, getNextSibling(currentNode));
|
796
|
-
}
|
797
|
-
}
|
798
|
-
}
|
799
|
-
_forceRemove(currentNode);
|
800
|
-
return true;
|
801
|
-
}
|
802
|
-
if (currentNode instanceof Element2 && !_checkValidNamespace(currentNode)) {
|
803
|
-
_forceRemove(currentNode);
|
804
|
-
return true;
|
805
|
-
}
|
806
|
-
if ((tagName === "noscript" || tagName === "noembed" || tagName === "noframes") && regExpTest(/<\/no(script|embed|frames)/i, currentNode.innerHTML)) {
|
807
|
-
_forceRemove(currentNode);
|
808
|
-
return true;
|
809
|
-
}
|
810
|
-
if (SAFE_FOR_TEMPLATES && currentNode.nodeType === NODE_TYPE.text) {
|
811
|
-
content = currentNode.textContent;
|
812
|
-
arrayForEach([MUSTACHE_EXPR2, ERB_EXPR2, TMPLIT_EXPR2], (expr) => {
|
813
|
-
content = stringReplace(content, expr, " ");
|
814
|
-
});
|
815
|
-
if (currentNode.textContent !== content) {
|
816
|
-
arrayPush(DOMPurify.removed, {
|
817
|
-
element: currentNode.cloneNode()
|
818
|
-
});
|
819
|
-
currentNode.textContent = content;
|
820
|
-
}
|
821
|
-
}
|
822
|
-
_executeHook("afterSanitizeElements", currentNode, null);
|
823
|
-
return false;
|
824
|
-
};
|
825
|
-
const _isValidAttribute = function _isValidAttribute2(lcTag, lcName, value) {
|
826
|
-
if (SANITIZE_DOM && (lcName === "id" || lcName === "name") && (value in document2 || value in formElement)) {
|
827
|
-
return false;
|
828
|
-
}
|
829
|
-
if (ALLOW_DATA_ATTR && !FORBID_ATTR[lcName] && regExpTest(DATA_ATTR2, lcName)) ;
|
830
|
-
else if (ALLOW_ARIA_ATTR && regExpTest(ARIA_ATTR2, lcName)) ;
|
831
|
-
else if (!ALLOWED_ATTR[lcName] || FORBID_ATTR[lcName]) {
|
832
|
-
if (
|
833
|
-
// First condition does a very basic check if a) it's basically a valid custom element tagname AND
|
834
|
-
// b) if the tagName passes whatever the user has configured for CUSTOM_ELEMENT_HANDLING.tagNameCheck
|
835
|
-
// and c) if the attribute name passes whatever the user has configured for CUSTOM_ELEMENT_HANDLING.attributeNameCheck
|
836
|
-
_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
|
837
|
-
// the value passes whatever the user has configured for CUSTOM_ELEMENT_HANDLING.tagNameCheck
|
838
|
-
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))
|
839
|
-
) ;
|
840
|
-
else {
|
841
|
-
return false;
|
842
|
-
}
|
843
|
-
} else if (URI_SAFE_ATTRIBUTES[lcName]) ;
|
844
|
-
else if (regExpTest(IS_ALLOWED_URI$1, stringReplace(value, ATTR_WHITESPACE2, ""))) ;
|
845
|
-
else if ((lcName === "src" || lcName === "xlink:href" || lcName === "href") && lcTag !== "script" && stringIndexOf(value, "data:") === 0 && DATA_URI_TAGS[lcTag]) ;
|
846
|
-
else if (ALLOW_UNKNOWN_PROTOCOLS && !regExpTest(IS_SCRIPT_OR_DATA2, stringReplace(value, ATTR_WHITESPACE2, ""))) ;
|
847
|
-
else if (value) {
|
848
|
-
return false;
|
849
|
-
} else ;
|
850
|
-
return true;
|
851
|
-
};
|
852
|
-
const _isBasicCustomElement = function _isBasicCustomElement2(tagName) {
|
853
|
-
return tagName !== "annotation-xml" && stringMatch(tagName, CUSTOM_ELEMENT2);
|
854
|
-
};
|
855
|
-
const _sanitizeAttributes = function _sanitizeAttributes2(currentNode) {
|
856
|
-
_executeHook("beforeSanitizeAttributes", currentNode, null);
|
857
|
-
const {
|
858
|
-
attributes
|
859
|
-
} = currentNode;
|
860
|
-
if (!attributes) {
|
861
|
-
return;
|
862
|
-
}
|
863
|
-
const hookEvent = {
|
864
|
-
attrName: "",
|
865
|
-
attrValue: "",
|
866
|
-
keepAttr: true,
|
867
|
-
allowedAttributes: ALLOWED_ATTR,
|
868
|
-
forceKeepAttr: void 0
|
869
|
-
};
|
870
|
-
let l = attributes.length;
|
871
|
-
while (l--) {
|
872
|
-
const attr = attributes[l];
|
873
|
-
const {
|
874
|
-
name,
|
875
|
-
namespaceURI,
|
876
|
-
value: attrValue
|
877
|
-
} = attr;
|
878
|
-
const lcName = transformCaseFunc(name);
|
879
|
-
let value = name === "value" ? attrValue : stringTrim(attrValue);
|
880
|
-
hookEvent.attrName = lcName;
|
881
|
-
hookEvent.attrValue = value;
|
882
|
-
hookEvent.keepAttr = true;
|
883
|
-
hookEvent.forceKeepAttr = void 0;
|
884
|
-
_executeHook("uponSanitizeAttribute", currentNode, hookEvent);
|
885
|
-
value = hookEvent.attrValue;
|
886
|
-
if (SANITIZE_NAMED_PROPS && (lcName === "id" || lcName === "name")) {
|
887
|
-
_removeAttribute(name, currentNode);
|
888
|
-
value = SANITIZE_NAMED_PROPS_PREFIX + value;
|
889
|
-
}
|
890
|
-
if (SAFE_FOR_XML && regExpTest(/((--!?|])>)|<\/(style|title)/i, value)) {
|
891
|
-
_removeAttribute(name, currentNode);
|
892
|
-
continue;
|
893
|
-
}
|
894
|
-
if (hookEvent.forceKeepAttr) {
|
895
|
-
continue;
|
896
|
-
}
|
897
|
-
_removeAttribute(name, currentNode);
|
898
|
-
if (!hookEvent.keepAttr) {
|
899
|
-
continue;
|
900
|
-
}
|
901
|
-
if (!ALLOW_SELF_CLOSE_IN_ATTR && regExpTest(/\/>/i, value)) {
|
902
|
-
_removeAttribute(name, currentNode);
|
903
|
-
continue;
|
904
|
-
}
|
905
|
-
if (SAFE_FOR_TEMPLATES) {
|
906
|
-
arrayForEach([MUSTACHE_EXPR2, ERB_EXPR2, TMPLIT_EXPR2], (expr) => {
|
907
|
-
value = stringReplace(value, expr, " ");
|
908
|
-
});
|
909
|
-
}
|
910
|
-
const lcTag = transformCaseFunc(currentNode.nodeName);
|
911
|
-
if (!_isValidAttribute(lcTag, lcName, value)) {
|
912
|
-
continue;
|
913
|
-
}
|
914
|
-
if (trustedTypesPolicy && typeof trustedTypes === "object" && typeof trustedTypes.getAttributeType === "function") {
|
915
|
-
if (namespaceURI) ;
|
916
|
-
else {
|
917
|
-
switch (trustedTypes.getAttributeType(lcTag, lcName)) {
|
918
|
-
case "TrustedHTML": {
|
919
|
-
value = trustedTypesPolicy.createHTML(value);
|
920
|
-
break;
|
921
|
-
}
|
922
|
-
case "TrustedScriptURL": {
|
923
|
-
value = trustedTypesPolicy.createScriptURL(value);
|
924
|
-
break;
|
925
|
-
}
|
926
|
-
}
|
927
|
-
}
|
928
|
-
}
|
929
|
-
try {
|
930
|
-
if (namespaceURI) {
|
931
|
-
currentNode.setAttributeNS(namespaceURI, name, value);
|
932
|
-
} else {
|
933
|
-
currentNode.setAttribute(name, value);
|
934
|
-
}
|
935
|
-
if (_isClobbered(currentNode)) {
|
936
|
-
_forceRemove(currentNode);
|
937
|
-
} else {
|
938
|
-
arrayPop(DOMPurify.removed);
|
939
|
-
}
|
940
|
-
} catch (_) {
|
941
|
-
}
|
942
|
-
}
|
943
|
-
_executeHook("afterSanitizeAttributes", currentNode, null);
|
944
|
-
};
|
945
|
-
const _sanitizeShadowDOM = function _sanitizeShadowDOM2(fragment) {
|
946
|
-
let shadowNode = null;
|
947
|
-
const shadowIterator = _createNodeIterator(fragment);
|
948
|
-
_executeHook("beforeSanitizeShadowDOM", fragment, null);
|
949
|
-
while (shadowNode = shadowIterator.nextNode()) {
|
950
|
-
_executeHook("uponSanitizeShadowNode", shadowNode, null);
|
951
|
-
if (_sanitizeElements(shadowNode)) {
|
952
|
-
continue;
|
953
|
-
}
|
954
|
-
if (shadowNode.content instanceof DocumentFragment2) {
|
955
|
-
_sanitizeShadowDOM2(shadowNode.content);
|
956
|
-
}
|
957
|
-
_sanitizeAttributes(shadowNode);
|
958
|
-
}
|
959
|
-
_executeHook("afterSanitizeShadowDOM", fragment, null);
|
960
|
-
};
|
961
|
-
DOMPurify.sanitize = function(dirty) {
|
962
|
-
let cfg = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : {};
|
963
|
-
let body = null;
|
964
|
-
let importedNode = null;
|
965
|
-
let currentNode = null;
|
966
|
-
let returnNode = null;
|
967
|
-
IS_EMPTY_INPUT = !dirty;
|
968
|
-
if (IS_EMPTY_INPUT) {
|
969
|
-
dirty = "<!-->";
|
970
|
-
}
|
971
|
-
if (typeof dirty !== "string" && !_isNode(dirty)) {
|
972
|
-
if (typeof dirty.toString === "function") {
|
973
|
-
dirty = dirty.toString();
|
974
|
-
if (typeof dirty !== "string") {
|
975
|
-
throw typeErrorCreate("dirty is not a string, aborting");
|
976
|
-
}
|
977
|
-
} else {
|
978
|
-
throw typeErrorCreate("toString is not a function");
|
979
|
-
}
|
980
|
-
}
|
981
|
-
if (!DOMPurify.isSupported) {
|
982
|
-
return dirty;
|
983
|
-
}
|
984
|
-
if (!SET_CONFIG) {
|
985
|
-
_parseConfig(cfg);
|
682
|
+
let scopedResult = template;
|
683
|
+
for (const [key, value] of attrs) {
|
684
|
+
scopedResult = scopedResult.replace(new RegExp(`{{attr:${key}}}`, "gm"), value);
|
986
685
|
}
|
987
|
-
|
988
|
-
|
989
|
-
|
990
|
-
|
991
|
-
|
992
|
-
|
993
|
-
const tagName = transformCaseFunc(dirty.nodeName);
|
994
|
-
if (!ALLOWED_TAGS[tagName] || FORBID_TAGS[tagName]) {
|
995
|
-
throw typeErrorCreate("root node is forbidden and cannot be sanitized in-place");
|
996
|
-
}
|
997
|
-
}
|
998
|
-
} else if (dirty instanceof Node) {
|
999
|
-
body = _initDocument("<!---->");
|
1000
|
-
importedNode = body.ownerDocument.importNode(dirty, true);
|
1001
|
-
if (importedNode.nodeType === NODE_TYPE.element && importedNode.nodeName === "BODY") {
|
1002
|
-
body = importedNode;
|
1003
|
-
} else if (importedNode.nodeName === "HTML") {
|
1004
|
-
body = importedNode;
|
1005
|
-
} else {
|
1006
|
-
body.appendChild(importedNode);
|
1007
|
-
}
|
1008
|
-
} else {
|
1009
|
-
if (!RETURN_DOM && !SAFE_FOR_TEMPLATES && !WHOLE_DOCUMENT && // eslint-disable-next-line unicorn/prefer-includes
|
1010
|
-
dirty.indexOf("<") === -1) {
|
1011
|
-
return trustedTypesPolicy && RETURN_TRUSTED_TYPE ? trustedTypesPolicy.createHTML(dirty) : dirty;
|
1012
|
-
}
|
1013
|
-
body = _initDocument(dirty);
|
1014
|
-
if (!body) {
|
1015
|
-
return RETURN_DOM ? null : RETURN_TRUSTED_TYPE ? emptyHTML : "";
|
1016
|
-
}
|
1017
|
-
}
|
1018
|
-
if (body && FORCE_BODY) {
|
1019
|
-
_forceRemove(body.firstChild);
|
1020
|
-
}
|
1021
|
-
const nodeIterator = _createNodeIterator(IN_PLACE ? dirty : body);
|
1022
|
-
while (currentNode = nodeIterator.nextNode()) {
|
1023
|
-
if (_sanitizeElements(currentNode)) {
|
1024
|
-
continue;
|
1025
|
-
}
|
1026
|
-
if (currentNode.content instanceof DocumentFragment2) {
|
1027
|
-
_sanitizeShadowDOM(currentNode.content);
|
1028
|
-
}
|
1029
|
-
_sanitizeAttributes(currentNode);
|
1030
|
-
}
|
1031
|
-
if (IN_PLACE) {
|
1032
|
-
return dirty;
|
1033
|
-
}
|
1034
|
-
if (RETURN_DOM) {
|
1035
|
-
if (RETURN_DOM_FRAGMENT) {
|
1036
|
-
returnNode = createDocumentFragment.call(body.ownerDocument);
|
1037
|
-
while (body.firstChild) {
|
1038
|
-
returnNode.appendChild(body.firstChild);
|
1039
|
-
}
|
1040
|
-
} else {
|
1041
|
-
returnNode = body;
|
1042
|
-
}
|
1043
|
-
if (ALLOWED_ATTR.shadowroot || ALLOWED_ATTR.shadowrootmode) {
|
1044
|
-
returnNode = importNode.call(originalDocument, returnNode, true);
|
1045
|
-
}
|
1046
|
-
return returnNode;
|
1047
|
-
}
|
1048
|
-
let serializedHTML = WHOLE_DOCUMENT ? body.outerHTML : body.innerHTML;
|
1049
|
-
if (WHOLE_DOCUMENT && ALLOWED_TAGS["!doctype"] && body.ownerDocument && body.ownerDocument.doctype && body.ownerDocument.doctype.name && regExpTest(DOCTYPE_NAME, body.ownerDocument.doctype.name)) {
|
1050
|
-
serializedHTML = "<!DOCTYPE " + body.ownerDocument.doctype.name + ">\n" + serializedHTML;
|
1051
|
-
}
|
1052
|
-
if (SAFE_FOR_TEMPLATES) {
|
1053
|
-
arrayForEach([MUSTACHE_EXPR2, ERB_EXPR2, TMPLIT_EXPR2], (expr) => {
|
1054
|
-
serializedHTML = stringReplace(serializedHTML, expr, " ");
|
1055
|
-
});
|
1056
|
-
}
|
1057
|
-
return trustedTypesPolicy && RETURN_TRUSTED_TYPE ? trustedTypesPolicy.createHTML(serializedHTML) : serializedHTML;
|
1058
|
-
};
|
1059
|
-
DOMPurify.setConfig = function() {
|
1060
|
-
let cfg = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : {};
|
1061
|
-
_parseConfig(cfg);
|
1062
|
-
SET_CONFIG = true;
|
1063
|
-
};
|
1064
|
-
DOMPurify.clearConfig = function() {
|
1065
|
-
CONFIG = null;
|
1066
|
-
SET_CONFIG = false;
|
1067
|
-
};
|
1068
|
-
DOMPurify.isValidAttribute = function(tag, attr, value) {
|
1069
|
-
if (!CONFIG) {
|
1070
|
-
_parseConfig({});
|
1071
|
-
}
|
1072
|
-
const lcTag = transformCaseFunc(tag);
|
1073
|
-
const lcName = transformCaseFunc(attr);
|
1074
|
-
return _isValidAttribute(lcTag, lcName, value);
|
1075
|
-
};
|
1076
|
-
DOMPurify.addHook = function(entryPoint, hookFunction) {
|
1077
|
-
if (typeof hookFunction !== "function") {
|
1078
|
-
return;
|
1079
|
-
}
|
1080
|
-
hooks[entryPoint] = hooks[entryPoint] || [];
|
1081
|
-
arrayPush(hooks[entryPoint], hookFunction);
|
1082
|
-
};
|
1083
|
-
DOMPurify.removeHook = function(entryPoint) {
|
1084
|
-
if (hooks[entryPoint]) {
|
1085
|
-
return arrayPop(hooks[entryPoint]);
|
1086
|
-
}
|
1087
|
-
};
|
1088
|
-
DOMPurify.removeHooks = function(entryPoint) {
|
1089
|
-
if (hooks[entryPoint]) {
|
1090
|
-
hooks[entryPoint] = [];
|
1091
|
-
}
|
1092
|
-
};
|
1093
|
-
DOMPurify.removeAllHooks = function() {
|
1094
|
-
hooks = {};
|
1095
|
-
};
|
1096
|
-
return DOMPurify;
|
1097
|
-
}
|
1098
|
-
var purify = createDOMPurify();
|
686
|
+
return $1 + scopedResult;
|
687
|
+
});
|
688
|
+
};
|
689
|
+
var clientOnlyCallback = (fn) => {
|
690
|
+
if (!isServer) return fn();
|
691
|
+
};
|
1099
692
|
|
1100
693
|
// src/render.ts
|
1101
|
-
var
|
694
|
+
var clearHTML = (element) => {
|
695
|
+
while (element.childNodes.length > 0) {
|
696
|
+
element.childNodes[0].remove();
|
697
|
+
}
|
698
|
+
};
|
699
|
+
var parseFragment = (htmlStr) => {
|
700
|
+
const range = document.createRange();
|
701
|
+
range.selectNode(document.body);
|
702
|
+
return range.createContextualFragment(htmlStr);
|
703
|
+
};
|
704
|
+
var setInnerHTML = (element, html2) => {
|
705
|
+
clearHTML(element);
|
706
|
+
const fragment = typeof html2 === "string" ? parseFragment(html2) : html2;
|
707
|
+
element.append(fragment);
|
708
|
+
};
|
709
|
+
var logValueError = (value) => {
|
710
|
+
console.error(
|
711
|
+
"An invalid value was passed to a template function. Non-primitive values are not supported.\n\nValue:\n",
|
712
|
+
value
|
713
|
+
);
|
714
|
+
};
|
715
|
+
var html = (strings, ...values) => {
|
1102
716
|
let innerHTML = "";
|
1103
717
|
const signalMap = /* @__PURE__ */ new Map();
|
1104
718
|
strings.forEach((string, i) => {
|
@@ -1106,11 +720,17 @@ var html2 = (strings, ...values) => {
|
|
1106
720
|
if (typeof value === "function") {
|
1107
721
|
const uniqueKey = crypto.randomUUID();
|
1108
722
|
signalMap.set(uniqueKey, value);
|
1109
|
-
value = `{{signal:${uniqueKey}}}`;
|
723
|
+
value = isServer ? value() : `{{signal:${uniqueKey}}}`;
|
724
|
+
}
|
725
|
+
if (typeof value === "object" && value !== null) {
|
726
|
+
logValueError(value);
|
727
|
+
value = "";
|
1110
728
|
}
|
1111
729
|
innerHTML += string + String(value);
|
1112
730
|
});
|
1113
|
-
|
731
|
+
if (isServer) {
|
732
|
+
return innerHTML;
|
733
|
+
}
|
1114
734
|
const fragment = parseFragment(innerHTML);
|
1115
735
|
const callbackBindingRegex = /(\{\{callback:.+\}\})/;
|
1116
736
|
const signalBindingRegex = /(\{\{signal:.+\}\})/;
|
@@ -1118,10 +738,10 @@ var html2 = (strings, ...values) => {
|
|
1118
738
|
for (const child of element.childNodes) {
|
1119
739
|
if (child instanceof Text && signalBindingRegex.test(child.data)) {
|
1120
740
|
const textList = child.data.split(signalBindingRegex);
|
1121
|
-
textList.forEach((
|
1122
|
-
const uniqueKey =
|
1123
|
-
const signal = uniqueKey !==
|
1124
|
-
const newValue = signal !== void 0 ? signal() :
|
741
|
+
textList.forEach((text, i) => {
|
742
|
+
const uniqueKey = text.replace(/\{\{signal:(.+)\}\}/, "$1");
|
743
|
+
const signal = uniqueKey !== text ? signalMap.get(uniqueKey) : void 0;
|
744
|
+
const newValue = signal !== void 0 ? signal() : text;
|
1125
745
|
const newNode = (() => {
|
1126
746
|
if (typeof newValue === "string") return new Text(newValue);
|
1127
747
|
if (newValue instanceof DocumentFragment) return newValue;
|
@@ -1146,12 +766,12 @@ var html2 = (strings, ...values) => {
|
|
1146
766
|
createEffect(() => {
|
1147
767
|
let newText = "";
|
1148
768
|
let hasNull = false;
|
1149
|
-
for (const
|
1150
|
-
const uniqueKey =
|
1151
|
-
const signal = uniqueKey !==
|
1152
|
-
const value = signal !== void 0 ? signal() :
|
769
|
+
for (const text of textList) {
|
770
|
+
const uniqueKey = text.replace(/\{\{signal:(.+)\}\}/, "$1");
|
771
|
+
const signal = uniqueKey !== text ? signalMap.get(uniqueKey) : void 0;
|
772
|
+
const value = signal !== void 0 ? signal() : text;
|
1153
773
|
if (value === null) hasNull = true;
|
1154
|
-
newText += value;
|
774
|
+
newText += String(value);
|
1155
775
|
}
|
1156
776
|
if (hasNull && newText === "null") {
|
1157
777
|
child.removeAttribute(attr.name);
|
@@ -1189,23 +809,31 @@ var css = (strings, ...values) => {
|
|
1189
809
|
if (typeof value === "function") {
|
1190
810
|
const uniqueKey = crypto.randomUUID();
|
1191
811
|
signalMap.set(uniqueKey, value);
|
1192
|
-
value = `{{signal:${uniqueKey}}}`;
|
812
|
+
value = isServer ? value() : `{{signal:${uniqueKey}}}`;
|
813
|
+
}
|
814
|
+
if (typeof value === "object" && value !== null) {
|
815
|
+
logValueError(value);
|
816
|
+
value = "";
|
1193
817
|
}
|
1194
818
|
cssText += string + String(value);
|
1195
819
|
});
|
1196
|
-
|
820
|
+
if (isServer) {
|
821
|
+
return cssText;
|
822
|
+
}
|
823
|
+
const stylesheet = adoptedStylesSupported ? new CSSStyleSheet() : document.createElement("style");
|
1197
824
|
const textList = cssText.split(signalBindingRegex);
|
1198
825
|
createEffect(() => {
|
1199
826
|
const newCSSTextList = [];
|
1200
|
-
for (const
|
1201
|
-
const uniqueKey =
|
1202
|
-
const signal = uniqueKey !==
|
1203
|
-
const
|
827
|
+
for (const text of textList) {
|
828
|
+
const uniqueKey = text.replace(/\{\{signal:(.+)\}\}/, "$1");
|
829
|
+
const signal = uniqueKey !== text ? signalMap.get(uniqueKey) : null;
|
830
|
+
const newValue = signal !== null ? signal() : text;
|
831
|
+
const newText = String(newValue);
|
1204
832
|
newCSSTextList.push(newText);
|
1205
833
|
}
|
1206
834
|
const newCSSText = newCSSTextList.join("");
|
1207
835
|
if (isCSSStyleSheet(stylesheet)) {
|
1208
|
-
stylesheet.replace(newCSSText);
|
836
|
+
stylesheet.replace(newCSSText).catch(console.error);
|
1209
837
|
} else {
|
1210
838
|
stylesheet.textContent = newCSSText;
|
1211
839
|
}
|
@@ -1214,42 +842,63 @@ var css = (strings, ...values) => {
|
|
1214
842
|
};
|
1215
843
|
|
1216
844
|
// src/custom-element.ts
|
1217
|
-
var DEFAULT_RENDER_OPTIONS = {
|
1218
|
-
formAssociated: false,
|
1219
|
-
observedAttributes: [],
|
1220
|
-
attributesAsProperties: [],
|
1221
|
-
attachShadow: true,
|
1222
|
-
shadowRootOptions: {
|
1223
|
-
mode: "closed"
|
1224
|
-
}
|
1225
|
-
};
|
1226
|
-
if (typeof window !== "undefined") {
|
1227
|
-
class TrackableCustomElementRegistry extends window.CustomElementRegistry {
|
1228
|
-
__tagNames = /* @__PURE__ */ new Set();
|
1229
|
-
define(tagName, constructor) {
|
1230
|
-
super.define(tagName, constructor);
|
1231
|
-
this.__tagNames.add(tagName);
|
1232
|
-
}
|
1233
|
-
}
|
1234
|
-
window.CustomElementRegistry = TrackableCustomElementRegistry;
|
1235
|
-
}
|
1236
|
-
var getPropName = (attrName) => attrName.replace(/^([A-Z]+)/, (_, letter) => letter.toLowerCase()).replace(/(-|_| )([a-zA-Z])/g, (_, letter) => letter.toUpperCase());
|
1237
845
|
var customElement = (render, options) => {
|
846
|
+
const _options = { ...DEFAULT_RENDER_OPTIONS, ...options };
|
1238
847
|
const {
|
1239
848
|
formAssociated,
|
1240
849
|
observedAttributes: _observedAttributes,
|
1241
850
|
attributesAsProperties,
|
1242
851
|
attachShadow,
|
1243
852
|
shadowRootOptions: _shadowRootOptions
|
1244
|
-
} =
|
853
|
+
} = _options;
|
1245
854
|
const shadowRootOptions = { ...DEFAULT_RENDER_OPTIONS.shadowRootOptions, ..._shadowRootOptions };
|
855
|
+
const allOptions = { ..._options, shadowRootOptions };
|
856
|
+
if (isServer) {
|
857
|
+
const serverRender = render;
|
858
|
+
let _tagName2;
|
859
|
+
let _registry2;
|
860
|
+
const scopedRegistry = (() => {
|
861
|
+
if (shadowRootOptions.registry !== void 0 && "scoped" in shadowRootOptions.registry && shadowRootOptions.registry.scoped) {
|
862
|
+
return shadowRootOptions.registry;
|
863
|
+
}
|
864
|
+
})();
|
865
|
+
return {
|
866
|
+
define(tagName) {
|
867
|
+
_tagName2 = tagName;
|
868
|
+
serverDefine({
|
869
|
+
tagName,
|
870
|
+
serverRender,
|
871
|
+
options: allOptions,
|
872
|
+
scopedRegistry,
|
873
|
+
parentRegistry: _registry2
|
874
|
+
});
|
875
|
+
return this;
|
876
|
+
},
|
877
|
+
register(registry) {
|
878
|
+
if (_tagName2 !== void 0 && "eject" in registry && registry.scoped) {
|
879
|
+
console.error("Must call `register()` before `define()` for scoped registries.");
|
880
|
+
return this;
|
881
|
+
}
|
882
|
+
if ("eject" in registry) {
|
883
|
+
_registry2 = registry;
|
884
|
+
} else {
|
885
|
+
console.error("Registry must be created with `createRegistry()` for SSR.");
|
886
|
+
}
|
887
|
+
return this;
|
888
|
+
},
|
889
|
+
eject() {
|
890
|
+
throw new Error("Cannot eject a custom element on the server.");
|
891
|
+
}
|
892
|
+
};
|
893
|
+
}
|
1246
894
|
shadowRootOptions.registry = shadowRootOptions.customElements = shadowRootOptions.registry instanceof CustomElementRegistry ? shadowRootOptions.registry : shadowRootOptions.registry?.eject();
|
1247
895
|
const observedAttributesSet = new Set(_observedAttributes);
|
1248
896
|
const attributesAsPropertiesMap = /* @__PURE__ */ new Map();
|
1249
897
|
for (const [attrName, coerce] of attributesAsProperties) {
|
1250
898
|
observedAttributesSet.add(attrName);
|
1251
899
|
attributesAsPropertiesMap.set(attrName, {
|
1252
|
-
|
900
|
+
// convert kebab-case attribute names to camelCase property names
|
901
|
+
prop: attrName.replace(/^([A-Z]+)/, (_, letter) => letter.toLowerCase()).replace(/(-|_| )([a-zA-Z])/g, (_, letter) => letter.toUpperCase()),
|
1253
902
|
coerce,
|
1254
903
|
value: null
|
1255
904
|
});
|
@@ -1267,6 +916,7 @@ var customElement = (render, options) => {
|
|
1267
916
|
#formDisabledCallbackFns = /* @__PURE__ */ new Set();
|
1268
917
|
#formResetCallbackFns = /* @__PURE__ */ new Set();
|
1269
918
|
#formStateRestoreCallbackFns = /* @__PURE__ */ new Set();
|
919
|
+
#clientOnlyCallbackFns = /* @__PURE__ */ new Set();
|
1270
920
|
__customCallbackFns = /* @__PURE__ */ new Map();
|
1271
921
|
#shadowRoot = attachShadow ? this.attachShadow(shadowRootOptions) : null;
|
1272
922
|
#internals = this.attachInternals();
|
@@ -1276,8 +926,7 @@ var customElement = (render, options) => {
|
|
1276
926
|
if (mutation.type !== "attributes" || attrName === null) continue;
|
1277
927
|
if (!(attrName in this.#attrSignals)) this.#attrSignals[attrName] = createSignal(null);
|
1278
928
|
const [getter, setter] = this.#attrSignals[attrName];
|
1279
|
-
const
|
1280
|
-
const oldValue = _oldValue === null ? null : _oldValue;
|
929
|
+
const oldValue = getter();
|
1281
930
|
const newValue = this.getAttribute(attrName);
|
1282
931
|
setter(newValue);
|
1283
932
|
for (const fn of this.#attributeChangedFns) {
|
@@ -1299,6 +948,7 @@ var customElement = (render, options) => {
|
|
1299
948
|
formDisabledCallback: (fn) => this.#formDisabledCallbackFns.add(fn),
|
1300
949
|
formResetCallback: (fn) => this.#formResetCallbackFns.add(fn),
|
1301
950
|
formStateRestoreCallback: (fn) => this.#formStateRestoreCallbackFns.add(fn),
|
951
|
+
clientOnlyCallback: (fn) => this.#clientOnlyCallbackFns.add(fn),
|
1302
952
|
customCallback: (fn) => {
|
1303
953
|
const key = crypto.randomUUID();
|
1304
954
|
this.__customCallbackFns.set(key, fn);
|
@@ -1387,7 +1037,7 @@ You must set an initial value before calling a property signal's getter.
|
|
1387
1037
|
tempContainer.append(fragment.cloneNode(true));
|
1388
1038
|
const fragmentContent = tempContainer.innerHTML;
|
1389
1039
|
root.innerHTML = fragmentContent;
|
1390
|
-
if (registry
|
1040
|
+
if (registry?.__tagNames !== void 0) {
|
1391
1041
|
for (const tagName of registry.__tagNames) {
|
1392
1042
|
const upgradedElements = root.querySelectorAll(tagName);
|
1393
1043
|
const nonUpgradedElements = fragment.querySelectorAll(tagName);
|
@@ -1397,6 +1047,9 @@ You must set an initial value before calling a property signal's getter.
|
|
1397
1047
|
});
|
1398
1048
|
}
|
1399
1049
|
}
|
1050
|
+
for (const fn of this.#clientOnlyCallbackFns) {
|
1051
|
+
fn();
|
1052
|
+
}
|
1400
1053
|
setInnerHTML(root, fragment);
|
1401
1054
|
}
|
1402
1055
|
static get formAssociated() {
|
@@ -1493,79 +1146,107 @@ You must set an initial value before calling a property signal's getter.
|
|
1493
1146
|
}
|
1494
1147
|
}
|
1495
1148
|
}
|
1496
|
-
let _tagName
|
1497
|
-
let _registry
|
1498
|
-
let _registered = false;
|
1499
|
-
const register = () => {
|
1500
|
-
if (_tagName === null || _registry === null || _registered) return;
|
1501
|
-
_registry.register(_tagName, CustomElement);
|
1502
|
-
_registry.register(_tagName, elementResult);
|
1503
|
-
_registered = true;
|
1504
|
-
};
|
1149
|
+
let _tagName;
|
1150
|
+
let _registry;
|
1505
1151
|
const elementResult = {
|
1506
|
-
define(tagName) {
|
1507
|
-
const registry = _registry
|
1508
|
-
|
1152
|
+
define(tagName, options2) {
|
1153
|
+
const registry = _registry ?? customElements;
|
1154
|
+
const nativeRegistry = "eject" in registry ? registry.eject() : registry;
|
1155
|
+
if (nativeRegistry.get(tagName) !== void 0) {
|
1509
1156
|
console.warn(`Custom element "${tagName}" was already defined. Skipping...`);
|
1510
1157
|
return this;
|
1511
1158
|
}
|
1512
|
-
registry.define(tagName, CustomElement);
|
1159
|
+
registry.define(tagName, CustomElement, options2);
|
1513
1160
|
_tagName = tagName;
|
1514
|
-
register();
|
1515
1161
|
return this;
|
1516
1162
|
},
|
1517
1163
|
register(registry) {
|
1518
|
-
if (_tagName !==
|
1164
|
+
if (_tagName !== void 0 && "eject" in registry && registry.scoped) {
|
1519
1165
|
console.error("Must call `register()` before `define()` for scoped registries.");
|
1520
1166
|
return this;
|
1521
1167
|
}
|
1522
1168
|
_registry = registry;
|
1523
|
-
register();
|
1524
1169
|
return this;
|
1525
1170
|
},
|
1526
1171
|
eject: () => CustomElement
|
1527
1172
|
};
|
1528
1173
|
return elementResult;
|
1529
1174
|
};
|
1175
|
+
|
1176
|
+
// src/registry.ts
|
1530
1177
|
var createRegistry = (args) => {
|
1531
1178
|
const { scoped = false } = args ?? {};
|
1532
|
-
const
|
1533
|
-
const
|
1534
|
-
|
1535
|
-
|
1536
|
-
|
1537
|
-
|
1538
|
-
console.error(
|
1539
|
-
"Scoped custom element registries are not supported in this environment. Please install `@webcomponents/scoped-custom-element-registry` to use this feature."
|
1540
|
-
);
|
1541
|
-
return customElements;
|
1542
|
-
}
|
1179
|
+
const customElementMap = /* @__PURE__ */ new Map();
|
1180
|
+
const customElementTags = /* @__PURE__ */ new Set();
|
1181
|
+
const nativeRegistry = (() => {
|
1182
|
+
if (isServer) return;
|
1183
|
+
if (scoped) return new CustomElementRegistry();
|
1184
|
+
return customElements;
|
1543
1185
|
})();
|
1544
1186
|
return {
|
1545
|
-
|
1546
|
-
|
1547
|
-
|
1548
|
-
|
1187
|
+
__serverCss: /* @__PURE__ */ new Map(),
|
1188
|
+
__serverRenderOpts: /* @__PURE__ */ new Map(),
|
1189
|
+
define(tagName, ElementResult, options) {
|
1190
|
+
const isResult = "eject" in ElementResult;
|
1191
|
+
if (isServer) {
|
1192
|
+
if (isResult) ElementResult.register(this).define(tagName, options);
|
1193
|
+
return this;
|
1194
|
+
}
|
1195
|
+
const CustomElement = isResult ? ElementResult.eject() : ElementResult;
|
1196
|
+
if (customElementMap.has(CustomElement)) {
|
1197
|
+
console.warn(`Custom element class "${CustomElement.constructor.name}" was already defined. Skipping...`);
|
1198
|
+
return this;
|
1199
|
+
}
|
1200
|
+
if (customElementTags.has(tagName)) {
|
1201
|
+
console.warn(`Custom element tag name "${tagName}" was already defined. Skipping...`);
|
1202
|
+
return this;
|
1203
|
+
}
|
1204
|
+
customElementMap.set(CustomElement, tagName.toUpperCase());
|
1205
|
+
customElementTags.add(tagName);
|
1206
|
+
if (CustomElement === void 0) {
|
1207
|
+
console.error(`Custom element class for tag name "${tagName}" was not found. You must register it first.`);
|
1208
|
+
return this;
|
1209
|
+
}
|
1210
|
+
nativeRegistry?.define(tagName, CustomElement, options);
|
1211
|
+
return this;
|
1212
|
+
},
|
1213
|
+
getTagName: (ElementResult) => {
|
1214
|
+
const CustomElement = "eject" in ElementResult ? ElementResult.eject() : ElementResult;
|
1215
|
+
return customElementMap.get(CustomElement);
|
1216
|
+
},
|
1217
|
+
getAllTagNames: () => Array.from(customElementTags),
|
1218
|
+
eject: () => {
|
1219
|
+
if (nativeRegistry === void 0) {
|
1220
|
+
throw new Error("Cannot eject a registry on the server.");
|
1549
1221
|
}
|
1550
|
-
|
1222
|
+
return nativeRegistry;
|
1551
1223
|
},
|
1552
|
-
getTagName: (element) => registryResult.get(element),
|
1553
|
-
eject: () => registry,
|
1554
1224
|
scoped
|
1555
1225
|
};
|
1556
1226
|
};
|
1557
1227
|
// Annotate the CommonJS export names for ESM import in node:
|
1558
1228
|
0 && (module.exports = {
|
1229
|
+
clientOnlyCallback,
|
1559
1230
|
createEffect,
|
1560
1231
|
createRegistry,
|
1561
1232
|
createSignal,
|
1562
1233
|
css,
|
1563
1234
|
customElement,
|
1564
1235
|
derived,
|
1565
|
-
html
|
1236
|
+
html,
|
1237
|
+
insertTemplates,
|
1238
|
+
onServerDefine
|
1566
1239
|
});
|
1567
|
-
|
1568
|
-
|
1569
|
-
|
1570
|
-
|
1571
|
-
|
1240
|
+
/**
|
1241
|
+
* @license
|
1242
|
+
* Copyright (c) 2020 The Polymer Project Authors. All rights reserved.
|
1243
|
+
* This code may only be used under the BSD style license found at
|
1244
|
+
* http://polymer.github.io/LICENSE.txt
|
1245
|
+
* The complete set of authors may be found at
|
1246
|
+
* http://polymer.github.io/AUTHORS.txt
|
1247
|
+
* The complete set of contributors may be found at
|
1248
|
+
* http://polymer.github.io/CONTRIBUTORS.txt
|
1249
|
+
* Code distributed by Google as part of the polymer project is also
|
1250
|
+
* subject to an additional IP rights grant found at
|
1251
|
+
* http://polymer.github.io/PATENTS.txt
|
1252
|
+
*/
|