@epa-wg/custom-element 0.0.10 → 0.0.11

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/custom-element.js CHANGED
@@ -1,46 +1,27 @@
1
1
  const XML_DECLARATION = '<?xml version="1.0" encoding="UTF-8"?>'
2
- , XSL_NS_URL = 'http://www.w3.org/1999/XSL/Transform';
2
+ , XSL_NS_URL = 'http://www.w3.org/1999/XSL/Transform'
3
+ , DCE_NS_URL ="urn:schemas-epa-wg:dce";
3
4
 
4
5
  // const log = x => console.debug( new XMLSerializer().serializeToString( x ) );
5
6
 
6
7
  const attr = (el, attr)=> el.getAttribute(attr)
7
- , create = ( tag, t = '' ) => ( e => ((e.innerText = t||''),e) )(document.createElement( tag ));
8
+ , create = ( tag, t = '' ) => ( e => ((e.innerText = t||''),e) )(document.createElement( tag ))
9
+ , createNS = ( ns, tag, t = '' ) => ( e => ((e.innerText = t||''),e) )(document.createElementNS( ns, tag ));
8
10
 
9
11
  function
10
12
  xml2dom( xmlString )
11
13
  {
12
14
  return new DOMParser().parseFromString( XML_DECLARATION + xmlString, "application/xml" )
13
15
  }
14
-
15
16
  function
16
- bodyXml( dce )
17
- {
18
- const t = dce.firstElementChild
19
- , sanitize = s => s.replaceAll("<html:","<")
20
- .replaceAll("</html:","</")
21
- .replaceAll( />\s*<\/xsl:value-of>/g ,"/>")
22
- .replaceAll( />\s*<\/(br|hr|img|area|base|col|embed|input|link|meta|param|source|track|wbr)>/g ,"/>");
23
- if( t?.tagName === 'TEMPLATE')
24
- return sanitize( new XMLSerializer().serializeToString( t.content ) );
25
-
26
- const s = new XMLSerializer().serializeToString( dce );
27
- return sanitize( s.substring( s.indexOf( '>' ) + 1, s.lastIndexOf( '<' ) ) );
28
- }
29
-
30
- function
31
- slot2xsl( s )
32
- {
33
- const v = document.createElementNS( XSL_NS_URL, 'value-of' );
34
- v.setAttribute( 'select', `//*[@slot="${ s.name }"]` );
35
- s.parentNode.replaceChild( v, s );
36
- }
17
+ xmlString(doc){ return new XMLSerializer().serializeToString( doc ) }
37
18
 
38
19
  function
39
20
  injectData( root, sectionName, arr, cb )
40
21
  {
41
22
  const inject = ( tag, parent, s ) =>
42
23
  {
43
- parent.append( s = create( tag ) );
24
+ parent.append( s = createNS( DCE_NS_URL, tag ) );
44
25
  return s;
45
26
  };
46
27
  const l = inject( sectionName, root );
@@ -91,7 +72,106 @@ Json2Xml( o, tag )
91
72
  return ret.join('\n');
92
73
  }
93
74
 
94
- function
75
+ export function
76
+ createXsltFromDom( templateNode, S = 'xsl:stylesheet' )
77
+ {
78
+ if( templateNode.tagName === S || templateNode.documentElement?.tagName === S )
79
+ return templateNode
80
+ const dom = xml2dom(
81
+ `<xsl:stylesheet version="1.0"
82
+ xmlns:xsl="${ XSL_NS_URL }"
83
+ >
84
+ <xsl:output method="html" />
85
+
86
+ <xsl:template match="/">
87
+ <xsl:for-each select="//attributes">
88
+ <xsl:call-template name="attributes"/>\t
89
+ </xsl:for-each>
90
+ </xsl:template>
91
+ <xsl:template name="slot" >
92
+ <xsl:param name="slotname" />
93
+ <xsl:param name="defaultvalue" />
94
+ <xsl:choose>
95
+ <xsl:when test="//payload/*[@slot=$slotname]">
96
+ <xsl:copy-of select="//payload/*[@slot=$slotname]"/>
97
+ </xsl:when>
98
+ <xsl:otherwise>
99
+ <xsl:copy-of select="$defaultvalue"/>
100
+ </xsl:otherwise>
101
+ </xsl:choose>
102
+ </xsl:template>
103
+ <xsl:template name="attributes"></xsl:template>
104
+ <xsl:variable name="slottemplate">
105
+ <xsl:call-template name="slot" >
106
+ <xsl:with-param name="slotname" select="''"/>
107
+ <xsl:with-param name="defaultvalue"/>
108
+ </xsl:call-template>
109
+ </xsl:variable>
110
+ </xsl:stylesheet>`
111
+ );
112
+
113
+ const attrsTemplate = dom.documentElement.lastElementChild.previousElementSibling
114
+ , getTemplateRoot = n => n.documentElement || n.firstElementChild?.content || n.content || n.body || n
115
+ , tc = getTemplateRoot(templateNode)
116
+ , cc = tc?.childNodes || [];
117
+ if( (tc instanceof CustomElement) || tc.nodeType===11) {
118
+ for( let c of cc )
119
+ attrsTemplate.append(dom.importNode(c,true))
120
+ }else
121
+ {
122
+ attrsTemplate.append(dom.importNode(tc,true))
123
+ }
124
+
125
+ const slot2xsl = s =>
126
+ { const v = dom.firstElementChild.lastElementChild.lastElementChild.cloneNode(true);
127
+ v.firstElementChild.setAttribute('select',`'${s.name}'`)
128
+ for( let c of s.childNodes)
129
+ v.lastElementChild.append(c)
130
+ return v
131
+ }
132
+
133
+ for( const s of attrsTemplate.querySelectorAll('slot') )
134
+ s.parentNode.replaceChild( slot2xsl(s), s )
135
+
136
+ // apply bodyXml changes
137
+ return dom
138
+ }
139
+ export async function
140
+ xhrTemplate(src)
141
+ {
142
+ const dom = await new Promise((resolve,reject)=>
143
+ { const xhr = new XMLHttpRequest();
144
+ xhr.open("GET", src);
145
+ xhr.responseType = "document";
146
+ // xhr.overrideMimeType("text/xml");
147
+ xhr.onload = () =>
148
+ { if( xhr.readyState === xhr.DONE && xhr.status === 200 )
149
+ resolve( xhr.responseXML || create('div', xhr.responseText ) )
150
+ reject(xhr.statusText)
151
+ };
152
+ xhr.addEventListener("error", ev=>reject(ev) );
153
+
154
+ xhr.send();
155
+ })
156
+ return dom
157
+ }
158
+ export function
159
+ deepEqual(a, b, O=false)
160
+ {
161
+ if( a === b )
162
+ return true;
163
+
164
+ if( (typeof a !== "object" || a === null) || (typeof b !== "object" || b === null)
165
+ || Object.keys(a).length !== Object.keys(b).length )
166
+ return O;
167
+
168
+ for( let k in a )
169
+ if( !(k in b) || !deepEqual( a[k], b[k] ) )
170
+ return O
171
+ return true;
172
+ }
173
+
174
+ export function
95
175
  injectSlice( x, s, data )
