skeleton-webcomponent-loader 1.0.2 → 2.1.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 (43) hide show
  1. package/CHANGELOG.md +26 -0
  2. package/dist/cjs/{css-shim-b5b9a7c7.js → css-shim-b3e497ca.js} +1 -1
  3. package/dist/cjs/{index-b7b0a13e.js → index-b5d2dca0.js} +209 -138
  4. package/dist/cjs/loader.cjs.js +5 -5
  5. package/dist/cjs/nb-skeleton.cjs.entry.js +23 -77
  6. package/dist/cjs/skeleton-webcomponent.cjs.js +5 -5
  7. package/dist/collection/collection-manifest.json +2 -2
  8. package/dist/collection/components/skeleton/skeleton.js +71 -39
  9. package/dist/custom-elements/index.d.ts +10 -2
  10. package/dist/custom-elements/index.js +26 -79
  11. package/dist/esm/{css-shim-2bc9d17d.js → css-shim-2f04a37a.js} +1 -1
  12. package/dist/esm/{index-f5ca0f12.js → index-63fd3905.js} +193 -121
  13. package/dist/esm/loader.js +5 -5
  14. package/dist/esm/nb-skeleton.entry.js +23 -77
  15. package/dist/esm/polyfills/index.js +2 -2
  16. package/dist/esm/skeleton-webcomponent.js +5 -5
  17. package/dist/esm-es5/{css-shim-2bc9d17d.js → css-shim-2f04a37a.js} +0 -0
  18. package/dist/esm-es5/index-63fd3905.js +1 -0
  19. package/dist/esm-es5/loader.js +1 -1
  20. package/dist/esm-es5/nb-skeleton.entry.js +1 -7
  21. package/dist/esm-es5/skeleton-webcomponent.js +1 -1
  22. package/dist/skeleton-webcomponent/p-12077897.js +1 -0
  23. package/dist/skeleton-webcomponent/{p-527e1426.system.js → p-16aec442.system.js} +0 -0
  24. package/dist/skeleton-webcomponent/p-63ed3b45.entry.js +1 -0
  25. package/dist/skeleton-webcomponent/p-7e96e5d4.js +1 -0
  26. package/dist/skeleton-webcomponent/p-8bef7229.system.js +1 -0
  27. package/dist/skeleton-webcomponent/p-dc1bf577.system.entry.js +1 -0
  28. package/dist/skeleton-webcomponent/p-f59432d4.system.js +1 -0
  29. package/dist/skeleton-webcomponent/skeleton-webcomponent.esm.js +1 -1
  30. package/dist/skeleton-webcomponent/skeleton-webcomponent.js +1 -1
  31. package/dist/types/components/skeleton/skeleton.d.ts +9 -1
  32. package/dist/types/components.d.ts +14 -2
  33. package/dist/types/stencil-public-runtime.d.ts +225 -195
  34. package/loader/index.d.ts +0 -1
  35. package/package.json +19 -7
  36. package/readme.md +7 -5
  37. package/dist/esm-es5/index-f5ca0f12.js +0 -1
  38. package/dist/skeleton-webcomponent/p-4be3ea66.system.entry.js +0 -7
  39. package/dist/skeleton-webcomponent/p-8715773a.entry.js +0 -7
  40. package/dist/skeleton-webcomponent/p-8f82881f.js +0 -1
  41. package/dist/skeleton-webcomponent/p-b131d02e.system.js +0 -1
  42. package/dist/skeleton-webcomponent/p-d9243289.js +0 -1
  43. package/dist/skeleton-webcomponent/p-fde56e0b.system.js +0 -1
@@ -1,48 +1,48 @@
1
1
  'use strict';
2
2
 
