@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,152 +0,0 @@
1
- import{w as o,e}from"./index-CxRwF5Or.js";import"./custom-element-D59Fok1f.js";function p(i){return new Promise(t=>setTimeout(t,i))}function u(i){const{title:t,body:a}=i;return`
2
- <fieldset>
3
- <legend>${t}</legend>
4
- ${a}
5
- </fieldset>
6
- `}const m={title:"attributes",render:u},n={args:{title:"Attributes definition",body:`
7
- <p>Params needed to declare DCE attributes and track the attributes changes. It also is used by IDE and validation.</p>
8
- <custom-element tag="dce-link" >
9
- <template>
10
- <attribute name="p1">default_P1 </attribute>
11
- <attribute name="p2" select="'always_p2'" ></attribute>
12
- <attribute name="p3" select="//p3 ?? 'def_P3' "></attribute>
13
- p1: <code data-testid="p1">{$p1}</code> <br/>
14
- p2: <code data-testid="p2">{$p2}</code> <br/>
15
- p3: <code data-testid="p3">{$p3}</code>
16
- </template>
17
- </custom-element>
18
- <dce-link id="dce1"></dce-link>
19
- `},play:async({canvasElement:i})=>{n.args.title;const t=o(i);e(await await t.findByTestId("p1")).toHaveTextContent("default_P1"),e(await await t.findByTestId("p2")).toHaveTextContent("always_p2"),e(await await t.findByTestId("p3")).toHaveTextContent("def_P3")}},s={args:{title:"Attributes runtime change",body:`
20
- <p>Params needed to declare DCE attributes and track the attributes changes. It also be used by IDE and validation.</p>
21
- <custom-element tag="dce-link2" >
22
- <template>
23
- <attribute name="p1">default_P1 </attribute>
24
- <attribute name="p2" select="'always_p2'" ></attribute>
25
- <attribute name="p3" select="//p3 ?? 'def_P3' "></attribute>
26
- p1: <code data-testid="t1">{$p1}</code> <br/>
27
- p2: <code data-testid="t2">{$p2}</code> <br/>
28
- p3: <code data-testid="t3">{$p3}</code>
29
- </template>
30
- </custom-element>
31
- <section>
32
- <dce-link2 id="dce2" p1="123" p2="override ignored as select is defined"></dce-link2> <br>
33
- <div><input id="i1" value="P1"> <button onclick="dce2.setAttribute('p1',i1.value)"> set p1</button> </div>
34
- <div><input id="i2" value="P2"> <button onclick="dce2.setAttribute('p2',i2.value)"> set p2</button> </div>
35
- <div><input id="i3" value="P3"> <button onclick="dce2.setAttribute('p3',i3.value)"> set p3</button> </div>
36
- </section>
37
- `},play:async({canvasElement:i})=>{const t=o(i),a=async r=>await t.findByTestId(r);await p(20),e(await a("t1")).toHaveTextContent("123"),e(await a("t2")).toHaveTextContent("always_p2"),e(await a("t3")).toHaveTextContent("def_P3");const d=window.dce2;d.setAttribute("P1",i1.value),await e(await t.findByText("P1")).toBeInTheDocument(),e(await a("t1")).toHaveTextContent("P1"),d.setAttribute("p2",i2.value),e(t.getByTestId("t2")).toHaveTextContent("always_p2"),d.setAttribute("p3",i3.value),await e(await t.findByText("P3")).toBeInTheDocument(),e(t.getByTestId("t3")).toHaveTextContent("P3")}},c={args:{title:"Instance Attributes",body:`
38
- <p>Params needed to declare DCE attributes and track the attributes changes. It also is used by IDE and validation.</p>
39
- <custom-element tag="dce-link3" >
40
- <template>
41
- <attribute name="p1">default_P1 </attribute>
42
- <attribute name="p2" select="'always_p2'" ></attribute>
43
- <attribute name="p3" select="//p3 ?? 'def_P3' "></attribute>
44
- p1: <code data-testid="p1">{$p1}</code> <br/>
45
- p2: <code data-testid="p2">{$p2}</code> <br/>
46
- p3: <code data-testid="p3">{$p3}</code>
47
- </template>
48
- </custom-element>
49
- <dce-link3 id="dce3" p1="123" p3="qwe"></dce-link3> |
50
- `},play:async({canvasElement:i})=>{n.args.title;const t=o(i),a=async d=>(await t.findByTestId(d)).textContent.trim();await p(20),e(await a("p1")).toEqual("123"),e(await a("p2")).toEqual("always_p2"),e(await a("p3")).toEqual("qwe")}};n.parameters={...n.parameters,docs:{...n.parameters?.docs,source:{originalSource:`{
51
- args: {
52
- title: 'Attributes definition',
53
- body: \`
54
- <p>Params needed to declare DCE attributes and track the attributes changes. It also is used by IDE and validation.</p>
55
- <custom-element tag="dce-link" >
56
- <template>
57
- <attribute name="p1">default_P1 </attribute>
58
- <attribute name="p2" select="'always_p2'" ></attribute>
59
- <attribute name="p3" select="//p3 ?? 'def_P3' "></attribute>
60
- p1: <code data-testid="p1">{$p1}</code> <br/>
61
- p2: <code data-testid="p2">{$p2}</code> <br/>
62
- p3: <code data-testid="p3">{$p3}</code>
63
- </template>
64
- </custom-element>
65
- <dce-link id="dce1"></dce-link>
66
- \`
67
- },
68
- play: async ({
69
- canvasElement
70
- }) => {
71
- const titleText = AttributeDefaults.args!.title as string;
72
- const canvas = within(canvasElement),
73
- code = async id => (await canvas.findByTestId(id)).textContent.trim();
74
- expect(await await canvas.findByTestId('p1')).toHaveTextContent('default_P1');
75
- expect(await await canvas.findByTestId('p2')).toHaveTextContent('always_p2');
76
- expect(await await canvas.findByTestId('p3')).toHaveTextContent('def_P3');
77
- }
78
- }`,...n.parameters?.docs?.source}}};s.parameters={...s.parameters,docs:{...s.parameters?.docs,source:{originalSource:`{
79
- args: {
80
- title: 'Attributes runtime change',
81
- body: \`
82
- <p>Params needed to declare DCE attributes and track the attributes changes. It also be used by IDE and validation.</p>
83
- <custom-element tag="dce-link2" >
84
- <template>
85
- <attribute name="p1">default_P1 </attribute>
86
- <attribute name="p2" select="'always_p2'" ></attribute>
87
- <attribute name="p3" select="//p3 ?? 'def_P3' "></attribute>
88
- p1: <code data-testid="t1">{$p1}</code> <br/>
89
- p2: <code data-testid="t2">{$p2}</code> <br/>
90
- p3: <code data-testid="t3">{$p3}</code>
91
- </template>
92
- </custom-element>
93
- <section>
94
- <dce-link2 id="dce2" p1="123" p2="override ignored as select is defined"></dce-link2> <br>
95
- <div><input id="i1" value="P1"> <button onclick="dce2.setAttribute('p1',i1.value)"> set p1</button> </div>
96
- <div><input id="i2" value="P2"> <button onclick="dce2.setAttribute('p2',i2.value)"> set p2</button> </div>
97
- <div><input id="i3" value="P3"> <button onclick="dce2.setAttribute('p3',i3.value)"> set p3</button> </div>
98
- </section>
99
- \`
100
- },
101
- play: async ({
102
- canvasElement
103
- }) => {
104
- const canvas = within(canvasElement),
105
- code = async (id: string) => await canvas.findByTestId(id);
106
- await sleep(20);
107
- expect(await code('t1')).toHaveTextContent('123');
108
- expect(await code('t2')).toHaveTextContent('always_p2'); // no overrides due to value is hardcoded
109
- expect(await code('t3')).toHaveTextContent('def_P3');
110
- const dce2 = window.dce2;
111
- dce2.setAttribute('P1', i1.value);
112
- await expect(await canvas.findByText('P1')).toBeInTheDocument();
113
- expect(await code('t1')).toHaveTextContent('P1'); // 4. set p1 in runtime'
114
-
115
- dce2.setAttribute('p2', i2.value);
116
- // await expect(await canvas.findByText('P2')).toBeInTheDocument();
117
- expect(canvas.getByTestId('t2')).toHaveTextContent('always_p2'); // can not set p2 in runtime
118
-
119
- dce2.setAttribute('p3', i3.value);
120
- await expect(await canvas.findByText('P3')).toBeInTheDocument();
121
- expect(canvas.getByTestId('t3')).toHaveTextContent('P3'); // set p3 in runtime
122
- }
123
- }`,...s.parameters?.docs?.source}}};c.parameters={...c.parameters,docs:{...c.parameters?.docs,source:{originalSource:`{
124
- args: {
125
- title: 'Instance Attributes',
126
- body: \`
127
- <p>Params needed to declare DCE attributes and track the attributes changes. It also is used by IDE and validation.</p>
128
- <custom-element tag="dce-link3" >
129
- <template>
130
- <attribute name="p1">default_P1 </attribute>
131
- <attribute name="p2" select="'always_p2'" ></attribute>
132
- <attribute name="p3" select="//p3 ?? 'def_P3' "></attribute>
133
- p1: <code data-testid="p1">{$p1}</code> <br/>
134
- p2: <code data-testid="p2">{$p2}</code> <br/>
135
- p3: <code data-testid="p3">{$p3}</code>
136
- </template>
137
- </custom-element>
138
- <dce-link3 id="dce3" p1="123" p3="qwe"></dce-link3> |
139
- \`
140
- },
141
- play: async ({
142
- canvasElement
143
- }) => {
144
- const titleText = AttributeDefaults.args!.title as string;
145
- const canvas = within(canvasElement),
146
- code = async id => (await canvas.findByTestId(id)).textContent.trim();
147
- await sleep(20);
148
- expect(await code('p1')).toEqual('123');
149
- expect(await code('p2')).toEqual('always_p2');
150
- expect(await code('p3')).toEqual('qwe');
151
- }
152
- }`,...c.parameters?.docs?.source}}};const v=["AttributeDefaults","AttributesRuntimeChange","InstanceAttributes"];export{n as AttributeDefaults,s as AttributesRuntimeChange,c as InstanceAttributes,v as __namedExportsOrder,m as default};
@@ -1,97 +0,0 @@
1
- const W="http://www.w3.org/1999/XSL/Transform",V="http://www.w3.org/1999/xhtml",de="http://exslt.org/common",f=(e,l)=>e.getAttribute?.(l),Z=e=>e.nodeType===3,ue=e=>typeof e=="string",pe=e=>e&&typeof e.nodeType=="number",D=(e,l)=>(e.ownerDocument||e).createTextNode(l),se=e=>{for(;e.firstChild;)e.firstChild.remove();return e},k=e=>(e.getAttributeNames().map(l=>e.removeAttribute(l)),se(e)),le=e=>(e?.setAttribute("xmlns:xsl",W),e),ne=e=>(e?.setAttribute("xmlns:xhtml",V),le(e)),ae=e=>/^[_a-zA-Z][-_:a-zA-Z0-9]*$/.test(e),T=(e,l="",t=document)=>{const s=i=>(r=>(l&&r.append(D(t.ownerDocument||t,l)),r))((t.ownerDocument||t).createElement(i));if(ae(e))return s(e);const n=s("dce-object");return n.setAttribute("dce-object-name",e),n},J=(e,l)=>{const t=e.ownerDocument.createElementNS(e.namespaceURI,l);for(let s of e.attributes)t.setAttribute(s.name,s.value);for(;e.firstChild;)t.append(e.firstChild);return t};function q(e){return new DOMParser().parseFromString(e,"application/xml")}function j(e){return new XMLSerializer().serializeToString(e)}function H(e,l,t,s){const n=x=>e.ownerDocument.createElement(x),r=((x,p,N)=>(p.append(N=n(x)),N))(l,e);return[...t].forEach(x=>r.append(s(x))),r}function fe(e){return e.slot||(e.setAttribute||(e=T("span",e.textContent.replaceAll(`
2
- `,""))),e.setAttribute("slot","")),e}function K(e,l){e.getAttributeNames().forEach(t=>l.includes(t)||e.removeAttribute(t))}const Q=e=>[...e].filter(l=>!(l.nodeType===3&&l.data.trim()===""));function z(e,l,t){const s=typeof e;if(s==="string")return T(l,e,t);if(s==="number")return T(l,""+e,t);if(e instanceof Array){const i=T("array","",t);return e.map(r=>i.append(z(r,l,t))),i}if(e instanceof FormData){const i=T("form-data","",t);for(const r of e)i.append(z(r[1],r[0],t));return i}const n=T(l,"",t);for(let i in e)pe(e[i])||typeof e[i]=="function"||e[i]instanceof Window||(typeof e[i]!="object"&&ae(i)?n.setAttribute(i,e[i]):n.append(z(e[i],i,t)));return n}function ee(e){if($(e,"*",l=>[...l.childNodes].filter(t=>t.nodeType===3&&t.parentNode.localName!=="style"&&t.data).forEach(t=>{const s=t.data,n=s.matchAll(/{([^}]*)}/g);if(n){let i=0,r=p=>D(t,p),x=[];if([...n].forEach(p=>{p.index>i&&x.push(r(p.input.substring(i,p.index)));const N=e.querySelector("value-of").cloneNode();N.setAttribute("select",p[1]),x.push(N),i=p.index+p[0].length}),i<s.length&&x.push(r(s.substring(i,s.length))),x.length){for(let p of x)l.insertBefore(p,t);l.removeChild(t)}}})),"all"in e){let l=1;for(let t of e.all)t.setAttribute&&!t.tagName.startsWith("xsl:")&&t.setAttribute("data-dce-id",""+l++)}return e}function he(e,l="xsl:stylesheet"){if(e.tagName===l||e.documentElement?.tagName===l)return ee(e);const t=q(`<xsl:stylesheet version="1.0" xmlns:xsl="${W}" xmlns:xhtml="${V}" xmlns:exsl="${de}" exclude-result-prefixes="exsl" >
3
- <xsl:output method="xml"/>
4
- <xsl:template match="/"><dce-root xmlns="${V}"><xsl:apply-templates select="*" /></dce-root></xsl:template>
5
- <xsl:template match="*[name()='template']">
6
- <xsl:apply-templates mode="sanitize" select="*|text()"/>
7
- </xsl:template>
8
- <xsl:template match="*">
9
- <xsl:apply-templates mode="sanitize" select="*|text()"/>
10
- </xsl:template>
11
- <xsl:template match="*[name()='svg']|*[name()='math']">
12
- <xsl:apply-templates mode="sanitize" select="."/>
13
- </xsl:template>
14
- <xsl:template mode="sanitize" match="*[count(text())=1 and count(*)=0]">
15
- <xsl:copy>
16
- <xsl:apply-templates mode="sanitize" select="@*"/>
17
- <xsl:value-of select="text()"></xsl:value-of>
18
- </xsl:copy>
19
- </xsl:template>
20
- <xsl:template mode="sanitize" match="xhtml:*[count(text())=1 and count(*)=0]">
21
- <xsl:element name="{local-name()}">
22
- <xsl:apply-templates mode="sanitize" select="@*"/>
23
- <xsl:value-of select="text()"></xsl:value-of>
24
- </xsl:element>
25
- </xsl:template>
26
- <xsl:template mode="sanitize" match="*|@*">
27
- <xsl:copy>
28
- <xsl:apply-templates mode="sanitize" select="*|@*|text()"/>
29
- </xsl:copy>
30
- </xsl:template>
31
- <xsl:template mode="sanitize" match="text()[normalize-space(.) = '']"/>
32
- <xsl:template mode="sanitize" match="text()">
33
- <dce-text>
34
- <xsl:copy/>
35
- </dce-text>
36
- </xsl:template>
37
- <xsl:template mode="sanitize" match="xsl:value-of|*[name()='slot']">
38
- <xsl:copy>
39
- <xsl:apply-templates mode="sanitize" select="*|@*|text()"/>
40
- </xsl:copy>
41
- </xsl:template>
42
- <xsl:template mode="sanitize" match="xhtml:*">
43
- <xsl:element name="{local-name()}">
44
- <xsl:apply-templates mode="sanitize" select="*|@*|text()"/>
45
- </xsl:element>
46
- </xsl:template>
47
- <xsl:template mode="sanitize" match="xhtml:input">
48
- <xsl:element name="{local-name()}">
49
- <xsl:apply-templates mode="sanitize" select="*|@*|text()"/>
50
- </xsl:element>
51
- <xsl:for-each select="*">
52
- <xsl:copy>
53
- <xsl:attribute name="for" >^</xsl:attribute>
54
- <xsl:apply-templates mode="sanitize" select="*|@*|text()"/>
55
- </xsl:copy>
56
- </xsl:for-each>
57
- </xsl:template>
58
- </xsl:stylesheet>`),s=new XSLTProcessor,n=(a=>{$(a,"custom-element",b=>{b.firstElementChild.localName==="template"&&([...b.firstElementChild.content.childNodes].forEach(y=>b.append(y)),b.firstElementChild.remove())}),$(a,"script",b=>b.remove());const c=a.content??a.firstElementChild?.content??a.body??a;Ae.forEach(b=>$(c,b,y=>we(y,c)));const A=a.firstElementChild?.content||a.content,E=b=>{const y=q("<xhtml/>"),P=y.importNode(b,!0);return y.replaceChild(P,y.documentElement),ne(P)};if(A){const b=T("div");return[...A.childNodes].map(y=>b.append(y.cloneNode(!0))),E(b)}return E(a.documentElement||a.body||a)})(e),i=q(`<xsl:stylesheet version="1.0"
59
- xmlns:xsl="${W}"
60
- xmlns:xhtml="${V}"
61
- xmlns:dce="urn:schemas-epa-wg:dce"
62
- xmlns:exsl="http://exslt.org/common"
63
- exclude-result-prefixes="exsl"
64
- >
65
- <xsl:template match="ignore">
66
- <xsl:choose>
67
- <xsl:when test="//attr">{//attr}</xsl:when>
68
- <xsl:otherwise>{def}</xsl:otherwise>
69
- </xsl:choose><xsl:value-of select="."></xsl:value-of></xsl:template>
70
- <xsl:template mode="payload" match="attributes"></xsl:template>
71
- <xsl:template match="/">
72
- <xsl:apply-templates mode="payload" select="/datadom/attributes"/>
73
- </xsl:template>
74
- <xsl:template name="slot" >
75
- <xsl:param name="slotname" />
76
- <xsl:param name="defaultvalue" />
77
- <xsl:choose>
78
- <xsl:when test="//payload/*[@slot=$slotname]">
79
- <xsl:copy-of select="//payload/*[@slot=$slotname]"/>
80
- </xsl:when>
81
- <xsl:otherwise>
82
- <xsl:copy-of select="$defaultvalue"/>
83
- </xsl:otherwise>
84
- </xsl:choose>
85
- </xsl:template>
86
- <xsl:variable name="js-injected-body">
87
- <xsl:call-template name="slot" >
88
- <xsl:with-param name="slotname" select="''"/>
89
- <xsl:with-param name="defaultvalue"/>
90
- </xsl:call-template>
91
- </xsl:variable>
92
- </xsl:stylesheet>`);s.importStylesheet(t);const r=s.transformToFragment(n,document),x=(a,c)=>a.querySelector(c),p=x(i,'template[mode="payload"]');if(!r)return console.error("transformation error",{xml:n.outerHTML,xsl:j(t)});if(r.firstElementChild.localName!=="dce-root"){const a=r.ownerDocument.createElement("dce-root");[...r.childNodes].forEach(c=>a.append(c)),r.append(a)}const N=[];[...r.querySelectorAll("dce-root>attribute")].forEach(a=>{K(a,"namespace,name,select");const c=J(a,"xsl:param"),A=f(a,"name");p.append(c),K(c,"select,name");let E=f(c,"select")?.split("??");E||(E=["//"+A,`'${c.textContent}'`],k(c),c.setAttribute("name",A));let b;if(E?.length>1){c.removeAttribute("select");const y=x(i,'template[match="ignore"]>choose').cloneNode(!0);k(y.firstElementChild).append(D(y,"{"+E[0]+"}")),k(y.lastElementChild).append(D(y,"{"+E[1]+"}")),y.firstElementChild.setAttribute("test",E[0]),c.append(y),b=y.cloneNode(!0)}else b=J(a,"xsl:value-of");b.removeAttribute("name"),a.append(b),a.removeAttribute("select"),N.push(c)}),[...r.querySelectorAll("[value]")].filter(a=>a.getAttribute("value").match(/\{(.*)\?\?(.*)\}/g)).forEach(a=>{const c=f(a,"value");c&&a.setAttribute("value",Ne(c))});for(const a of r.childNodes)p.append(i.importNode(a,!0));[...p.getElementsByTagName("xsl:template")].forEach(a=>p.ownerDocument.documentElement.append(a));const C=x(i,'call-template[name="slot"]'),d=a=>{const c=C.cloneNode(!0),A=f(a,"name");A&&c.firstElementChild.setAttribute("select",`'${A}'`);for(let E of a.childNodes)c.lastElementChild.append(E);return c};$(p,"slot",a=>a.parentNode.replaceChild(d(a),a));const m=ee(i);return m.params=N,m}async function xe(e){return await new Promise((t,s)=>{const n=new XMLHttpRequest;n.open("GET",e),n.responseType="document",n.onload=()=>{n.readyState===n.DONE&&n.status===200?t(n.responseXML?.body||n.responseXML||T("div",n.responseText)):s(`${n.statusText} - ${e}`)},n.addEventListener("error",i=>s(i)),n.send()})}const ie=e=>e.split("|").map(l=>l.trim()).filter(l=>l),be=(e,l)=>ie(l).map(t=>{let s=e.ownerDocument,n=i=>(e.append(i),i);if(t.includes("/")){const i=[],r=s.evaluate(t,e);for(let x;x=r.iterateNext();)i.push(x);return i}return[...e.childNodes].find(i=>i.localName===t)||n(T(t,"",s))}).flat();function te(e,l,t,s){if(!t.sliceProcessed)return t.sliceProcessed=1,be(e,l??"").map(n=>{const i=e.ownerDocument,r=t.sliceEventSource,x=t.sliceElement,p=()=>[...n.childNodes].filter(u=>u.nodeType===3||u.localName==="value"||u.localName==="form-data").map(u=>u.remove());r.getAttributeNames().map(u=>n.setAttribute(u,f(r,u))),[...n.childNodes].filter(u=>u.localName==="event").map(u=>u.remove()),"validationMessage"in r&&n.setAttribute("validation-message",r.validationMessage),t.type==="init"&&p(),n.append(z(t,"event",i));const N=(r.type==="checkbox"||r.type==="radio")&&!r.checked;if(x.hasAttribute("slice-value")){r.value===void 0?n.removeAttribute("value"):n.setAttribute("value",r.value);const u=N?"":M(f(x,"slice-value"),n);p(),n.append(D(i,u))}else{if("elements"in r)return p(),n.append(z(new FormData(r),"value",n.ownerDocument)),n;const u=N?"":r.value??f(r,"value");p(),u==null?[...n.childNodes].filter(C=>C.localName!=="event").map(C=>C.remove()):ue(u)?n.append(D(i,u)):n.append(z(u,"value",n.ownerDocument))}return n})}function $(e,l,t){e.querySelectorAll&&[...e.querySelectorAll(l)].forEach(t)}const ye=async(e,l)=>{if(!e||!e.trim())return[l];if(e.startsWith("#"))return(t=>{const s=t.querySelectorAll(e);return[...s.length?s:t.getRootNode().querySelectorAll(e)]})(l.parentElement);try{const[t,s]=e.split("#");if(e.charAt(0)===".")e=new URL(t,l.closest("[base]")?.getAttribute("base")||location).href;else try{e=import.meta.resolve(t),s&&(e+="#"+s)}catch(i){console.error(i.message)}const n=await xe(e);if(l.setAttributeNS("xml","base",e),s){const i=n.querySelectorAll("#"+s);return i.length?[...i]:(console.error("template not found",e+"#"+s),[l])}return[n]}catch{return[l]}};function ve(e,l){for(let t of e.attributes)t.namespaceURI?l.setAttributeNS(t.namespaceURI,t.name,t.value):l.setAttribute(t.name,t.value),t.name==="value"&&(l.value=t.value)}function oe(e,l=0){const t={};for(const s of e.childNodes){const n=f(s,"data-dce-id")||s.dceId||0;if(!t[n])n?t[n]=1:(t[n]=s.dceId=++l,s.setAttribute&&s.setAttribute("data-dce-id",s.dceId));else{const i=s.dceId=n+"-"+t[n]++;s.setAttribute&&s.setAttribute("data-dce-id",i)}s.childNodes.length&&oe(s)}}function ge(e,l,t){t=1*t;for(let s of e.childNodes)if((s.dceId??s.getAttribute("data-dce-id")*1)>t)return e.insertBefore(l,s);e.append(l)}function re(e,l){if(e.firstElementChild?.localName==="dce-root"&&l[0].localName!=="dce-root")return;if(!l.length)return e.firstElementChild?.localName!=="dce-root"&&se(e);const t={};for(let s of e.childNodes)t[s.dceId],Z(s)?(s.data.trim(),t[s.dceId||0]=s):t[f(s,"data-dce-id")||0]=s;for(let s of[...l]){const n=f(s,"data-dce-id")||s.dceId,i=t[n];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[n]):ge(e,s,n)}for(let s of Object.values(t))s.localName!=="dce-root"&&s.remove()}function Ee(e,l){return e.hasAttribute(l)||e.setAttribute(l,crypto.randomUUID()),e.getAttribute(l)}const Ne=e=>[...e?.matchAll(/([^{}]*)(\{)([^}]+)}([^{}]*)/g)].map(t=>`${t[1]}{${Y(t[3])}}${t[4]}`).join(""),Y=e=>{if(!e.trim())return e;const l=e.split("??"),t=l.shift(),s=Y(l.join("??"));return l.length?`concat( ${t} , substring( ${s} , (1+string-length( ${s} )) * string-length( ${t} ) ) )`:e},M=(e,l)=>{const t=e.split("??");if(t.length>1)return M(t[0],l)||M(t[1],l);e=Y(e);const s=l.ownerDocument.evaluate(e,l);switch(s.resultType){case XPathResult.NUMBER_TYPE:return s.numberValue;case XPathResult.STRING_TYPE:return s.stringValue;case XPathResult.BOOLEAN_TYPE:return s.booleanValue}let n="";for(let i;i=s.iterateNext();)n+=i.textContent;return n},Ae="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(","),we=(e,l)=>{const t=T("xsl:"+e.localName);for(let s of e.attributes)t.setAttribute(s.name,s.value);for(;e.firstChild;)t.append(e.firstChild);if(e.parentElement)e.parentElement.replaceChild(t,e);else{const s=e.parentElement||l,n=[...s.childNodes];n.forEach((i,r)=>{i===e&&(n[r]=t)}),s.replaceChildren(...n)}};class Te extends HTMLElement{static observedAttributes=["src","tag","hidden"];async connectedCallback(){this.firstElementChild&&this.firstElementChild.localName!=="template"&&console.warn(`custom-element used without template wrapping content
93
- `,this.outerHTML);const l=await ye(f(this,"src"),this),t=f(this,"tag"),s=t||"dce-"+crypto.randomUUID();for(const d of l)$(d.templateNode||d.content||d,"style",m=>{const a=m.closest("slot"),c=a?`slot[name="${a.name}"]`:"";m.innerHTML=`${s} ${c}{${m.innerHTML}}`,this.append(m)});const n=l.map(d=>he(d)),i=n.map((d,m)=>{m=new XSLTProcessor;try{m.importStylesheet(d)}catch(a){console.error(a,j(d))}return m});Object.defineProperty(this,"xsltString",{get:()=>n.map(d=>j(d)).join(`
94
- `)});const r=this,x=[...this.templateNode.querySelectorAll("[slice]")],p=x.map(d=>f(d,"slice")).filter(d=>!d.includes("/")).filter((d,m,a)=>a.indexOf(d)===m).map(ie).flat(),N=n.reduce((d,m)=>(m.params&&d.push(...m.params),d),[]);class u extends HTMLElement{static get observedAttributes(){return N.map(m=>f(m,"name"))}#e=0;connectedCallback(){let m=Q(this.childNodes);if(this.firstElementChild?.tagName==="TEMPLATE"){this.firstElementChild!==this.lastElementChild&&console.error("payload should have TEMPLATE as only child",this.outerHTML);const h=this.firstElementChild;h.remove(),m=Q(h.content.childNodes);for(const v of m)if(v.localName==="style"){const o=Ee(this,"data-dce-style");v.innerHTML=`${s}[data-dce-style="${o}"]{${v.innerHTML}}`,h.insertAdjacentElement("beforebegin",v)}else v.nodeType===1?h.insertAdjacentElement("beforebegin",v):v.nodeType===3&&h.insertAdjacentText("beforebegin",v.data)}const a=q("<datadom/>").documentElement,c=(h,v="")=>(o=>(v&&o.append(D(a,v)),o))(a.ownerDocument.createElement(h)),A=H(a,"payload",m,fe);le(A),ne(A),this.innerHTML="";const E=H(a,"attributes",this.attributes,h=>c(h.nodeName,h.value));H(a,"dataset",Object.keys(this.dataset),h=>c(h,this.dataset[h]));const b=H(a,"slice",p,h=>c(h,"")),y=h=>M(h,b);this.xml=a;const P=[],G=()=>{const h={};for(let v;v=P.pop();){const o=f(v.sliceElement,"slice");h[o]||(te(b,o,v),h[o]=v)}Object.keys(h).length!==0&&U()};let _;this.onSlice=h=>{P.push(h),_||(_=setTimeout(()=>{G(),_=0},1))};const U=this.transform=()=>{if(this.#e)debugger;this.#e=1,i.map((o,g)=>{const S=o.transformToFragment(a.ownerDocument,document);return S||console.error(`XSLT transformation error. xsl:
95
- `,j(n[g]),`
96
- xml:
97
- `,j(a)),S}).map(o=>{o&&(oe(o),re(this,o.childNodes))}),u.observedAttributes.map(o=>{let g=f(this.firstElementChild,o);g!==f(this,o)&&(this.setAttribute(o,g),this.#t(o,g))});function v(o){let g=o;if(o.localName==="slice"){const S=f(o,"for");if(S||(g=o.parentElement),S==="^")do g=g.previousElementSibling;while(g.localName==="slice");else g=this.querySelector(S);if(!g)return console.warn(`can not find selector in "slice for=${S}" `,o.outerHTML);f(o,"slice")||o.setAttribute("slice",f(o,"name"))}return g}$(this,"[slice],[slice-event]",o=>{let g=f(o,"slice-event");const S=o.hasAttribute("slice-value")||o.hasAttribute("value")||o.value,R=v(o);o.dceInitialized||(o.dceInitialized=1,R.hasAttribute("custom-validity")&&(g+=" change submit"),[...new Set((g||"change").split(" "))].forEach(ce=>R.addEventListener(ce,w=>{w.sliceElement=o,w.sliceEventSource=w.currentTarget||w.target,w.sliceProcessed=0;const me=te(b,f(w.sliceElement,"slice"),w);$(this,"[custom-validity]",I=>{if(!I.setCustomValidity)return;const F=f(I,"custom-validity");try{const X=F&&M(F,E);I.setCustomValidity(X===!0?"":X===!1?"invalid":X)}catch(X){console.error(X,"xPath",F)}});const O=f(R,"custom-validity"),L=O&&M(O,E),B=L===!0?"":L;if(O){if(o.setCustomValidity?o.setCustomValidity(B):o.validationMessage=B,me.map(I=>I.setAttribute("validation-message",B)),w.type==="submit")return L===!0?void 0:(setTimeout(U,1),!!L===L?(L||w.preventDefault(),L):L?(w.preventDefault(),!1):void 0);setTimeout(U,1)}this.onSlice(w)})),(!g||g.includes("init"))&&(S?this.onSlice({type:"init",target:R,sliceElement:o,sliceEventSource:R}):o.value=y(f(o,"slice"))))}),this.#e=0};U(),G()}#t(m,a){m==="value"&&(this.value=a);let c=this.xml.querySelector(`attributes>${m}`);c?k(c).append(D(c,a)):(c=T(m,a,this.xml),this.xml.querySelector("attributes").append(c)),this.dispatchEvent(new CustomEvent("change",{bubbles:!0,detail:{[m]:a}}))}attributeChangedCallback(m,a,c){!this.xml||this.#e||(this.#t(m,c),this.transform())}get dce(){return r}}const C=d=>{window.customElements.get(d)!==u&&window.customElements.define(d,u)};if(t)C(t);else{const d=s;this.setAttribute("tag",d),C(d);const m=document.createElement(d);this.getAttributeNames().forEach(a=>m.setAttribute(a,this.getAttribute(a))),m.append(...[...this.childNodes].filter(a=>a.localName!=="style")),this.append(m)}}get templateNode(){return this.firstElementChild?.tagName==="TEMPLATE"?this.firstElementChild.content:this}get dce(){return this}get xslt(){return q(this.xsltString)}}window.customElements.define("custom-element",Te);