96
176
  {
97
177
  const isString = typeof data === 'string' ;
@@ -100,36 +180,67 @@ injectSlice( x, s, data )
100
180
  ? create(s, data)
101
181
  : document.adoptNode( xml2dom( Json2Xml( data, s ) ).documentElement);
102
182
  [...x.children].filter( e=>e.localName === s ).map( el=>el.remove() );
183
+ el.data = data
103
184
  x.append(el);
104
185
  }
105
186
 
187
+ function forEach$( el, css, cb){
188
+ if( el.querySelectorAll )
189
+ for( let n of el.querySelectorAll(css) )
190
+ cb(n)
191
+ }
192
+ const getByHashId = ( n, id )=> ( p => n===p? null: (p && ( p.querySelector(id) || getByHashId(p,id) ) ))( n.getRootNode() )
193
+ const loadTemplateRoots = async ( src, dce )=>
194
+ {
195
+ if( !src || !src.trim() )
196
+ return [dce]
197
+ if( src.startsWith('#') )
198
+ return ( n =>
199
+ { if(!n) return []
200
+ const a = n.querySelectorAll(src)
201
+ if( a.length )
202
+ return [...a]
203
+ const r = n.getRootNode();
204
+ return r===n ? []: getByHashId(r)
205
+ })(dce.parentElement)
206
+ try
207
+ { // todo cache
208
+ const dom = await xhrTemplate(src)
209
+ const hash = new URL(src, location).hash
210
+ if( hash )
211
+ { const ret = dom.querySelectorAll(hash);
212
+ if( ret.length )
213
+ return [...ret]
214
+ return [dce]
215
+ }
216
+ return [dom]
217
+ }catch (error){ return [dce]}
218
+ }
106
219
  export class
107
220
  CustomElement extends HTMLElement