3
3
  function _interopNamespace(e) {
4
- if (e && e.__esModule) { return e; } else {
5
- var n = Object.create(null);
6
- if (e) {
7
- Object.keys(e).forEach(function (k) {
8
- if (k !== 'default') {
9
- var d = Object.getOwnPropertyDescriptor(e, k);
10
- Object.defineProperty(n, k, d.get ? d : {
11
- enumerable: true,
12
- get: function () {
13
- return e[k];
14
- }
15
- });
16
- }
17
- });
18
- }
19
- n['default'] = e;
20
- return Object.freeze(n);
4
+ if (e && e.__esModule) return e;
5
+ var n = Object.create(null);
6
+ if (e) {
7
+ Object.keys(e).forEach(function (k) {
8
+ if (k !== 'default') {
9
+ var d = Object.getOwnPropertyDescriptor(e, k);
10
+ Object.defineProperty(n, k, d.get ? d : {
11
+ enumerable: true,
12
+ get: function () {
13
+ return e[k];
14
+ }
15
+ });
16
+ }
17
+ });
21
18
  }
19
+ n['default'] = e;
20
+ return Object.freeze(n);
22
21
  }
23
22
 
24
23
  const NAMESPACE = 'skeleton-webcomponent';
25
24
 
26
25
  let scopeId;
26
+ let hostTagName;
27
27
  let isSvgMode = false;
28
28
  let queuePending = false;
29
29
  const win = typeof window !== 'undefined' ? window : {};
30
- const CSS = win.CSS ;
30
+ const CSS = win.CSS ;
31
31
  const doc = win.document || { head: {} };
32
32
  const plt = {
33
33
  $flags$: 0,
34
34
  $resourcesUrl$: '',
35
- jmp: h => h(),
36
- raf: h => requestAnimationFrame(h),
35
+ jmp: (h) => h(),
36
+ raf: (h) => requestAnimationFrame(h),
37
37
  ael: (el, eventName, listener, opts) => el.addEventListener(eventName, listener, opts),
38
38
  rel: (el, eventName, listener, opts) => el.removeEventListener(eventName, listener, opts),
39
39
  ce: (eventName, opts) => new CustomEvent(eventName, opts),
40
40
  };
41
41
  const promiseResolve = (v) => Promise.resolve(v);
42
- const supportsConstructibleStylesheets = /*@__PURE__*/ (() => {
42
+ const supportsConstructibleStylesheets = /*@__PURE__*/ (() => {
43
43
  try {
44
44
  new CSSStyleSheet();
45
- return true;
45
+ return typeof new CSSStyleSheet().replace === 'function';
46
46
  }
47
47
  catch (e) { }
48
48
  return false;
@@ -91,7 +91,7 @@ const addStyle = (styleContainerNode, cmpMeta, mode, hostElm) => {
91
91
  }
92
92
  if (!appliedStyles.has(scopeId)) {
93
93
  {
94
- if ( plt.$cssShim$) {
94
+ if (plt.$cssShim$) {
95
95
  styleElm = plt.$cssShim$.createHostStyle(hostElm, scopeId, style, !!(cmpMeta.$flags$ & 10 /* needsScopedEncapsulation */));
96
96
  const newScopeId = styleElm['s-sc'];
97
97
  if (newScopeId) {
@@ -113,7 +113,7 @@ const addStyle = (styleContainerNode, cmpMeta, mode, hostElm) => {
113
113
  }
114
114
  }
115
115
  }
116
- else if ( !styleContainerNode.adoptedStyleSheets.includes(style)) {
116
+ else if (!styleContainerNode.adoptedStyleSheets.includes(style)) {
117
117
  styleContainerNode.adoptedStyleSheets = [...styleContainerNode.adoptedStyleSheets, style];
118
118
  }
119
119
  }
@@ -124,8 +124,8 @@ const attachStyles = (hostRef) => {
124
124
  const elm = hostRef.$hostElement$;
125
125
  const flags = cmpMeta.$flags$;
126
126
  const endAttachStyles = createTime('attachStyles', cmpMeta.$tagName$);
127
- const scopeId = addStyle( elm.getRootNode(), cmpMeta, hostRef.$modeName$, elm);
128
- if ( flags & 10 /* needsScopedEncapsulation */) {
127
+ const scopeId = addStyle(elm.shadowRoot ? elm.shadowRoot : elm.getRootNode(), cmpMeta, hostRef.$modeName$, elm);
128
+ if (flags & 10 /* needsScopedEncapsulation */) {
129
129
  // only required when we're NOT using native shadow dom (slot)
130
130
  // or this browser doesn't support native shadow dom
131
131
  // and this host element was NOT created with SSR
@@ -135,13 +135,10 @@ const attachStyles = (hostRef) => {
135
135
  // DOM WRITE!!
136
136
  elm['s-sc'] = scopeId;
137
137
  elm.classList.add(scopeId + '-h');
138
- if ( flags & 2 /* scopedCssEncapsulation */) {
139
- elm.classList.add(scopeId + '-s');
140
- }
141
138
  }
142
139
  endAttachStyles();
143
140
  };
144
- const getScopeId = (cmp, mode) => 'sc-' + ( cmp.$tagName$);
141
+ const getScopeId = (cmp, mode) => 'sc-' + (cmp.$tagName$);
145
142
  /**
146
143
  * Default style mode id
147
144
  */
@@ -198,7 +195,7 @@ const h = (nodeName, vnodeData, ...children) => {
198
195
  walk(children);
199
196
  if (vnodeData) {
200
197
  // normalize class / classname attributes
201
- if ( vnodeData.key) {
198
+ if (vnodeData.key) {
202
199
  key = vnodeData.key;
203
200
  }
204
201
  {
@@ -208,7 +205,7 @@ const h = (nodeName, vnodeData, ...children) => {
208
205
  typeof classData !== 'object'
209
206
  ? classData
210
207
  : Object.keys(classData)
211
- .filter(k => classData[k])
208
+ .filter((k) => classData[k])
212
209
  .join(' ');
213
210
  }
214
211
  }
@@ -252,20 +249,20 @@ const isHost = (node) => node && node.$tag$ === Host;
252
249
  const setAccessor = (elm, memberName, oldValue, newValue, isSvg, flags) => {
253
250
  if (oldValue !== newValue) {
254
251
  let isProp = isMemberInElement(elm, memberName);
255
- let ln = memberName.toLowerCase();
256
- if ( memberName === 'class') {
252
+ memberName.toLowerCase();
253
+ if (memberName === 'class') {
257
254
  const classList = elm.classList;
258
255
  const oldClasses = parseClassList(oldValue);
259
256
  const newClasses = parseClassList(newValue);
260
- classList.remove(...oldClasses.filter(c => c && !newClasses.includes(c)));
261
- classList.add(...newClasses.filter(c => c && !oldClasses.includes(c)));
257
+ classList.remove(...oldClasses.filter((c) => c && !newClasses.includes(c)));
258
+ classList.add(...newClasses.filter((c) => c && !oldClasses.includes(c)));
262
259
  }
263
- else if ( memberName === 'style') {
260
+ else if (memberName === 'style') {
264
261
  // update style attribute, css properties and values
265
262
  {
266
263
  for (const prop in oldValue) {
267
264
  if (!newValue || newValue[prop] == null) {
268
- if ( prop.includes('-')) {
265
+ if (prop.includes('-')) {
269
266
  elm.style.removeProperty(prop);
270
267
  }
271
268
  else {
@@ -276,7 +273,7 @@ const setAccessor = (elm, memberName, oldValue, newValue, isSvg, flags) => {
276
273
  }
277
274
  for (const prop in newValue) {
278
275
  if (!oldValue || newValue[prop] !== oldValue[prop]) {
279
- if ( prop.includes('-')) {
276
+ if (prop.includes('-')) {
280
277
  elm.style.setProperty(prop, newValue[prop]);
281
278
  }
282
279
  else {
@@ -285,7 +282,7 @@ const setAccessor = (elm, memberName, oldValue, newValue, isSvg, flags) => {
285
282
  }
286
283
  }
287
284
  }
288
- else if ( memberName === 'key')
285
+ else if (memberName === 'key')
289
286
  ;
290
287
  else {
291
288
  // Set property if it exists and it's not a SVG
@@ -297,7 +294,6 @@ const setAccessor = (elm, memberName, oldValue, newValue, isSvg, flags) => {
297
294
  // Workaround for Safari, moving the <input> caret when re-assigning the same valued
298
295
  if (memberName === 'list') {
299
296
  isProp = false;
300
- // tslint:disable-next-line: triple-equals
301
297
  }
302
298
  else if (oldValue == null || elm[memberName] != n) {
303
299
  elm[memberName] = n;
@@ -331,7 +327,9 @@ const updateElement = (oldVnode, newVnode, isSvgMode, memberName) => {
331
327
  // if the element passed in is a shadow root, which is a document fragment
332
328
  // then we want to be adding attrs/props to the shadow root's "host" element
333
329
  // if it's not a shadow root, then we add attrs/props to the same element
334
- const elm = newVnode.$elm$.nodeType === 11 /* DocumentFragment */ && newVnode.$elm$.host ? newVnode.$elm$.host : newVnode.$elm$;
330
+ const elm = newVnode.$elm$.nodeType === 11 /* DocumentFragment */ && newVnode.$elm$.host
331
+ ? newVnode.$elm$.host
332
+ : newVnode.$elm$;
335
333
  const oldVnodeAttrs = (oldVnode && oldVnode.$attrs$) || EMPTY_OBJ;
336
334
  const newVnodeAttrs = newVnode.$attrs$ || EMPTY_OBJ;
337
335
  {
@@ -355,12 +353,12 @@ const createElm = (oldParentVNode, newParentVNode, childIndex, parentElm) => {
355
353
  let childNode;
356
354
  {
357
355
  // create element
358
- elm = newVNode.$elm$ = ( doc.createElement( newVNode.$tag$));
356
+ elm = newVNode.$elm$ = (doc.createElement(newVNode.$tag$));
359
357
  // add css classes, attrs, props, listeners, etc.
360
358
  {
361
359
  updateElement(null, newVNode, isSvgMode);
362
360
  }
363
- if ( isDef(scopeId) && elm['s-si'] !== scopeId) {
361
+ if (isDef(scopeId) && elm['s-si'] !== scopeId) {
364
362
  // if there is a scopeId and this is the initial render
365
363
  // then let's add the scopeId as a css class
366
364
  elm.classList.add((elm['s-si'] = scopeId));
@@ -380,14 +378,17 @@ const createElm = (oldParentVNode, newParentVNode, childIndex, parentElm) => {
380
378
  return elm;
381
379
  };
382
380
  const addVnodes = (parentElm, before, parentVNode, vnodes, startIdx, endIdx) => {
383
- let containerElm = ( parentElm);
381
+ let containerElm = (parentElm);
384
382
  let childNode;
383
+ if (containerElm.shadowRoot && containerElm.tagName === hostTagName) {
384
+ containerElm = containerElm.shadowRoot;
385
+ }
385
386
  for (; startIdx <= endIdx; ++startIdx) {
386
387
  if (vnodes[startIdx]) {
387
388
  childNode = createElm(null, parentVNode, startIdx);
388
389
  if (childNode) {
389
390
  vnodes[startIdx].$elm$ = childNode;
390
- containerElm.insertBefore(childNode, before);
391
+ containerElm.insertBefore(childNode, before);
391
392
  }
392
393
  }
393
394
  }
@@ -461,7 +462,7 @@ const updateChildren = (parentElm, oldCh, newVNode, newCh) => {
461
462
  }
462
463
  }
463
464
  }
464
- if ( idxInOld >= 0) {
465
+ if (idxInOld >= 0) {
465
466
  elmToMove = oldCh[idxInOld];
466
467
  if (elmToMove.$tag$ !== newStartVnode.$tag$) {
467
468
  node = createElm(oldCh && oldCh[newStartIdx], newVNode, idxInOld);
@@ -488,7 +489,7 @@ const updateChildren = (parentElm, oldCh, newVNode, newCh) => {
488
489
  if (oldStartIdx > oldEndIdx) {
489
490
  addVnodes(parentElm, newCh[newEndIdx + 1] == null ? null : newCh[newEndIdx + 1].$elm$, newVNode, newCh, newStartIdx, newEndIdx);
490
491
  }
491
- else if ( newStartIdx > newEndIdx) {
492
+ else if (newStartIdx > newEndIdx) {
492
493
  removeVnodes(oldCh, oldStartIdx, oldEndIdx);
493
494
  }
494
495
  };
@@ -516,7 +517,7 @@ const patch = (oldVNode, newVNode) => {
516
517
  updateElement(oldVNode, newVNode, isSvgMode);
517
518
  }
518
519
  }
519
- if ( oldChildren !== null && newChildren !== null) {
520
+ if (oldChildren !== null && newChildren !== null) {
520
521
  // looks like there's child vnodes for both the old and new vnodes
521
522
  updateChildren(elm, oldChildren, newVNode, newChildren);
522
523
  }
@@ -524,7 +525,7 @@ const patch = (oldVNode, newVNode) => {
524
525
  // add the new vnode children
525
526
  addVnodes(elm, null, newVNode, newChildren, 0, newChildren.length - 1);
526
527
  }
527
- else if ( oldChildren !== null) {
528
+ else if (oldChildren !== null) {
528
529
  // no new child vnodes, but there are old child vnodes to remove
529
530
  removeVnodes(oldChildren, 0, oldChildren.length - 1);
530
531
  }
@@ -534,31 +535,39 @@ const renderVdom = (hostRef, renderFnResults) => {
534
535
  const hostElm = hostRef.$hostElement$;
535
536
  const oldVNode = hostRef.$vnode$ || newVNode(null, null);
536
537
  const rootVnode = isHost(renderFnResults) ? renderFnResults : h(null, null, renderFnResults);
538
+ hostTagName = hostElm.tagName;
537
539
  rootVnode.$tag$ = null;
538
540
  rootVnode.$flags$ |= 4 /* isHost */;
539
541
  hostRef.$vnode$ = rootVnode;
540
- rootVnode.$elm$ = oldVNode.$elm$ = ( hostElm);
542
+ rootVnode.$elm$ = oldVNode.$elm$ = (hostElm.shadowRoot || hostElm );
541
543
  {
542
544
  scopeId = hostElm['s-sc'];
543
545
  }
544
546
  // synchronous patch
545
547
  patch(oldVNode, rootVnode);
546
548
  };
549
+ /**
550
+ * Helper function to create & dispatch a custom Event on a provided target
551
+ * @param elm the target of the Event
552
+ * @param name the name to give the custom Event
553
+ * @param opts options for configuring a custom Event
554
+ * @returns the custom Event
555
+ */
547
556
  const emitEvent = (elm, name, opts) => {
548
557
  const ev = plt.ce(name, opts);
549
558
  elm.dispatchEvent(ev);
550
559
  return ev;
551
560
  };
552
561
  const attachToAncestor = (hostRef, ancestorComponent) => {
553
- if ( ancestorComponent && !hostRef.$onRenderResolve$ && ancestorComponent['s-p']) {
554
- ancestorComponent['s-p'].push(new Promise(r => (hostRef.$onRenderResolve$ = r)));
562
+ if (ancestorComponent && !hostRef.$onRenderResolve$ && ancestorComponent['s-p']) {
563
+ ancestorComponent['s-p'].push(new Promise((r) => (hostRef.$onRenderResolve$ = r)));
555
564
  }
556
565
  };
557
566
  const scheduleUpdate = (hostRef, isInitialLoad) => {
558
567
  {
559
568
  hostRef.$flags$ |= 16 /* isQueuedForUpdate */;
560
569
  }
561
- if ( hostRef.$flags$ & 4 /* isWaitingForChildren */) {
570
+ if (hostRef.$flags$ & 4 /* isWaitingForChildren */) {
562
571
  hostRef.$flags$ |= 512 /* needsRerender */;
563
572
  return;
564
573
  }
@@ -567,11 +576,11 @@ const scheduleUpdate = (hostRef, isInitialLoad) => {
567
576
  // has already fired off its lifecycle update then
568
577
  // fire off the initial update
569
578
  const dispatch = () => dispatchHooks(hostRef, isInitialLoad);
570
- return writeTask(dispatch) ;
579
+ return writeTask(dispatch) ;
571
580
  };
572
581
  const dispatchHooks = (hostRef, isInitialLoad) => {
573
582
  const endSchedule = createTime('scheduleUpdate', hostRef.$cmpMeta$.$tagName$);
574
- const instance = hostRef.$lazyInstance$ ;
583
+ const instance = hostRef.$lazyInstance$ ;
575
584
  let promise;
576
585
  if (isInitialLoad) {
577
586
  {
@@ -591,29 +600,22 @@ const updateComponent = async (hostRef, instance, isInitialLoad) => {
591
600
  const elm = hostRef.$hostElement$;
592
601
  const endUpdate = createTime('update', hostRef.$cmpMeta$.$tagName$);
593
602
  const rc = elm['s-rc'];
594
- if ( isInitialLoad) {
603
+ if (isInitialLoad) {
595
604
  // DOM WRITE!
596
605
  attachStyles(hostRef);
597
606
  }
598
607
  const endRender = createTime('render', hostRef.$cmpMeta$.$tagName$);
599
608
  {
600
- {
601
- // looks like we've got child nodes to render into this host element
602
- // or we need to update the css class/attrs on the host element
603
- // DOM WRITE!
604
- {
605
- renderVdom(hostRef, callRender(hostRef, instance));
606
- }
607
- }
609
+ callRender(hostRef, instance);
608
610
  }
609
- if ( plt.$cssShim$) {
611
+ if (plt.$cssShim$) {
610
612
  plt.$cssShim$.updateHost(elm);
611
613
  }
612
- if ( rc) {
614
+ if (rc) {
613
615
  // ok, so turns out there are some child host elements
614
616
  // waiting on this parent element to load
615
617
  // let's fire off all update callbacks waiting
616
- rc.map(cb => cb());
618
+ rc.map((cb) => cb());
617
619
  elm['s-rc'] = undefined;
618
620
  }
619
621
  endRender();
@@ -631,20 +633,30 @@ const updateComponent = async (hostRef, instance, isInitialLoad) => {
631
633
  }
632
634
  }
633
635
  };
634
- const callRender = (hostRef, instance) => {
636
+ const callRender = (hostRef, instance, elm) => {
635
637
  try {
636
- instance = instance.render() ;
638
+ instance = instance.render() ;
637
639
  {
638
640
  hostRef.$flags$ &= ~16 /* isQueuedForUpdate */;
639
641
  }
640
642
  {
641
643
  hostRef.$flags$ |= 2 /* hasRendered */;
642
644
  }
645
+ {
646
+ {
647
+ // looks like we've got child nodes to render into this host element
648
+ // or we need to update the css class/attrs on the host element
649
+ // DOM WRITE!
650
+ {
651
+ renderVdom(hostRef, instance);
652
+ }
653
+ }
654
+ }
643
655
  }
644
656
  catch (e) {
645
- consoleError(e);
657
+ consoleError(e, hostRef.$hostElement$);
646
658
  }
647
- return instance;
659
+ return null;
648
660
  };
649
661
  const postUpdateComponent = (hostRef) => {
650
662
  const tagName = hostRef.$cmpMeta$.$tagName$;
@@ -706,20 +718,21 @@ const safeCall = (instance, method, arg) => {
706
718
  const then = (promise, thenFn) => {
707
719
  return promise && promise.then ? promise.then(thenFn) : thenFn();
708
720
  };
709
- const addHydratedFlag = (elm) => ( elm.classList.add('hydrated') );
721
+ const addHydratedFlag = (elm) => elm.classList.add('hydrated')
722
+ ;
710
723
  const parsePropertyValue = (propValue, propType) => {
711
724
  // ensure this value is of the correct prop type
712
725
  if (propValue != null && !isComplexType(propValue)) {
713
- if ( propType & 4 /* Boolean */) {
726
+ if (propType & 4 /* Boolean */) {
714
727
  // per the HTML spec, any string value means it is a boolean true value
715
728
  // but we'll cheat here and say that the string "false" is the boolean false
716
729
  return propValue === 'false' ? false : propValue === '' || !!propValue;
717
730
  }
718
- if ( propType & 2 /* Number */) {
731
+ if (propType & 2 /* Number */) {
719
732
  // force it to be a number
720
733
  return parseFloat(propValue);
721
734
  }
722
- if ( propType & 1 /* String */) {
735
+ if (propType & 1 /* String */) {
723
736
  // could have been passed as a number or boolean
724
737
  // but we still want it as a string
725
738
  return String(propValue);
@@ -737,14 +750,14 @@ const setValue = (ref, propName, newVal, cmpMeta) => {
737
750
  const hostRef = getHostRef(ref);
738
751
  const oldVal = hostRef.$instanceValues$.get(propName);
739
752
  const flags = hostRef.$flags$;
740
- const instance = hostRef.$lazyInstance$ ;
753
+ const instance = hostRef.$lazyInstance$ ;
741
754
  newVal = parsePropertyValue(newVal, cmpMeta.$members$[propName][0]);
742
- if (( !(flags & 8 /* isConstructingInstance */) || oldVal === undefined) && newVal !== oldVal) {
755
+ if ((!(flags & 8 /* isConstructingInstance */) || oldVal === undefined) && newVal !== oldVal) {
743
756
  // gadzooks! the property's value has changed!!
744
757
  // set our new value!
745
758
  hostRef.$instanceValues$.set(propName, newVal);
746
- if ( instance) {
747
- if ( (flags & (2 /* hasRendered */ | 16 /* isQueuedForUpdate */)) === 2 /* hasRendered */) {
759
+ if (instance) {
760
+ if ((flags & (2 /* hasRendered */ | 16 /* isQueuedForUpdate */)) === 2 /* hasRendered */) {
748
761
  // looks like this value actually changed, so we've got work to do!
749
762
  // but only if we've already rendered, otherwise just chill out
750
763
  // queue that we need to do an update, but don't worry about queuing
@@ -755,12 +768,13 @@ const setValue = (ref, propName, newVal, cmpMeta) => {
755
768
  }
756
769
  };
757
770
  const proxyComponent = (Cstr, cmpMeta, flags) => {
758
- if ( cmpMeta.$members$) {
771
+ if (cmpMeta.$members$) {
759
772
  // It's better to have a const than two Object.entries()
760
773
  const members = Object.entries(cmpMeta.$members$);
761
774
  const prototype = Cstr.prototype;
762
775
  members.map(([memberName, [memberFlags]]) => {
763
- if ( (memberFlags & 31 /* Prop */ || (( flags & 2 /* proxyState */) && memberFlags & 32 /* State */))) {
776
+ if ((memberFlags & 31 /* Prop */ ||
777
+ ((flags & 2 /* proxyState */) && memberFlags & 32 /* State */))) {
764
778
  // proxyComponent - prop
765
779
  Object.defineProperty(prototype, memberName, {
766
780
  get() {
@@ -776,11 +790,56 @@ const proxyComponent = (Cstr, cmpMeta, flags) => {
776
790
  });
777
791
  }
778
792
  });
779
- if ( ( flags & 1 /* isElementConstructor */)) {
793
+ if ((flags & 1 /* isElementConstructor */)) {
780
794
  const attrNameToPropName = new Map();
781
795
  prototype.attributeChangedCallback = function (attrName, _oldValue, newValue) {
782
796
  plt.jmp(() => {
783
797
  const propName = attrNameToPropName.get(attrName);
798
+ // In a web component lifecycle the attributeChangedCallback runs prior to connectedCallback
799
+ // in the case where an attribute was set inline.
800
+ // ```html
801
+ // <my-component some-attribute="some-value"></my-component>
802
+ // ```
803
+ //
804
+ // There is an edge case where a developer sets the attribute inline on a custom element and then
805
+ // programmatically changes it before it has been upgraded as shown below:
806
+ //
807
+ // ```html
808
+ // <!-- this component has _not_ been upgraded yet -->
809
+ // <my-component id="test" some-attribute="some-value"></my-component>
810
+ // <script>
811
+ // // grab non-upgraded component
812
+ // el = document.querySelector("#test");
813
+ // el.someAttribute = "another-value";
814
+ // // upgrade component
815
+ // customElements.define('my-component', MyComponent);
816
+ // </script>
817
+ // ```
818
+ // In this case if we do not unshadow here and use the value of the shadowing property, attributeChangedCallback
819
+ // will be called with `newValue = "some-value"` and will set the shadowed property (this.someAttribute = "another-value")
820
+ // to the value that was set inline i.e. "some-value" from above example. When
821
+ // the connectedCallback attempts to unshadow it will use "some-value" as the initial value rather than "another-value"
822
+ //
823
+ // The case where the attribute was NOT set inline but was not set programmatically shall be handled/unshadowed
824
+ // by connectedCallback as this attributeChangedCallback will not fire.
825
+ //
826
+ // https://developers.google.com/web/fundamentals/web-components/best-practices#lazy-properties
827
+ //
828
+ // TODO(STENCIL-16) we should think about whether or not we actually want to be reflecting the attributes to
829
+ // properties here given that this goes against best practices outlined here
830
+ // https://developers.google.com/web/fundamentals/web-components/best-practices#avoid-reentrancy
831
+ if (this.hasOwnProperty(propName)) {
832
+ newValue = this[propName];
833
+ delete this[propName];
834
+ }
835
+ else if (prototype.hasOwnProperty(propName) &&
836
+ typeof this[propName] === 'number' &&
837
+ this[propName] == newValue) {
838
+ // if the propName exists on the prototype of `Cstr`, this update may be a result of Stencil using native
839
+ // APIs to reflect props as attributes. Calls to `setAttribute(someElement, propName)` will result in
840
+ // `propName` to be converted to a `DOMString`, which may not be what we want for other primitive props.
841
+ return;
842
+ }
784
843
  this[propName] = newValue === null && typeof this[propName] === 'boolean' ? false : newValue;
785
844
  });
786
845
  };
@@ -799,7 +858,7 @@ const proxyComponent = (Cstr, cmpMeta, flags) => {
799
858
  };
800
859
  const initializeComponent = async (elm, hostRef, cmpMeta, hmrVersionId, Cstr) => {
801
860
  // initializeComponent
802
- if ( (hostRef.$flags$ & 32 /* hasInitializedComponent */) === 0) {
861
+ if ((hostRef.$flags$ & 32 /* hasInitializedComponent */) === 0) {
803
862
  {
804
863
  // we haven't initialized this element yet
805
864
  hostRef.$flags$ |= 32 /* hasInitializedComponent */;
@@ -813,7 +872,7 @@ const initializeComponent = async (elm, hostRef, cmpMeta, hmrVersionId, Cstr) =>
813
872
  Cstr = await Cstr;
814
873
  endLoad();
815
874
  }
816
- if ( !Cstr.isProxied) {
875
+ if (!Cstr.isProxied) {
817
876
  proxyComponent(Cstr, cmpMeta, 2 /* proxyState */);
818
877
  Cstr.isProxied = true;
819
878
  }
@@ -839,7 +898,7 @@ const initializeComponent = async (elm, hostRef, cmpMeta, hmrVersionId, Cstr) =>
839
898
  }
840
899
  endNewInstance();
841
900
  }
842
- if ( Cstr.style) {
901
+ if (Cstr.style) {
843
902
  // this component has styles but we haven't registered them yet
844
903
  let style = Cstr.style;
845
904
  const scopeId = getScopeId(cmpMeta);
@@ -853,8 +912,8 @@ const initializeComponent = async (elm, hostRef, cmpMeta, hmrVersionId, Cstr) =>
853
912
  // we've successfully created a lazy instance
854
913
  const ancestorComponent = hostRef.$ancestorComponent$;
855
914
  const schedule = () => scheduleUpdate(hostRef, true);
856
- if ( ancestorComponent && ancestorComponent['s-rc']) {
857
- // this is the intial load and this component it has an ancestor component
915
+ if (ancestorComponent && ancestorComponent['s-rc']) {
916
+ // this is the initial load and this component it has an ancestor component
858
917
  // but the ancestor component has NOT fired its will update lifecycle yet
859
918
  // so let's just cool our jets and wait for the ancestor to continue first
860
919
  // this will get fired off when the ancestor component
@@ -881,8 +940,7 @@ const connectedCallback = (elm) => {
881
940
  while ((ancestorComponent = ancestorComponent.parentNode || ancestorComponent.host)) {
882
941
  // climb up the ancestors looking for the first
883
942
  // component that hasn't finished its lifecycle update yet
884
- if (
885
- ancestorComponent['s-p']) {
943
+ if (ancestorComponent['s-p']) {
886
944
  // we found this components first ancestor component
887
945
  // keep a reference to this component's ancestor component
888
946
  attachToAncestor(hostRef, (hostRef.$ancestorComponent$ = ancestorComponent));
@@ -892,7 +950,7 @@ const connectedCallback = (elm) => {
892
950
  }
893
951
  // Lazy properties
894
952
  // https://developers.google.com/web/fundamentals/web-components/best-practices#lazy-properties
895
- if ( cmpMeta.$members$) {
953
+ if (cmpMeta.$members$) {
896
954
  Object.entries(cmpMeta.$members$).map(([memberName, [memberFlags]]) => {
897
955
  if (memberFlags & 31 /* Prop */ && elm.hasOwnProperty(memberName)) {
898
956
  const value = elm[memberName];
@@ -910,9 +968,9 @@ const connectedCallback = (elm) => {
910
968
  };
911
969
  const disconnectedCallback = (elm) => {
912
970
  if ((plt.$flags$ & 1 /* isTmpDisconnected */) === 0) {
913
- const hostRef = getHostRef(elm);
971
+ getHostRef(elm);
914
972
  // clear CSS var-shim tracking
915
- if ( plt.$cssShim$) {
973
+ if (plt.$cssShim$) {
916
974
  plt.$cssShim$.removeHost(elm);
917
975
  }
918
976
  }
@@ -930,51 +988,64 @@ const bootstrapLazy = (lazyBundles, options = {}) => {
930
988
  let isBootstrapping = true;
931
989
  Object.assign(plt, options);
932
990
  plt.$resourcesUrl$ = new URL(options.resourcesUrl || './', doc.baseURI).href;
933
- lazyBundles.map(lazyBundle => lazyBundle[1].map(compactMeta => {
934
- const cmpMeta = {
935
- $flags$: compactMeta[0],
936
- $tagName$: compactMeta[1],
937
- $members$: compactMeta[2],
938
- $listeners$: compactMeta[3],
939
- };
940
- {
941
- cmpMeta.$members$ = compactMeta[2];
942
- }
943
- const tagName = cmpMeta.$tagName$;
944
- const HostElement = class extends HTMLElement {
945
- // StencilLazyHost
946
- constructor(self) {
947
- // @ts-ignore
948
- super(self);
949
- self = this;
950
- registerHost(self, cmpMeta);
991
+ lazyBundles.map((lazyBundle) => {
992
+ lazyBundle[1].map((compactMeta) => {
993
+ const cmpMeta = {
994
+ $flags$: compactMeta[0],
995
+ $tagName$: compactMeta[1],
996
+ $members$: compactMeta[2],
997
+ $listeners$: compactMeta[3],
998
+ };
999
+ {
1000
+ cmpMeta.$members$ = compactMeta[2];
951
1001
  }
952
- connectedCallback() {
953
- if (appLoadFallback) {
954
- clearTimeout(appLoadFallback);
955
- appLoadFallback = null;
1002
+ const tagName = cmpMeta.$tagName$;
1003
+ const HostElement = class extends HTMLElement {
1004
+ // StencilLazyHost
1005
+ constructor(self) {
1006
+ // @ts-ignore
1007
+ super(self);
1008
+ self = this;
1009
+ registerHost(self, cmpMeta);
1010
+ if (cmpMeta.$flags$ & 1 /* shadowDomEncapsulation */) {
1011
+ // this component is using shadow dom
1012
+ // and this browser supports shadow dom
1013
+ // add the read-only property "shadowRoot" to the host element
1014
+ // adding the shadow root build conditionals to minimize runtime
1015
+ {
1016
+ {
1017
+ self.attachShadow({ mode: 'open' });
1018
+ }
1019
+ }
1020
+ }
956
1021
  }
957
- if (isBootstrapping) {
958
- // connectedCallback will be processed once all components have been registered
959
- deferredConnectedCallbacks.push(this);
1022
+ connectedCallback() {
1023
+ if (appLoadFallback) {
1024
+ clearTimeout(appLoadFallback);
1025
+ appLoadFallback = null;
1026
+ }
1027
+ if (isBootstrapping) {
1028
+ // connectedCallback will be processed once all components have been registered
1029
+ deferredConnectedCallbacks.push(this);
1030
+ }
1031
+ else {
1032
+ plt.jmp(() => connectedCallback(this));
1033
+ }
960
1034
  }
961
- else {
962
- plt.jmp(() => connectedCallback(this));
1035
+ disconnectedCallback() {
1036
+ plt.jmp(() => disconnectedCallback(this));
963
1037
  }
1038
+ componentOnReady() {
1039
+ return getHostRef(this).$onReadyPromise$;
1040
+ }
1041
+ };
1042
+ cmpMeta.$lazyBundleId$ = lazyBundle[0];
1043
+ if (!exclude.includes(tagName) && !customElements.get(tagName)) {
1044
+ cmpTags.push(tagName);
1045
+ customElements.define(tagName, proxyComponent(HostElement, cmpMeta, 1 /* isElementConstructor */));
964
1046
  }
965
- disconnectedCallback() {
966
- plt.jmp(() => disconnectedCallback(this));
967
- }
968
- componentOnReady() {
969
- return getHostRef(this).$onReadyPromise$;
970
- }
971
- };
972
- cmpMeta.$lazyBundleId$ = lazyBundle[0];
973
- if (!exclude.includes(tagName) && !customElements.get(tagName)) {
974
- cmpTags.push(tagName);
975
- customElements.define(tagName, proxyComponent(HostElement, cmpMeta, 1 /* isElementConstructor */));
976
- }
977
- }));
1047
+ });
1048
+ });
978
1049
  {
979
1050
  visibilityStyle.innerHTML = cmpTags + HYDRATED_CSS;
980
1051
  visibilityStyle.setAttribute('data-styles', '');
@@ -983,7 +1054,7 @@ const bootstrapLazy = (lazyBundles, options = {}) => {
983
1054
  // Process deferred connectedCallbacks now all components have been registered
984
1055
  isBootstrapping = false;
985
1056
  if (deferredConnectedCallbacks.length) {
986
- deferredConnectedCallbacks.map(host => host.connectedCallback());
1057
+ deferredConnectedCallbacks.map((host) => host.connectedCallback());
987
1058
  }
988
1059
  else {
989
1060
  {
@@ -1004,20 +1075,20 @@ const registerHost = (elm, cmpMeta) => {
1004
1075
  $instanceValues$: new Map(),
1005
1076
  };
1006
1077
  {
1007
- hostRef.$onReadyPromise$ = new Promise(r => (hostRef.$onReadyResolve$ = r));
1078
+ hostRef.$onReadyPromise$ = new Promise((r) => (hostRef.$onReadyResolve$ = r));
1008
1079
  elm['s-p'] = [];
1009
1080
  elm['s-rc'] = [];
1010
1081
  }
1011
1082
  return hostRefs.set(elm, hostRef);
1012
1083
  };
1013
1084
  const isMemberInElement = (elm, memberName) => memberName in elm;
1014
- const consoleError = (e) => console.error(e);
1085
+ const consoleError = (e, el) => (0, console.error)(e, el);
1015
1086
  const cmpModules = /*@__PURE__*/ new Map();
1016
1087
  const loadModule = (cmpMeta, hostRef, hmrVersionId) => {
1017
1088
  // loadModuleImport
1018
1089
  const exportName = cmpMeta.$tagName$.replace(/-/g, '_');
1019
1090
  const bundleId = cmpMeta.$lazyBundleId$;
1020
- const module = cmpModules.get(bundleId) ;
1091
+ const module = cmpModules.get(bundleId) ;
1021
1092
  if (module) {
1022
1093
  return module[exportName];
1023
1094
  }
@@ -1025,7 +1096,7 @@ const loadModule = (cmpMeta, hostRef, hmrVersionId) => {
1025
1096
  /* webpackInclude: /\.entry\.js$/ */
1026
1097
  /* webpackExclude: /\.system\.entry\.js$/ */
1027
1098
  /* webpackMode: "lazy" */
1028
- `./${bundleId}.entry.js${ ''}`)); }).then(importedModule => {
1099
+ `./${bundleId}.entry.js${''}`)); }).then((importedModule) => {
1029
1100
  {
1030
1101
  cmpModules.set(bundleId, importedModule);
1031
1102
  }