situs-kit 0.1.5 → 0.1.7
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 +1 -1
- package/dist/chunk-nfvb3yjq.js +2 -0
- package/dist/index.js +1 -1
- package/dist/split-text/index.d.ts +6 -2
- package/dist/split-text/index.js +1 -1
- package/package.json +1 -1
- package/dist/chunk-fqr7g8fv.js +0 -2
package/README.md
CHANGED
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
function C(q,z){return typeof globalThis.getComputedStyle==="function"?globalThis.getComputedStyle(q,z??null):null}var B=1,v=2,y=4,I="inline-block",h="nowrap",g="baseline",L="0px",f="block",E="maskChar",m="maskWord",n="maskLine",s=/^\s+$/,d=/(\s+)/,o=",div,span,svg,img,br,hr,canvas,video,audio,iframe,input,textarea,select,button,picture,figure,",p={u:"underline",ins:"underline",s:"line-through",strike:"line-through",del:"line-through"};class a{dom;chars;words;lines;masks;_n;_k;_g;_j;_f=[];_o=new Map;_i=null;_h=0;_l=!1;_c="";_d;_e;_b;_a=null;constructor(q,z={}){if(Array.isArray(q)){if(q.length===0)throw Error("SplitText: empty element array");this._a=q.map(($)=>new a($,z)),this.dom=q,this.chars=this._a.flatMap(($)=>$.chars),this.words=this._a.flatMap(($)=>$.words),this.lines=this._a.flatMap(($)=>$.lines),this.masks={chars:this._a.flatMap(($)=>$.masks.chars),words:this._a.flatMap(($)=>$.masks.words),lines:this._a.flatMap(($)=>$.masks.lines)},this._n="",this._k=0,this._g=0,this._j="";return}let F=typeof q==="string"?document.querySelector(q):q;if(!F)throw Error("SplitText: element not found");this._b=F,this.dom=F,this._n=F.innerHTML,this.chars=[],this.words=[],this.lines=[],this.masks={chars:[],words:[],lines:[]};let Q=z.type?Array.isArray(z.type)?z.type:[z.type]:["chars","words","lines"],V=0;for(let $ of Q)if($==="chars")V|=B;else if($==="words")V|=v;else if($==="lines")V|=y;this._k=V,this._j=z.tag??"span";let U=0;if(z.mask===!0)U=V;else if(Array.isArray(z.mask)){for(let $ of z.mask)if($==="chars")U|=B;else if($==="words")U|=v;else if($==="lines")U|=y}if(this._g=U,this._d=z.style,this._e=z.class,this._w(),(z.resize??!0)&&V&y)this._x()}_p(q,z){let F=document.createElement(this._j);if(q)F.dataset[q]="";if(F.style.display=I,z!==void 0)F.textContent=z;return F}_s(q,z){let F=document.createElement(this._j);if(F.dataset[z]="",F.style.overflow="hidden",F.style.display=q,this._d?.mask)Object.assign(F.style,this._d.mask);if(this._e?.mask)F.classList.add(this._e.mask);return F}_r(q,z,F,Q,V){if(this._g&z){let U=this._s(F,Q);return U.appendChild(q),V.push(U),U}return q}_m(q,z,F,Q){if(F){let{outer:V,inner:U}=F();if(U.appendChild(z),Q)this._o.set(Q,V);q.appendChild(V)}else q.appendChild(z)}_q(q,z,F){if(q.style.textDecoration=z,F)q.style.textDecorationColor=F}_w(){this._l=!0;let q=this._b,z=C(q),F=z?parseFloat(z.letterSpacing)||0:0;if(this._c=z?z.textIndent:"",this._c&&this._c!==L)q.style.textIndent="0";let Q=this._k,V=!!(Q&B),U=!!(Q&v),$=!!(Q&y),P=U||$,D=!!(this._g&B),T=new Map,G=(N)=>{for(let j of Array.from(N.childNodes))if(j.nodeType===1){let R=j.tagName.toLowerCase();if(p[R]){let O=C(j)?.textDecorationColor;if(O)T.set(j,O)}G(j)}};G(q);let X=Array.from(q.childNodes),M=document.createDocumentFragment();q.replaceChildren();let k=(N,j,R,O)=>{if(N.nodeType===3){let u=(N.textContent??"").split(d);for(let H of u){if(!H)continue;if(s.test(H)){M.appendChild(document.createTextNode(H));continue}let J=P?this._p(U?"word":""):null;if(J){if(J.style.whiteSpace=h,R&&!V)this._q(J,R,O)}if(V){let Y=[...H],w=this.chars.length;for(let Z=0;Z<Y.length;Z++){let b=this._p("char",Y[Z]);if(F&&Z<Y.length-1)b.style.marginRight=`${F}px`;if(R)this._q(b,R,O);if(this.chars.push(b),this._d?.chars)Object.assign(b.style,this._d.chars);if(this._e?.chars)b.classList.add(this._e.chars);let S=D?this._r(b,B,I,E,this.masks.chars):b;if(J)J.appendChild(S)}if(!J){let Z=j?j():null,b=Z?Z.inner:M;for(let S=w;S<this.chars.length;S++){let _=this.chars[S];b.appendChild(D&&_.parentElement?.dataset?.[E]!==void 0?_.parentElement:_)}if(Z)M.appendChild(Z.outer)}}else if(J){if(J.textContent=H,F)J.style.letterSpacing=`${F}px`}if(J){if(U){if(this.words.push(J),this._d?.words)Object.assign(J.style,this._d.words);if(this._e?.words)J.classList.add(this._e.words)}this._f.push(J);let Y=this._g&v?this._r(J,v,I,m,this.masks.words):J;this._m(M,Y,j,J)}else if(!V)this._m(M,document.createTextNode(H),j)}return}if(N.nodeType!==1)return;let x=N,W=x.tagName.toLowerCase();if(o.includes(","+W+",")){let u=x.cloneNode(!0);if(R)this._q(u,R,O);let H=C(x)?.verticalAlign;if(H&&H!==g)u.style.verticalAlign=H;if(P){let J=this._p(U?"word":"");if(J.style.whiteSpace=h,H&&H!==g)J.style.verticalAlign=H;if(J.appendChild(u),U){if(this.words.push(J),this._d?.words)Object.assign(J.style,this._d.words);if(this._e?.words)J.classList.add(this._e.words)}this._f.push(J);let Y=this._g&v?this._r(J,v,I,m,this.masks.words):J;this._m(M,Y,j,J)}else this._m(M,u,j);return}let c=()=>{let u=x.cloneNode(!1);if(j){let{outer:H,inner:J}=j();return J.appendChild(u),{outer:H,inner:u}}return{outer:u,inner:u}},K=p[W],r=K?R?`${R} ${K}`:K:R,i=K?T.get(x)||O:O;for(let u of Array.from(x.childNodes))k(u,c,r,i)};for(let N of X)k(N,null,"","");q.appendChild(M);let A=!!(this._c&&this._c!==L);if($)this._y(A);else if(A){let N=U?this.words[0]:V?this.chars[0]:null;if(N)N.style.marginLeft=this._c,q.style.textIndent="0"}this._l=!1}_y(q){if(q&&this._f[0])this._f[0].style.marginLeft=this._c;this._t();let z=[];if(typeof document.fonts?.status==="string"&&document.fonts.status!=="loaded")z.push(document.fonts.ready);let F=this._b.querySelectorAll("img");for(let Q=0;Q<F.length;Q++){let V=F[Q];if(!V.complete)z.push(new Promise((U)=>{V.addEventListener("load",U,{once:!0}),V.addEventListener("error",U,{once:!0})}))}if(z.length){let Q=this._b.offsetHeight;Promise.all(z).then(()=>{if(this._b.offsetHeight!==Q)this.reflow()})}}_u(q){return this._o.get(q)??q}_t(){let q=this._f;if(!q.length)return;let z=q[0].offsetTop,F=z+q[0].offsetHeight,Q=[],V=[];for(let D of q){let T=D.offsetTop,G=T+D.offsetHeight;if(T<F&&G>z)z=Math.min(z,T),F=Math.max(F,G);else V.push(Q),Q=[],z=T,F=G;Q.push(D)}if(Q.length)V.push(Q);let U=!!(this._c&&this._c!==L);if(U&&q[0])q[0].style.marginLeft="";let $=!!(this._g&y),P=document.createDocumentFragment();for(let D=0;D<V.length;D++){let T=V[D],G=document.createElement(this._j);if(G.dataset.line="",G.style.display=f,D===0&&U)G.style.paddingLeft=this._c;for(let X=0;X<T.length;X++){if(X>0)G.appendChild(document.createTextNode(" "));G.appendChild(this._u(T[X]))}if(this.lines.push(G),this._d?.lines)Object.assign(G.style,this._d.lines);if(this._e?.lines)G.classList.add(this._e.lines);if($){let X=this._s(f,n);X.appendChild(G),this.masks.lines.push(X),P.appendChild(X)}else P.appendChild(G)}this._b.replaceChildren(P)}_x(){let q=this._b.offsetParent?this._b.offsetParent.offsetWidth:window.innerWidth,z=()=>{if(this._l)return;let Q=this._b.offsetParent,V=Q?Q.offsetWidth:window.innerWidth;if(V===q)return;if(q=V,this._h)cancelAnimationFrame(this._h);this._h=requestAnimationFrame(()=>this.reflow())};this._i=new ResizeObserver(z);let F=this._b.offsetParent??this._b.parentElement;if(F)this._i.observe(F);else this._i.observe(this._b)}reflow(){if(this._a){this._a.forEach((z)=>z.reflow()),this._v();return}if(!(this._k&y)||this._l)return;let q=document.createDocumentFragment();for(let z=0;z<this._f.length;z++){if(z>0)q.appendChild(document.createTextNode(" "));q.appendChild(this._u(this._f[z]))}if(this._b.replaceChildren(q),this.lines.length=0,this.masks.lines.length=0,this._c&&this._c!==L&&this._f[0])this._f[0].style.marginLeft=this._c;this._t()}revert(){if(this._a){this._a.forEach((q)=>q.revert()),this._v();return}this.destroy(),this._b.innerHTML=this._n,this.chars.length=0,this.words.length=0,this._f.length=0,this._o.clear(),this.lines.length=0,this.masks.chars.length=0,this.masks.words.length=0,this.masks.lines.length=0}destroy(){if(this._a){this._a.forEach((q)=>q.destroy());return}if(this._h)cancelAnimationFrame(this._h),this._h=0;if(this._i)this._i.disconnect(),this._i=null}_v(){if(!this._a)return;this.chars.length=0,this.words.length=0,this.lines.length=0,this.masks.chars.length=0,this.masks.words.length=0,this.masks.lines.length=0;for(let q of this._a)this.chars.push(...q.chars),this.words.push(...q.words),this.lines.push(...q.lines),this.masks.chars.push(...q.masks.chars),this.masks.words.push(...q.masks.words),this.masks.lines.push(...q.masks.lines)}}
|
|
2
|
+
export{a};
|
package/dist/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{a as b}from"./chunk-
|
|
1
|
+
import{a as b}from"./chunk-nfvb3yjq.js";export{b as SplitText};
|
|
@@ -24,7 +24,7 @@ type WF = () => {
|
|
|
24
24
|
inner: HTMLElement;
|
|
25
25
|
};
|
|
26
26
|
export declare class SplitText {
|
|
27
|
-
readonly dom: HTMLElement;
|
|
27
|
+
readonly dom: HTMLElement | HTMLElement[];
|
|
28
28
|
readonly chars: HTMLElement[];
|
|
29
29
|
readonly words: HTMLElement[];
|
|
30
30
|
readonly lines: HTMLElement[];
|
|
@@ -45,7 +45,9 @@ export declare class SplitText {
|
|
|
45
45
|
/** @internal */ _textIndent: string;
|
|
46
46
|
/** @internal */ _styles: SplitTextOptions["style"];
|
|
47
47
|
/** @internal */ _classes: SplitTextOptions["class"];
|
|
48
|
-
|
|
48
|
+
/** @internal */ _el: HTMLElement;
|
|
49
|
+
/** @internal */ _instances: SplitText[] | null;
|
|
50
|
+
constructor(element: HTMLElement | HTMLElement[] | string, options?: SplitTextOptions);
|
|
49
51
|
/** @internal — create a styled inline-block element. */
|
|
50
52
|
_makeEl(dataAttr: string, text?: string): HTMLElement;
|
|
51
53
|
/** @internal — create a mask wrapper element. */
|
|
@@ -70,5 +72,7 @@ export declare class SplitText {
|
|
|
70
72
|
reflow(): void;
|
|
71
73
|
revert(): void;
|
|
72
74
|
destroy(): void;
|
|
75
|
+
/** @internal — re-aggregate arrays from sub-instances after reflow/revert. */
|
|
76
|
+
_syncAggregated(): void;
|
|
73
77
|
}
|
|
74
78
|
export {};
|
package/dist/split-text/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{a}from"../chunk-
|
|
1
|
+
import{a}from"../chunk-nfvb3yjq.js";export{a as SplitText};
|
package/package.json
CHANGED
package/dist/chunk-fqr7g8fv.js
DELETED
|
@@ -1,2 +0,0 @@
|
|
|
1
|
-
function C(z,q){return typeof globalThis.getComputedStyle==="function"?globalThis.getComputedStyle(z,q??null):null}var B=1,Y=2,S=4,I="inline-block",h="nowrap",f="baseline",L="0px",g="block",m="maskChar",E="maskWord",n="maskLine",s=/^\s+$/,w=/(\s+)/,o=",div,span,svg,img,br,hr,canvas,video,audio,iframe,input,textarea,select,button,picture,figure,",i={u:"underline",ins:"underline",s:"line-through",strike:"line-through",del:"line-through"};class d{dom;chars;words;lines;masks;_p;_k;_e;_h;_d=[];_l=new Map;_g=null;_f=0;_i=!1;_a="";_b;_c;constructor(z,q={}){let F=typeof z==="string"?document.querySelector(z):z;if(!F)throw Error("SplitText: element not found");this.dom=F,this._p=F.innerHTML,this.chars=[],this.words=[],this.lines=[],this.masks={chars:[],words:[],lines:[]};let $=q.type?Array.isArray(q.type)?q.type:[q.type]:["chars","words","lines"],V=0;for(let b of $)if(b==="chars")V|=B;else if(b==="words")V|=Y;else if(b==="lines")V|=S;this._k=V,this._h=q.tag??"span";let Q=0;if(q.mask===!0)Q=V;else if(Array.isArray(q.mask)){for(let b of q.mask)if(b==="chars")Q|=B;else if(b==="words")Q|=Y;else if(b==="lines")Q|=S}if(this._e=Q,this._b=q.style,this._c=q.class,this._t(),(q.resize??!0)&&V&S)this._u()}_m(z,q){let F=document.createElement(this._h);if(z)F.dataset[z]="";if(F.style.display=I,q!==void 0)F.textContent=q;return F}_q(z,q){let F=document.createElement(this._h);if(F.dataset[q]="",F.style.overflow="hidden",F.style.display=z,this._b?.mask)Object.assign(F.style,this._b.mask);if(this._c?.mask)F.classList.add(this._c.mask);return F}_o(z,q,F,$,V){if(this._e&q){let Q=this._q(F,$);return Q.appendChild(z),V.push(Q),Q}return z}_j(z,q,F,$){if(F){let{outer:V,inner:Q}=F();if(Q.appendChild(q),$)this._l.set($,V);z.appendChild(V)}else z.appendChild(q)}_n(z,q,F){if(z.style.textDecoration=q,F)z.style.textDecorationColor=F}_t(){this._i=!0;let z=this.dom,q=C(z),F=q?parseFloat(q.letterSpacing)||0:0;if(this._a=q?q.textIndent:"",this._a&&this._a!==L)z.style.textIndent="0";let $=this._k,V=!!($&B),Q=!!($&Y),b=!!($&S),u=Q||b,j=!!(this._e&B),X=new Map,U=(D)=>{for(let H of Array.from(D.childNodes))if(H.nodeType===1){let N=H.tagName.toLowerCase();if(i[N]){let O=C(H)?.textDecorationColor;if(O)X.set(H,O)}U(H)}};U(z);let Z=Array.from(z.childNodes),M=document.createDocumentFragment();z.replaceChildren();let k=(D,H,N,O)=>{if(D.nodeType===3){let T=(D.textContent??"").split(w);for(let G of T){if(!G)continue;if(s.test(G)){M.appendChild(document.createTextNode(G));continue}let J=u?this._m(Q?"word":""):null;if(J){if(J.style.whiteSpace=h,N&&!V)this._n(J,N,O)}if(V){let R=[...G],c=this.chars.length;for(let v=0;v<R.length;v++){let x=this._m("char",R[v]);if(F&&v<R.length-1)x.style.marginRight=`${F}px`;if(N)this._n(x,N,O);if(this.chars.push(x),this._b?.chars)Object.assign(x.style,this._b.chars);if(this._c?.chars)x.classList.add(this._c.chars);let y=j?this._o(x,B,I,m,this.masks.chars):x;if(J)J.appendChild(y)}if(!J){let v=H?H():null,x=v?v.inner:M;for(let y=c;y<this.chars.length;y++){let _=this.chars[y];x.appendChild(j&&_.parentElement?.dataset?.[m]!==void 0?_.parentElement:_)}if(v)M.appendChild(v.outer)}}else if(J){if(J.textContent=G,F)J.style.letterSpacing=`${F}px`}if(J){if(Q){if(this.words.push(J),this._b?.words)Object.assign(J.style,this._b.words);if(this._c?.words)J.classList.add(this._c.words)}this._d.push(J);let R=this._e&Y?this._o(J,Y,I,E,this.masks.words):J;this._j(M,R,H,J)}else if(!V)this._j(M,document.createTextNode(G),H)}return}if(D.nodeType!==1)return;let P=D,W=P.tagName.toLowerCase();if(o.includes(","+W+",")){let T=P.cloneNode(!0);if(N)this._n(T,N,O);let G=C(P)?.verticalAlign;if(G&&G!==f)T.style.verticalAlign=G;if(u){let J=this._m(Q?"word":"");if(J.style.whiteSpace=h,G&&G!==f)J.style.verticalAlign=G;if(J.appendChild(T),Q){if(this.words.push(J),this._b?.words)Object.assign(J.style,this._b.words);if(this._c?.words)J.classList.add(this._c.words)}this._d.push(J);let R=this._e&Y?this._o(J,Y,I,E,this.masks.words):J;this._j(M,R,H,J)}else this._j(M,T,H);return}let p=()=>{let T=P.cloneNode(!1);if(H){let{outer:G,inner:J}=H();return J.appendChild(T),{outer:G,inner:T}}return{outer:T,inner:T}},K=i[W],a=K?N?`${N} ${K}`:K:N,r=K?X.get(P)||O:O;for(let T of Array.from(P.childNodes))k(T,p,a,r)};for(let D of Z)k(D,null,"","");z.appendChild(M);let A=!!(this._a&&this._a!==L);if(b)this._v(A);else if(A){let D=Q?this.words[0]:V?this.chars[0]:null;if(D)D.style.marginLeft=this._a,z.style.textIndent="0"}this._i=!1}_v(z){if(z&&this._d[0])this._d[0].style.marginLeft=this._a;this._r();let q=[];if(typeof document.fonts?.status==="string"&&document.fonts.status!=="loaded")q.push(document.fonts.ready);let F=this.dom.querySelectorAll("img");for(let $=0;$<F.length;$++){let V=F[$];if(!V.complete)q.push(new Promise((Q)=>{V.addEventListener("load",Q,{once:!0}),V.addEventListener("error",Q,{once:!0})}))}if(q.length){let $=this.dom.offsetHeight;Promise.all(q).then(()=>{if(this.dom.offsetHeight!==$)this.reflow()})}}_s(z){return this._l.get(z)??z}_r(){let z=this._d;if(!z.length)return;let q=z[0].offsetTop,F=q+z[0].offsetHeight,$=[],V=[];for(let j of z){let X=j.offsetTop,U=X+j.offsetHeight;if(X<F&&U>q)q=Math.min(q,X),F=Math.max(F,U);else V.push($),$=[],q=X,F=U;$.push(j)}if($.length)V.push($);let Q=!!(this._a&&this._a!==L);if(Q&&z[0])z[0].style.marginLeft="";let b=!!(this._e&S),u=document.createDocumentFragment();for(let j=0;j<V.length;j++){let X=V[j],U=document.createElement(this._h);if(U.dataset.line="",U.style.display=g,j===0&&Q)U.style.paddingLeft=this._a;for(let Z=0;Z<X.length;Z++){if(Z>0)U.appendChild(document.createTextNode(" "));U.appendChild(this._s(X[Z]))}if(this.lines.push(U),this._b?.lines)Object.assign(U.style,this._b.lines);if(this._c?.lines)U.classList.add(this._c.lines);if(b){let Z=this._q(g,n);Z.appendChild(U),this.masks.lines.push(Z),u.appendChild(Z)}else u.appendChild(U)}this.dom.replaceChildren(u)}_u(){let z=this.dom.offsetParent?this.dom.offsetParent.offsetWidth:window.innerWidth,q=()=>{if(this._i)return;let $=this.dom.offsetParent,V=$?$.offsetWidth:window.innerWidth;if(V===z)return;if(z=V,this._f)cancelAnimationFrame(this._f);this._f=requestAnimationFrame(()=>this.reflow())};this._g=new ResizeObserver(q);let F=this.dom.offsetParent??this.dom.parentElement;if(F)this._g.observe(F);else this._g.observe(this.dom)}reflow(){if(!(this._k&S)||this._i)return;let z=document.createDocumentFragment();for(let q=0;q<this._d.length;q++){if(q>0)z.appendChild(document.createTextNode(" "));z.appendChild(this._s(this._d[q]))}if(this.dom.replaceChildren(z),this.lines.length=0,this.masks.lines.length=0,this._a&&this._a!==L&&this._d[0])this._d[0].style.marginLeft=this._a;this._r()}revert(){this.destroy(),this.dom.innerHTML=this._p,this.chars.length=0,this.words.length=0,this._d.length=0,this._l.clear(),this.lines.length=0,this.masks.chars.length=0,this.masks.words.length=0,this.masks.lines.length=0}destroy(){if(this._f)cancelAnimationFrame(this._f),this._f=0;if(this._g)this._g.disconnect(),this._g=null}}
|
|
2
|
-
export{d as a};
|