UNPKG

@qwik.dev/core

Version:

An open source framework for building instant loading web apps at any scale, without the extra effort.

1,203 lines 171 kB
"use strict"; var __defProp = Object.defineProperty; var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value; var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value); var _a, _b, _c, _d, _e; Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" }); const core = require("@qwik.dev/core"); var isBrowser = /* @__PURE__ */ (() => typeof window !== "undefined" && typeof HTMLElement !== "undefined" && !!window.document && String(HTMLElement).includes("[native code]"))(); var isServer = !isBrowser; var isDev = false; /** * @license * @qwik.dev/core 2.0.0-alpha.9-dev+56ed5bd * Copyright QwikDev. 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/QwikDev/qwik/blob/main/LICENSE */ const logError = (message, ...optionalParams) => createAndLogError(false, message, ...optionalParams); const throwErrorAndStop = (message, ...optionalParams) => { throw createAndLogError(false, message, ...optionalParams); }; const logErrorAndStop = (message, ...optionalParams) => createAndLogError(true, message, ...optionalParams); const createAndLogError = (asyncThrow, message, ...optionalParams) => { const err = message instanceof Error ? message : new Error(message); return console.error("%cQWIK ERROR", "", err.message, ...optionalParams, err.stack), asyncThrow && setTimeout(() => { throw err; }, 0), err; }; function assertDefined() { } function assertEqual() { } function assertTrue() { } function assertFalse() { } const codeToText = (code) => `Code(Q${code}) https://github.com/QwikDev/qwik/blob/main/packages/qwik/src/core/error/error.ts#L${8 + code}`; const qError = (code, errorMessageArgs = []) => { const text = codeToText(code, ...errorMessageArgs); return logErrorAndStop(text, ...errorMessageArgs); }; const isSyncQrl = (value) => isQrl$1(value) && "<sync>" == value.$symbol$; const isQrl$1 = (value) => "function" == typeof value && "function" == typeof value.getSymbol; const getSymbolHash = (symbolName) => { const index = symbolName.lastIndexOf("_"); return index > -1 ? symbolName.slice(index + 1) : symbolName; }; const QSlot = "q:slot"; const QSlotS = "q:s"; const QStyle = "q:style"; const QStyleSelector = "style[q\\:style]"; const QStylesAllSelector = "style[q\\:style],style[q\\:sstyle]"; const getQFuncs = (document2, hash) => document2["qFuncs_" + hash] || []; const QContainerIsland = "q:container-island"; const QContainerIslandEnd = "/" + QContainerIsland; const QIgnore = "q:ignore"; const QIgnoreEnd = "/q:ignore"; const QTemplate = "q:template"; const QContainerSelector = "[q\\:container]:not([q\\:container=html]):not([q\\:container=text])"; const HTML_NS = "http://www.w3.org/1999/xhtml"; const SVG_NS = "http://www.w3.org/2000/svg"; const MATH_NS = "http://www.w3.org/1998/Math/MathML"; const dangerouslySetInnerHTML = "dangerouslySetInnerHTML"; const createPlatform = () => ({ isServer, importSymbol(containerEl, url, symbolName) { if (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 = ""; 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; const isPromise = (value) => !!value && "object" == typeof value && "function" == typeof value.then; const safeCall = (call, thenFn, rejectFn) => { try { const result = call(); return isPromise(result) ? result.then(thenFn, rejectFn) : thenFn(result); } catch (e) { return rejectFn(e); } }; const maybeThen = (valueOrPromise, thenFn) => isPromise(valueOrPromise) ? valueOrPromise.then(thenFn, shouldNotError) : thenFn(valueOrPromise); const shouldNotError = (reason) => { throwErrorAndStop(reason); }; const delay = (timeout) => new Promise((resolve) => { setTimeout(resolve, timeout); }); function retryOnPromise(fn, retryCount = 0) { const retryOrThrow = (e) => { if (isPromise(e) && retryCount < 100) { return e.then(retryOnPromise.bind(null, fn, retryCount++)); } throw e; }; try { const result = fn(); return isPromise(result) ? result.catch((e) => retryOrThrow(e)) : result; } catch (e) { return retryOrThrow(e); } } const isSerializableObject = (v) => { const proto = Object.getPrototypeOf(v); return proto === Object.prototype || proto === Array.prototype || null === proto; }; const isArray = (v) => Array.isArray(v); const isString = (v) => "string" == typeof v; const isFunction = (v) => "function" == typeof v; const EMPTY_ARRAY = []; const EMPTY_OBJ = {}; Object.freeze(EMPTY_ARRAY), Object.freeze(EMPTY_OBJ); const isJsxPropertyAnEventName = (name) => (name.startsWith("on") || name.startsWith("window:on") || name.startsWith("document:on")) && name.endsWith("$"); const isHtmlAttributeAnEventName = (name) => name.startsWith("on:") || name.startsWith("on-window:") || name.startsWith("on-document:"); function jsxEventToHtmlAttribute(jsxEvent) { if (jsxEvent.endsWith("$")) { const [prefix, idx] = getEventScopeDataFromJsxEvent(jsxEvent); if (-1 !== idx) { const eventName = getEventNameFromJsxEvent(jsxEvent); return prefix + fromCamelToKebabCase(eventName); } } return null; } function getEventNameFromJsxEvent(jsxEvent) { if (jsxEvent.endsWith("$")) { const [, idx] = getEventScopeDataFromJsxEvent(jsxEvent); if (-1 != idx) { return jsxEventToEventName(jsxEvent, idx); } } return null; } function jsxEventToEventName(jsxEvent, startIdx = 0) { let lastIdx = startIdx; const isCaseSensitive = isDash(jsxEvent.charCodeAt(startIdx)); isCaseSensitive && lastIdx++; let eventName = ""; const chunk = jsxEvent.substring(lastIdx, jsxEvent.length - 1); return "DOMContentLoaded" === chunk ? "DOMContentLoaded" : (eventName += isCaseSensitive ? chunk : chunk.toLowerCase(), eventName); } function getEventScopeDataFromJsxEvent(eventName) { let prefix = null; let idx = -1; return eventName.startsWith("on") ? (prefix = "on:", idx = 2) : eventName.startsWith("window:on") ? (prefix = "on-window:", idx = 9) : eventName.startsWith("document:on") && (prefix = "on-document:", idx = 11), [prefix, idx]; } const isDash = (charCode) => 45 === charCode; const getEventNameScopeFromJsxEvent = (name) => { const index = name.indexOf(":"); return -1 !== index ? name.substring(0, index) : ""; }; function isPreventDefault(key) { return key.startsWith("preventdefault:"); } const fromCamelToKebabCase = (text) => text.replace(/([A-Z-])/g, "-$1").toLowerCase(); const createContextId = (name) => /* @__PURE__ */ Object.freeze({ id: fromCamelToKebabCase(name) }); const ERROR_CONTEXT = /* @__PURE__ */ createContextId("qk-error"); const version = "2.0.0-alpha.9-dev+56ed5bd"; const Slot = (props) => _jsxSorted(Virtual, null, { [QSlotS]: "" }, props.children, 0, props.name ?? ""); const SkipRender = Symbol("skip render"); const SSRRaw = () => null; const SSRComment = () => null; const NEEDS_COMPUTATION = Symbol("invalid"); const _EFFECT_BACK_REF = Symbol("backRef"); function getSubscriber(effect, prop, data) { effect[_EFFECT_BACK_REF] || (isServer && isSsrNode(effect) ? effect.setProp("q:brefs", /* @__PURE__ */ new Map()) : effect[_EFFECT_BACK_REF] = /* @__PURE__ */ new Map()); const subMap = effect[_EFFECT_BACK_REF]; let sub = subMap.get(prop); return sub || (sub = [effect, prop], subMap.set(prop, sub)), data && (sub[3] = data), sub; } function isSsrNode(value) { return "__brand__" in value && "currentComponentNode" in value; } const throwIfQRLNotResolved = (qrl2) => { if (!qrl2.resolved) { throw qrl2.resolve(); } }; const isSignal = (value) => value instanceof SignalImpl; class SubscriptionData { constructor(data) { __publicField(this, "data"); this.data = data; } } class SignalImpl { constructor(container, value) { __publicField(this, "$untrackedValue$"); __publicField(this, "$effects$", null); __publicField(this, "$container$", null); this.$container$ = container, this.$untrackedValue$ = value; } get untrackedValue() { return this.$untrackedValue$; } set untrackedValue(value) { this.$untrackedValue$ = value; } get value() { const ctx = tryGetInvokeContext(); if (ctx) { if (null === this.$container$) { if (!ctx.$container$) { return this.untrackedValue; } this.$container$ = ctx.$container$; } else { assertTrue(!ctx.$container$ || ctx.$container$ === this.$container$); } const effectSubscriber = ctx.$effectSubscriber$; if (effectSubscriber) { const effects = this.$effects$ || (this.$effects$ = /* @__PURE__ */ new Set()); ensureContainsSubscription(effects, effectSubscriber), ensureContainsBackRef(effectSubscriber, this), addQrlToSerializationCtx(effectSubscriber, this.$container$); } } return this.untrackedValue; } set value(value) { value !== this.$untrackedValue$ && (this.$untrackedValue$ = value, triggerEffects(this.$container$, this, this.$effects$)); } valueOf() { } toString() { return this.constructor.name; } toJSON() { return { value: this.$untrackedValue$ }; } } const ensureContainsSubscription = (array, effectSubscription) => { array.add(effectSubscription); }; const ensureContainsBackRef = (array, value) => { array[2] || (array[2] = /* @__PURE__ */ new Set()), array[2].add(value); }; const addQrlToSerializationCtx = (effectSubscriber, container) => { if (container && !isDomContainer(container)) { const effect = effectSubscriber[0]; const property = effectSubscriber[1]; let qrl2 = null; isTask(effect) ? qrl2 = effect.$qrl$ : effect instanceof ComputedSignalImpl ? qrl2 = effect.$computeQrl$ : ":" === property && (qrl2 = container.getHostProp(effect, "q:renderFn")), qrl2 && container.serializationCtx.$eventQrls$.add(qrl2); } }; const triggerEffects = (container, signal, effects) => { const isBrowser2 = isDomContainer(container); if (effects) { const scheduleEffect = (effectSubscription) => { const consumer = effectSubscription[0]; const property = effectSubscription[1]; if (isTask(consumer)) { consumer.$flags$ |= 8; let choreType = 3; 1 & consumer.$flags$ && (choreType = 32), container.$scheduler$(choreType, consumer); } else if (consumer instanceof SignalImpl) { consumer instanceof ComputedSignalImpl && (consumer.$computeQrl$.resolved || container.$scheduler$(1, null, consumer.$computeQrl$)), consumer.$invalidate$(); } else if (":" === property) { const host = consumer; const qrl2 = container.getHostProp(host, "q:renderFn"); const props = container.getHostProp(host, "q:props"); container.$scheduler$(6, host, qrl2, props); } else if (isBrowser2) { if ("." === property) { container.$scheduler$(4, consumer, consumer, signal); } else { const effectData = effectSubscription[3]; if (effectData instanceof SubscriptionData) { const payload = { ...effectData.data, $value$: signal }; container.$scheduler$(5, consumer, property, payload); } } } }; for (const effect of effects) { scheduleEffect(effect); } } }; class ComputedSignalImpl extends (_b = SignalImpl, _a = _EFFECT_BACK_REF, _b) { constructor(container, fn, flags = 1) { super(container, NEEDS_COMPUTATION); __publicField(this, "$computeQrl$"); __publicField(this, "$flags$"); __publicField(this, "$forceRunEffects$", false); __publicField(this, _a, null); this.$computeQrl$ = fn, this.$flags$ = flags; } $invalidate$() { this.$flags$ |= 1, this.$forceRunEffects$ = false, this.$container$?.$scheduler$(7, null, this); } force() { this.$forceRunEffects$ = true, this.$container$?.$scheduler$(7, null, this); } get untrackedValue() { const didChange = this.$computeIfNeeded$(); return didChange && (this.$forceRunEffects$ = didChange), assertFalse(this.$untrackedValue$ === NEEDS_COMPUTATION), this.$untrackedValue$; } $computeIfNeeded$() { if (!(1 & this.$flags$)) { return false; } const computeQrl = this.$computeQrl$; throwIfQRLNotResolved(computeQrl); const ctx = tryGetInvokeContext(); const previousEffectSubscription = ctx?.$effectSubscriber$; ctx && (ctx.$effectSubscriber$ = getSubscriber(this, ".")); try { const untrackedValue = computeQrl.getFn(ctx)(); if (isPromise(untrackedValue)) { throw qError(46, [computeQrl.dev ? computeQrl.dev.file : "", computeQrl.$hash$]); } this.$flags$ &= -2; const didChange = untrackedValue !== this.$untrackedValue$; return didChange && (this.$untrackedValue$ = untrackedValue), didChange; } finally { ctx && (ctx.$effectSubscriber$ = previousEffectSubscription); } } set value(_) { throw qError(47); } get value() { return super.value; } } class WrappedSignal extends (_d = SignalImpl, _c = _EFFECT_BACK_REF, _d) { constructor(container, fn, args, fnStr, flags = 3) { super(container, NEEDS_COMPUTATION); __publicField(this, "$args$"); __publicField(this, "$func$"); __publicField(this, "$funcStr$"); __publicField(this, "$flags$"); __publicField(this, "$hostElement$", null); __publicField(this, "$forceRunEffects$", false); __publicField(this, _c, null); this.$args$ = args, this.$func$ = fn, this.$funcStr$ = fnStr, this.$flags$ = flags; } $invalidate$() { this.$flags$ |= 1, this.$forceRunEffects$ = false, this.$container$?.$scheduler$(7, this.$hostElement$, this); } force() { this.$flags$ |= 1, this.$forceRunEffects$ = false, triggerEffects(this.$container$, this, this.$effects$); } get untrackedValue() { const didChange = this.$computeIfNeeded$(); return didChange && (this.$forceRunEffects$ = didChange), assertFalse(this.$untrackedValue$ === NEEDS_COMPUTATION), this.$untrackedValue$; } $computeIfNeeded$() { if (!(1 & this.$flags$)) { return false; } const untrackedValue = trackSignal(() => this.$func$(...this.$args$), this, ".", this.$container$); const didChange = untrackedValue !== this.$untrackedValue$; return didChange && (this.$untrackedValue$ = untrackedValue), didChange; } set value(_) { throw qError(48); } get value() { return super.value; } } class SerializerSignalImpl extends ComputedSignalImpl { constructor(container, argQrl) { super(container, argQrl); __publicField(this, "$didInitialize$", false); } $computeIfNeeded$() { if (!(1 & this.$flags$)) { return false; } throwIfQRLNotResolved(this.$computeQrl$); let arg = this.$computeQrl$.resolved; "function" == typeof arg && (arg = arg()); const { deserialize, initial } = arg; const update = arg.update; const currentValue = this.$untrackedValue$ === NEEDS_COMPUTATION ? initial : this.$untrackedValue$; const untrackedValue = trackSignal(() => this.$didInitialize$ ? update?.(currentValue) : deserialize(currentValue), this, ".", this.$container$); const didChange = this.$didInitialize$ && "undefined" !== untrackedValue || untrackedValue !== this.$untrackedValue$; return this.$flags$ &= -2, this.$didInitialize$ = true, didChange && (this.$untrackedValue$ = untrackedValue), didChange; } } const isSerializerObj = (obj) => "object" == typeof obj && null !== obj && "function" == typeof obj[SerializerSymbol]; const STORE_TARGET = Symbol("store.target"); const STORE_HANDLER = Symbol("store.handler"); const STORE_ALL_PROPS = Symbol("store.all"); const getStoreHandler = (value) => value[STORE_HANDLER]; const getStoreTarget = (value) => value?.[STORE_TARGET] || null; const unwrapStore = (value) => getStoreTarget(value) || value; const isStore = (value) => STORE_TARGET in value; function createStore(container, obj, flags) { return new Proxy(obj, new StoreHandler(flags, container || null)); } const getOrCreateStore = (obj, flags, container) => { if (isSerializableObject(obj) && container) { let store = container.$storeProxyMap$.get(obj); return store || (store = createStore(container, obj, flags), container.$storeProxyMap$.set(obj, store)), store; } return obj; }; class StoreHandler { constructor($flags$, $container$) { __publicField(this, "$flags$"); __publicField(this, "$container$"); __publicField(this, "$effects$", null); this.$flags$ = $flags$, this.$container$ = $container$; } toString() { return "[Store]"; } get(target, prop) { if ("symbol" == typeof prop) { return prop === STORE_TARGET ? target : prop === STORE_HANDLER ? this : target[prop]; } const ctx = tryGetInvokeContext(); const value = target[prop]; if (ctx) { if (null === this.$container$) { if (!ctx.$container$) { return value; } this.$container$ = ctx.$container$; } else { assertTrue(!ctx.$container$ || ctx.$container$ === this.$container$); } const effectSubscriber = ctx.$effectSubscriber$; effectSubscriber && addStoreEffect(target, Array.isArray(target) ? STORE_ALL_PROPS : prop, this, effectSubscriber); } if ("toString" === prop && value === Object.prototype.toString) { return this.toString; } return 1 & this.$flags$ && "object" == typeof value && null !== value && !Object.isFrozen(value) && !isStore(value) && !Object.isFrozen(target) ? getOrCreateStore(value, this.$flags$, this.$container$) : value; } set(target, prop, value) { if ("symbol" == typeof prop) { return target[prop] = value, true; } const newValue = 1 & this.$flags$ ? unwrapStore(value) : value; if (prop in target) { newValue !== target[prop] && setNewValueAndTriggerEffects(prop, newValue, target, this); } else { setNewValueAndTriggerEffects(prop, newValue, target, this); } return true; } deleteProperty(target, prop) { return "string" == typeof prop && delete target[prop] && (triggerEffects(this.$container$, this, getEffects(target, prop, this.$effects$)), true); } has(target, prop) { if (prop === STORE_TARGET) { return true; } if ("string" == typeof prop) { const ctx = tryGetInvokeContext(); if (ctx) { const effectSubscriber = ctx.$effectSubscriber$; effectSubscriber && addStoreEffect(target, Array.isArray(target) ? STORE_ALL_PROPS : prop, this, effectSubscriber); } } return Object.prototype.hasOwnProperty.call(target, prop); } ownKeys(target) { const ctx = tryGetInvokeContext(); const effectSubscriber = ctx?.$effectSubscriber$; return effectSubscriber && addStoreEffect(target, STORE_ALL_PROPS, this, effectSubscriber), Reflect.ownKeys(target); } getOwnPropertyDescriptor(target, prop) { const descriptor = Reflect.getOwnPropertyDescriptor(target, prop); return Array.isArray(target) || "symbol" == typeof prop || descriptor && !descriptor.configurable ? descriptor : { enumerable: true, configurable: true }; } } function addStoreEffect(target, prop, store, effectSubscription) { const effectsMap = store.$effects$ || (store.$effects$ = /* @__PURE__ */ new Map()); let effects = effectsMap.get(prop); effects || (effects = /* @__PURE__ */ new Set(), effectsMap.set(prop, effects)), ensureContainsSubscription(effects, effectSubscription), ensureContainsBackRef(effectSubscription, target), addQrlToSerializationCtx(effectSubscription, store.$container$); } function setNewValueAndTriggerEffects(prop, value, target, currentStore) { target[prop] = value, triggerEffects(currentStore.$container$, currentStore, getEffects(target, prop, currentStore.$effects$)); } function getEffects(target, prop, storeEffects) { let effectsToTrigger; if (storeEffects) { if (Array.isArray(target)) { for (const effects of storeEffects.values()) { effectsToTrigger || (effectsToTrigger = /* @__PURE__ */ new Set()); for (const effect of effects) { effectsToTrigger.add(effect); } } } else { effectsToTrigger = storeEffects.get(prop); } } const storeArrayValue = storeEffects?.get(STORE_ALL_PROPS); if (storeArrayValue) { effectsToTrigger || (effectsToTrigger = /* @__PURE__ */ new Set()); for (const effect of storeArrayValue) { effectsToTrigger.add(effect); } } return effectsToTrigger || null; } _e = _EFFECT_BACK_REF; class BackRef { constructor() { __publicField(this, _e, null); } } function clearAllEffects(container, consumer) { vnode_isVNode(consumer) && vnode_isElementVNode(consumer) && ensureMaterialized(consumer); const effects = consumer[_EFFECT_BACK_REF]; if (effects) { for (const [, effect] of effects) { const backRefs = effect[2]; if (!backRefs) { return; } for (const producer of backRefs) { if (producer instanceof SignalImpl) { clearSignal(container, producer, effect); } else if (container.$storeProxyMap$.has(producer)) { const target = container.$storeProxyMap$.get(producer); clearStore(getStoreHandler(target), effect); } } } } } function clearSignal(container, producer, effect) { const effects = producer.$effects$; effects && effects.delete(effect), producer instanceof WrappedSignal && (producer.$hostElement$ = null, clearAllEffects(container, producer)); } function clearStore(producer, effect) { const effects = producer?.$effects$; if (effects) { for (const propEffects of effects.values()) { propEffects.delete(effect); } } } const runTask = (task, container, host) => { task.$flags$ &= -9, cleanupTask(task); const iCtx = newInvokeContext(container.$locale$, host, void 0, "qTask"); iCtx.$container$ = container; const taskFn = task.$qrl$.getFn(iCtx, () => clearAllEffects(container, task)); let cleanupFns = null; const cleanup2 = (fn) => { "function" == typeof fn && (cleanupFns || (cleanupFns = [], task.$destroy$ = noSerialize(() => { task.$destroy$ = null, cleanupFns.forEach((fn2) => { try { fn2(); } catch (err) { container.handleError(err, host); } }); })), cleanupFns.push(fn)); }; const taskApi = { track: (obj, prop) => { const ctx = newInvokeContext(); return ctx.$effectSubscriber$ = getSubscriber(task, ":"), ctx.$container$ = container, invoke(ctx, () => { if (isFunction(obj)) { return obj(); } if (prop) { return obj[prop]; } if (isSignal(obj)) { return obj.value; } if (isStore(obj)) { return addStoreEffect(getStoreTarget(obj), STORE_ALL_PROPS, getStoreHandler(obj), ctx.$effectSubscriber$), obj; } throw qError(2); }); }, cleanup: cleanup2 }; return safeCall(() => taskFn(taskApi), cleanup2, (err) => { if (isPromise(err)) { return err.then(() => runTask(task, container, host)); } throw err; }); }; const cleanupTask = (task) => { const destroy = task.$destroy$; if (destroy) { task.$destroy$ = null; try { destroy(); } catch (err) { logError(err); } } }; class Task extends BackRef { constructor($flags$, $index$, $el$, $qrl$, $state$, $destroy$) { super(); __publicField(this, "$flags$"); __publicField(this, "$index$"); __publicField(this, "$el$"); __publicField(this, "$qrl$"); __publicField(this, "$state$"); __publicField(this, "$destroy$"); this.$flags$ = $flags$, this.$index$ = $index$, this.$el$ = $el$, this.$qrl$ = $qrl$, this.$state$ = $state$, this.$destroy$ = $destroy$; } } const isTask = (value) => value instanceof Task; const styleContent = (styleId) => "⚡️" + styleId; function hasClassAttr(props) { for (const key in props) { if (Object.prototype.hasOwnProperty.call(props, key) && isClassAttr(key)) { return true; } } return false; } function isClassAttr(key) { return "class" === key || "className" === key; } function convertScopedStyleIdsToArray(scopedStyleIds) { return scopedStyleIds?.split(" ") ?? null; } function convertStyleIdsToString(scopedStyleIds) { return Array.from(scopedStyleIds).join(" "); } const addComponentStylePrefix = (styleId) => { if (styleId) { let idx = 0; do { styleId = styleId.substring(0, idx) + styleContent(styleId.substring(idx)); } while (0 !== (idx = styleId.indexOf(" ", idx) + 1)); } return styleId || null; }; const mapApp_findIndx = (array, key, start) => { let bottom = start >> 1; let top = array.length - 2 >> 1; for (; bottom <= top; ) { const mid = bottom + (top - bottom >> 1); const midKey = array[mid << 1]; if (midKey === key) { return mid << 1; } midKey < key ? bottom = mid + 1 : top = mid - 1; } return ~(bottom << 1); }; const mapArray_set = (array, key, value, start) => { const indx = mapApp_findIndx(array, key, start); indx >= 0 ? null == value ? array.splice(indx, 2) : array[indx + 1] = value : null != value && array.splice(~indx, 0, key, value); }; const mapArray_get = (array, key, start) => { const indx = mapApp_findIndx(array, key, start); return indx >= 0 ? array[indx + 1] : null; }; const isForeignObjectElement = (elementName) => "foreignObject" === elementName; const isSvgElement = (elementName) => "svg" === elementName || isForeignObjectElement(elementName); const isMathElement = (elementName) => "math" === elementName; const vnode_isDefaultNamespace = (vnode) => !(192 & vnode[0]); const vnode_getElementNamespaceFlags = (element) => { switch (fastNamespaceURI(element)) { case SVG_NS: return 64; case MATH_NS: return 128; default: return 0; } }; function vnode_getDomChildrenWithCorrectNamespacesToInsert(journal, domParentVNode, newChild) { const { elementNamespace, elementNamespaceFlag } = getNewElementNamespaceData(domParentVNode, newChild); let domChildren = []; if (elementNamespace === HTML_NS) { domChildren = vnode_getDOMChildNodes(journal, newChild); } else { const children = vnode_getDOMChildNodes(journal, newChild, true); for (let i = 0; i < children.length; i++) { const childVNode = children[i]; if (vnode_isTextVNode(childVNode)) { domChildren.push(childVNode[4]); continue; } if ((192 & childVNode[0]) == (192 & domParentVNode[0])) { domChildren.push(childVNode[6]); continue; } const newChildElement = vnode_cloneElementWithNamespace(childVNode, domParentVNode, elementNamespace, elementNamespaceFlag); newChildElement && domChildren.push(newChildElement); } } return domChildren; } function cloneElementWithNamespace(element, elementName, namespace) { const newElement = element.ownerDocument.createElementNS(namespace, elementName); const attributes = element.attributes; for (const attribute of attributes) { const name = attribute.name; name && ":" !== name && newElement.setAttribute(name, attribute.value); } return newElement; } function vnode_cloneElementWithNamespace(elementVNode, parentVNode, namespace, namespaceFlag) { ensureElementVNode(elementVNode); let vCursor = elementVNode; let vParent = null; let rootElement = null; let parentElement = null; for (; vCursor; ) { let childElement = null; let newChildElement = null; if (vnode_isElementVNode(vCursor)) { childElement = vCursor[6]; const childElementTag = vnode_getElementName(vCursor); const vCursorParent = vnode_getParent(vCursor); const vCursorDomParent = null == rootElement ? parentVNode : vCursorParent && vnode_getDomParentVNode(vCursorParent); if (vCursorDomParent) { const namespaceData = getNewElementNamespaceData(vCursorDomParent, vnode_getElementName(vCursor)); namespace = namespaceData.elementNamespace, namespaceFlag = namespaceData.elementNamespaceFlag; } newChildElement = cloneElementWithNamespace(childElement, childElementTag, namespace), childElement.remove(), null == rootElement && (rootElement = newChildElement), parentElement && parentElement.appendChild(newChildElement); const vFirstChild = vnode_getFirstChild(vCursor); if (vCursor[6] = newChildElement, vCursor[0] &= -193, vCursor[0] |= namespaceFlag, vFirstChild) { vCursor = vFirstChild, parentElement = newChildElement; continue; } if (shouldIgnoreChildren(childElement)) { const container = getDomContainerFromQContainerElement(childElement); if (container) { const innerContainerFirstVNode = vnode_getFirstChild(container.rootVNode); if (innerContainerFirstVNode) { vCursor = innerContainerFirstVNode, parentElement = newChildElement; continue; } } } } if (vCursor === elementVNode) { return rootElement; } const vNextSibling = vnode_getNextSibling(vCursor); if (vNextSibling) { vCursor = vNextSibling; } else { for (vParent = vnode_getParent(vCursor); vParent; ) { if (vParent === elementVNode) { return rootElement; } const vNextParentSibling = vnode_getNextSibling(vParent); if (vNextParentSibling) { return vCursor = vNextParentSibling, rootElement; } vParent = vnode_getParent(vParent); } if (null == vParent) { return rootElement; } } } return rootElement; } function isSvg(tagOrVNode) { return "string" == typeof tagOrVNode ? isSvgElement(tagOrVNode) : !!(64 & tagOrVNode[0]); } function isMath(tagOrVNode) { return "string" == typeof tagOrVNode ? isMathElement(tagOrVNode) : !!(128 & tagOrVNode[0]); } function getNewElementNamespaceData(domParentVNode, tagOrVNode) { const parentIsDefaultNamespace = !domParentVNode || !!vnode_getElementName(domParentVNode) && vnode_isDefaultNamespace(domParentVNode); const parentIsForeignObject = !parentIsDefaultNamespace && isForeignObjectElement(vnode_getElementName(domParentVNode)); let elementNamespace = HTML_NS; let elementNamespaceFlag = 0; const isElementVNodeOrString = "string" == typeof tagOrVNode || vnode_isElementVNode(tagOrVNode); if (isElementVNodeOrString && isSvg(tagOrVNode)) { elementNamespace = SVG_NS, elementNamespaceFlag = 64; } else if (isElementVNodeOrString && isMath(tagOrVNode)) { elementNamespace = MATH_NS, elementNamespaceFlag = 128; } else if (domParentVNode && !parentIsForeignObject && !parentIsDefaultNamespace) { elementNamespace = !!(64 & domParentVNode[0]) ? SVG_NS : !!(128 & domParentVNode[0]) ? MATH_NS : HTML_NS, elementNamespaceFlag = 192 & domParentVNode[0]; } return { elementNamespace, elementNamespaceFlag }; } const executeComponent = (container, renderHost, subscriptionHost, componentQRL, props) => { const iCtx = newInvokeContext(container.$locale$, subscriptionHost || void 0, void 0, "qRender"); let componentFn; subscriptionHost && (iCtx.$effectSubscriber$ = getSubscriber(subscriptionHost, ":"), iCtx.$container$ = container), container.ensureProjectionResolved(renderHost); let isInlineComponent = false; if (null === componentQRL && assertDefined(componentQRL = container.getHostProp(renderHost, "q:renderFn")), isQrl$1(componentQRL)) { (props = props || container.getHostProp(renderHost, "q:props") || EMPTY_OBJ).children && delete props.children, componentFn = componentQRL.getFn(iCtx); } else if (isQwikComponent(componentQRL)) { const qComponentFn = componentQRL; componentFn = () => invokeApply(iCtx, qComponentFn, [props || EMPTY_OBJ, null, 0]); } else { isInlineComponent = true; const inlineComponent = componentQRL; componentFn = () => invokeApply(iCtx, inlineComponent, [props || EMPTY_OBJ]); } const executeComponentWithPromiseExceptionRetry = (retryCount = 0) => safeCall(() => (isInlineComponent || (container.setHostProp(renderHost, "q:seqIdx", null), container.setHostProp(renderHost, ":onIdx", null), container.setHostProp(renderHost, "q:props", props)), vnode_isVNode(renderHost) && clearAllEffects(container, renderHost), componentFn(props)), (jsx2) => { const useOnEvents = container.getHostProp(renderHost, ":on"); return useOnEvents ? addUseOnEvents(jsx2, useOnEvents) : jsx2; }, (err) => { if (isPromise(err) && retryCount < 100) { return err.then(() => executeComponentWithPromiseExceptionRetry(retryCount++)); } throw err; }); return executeComponentWithPromiseExceptionRetry(); }; function addUseOnEvents(jsx2, useOnEvents) { const jsxElement = findFirstStringJSX(jsx2); let jsxResult = jsx2; return maybeThen(jsxElement, (jsxElement2) => { let isInvisibleComponent = false; jsxElement2 || (isInvisibleComponent = true); for (const key in useOnEvents) { if (Object.prototype.hasOwnProperty.call(useOnEvents, key)) { if (isInvisibleComponent) { if ("onQvisible$" === key) { const [jsxElement3, jsx3] = addScriptNodeForInvisibleComponents(jsxResult); jsxResult = jsx3, jsxElement3 && addUseOnEvent(jsxElement3, "document:onQinit$", useOnEvents[key]); } else if (key.startsWith("document:") || key.startsWith("window:")) { const [jsxElement3, jsx3] = addScriptNodeForInvisibleComponents(jsxResult); jsxResult = jsx3, jsxElement3 && addUseOnEvent(jsxElement3, key, useOnEvents[key]); } else ; } else { jsxElement2 && addUseOnEvent(jsxElement2, key, useOnEvents[key]); } } } return jsxResult; }); } function addUseOnEvent(jsxElement, key, value) { let props = jsxElement.props; props === EMPTY_OBJ && (props = jsxElement.props = {}); let propValue = props[key]; void 0 === propValue ? propValue = [] : Array.isArray(propValue) || (propValue = [propValue]), propValue.push(...value), props[key] = propValue; } function findFirstStringJSX(jsx2) { const queue = [jsx2]; for (; queue.length; ) { const jsx3 = queue.shift(); if (isJSXNode(jsx3)) { if ("string" == typeof jsx3.type) { return jsx3; } queue.push(jsx3.children); } else if (Array.isArray(jsx3)) { queue.push(...jsx3); } else { if (isPromise(jsx3)) { return maybeThen(jsx3, (jsx4) => findFirstStringJSX(jsx4)); } if (isSignal(jsx3)) { return findFirstStringJSX(untrack(() => jsx3.value)); } } } return null; } function addScriptNodeForInvisibleComponents(jsx2) { if (isJSXNode(jsx2)) { const jsxElement = new JSXNodeImpl("script", {}, { type: "placeholder", hidden: "" }, null, 3); return jsx2.type === Slot ? [jsxElement, _jsxSorted(Fragment, null, null, [jsx2, jsxElement], 0, null)] : (null == jsx2.children ? jsx2.children = jsxElement : Array.isArray(jsx2.children) ? jsx2.children.push(jsxElement) : jsx2.children = [jsx2.children, jsxElement], [jsxElement, jsx2]); } if (Array.isArray(jsx2) && jsx2.length) { const [jsxElement, _] = addScriptNodeForInvisibleComponents(jsx2[0]); return [jsxElement, jsx2]; } return [null, null]; } const _CONST_PROPS = Symbol("CONST"); const _VAR_PROPS = Symbol("VAR"); function isSlotProp(prop) { return !prop.startsWith("q:") && !prop.startsWith(":"); } function escapeHTML(html) { let escapedHTML = ""; const length = html.length; let idx = 0; let lastIdx = idx; for (; idx < length; idx++) { const ch = html.charCodeAt(idx); if (60 === ch) { escapedHTML += html.substring(lastIdx, idx) + "&lt;"; } else if (62 === ch) { escapedHTML += html.substring(lastIdx, idx) + "&gt;"; } else if (38 === ch) { escapedHTML += html.substring(lastIdx, idx) + "&amp;"; } else if (34 === ch) { escapedHTML += html.substring(lastIdx, idx) + "&quot;"; } else { if (39 !== ch) { continue; } escapedHTML += html.substring(lastIdx, idx) + "&#39;"; } lastIdx = idx + 1; } return 0 === lastIdx ? html : escapedHTML + html.substring(lastIdx); } const unitlessNumbers = /* @__PURE__ */ new Set(["animationIterationCount", "aspectRatio", "borderImageOutset", "borderImageSlice", "borderImageWidth", "boxFlex", "boxFlexGroup", "boxOrdinalGroup", "columnCount", "columns", "flex", "flexGrow", "flexShrink", "gridArea", "gridRow", "gridRowEnd", "gridRowStart", "gridColumn", "gridColumnEnd", "gridColumnStart", "fontWeight", "lineClamp", "lineHeight", "opacity", "order", "orphans", "scale", "tabSize", "widows", "zIndex", "zoom", "MozAnimationIterationCount", "MozBoxFlex", "msFlex", "msFlexPositive", "WebkitAnimationIterationCount", "WebkitBoxFlex", "WebkitBoxOrdinalGroup", "WebkitColumnCount", "WebkitColumns", "WebkitFlex", "WebkitFlexGrow", "WebkitFlexShrink", "WebkitLineClamp"]); const isUnitlessNumber = (name) => unitlessNumbers.has(name); const serializeClass = (obj) => { if (!obj) { return ""; } if (isString(obj)) { return obj.trim(); } const classes = []; if (isArray(obj)) { for (const o of obj) { const classList = serializeClass(o); classList && classes.push(classList); } } else { for (const [key, value] of Object.entries(obj)) { value && classes.push(key.trim()); } } return classes.join(" "); }; const fromCamelToKebabCaseWithDash = (text) => text.replace(/([A-Z])/g, "-$1").toLowerCase(); 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]; null != value && "function" != typeof value && (key.startsWith("--") ? chunks.push(key + ":" + value) : chunks.push(fromCamelToKebabCaseWithDash(key) + ":" + setValueForStyle(key, value))); } } return chunks.join(";"); } } return String(obj); }; const serializeBooleanOrNumberAttribute = (value) => null != value ? String(value) : null; function serializeAttribute(key, value, styleScopedId) { if (isClassAttr(key)) { const serializedClass = serializeClass(value); value = styleScopedId ? styleScopedId + (serializedClass.length ? " " + serializedClass : serializedClass) : serializedClass; } else { "style" === key ? value = stringifyStyle(value) : isEnumeratedBooleanAttribute(key) || "number" == typeof value ? value = serializeBooleanOrNumberAttribute(value) : false === value || null == value ? value = null : true === value && isPreventDefault(key) && (value = ""); } return value; } function isEnumeratedBooleanAttribute(key) { return isAriaAttribute(key) || ["spellcheck", "draggable", "contenteditable"].includes(key); } const setValueForStyle = (styleName, value) => "number" != typeof value || 0 === value || isUnitlessNumber(styleName) ? value : value + "px"; function isAriaAttribute(prop) { return prop.startsWith("aria-"); } function getFileLocationFromJsx(jsxDev) { if (!jsxDev) { return null; } const sanitizedFileName = jsxDev.fileName?.replace(/\\/g, "/"); return sanitizedFileName ? `${sanitizedFileName}:${jsxDev.lineNumber}:${jsxDev.columnNumber}` : null; } const vnode_diff = (container, jsxNode, vStartNode, scopedStyleIdPrefix) => { let journal = container.$journal$; const stack2 = []; const asyncQueue = []; let vParent = null; let vCurrent = null; let vNewNode = null; let vSiblings = null; let vSiblingsArray = null; let jsxChildren = null; let jsxValue = null; let jsxIdx = 0; let jsxCount = 0; let shouldAdvance = true; return diff(jsxNode, vStartNode), function drainAsyncQueue() { for (; asyncQueue.length; ) { const jsxNode2 = asyncQueue.shift(); const vHostNode = asyncQueue.shift(); if (isPromise(jsxNode2)) { return jsxNode2.then((jsxNode3) => (diff(jsxNode3, vHostNode), drainAsyncQueue())); } diff(jsxNode2, vHostNode); } }(); function diff(jsxNode2, vStartNode2) { for (vParent = vStartNode2, vNewNode = null, vCurrent = vnode_getFirstChild(vStartNode2), stackPush(jsxNode2, true); stack2.length; ) { for (; jsxIdx < jsxCount; ) { if ("string" == typeof jsxValue) { expectText(jsxValue); } else if ("number" == typeof jsxValue) { expectText(String(jsxValue)); } else if (jsxValue && "object" == typeof jsxValue) { if (Array.isArray(jsxValue)) { descend(jsxValue, false); } else if (isSignal(jsxValue)) { vCurrent && clearAllEffects(container, vCurrent), expectVirtual("S", null), descend(trackSignalAndAssignHost(jsxValue, vNewNode || vCurrent, ".", container), true); } else if (isPromise(jsxValue)) { expectVirtual("A", null), asyncQueue.push(jsxValue, vNewNode || vCurrent); } else if (isJSXNode(jsxValue)) { const type = jsxValue.type; "string" == typeof type ? (expectNoMoreTextNodes(), expectElement(jsxValue, type), descend(jsxValue.children, true)) : "function" == typeof type && (type === Fragment ? (expectNoMoreTextNodes(), expectVirtual("F", jsxValue.key), descend(jsxValue.children, true)) : type === Slot ? (expectNoMoreTextNodes(), expectSlot() || descend(jsxValue.children, true)) : type === Projection ? (expectProjection(), descend(jsxValue.children, true)) : type === SSRComment || type === SSRRaw ? expectNoMore() : (expectNoMoreTextNodes(), expectComponent(type))); } } else { jsxValue === SkipRender ? journal = [] : expectText(""); } advance(); } expectNoMore(), ascend(); } } function advance() { if (shouldAdvance) { if (jsxIdx++, jsxIdx < jsxCount) { jsxValue = jsxChildren[jsxIdx]; } else if (false === stack2[stack2.length - 1]) { return ascend(); } null !== vNewNode ? vNewNode = null : advanceToNextSibling(); } else { shouldAdvance = true; } } function peekNextSibling() { return vCurrent ? vnode_getNextSibling(vCurrent) : null; } function advanceToNextSibling() { vCurrent = peekNextSibling(); } function descend(children, descendVNode) { null != children ? (stackPush(children, descendVNode), descendVNode && (vSiblings = null, vSiblingsArray = null, vParent = vNewNode || vCurrent, vCurrent = vnode_getFirstChild(vParent), vNewNode = null), shouldAdvance = false) : function() { const vFirstChild = vCurrent && vnode_getFirstChild(vCurrent); if (null !== vFirstChild) { let vChild = vFirstChild; for (; vChild; ) { cleanup(container, vChild), vChild = vnode_getNextSibling(vChild); } vnode_truncate(journal, vCurrent, vFirstChild); } }(); } function ascend() { stack2.pop() && (vSiblings = stack2.pop(), vSiblingsArray = stack2.pop(), vNewNode = stack2.pop(), vCurrent = stack2.pop(), vParent = stack2.pop()), jsxValue = stack2.pop(), jsxCount = stack2.pop(), jsxIdx = stack2.pop(), jsxChildren = stack2.pop(), advance(); } function stackPush(children, descendVNode) { stack2.push(jsxChildren, jsxIdx, jsxCount, jsxValue), descendVNode && stack2.push(vParent, vCurrent, vNewNode, vSiblingsArray, vSiblings), stack2.push(descendVNode), Array.isArray(children) ? (jsxIdx = 0, jsxCount = children.length, jsxChildren = children, jsxValue = jsxCount > 0 ? children[0] : null) : void 0 === children ? (jsxIdx = 0, jsxValue = null, jsxChildren = null, jsxCount = 0) : (jsxIdx = 0, jsxValue = children, jsxChildren = null, jsxCount = 1); } function getInsertBefore() { return vNewNode ? vCurrent : peekNextSibling(); } function expectProjection() { const slotName = jsxValue.key; vCurrent = vnode_getProp(vParent, slotName, (id) => vnode_locate(container.rootVNode, id)), vCurrent = vCurrent && 32 & vCurrent[0] ? null : vCurrent, null == vCurrent && (vNewNode = vnode_newVirtual(), vnode_setProp(vNewNode, QSlot, slotName), vnode_setProp(vNewNode, "q:sparent", vParent), vnode_setProp(vParent, slotName, vNewNode)); } function expectSlot() { const vHost = vnode_getProjectionParentComponent(vParent, container.rootVNode); const slotNameKey = function(vHost2) { const jsxNode2 = jsxValue; const constProps = jsxNode2.constProps; if (constProps && "object" == typeof constProps && "name" in constProps) { const constValue = constProps.name; if (vHost2 && constValue instanceof WrappedSignal) { return trackSignalAndAssignHost(constValue, vHost2, ":", container); } } return directGetPropsProxyProp(jsxNode2, "name") || ""; }(vHost); const vProjectedNode = vHost ? vnode_getProp(vHost, slotNameKey, null) : null; return null == vProjectedNode ? (vnode_insertBefore(journal, vParent, vNewNode = vnode_newVirtual(), vCurrent && getInsertBefore()), vnode_setProp(vNewNode, QSlot, slotNameKey), vHost && vnode_setProp(vHost, slotNameKey, vNewNode), false) : (vProjectedNode === vCurrent || (vnode_insertBefore(journal, vParent, vNewNode = vProjectedNode, vCurrent && getInsertBefore()), vnode_setProp(vNewNode, QSlot, slotNameKey), vHost && vnode_setProp(vHost, slotNameKey, vNewNode), isDev), true); } function expectNoMore() { if (null !== vCurrent) { for (; vCurrent; ) { const toRemove = vCurrent; advanceToNextSibling(), vParent === vnode_getParent(toRemove) && (cleanup(container, toRemove), vnode_remove(journal, vParent, toRemove, true)); } } } function expectNoMoreTextNodes() { for (; null !== vCurrent && vnode_isTextVNode(vCurrent); ) { cleanup(container, vCurrent); const toRemove = vCurrent; advanceToNextSibling(), vnode_remove(journal, vParent, toRemove, true); } } function createNewElement(jsx2, elementName, currentFile) { const element = function(elementName2) { const domParentVNode = vnode_getDomParentVNode(vParent); const { elementNamespace, elementNamespaceFlag } = getNewElementNamespaceData(domParentVNode, elementName2); const element2 = container.document.createElementNS(elementNamespace, elementName2); return vNewNode = vnode_newElement(element2, elementName2), vNewNode[0] |= elementNamespaceFlag, element2; }(elementName); const { constProps } = jsx2; let needsQDispatchEventPatch = false; if (constProps) { for (const key2 in constProps) { let value = constProps[key2]; if (isJsxPropertyAnEventName(key2)) { const eventName = getEventNameFromJsxEvent(key2); const scope = getEventNameScopeFromJsxEvent(key2); if (eventName && (vnode_setProp(vNewNode, HANDLER_PREFIX + ":" + scope + ":" + eventName, value), registerQwikLoaderEvent(eventName)), scope) { const htmlEvent = jsxEventToHtmlAttribute(key2); htmlEvent && vnode_setAttr(journal, vNewNode, htmlEvent, ""); } needsQDispatchEventPatch = true; } else { if ("ref" === key2) { if (isSignal(value)) { value.value = element; continue; } if ("function" == typeof value) { value(element); continue; } if (null == value) { continue; } throw qError(32, [currentFile]); } if (isSignal(value)) { const signalData = new SubscriptionData({ $scopedStyleIdPrefix$: scopedStyleIdPrefix, $isConst$: true }); value = trackSignalAndAssignHost(value, vNewNode, key2, container, signalData); } if (key2 !== dangerouslySetInnerHTML) { if ("textarea" !== elementName || "value" !== key2) { value = serializeAttribute(key2, value, scopedStyleIdPrefix), null != value && element.setAttribute(key2, String(value)); } else { if (value && "string" != typeof value) { continue; } element.value = escapeHTML(value || ""); } } else { element.innerHTML = value, element.setAttribute("q:container", "html"); } } } } const key = jsx2.key; key && (element.setAttribute("q:key", key), vnode_setProp(vNewNode, "q:key", key)); return !(hasClassAttr(jsx2.varProps) || jsx2.constProps && hasClassAttr(jsx2.constProps)) && scopedStyleIdPrefix && element.setAttribute("class", scopedStyleIdPrefix), vnod