@epa-wg/custom-element-dist 0.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.
Files changed (284) hide show
  1. package/.editorconfig +11 -0
  2. package/.gitignore +26 -0
  3. package/.idea/codeStyles/codeStyleConfig.xml +5 -0
  4. package/.idea/compiler.xml +6 -0
  5. package/.idea/custom-element-dist.iml +13 -0
  6. package/.idea/inspectionProfiles/Project_Default.xml +6 -0
  7. package/.idea/misc.xml +6 -0
  8. package/.idea/modules.xml +8 -0
  9. package/.idea/vcs.xml +6 -0
  10. package/.storybook/main.ts +21 -0
  11. package/.storybook/preview.ts +17 -0
  12. package/.vscode/settings.json +24 -0
  13. package/LICENSE +201 -0
  14. package/README.md +32 -0
  15. package/bin/build.sh +8 -0
  16. package/bin/clean.sh +5 -0
  17. package/bin/postinstall.sh +17 -0
  18. package/bin/start.sh +2 -0
  19. package/coverage/base.css +224 -0
  20. package/coverage/block-navigation.js +87 -0
  21. package/coverage/coverage-final.json +16 -0
  22. package/coverage/favicon.png +0 -0
  23. package/coverage/index.html +161 -0
  24. package/coverage/prettify.css +1 -0
  25. package/coverage/prettify.js +2 -0
  26. package/coverage/sort-arrow-sprite.png +0 -0
  27. package/coverage/sorter.js +196 -0
  28. package/coverage/src/coverage.svg +10 -0
  29. package/coverage/src/custom-element/coverage.svg +10 -0
  30. package/coverage/src/custom-element/custom-element.js/coverage.svg +10 -0
  31. package/coverage/src/custom-element/custom-element.js.html +2149 -0
  32. package/coverage/src/custom-element/http-request.js/coverage.svg +10 -0
  33. package/coverage/src/custom-element/http-request.js.html +352 -0
  34. package/coverage/src/custom-element/index.html +161 -0
  35. package/coverage/src/custom-element/local-storage.js/coverage.svg +10 -0
  36. package/coverage/src/custom-element/local-storage.js.html +346 -0
  37. package/coverage/src/custom-element/location-element.js/coverage.svg +10 -0
  38. package/coverage/src/custom-element/location-element.js.html +343 -0
  39. package/coverage/src/index.html +116 -0
  40. package/coverage/src/mocks/coverage.svg +10 -0
  41. package/coverage/src/mocks/handlers.ts/coverage.svg +10 -0
  42. package/coverage/src/mocks/handlers.ts.html +172 -0
  43. package/coverage/src/mocks/index.html +116 -0
  44. package/coverage/src/stories/attributes.stories.ts/coverage.svg +10 -0
  45. package/coverage/src/stories/attributes.stories.ts.html +481 -0
  46. package/coverage/src/stories/coverage.svg +10 -0
  47. package/coverage/src/stories/css.stories.ts/coverage.svg +10 -0
  48. package/coverage/src/stories/css.stories.ts.html +397 -0
  49. package/coverage/src/stories/dom-merge.stories.ts/coverage.svg +10 -0
  50. package/coverage/src/stories/dom-merge.stories.ts.html +424 -0
  51. package/coverage/src/stories/external-template.stories.ts/coverage.svg +10 -0
  52. package/coverage/src/stories/external-template.stories.ts.html +820 -0
  53. package/coverage/src/stories/http-request.stories.ts/coverage.svg +10 -0
  54. package/coverage/src/stories/http-request.stories.ts.html +817 -0
  55. package/coverage/src/stories/index.html +236 -0
  56. package/coverage/src/stories/local-storage.stories.ts/coverage.svg +10 -0
  57. package/coverage/src/stories/local-storage.stories.ts.html +1249 -0
  58. package/coverage/src/stories/location-element.stories.ts/coverage.svg +10 -0
  59. package/coverage/src/stories/location-element.stories.ts.html +484 -0
  60. package/coverage/src/stories/renderPlay.ts/coverage.svg +10 -0
  61. package/coverage/src/stories/renderPlay.ts.html +151 -0
  62. package/coverage/src/stories/slice-events.stories.ts/coverage.svg +10 -0
  63. package/coverage/src/stories/slice-events.stories.ts.html +436 -0
  64. package/coverage/src/sum.ts/coverage.svg +10 -0
  65. package/coverage/src/sum.ts.html +94 -0
  66. package/dist/confused.svg +37 -0
  67. package/dist/custom-element-B4v-KaIh.cjs +53 -0
  68. package/dist/custom-element-_g0GTup2.js +436 -0
  69. package/dist/custom-element-bundle.cjs +1 -0
  70. package/dist/custom-element-bundle.js +31 -0
  71. package/dist/embed-1.html +3 -0
  72. package/dist/html-template.html +126 -0
  73. package/dist/html-template.xhtml +45 -0
  74. package/dist/html-template.xml +45 -0
  75. package/dist/http-request-BOvP4KTl.js +56 -0
  76. package/dist/http-request-DPrY7mGh.cjs +1 -0
  77. package/dist/local-storage-Boafngui.cjs +1 -0
  78. package/dist/local-storage-BqDEu2kF.js +59 -0
  79. package/dist/location-element-2m0gWq_d.cjs +1 -0
  80. package/dist/location-element-nA_wsqBt.js +49 -0
  81. package/dist/mockServiceWorker.js +284 -0
  82. package/dist/tree.xsl +33 -0
  83. package/dist/vite.svg +1 -0
  84. package/index.html +17 -0
  85. package/package.json +97 -0
  86. package/public/confused.svg +37 -0
  87. package/public/embed-1.html +3 -0
  88. package/public/html-template.html +126 -0
  89. package/public/html-template.xhtml +45 -0
  90. package/public/html-template.xml +45 -0
  91. package/public/mockServiceWorker.js +284 -0
  92. package/public/tree.xsl +33 -0
  93. package/public/vite.svg +1 -0
  94. package/src/assets/lit.svg +1 -0
  95. package/src/custom-element/custom-element.d.ts +36 -0
  96. package/src/custom-element/custom-element.js +688 -0
  97. package/src/custom-element/demo/a.html +63 -0
  98. package/src/custom-element/demo/confused.svg +37 -0
  99. package/src/custom-element/demo/data-slices.html +184 -0
  100. package/src/custom-element/demo/dce-social-preview.png +0 -0
  101. package/src/custom-element/demo/demo.css +22 -0
  102. package/src/custom-element/demo/dom-merge.html +123 -0
  103. package/src/custom-element/demo/embed-1.html +3 -0
  104. package/src/custom-element/demo/external-template.html +179 -0
  105. package/src/custom-element/demo/hex-grid-dce.html +183 -0
  106. package/src/custom-element/demo/hex-grid-transform.png +0 -0
  107. package/src/custom-element/demo/hex-grid.html +66 -0
  108. package/src/custom-element/demo/html-template.html +126 -0
  109. package/src/custom-element/demo/html-template.xhtml +45 -0
  110. package/src/custom-element/demo/html-template.xml +45 -0
  111. package/src/custom-element/demo/http-request.html +143 -0
  112. package/src/custom-element/demo/local-storage.html +218 -0
  113. package/src/custom-element/demo/location-element.html +155 -0
  114. package/src/custom-element/demo/logo.png +0 -0
  115. package/src/custom-element/demo/parameters.html +70 -0
  116. package/src/custom-element/demo/s.xml +14 -0
  117. package/src/custom-element/demo/s.xslt +76 -0
  118. package/src/custom-element/demo/scoped-css.html +169 -0
  119. package/src/custom-element/demo/ss.html +57 -0
  120. package/src/custom-element/demo/table.xml +25 -0
  121. package/src/custom-element/demo/table.xsl +293 -0
  122. package/src/custom-element/demo/template.xsl +46 -0
  123. package/src/custom-element/demo/tree.xml +25 -0
  124. package/src/custom-element/demo/tree.xsl +33 -0
  125. package/src/custom-element/demo/wc-square.svg +1 -0
  126. package/src/custom-element/demo/xhtml-template.xhtml +45 -0
  127. package/src/custom-element/demo/z.html +62 -0
  128. package/src/custom-element/demo/z.xml +60 -0
  129. package/src/custom-element/http-request.js +89 -0
  130. package/src/custom-element/ide/IDE.md +31 -0
  131. package/src/custom-element/ide/customData-dce.json +112 -0
  132. package/src/custom-element/ide/customData-xsl.json +1018 -0
  133. package/src/custom-element/ide/web-types-dce.json +111 -0
  134. package/src/custom-element/ide/web-types-xsl.json +867 -0
  135. package/src/custom-element/index.html +168 -0
  136. package/src/custom-element/index.js +7 -0
  137. package/src/custom-element/local-storage.js +87 -0
  138. package/src/custom-element/location-element.js +87 -0
  139. package/src/custom-element.test.ts +10 -0
  140. package/src/index.css +38 -0
  141. package/src/mocks/handlers.ts +29 -0
  142. package/src/mocks/pokemons.mock.ts +13 -0
  143. package/src/stories/Configure.mdx +364 -0
  144. package/src/stories/assets/accessibility.png +0 -0
  145. package/src/stories/assets/accessibility.svg +5 -0
  146. package/src/stories/assets/addon-library.png +0 -0
  147. package/src/stories/assets/assets.png +0 -0
  148. package/src/stories/assets/avif-test-image.avif +0 -0
  149. package/src/stories/assets/context.png +0 -0
  150. package/src/stories/assets/discord.svg +15 -0
  151. package/src/stories/assets/docs.png +0 -0
  152. package/src/stories/assets/figma-plugin.png +0 -0
  153. package/src/stories/assets/github.svg +3 -0
  154. package/src/stories/assets/share.png +0 -0
  155. package/src/stories/assets/styling.png +0 -0
  156. package/src/stories/assets/testing.png +0 -0
  157. package/src/stories/assets/theming.png +0 -0
  158. package/src/stories/assets/tutorials.svg +12 -0
  159. package/src/stories/assets/youtube.svg +4 -0
  160. package/src/stories/attributes.stories.ts +132 -0
  161. package/src/stories/attributes.test.ts +14 -0
  162. package/src/stories/css.stories.ts +104 -0
  163. package/src/stories/css.test.ts +12 -0
  164. package/src/stories/dom-merge.stories.ts +113 -0
  165. package/src/stories/dom-merge.test.ts +12 -0
  166. package/src/stories/external-template.stories.ts +245 -0
  167. package/src/stories/external-template.test.ts +12 -0
  168. package/src/stories/http-request.stories.ts +244 -0
  169. package/src/stories/http-request.test.ts +29 -0
  170. package/src/stories/local-storage.stories.ts +388 -0
  171. package/src/stories/local-storage.test.ts +12 -0
  172. package/src/stories/location-element.stories.ts +133 -0
  173. package/src/stories/location-element.test.ts +14 -0
  174. package/src/stories/renderPlay.ts +22 -0
  175. package/src/stories/slice-events.stories.ts +117 -0
  176. package/src/stories/slice-events.test.ts +12 -0
  177. package/src/sum.test.ts +6 -0
  178. package/src/sum.ts +4 -0
  179. package/src/vite-env.d.ts +1 -0
  180. package/storybook-static/assets/Color-RQJUDNI5-C4yZhNbM.js +1 -0
  181. package/storybook-static/assets/Configure-C7d36rng.js +173 -0
  182. package/storybook-static/assets/DocsRenderer-K4EAMTCU-BLMupvSb.js +2 -0
  183. package/storybook-static/assets/WithTooltip-Y7J54OF7-BAQSPSFk.js +1 -0
  184. package/storybook-static/assets/accessibility-W_h2acOZ.png +0 -0
  185. package/storybook-static/assets/addon-library-BWUCAmyN.png +0 -0
  186. package/storybook-static/assets/attributes.stories-ZB0RTY1d.js +151 -0
  187. package/storybook-static/assets/context-C0qIqeS4.png +0 -0
  188. package/storybook-static/assets/css.stories-CLSX-Xxd.js +86 -0
  189. package/storybook-static/assets/custom-element-BLZZ00dz.js +53 -0
  190. package/storybook-static/assets/docs---vsFbMi.png +0 -0
  191. package/storybook-static/assets/dom-merge.stories-CgHZUABU.js +138 -0
  192. package/storybook-static/assets/entry-preview-CQqNFx4W.js +8 -0
  193. package/storybook-static/assets/entry-preview-docs-CWgqLfd3.js +2 -0
  194. package/storybook-static/assets/external-template.stories-DtSLMxvg.js +316 -0
  195. package/storybook-static/assets/figma-plugin-CH2hELiO.png +0 -0
  196. package/storybook-static/assets/formatter-B5HCVTEV-tKeEfJA9.js +58 -0
  197. package/storybook-static/assets/http-request.stories-CUzlXO89.js +300 -0
  198. package/storybook-static/assets/iframe-gCvlWuoC.js +2 -0
  199. package/storybook-static/assets/index-CBQwM6ST.js +508 -0
  200. package/storybook-static/assets/index-CDavW7r9.js +193 -0
  201. package/storybook-static/assets/index-CQA5dlr6.js +13 -0
  202. package/storybook-static/assets/index-Cc7K62zD.js +3 -0
  203. package/storybook-static/assets/index-DgaNIR0t.js +1 -0
  204. package/storybook-static/assets/index-Dkj0J1ds.js +1 -0
  205. package/storybook-static/assets/index-DnEJ_bKa.js +1 -0
  206. package/storybook-static/assets/index-DrFu-skq.js +6 -0
  207. package/storybook-static/assets/lit-element-B4_0akdT.js +19 -0
  208. package/storybook-static/assets/local-storage.stories-BkO6djDz.js +415 -0
  209. package/storybook-static/assets/location-element.stories-DCIOUd0D.js +108 -0
  210. package/storybook-static/assets/preview-B4GcaC1c.js +1 -0
  211. package/storybook-static/assets/preview-B63p-W8V.js +20 -0
  212. package/storybook-static/assets/preview-BAz7FMXc.js +396 -0
  213. package/storybook-static/assets/preview-BDY5ThwJ.js +1 -0
  214. package/storybook-static/assets/preview-C6t8KBFr.js +1 -0
  215. package/storybook-static/assets/preview-CYD85dwb.js +7 -0
  216. package/storybook-static/assets/preview-CkgAD_DE.js +2 -0
  217. package/storybook-static/assets/preview-D8LadFCz.js +48 -0
  218. package/storybook-static/assets/preview-DNpCpRPf.js +1 -0
  219. package/storybook-static/assets/preview-PxUn-cIn.js +1 -0
  220. package/storybook-static/assets/share-DGA-UcQf.png +0 -0
  221. package/storybook-static/assets/slice-events.stories-DXKjXI37.js +115 -0
  222. package/storybook-static/assets/styling-Bk6zjRzU.png +0 -0
  223. package/storybook-static/assets/syntaxhighlighter-JOJW2KGS-C04pIVD3.js +1 -0
  224. package/storybook-static/assets/testing-cbzR9l9r.png +0 -0
  225. package/storybook-static/assets/theming-D6WJLNoW.png +0 -0
  226. package/storybook-static/assets/tiny-invariant-BxWVcicq.js +1 -0
  227. package/storybook-static/confused.svg +37 -0
  228. package/storybook-static/embed-1.html +3 -0
  229. package/storybook-static/favicon.svg +7 -0
  230. package/storybook-static/html-template.html +126 -0
  231. package/storybook-static/html-template.xhtml +45 -0
  232. package/storybook-static/html-template.xml +45 -0
  233. package/storybook-static/iframe.html +492 -0
  234. package/storybook-static/index.html +163 -0
  235. package/storybook-static/index.json +1 -0
  236. package/storybook-static/mockServiceWorker.js +284 -0
  237. package/storybook-static/project.json +1 -0
  238. package/storybook-static/sb-addons/chromatic-com-storybook-9/manager-bundle.js +327 -0
  239. package/storybook-static/sb-addons/chromatic-com-storybook-9/manager-bundle.js.LEGAL.txt +40 -0
  240. package/storybook-static/sb-addons/essentials-actions-3/manager-bundle.js +3 -0
  241. package/storybook-static/sb-addons/essentials-actions-3/manager-bundle.js.LEGAL.txt +0 -0
  242. package/storybook-static/sb-addons/essentials-backgrounds-4/manager-bundle.js +12 -0
  243. package/storybook-static/sb-addons/essentials-backgrounds-4/manager-bundle.js.LEGAL.txt +0 -0
  244. package/storybook-static/sb-addons/essentials-controls-2/manager-bundle.js +60 -0
  245. package/storybook-static/sb-addons/essentials-controls-2/manager-bundle.js.LEGAL.txt +18 -0
  246. package/storybook-static/sb-addons/essentials-measure-7/manager-bundle.js +3 -0
  247. package/storybook-static/sb-addons/essentials-measure-7/manager-bundle.js.LEGAL.txt +0 -0
  248. package/storybook-static/sb-addons/essentials-outline-8/manager-bundle.js +3 -0
  249. package/storybook-static/sb-addons/essentials-outline-8/manager-bundle.js.LEGAL.txt +0 -0
  250. package/storybook-static/sb-addons/essentials-toolbars-6/manager-bundle.js +3 -0
  251. package/storybook-static/sb-addons/essentials-toolbars-6/manager-bundle.js.LEGAL.txt +0 -0
  252. package/storybook-static/sb-addons/essentials-viewport-5/manager-bundle.js +3 -0
  253. package/storybook-static/sb-addons/essentials-viewport-5/manager-bundle.js.LEGAL.txt +0 -0
  254. package/storybook-static/sb-addons/interactions-10/manager-bundle.js +33 -0
  255. package/storybook-static/sb-addons/interactions-10/manager-bundle.js.LEGAL.txt +0 -0
  256. package/storybook-static/sb-addons/links-1/manager-bundle.js +3 -0
  257. package/storybook-static/sb-addons/links-1/manager-bundle.js.LEGAL.txt +0 -0
  258. package/storybook-static/sb-addons/storybook-core-server-presets-0/common-manager-bundle.js +3 -0
  259. package/storybook-static/sb-addons/storybook-core-server-presets-0/common-manager-bundle.js.LEGAL.txt +0 -0
  260. package/storybook-static/sb-common-assets/fonts.css +31 -0
  261. package/storybook-static/sb-common-assets/nunito-sans-bold-italic.woff2 +0 -0
  262. package/storybook-static/sb-common-assets/nunito-sans-bold.woff2 +0 -0
  263. package/storybook-static/sb-common-assets/nunito-sans-italic.woff2 +0 -0
  264. package/storybook-static/sb-common-assets/nunito-sans-regular.woff2 +0 -0
  265. package/storybook-static/sb-manager/WithTooltip-Y7J54OF7-CEHQ77YF.js +1 -0
  266. package/storybook-static/sb-manager/chunk-E3WK6ZOZ.js +234 -0
  267. package/storybook-static/sb-manager/chunk-E6ABNH5R.js +183 -0
  268. package/storybook-static/sb-manager/chunk-FEE35O7J.js +9 -0
  269. package/storybook-static/sb-manager/chunk-S4VOIVUE.js +347 -0
  270. package/storybook-static/sb-manager/chunk-XCO5HRLK.js +6 -0
  271. package/storybook-static/sb-manager/chunk-XP3HGWTR.js +1 -0
  272. package/storybook-static/sb-manager/formatter-B5HCVTEV-7DCBOGO6.js +58 -0
  273. package/storybook-static/sb-manager/globals-module-info.js +1 -0
  274. package/storybook-static/sb-manager/globals-runtime.js +1 -0
  275. package/storybook-static/sb-manager/globals.js +1 -0
  276. package/storybook-static/sb-manager/index.js +1 -0
  277. package/storybook-static/sb-manager/runtime.js +1 -0
  278. package/storybook-static/sb-manager/syntaxhighlighter-JOJW2KGS-VF6EEVPI.js +1 -0
  279. package/storybook-static/sb-preview/globals.js +1 -0
  280. package/storybook-static/sb-preview/runtime.js +139 -0
  281. package/storybook-static/tree.xsl +33 -0
  282. package/storybook-static/vite.svg +1 -0
  283. package/tsconfig.json +25 -0
  284. package/vite.config.js +55 -0
