favesalon-embed 0.0.4 → 1.0.0
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/LICENSE +21 -0
- package/dist/cjs/chat-button.cjs.entry.js +118 -0
- package/dist/cjs/colors-38421769.js +69 -0
- package/dist/cjs/favesalon-embed.cjs.js +24 -0
- package/dist/cjs/google-map_5.cjs.entry.js +310 -0
- package/{cjs/index-d5de0b9d.js → dist/cjs/index-47c2a5f6.js} +513 -199
- package/{cjs/index-48ac68d0.js → dist/cjs/index-7f190886.js} +1924 -0
- package/dist/cjs/loader.cjs.js +23 -0
- package/dist/cjs/relativeTime-3721080d.js +9 -0
- package/{cjs → dist/cjs}/salon-booking-modal.cjs.entry.js +7 -6
- package/{cjs → dist/cjs}/salon-booking.cjs.entry.js +8 -8
- package/dist/cjs/salon-gift-card-modal.cjs.entry.js +29 -0
- package/{cjs → dist/cjs}/salon-gift-card.cjs.entry.js +9 -8
- package/dist/cjs/salon-latest-reviews.cjs.entry.js +97 -0
- package/{cjs/salon-lookbook_2.cjs.entry.js → dist/cjs/salon-lookbook.cjs.entry.js} +28 -58
- package/{cjs → dist/cjs}/salon-ranking.cjs.entry.js +9 -8
- package/dist/cjs/salon-reviews.cjs.entry.js +193 -0
- package/dist/cjs/salon-services.cjs.entry.js +81 -0
- package/dist/cjs/salon-stylists.cjs.entry.js +118 -0
- package/dist/cjs/services-125c82d8.js +21492 -0
- package/dist/cjs/style-detail.cjs.entry.js +312 -0
- package/dist/cjs/user-avatar.cjs.entry.js +45 -0
- package/{collection → dist/collection}/collection-manifest.json +5 -5
- package/dist/collection/components/chat-button/index.css +122 -0
- package/dist/collection/components/chat-button/index.js +218 -0
- package/dist/collection/components/chat-conversation/index.js +103 -0
- package/dist/collection/components/google-map/assets/map--placeholder.jpeg +0 -0
- package/{collection → dist/collection}/components/google-map/index.css +0 -1
- package/dist/collection/components/google-map/index.js +90 -0
- package/{collection → dist/collection}/components/salon-booking/index.css +11 -20
- package/dist/collection/components/salon-booking/index.js +126 -0
- package/dist/collection/components/salon-booking/salon-booking-modal.js +92 -0
- package/dist/collection/components/salon-gift-card/index.css +30 -0
- package/dist/collection/components/salon-gift-card/index.js +126 -0
- package/dist/collection/components/salon-gift-card/salon-gift-card-modal.js +73 -0
- package/dist/collection/components/salon-info/index.js +77 -0
- package/dist/collection/components/salon-latest-reviews/index.js +163 -0
- package/dist/collection/components/salon-latest-styles/index.css +12 -0
- package/dist/collection/components/salon-latest-styles/index.js +183 -0
- package/{collection/components/salon-contact → dist/collection/components/salon-locations}/index.css +7 -4
- package/dist/collection/components/salon-locations/index.js +143 -0
- package/{collection → dist/collection}/components/salon-lookbook/index.css +3 -9
- package/dist/collection/components/salon-lookbook/index.js +368 -0
- package/dist/collection/components/salon-ranking/index.js +117 -0
- package/{collection → dist/collection}/components/salon-reviews/index.css +3 -0
- package/dist/collection/components/salon-reviews/index.js +249 -0
- package/dist/collection/components/salon-schedules/index.css +18 -0
- package/dist/collection/components/salon-schedules/index.js +167 -0
- package/dist/collection/components/salon-services/index.css +1 -0
- package/dist/collection/components/salon-services/index.js +146 -0
- package/dist/collection/components/salon-stylists/index.js +184 -0
- package/dist/collection/components/style-detail/index.css +76 -0
- package/dist/collection/components/style-detail/index.js +386 -0
- package/dist/collection/components/user-avatar/index.js +134 -0
- package/dist/collection/constants/colors.js +65 -0
- package/dist/collection/mocks/users.js +10 -0
- package/dist/collection/services/services.js +295 -0
- package/dist/collection/types/chat.js +23 -0
- package/dist/collection/types/common.js +11 -0
- package/{collection → dist/collection}/types/review.js +9 -5
- package/dist/collection/types/salon.js +58 -0
- package/dist/collection/types/style.js +128 -0
- package/{collection → dist/collection}/types/stylist.js +12 -9
- package/dist/collection/types/user.js +10 -0
- package/{custom-elements → dist/custom-elements}/index.d.ts +18 -18
- package/dist/custom-elements/index.js +28340 -0
- package/dist/esm/chat-button.entry.js +114 -0
- package/dist/esm/colors-ea36347a.js +67 -0
- package/dist/esm/favesalon-embed.js +19 -0
- package/dist/esm/google-map_5.entry.js +302 -0
- package/{esm/index-0f8eed73.js → dist/esm/index-3fae868e.js} +512 -200
- package/{esm/index-67d677ba.js → dist/esm/index-80523fec.js} +1924 -1
- package/dist/esm/index.js +1 -0
- package/dist/esm/loader.js +19 -0
- package/dist/esm/polyfills/css-shim.js +1 -0
- package/dist/esm/relativeTime-cd452e6d.js +7 -0
- package/{esm → dist/esm}/salon-booking-modal.entry.js +7 -6
- package/{esm → dist/esm}/salon-booking.entry.js +7 -7
- package/dist/esm/salon-gift-card-modal.entry.js +25 -0
- package/{esm → dist/esm}/salon-gift-card.entry.js +8 -7
- package/dist/esm/salon-latest-reviews.entry.js +93 -0
- package/{esm/salon-lookbook_2.entry.js → dist/esm/salon-lookbook.entry.js} +29 -58
- package/{esm → dist/esm}/salon-ranking.entry.js +9 -8
- package/dist/esm/salon-reviews.entry.js +189 -0
- package/dist/esm/salon-services.entry.js +77 -0
- package/dist/esm/salon-stylists.entry.js +114 -0
- package/dist/esm/services-40a3e622.js +21485 -0
- package/dist/esm/style-detail.entry.js +308 -0
- package/dist/esm/user-avatar.entry.js +41 -0
- package/dist/favesalon-embed/assets/map--placeholder.jpeg +0 -0
- package/{favesalon-embed → dist/favesalon-embed}/favesalon-embed.css +1 -1
- package/dist/favesalon-embed/favesalon-embed.esm.js +1 -0
- package/dist/favesalon-embed/p-019c5ccd.entry.js +1 -0
- package/dist/favesalon-embed/p-083a8821.entry.js +1 -0
- package/dist/favesalon-embed/p-0d0ed9ea.entry.js +1 -0
- package/dist/favesalon-embed/p-119db8de.entry.js +1 -0
- package/dist/favesalon-embed/p-1432c51b.entry.js +1 -0
- package/dist/favesalon-embed/p-22093506.entry.js +1 -0
- package/dist/favesalon-embed/p-32b314e9.js +2 -0
- package/dist/favesalon-embed/p-4a5eca9a.js +6 -0
- package/dist/favesalon-embed/p-58d2e9be.js +1 -0
- package/dist/favesalon-embed/p-71404b6a.entry.js +1 -0
- package/dist/favesalon-embed/p-857c3a61.entry.js +1 -0
- package/dist/favesalon-embed/p-99ec77f7.entry.js +1 -0
- package/dist/favesalon-embed/p-a33331cc.js +1 -0
- package/dist/favesalon-embed/p-b0c3673a.entry.js +1 -0
- package/dist/favesalon-embed/p-b287b1ea.entry.js +1 -0
- package/dist/favesalon-embed/p-b3af7842.entry.js +1 -0
- package/dist/favesalon-embed/p-b630ae68.js +1580 -0
- package/dist/favesalon-embed/p-ce2c1c9a.entry.js +1 -0
- package/dist/favesalon-embed/p-d9b7ad58.entry.js +1 -0
- package/dist/favesalon-embed/p-fc9a5551.js +6 -0
- package/dist/types/components/chat-button/index.d.ts +24 -0
- package/dist/types/components/google-map/index.d.ts +5 -0
- package/{types → dist/types}/components/salon-gift-card/salon-gift-card-modal.d.ts +1 -0
- package/{types → dist/types}/components/salon-info/index.d.ts +0 -1
- package/{types → dist/types}/components/salon-latest-reviews/index.d.ts +2 -0
- package/dist/types/components/salon-latest-styles/index.d.ts +12 -0
- package/{types → dist/types}/components/salon-locations/index.d.ts +2 -0
- package/{types → dist/types}/components/salon-lookbook/index.d.ts +3 -3
- package/dist/types/components/salon-reviews/index.d.ts +24 -0
- package/{types → dist/types}/components/salon-schedules/index.d.ts +2 -0
- package/{types → dist/types}/components/salon-services/index.d.ts +1 -0
- package/{types → dist/types}/components/salon-stylists/index.d.ts +6 -0
- package/dist/types/components/style-detail/index.d.ts +24 -0
- package/{types → dist/types}/components.d.ts +76 -59
- package/dist/types/constants/colors.d.ts +65 -0
- package/dist/types/mocks/users.d.ts +10 -0
- package/dist/types/services/services.d.ts +75 -0
- package/{types → dist/types}/stencil-public-runtime.d.ts +85 -11
- package/dist/types/types/chat.d.ts +17 -0
- package/dist/types/types/common.d.ts +11 -0
- package/{types → dist/types}/types/review.d.ts +4 -0
- package/{types → dist/types}/types/salon.d.ts +3 -1
- package/dist/types/types/style.d.ts +88 -0
- package/{types → dist/types}/types/stylist.d.ts +1 -1
- package/{types → dist/types}/types/user.d.ts +2 -2
- package/loader/cdn.js +3 -0
- package/loader/index.cjs.js +3 -0
- package/loader/index.d.ts +21 -0
- package/loader/index.es2017.js +3 -0
- package/loader/index.js +4 -0
- package/loader/package.json +11 -0
- package/package.json +19 -14
- package/readme.md +24 -7
- package/cjs/colors-7f354880.js +0 -95
- package/cjs/favesalon-embed.cjs.js +0 -20
- package/cjs/google-map.cjs.entry.js +0 -47
- package/cjs/index-95daad08.js +0 -1928
- package/cjs/loader.cjs.js +0 -22
- package/cjs/salon-contact_4.cjs.entry.js +0 -155
- package/cjs/salon-gift-card-modal.cjs.entry.js +0 -25
- package/cjs/salon-info.cjs.entry.js +0 -35
- package/cjs/salon-latest-reviews.cjs.entry.js +0 -58
- package/cjs/salon-lookbook-modal.cjs.entry.js +0 -141
- package/cjs/salon-reviews.cjs.entry.js +0 -205
- package/cjs/salon-services.cjs.entry.js +0 -47
- package/cjs/salon-stylists.cjs.entry.js +0 -54
- package/cjs/services-f1102d4a.js +0 -5762
- package/collection/components/google-map/index.js +0 -97
- package/collection/components/salon-booking/index.js +0 -121
- package/collection/components/salon-booking/salon-booking-modal.js +0 -88
- package/collection/components/salon-contact/index.js +0 -88
- package/collection/components/salon-gift-card/index.css +0 -25
- package/collection/components/salon-gift-card/index.js +0 -120
- package/collection/components/salon-gift-card/salon-gift-card-modal.js +0 -48
- package/collection/components/salon-info/index.css +0 -3
- package/collection/components/salon-info/index.js +0 -97
- package/collection/components/salon-latest-reviews/index.js +0 -108
- package/collection/components/salon-locations/index.js +0 -80
- package/collection/components/salon-lookbook/index.js +0 -376
- package/collection/components/salon-lookbook/lookbook-modal.css +0 -72
- package/collection/components/salon-lookbook/salon-lookbook-modal.js +0 -248
- package/collection/components/salon-ranking/index.js +0 -114
- package/collection/components/salon-reviews/index.js +0 -317
- package/collection/components/salon-schedules/index.css +0 -14
- package/collection/components/salon-schedules/index.js +0 -103
- package/collection/components/salon-services/index.js +0 -113
- package/collection/components/salon-styles/index.css +0 -23
- package/collection/components/salon-styles/index.js +0 -100
- package/collection/components/salon-stylists/index.js +0 -96
- package/collection/components/user-avatar/index.css +0 -0
- package/collection/components/user-avatar/index.js +0 -127
- package/collection/constants/colors.js +0 -91
- package/collection/services/services.js +0 -225
- package/collection/types/common.js +0 -2
- package/collection/types/salon.js +0 -52
- package/collection/types/style.js +0 -103
- package/collection/types/user.js +0 -10
- package/custom-elements/index.js +0 -12125
- package/esm/colors-1ec90c5f.js +0 -93
- package/esm/favesalon-embed.js +0 -18
- package/esm/google-map.entry.js +0 -43
- package/esm/index-09d43e3e.js +0 -1926
- package/esm/loader.js +0 -18
- package/esm/polyfills/css-shim.js +0 -1
- package/esm/salon-contact_4.entry.js +0 -148
- package/esm/salon-gift-card-modal.entry.js +0 -21
- package/esm/salon-info.entry.js +0 -31
- package/esm/salon-latest-reviews.entry.js +0 -54
- package/esm/salon-lookbook-modal.entry.js +0 -137
- package/esm/salon-reviews.entry.js +0 -201
- package/esm/salon-services.entry.js +0 -43
- package/esm/salon-stylists.entry.js +0 -50
- package/esm/services-74d84ca9.js +0 -5756
- package/favesalon-embed/favesalon-embed.esm.js +0 -1
- package/favesalon-embed/p-0188d4dc.entry.js +0 -1
- package/favesalon-embed/p-0318501e.js +0 -1
- package/favesalon-embed/p-078f242d.entry.js +0 -1
- package/favesalon-embed/p-13e23c61.entry.js +0 -1
- package/favesalon-embed/p-17df13ad.js +0 -1
- package/favesalon-embed/p-1a3179c8.entry.js +0 -1
- package/favesalon-embed/p-20aa75de.js +0 -6
- package/favesalon-embed/p-2901a6d6.entry.js +0 -1
- package/favesalon-embed/p-2b861430.entry.js +0 -1
- package/favesalon-embed/p-44d810a0.js +0 -1
- package/favesalon-embed/p-4a5eca9a.js +0 -6
- package/favesalon-embed/p-4c68700f.entry.js +0 -1
- package/favesalon-embed/p-4e2d7b29.js +0 -1
- package/favesalon-embed/p-6b845bf1.entry.js +0 -1
- package/favesalon-embed/p-7350f6b5.entry.js +0 -1
- package/favesalon-embed/p-897c2b1c.entry.js +0 -1
- package/favesalon-embed/p-8e60f56f.entry.js +0 -1
- package/favesalon-embed/p-a49afdc1.entry.js +0 -1
- package/favesalon-embed/p-c93867c4.entry.js +0 -1
- package/favesalon-embed/p-ea6a097f.entry.js +0 -1
- package/types/components/google-map/index.d.ts +0 -10
- package/types/components/salon-contact/index.d.ts +0 -9
- package/types/components/salon-lookbook/salon-lookbook-modal.d.ts +0 -13
- package/types/components/salon-reviews/index.d.ts +0 -24
- package/types/components/salon-styles/index.d.ts +0 -9
- package/types/constants/colors.d.ts +0 -88
- package/types/services/services.d.ts +0 -26
- package/types/types/common.d.ts +0 -2
- package/types/types/style.d.ts +0 -59
- /package/{cjs → dist/cjs}/_commonjsHelpers-5cfcba41.js +0 -0
- /package/{cjs → dist/cjs}/global-9073d10e.js +0 -0
- /package/{cjs → dist/cjs}/index.cjs.js +0 -0
- /package/{cjs → dist/cjs}/utils-c5a33b3c.js +0 -0
- /package/{esm/index.js → dist/collection/components/salon-info/index.css} +0 -0
- /package/{collection → dist/collection}/components/salon-latest-reviews/index.css +0 -0
- /package/{collection → dist/collection}/components/salon-ranking/index.css +0 -0
- /package/{collection → dist/collection}/components/salon-stylists/index.css +0 -0
- /package/{collection/components/salon-locations → dist/collection/components/user-avatar}/index.css +0 -0
- /package/{collection → dist/collection}/global/global.js +0 -0
- /package/{collection → dist/collection}/index.js +0 -0
- /package/{collection → dist/collection}/types/service.js +0 -0
- /package/{collection → dist/collection}/utils/utils.js +0 -0
- /package/{esm → dist/esm}/_commonjsHelpers-098d5b27.js +0 -0
- /package/{esm → dist/esm}/global-e1089ffd.js +0 -0
- /package/{esm → dist/esm}/polyfills/core-js.js +0 -0
- /package/{esm → dist/esm}/polyfills/dom.js +0 -0
- /package/{esm → dist/esm}/polyfills/es5-html-element.js +0 -0
- /package/{esm → dist/esm}/polyfills/index.js +0 -0
- /package/{esm → dist/esm}/polyfills/system.js +0 -0
- /package/{esm → dist/esm}/utils-e97485e0.js +0 -0
- /package/{favesalon-embed → dist/favesalon-embed}/index.esm.js +0 -0
- /package/{favesalon-embed → dist/favesalon-embed}/p-47e646f8.js +0 -0
- /package/{favesalon-embed → dist/favesalon-embed}/p-d6083940.js +0 -0
- /package/{index.cjs.js → dist/index.cjs.js} +0 -0
- /package/{index.js → dist/index.js} +0 -0
- /package/{collection/components/salon-services/index.css → dist/types/components/chat-conversation/index.d.ts} +0 -0
- /package/{types → dist/types}/components/salon-booking/index.d.ts +0 -0
- /package/{types → dist/types}/components/salon-booking/salon-booking-modal.d.ts +0 -0
- /package/{types → dist/types}/components/salon-gift-card/index.d.ts +0 -0
- /package/{types → dist/types}/components/salon-ranking/index.d.ts +0 -0
- /package/{types → dist/types}/components/user-avatar/index.d.ts +0 -0
- /package/{types → dist/types}/index.d.ts +0 -0
- /package/{types → dist/types}/types/service.d.ts +0 -0
- /package/{types → dist/types}/utils/utils.d.ts +0 -0
|
@@ -1,30 +1,19 @@
|
|
|
1
1
|
const NAMESPACE = 'favesalon-embed';
|
|
2
2
|
|
|
3
|
+
/**
|
|
4
|
+
* Virtual DOM patching algorithm based on Snabbdom by
|
|
5
|
+
* Simon Friis Vindum (@paldepind)
|
|
6
|
+
* Licensed under the MIT License
|
|
7
|
+
* https://github.com/snabbdom/snabbdom/blob/master/LICENSE
|
|
8
|
+
*
|
|
9
|
+
* Modified for Stencil's renderer and slot projection
|
|
10
|
+
*/
|
|
3
11
|
let isSvgMode = false;
|
|
4
12
|
let queuePending = false;
|
|
5
|
-
const
|
|
6
|
-
const
|
|
7
|
-
|
|
8
|
-
$flags$: 0,
|
|
9
|
-
$resourcesUrl$: '',
|
|
10
|
-
jmp: (h) => h(),
|
|
11
|
-
raf: (h) => requestAnimationFrame(h),
|
|
12
|
-
ael: (el, eventName, listener, opts) => el.addEventListener(eventName, listener, opts),
|
|
13
|
-
rel: (el, eventName, listener, opts) => el.removeEventListener(eventName, listener, opts),
|
|
14
|
-
ce: (eventName, opts) => new CustomEvent(eventName, opts),
|
|
13
|
+
const getAssetPath = (path) => {
|
|
14
|
+
const assetUrl = new URL(path, plt.$resourcesUrl$);
|
|
15
|
+
return assetUrl.origin !== win.location.origin ? assetUrl.href : assetUrl.pathname;
|
|
15
16
|
};
|
|
16
|
-
const promiseResolve = (v) => Promise.resolve(v);
|
|
17
|
-
const supportsConstructibleStylesheets = /*@__PURE__*/ (() => {
|
|
18
|
-
try {
|
|
19
|
-
new CSSStyleSheet();
|
|
20
|
-
return typeof new CSSStyleSheet().replace === 'function';
|
|
21
|
-
}
|
|
22
|
-
catch (e) { }
|
|
23
|
-
return false;
|
|
24
|
-
})()
|
|
25
|
-
;
|
|
26
|
-
const HYDRATED_CSS = '{visibility:hidden}.hydrated{visibility:inherit}';
|
|
27
|
-
const XLINK_NS = 'http://www.w3.org/1999/xlink';
|
|
28
17
|
const createTime = (fnName, tagName = '') => {
|
|
29
18
|
{
|
|
30
19
|
return () => {
|
|
@@ -39,59 +28,8 @@ const uniqueTime = (key, measureText) => {
|
|
|
39
28
|
};
|
|
40
29
|
}
|
|
41
30
|
};
|
|
42
|
-
const
|
|
43
|
-
const
|
|
44
|
-
let style = styles.get(scopeId);
|
|
45
|
-
if (supportsConstructibleStylesheets && allowCS) {
|
|
46
|
-
style = (style || new CSSStyleSheet());
|
|
47
|
-
style.replace(cssText);
|
|
48
|
-
}
|
|
49
|
-
else {
|
|
50
|
-
style = cssText;
|
|
51
|
-
}
|
|
52
|
-
styles.set(scopeId, style);
|
|
53
|
-
};
|
|
54
|
-
const addStyle = (styleContainerNode, cmpMeta, mode, hostElm) => {
|
|
55
|
-
let scopeId = getScopeId(cmpMeta);
|
|
56
|
-
let style = styles.get(scopeId);
|
|
57
|
-
// if an element is NOT connected then getRootNode() will return the wrong root node
|
|
58
|
-
// so the fallback is to always use the document for the root node in those cases
|
|
59
|
-
styleContainerNode = styleContainerNode.nodeType === 11 /* DocumentFragment */ ? styleContainerNode : doc;
|
|
60
|
-
if (style) {
|
|
61
|
-
if (typeof style === 'string') {
|
|
62
|
-
styleContainerNode = styleContainerNode.head || styleContainerNode;
|
|
63
|
-
let appliedStyles = rootAppliedStyles.get(styleContainerNode);
|
|
64
|
-
let styleElm;
|
|
65
|
-
if (!appliedStyles) {
|
|
66
|
-
rootAppliedStyles.set(styleContainerNode, (appliedStyles = new Set()));
|
|
67
|
-
}
|
|
68
|
-
if (!appliedStyles.has(scopeId)) {
|
|
69
|
-
{
|
|
70
|
-
{
|
|
71
|
-
styleElm = doc.createElement('style');
|
|
72
|
-
styleElm.innerHTML = style;
|
|
73
|
-
}
|
|
74
|
-
styleContainerNode.insertBefore(styleElm, styleContainerNode.querySelector('link'));
|
|
75
|
-
}
|
|
76
|
-
if (appliedStyles) {
|
|
77
|
-
appliedStyles.add(scopeId);
|
|
78
|
-
}
|
|
79
|
-
}
|
|
80
|
-
}
|
|
81
|
-
else if (!styleContainerNode.adoptedStyleSheets.includes(style)) {
|
|
82
|
-
styleContainerNode.adoptedStyleSheets = [...styleContainerNode.adoptedStyleSheets, style];
|
|
83
|
-
}
|
|
84
|
-
}
|
|
85
|
-
return scopeId;
|
|
86
|
-
};
|
|
87
|
-
const attachStyles = (hostRef) => {
|
|
88
|
-
const cmpMeta = hostRef.$cmpMeta$;
|
|
89
|
-
const elm = hostRef.$hostElement$;
|
|
90
|
-
const endAttachStyles = createTime('attachStyles', cmpMeta.$tagName$);
|
|
91
|
-
addStyle(elm.getRootNode(), cmpMeta);
|
|
92
|
-
endAttachStyles();
|
|
93
|
-
};
|
|
94
|
-
const getScopeId = (cmp, mode) => 'sc-' + (cmp.$tagName$);
|
|
31
|
+
const HYDRATED_CSS = '{visibility:hidden}.hydrated{visibility:inherit}';
|
|
32
|
+
const XLINK_NS = 'http://www.w3.org/1999/xlink';
|
|
95
33
|
/**
|
|
96
34
|
* Default style mode id
|
|
97
35
|
*/
|
|
@@ -110,6 +48,18 @@ const isComplexType = (o) => {
|
|
|
110
48
|
o = typeof o;
|
|
111
49
|
return o === 'object' || o === 'function';
|
|
112
50
|
};
|
|
51
|
+
/**
|
|
52
|
+
* Helper method for querying a `meta` tag that contains a nonce value
|
|
53
|
+
* out of a DOM's head.
|
|
54
|
+
*
|
|
55
|
+
* @param doc The DOM containing the `head` to query against
|
|
56
|
+
* @returns The content of the meta tag representing the nonce value, or `undefined` if no tag
|
|
57
|
+
* exists or the tag has no content.
|
|
58
|
+
*/
|
|
59
|
+
function queryNonceMetaTagContent(doc) {
|
|
60
|
+
var _a, _b, _c;
|
|
61
|
+
return (_c = (_b = (_a = doc.head) === null || _a === void 0 ? void 0 : _a.querySelector('meta[name="csp-nonce"]')) === null || _b === void 0 ? void 0 : _b.getAttribute('content')) !== null && _c !== void 0 ? _c : undefined;
|
|
62
|
+
}
|
|
113
63
|
/**
|
|
114
64
|
* Production h() function based on Preact by
|
|
115
65
|
* Jason Miller (@developit)
|
|
@@ -118,7 +68,6 @@ const isComplexType = (o) => {
|
|
|
118
68
|
*
|
|
119
69
|
* Modified for Stencil's compiler and vdom
|
|
120
70
|
*/
|
|
121
|
-
// const stack: any[] = [];
|
|
122
71
|
// export function h(nodeName: string | d.FunctionalComponent, vnodeData: d.PropsType, child?: d.ChildType): d.VNode;
|
|
123
72
|
// export function h(nodeName: string | d.FunctionalComponent, vnodeData: d.PropsType, ...children: d.ChildType[]): d.VNode;
|
|
124
73
|
const h = (nodeName, vnodeData, ...children) => {
|
|
@@ -126,7 +75,7 @@ const h = (nodeName, vnodeData, ...children) => {
|
|
|
126
75
|
let key = null;
|
|
127
76
|
let simple = false;
|
|
128
77
|
let lastSimple = false;
|
|
129
|
-
|
|
78
|
+
const vNodeChildren = [];
|
|
130
79
|
const walk = (c) => {
|
|
131
80
|
for (let i = 0; i < c.length; i++) {
|
|
132
81
|
child = c[i];
|
|
@@ -177,6 +126,14 @@ const h = (nodeName, vnodeData, ...children) => {
|
|
|
177
126
|
}
|
|
178
127
|
return vnode;
|
|
179
128
|
};
|
|
129
|
+
/**
|
|
130
|
+
* A utility function for creating a virtual DOM node from a tag and some
|
|
131
|
+
* possible text content.
|
|
132
|
+
*
|
|
133
|
+
* @param tag the tag for this element
|
|
134
|
+
* @param text possible text content for the node
|
|
135
|
+
* @returns a newly-minted virtual DOM node
|
|
136
|
+
*/
|
|
180
137
|
const newVNode = (tag, text) => {
|
|
181
138
|
const vnode = {
|
|
182
139
|
$flags$: 0,
|
|
@@ -194,7 +151,136 @@ const newVNode = (tag, text) => {
|
|
|
194
151
|
return vnode;
|
|
195
152
|
};
|
|
196
153
|
const Host = {};
|
|
154
|
+
/**
|
|
155
|
+
* Check whether a given node is a Host node or not
|
|
156
|
+
*
|
|
157
|
+
* @param node the virtual DOM node to check
|
|
158
|
+
* @returns whether it's a Host node or not
|
|
159
|
+
*/
|
|
197
160
|
const isHost = (node) => node && node.$tag$ === Host;
|
|
161
|
+
/**
|
|
162
|
+
* Parse a new property value for a given property type.
|
|
163
|
+
*
|
|
164
|
+
* While the prop value can reasonably be expected to be of `any` type as far as TypeScript's type checker is concerned,
|
|
165
|
+
* it is not safe to assume that the string returned by evaluating `typeof propValue` matches:
|
|
166
|
+
* 1. `any`, the type given to `propValue` in the function signature
|
|
167
|
+
* 2. the type stored from `propType`.
|
|
168
|
+
*
|
|
169
|
+
* This function provides the capability to parse/coerce a property's value to potentially any other JavaScript type.
|
|
170
|
+
*
|
|
171
|
+
* Property values represented in TSX preserve their type information. In the example below, the number 0 is passed to
|
|
172
|
+
* a component. This `propValue` will preserve its type information (`typeof propValue === 'number'`). Note that is
|
|
173
|
+
* based on the type of the value being passed in, not the type declared of the class member decorated with `@Prop`.
|
|
174
|
+
* ```tsx
|
|
175
|
+
* <my-cmp prop-val={0}></my-cmp>
|
|
176
|
+
* ```
|
|
177
|
+
*
|
|
178
|
+
* HTML prop values on the other hand, will always a string
|
|
179
|
+
*
|
|
180
|
+
* @param propValue the new value to coerce to some type
|
|
181
|
+
* @param propType the type of the prop, expressed as a binary number
|
|
182
|
+
* @returns the parsed/coerced value
|
|
183
|
+
*/
|
|
184
|
+
const parsePropertyValue = (propValue, propType) => {
|
|
185
|
+
// ensure this value is of the correct prop type
|
|
186
|
+
if (propValue != null && !isComplexType(propValue)) {
|
|
187
|
+
if (propType & 4 /* MEMBER_FLAGS.Boolean */) {
|
|
188
|
+
// per the HTML spec, any string value means it is a boolean true value
|
|
189
|
+
// but we'll cheat here and say that the string "false" is the boolean false
|
|
190
|
+
return propValue === 'false' ? false : propValue === '' || !!propValue;
|
|
191
|
+
}
|
|
192
|
+
if (propType & 2 /* MEMBER_FLAGS.Number */) {
|
|
193
|
+
// force it to be a number
|
|
194
|
+
return parseFloat(propValue);
|
|
195
|
+
}
|
|
196
|
+
if (propType & 1 /* MEMBER_FLAGS.String */) {
|
|
197
|
+
// could have been passed as a number or boolean
|
|
198
|
+
// but we still want it as a string
|
|
199
|
+
return String(propValue);
|
|
200
|
+
}
|
|
201
|
+
// redundant return here for better minification
|
|
202
|
+
return propValue;
|
|
203
|
+
}
|
|
204
|
+
// not sure exactly what type we want
|
|
205
|
+
// so no need to change to a different type
|
|
206
|
+
return propValue;
|
|
207
|
+
};
|
|
208
|
+
/**
|
|
209
|
+
* Helper function to create & dispatch a custom Event on a provided target
|
|
210
|
+
* @param elm the target of the Event
|
|
211
|
+
* @param name the name to give the custom Event
|
|
212
|
+
* @param opts options for configuring a custom Event
|
|
213
|
+
* @returns the custom Event
|
|
214
|
+
*/
|
|
215
|
+
const emitEvent = (elm, name, opts) => {
|
|
216
|
+
const ev = plt.ce(name, opts);
|
|
217
|
+
elm.dispatchEvent(ev);
|
|
218
|
+
return ev;
|
|
219
|
+
};
|
|
220
|
+
const rootAppliedStyles = /*@__PURE__*/ new WeakMap();
|
|
221
|
+
const registerStyle = (scopeId, cssText, allowCS) => {
|
|
222
|
+
let style = styles.get(scopeId);
|
|
223
|
+
if (supportsConstructableStylesheets && allowCS) {
|
|
224
|
+
style = (style || new CSSStyleSheet());
|
|
225
|
+
if (typeof style === 'string') {
|
|
226
|
+
style = cssText;
|
|
227
|
+
}
|
|
228
|
+
else {
|
|
229
|
+
style.replaceSync(cssText);
|
|
230
|
+
}
|
|
231
|
+
}
|
|
232
|
+
else {
|
|
233
|
+
style = cssText;
|
|
234
|
+
}
|
|
235
|
+
styles.set(scopeId, style);
|
|
236
|
+
};
|
|
237
|
+
const addStyle = (styleContainerNode, cmpMeta, mode, hostElm) => {
|
|
238
|
+
var _a;
|
|
239
|
+
let scopeId = getScopeId(cmpMeta);
|
|
240
|
+
const style = styles.get(scopeId);
|
|
241
|
+
// if an element is NOT connected then getRootNode() will return the wrong root node
|
|
242
|
+
// so the fallback is to always use the document for the root node in those cases
|
|
243
|
+
styleContainerNode = styleContainerNode.nodeType === 11 /* NODE_TYPE.DocumentFragment */ ? styleContainerNode : doc;
|
|
244
|
+
if (style) {
|
|
245
|
+
if (typeof style === 'string') {
|
|
246
|
+
styleContainerNode = styleContainerNode.head || styleContainerNode;
|
|
247
|
+
let appliedStyles = rootAppliedStyles.get(styleContainerNode);
|
|
248
|
+
let styleElm;
|
|
249
|
+
if (!appliedStyles) {
|
|
250
|
+
rootAppliedStyles.set(styleContainerNode, (appliedStyles = new Set()));
|
|
251
|
+
}
|
|
252
|
+
if (!appliedStyles.has(scopeId)) {
|
|
253
|
+
{
|
|
254
|
+
{
|
|
255
|
+
styleElm = doc.createElement('style');
|
|
256
|
+
styleElm.innerHTML = style;
|
|
257
|
+
}
|
|
258
|
+
// Apply CSP nonce to the style tag if it exists
|
|
259
|
+
const nonce = (_a = plt.$nonce$) !== null && _a !== void 0 ? _a : queryNonceMetaTagContent(doc);
|
|
260
|
+
if (nonce != null) {
|
|
261
|
+
styleElm.setAttribute('nonce', nonce);
|
|
262
|
+
}
|
|
263
|
+
styleContainerNode.insertBefore(styleElm, styleContainerNode.querySelector('link'));
|
|
264
|
+
}
|
|
265
|
+
if (appliedStyles) {
|
|
266
|
+
appliedStyles.add(scopeId);
|
|
267
|
+
}
|
|
268
|
+
}
|
|
269
|
+
}
|
|
270
|
+
else if (!styleContainerNode.adoptedStyleSheets.includes(style)) {
|
|
271
|
+
styleContainerNode.adoptedStyleSheets = [...styleContainerNode.adoptedStyleSheets, style];
|
|
272
|
+
}
|
|
273
|
+
}
|
|
274
|
+
return scopeId;
|
|
275
|
+
};
|
|
276
|
+
const attachStyles = (hostRef) => {
|
|
277
|
+
const cmpMeta = hostRef.$cmpMeta$;
|
|
278
|
+
const elm = hostRef.$hostElement$;
|
|
279
|
+
const endAttachStyles = createTime('attachStyles', cmpMeta.$tagName$);
|
|
280
|
+
addStyle(elm.getRootNode(), cmpMeta);
|
|
281
|
+
endAttachStyles();
|
|
282
|
+
};
|
|
283
|
+
const getScopeId = (cmp, mode) => 'sc-' + (cmp.$tagName$);
|
|
198
284
|
/**
|
|
199
285
|
* Production setAccessor() function based on Preact by
|
|
200
286
|
* Jason Miller (@developit)
|
|
@@ -292,11 +378,10 @@ const setAccessor = (elm, memberName, oldValue, newValue, isSvg, flags) => {
|
|
|
292
378
|
if ((isProp || (isComplex && newValue !== null)) && !isSvg) {
|
|
293
379
|
try {
|
|
294
380
|
if (!elm.tagName.includes('-')) {
|
|
295
|
-
|
|
381
|
+
const n = newValue == null ? '' : newValue;
|
|
296
382
|
// Workaround for Safari, moving the <input> caret when re-assigning the same valued
|
|
297
383
|
if (memberName === 'list') {
|
|
298
384
|
isProp = false;
|
|
299
|
-
// tslint:disable-next-line: triple-equals
|
|
300
385
|
}
|
|
301
386
|
else if (oldValue == null || elm[memberName] != n) {
|
|
302
387
|
elm[memberName] = n;
|
|
@@ -332,7 +417,7 @@ const setAccessor = (elm, memberName, oldValue, newValue, isSvg, flags) => {
|
|
|
332
417
|
}
|
|
333
418
|
}
|
|
334
419
|
}
|
|
335
|
-
else if ((!isProp || flags & 4 /* isHost */ || isSvg) && !isComplex) {
|
|
420
|
+
else if ((!isProp || flags & 4 /* VNODE_FLAGS.isHost */ || isSvg) && !isComplex) {
|
|
336
421
|
newValue = newValue === true ? '' : newValue;
|
|
337
422
|
if (xlink) {
|
|
338
423
|
elm.setAttributeNS(XLINK_NS, memberName, newValue);
|
|
@@ -350,7 +435,7 @@ const updateElement = (oldVnode, newVnode, isSvgMode, memberName) => {
|
|
|
350
435
|
// if the element passed in is a shadow root, which is a document fragment
|
|
351
436
|
// then we want to be adding attrs/props to the shadow root's "host" element
|
|
352
437
|
// if it's not a shadow root, then we add attrs/props to the same element
|
|
353
|
-
const elm = newVnode.$elm$.nodeType === 11 /* DocumentFragment */ && newVnode.$elm$.host
|
|
438
|
+
const elm = newVnode.$elm$.nodeType === 11 /* NODE_TYPE.DocumentFragment */ && newVnode.$elm$.host
|
|
354
439
|
? newVnode.$elm$.host
|
|
355
440
|
: newVnode.$elm$;
|
|
356
441
|
const oldVnodeAttrs = (oldVnode && oldVnode.$attrs$) || EMPTY_OBJ;
|
|
@@ -368,9 +453,19 @@ const updateElement = (oldVnode, newVnode, isSvgMode, memberName) => {
|
|
|
368
453
|
setAccessor(elm, memberName, oldVnodeAttrs[memberName], newVnodeAttrs[memberName], isSvgMode, newVnode.$flags$);
|
|
369
454
|
}
|
|
370
455
|
};
|
|
456
|
+
/**
|
|
457
|
+
* Create a DOM Node corresponding to one of the children of a given VNode.
|
|
458
|
+
*
|
|
459
|
+
* @param oldParentVNode the parent VNode from the previous render
|
|
460
|
+
* @param newParentVNode the parent VNode from the current render
|
|
461
|
+
* @param childIndex the index of the VNode, in the _new_ parent node's
|
|
462
|
+
* children, for which we will create a new DOM node
|
|
463
|
+
* @param parentElm the parent DOM node which our new node will be a child of
|
|
464
|
+
* @returns the newly created node
|
|
465
|
+
*/
|
|
371
466
|
const createElm = (oldParentVNode, newParentVNode, childIndex, parentElm) => {
|
|
372
467
|
// tslint:disable-next-line: prefer-const
|
|
373
|
-
|
|
468
|
+
const newVNode = newParentVNode.$children$[childIndex];
|
|
374
469
|
let i = 0;
|
|
375
470
|
let elm;
|
|
376
471
|
let childNode;
|
|
@@ -416,6 +511,21 @@ const createElm = (oldParentVNode, newParentVNode, childIndex, parentElm) => {
|
|
|
416
511
|
}
|
|
417
512
|
return elm;
|
|
418
513
|
};
|
|
514
|
+
/**
|
|
515
|
+
* Create DOM nodes corresponding to a list of {@link d.Vnode} objects and
|
|
516
|
+
* add them to the DOM in the appropriate place.
|
|
517
|
+
*
|
|
518
|
+
* @param parentElm the DOM node which should be used as a parent for the new
|
|
519
|
+
* DOM nodes
|
|
520
|
+
* @param before a child of the `parentElm` which the new children should be
|
|
521
|
+
* inserted before (optional)
|
|
522
|
+
* @param parentVNode the parent virtual DOM node
|
|
523
|
+
* @param vnodes the new child virtual DOM nodes to produce DOM nodes for
|
|
524
|
+
* @param startIdx the index in the child virtual DOM nodes at which to start
|
|
525
|
+
* creating DOM nodes (inclusive)
|
|
526
|
+
* @param endIdx the index in the child virtual DOM nodes at which to stop
|
|
527
|
+
* creating DOM nodes (inclusive)
|
|
528
|
+
*/
|
|
419
529
|
const addVnodes = (parentElm, before, parentVNode, vnodes, startIdx, endIdx) => {
|
|
420
530
|
let containerElm = (parentElm);
|
|
421
531
|
let childNode;
|
|
@@ -429,6 +539,19 @@ const addVnodes = (parentElm, before, parentVNode, vnodes, startIdx, endIdx) =>
|
|
|
429
539
|
}
|
|
430
540
|
}
|
|
431
541
|
};
|
|
542
|
+
/**
|
|
543
|
+
* Remove the DOM elements corresponding to a list of {@link d.VNode} objects.
|
|
544
|
+
* This can be used to, for instance, clean up after a list of children which
|
|
545
|
+
* should no longer be shown.
|
|
546
|
+
*
|
|
547
|
+
* This function also handles some of Stencil's slot relocation logic.
|
|
548
|
+
*
|
|
549
|
+
* @param vnodes a list of virtual DOM nodes to remove
|
|
550
|
+
* @param startIdx the index at which to start removing nodes (inclusive)
|
|
551
|
+
* @param endIdx the index at which to stop removing nodes (inclusive)
|
|
552
|
+
* @param vnode a VNode
|
|
553
|
+
* @param elm an element
|
|
554
|
+
*/
|
|
432
555
|
const removeVnodes = (vnodes, startIdx, endIdx, vnode, elm) => {
|
|
433
556
|
for (; startIdx <= endIdx; ++startIdx) {
|
|
434
557
|
if ((vnode = vnodes[startIdx])) {
|
|
@@ -439,6 +562,74 @@ const removeVnodes = (vnodes, startIdx, endIdx, vnode, elm) => {
|
|
|
439
562
|
}
|
|
440
563
|
}
|
|
441
564
|
};
|
|
565
|
+
/**
|
|
566
|
+
* Reconcile the children of a new VNode with the children of an old VNode by
|
|
567
|
+
* traversing the two collections of children, identifying nodes that are
|
|
568
|
+
* conserved or changed, calling out to `patch` to make any necessary
|
|
569
|
+
* updates to the DOM, and rearranging DOM nodes as needed.
|
|
570
|
+
*
|
|
571
|
+
* The algorithm for reconciling children works by analyzing two 'windows' onto
|
|
572
|
+
* the two arrays of children (`oldCh` and `newCh`). We keep track of the
|
|
573
|
+
* 'windows' by storing start and end indices and references to the
|
|
574
|
+
* corresponding array entries. Initially the two 'windows' are basically equal
|
|
575
|
+
* to the entire array, but we progressively narrow the windows until there are
|
|
576
|
+
* no children left to update by doing the following:
|
|
577
|
+
*
|
|
578
|
+
* 1. Skip any `null` entries at the beginning or end of the two arrays, so
|
|
579
|
+
* that if we have an initial array like the following we'll end up dealing
|
|
580
|
+
* only with a window bounded by the highlighted elements:
|
|
581
|
+
*
|
|
582
|
+
* [null, null, VNode1 , ... , VNode2, null, null]
|
|
583
|
+
* ^^^^^^ ^^^^^^
|
|
584
|
+
*
|
|
585
|
+
* 2. Check to see if the elements at the head and tail positions are equal
|
|
586
|
+
* across the windows. This will basically detect elements which haven't
|
|
587
|
+
* been added, removed, or changed position, i.e. if you had the following
|
|
588
|
+
* VNode elements (represented as HTML):
|
|
589
|
+
*
|
|
590
|
+
* oldVNode: `<div><p><span>HEY</span></p></div>`
|
|
591
|
+
* newVNode: `<div><p><span>THERE</span></p></div>`
|
|
592
|
+
*
|
|
593
|
+
* Then when comparing the children of the `<div>` tag we check the equality
|
|
594
|
+
* of the VNodes corresponding to the `<p>` tags and, since they are the
|
|
595
|
+
* same tag in the same position, we'd be able to avoid completely
|
|
596
|
+
* re-rendering the subtree under them with a new DOM element and would just
|
|
597
|
+
* call out to `patch` to handle reconciling their children and so on.
|
|
598
|
+
*
|
|
599
|
+
* 3. Check, for both windows, to see if the element at the beginning of the
|
|
600
|
+
* window corresponds to the element at the end of the other window. This is
|
|
601
|
+
* a heuristic which will let us identify _some_ situations in which
|
|
602
|
+
* elements have changed position, for instance it _should_ detect that the
|
|
603
|
+
* children nodes themselves have not changed but merely moved in the
|
|
604
|
+
* following example:
|
|
605
|
+
*
|
|
606
|
+
* oldVNode: `<div><element-one /><element-two /></div>`
|
|
607
|
+
* newVNode: `<div><element-two /><element-one /></div>`
|
|
608
|
+
*
|
|
609
|
+
* If we find cases like this then we also need to move the concrete DOM
|
|
610
|
+
* elements corresponding to the moved children to write the re-order to the
|
|
611
|
+
* DOM.
|
|
612
|
+
*
|
|
613
|
+
* 4. Finally, if VNodes have the `key` attribute set on them we check for any
|
|
614
|
+
* nodes in the old children which have the same key as the first element in
|
|
615
|
+
* our window on the new children. If we find such a node we handle calling
|
|
616
|
+
* out to `patch`, moving relevant DOM nodes, and so on, in accordance with
|
|
617
|
+
* what we find.
|
|
618
|
+
*
|
|
619
|
+
* Finally, once we've narrowed our 'windows' to the point that either of them
|
|
620
|
+
* collapse (i.e. they have length 0) we then handle any remaining VNode
|
|
621
|
+
* insertion or deletion that needs to happen to get a DOM state that correctly
|
|
622
|
+
* reflects the new child VNodes. If, for instance, after our window on the old
|
|
623
|
+
* children has collapsed we still have more nodes on the new children that
|
|
624
|
+
* we haven't dealt with yet then we need to add them, or if the new children
|
|
625
|
+
* collapse but we still have unhandled _old_ children then we need to make
|
|
626
|
+
* sure the corresponding DOM nodes are removed.
|
|
627
|
+
*
|
|
628
|
+
* @param parentElm the node into which the parent VNode is rendered
|
|
629
|
+
* @param oldCh the old children of the parent node
|
|
630
|
+
* @param newVNode the new VNode which will replace the parent
|
|
631
|
+
* @param newCh the new children of the parent node
|
|
632
|
+
*/
|
|
442
633
|
const updateChildren = (parentElm, oldCh, newVNode, newCh) => {
|
|
443
634
|
let oldStartIdx = 0;
|
|
444
635
|
let newStartIdx = 0;
|
|
@@ -454,7 +645,7 @@ const updateChildren = (parentElm, oldCh, newVNode, newCh) => {
|
|
|
454
645
|
let elmToMove;
|
|
455
646
|
while (oldStartIdx <= oldEndIdx && newStartIdx <= newEndIdx) {
|
|
456
647
|
if (oldStartVnode == null) {
|
|
457
|
-
//
|
|
648
|
+
// VNode might have been moved left
|
|
458
649
|
oldStartVnode = oldCh[++oldStartIdx];
|
|
459
650
|
}
|
|
460
651
|
else if (oldEndVnode == null) {
|
|
@@ -467,29 +658,65 @@ const updateChildren = (parentElm, oldCh, newVNode, newCh) => {
|
|
|
467
658
|
newEndVnode = newCh[--newEndIdx];
|
|
468
659
|
}
|
|
469
660
|
else if (isSameVnode(oldStartVnode, newStartVnode)) {
|
|
661
|
+
// if the start nodes are the same then we should patch the new VNode
|
|
662
|
+
// onto the old one, and increment our `newStartIdx` and `oldStartIdx`
|
|
663
|
+
// indices to reflect that. We don't need to move any DOM Nodes around
|
|
664
|
+
// since things are matched up in order.
|
|
470
665
|
patch(oldStartVnode, newStartVnode);
|
|
471
666
|
oldStartVnode = oldCh[++oldStartIdx];
|
|
472
667
|
newStartVnode = newCh[++newStartIdx];
|
|
473
668
|
}
|
|
474
669
|
else if (isSameVnode(oldEndVnode, newEndVnode)) {
|
|
670
|
+
// likewise, if the end nodes are the same we patch new onto old and
|
|
671
|
+
// decrement our end indices, and also likewise in this case we don't
|
|
672
|
+
// need to move any DOM Nodes.
|
|
475
673
|
patch(oldEndVnode, newEndVnode);
|
|
476
674
|
oldEndVnode = oldCh[--oldEndIdx];
|
|
477
675
|
newEndVnode = newCh[--newEndIdx];
|
|
478
676
|
}
|
|
479
677
|
else if (isSameVnode(oldStartVnode, newEndVnode)) {
|
|
480
678
|
patch(oldStartVnode, newEndVnode);
|
|
679
|
+
// We need to move the element for `oldStartVnode` into a position which
|
|
680
|
+
// will be appropriate for `newEndVnode`. For this we can use
|
|
681
|
+
// `.insertBefore` and `oldEndVnode.$elm$.nextSibling`. If there is a
|
|
682
|
+
// sibling for `oldEndVnode.$elm$` then we want to move the DOM node for
|
|
683
|
+
// `oldStartVnode` between `oldEndVnode` and it's sibling, like so:
|
|
684
|
+
//
|
|
685
|
+
// <old-start-node />
|
|
686
|
+
// <some-intervening-node />
|
|
687
|
+
// <old-end-node />
|
|
688
|
+
// <!-- -> <-- `oldStartVnode.$elm$` should be inserted here
|
|
689
|
+
// <next-sibling />
|
|
690
|
+
//
|
|
691
|
+
// If instead `oldEndVnode.$elm$` has no sibling then we just want to put
|
|
692
|
+
// the node for `oldStartVnode` at the end of the children of
|
|
693
|
+
// `parentElm`. Luckily, `Node.nextSibling` will return `null` if there
|
|
694
|
+
// aren't any siblings, and passing `null` to `Node.insertBefore` will
|
|
695
|
+
// append it to the children of the parent element.
|
|
481
696
|
parentElm.insertBefore(oldStartVnode.$elm$, oldEndVnode.$elm$.nextSibling);
|
|
482
697
|
oldStartVnode = oldCh[++oldStartIdx];
|
|
483
698
|
newEndVnode = newCh[--newEndIdx];
|
|
484
699
|
}
|
|
485
700
|
else if (isSameVnode(oldEndVnode, newStartVnode)) {
|
|
486
701
|
patch(oldEndVnode, newStartVnode);
|
|
702
|
+
// We've already checked above if `oldStartVnode` and `newStartVnode` are
|
|
703
|
+
// the same node, so since we're here we know that they are not. Thus we
|
|
704
|
+
// can move the element for `oldEndVnode` _before_ the element for
|
|
705
|
+
// `oldStartVnode`, leaving `oldStartVnode` to be reconciled in the
|
|
706
|
+
// future.
|
|
487
707
|
parentElm.insertBefore(oldEndVnode.$elm$, oldStartVnode.$elm$);
|
|
488
708
|
oldEndVnode = oldCh[--oldEndIdx];
|
|
489
709
|
newStartVnode = newCh[++newStartIdx];
|
|
490
710
|
}
|
|
491
711
|
else {
|
|
492
|
-
//
|
|
712
|
+
// Here we do some checks to match up old and new nodes based on the
|
|
713
|
+
// `$key$` attribute, which is set by putting a `key="my-key"` attribute
|
|
714
|
+
// in the JSX for a DOM element in the implementation of a Stencil
|
|
715
|
+
// component.
|
|
716
|
+
//
|
|
717
|
+
// First we check to see if there are any nodes in the array of old
|
|
718
|
+
// children which have the same key as the first node in the new
|
|
719
|
+
// children.
|
|
493
720
|
idxInOld = -1;
|
|
494
721
|
{
|
|
495
722
|
for (i = oldStartIdx; i <= oldEndIdx; ++i) {
|
|
@@ -500,23 +727,32 @@ const updateChildren = (parentElm, oldCh, newVNode, newCh) => {
|
|
|
500
727
|
}
|
|
501
728
|
}
|
|
502
729
|
if (idxInOld >= 0) {
|
|
730
|
+
// We found a node in the old children which matches up with the first
|
|
731
|
+
// node in the new children! So let's deal with that
|
|
503
732
|
elmToMove = oldCh[idxInOld];
|
|
504
733
|
if (elmToMove.$tag$ !== newStartVnode.$tag$) {
|
|
734
|
+
// the tag doesn't match so we'll need a new DOM element
|
|
505
735
|
node = createElm(oldCh && oldCh[newStartIdx], newVNode, idxInOld);
|
|
506
736
|
}
|
|
507
737
|
else {
|
|
508
738
|
patch(elmToMove, newStartVnode);
|
|
739
|
+
// invalidate the matching old node so that we won't try to update it
|
|
740
|
+
// again later on
|
|
509
741
|
oldCh[idxInOld] = undefined;
|
|
510
742
|
node = elmToMove.$elm$;
|
|
511
743
|
}
|
|
512
744
|
newStartVnode = newCh[++newStartIdx];
|
|
513
745
|
}
|
|
514
746
|
else {
|
|
515
|
-
//
|
|
747
|
+
// We either didn't find an element in the old children that matches
|
|
748
|
+
// the key of the first new child OR the build is not using `key`
|
|
749
|
+
// attributes at all. In either case we need to create a new element
|
|
750
|
+
// for the new node.
|
|
516
751
|
node = createElm(oldCh && oldCh[newStartIdx], newVNode, newStartIdx);
|
|
517
752
|
newStartVnode = newCh[++newStartIdx];
|
|
518
753
|
}
|
|
519
754
|
if (node) {
|
|
755
|
+
// if we created a new node then handle inserting it to the DOM
|
|
520
756
|
{
|
|
521
757
|
oldStartVnode.$elm$.parentNode.insertBefore(node, oldStartVnode.$elm$);
|
|
522
758
|
}
|
|
@@ -524,22 +760,53 @@ const updateChildren = (parentElm, oldCh, newVNode, newCh) => {
|
|
|
524
760
|
}
|
|
525
761
|
}
|
|
526
762
|
if (oldStartIdx > oldEndIdx) {
|
|
763
|
+
// we have some more new nodes to add which don't match up with old nodes
|
|
527
764
|
addVnodes(parentElm, newCh[newEndIdx + 1] == null ? null : newCh[newEndIdx + 1].$elm$, newVNode, newCh, newStartIdx, newEndIdx);
|
|
528
765
|
}
|
|
529
766
|
else if (newStartIdx > newEndIdx) {
|
|
767
|
+
// there are nodes in the `oldCh` array which no longer correspond to nodes
|
|
768
|
+
// in the new array, so lets remove them (which entails cleaning up the
|
|
769
|
+
// relevant DOM nodes)
|
|
530
770
|
removeVnodes(oldCh, oldStartIdx, oldEndIdx);
|
|
531
771
|
}
|
|
532
772
|
};
|
|
533
|
-
|
|
773
|
+
/**
|
|
774
|
+
* Compare two VNodes to determine if they are the same
|
|
775
|
+
*
|
|
776
|
+
* **NB**: This function is an equality _heuristic_ based on the available
|
|
777
|
+
* information set on the two VNodes and can be misleading under certain
|
|
778
|
+
* circumstances. In particular, if the two nodes do not have `key` attrs
|
|
779
|
+
* (available under `$key$` on VNodes) then the function falls back on merely
|
|
780
|
+
* checking that they have the same tag.
|
|
781
|
+
*
|
|
782
|
+
* So, in other words, if `key` attrs are not set on VNodes which may be
|
|
783
|
+
* changing order within a `children` array or something along those lines then
|
|
784
|
+
* we could obtain a false negative and then have to do needless re-rendering
|
|
785
|
+
* (i.e. we'd say two VNodes aren't equal when in fact they should be).
|
|
786
|
+
*
|
|
787
|
+
* @param leftVNode the first VNode to check
|
|
788
|
+
* @param rightVNode the second VNode to check
|
|
789
|
+
* @returns whether they're equal or not
|
|
790
|
+
*/
|
|
791
|
+
const isSameVnode = (leftVNode, rightVNode) => {
|
|
534
792
|
// compare if two vnode to see if they're "technically" the same
|
|
535
793
|
// need to have the same element tag, and same key to be the same
|
|
536
|
-
if (
|
|
794
|
+
if (leftVNode.$tag$ === rightVNode.$tag$) {
|
|
795
|
+
// this will be set if components in the build have `key` attrs set on them
|
|
537
796
|
{
|
|
538
|
-
return
|
|
797
|
+
return leftVNode.$key$ === rightVNode.$key$;
|
|
539
798
|
}
|
|
540
799
|
}
|
|
541
800
|
return false;
|
|
542
801
|
};
|
|
802
|
+
/**
|
|
803
|
+
* Handle reconciling an outdated VNode with a new one which corresponds to
|
|
804
|
+
* it. This function handles flushing updates to the DOM and reconciling the
|
|
805
|
+
* children of the two nodes (if any).
|
|
806
|
+
*
|
|
807
|
+
* @param oldVNode an old VNode whose DOM element and children we want to update
|
|
808
|
+
* @param newVNode a new VNode representing an updated version of the old one
|
|
809
|
+
*/
|
|
543
810
|
const patch = (oldVNode, newVNode) => {
|
|
544
811
|
const elm = (newVNode.$elm$ = oldVNode.$elm$);
|
|
545
812
|
const oldChildren = oldVNode.$children$;
|
|
@@ -552,7 +819,6 @@ const patch = (oldVNode, newVNode) => {
|
|
|
552
819
|
// only add this to the when the compiler sees we're using an svg somewhere
|
|
553
820
|
isSvgMode = tag === 'svg' ? true : tag === 'foreignObject' ? false : isSvgMode;
|
|
554
821
|
}
|
|
555
|
-
// element node
|
|
556
822
|
{
|
|
557
823
|
{
|
|
558
824
|
// either this is the first render of an element OR it's an update
|
|
@@ -563,6 +829,7 @@ const patch = (oldVNode, newVNode) => {
|
|
|
563
829
|
}
|
|
564
830
|
if (oldChildren !== null && newChildren !== null) {
|
|
565
831
|
// looks like there's child vnodes for both the old and new vnodes
|
|
832
|
+
// so we need to call `updateChildren` to reconcile them
|
|
566
833
|
updateChildren(elm, oldChildren, newVNode, newChildren);
|
|
567
834
|
}
|
|
568
835
|
else if (newChildren !== null) {
|
|
@@ -594,29 +861,29 @@ const callNodeRefs = (vNode) => {
|
|
|
594
861
|
vNode.$children$ && vNode.$children$.map(callNodeRefs);
|
|
595
862
|
}
|
|
596
863
|
};
|
|
864
|
+
/**
|
|
865
|
+
* The main entry point for Stencil's virtual DOM-based rendering engine
|
|
866
|
+
*
|
|
867
|
+
* Given a {@link d.HostRef} container and some virtual DOM nodes, this
|
|
868
|
+
* function will handle creating a virtual DOM tree with a single root, patching
|
|
869
|
+
* the current virtual DOM tree onto an old one (if any), dealing with slot
|
|
870
|
+
* relocation, and reflecting attributes.
|
|
871
|
+
*
|
|
872
|
+
* @param hostRef data needed to root and render the virtual DOM tree, such as
|
|
873
|
+
* the DOM node into which it should be rendered.
|
|
874
|
+
* @param renderFnResults the virtual DOM nodes to be rendered
|
|
875
|
+
*/
|
|
597
876
|
const renderVdom = (hostRef, renderFnResults) => {
|
|
598
877
|
const hostElm = hostRef.$hostElement$;
|
|
599
878
|
const oldVNode = hostRef.$vnode$ || newVNode(null, null);
|
|
600
879
|
const rootVnode = isHost(renderFnResults) ? renderFnResults : h(null, null, renderFnResults);
|
|
601
880
|
rootVnode.$tag$ = null;
|
|
602
|
-
rootVnode.$flags$ |= 4 /* isHost */;
|
|
881
|
+
rootVnode.$flags$ |= 4 /* VNODE_FLAGS.isHost */;
|
|
603
882
|
hostRef.$vnode$ = rootVnode;
|
|
604
883
|
rootVnode.$elm$ = oldVNode.$elm$ = (hostElm);
|
|
605
884
|
// synchronous patch
|
|
606
885
|
patch(oldVNode, rootVnode);
|
|
607
886
|
};
|
|
608
|
-
/**
|
|
609
|
-
* Helper function to create & dispatch a custom Event on a provided target
|
|
610
|
-
* @param elm the target of the Event
|
|
611
|
-
* @param name the name to give the custom Event
|
|
612
|
-
* @param opts options for configuring a custom Event
|
|
613
|
-
* @returns the custom Event
|
|
614
|
-
*/
|
|
615
|
-
const emitEvent = (elm, name, opts) => {
|
|
616
|
-
const ev = plt.ce(name, opts);
|
|
617
|
-
elm.dispatchEvent(ev);
|
|
618
|
-
return ev;
|
|
619
|
-
};
|
|
620
887
|
const attachToAncestor = (hostRef, ancestorComponent) => {
|
|
621
888
|
if (ancestorComponent && !hostRef.$onRenderResolve$ && ancestorComponent['s-p']) {
|
|
622
889
|
ancestorComponent['s-p'].push(new Promise((r) => (hostRef.$onRenderResolve$ = r)));
|
|
@@ -624,10 +891,10 @@ const attachToAncestor = (hostRef, ancestorComponent) => {
|
|
|
624
891
|
};
|
|
625
892
|
const scheduleUpdate = (hostRef, isInitialLoad) => {
|
|
626
893
|
{
|
|
627
|
-
hostRef.$flags$ |= 16 /* isQueuedForUpdate */;
|
|
894
|
+
hostRef.$flags$ |= 16 /* HOST_FLAGS.isQueuedForUpdate */;
|
|
628
895
|
}
|
|
629
|
-
if (hostRef.$flags$ & 4 /* isWaitingForChildren */) {
|
|
630
|
-
hostRef.$flags$ |= 512 /* needsRerender */;
|
|
896
|
+
if (hostRef.$flags$ & 4 /* HOST_FLAGS.isWaitingForChildren */) {
|
|
897
|
+
hostRef.$flags$ |= 512 /* HOST_FLAGS.needsRerender */;
|
|
631
898
|
return;
|
|
632
899
|
}
|
|
633
900
|
attachToAncestor(hostRef, hostRef.$ancestorComponent$);
|
|
@@ -646,6 +913,11 @@ const dispatchHooks = (hostRef, isInitialLoad) => {
|
|
|
646
913
|
promise = safeCall(instance, 'componentWillLoad');
|
|
647
914
|
}
|
|
648
915
|
}
|
|
916
|
+
else {
|
|
917
|
+
{
|
|
918
|
+
promise = safeCall(instance, 'componentWillUpdate');
|
|
919
|
+
}
|
|
920
|
+
}
|
|
649
921
|
endSchedule();
|
|
650
922
|
return then(promise, () => updateComponent(hostRef, instance, isInitialLoad));
|
|
651
923
|
};
|
|
@@ -679,7 +951,7 @@ const updateComponent = async (hostRef, instance, isInitialLoad) => {
|
|
|
679
951
|
}
|
|
680
952
|
else {
|
|
681
953
|
Promise.all(childrenPromises).then(postUpdate);
|
|
682
|
-
hostRef.$flags$ |= 4 /* isWaitingForChildren */;
|
|
954
|
+
hostRef.$flags$ |= 4 /* HOST_FLAGS.isWaitingForChildren */;
|
|
683
955
|
childrenPromises.length = 0;
|
|
684
956
|
}
|
|
685
957
|
}
|
|
@@ -688,10 +960,10 @@ const callRender = (hostRef, instance, elm) => {
|
|
|
688
960
|
try {
|
|
689
961
|
instance = instance.render() ;
|
|
690
962
|
{
|
|
691
|
-
hostRef.$flags$ &= ~16 /* isQueuedForUpdate */;
|
|
963
|
+
hostRef.$flags$ &= ~16 /* HOST_FLAGS.isQueuedForUpdate */;
|
|
692
964
|
}
|
|
693
965
|
{
|
|
694
|
-
hostRef.$flags$ |= 2 /* hasRendered */;
|
|
966
|
+
hostRef.$flags$ |= 2 /* HOST_FLAGS.hasRendered */;
|
|
695
967
|
}
|
|
696
968
|
{
|
|
697
969
|
{
|
|
@@ -718,8 +990,8 @@ const postUpdateComponent = (hostRef) => {
|
|
|
718
990
|
{
|
|
719
991
|
safeCall(instance, 'componentDidRender');
|
|
720
992
|
}
|
|
721
|
-
if (!(hostRef.$flags$ & 64 /* hasLoadedComponent */)) {
|
|
722
|
-
hostRef.$flags$ |= 64 /* hasLoadedComponent */;
|
|
993
|
+
if (!(hostRef.$flags$ & 64 /* HOST_FLAGS.hasLoadedComponent */)) {
|
|
994
|
+
hostRef.$flags$ |= 64 /* HOST_FLAGS.hasLoadedComponent */;
|
|
723
995
|
{
|
|
724
996
|
// DOM WRITE!
|
|
725
997
|
addHydratedFlag(elm);
|
|
@@ -748,10 +1020,10 @@ const postUpdateComponent = (hostRef) => {
|
|
|
748
1020
|
hostRef.$onRenderResolve$();
|
|
749
1021
|
hostRef.$onRenderResolve$ = undefined;
|
|
750
1022
|
}
|
|
751
|
-
if (hostRef.$flags$ & 512 /* needsRerender */) {
|
|
1023
|
+
if (hostRef.$flags$ & 512 /* HOST_FLAGS.needsRerender */) {
|
|
752
1024
|
nextTick(() => scheduleUpdate(hostRef, false));
|
|
753
1025
|
}
|
|
754
|
-
hostRef.$flags$ &= ~(4 /* isWaitingForChildren */ | 512 /* needsRerender */);
|
|
1026
|
+
hostRef.$flags$ &= ~(4 /* HOST_FLAGS.isWaitingForChildren */ | 512 /* HOST_FLAGS.needsRerender */);
|
|
755
1027
|
}
|
|
756
1028
|
// ( •_•)
|
|
757
1029
|
// ( •_•)>⌐■-■
|
|
@@ -781,25 +1053,6 @@ const then = (promise, thenFn) => {
|
|
|
781
1053
|
};
|
|
782
1054
|
const addHydratedFlag = (elm) => elm.classList.add('hydrated')
|
|
783
1055
|
;
|
|
784
|
-
const parsePropertyValue = (propValue, propType) => {
|
|
785
|
-
// ensure this value is of the correct prop type
|
|
786
|
-
if (propValue != null && !isComplexType(propValue)) {
|
|
787
|
-
if (propType & 2 /* Number */) {
|
|
788
|
-
// force it to be a number
|
|
789
|
-
return parseFloat(propValue);
|
|
790
|
-
}
|
|
791
|
-
if (propType & 1 /* String */) {
|
|
792
|
-
// could have been passed as a number or boolean
|
|
793
|
-
// but we still want it as a string
|
|
794
|
-
return String(propValue);
|
|
795
|
-
}
|
|
796
|
-
// redundant return here for better minification
|
|
797
|
-
return propValue;
|
|
798
|
-
}
|
|
799
|
-
// not sure exactly what type we want
|
|
800
|
-
// so no need to change to a different type
|
|
801
|
-
return propValue;
|
|
802
|
-
};
|
|
803
1056
|
const getValue = (ref, propName) => getHostRef(ref).$instanceValues$.get(propName);
|
|
804
1057
|
const setValue = (ref, propName, newVal, cmpMeta) => {
|
|
805
1058
|
// check our new property value against our internal value
|
|
@@ -808,12 +1061,15 @@ const setValue = (ref, propName, newVal, cmpMeta) => {
|
|
|
808
1061
|
const flags = hostRef.$flags$;
|
|
809
1062
|
const instance = hostRef.$lazyInstance$ ;
|
|
810
1063
|
newVal = parsePropertyValue(newVal, cmpMeta.$members$[propName][0]);
|
|
811
|
-
|
|
1064
|
+
// explicitly check for NaN on both sides, as `NaN === NaN` is always false
|
|
1065
|
+
const areBothNaN = Number.isNaN(oldVal) && Number.isNaN(newVal);
|
|
1066
|
+
const didValueChange = newVal !== oldVal && !areBothNaN;
|
|
1067
|
+
if ((!(flags & 8 /* HOST_FLAGS.isConstructingInstance */) || oldVal === undefined) && didValueChange) {
|
|
812
1068
|
// gadzooks! the property's value has changed!!
|
|
813
1069
|
// set our new value!
|
|
814
1070
|
hostRef.$instanceValues$.set(propName, newVal);
|
|
815
1071
|
if (instance) {
|
|
816
|
-
if ((flags & (2 /* hasRendered */ | 16 /* isQueuedForUpdate */)) === 2 /* hasRendered */) {
|
|
1072
|
+
if ((flags & (2 /* HOST_FLAGS.hasRendered */ | 16 /* HOST_FLAGS.isQueuedForUpdate */)) === 2 /* HOST_FLAGS.hasRendered */) {
|
|
817
1073
|
// looks like this value actually changed, so we've got work to do!
|
|
818
1074
|
// but only if we've already rendered, otherwise just chill out
|
|
819
1075
|
// queue that we need to do an update, but don't worry about queuing
|
|
@@ -823,14 +1079,24 @@ const setValue = (ref, propName, newVal, cmpMeta) => {
|
|
|
823
1079
|
}
|
|
824
1080
|
}
|
|
825
1081
|
};
|
|
1082
|
+
/**
|
|
1083
|
+
* Attach a series of runtime constructs to a compiled Stencil component
|
|
1084
|
+
* constructor, including getters and setters for the `@Prop` and `@State`
|
|
1085
|
+
* decorators, callbacks for when attributes change, and so on.
|
|
1086
|
+
*
|
|
1087
|
+
* @param Cstr the constructor for a component that we need to process
|
|
1088
|
+
* @param cmpMeta metadata collected previously about the component
|
|
1089
|
+
* @param flags a number used to store a series of bit flags
|
|
1090
|
+
* @returns a reference to the same constructor passed in (but now mutated)
|
|
1091
|
+
*/
|
|
826
1092
|
const proxyComponent = (Cstr, cmpMeta, flags) => {
|
|
827
1093
|
if (cmpMeta.$members$) {
|
|
828
1094
|
// It's better to have a const than two Object.entries()
|
|
829
1095
|
const members = Object.entries(cmpMeta.$members$);
|
|
830
1096
|
const prototype = Cstr.prototype;
|
|
831
1097
|
members.map(([memberName, [memberFlags]]) => {
|
|
832
|
-
if ((memberFlags & 31 /* Prop */ ||
|
|
833
|
-
((flags & 2 /* proxyState */) && memberFlags & 32 /* State */))) {
|
|
1098
|
+
if ((memberFlags & 31 /* MEMBER_FLAGS.Prop */ ||
|
|
1099
|
+
((flags & 2 /* PROXY_FLAGS.proxyState */) && memberFlags & 32 /* MEMBER_FLAGS.State */))) {
|
|
834
1100
|
// proxyComponent - prop
|
|
835
1101
|
Object.defineProperty(prototype, memberName, {
|
|
836
1102
|
get() {
|
|
@@ -845,8 +1111,8 @@ const proxyComponent = (Cstr, cmpMeta, flags) => {
|
|
|
845
1111
|
enumerable: true,
|
|
846
1112
|
});
|
|
847
1113
|
}
|
|
848
|
-
else if (flags & 1 /* isElementConstructor */ &&
|
|
849
|
-
memberFlags & 64 /* Method */) {
|
|
1114
|
+
else if (flags & 1 /* PROXY_FLAGS.isElementConstructor */ &&
|
|
1115
|
+
memberFlags & 64 /* MEMBER_FLAGS.Method */) {
|
|
850
1116
|
// proxyComponent - method
|
|
851
1117
|
Object.defineProperty(prototype, memberName, {
|
|
852
1118
|
value(...args) {
|
|
@@ -856,19 +1122,19 @@ const proxyComponent = (Cstr, cmpMeta, flags) => {
|
|
|
856
1122
|
});
|
|
857
1123
|
}
|
|
858
1124
|
});
|
|
859
|
-
if ((flags & 1 /* isElementConstructor */)) {
|
|
1125
|
+
if ((flags & 1 /* PROXY_FLAGS.isElementConstructor */)) {
|
|
860
1126
|
const attrNameToPropName = new Map();
|
|
861
1127
|
prototype.attributeChangedCallback = function (attrName, _oldValue, newValue) {
|
|
862
1128
|
plt.jmp(() => {
|
|
863
1129
|
const propName = attrNameToPropName.get(attrName);
|
|
864
|
-
// In a
|
|
1130
|
+
// In a web component lifecycle the attributeChangedCallback runs prior to connectedCallback
|
|
865
1131
|
// in the case where an attribute was set inline.
|
|
866
1132
|
// ```html
|
|
867
1133
|
// <my-component some-attribute="some-value"></my-component>
|
|
868
1134
|
// ```
|
|
869
1135
|
//
|
|
870
|
-
// There is an edge case where a developer sets the attribute inline on a custom element and then
|
|
871
|
-
// changes it before it has been upgraded as shown below:
|
|
1136
|
+
// There is an edge case where a developer sets the attribute inline on a custom element and then
|
|
1137
|
+
// programmatically changes it before it has been upgraded as shown below:
|
|
872
1138
|
//
|
|
873
1139
|
// ```html
|
|
874
1140
|
// <!-- this component has _not_ been upgraded yet -->
|
|
@@ -878,13 +1144,13 @@ const proxyComponent = (Cstr, cmpMeta, flags) => {
|
|
|
878
1144
|
// el = document.querySelector("#test");
|
|
879
1145
|
// el.someAttribute = "another-value";
|
|
880
1146
|
// // upgrade component
|
|
881
|
-
//
|
|
1147
|
+
// customElements.define('my-component', MyComponent);
|
|
882
1148
|
// </script>
|
|
883
1149
|
// ```
|
|
884
1150
|
// In this case if we do not unshadow here and use the value of the shadowing property, attributeChangedCallback
|
|
885
1151
|
// will be called with `newValue = "some-value"` and will set the shadowed property (this.someAttribute = "another-value")
|
|
886
1152
|
// to the value that was set inline i.e. "some-value" from above example. When
|
|
887
|
-
// the connectedCallback attempts to unshadow it will use "some-value" as the
|
|
1153
|
+
// the connectedCallback attempts to unshadow it will use "some-value" as the initial value rather than "another-value"
|
|
888
1154
|
//
|
|
889
1155
|
// The case where the attribute was NOT set inline but was not set programmatically shall be handled/unshadowed
|
|
890
1156
|
// by connectedCallback as this attributeChangedCallback will not fire.
|
|
@@ -898,13 +1164,21 @@ const proxyComponent = (Cstr, cmpMeta, flags) => {
|
|
|
898
1164
|
newValue = this[propName];
|
|
899
1165
|
delete this[propName];
|
|
900
1166
|
}
|
|
1167
|
+
else if (prototype.hasOwnProperty(propName) &&
|
|
1168
|
+
typeof this[propName] === 'number' &&
|
|
1169
|
+
this[propName] == newValue) {
|
|
1170
|
+
// if the propName exists on the prototype of `Cstr`, this update may be a result of Stencil using native
|
|
1171
|
+
// APIs to reflect props as attributes. Calls to `setAttribute(someElement, propName)` will result in
|
|
1172
|
+
// `propName` to be converted to a `DOMString`, which may not be what we want for other primitive props.
|
|
1173
|
+
return;
|
|
1174
|
+
}
|
|
901
1175
|
this[propName] = newValue === null && typeof this[propName] === 'boolean' ? false : newValue;
|
|
902
1176
|
});
|
|
903
1177
|
};
|
|
904
1178
|
// create an array of attributes to observe
|
|
905
1179
|
// and also create a map of html attribute name to js property name
|
|
906
1180
|
Cstr.observedAttributes = members
|
|
907
|
-
.filter(([_, m]) => m[0] & 15 /* HasAttribute */) // filter to only keep props that should match attributes
|
|
1181
|
+
.filter(([_, m]) => m[0] & 15 /* MEMBER_FLAGS.HasAttribute */) // filter to only keep props that should match attributes
|
|
908
1182
|
.map(([propName, m]) => {
|
|
909
1183
|
const attrName = m[1] || propName;
|
|
910
1184
|
attrNameToPropName.set(attrName, propName);
|
|
@@ -916,10 +1190,10 @@ const proxyComponent = (Cstr, cmpMeta, flags) => {
|
|
|
916
1190
|
};
|
|
917
1191
|
const initializeComponent = async (elm, hostRef, cmpMeta, hmrVersionId, Cstr) => {
|
|
918
1192
|
// initializeComponent
|
|
919
|
-
if ((hostRef.$flags$ & 32 /* hasInitializedComponent */) === 0) {
|
|
1193
|
+
if ((hostRef.$flags$ & 32 /* HOST_FLAGS.hasInitializedComponent */) === 0) {
|
|
920
1194
|
{
|
|
921
1195
|
// we haven't initialized this element yet
|
|
922
|
-
hostRef.$flags$ |= 32 /* hasInitializedComponent */;
|
|
1196
|
+
hostRef.$flags$ |= 32 /* HOST_FLAGS.hasInitializedComponent */;
|
|
923
1197
|
// lazy loaded components
|
|
924
1198
|
// request the component's implementation to be
|
|
925
1199
|
// wired up with the host element
|
|
@@ -931,7 +1205,7 @@ const initializeComponent = async (elm, hostRef, cmpMeta, hmrVersionId, Cstr) =>
|
|
|
931
1205
|
endLoad();
|
|
932
1206
|
}
|
|
933
1207
|
if (!Cstr.isProxied) {
|
|
934
|
-
proxyComponent(Cstr, cmpMeta, 2 /* proxyState */);
|
|
1208
|
+
proxyComponent(Cstr, cmpMeta, 2 /* PROXY_FLAGS.proxyState */);
|
|
935
1209
|
Cstr.isProxied = true;
|
|
936
1210
|
}
|
|
937
1211
|
const endNewInstance = createTime('createInstance', cmpMeta.$tagName$);
|
|
@@ -939,7 +1213,7 @@ const initializeComponent = async (elm, hostRef, cmpMeta, hmrVersionId, Cstr) =>
|
|
|
939
1213
|
// but let's keep track of when we start and stop
|
|
940
1214
|
// so that the getters/setters don't incorrectly step on data
|
|
941
1215
|
{
|
|
942
|
-
hostRef.$flags$ |= 8 /* isConstructingInstance */;
|
|
1216
|
+
hostRef.$flags$ |= 8 /* HOST_FLAGS.isConstructingInstance */;
|
|
943
1217
|
}
|
|
944
1218
|
// construct the lazy-loaded component implementation
|
|
945
1219
|
// passing the hostRef is very important during
|
|
@@ -952,7 +1226,7 @@ const initializeComponent = async (elm, hostRef, cmpMeta, hmrVersionId, Cstr) =>
|
|
|
952
1226
|
consoleError(e);
|
|
953
1227
|
}
|
|
954
1228
|
{
|
|
955
|
-
hostRef.$flags$ &= ~8 /* isConstructingInstance */;
|
|
1229
|
+
hostRef.$flags$ &= ~8 /* HOST_FLAGS.isConstructingInstance */;
|
|
956
1230
|
}
|
|
957
1231
|
endNewInstance();
|
|
958
1232
|
}
|
|
@@ -962,7 +1236,7 @@ const initializeComponent = async (elm, hostRef, cmpMeta, hmrVersionId, Cstr) =>
|
|
|
962
1236
|
const scopeId = getScopeId(cmpMeta);
|
|
963
1237
|
if (!styles.has(scopeId)) {
|
|
964
1238
|
const endRegisterStyles = createTime('registerStyles', cmpMeta.$tagName$);
|
|
965
|
-
registerStyle(scopeId, style, !!(cmpMeta.$flags$ & 1 /* shadowDomEncapsulation */));
|
|
1239
|
+
registerStyle(scopeId, style, !!(cmpMeta.$flags$ & 1 /* CMP_FLAGS.shadowDomEncapsulation */));
|
|
966
1240
|
endRegisterStyles();
|
|
967
1241
|
}
|
|
968
1242
|
}
|
|
@@ -971,7 +1245,7 @@ const initializeComponent = async (elm, hostRef, cmpMeta, hmrVersionId, Cstr) =>
|
|
|
971
1245
|
const ancestorComponent = hostRef.$ancestorComponent$;
|
|
972
1246
|
const schedule = () => scheduleUpdate(hostRef, true);
|
|
973
1247
|
if (ancestorComponent && ancestorComponent['s-rc']) {
|
|
974
|
-
// this is the
|
|
1248
|
+
// this is the initial load and this component it has an ancestor component
|
|
975
1249
|
// but the ancestor component has NOT fired its will update lifecycle yet
|
|
976
1250
|
// so let's just cool our jets and wait for the ancestor to continue first
|
|
977
1251
|
// this will get fired off when the ancestor component
|
|
@@ -984,13 +1258,13 @@ const initializeComponent = async (elm, hostRef, cmpMeta, hmrVersionId, Cstr) =>
|
|
|
984
1258
|
}
|
|
985
1259
|
};
|
|
986
1260
|
const connectedCallback = (elm) => {
|
|
987
|
-
if ((plt.$flags$ & 1 /* isTmpDisconnected */) === 0) {
|
|
1261
|
+
if ((plt.$flags$ & 1 /* PLATFORM_FLAGS.isTmpDisconnected */) === 0) {
|
|
988
1262
|
const hostRef = getHostRef(elm);
|
|
989
1263
|
const cmpMeta = hostRef.$cmpMeta$;
|
|
990
1264
|
const endConnected = createTime('connectedCallback', cmpMeta.$tagName$);
|
|
991
|
-
if (!(hostRef.$flags$ & 1 /* hasConnected */)) {
|
|
1265
|
+
if (!(hostRef.$flags$ & 1 /* HOST_FLAGS.hasConnected */)) {
|
|
992
1266
|
// first time this component has connected
|
|
993
|
-
hostRef.$flags$ |= 1 /* hasConnected */;
|
|
1267
|
+
hostRef.$flags$ |= 1 /* HOST_FLAGS.hasConnected */;
|
|
994
1268
|
{
|
|
995
1269
|
// find the first ancestor component (if there is one) and register
|
|
996
1270
|
// this component as one of the actively loading child components for its ancestor
|
|
@@ -1010,7 +1284,7 @@ const connectedCallback = (elm) => {
|
|
|
1010
1284
|
// https://developers.google.com/web/fundamentals/web-components/best-practices#lazy-properties
|
|
1011
1285
|
if (cmpMeta.$members$) {
|
|
1012
1286
|
Object.entries(cmpMeta.$members$).map(([memberName, [memberFlags]]) => {
|
|
1013
|
-
if (memberFlags & 31 /* Prop */ && elm.hasOwnProperty(memberName)) {
|
|
1287
|
+
if (memberFlags & 31 /* MEMBER_FLAGS.Prop */ && elm.hasOwnProperty(memberName)) {
|
|
1014
1288
|
const value = elm[memberName];
|
|
1015
1289
|
delete elm[memberName];
|
|
1016
1290
|
elm[memberName] = value;
|
|
@@ -1025,11 +1299,12 @@ const connectedCallback = (elm) => {
|
|
|
1025
1299
|
}
|
|
1026
1300
|
};
|
|
1027
1301
|
const disconnectedCallback = (elm) => {
|
|
1028
|
-
if ((plt.$flags$ & 1 /* isTmpDisconnected */) === 0) {
|
|
1302
|
+
if ((plt.$flags$ & 1 /* PLATFORM_FLAGS.isTmpDisconnected */) === 0) {
|
|
1029
1303
|
getHostRef(elm);
|
|
1030
1304
|
}
|
|
1031
1305
|
};
|
|
1032
1306
|
const bootstrapLazy = (lazyBundles, options = {}) => {
|
|
1307
|
+
var _a;
|
|
1033
1308
|
const endBootstrap = createTime();
|
|
1034
1309
|
const cmpTags = [];
|
|
1035
1310
|
const exclude = options.exclude || [];
|
|
@@ -1042,54 +1317,61 @@ const bootstrapLazy = (lazyBundles, options = {}) => {
|
|
|
1042
1317
|
let isBootstrapping = true;
|
|
1043
1318
|
Object.assign(plt, options);
|
|
1044
1319
|
plt.$resourcesUrl$ = new URL(options.resourcesUrl || './', doc.baseURI).href;
|
|
1045
|
-
lazyBundles.map((lazyBundle) =>
|
|
1046
|
-
|
|
1047
|
-
|
|
1048
|
-
|
|
1049
|
-
|
|
1050
|
-
|
|
1051
|
-
|
|
1052
|
-
|
|
1053
|
-
|
|
1054
|
-
|
|
1055
|
-
const tagName = cmpMeta.$tagName$;
|
|
1056
|
-
const HostElement = class extends HTMLElement {
|
|
1057
|
-
// StencilLazyHost
|
|
1058
|
-
constructor(self) {
|
|
1059
|
-
// @ts-ignore
|
|
1060
|
-
super(self);
|
|
1061
|
-
self = this;
|
|
1062
|
-
registerHost(self, cmpMeta);
|
|
1320
|
+
lazyBundles.map((lazyBundle) => {
|
|
1321
|
+
lazyBundle[1].map((compactMeta) => {
|
|
1322
|
+
const cmpMeta = {
|
|
1323
|
+
$flags$: compactMeta[0],
|
|
1324
|
+
$tagName$: compactMeta[1],
|
|
1325
|
+
$members$: compactMeta[2],
|
|
1326
|
+
$listeners$: compactMeta[3],
|
|
1327
|
+
};
|
|
1328
|
+
{
|
|
1329
|
+
cmpMeta.$members$ = compactMeta[2];
|
|
1063
1330
|
}
|
|
1064
|
-
|
|
1065
|
-
|
|
1066
|
-
|
|
1067
|
-
|
|
1331
|
+
const tagName = cmpMeta.$tagName$;
|
|
1332
|
+
const HostElement = class extends HTMLElement {
|
|
1333
|
+
// StencilLazyHost
|
|
1334
|
+
constructor(self) {
|
|
1335
|
+
// @ts-ignore
|
|
1336
|
+
super(self);
|
|
1337
|
+
self = this;
|
|
1338
|
+
registerHost(self, cmpMeta);
|
|
1068
1339
|
}
|
|
1069
|
-
|
|
1070
|
-
|
|
1071
|
-
|
|
1340
|
+
connectedCallback() {
|
|
1341
|
+
if (appLoadFallback) {
|
|
1342
|
+
clearTimeout(appLoadFallback);
|
|
1343
|
+
appLoadFallback = null;
|
|
1344
|
+
}
|
|
1345
|
+
if (isBootstrapping) {
|
|
1346
|
+
// connectedCallback will be processed once all components have been registered
|
|
1347
|
+
deferredConnectedCallbacks.push(this);
|
|
1348
|
+
}
|
|
1349
|
+
else {
|
|
1350
|
+
plt.jmp(() => connectedCallback(this));
|
|
1351
|
+
}
|
|
1072
1352
|
}
|
|
1073
|
-
|
|
1074
|
-
plt.jmp(() =>
|
|
1353
|
+
disconnectedCallback() {
|
|
1354
|
+
plt.jmp(() => disconnectedCallback(this));
|
|
1075
1355
|
}
|
|
1356
|
+
componentOnReady() {
|
|
1357
|
+
return getHostRef(this).$onReadyPromise$;
|
|
1358
|
+
}
|
|
1359
|
+
};
|
|
1360
|
+
cmpMeta.$lazyBundleId$ = lazyBundle[0];
|
|
1361
|
+
if (!exclude.includes(tagName) && !customElements.get(tagName)) {
|
|
1362
|
+
cmpTags.push(tagName);
|
|
1363
|
+
customElements.define(tagName, proxyComponent(HostElement, cmpMeta, 1 /* PROXY_FLAGS.isElementConstructor */));
|
|
1076
1364
|
}
|
|
1077
|
-
|
|
1078
|
-
|
|
1079
|
-
}
|
|
1080
|
-
componentOnReady() {
|
|
1081
|
-
return getHostRef(this).$onReadyPromise$;
|
|
1082
|
-
}
|
|
1083
|
-
};
|
|
1084
|
-
cmpMeta.$lazyBundleId$ = lazyBundle[0];
|
|
1085
|
-
if (!exclude.includes(tagName) && !customElements.get(tagName)) {
|
|
1086
|
-
cmpTags.push(tagName);
|
|
1087
|
-
customElements.define(tagName, proxyComponent(HostElement, cmpMeta, 1 /* isElementConstructor */));
|
|
1088
|
-
}
|
|
1089
|
-
}));
|
|
1365
|
+
});
|
|
1366
|
+
});
|
|
1090
1367
|
{
|
|
1091
1368
|
visibilityStyle.innerHTML = cmpTags + HYDRATED_CSS;
|
|
1092
1369
|
visibilityStyle.setAttribute('data-styles', '');
|
|
1370
|
+
// Apply CSP nonce to the style tag if it exists
|
|
1371
|
+
const nonce = (_a = plt.$nonce$) !== null && _a !== void 0 ? _a : queryNonceMetaTagContent(doc);
|
|
1372
|
+
if (nonce != null) {
|
|
1373
|
+
visibilityStyle.setAttribute('nonce', nonce);
|
|
1374
|
+
}
|
|
1093
1375
|
head.insertBefore(visibilityStyle, metaCharset ? metaCharset.nextSibling : head.firstChild);
|
|
1094
1376
|
}
|
|
1095
1377
|
// Process deferred connectedCallbacks now all components have been registered
|
|
@@ -1105,7 +1387,14 @@ const bootstrapLazy = (lazyBundles, options = {}) => {
|
|
|
1105
1387
|
// Fallback appLoad event
|
|
1106
1388
|
endBootstrap();
|
|
1107
1389
|
};
|
|
1108
|
-
|
|
1390
|
+
/**
|
|
1391
|
+
* Assigns the given value to the nonce property on the runtime platform object.
|
|
1392
|
+
* During runtime, this value is used to set the nonce attribute on all dynamically created script and style tags.
|
|
1393
|
+
* @param nonce The value to be assigned to the platform nonce property.
|
|
1394
|
+
* @returns void
|
|
1395
|
+
*/
|
|
1396
|
+
const setNonce = (nonce) => (plt.$nonce$ = nonce);
|
|
1397
|
+
const hostRefs = /*@__PURE__*/ new WeakMap();
|
|
1109
1398
|
const getHostRef = (ref) => hostRefs.get(ref);
|
|
1110
1399
|
const registerInstance = (lazyInstance, hostRef) => hostRefs.set((hostRef.$lazyInstance$ = lazyInstance), hostRef);
|
|
1111
1400
|
const registerHost = (elm, cmpMeta) => {
|
|
@@ -1136,7 +1425,9 @@ const loadModule = (cmpMeta, hostRef, hmrVersionId) => {
|
|
|
1136
1425
|
if (module) {
|
|
1137
1426
|
return module[exportName];
|
|
1138
1427
|
}
|
|
1428
|
+
/*!__STENCIL_STATIC_IMPORT_SWITCH__*/
|
|
1139
1429
|
return import(
|
|
1430
|
+
/* @vite-ignore */
|
|
1140
1431
|
/* webpackInclude: /\.entry\.js$/ */
|
|
1141
1432
|
/* webpackExclude: /\.system\.entry\.js$/ */
|
|
1142
1433
|
/* webpackMode: "lazy" */
|
|
@@ -1147,14 +1438,35 @@ const loadModule = (cmpMeta, hostRef, hmrVersionId) => {
|
|
|
1147
1438
|
return importedModule[exportName];
|
|
1148
1439
|
}, consoleError);
|
|
1149
1440
|
};
|
|
1150
|
-
const styles = new Map();
|
|
1441
|
+
const styles = /*@__PURE__*/ new Map();
|
|
1442
|
+
const win = typeof window !== 'undefined' ? window : {};
|
|
1443
|
+
const doc = win.document || { head: {} };
|
|
1444
|
+
const plt = {
|
|
1445
|
+
$flags$: 0,
|
|
1446
|
+
$resourcesUrl$: '',
|
|
1447
|
+
jmp: (h) => h(),
|
|
1448
|
+
raf: (h) => requestAnimationFrame(h),
|
|
1449
|
+
ael: (el, eventName, listener, opts) => el.addEventListener(eventName, listener, opts),
|
|
1450
|
+
rel: (el, eventName, listener, opts) => el.removeEventListener(eventName, listener, opts),
|
|
1451
|
+
ce: (eventName, opts) => new CustomEvent(eventName, opts),
|
|
1452
|
+
};
|
|
1453
|
+
const promiseResolve = (v) => Promise.resolve(v);
|
|
1454
|
+
const supportsConstructableStylesheets = /*@__PURE__*/ (() => {
|
|
1455
|
+
try {
|
|
1456
|
+
new CSSStyleSheet();
|
|
1457
|
+
return typeof new CSSStyleSheet().replaceSync === 'function';
|
|
1458
|
+
}
|
|
1459
|
+
catch (e) { }
|
|
1460
|
+
return false;
|
|
1461
|
+
})()
|
|
1462
|
+
;
|
|
1151
1463
|
const queueDomReads = [];
|
|
1152
1464
|
const queueDomWrites = [];
|
|
1153
1465
|
const queueTask = (queue, write) => (cb) => {
|
|
1154
1466
|
queue.push(cb);
|
|
1155
1467
|
if (!queuePending) {
|
|
1156
1468
|
queuePending = true;
|
|
1157
|
-
if (write && plt.$flags$ & 4 /* queueSync */) {
|
|
1469
|
+
if (write && plt.$flags$ & 4 /* PLATFORM_FLAGS.queueSync */) {
|
|
1158
1470
|
nextTick(flush);
|
|
1159
1471
|
}
|
|
1160
1472
|
else {
|
|
@@ -1191,4 +1503,4 @@ const flush = () => {
|
|
|
1191
1503
|
const nextTick = /*@__PURE__*/ (cb) => promiseResolve().then(cb);
|
|
1192
1504
|
const writeTask = /*@__PURE__*/ queueTask(queueDomWrites, true);
|
|
1193
1505
|
|
|
1194
|
-
export { bootstrapLazy as b, h, promiseResolve as p, registerInstance as r };
|
|
1506
|
+
export { bootstrapLazy as b, getAssetPath as g, h, promiseResolve as p, registerInstance as r, setNonce as s };
|