UNPKG

40.8 kBJavaScriptView Raw
1const NAMESPACE = 'sgnw-components';
2
3let scopeId;
4let hostTagName;
5let isSvgMode = false;
6let queuePending = false;
7const win = typeof window !== 'undefined' ? window : {};
8const doc = win.document || { head: {} };
9const plt = {
10 $flags$: 0,
11 $resourcesUrl$: '',
12 jmp: h => h(),
13 raf: h => requestAnimationFrame(h),
14 ael: (el, eventName, listener, opts) => el.addEventListener(eventName, listener, opts),
15 rel: (el, eventName, listener, opts) => el.removeEventListener(eventName, listener, opts),
16 ce: (eventName, opts) => new CustomEvent(eventName, opts),
17};
18const promiseResolve = (v) => Promise.resolve(v);
19const supportsConstructibleStylesheets = /*@__PURE__*/ (() => {
20 try {
21 new CSSStyleSheet();
22 return typeof (new CSSStyleSheet()).replace === 'function';
23 }
24 catch (e) { }
25 return false;
26 })()
27 ;
28const HYDRATED_CSS = '{visibility:hidden}.hydrated{visibility:inherit}';
29const createTime = (fnName, tagName = '') => {
30 {
31 return () => {
32 return;
33 };
34 }
35};
36const uniqueTime = (key, measureText) => {
37 {
38 return () => {
39 return;
40 };
41 }
42};
43const rootAppliedStyles = new WeakMap();
44const registerStyle = (scopeId, cssText, allowCS) => {
45 let style = styles.get(scopeId);
46 if (supportsConstructibleStylesheets && allowCS) {
47 style = (style || new CSSStyleSheet());
48 style.replace(cssText);
49 }
50 else {
51 style = cssText;
52 }
53 styles.set(scopeId, style);
54};
55const addStyle = (styleContainerNode, cmpMeta, mode, hostElm) => {
56 let scopeId = getScopeId(cmpMeta);
57 let style = styles.get(scopeId);
58 // if an element is NOT connected then getRootNode() will return the wrong root node
59 // so the fallback is to always use the document for the root node in those cases
60 styleContainerNode = styleContainerNode.nodeType === 11 /* DocumentFragment */ ? styleContainerNode : doc;
61 if (style) {
62 if (typeof style === 'string') {
63 styleContainerNode = styleContainerNode.head || styleContainerNode;
64 let appliedStyles = rootAppliedStyles.get(styleContainerNode);
65 let styleElm;
66 if (!appliedStyles) {
67 rootAppliedStyles.set(styleContainerNode, (appliedStyles = new Set()));
68 }
69 if (!appliedStyles.has(scopeId)) {
70 {
71 {
72 styleElm = doc.createElement('style');
73 styleElm.innerHTML = style;
74 }
75 styleContainerNode.insertBefore(styleElm, styleContainerNode.querySelector('link'));
76 }
77 if (appliedStyles) {
78 appliedStyles.add(scopeId);
79 }
80 }
81 }
82 else if (!styleContainerNode.adoptedStyleSheets.includes(style)) {
83 styleContainerNode.adoptedStyleSheets = [...styleContainerNode.adoptedStyleSheets, style];
84 }
85 }
86 return scopeId;
87};
88const attachStyles = (hostRef) => {
89 const cmpMeta = hostRef.$cmpMeta$;
90 const elm = hostRef.$hostElement$;
91 const flags = cmpMeta.$flags$;
92 const endAttachStyles = createTime('attachStyles', cmpMeta.$tagName$);
93 const scopeId = addStyle(elm.shadowRoot ? elm.shadowRoot : elm.getRootNode(), cmpMeta);
94 if (flags & 10 /* needsScopedEncapsulation */) {
95 // only required when we're NOT using native shadow dom (slot)
96 // or this browser doesn't support native shadow dom
97 // and this host element was NOT created with SSR
98 // let's pick out the inner content for slot projection
99 // create a node to represent where the original
100 // content was first placed, which is useful later on
101 // DOM WRITE!!
102 elm['s-sc'] = scopeId;
103 elm.classList.add(scopeId + '-h');
104 }
105 endAttachStyles();
106};
107const getScopeId = (cmp, mode) => 'sc-' + (cmp.$tagName$);
108/**
109 * Default style mode id
110 */
111/**
112 * Reusable empty obj/array
113 * Don't add values to these!!
114 */
115const EMPTY_OBJ = {};
116const isDef = (v) => v != null;
117const isComplexType = (o) => {
118 // https://jsperf.com/typeof-fn-object/5
119 o = typeof o;
120 return o === 'object' || o === 'function';
121};
122/**
123 * Production h() function based on Preact by
124 * Jason Miller (@developit)
125 * Licensed under the MIT License
126 * https://github.com/developit/preact/blob/master/LICENSE
127 *
128 * Modified for Stencil's compiler and vdom
129 */
130// const stack: any[] = [];
131// export function h(nodeName: string | d.FunctionalComponent, vnodeData: d.PropsType, child?: d.ChildType): d.VNode;
132// export function h(nodeName: string | d.FunctionalComponent, vnodeData: d.PropsType, ...children: d.ChildType[]): d.VNode;
133const h = (nodeName, vnodeData, ...children) => {
134 let child = null;
135 let simple = false;
136 let lastSimple = false;
137 let vNodeChildren = [];
138 const walk = (c) => {
139 for (let i = 0; i < c.length; i++) {
140 child = c[i];
141 if (Array.isArray(child)) {
142 walk(child);
143 }
144 else if (child != null && typeof child !== 'boolean') {
145 if ((simple = typeof nodeName !== 'function' && !isComplexType(child))) {
146 child = String(child);
147 }
148 if (simple && lastSimple) {
149 // If the previous child was simple (string), we merge both
150 vNodeChildren[vNodeChildren.length - 1].$text$ += child;
151 }
152 else {
153 // Append a new vNode, if it's text, we create a text vNode
154 vNodeChildren.push(simple ? newVNode(null, child) : child);
155 }
156 lastSimple = simple;
157 }
158 }
159 };
160 walk(children);
161 const vnode = newVNode(nodeName, null);
162 vnode.$attrs$ = vnodeData;
163 if (vNodeChildren.length > 0) {
164 vnode.$children$ = vNodeChildren;
165 }
166 return vnode;
167};
168const newVNode = (tag, text) => {
169 const vnode = {
170 $flags$: 0,
171 $tag$: tag,
172 $text$: text,
173 $elm$: null,
174 $children$: null,
175 };
176 {
177 vnode.$attrs$ = null;
178 }
179 return vnode;
180};
181const Host = {};
182const isHost = (node) => node && node.$tag$ === Host;
183/**
184 * Production setAccessor() function based on Preact by
185 * Jason Miller (@developit)
186 * Licensed under the MIT License
187 * https://github.com/developit/preact/blob/master/LICENSE
188 *
189 * Modified for Stencil's compiler and vdom
190 */
191const setAccessor = (elm, memberName, oldValue, newValue, isSvg, flags) => {
192 if (oldValue !== newValue) {
193 let isProp = isMemberInElement(elm, memberName);
194 memberName.toLowerCase();
195 {
196 // Set property if it exists and it's not a SVG
197 const isComplex = isComplexType(newValue);
198 if ((isProp || (isComplex && newValue !== null)) && !isSvg) {
199 try {
200 if (!elm.tagName.includes('-')) {
201 let n = newValue == null ? '' : newValue;
202 // Workaround for Safari, moving the <input> caret when re-assigning the same valued
203 if (memberName === 'list') {
204 isProp = false;
205 // tslint:disable-next-line: triple-equals
206 }
207 else if (oldValue == null || elm[memberName] != n) {
208 elm[memberName] = n;
209 }
210 }
211 else {
212 elm[memberName] = newValue;
213 }
214 }
215 catch (e) { }
216 }
217 if (newValue == null || newValue === false) {
218 if (newValue !== false || elm.getAttribute(memberName) === '') {
219 {
220 elm.removeAttribute(memberName);
221 }
222 }
223 }
224 else if ((!isProp || flags & 4 /* isHost */ || isSvg) && !isComplex) {
225 newValue = newValue === true ? '' : newValue;
226 {
227 elm.setAttribute(memberName, newValue);
228 }
229 }
230 }
231 }
232};
233const updateElement = (oldVnode, newVnode, isSvgMode, memberName) => {
234 // if the element passed in is a shadow root, which is a document fragment
235 // then we want to be adding attrs/props to the shadow root's "host" element
236 // if it's not a shadow root, then we add attrs/props to the same element
237 const elm = newVnode.$elm$.nodeType === 11 /* DocumentFragment */ && newVnode.$elm$.host ? newVnode.$elm$.host : newVnode.$elm$;
238 const oldVnodeAttrs = (oldVnode && oldVnode.$attrs$) || EMPTY_OBJ;
239 const newVnodeAttrs = newVnode.$attrs$ || EMPTY_OBJ;
240 {
241 // remove attributes no longer present on the vnode by setting them to undefined
242 for (memberName in oldVnodeAttrs) {
243 if (!(memberName in newVnodeAttrs)) {
244 setAccessor(elm, memberName, oldVnodeAttrs[memberName], undefined, isSvgMode, newVnode.$flags$);
245 }
246 }
247 }
248 // add new & update changed attributes
249 for (memberName in newVnodeAttrs) {
250 setAccessor(elm, memberName, oldVnodeAttrs[memberName], newVnodeAttrs[memberName], isSvgMode, newVnode.$flags$);
251 }
252};
253const createElm = (oldParentVNode, newParentVNode, childIndex, parentElm) => {
254 // tslint:disable-next-line: prefer-const
255 let newVNode = newParentVNode.$children$[childIndex];
256 let i = 0;
257 let elm;
258 let childNode;
259 {
260 // create element
261 elm = newVNode.$elm$ = (doc.createElement(newVNode.$tag$));
262 // add css classes, attrs, props, listeners, etc.
263 {
264 updateElement(null, newVNode, isSvgMode);
265 }
266 if (isDef(scopeId) && elm['s-si'] !== scopeId) {
267 // if there is a scopeId and this is the initial render
268 // then let's add the scopeId as a css class
269 elm.classList.add((elm['s-si'] = scopeId));
270 }
271 if (newVNode.$children$) {
272 for (i = 0; i < newVNode.$children$.length; ++i) {
273 // create the node
274 childNode = createElm(oldParentVNode, newVNode, i);
275 // return node could have been null
276 if (childNode) {
277 // append our new node
278 elm.appendChild(childNode);
279 }
280 }
281 }
282 }
283 return elm;
284};
285const addVnodes = (parentElm, before, parentVNode, vnodes, startIdx, endIdx) => {
286 let containerElm = (parentElm);
287 let childNode;
288 if (containerElm.shadowRoot && containerElm.tagName === hostTagName) {
289 containerElm = containerElm.shadowRoot;
290 }
291 for (; startIdx <= endIdx; ++startIdx) {
292 if (vnodes[startIdx]) {
293 childNode = createElm(null, parentVNode, startIdx);
294 if (childNode) {
295 vnodes[startIdx].$elm$ = childNode;
296 containerElm.insertBefore(childNode, before);
297 }
298 }
299 }
300};
301const removeVnodes = (vnodes, startIdx, endIdx, vnode, elm) => {
302 for (; startIdx <= endIdx; ++startIdx) {
303 if ((vnode = vnodes[startIdx])) {
304 elm = vnode.$elm$;
305 // remove the vnode's element from the dom
306 elm.remove();
307 }
308 }
309};
310const updateChildren = (parentElm, oldCh, newVNode, newCh) => {
311 let oldStartIdx = 0;
312 let newStartIdx = 0;
313 let oldEndIdx = oldCh.length - 1;
314 let oldStartVnode = oldCh[0];
315 let oldEndVnode = oldCh[oldEndIdx];
316 let newEndIdx = newCh.length - 1;
317 let newStartVnode = newCh[0];
318 let newEndVnode = newCh[newEndIdx];
319 let node;
320 while (oldStartIdx <= oldEndIdx && newStartIdx <= newEndIdx) {
321 if (oldStartVnode == null) {
322 // Vnode might have been moved left
323 oldStartVnode = oldCh[++oldStartIdx];
324 }
325 else if (oldEndVnode == null) {
326 oldEndVnode = oldCh[--oldEndIdx];
327 }
328 else if (newStartVnode == null) {
329 newStartVnode = newCh[++newStartIdx];
330 }
331 else if (newEndVnode == null) {
332 newEndVnode = newCh[--newEndIdx];
333 }
334 else if (isSameVnode(oldStartVnode, newStartVnode)) {
335 patch(oldStartVnode, newStartVnode);
336 oldStartVnode = oldCh[++oldStartIdx];
337 newStartVnode = newCh[++newStartIdx];
338 }
339 else if (isSameVnode(oldEndVnode, newEndVnode)) {
340 patch(oldEndVnode, newEndVnode);
341 oldEndVnode = oldCh[--oldEndIdx];
342 newEndVnode = newCh[--newEndIdx];
343 }
344 else if (isSameVnode(oldStartVnode, newEndVnode)) {
345 patch(oldStartVnode, newEndVnode);
346 parentElm.insertBefore(oldStartVnode.$elm$, oldEndVnode.$elm$.nextSibling);
347 oldStartVnode = oldCh[++oldStartIdx];
348 newEndVnode = newCh[--newEndIdx];
349 }
350 else if (isSameVnode(oldEndVnode, newStartVnode)) {
351 patch(oldEndVnode, newStartVnode);
352 parentElm.insertBefore(oldEndVnode.$elm$, oldStartVnode.$elm$);
353 oldEndVnode = oldCh[--oldEndIdx];
354 newStartVnode = newCh[++newStartIdx];
355 }
356 else {
357 {
358 // new element
359 node = createElm(oldCh && oldCh[newStartIdx], newVNode, newStartIdx);
360 newStartVnode = newCh[++newStartIdx];
361 }
362 if (node) {
363 {
364 oldStartVnode.$elm$.parentNode.insertBefore(node, oldStartVnode.$elm$);
365 }
366 }
367 }
368 }
369 if (oldStartIdx > oldEndIdx) {
370 addVnodes(parentElm, newCh[newEndIdx + 1] == null ? null : newCh[newEndIdx + 1].$elm$, newVNode, newCh, newStartIdx, newEndIdx);
371 }
372 else if (newStartIdx > newEndIdx) {
373 removeVnodes(oldCh, oldStartIdx, oldEndIdx);
374 }
375};
376const isSameVnode = (vnode1, vnode2) => {
377 // compare if two vnode to see if they're "technically" the same
378 // need to have the same element tag, and same key to be the same
379 if (vnode1.$tag$ === vnode2.$tag$) {
380 return true;
381 }
382 return false;
383};
384const patch = (oldVNode, newVNode) => {
385 const elm = (newVNode.$elm$ = oldVNode.$elm$);
386 const oldChildren = oldVNode.$children$;
387 const newChildren = newVNode.$children$;
388 const tag = newVNode.$tag$;
389 {
390 // element node
391 {
392 if (tag === 'slot')
393 ;
394 else {
395 // either this is the first render of an element OR it's an update
396 // AND we already know it's possible it could have changed
397 // this updates the element's css classes, attrs, props, listeners, etc.
398 updateElement(oldVNode, newVNode, isSvgMode);
399 }
400 }
401 if (oldChildren !== null && newChildren !== null) {
402 // looks like there's child vnodes for both the old and new vnodes
403 updateChildren(elm, oldChildren, newVNode, newChildren);
404 }
405 else if (newChildren !== null) {
406 // add the new vnode children
407 addVnodes(elm, null, newVNode, newChildren, 0, newChildren.length - 1);
408 }
409 else if (oldChildren !== null) {
410 // no new child vnodes, but there are old child vnodes to remove
411 removeVnodes(oldChildren, 0, oldChildren.length - 1);
412 }
413 }
414};
415const renderVdom = (hostRef, renderFnResults) => {
416 const hostElm = hostRef.$hostElement$;
417 const cmpMeta = hostRef.$cmpMeta$;
418 const oldVNode = hostRef.$vnode$ || newVNode(null, null);
419 const rootVnode = isHost(renderFnResults) ? renderFnResults : h(null, null, renderFnResults);
420 hostTagName = hostElm.tagName;
421 if (cmpMeta.$attrsToReflect$) {
422 rootVnode.$attrs$ = rootVnode.$attrs$ || {};
423 cmpMeta.$attrsToReflect$.map(([propName, attribute]) => (rootVnode.$attrs$[attribute] = hostElm[propName]));
424 }
425 rootVnode.$tag$ = null;
426 rootVnode.$flags$ |= 4 /* isHost */;
427 hostRef.$vnode$ = rootVnode;
428 rootVnode.$elm$ = oldVNode.$elm$ = (hostElm.shadowRoot || hostElm );
429 {
430 scopeId = hostElm['s-sc'];
431 }
432 // synchronous patch
433 patch(oldVNode, rootVnode);
434};
435const getElement = (ref) => (getHostRef(ref).$hostElement$ );
436const emitEvent = (elm, name, opts) => {
437 const ev = plt.ce(name, opts);
438 elm.dispatchEvent(ev);
439 return ev;
440};
441const attachToAncestor = (hostRef, ancestorComponent) => {
442 if (ancestorComponent && !hostRef.$onRenderResolve$ && ancestorComponent['s-p']) {
443 ancestorComponent['s-p'].push(new Promise(r => (hostRef.$onRenderResolve$ = r)));
444 }
445};
446const scheduleUpdate = (hostRef, isInitialLoad) => {
447 {
448 hostRef.$flags$ |= 16 /* isQueuedForUpdate */;
449 }
450 if (hostRef.$flags$ & 4 /* isWaitingForChildren */) {
451 hostRef.$flags$ |= 512 /* needsRerender */;
452 return;
453 }
454 attachToAncestor(hostRef, hostRef.$ancestorComponent$);
455 // there is no ancestor component or the ancestor component
456 // has already fired off its lifecycle update then
457 // fire off the initial update
458 const dispatch = () => dispatchHooks(hostRef, isInitialLoad);
459 return writeTask(dispatch) ;
460};
461const dispatchHooks = (hostRef, isInitialLoad) => {
462 const endSchedule = createTime('scheduleUpdate', hostRef.$cmpMeta$.$tagName$);
463 const instance = hostRef.$lazyInstance$ ;
464 let promise;
465 endSchedule();
466 return then(promise, () => updateComponent(hostRef, instance, isInitialLoad));
467};
468const updateComponent = async (hostRef, instance, isInitialLoad) => {
469 // updateComponent
470 const elm = hostRef.$hostElement$;
471 const endUpdate = createTime('update', hostRef.$cmpMeta$.$tagName$);
472 const rc = elm['s-rc'];
473 if (isInitialLoad) {
474 // DOM WRITE!
475 attachStyles(hostRef);
476 }
477 const endRender = createTime('render', hostRef.$cmpMeta$.$tagName$);
478 {
479 callRender(hostRef, instance);
480 }
481 if (rc) {
482 // ok, so turns out there are some child host elements
483 // waiting on this parent element to load
484 // let's fire off all update callbacks waiting
485 rc.map(cb => cb());
486 elm['s-rc'] = undefined;
487 }
488 endRender();
489 endUpdate();
490 {
491 const childrenPromises = elm['s-p'];
492 const postUpdate = () => postUpdateComponent(hostRef);
493 if (childrenPromises.length === 0) {
494 postUpdate();
495 }
496 else {
497 Promise.all(childrenPromises).then(postUpdate);
498 hostRef.$flags$ |= 4 /* isWaitingForChildren */;
499 childrenPromises.length = 0;
500 }
501 }
502};
503const callRender = (hostRef, instance, elm) => {
504 try {
505 instance = instance.render() ;
506 {
507 hostRef.$flags$ &= ~16 /* isQueuedForUpdate */;
508 }
509 {
510 hostRef.$flags$ |= 2 /* hasRendered */;
511 }
512 {
513 {
514 // looks like we've got child nodes to render into this host element
515 // or we need to update the css class/attrs on the host element
516 // DOM WRITE!
517 {
518 renderVdom(hostRef, instance);
519 }
520 }
521 }
522 }
523 catch (e) {
524 consoleError(e, hostRef.$hostElement$);
525 }
526 return null;
527};
528const postUpdateComponent = (hostRef) => {
529 const tagName = hostRef.$cmpMeta$.$tagName$;
530 const elm = hostRef.$hostElement$;
531 const endPostUpdate = createTime('postUpdate', tagName);
532 const ancestorComponent = hostRef.$ancestorComponent$;
533 if (!(hostRef.$flags$ & 64 /* hasLoadedComponent */)) {
534 hostRef.$flags$ |= 64 /* hasLoadedComponent */;
535 {
536 // DOM WRITE!
537 addHydratedFlag(elm);
538 }
539 endPostUpdate();
540 {
541 hostRef.$onReadyResolve$(elm);
542 if (!ancestorComponent) {
543 appDidLoad();
544 }
545 }
546 }
547 else {
548 endPostUpdate();
549 }
550 // load events fire from bottom to top
551 // the deepest elements load first then bubbles up
552 {
553 if (hostRef.$onRenderResolve$) {
554 hostRef.$onRenderResolve$();
555 hostRef.$onRenderResolve$ = undefined;
556 }
557 if (hostRef.$flags$ & 512 /* needsRerender */) {
558 nextTick(() => scheduleUpdate(hostRef, false));
559 }
560 hostRef.$flags$ &= ~(4 /* isWaitingForChildren */ | 512 /* needsRerender */);
561 }
562 // ( •_•)
563 // ( •_•)>⌐■-■
564 // (⌐■_■)
565};
566const appDidLoad = (who) => {
567 // on appload
568 // we have finish the first big initial render
569 {
570 addHydratedFlag(doc.documentElement);
571 }
572 nextTick(() => emitEvent(win, 'appload', { detail: { namespace: NAMESPACE } }));
573};
574const safeCall = (instance, method, arg) => {
575 if (instance && instance[method]) {
576 try {
577 return instance[method](arg);
578 }
579 catch (e) {
580 consoleError(e);
581 }
582 }
583 return undefined;
584};
585const then = (promise, thenFn) => {
586 return promise && promise.then ? promise.then(thenFn) : thenFn();
587};
588const addHydratedFlag = (elm) => (elm.classList.add('hydrated') );
589const parsePropertyValue = (propValue, propType) => {
590 // ensure this value is of the correct prop type
591 if (propValue != null && !isComplexType(propValue)) {
592 if (propType & 1 /* String */) {
593 // could have been passed as a number or boolean
594 // but we still want it as a string
595 return String(propValue);
596 }
597 // redundant return here for better minification
598 return propValue;
599 }
600 // not sure exactly what type we want
601 // so no need to change to a different type
602 return propValue;
603};
604const getValue = (ref, propName) => getHostRef(ref).$instanceValues$.get(propName);
605const setValue = (ref, propName, newVal, cmpMeta) => {
606 // check our new property value against our internal value
607 const hostRef = getHostRef(ref);
608 const oldVal = hostRef.$instanceValues$.get(propName);
609 const flags = hostRef.$flags$;
610 const instance = hostRef.$lazyInstance$ ;
611 newVal = parsePropertyValue(newVal, cmpMeta.$members$[propName][0]);
612 if ((!(flags & 8 /* isConstructingInstance */) || oldVal === undefined) && newVal !== oldVal) {
613 // gadzooks! the property's value has changed!!
614 // set our new value!
615 hostRef.$instanceValues$.set(propName, newVal);
616 if (instance) {
617 if ((flags & (2 /* hasRendered */ | 16 /* isQueuedForUpdate */)) === 2 /* hasRendered */) {
618 // looks like this value actually changed, so we've got work to do!
619 // but only if we've already rendered, otherwise just chill out
620 // queue that we need to do an update, but don't worry about queuing
621 // up millions cuz this function ensures it only runs once
622 scheduleUpdate(hostRef, false);
623 }
624 }
625 }
626};
627const proxyComponent = (Cstr, cmpMeta, flags) => {
628 if (cmpMeta.$members$) {
629 // It's better to have a const than two Object.entries()
630 const members = Object.entries(cmpMeta.$members$);
631 const prototype = Cstr.prototype;
632 members.map(([memberName, [memberFlags]]) => {
633 if ((memberFlags & 31 /* Prop */ || ((flags & 2 /* proxyState */) && memberFlags & 32 /* State */))) {
634 // proxyComponent - prop
635 Object.defineProperty(prototype, memberName, {
636 get() {
637 // proxyComponent, get value
638 return getValue(this, memberName);
639 },
640 set(newValue) {
641 // proxyComponent, set value
642 setValue(this, memberName, newValue, cmpMeta);
643 },
644 configurable: true,
645 enumerable: true,
646 });
647 }
648 });
649 if ((flags & 1 /* isElementConstructor */)) {
650 const attrNameToPropName = new Map();
651 prototype.attributeChangedCallback = function (attrName, _oldValue, newValue) {
652 plt.jmp(() => {
653 const propName = attrNameToPropName.get(attrName);
654 this[propName] = newValue === null && typeof this[propName] === 'boolean' ? false : newValue;
655 });
656 };
657 // create an array of attributes to observe
658 // and also create a map of html attribute name to js property name
659 Cstr.observedAttributes = members
660 .filter(([_, m]) => m[0] & 15 /* HasAttribute */) // filter to only keep props that should match attributes
661 .map(([propName, m]) => {
662 const attrName = m[1] || propName;
663 attrNameToPropName.set(attrName, propName);
664 if (m[0] & 512 /* ReflectAttr */) {
665 cmpMeta.$attrsToReflect$.push([propName, attrName]);
666 }
667 return attrName;
668 });
669 }
670 }
671 return Cstr;
672};
673const initializeComponent = async (elm, hostRef, cmpMeta, hmrVersionId, Cstr) => {
674 // initializeComponent
675 if ((hostRef.$flags$ & 32 /* hasInitializedComponent */) === 0) {
676 {
677 // we haven't initialized this element yet
678 hostRef.$flags$ |= 32 /* hasInitializedComponent */;
679 // lazy loaded components
680 // request the component's implementation to be
681 // wired up with the host element
682 Cstr = loadModule(cmpMeta);
683 if (Cstr.then) {
684 // Await creates a micro-task avoid if possible
685 const endLoad = uniqueTime();
686 Cstr = await Cstr;
687 endLoad();
688 }
689 if (!Cstr.isProxied) {
690 proxyComponent(Cstr, cmpMeta, 2 /* proxyState */);
691 Cstr.isProxied = true;
692 }
693 const endNewInstance = createTime('createInstance', cmpMeta.$tagName$);
694 // ok, time to construct the instance
695 // but let's keep track of when we start and stop
696 // so that the getters/setters don't incorrectly step on data
697 {
698 hostRef.$flags$ |= 8 /* isConstructingInstance */;
699 }
700 // construct the lazy-loaded component implementation
701 // passing the hostRef is very important during
702 // construction in order to directly wire together the
703 // host element and the lazy-loaded instance
704 try {
705 new Cstr(hostRef);
706 }
707 catch (e) {
708 consoleError(e);
709 }
710 {
711 hostRef.$flags$ &= ~8 /* isConstructingInstance */;
712 }
713 endNewInstance();
714 fireConnectedCallback(hostRef.$lazyInstance$);
715 }
716 if (Cstr.style) {
717 // this component has styles but we haven't registered them yet
718 let style = Cstr.style;
719 const scopeId = getScopeId(cmpMeta);
720 if (!styles.has(scopeId)) {
721 const endRegisterStyles = createTime('registerStyles', cmpMeta.$tagName$);
722 registerStyle(scopeId, style, !!(cmpMeta.$flags$ & 1 /* shadowDomEncapsulation */));
723 endRegisterStyles();
724 }
725 }
726 }
727 // we've successfully created a lazy instance
728 const ancestorComponent = hostRef.$ancestorComponent$;
729 const schedule = () => scheduleUpdate(hostRef, true);
730 if (ancestorComponent && ancestorComponent['s-rc']) {
731 // this is the intial load and this component it has an ancestor component
732 // but the ancestor component has NOT fired its will update lifecycle yet
733 // so let's just cool our jets and wait for the ancestor to continue first
734 // this will get fired off when the ancestor component
735 // finally gets around to rendering its lazy self
736 // fire off the initial update
737 ancestorComponent['s-rc'].push(schedule);
738 }
739 else {
740 schedule();
741 }
742};
743const fireConnectedCallback = (instance) => {
744 {
745 safeCall(instance, 'connectedCallback');
746 }
747};
748const connectedCallback = (elm) => {
749 if ((plt.$flags$ & 1 /* isTmpDisconnected */) === 0) {
750 const hostRef = getHostRef(elm);
751 const cmpMeta = hostRef.$cmpMeta$;
752 const endConnected = createTime('connectedCallback', cmpMeta.$tagName$);
753 if (!(hostRef.$flags$ & 1 /* hasConnected */)) {
754 // first time this component has connected
755 hostRef.$flags$ |= 1 /* hasConnected */;
756 {
757 // find the first ancestor component (if there is one) and register
758 // this component as one of the actively loading child components for its ancestor
759 let ancestorComponent = elm;
760 while ((ancestorComponent = ancestorComponent.parentNode || ancestorComponent.host)) {
761 // climb up the ancestors looking for the first
762 // component that hasn't finished its lifecycle update yet
763 if (ancestorComponent['s-p']) {
764 // we found this components first ancestor component
765 // keep a reference to this component's ancestor component
766 attachToAncestor(hostRef, (hostRef.$ancestorComponent$ = ancestorComponent));
767 break;
768 }
769 }
770 }
771 // Lazy properties
772 // https://developers.google.com/web/fundamentals/web-components/best-practices#lazy-properties
773 if (cmpMeta.$members$) {
774 Object.entries(cmpMeta.$members$).map(([memberName, [memberFlags]]) => {
775 if (memberFlags & 31 /* Prop */ && elm.hasOwnProperty(memberName)) {
776 const value = elm[memberName];
777 delete elm[memberName];
778 elm[memberName] = value;
779 }
780 });
781 }
782 {
783 initializeComponent(elm, hostRef, cmpMeta);
784 }
785 }
786 else {
787 // fire off connectedCallback() on component instance
788 fireConnectedCallback(hostRef.$lazyInstance$);
789 }
790 endConnected();
791 }
792};
793const disconnectedCallback = (elm) => {
794 if ((plt.$flags$ & 1 /* isTmpDisconnected */) === 0) {
795 getHostRef(elm);
796 }
797};
798const bootstrapLazy = (lazyBundles, options = {}) => {
799 const endBootstrap = createTime();
800 const cmpTags = [];
801 const exclude = options.exclude || [];
802 const customElements = win.customElements;
803 const head = doc.head;
804 const metaCharset = /*@__PURE__*/ head.querySelector('meta[charset]');
805 const visibilityStyle = /*@__PURE__*/ doc.createElement('style');
806 const deferredConnectedCallbacks = [];
807 let appLoadFallback;
808 let isBootstrapping = true;
809 Object.assign(plt, options);
810 plt.$resourcesUrl$ = new URL(options.resourcesUrl || './', doc.baseURI).href;
811 lazyBundles.map(lazyBundle => lazyBundle[1].map(compactMeta => {
812 const cmpMeta = {
813 $flags$: compactMeta[0],
814 $tagName$: compactMeta[1],
815 $members$: compactMeta[2],
816 $listeners$: compactMeta[3],
817 };
818 {
819 cmpMeta.$members$ = compactMeta[2];
820 }
821 {
822 cmpMeta.$attrsToReflect$ = [];
823 }
824 const tagName = cmpMeta.$tagName$;
825 const HostElement = class extends HTMLElement {
826 // StencilLazyHost
827 constructor(self) {
828 // @ts-ignore
829 super(self);
830 self = this;
831 registerHost(self, cmpMeta);
832 if (cmpMeta.$flags$ & 1 /* shadowDomEncapsulation */) {
833 // this component is using shadow dom
834 // and this browser supports shadow dom
835 // add the read-only property "shadowRoot" to the host element
836 // adding the shadow root build conditionals to minimize runtime
837 {
838 {
839 self.attachShadow({ mode: 'open' });
840 }
841 }
842 }
843 }
844 connectedCallback() {
845 if (appLoadFallback) {
846 clearTimeout(appLoadFallback);
847 appLoadFallback = null;
848 }
849 if (isBootstrapping) {
850 // connectedCallback will be processed once all components have been registered
851 deferredConnectedCallbacks.push(this);
852 }
853 else {
854 plt.jmp(() => connectedCallback(this));
855 }
856 }
857 disconnectedCallback() {
858 plt.jmp(() => disconnectedCallback(this));
859 }
860 componentOnReady() {
861 return getHostRef(this).$onReadyPromise$;
862 }
863 };
864 cmpMeta.$lazyBundleId$ = lazyBundle[0];
865 if (!exclude.includes(tagName) && !customElements.get(tagName)) {
866 cmpTags.push(tagName);
867 customElements.define(tagName, proxyComponent(HostElement, cmpMeta, 1 /* isElementConstructor */));
868 }
869 }));
870 {
871 visibilityStyle.innerHTML = cmpTags + HYDRATED_CSS;
872 visibilityStyle.setAttribute('data-styles', '');
873 head.insertBefore(visibilityStyle, metaCharset ? metaCharset.nextSibling : head.firstChild);
874 }
875 // Process deferred connectedCallbacks now all components have been registered
876 isBootstrapping = false;
877 if (deferredConnectedCallbacks.length) {
878 deferredConnectedCallbacks.map(host => host.connectedCallback());
879 }
880 else {
881 {
882 plt.jmp(() => (appLoadFallback = setTimeout(appDidLoad, 30)));
883 }
884 }
885 // Fallback appLoad event
886 endBootstrap();
887};
888const hostRefs = new WeakMap();
889const getHostRef = (ref) => hostRefs.get(ref);
890const registerInstance = (lazyInstance, hostRef) => hostRefs.set((hostRef.$lazyInstance$ = lazyInstance), hostRef);
891const registerHost = (elm, cmpMeta) => {
892 const hostRef = {
893 $flags$: 0,
894 $hostElement$: elm,
895 $cmpMeta$: cmpMeta,
896 $instanceValues$: new Map(),
897 };
898 {
899 hostRef.$onReadyPromise$ = new Promise(r => (hostRef.$onReadyResolve$ = r));
900 elm['s-p'] = [];
901 elm['s-rc'] = [];
902 }
903 return hostRefs.set(elm, hostRef);
904};
905const isMemberInElement = (elm, memberName) => memberName in elm;
906const consoleError = (e, el) => (0, console.error)(e, el);
907const cmpModules = /*@__PURE__*/ new Map();
908const loadModule = (cmpMeta, hostRef, hmrVersionId) => {
909 // loadModuleImport
910 const exportName = cmpMeta.$tagName$.replace(/-/g, '_');
911 const bundleId = cmpMeta.$lazyBundleId$;
912 const module = cmpModules.get(bundleId) ;
913 if (module) {
914 return module[exportName];
915 }
916 return import(
917 /* webpackInclude: /\.entry\.js$/ */
918 /* webpackExclude: /\.system\.entry\.js$/ */
919 /* webpackMode: "lazy" */
920 `./${bundleId}.entry.js${''}`).then(importedModule => {
921 {
922 cmpModules.set(bundleId, importedModule);
923 }
924 return importedModule[exportName];
925 }, consoleError);
926};
927const styles = new Map();
928const queueDomReads = [];
929const queueDomWrites = [];
930const queueTask = (queue, write) => (cb) => {
931 queue.push(cb);
932 if (!queuePending) {
933 queuePending = true;
934 if (write && plt.$flags$ & 4 /* queueSync */) {
935 nextTick(flush);
936 }
937 else {
938 plt.raf(flush);
939 }
940 }
941};
942const consume = (queue) => {
943 for (let i = 0; i < queue.length; i++) {
944 try {
945 queue[i](performance.now());
946 }
947 catch (e) {
948 consoleError(e);
949 }
950 }
951 queue.length = 0;
952};
953const flush = () => {
954 // always force a bunch of medium callbacks to run, but still have
955 // a throttle on how many can run in a certain time
956 // DOM READS!!!
957 consume(queueDomReads);
958 // DOM WRITES!!!
959 {
960 consume(queueDomWrites);
961 if ((queuePending = queueDomReads.length > 0)) {
962 // still more to do yet, but we've run out of time
963 // let's let this thing cool off and try again in the next tick
964 plt.raf(flush);
965 }
966 }
967};
968const nextTick = /*@__PURE__*/ (cb) => promiseResolve().then(cb);
969const writeTask = /*@__PURE__*/ queueTask(queueDomWrites, true);
970
971/* Sutton SignWriting TrueType Font Module v1.2.0 (https://github.com/sutton-signwriting/font-ttf), author: Steve Slevinski (https://SteveSlevinski.me), license: MIT */
972const t=function(t=""){if(!document.getElementById("SgnwFontCss")){const n=document.createElement("style");n.setAttribute("id","SgnwFontCss"),n.appendChild(document.createTextNode(`\n @font-face {\n font-family: "SuttonSignWritingLine";\n src: \n local('SuttonSignWritingLine'),\n ${t?`url('${t}SuttonSignWritingLine.ttf') format('truetype'),`:""}\n url('https://cdn.jsdelivr.net/npm/@sutton-signwriting/font-ttf@1.0.0/font/SuttonSignWritingLine.ttf') format('truetype');\n }\n @font-face {\n font-family: "SuttonSignWritingFill";\n src: \n local('SuttonSignWritingFill'),\n ${t?`url('${t}SuttonSignWritingFill.ttf') format('truetype'),`:""}\n url('https://cdn.jsdelivr.net/npm/@sutton-signwriting/font-ttf@1.0.0/font/SuttonSignWritingFill.ttf') format('truetype');\n }\n @font-face {\n font-family: "SuttonSignWritingOneD";\n src: \n local('SuttonSignWritingOneD'),\n ${t?`url('${t}SuttonSignWritingOneD.ttf') format('truetype'),`:""}\n url('https://cdn.jsdelivr.net/npm/@sutton-signwriting/font-ttf@1.0.0/font/SuttonSignWritingOneD.ttf') format('truetype');\n }\n `)),document.head.appendChild(n);}};let n={};const e=document.createElement("canvas");e.width=152,e.height=152;const i=e.getContext("2d"),o=function(t){if(t in n)return [...n[t]];i.clearRect(0,0,152,152),i.font="60px 'SuttonSignWritingLine'",i.fillText(String.fromCodePoint(t+983040),0,0);const e=i.getImageData(0,0,152,152).data;let o,r,l,f;t:for(o=151;o>=0;o--)for(r=0;r<152;r+=1)for(f=0;f<4;f+=1)if(l=4*o+4*r*152+f,e[l])break t;var c=o;t:for(r=151;r>=0;r--)for(o=0;o<c;o+=1)for(f=0;f<4;f+=1)if(l=4*o+4*r*152+f,e[l])break t;var u=r+1;if(c=Math.ceil(c/2),u=Math.ceil(u/2),14394==t&&(c=19),[10468,10480,10496,10512,10500,10532,10548,10862,10878,10894,11058,11074,11476,11488,11492,11504,11508,11520,10516,10910,10926,11042,11082,10942].includes(t)&&(c=20),31921==t&&(c=22),38460==t&&(c=23),[20164,20212].includes(t)&&(c=25),31894==t&&(c=28),46698==t&&(c=29),29606==t&&(c=30),44855==t&&(c=40),32667==t&&(c=50),[11088,11474,11490,11506].includes(t)&&(u=20),6285==t&&(u=21),40804==t&&(u=31),41475==t&&(u=36),0==c&&0==u){const n={9:[15,30],10:[21,30],11:[30,15],12:[30,21],13:[15,30],14:[21,30]};t in n&&(c=n[t][0],u=n[t][1]);}return 0!=c||0!=u?(n[t]=[c,u],[c,u]):void 0},l=function(t){return String.fromCodePoint(t+1048576)},c=function(t){let n=!1,e=!1;u(()=>{n=!0;}),a(()=>{e=!0;});const i=setInterval((function(){n&&e&&(clearInterval(i),t());}),100);},u=function(t){if(o(1))t();else {const n=setInterval((function(){o(1)&&(clearInterval(n),t());}),100);}},a=function(t){const n=function(){const t=document.createElement("canvas");t.width=15,t.height=30;const n=t.getContext("2d");n.font="30px 'SuttonSignWritingFill'",n.fillText(l(1),0,0);return !n.getImageData(0,0,15,30).data.every(t=>0===t)};if(n())t();else {const e=setInterval((function(){n()&&(clearInterval(e),t());}),100);}};
973
974// @ts-ignore
975window['sgnw'] = false;
976const event = new Event('sgnw');
977const rgb2hex = function (rgba) {
978 return rgba.replace(/rgba?\((.+?)\)/ig, (_, values) => {
979 let parts = values.split(',');
980 if (parts.length == 4 && (parseInt(parts[3]) == 0)) {
981 return 'transparent';
982 }
983 else {
984 return parts.slice(0, 3)
985 .map(str => parseInt(str, 10).toString(16).padStart(2, '0'))
986 .join('');
987 }
988 });
989};
990const rgba2hex = function (rgba) {
991 return rgba.replace(/rgba?\((.+?)\)/ig, (_, values) => {
992 let parts = values.split(',');
993 if (parts.length == 4 && (parseInt(parts[3]) < 1)) {
994 return 'transparent';
995 }
996 else {
997 return parts.slice(0, 3)
998 .map(str => parseInt(str, 10).toString(16).padStart(2, '0'))
999 .join('');
1000 }
1001 });
1002};
1003function appGlobalScript () {
1004 t();
1005 c(() => {
1006 window['sgnw'] = true;
1007 window.dispatchEvent(event);
1008 });
1009}
1010
1011export { Host as H, appGlobalScript as a, bootstrapLazy as b, rgba2hex as c, rgb2hex as d, getElement as g, h, promiseResolve as p, registerInstance as r };