@epa-wg/custom-element-dist 0.0.31 → 0.0.32

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (118) hide show
  1. package/.idea/inspectionProfiles/Project_Default.xml +2 -1
  2. package/README.md +4 -4
  3. package/coverage/coverage-final.json +6 -6
  4. package/coverage/index.html +27 -27
  5. package/coverage/src/custom-element/coverage.svg +1 -1
  6. package/coverage/src/custom-element/custom-element.js/coverage.svg +1 -1
  7. package/coverage/src/custom-element/custom-element.js.html +476 -380
  8. package/coverage/src/custom-element/http-request.js.html +10 -10
  9. package/coverage/src/custom-element/index.html +18 -18
  10. package/coverage/src/custom-element/local-storage.js.html +1 -1
  11. package/coverage/src/custom-element/location-element.js.html +1 -1
  12. package/coverage/src/custom-element/module-url.js.html +1 -1
  13. package/coverage/src/index.html +1 -1
  14. package/coverage/src/mocks/handlers.ts.html +1 -1
  15. package/coverage/src/mocks/index.html +1 -1
  16. package/coverage/src/stories/attributes.test.stories.ts/coverage.svg +1 -1
  17. package/coverage/src/stories/attributes.test.stories.ts.html +313 -13
  18. package/coverage/src/stories/coverage.svg +1 -1
  19. package/coverage/src/stories/css.test.stories.ts.html +1 -1
  20. package/coverage/src/stories/dom-merge.test.stories.ts.html +1 -1
  21. package/coverage/src/stories/external-template.test.stories.ts.html +2 -2
  22. package/coverage/src/stories/form.test.stories.ts.html +1 -1
  23. package/coverage/src/stories/http-request.stories.ts.html +1 -1
  24. package/coverage/src/stories/index.html +15 -15
  25. package/coverage/src/stories/local-storage.test.stories.ts.html +1 -1
  26. package/coverage/src/stories/location-element.test.stories.ts.html +1 -1
  27. package/coverage/src/stories/module-url.test.stories.ts.html +1 -1
  28. package/coverage/src/stories/set-url.test.stories.ts.html +1 -1
  29. package/coverage/src/stories/slice-events.test.stories.ts.html +1 -1
  30. package/coverage/src/stories/slots.test.stories.ts.html +1 -1
  31. package/coverage/src/stories/testStoryBook.ts.html +8 -8
  32. package/coverage/src/stories/version-select.test.stories.ts.html +3 -3
  33. package/coverage/src/sum.ts.html +1 -1
  34. package/dist/custom-element-D2wf_rqP.js +576 -0
  35. package/dist/custom-element-Dtzhbjkc.cjs +97 -0
  36. package/dist/custom-element-bundle.cjs +1 -1
  37. package/dist/custom-element-bundle.js +30 -28
  38. package/dist/demo/a.html +51 -38
  39. package/dist/demo/data-slices.html +2 -2
  40. package/dist/demo/external-template.html +1 -0
  41. package/dist/demo/form.html +42 -0
  42. package/dist/demo/hex-grid-dce.html +1 -1
  43. package/dist/demo/hex-grid.html +1 -1
  44. package/dist/demo/parameters.html +20 -1
  45. package/dist/demo/s.xml +6 -12
  46. package/dist/demo/s.xslt +64 -15
  47. package/dist/demo/ss.html +4 -23
  48. package/package.json +2 -2
  49. package/public/demo/a.html +51 -38
  50. package/public/demo/data-slices.html +2 -2
  51. package/public/demo/external-template.html +1 -0
  52. package/public/demo/form.html +42 -0
  53. package/public/demo/hex-grid-dce.html +1 -1
  54. package/public/demo/hex-grid.html +1 -1
  55. package/public/demo/parameters.html +20 -1
  56. package/public/demo/s.xml +6 -12
  57. package/public/demo/s.xslt +64 -15
  58. package/public/demo/ss.html +4 -23
  59. package/src/custom-element/custom-element.js +72 -40
  60. package/src/custom-element/demo/a.html +51 -38
  61. package/src/custom-element/demo/data-slices.html +2 -2
  62. package/src/custom-element/demo/external-template.html +1 -0
  63. package/src/custom-element/demo/form.html +42 -0
  64. package/src/custom-element/demo/hex-grid-dce.html +1 -1
  65. package/src/custom-element/demo/hex-grid.html +1 -1
  66. package/src/custom-element/demo/parameters.html +20 -1
  67. package/src/custom-element/demo/s.xml +6 -12
  68. package/src/custom-element/demo/s.xslt +64 -15
  69. package/src/custom-element/demo/ss.html +4 -23
  70. package/src/custom-element/ide/web-types-dce.json +1 -1
  71. package/src/custom-element/ide/web-types-xsl.json +1 -1
  72. package/src/material/components/dropdown.html +21 -4
  73. package/src/material/components/input.html +363 -0
  74. package/src/mocks/versions.mock.ts +1 -1
  75. package/src/stories/attributes.test.stories.ts +103 -3
  76. package/src/stories/external-template.test.stories.ts +1 -1
  77. package/storybook-static/assets/{Color-F6OSRLHC-CFyd3TND.js → Color-F6OSRLHC-BU3iy8jH.js} +1 -1
  78. package/storybook-static/assets/{Configure-UGTbPRKK.js → Configure-DN6ifayP.js} +1 -1
  79. package/storybook-static/assets/{DocsRenderer-CFRXHY34-Dpr5iB0o.js → DocsRenderer-CFRXHY34-BaVEufDj.js} +2 -2
  80. package/storybook-static/assets/attributes.test.stories-D1X6EBrd.js +278 -0
  81. package/storybook-static/assets/{css.test.stories-Cgn6ICr0.js → css.test.stories-Cp_g2hE1.js} +1 -1
  82. package/storybook-static/assets/custom-element-uuAtIYWS.js +97 -0
  83. package/storybook-static/assets/{dom-merge.test.stories-CBObfPWg.js → dom-merge.test.stories-hbpdCka0.js} +1 -1
  84. package/storybook-static/assets/{external-template.test.stories-VfKUQ8eu.js → external-template.test.stories-BK89h6sk.js} +3 -3
  85. package/storybook-static/assets/{form.test.stories-CnuGN7Zw.js → form.test.stories-BfoLe_rw.js} +1 -1
  86. package/storybook-static/assets/{handlers-V_T7WjNK.js → handlers-yVPwH_Nz.js} +1 -1
  87. package/storybook-static/assets/{http-request.stories-8NN1Coqm.js → http-request.stories-CBFJS2Ws.js} +1 -1
  88. package/storybook-static/assets/{iframe-DnhkgdtG.js → iframe-CJEL_4Nu.js} +2 -2
  89. package/storybook-static/assets/{index-CIBI7sCB.js → index-D5fBh-7N.js} +1 -1
  90. package/storybook-static/assets/{index-DN1RoK17.js → index-DM-KBPdl.js} +1 -1
  91. package/storybook-static/assets/{index-DjJD7gkO.js → index-RSFf30w1.js} +1 -1
  92. package/storybook-static/assets/{index-3Sfy-t3H.js → index-SnjB5uV8.js} +4 -4
  93. package/storybook-static/assets/{local-storage.test.stories-Dk5Yqc7m.js → local-storage.test.stories-C0Yzy6Am.js} +1 -1
  94. package/storybook-static/assets/{location-element.test.stories-56um6s5L.js → location-element.test.stories-DNFrEu5A.js} +1 -1
  95. package/storybook-static/assets/{module-url.test.stories-DEponQ7l.js → module-url.test.stories-CXibF5Ta.js} +1 -1
  96. package/storybook-static/assets/{preview-vbpHsp94.js → preview-Bnd0XhaF.js} +1 -1
  97. package/storybook-static/assets/{preview-Czc-sw5H.js → preview-DJMlNTk8.js} +2 -2
  98. package/storybook-static/assets/{set-url.test.stories-B4E6hIe-.js → set-url.test.stories-BBfLxv2u.js} +1 -1
  99. package/storybook-static/assets/{slice-events.test.stories-BR0F-B6I.js → slice-events.test.stories-HcXF8XQI.js} +1 -1
  100. package/storybook-static/assets/{slots.test.stories-CgfJIyCr.js → slots.test.stories-i6mnIFM2.js} +1 -1
  101. package/storybook-static/assets/{version-select.test.stories-nmxATIwv.js → version-select.test.stories-BsUFH6Va.js} +1 -1
  102. package/storybook-static/demo/a.html +51 -38
  103. package/storybook-static/demo/data-slices.html +2 -2
  104. package/storybook-static/demo/external-template.html +1 -0
  105. package/storybook-static/demo/form.html +42 -0
  106. package/storybook-static/demo/hex-grid-dce.html +1 -1
  107. package/storybook-static/demo/hex-grid.html +1 -1
  108. package/storybook-static/demo/parameters.html +20 -1
  109. package/storybook-static/demo/s.xml +6 -12
  110. package/storybook-static/demo/s.xslt +64 -15
  111. package/storybook-static/demo/ss.html +4 -23
  112. package/storybook-static/iframe.html +1 -1
  113. package/storybook-static/index.json +1 -1
  114. package/storybook-static/project.json +1 -1
  115. package/dist/custom-element-BbJMY20-.cjs +0 -97
  116. package/dist/custom-element-CoRNKeEP.js +0 -567
  117. package/storybook-static/assets/attributes.test.stories-DSOLHHOW.js +0 -152
  118. package/storybook-static/assets/custom-element-D59Fok1f.js +0 -97
