@a-qoot/core
Advanced tools
Comparing version 0.0.3 to 0.0.4
@@ -440,6 +440,15 @@ { | ||
}, | ||
"bazel-out/darwin-fastbuild/bin/client/util/promises.js": { | ||
"bytes": 3008, | ||
"bazel-out/darwin-fastbuild/bin/client/util/array.js": { | ||
"bytes": 2213, | ||
"imports": [] | ||
}, | ||
"bazel-out/darwin-fastbuild/bin/client/util/promises.js": { | ||
"bytes": 3182, | ||
"imports": [ | ||
{ | ||
"path": "bazel-out/darwin-fastbuild/bin/client/util/array.js", | ||
"kind": "import-statement" | ||
} | ||
] | ||
}, | ||
"bazel-out/darwin-fastbuild/bin/client/import/qrl.js": { | ||
@@ -561,3 +570,3 @@ "bytes": 9181, | ||
"bazel-out/darwin-fastbuild/bin/client/render/jsx/factory.js": { | ||
"bytes": 9105, | ||
"bytes": 9282, | ||
"imports": [ | ||
@@ -567,2 +576,6 @@ { | ||
"kind": "import-statement" | ||
}, | ||
{ | ||
"path": "bazel-out/darwin-fastbuild/bin/client/util/array.js", | ||
"kind": "import-statement" | ||
} | ||
@@ -875,3 +888,3 @@ ] | ||
"inputs": {}, | ||
"bytes": 28884 | ||
"bytes": 29106 | ||
}, | ||
@@ -991,4 +1004,7 @@ "bazel-out/darwin-fastbuild/bin/client/cjs/qoot.js": { | ||
}, | ||
"bazel-out/darwin-fastbuild/bin/client/util/array.js": { | ||
"bytesInOutput": 475 | ||
}, | ||
"bazel-out/darwin-fastbuild/bin/client/util/promises.js": { | ||
"bytesInOutput": 580 | ||
"bytesInOutput": 587 | ||
}, | ||
@@ -1023,3 +1039,3 @@ "bazel-out/darwin-fastbuild/bin/client/import/qrl.js": { | ||
"bazel-out/darwin-fastbuild/bin/client/render/jsx/factory.js": { | ||
"bytesInOutput": 780 | ||
"bytesInOutput": 785 | ||
}, | ||
@@ -1069,5 +1085,5 @@ "bazel-out/darwin-fastbuild/bin/client/render/jsx/index.js": { | ||
}, | ||
"bytes": 69792 | ||
"bytes": 70335 | ||
} | ||
} | ||
} |
{ | ||
"name": "@a-qoot/core", | ||
"version": "0.0.3", | ||
"version": "0.0.4", | ||
"description": "An Open-Source sub-framework designed with a focus on server-side-rendering, lazy-loading, and styling/animation.", | ||
@@ -5,0 +5,0 @@ "typings": "./qoot.d.ts", |
@@ -1,1 +0,1 @@ | ||
function isDomElementWithTagName(t,e){return isHtmlElement(t)&&t.tagName.toLowerCase()==e.toLowerCase()}function isHtmlElement(t){return!!t&&1===t.nodeType}function isTextNode(t){return!!t&&3===t.nodeType}function stringifyDebug(t){return null==t?String(t):"function"==typeof t?t.name:isHtmlElement(t)?stringifyElement(t):t instanceof URL?String(t):"object"==typeof t?JSON.stringify(t,(function(t,e){return isHtmlElement(e)?stringifyElement(e):e})):String(t)}function stringifyElement(t){let e="<"+t.tagName.toLowerCase();const n=t.attributes,r=[];for(let t=0;t<n.length;t++)r.push(n[t].name);r.sort();for(let n=0;n<r.length;n++){const o=r[n];let i=t.getAttribute(o);(null==i?void 0:i.startsWith("file:/"))&&(i=i.replace(/(file:\/\/).*(\/.*)$/,((t,e,n)=>e+"..."+n))),e+=" "+o+(null==i||""==i?"":"='"+i.replace("'","'")+"'")}return e+">"}function qError(t,...e){const n=codeToText(t).split("{}"),r=n.map(((t,r)=>t+(r===n.length-1?"":stringifyDebug(e[r])))).join("");return new Error(r)}function codeToText(t){const e={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(t/100)],n={1:"QConfig not found in path '{}'.",2:"Unrecognized stack format '{}'",3:"Could not find entity state '{}' at '{}' or any of it's parents.",4:"Could not find entity state '{}' ( or entity provider '{}') at '{}' or any of it's parents.",5:"Missing property '{}' in props '{}'.",6:"Missing export '{}' from '{}'. Exported symbols are: {}",100:"QRL '${}' should point to function, was '{}'.",200:"Can't find host element above '{}'.",201:"Provider is expecting '{}' but got '{}'.",202:"Expected 'Element' was '{}'.",203:"Expected injection 'this' to be of type '{}', but was of type '{}'.",204:"Entity key '{}' is found on '{}' but does not contain state. Was 'serializeState()' not run during dehydration?",206:"No injector can be found starting at '{}'.",207:"EventInjector does not support serialization.",300:"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:"A entity with key '{}' already exists.",303:"'{}' is not a valid attribute. Attributes can only contain 'a-z' (lowercase), '0-9', '-' and '_'.",304:"Found '{}' but expando did not have entity and attribute did not have state.",305:"Element '{}' is missing entity attribute definition '{}'.",306:"Unable to create state for entity '{}' with props '{}' because no state found and '$newState()' method was not defined on entity.",307:"'{}' is not an instance of 'Entity'.",308:"'{}' overrides 'constructor' property preventing 'EntityType' retrieval.",311:"Entity '{}' does not define '$keyProps'.",310:"Entity '{}' must have static '$type' property defining the name of the entity.",312:"Entity '{}' must have static '$qrl' property defining the import location of the entity.",313:"Name collision. Already have entity named '{}' with QRL '{}' but expected QRL '{}'.",309:"Entity key '{}' is missing values. Expecting '{}:someValue'.",314:"Entity '{}' defines '$keyProps' as '{}'. Actual key '{}' has more parts than entity defines.",315:"Key '{}' belongs to entity named '{}', but expected entity '{}' with name '{}'.",316:"Entity state is missing '$key'. Are you sure you passed in state? Got '{}'.",400:"'bind:' must have an key. (Example: 'bind:key=\"propertyName\"').",401:"'bind:id' must have a property name. (Example: 'bind:key=\"propertyName\"').",402:"Can't find state on host element.",403:"Components must be instantiated inside an injection context. Use '{}.new(...)' for creation.",404:"Property '{}' not found in '{}' on component '{}'.",405:"Unable to find '{}' component.",406:"Requesting component '{}' does not match existing component '{}'. Verify that the two components have distinct '$templateQRL's.",407:"Expecting Component '{}' to have static '$templateQRL' property, but none was found.",408:"Unable to create state for component '{}' with props '{}' because no state found and '$newState()' method was not defined on component.",500:"Unrecognized expression format '{}'.",600:"Unexpected JSXNode<{}> type.",601:"Value '{}' can't be written into '{}' attribute.",602:"Expecting entity object, got '{}'.",603:"Expecting array of entities, got '{}'.",604:"Expecting Entity or Component got '{}'.",605:"'requestAnimationFrame' not found. If you are running on server design your applications in a way which does not require 'requestAnimationFrame' on first render.",606:"Expecting that element with 'bind:{}' should be a component (should have 'decl:template=\"qrl\"' attribute): {}",700:"Missing '$type' attribute in the '{}' url.",701:"Re-emitting event '{}' but no listener found at '{}' or any of its parents."}[t];let r="000"+t;return r=r.substr(r.length-3),`${e}(Q-${r}): ${n}`}const _globalThis="undefined"!=typeof globalThis&&globalThis,_window="undefined"!=typeof window&&window,_self="undefined"!=typeof self&&"undefined"!=typeof WorkerGlobalScope&&self instanceof WorkerGlobalScope&&self,__global="undefined"!=typeof global&&global,_global=_globalThis||__global||_window||_self;function dirname(t){const e=t.lastIndexOf("/",t.length-2);return-1==e?t:t.substr(0,e+1)}"undefined"==typeof qDev&&(_global.qDev=!0);const configs=[];function setConfig(t){t.baseURI.endsWith("/")||(t.baseURI=dirname(t.baseURI)),t.baseURI=normalizeBaseUri(t.baseURI),configs.push(t),configs.sort(((t,e)=>e.baseURI.length-t.baseURI.length))}function normalizeBaseUri(t){return t.startsWith("/")&&(t="file://"+t),t}function getConfig(t){if(null!=t){t=normalizeBaseUri(t);for(let e=0;e<configs.length;e++){const n=configs[e];if(t.startsWith(n.baseURI))return n}}if("undefined"==typeof document)throw qError(1,t+"\n"+configs.map((t=>JSON.stringify(t))).join("\n"));return _global.Q||(_global.Q={}),Q.baseURI||(Q.baseURI=document.baseURI),Q.protocol||(Q.protocol={}),Q}let importCache;function qImport(t,e){importCache||(importCache=new Map);const n=toUrl(toBaseURI(t),e),r=toImportPath(n),o=qExport(n),i=`${r}#${o}`,s=importCache.get(i);if(s)return s;const a=import(r+".js").then((t=>{const e=t[o];if(!e)throw qError(6,o,r,Object.keys(t));return qImportSet(i,e),e}));return qImportSet(i,a),a}function qImportSet(t,e){importCache.set(t,e)}function toBaseURI(t){if("string"==typeof t)return t;return(t.ownerDocument||t).baseURI}function toUrl(t,e){if("string"==typeof e){const n=getConfig(t);return new URL(adjustProtocol(n,e),n.baseURI)}return e}function toImportPath(t){const e=new URL(String(t));return e.hash="",e.search="",String(e).replace(/\.(ts|tsx)$/,".js")}function adjustProtocol(t,e){return String(e).replace(/(^\w+):\/?/,((e,n)=>{let r=t.protocol[n];return r?(r.endsWith("/")||(r+="/"),r):e}))}function qExport(t){return t.hash.replace(/^#?([^?]*).*$/,"$1")||"default"}function qParams(t){return new URLSearchParams(t.hash.replace(/^[^?]*\??(.*)$/,"$1"))}function assertValidDataKey(t){if(t)for(let e=0;e<t.length;e++){if(!isAlphanumeric(t.charCodeAt(e)))throw qError(300,t)}}function isAlphanumeric(t){return 65<=t&&t<=90||isAlphanumericAttribute(t)||46==t||58==t}function isAlphanumericAttribute(t){return 97<=t&&t<=122||48<=t&&t<=57||45==t||95==t}function isValidAttribute(t){for(let e=0;e<t.length;e++){if(!isAlphanumericAttribute(t.charCodeAt(e)))return!1}return!0}const camelToKebabCase=new Map;function fromCamelToKebabCase(t,e=!1){if("string"!=typeof t)return t;const n=camelToKebabCase.get(t);if(null!=n)return n;let r="";for(let n=0;n<t.length;n++){const o=t.charAt(n);isUpperCase(o)?r+=(0!=n||e?"-":"")+o.toLowerCase():r+=o}return camelToKebabCase.set(t,r),r}const kebabToCamelCase=new Map;function fromKebabToCamelCase(t,e=!0){const n=kebabToCamelCase.get(t);if(null!=n)return n;let r="",o=e;for(let e=0;e<t.length;e++){const n=t.charAt(e);isKebab(n)?o=!0:o?(o=!1,r+=n.toUpperCase()):r+=n}return kebabToCamelCase.set(t,r),r}function isUpperCase(t){return"A"<=t&&t<="Z"}function isKebab(t){return"-"===t}function stringify(t){return null==t?null:String(t)}function assertDefined(t,e){if(null==t)throw newError(e||"Expected defined value.")}function assertString(t,e){if("string"!=typeof t)throw newError(e||`Expected value '${t}' to be 'string' but was '${typeOf(t)}'.`)}function assertEqual(t,e,n){if(t!==e)throw newError(n||`Expected '${t}' === '${e}'.`)}function typeOf(t){var e;if(null===t)return"null";const n=typeof t;return"object"===n?(null===(e=null==t?void 0:t.constructor)||void 0===e?void 0:e.name)||"<unknown>":n}function newError(t){return new Error(t)}function toEntityKey(t){return qDev&&assertString(t),t}function propsToKey(t,e){let n=fromCamelToKebabCase(t.$type)+":";const r=t.$keyProps;if(!r)throw qError(311,t);for(let t=0;t<r.length;t++){0!=t&&(n+=":");n+=validateKeyPart(fromCamelToKebabCase(stringify(e[r[t]]),!0))}return n}function keyToProps(t,e){const n={},r=t.$keyProps;if(!r)throw qError(311,t);r.forEach((t=>n[t]=null));const o=String(e).split(":");if(o.length<=1)throw qError(309,e,e);const i=o.shift(),s=fromCamelToKebabCase(t.$type);if(s!==i)throw qError(315,e,i,t,s);if(0==r.length&&1==o.length&&""==o[0])return n;for(let i=0;i<o.length;i++){const s=o[i];if(i>=r.length)throw qError(314,t,r,e);const a=r[i];n[a]=""==s&&i==o.length-1?null:fromKebabToCamelCase(s,!1)}return n}function validateKeyPart(t){const e=null==t?"":String(t);if(isValidAttribute(e))return e;throw qError(303,t)}function entityStateKey(t){const e=t.$key;if("string"!=typeof e)throw qError(316,t);return e}function keyToEntityAttribute(t){const e=t,n=e.indexOf(":");if(-1==n)throw qError(300,e);return"::"+e.substr(0,n)}function findAttribute(t,e,n,r,o,i){let s=t;for(;s;){const t=s.getAttribute(n);if(null!==t)return r(s,n,t);if(o&&i){const t=s.getAttribute(o);if(null!==t)return i(s,o,t)}s=s.parentElement}throw o?qError(e,n,o,t):qError(e,n,t)}function extractPropsFromElement(t){const e={},n=t.attributes;for(let t=0;t<n.length;t++){const r=n[t],o=r.name,i=r.value;if(o.startsWith("bind:")){const t=o.substr(5);if(!t)throw qError(400);if(!i)throw qError(401);i.split(";").forEach((n=>n&&(e[n]=t)))}else-1!==o.indexOf(":")||(e[fromKebabToCamelCase(o,!1)]=i)}return e}function resolveArgs(t,...e){const n=[];for(let r=0;r<e.length;r++){const o=e[r];n.push(isProvider(o)?o(t):o)}return Promise.all(n)}function isProvider(t){return"function"==typeof t}class BaseInjector{constructor(t){this._props=null,this.element=t}invoke(t,e,...n){if(!isInjectedFunction(t))return Promise.resolve(t.apply(null,n));try{const r=t.$thisType;if(e&&r&&!(e instanceof r))throw qError(203,r,e.constructor);return resolveArgs(this,r&&null==e?this.getComponent(r):e,...t.$inject).then((e=>t.apply(e.shift(),e.concat(n))),(e=>Promise.reject(addDeclaredInfo(t,e))))}catch(e){throw addDeclaredInfo(t,e)}}set elementProps(t){this._props=t}get elementProps(){const t=this._props;return null!=t?t:extractPropsFromElement(this.element)}}function addDeclaredInfo(t,e){const n=t.$debugStack;if(!n)return e;e instanceof Error||(e=new Error(String(e)));const r=n.stack.split("\n")[2].trim(),o=e.stack,i=e.message;return e.stack=o.replace(i,i+"\n DECLARED "+r),e}function isInjectedFunction(t){return!!t.$inject}class ElementInjector extends BaseInjector{constructor(){super(...arguments),this.component=null,this.componentPromise=null,this.entities=null}getParent(){let t=this.element.parentElement;for(;t;){if(t.hasAttribute(":")||t.hasAttribute("decl:template"))return getInjector(t);t=t.parentElement}return null}getComponent(t){const e=this.element.getAttribute("decl:template"),n=t.$templateQRL;if(!n)throw qError(407,t);if(e===n){let e=this.component;if(e){if(e instanceof t)return this.componentPromise;throw qError(406,t,e.constructor)}{const n=this.element.getAttribute(":."),r=n?JSON.parse(n):null;return this.component=e=new t(this.element,this.elementProps,r),this.componentPromise=new Promise(((t,n)=>{let o;o=null==r?Promise.resolve(e.$newState(e.$props)).then((t=>{e.$state=t})):Promise.resolve(e),o.then((()=>e.$init())).then((()=>t(e)),n)}))}}{const e=this.getParent();if(!e)throw qError(405,t);return e.getComponent(t)}}getEntity(t,e,n){var r,o;let i=null===(o=null===(r=this.entities)||void 0===r?void 0:r.get(t))||void 0===o?void 0:o.promise;if(i)return i;const s=keyToEntityAttribute(t),a=this;return findAttribute(this.element,4,String(t),l,s,l);function l(r,o,l){var c,u;const f=r===a.element?a:getInjector(r);if(i=null===(u=null===(c=f.entities)||void 0===c?void 0:c.get(t))||void 0===u?void 0:u.promise,i)return i;f.element.setAttribute(String(t),"");const p=r.getAttribute(s);if(!p)throw qError(305,r,s);const m=Promise.resolve(n||qImport(r,p));i=toEntityPromise(t,new Promise(((n,i)=>{m.then((s=>{if("function"!=typeof s)throw qError(100,p,s);let c=e||null;c||o!==String(t)||(c=JSON.parse(l),c.$key=t);const u=s.$keyToProps(t),f=new s(r,u,c);let m;c?(d.entity=f,m=Promise.resolve(f)):m=f.$newState(u).then((e=>(d.entity=f,e.$key=t,f.$state=e,f)),(e=>{var n;return null===(n=a.entities)||void 0===n||n.delete(t),Promise.reject(e)})),m.then((()=>{Promise.resolve(f.$init()).then((()=>n(f)))}),i)}),i)})));const d={promise:i,entity:null};return(f.entities||(f.entities=new Map)).set(t,d),i}}getEntityState(t){const e=keyToEntityAttribute(t);return findAttribute(this.element,4,t,((e,n,r)=>{var o,i;const s=null===(i=null===(o=(e==this.element?this:getInjector(e)).entities)||void 0===o?void 0:o.get(t))||void 0===i?void 0:i.promise;if(s)return s.then((t=>t.$state));if(!r)throw qError(204,t,e);const a=JSON.parse(r);return a.$key=n,Promise.resolve(a)}),e,(e=>getInjector(e).getEntity(t).then((t=>t.$state))))}releaseEntity(t){var e;(null===(e=this.entities)||void 0===e?void 0:e.delete(t))&&this.element.removeAttribute(t)}serialize(){var t,e;const n=this.element,r=null===(t=this.component)||void 0===t?void 0:t.$state;null!=r&&n.setAttribute(":.",JSON.stringify(r)),null===(e=this.entities)||void 0===e||e.forEach((t=>{var e;const r=null===(e=t.entity)||void 0===e?void 0:e.$state;r&&n.setAttribute(r.$key,JSON.stringify(r,filterFrameworkKeys))}))}}function filterFrameworkKeys(t,e){return t.startsWith("$")?void 0:e}function toEntityPromise(t,e){const n=e;return n.$key=t,n}function getInjector(t,e=!0){if(!isHtmlElement(t))throw qError(202,t);const n=t;let r=n.$injector;return e&&!r&&(n.$injector=r=new ElementInjector(t),t.setAttribute(":","")),r||null}function getClosestInjector(t,e=!0){let n=t;for(;n;){if(n.hasAttribute(":")||n.hasAttribute("decl:template"))return getInjector(n);n=n.parentElement}if(e)throw qError(206,t);return null}class Component{constructor(t,e,n){this.$host=t,this.$props=e,this.$state=n}static $new(t){const e=this,n=t.getAttribute("decl:template");if(n){if(n!==e.$templateQRL)throw new Error("Write proper error")}else t.setAttribute("decl:template",e.$templateQRL);return getInjector(t).getComponent(e)}$init(){}$newState(t){throw qError(408,this.constructor,t)}}function isComponent(t){var e;return"string"==typeof(null===(e=null==t?void 0:t.constructor)||void 0===e?void 0:e.$templateQRL)}function emitEvent(t,e,n){const r=qParams(n),o=r.get("$type");if(null==o)throw qError(700,n);const i=findAttribute(t,701,"on:"+fromCamelToKebabCase(o),((t,e,n)=>{const i=n;return Promise.resolve(qImport(t,i)).then((e=>{const n=toUrl(toBaseURI(t),i),s=new CustomEvent(o);return r.forEach(((t,e)=>{s[e]=t})),e(t,s,n)}))}));return Promise.resolve(i)}function getFilePathFromFrame(t){const e=t.match(/\(?(\S*):\d+:\d+\)?/);if(!e)throw qError(2,t);return e[1].replace(/\.(ts|tsx)$/,".js")}Component.$templateQRL=null;class Entity{constructor(t,e,n){const r=getEntityType(this);this.$props=e,this.$state=n,this.$element=t,this.$key=propsToKey(r,e),e&&r.$attachEntity(t),e&&r.$attachEntityState(t,e,null)}static get $type(){return this.$_name}static set $type(t){if(!t.startsWith("$")){const e=getFilePathFromFrame((new Error).stack.split("\n")[2]);this.$config=getConfig(e),this.$_name=t}}static $attachEntity(t){const e=this;if(!e.$type)throw qError(310,e);if(!e.$qrl)throw qError(312,e);const n="::"+fromCamelToKebabCase(e.$type),r=t.getAttribute(n);if(r){if(r!=e.$qrl)throw qError(313,e.$type,r,e.$qrl)}else t.setAttribute(n,String(e.$qrl))}static $attachEntityState(t,e,n){this.$attachEntity(t);const r="string"==typeof e?e:propsToKey(this,e);t.hasAttribute(String(r))||t.setAttribute(String(r),null==n?"":JSON.stringify(n))}static $hydrate(t,e,n){const r="string"==typeof e?e:propsToKey(this,e);n&&(n.$key=r);const o=keyToEntityAttribute(r);t.hasAttribute(o)||this.$attachEntity(t);return getInjector(t).getEntity(r,n,this)}static $keyToProps(t){return keyToProps(this,t)}static $propsToKey(t){return propsToKey(this,t)}async $invokeQRL(t,...e){const n=getEntityType(this),r=await qImport(n.$config,t);return getInjector(this.$element).invoke(r,this,...e)}$newState(t){throw qError(306,this.constructor.$type,t)}async $init(){}$release(){const t=getInjector(this.$element),e=propsToKey(getEntityType(this),this.$props);t.releaseEntity(e)}}function getEntityType(t){if(!(t instanceof Entity))throw qError(307,t);const e=t.constructor;if(e.$attachEntityState!==Entity.$attachEntityState)throw qError(308,t);return e}function isEntity(t){return Object.prototype.hasOwnProperty.call(t,"$key")}Entity.$config=null,Entity.$_name=null,Entity.$keyProps=[];class EventEntity extends Entity{constructor(t,e,n,r){super(t,null,null),this.$key=EventEntity.KEY,this.event=e,this.url=n,this.props=r}}EventEntity.$qrl="",EventEntity.$type="$EventEntity",EventEntity.$props=["id"],EventEntity.KEY="$event:";class EventInjector extends BaseInjector{constructor(t,e,n){super(t),this.parentInjector=null;const r={};qParams(n).forEach(((t,e)=>r[e]=t)),this.eventEntity=new EventEntity(t,e,n,r)}getParent(){const t=this.parentInjector;return t||(this.parentInjector=getClosestInjector(this.element,!1))}getComponent(t){return this.getParent().getComponent(t)}getEntity(t,e,n){return t===EventEntity.KEY?this.eventEntity:this.getParent().getEntity(t,e,n)}getEntityState(t){return this.getParent().getEntityState(t)}releaseEntity(t){var e;return null===(e=this.getParent())||void 0===e?void 0:e.releaseEntity(t)}serialize(){throw qError(207)}}function injectEventHandler(...t){const e=t.pop(),n=e.$thisType=t.shift();e.$inject=t,qDev&&(e.$debugStack=new Error);const r=function(t,r,o){var i;const s=new EventInjector(t,r,o);return Promise.resolve(n&&(null===(i=s.getParent())||void 0===i?void 0:i.getComponent(n))||null).then((t=>s.invoke(e,t)))};return r.$delegate=e,r}function provideElement(){return function(t){return t.element}}function provideEvent(){return async function(t){return(await t.getEntity(EventEntity.KEY)).event}}function provideQrlExp(t){return async function(e){const n=await e.getEntity(EventEntity.KEY),r=n.props[t];if(null==r)throw qError(5,t,n.props);switch(r.charAt(0)){case".":let t=n.event;qDev&&assertDefined(t);const e=r.substr(1).split(".");for(;e.length&&t;)t=t[e.shift()];return t;default:throw qError(500,r)}}}function provideUrlProp(t){return async function(e){return(await e.getEntity(EventEntity.KEY)).props[t]||null}}function flattenPromiseTree(t){return Promise.all(t).then((t=>{const e=t.flat();for(let t=0;t<e.length;t++)if(isPromise(e[t]))return flattenPromiseTree(e);return e}))}function isPromise(t){return t instanceof Promise}function QRL(t,...e){let n="";for(let r=0;r<t.length;r++){n+=t[r],r<e.length&&(n+=e[r])}return qDev&&assertEqual(!!n.match(/^[.|/|\w+:]/),!0,"Expecting URL to start with '.', '/', '<protocol>:'. Was: "+n),qDev&&verifyQrl(new Error("Invalid import: "+n),n),n}async function verifyQrl(t,e){const n=t.stack;if(!n)return Promise.resolve(null);const r=getFilePathFromFrame(n.split("\n")[2]),o=getConfig(r);try{const t=qImport(o,e);return isPromise(t)?t.catch((t=>Promise.reject(i(t)))):t}catch(t){throw new Error(i(t))}function i(t){return`QRL-ERROR: '${e}' is not a valid import.\nResolved URL: ${toUrl(r,e)}\n Base URL: ${o.baseURI}\n CONFIG: ${JSON.stringify(o)}\n STACK: ${n}\n => ${t}`}}function injectFunction(...t){const e=t.pop();return e.$thisType=null,e.$inject=t,qDev&&(e.$debugStack=new Error),e}function injectMethod(...t){const e=t.pop();return e.$thisType=t.shift(),e.$inject=t,qDev&&(e.$debugStack=new Error),e}function provideInjector(){return async function(t){return t}}function provideProviderOf(t){return async function(e){return()=>Promise.resolve(t(e))}}function serializeState(t){isHtmlElement(t)&&serializeNode(t),t.querySelectorAll("[\\:]").forEach(serializeNode)}function serializeNode(t){const e=getInjector(t,!1);e&&e.serialize()}const EMPTY_ARRAY=[];qDev&&Object.freeze(EMPTY_ARRAY);const EMPTY_OBJ={};qDev&&Object.freeze(EMPTY_OBJ);class JSXNode_{constructor(t,e,n){this.tag=t,this.props=e||EMPTY_OBJ,this.children=n}}function isJSXNode(t){return t instanceof JSXNode_}function jsxFactory(t,e,...n){return new JSXNode_(t,e,n.flat(99))}function jsxDeclareComponent(t,e="div",n){return function(r){return jsxFactory(e,Object.assign(Object.assign({"decl:template":t},n),r))}}function removeNode(t,e){const n=e.nextSibling;return t.removeChild(e),n}function replaceNode(t,e,n){return t.insertBefore(n,e),e&&t.removeChild(e),n}function applyAttributes(t,e,n){let r=!1;if(e){let o=null;for(const i in e)if(Object.prototype.hasOwnProperty.call(e,i)){const s=fromCamelToKebabCase(i),a=e[i];"decl:entity"===i?applyEntityProviders(a,t):"decl:template"===i?setAttribute(t,"decl:template",a):i.startsWith("on:")?setAttribute(t,s,a):i.startsWith("$")?addToBindMap(stringify(a),o||(o=new Map),i):n?t.getAttribute(s)!==a&&(setAttribute(t,i,a,s),r=!0):setAttribute(t,i,a,s)}o&&(r=updateBindMap(t,o)||r)}return r}function applyEntityProviders(t,e){if(!Array.isArray(t))throw qError(603,t);t.forEach((t=>{if("function"!=typeof(null==t?void 0:t.$attachEntity))throw qError(602,t);t.$attachEntity(e)}))}function addToBindMap(t,e,n){qDev&&assertValidDataKey(t);const r="bind:"+(t?fromCamelToKebabCase(t):"");let o=e.get(r);o?o+="|"+n:o=n,e.set(r,o)}function updateBindMap(t,e){let n=!1;for(let r=0,o=t.attributes;r<o.length;r++){const i=o[r],s=i.name;if(s.startsWith("bind:")){const o=e.get(s);null!=o?(e.delete(s),i.value===o?e.delete(s):(n=!0,i.value=o)):(n=!0,t.removeAttribute(s),r--)}}return e.forEach(((e,r)=>{n=!0,t.setAttribute(r,e)})),n}function setAttribute(t,e,n,r){"class"==e?t.setAttribute("class",stringifyClassOrStyle(n,!0)):"style"==e?t.setAttribute("style",stringifyClassOrStyle(n,!1)):null==n||!1===n?t.removeAttribute(e):"innerHTML"===e||"innerText"===e?(t.setAttribute(r,""),t[e]=n):"INPUT"===t.tagName&&-1==e.indexOf(":")?(t.setAttribute(e,String(n)),t[e]=n):t.setAttribute(e,String(n))}function stringifyClassOrStyle(t,e){if(null==t)return"";if("object"==typeof t){let n="",r="";if(Array.isArray(t)){if(!e)throw qError(601,t,"style");for(let e=0;e<t.length;e++)n+=r+t[e],r=" "}else for(const o in t)if(Object.prototype.hasOwnProperty.call(t,o)){const i=t[o];n+=e?i?r+o:"":r+o+":"+i,r=e?" ":";"}return n}return String(t)}function Host(){throw newError("Should not execute")}async function jsxRender(t,e,n){const r=[];let o=t.firstChild;for(;o&&o.nodeType>8;)o=o.nextSibling;return visitJSXNode(n||document,r,t,o,e),flattenPromiseTree(r)}function visitJSXNode(t,e,n,r,o){if(!o)return null;if(isPromise(o))return e.push(o.then((e=>{const o=[],i=visitJSXNode(t,o,n,r,e);return i&&o.push(i),o}),writeErrorToDom(n))),null;if("string"==typeof o.tag)return visitJSXDomNode(t,e,n,r,o);if(o.tag===Host)return visitJSXHostNode(t,e,n,r,o);if("function"==typeof o.tag)return visitJSXFactoryNode(t,e,n,r,o);if(null===o.tag)return visitJSXFragmentNode(t,e,n,r,o);throw qError(600,o.tag)}function visitJSXDomNode(t,e,n,r,o){const i=o.tag;let s,a=!1;isDomElementWithTagName(r,i)?s=r:(s=replaceNode(n,r,t.createElement(i)),a=!0);const l=getComponentTemplateUrl(o),c=!!l;return a=applyAttributes(s,o.props,c)||a,l&&a&&jsxRenderComponent(s,l,e,o.props,t),l||"innerHTML"in o.props||"innerText"in o.props||visitChildren(t,e,s,s.firstChild,o.children),s}function jsxRenderComponent(t,e,n,r,o=document){const i=qImport(t,e);isPromise(i)?n.push(i.then((e=>{const n=[t];return visitJSXComponentNode(o,n,t,t.firstChild,e,r),n}))):visitJSXComponentNode(o,n,t,t.firstChild,i,r)}function visitJSXComponentNode(t,e,n,r,o,i){i||(i=EMPTY_OBJ);const s=getInjector(n);s.elementProps=i;return visitJSXNode(t,e,n,r,s.invoke(o,void 0,i))}function getComponentTemplateUrl(t){return(t.props||EMPTY_OBJ)["decl:template"]||null}function visitJSXFactoryNode(t,e,n,r,o){return visitJSXNode(t,e,n,r,o.tag(o.props))}function visitJSXHostNode(t,e,n,r,o){return applyAttributes(n,o.props,!1),visitChildren(t,e,n,r,o.children),n}function visitJSXFragmentNode(t,e,n,r,o){return visitChildren(t,e,n,r,o.children)}function visitChildren(t,e,n,r,o){if(o)for(let i=0;i<o.length;i++){const s=o[i];isJSXNode(s)?r=visitJSXNode(t,e,n,r,s):null==s?r&&(r=removeNode(n,r)):isTextNode(r)?r.textContent=String(s):replaceNode(n,r,t.createTextNode(String(s))),r=(null==r?void 0:r.nextSibling)||null}for(;r;)r=removeNode(n,r);return null}function writeErrorToDom(t){return function(e){console.error("ERROR:",e);const n=t,r=n.ownerDocument.createElement("pre");return n.appendChild(r),r.textContent=String(e),Promise.reject(e)}}function isElement(t){return t&&!!t.ownerDocument}function markDirty(t){if(isEntity(t))return markEntityDirty(t);if(isComponent(t))return markComponentDirty(t);if(isElement(t))return markElementDirty(t);throw qError(604,t)}function markComponentDirty(t){return markElementDirty(t.$host)}function markElementDirty(t){const e=t.ownerDocument;t.setAttribute("on:q-render",t.getAttribute("decl:template"));const n=e.$qScheduledRender;return isPromise(n)?n:scheduleRender(e)}function markEntityDirty(t){const e=t.$key,n=t.$element.ownerDocument;let r=!1;return n.querySelectorAll(toAttrQuery("bind:"+e)).forEach((t=>{const n=t.getAttribute("decl:template");if(!n)throw qError(606,e,t);r=!0,t.setAttribute("on:q-render",n)})),r?scheduleRender(n):Promise.resolve([])}function toAttrQuery(t){return"["+t.replace(/[:.\-_]/g,(t=>"\\"+t))+"]"}function scheduleRender(t){const e=t.$qScheduledRender;if(e)return e;const n=t.defaultView.requestAnimationFrame;if(!n)throw qError(605);return t.$qScheduledRender=new Promise(((e,r)=>{n((()=>{const n=[],o=t.querySelectorAll("[on\\:q-render]"),i=[];o.forEach((e=>{e.removeAttribute("on:q-render");const r=e.getAttribute("decl:template");qDev&&assertString(r);const o=extractPropsFromElement(e);jsxRenderComponent(e,r,n,o,t),i.push(e)})),flattenPromiseTree(n).then((()=>{t.$qScheduledRender=null,e(i)}),r)}))}))}function provideComponentState(t=!0){return function(e){const n=e.element.getAttribute(":.");if(null!=n)return JSON.parse(n);if(t)throw qError(402)}}function provideComponentProps(){return function(t){const e=t.elementProps;return qDev&&assertDefined(e),e}}function provideComponentProp(t){return function(e){const n=getClosestInjector(e.element),r=n.elementProps[t];if(null==r)throw qError(404,t,n.elementProps,n.element);return r}}function provideEntity(t){return async function(e){const n=getClosestInjector(e.element),[r]=await resolveArgs(e,t);return n.getEntity(r)}}function provideEntityState(t){return async function(e){const n=getClosestInjector(e.element),[r]=await resolveArgs(e,t);return n.getEntityState(r)}}export{Component,Entity,EventEntity,Host,QRL,dirname,emitEvent,entityStateKey,getInjector,injectEventHandler,injectFunction,injectMethod,jsxDeclareComponent,jsxFactory,jsxRender,markDirty,provideComponentProp,provideComponentProps,provideComponentState,provideElement,provideEntity,provideEntityState,provideEvent,provideInjector,provideProviderOf,provideQrlExp,provideUrlProp,qImport,serializeState,setConfig,toEntityKey}; | ||
function isDomElementWithTagName(t,e){return isHtmlElement(t)&&t.tagName.toLowerCase()==e.toLowerCase()}function isHtmlElement(t){return!!t&&1===t.nodeType}function isTextNode(t){return!!t&&3===t.nodeType}function stringifyDebug(t){return null==t?String(t):"function"==typeof t?t.name:isHtmlElement(t)?stringifyElement(t):t instanceof URL?String(t):"object"==typeof t?JSON.stringify(t,(function(t,e){return isHtmlElement(e)?stringifyElement(e):e})):String(t)}function stringifyElement(t){let e="<"+t.tagName.toLowerCase();const n=t.attributes,r=[];for(let t=0;t<n.length;t++)r.push(n[t].name);r.sort();for(let n=0;n<r.length;n++){const o=r[n];let i=t.getAttribute(o);(null==i?void 0:i.startsWith("file:/"))&&(i=i.replace(/(file:\/\/).*(\/.*)$/,((t,e,n)=>e+"..."+n))),e+=" "+o+(null==i||""==i?"":"='"+i.replace("'","'")+"'")}return e+">"}function qError(t,...e){const n=codeToText(t).split("{}"),r=n.map(((t,r)=>t+(r===n.length-1?"":stringifyDebug(e[r])))).join("");return new Error(r)}function codeToText(t){const e={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(t/100)],n={1:"QConfig not found in path '{}'.",2:"Unrecognized stack format '{}'",3:"Could not find entity state '{}' at '{}' or any of it's parents.",4:"Could not find entity state '{}' ( or entity provider '{}') at '{}' or any of it's parents.",5:"Missing property '{}' in props '{}'.",6:"Missing export '{}' from '{}'. Exported symbols are: {}",100:"QRL '${}' should point to function, was '{}'.",200:"Can't find host element above '{}'.",201:"Provider is expecting '{}' but got '{}'.",202:"Expected 'Element' was '{}'.",203:"Expected injection 'this' to be of type '{}', but was of type '{}'.",204:"Entity key '{}' is found on '{}' but does not contain state. Was 'serializeState()' not run during dehydration?",206:"No injector can be found starting at '{}'.",207:"EventInjector does not support serialization.",300:"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:"A entity with key '{}' already exists.",303:"'{}' is not a valid attribute. Attributes can only contain 'a-z' (lowercase), '0-9', '-' and '_'.",304:"Found '{}' but expando did not have entity and attribute did not have state.",305:"Element '{}' is missing entity attribute definition '{}'.",306:"Unable to create state for entity '{}' with props '{}' because no state found and '$newState()' method was not defined on entity.",307:"'{}' is not an instance of 'Entity'.",308:"'{}' overrides 'constructor' property preventing 'EntityType' retrieval.",311:"Entity '{}' does not define '$keyProps'.",310:"Entity '{}' must have static '$type' property defining the name of the entity.",312:"Entity '{}' must have static '$qrl' property defining the import location of the entity.",313:"Name collision. Already have entity named '{}' with QRL '{}' but expected QRL '{}'.",309:"Entity key '{}' is missing values. Expecting '{}:someValue'.",314:"Entity '{}' defines '$keyProps' as '{}'. Actual key '{}' has more parts than entity defines.",315:"Key '{}' belongs to entity named '{}', but expected entity '{}' with name '{}'.",316:"Entity state is missing '$key'. Are you sure you passed in state? Got '{}'.",400:"'bind:' must have an key. (Example: 'bind:key=\"propertyName\"').",401:"'bind:id' must have a property name. (Example: 'bind:key=\"propertyName\"').",402:"Can't find state on host element.",403:"Components must be instantiated inside an injection context. Use '{}.new(...)' for creation.",404:"Property '{}' not found in '{}' on component '{}'.",405:"Unable to find '{}' component.",406:"Requesting component '{}' does not match existing component '{}'. Verify that the two components have distinct '$templateQRL's.",407:"Expecting Component '{}' to have static '$templateQRL' property, but none was found.",408:"Unable to create state for component '{}' with props '{}' because no state found and '$newState()' method was not defined on component.",500:"Unrecognized expression format '{}'.",600:"Unexpected JSXNode<{}> type.",601:"Value '{}' can't be written into '{}' attribute.",602:"Expecting entity object, got '{}'.",603:"Expecting array of entities, got '{}'.",604:"Expecting Entity or Component got '{}'.",605:"'requestAnimationFrame' not found. If you are running on server design your applications in a way which does not require 'requestAnimationFrame' on first render.",606:"Expecting that element with 'bind:{}' should be a component (should have 'decl:template=\"qrl\"' attribute): {}",700:"Missing '$type' attribute in the '{}' url.",701:"Re-emitting event '{}' but no listener found at '{}' or any of its parents."}[t];let r="000"+t;return r=r.substr(r.length-3),`${e}(Q-${r}): ${n}`}const _globalThis="undefined"!=typeof globalThis&&globalThis,_window="undefined"!=typeof window&&window,_self="undefined"!=typeof self&&"undefined"!=typeof WorkerGlobalScope&&self instanceof WorkerGlobalScope&&self,__global="undefined"!=typeof global&&global,_global=_globalThis||__global||_window||_self;function dirname(t){const e=t.lastIndexOf("/",t.length-2);return-1==e?t:t.substr(0,e+1)}"undefined"==typeof qDev&&(_global.qDev=!0);const configs=[];function setConfig(t){t.baseURI.endsWith("/")||(t.baseURI=dirname(t.baseURI)),t.baseURI=normalizeBaseUri(t.baseURI),configs.push(t),configs.sort(((t,e)=>e.baseURI.length-t.baseURI.length))}function normalizeBaseUri(t){return t.startsWith("/")&&(t="file://"+t),t}function getConfig(t){if(null!=t){t=normalizeBaseUri(t);for(let e=0;e<configs.length;e++){const n=configs[e];if(t.startsWith(n.baseURI))return n}}if("undefined"==typeof document)throw qError(1,t+"\n"+configs.map((t=>JSON.stringify(t))).join("\n"));return _global.Q||(_global.Q={}),Q.baseURI||(Q.baseURI=document.baseURI),Q.protocol||(Q.protocol={}),Q}let importCache;function qImport(t,e){importCache||(importCache=new Map);const n=toUrl(toBaseURI(t),e),r=toImportPath(n),o=qExport(n),i=`${r}#${o}`,s=importCache.get(i);if(s)return s;const a=import(r+".js").then((t=>{const e=t[o];if(!e)throw qError(6,o,r,Object.keys(t));return qImportSet(i,e),e}));return qImportSet(i,a),a}function qImportSet(t,e){importCache.set(t,e)}function toBaseURI(t){if("string"==typeof t)return t;return(t.ownerDocument||t).baseURI}function toUrl(t,e){if("string"==typeof e){const n=getConfig(t);return new URL(adjustProtocol(n,e),n.baseURI)}return e}function toImportPath(t){const e=new URL(String(t));return e.hash="",e.search="",String(e).replace(/\.(ts|tsx)$/,".js")}function adjustProtocol(t,e){return String(e).replace(/(^\w+):\/?/,((e,n)=>{let r=t.protocol[n];return r?(r.endsWith("/")||(r+="/"),r):e}))}function qExport(t){return t.hash.replace(/^#?([^?]*).*$/,"$1")||"default"}function qParams(t){return new URLSearchParams(t.hash.replace(/^[^?]*\??(.*)$/,"$1"))}function assertValidDataKey(t){if(t)for(let e=0;e<t.length;e++){if(!isAlphanumeric(t.charCodeAt(e)))throw qError(300,t)}}function isAlphanumeric(t){return 65<=t&&t<=90||isAlphanumericAttribute(t)||46==t||58==t}function isAlphanumericAttribute(t){return 97<=t&&t<=122||48<=t&&t<=57||45==t||95==t}function isValidAttribute(t){for(let e=0;e<t.length;e++){if(!isAlphanumericAttribute(t.charCodeAt(e)))return!1}return!0}const camelToKebabCase=new Map;function fromCamelToKebabCase(t,e=!1){if("string"!=typeof t)return t;const n=camelToKebabCase.get(t);if(null!=n)return n;let r="";for(let n=0;n<t.length;n++){const o=t.charAt(n);isUpperCase(o)?r+=(0!=n||e?"-":"")+o.toLowerCase():r+=o}return camelToKebabCase.set(t,r),r}const kebabToCamelCase=new Map;function fromKebabToCamelCase(t,e=!0){const n=kebabToCamelCase.get(t);if(null!=n)return n;let r="",o=e;for(let e=0;e<t.length;e++){const n=t.charAt(e);isKebab(n)?o=!0:o?(o=!1,r+=n.toUpperCase()):r+=n}return kebabToCamelCase.set(t,r),r}function isUpperCase(t){return"A"<=t&&t<="Z"}function isKebab(t){return"-"===t}function stringify(t){return null==t?null:String(t)}function assertDefined(t,e){if(null==t)throw newError(e||"Expected defined value.")}function assertString(t,e){if("string"!=typeof t)throw newError(e||`Expected value '${t}' to be 'string' but was '${typeOf(t)}'.`)}function assertEqual(t,e,n){if(t!==e)throw newError(n||`Expected '${t}' === '${e}'.`)}function typeOf(t){var e;if(null===t)return"null";const n=typeof t;return"object"===n?(null===(e=null==t?void 0:t.constructor)||void 0===e?void 0:e.name)||"<unknown>":n}function newError(t){return new Error(t)}function toEntityKey(t){return qDev&&assertString(t),t}function propsToKey(t,e){let n=fromCamelToKebabCase(t.$type)+":";const r=t.$keyProps;if(!r)throw qError(311,t);for(let t=0;t<r.length;t++){0!=t&&(n+=":");n+=validateKeyPart(fromCamelToKebabCase(stringify(e[r[t]]),!0))}return n}function keyToProps(t,e){const n={},r=t.$keyProps;if(!r)throw qError(311,t);r.forEach((t=>n[t]=null));const o=String(e).split(":");if(o.length<=1)throw qError(309,e,e);const i=o.shift(),s=fromCamelToKebabCase(t.$type);if(s!==i)throw qError(315,e,i,t,s);if(0==r.length&&1==o.length&&""==o[0])return n;for(let i=0;i<o.length;i++){const s=o[i];if(i>=r.length)throw qError(314,t,r,e);const a=r[i];n[a]=""==s&&i==o.length-1?null:fromKebabToCamelCase(s,!1)}return n}function validateKeyPart(t){const e=null==t?"":String(t);if(isValidAttribute(e))return e;throw qError(303,t)}function entityStateKey(t){const e=t.$key;if("string"!=typeof e)throw qError(316,t);return e}function keyToEntityAttribute(t){const e=t,n=e.indexOf(":");if(-1==n)throw qError(300,e);return"::"+e.substr(0,n)}function findAttribute(t,e,n,r,o,i){let s=t;for(;s;){const t=s.getAttribute(n);if(null!==t)return r(s,n,t);if(o&&i){const t=s.getAttribute(o);if(null!==t)return i(s,o,t)}s=s.parentElement}throw o?qError(e,n,o,t):qError(e,n,t)}function extractPropsFromElement(t){const e={},n=t.attributes;for(let t=0;t<n.length;t++){const r=n[t],o=r.name,i=r.value;if(o.startsWith("bind:")){const t=o.substr(5);if(!t)throw qError(400);if(!i)throw qError(401);i.split(";").forEach((n=>n&&(e[n]=t)))}else-1!==o.indexOf(":")||(e[fromKebabToCamelCase(o,!1)]=i)}return e}function resolveArgs(t,...e){const n=[];for(let r=0;r<e.length;r++){const o=e[r];n.push(isProvider(o)?o(t):o)}return Promise.all(n)}function isProvider(t){return"function"==typeof t}class BaseInjector{constructor(t){this._props=null,this.element=t}invoke(t,e,...n){if(!isInjectedFunction(t))return Promise.resolve(t.apply(null,n));try{const r=t.$thisType;if(e&&r&&!(e instanceof r))throw qError(203,r,e.constructor);return resolveArgs(this,r&&null==e?this.getComponent(r):e,...t.$inject).then((e=>t.apply(e.shift(),e.concat(n))),(e=>Promise.reject(addDeclaredInfo(t,e))))}catch(e){throw addDeclaredInfo(t,e)}}set elementProps(t){this._props=t}get elementProps(){const t=this._props;return null!=t?t:extractPropsFromElement(this.element)}}function addDeclaredInfo(t,e){const n=t.$debugStack;if(!n)return e;e instanceof Error||(e=new Error(String(e)));const r=n.stack.split("\n")[2].trim(),o=e.stack,i=e.message;return e.stack=o.replace(i,i+"\n DECLARED "+r),e}function isInjectedFunction(t){return!!t.$inject}class ElementInjector extends BaseInjector{constructor(){super(...arguments),this.component=null,this.componentPromise=null,this.entities=null}getParent(){let t=this.element.parentElement;for(;t;){if(t.hasAttribute(":")||t.hasAttribute("decl:template"))return getInjector(t);t=t.parentElement}return null}getComponent(t){const e=this.element.getAttribute("decl:template"),n=t.$templateQRL;if(!n)throw qError(407,t);if(e===n){let e=this.component;if(e){if(e instanceof t)return this.componentPromise;throw qError(406,t,e.constructor)}{const n=this.element.getAttribute(":."),r=n?JSON.parse(n):null;return this.component=e=new t(this.element,this.elementProps,r),this.componentPromise=new Promise(((t,n)=>{let o;o=null==r?Promise.resolve(e.$newState(e.$props)).then((t=>{e.$state=t})):Promise.resolve(e),o.then((()=>e.$init())).then((()=>t(e)),n)}))}}{const e=this.getParent();if(!e)throw qError(405,t);return e.getComponent(t)}}getEntity(t,e,n){var r,o;let i=null===(o=null===(r=this.entities)||void 0===r?void 0:r.get(t))||void 0===o?void 0:o.promise;if(i)return i;const s=keyToEntityAttribute(t),a=this;return findAttribute(this.element,4,String(t),l,s,l);function l(r,o,l){var c,u;const f=r===a.element?a:getInjector(r);if(i=null===(u=null===(c=f.entities)||void 0===c?void 0:c.get(t))||void 0===u?void 0:u.promise,i)return i;f.element.setAttribute(String(t),"");const p=r.getAttribute(s);if(!p)throw qError(305,r,s);const m=Promise.resolve(n||qImport(r,p));i=toEntityPromise(t,new Promise(((n,i)=>{m.then((s=>{if("function"!=typeof s)throw qError(100,p,s);let c=e||null;c||o!==String(t)||(c=JSON.parse(l),c.$key=t);const u=s.$keyToProps(t),f=new s(r,u,c);let m;c?(d.entity=f,m=Promise.resolve(f)):m=f.$newState(u).then((e=>(d.entity=f,e.$key=t,f.$state=e,f)),(e=>{var n;return null===(n=a.entities)||void 0===n||n.delete(t),Promise.reject(e)})),m.then((()=>{Promise.resolve(f.$init()).then((()=>n(f)))}),i)}),i)})));const d={promise:i,entity:null};return(f.entities||(f.entities=new Map)).set(t,d),i}}getEntityState(t){const e=keyToEntityAttribute(t);return findAttribute(this.element,4,t,((e,n,r)=>{var o,i;const s=null===(i=null===(o=(e==this.element?this:getInjector(e)).entities)||void 0===o?void 0:o.get(t))||void 0===i?void 0:i.promise;if(s)return s.then((t=>t.$state));if(!r)throw qError(204,t,e);const a=JSON.parse(r);return a.$key=n,Promise.resolve(a)}),e,(e=>getInjector(e).getEntity(t).then((t=>t.$state))))}releaseEntity(t){var e;(null===(e=this.entities)||void 0===e?void 0:e.delete(t))&&this.element.removeAttribute(t)}serialize(){var t,e;const n=this.element,r=null===(t=this.component)||void 0===t?void 0:t.$state;null!=r&&n.setAttribute(":.",JSON.stringify(r)),null===(e=this.entities)||void 0===e||e.forEach((t=>{var e;const r=null===(e=t.entity)||void 0===e?void 0:e.$state;r&&n.setAttribute(r.$key,JSON.stringify(r,filterFrameworkKeys))}))}}function filterFrameworkKeys(t,e){return t.startsWith("$")?void 0:e}function toEntityPromise(t,e){const n=e;return n.$key=t,n}function getInjector(t,e=!0){if(!isHtmlElement(t))throw qError(202,t);const n=t;let r=n.$injector;return e&&!r&&(n.$injector=r=new ElementInjector(t),t.setAttribute(":","")),r||null}function getClosestInjector(t,e=!0){let n=t;for(;n;){if(n.hasAttribute(":")||n.hasAttribute("decl:template"))return getInjector(n);n=n.parentElement}if(e)throw qError(206,t);return null}class Component{constructor(t,e,n){this.$host=t,this.$props=e,this.$state=n}static $new(t){const e=this,n=t.getAttribute("decl:template");if(n){if(n!==e.$templateQRL)throw new Error("Write proper error")}else t.setAttribute("decl:template",e.$templateQRL);return getInjector(t).getComponent(e)}$init(){}$newState(t){throw qError(408,this.constructor,t)}}function isComponent(t){var e;return"string"==typeof(null===(e=null==t?void 0:t.constructor)||void 0===e?void 0:e.$templateQRL)}function emitEvent(t,e,n){const r=qParams(n),o=r.get("$type");if(null==o)throw qError(700,n);const i=findAttribute(t,701,"on:"+fromCamelToKebabCase(o),((t,e,n)=>{const i=n;return Promise.resolve(qImport(t,i)).then((e=>{const n=toUrl(toBaseURI(t),i),s=new CustomEvent(o);return r.forEach(((t,e)=>{s[e]=t})),e(t,s,n)}))}));return Promise.resolve(i)}function getFilePathFromFrame(t){const e=t.match(/\(?(\S*):\d+:\d+\)?/);if(!e)throw qError(2,t);return e[1].replace(/\.(ts|tsx)$/,".js")}Component.$templateQRL=null;class Entity{constructor(t,e,n){const r=getEntityType(this);this.$props=e,this.$state=n,this.$element=t,this.$key=propsToKey(r,e),e&&r.$attachEntity(t),e&&r.$attachEntityState(t,e,null)}static get $type(){return this.$_name}static set $type(t){if(!t.startsWith("$")){const e=getFilePathFromFrame((new Error).stack.split("\n")[2]);this.$config=getConfig(e),this.$_name=t}}static $attachEntity(t){const e=this;if(!e.$type)throw qError(310,e);if(!e.$qrl)throw qError(312,e);const n="::"+fromCamelToKebabCase(e.$type),r=t.getAttribute(n);if(r){if(r!=e.$qrl)throw qError(313,e.$type,r,e.$qrl)}else t.setAttribute(n,String(e.$qrl))}static $attachEntityState(t,e,n){this.$attachEntity(t);const r="string"==typeof e?e:propsToKey(this,e);t.hasAttribute(String(r))||t.setAttribute(String(r),null==n?"":JSON.stringify(n))}static $hydrate(t,e,n){const r="string"==typeof e?e:propsToKey(this,e);n&&(n.$key=r);const o=keyToEntityAttribute(r);t.hasAttribute(o)||this.$attachEntity(t);return getInjector(t).getEntity(r,n,this)}static $keyToProps(t){return keyToProps(this,t)}static $propsToKey(t){return propsToKey(this,t)}async $invokeQRL(t,...e){const n=getEntityType(this),r=await qImport(n.$config,t);return getInjector(this.$element).invoke(r,this,...e)}$newState(t){throw qError(306,this.constructor.$type,t)}async $init(){}$release(){const t=getInjector(this.$element),e=propsToKey(getEntityType(this),this.$props);t.releaseEntity(e)}}function getEntityType(t){if(!(t instanceof Entity))throw qError(307,t);const e=t.constructor;if(e.$attachEntityState!==Entity.$attachEntityState)throw qError(308,t);return e}function isEntity(t){return Object.prototype.hasOwnProperty.call(t,"$key")}Entity.$config=null,Entity.$_name=null,Entity.$keyProps=[];class EventEntity extends Entity{constructor(t,e,n,r){super(t,null,null),this.$key=EventEntity.KEY,this.event=e,this.url=n,this.props=r}}EventEntity.$qrl="",EventEntity.$type="$EventEntity",EventEntity.$props=["id"],EventEntity.KEY="$event:";class EventInjector extends BaseInjector{constructor(t,e,n){super(t),this.parentInjector=null;const r={};qParams(n).forEach(((t,e)=>r[e]=t)),this.eventEntity=new EventEntity(t,e,n,r)}getParent(){const t=this.parentInjector;return t||(this.parentInjector=getClosestInjector(this.element,!1))}getComponent(t){return this.getParent().getComponent(t)}getEntity(t,e,n){return t===EventEntity.KEY?this.eventEntity:this.getParent().getEntity(t,e,n)}getEntityState(t){return this.getParent().getEntityState(t)}releaseEntity(t){var e;return null===(e=this.getParent())||void 0===e?void 0:e.releaseEntity(t)}serialize(){throw qError(207)}}function injectEventHandler(...t){const e=t.pop(),n=e.$thisType=t.shift();e.$inject=t,qDev&&(e.$debugStack=new Error);const r=function(t,r,o){var i;const s=new EventInjector(t,r,o);return Promise.resolve(n&&(null===(i=s.getParent())||void 0===i?void 0:i.getComponent(n))||null).then((t=>s.invoke(e,t)))};return r.$delegate=e,r}function provideElement(){return function(t){return t.element}}function provideEvent(){return async function(t){return(await t.getEntity(EventEntity.KEY)).event}}function provideQrlExp(t){return async function(e){const n=await e.getEntity(EventEntity.KEY),r=n.props[t];if(null==r)throw qError(5,t,n.props);switch(r.charAt(0)){case".":let t=n.event;qDev&&assertDefined(t);const e=r.substr(1).split(".");for(;e.length&&t;)t=t[e.shift()];return t;default:throw qError(500,r)}}}function provideUrlProp(t){return async function(e){return(await e.getEntity(EventEntity.KEY)).props[t]||null}}function flattenArray(t,e){e||(e=[]);for(let n=0;n<t.length;n++){const r=t[n];Array.isArray(r)?flattenArray(r,e):e.push(r)}return e}function flattenPromiseTree(t){return Promise.all(t).then((t=>{const e=flattenArray(t);for(let t=0;t<e.length;t++)if(isPromise(e[t]))return flattenPromiseTree(e);return e}))}function isPromise(t){return t instanceof Promise}function QRL(t,...e){let n="";for(let r=0;r<t.length;r++){n+=t[r],r<e.length&&(n+=e[r])}return qDev&&assertEqual(!!n.match(/^[.|/|\w+:]/),!0,"Expecting URL to start with '.', '/', '<protocol>:'. Was: "+n),qDev&&verifyQrl(new Error("Invalid import: "+n),n),n}async function verifyQrl(t,e){const n=t.stack;if(!n)return Promise.resolve(null);const r=getFilePathFromFrame(n.split("\n")[2]),o=getConfig(r);try{const t=qImport(o,e);return isPromise(t)?t.catch((t=>Promise.reject(i(t)))):t}catch(t){throw new Error(i(t))}function i(t){return`QRL-ERROR: '${e}' is not a valid import.\nResolved URL: ${toUrl(r,e)}\n Base URL: ${o.baseURI}\n CONFIG: ${JSON.stringify(o)}\n STACK: ${n}\n => ${t}`}}function injectFunction(...t){const e=t.pop();return e.$thisType=null,e.$inject=t,qDev&&(e.$debugStack=new Error),e}function injectMethod(...t){const e=t.pop();return e.$thisType=t.shift(),e.$inject=t,qDev&&(e.$debugStack=new Error),e}function provideInjector(){return async function(t){return t}}function provideProviderOf(t){return async function(e){return()=>Promise.resolve(t(e))}}function serializeState(t){isHtmlElement(t)&&serializeNode(t),t.querySelectorAll("[\\:]").forEach(serializeNode)}function serializeNode(t){const e=getInjector(t,!1);e&&e.serialize()}const EMPTY_ARRAY=[];qDev&&Object.freeze(EMPTY_ARRAY);const EMPTY_OBJ={};qDev&&Object.freeze(EMPTY_OBJ);class JSXNode_{constructor(t,e,n){this.tag=t,this.props=e||EMPTY_OBJ,this.children=n}}function isJSXNode(t){return t instanceof JSXNode_}function jsxFactory(t,e,...n){return new JSXNode_(t,e,flattenArray(n))}function jsxDeclareComponent(t,e="div",n){return function(r){return jsxFactory(e,Object.assign(Object.assign({"decl:template":t},n),r))}}function removeNode(t,e){const n=e.nextSibling;return t.removeChild(e),n}function replaceNode(t,e,n){return t.insertBefore(n,e),e&&t.removeChild(e),n}function applyAttributes(t,e,n){let r=!1;if(e){let o=null;for(const i in e)if(Object.prototype.hasOwnProperty.call(e,i)){const s=fromCamelToKebabCase(i),a=e[i];"decl:entity"===i?applyEntityProviders(a,t):"decl:template"===i?setAttribute(t,"decl:template",a):i.startsWith("on:")?setAttribute(t,s,a):i.startsWith("$")?addToBindMap(stringify(a),o||(o=new Map),i):n?t.getAttribute(s)!==a&&(setAttribute(t,i,a,s),r=!0):setAttribute(t,i,a,s)}o&&(r=updateBindMap(t,o)||r)}return r}function applyEntityProviders(t,e){if(!Array.isArray(t))throw qError(603,t);t.forEach((t=>{if("function"!=typeof(null==t?void 0:t.$attachEntity))throw qError(602,t);t.$attachEntity(e)}))}function addToBindMap(t,e,n){qDev&&assertValidDataKey(t);const r="bind:"+(t?fromCamelToKebabCase(t):"");let o=e.get(r);o?o+="|"+n:o=n,e.set(r,o)}function updateBindMap(t,e){let n=!1;for(let r=0,o=t.attributes;r<o.length;r++){const i=o[r],s=i.name;if(s.startsWith("bind:")){const o=e.get(s);null!=o?(e.delete(s),i.value===o?e.delete(s):(n=!0,i.value=o)):(n=!0,t.removeAttribute(s),r--)}}return e.forEach(((e,r)=>{n=!0,t.setAttribute(r,e)})),n}function setAttribute(t,e,n,r){"class"==e?t.setAttribute("class",stringifyClassOrStyle(n,!0)):"style"==e?t.setAttribute("style",stringifyClassOrStyle(n,!1)):null==n||!1===n?t.removeAttribute(e):"innerHTML"===e||"innerText"===e?(t.setAttribute(r,""),t[e]=n):"INPUT"===t.tagName&&-1==e.indexOf(":")?(t.setAttribute(e,String(n)),t[e]=n):t.setAttribute(e,String(n))}function stringifyClassOrStyle(t,e){if(null==t)return"";if("object"==typeof t){let n="",r="";if(Array.isArray(t)){if(!e)throw qError(601,t,"style");for(let e=0;e<t.length;e++)n+=r+t[e],r=" "}else for(const o in t)if(Object.prototype.hasOwnProperty.call(t,o)){const i=t[o];n+=e?i?r+o:"":r+o+":"+i,r=e?" ":";"}return n}return String(t)}function Host(){throw newError("Should not execute")}async function jsxRender(t,e,n){const r=[];let o=t.firstChild;for(;o&&o.nodeType>8;)o=o.nextSibling;return visitJSXNode(n||document,r,t,o,e),flattenPromiseTree(r)}function visitJSXNode(t,e,n,r,o){if(!o)return null;if(isPromise(o))return e.push(o.then((e=>{const o=[],i=visitJSXNode(t,o,n,r,e);return i&&o.push(i),o}),writeErrorToDom(n))),null;if("string"==typeof o.tag)return visitJSXDomNode(t,e,n,r,o);if(o.tag===Host)return visitJSXHostNode(t,e,n,r,o);if("function"==typeof o.tag)return visitJSXFactoryNode(t,e,n,r,o);if(null===o.tag)return visitJSXFragmentNode(t,e,n,r,o);throw qError(600,o.tag)}function visitJSXDomNode(t,e,n,r,o){const i=o.tag;let s,a=!1;isDomElementWithTagName(r,i)?s=r:(s=replaceNode(n,r,t.createElement(i)),a=!0);const l=getComponentTemplateUrl(o),c=!!l;return a=applyAttributes(s,o.props,c)||a,l&&a&&jsxRenderComponent(s,l,e,o.props,t),l||"innerHTML"in o.props||"innerText"in o.props||visitChildren(t,e,s,s.firstChild,o.children),s}function jsxRenderComponent(t,e,n,r,o=document){const i=qImport(t,e);isPromise(i)?n.push(i.then((e=>{const n=[t];return visitJSXComponentNode(o,n,t,t.firstChild,e,r),n}))):visitJSXComponentNode(o,n,t,t.firstChild,i,r)}function visitJSXComponentNode(t,e,n,r,o,i){i||(i=EMPTY_OBJ);const s=getInjector(n);s.elementProps=i;return visitJSXNode(t,e,n,r,s.invoke(o,void 0,i))}function getComponentTemplateUrl(t){return(t.props||EMPTY_OBJ)["decl:template"]||null}function visitJSXFactoryNode(t,e,n,r,o){return visitJSXNode(t,e,n,r,o.tag(o.props))}function visitJSXHostNode(t,e,n,r,o){return applyAttributes(n,o.props,!1),visitChildren(t,e,n,r,o.children),n}function visitJSXFragmentNode(t,e,n,r,o){return visitChildren(t,e,n,r,o.children)}function visitChildren(t,e,n,r,o){if(o)for(let i=0;i<o.length;i++){const s=o[i];isJSXNode(s)?r=visitJSXNode(t,e,n,r,s):null==s?r&&(r=removeNode(n,r)):isTextNode(r)?r.textContent=String(s):replaceNode(n,r,t.createTextNode(String(s))),r=(null==r?void 0:r.nextSibling)||null}for(;r;)r=removeNode(n,r);return null}function writeErrorToDom(t){return function(e){console.error("ERROR:",e);const n=t,r=n.ownerDocument.createElement("pre");return n.appendChild(r),r.textContent=String(e),Promise.reject(e)}}function isElement(t){return t&&!!t.ownerDocument}function markDirty(t){if(isEntity(t))return markEntityDirty(t);if(isComponent(t))return markComponentDirty(t);if(isElement(t))return markElementDirty(t);throw qError(604,t)}function markComponentDirty(t){return markElementDirty(t.$host)}function markElementDirty(t){const e=t.ownerDocument;t.setAttribute("on:q-render",t.getAttribute("decl:template"));const n=e.$qScheduledRender;return isPromise(n)?n:scheduleRender(e)}function markEntityDirty(t){const e=t.$key,n=t.$element.ownerDocument;let r=!1;return n.querySelectorAll(toAttrQuery("bind:"+e)).forEach((t=>{const n=t.getAttribute("decl:template");if(!n)throw qError(606,e,t);r=!0,t.setAttribute("on:q-render",n)})),r?scheduleRender(n):Promise.resolve([])}function toAttrQuery(t){return"["+t.replace(/[:.\-_]/g,(t=>"\\"+t))+"]"}function scheduleRender(t){const e=t.$qScheduledRender;if(e)return e;const n=t.defaultView.requestAnimationFrame;if(!n)throw qError(605);return t.$qScheduledRender=new Promise(((e,r)=>{n((()=>{const n=[],o=t.querySelectorAll("[on\\:q-render]"),i=[];o.forEach((e=>{e.removeAttribute("on:q-render");const r=e.getAttribute("decl:template");qDev&&assertString(r);const o=extractPropsFromElement(e);jsxRenderComponent(e,r,n,o,t),i.push(e)})),flattenPromiseTree(n).then((()=>{t.$qScheduledRender=null,e(i)}),r)}))}))}function provideComponentState(t=!0){return function(e){const n=e.element.getAttribute(":.");if(null!=n)return JSON.parse(n);if(t)throw qError(402)}}function provideComponentProps(){return function(t){const e=t.elementProps;return qDev&&assertDefined(e),e}}function provideComponentProp(t){return function(e){const n=getClosestInjector(e.element),r=n.elementProps[t];if(null==r)throw qError(404,t,n.elementProps,n.element);return r}}function provideEntity(t){return async function(e){const n=getClosestInjector(e.element),[r]=await resolveArgs(e,t);return n.getEntity(r)}}function provideEntityState(t){return async function(e){const n=getClosestInjector(e.element),[r]=await resolveArgs(e,t);return n.getEntityState(r)}}export{Component,Entity,EventEntity,Host,QRL,dirname,emitEvent,entityStateKey,getInjector,injectEventHandler,injectFunction,injectMethod,jsxDeclareComponent,jsxFactory,jsxRender,markDirty,provideComponentProp,provideComponentProps,provideComponentState,provideElement,provideEntity,provideEntityState,provideEvent,provideInjector,provideProviderOf,provideQrlExp,provideUrlProp,qImport,serializeState,setConfig,toEntityKey}; |
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is too big to display
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
1025210
10905
3