'use strict'; if (typeof globalThis == 'undefined') { const e = 'undefined' != typeof global ? global : 'undefined' != typeof window ? window : 'undefined' != typeof self ? self : {}; e.globalThis = e; } Object.defineProperty(exports, '__esModule', { value: true }); function _interopNamespace(e) { if (e && e.__esModule) return e; var n = Object.create(null); if (e) { Object.keys(e).forEach(function (k) { if (k !== 'default') { var d = Object.getOwnPropertyDescriptor(e, k); Object.defineProperty(n, k, d.get ? d : { enumerable: true, get: function () { return e[k]; } }); } }); } n["default"] = e; return Object.freeze(n); } /** * @license * 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 */ // minification can replace the `globalThis.qDev` with `false` // which will remove all dev code within from the build const qDev = true; /** * @license * 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 */ const EMPTY_ARRAY = []; const EMPTY_OBJ = {}; if (qDev) { Object.freeze(EMPTY_ARRAY); Object.freeze(EMPTY_OBJ); } function isQrl(value) { return value instanceof QRLInternal; } class QRL { constructor(chunk, symbol, symbolRef, symbolFn, capture, captureRef, guard) { this.chunk = chunk; this.symbol = symbol; this.symbolRef = symbolRef; this.symbolFn = symbolFn; this.capture = capture; this.captureRef = captureRef; this.guard = guard; this.canonicalChunk = chunk.replace(FIND_EXT, ''); } } const QRLInternal = QRL; // https://regexr.com/6enjv const FIND_EXT = /\.[\w?=&]+$/; /** * @license * 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 assertDefined(value, text) { if (qDev) { if (value != null) return; throw newError(text || 'Expected defined value.'); } } function assertNotEqual(value1, value2, text) { if (qDev) { if (value1 !== value2) return; throw newError(text || `Expected '${value1}' !== '${value2}'.`); } } function assertEqual(value1, value2, text) { if (qDev) { if (value1 === value2) return; throw newError(text || `Expected '${value1}' === '${value2}'.`); } } function assertGreaterOrEqual(value1, value2, text) { if (qDev) { if (value1 >= value2) return; throw newError(text || `Expected '${value1}' >= '${value2}'.`); } } function assertGreater(value1, value2, text) { if (qDev) { if (value1 > value2) return; throw newError(text || `Expected '${value1}' > '${value2}'.`); } } function newError(text) { debugger; // eslint-disable-line no-debugger const error = new Error(text); console.error(error); // eslint-disable-line no-console return error; } /** * @license * 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 */ let runtimeSymbolId = 0; const RUNTIME_QRL = '/runtimeQRL'; // https://regexr.com/68v72 const EXTRACT_IMPORT_PATH = /\(\s*(['"])([^\1]+)\1\s*\)/; // https://regexr.com/690ds const EXTRACT_SELF_IMPORT = /Promise\s*\.\s*resolve/; // https://regexr.com/6a83h const EXTRACT_FILE_NAME = /[\\/(]([\w\d.\-_]+\.(js|ts)x?):/; function toInternalQRL(qrl) { assertEqual(isQrl(qrl), true); return qrl; } function staticQrl(chunkOrFn, symbol, lexicalScopeCapture = EMPTY_ARRAY) { let chunk; let symbolFn = null; if (typeof chunkOrFn === 'string') { chunk = chunkOrFn; } else if (typeof chunkOrFn === 'function') { symbolFn = chunkOrFn; let match; const srcCode = String(chunkOrFn); if ((match = srcCode.match(EXTRACT_IMPORT_PATH)) && match[2]) { chunk = match[2]; } else if ((match = srcCode.match(EXTRACT_SELF_IMPORT))) { const ref = 'QWIK-SELF'; const frames = new Error(ref).stack.split('\n'); const start = frames.findIndex((f) => f.includes(ref)); const frame = frames[start + 2]; match = frame.match(EXTRACT_FILE_NAME); if (!match) { chunk = 'main'; } else { chunk = match[1]; } } else { throw new Error('Q-ERROR: Dynamic import not found: ' + srcCode); } } else { throw new Error('Q-ERROR: Unknown type argument: ' + chunkOrFn); } return new QRLInternal(chunk, symbol, null, symbolFn, null, lexicalScopeCapture, null); } function runtimeQrl(symbol, lexicalScopeCapture = EMPTY_ARRAY) { return new QRLInternal(RUNTIME_QRL, 's' + runtimeSymbolId++, symbol, null, null, lexicalScopeCapture, null); } function stringifyQRL(qrl, element) { const qrl_ = toInternalQRL(qrl); const parts = [qrl_.chunk]; const symbol = qrl_.symbol; if (symbol && symbol !== 'default') { parts.push('#', symbol); } const guard = qrl_.guard; guard === null || guard === void 0 ? void 0 : guard.forEach((value, key) => parts.push('|', key, value && value.length ? '.' + value.join('.') : '')); const capture = qrl_.capture; if (capture && capture.length > 0) { parts.push(JSON.stringify(capture)); } const qrlString = parts.join(''); if (qrl_.chunk === RUNTIME_QRL && element) { const qrls = element.__qrls__ || (element.__qrls__ = new Set()); qrls.add(qrl); } return qrlString; } /** * `./chunk#symbol|symbol.propA.propB|[captures] */ function parseQRL(qrl, element) { if (element) { const qrls = element.__qrls__; if (qrls) { for (const runtimeQrl of qrls) { if (stringifyQRL(runtimeQrl) == qrl) { return runtimeQrl; } } } } const endIdx = qrl.length; const hashIdx = indexOf(qrl, 0, '#'); const guardIdx = indexOf(qrl, hashIdx, '|'); const captureIdx = indexOf(qrl, guardIdx, '['); const chunkEndIdx = Math.min(hashIdx, guardIdx, captureIdx); const chunk = qrl.substring(0, chunkEndIdx); const symbolStartIdx = hashIdx == endIdx ? hashIdx : hashIdx + 1; const symbolEndIdx = Math.min(guardIdx, captureIdx); const symbol = symbolStartIdx == symbolEndIdx ? 'default' : qrl.substring(symbolStartIdx, symbolEndIdx); const guardStartIdx = guardIdx; const guardEndIdx = captureIdx; const guard = guardStartIdx < guardEndIdx ? parseGuard(qrl.substring(guardStartIdx, guardEndIdx)) : null; const captureStartIdx = captureIdx; const captureEndIdx = endIdx; const capture = captureStartIdx === captureEndIdx ? EMPTY_ARRAY : JSONparse(qrl.substring(captureStartIdx, captureEndIdx)); if (chunk === RUNTIME_QRL) { console.error(`Q-ERROR: '${qrl}' is runtime but no instance found on element.`); } return new QRLInternal(chunk, symbol, null, null, capture, null, guard); } function JSONparse(json) { try { return JSON.parse(json); } catch (e) { console.error('JSON:', json); throw e; } } function parseGuard(text) { let map = null; if (text) { text.split('|').forEach((obj) => { if (obj) { const parts = obj.split('.'); const id = parts.shift(); if (!map) map = new Map(); map.set(id, parts); } }); } return map; } function indexOf(text, startIdx, char) { const endIdx = text.length; const charIdx = text.indexOf(char, startIdx == endIdx ? 0 : startIdx); return charIdx == -1 ? endIdx : charIdx; } function toQrlOrError(symbolOrQrl) { if (!isQrl(symbolOrQrl)) { if (typeof symbolOrQrl == 'function' || typeof symbolOrQrl == 'string') { symbolOrQrl = runtimeQrl(symbolOrQrl); } else { // TODO(misko): centralize throw new Error(`Q-ERROR Only 'function's and 'string's are supported.`); } } return symbolOrQrl; } /** * Returns true if the `node` is `Element` and of the right `tagName`. * * @param node * @private */ function isDomElementWithTagName(node, tagName) { return isHtmlElement(node) && node.tagName.toUpperCase() == tagName.toUpperCase(); } /** * @private */ function isTemplateElement(node) { return isDomElementWithTagName(node, 'template'); } /** * @private */ function isQSLotTemplateElement(node) { return isTemplateElement(node) && node.hasAttribute("q:slot" /* QSlotAttr */); } /** * @private */ function isComponentElement(node) { return isHtmlElement(node) && node.hasAttribute("on:q-render" /* OnRenderAttr */); } /** * @private */ function isHtmlElement(node) { return node ? node.nodeType === 1 /* ELEMENT_NODE */ : false; } /** * @license * 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 isNode(value) { return value && typeof value.nodeType == 'number'; } function isDocument(value) { return value && value.nodeType == 9 /* DOCUMENT_NODE */; } function isElement(value) { return isNode(value) && value.nodeType == 1 /* ELEMENT_NODE */; } function isComment(value) { return isNode(value) && value.nodeType == 8 /* COMMENT_NODE */; } const createPlatform = (doc) => { let queuePromise; let storePromise; const moduleCache = new Map(); return { importSymbol(element, url, symbolName) { const urlDoc = toUrl(element.ownerDocument, element, url).toString(); const urlCopy = new URL(urlDoc); urlCopy.hash = ''; urlCopy.search = ''; const importURL = urlCopy.href; const mod = moduleCache.get(importURL); if (mod) { return mod[symbolName]; } return (function (t) { return Promise.resolve().then(function () { return /*#__PURE__*/_interopNamespace(require(t)); }); })(/* @vite-ignore */ importURL).then((mod) => { moduleCache.set(importURL, mod); return mod[symbolName]; }); }, queueRender: (renderMarked) => { if (!queuePromise) { queuePromise = new Promise((resolve, reject) => doc.defaultView.requestAnimationFrame(() => { queuePromise = null; renderMarked(doc).then(resolve, reject); })); } return queuePromise; }, queueStoreFlush: (flushStore) => { if (!storePromise) { storePromise = new Promise((resolve, reject) => doc.defaultView.requestAnimationFrame(() => { storePromise = null; flushStore(doc).then(resolve, reject); })); } return storePromise; }, }; }; /** * Convert relative base URI and relative URL into a fully qualified URL. * * @param base -`QRL`s are relative, and therefore they need a base for resolution. * - `Element` use `base.ownerDocument.baseURI` * - `Document` use `base.baseURI` * - `string` use `base` as is * - `QConfig` use `base.baseURI` * @param url - relative URL * @returns fully qualified URL. */ function toUrl(doc, element, url) { let _url; let _base = undefined; if (url === undefined) { // recursive call if (element) { _url = element.getAttribute('q:base'); _base = toUrl(doc, element.parentNode && element.parentNode.closest('[q\\:base]')); } else { _url = doc.baseURI; } } else if (url) { (_url = url), (_base = toUrl(doc, element.closest('[q\\:base]'))); } else { throw new Error('INTERNAL ERROR'); } return new URL(String(_url), _base); } /** * @public */ const setPlatform = (doc, plt) => (doc[DocumentPlatform] = plt); /** * @public */ const getPlatform = (docOrNode) => { const doc = (isDocument(docOrNode) ? docOrNode : docOrNode.ownerDocument); return doc[DocumentPlatform] || (doc[DocumentPlatform] = createPlatform(doc)); }; const DocumentPlatform = /*@__PURE__*/ Symbol(); // // !!DO NOT EDIT THIS COMMENT DIRECTLY!!! (edit https://hackmd.io/m5DzCi5MTa26LuUj5t3HpQ#qrlImport instead) /** * Lazy-load a `QRL` symbol and return the lazy-loaded value. * * See: `QRL` * * @param element - Location of the URL to resolve against. This is needed to take `q:base` into * account. * @param qrl - QRL to load. * @returns A resolved QRL value as a Promise. * @public */ // async function qrlImport(element, qrl) { const qrl_ = toInternalQRL(qrl); if (qrl_.symbolRef) return qrl_.symbolRef; const doc = element.ownerDocument; if (qrl_.symbolFn) { return (qrl_.symbolRef = qrl_.symbolFn().then((module) => module[qrl_.symbol])); } else { return (qrl_.symbolRef = await getPlatform(doc).importSymbol(element, qrl_.chunk, qrl_.symbol)); } } // // !!DO NOT EDIT THIS COMMENT DIRECTLY!!! (edit https://hackmd.io/m5DzCi5MTa26LuUj5t3HpQ#$ instead) /** * Qwik Optimizer marker function. * * Use `$(...)` to tell Qwik Optimizer to extract the expression in `$(...)` into a lazy-loadable * resource referenced by `QRL`. * * See: `implicit$FirstArg` for additional `____$(...)` rules. * * In this example `$(...)` is used to capture the callback function of `onmousemove` into * lazy-loadable reference. This allows the code to refer to the function without actually * loading the function. In this example, the callback function does not get loaded until * `mousemove` event fires. * * ```typescript * onDocument( * 'mousemove', * $(() => console.log('mousemove')) * ); * ``` * * In this code the Qwik Optimizer detects `$(...)` and transforms the code into: * * ```typescript * // FILE: * onDocument('mousemove', qrl('./chunk-abc.js', 'onMousemove')); * * // FILE: chunk-abc.js * export const onMousemove = () => console.log('mousemove'); * ``` * * ## Special Rules * * The Qwik Optimizer places special rules on functions that can be lazy-loaded. * * 1. The expression of the `$(expression)` function must be importable by the system. * (expression shows up in `import` or has `export`) * 2. If inlined function then all lexically captured values must be: * - importable (vars shows up in `import` or has `export`) * - const (The capturing process differs from JS capturing in that writing to captured * variables does not update them, and therefore writes are forbidden. The best practice is that * all captured variables are constants.) * - Must be runtime serializable. * * ```typescript * import { importedFn } from './example'; * * export const greet = () => console.log('greet'); * function topLevelFn() {} * * function myCode() { * const store = createStore({}); * function localFn() {} * // Valid Examples * $(greet); // greet is importable * $(importedFn); // importedFn is importable * $(() => greet()); // greet is importable; * $(() => importedFn()); // importedFn is importable * $(() => console.log(store)); // store is serializable. * * // Compile time errors * $(topLevelFn); // ERROR: `topLevelFn` not importable * $(() => topLevelFn()); // ERROR: `topLevelFn` not importable * * // Runtime errors * $(localFn); // ERROR: `localFn` fails serialization * $(() => localFn()); // ERROR: `localFn` fails serialization * } * * ``` * * @param expression - Expression which should be lazy loaded * @public */ // function $(expression) { return runtimeQrl(expression); } // // !!DO NOT EDIT THIS COMMENT DIRECTLY!!! (edit https://hackmd.io/m5DzCi5MTa26LuUj5t3HpQ#implicit$FirstArg instead) /** * Create a `____$(...)` convenience method from `___(...)`. * * It is very common for functions to take a lazy-loadable resource as a first argument. For this * reason, the Qwik Optimizer automatically extracts the first argument from any function which * ends in `$`. * * This means that `foo$(arg0)` and `foo($(arg0))` are equivalent with respect to Qwik Optimizer. * The former is just a shorthand for the latter. * * For example all of these function call are equivalent: * * - `component$(() => {...})` is same as `onRender($(() => {...}))` * - `$(() => <>...)` is same as `onRender($(() => <>...))` * * ```typescript * export function myApi(callback: QRL<() => void>): void { * // ... * } * * export const myApi$ = implicit$FirstArg(myApi); * // type of myApi$: (callback: () => void): void * * // can be used as: * myApi$(() => console.log('callback')); * * // will be transpiled to: * // FILE: * myApi(qrl('./chunk-abc.js', 'callback')); * * // FILE: chunk-abc.js * export const callback = () => console.log('callback'); * ``` * * @param fn - function that should have its first argument automatically `$`. * @public */ // function implicit$FirstArg(fn) { return function (first, ...rest) { return fn.call(null, $(first), ...rest); }; } // // !!DO NOT EDIT THIS COMMENT DIRECTLY!!! (edit https://hackmd.io/m5DzCi5MTa26LuUj5t3HpQ#qrl instead) /** * Used by Qwik Optimizer to point to lazy-loaded resources. * * This function should be used by the Qwik Optimizer only. The function should not be directly * referred to in the source code of the application. * * See: `QRL`, `$(...)` * * @param chunkOrFn - Chunk name (or function which is stringified to extract chunk name) * @param symbol - Symbol to lazy load * @param lexicalScopeCapture - a set of lexically scoped variables to capture. * @public */ // const qrl = staticQrl; /** * @license * 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 stringifyDebug(value) { if (value == null) return String(value); if (typeof value === 'function') return value.name; if (isHtmlElement(value)) return stringifyElement(value); if (value instanceof URL) return String(value); if (typeof value === 'object') return JSON.stringify(value, function (key, value) { if (isHtmlElement(value)) return stringifyElement(value); return value; }); return String(value); } function stringifyElement(element) { let html = '<' + element.tagName.toLowerCase(); const attributes = element.attributes; const names = []; for (let i = 0; i < attributes.length; i++) { names.push(attributes[i].name); } names.sort(); for (let i = 0; i < names.length; i++) { const name = names[i]; let value = element.getAttribute(name); if (value === null || value === void 0 ? void 0 : value.startsWith('file:/')) { value = value.replace(/(file:\/\/).*(\/.*)$/, (all, protocol, file) => protocol + '...' + file); } html += ' ' + name + (value == null || value == '' ? '' : "='" + value.replace("'", ''') + "'"); } return html + '>'; } /** * @license * 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 qError(code, ...args) { if (qDev) { const text = codeToText(code); const parts = text.split('{}'); const error = parts .map((value, index) => { return value + (index === parts.length - 1 ? '' : stringifyDebug(args[index])); }) .join(''); debugger; // eslint-disable-line no-debugger return new Error(error); } else { return new Error(`QError ` + code); } } function codeToText(code) { const area = { 0: 'ERROR', 1: 'QRL-ERROR', 2: 'INJECTOR-ERROR', 3: 'SERVICE-ERROR', 4: 'COMPONENT-ERROR', 5: 'PROVIDER-ERROR', 6: 'RENDER-ERROR', 7: 'EVENT-ERROR', }[Math.floor(code / 100)]; const text = { [1 /* Core_qConfigNotFound_path */]: "QConfig not found in path '{}'.", [2 /* Core_unrecognizedStack_frame */]: "Unrecognized stack format '{}'", [3 /* Core_noAttribute_atr1_element */]: "Could not find entity state '{}' at '{}' or any of it's parents.", [4 /* Core_noAttribute_atr1_attr2_element */]: "Could not find entity state '{}' ( or entity provider '{}') at '{}' or any of it's parents.", [5 /* Core_missingProperty_name_props */]: "Missing property '{}' in props '{}'.", [6 /* Core_missingExport_name_url_props */]: "Missing export '{}' from '{}'. Exported symbols are: {}", ////////////// [100 /* QRL_expectFunction_url_actual */]: "QRL '${}' should point to function, was '{}'.", ////////////// [200 /* Injector_noHost_element */]: "Can't find host element above '{}'.", [201 /* Injector_expectedSpecificInjector_expected_actual */]: "Provider is expecting '{}' but got '{}'.", [202 /* Injector_notElement_arg */]: "Expected 'Element' was '{}'.", [203 /* Injector_wrongMethodThis_expected_actual */]: "Expected injection 'this' to be of type '{}', but was of type '{}'.", [204 /* Injector_missingSerializedState_entityKey_element */]: "Entity key '{}' is found on '{}' but does not contain state. Was 'serializeState()' not run during dehydration?", [206 /* Injector_notFound_element */]: "No injector can be found starting at '{}'.", [207 /* Injector_eventInjectorNotSerializable */]: 'EventInjector does not support serialization.', ////////////// [300 /* Entity_notValidKey_key */]: "Data key '{}' is not a valid key.\n" + ' - Data key can only contain characters (preferably lowercase) or number\n' + ' - Data key is prefixed with entity name\n' + " - Data key is made up from parts that are separated with ':'.", [301 /* Entity_keyAlreadyExists_key */]: "A entity with key '{}' already exists.", [303 /* Entity_invalidAttribute_name */]: "'{}' is not a valid attribute. " + "Attributes can only contain 'a-z' (lowercase), '0-9', '-' and '_'.", [304 /* Entity_missingExpandoOrState_attrName */]: "Found '{}' but expando did not have entity and attribute did not have state.", [305 /* Entity_elementMissingEntityAttr_element_attr */]: "Element '{}' is missing entity attribute definition '{}'.", [306 /* Entity_noState_entity_props */]: "Unable to create state for entity '{}' with props '{}' because no state found and '$newState()' method was not defined on entity.", [307 /* Entity_expected_obj */]: "'{}' is not an instance of 'Entity'.", [308 /* Entity_overridesConstructor_entity */]: "'{}' overrides 'constructor' property preventing 'EntityType' retrieval.", [311 /* Entity_no$keyProps_entity */]: "Entity '{}' does not define '$keyProps'.", [310 /* Entity_no$type_entity */]: "Entity '{}' must have static '$type' property defining the name of the entity.", [312 /* Entity_no$qrl_entity */]: "Entity '{}' must have static '$qrl' property defining the import location of the entity.", [313 /* Entity_nameCollision_name_currentQrl_expectedQrl */]: "Name collision. Already have entity named '{}' with QRL '{}' but expected QRL '{}'.", [309 /* Entity_keyMissingParts_key_key */]: "Entity key '{}' is missing values. Expecting '{}:someValue'.", [314 /* Entity_keyTooManyParts_entity_parts_key */]: "Entity '{}' defines '$keyProps' as '{}'. Actual key '{}' has more parts than entity defines.", [315 /* Entity_keyNameMismatch_key_name_entity_name */]: "Key '{}' belongs to entity named '{}', but expected entity '{}' with name '{}'.", [316 /* Entity_stateMissingKey_state */]: "Entity state is missing '$key'. Are you sure you passed in state? Got '{}'.", ////////////// [400 /* Component_bindNeedsKey */]: "'bind:' must have an key. (Example: 'bind:key=\"propertyName\"').", [401 /* Component_bindNeedsValue */]: "'bind:id' must have a property name. (Example: 'bind:key=\"propertyName\"').", [402 /* Component_needsState */]: "Can't find state on host element.", [403 /* Component_needsInjectionContext_constructor */]: "Components must be instantiated inside an injection context. Use '{}.new(...)' for creation.", [404 /* Component_noProperty_propName_props_host */]: "Property '{}' not found in '{}' on component '{}'.", [405 /* Component_notFound_component */]: "Unable to find '{}' component.", [406 /* Component_doesNotMatch_component_actual */]: "Requesting component type '{}' does not match existing component instance '{}'.", [408 /* Component_noState_component_props */]: "Unable to create state for component '{}' with props '{}' because no state found and '$newState()' method was not defined on component.", ////////////// [500 /* Provider_unrecognizedFormat_value */]: "Unrecognized expression format '{}'.", ////////////// [600 /* Render_unexpectedJSXNodeType_type */]: 'Unexpected JSXNode<{}> type.', [601 /* Render_unsupportedFormat_obj_attr */]: "Value '{}' can't be written into '{}' attribute.", [602 /* Render_expectingEntity_entity */]: "Expecting entity object, got '{}'.", [603 /* Render_expectingEntityArray_obj */]: "Expecting array of entities, got '{}'.", [604 /* Render_expectingEntityOrComponent_obj */]: "Expecting Entity or Component got '{}'.", [699 /* Render_stateMachineStuck */]: 'Render state machine did not advance.', ////////////// [700 /* Event_emitEventRequiresName_url */]: "Missing '$type' attribute in the '{}' url.", [701 /* Event_emitEventCouldNotFindListener_event_element */]: "Re-emitting event '{}' but no listener found at '{}' or any of its parents.", }[code]; let textCode = '000' + code; textCode = textCode.substr(textCode.length - 3); return `${area}(Q-${textCode}): ${text}`; } /** * Remove item from array (Same as `Array.splice()` but faster.) * * `Array.splice()` is not as fast because it has to allocate an array for the elements which were * removed. This causes memory pressure and slows down code when most of the time we don't * care about the deleted items array. * * https://jsperf.com/fast-array-splice (About 20x faster) * * @param array Array to splice * @param index Index of element in array to remove. * @param count Number of items to remove. */ /** * Same as `Array.splice2(index, 0, value1, value2)` but faster. * * `Array.splice()` is not fast because it has to allocate an array for the elements which were * removed. This causes memory pressure and slows down code when most of the time we don't * care about the deleted items array. * * @param array Array to splice. * @param index Index in array where the `value` should be added. * @param value1 Value to add to array. * @param value2 Value to add to array. */ function arrayInsert2(array, index, value1, value2) { let end = array.length; if (end == index) { // inserting at the end. array.push(value1, value2); } else if (end === 1) { // corner case when we have less items in array than we have items to insert. array.push(value2, array[0]); array[0] = value1; } else { end--; array.push(array[end - 1], array[end]); while (end > index) { const previousEnd = end - 2; array[end] = array[previousEnd]; end--; } array[index] = value1; array[index + 1] = value2; } } function keyValueArrayGet(keyValueArray, key, notFoundFactory) { const index = keyValueArrayIndexOf(keyValueArray, key); if (index >= 0) { // if we found it retrieve it. return keyValueArray[index | 1]; } if (notFoundFactory) { const value = notFoundFactory(); arrayInsert2(keyValueArray, ~index, key, value); return value; } return undefined; } /** * Retrieve a `key` index value in the array or `-1` if not found. * * @param keyValueArray to search. * @param key The key to locate. * @returns index of where the key is (or should have been.) * - positive (even) index if key found. * - negative index if key not found. (`~index` (even) to get the index where it should have * been inserted.) */ function keyValueArrayIndexOf(keyValueArray, key) { return _arrayIndexOfSorted(keyValueArray, key, 1); } /** * INTERNAL: Get an index of an `value` in a sorted `array` by grouping search by `shift`. * * NOTE: * - This uses binary search algorithm for fast removals. * * @param array A sorted array to binary search. * @param value The value to look for. * @param shift grouping shift. * - `0` means look at every location * - `1` means only look at every other (even) location (the odd locations are to be ignored as * they are values.) * @returns index of the value. * - positive index if value found. * - negative index if value not found. (`~index` to get the value where it should have been * inserted) */ function _arrayIndexOfSorted(array, value, shift) { let start = 0; let end = array.length >> shift; while (end !== start) { const middle = start + ((end - start) >> 1); // find the middle. const current = array[middle << shift]; if (value === current) { return middle << shift; } else if (current > value) { end = middle; } else { start = middle + 1; // We already searched middle so make it non-inclusive by adding 1 } } return ~(end << shift); } function isSlotMap(value) { return Array.isArray(value); } /** * Retrieves the current `SlotMap` from `QComponent` * * * This method collects the content `Node`s for a given component. * * @param component * @returns */ function getSlotMap(component) { const slots = []; const host = component.hostElement; const firstChild = host.firstElementChild; if (isQSlotTemplate(firstChild)) { slotMapAddChildren(slots, firstChild.content, null); } const previousSlots = []; host.querySelectorAll("Q\\:SLOT" /* QSlotSelector */).forEach((qSlot) => { for (const parent of previousSlots) { if (parent.contains(qSlot)) { // When we do `querySelectorAll` it is possible that we get `` // which are children of existing ``. This check is here // to make sure that we don't get `` recursively. // // // // // return; } } previousSlots.push(qSlot); const name = qSlot.getAttribute('name') || ''; slotMapAddChildren(slots, qSlot, name); }); return slots; } /** * Determines if the `node` is `