UNPKG

@7x7cl/qwik

Version:

An Open-Source sub-framework designed with a focus on server-side-rendering, lazy-loading, and styling/animation.

1,222 lines 212 kB
/** * @license * @builder.io/qwik 1.1.5-dev20230608174334 * Copyright Builder.io, Inc. All Rights Reserved. * Use of this source code is governed by an MIT-style license that can be * found in the LICENSE file at https://github.com/BuilderIO/qwik/blob/main/LICENSE */ !function(global, factory) { "object" == typeof exports && "undefined" != typeof module ? factory(exports, require("@builder.io/qwik/build")) : "function" == typeof define && define.amd ? define([ "exports", "@builder.io/qwik/build" ], factory) : factory((global = "undefined" != typeof globalThis ? globalThis : global || self).qwikCore = {}, global.qwikBuild); }(this, (function(exports, build) { "use strict"; const implicit$FirstArg = fn => function(first, ...rest) { return fn.call(null, $(first), ...rest); }; const qDev = !1; const seal = () => { qDev; }; const isNode$1 = value => value && "number" == typeof value.nodeType; const isDocument = value => 9 === value.nodeType; const isElement$1 = value => 1 === value.nodeType; const isQwikElement = value => { const nodeType = value.nodeType; return 1 === nodeType || 111 === nodeType; }; const isNodeElement = value => { const nodeType = value.nodeType; return 1 === nodeType || 111 === nodeType || 3 === nodeType; }; const isVirtualElement = value => 111 === value.nodeType; const isText = value => 3 === value.nodeType; const isComment = value => 8 === value.nodeType; const logError = (message, ...optionalParams) => { const err = message instanceof Error ? message : createError(message); return console.error("%cQWIK ERROR", "", err.stack || err.message, ...printParams(optionalParams)), err; }; const createError = message => new Error(message); const logErrorAndStop = (message, ...optionalParams) => logError(message, ...optionalParams); const logWarn = () => { qDev; }; const logDebug = () => { qDev; }; const printParams = optionalParams => optionalParams; const qError = (code, ...parts) => { const text = codeToText(code); return logErrorAndStop(text, ...parts); }; const codeToText = code => `Code(${code})`; const createPlatform = () => ({ isServer: build.isServer, importSymbol(containerEl, url, symbolName) { if (build.isServer) { const hash = getSymbolHash(symbolName); const regSym = globalThis.__qwik_reg_symbols?.get(hash); if (regSym) { return regSym; } } if (!url) { throw qError(31, symbolName); } if (!containerEl) { throw qError(30, url, symbolName); } const urlDoc = toUrl(containerEl.ownerDocument, containerEl, url).toString(); const urlCopy = new URL(urlDoc); urlCopy.hash = "", urlCopy.search = ""; return import(urlCopy.href).then((mod => mod[symbolName])); }, raf: fn => new Promise((resolve => { requestAnimationFrame((() => { resolve(fn()); })); })), nextTick: fn => new Promise((resolve => { setTimeout((() => { resolve(fn()); })); })), chunkForSymbol: (symbolName, chunk) => [ symbolName, chunk ?? "_" ] }); const toUrl = (doc, containerEl, url) => { const baseURI = doc.baseURI; const base = new URL(containerEl.getAttribute("q:base") ?? baseURI, baseURI); return new URL(url, base); }; let _platform = /*#__PURE__ */ createPlatform(); const getPlatform = () => _platform; const isServerPlatform = () => _platform.isServer; function assertDefined() { qDev; } function assertEqual() { qDev; } function assertFail() { qDev; } function assertTrue() { qDev; } function assertNumber() { qDev; } function assertString() { qDev; } function assertQwikElement() { qDev; } function assertElement() { qDev; } const isSerializableObject = v => { const proto = Object.getPrototypeOf(v); return proto === Object.prototype || null === proto; }; const isObject = v => v && "object" == typeof v; const isArray = v => Array.isArray(v); const isString = v => "string" == typeof v; const isFunction = v => "function" == typeof v; const isPromise = value => value instanceof Promise; const safeCall = (call, thenFn, rejectFn) => { try { const promise = call(); return isPromise(promise) ? promise.then(thenFn, rejectFn) : thenFn(promise); } catch (e) { return rejectFn(e); } }; const then = (promise, thenFn) => isPromise(promise) ? promise.then(thenFn) : thenFn(promise); const promiseAll = promises => promises.some(isPromise) ? Promise.all(promises) : promises; const promiseAllLazy = promises => promises.length > 0 ? Promise.all(promises) : promises; const isNotNullable = v => null != v; const delay = timeout => new Promise((resolve => { setTimeout(resolve, timeout); })); const EMPTY_ARRAY = []; const EMPTY_OBJ = {}; const getDocument = node => { if ("undefined" != typeof document) { return document; } if (9 === node.nodeType) { return node; } const doc = node.ownerDocument; return assertDefined(), doc; }; const QSlot = "q:slot"; const fromCamelToKebabCase = text => text.replace(/([A-Z])/g, "-$1").toLowerCase(); const directSetAttribute = (el, prop, value) => el.setAttribute(prop, value); const directGetAttribute = (el, prop) => el.getAttribute(prop); const directRemoveAttribute = (el, prop) => el.removeAttribute(prop); const CONTAINER_STATE = Symbol("ContainerState"); const _getContainerState = containerEl => { let set = containerEl[CONTAINER_STATE]; return set || (containerEl[CONTAINER_STATE] = set = createContainerState(containerEl, directGetAttribute(containerEl, "q:base") ?? "/")), set; }; const createContainerState = (containerEl, base) => { const containerState = { $containerEl$: containerEl, $elementIndex$: 0, $styleMoved$: !1, $proxyMap$: new WeakMap, $opsNext$: new Set, $watchNext$: new Set, $watchStaging$: new Set, $hostsNext$: new Set, $hostsStaging$: new Set, $styleIds$: new Set, $events$: new Set, $serverData$: {}, $base$: base, $renderPromise$: void 0, $hostsRendering$: void 0, $pauseCtx$: void 0, $subsManager$: null }; return seal(), containerState.$subsManager$ = createSubscriptionManager(containerState), containerState; }; const setRef = (value, elm) => { if (isFunction(value)) { return value(elm); } if (isObject(value) && "value" in value) { return value.value = elm; } throw qError(32, value); }; const intToStr = nu => nu.toString(36); const strToInt = nu => parseInt(nu, 36); const getEventName = attribute => { const colonPos = attribute.indexOf(":"); return attribute ? attribute.slice(colonPos + 1).replace(/-./g, (x => x[1].toUpperCase())) : attribute; }; const ON_PROP_REGEX = /^(on|window:|document:)/; const isOnProp = prop => prop.endsWith("$") && ON_PROP_REGEX.test(prop); const groupListeners = listeners => { if (0 === listeners.length) { return EMPTY_ARRAY; } if (1 === listeners.length) { const listener = listeners[0]; return [ [ listener[0], [ listener[1] ] ] ]; } const keys = []; for (let i = 0; i < listeners.length; i++) { const eventName = listeners[i][0]; keys.includes(eventName) || keys.push(eventName); } return keys.map((eventName => [ eventName, listeners.filter((l => l[0] === eventName)).map((a => a[1])) ])); }; const setEvent = (existingListeners, prop, input, containerEl) => { if (assertTrue(prop.endsWith("$")), prop = normalizeOnProp(prop.slice(0, -1)), input) { if (isArray(input)) { const processed = input.flat(1 / 0).filter((q => null != q)).map((q => [ prop, ensureQrl(q, containerEl) ])); existingListeners.push(...processed); } else { existingListeners.push([ prop, ensureQrl(input, containerEl) ]); } } return prop; }; const PREFIXES = [ "on", "window:on", "document:on" ]; const SCOPED = [ "on", "on-window", "on-document" ]; const normalizeOnProp = prop => { let scope = "on"; for (let i = 0; i < PREFIXES.length; i++) { const prefix = PREFIXES[i]; if (prop.startsWith(prefix)) { scope = SCOPED[i], prop = prop.slice(prefix.length); break; } } return scope + ":" + (prop = prop.startsWith("-") ? fromCamelToKebabCase(prop.slice(1)) : prop.toLowerCase()); }; const ensureQrl = (value, containerEl) => (assertQrl(value), value.$setContainer$(containerEl), value); function isElement(value) { return function(value) { return value && "number" == typeof value.nodeType; }(value) && 1 === value.nodeType; } const QOjectTargetSymbol = Symbol("proxy target"); const QObjectFlagsSymbol = Symbol("proxy flags"); const QObjectManagerSymbol = Symbol("proxy manager"); const _IMMUTABLE = Symbol("IMMUTABLE"); var _a$1; const _createSignal = (value, containerState, flags, subscriptions) => { const manager = containerState.$subsManager$.$createManager$(subscriptions); return new SignalImpl(value, manager, flags); }; const QObjectSignalFlags = Symbol("proxy manager"); const SignalUnassignedException = Symbol("unassigned signal"); class SignalBase {} class SignalImpl extends SignalBase { constructor(v, manager, flags) { super(), this[_a$1] = 0, this.untrackedValue = v, this[QObjectManagerSymbol] = manager, this[QObjectSignalFlags] = flags; } valueOf() { qDev; } toString() { return `[Signal ${String(this.value)}]`; } toJSON() { return { value: this.value }; } get value() { if (2 & this[QObjectSignalFlags]) { throw SignalUnassignedException; } const sub = tryGetInvokeContext()?.$subscriber$; return sub && this[QObjectManagerSymbol].$addSub$(sub), this.untrackedValue; } set value(v) { const manager = this[QObjectManagerSymbol]; manager && this.untrackedValue !== v && (this.untrackedValue = v, manager.$notifySubs$()); } } _a$1 = QObjectSignalFlags; class SignalDerived extends SignalBase { constructor($func$, $args$, $funcStr$) { super(), this.$func$ = $func$, this.$args$ = $args$, this.$funcStr$ = $funcStr$; } get value() { return this.$func$.apply(void 0, this.$args$); } } class SignalWrapper extends SignalBase { constructor(ref, prop) { super(), this.ref = ref, this.prop = prop; } get [QObjectManagerSymbol]() { return getProxyManager(this.ref); } get value() { return this.ref[this.prop]; } set value(value) { this.ref[this.prop] = value; } } const isSignal = obj => obj instanceof SignalBase; const _wrapProp = (obj, prop) => { if (!isObject(obj)) { return obj[prop]; } if (obj instanceof SignalBase) { return assertEqual(), obj; } const target = getProxyTarget(obj); if (target) { const signal = target["$$" + prop]; if (signal) { return assertTrue(isSignal(signal)), signal; } if (!0 !== target[_IMMUTABLE]?.[prop]) { return new SignalWrapper(obj, prop); } } const immutable = obj[_IMMUTABLE]?.[prop]; return isSignal(immutable) ? immutable : _IMMUTABLE; }; const getOrCreateProxy = (target, containerState, flags = 0) => { const proxy = containerState.$proxyMap$.get(target); return proxy || (0 !== flags && setObjectFlags(target, flags), createProxy(target, containerState, void 0)); }; const createProxy = (target, containerState, subs) => { assertEqual(unwrapProxy(target)), assertTrue(containerState.$proxyMap$.has(target)), assertTrue(isObject(target)), assertTrue(isSerializableObject(target) || isArray(target)); const manager = containerState.$subsManager$.$createManager$(subs); const proxy = new Proxy(target, new ReadWriteProxyHandler(containerState, manager)); return containerState.$proxyMap$.set(target, proxy), proxy; }; const createPropsState = () => { const props = {}; return setObjectFlags(props, 2), props; }; const setObjectFlags = (obj, flags) => { Object.defineProperty(obj, QObjectFlagsSymbol, { value: flags, enumerable: !1 }); }; class ReadWriteProxyHandler { constructor($containerState$, $manager$) { this.$containerState$ = $containerState$, this.$manager$ = $manager$; } deleteProperty(target, prop) { if (2 & target[QObjectFlagsSymbol]) { throw qError(17); } return "string" == typeof prop && delete target[prop] && (this.$manager$.$notifySubs$(isArray(target) ? void 0 : prop), !0); } get(target, prop) { if ("symbol" == typeof prop) { return prop === QOjectTargetSymbol ? target : prop === QObjectManagerSymbol ? this.$manager$ : target[prop]; } const flags = target[QObjectFlagsSymbol] ?? 0; assertNumber(); const invokeCtx = tryGetInvokeContext(); const recursive = 0 != (1 & flags); const hiddenSignal = target["$$" + prop]; let subscriber; let value; if (invokeCtx && (subscriber = invokeCtx.$subscriber$), !(0 != (2 & flags)) || prop in target && !immutableValue(target[_IMMUTABLE]?.[prop]) || (subscriber = null), hiddenSignal ? (assertTrue(isSignal(hiddenSignal)), value = hiddenSignal.value, subscriber = null) : value = target[prop], subscriber) { const isA = isArray(target); this.$manager$.$addSub$(subscriber, isA ? void 0 : prop); } return recursive ? wrap(value, this.$containerState$) : value; } set(target, prop, newValue) { if ("symbol" == typeof prop) { return target[prop] = newValue, !0; } const flags = target[QObjectFlagsSymbol] ?? 0; assertNumber(); if (0 != (2 & flags)) { throw qError(17); } const unwrappedNewValue = 0 != (1 & flags) ? unwrapProxy(newValue) : newValue; if (isArray(target)) { return target[prop] = unwrappedNewValue, this.$manager$.$notifySubs$(), !0; } const oldValue = target[prop]; return target[prop] = unwrappedNewValue, oldValue !== unwrappedNewValue && this.$manager$.$notifySubs$(prop), !0; } has(target, property) { if (property === QOjectTargetSymbol) { return !0; } const hasOwnProperty = Object.prototype.hasOwnProperty; return !!hasOwnProperty.call(target, property) || !("string" != typeof property || !hasOwnProperty.call(target, "$$" + property)); } ownKeys(target) { const flags = target[QObjectFlagsSymbol] ?? 0; assertNumber(); if (!(0 != (2 & flags))) { let subscriber = null; const invokeCtx = tryGetInvokeContext(); invokeCtx && (subscriber = invokeCtx.$subscriber$), subscriber && this.$manager$.$addSub$(subscriber); } return isArray(target) ? Reflect.ownKeys(target) : Reflect.ownKeys(target).map((a => "string" == typeof a && a.startsWith("$$") ? a.slice(2) : a)); } getOwnPropertyDescriptor(target, prop) { return isArray(target) || "symbol" == typeof prop ? Object.getOwnPropertyDescriptor(target, prop) : { enumerable: !0, configurable: !0 }; } } const immutableValue = value => value === _IMMUTABLE || isSignal(value); const wrap = (value, containerState) => { if (isObject(value)) { if (Object.isFrozen(value)) { return value; } const nakedValue = unwrapProxy(value); if (nakedValue !== value) { return value; } if (fastSkipSerialize(nakedValue)) { return value; } if (isSerializableObject(nakedValue) || isArray(nakedValue)) { const proxy = containerState.$proxyMap$.get(nakedValue); return proxy || getOrCreateProxy(nakedValue, containerState, 1); } } return value; }; const tryGetContext = element => element._qc_; const getContext = (el, containerState) => { assertQwikElement(); const ctx = tryGetContext(el); if (ctx) { return ctx; } const elCtx = createContext(el); const elementID = directGetAttribute(el, "q:id"); if (elementID) { const pauseCtx = containerState.$pauseCtx$; if (elCtx.$id$ = elementID, pauseCtx) { const {getObject, meta, refs} = pauseCtx; if (isElement(el)) { const refMap = refs[elementID]; refMap && (assertTrue(isElement(el)), elCtx.$refMap$ = refMap.split(" ").map(getObject), elCtx.li = ((elCtx, containerEl) => { const attributes = elCtx.$element$.attributes; const listeners = []; for (let i = 0; i < attributes.length; i++) { const {name, value} = attributes.item(i); if (name.startsWith("on:") || name.startsWith("on-window:") || name.startsWith("on-document:")) { const urls = value.split("\n"); for (const url of urls) { const qrl = parseQRL(url, containerEl); qrl.$capture$ && inflateQrl(qrl, elCtx), listeners.push([ name, qrl ]); } } } return listeners; })(elCtx, containerState.$containerEl$)); } else { const styleIds = el.getAttribute("q:sstyle"); elCtx.$scopeIds$ = styleIds ? styleIds.split("|") : null; const ctxMeta = meta[elementID]; if (ctxMeta) { const seq = ctxMeta.s; const host = ctxMeta.h; const contexts = ctxMeta.c; const watches = ctxMeta.w; if (seq && (elCtx.$seq$ = seq.split(" ").map(getObject)), watches && (elCtx.$watches$ = watches.split(" ").map(getObject)), contexts) { elCtx.$contexts$ = new Map; for (const part of contexts.split(" ")) { const [key, value] = part.split("="); elCtx.$contexts$.set(key, getObject(value)); } } if (host) { const [renderQrl, props] = host.split(" "); if (elCtx.$flags$ = 4, renderQrl && (elCtx.$componentQrl$ = getObject(renderQrl)), props) { const propsObj = getObject(props); elCtx.$props$ = propsObj, setObjectFlags(propsObj, 2), propsObj[_IMMUTABLE] = getImmutableFromProps(propsObj); } else { elCtx.$props$ = createProxy(createPropsState(), containerState); } } } } } } return elCtx; }; const getImmutableFromProps = props => { const immutable = {}; const target = getProxyTarget(props); for (const key in target) { key.startsWith("$$") && (immutable[key.slice(2)] = target[key]); } return immutable; }; const createContext = element => { const ctx = { $flags$: 0, $id$: "", $element$: element, $refMap$: [], li: [], $watches$: null, $seq$: null, $slots$: null, $scopeIds$: null, $appendStyles$: null, $props$: null, $vdom$: null, $componentQrl$: null, $contexts$: null, $dynamicSlots$: null, $parent$: null, $slotParent$: null }; return seal(), element._qc_ = ctx, ctx; }; let _locale; let _context; const tryGetInvokeContext = () => { if (!_context) { const context = "undefined" != typeof document && document && document.__q_context__; if (!context) { return; } return isArray(context) ? document.__q_context__ = newInvokeContextFromTuple(context) : context; } return _context; }; const getInvokeContext = () => { const ctx = tryGetInvokeContext(); if (!ctx) { throw qError(14); } return ctx; }; const useInvokeContext = () => { const ctx = tryGetInvokeContext(); if (!ctx || "qRender" !== ctx.$event$) { throw qError(20); } return assertDefined(), assertDefined(), assertDefined(), assertDefined(), ctx; }; const useBindInvokeContext = callback => { if (null == callback) { return callback; } const ctx = getInvokeContext(); return (...args) => invoke(ctx, callback.bind(void 0, ...args)); }; function invoke(context, fn, ...args) { const previousContext = _context; let returnValue; try { _context = context, returnValue = fn.apply(this, args); } finally { _context = previousContext; } return returnValue; } const waitAndRun = (ctx, callback) => { const waitOn = ctx.$waitOn$; if (0 === waitOn.length) { const result = callback(); isPromise(result) && waitOn.push(result); } else { waitOn.push(Promise.all(waitOn).then(callback)); } }; const newInvokeContextFromTuple = context => { const element = context[0]; const container = element.closest("[q\\:container]"); const locale = container?.getAttribute("q:locale") || void 0; return locale && function(locale) { _locale = locale; }(locale), newInvokeContext(locale, void 0, element, context[1], context[2]); }; const newInvokeContext = (locale, hostElement, element, event, url) => { const ctx = { $seq$: 0, $hostElement$: hostElement, $element$: element, $event$: event, $url$: url, $locale$: locale, $qrl$: void 0, $renderCtx$: void 0, $subscriber$: void 0, $waitOn$: void 0 }; return seal(), ctx; }; const getWrappingContainer = el => el.closest("[q\\:container]"); const untrack = fn => invoke(void 0, fn); const trackInvocation = /*#__PURE__*/ newInvokeContext(void 0, void 0, void 0, "qRender"); const trackSignal = (signal, sub) => (trackInvocation.$subscriber$ = sub, invoke(trackInvocation, (() => signal.value))); const useOn = (event, eventQrl) => _useOn(`on-${event}`, eventQrl); const useOnDocument = (event, eventQrl) => _useOn(`document:on-${event}`, eventQrl); const _useOn = (eventName, eventQrl) => { if (eventQrl) { const invokeCtx = useInvokeContext(); const elCtx = getContext(invokeCtx.$hostElement$, invokeCtx.$renderCtx$.$static$.$containerState$); assertQrl(eventQrl), "string" == typeof eventName ? elCtx.li.push([ normalizeOnProp(eventName), eventQrl ]) : elCtx.li.push(...eventName.map((name => [ normalizeOnProp(name), eventQrl ]))), elCtx.$flags$ |= 2; } }; const SkipRender = Symbol("skip render"); const SSRRaw = () => null; const SSRComment = props => jsx(SSRRaw, { data: `\x3c!--${props.data}--\x3e` }, null); const InternalSSRStream = () => null; const useSequentialScope = () => { const iCtx = useInvokeContext(); const i = iCtx.$seq$; const elCtx = getContext(iCtx.$hostElement$, iCtx.$renderCtx$.$static$.$containerState$); const seq = elCtx.$seq$ ? elCtx.$seq$ : elCtx.$seq$ = []; iCtx.$seq$++; return { get: seq[i], set: value => seq[i] = value, i, iCtx, elCtx }; }; const setAttribute = (staticCtx, el, prop, value) => { staticCtx.$operations$.push({ $operation$: _setAttribute, $args$: [ el, prop, value ] }); }; const _setAttribute = (el, prop, value) => { if (null == value || !1 === value) { el.removeAttribute(prop); } else { const str = !0 === value ? "" : String(value); directSetAttribute(el, prop, str); } }; const setProperty = (staticCtx, node, key, value) => { staticCtx.$operations$.push({ $operation$: _setProperty, $args$: [ node, key, value ] }); }; const _setProperty = (node, key, value) => { try { node[key] = null == value ? "" : value, null == value && isNode$1(node) && isElement$1(node) && node.removeAttribute(key); } catch (err) { logError(codeToText(6), { node, key, value }, err); } }; const createElement = (doc, expectTag, isSvg) => isSvg ? doc.createElementNS(SVG_NS, expectTag) : doc.createElement(expectTag); const insertBefore = (staticCtx, parent, newChild, refChild) => (staticCtx.$operations$.push({ $operation$: directInsertBefore, $args$: [ parent, newChild, refChild || null ] }), newChild); const insertAfter = (staticCtx, parent, newChild, refChild) => (staticCtx.$operations$.push({ $operation$: directInsertAfter, $args$: [ parent, newChild, refChild || null ] }), newChild); const appendChild = (staticCtx, parent, newChild) => (staticCtx.$operations$.push({ $operation$: directAppendChild, $args$: [ parent, newChild ] }), newChild); const appendHeadStyle = (staticCtx, styleTask) => { staticCtx.$containerState$.$styleIds$.add(styleTask.styleId), staticCtx.$postOperations$.push({ $operation$: _appendHeadStyle, $args$: [ staticCtx.$containerState$.$containerEl$, styleTask ] }); }; const _appendHeadStyle = (containerEl, styleTask) => { const doc = getDocument(containerEl); const isDoc = doc.documentElement === containerEl; const headEl = doc.head; const style = doc.createElement("style"); isDoc && !headEl && logWarn("document.head is undefined"), directSetAttribute(style, "q:style", styleTask.styleId), directSetAttribute(style, "hidden", ""), style.textContent = styleTask.content, isDoc && headEl ? directAppendChild(headEl, style) : directInsertBefore(containerEl, style, containerEl.firstChild); }; const directPrepend = (parent, newChild) => { directInsertBefore(parent, newChild, parent.firstChild); }; const removeNode = (staticCtx, el) => { if (isQwikElement(el)) { cleanupTree(el, staticCtx, staticCtx.$containerState$.$subsManager$, !0); } staticCtx.$operations$.push({ $operation$: _removeNode, $args$: [ el, staticCtx ] }); }; const _removeNode = el => { const parent = el.parentElement; parent && directRemoveChild(parent, el); }; const createTemplate = (doc, slotName) => { const template = createElement(doc, "q:template", !1); return directSetAttribute(template, QSlot, slotName), directSetAttribute(template, "hidden", ""), directSetAttribute(template, "aria-hidden", "true"), template; }; const executeDOMRender = staticCtx => { for (const op of staticCtx.$operations$) { op.$operation$.apply(void 0, op.$args$); } resolveSlotProjection(staticCtx); }; const getKey = el => directGetAttribute(el, "q:key"); const resolveSlotProjection = staticCtx => { const subsManager = staticCtx.$containerState$.$subsManager$; for (const slotEl of staticCtx.$rmSlots$) { const key = getKey(slotEl); assertDefined(); const slotChildren = getChildren(slotEl, isChildComponent); if (slotChildren.length > 0) { const sref = slotEl.getAttribute("q:sref"); const hostCtx = staticCtx.$roots$.find((r => r.$id$ === sref)); if (hostCtx) { const hostElm = hostCtx.$element$; if (hostElm.isConnected) { if (getChildren(hostElm, isSlotTemplate).some((node => directGetAttribute(node, QSlot) === key))) { cleanupTree(slotEl, staticCtx, subsManager, !1); } else { const template = createTemplate(staticCtx.$doc$, key); for (const child of slotChildren) { directAppendChild(template, child); } directInsertBefore(hostElm, template, hostElm.firstChild); } } else { cleanupTree(slotEl, staticCtx, subsManager, !1); } } else { cleanupTree(slotEl, staticCtx, subsManager, !1); } } } for (const [slotEl, hostElm] of staticCtx.$addSlots$) { const key = getKey(slotEl); assertDefined(); const template = getChildren(hostElm, isSlotTemplate).find((node => node.getAttribute(QSlot) === key)); template && (getChildren(template, isChildComponent).forEach((child => { directAppendChild(slotEl, child); })), template.remove()); } }; const printRenderStats = () => { qDev; }; const queryAllVirtualByAttribute = (el, prop, value) => { const walker = ((el, prop, value) => el.ownerDocument.createTreeWalker(el, 128, { acceptNode(c) { const virtual = getVirtualElement(c); return virtual && directGetAttribute(virtual, prop) === value ? 1 : 2; } }))(el, prop, value); const pars = []; let currentNode = null; for (;currentNode = walker.nextNode(); ) { pars.push(getVirtualElement(currentNode)); } return pars; }; const escape = s => s.replace(/ /g, "+"); const unescape = s => s.replace(/\+/g, " "); class VirtualElementImpl { constructor(open, close, isSvg) { this.open = open, this.close = close, this.isSvg = isSvg, this._qc_ = null, this.nodeType = 111, this.localName = ":virtual", this.nodeName = ":virtual"; const doc = this.ownerDocument = open.ownerDocument; this.$template$ = createElement(doc, "template", !1), this.$attributes$ = (str => { if (!str) { return {}; } const attributes = str.split(" "); return Object.fromEntries(attributes.map((attr => { const index = attr.indexOf("="); return index >= 0 ? [ attr.slice(0, index), unescape(attr.slice(index + 1)) ] : [ attr, "" ]; }))); })(open.data.slice(3)), assertTrue(open.data.startsWith("qv ")), open.__virtual = this, seal(); } insertBefore(node, ref) { const parent = this.parentElement; if (parent) { parent.insertBefore(node, ref || this.close); } else { this.$template$.insertBefore(node, ref); } return node; } remove() { const parent = this.parentElement; if (parent) { const ch = this.childNodes; assertEqual(), parent.removeChild(this.open), this.$template$.append(...ch), parent.removeChild(this.close); } } appendChild(node) { return this.insertBefore(node, null); } insertBeforeTo(newParent, child) { const ch = this.childNodes; newParent.insertBefore(this.open, child); for (const c of ch) { newParent.insertBefore(c, child); } newParent.insertBefore(this.close, child), assertEqual(); } appendTo(newParent) { this.insertBeforeTo(newParent, null); } get namespaceURI() { return this.parentElement?.namespaceURI ?? ""; } removeChild(child) { this.parentElement ? this.parentElement.removeChild(child) : this.$template$.removeChild(child); } getAttribute(prop) { return this.$attributes$[prop] ?? null; } hasAttribute(prop) { return prop in this.$attributes$; } setAttribute(prop, value) { this.$attributes$[prop] = value, this.open.data = updateComment(this.$attributes$); } removeAttribute(prop) { delete this.$attributes$[prop], this.open.data = updateComment(this.$attributes$); } matches(_) { return !1; } compareDocumentPosition(other) { return this.open.compareDocumentPosition(other); } closest(query) { const parent = this.parentElement; return parent ? parent.closest(query) : null; } querySelectorAll(query) { const result = []; return getChildren(this, isNodeElement).forEach((el => { isQwikElement(el) && (el.matches(query) && result.push(el), result.concat(Array.from(el.querySelectorAll(query)))); })), result; } querySelector(query) { for (const el of this.childNodes) { if (isElement$1(el)) { if (el.matches(query)) { return el; } const v = el.querySelector(query); if (null !== v) { return v; } } } return null; } get innerHTML() { return ""; } set innerHTML(html) { const parent = this.parentElement; parent ? (this.childNodes.forEach((a => this.removeChild(a))), this.$template$.innerHTML = html, parent.insertBefore(this.$template$.content, this.close)) : this.$template$.innerHTML = html; } get firstChild() { if (this.parentElement) { const first = this.open.nextSibling; return first === this.close ? null : first; } return this.$template$.firstChild; } get nextSibling() { return this.close.nextSibling; } get previousSibling() { return this.open.previousSibling; } get childNodes() { if (!this.parentElement) { return Array.from(this.$template$.childNodes); } const nodes = []; let node = this.open; for (;(node = node.nextSibling) && node !== this.close; ) { nodes.push(node); } return nodes; } get isConnected() { return this.open.isConnected; } get parentElement() { return this.open.parentElement; } } const updateComment = attributes => `qv ${(map => { const attributes = []; return Object.entries(map).forEach((([key, value]) => { attributes.push(value ? `${key}=${escape(value)}` : `${key}`); })), attributes.join(" "); })(attributes)}`; const processVirtualNodes = node => { if (null == node) { return null; } if (isComment(node)) { const virtual = getVirtualElement(node); if (virtual) { return virtual; } } return node; }; const getVirtualElement = open => { const virtual = open.__virtual; if (virtual) { return virtual; } if (open.data.startsWith("qv ")) { const close = findClose(open); return new VirtualElementImpl(open, close, open.parentElement?.namespaceURI === SVG_NS); } return null; }; const findClose = open => { let node = open.nextSibling; let stack = 1; for (;node; ) { if (isComment(node)) { if (node.data.startsWith("qv ")) { stack++; } else if ("/qv" === node.data && (stack--, 0 === stack)) { return node; } } node = node.nextSibling; } assertFail(); }; const getRootNode = node => null == node ? null : isVirtualElement(node) ? node.open : node; const createContextId = name => (assertTrue(/^[\w/.-]+$/.test(name)), /*#__PURE__*/ Object.freeze({ id: fromCamelToKebabCase(name) })); const useContextProvider = (context, newValue) => { const {get, set, elCtx} = useSequentialScope(); if (void 0 !== get) { return; } let contexts = elCtx.$contexts$; contexts || (elCtx.$contexts$ = contexts = new Map), contexts.set(context.id, newValue), set(!0); }; const resolveContext = (context, hostCtx, containerState) => { const contextID = context.id; if (hostCtx) { let hostElement = hostCtx.$element$; let ctx = hostCtx.$slotParent$ ?? hostCtx.$parent$; for (;ctx; ) { if (hostElement = ctx.$element$, ctx.$contexts$) { const found = ctx.$contexts$.get(contextID); if (found) { return found; } if (!0 === ctx.$contexts$.get("_")) { break; } } ctx = ctx.$slotParent$ ?? ctx.$parent$; } if (hostElement.closest) { const value = queryContextFromDom(hostElement, containerState, contextID); if (void 0 !== value) { return value; } } } }; const queryContextFromDom = (hostElement, containerState, contextId) => { let element = hostElement; for (;element; ) { let node = element; let virtual; for (;node && (virtual = findVirtual(node)); ) { const contexts = getContext(virtual, containerState)?.$contexts$; if (contexts && contexts.has(contextId)) { return contexts.get(contextId); } node = virtual; } element = element.parentElement; } }; const findVirtual = el => { let node = el; let stack = 1; for (;node = node.previousSibling; ) { if (isComment(node)) { if ("/qv" === node.data) { stack++; } else if (node.data.startsWith("qv ") && (stack--, 0 === stack)) { return getVirtualElement(node); } } } return null; }; const ERROR_CONTEXT = /*#__PURE__*/ createContextId("qk-error"); const handleError = (err, hostElement, rCtx) => { const elCtx = tryGetContext(hostElement); if (isServerPlatform()) { throw err; } { const errorStore = resolveContext(ERROR_CONTEXT, elCtx, rCtx.$static$.$containerState$); if (void 0 === errorStore) { throw err; } errorStore.error = err; } }; const executeComponent = (rCtx, elCtx) => { elCtx.$flags$ &= -2, elCtx.$flags$ |= 4, elCtx.$slots$ = [], elCtx.li.length = 0; const hostElement = elCtx.$element$; const componentQRL = elCtx.$componentQrl$; const props = elCtx.$props$; const newCtx = pushRenderContext(rCtx); const iCtx = newInvokeContext(rCtx.$static$.$locale$, hostElement, void 0, "qRender"); const waitOn = iCtx.$waitOn$ = []; assertDefined(), assertDefined(), newCtx.$cmpCtx$ = elCtx, newCtx.$slotCtx$ = null, iCtx.$subscriber$ = [ 0, hostElement ], iCtx.$renderCtx$ = rCtx, componentQRL.$setContainer$(rCtx.$static$.$containerState$.$containerEl$); const componentFn = componentQRL.getFn(iCtx); return safeCall((() => componentFn(props)), (jsxNode => waitOn.length > 0 ? Promise.all(waitOn).then((() => 1 & elCtx.$flags$ ? executeComponent(rCtx, elCtx) : { node: jsxNode, rCtx: newCtx })) : 1 & elCtx.$flags$ ? executeComponent(rCtx, elCtx) : { node: jsxNode, rCtx: newCtx }), (err => err === SignalUnassignedException ? Promise.all(waitOn).then((() => executeComponent(rCtx, elCtx))) : (handleError(err, hostElement, rCtx), { node: SkipRender, rCtx: newCtx }))); }; const createRenderContext = (doc, containerState) => { const ctx = { $static$: { $doc$: doc, $locale$: containerState.$serverData$.locale, $containerState$: containerState, $hostElements$: new Set, $operations$: [], $postOperations$: [], $roots$: [], $addSlots$: [], $rmSlots$: [], $visited$: [] }, $cmpCtx$: null, $slotCtx$: null }; return seal(), seal(), ctx; }; const pushRenderContext = ctx => ({ $static$: ctx.$static$, $cmpCtx$: ctx.$cmpCtx$, $slotCtx$: ctx.$slotCtx$ }); const serializeClassWithHost = (obj, hostCtx) => hostCtx && hostCtx.$scopeIds$ ? hostCtx.$scopeIds$.join(" ") + " " + serializeClass(obj) : serializeClass(obj); const serializeClass = obj => obj ? isString(obj) ? obj.trim() : isArray(obj) ? obj.reduce(((result, o) => { const classList = serializeClass(o); return classList ? result ? `${result} ${classList}` : classList : result; }), "") : Object.entries(obj).reduce(((result, [key, value]) => value ? result ? `${result} ${key.trim()}` : key.trim() : result), "") : ""; const stringifyStyle = obj => { if (null == obj) { return ""; } if ("object" == typeof obj) { if (isArray(obj)) { throw qError(0, obj, "style"); } { const chunks = []; for (const key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { const value = obj[key]; if (null != value) { const normalizedKey = key.startsWith("--") ? key : fromCamelToKebabCase(key); chunks.push(normalizedKey + ":" + value); } } } return chunks.join(";"); } } return String(obj); }; const getNextIndex = ctx => intToStr(ctx.$static$.$containerState$.$elementIndex$++); const setQId = (rCtx, elCtx) => { const id = getNextIndex(rCtx); elCtx.$id$ = id; }; const jsxToString = data => isSignal(data) ? jsxToString(data.value) : null == data || "boolean" == typeof data ? "" : String(data); function isAriaAttribute(prop) { return prop.startsWith("aria-"); } const shouldWrapFunctional = (res, node) => !!node.key && (!isJSXNode(res) || !isFunction(res.type) && res.key != node.key); const version = "1.1.5-dev20230608174334"; const hashCode = (text, hash = 0) => { if (0 === text.length) { return hash; } for (let i = 0; i < text.length; i++) { hash = (hash << 5) - hash + text.charCodeAt(i), hash |= 0; } return Number(Math.abs(hash)).toString(36); }; const serializeSStyle = scopeIds => { const value = scopeIds.join("|"); if (value.length > 0) { return value; } }; var _a; class MockElement { constructor(nodeType) { this.nodeType = nodeType, this[_a] = null, seal(); } } _a = "_qc_"; const renderRoot$1 = async (node, rCtx, ssrCtx, stream, containerState, opts) => { const beforeClose = opts.beforeClose; return await renderNode(node, rCtx, ssrCtx, stream, 0, beforeClose ? stream => { const result = beforeClose(ssrCtx.$static$.$contexts$, containerState, !1, ssrCtx.$static$.$textNodes$); return processData$1(result, rCtx, ssrCtx, stream, 0, void 0); } : void 0), rCtx; }; const renderNodeVirtual = (node, elCtx, extraNodes, rCtx, ssrCtx, stream, flags, beforeClose) => { const props = node.props; const renderQrl = props["q:renderFn"]; if (renderQrl) { return elCtx.$componentQrl$ = renderQrl, renderSSRComponent(rCtx, ssrCtx, stream, elCtx, node, flags, beforeClose); } let virtualComment = "\x3c!--qv" + renderVirtualAttributes(props); const isSlot = "q:s" in props; const key = null != node.key ? String(node.key) : null; isSlot && (assertDefined(), virtualComment += " q:sref=" + rCtx.$cmpCtx$.$id$), null != key && (virtualComment += " q:key=" + key), virtualComment += "--\x3e", stream.write(virtualComment); const html = node.props.dangerouslySetInnerHTML; if (html) { return stream.write(html), void stream.write(CLOSE_VIRTUAL); } if (extraNodes) { for (const node of extraNodes) { renderNodeElementSync(node.type, node.props, stream); } } const promise = walkChildren(node.children, rCtx, ssrCtx, stream, flags); return then(promise, (() => { if (!isSlot && !beforeClose) { return void stream.write(CLOSE_VIRTUAL); } let promise; if (isSlot) { assertDefined(); const content = ssrCtx.$projectedChildren$?.[key]; if (content) { const [rCtx, sCtx] = ssrCtx.$projectedCtxs$; const newSlotRctx = pushRenderContext(rCtx); newSlotRctx.$slotCtx$ = elCtx, ssrCtx.$projectedChildren$[key] = void 0, promise = processData$1(content, newSlotRctx, sCtx, stream, flags); } } return beforeClose && (promise = then(promise, (() => beforeClose(stream)))), then(promise, (() => { stream.write(CLOSE_VIRTUAL); })); })); }; const CLOSE_VIRTUAL = "\x3c!--/qv--\x3e"; const renderVirtualAttributes = attributes => { let text = ""; for (const prop in attributes) { if ("children" === prop || "dangerouslySetInnerHTML" === prop) { continue; } const value = attributes[prop]; null != value && (text += " " + ("" === value ? prop : prop + "=" + value)); } return text; }; const renderNodeElementSync = (tagName, attributes, stream) => { stream.