@@ -0,0 +1,688 @@
1
+ const XSL_NS_URL = 'http://www.w3.org/1999/XSL/Transform'
2
+ , HTML_NS_URL = 'http://www.w3.org/1999/xhtml'
3
+ , EXSL_NS_URL = 'http://exslt.org/common'
4
+ , DCE_NS_URL ="urn:schemas-epa-wg:dce";
5
+
6
+ // const log = x => console.debug( new XMLSerializer().serializeToString( x ) );
7
+
8
+ const attr = (el, attr)=> el.getAttribute?.(attr)
9
+ , isText = e => e.nodeType === 3
10
+ , isString = s => typeof s === 'string'
11
+ , isNode = e => e && typeof e.nodeType === 'number'
12
+ , create = ( tag, t = '', d=document ) => ( e => ((t && e.append(createText(d.ownerDocument||d, t))),e) )((d.ownerDocument || d ).createElement( tag ))
13
+ , createText = ( d, t) => (d.ownerDocument || d ).createTextNode( t )
14
+ , removeChildren = n => { while(n.firstChild) n.firstChild.remove(); return n; }
15
+ , emptyNode = n => { n.getAttributeNames().map( a => n.removeAttribute(a) ); return removeChildren(n); }
16
+ , createNS = ( ns, tag, t = '' ) => ( e => ((e.innerText = t||''),e) )(document.createElementNS( ns, tag ))
17
+ , xslNs = x => ( x?.setAttribute('xmlns:xsl', XSL_NS_URL ), x )
18
+ , xslHtmlNs = x => ( x?.setAttribute('xmlns:xhtml', HTML_NS_URL ), xslNs(x) )
19
+ , cloneAs = (p,tag) =>
20
+ { const px = p.ownerDocument.createElementNS(p.namespaceURI,tag);
21
+ for( let a of p.attributes)
22
+ px.setAttribute(a.name, a.value);
23
+ while( p.firstChild )
24
+ px.append(p.firstChild);
25
+ return px;
26
+ }
27
+
28
+ function
29
+ ASSERT(x)
30
+ {
31
+ // if(!x)
32
+ // debugger
33
+ }
34
+ export function
35
+ xml2dom( xmlString )
36
+ {
37
+ return new DOMParser().parseFromString( xmlString, "application/xml" )
38
+ }
39
+ export function
40
+ xmlString(doc){ return new XMLSerializer().serializeToString( doc ) }
41
+
42
+ function
43
+ injectData( root, sectionName, arr, cb )
44
+ { const create = ( tag ) => root.ownerDocument.createElement( tag );
45
+ const inject = ( tag, parent, s ) =>
46
+ { parent.append( s = create( tag ) );
47
+ return s;
48
+ };
49
+ const l = inject( sectionName, root );
50
+ [ ...arr ].forEach( e => l.append( cb( e ) ) );
51
+ return l;
52
+ }
53
+
54
+ function
55
+ assureSlot( e )
56
+ {
57
+ if( !e.slot )
58
+ {
59
+ if( !e.setAttribute )
60
+ e = create( 'span', e.textContent.replaceAll( '\n', '' ) );
61
+ e.setAttribute( 'slot', '' )
62
+ }
63
+ return e;
64
+ }
65
+
66
+ export function
67
+ obj2node( o, tag, doc )
68
+ { const t = typeof o;
69
+ if( t === 'function'){debugger}
70
+ if( t === 'string' )
71
+ return create(tag,o,doc);
72
+ if( t === 'number' )
73
+ return create(tag,''+o,doc);
74
+
75
+ if( o instanceof Array )
76
+ { const ret = create('array');
77
+ o.map( ae => ret.append( obj2node(ae,tag,doc)) );
78
+ return ret
79
+ }
80
+ const ret = create(tag,'',doc);
81
+ for( let k in o )
82
+ if( isNode(o[k]) || typeof o[k] ==='function' || o[k] instanceof Window )
83
+ continue
84
+ else
85
+ if( typeof o[k] !== "object" )
86
+ ret.setAttribute(k, o[k] );
87
+ else
88
+ ret.append(obj2node(o[k], k, doc))
89
+ return ret;
90
+ }
91
+ export function
92
+ tagUid( node )
93
+ { // {} to xsl:value-of
94
+ forEach$(node,'*',d => [...d.childNodes].filter( e=>e.nodeType === 3 ).forEach( e=>
95
+ { if( e.parentNode.localName === 'style' )
96
+ return;
97
+ const m = e.data.matchAll( /{([^}]*)}/g );
98
+ if(m)
99
+ { let l = 0
100
+ , txt = t => createText(e,t||'')
101
+ , tt = [];
102
+ [...m].forEach(t=>
103
+ { if( t.index > l )
104
+ tt.push( txt( t.input.substring( l, t.index ) ))
105
+ const v = node.querySelector('value-of').cloneNode();
106
+ v.setAttribute('select', t[1] );
107
+ tt.push(v);
108
+ l = t.index+t[0].length;
109
+ })
110
+ if( l < e.data.length)
111
+ tt.push( txt( e.data.substring(l,e.data.length) ));
112
+ if( tt.length )
113
+ { for( let t of tt )
114
+ d.insertBefore(t,e);
115
+ d.removeChild(e);
116
+ }
117
+ }
118
+ }));
119
+
120
+ if( 'all' in node ) {
121
+ let i= 1;
122
+ for( let e of node.all )
123
+ e.setAttribute && !e.tagName.startsWith('xsl:') && e.setAttribute('data-dce-id', '' + i++)
124
+ }
125
+ return node
126
+ }
127
+ export function
128
+ createXsltFromDom( templateNode, S = 'xsl:stylesheet' )
129
+ {
130
+ if( templateNode.tagName === S || templateNode.documentElement?.tagName === S )
131
+ return tagUid(templateNode)
132
+ const sanitizeXsl = xml2dom(`<xsl:stylesheet version="1.0" xmlns:xsl="${ XSL_NS_URL }" xmlns:xhtml="${ HTML_NS_URL }" xmlns:exsl="${EXSL_NS_URL}" exclude-result-prefixes="exsl" >
133
+ <xsl:output method="xml" />
134
+ <xsl:template match="/"><dce-root xmlns="${ HTML_NS_URL }"><xsl:apply-templates select="*"/></dce-root></xsl:template>
135
+ <xsl:template match="*[name()='template']"><xsl:apply-templates mode="sanitize" select="*|text()"/></xsl:template>
136
+ <xsl:template match="*"><xsl:apply-templates mode="sanitize" select="*|text()"/></xsl:template>
137
+ <xsl:template match="*[name()='svg']|*[name()='math']"><xsl:apply-templates mode="sanitize" select="."/></xsl:template>
138
+ <xsl:template mode="sanitize" match="*[count(text())=1 and count(*)=0]"><xsl:copy><xsl:apply-templates mode="sanitize" select="@*"/><xsl:value-of select="text()"></xsl:value-of></xsl:copy></xsl:template>
139
+ <xsl:template mode="sanitize" match="xhtml:*[count(text())=1 and count(*)=0]"><xsl:element name="{local-name()}"><xsl:apply-templates mode="sanitize" select="@*"/><xsl:value-of select="text()"></xsl:value-of></xsl:element></xsl:template>
140
+ <xsl:template mode="sanitize" match="*|@*"><xsl:copy><xsl:apply-templates mode="sanitize" select="*|@*|text()"/></xsl:copy></xsl:template>
141
+ <xsl:template mode="sanitize" match="text()[normalize-space(.) = '']"/>
142
+ <xsl:template mode="sanitize" match="text()"><dce-text><xsl:copy/></dce-text></xsl:template>
143
+ <xsl:template mode="sanitize" match="xsl:value-of|*[name()='slot']"><dce-text><xsl:copy><xsl:apply-templates mode="sanitize" select="*|@*|text()"/></xsl:copy></dce-text></xsl:template>
144
+ <xsl:template mode="sanitize" match="xhtml:*"><xsl:element name="{local-name()}"><xsl:apply-templates mode="sanitize" select="*|@*|text()"/></xsl:element></xsl:template>
145
+ </xsl:stylesheet>`)
146
+ const sanitizeProcessor = new XSLTProcessor()
147
+ , tc = (n =>
148
+ {
149
+ forEach$(n,'script', s=> s.remove() );
150
+ const xslRoot = n.content ?? n.firstElementChild?.content ?? n.body ?? n;
151
+ xslTags.forEach( tag => forEach$( xslRoot, tag, el=>toXsl(el,xslRoot) ) );
152
+ const e = n.firstElementChild?.content || n.content
153
+ , asXmlNode = r => {
154
+ const d = xml2dom( '<xhtml/>' )
155
+ , n = d.importNode(r, true);
156
+ d.replaceChild(n,d.documentElement);
157
+ return xslHtmlNs(n);
158
+ };
159
+ if( e )
160
+ { const t = create('div');
161
+ [ ...e.childNodes ].map( c => t.append(c.cloneNode(true)) )
162
+ return asXmlNode(t)
163
+ }
164
+ return asXmlNode(n.documentElement || n.body || n)
165
+ })(templateNode)
166
+ , xslDom = xml2dom(
167
+ `<xsl:stylesheet version="1.0"
168
+ xmlns:xsl="${ XSL_NS_URL }"
169
+ xmlns:xhtml="${ HTML_NS_URL }"
170
+ xmlns:dce="urn:schemas-epa-wg:dce"
171
+ xmlns:exsl="http://exslt.org/common"
172
+ exclude-result-prefixes="exsl"
173
+ >
174
+ <xsl:template match="ignore">
175
+ <xsl:choose>
176
+ <xsl:when test="//attr">{//attr}</xsl:when>
177
+ <xsl:otherwise>{def}</xsl:otherwise>
178
+ </xsl:choose><xsl:value-of select="."></xsl:value-of></xsl:template>
179
+ <xsl:template mode="payload" match="attributes"></xsl:template>
180
+ <xsl:template match="/">
181
+ <xsl:apply-templates mode="payload" select="/datadom/attributes"/>
182
+ </xsl:template>
183
+ <xsl:template name="slot" >
184
+ <xsl:param name="slotname" />
185
+ <xsl:param name="defaultvalue" />
186
+ <xsl:choose>
187
+ <xsl:when test="//payload/*[@slot=$slotname]">
188
+ <xsl:copy-of select="//payload/*[@slot=$slotname]"/>
189
+ </xsl:when>
190
+ <xsl:otherwise>
191
+ <xsl:copy-of select="$defaultvalue"/>
192
+ </xsl:otherwise>
193
+ </xsl:choose>
194
+ </xsl:template>
195
+ <xsl:variable name="js-injected-body">
196
+ <xsl:call-template name="slot" >
197
+ <xsl:with-param name="slotname" select="''"/>
198
+ <xsl:with-param name="defaultvalue"/>
199
+ </xsl:call-template>
200
+ </xsl:variable>
201
+ </xsl:stylesheet>`
202
+ );
203
+
204
+ sanitizeProcessor.importStylesheet( sanitizeXsl );
205
+
206
+ const fr = sanitizeProcessor.transformToFragment(tc, document)
207
+ , $ = (e,css) => e.querySelector(css)
208
+ , payload = $( xslDom, 'template[mode="payload"]');
209
+ if( !fr )
210
+ return console.error("transformation error",{ xml:tc.outerHTML, xsl: xmlString( sanitizeXsl ) });
211
+ const params = [];
212
+ [...fr.querySelectorAll('dce-root>attribute')].forEach( a=>
213
+ {
214
+ const p = cloneAs(a,'xsl:param')
215
+ , name = attr(a,'name');
216
+ payload.append(p);
217
+ let select = attr(p,'select')?.split('??')
218
+ if( !select)
219
+ { select = ['//'+name, `'${p.textContent}'`];
220
+ emptyNode(p);
221
+ p.setAttribute('name',name);
222
+ }
223
+ let val;
224
+ if( select?.length>1 ){
225
+ p.removeAttribute('select');
226
+ const c = $( xslDom, 'template[match="ignore"]>choose').cloneNode(true);
227
+ emptyNode(c.firstElementChild).append( createText(c,'{'+select[0]+'}'));
228
+ emptyNode(c.lastElementChild ).append( createText(c,'{'+select[1]+'}'));
229
+ c.firstElementChild.setAttribute('test',select[0]);
230
+ p.append(c);
231
+ val = c.cloneNode(true);
232
+ }else
233
+ val=cloneAs(a,'xsl:value-of');
234
+ val.removeAttribute('name');
235
+ a.append(val);
236
+ a.removeAttribute('select');
237
+ params.push(p)
238
+ });
239
+ [...fr.querySelectorAll('[value]')].filter(el=>el.getAttribute('value').match( /\{(.*)\?\?(.*)\}/g )).forEach(el=>
240
+ { const v = attr(el,'value');
241
+ if(v)
242
+ el.setAttribute('value', evalCurly(v));
243
+ });
244
+ for( const c of fr.childNodes )
245
+ payload.append(xslDom.importNode(c,true))
246
+
247
+ const embeddedTemplates = [...payload.querySelectorAll('template')];
248
+ embeddedTemplates.forEach(t=>payload.ownerDocument.documentElement.append(t));
249
+
250
+ const slotCall = $(xslDom,'call-template[name="slot"]')
251
+ , slot2xsl = s =>
252
+ { const v = slotCall.cloneNode(true)
253
+ , name = attr(s,'name') || '';
254
+ name && v.firstElementChild.setAttribute('select',`'${ name }'`)
255
+ for( let c of s.childNodes)
256
+ v.lastElementChild.append(c)
257
+ return v
258
+ }
259
+
260
+ forEach$( payload,'slot', s => s.parentNode.replaceChild( slot2xsl(s), s ) )
261
+
262
+ const ret = tagUid(xslDom)
263
+ ret.params = params;
264
+ return ret;
265
+ }
266
+ export async function
267
+ xhrTemplate(src)
268
+ {
269
+ const dom = await new Promise((resolve,reject)=>
270
+ { const xhr = new XMLHttpRequest();
271
+ xhr.open("GET", src);
272
+ xhr.responseType = "document";
273
+ // xhr.overrideMimeType("text/xml");
274
+ xhr.onload = () =>
275
+ { if( xhr.readyState === xhr.DONE && xhr.status === 200 )
276
+ resolve( xhr.responseXML || create('div', xhr.responseText ) )
277
+ reject(xhr.statusText)
278
+ };
279
+ xhr.addEventListener("error", ev=>reject(ev) );
280
+
281
+ xhr.send();
282
+ })
283
+ return dom
284
+ }
285
+ export function
286
+ deepEqual(a, b, O=false)
287
+ {
288
+ if( a === b )
289
+ return true;
290
+
291
+ if( (typeof a !== "object" || a === null) || (typeof b !== "object" || b === null)
292
+ || Object.keys(a).length !== Object.keys(b).length )
293
+ return O;
294
+
295
+ for( let k in a )
296
+ if( !(k in b) || !deepEqual( a[k], b[k] ) )
297
+ return O
298
+ return true;
299
+ }
300
+ export const
301
+ assureSlices = ( root, names) =>
302
+ names.split('|').map(n=>n.trim()).map( xp =>
303
+ { if(xp.includes('/'))
304
+ { const ret = [], r = root.ownerDocument.evaluate( xp, root );
305
+ for( let n; n = r.iterateNext(); )
306
+ ret.push( n )
307
+ return ret
308
+ }
309
+ return [...root.childNodes].find(n=>n.localName === xp) || create(xp);
310
+ }).flat();
311
+
312
+ /**
313
+ *
314
+ * @param x slice node
315
+ * @param sliceNames slice name, xPath in /datadom/slice/
316
+ * @param ev Event obj
317
+ * @param dce
318
+ */
319
+ export function
320
+ event2slice( x, sliceNames, ev, dce )
321
+ {
322
+ // evaluate slices[]
323
+ // inject @attributes
324
+ // inject event
325
+ // evaluate slice-value
326
+ // slice[i] = slice-value
327
+ assureSlices(x,sliceNames).map( s =>
328
+ {
329
+ const d = x.ownerDocument
330
+ , el = ev.sliceEventSource
331
+ , sel = ev.sliceElement
332
+ , cleanSliceValue = ()=>[...s.childNodes].filter(n=>n.nodeType===3 || n.localName==='value').map(n=>n.remove());
333
+ el.getAttributeNames().map( a => s.setAttribute( a, attr(el,a) ) );
334
+ [...s.childNodes].filter(n=>n.localName==='event').map(n=>n.remove());
335
+ ev.type==='init' && cleanSliceValue();
336
+ s.append( obj2node( ev, 'event', d ) );
337
+ if( sel.hasAttribute('slice-value') )
338
+ { if( el.value === undefined)
339
+ s.removeAttribute('value')
340
+ else
341
+ s.setAttribute('value', el.value );
342
+ const v = xPath( attr( sel, 'slice-value'),s );
343
+ cleanSliceValue();
344
+ s.append( createText( d, v ) );
345
+ }else
346
+ { const v = el.value ?? attr( sel, 'value' ) ;
347
+ cleanSliceValue();
348
+ if( v === null || v === undefined )
349
+ [...s.childNodes].filter(n=>n.localName!=='event').map(n=>n.remove());
350
+ else
351
+ if( isString(v) )
352
+ s.append( createText( d, v) );
353
+ else
354
+ s.append( obj2node(v,'value',s.ownerDocument) )
355
+ }
356
+ })
357
+ }
358
+
359
+ function forEach$( el, css, cb){
360
+ if( el.querySelectorAll )
361
+ [...el.querySelectorAll(css)].forEach(cb)
362
+ }
363
+ const getByHashId = ( n, id )=> ( p => n===p? null: (p && ( p.querySelector(id) || getByHashId(p,id) ) ))( n.getRootNode() )
364
+ const loadTemplateRoots = async ( src, dce )=>
365
+ {
366
+ if( !src || !src.trim() )
367
+ return [dce]
368
+ if( src.startsWith('#') )
369
+ return ( n =>
370
+ { if(!n) return []
371
+ const a = n.querySelectorAll(src)
372
+ if( a.length )
373
+ return [...a]
374
+ const r = n.getRootNode();
375
+ return r===n ? []: getByHashId(r)
376
+ })(dce.parentElement)
377
+ try
378
+ { // todo cache
379
+ const dom = await xhrTemplate(src)
380
+ const hash = new URL(src, location).hash
381
+ if( hash )
382
+ { const ret = dom.querySelectorAll(hash);
383
+ if( ret.length )
384
+ return [...ret]
385
+ return [dce]
386
+ }
387
+ return [dom]
388
+ }catch (error){ return [dce]}
389
+ }
390
+ export function mergeAttr( from, to )
391
+ { if( isText(from) )
392
+ {
393
+ if( !isText(to) ){ debugger }
394
+ return
395
+ }
396
+ for( let a of from.attributes)
397
+ { a.namespaceURI? to.setAttributeNS( a.namespaceURI, a.name, a.value ) : to.setAttribute( a.name, a.value )
398
+ if( a.name === 'value')
399
+ to.value = a.value
400
+ }
401
+ }
402
+ export function assureUnique(n, id=0)
403
+ {
404
+ const m = {}
405
+ for( const e of n.childNodes )
406
+ {
407
+ const a = attr(e,'data-dce-id') || e.dceId || 0;
408
+ if( !m[a] )
409
+ { if( !a )
410
+ { m[a] = e.dceId = ++id;
411
+ if( e.setAttribute )
412
+ e.setAttribute('data-dce-id', e.dceId )
413
+ }else
414
+ m[a] = 1;
415
+ }else
416
+ { const v = e.dceId = a + '-' + m[a]++;
417
+ if( e.setAttribute )
418
+ e.setAttribute('data-dce-id', v )
419
+ }
420
+ e.childNodes.length && assureUnique(e)
421
+ }
422
+ }
423
+ export function merge( parent, fromArr )
424
+ {
425
+ if(!fromArr.length)
426
+ return removeChildren(parent);
427
+ const id2old = {};
428
+ for( let c of parent.childNodes)
429
+ { ASSERT( !id2old[c.dceId] );
430
+ if( isText(c) )
431
+ { ASSERT( c.data.trim() );
432
+ id2old[c.dceId || 0] = c;
433
+ } else
434
+ id2old[attr(c, 'data-dce-id') || 0] = c;
435
+ }
436
+ for( let e of [...fromArr] )
437
+ { const k = attr(e, 'data-dce-id') || e.dceId;
438
+ const o = id2old[ k ];
439
+ if( o )
440
+ { if( isText(e) )
441
+ { if( o.nodeValue !== e.nodeValue )
442
+ o.nodeValue = e.nodeValue;
443
+ }else
444
+ { mergeAttr(e,o)
445
+ if( o.childNodes.length || e.childNodes.length )
446
+ merge(o, e.childNodes)
447
+ }
448
+ delete id2old[ k ]
449
+ }else
450
+ parent.append( e )
451
+ }
452
+ for( let v of Object.values(id2old) )
453
+ v.remove();
454
+ }
455
+ export function assureUID(n,attr)
456
+ { if( !n.hasAttribute(attr) )
457
+ n.setAttribute(attr, crypto.randomUUID());
458
+ return n.getAttribute(attr)
459
+ }
460
+ export const evalCurly = s =>
461
+ { const exp = [...s?.matchAll( /([^{}]*)(\{)([^}]+)}([^{}]*)/g ) ].map(l=>`${l[1]}{${ xPathDefaults(l[3] )}}${l[4]}`);
462
+ return exp.join('');
463
+ }
464
+ export const xPathDefaults = x=>
465
+ { if(!x.trim())
466
+ return x;
467
+ const xx = x.split('??')
468
+ , a = xx.shift()
469
+ , b = xPathDefaults(xx.join('??'));
470
+
471
+ return xx.length ? `concat( ${a} , substring( ${b} , (1+string-length( ${b} )) * string-length( ${a} ) ) )`: x
472
+ // return xx.length ? `${a}|(${xPathDefaults(xx.join('??'))})[not(${a})]`: a
473
+ }
474
+ export const xPath = (x,root)=>
475
+ { x = xPathDefaults(x);
476
+
477
+ const it = root.ownerDocument.evaluate(x, root);
478
+ switch( it.resultType )
479
+ { case XPathResult.NUMBER_TYPE: return it.numberValue;
480
+ case XPathResult.STRING_TYPE: return it.stringValue;
481
+ }
482
+
483
+ let ret = '';
484
+ for( let n ;n=it.iterateNext(); )
485
+ ret += n.textContent;
486
+ return ret
487
+ }
488
+ export const xslTags = 'stylesheet,transform,import,include,strip-space,preserve-space,output,key,decimal-format,namespace-alias,template,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(',');
489
+ export const toXsl = (el, defParent) => {
490
+ const x = create('xsl:'+el.localName);
491
+ for( let a of el.attributes )
492
+ x.setAttribute( a.name, a.value );
493
+ while(el.firstChild)
494
+ x.append(el.firstChild);
495
+ if( el.parentElement )
496
+ el.parentElement.replaceChild( x, el );
497
+ else
498
+ { const p = (el.parentElement || defParent)
499
+ , arr = [...p.childNodes];
500
+ arr.forEach((n, i) => {
501
+ if (n === el)
502
+ arr[i] = x;
503
+ });
504
+ p.replaceChildren(...arr);
505
+ }
506
+ };
507
+
508
+ export class
509
+ CustomElement extends HTMLElement
510
+ {
511
+ static observedAttributes = ['src','tag','hidden'];
512
+ async connectedCallback()
513
+ {
514
+ const templateRoots = await loadTemplateRoots( attr( this, 'src' ), this )
515
+ , tag = attr( this, 'tag' )
516
+ , tagName = tag ? tag : 'dce-'+crypto.randomUUID();
517
+
518
+ for( const t of templateRoots )
519
+ forEach$(t.templateNode||t.content||t, 'style',s=>{
520
+ const slot = s.closest('slot');
521
+ const sName = slot ? `slot[name="${slot.name}"]`:'';
522
+ s.innerHTML = `${tagName} ${sName}{${s.innerHTML}}`;
523
+ this.append(s);
524
+ })
525
+ const templateDocs = templateRoots.map( n => createXsltFromDom( n ) )
526
+ , xp = templateDocs.map( (td, p) =>{ p = new XSLTProcessor(); p.importStylesheet( td ); return p })
527
+
528
+ Object.defineProperty( this, "xsltString", { get: ()=>templateDocs.map( td => xmlString(td) ).join('\n') });
529
+
530
+ const dce = this
531
+ , sliceNodes = [...this.templateNode.querySelectorAll('[slice]')]
532
+ , sliceNames = sliceNodes.map(e=>attr(e,'slice')).filter(n=>!n.includes('/')).filter((v, i, a)=>a.indexOf(v) === i)
533
+ , declaredAttributes = templateDocs.reduce( (ret,t) => { if( t.params ) ret.push( ...t.params ); return ret; }, [] );
534
+
535
+ class DceElement extends HTMLElement
536
+ {
537
+ static get observedAttributes(){ return declaredAttributes.map( a=>attr(a,'name')); }
538
+ #inTransform = 0;
539
+ connectedCallback()
540
+ { let payload = this.childNodes;
541
+ if( this.firstElementChild?.tagName === 'TEMPLATE' )
542
+ {
543
+ const t = this.firstElementChild;
544
+ t.remove();
545
+ payload = t.content.childNodes;
546
+
547
+ for( const n of [...t.content.childNodes] )
548
+ if( n.localName === 'style' ){
549
+ const id = assureUID(this,'data-dce-style')
550
+ n.innerHTML= `${tagName}[data-dce-style="${id}"]{${n.innerHTML}}`;
551
+ t.insertAdjacentElement('beforebegin',n);
552
+ }else
553
+ if(n.nodeType===1)
554
+ t.insertAdjacentElement('beforebegin',n);
555
+ else if(n.nodeType===3)
556
+ t.insertAdjacentText('beforebegin',n.data);
557
+ }
558
+ const x = xml2dom( '<datadom/>' ).documentElement;
559
+ const createXmlNode = ( tag, t = '' ) => ( e =>
560
+ { if( t )
561
+ e.append( createText( x, t ))
562
+ return e;
563
+ })(x.ownerDocument.createElement( tag ))
564
+ injectData( x, 'payload' , payload , assureSlot );
565
+ this.innerHTML='';
566
+ injectData( x, 'attributes' , this.attributes, e => createXmlNode( e.nodeName, e.value ) );
567
+ injectData( x, 'dataset', Object.keys( this.dataset ), k => createXmlNode( k, this.dataset[ k ] ) );
568
+ const sliceRoot = injectData( x, 'slice', sliceNames, k => createXmlNode( k, '' ) )
569
+ , sliceXPath = x => xPath(x, sliceRoot);
570
+ this.xml = x;
571
+
572
+ const sliceEvents=[];
573
+ const applySlices = ()=>
574
+ { const processed = {}
575
+
576
+ for(let ev; ev = sliceEvents.pop(); )
577
+ { const s = attr( ev.sliceElement, 'slice');
578
+ if( processed[s] )
579
+ continue;
580
+ event2slice( sliceRoot, s, ev, this );
581
+ processed[s] = ev;
582
+ }
583
+ Object.keys(processed).length !== 0 && transform();
584
+ }
585
+ let timeoutID;
586
+
587
+ this.onSlice = ev=>
588
+ { ev.stopPropagation?.();
589
+ ev.sliceEventSource = ev.currentTarget || ev.target;
590
+ sliceEvents.push(ev);
591
+ if( !timeoutID )
592
+ timeoutID = setTimeout(()=>
593
+ { applySlices();
594
+ timeoutID =0;
595
+ },10);
596
+ };
597
+ const transform = this.transform = ()=>
598
+ { if(this.#inTransform){ debugger }
599
+ this.#inTransform = 1;
600
+
601
+ const ff = xp.map( (p,i) =>
602
+ { const f = p.transformToFragment(x.ownerDocument, document)
603
+ if( !f )
604
+ console.error( "XSLT transformation error. xsl:\n", xmlString(templateDocs[i]), '\nxml:\n', xmlString(x) );
605
+ return f
606
+ });
607
+ ff.map( f =>
608
+ { if( !f )
609
+ return;
610
+ assureUnique(f);
611
+ merge( this, f.childNodes )
612
+ })
613
+
614
+ DceElement.observedAttributes.map( a =>
615
+ { let v = attr(this.firstElementChild,a);
616
+ if( v !== attr(this,a) )
617
+ { this.setAttribute( a, v );
618
+ this.#applyAttribute( a, v );
619
+ }
620
+ })
621
+
622
+ forEach$( this,'[slice]', el =>
623
+ { if( !el.dceInitialized )
624
+ { el.dceInitialized = 1;
625
+ const evs = attr(el,'slice-event');
626
+ (evs || 'change')
627
+ .split(' ')
628
+ .forEach( t=> (el.localName==='slice'? el.parentElement : el)
629
+ .addEventListener( t, ev=>
630
+ { ev.sliceElement = el;
631
+ this.onSlice(ev)
632
+ } ));
633
+ if( !evs || evs.includes('init') )
634
+ { if( el.hasAttribute('slice-value') || el.hasAttribute('value') || el.value )
635
+ this.onSlice({type:'init', target: el, sliceElement:el })
636
+ else
637
+ el.value = sliceXPath( attr(el,'slice') )
638
+ }
639
+ }
640
+ });
641
+ this.#inTransform = 0;
642
+ };
643
+ transform();
644
+ applySlices();
645
+ }
646
+ #applyAttribute(name, newValue)
647
+ { let a = this.xml.querySelector(`attributes>${name}`);
648
+ if( a )
649
+ emptyNode(a).append( createText(a,newValue) );
650
+ else
651
+ { a = create( name, newValue, this.xml );
652
+ this.xml.querySelector('attributes').append( a );
653
+ }
654
+ }
655
+ attributeChangedCallback(name, oldValue, newValue)
656
+ { if( !this.xml || this.#inTransform )
657
+ return;
658
+ this.#applyAttribute(name, newValue);
659
+ this.transform(); // needs throttling
660
+ }
661
+
662
+ get dce(){ return dce }
663
+ }
664
+ const registerTag = tag =>
665
+ {
666
+ if( window.customElements.get(tag) !== DceElement )
667
+ window.customElements.define( tag, DceElement);
668
+ };
669
+ if(tag)
670
+ registerTag(tag);
671
+ else
672
+ { const t = tagName;
673
+ this.setAttribute('tag', t );
674
+ registerTag(t);
675
+ const el = document.createElement(t);
676
+ this.getAttributeNames().forEach(a=>el.setAttribute(a,this.getAttribute(a)));
677
+ el.append(...[...this.childNodes].filter( e => e.localName!=='style') );
678
+ this.append(el);
679
+ }
680
+ }
681
+ get templateNode(){ return this.firstElementChild?.tagName === 'TEMPLATE'? this.firstElementChild.content : this }
682
+ get dce(){ return this }
683
+
684
+ get xslt(){ return xml2dom( this.xsltString ) }
685
+ }
686
+
687
+ window.customElements.define( 'custom-element', CustomElement );
688
+ export default CustomElement;