@@ -1,567 +0,0 @@
1
- const W = "http://www.w3.org/1999/XSL/Transform", H = "http://www.w3.org/1999/xhtml", ue = "http://exslt.org/common", f = (e, l) => e.getAttribute?.(l), Z = (e) => e.nodeType === 3, de = (e) => typeof e == "string", pe = (e) => e && typeof e.nodeType == "number", D = (e, l) => (e.ownerDocument || e).createTextNode(l), se = (e) => {
2
- for (; e.firstChild; ) e.firstChild.remove();
3
- return e;
4
- }, V = (e) => (e.getAttributeNames().map((l) => e.removeAttribute(l)), se(e)), le = (e) => (e?.setAttribute("xmlns:xsl", W), e), ae = (e) => (e?.setAttribute("xmlns:xhtml", H), le(e)), ne = (e) => /^[_a-zA-Z][-_:a-zA-Z0-9]*$/.test(e), T = (e, l = "", t = document) => {
5
- const s = (i) => ((r) => (l && r.append(D(t.ownerDocument || t, l)), r))((t.ownerDocument || t).createElement(i));
6
- if (ne(e))
7
- return s(e);
8
- const a = s("dce-object");
9
- return a.setAttribute("dce-object-name", e), a;
10
- }, J = (e, l) => {
11
- const t = e.ownerDocument.createElementNS(e.namespaceURI, l);
12
- for (let s of e.attributes)
13
- t.setAttribute(s.name, s.value);
14
- for (; e.firstChild; )
15
- t.append(e.firstChild);
16
- return t;
17
- };
18
- function q(e) {
19
- return new DOMParser().parseFromString(e, "application/xml");
20
- }
21
- function X(e) {
22
- return new XMLSerializer().serializeToString(e);
23
- }
24
- function U(e, l, t, s) {
25
- const a = (x) => e.ownerDocument.createElement(x), r = ((x, p, N) => (p.append(N = a(x)), N))(l, e);
26
- return [...t].forEach((x) => r.append(s(x))), r;
27
- }
28
- function fe(e) {
29
- return e.slot || (e.setAttribute || (e = T("span", e.textContent.replaceAll(`
30
- `, ""))), e.setAttribute("slot", "")), e;
31
- }
32
- function K(e, l) {
33
- e.getAttributeNames().forEach((t) => l.includes(t) || e.removeAttribute(t));
34
- }
35
- const Q = (e) => [...e].filter((l) => !(l.nodeType === 3 && l.data.trim() === ""));
36
- function z(e, l, t) {
37
- const s = typeof e;
38
- if (s === "string")
39
- return T(l, e, t);
40
- if (s === "number")
41
- return T(l, "" + e, t);
42
- if (e instanceof Array) {
43
- const i = T("array", "", t);
44
- return e.map((r) => i.append(z(r, l, t))), i;
45
- }
46
- if (e instanceof FormData) {
47
- const i = T("form-data", "", t);
48
- for (const r of e)
49
- i.append(z(r[1], r[0], t));
50
- return i;
51
- }
52
- const a = T(l, "", t);
53
- for (let i in e)
54
- pe(e[i]) || typeof e[i] == "function" || e[i] instanceof Window || (typeof e[i] != "object" && ne(i) ? a.setAttribute(i, e[i]) : a.append(z(e[i], i, t)));
55
- return a;
56
- }
57
- function ee(e) {
58
- if ($(e, "*", (l) => [...l.childNodes].filter((t) => t.nodeType === 3 && t.parentNode.localName !== "style" && t.data).forEach((t) => {
59
- const s = t.data, a = s.matchAll(/{([^}]*)}/g);
60
- if (a) {
61
- let i = 0, r = (p) => D(t, p), x = [];
62
- if ([...a].forEach((p) => {
63
- p.index > i && x.push(r(p.input.substring(i, p.index)));
64
- const N = e.querySelector("value-of").cloneNode();
65
- N.setAttribute("select", p[1]), x.push(N), i = p.index + p[0].length;
66
- }), i < s.length && x.push(r(s.substring(i, s.length))), x.length) {
67
- for (let p of x)
68
- l.insertBefore(p, t);
69
- l.removeChild(t);
70
- }
71
- }
72
- })), "all" in e) {
73
- let l = 1;
74
- for (let t of e.all)
75
- t.setAttribute && !t.tagName.startsWith("xsl:") && t.setAttribute("data-dce-id", "" + l++);
76
- }
77
- return e;
78
- }
79
- function he(e, l = "xsl:stylesheet") {
80
- if (e.tagName === l || e.documentElement?.tagName === l)
81
- return ee(e);
82
- const t = q(`<xsl:stylesheet version="1.0" xmlns:xsl="${W}" xmlns:xhtml="${H}" xmlns:exsl="${ue}" exclude-result-prefixes="exsl" >
83
- <xsl:output method="xml"/>
84
- <xsl:template match="/"><dce-root xmlns="${H}"><xsl:apply-templates select="*" /></dce-root></xsl:template>
85
- <xsl:template match="*[name()='template']">
86
- <xsl:apply-templates mode="sanitize" select="*|text()"/>
87
- </xsl:template>
88
- <xsl:template match="*">
89
- <xsl:apply-templates mode="sanitize" select="*|text()"/>
90
- </xsl:template>
91
- <xsl:template match="*[name()='svg']|*[name()='math']">
92
- <xsl:apply-templates mode="sanitize" select="."/>
93
- </xsl:template>
94
- <xsl:template mode="sanitize" match="*[count(text())=1 and count(*)=0]">
95
- <xsl:copy>
96
- <xsl:apply-templates mode="sanitize" select="@*"/>
97
- <xsl:value-of select="text()"></xsl:value-of>
98
- </xsl:copy>
99
- </xsl:template>
100
- <xsl:template mode="sanitize" match="xhtml:*[count(text())=1 and count(*)=0]">
101
- <xsl:element name="{local-name()}">
102
- <xsl:apply-templates mode="sanitize" select="@*"/>
103
- <xsl:value-of select="text()"></xsl:value-of>
104
- </xsl:element>
105
- </xsl:template>
106
- <xsl:template mode="sanitize" match="*|@*">
107
- <xsl:copy>
108
- <xsl:apply-templates mode="sanitize" select="*|@*|text()"/>
109
- </xsl:copy>
110
- </xsl:template>
111
- <xsl:template mode="sanitize" match="text()[normalize-space(.) = '']"/>
112
- <xsl:template mode="sanitize" match="text()">
113
- <dce-text>
114
- <xsl:copy/>
115
- </dce-text>
116
- </xsl:template>
117
- <xsl:template mode="sanitize" match="xsl:value-of|*[name()='slot']">
118
- <xsl:copy>
119
- <xsl:apply-templates mode="sanitize" select="*|@*|text()"/>
120
- </xsl:copy>
121
- </xsl:template>
122
- <xsl:template mode="sanitize" match="xhtml:*">
123
- <xsl:element name="{local-name()}">
124
- <xsl:apply-templates mode="sanitize" select="*|@*|text()"/>
125
- </xsl:element>
126
- </xsl:template>
127
- <xsl:template mode="sanitize" match="xhtml:input">
128
- <xsl:element name="{local-name()}">
129
- <xsl:apply-templates mode="sanitize" select="*|@*|text()"/>
130
- </xsl:element>
131
- <xsl:for-each select="*">
132
- <xsl:copy>
133
- <xsl:attribute name="for" >^</xsl:attribute>
134
- <xsl:apply-templates mode="sanitize" select="*|@*|text()"/>
135
- </xsl:copy>
136
- </xsl:for-each>
137
- </xsl:template>
138
- </xsl:stylesheet>`), s = new XSLTProcessor(), a = ((n) => {
139
- $(n, "custom-element", (b) => {
140
- b.firstElementChild.localName === "template" && ([...b.firstElementChild.content.childNodes].forEach((y) => b.append(y)), b.firstElementChild.remove());
141
- }), $(n, "script", (b) => b.remove());
142
- const c = n.content ?? n.firstElementChild?.content ?? n.body ?? n;
143
- we.forEach((b) => $(c, b, (y) => Te(y, c)));
144
- const A = n.firstElementChild?.content || n.content, E = (b) => {
145
- const y = q("<xhtml/>"), j = y.importNode(b, !0);
146
- return y.replaceChild(j, y.documentElement), ae(j);
147
- };
148
- if (A) {
149
- const b = T("div");
150
- return [...A.childNodes].map((y) => b.append(y.cloneNode(!0))), E(b);
151
- }
152
- return E(n.documentElement || n.body || n);
153
- })(e), i = q(
154
- `<xsl:stylesheet version="1.0"
155
- xmlns:xsl="${W}"
156
- xmlns:xhtml="${H}"
157
- xmlns:dce="urn:schemas-epa-wg:dce"
158
- xmlns:exsl="http://exslt.org/common"
159
- exclude-result-prefixes="exsl"
160
- >
161
- <xsl:template match="ignore">
162
- <xsl:choose>
163
- <xsl:when test="//attr">{//attr}</xsl:when>
164
- <xsl:otherwise>{def}</xsl:otherwise>
165
- </xsl:choose><xsl:value-of select="."></xsl:value-of></xsl:template>
166
- <xsl:template mode="payload" match="attributes"></xsl:template>
167
- <xsl:template match="/">
168
- <xsl:apply-templates mode="payload" select="/datadom/attributes"/>
169
- </xsl:template>
170
- <xsl:template name="slot" >
171
- <xsl:param name="slotname" />
172
- <xsl:param name="defaultvalue" />
173
- <xsl:choose>
174
- <xsl:when test="//payload/*[@slot=$slotname]">
175
- <xsl:copy-of select="//payload/*[@slot=$slotname]"/>
176
- </xsl:when>
177
- <xsl:otherwise>
178
- <xsl:copy-of select="$defaultvalue"/>
179
- </xsl:otherwise>
180
- </xsl:choose>
181
- </xsl:template>
182
- <xsl:variable name="js-injected-body">
183
- <xsl:call-template name="slot" >
184
- <xsl:with-param name="slotname" select="''"/>
185
- <xsl:with-param name="defaultvalue"/>
186
- </xsl:call-template>
187
- </xsl:variable>
188
- </xsl:stylesheet>`
189
- );
190
- s.importStylesheet(t);
191
- const r = s.transformToFragment(a, document), x = (n, c) => n.querySelector(c), p = x(i, 'template[mode="payload"]');
192
- if (!r)
193
- return console.error("transformation error", { xml: a.outerHTML, xsl: X(t) });
194
- if (r.firstElementChild.localName !== "dce-root") {
195
- const n = r.ownerDocument.createElement("dce-root");
196
- [...r.childNodes].forEach((c) => n.append(c)), r.append(n);
197
- }
198
- const N = [];
199
- [...r.querySelectorAll("dce-root>attribute")].forEach((n) => {
200
- K(n, "namespace,name,select");
201
- const c = J(n, "xsl:param"), A = f(n, "name");
202
- p.append(c), K(c, "select,name");
203
- let E = f(c, "select")?.split("??");
204
- E || (E = ["//" + A, `'${c.textContent}'`], V(c), c.setAttribute("name", A));
205
- let b;
206
- if (E?.length > 1) {
207
- c.removeAttribute("select");
208
- const y = x(i, 'template[match="ignore"]>choose').cloneNode(!0);
209
- V(y.firstElementChild).append(D(y, "{" + E[0] + "}")), V(y.lastElementChild).append(D(y, "{" + E[1] + "}")), y.firstElementChild.setAttribute("test", E[0]), c.append(y), b = y.cloneNode(!0);
210
- } else
211
- b = J(n, "xsl:value-of");
212
- b.removeAttribute("name"), n.append(b), n.removeAttribute("select"), N.push(c);
213
- }), [...r.querySelectorAll("[value]")].filter((n) => n.getAttribute("value").match(/\{(.*)\?\?(.*)\}/g)).forEach((n) => {
214
- const c = f(n, "value");
215
- c && n.setAttribute("value", Ae(c));
216
- });
217
- for (const n of r.childNodes)
218
- p.append(i.importNode(n, !0));
219
- [...p.getElementsByTagName("xsl:template")].forEach((n) => p.ownerDocument.documentElement.append(n));
220
- const S = x(i, 'call-template[name="slot"]'), u = (n) => {
221
- const c = S.cloneNode(!0), A = f(n, "name");
222
- A && c.firstElementChild.setAttribute("select", `'${A}'`);
223
- for (let E of n.childNodes)
224
- c.lastElementChild.append(E);
225
- return c;
226
- };
227
- $(p, "slot", (n) => n.parentNode.replaceChild(u(n), n));
228
- const m = ee(i);
229
- return m.params = N, m;
230
- }
231
- async function xe(e) {
232
- return await new Promise((t, s) => {
233
- const a = new XMLHttpRequest();
234
- a.open("GET", e), a.responseType = "document", a.onload = () => {
235
- a.readyState === a.DONE && a.status === 200 ? t(a.responseXML?.body || a.responseXML || T("div", a.responseText)) : s(`${a.statusText} - ${e}`);
236
- }, a.addEventListener("error", (i) => s(i)), a.send();
237
- });
238
- }
239
- function be(e, l, t = !1) {
240
- if (e === l)
241
- return !0;
242
- if (typeof e != "object" || e === null || typeof l != "object" || l === null || Object.keys(e).length !== Object.keys(l).length)
243
- return t;
244
- for (let s in e)
245
- if (!(s in l) || !be(e[s], l[s]))
246
- return t;
247
- return !0;
248
- }
249
- const ie = (e) => e.split("|").map((l) => l.trim()).filter((l) => l), ye = (e, l) => ie(l).map((t) => {
250
- let s = e.ownerDocument, a = (i) => (e.append(i), i);
251
- if (t.includes("/")) {
252
- const i = [], r = s.evaluate(t, e);
253
- for (let x; x = r.iterateNext(); )
254
- i.push(x);
255
- return i;
256
- }
257
- return [...e.childNodes].find((i) => i.localName === t) || a(T(t, "", s));
258
- }).flat();
259
- function te(e, l, t, s) {
260
- if (!t.sliceProcessed)
261
- return t.sliceProcessed = 1, ye(e, l ?? "").map((a) => {
262
- const i = e.ownerDocument, r = t.sliceEventSource, x = t.sliceElement, p = () => [...a.childNodes].filter((d) => d.nodeType === 3 || d.localName === "value" || d.localName === "form-data").map((d) => d.remove());
263
- r.getAttributeNames().map((d) => a.setAttribute(d, f(r, d))), [...a.childNodes].filter((d) => d.localName === "event").map((d) => d.remove()), "validationMessage" in r && a.setAttribute("validation-message", r.validationMessage), t.type === "init" && p(), a.append(z(t, "event", i));
264
- const N = (r.type === "checkbox" || r.type === "radio") && !r.checked;
265
- if (x.hasAttribute("slice-value")) {
266
- r.value === void 0 ? a.removeAttribute("value") : a.setAttribute("value", r.value);
267
- const d = N ? "" : M(f(x, "slice-value"), a);
268
- p(), a.append(D(i, d));
269
- } else {
270
- if ("elements" in r)
271
- return p(), a.append(z(new FormData(r), "value", a.ownerDocument)), a;
272
- const d = N ? "" : r.value ?? f(r, "value");
273
- p(), d == null ? [...a.childNodes].filter((S) => S.localName !== "event").map((S) => S.remove()) : de(d) ? a.append(D(i, d)) : a.append(z(d, "value", a.ownerDocument));
274
- }
275
- return a;
276
- });
277
- }
278
- function $(e, l, t) {
279
- e.querySelectorAll && [...e.querySelectorAll(l)].forEach(t);
280
- }
281
- const ge = async (e, l) => {
282
- if (!e || !e.trim())
283
- return [l];
284
- if (e.startsWith("#"))
285
- return ((t) => {
286
- const s = t.querySelectorAll(e);
287
- return [...s.length ? s : t.getRootNode().querySelectorAll(e)];
288
- })(l.parentElement);
289
- try {
290
- const [t, s] = e.split("#");
291
- if (e.charAt(0) === ".")
292
- e = new URL(t, l.closest("[base]")?.getAttribute("base") || location).href;
293
- else
294
- try {
295
- e = import.meta.resolve(t), s && (e += "#" + s);
296
- } catch (i) {
297
- console.error(i.message);
298
- }
299
- const a = await xe(e);
300
- if (l.setAttributeNS("xml", "base", e), s) {
301
- const i = a.querySelectorAll("#" + s);
302
- return i.length ? [...i] : (console.error("template not found", e + "#" + s), [l]);
303
- }
304
- return [a];
305
- } catch {
306
- return [l];
307
- }
308
- };
309
- function ve(e, l) {
310
- for (let t of e.attributes)
311
- t.namespaceURI ? l.setAttributeNS(t.namespaceURI, t.name, t.value) : l.setAttribute(t.name, t.value), t.name === "value" && (l.value = t.value);
312
- }
313
- function oe(e, l = 0) {
314
- const t = {};
315
- for (const s of e.childNodes) {
316
- const a = f(s, "data-dce-id") || s.dceId || 0;
317
- if (!t[a])
318
- a ? t[a] = 1 : (t[a] = s.dceId = ++l, s.setAttribute && s.setAttribute("data-dce-id", s.dceId));
319
- else {
320
- const i = s.dceId = a + "-" + t[a]++;
321
- s.setAttribute && s.setAttribute("data-dce-id", i);
322
- }
323
- s.childNodes.length && oe(s);
324
- }
325
- }
326
- function Ee(e, l, t) {
327
- t = 1 * t;
328
- for (let s of e.childNodes)
329
- if ((s.dceId ?? s.getAttribute("data-dce-id") * 1) > t)
330
- return e.insertBefore(l, s);
331
- e.append(l);
332
- }
333
- function re(e, l) {
334
- if (e.firstElementChild?.localName === "dce-root" && l[0].localName !== "dce-root")
335
- return;
336
- if (!l.length)
337
- return e.firstElementChild?.localName !== "dce-root" && se(e);
338
- const t = {};
339
- for (let s of e.childNodes)
340
- t[s.dceId], Z(s) ? (s.data.trim(), t[s.dceId || 0] = s) : t[f(s, "data-dce-id") || 0] = s;
341
- for (let s of [...l]) {
342
- const a = f(s, "data-dce-id") || s.dceId, i = t[a];
343
- i ? (Z(s) ? i.nodeValue !== s.nodeValue && (i.nodeValue = s.nodeValue) : (ve(s, i), (i.childNodes.length || s.childNodes.length) && re(i, s.childNodes)), delete t[a]) : Ee(e, s, a);
344
- }
345
- for (let s of Object.values(t))
346
- s.localName !== "dce-root" && s.remove();
347
- }
348
- function Ne(e, l) {
349
- return e.hasAttribute(l) || e.setAttribute(l, crypto.randomUUID()), e.getAttribute(l);
350
- }
351
- const Ae = (e) => [...e?.matchAll(/([^{}]*)(\{)([^}]+)}([^{}]*)/g)].map((t) => `${t[1]}{${Y(t[3])}}${t[4]}`).join(""), Y = (e) => {
352
- if (!e.trim())
353
- return e;
354
- const l = e.split("??"), t = l.shift(), s = Y(l.join("??"));
355
- return l.length ? `concat( ${t} , substring( ${s} , (1+string-length( ${s} )) * string-length( ${t} ) ) )` : e;
356
- }, M = (e, l) => {
357
- const t = e.split("??");
358
- if (t.length > 1)
359
- return M(t[0], l) || M(t[1], l);
360
- e = Y(e);
361
- const s = l.ownerDocument.evaluate(e, l);
362
- switch (s.resultType) {
363
- case XPathResult.NUMBER_TYPE:
364
- return s.numberValue;
365
- case XPathResult.STRING_TYPE:
366
- return s.stringValue;
367
- case XPathResult.BOOLEAN_TYPE:
368
- return s.booleanValue;
369
- }
370
- let a = "";
371
- for (let i; i = s.iterateNext(); )
372
- a += i.textContent;
373
- return a;
374
- }, we = "stylesheet,transform,import,include,strip-space,preserve-space,output,key,decimal-format,namespace-alias,value-of,copy-of,number,apply-templates,apply-imports,for-each,sort,if,choose,when,otherwise,attribute-set,call-template,with-param,variable,param,text,processing-instruction,element,attribute,comment,copy,message,fallback".split(","), Te = (e, l) => {
375
- const t = T("xsl:" + e.localName);
376
- for (let s of e.attributes)
377
- t.setAttribute(s.name, s.value);
378
- for (; e.firstChild; )
379
- t.append(e.firstChild);
380
- if (e.parentElement)
381
- e.parentElement.replaceChild(t, e);
382
- else {
383
- const s = e.parentElement || l, a = [...s.childNodes];
384
- a.forEach((i, r) => {
385
- i === e && (a[r] = t);
386
- }), s.replaceChildren(...a);
387
- }
388
- };
389
- class Ce extends HTMLElement {
390
- static observedAttributes = ["src", "tag", "hidden"];
391
- async connectedCallback() {
392
- this.firstElementChild && this.firstElementChild.localName !== "template" && console.warn(`custom-element used without template wrapping content
393
- `, this.outerHTML);
394
- const l = await ge(f(this, "src"), this), t = f(this, "tag"), s = t || "dce-" + crypto.randomUUID();
395
- for (const u of l)
396
- $(u.templateNode || u.content || u, "style", (m) => {
397
- const n = m.closest("slot"), c = n ? `slot[name="${n.name}"]` : "";
398
- m.innerHTML = `${s} ${c}{${m.innerHTML}}`, this.append(m);
399
- });
400
- const a = l.map((u) => he(u)), i = a.map((u, m) => {
401
- m = new XSLTProcessor();
402
- try {
403
- m.importStylesheet(u);
404
- } catch (n) {
405
- console.error(n, X(u));
406
- }
407
- return m;
408
- });
409
- Object.defineProperty(this, "xsltString", { get: () => a.map((u) => X(u)).join(`
410
- `) });
411
- const r = this, x = [...this.templateNode.querySelectorAll("[slice]")], p = x.map((u) => f(u, "slice")).filter((u) => !u.includes("/")).filter((u, m, n) => n.indexOf(u) === m).map(ie).flat(), N = a.reduce((u, m) => (m.params && u.push(...m.params), u), []);
412
- class d extends HTMLElement {
413
- static get observedAttributes() {
414
- return N.map((m) => f(m, "name"));
415
- }
416
- #e = 0;
417
- connectedCallback() {
418
- let m = Q(this.childNodes);
419
- if (this.firstElementChild?.tagName === "TEMPLATE") {
420
- this.firstElementChild !== this.lastElementChild && console.error("payload should have TEMPLATE as only child", this.outerHTML);
421
- const h = this.firstElementChild;
422
- h.remove(), m = Q(h.content.childNodes);
423
- for (const g of m)
424
- if (g.localName === "style") {
425
- const o = Ne(this, "data-dce-style");
426
- g.innerHTML = `${s}[data-dce-style="${o}"]{${g.innerHTML}}`, h.insertAdjacentElement("beforebegin", g);
427
- } else
428
- g.nodeType === 1 ? h.insertAdjacentElement("beforebegin", g) : g.nodeType === 3 && h.insertAdjacentText("beforebegin", g.data);
429
- }
430
- const n = q("<datadom/>").documentElement, c = (h, g = "") => ((o) => (g && o.append(D(n, g)), o))(n.ownerDocument.createElement(h)), A = U(n, "payload", m, fe);
431
- le(A), ae(A), this.innerHTML = "";
432
- const E = U(n, "attributes", this.attributes, (h) => c(h.nodeName, h.value));
433
- U(n, "dataset", Object.keys(this.dataset), (h) => c(h, this.dataset[h]));
434
- const b = U(n, "slice", p, (h) => c(h, "")), y = (h) => M(h, b);
435
- this.xml = n;
436
- const j = [], G = () => {
437
- const h = {};
438
- for (let g; g = j.pop(); ) {
439
- const o = f(g.sliceElement, "slice");
440
- h[o] || (te(b, o, g), h[o] = g);
441
- }
442
- Object.keys(h).length !== 0 && k();
443
- };
444
- let O;
445
- this.onSlice = (h) => {
446
- j.push(h), O || (O = setTimeout(() => {
447
- G(), O = 0;
448
- }, 1));
449
- };
450
- const k = this.transform = () => {
451
- if (this.#e)
452
- debugger;
453
- this.#e = 1, i.map((o, v) => {
454
- const C = o.transformToFragment(n.ownerDocument, document);
455
- return C || console.error(`XSLT transformation error. xsl:
456
- `, X(a[v]), `
457
- xml:
458
- `, X(n)), C;
459
- }).map((o) => {
460
- o && (oe(o), re(this, o.childNodes));
461
- }), d.observedAttributes.map((o) => {
462
- let v = f(this.firstElementChild, o);
463
- v !== f(this, o) && (this.setAttribute(o, v), this.#t(o, v));
464
- });
465
- function g(o) {
466
- let v = o;
467
- if (o.localName === "slice") {
468
- const C = f(o, "for");
469
- if (C || (v = o.parentElement), C === "^")
470
- do
471
- v = v.previousElementSibling;
472
- while (v.localName === "slice");
473
- else
474
- v = this.querySelector(C);
475
- if (!v)
476
- return console.warn(`can not find selector in "slice for=${C}" `, o.outerHTML);
477
- f(o, "slice") || o.setAttribute("slice", f(o, "name"));
478
- }
479
- return v;
480
- }
481
- $(this, "[slice],[slice-event]", (o) => {
482
- let v = f(o, "slice-event");
483
- const C = o.hasAttribute("slice-value") || o.hasAttribute("value") || o.value, P = g(o);
484
- o.dceInitialized || (o.dceInitialized = 1, P.hasAttribute("custom-validity") && (v += " change submit"), [...new Set((v || "change").split(" "))].forEach((ce) => P.addEventListener(ce, (w) => {
485
- w.sliceElement = o, w.sliceEventSource = w.currentTarget || w.target, w.sliceProcessed = 0;
486
- const me = te(b, f(w.sliceElement, "slice"), w);
487
- $(this, "[custom-validity]", (R) => {
488
- if (!R.setCustomValidity)
489
- return;
490
- const F = f(R, "custom-validity");
491
- try {
492
- const I = F && M(F, E);
493
- R.setCustomValidity(I === !0 ? "" : I === !1 ? "invalid" : I);
494
- } catch (I) {
495
- console.error(I, "xPath", F);
496
- }
497
- });
498
- const _ = f(P, "custom-validity"), L = _ && M(_, E), B = L === !0 ? "" : L;
499
- if (_) {
500
- if (o.setCustomValidity ? o.setCustomValidity(B) : o.validationMessage = B, me.map((R) => R.setAttribute("validation-message", B)), w.type === "submit")
501
- return L === !0 ? void 0 : (setTimeout(k, 1), !!L === L ? (L || w.preventDefault(), L) : L ? (w.preventDefault(), !1) : void 0);
502
- setTimeout(k, 1);
503
- }
504
- this.onSlice(w);
505
- })), (!v || v.includes("init")) && (C ? this.onSlice({ type: "init", target: P, sliceElement: o, sliceEventSource: P }) : o.value = y(f(o, "slice"))));
506
- }), this.#e = 0;
507
- };
508
- k(), G();
509
- }
510
- #t(m, n) {
511
- m === "value" && (this.value = n);
512
- let c = this.xml.querySelector(`attributes>${m}`);
513
- c ? V(c).append(D(c, n)) : (c = T(m, n, this.xml), this.xml.querySelector("attributes").append(c)), this.dispatchEvent(new CustomEvent("change", { bubbles: !0, detail: { [m]: n } }));
514
- }
515
- attributeChangedCallback(m, n, c) {
516
- !this.xml || this.#e || (this.#t(m, c), this.transform());
517
- }
518
- get dce() {
519
- return r;
520
- }
521
- }
522
- const S = (u) => {
523
- window.customElements.get(u) !== d && window.customElements.define(u, d);
524
- };
525
- if (t)
526
- S(t);
527
- else {
528
- const u = s;
529
- this.setAttribute("tag", u), S(u);
530
- const m = document.createElement(u);
531
- this.getAttributeNames().forEach((n) => m.setAttribute(n, this.getAttribute(n))), m.append(...[...this.childNodes].filter((n) => n.localName !== "style")), this.append(m);
532
- }
533
- }
534
- get templateNode() {
535
- return this.firstElementChild?.tagName === "TEMPLATE" ? this.firstElementChild.content : this;
536
- }
537
- get dce() {
538
- return this;
539
- }
540
- get xslt() {
541
- return q(this.xsltString);
542
- }
543
- }
544
- window.customElements.define("custom-element", Ce);
545
- export {
546
- Ce as C,
547
- X as a,
548
- xe as b,
549
- he as c,
550
- be as d,
551
- ye as e,
552
- te as f,
553
- oe as g,
554
- Ee as h,
555
- re as i,
556
- Ne as j,
557
- Ae as k,
558
- Y as l,
559
- ve as m,
560
- M as n,
561
- z as o,
562
- we as p,
563
- Te as q,
564
- Q as s,
565
- ee as t,
566
- q as x
567
- };