@webtides/element-js 1.0.0-alpha.1 → 1.0.0-alpha.2
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.js +25 -6
- package/dist/index.js.map +3 -3
- package/index.js +2 -1
- package/package.json +1 -1
- package/src/BaseElement.js +100 -23
- package/src/StyledElement.js +33 -3
- package/src/TemplateElement.js +24 -0
- package/src/dom-parts/TemplateResult.js +2 -1
- package/src/dom-parts/directives.js +40 -15
- package/src/util/AttributeParser.js +54 -21
- package/src/util/DOMHelper.js +43 -14
- package/src/util/Directive.js +13 -0
- package/src/util/Store.js +25 -4
- package/src/util/defineElement.js +2 -2
- package/src/util/i18n.js +3 -3
- package/src/util/toString.js +2 -2
package/dist/index.js
CHANGED
|
@@ -9,9 +9,9 @@ var __publicField = (obj, key, value) => {
|
|
|
9
9
|
function isObjectLike(value) {
|
|
10
10
|
return typeof value == "object" && value !== null;
|
|
11
11
|
}
|
|
12
|
-
function isJSON(
|
|
12
|
+
function isJSON(value) {
|
|
13
13
|
try {
|
|
14
|
-
return JSON.parse(
|
|
14
|
+
return JSON.parse(value) && !!value;
|
|
15
15
|
} catch (e) {
|
|
16
16
|
return false;
|
|
17
17
|
}
|
|
@@ -86,8 +86,9 @@ function getShadowParentOrBody(element) {
|
|
|
86
86
|
}
|
|
87
87
|
return document.body;
|
|
88
88
|
}
|
|
89
|
-
var supportsAdoptingStyleSheets = () =>
|
|
90
|
-
|
|
89
|
+
var supportsAdoptingStyleSheets = () => {
|
|
90
|
+
return "adoptedStyleSheets" in Document.prototype && "replace" in CSSStyleSheet.prototype;
|
|
91
|
+
};
|
|
91
92
|
var convertStringToTemplate = (string) => {
|
|
92
93
|
var _a;
|
|
93
94
|
const template = (_a = globalThis.document) == null ? void 0 : _a.createElement("template");
|
|
@@ -525,7 +526,8 @@ function i18n(key, fallback) {
|
|
|
525
526
|
// src/StyledElement.js
|
|
526
527
|
var _StyledElement = class extends BaseElement {
|
|
527
528
|
static updateGlobalStyles() {
|
|
528
|
-
|
|
529
|
+
var _a;
|
|
530
|
+
_StyledElement.globalStyles = (_a = globalThis.document) == null ? void 0 : _a.getElementById("globalStyles");
|
|
529
531
|
if (_StyledElement.globalStyles && _StyledElement["globalStyleSheet"]) {
|
|
530
532
|
_StyledElement["globalStyleSheet"].replaceSync(_StyledElement.globalStyles.textContent);
|
|
531
533
|
}
|
|
@@ -582,9 +584,10 @@ var _StyledElement = class extends BaseElement {
|
|
|
582
584
|
appendStyleSheets(styles) {
|
|
583
585
|
const parentDocument = getShadowParentOrBody(this.getRoot());
|
|
584
586
|
styles.forEach((style, index) => {
|
|
587
|
+
var _a;
|
|
585
588
|
const identifier = this.tagName + index;
|
|
586
589
|
if (!parentDocument.querySelector(`#${identifier}`)) {
|
|
587
|
-
const styleElement = document.createElement("style");
|
|
590
|
+
const styleElement = (_a = globalThis.document) == null ? void 0 : _a.createElement("style");
|
|
588
591
|
styleElement.id = identifier;
|
|
589
592
|
styleElement.style.display = "none";
|
|
590
593
|
styleElement.textContent = style;
|
|
@@ -1184,6 +1187,8 @@ var TemplateResult = class {
|
|
|
1184
1187
|
parts.push((value) => {
|
|
1185
1188
|
let result = pre;
|
|
1186
1189
|
if (isObjectLike(value) && value.directiveClass) {
|
|
1190
|
+
const directive = new value.directiveClass();
|
|
1191
|
+
result += directive.stringify(...value.values);
|
|
1187
1192
|
} else if (value != null) {
|
|
1188
1193
|
result += encodeAttribute(isObjectLike(value) ? JSON.stringify(value) : value);
|
|
1189
1194
|
}
|
|
@@ -1317,8 +1322,22 @@ var TemplateElement = class extends StyledElement {
|
|
|
1317
1322
|
return this.shadowRoot !== null ? this.shadowRoot : this;
|
|
1318
1323
|
}
|
|
1319
1324
|
};
|
|
1325
|
+
|
|
1326
|
+
// src/util/Directive.js
|
|
1327
|
+
var Directive = class {
|
|
1328
|
+
constructor(node) {
|
|
1329
|
+
__publicField(this, "node");
|
|
1330
|
+
this.node = node;
|
|
1331
|
+
}
|
|
1332
|
+
update() {
|
|
1333
|
+
}
|
|
1334
|
+
stringify(...values) {
|
|
1335
|
+
return "";
|
|
1336
|
+
}
|
|
1337
|
+
};
|
|
1320
1338
|
export {
|
|
1321
1339
|
BaseElement,
|
|
1340
|
+
Directive,
|
|
1322
1341
|
Store,
|
|
1323
1342
|
StyledElement,
|
|
1324
1343
|
TemplateElement,
|