jj 2.3.0 → 2.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +18 -57
- package/lib/JJD.d.ts +36 -25
- package/lib/JJD.js +56 -28
- package/lib/JJD.js.map +1 -1
- package/lib/JJDF.d.ts +19 -5
- package/lib/JJDF.js +32 -2
- package/lib/JJDF.js.map +1 -1
- package/lib/JJE.d.ts +96 -110
- package/lib/JJE.js +143 -154
- package/lib/JJE.js.map +1 -1
- package/lib/JJET.d.ts +79 -0
- package/lib/JJET.js +114 -0
- package/lib/JJET.js.map +1 -0
- package/lib/JJEx.d.ts +63 -0
- package/lib/JJEx.js +83 -0
- package/lib/JJEx.js.map +1 -0
- package/lib/JJHE.d.ts +26 -37
- package/lib/JJHE.js +34 -62
- package/lib/JJHE.js.map +1 -1
- package/lib/JJN-wrap.js +46 -0
- package/lib/JJN-wrap.js.map +1 -0
- package/lib/JJN.d.ts +21 -106
- package/lib/JJN.js +44 -164
- package/lib/JJN.js.map +1 -1
- package/lib/JJNx.d.ts +126 -0
- package/lib/JJNx.js +157 -0
- package/lib/JJNx.js.map +1 -0
- package/lib/JJSE.d.ts +32 -10
- package/lib/JJSE.js +36 -9
- package/lib/JJSE.js.map +1 -1
- package/lib/JJSR.d.ts +8 -4
- package/lib/JJSR.js +10 -5
- package/lib/JJSR.js.map +1 -1
- package/lib/JJT.d.ts +26 -13
- package/lib/JJT.js +38 -30
- package/lib/JJT.js.map +1 -1
- package/lib/bundle.js +779 -734
- package/lib/bundle.js.map +3 -3
- package/lib/bundle.min.js +1 -2
- package/lib/components.js +5 -4
- package/lib/components.js.map +1 -1
- package/lib/helpers.d.ts +3 -2
- package/lib/helpers.js +11 -9
- package/lib/helpers.js.map +1 -1
- package/lib/index.d.ts +20 -2
- package/lib/index.js +21 -2
- package/lib/index.js.map +1 -1
- package/lib/internal.d.ts +30 -0
- package/lib/internal.js +35 -0
- package/lib/internal.js.map +1 -0
- package/lib/types.d.ts +18 -30
- package/lib/util.d.ts +0 -28
- package/lib/util.js +0 -32
- package/lib/util.js.map +1 -1
- package/llms.txt +214 -0
- package/package.json +11 -3
- package/lib/case.test.js +0 -79
- package/lib/case.test.js.map +0 -1
- package/lib/mixin-types.d.ts +0 -143
- package/lib/mixin-types.js +0 -2
- package/lib/mixin-types.js.map +0 -1
- package/lib/mixins.d.ts +0 -94
- package/lib/mixins.js +0 -359
- package/lib/mixins.js.map +0 -1
- package/lib/util.test.d.ts +0 -1
- package/lib/util.test.js +0 -46
- package/lib/util.test.js.map +0 -1
- /package/lib/{case.test.d.ts → JJN-wrap.d.ts} +0 -0
package/lib/bundle.min.js
CHANGED
|
@@ -1,2 +1 @@
|
|
|
1
|
-
function m(e){return e!==void 0}function d(e){return typeof e=="function"}var{isNaN:O,isFinite:K,isInteger:X}=Number;function J(e){return typeof e=="number"&&!O(e)}function A(e,t,r){if(!J(e))throw new TypeError(`inRange(): "x" must be a number. Got ${e} (${typeof e})`);if(m(t)){if(!J(t))throw new TypeError(`inRange(): "min" must be a number. Got ${t} (${typeof t})`);if(m(r)){if(!J(r))throw new TypeError(`inRange(): "max" must be a number. Got ${r} (${typeof r})`);return t>r?r<=e&&e<=t:t<=e&&e<=r}return e>=t}else if(m(r)){if(!J(r))throw new TypeError(`inRange(): "max" must be a number. Got ${r} (${typeof r})`);return e<=r}throw new TypeError(`inRange(): expected at least min or max to be defined. Got min=${t} and max=${r}`)}var{isArray:F}=Array;function S(e,t=0,r){return F(e)&&A(e.length,t,r)}var{hasOwnProperty:nt}=Object;function h(e){return!!e&&typeof e=="object"}function n(e,t){if(!d(t))throw new TypeError(`Expected a constructor function. Got ${t} (${typeof t})`);return e instanceof t}function c(e,...t){if(!h(e))return!1;for(let r of t)if(!(r in e))return!1;return!0}function o(e){return typeof e=="string"}var{hasOwnProperty:lt}=Object,{isArray:mt}=Array;function G(e){if(!o(e))throw new TypeError(`Expected a string file path. Got ${e} (${typeof e})`);let t=e.lastIndexOf(".");if(t===-1)return"";let r=e.slice(t+1);return r.indexOf("/")!==-1?"":r.toLowerCase().trim()}function $t(){return new Promise(e=>requestAnimationFrame(e))}function At(e=0){return new Promise(t=>setTimeout(t,e))}function I(e,t,r){e.addEventListener(t,r)}function R(e,t,r){e.removeEventListener(t,r)}async function $(e){return await new CSSStyleSheet().replace(e)}function Lt(e){if(!o(e))throw new TypeError(`Expected a string. Got ${e} (${typeof e})`);if(/[^a-zA-Z0-9_]/.test(e))throw new TypeError(`Invalid characters in string. Only alphanumeric and underscores are allowed. Got: ${e}`);return e.replace(/([a-z0-9])([A-Z])/g,"$1-$2").replace(/([A-Z])([A-Z][a-z])/g,"$1-$2").replace(/_/g,"-").toLowerCase()}function Gt(e){if(!o(e))throw new TypeError(`Expected a string. Got ${e} (${typeof e})`);return e.split("-").filter(Boolean).map(t=>t.charAt(0).toUpperCase()+t.slice(1)).join("")||(e.length>0?e.charAt(0).toUpperCase()+e.slice(1):"")}function v(e){if(!o(e))throw new TypeError(`Expected a string. Got ${e} (${typeof e})`);return e.replace(/^-+|-+$/g,"").replace(/-+([a-z])/g,(t,r)=>r.toUpperCase())}var s=class e{static from(t){return new e(t)}static wrap(t){throw new ReferenceError("The mixin is supposed to override this method.")}static unwrap(t){throw new ReferenceError("The mixin is supposed to override this method.")}static wrapAll(t){return Array.from(t,e.wrap)}static unwrapAll(t){return Array.from(t,e.unwrap)}#t;constructor(t){if(!n(t,Node))throw new TypeError(`Expected a Node. Got ${t} (${typeof t})`);this.#t=t}get ref(){return this.#t}clone(t){return e.wrap(this.ref.cloneNode(t))}append(...t){let r=e.unwrapAll(t),i=this.ref;for(let p of r)p&&i.appendChild(p);return this}mapAppend(t,r){return this.append(...t.map(r))}prepend(...t){let r=e.unwrapAll(t),i=this.ref,p=i.firstChild;for(let a of r)a&&i.insertBefore(a,p);return this}mapPrepend(t,r){return this.prepend(...t.map(r))}replaceChildren(...t){return this.empty().append(...t)}on(t,r){return I(this.ref,t,r),this}off(t,r){return R(this.ref,t,r),this}rm(){return this.ref.parentNode?.removeChild(this.ref),this}empty(){let t=this.ref;for(;t.firstChild;)t.removeChild(t.firstChild);return this}run(t,...r){return t.call(this,...r)}};var y=class e extends s{static from(t){if(!n(t,Text))throw new TypeError(`Expected a Text object. Got: ${t} (${typeof t})`);return new e(t)}constructor(t){if(o(t))super(document.createTextNode(t));else if(n(t,Text))super(t);else throw new TypeError(`Expected a Text. Got: ${t} (${typeof t})`)}getText(){return this.ref.textContent??""}setText(t){if(!o(t))throw new TypeError(`Expected a string. Got: ${t} (${typeof t})`);return this.ref.textContent=t,this}empty(){return this.setText("")}addLines(...t){return this.setText(t.join(`
|
|
2
|
-
`))}};var l=class e extends s{static from(t){return new e(t)}static create(){return new e(document.createDocumentFragment())}constructor(t){if(!n(t,DocumentFragment))throw new TypeError(`Expected a DocumentFragment. Got ${t} (${typeof t})`);super(t)}};var g=class e extends l{static from(t){return new e(t)}constructor(t){if(!n(t,ShadowRoot))throw new TypeError(`Expected a ShadowRoot. Got ${t} (${typeof t})`);super(t)}getHTML(){return this.ref.innerHTML}setHTML(t,r){return this.ref.innerHTML=t,this}addStyleSheets(...t){return this.ref.adoptedStyleSheets.push(...t),this}};var f=class e extends s{static from(t){return new e(t)}constructor(t){if(!n(t,Element))throw new TypeError(`Expected an Element. Got: ${t} (${typeof t})`);super(t)}byId(t,r=!0){if(!o(t))throw new TypeError(`Expected a string id. Got ${t} (${typeof t})`);return this.query(`#${t}`,r)}getAttr(t){return this.ref.getAttribute(t)}hasAttr(t){return this.ref.hasAttribute(t)}setAttr(t,r){return this.ref.setAttribute(t,r),this}setAttrs(t){if(!h(t))throw new TypeError(`Expected an object. Got: ${t} (${typeof t})`);for(let[r,i]of Object.entries(t))this.setAttr(r,i);return this}rmAttr(t){return this.rmAttrs(t)}rmAttrs(...t){for(let r of t)this.ref.removeAttribute(r);return this}getAria(t){return this.ref.getAttribute(`aria-${t}`)}hasAria(t){return this.ref.hasAttribute(`aria-${t}`)}setAria(t,r){return this.ref.setAttribute(`aria-${t}`,r),this}rmAria(t){return this.ref.removeAttribute(`aria-${t}`),this}getClass(){return this.getAttr("class")}setClass(t){return this.setAttr("class",t)}rmClass(){return this.rmAttr("class")}addClass(...t){return this.ref.classList.add(...t),this}rmClasses(...t){return this.ref.classList.remove(...t),this}hasClass(t){return this.ref.classList.contains(t)}toggleClass(t){return this.ref.classList.toggle(t),this}replaceClass(t,r){return this.ref.classList.replace(t,r),this}onClick(t){return this.on("click",t)}hide(){return this.setAttr("hidden","").setAttr("aria-hidden","true")}show(){return this.rmAttrs("hidden","aria-hidden")}disable(){return this.setAttr("disabled","").setAttr("aria-disabled","true")}enable(){return this.rmAttrs("disabled","aria-disabled")}getTitle(){return this.getAttr("title")}setTitle(t){return this.setAttr("title",t)}setId(t){return this.setAttr("id",t)}getId(){return this.getAttr("id")}getHTML(){return this.ref.innerHTML}setHTML(t){return this.ref.innerHTML=t,this}initShadow(t="open",r){let i=this.ref.shadowRoot??this.ref.attachShadow({mode:t});if(h(r)){let{template:p,styles:a}=r;p&&(i.innerHTML=p),S(a)&&a.length&&i.adoptedStyleSheets.push(...a)}return this}get shadow(){return this.ref.shadowRoot?new g(this.ref.shadowRoot):null}};var u=class e extends f{static from(t){return new e(t)}static fromTag(t,r){if(!o(t))throw new TypeError(`Expected a string for tagName. Got: ${t} (${typeof t})`);return new e(document.createElement(t,r))}constructor(t){if(!n(t,HTMLElement))throw new TypeError(`Expected an HTMLElement. Got ${t} (${typeof t})`);super(t)}getValue(){if(!c(this.ref,"value"))throw new Error("Element does not have a value property");return this.ref.value}setValue(t){if(!c(this.ref,"value"))throw new Error("Element does not have a value property");return this.ref.value=t,this}focus(){return this.ref.focus(),this}click(){return this.ref.click(),this}getText(){return this.ref.innerText}setText(t){return this.ref.innerText=t,this}query(t,r=!0){let i=this.ref.querySelector(t);if(i)return s.wrap(i);if(r)throw new TypeError(`Element with selector ${t} not found`);return null}queryAll(t){return s.wrapAll(this.ref.querySelectorAll(t))}};var M="http://www.w3.org/2000/svg",E=class e extends f{static from(t){return new e(t)}static fromTag(t,r){if(!o(t))throw new TypeError(`Expected a string for tagName. Got: ${t} (${typeof t})`);let i=document.createElementNS(M,t,r);return new e(i)}constructor(t){if(!n(t,SVGElement))throw new TypeError(`Expected an SVGElement. Got ${t} (${typeof t})`);super(t)}getText(){return this.ref.textContent??""}setText(t){return this.ref.textContent=t,this}empty(){return this.ref.textContent="",this}setFill(t){return this.setAttr("fill",t)}setStroke(t){return this.setAttr("stroke",t)}setStrokeWidth(t){return this.setAttr("stroke-width",String(t))}setViewBox(t,r,i,p){if(typeof t=="number"&&r!==void 0&&i!==void 0&&p!==void 0)return this.setAttr("viewBox",`${t} ${r} ${i} ${p}`);let a=t;return this.setAttr("viewBox",Array.isArray(a)?a.join(" "):a)}setWidth(t){return this.setAttr("width",String(t))}setHeight(t){return this.setAttr("height",String(t))}setD(t){return this.setAttr("d",Array.isArray(t)?t.join(" "):t)}setTransform(t){return this.setAttr("transform",t)}};var w=class e extends s{static from(t){return new e(t)}constructor(t){if(!n(t,Document))throw new TypeError(`Expected a Document. Got ${t} (${typeof t})`);super(t)}get head(){return s.wrap(this.ref.head)}get body(){return s.wrap(this.ref.body)}setTitle(t){return this.ref.title=t,this}getTitle(){return this.ref.title}};var{wrapAll:D,unwrapAll:b}=s;function T(e){if(o(e))return y.from(document.createTextNode(e));if(!h(e))throw new TypeError(`Expected an object to wrap. Got ${e} (${typeof e})`);if(n(e,s))return e;if(n(e,HTMLElement))return u.from(e);if(n(e,SVGElement))return E.from(e);if(n(e,Element))return f.from(e);if(n(e,ShadowRoot))return g.from(e);if(n(e,DocumentFragment))return l.from(e);if(n(e,Document))return w.from(e);if(n(e,Text))return y.from(e);if(n(e,Node))return s.from(e);throw new TypeError(`Expected a Node to wrap. Got ${e} (${typeof e})`)}function N(e){if(o(e))return document.createTextNode(e);if(!h(e))throw new TypeError(`Expected an object. Got ${e} (${typeof e})`);if(n(e,Node))return e;if(n(e,s))return e.ref;throw new TypeError(`Could not unwrap ${e} (${typeof e})`)}function ce(e,t=!0){let r=document.getElementById(e);if(r)return T(r);if(t)throw new TypeError(`Found no element with id ${e} in the document.`);return null}function le(e){return D(document.getElementsByClassName(e))}function me(e,t=!0){let r=document.querySelector(e);if(r)return T(r);if(t)throw new TypeError(`Element with selector ${e} not found`);return null}function de(e){return D(document.querySelectorAll(e))}var P={byId(e,t=!0){let r=this.ref.getElementById(e);if(r)return T(r);if(t)throw new TypeError(`Element with id ${e} not found`);return null}},L={query(e,t=!0){let r=this.ref.querySelector(e);if(r)return T(r);if(t)throw new TypeError(`Element with selector ${e} not found`);return null},queryAll(e){return D(this.ref.querySelectorAll(e))},append(...e){let t=b(e);return this.ref.append(...t),this},prepend(...e){let t=b(e);return this.ref.prepend(...t),this},replaceChildren(...e){let t=b(e);return this.ref.replaceChildren(...t),this},empty(){return this.replaceChildren(),this}},C={getData(e){return this.ref.dataset[e]},hasData(e){return c(this.ref.dataset,e)},setData(e,t){return this.ref.dataset[e]=t,this},setDataObj(e){for(let[t,r]of Object.entries(e))this.setData(t,r);return this},rmData(e){return delete this.ref.dataset[e],this}};function x(e,...t){for(let r of t)Object.assign(e.prototype,r)}s.wrap=T;s.unwrap=N;x(f,L);x(w,P,L);x(l,P,L);x(u,C);x(E,C);function Te(e,t,...r){let i=u.fromTag(e).append(...r);return t&&i.setAttrs(t),i}function k(e){switch(G(e)){case"html":case"htm":case"md":return"fetch";case"css":return"style";case"js":case"mjs":case"cjs":return"script";default:throw new Error(`No 'as' attribute was specified and we failed to guess it from the URL: ${e}`)}}function j(e,t,r){if(!o(t)){if(!n(t,URL))throw new TypeError(`Expected a string or URL. Got ${t} (${typeof t})`);t=t.toString()}if(!["prefetch","preload"].includes(e))throw new RangeError(`rel should be one of 'prefetch' or 'preload'. Got ${e} (${typeof e})`);if(!r&&(r=k(t),!r))throw new Error(`No 'as' attribute was specified and we failed to guess it from the URL: ${t}`);if(!["fetch","style","script"].includes(r))throw new RangeError(`as should be one of 'fetch' or 'style'. Got ${r} (${typeof r})`);return u.fromTag("link").setAttrs({rel:e,href:t,as:r})}function xe(...e){let t=j(...e);return document.head.append(t.ref),t}async function W(e,t="text/*"){if(!o(t))throw new TypeError(`Expected a string mime like 'text/html' or 'text/css'. Got ${t} (${typeof t})`);let r=await fetch(e,{headers:{Accept:t}});if(!r.ok)throw new Error(`GET ${e} failed: ${r.status} ${r.statusText}`);return r.text()}async function Je(e){return await W(e,"text/html")}async function B(e){return await W(e,"text/css")}async function Se(e){return await $(await B(e))}async function U(e){if(m(e)){if(d(e)&&(e=await e()),e=await e,o(e))return e;if(n(e,u))return e.getHTML();if(n(e,HTMLElement))return e.outerHTML;throw new TypeError(`Expected a string, JJHE or HTMLElement. Got ${e} (${typeof e})`)}}async function q(e){if(d(e)&&(e=await e()),e=await e,n(e,CSSStyleSheet))return e;if(o(e))return await $(e);throw new TypeError(`Expected a css string or CSSStyleSheet. Got ${e} (${typeof e})`)}function V(e){return S(e)?e.map(q):[]}async function z(e,t){let[r,...i]=await Promise.all([U(e),...V(t)]);return{template:r,styles:i}}var H=class e{#t=void 0;#r=[];#e=void 0;static create(){return new e}constructor(){}setTemplate(t){return this.#t=t,this}addStyles(...t){return this.#r.push(...t),this}async getResolved(){return this.#e||(this.#e=z(this.#t,this.#r)),await this.#e}};function Ge(e,t,r,i){if(!n(e,HTMLElement))throw new TypeError(`Expected an HTMLElement or a custom element instance. Got ${e} (${typeof e})`);if(r!==i){let p=v(t);if(c(e,p))return e[p]=i,!0}return!1}async function Ie(e,t,r){if(!o(e))throw new TypeError(`Expected a string name. Got ${e} (${typeof e})`);if(!d(t))throw new TypeError(`Expected a constructor function. Got ${t} (${typeof t})`);customElements.get(e)||(customElements.define(e,t,r),await customElements.whenDefined(e))}export{w as JJD,l as JJDF,f as JJE,u as JJHE,s as JJN,E as JJSE,g as JJSR,y as JJT,H as ShadowMaster,xe as addLinkPre,Ge as attr2prop,le as byClass,ce as byId,j as createLinkPre,$ as cssToStyle,B as fetchCss,Je as fetchHtml,Se as fetchStyle,W as fetchText,G as fileExt,Te as h,v as keb2cam,Gt as keb2pas,$t as nextAnimationFrame,R as off,I as on,Lt as pas2keb,me as query,de as queryAll,Ie as registerComponent,At as sleep,N as unwrap,b as unwrapAll,T as wrap,D as wrapAll};
|
|
1
|
+
function c(e){return e!==void 0}function d(e){return typeof e=="function"}var{isNaN:M,isFinite:z,isInteger:q}=Number;function S(e){return typeof e=="number"&&!M(e)}function D(e,t,r){if(!S(e))throw new TypeError(`inRange(): "x" must be a number. Got ${e} (${typeof e})`);if(c(t)){if(!S(t))throw new TypeError(`inRange(): "min" must be a number. Got ${t} (${typeof t})`);if(c(r)){if(!S(r))throw new TypeError(`inRange(): "max" must be a number. Got ${r} (${typeof r})`);return t>r?r<=e&&e<=t:t<=e&&e<=r}return e>=t}else if(c(r)){if(!S(r))throw new TypeError(`inRange(): "max" must be a number. Got ${r} (${typeof r})`);return e<=r}throw new TypeError(`inRange(): expected at least min or max to be defined. Got min=${t} and max=${r}`)}var{isArray:H}=Array;function J(e,t=0,r){return H(e)&&D(e.length,t,r)}var{hasOwnProperty:_}=Object;function p(e){return!!e&&typeof e=="object"}function o(e,t){if(!d(t))throw new TypeError(`Expected a constructor function. Got ${t} (${typeof t})`);return e instanceof t}function h(e,...t){if(!p(e))return!1;for(let r of t)if(!(r in e))return!1;return!0}function n(e){return typeof e=="string"}var{hasOwnProperty:pt}=Object,{isArray:ut}=Array;function R(e){if(!n(e))throw new TypeError(`Expected a string file path. Got ${e} (${typeof e})`);let t=e.lastIndexOf(".");if(t===-1)return"";let r=e.slice(t+1);return r.indexOf("/")!==-1?"":r.toLowerCase().trim()}function Tt(){return new Promise(e=>requestAnimationFrame(e))}function xt(e=0){return new Promise(t=>setTimeout(t,e))}async function b(e){return await new CSSStyleSheet().replace(e)}function bt(e){if(!n(e))throw new TypeError(`Expected a string. Got ${e} (${typeof e})`);if(/[^a-zA-Z0-9_]/.test(e))throw new TypeError(`Invalid characters in string. Only alphanumeric and underscores are allowed. Got: ${e}`);return e.replace(/([a-z0-9])([A-Z])/g,"$1-$2").replace(/([A-Z])([A-Z][a-z])/g,"$1-$2").replace(/_/g,"-").toLowerCase()}function $t(e){if(!n(e))throw new TypeError(`Expected a string. Got ${e} (${typeof e})`);return e.split("-").filter(Boolean).map(t=>t.charAt(0).toUpperCase()+t.slice(1)).join("")||(e.length>0?e.charAt(0).toUpperCase()+e.slice(1):"")}function v(e){if(!n(e))throw new TypeError(`Expected a string. Got ${e} (${typeof e})`);return e.replace(/^-+|-+$/g,"").replace(/-+([a-z])/g,(t,r)=>r.toUpperCase())}var $=class e{static from(t){return new e(t)}#t;constructor(t){if(!o(t,EventTarget))throw new TypeError(`JJET expects an EventTarget instance. Got ${t} (${typeof t}). `);this.#t=t}get ref(){return this.#t}on(t,r,i){return this.ref.addEventListener(t,r,i),this}off(t,r,i){return this.ref.removeEventListener(t,r,i),this}trigger(t){return this.ref.dispatchEvent(t),this}run(t,...r){return t.call(this,...r)}};var a=class e extends ${static from(t){return new e(t)}static isWrapable(t){return n(t)||o(t,Node)||o(t,e)}static wrap(t){throw new ReferenceError("The mixin is supposed to override this method.")}static unwrap(t){if(n(t))return document.createTextNode(t);if(!p(t))throw new TypeError(`JJN.unwrap() expects a string, DOM Node, or JJ wrapper. Got ${t} (${typeof t}). `);if(o(t,Node))return t;if(o(t,e))return t.ref;throw new TypeError(`Could not unwrap ${t} (${typeof t}). Expected a string, Node, or JJ wrapper. Make sure you're passing a valid DOM element or JJ wrapper.`)}static wrapAll(t){return Array.from(t,e.wrap)}static unwrapAll(t){return Array.from(t,e.unwrap)}constructor(t){if(!o(t,Node))throw new TypeError(`JJN expects a Node instance. Got ${t} (${typeof t}). Use JJN.from(node) with a DOM Node, or check that you're passing a valid DOM element.`);super(t)}clone(t){return e.wrap(this.ref.cloneNode(t))}addText(t){return t&&this.ref.appendChild(document.createTextNode(t)),this}};var m=class extends a{query(t,r=!1){let i=this.ref.querySelector(t);if(i)return a.wrap(i);if(r)throw new TypeError(`Element with selector "${t}" not found. Did you mean to call .query("${t}", false) to return null instead? `);return null}queryAll(t){return a.wrapAll(this.ref.querySelectorAll(t))}append(...t){let r=a.unwrapAll(t.filter(a.isWrapable));return this.ref.append(...r),this}prepend(...t){let r=a.unwrapAll(t.filter(a.isWrapable));return this.ref.prepend(...r),this}mapAppend(t,r){return this.append(...t.map(r))}mapPrepend(t,r){return this.prepend(...t.map(r))}setChildren(...t){let r=a.unwrapAll(t.filter(a.isWrapable));return this.ref.replaceChildren(...r),this}empty(){return this.setChildren(),this}};function A(e,t,r){return`Expected '${e}' to be ${t}. Got ${r} (${typeof r})`}function s(e,t,r){return new TypeError(A(e,t,r))}var g=class e extends m{static from(t){return new e(t)}static create(){return new e(document.createDocumentFragment())}constructor(t){if(!o(t,DocumentFragment))throw new TypeError(`Expected a DocumentFragment. Got ${t} (${typeof t})`);super(t)}byId(t,r=!1){if(!n(t))throw s("id","a string",t);let i=this.ref.getElementById(t);if(i)return a.wrap(i);if(r)throw new TypeError(`Element with id ${t} not found`);return null}};var w=class e extends g{static from(t){return new e(t)}constructor(t){if(!o(t,ShadowRoot))throw new TypeError(`JJSR expects a ShadowRoot instance. Got ${t} (${typeof t}). Access a shadow root using element.shadowRoot after calling element.attachShadow().`);super(t)}getHTML(){return this.ref.innerHTML}setHTML(t,r){return this.ref.innerHTML=t,this}addStyleSheets(...t){return this.ref.adoptedStyleSheets.push(...t),this}};var y=class e extends m{static from(t){return new e(t)}constructor(t){if(!o(t,Element))throw new TypeError(`JJE expects an Element instance. Got ${t} (${typeof t}). Use JJE.from(element) with a DOM Element, or use the specific wrapper (JJHE for HTMLElement, JJSE for SVGElement).`);super(t)}getAttr(t){if(!n(t))throw s("name","a string",t);return this.ref.getAttribute(t)}hasAttr(t){if(!n(t))throw s("name","a string",t);return this.ref.hasAttribute(t)}setAttr(t,r){if(typeof t=="string")this.ref.setAttribute(t,r);else if(p(t))for(let[i,f]of Object.entries(t))this.ref.setAttribute(i,f);else throw s("nameOrObj","a string or object",t);return this}rmAttr(...t){for(let r of t){if(!n(r))throw s("name","a string",r);this.ref.removeAttribute(r)}return this}getAria(t){if(!n(t))throw s("name","a string",t);return this.ref.getAttribute(`aria-${t}`)}hasAria(t){if(!n(t))throw s("name","a string",t);return this.ref.hasAttribute(`aria-${t}`)}setAria(t,r){if(n(t))this.ref.setAttribute(`aria-${t}`,r);else if(p(t))for(let[i,f]of Object.entries(t))this.ref.setAttribute(`aria-${i}`,f);else throw s("nameOrObj","a string or object",t);return this}rmAria(...t){for(let r of t){if(!n(r))throw s("name","a string",r);this.ref.removeAttribute(`aria-${r}`)}return this}getClass(){return this.getAttr("class")}setClass(t){if(typeof t=="string")return this.setAttr("class",t);for(let[r,i]of Object.entries(t))i?this.ref.classList.add(r):this.ref.classList.remove(r);return this}addClass(...t){for(let r of t)if(!n(r))throw s("className","a string",r);return this.ref.classList.add(...t),this}rmClass(...t){for(let r of t)if(!n(r))throw s("className","a string",r);return this.ref.classList.remove(...t),this}hasClass(t){if(!n(t))throw s("className","a string",t);return this.ref.classList.contains(t)}toggleClass(t){if(!n(t))throw s("className","a string",t);return this.ref.classList.toggle(t),this}replaceClass(t,r){if(!n(t))throw s("oldClassName","a string",t);if(!n(r))throw s("newClassName","a string",r);return this.ref.classList.replace(t,r),this}hide(){return this.setAttr("hidden","").setAttr("aria-hidden","true")}show(){return this.rmAttr("hidden","aria-hidden")}disable(){return this.setAttr("disabled","").setAttr("aria-disabled","true")}enable(){return this.rmAttr("disabled","aria-disabled")}getHTML(){return this.ref.innerHTML}setHTML(t){return this.ref.innerHTML=t??"",this}initShadow(t="open",r){let i=this.ref.shadowRoot??this.ref.attachShadow({mode:t});if(p(r)){let{template:f,styles:l}=r;f&&(i.innerHTML=f),J(l)&&l.length&&i.adoptedStyleSheets.push(...l)}return this}get shadow(){return this.ref.shadowRoot?new w(this.ref.shadowRoot):null}};var E=class extends y{getData(t){if(!n(t))throw s("name","a string",t);return this.ref.dataset[t]}hasData(t){if(!n(t))throw s("name","a string",t);return h(this.ref.dataset,t)}setData(t,r){if(typeof t=="string")this.ref.dataset[t]=r;else if(p(t))for(let[i,f]of Object.entries(t))this.ref.dataset[i]=f;else throw s("nameOrObj","a string or object",t);return this}rmData(...t){for(let r of t){if(!n(r))throw s("name","a string",r);delete this.ref.dataset[r]}return this}};var u=class e extends E{static from(t){return new e(t)}static fromTag(t,r){if(!n(t))throw new TypeError(`JJHE.fromTag() expects tagName to be a string (e.g., 'div', 'button'). Got ${t} (${typeof t}). Did you mean to use a string literal like 'div'?`);return new e(document.createElement(t,r))}constructor(t){if(!o(t,HTMLElement))throw new TypeError(`JJHE expects an HTMLElement. Got ${t} (${typeof t}). If you have a DOM node, use JJHE.from(element). If creating a new element, use JJHE.fromTag('div').`);super(t)}getValue(){if(!h(this.ref,"value"))throw new Error(`Cannot get value from <${this.ref.tagName.toLowerCase()}>. The value property only exists on form elements (input, textarea, select). If you need text content, try .getText() instead.`);return this.ref.value}setValue(t){if(!h(this.ref,"value"))throw new Error(`Cannot set value on <${this.ref.tagName.toLowerCase()}>. The value property only exists on form elements (input, textarea, select). If you need to set text content, try .setText() instead.`);return this.ref.value=t,this}focus(){return this.ref.focus(),this}click(){return this.ref.click(),this}getText(){return this.ref.innerText}setText(t){return this.ref.innerText=t??"",this}};var x=class e extends a{static from(t){return new e(t)}static fromStr(t){return new e(document.createTextNode(t))}constructor(t){if(!o(t,Text))throw new TypeError(`JJT expects a Text node. Got ${t} (${typeof t}). Create a Text node with JJT.fromStr() or document.createTextNode('text').`);super(t)}getText(){return this.ref.textContent}setText(t){return this.ref.textContent=t??null,this}addText(t){return t!=null&&(this.ref.textContent+=t),this}empty(){return this.setText("")}};var T=class e extends m{static from(t){return new e(t)}constructor(t){if(!o(t,Document))throw new TypeError(`JJD expects a Document instance. Got ${t} (${typeof t}). `);super(t)}byId(t,r=!1){if(!n(t))throw s("id","a string",t);let i=this.ref.getElementById(t);if(i)return a.wrap(i);if(r)throw new TypeError(`Element with id "${t}" not found in the document. Did you mean to call .byId("${t}", false) to return null instead? `);return null}byClass(t){if(!n(t))throw s("className","a string",t);return a.wrapAll(this.ref.getElementsByClassName(t))}get head(){return a.wrap(this.ref.head)}get body(){return a.wrap(this.ref.body)}};var W="http://www.w3.org/2000/svg",L=class e extends E{static from(t){return new e(t)}static fromTag(t,r){if(!n(t))throw new TypeError(`JJSE.fromTag() expects tagName to be a string (e.g., 'circle', 'path'). Got ${t} (${typeof t}). Did you mean to pass a string literal like 'circle'?`);let i=document.createElementNS(W,t,r);return new e(i)}constructor(t){if(!o(t,SVGElement))throw new TypeError(`JJSE expects an SVGElement. Got ${t} (${typeof t}). Use JJSE.from(element) with an SVG element, or JJSE.fromTag('circle') to create one.`);super(t)}getText(){return this.ref.textContent??""}setText(t){return this.ref.textContent=t??"",this}empty(){return this.ref.textContent="",this}setFill(t){return this.setAttr("fill",t)}setStroke(t){return this.setAttr("stroke",t)}setStrokeWidth(t){return this.setAttr("stroke-width",String(t))}setViewBox(t,r,i,f){if(typeof t=="number"&&r!==void 0&&i!==void 0&&f!==void 0)return this.setAttr("viewBox",`${t} ${r} ${i} ${f}`);let l=t;return this.setAttr("viewBox",Array.isArray(l)?l.join(" "):l)}setWidth(t){return this.setAttr("width",String(t))}setHeight(t){return this.setAttr("height",String(t))}setD(t){return this.setAttr("d",Array.isArray(t)?t.join(" "):t)}setTransform(t){return this.setAttr("transform",t)}};a.wrap=function(t){if(n(t))return x.fromStr(t);if(!p(t))throw new TypeError(`Expected an object to wrap. Got ${t} (${typeof t})`);if(o(t,a))return t;if(o(t,HTMLElement))return u.from(t);if(o(t,SVGElement))return L.from(t);if(o(t,Element))return y.from(t);if(o(t,ShadowRoot))return w.from(t);if(o(t,DocumentFragment))return g.from(t);if(o(t,Document))return T.from(t);if(o(t,Text))return x.from(t);if(o(t,Node))return a.from(t);throw new TypeError(`Expected a Node to wrap. Got ${t} (${typeof t})`)};function Ae(e,t,...r){let i=u.fromTag(e).append(...r);return t&&i.setAttr(t),i}function N(e){switch(R(e)){case"html":case"htm":case"md":return"fetch";case"css":return"style";case"js":case"mjs":case"cjs":return"script";default:throw new Error(`No 'as' attribute was specified and we failed to guess it from the URL: ${e}`)}}function k(e,t,r){if(!n(e)){if(!o(e,URL))throw s("href","a string or URL",e);e=e.toString()}if(!["prefetch","preload"].includes(t))throw new RangeError(A("rel","'prefetch' or 'preload'",t));if(!r&&(r=N(e),!r))throw new Error(`Could not guess 'as' attribute from URL: ${e}`);if(!["fetch","style","script"].includes(r))throw new RangeError(A("as","'fetch', 'style', or 'script'",r));return u.fromTag("link").setAttr({href:e,rel:t,as:r})}function Le(...e){let t=k(...e);return document.head.append(t.ref),t}async function G(e,t="text/*"){if(!n(t))throw new TypeError(`Expected a string mime like 'text/html' or 'text/css'. Got ${t} (${typeof t})`);let r=await fetch(e,{headers:{Accept:t}});if(!r.ok)throw new Error(`GET ${e} failed: ${r.status} ${r.statusText}`);return r.text()}async function De(e){return await G(e,"text/html")}async function P(e){return await G(e,"text/css")}async function Re(e){return await b(await P(e))}async function I(e){if(c(e)){if(d(e)&&(e=await e()),e=await e,n(e))return e;if(o(e,u))return e.getHTML();if(o(e,HTMLElement))return e.outerHTML;throw new TypeError(`Expected template to be a string, JJHE, or HTMLElement. Got ${typeof e}`)}}async function O(e){if(d(e)&&(e=await e()),e=await e,o(e,CSSStyleSheet))return e;if(n(e))return await b(e);throw new TypeError(`Expected style to be a CSS string or CSSStyleSheet. Got ${typeof e}`)}function F(e){return J(e)?e.map(O):[]}async function U(e,t){let[r,...i]=await Promise.all([I(e),...F(t)]);return{template:r,styles:i}}var C=class e{#t=void 0;#r=[];#e=void 0;static create(){return new e}constructor(){}setTemplate(t){return this.#t=t,this}addStyles(...t){return this.#r.push(...t),this}async getResolved(){return this.#e||(this.#e=U(this.#t,this.#r)),await this.#e}};function Ne(e,t,r,i){if(!o(e,HTMLElement))throw new TypeError(`Expected an HTMLElement or a custom element instance. Got ${e} (${typeof e})`);if(r!==i){let f=v(t);if(h(e,f))return e[f]=i,!0}return!1}async function ke(e,t,r){if(!n(e))throw s("name","a string",e);if(!d(t))throw s("constructor","a function",t);customElements.get(e)||(customElements.define(e,t,r),await customElements.whenDefined(e))}var j=T.from(document),Fe=j;export{T as JJD,g as JJDF,y as JJE,$ as JJET,u as JJHE,a as JJN,L as JJSE,w as JJSR,x as JJT,C as ShadowMaster,Le as addLinkPre,Ne as attr2prop,k as createLinkPre,b as cssToStyle,Fe as default,P as fetchCss,De as fetchHtml,Re as fetchStyle,G as fetchText,R as fileExt,Ae as h,v as keb2cam,$t as keb2pas,Tt as nextAnimationFrame,bt as pas2keb,ke as registerComponent,xt as sleep};
|
package/lib/components.js
CHANGED
|
@@ -13,6 +13,7 @@ var _ShadowMaster_templateConfig, _ShadowMaster_stylesConfig, _ShadowMaster_norm
|
|
|
13
13
|
import { hasProp, isA, isArr, isDef, isFn, isStr } from 'jty';
|
|
14
14
|
import { JJHE } from './JJHE.js';
|
|
15
15
|
import { cssToStyle } from './util.js';
|
|
16
|
+
import { typeErr } from './internal.js';
|
|
16
17
|
import { keb2cam } from './case.js';
|
|
17
18
|
/**
|
|
18
19
|
* Resolves a template configuration into a string suitable for Shadow DOM.
|
|
@@ -41,7 +42,7 @@ async function templatePromise(templateConfig) {
|
|
|
41
42
|
if (isA(templateConfig, HTMLElement)) {
|
|
42
43
|
return templateConfig.outerHTML;
|
|
43
44
|
}
|
|
44
|
-
throw new TypeError(`Expected a string, JJHE or HTMLElement. Got ${
|
|
45
|
+
throw new TypeError(`Expected template to be a string, JJHE, or HTMLElement. Got ${typeof templateConfig}`);
|
|
45
46
|
}
|
|
46
47
|
/**
|
|
47
48
|
* Resolves a style configuration into a CSSStyleSheet.
|
|
@@ -65,7 +66,7 @@ async function stylePromise(styleConfig) {
|
|
|
65
66
|
if (isStr(styleConfig)) {
|
|
66
67
|
return await cssToStyle(styleConfig);
|
|
67
68
|
}
|
|
68
|
-
throw new TypeError(`Expected a
|
|
69
|
+
throw new TypeError(`Expected style to be a CSS string or CSSStyleSheet. Got ${typeof styleConfig}`);
|
|
69
70
|
}
|
|
70
71
|
/**
|
|
71
72
|
* Maps an array of style configurations to an array of promises resolving to CSSStyleSheets.
|
|
@@ -273,10 +274,10 @@ export function attr2prop(instance, name, oldValue, newValue) {
|
|
|
273
274
|
*/
|
|
274
275
|
export async function registerComponent(name, constructor, options) {
|
|
275
276
|
if (!isStr(name)) {
|
|
276
|
-
throw
|
|
277
|
+
throw typeErr('name', 'a string', name);
|
|
277
278
|
}
|
|
278
279
|
if (!isFn(constructor)) {
|
|
279
|
-
throw
|
|
280
|
+
throw typeErr('constructor', 'a function', constructor);
|
|
280
281
|
}
|
|
281
282
|
if (!customElements.get(name)) {
|
|
282
283
|
customElements.define(name, constructor, options);
|
package/lib/components.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"components.js","sourceRoot":"","sources":["../src/components.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,OAAO,EAAE,OAAO,EAAE,GAAG,EAAE,KAAK,EAAE,KAAK,EAAE,IAAI,EAAE,KAAK,EAAE,MAAM,KAAK,CAAA;AAE7D,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAA;AAChC,OAAO,EAAE,UAAU,EAAE,MAAM,WAAW,CAAA;AACtC,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAA;AAEnC;;;;;;;;;GASG;AACH,KAAK,UAAU,eAAe,CAAC,cAAiC;IAC5D,IAAI,CAAC,KAAK,CAAC,cAAc,CAAC,EAAE,CAAC;QACzB,OAAO,SAAS,CAAA;IACpB,CAAC;IAED,IAAI,IAAI,CAAC,cAAc,CAAC,EAAE,CAAC;QACvB,cAAc,GAAG,MAAM,cAAc,EAAE,CAAA;IAC3C,CAAC;IAED,cAAc,GAAG,MAAM,cAAc,CAAA;IAErC,IAAI,KAAK,CAAC,cAAc,CAAC,EAAE,CAAC;QACxB,OAAO,cAAc,CAA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,CAAC;IACD,OAAO,KAAK,CAAA;AAChB,CAAC;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4BG;AACH,MAAM,CAAC,KAAK,UAAU,iBAAiB,CACnC,IAAY,EACZ,WAAqC,EACrC,OAAkC;IAElC,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,EAAE,CAAC;QACf,MAAM,OAAO,CAAC,MAAM,EAAE,UAAU,EAAE,IAAI,CAAC,CAAA;IAC3C,CAAC;IACD,IAAI,CAAC,IAAI,CAAC,WAAW,CAAC,EAAE,CAAC;QACrB,MAAM,OAAO,CAAC,aAAa,EAAE,YAAY,EAAE,WAAW,CAAC,CAAA;IAC3D,CAAC;IACD,IAAI,CAAC,cAAc,CAAC,GAAG,CAAC,IAAI,CAAC,EAAE,CAAC;QAC5B,cAAc,CAAC,MAAM,CAAC,IAAI,EAAE,WAAW,EAAE,OAAO,CAAC,CAAA;QACjD,MAAM,cAAc,CAAC,WAAW,CAAC,IAAI,CAAC,CAAA;IAC1C,CAAC;AACL,CAAC"}
|
package/lib/helpers.d.ts
CHANGED
|
@@ -44,8 +44,8 @@ export declare function h(tagName: string, attributes?: Record<string, string> |
|
|
|
44
44
|
* This function validates the input arguments and returns a wrapped `JJHE` instance.
|
|
45
45
|
* It does not append the element to the document.
|
|
46
46
|
*
|
|
47
|
-
* @param rel - The relationship of the linked resource ('prefetch' or 'preload').
|
|
48
47
|
* @param href - The URL of the resource.
|
|
48
|
+
* @param rel - The relationship of the linked resource ('prefetch' or 'preload').
|
|
49
49
|
* @param as - The type of content being loaded ('fetch' for HTML, 'style' for CSS, or 'script' for JavaScript files).
|
|
50
50
|
* If it's not provided or set to a falsy value, it runs heuristics to find the best match from the href parameter.
|
|
51
51
|
*
|
|
@@ -55,7 +55,7 @@ export declare function h(tagName: string, attributes?: Record<string, string> |
|
|
|
55
55
|
* @see {@link https://developer.mozilla.org/en-US/docs/Web/HTML/Attributes/rel/preload | Link types: preload}
|
|
56
56
|
* @see {@link https://developer.mozilla.org/en-US/docs/Web/HTML/Attributes/rel/prefetch | Link types: prefetch}
|
|
57
57
|
*/
|
|
58
|
-
export declare function createLinkPre(rel: 'prefetch' | 'preload',
|
|
58
|
+
export declare function createLinkPre(href: string | URL, rel: 'prefetch' | 'preload', as?: 'fetch' | 'style' | 'script'): JJHE;
|
|
59
59
|
/**
|
|
60
60
|
* Adds a `<link>` tag to the document head for prefetching or preloading resources.
|
|
61
61
|
*
|
|
@@ -74,6 +74,7 @@ export declare function createLinkPre(rel: 'prefetch' | 'preload', href: string
|
|
|
74
74
|
* addLinkPre('/next-page.css', 'prefetch', 'style')
|
|
75
75
|
* ```
|
|
76
76
|
*
|
|
77
|
+
* @param args - The arguments to be passed to {@link createLinkPre}.
|
|
77
78
|
* @returns The JJHE instance representing the link element.
|
|
78
79
|
* @throws {TypeError} If `href` is not a string or URL.
|
|
79
80
|
* @throws {RangeError} If `rel` or `as` are not valid values.
|
package/lib/helpers.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { isA, isStr } from 'jty';
|
|
2
2
|
import { JJHE } from './JJHE.js';
|
|
3
3
|
import { cssToStyle, fileExt } from './util.js';
|
|
4
|
+
import { typeErr, errMsg } from './internal.js';
|
|
4
5
|
/**
|
|
5
6
|
* Hyperscript helper to create JJHE instances.
|
|
6
7
|
* The `h` function provides a concise way to create DOM wrappers with attributes and children,
|
|
@@ -40,7 +41,7 @@ import { cssToStyle, fileExt } from './util.js';
|
|
|
40
41
|
export function h(tagName, attributes, ...children) {
|
|
41
42
|
const ret = JJHE.fromTag(tagName).append(...children);
|
|
42
43
|
if (attributes) {
|
|
43
|
-
ret.
|
|
44
|
+
ret.setAttr(attributes);
|
|
44
45
|
}
|
|
45
46
|
return ret;
|
|
46
47
|
}
|
|
@@ -73,8 +74,8 @@ function linkAs(href) {
|
|
|
73
74
|
* This function validates the input arguments and returns a wrapped `JJHE` instance.
|
|
74
75
|
* It does not append the element to the document.
|
|
75
76
|
*
|
|
76
|
-
* @param rel - The relationship of the linked resource ('prefetch' or 'preload').
|
|
77
77
|
* @param href - The URL of the resource.
|
|
78
|
+
* @param rel - The relationship of the linked resource ('prefetch' or 'preload').
|
|
78
79
|
* @param as - The type of content being loaded ('fetch' for HTML, 'style' for CSS, or 'script' for JavaScript files).
|
|
79
80
|
* If it's not provided or set to a falsy value, it runs heuristics to find the best match from the href parameter.
|
|
80
81
|
*
|
|
@@ -84,28 +85,28 @@ function linkAs(href) {
|
|
|
84
85
|
* @see {@link https://developer.mozilla.org/en-US/docs/Web/HTML/Attributes/rel/preload | Link types: preload}
|
|
85
86
|
* @see {@link https://developer.mozilla.org/en-US/docs/Web/HTML/Attributes/rel/prefetch | Link types: prefetch}
|
|
86
87
|
*/
|
|
87
|
-
export function createLinkPre(
|
|
88
|
+
export function createLinkPre(href, rel, as) {
|
|
88
89
|
if (!isStr(href)) {
|
|
89
90
|
if (!isA(href, URL)) {
|
|
90
|
-
throw
|
|
91
|
+
throw typeErr('href', 'a string or URL', href);
|
|
91
92
|
}
|
|
92
93
|
href = href.toString();
|
|
93
94
|
}
|
|
94
95
|
if (!['prefetch', 'preload'].includes(rel)) {
|
|
95
|
-
throw new RangeError(
|
|
96
|
+
throw new RangeError(errMsg('rel', `'prefetch' or 'preload'`, rel));
|
|
96
97
|
}
|
|
97
98
|
if (!as) {
|
|
98
99
|
as = linkAs(href);
|
|
99
100
|
if (!as) {
|
|
100
|
-
throw new Error(`
|
|
101
|
+
throw new Error(`Could not guess 'as' attribute from URL: ${href}`);
|
|
101
102
|
}
|
|
102
103
|
}
|
|
103
104
|
if (!['fetch', 'style', 'script'].includes(as)) {
|
|
104
|
-
throw new RangeError(
|
|
105
|
+
throw new RangeError(errMsg('as', `'fetch', 'style', or 'script'`, as));
|
|
105
106
|
}
|
|
106
|
-
return JJHE.fromTag('link').
|
|
107
|
-
rel,
|
|
107
|
+
return JJHE.fromTag('link').setAttr({
|
|
108
108
|
href,
|
|
109
|
+
rel,
|
|
109
110
|
as,
|
|
110
111
|
});
|
|
111
112
|
}
|
|
@@ -127,6 +128,7 @@ export function createLinkPre(rel, href, as) {
|
|
|
127
128
|
* addLinkPre('/next-page.css', 'prefetch', 'style')
|
|
128
129
|
* ```
|
|
129
130
|
*
|
|
131
|
+
* @param args - The arguments to be passed to {@link createLinkPre}.
|
|
130
132
|
* @returns The JJHE instance representing the link element.
|
|
131
133
|
* @throws {TypeError} If `href` is not a string or URL.
|
|
132
134
|
* @throws {RangeError} If `rel` or `as` are not valid values.
|
package/lib/helpers.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"helpers.js","sourceRoot":"","sources":["../src/helpers.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,GAAG,EAAE,KAAK,EAAE,MAAM,KAAK,CAAA;AAChC,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAA;AAEhC,OAAO,EAAE,UAAU,EAAE,OAAO,EAAE,MAAM,WAAW,CAAA;AAE/C;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAmCG;AACH,MAAM,UAAU,CAAC,CAAC,OAAe,EAAE,UAA0C,EAAE,GAAG,QAAqB;IACnG,MAAM,GAAG,GAAG,IAAI,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC,MAAM,CAAC,GAAG,QAAQ,CAAC,CAAA;IACrD,IAAI,UAAU,EAAE,CAAC;QACb,GAAG,CAAC,
|
|
1
|
+
{"version":3,"file":"helpers.js","sourceRoot":"","sources":["../src/helpers.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,GAAG,EAAE,KAAK,EAAE,MAAM,KAAK,CAAA;AAChC,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAA;AAEhC,OAAO,EAAE,UAAU,EAAE,OAAO,EAAE,MAAM,WAAW,CAAA;AAC/C,OAAO,EAAE,OAAO,EAAE,MAAM,EAAE,MAAM,eAAe,CAAA;AAE/C;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA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QACf,MAAM,IAAI,KAAK,CAAC,OAAO,GAAG,YAAY,QAAQ,CAAC,MAAM,IAAI,QAAQ,CAAC,UAAU,EAAE,CAAC,CAAA;IACnF,CAAC;IACD,OAAO,QAAQ,CAAC,IAAI,EAAE,CAAA;AAC1B,CAAC;AAED;;;;;;;;;;;;;;;;GAgBG;AACH,MAAM,CAAC,KAAK,UAAU,SAAS,CAAC,GAAiB;IAC7C,OAAO,MAAM,SAAS,CAAC,GAAG,EAAE,WAAW,CAAC,CAAA;AAC5C,CAAC;AAED;;;;;;;;;;;;;;GAcG;AACH,MAAM,CAAC,KAAK,UAAU,QAAQ,CAAC,GAAiB;IAC5C,OAAO,MAAM,SAAS,CAAC,GAAG,EAAE,UAAU,CAAC,CAAA;AAC3C,CAAC;AAED;;;;;;;;;;;;;;;;;GAiBG;AACH,MAAM,CAAC,KAAK,UAAU,UAAU,CAAC,GAAiB;IAC9C,OAAO,MAAM,UAAU,CAAC,MAAM,QAAQ,CAAC,GAAG,CAAC,CAAC,CAAA;AAChD,CAAC"}
|
package/lib/index.d.ts
CHANGED
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
export * from './types.js';
|
|
2
2
|
export * from './util.js';
|
|
3
3
|
export * from './case.js';
|
|
4
|
+
export * from './JJET.js';
|
|
4
5
|
export * from './JJN.js';
|
|
6
|
+
import './JJN-wrap.js';
|
|
5
7
|
export * from './JJT.js';
|
|
6
8
|
export * from './JJE.js';
|
|
7
9
|
export * from './JJHE.js';
|
|
@@ -9,7 +11,23 @@ export * from './JJSE.js';
|
|
|
9
11
|
export * from './JJD.js';
|
|
10
12
|
export * from './JJDF.js';
|
|
11
13
|
export * from './JJSR.js';
|
|
12
|
-
import './mixins.js';
|
|
13
14
|
export * from './helpers.js';
|
|
14
|
-
export * from './mixins.js';
|
|
15
15
|
export * from './components.js';
|
|
16
|
+
import { JJD } from './JJD.js';
|
|
17
|
+
/**
|
|
18
|
+
* A wrapped document for convenience.
|
|
19
|
+
* It can be used instead of document
|
|
20
|
+
*
|
|
21
|
+
* @example
|
|
22
|
+
* ```ts
|
|
23
|
+
* const el = doc.byId('my-element') // A JJHE instance
|
|
24
|
+
* const body = doc.body // A JJHE instance
|
|
25
|
+
* doc.append(JJHE.fromTag('script').setAttr('src', 'my-code.js'))
|
|
26
|
+
* doc.head.append(JJHE.fromTag('link').setAttr({
|
|
27
|
+
* rel: 'stylesheet',
|
|
28
|
+
* href: 'code.css'
|
|
29
|
+
* }))
|
|
30
|
+
* ```
|
|
31
|
+
*/
|
|
32
|
+
declare const doc: JJD<Document>;
|
|
33
|
+
export default doc;
|
package/lib/index.js
CHANGED
|
@@ -1,7 +1,10 @@
|
|
|
1
1
|
export * from './types.js';
|
|
2
2
|
export * from './util.js';
|
|
3
3
|
export * from './case.js';
|
|
4
|
+
export * from './JJET.js';
|
|
4
5
|
export * from './JJN.js';
|
|
6
|
+
// Monkey patch the wrap() method which requires all the other JJ classes
|
|
7
|
+
import './JJN-wrap.js';
|
|
5
8
|
export * from './JJT.js';
|
|
6
9
|
export * from './JJE.js';
|
|
7
10
|
export * from './JJHE.js';
|
|
@@ -9,8 +12,24 @@ export * from './JJSE.js';
|
|
|
9
12
|
export * from './JJD.js';
|
|
10
13
|
export * from './JJDF.js';
|
|
11
14
|
export * from './JJSR.js';
|
|
12
|
-
import './mixins.js';
|
|
13
15
|
export * from './helpers.js';
|
|
14
|
-
export * from './mixins.js';
|
|
15
16
|
export * from './components.js';
|
|
17
|
+
import { JJD } from './JJD.js';
|
|
18
|
+
/**
|
|
19
|
+
* A wrapped document for convenience.
|
|
20
|
+
* It can be used instead of document
|
|
21
|
+
*
|
|
22
|
+
* @example
|
|
23
|
+
* ```ts
|
|
24
|
+
* const el = doc.byId('my-element') // A JJHE instance
|
|
25
|
+
* const body = doc.body // A JJHE instance
|
|
26
|
+
* doc.append(JJHE.fromTag('script').setAttr('src', 'my-code.js'))
|
|
27
|
+
* doc.head.append(JJHE.fromTag('link').setAttr({
|
|
28
|
+
* rel: 'stylesheet',
|
|
29
|
+
* href: 'code.css'
|
|
30
|
+
* }))
|
|
31
|
+
* ```
|
|
32
|
+
*/
|
|
33
|
+
const doc = JJD.from(document);
|
|
34
|
+
export default doc;
|
|
16
35
|
//# sourceMappingURL=index.js.map
|
package/lib/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,YAAY,CAAA;AAC1B,cAAc,WAAW,CAAA;AACzB,cAAc,WAAW,CAAA;AACzB,cAAc,UAAU,CAAA;AACxB,cAAc,UAAU,CAAA;AACxB,cAAc,UAAU,CAAA;AACxB,cAAc,WAAW,CAAA;AACzB,cAAc,WAAW,CAAA;AACzB,cAAc,UAAU,CAAA;AACxB,cAAc,WAAW,CAAA;AACzB,cAAc,WAAW,CAAA;AACzB,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,YAAY,CAAA;AAC1B,cAAc,WAAW,CAAA;AACzB,cAAc,WAAW,CAAA;AACzB,cAAc,WAAW,CAAA;AACzB,cAAc,UAAU,CAAA;AACxB,yEAAyE;AACzE,OAAO,eAAe,CAAA;AACtB,cAAc,UAAU,CAAA;AACxB,cAAc,UAAU,CAAA;AACxB,cAAc,WAAW,CAAA;AACzB,cAAc,WAAW,CAAA;AACzB,cAAc,UAAU,CAAA;AACxB,cAAc,WAAW,CAAA;AACzB,cAAc,WAAW,CAAA;AACzB,cAAc,cAAc,CAAA;AAC5B,cAAc,iBAAiB,CAAA;AAE/B,OAAO,EAAE,GAAG,EAAE,MAAM,UAAU,CAAA;AAE9B;;;;;;;;;;;;;;GAcG;AACH,MAAM,GAAG,GAAG,GAAG,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAA;AAC9B,eAAe,GAAG,CAAA"}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Internal utilities for the JJ library.
|
|
3
|
+
* These are not part of the public API.
|
|
4
|
+
*/
|
|
5
|
+
/**
|
|
6
|
+
* Creates a gzip-friendly error message by concatenating strings.
|
|
7
|
+
* This avoids repeating common error message patterns that compress well.
|
|
8
|
+
*
|
|
9
|
+
* @remarks
|
|
10
|
+
* Uses backtick strings to take advantage of gzip compression across the codebase.
|
|
11
|
+
* Common patterns like `Expected 'x' to be ...` compress very efficiently.
|
|
12
|
+
*
|
|
13
|
+
* @internal
|
|
14
|
+
* @param varName - The name of the variable
|
|
15
|
+
* @param expected - Description of expected type
|
|
16
|
+
* @param received - The actual value received
|
|
17
|
+
* @returns Error message string
|
|
18
|
+
*/
|
|
19
|
+
export declare function errMsg(varName: string, expected: string, received: unknown): string;
|
|
20
|
+
/**
|
|
21
|
+
* Creates a TypeError with a standardized error message.
|
|
22
|
+
* Convenience wrapper around errMsg for type errors.
|
|
23
|
+
*
|
|
24
|
+
* @internal
|
|
25
|
+
* @param varName - The name of the variable
|
|
26
|
+
* @param expected - Description of expected type
|
|
27
|
+
* @param received - The actual value received
|
|
28
|
+
* @returns A TypeError ready to be thrown
|
|
29
|
+
*/
|
|
30
|
+
export declare function typeErr(varName: string, expected: string, received: unknown): TypeError;
|
package/lib/internal.js
ADDED
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Internal utilities for the JJ library.
|
|
3
|
+
* These are not part of the public API.
|
|
4
|
+
*/
|
|
5
|
+
/**
|
|
6
|
+
* Creates a gzip-friendly error message by concatenating strings.
|
|
7
|
+
* This avoids repeating common error message patterns that compress well.
|
|
8
|
+
*
|
|
9
|
+
* @remarks
|
|
10
|
+
* Uses backtick strings to take advantage of gzip compression across the codebase.
|
|
11
|
+
* Common patterns like `Expected 'x' to be ...` compress very efficiently.
|
|
12
|
+
*
|
|
13
|
+
* @internal
|
|
14
|
+
* @param varName - The name of the variable
|
|
15
|
+
* @param expected - Description of expected type
|
|
16
|
+
* @param received - The actual value received
|
|
17
|
+
* @returns Error message string
|
|
18
|
+
*/
|
|
19
|
+
export function errMsg(varName, expected, received) {
|
|
20
|
+
return `Expected '${varName}' to be ${expected}. Got ${received} (${typeof received})`;
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* Creates a TypeError with a standardized error message.
|
|
24
|
+
* Convenience wrapper around errMsg for type errors.
|
|
25
|
+
*
|
|
26
|
+
* @internal
|
|
27
|
+
* @param varName - The name of the variable
|
|
28
|
+
* @param expected - Description of expected type
|
|
29
|
+
* @param received - The actual value received
|
|
30
|
+
* @returns A TypeError ready to be thrown
|
|
31
|
+
*/
|
|
32
|
+
export function typeErr(varName, expected, received) {
|
|
33
|
+
return new TypeError(errMsg(varName, expected, received));
|
|
34
|
+
}
|
|
35
|
+
//# sourceMappingURL=internal.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"internal.js","sourceRoot":"","sources":["../src/internal.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH;;;;;;;;;;;;;GAaG;AACH,MAAM,UAAU,MAAM,CAAC,OAAe,EAAE,QAAgB,EAAE,QAAiB;IACvE,OAAO,aAAa,OAAO,WAAW,QAAQ,SAAS,QAAQ,KAAK,OAAO,QAAQ,GAAG,CAAA;AAC1F,CAAC;AAED;;;;;;;;;GASG;AACH,MAAM,UAAU,OAAO,CAAC,OAAe,EAAE,QAAgB,EAAE,QAAiB;IACxE,OAAO,IAAI,SAAS,CAAC,MAAM,CAAC,OAAO,EAAE,QAAQ,EAAE,QAAQ,CAAC,CAAC,CAAA;AAC7D,CAAC"}
|
package/lib/types.d.ts
CHANGED
|
@@ -21,50 +21,38 @@ export type Wrapped = JJN | JJT | JJE | JJHE | JJSE | JJD | JJDF | JJSR;
|
|
|
21
21
|
* @see {@link https://developer.mozilla.org/en-US/docs/Web/API/Node | Node}
|
|
22
22
|
*/
|
|
23
23
|
export type Unwrapped = Node | Text | Element | HTMLElement | SVGElement | Document | DocumentFragment | ShadowRoot;
|
|
24
|
-
/**
|
|
25
|
-
* Represents a resource that can be a direct value, a Promise, or a function returning either.
|
|
26
|
-
* Used for lazy loading or dynamic generation.
|
|
27
|
-
*
|
|
28
|
-
* @example
|
|
29
|
-
* ```ts
|
|
30
|
-
* type MyConfig = JJResource<string>
|
|
31
|
-
* const c1: MyConfig = 'value'
|
|
32
|
-
* const c2: MyConfig = Promise.resolve('value')
|
|
33
|
-
* const c3: MyConfig = () => 'value'
|
|
34
|
-
* const c4: MyConfig = async () => 'value'
|
|
35
|
-
* ```
|
|
36
|
-
*/
|
|
37
|
-
export type JJResource<T> = T | Promise<T> | (() => T | Promise<T>);
|
|
38
24
|
/**
|
|
39
25
|
* Configuration for the component's template.
|
|
40
|
-
* Can be an HTML string, a JJHE instance,
|
|
26
|
+
* Can be an HTML string, a JJHE instance, a raw HTMLElement, or a
|
|
27
|
+
* Promise / factory that yields one of those.
|
|
41
28
|
*
|
|
29
|
+
* @see {@link https://developer.mozilla.org/en-US/docs/Web/API/Element/innerHTML | Element.innerHTML}
|
|
42
30
|
* @example
|
|
43
31
|
* ```ts
|
|
44
|
-
* const t1:
|
|
45
|
-
* const t2:
|
|
32
|
+
* const t1: tmplConf = '<div>Hello</div>'
|
|
33
|
+
* const t2: tmplConf = fetchHtml('./template.html') // Lazy loading
|
|
34
|
+
* const t3: tmplConf = () => fetchHtml('./template.html') // Lazy loading
|
|
35
|
+
* const t4: tmplConf = new JJHE(document.createElement('div')) // JJHE instance
|
|
36
|
+
* const t5: tmplConf = document.createElement('div') // Raw HTMLElement
|
|
37
|
+
* const t6: tmplConf = await fetchHtml('./template.html') // Eager loading
|
|
46
38
|
* ```
|
|
47
|
-
*
|
|
48
|
-
* @see {@link https://developer.mozilla.org/en-US/docs/Web/API/Element/innerHTML | Element.innerHTML}
|
|
49
39
|
*/
|
|
50
|
-
export type JJTemplateConfig =
|
|
40
|
+
export type JJTemplateConfig = string | JJHE | HTMLElement | Promise<string | JJHE | HTMLElement> | (() => string | JJHE | HTMLElement | Promise<string | JJHE | HTMLElement>);
|
|
51
41
|
/**
|
|
52
42
|
* Configuration for the component's styles.
|
|
53
|
-
* Can be a CSS string or a
|
|
43
|
+
* Can be a CSS string, a CSSStyleSheet, or a Promise / factory that yields one of those.
|
|
54
44
|
*
|
|
45
|
+
* @see {@link https://developer.mozilla.org/en-US/docs/Web/API/CSSStyleSheet | CSSStyleSheet}
|
|
55
46
|
* @example
|
|
56
47
|
* ```ts
|
|
57
|
-
* const s1: JJStyleConfig = 'p { color: red; }'
|
|
58
|
-
* const s2: JJStyleConfig =
|
|
48
|
+
* const s1: JJStyleConfig = 'p { color: red; }' // simple string
|
|
49
|
+
* const s2: JJStyleConfig = cssToSheet('p { color: red; }') // Parse string to CSSStyleSheet
|
|
50
|
+
* const s3: JJStyleConfig = await fetchCss('./style.css') // Eager loading
|
|
51
|
+
* const s4: JJStyleConfig = fetchCss('./style.css') // Lazy loading
|
|
52
|
+
* const s5: JJStyleConfig = () => fetchCss('./style.css') // Lazy loading
|
|
59
53
|
* ```
|
|
60
|
-
*
|
|
61
|
-
* @see {@link https://developer.mozilla.org/en-US/docs/Web/API/CSSStyleSheet | CSSStyleSheet}
|
|
62
|
-
*/
|
|
63
|
-
export type JJStyleConfig = JJResource<string | CSSStyleSheet>;
|
|
64
|
-
/**
|
|
65
|
-
* Configuration for one or more style resources.
|
|
66
54
|
*/
|
|
67
|
-
export type
|
|
55
|
+
export type JJStyleConfig = string | CSSStyleSheet | Promise<string | CSSStyleSheet> | (() => string | CSSStyleSheet | Promise<string | CSSStyleSheet>);
|
|
68
56
|
/**
|
|
69
57
|
* Configuration for initializing a shadowRoot
|
|
70
58
|
* @see {@link https://developer.mozilla.org/en-US/docs/Web/API/ShadowRoot/adoptedStyleSheets | ShadowRoot.adoptedStyleSheets}
|
package/lib/util.d.ts
CHANGED
|
@@ -49,34 +49,6 @@ export declare function nextAnimationFrame(): Promise<number>;
|
|
|
49
49
|
* @see {@link https://developer.mozilla.org/en-US/docs/Web/API/setTimeout | setTimeout}
|
|
50
50
|
*/
|
|
51
51
|
export declare function sleep(ms?: number): Promise<void>;
|
|
52
|
-
/**
|
|
53
|
-
* Adds an event listener to a target.
|
|
54
|
-
*
|
|
55
|
-
* @example
|
|
56
|
-
* ```ts
|
|
57
|
-
* on(window, 'resize', () => console.log('resized'))
|
|
58
|
-
* ```
|
|
59
|
-
*
|
|
60
|
-
* @param target - The event target.
|
|
61
|
-
* @param eventName - The name of the event.
|
|
62
|
-
* @param handler - The event handler.
|
|
63
|
-
* @see {@link https://developer.mozilla.org/en-US/docs/Web/API/EventTarget/addEventListener | EventTarget.addEventListener}
|
|
64
|
-
*/
|
|
65
|
-
export declare function on(target: EventTarget, eventName: string, handler: EventListenerOrEventListenerObject): void;
|
|
66
|
-
/**
|
|
67
|
-
* Removes an event listener from a target.
|
|
68
|
-
*
|
|
69
|
-
* @example
|
|
70
|
-
* ```ts
|
|
71
|
-
* off(window, 'resize', handler)
|
|
72
|
-
* ```
|
|
73
|
-
*
|
|
74
|
-
* @param target - The event target.
|
|
75
|
-
* @param eventName - The name of the event.
|
|
76
|
-
* @param handler - The event handler.
|
|
77
|
-
* @see {@link https://developer.mozilla.org/en-US/docs/Web/API/EventTarget/removeEventListener | EventTarget.removeEventListener}
|
|
78
|
-
*/
|
|
79
|
-
export declare function off(target: EventTarget, eventName: string, handler: EventListenerOrEventListenerObject): void;
|
|
80
52
|
/**
|
|
81
53
|
* Converts a CSS string to a CSSStyleSheet.
|
|
82
54
|
*
|
package/lib/util.js
CHANGED
|
@@ -67,38 +67,6 @@ export function nextAnimationFrame() {
|
|
|
67
67
|
export function sleep(ms = 0) {
|
|
68
68
|
return new Promise((resolve) => setTimeout(resolve, ms));
|
|
69
69
|
}
|
|
70
|
-
/**
|
|
71
|
-
* Adds an event listener to a target.
|
|
72
|
-
*
|
|
73
|
-
* @example
|
|
74
|
-
* ```ts
|
|
75
|
-
* on(window, 'resize', () => console.log('resized'))
|
|
76
|
-
* ```
|
|
77
|
-
*
|
|
78
|
-
* @param target - The event target.
|
|
79
|
-
* @param eventName - The name of the event.
|
|
80
|
-
* @param handler - The event handler.
|
|
81
|
-
* @see {@link https://developer.mozilla.org/en-US/docs/Web/API/EventTarget/addEventListener | EventTarget.addEventListener}
|
|
82
|
-
*/
|
|
83
|
-
export function on(target, eventName, handler) {
|
|
84
|
-
target.addEventListener(eventName, handler);
|
|
85
|
-
}
|
|
86
|
-
/**
|
|
87
|
-
* Removes an event listener from a target.
|
|
88
|
-
*
|
|
89
|
-
* @example
|
|
90
|
-
* ```ts
|
|
91
|
-
* off(window, 'resize', handler)
|
|
92
|
-
* ```
|
|
93
|
-
*
|
|
94
|
-
* @param target - The event target.
|
|
95
|
-
* @param eventName - The name of the event.
|
|
96
|
-
* @param handler - The event handler.
|
|
97
|
-
* @see {@link https://developer.mozilla.org/en-US/docs/Web/API/EventTarget/removeEventListener | EventTarget.removeEventListener}
|
|
98
|
-
*/
|
|
99
|
-
export function off(target, eventName, handler) {
|
|
100
|
-
target.removeEventListener(eventName, handler);
|
|
101
|
-
}
|
|
102
70
|
/**
|
|
103
71
|
* Converts a CSS string to a CSSStyleSheet.
|
|
104
72
|
*
|
package/lib/util.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"util.js","sourceRoot":"","sources":["../src/util.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,KAAK,CAAA;AAE3B;;;;;;;;;;;;;;;;GAgBG;AACH,MAAM,UAAU,OAAO,CAAC,IAAY;IAChC,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,EAAE,CAAC;QACf,MAAM,IAAI,SAAS,CAAC,oCAAoC,IAAI,KAAK,OAAO,IAAI,GAAG,CAAC,CAAA;IACpF,CAAC;IACD,MAAM,YAAY,GAAG,IAAI,CAAC,WAAW,CAAC,GAAG,CAAC,CAAA;IAC1C,IAAI,YAAY,KAAK,CAAC,CAAC,EAAE,CAAC;QACtB,OAAO,EAAE,CAAA;IAC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