108
221
  {
109
- constructor()
222
+ async connectedCallback()
110
223
  {
111
- super();
224
+ const templateRoots = await loadTemplateRoots( attr( this, 'src' ), this )
225
+ , templateDocs = templateRoots.map( n => createXsltFromDom( n ) )
226
+ , xp = templateDocs.map( (td, p) =>{ p = new XSLTProcessor(); p.importStylesheet( td ); return p })
227
+
228
+ Object.defineProperty( this, "xsltString", { get: ()=>xp.map( td => xmlString(td) ).join('\n') });
112
229
 
113
- [ ...this.templateNode.querySelectorAll('slot') ].forEach( slot2xsl );
114
- const p = new XSLTProcessor();
115
- p.importStylesheet( this.xslt );
116
230
  const tag = attr( this, 'tag' );
117
231
  const dce = this;
118
232
  const sliceNames = [...this.templateNode.querySelectorAll('[slice]')].map(e=>attr(e,'slice'));
119
- tag && window.customElements.define( tag, class extends HTMLElement
233
+ class DceElement extends HTMLElement
120
234
  {
121
- constructor()
122
- {
123
- super();
124
- const x = create( 'div' );
125
- injectData( x, 'payload', this.childNodes, assureSlot );
126
- injectData( x, 'attributes', this.attributes, e => create( e.nodeName, e.value ) );
235
+ connectedCallback()
236
+ { const x = createNS( DCE_NS_URL,'datadom' );
237
+ injectData( x, 'payload' , this.childNodes, assureSlot );
238
+ injectData( x, 'attributes' , this.attributes, e => create( e.nodeName, e.value ) );
127
239
  injectData( x, 'dataset', Object.keys( this.dataset ), k => create( k, this.dataset[ k ] ) );
128
240
  const sliceRoot = injectData( x, 'slice', sliceNames, k => create( k, '' ) );
129
241
  this.xml = x;
130
242
  const slices = {};
131
243
 
132
-
133
244
  const sliceEvents=[];
134
245
  const applySlices = ()=>
135
246
  { const processed = {}
@@ -147,6 +258,10 @@ CustomElement extends HTMLElement
147
258
 
148
259
  this.onSlice = ev=>
149
260
  { ev.stopPropagation?.();
261
+ const s = attr( ev.target, 'slice')
262
+ if( deepEqual( ev.detail, [...sliceRoot.children].find( e=>e.localName === s )?.data ) )
263
+ return
264
+
150
265
  sliceEvents.push(ev);
151
266
  if( !timeoutID )
152
267
  timeoutID = setTimeout(()=>
@@ -156,41 +271,39 @@ CustomElement extends HTMLElement
156
271
  };
157
272
  const transform = ()=>
158
273
  {
159
- const f = p.transformToFragment( x, document );
274
+ const ff = xp.map( p => p.transformToFragment(x, document) );
160
275
  this.innerHTML = '';
161
- [ ...f.childNodes ].forEach( e => this.appendChild( e ) );
276
+ ff.map( f =>
277
+ { [ ...f.childNodes ].forEach( e => this.append( e ) );
162
278
 
163
- for( let el of this.querySelectorAll('[slice]') )
164
- if( 'function' === typeof el.sliceInit )
165
- { const s = attr(el,'slice');
166
- slices[s] = el.sliceInit( slices[s] );
167
- }
279
+ forEach$( this,'[slice]', el =>
280
+ { if( 'function' === typeof el.sliceInit )
281
+ { const s = attr( el,'slice' );
282
+ slices[s] = el.sliceInit( slices[s] );
283
+ }
284
+ })
285
+ })
168
286
  };
169
287
  transform();
170
288
  applySlices();
171
289
  }
172
- get dce(){ return dce;}
173
- } );
290
+ get dce(){ return dce }
291
+ }
292
+ if(tag)
293
+ window.customElements.define( tag, DceElement);
294
+ else
295
+ { const t = 'dce-'+crypto.randomUUID()
296
+ window.customElements.define( t, DceElement);
297
+ const el = document.createElement(t);
298
+ this.getAttributeNames().forEach(a=>el.setAttribute(a,this.getAttribute(a)));
299
+ el.append(...this.childNodes)
300
+ this.append(el);
301
+ }
174
302
  }
175
303
  get templateNode(){ return this.firstElementChild?.tagName === 'TEMPLATE'? this.firstElementChild.content : this }
176
- get dce(){ return this;}
177
- get xsltString()
178
- {
179
- return (
180
- `<xsl:stylesheet version="1.0"
181
- xmlns:xsl="${ XSL_NS_URL }">
182
- <xsl:output method="html" />
304
+ get dce(){ return this }
183
305
 
184
- <xsl:template match="/">
185
- <xsl:apply-templates select="//attributes"/>
186
- </xsl:template>
187
- <xsl:template match="attributes">
188
- ${ bodyXml( this ) }
189
- </xsl:template>
190
-
191
- </xsl:stylesheet>` );
192
- }
193
- get xslt(){ return xml2dom( this.xsltString ); }
306
+ get xslt(){ return xml2dom( this.xsltString ) }
194
307
  }
195
308
 
196
309
  window.customElements.define( 'custom-element', CustomElement );
package/demo/a.html ADDED
@@ -0,0 +1,24 @@
1
+ <!DOCTYPE html>
2
+ <html lang="en" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
3
+ <head>
4
+ <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
5
+ <title>custom-element Declarative Custom Element implementation demo</title>
6
+ <link rel="icon" href="demo/wc-square.svg" />
7
+ <script type="module" src="../custom-element.js"></script>
8
+ <style>
9
+ @import "demo/demo.css";
10
+ svg{ max-width: 2rem;}
11
+ </style>
12
+ </head>
13
+ <body>
14
+
15
+ <template id="template1">
16
+ <slot> Hello </slot> World!
17
+ </template>
18
+
19
+ <custom-element src="html-template.html#dwc-logo" >
20
+ <template><i>loading from HTML templates file ...</i></template>
21
+ </custom-element>
22
+
23
+ </body>
24
+ </html>
@@ -0,0 +1,37 @@
1
+ <?xml version="1.0" encoding="UTF-8" standalone="no"?>
2
+ <svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" width="48" height="48" version="1.0">
3
+ <defs>
4
+ <linearGradient id="d">
5
+ <stop offset="0"/>
6
+ <stop offset=".5"/>
7
+ <stop offset=".80000001" stop-opacity=".46666667"/>
8
+ <stop offset="1" stop-opacity="0"/>
9
+ </linearGradient>
10
+ <linearGradient id="a">
11
+ <stop offset="0" stop-color="#fb0"/>
12
+ <stop offset=".5" stop-color="#e29d00"/>
13
+ <stop offset="1" stop-color="#fb0"/>
14
+ </linearGradient>
15
+ <linearGradient id="c">
16
+ <stop offset="0"/>
17
+ <stop offset="1" stop-opacity="0"/>
18
+ </linearGradient>
19
+ <linearGradient id="b">
20
+ <stop offset="0" stop-color="#ffc"/>
21
+ <stop offset=".5" stop-color="#fff965"/>
22
+ <stop offset="1" stop-color="#fc3"/>
23
+ </linearGradient>
24
+ <linearGradient xlink:href="#a" id="i" x1="8.0350637" x2="42.788235" y1="32.372219" y2="32.372219" gradientUnits="userSpaceOnUse" spreadMethod="pad"/>
25
+ <radialGradient xlink:href="#b" id="f" cx="17.986637" cy="16.545853" r="23.978155" fx="17.986637" fy="16.545853" gradientUnits="userSpaceOnUse"/>
26
+ <radialGradient xlink:href="#c" id="e" cx="53.309223" cy="94.956306" r="63.252911" fx="53.309223" fy="94.956306" gradientTransform="matrix(1 0 0 .34935 0 61.7838)" gradientUnits="userSpaceOnUse"/>
27
+ <radialGradient xlink:href="#d" id="g" cx="18.71347" cy="21.759708" r="1.8644418" fx="18.71347" fy="21.759708" gradientTransform="matrix(1 0 0 1.77778 0 -16.92422)" gradientUnits="userSpaceOnUse"/>
28
+ </defs>
29
+ <path fill="url(#e)" d="M116.56213 94.956306a63.252911 22.097088 0 1 1-126.5058174 0 63.252911 22.097088 0 1 1 126.5058174 0z" opacity=".53200001" transform="matrix(.3162 0 0 .33941 6.936944 8.132618)"/>
30
+ <path fill="url(#f)" stroke="#fb0" stroke-width="1.43869453" d="M47.094418 23.83131a23.478155 23.478155 0 1 1-46.9563107 0 23.478155 23.478155 0 1 1 46.9563107 0z" transform="translate(4.30185 4.122792) scale(.83409)"/>
31
+ <path id="h" fill="#fff" fill-opacity="1" fill-rule="nonzero" stroke="#fc0" stroke-dasharray="none" stroke-dashoffset="0" stroke-linejoin="miter" stroke-miterlimit="4" stroke-opacity="1" stroke-width="1" d="M21.682767 18.5142a3.9360437 6.9743929 0 1 1-7.872088 0 3.9360437 6.9743929 0 1 1 7.872088 0z" opacity="1" transform="matrix(1.01507 0 0 1.00354 -.0090285 .916405)"/>
32
+ <path id="j" fill="url(#g)" fill-opacity="1" fill-rule="nonzero" stroke="none" stroke-dasharray="none" stroke-dashoffset="0" stroke-linejoin="miter" stroke-miterlimit="4" stroke-opacity="1" stroke-width="1" d="M20.577912 21.759708a1.8644418 3.314563 0 1 1-3.728883 0 1.8644418 3.314563 0 1 1 3.728883 0z" opacity="1" transform="translate(-.138107 .535104)"/>
33
+ <use xlink:href="#h" width="48" height="48" transform="translate(12.50001 -4.4e-7)"/>
34
+ <path fill="none" stroke="url(#i)" stroke-linecap="round" stroke-width="1.97319973" d="M9.0216636 35.899178c4.7689724-7.457767 10.9544424-9.489956 17.3095664-3.728884 5.404329 4.899155 11.190398 4.350365 15.470406-.656007"/>
35
+ <path fill="none" stroke="#e2ac00" stroke-linecap="round" stroke-width="1.17813516" d="M15.504748 34.21319c3.012147-3.243177 6.693658.87012 6.693658.87012" opacity=".8"/>
36
+ <use xlink:href="#j" width="48" height="48" transform="translate(10.78418 -5)"/>
37
+ </svg>
package/demo/demo.css CHANGED
@@ -5,8 +5,10 @@ html
5
5
  body,nav{ display: flex; flex-wrap: wrap; align-content: stretch; gap: 1rem; }
6
6
  body>*{flex: auto;}
7
7
  nav{ flex-direction: column;}
8
+ custom-element+*,
9
+ custom-element:not([tag]),
8
10
  dce-link,dce-1-slot,dce-2-slot,dce-3-slot,dce-4-slot,dce-2-slots,greet-element,pokemon-tile,
9
- dce-1,dce-2,dce-3,dce-4
11
+ dce-1,dce-2,dce-3,dce-4,dce-internal,dce-hash
10
12
  { box-shadow: 0 0 0.5rem lime; padding: 1rem; display: inline-block; flex:1; }
11
13
  dd{ padding: 1rem;}
12
14
  p{ margin: 0;}
@@ -0,0 +1,3 @@
1
+ <h4>embed-1.html</h4>
2
+ <custom-element tag="dce-embed-1" hidden>🖖</custom-element>
3
+ <dce-embed-1>?</dce-embed-1>
@@ -0,0 +1,176 @@
1
+ <!DOCTYPE html>
2
+ <html lang="en">
3
+ <head>
4
+ <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
5
+ <title>http-request Declarative Custom Element implementation demo</title>
6
+ <link rel="icon" href="./wc-square.svg" />
7
+
8
+ <script type="module" src="../http-request.js"></script>
9
+ <script type="module" src="../custom-element.js"></script>
10
+ <style>
11
+ @import "./demo.css";
12
+
13
+ button
14
+ { display: inline-flex; flex-direction: column; align-items: center; flex: auto;
15
+ box-shadow: inset silver 0 0 1rem; min-width: 12rem; padding: 1rem;
16
+ color: coral; text-shadow: 1px 1px silver; font-weight: bolder;
17
+ }
18
+ button img{ max-height: 10vw; min-height: 4rem;}
19
+ table{ min-width: 16rem; }
20
+ td{ border-bottom: 1px solid silver; }
21
+ tfoot td{ border-bottom: none; }
22
+ td,th{text-align: right; }
23
+ caption{ padding: 1rem; font-weight: bolder; font-family: sans-serif; }
24
+ code{ text-align: right; min-width: 3rem;}
25
+ svg{ max-height: 3rem;}
26
+ </style>
27
+ </head>
28
+ <body>
29
+
30
+ <nav>
31
+ <a href="../index.html"><h3><code>custom-element</code> demo</h3></a>
32
+ <h3>Loading DCE template by SRC attribute</h3>
33
+ </nav>
34
+
35
+ <html-demo-element legend="1. reference the template in page DOM"
36
+ description="should render hand wave with '👋 World!' and 'Hello World!'">
37
+ <template>
38
+ <template id="template1">
39
+ <slot> Hello </slot> World!
40
+ </template>
41
+
42
+ <custom-element tag="dce-internal" src="#template1"></custom-element>
43
+ <!-- no need for loading fallback as the template exists -->
44
+
45
+ <dce-internal>👋</dce-internal>
46
+ <dce-internal></dce-internal>
47
+ </template>
48
+ </html-demo-element>
49
+
50
+
51
+ <html-demo-element legend="2. without TAG, inline instantiation"
52
+ description="hash value in SRC references template by ID. Should output 'construction' 2 times">
53
+ <template>
54
+ <template id="template2">
55
+ 🏗️ construction
56
+ </template>
57
+
58
+ <custom-element src="#template2"></custom-element>
59
+ <custom-element src="#template2"></custom-element>
60
+ </template>
61
+ </html-demo-element>
62
+
63
+ <html-demo-element legend="3. external SVG file" >
64
+ <template>
65
+ <custom-element tag="dce-external" src="confused.svg" >
66
+ <template><i>loading from SVG ...</i></template>
67
+ </custom-element>
68
+ <dce-external></dce-external>
69
+ <custom-element src="confused.svg" >
70
+ <i>inline DCE loading from SVG ...</i>
71
+ </custom-element>
72
+ <custom-element src="no.svg" >
73
+ <i>fallback for missing image</i>
74
+ </custom-element>
75
+ </template>
76
+ </html-demo-element>
77
+
78
+ <html-demo-element legend="4. external XSLT file" >
79
+ <template>
80
+ <custom-element tag="dce-external-4" src="tree.xsl" >
81
+ <template><i>loading from XSLT ...</i></template>
82
+ </custom-element>
83
+ <dce-external-4 title="DCE with external XSLT template" data-fruit="🍌">Hi</dce-external-4>
84
+ <custom-element src="tree.xsl" data-smile="👼" data-basket="🍒">
85
+ <i>inline DCE loading from XSLT ...</i>
86
+ </custom-element>
87
+ </template>
88
+ </html-demo-element>
89
+
90
+ <html-demo-element legend="5. external HTML template" description="Should render 👋👌, svg">
91
+ <template>
92
+ <custom-element tag="dce-external-5" src="html-template.html" >
93
+ <template><i>loading from HTML file ...</i></template>
94
+ </custom-element>
95
+ <dce-external-5 title="DCE with external XSLT template" data-fruit="🍌">Hi</dce-external-5>
96
+ <custom-element src="html-template.html" data-smile="👼" data-basket="🍒">
97
+ <i>inline DCE loading from HTML file ...</i>
98
+ </custom-element>
99
+ </template>
100
+ </html-demo-element>
101
+
102
+ <html-demo-element legend="6. HTML, SVG by ID within external file" description="Should render 👋, svg, 👌">
103
+ <a href="html-template.html">html-template.html</a>
104
+ <template>
105
+ <custom-element src="html-template.html#wave" >
106
+ <template><i>loading from HTML templates file ...</i></template>
107
+ </custom-element>
108
+ <custom-element src="html-template.html#dwc-logo" >
109
+ <template><i>loading from HTML templates file ...</i></template>
110
+ </custom-element>
111
+ <custom-element src="html-template.html#ok" >
112
+ <template><i>loading from HTML templates file ...</i></template>
113
+ </custom-element>
114
+ </template>
115
+ </html-demo-element>
116
+ <html-demo-element legend="7. XSLT by ID within external file" description="Should render tree, and fallback">
117
+ <a href="html-template.html">html-template.html</a>
118
+ <template>
119
+ <custom-element src="html-template.xhtml#embedded-xsl" >
120
+ <template>whole XSLT is embedded into HTML body</template>
121
+ </custom-element>
122
+ <custom-element src="html-template.html#none" >
123
+ <template><i>element with id=none is missing in template</i></template>
124
+ </custom-element>
125
+ </template>
126
+ </html-demo-element>
127
+
128
+ <html-demo-element legend="8. external file with embedding of another external DCE"
129
+ description="Should render Vulcan Salute 🖖"
130
+ >
131
+ <template>
132
+ <custom-element src="embed-1.html" >
133
+ loading from embed-1.html ...
134
+ </custom-element>
135
+ </template>
136
+ </html-demo-element>
137
+ <html-demo-element legend="embed-1.html external file " src="embed-1.html">
138
+ </html-demo-element>
139
+ <!--
140
+ <html-demo-element legend="9. deep external files, complex rendering" >
141
+ <template>
142
+ <custom-element src="../index.html#shared-template" hidden>
143
+ loading by hash from ../index.html#shared-template ...
144
+ </custom-element>
145
+ </template>
146
+ </html-demo-element>
147
+
148
+ <html-demo-element legend="9. own import maps" >
149
+ <template>
150
+ <custom-element src="../index.html#shared-template" hidden>
151
+ loading by hash from ../index.html#shared-template ...
152
+ </custom-element>
153
+ </template>
154
+ </html-demo-element>
155
+
156
+ <html-demo-element legend="10. deep external files with own import maps" >
157
+ <template>
158
+ <custom-element src="../index.html#shared-template" hidden>
159
+ loading by hash from ../index.html#shared-template ...
160
+ </custom-element>
161
+ </template>
162
+ </html-demo-element>
163
+
164
+ <html-demo-element legend="11. local template as a 'loading...' or fallback for remote, error handling" >
165
+ <template>
166
+ <custom-element src="../index.html#shared-template" hidden>
167
+ loading by hash from ../index.html#shared-template ...
168
+ </custom-element>
169
+ </template>
170
+ </html-demo-element>
171
+
172
+ -->
173
+ <script type="module" src="https://unpkg.com/html-demo-element@1/html-demo-element.js"></script>
174
+
175
+ </body>
176
+ </html>
@@ -0,0 +1,13 @@
1
+ <!DOCTYPE html>
2
+ <html lang="en" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
3
+ <head>
4
+ <meta charset="UTF-8">
5
+ <title>template based on HTML file</title>
6
+ </head>
7
+ <body>
8
+ <b id="wave">👋</b>
9
+ <b id="ok">👌</b>
10
+ <svg id="dwc-logo" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 216 209.18"><defs><style>.cls-1{fill:#c2e6f1;}.cls-2{fill:#dcf1f7;}.cls-3{fill:#2d4554;}.cls-4{fill:#60cae5;}</style></defs><polygon class="cls-3" points="0 82.47 0 126.71 34.84 146.83 34.84 187.06 73.16 209.18 108 189.07 142.84 209.18 181.16 187.06 181.16 146.83 216 126.71 216 82.47 181.16 62.35 181.16 22.12 142.84 0 108 20.12 73.16 0 34.84 22.12 34.84 62.35 0 82.47"/><path class="cls-2" d="m114.33,56.69l20.64-11.92c.47-.27.47-.79,0-1.06l-20.65-11.92h0c-4.44-2.57-8.22-2.57-12.67,0l-20.65,11.92c-.47.27-.47.79,0,1.06l20.64,11.92c4.44,2.57,8.22,2.57,12.67,0h0Z"/><path class="cls-2" d="m98.19,62.71h0s-20.64-11.92-20.64-11.92c-.47-.27-.92-.01-.92.53v23.84s0,0,0,0c0,5.13,1.89,8.4,6.33,10.97l20.65,11.92c.47.27.92,0,.92-.54v-23.84c0-5.13-1.89-8.4-6.33-10.97Z"/><path class="cls-1" d="m48.12,66.01l20.65,11.92c.47.27.92,0,.92-.54v-23.84c0-5.13-1.89-8.4-6.33-10.97h0s-20.64-11.92-20.64-11.92c-.47-.27-.92-.01-.92.53v23.84s0,0,0,0c0,5.13,1.89,8.4,6.33,10.97Z"/><path class="cls-2" d="m46.18,24.66l20.64,11.92c4.44,2.57,8.22,2.57,12.67,0h0s20.64-11.92,20.64-11.92c.47-.27.47-.79,0-1.06l-20.65-11.92h0c-4.44-2.57-8.22-2.57-12.67,0l-20.65,11.92c-.47.27-.47.79,0,1.06Z"/><path class="cls-2" d="m115.87,24.66l20.64,11.92c4.44,2.57,8.22,2.57,12.67,0h0s20.64-11.92,20.64-11.92c.47-.27.47-.79,0-1.06l-20.65-11.92h0c-4.44-2.57-8.22-2.57-12.67,0l-20.65,11.92c-.47.27-.47.79,0,1.06Z"/><path class="cls-2" d="m152.65,42.59c-4.44,2.56-6.33,5.84-6.33,10.97v23.84c0,.54.45.8.92.54l20.65-11.92c4.44-2.57,6.33-5.84,6.33-10.97h0v-23.84c0-.54-.45-.8-.92-.53l-20.64,11.92h0Z"/><path class="cls-2" d="m77.55,158.4l20.65-11.92h0c4.44-2.57,6.33-5.84,6.33-10.97v-23.84c0-.54-.45-.8-.92-.53l-20.64,11.92c-4.44,2.57-6.33,5.84-6.33,10.97h0s0,23.84,0,23.84c0,.54.45.8.92.54Z"/><path class="cls-4" d="m146.31,134.03v23.84c0,.54.45.8.92.54l20.65-11.92c4.44-2.57,6.33-5.84,6.33-10.97h0s0-23.84,0-23.84c0-.54-.45-.8-.92-.53l-20.64,11.92h0c-4.44,2.57-6.33,5.84-6.33,10.97Z"/><path class="cls-4" d="m63.35,123.06h0s-20.64-11.92-20.64-11.92c-.47-.27-.92-.01-.92.53v23.84s0,0,0,0c0,5.13,1.89,8.4,6.33,10.97l20.65,11.92c.47.27.92,0,.92-.54v-23.84c0-5.13-1.89-8.4-6.33-10.97Z"/><path class="cls-4" d="m103.61,151.37l-20.64,11.92c-4.44,2.57-6.33,5.84-6.33,10.97h0s0,23.84,0,23.84c0,.54.45.8.92.54l20.65-11.92h0c4.44-2.57,6.33-5.84,6.33-10.97v-23.84c0-.54-.45-.8-.92-.53Z"/><path class="cls-4" d="m63.35,163.29h0s-20.64-11.92-20.64-11.92c-.47-.27-.92-.01-.92.53v23.84s0,0,0,0c0,5.13,1.89,8.4,6.33,10.97l20.65,11.92c.47.27.92,0,.92-.54v-23.84c0-5.13-1.89-8.4-6.33-10.97Z"/><path class="cls-4" d="m28.51,102.94h0s-20.64-11.92-20.64-11.92c-.47-.27-.92-.01-.92.53v23.84s0,0,0,0c0,5.13,1.89,8.4,6.33,10.97l20.65,11.92c.47.27.92,0,.92-.54v-23.84c0-5.13-1.89-8.4-6.33-10.97Z"/><path class="cls-4" d="m133.04,163.29l-20.64-11.92c-.47-.27-.92-.01-.92.53v23.84c0,5.13,1.89,8.4,6.33,10.97h0s20.65,11.92,20.65,11.92c.47.27.92,0,.92-.54v-23.84s0,0,0,0c0-5.13-1.89-8.4-6.33-10.97Z"/><path class="cls-4" d="m173.29,151.37l-20.64,11.92h0c-4.44,2.57-6.33,5.84-6.33,10.97v23.84c0,.54.45.8.92.54l20.65-11.92c4.44-2.57,6.33-5.84,6.33-10.97h0s0-23.84,0-23.84c0-.54-.45-.8-.92-.53Z"/><path class="cls-4" d="m209.06,91.55c0-.54-.45-.8-.92-.53l-20.64,11.92h0c-4.44,2.57-6.33,5.84-6.33,10.97v23.84c0,.54.45.8.92.54l20.65-11.92c4.44-2.57,6.33-5.84,6.33-10.97h0v-23.84Z"/><path class="cls-2" d="m149.18,117.04l20.64-11.92c.47-.27.47-.79,0-1.06l-20.65-11.92h0c-4.44-2.57-8.22-2.57-12.67,0l-20.65,11.92c-.47.27-.47.79,0,1.06l20.64,11.92c4.44,2.57,8.22,2.57,12.67,0h0Z"/><path class="cls-1" d="m112.39,98.05l20.65-11.92c4.44-2.57,6.33-5.84,6.33-10.97h0v-23.84c0-.54-.45-.8-.92-.53l-20.64,11.92h0c-4.44,2.57-6.33,5.84-6.33,10.97v23.84c0,.54.45.8.92.54Z"/><path class="cls-1" d="m100.13,105.12c.47-.27.47-.79,0-1.06l-20.65-11.92c-4.44-2.57-8.22-2.57-12.67,0h0s-20.65,11.92-20.65,11.92c-.47.27-.47.79,0,1.06l20.64,11.92h0c4.44,2.57,8.22,2.57,12.67,0l20.64-11.92Z"/><path class="cls-2" d="m65.29,85.01c.47-.27.47-.79,0-1.06l-20.65-11.92c-4.44-2.57-8.22-2.57-12.67,0h0s-20.65,11.92-20.65,11.92c-.47.27-.47.79,0,1.06l20.64,11.92h0c4.44,2.57,8.22,2.57,12.67,0l20.64-11.92Z"/><path class="cls-1" d="m133.04,123.06l-20.64-11.92c-.47-.27-.92-.01-.92.53v23.84c0,5.13,1.89,8.4,6.33,10.97h0s20.65,11.92,20.65,11.92c.47.27.92,0,.92-.54v-23.84s0,0,0,0c0-5.13-1.89-8.4-6.33-10.97Z"/><path class="cls-1" d="m184.02,96.93l20.64-11.92c.47-.27.47-.79,0-1.06l-20.65-11.92h0c-4.44-2.57-8.22-2.57-12.67,0l-20.65,11.92c-.47.27-.47.79,0,1.06l20.64,11.92c4.44,2.57,8.22,2.57,12.67,0h0Z"/></svg>
11
+
12
+ </body>
13
+ </html>
@@ -0,0 +1,45 @@
1
+ <!DOCTYPE html>
2
+ <html lang="en" xmlns="http://www.w3.org/1999/xhtml" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
3
+ <head>
4
+ <meta charset="UTF-8"/>
5
+ <title>template based on HTML file</title>
6
+ </head>
7
+ <body>
8
+ <b id="wave">👋</b>
9
+ <b id="ok">👌</b>
10
+ <svg id="dwc-logo" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 216 209.18"><defs><style>.cls-1{fill:#c2e6f1;}.cls-2{fill:#dcf1f7;}.cls-3{fill:#2d4554;}.cls-4{fill:#60cae5;}</style></defs><polygon class="cls-3" points="0 82.47 0 126.71 34.84 146.83 34.84 187.06 73.16 209.18 108 189.07 142.84 209.18 181.16 187.06 181.16 146.83 216 126.71 216 82.47 181.16 62.35 181.16 22.12 142.84 0 108 20.12 73.16 0 34.84 22.12 34.84 62.35 0 82.47"/><path class="cls-2" d="m114.33,56.69l20.64-11.92c.47-.27.47-.79,0-1.06l-20.65-11.92h0c-4.44-2.57-8.22-2.57-12.67,0l-20.65,11.92c-.47.27-.47.79,0,1.06l20.64,11.92c4.44,2.57,8.22,2.57,12.67,0h0Z"/><path class="cls-2" d="m98.19,62.71h0s-20.64-11.92-20.64-11.92c-.47-.27-.92-.01-.92.53v23.84s0,0,0,0c0,5.13,1.89,8.4,6.33,10.97l20.65,11.92c.47.27.92,0,.92-.54v-23.84c0-5.13-1.89-8.4-6.33-10.97Z"/><path class="cls-1" d="m48.12,66.01l20.65,11.92c.47.27.92,0,.92-.54v-23.84c0-5.13-1.89-8.4-6.33-10.97h0s-20.64-11.92-20.64-11.92c-.47-.27-.92-.01-.92.53v23.84s0,0,0,0c0,5.13,1.89,8.4,6.33,10.97Z"/><path class="cls-2" d="m46.18,24.66l20.64,11.92c4.44,2.57,8.22,2.57,12.67,0h0s20.64-11.92,20.64-11.92c.47-.27.47-.79,0-1.06l-20.65-11.92h0c-4.44-2.57-8.22-2.57-12.67,0l-20.65,11.92c-.47.27-.47.79,0,1.06Z"/><path class="cls-2" d="m115.87,24.66l20.64,11.92c4.44,2.57,8.22,2.57,12.67,0h0s20.64-11.92,20.64-11.92c.47-.27.47-.79,0-1.06l-20.65-11.92h0c-4.44-2.57-8.22-2.57-12.67,0l-20.65,11.92c-.47.27-.47.79,0,1.06Z"/><path class="cls-2" d="m152.65,42.59c-4.44,2.56-6.33,5.84-6.33,10.97v23.84c0,.54.45.8.92.54l20.65-11.92c4.44-2.57,6.33-5.84,6.33-10.97h0v-23.84c0-.54-.45-.8-.92-.53l-20.64,11.92h0Z"/><path class="cls-2" d="m77.55,158.4l20.65-11.92h0c4.44-2.57,6.33-5.84,6.33-10.97v-23.84c0-.54-.45-.8-.92-.53l-20.64,11.92c-4.44,2.57-6.33,5.84-6.33,10.97h0s0,23.84,0,23.84c0,.54.45.8.92.54Z"/><path class="cls-4" d="m146.31,134.03v23.84c0,.54.45.8.92.54l20.65-11.92c4.44-2.57,6.33-5.84,6.33-10.97h0s0-23.84,0-23.84c0-.54-.45-.8-.92-.53l-20.64,11.92h0c-4.44,2.57-6.33,5.84-6.33,10.97Z"/><path class="cls-4" d="m63.35,123.06h0s-20.64-11.92-20.64-11.92c-.47-.27-.92-.01-.92.53v23.84s0,0,0,0c0,5.13,1.89,8.4,6.33,10.97l20.65,11.92c.47.27.92,0,.92-.54v-23.84c0-5.13-1.89-8.4-6.33-10.97Z"/><path class="cls-4" d="m103.61,151.37l-20.64,11.92c-4.44,2.57-6.33,5.84-6.33,10.97h0s0,23.84,0,23.84c0,.54.45.8.92.54l20.65-11.92h0c4.44-2.57,6.33-5.84,6.33-10.97v-23.84c0-.54-.45-.8-.92-.53Z"/><path class="cls-4" d="m63.35,163.29h0s-20.64-11.92-20.64-11.92c-.47-.27-.92-.01-.92.53v23.84s0,0,0,0c0,5.13,1.89,8.4,6.33,10.97l20.65,11.92c.47.27.92,0,.92-.54v-23.84c0-5.13-1.89-8.4-6.33-10.97Z"/><path class="cls-4" d="m28.51,102.94h0s-20.64-11.92-20.64-11.92c-.47-.27-.92-.01-.92.53v23.84s0,0,0,0c0,5.13,1.89,8.4,6.33,10.97l20.65,11.92c.47.27.92,0,.92-.54v-23.84c0-5.13-1.89-8.4-6.33-10.97Z"/><path class="cls-4" d="m133.04,163.29l-20.64-11.92c-.47-.27-.92-.01-.92.53v23.84c0,5.13,1.89,8.4,6.33,10.97h0s20.65,11.92,20.65,11.92c.47.27.92,0,.92-.54v-23.84s0,0,0,0c0-5.13-1.89-8.4-6.33-10.97Z"/><path class="cls-4" d="m173.29,151.37l-20.64,11.92h0c-4.44,2.57-6.33,5.84-6.33,10.97v23.84c0,.54.45.8.92.54l20.65-11.92c4.44-2.57,6.33-5.84,6.33-10.97h0s0-23.84,0-23.84c0-.54-.45-.8-.92-.53Z"/><path class="cls-4" d="m209.06,91.55c0-.54-.45-.8-.92-.53l-20.64,11.92h0c-4.44,2.57-6.33,5.84-6.33,10.97v23.84c0,.54.45.8.92.54l20.65-11.92c4.44-2.57,6.33-5.84,6.33-10.97h0v-23.84Z"/><path class="cls-2" d="m149.18,117.04l20.64-11.92c.47-.27.47-.79,0-1.06l-20.65-11.92h0c-4.44-2.57-8.22-2.57-12.67,0l-20.65,11.92c-.47.27-.47.79,0,1.06l20.64,11.92c4.44,2.57,8.22,2.57,12.67,0h0Z"/><path class="cls-1" d="m112.39,98.05l20.65-11.92c4.44-2.57,6.33-5.84,6.33-10.97h0v-23.84c0-.54-.45-.8-.92-.53l-20.64,11.92h0c-4.44,2.57-6.33,5.84-6.33,10.97v23.84c0,.54.45.8.92.54Z"/><path class="cls-1" d="m100.13,105.12c.47-.27.47-.79,0-1.06l-20.65-11.92c-4.44-2.57-8.22-2.57-12.67,0h0s-20.65,11.92-20.65,11.92c-.47.27-.47.79,0,1.06l20.64,11.92h0c4.44,2.57,8.22,2.57,12.67,0l20.64-11.92Z"/><path class="cls-2" d="m65.29,85.01c.47-.27.47-.79,0-1.06l-20.65-11.92c-4.44-2.57-8.22-2.57-12.67,0h0s-20.65,11.92-20.65,11.92c-.47.27-.47.79,0,1.06l20.64,11.92h0c4.44,2.57,8.22,2.57,12.67,0l20.64-11.92Z"/><path class="cls-1" d="m133.04,123.06l-20.64-11.92c-.47-.27-.92-.01-.92.53v23.84c0,5.13,1.89,8.4,6.33,10.97h0s20.65,11.92,20.65,11.92c.47.27.92,0,.92-.54v-23.84s0,0,0,0c0-5.13-1.89-8.4-6.33-10.97Z"/><path class="cls-1" d="m184.02,96.93l20.64-11.92c.47-.27.47-.79,0-1.06l-20.65-11.92h0c-4.44-2.57-8.22-2.57-12.67,0l-20.65,11.92c-.47.27-.47.79,0,1.06l20.64,11.92c4.44,2.57,8.22,2.57,12.67,0h0Z"/></svg>
11
+ <xsl:stylesheet
12
+ id="embedded-xsl"
13
+ version="1.0"
14
+ xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
15
+ <xsl:output
16
+ method="html"
17
+ omit-xml-declaration="yes"
18
+ standalone="yes"
19
+ indent="yes"
20
+ />
21
+
22
+ <xsl:template match="/">
23
+ <xsl:apply-templates select="*"/>
24
+ </xsl:template>
25
+ <xsl:template match="*">
26
+ <details style="padding:0 1rem" open="open">
27
+ <summary>
28
+ <b style="color:green"><xsl:value-of select="name()"/></b>
29
+ <xsl:apply-templates select="@*"/>
30
+ </summary>
31
+ <xsl:value-of select="./text()"/>
32
+ <xsl:apply-templates select="*"/>
33
+ </details>
34
+ </xsl:template>
35
+ <xsl:template match="@*">
36
+ <code style="margin-left:1rem;color:brown"><xsl:value-of select="name()"/>="<xsl:value-of select="."/>"</code>
37
+ </xsl:template>
38
+ <xsl:template match="text()">
39
+ <p>
40
+ <xsl:value-of select="."/>
41
+ </p>
42
+ </xsl:template>
43
+ </xsl:stylesheet>
44
+ </body>
45
+ </html>