1 | const NAMESPACE = 'sgnw-components';
|
2 |
|
3 | let scopeId;
|
4 | let hostTagName;
|
5 | let isSvgMode = false;
|
6 | let queuePending = false;
|
7 | const win = typeof window !== 'undefined' ? window : {};
|
8 | const doc = win.document || { head: {} };
|
9 | const 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 | };
|
18 | const promiseResolve = (v) => Promise.resolve(v);
|
19 | const supportsConstructibleStylesheets = (() => {
|
20 | try {
|
21 | new CSSStyleSheet();
|
22 | return typeof (new CSSStyleSheet()).replace === 'function';
|
23 | }
|
24 | catch (e) { }
|
25 | return false;
|
26 | })()
|
27 | ;
|
28 | const HYDRATED_CSS = '{visibility:hidden}.hydrated{visibility:inherit}';
|
29 | const createTime = (fnName, tagName = '') => {
|
30 | {
|
31 | return () => {
|
32 | return;
|
33 | };
|
34 | }
|
35 | };
|
36 | const uniqueTime = (key, measureText) => {
|
37 | {
|
38 | return () => {
|
39 | return;
|
40 | };
|
41 | }
|
42 | };
|
43 | const rootAppliedStyles = new WeakMap();
|
44 | const 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 | };
|
55 | const addStyle = (styleContainerNode, cmpMeta, mode, hostElm) => {
|
56 | let scopeId = getScopeId(cmpMeta);
|
57 | let style = styles.get(scopeId);
|
58 |
|
59 |
|
60 | styleContainerNode = styleContainerNode.nodeType === 11 ? 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 | };
|
88 | const 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 ) {
|
95 |
|
96 |
|
97 |
|
98 |
|
99 |
|
100 |
|
101 |
|
102 | elm['s-sc'] = scopeId;
|
103 | elm.classList.add(scopeId + '-h');
|
104 | }
|
105 | endAttachStyles();
|
106 | };
|
107 | const getScopeId = (cmp, mode) => 'sc-' + (cmp.$tagName$);
|
108 |
|
109 |
|
110 |
|
111 |
|
112 |
|
113 |
|
114 |
|
115 | const EMPTY_OBJ = {};
|
116 | const isDef = (v) => v != null;
|
117 | const isComplexType = (o) => {
|
118 |
|
119 | o = typeof o;
|
120 | return o === 'object' || o === 'function';
|
121 | };
|
122 |
|
123 |
|
124 |
|
125 |
|
126 |
|
127 |
|
128 |
|
129 |
|
130 |
|
131 |
|
132 |
|
133 | const 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 |
|
150 | vNodeChildren[vNodeChildren.length - 1].$text$ += child;
|
151 | }
|
152 | else {
|
153 |
|
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 | };
|
168 | const 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 | };
|
181 | const Host = {};
|
182 | const isHost = (node) => node && node.$tag$ === Host;
|
183 |
|
184 |
|
185 |
|
186 |
|
187 |
|
188 |
|
189 |
|
190 |
|
191 | const setAccessor = (elm, memberName, oldValue, newValue, isSvg, flags) => {
|
192 | if (oldValue !== newValue) {
|
193 | let isProp = isMemberInElement(elm, memberName);
|
194 | memberName.toLowerCase();
|
195 | {
|
196 |
|
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 |
|
203 | if (memberName === 'list') {
|
204 | isProp = false;
|
205 |
|
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 || isSvg) && !isComplex) {
|
225 | newValue = newValue === true ? '' : newValue;
|
226 | {
|
227 | elm.setAttribute(memberName, newValue);
|
228 | }
|
229 | }
|
230 | }
|
231 | }
|
232 | };
|
233 | const updateElement = (oldVnode, newVnode, isSvgMode, memberName) => {
|
234 |
|
235 |
|
236 |
|
237 | const elm = newVnode.$elm$.nodeType === 11 && 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 |
|
242 | for (memberName in oldVnodeAttrs) {
|
243 | if (!(memberName in newVnodeAttrs)) {
|
244 | setAccessor(elm, memberName, oldVnodeAttrs[memberName], undefined, isSvgMode, newVnode.$flags$);
|
245 | }
|
246 | }
|
247 | }
|
248 |
|
249 | for (memberName in newVnodeAttrs) {
|
250 | setAccessor(elm, memberName, oldVnodeAttrs[memberName], newVnodeAttrs[memberName], isSvgMode, newVnode.$flags$);
|
251 | }
|
252 | };
|
253 | const createElm = (oldParentVNode, newParentVNode, childIndex, parentElm) => {
|
254 |
|
255 | let newVNode = newParentVNode.$children$[childIndex];
|
256 | let i = 0;
|
257 | let elm;
|
258 | let childNode;
|
259 | {
|
260 |
|
261 | elm = newVNode.$elm$ = (doc.createElement(newVNode.$tag$));
|
262 |
|
263 | {
|
264 | updateElement(null, newVNode, isSvgMode);
|
265 | }
|
266 | if (isDef(scopeId) && elm['s-si'] !== scopeId) {
|
267 |
|
268 |
|
269 | elm.classList.add((elm['s-si'] = scopeId));
|
270 | }
|
271 | if (newVNode.$children$) {
|
272 | for (i = 0; i < newVNode.$children$.length; ++i) {
|
273 |
|
274 | childNode = createElm(oldParentVNode, newVNode, i);
|
275 |
|
276 | if (childNode) {
|
277 |
|
278 | elm.appendChild(childNode);
|
279 | }
|
280 | }
|
281 | }
|
282 | }
|
283 | return elm;
|
284 | };
|
285 | const 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 | };
|
301 | const removeVnodes = (vnodes, startIdx, endIdx, vnode, elm) => {
|
302 | for (; startIdx <= endIdx; ++startIdx) {
|
303 | if ((vnode = vnodes[startIdx])) {
|
304 | elm = vnode.$elm$;
|
305 |
|
306 | elm.remove();
|
307 | }
|
308 | }
|
309 | };
|
310 | const 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 |
|
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 |
|
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 | };
|
376 | const isSameVnode = (vnode1, vnode2) => {
|
377 |
|
378 |
|
379 | if (vnode1.$tag$ === vnode2.$tag$) {
|
380 | return true;
|
381 | }
|
382 | return false;
|
383 | };
|
384 | const 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 |
|
391 | {
|
392 | if (tag === 'slot')
|
393 | ;
|
394 | else {
|
395 |
|
396 |
|
397 |
|
398 | updateElement(oldVNode, newVNode, isSvgMode);
|
399 | }
|
400 | }
|
401 | if (oldChildren !== null && newChildren !== null) {
|
402 |
|
403 | updateChildren(elm, oldChildren, newVNode, newChildren);
|
404 | }
|
405 | else if (newChildren !== null) {
|
406 |
|
407 | addVnodes(elm, null, newVNode, newChildren, 0, newChildren.length - 1);
|
408 | }
|
409 | else if (oldChildren !== null) {
|
410 |
|
411 | removeVnodes(oldChildren, 0, oldChildren.length - 1);
|
412 | }
|
413 | }
|
414 | };
|
415 | const 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 ;
|
427 | hostRef.$vnode$ = rootVnode;
|
428 | rootVnode.$elm$ = oldVNode.$elm$ = (hostElm.shadowRoot || hostElm );
|
429 | {
|
430 | scopeId = hostElm['s-sc'];
|
431 | }
|
432 |
|
433 | patch(oldVNode, rootVnode);
|
434 | };
|
435 | const getElement = (ref) => (getHostRef(ref).$hostElement$ );
|
436 | const emitEvent = (elm, name, opts) => {
|
437 | const ev = plt.ce(name, opts);
|
438 | elm.dispatchEvent(ev);
|
439 | return ev;
|
440 | };
|
441 | const attachToAncestor = (hostRef, ancestorComponent) => {
|
442 | if (ancestorComponent && !hostRef.$onRenderResolve$ && ancestorComponent['s-p']) {
|
443 | ancestorComponent['s-p'].push(new Promise(r => (hostRef.$onRenderResolve$ = r)));
|
444 | }
|
445 | };
|
446 | const scheduleUpdate = (hostRef, isInitialLoad) => {
|
447 | {
|
448 | hostRef.$flags$ |= 16 ;
|
449 | }
|
450 | if (hostRef.$flags$ & 4 ) {
|
451 | hostRef.$flags$ |= 512 ;
|
452 | return;
|
453 | }
|
454 | attachToAncestor(hostRef, hostRef.$ancestorComponent$);
|
455 |
|
456 |
|
457 |
|
458 | const dispatch = () => dispatchHooks(hostRef, isInitialLoad);
|
459 | return writeTask(dispatch) ;
|
460 | };
|
461 | const 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 | };
|
468 | const updateComponent = async (hostRef, instance, isInitialLoad) => {
|
469 |
|
470 | const elm = hostRef.$hostElement$;
|
471 | const endUpdate = createTime('update', hostRef.$cmpMeta$.$tagName$);
|
472 | const rc = elm['s-rc'];
|
473 | if (isInitialLoad) {
|
474 |
|
475 | attachStyles(hostRef);
|
476 | }
|
477 | const endRender = createTime('render', hostRef.$cmpMeta$.$tagName$);
|
478 | {
|
479 | callRender(hostRef, instance);
|
480 | }
|
481 | if (rc) {
|
482 |
|
483 |
|
484 |
|
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 ;
|
499 | childrenPromises.length = 0;
|
500 | }
|
501 | }
|
502 | };
|
503 | const callRender = (hostRef, instance, elm) => {
|
504 | try {
|
505 | instance = instance.render() ;
|
506 | {
|
507 | hostRef.$flags$ &= ~16 ;
|
508 | }
|
509 | {
|
510 | hostRef.$flags$ |= 2 ;
|
511 | }
|
512 | {
|
513 | {
|
514 |
|
515 |
|
516 |
|
517 | {
|
518 | renderVdom(hostRef, instance);
|
519 | }
|
520 | }
|
521 | }
|
522 | }
|
523 | catch (e) {
|
524 | consoleError(e, hostRef.$hostElement$);
|
525 | }
|
526 | return null;
|
527 | };
|
528 | const 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 )) {
|
534 | hostRef.$flags$ |= 64 ;
|
535 | {
|
536 |
|
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 |
|
551 |
|
552 | {
|
553 | if (hostRef.$onRenderResolve$) {
|
554 | hostRef.$onRenderResolve$();
|
555 | hostRef.$onRenderResolve$ = undefined;
|
556 | }
|
557 | if (hostRef.$flags$ & 512 ) {
|
558 | nextTick(() => scheduleUpdate(hostRef, false));
|
559 | }
|
560 | hostRef.$flags$ &= ~(4 | 512 );
|
561 | }
|
562 |
|
563 |
|
564 |
|
565 | };
|
566 | const appDidLoad = (who) => {
|
567 |
|
568 |
|
569 | {
|
570 | addHydratedFlag(doc.documentElement);
|
571 | }
|
572 | nextTick(() => emitEvent(win, 'appload', { detail: { namespace: NAMESPACE } }));
|
573 | };
|
574 | const 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 | };
|
585 | const then = (promise, thenFn) => {
|
586 | return promise && promise.then ? promise.then(thenFn) : thenFn();
|
587 | };
|
588 | const addHydratedFlag = (elm) => (elm.classList.add('hydrated') );
|
589 | const parsePropertyValue = (propValue, propType) => {
|
590 |
|
591 | if (propValue != null && !isComplexType(propValue)) {
|
592 | if (propType & 1 ) {
|
593 |
|
594 |
|
595 | return String(propValue);
|
596 | }
|
597 |
|
598 | return propValue;
|
599 | }
|
600 |
|
601 |
|
602 | return propValue;
|
603 | };
|
604 | const getValue = (ref, propName) => getHostRef(ref).$instanceValues$.get(propName);
|
605 | const setValue = (ref, propName, newVal, cmpMeta) => {
|
606 |
|
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 |
|
614 |
|
615 | hostRef.$instanceValues$.set(propName, newVal);
|
616 | if (instance) {
|
617 | if ((flags & (2 | 16 )) === 2 ) {
|
618 |
|
619 |
|
620 |
|
621 |
|
622 | scheduleUpdate(hostRef, false);
|
623 | }
|
624 | }
|
625 | }
|
626 | };
|
627 | const proxyComponent = (Cstr, cmpMeta, flags) => {
|
628 | if (cmpMeta.$members$) {
|
629 |
|
630 | const members = Object.entries(cmpMeta.$members$);
|
631 | const prototype = Cstr.prototype;
|
632 | members.map(([memberName, [memberFlags]]) => {
|
633 | if ((memberFlags & 31 || ((flags & 2 ) && memberFlags & 32 ))) {
|
634 |
|
635 | Object.defineProperty(prototype, memberName, {
|
636 | get() {
|
637 |
|
638 | return getValue(this, memberName);
|
639 | },
|
640 | set(newValue) {
|
641 |
|
642 | setValue(this, memberName, newValue, cmpMeta);
|
643 | },
|
644 | configurable: true,
|
645 | enumerable: true,
|
646 | });
|
647 | }
|
648 | });
|
649 | if ((flags & 1 )) {
|
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 |
|
658 |
|
659 | Cstr.observedAttributes = members
|
660 | .filter(([_, m]) => m[0] & 15 )
|
661 | .map(([propName, m]) => {
|
662 | const attrName = m[1] || propName;
|
663 | attrNameToPropName.set(attrName, propName);
|
664 | if (m[0] & 512 ) {
|
665 | cmpMeta.$attrsToReflect$.push([propName, attrName]);
|
666 | }
|
667 | return attrName;
|
668 | });
|
669 | }
|
670 | }
|
671 | return Cstr;
|
672 | };
|
673 | const initializeComponent = async (elm, hostRef, cmpMeta, hmrVersionId, Cstr) => {
|
674 |
|
675 | if ((hostRef.$flags$ & 32 ) === 0) {
|
676 | {
|
677 |
|
678 | hostRef.$flags$ |= 32 ;
|
679 |
|
680 |
|
681 |
|
682 | Cstr = loadModule(cmpMeta);
|
683 | if (Cstr.then) {
|
684 |
|
685 | const endLoad = uniqueTime();
|
686 | Cstr = await Cstr;
|
687 | endLoad();
|
688 | }
|
689 | if (!Cstr.isProxied) {
|
690 | proxyComponent(Cstr, cmpMeta, 2 );
|
691 | Cstr.isProxied = true;
|
692 | }
|
693 | const endNewInstance = createTime('createInstance', cmpMeta.$tagName$);
|
694 |
|
695 |
|
696 |
|
697 | {
|
698 | hostRef.$flags$ |= 8 ;
|
699 | }
|
700 |
|
701 |
|
702 |
|
703 |
|
704 | try {
|
705 | new Cstr(hostRef);
|
706 | }
|
707 | catch (e) {
|
708 | consoleError(e);
|
709 | }
|
710 | {
|
711 | hostRef.$flags$ &= ~8 ;
|
712 | }
|
713 | endNewInstance();
|
714 | fireConnectedCallback(hostRef.$lazyInstance$);
|
715 | }
|
716 | if (Cstr.style) {
|
717 |
|
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 ));
|
723 | endRegisterStyles();
|
724 | }
|
725 | }
|
726 | }
|
727 |
|
728 | const ancestorComponent = hostRef.$ancestorComponent$;
|
729 | const schedule = () => scheduleUpdate(hostRef, true);
|
730 | if (ancestorComponent && ancestorComponent['s-rc']) {
|
731 |
|
732 |
|
733 |
|
734 |
|
735 |
|
736 |
|
737 | ancestorComponent['s-rc'].push(schedule);
|
738 | }
|
739 | else {
|
740 | schedule();
|
741 | }
|
742 | };
|
743 | const fireConnectedCallback = (instance) => {
|
744 | {
|
745 | safeCall(instance, 'connectedCallback');
|
746 | }
|
747 | };
|
748 | const connectedCallback = (elm) => {
|
749 | if ((plt.$flags$ & 1 ) === 0) {
|
750 | const hostRef = getHostRef(elm);
|
751 | const cmpMeta = hostRef.$cmpMeta$;
|
752 | const endConnected = createTime('connectedCallback', cmpMeta.$tagName$);
|
753 | if (!(hostRef.$flags$ & 1 )) {
|
754 |
|
755 | hostRef.$flags$ |= 1 ;
|
756 | {
|
757 |
|
758 |
|
759 | let ancestorComponent = elm;
|
760 | while ((ancestorComponent = ancestorComponent.parentNode || ancestorComponent.host)) {
|
761 |
|
762 |
|
763 | if (ancestorComponent['s-p']) {
|
764 |
|
765 |
|
766 | attachToAncestor(hostRef, (hostRef.$ancestorComponent$ = ancestorComponent));
|
767 | break;
|
768 | }
|
769 | }
|
770 | }
|
771 |
|
772 |
|
773 | if (cmpMeta.$members$) {
|
774 | Object.entries(cmpMeta.$members$).map(([memberName, [memberFlags]]) => {
|
775 | if (memberFlags & 31 && 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 |
|
788 | fireConnectedCallback(hostRef.$lazyInstance$);
|
789 | }
|
790 | endConnected();
|
791 | }
|
792 | };
|
793 | const disconnectedCallback = (elm) => {
|
794 | if ((plt.$flags$ & 1 ) === 0) {
|
795 | getHostRef(elm);
|
796 | }
|
797 | };
|
798 | const 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 = head.querySelector('meta[charset]');
|
805 | const visibilityStyle = 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 |
|
827 | constructor(self) {
|
828 |
|
829 | super(self);
|
830 | self = this;
|
831 | registerHost(self, cmpMeta);
|
832 | if (cmpMeta.$flags$ & 1 ) {
|
833 |
|
834 |
|
835 |
|
836 |
|
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 |
|
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 ));
|
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 |
|
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 |
|
886 | endBootstrap();
|
887 | };
|
888 | const hostRefs = new WeakMap();
|
889 | const getHostRef = (ref) => hostRefs.get(ref);
|
890 | const registerInstance = (lazyInstance, hostRef) => hostRefs.set((hostRef.$lazyInstance$ = lazyInstance), hostRef);
|
891 | const 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 | };
|
905 | const isMemberInElement = (elm, memberName) => memberName in elm;
|
906 | const consoleError = (e, el) => (0, console.error)(e, el);
|
907 | const cmpModules = new Map();
|
908 | const loadModule = (cmpMeta, hostRef, hmrVersionId) => {
|
909 |
|
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 |
|
918 |
|
919 |
|
920 | `./${bundleId}.entry.js${''}`).then(importedModule => {
|
921 | {
|
922 | cmpModules.set(bundleId, importedModule);
|
923 | }
|
924 | return importedModule[exportName];
|
925 | }, consoleError);
|
926 | };
|
927 | const styles = new Map();
|
928 | const queueDomReads = [];
|
929 | const queueDomWrites = [];
|
930 | const queueTask = (queue, write) => (cb) => {
|
931 | queue.push(cb);
|
932 | if (!queuePending) {
|
933 | queuePending = true;
|
934 | if (write && plt.$flags$ & 4 ) {
|
935 | nextTick(flush);
|
936 | }
|
937 | else {
|
938 | plt.raf(flush);
|
939 | }
|
940 | }
|
941 | };
|
942 | const 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 | };
|
953 | const flush = () => {
|
954 |
|
955 |
|
956 |
|
957 | consume(queueDomReads);
|
958 |
|
959 | {
|
960 | consume(queueDomWrites);
|
961 | if ((queuePending = queueDomReads.length > 0)) {
|
962 |
|
963 |
|
964 | plt.raf(flush);
|
965 | }
|
966 | }
|
967 | };
|
968 | const nextTick = (cb) => promiseResolve().then(cb);
|
969 | const writeTask = queueTask(queueDomWrites, true);
|
970 |
|
971 |
|
972 | const 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 |
|
975 | window['sgnw'] = false;
|
976 | const event = new Event('sgnw');
|
977 | const 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 | };
|
990 | const 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 | };
|
1003 | function appGlobalScript () {
|
1004 | t();
|
1005 | c(() => {
|
1006 | window['sgnw'] = true;
|
1007 | window.dispatchEvent(event);
|
1008 | });
|
1009 | }
|
1010 |
|
1011 | export { 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 };
|