situs-kit 0.1.2 → 0.1.4

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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2025 Surya Aditya
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md CHANGED
@@ -21,16 +21,9 @@ const split = new SplitText("#my-text", {
21
21
  type: ["chars", "words", "lines"],
22
22
  });
23
23
 
24
- // Animate each character
25
- split.chars.forEach((char, i) => {
26
- char.animate(
27
- [
28
- { opacity: 0, transform: "translateY(100%)" },
29
- { opacity: 1, transform: "translateY(0)" },
30
- ],
31
- { duration: 400, delay: i * 30, easing: "ease", fill: "both" }
32
- );
33
- });
24
+ split.chars; // HTMLElement[]
25
+ split.words; // HTMLElement[]
26
+ split.lines; // HTMLElement[]
34
27
  ```
35
28
 
36
29
  ### Options
@@ -39,7 +32,7 @@ split.chars.forEach((char, i) => {
39
32
  new SplitText(element, {
40
33
  type: ["chars", "words", "lines"], // which levels to split
41
34
  tag: "span", // wrapper element tag
42
- mask: true, // wrap in overflow:hidden containers
35
+ mask: ["chars", "lines"], // which levels to mask
43
36
  resize: true, // auto-reflow lines on resize
44
37
  style: {
45
38
  chars: { color: "red" },
@@ -60,7 +53,7 @@ new SplitText(element, {
60
53
  |--------|------|---------|-------------|
61
54
  | `type` | `string \| string[]` | `["chars", "words", "lines"]` | Split granularity |
62
55
  | `tag` | `string` | `"span"` | Wrapper element tag |
63
- | `mask` | `boolean \| string[]` | `false` | Create overflow-hidden wrappers |
56
+ | `mask` | `boolean \| SplitType[]` | `false` | Create overflow-hidden wrappers per split type |
64
57
  | `resize` | `boolean` | `true` | Auto-reflow lines on window resize |
65
58
  | `style` | `object` | — | Inline styles per split type |
66
59
  | `class` | `object` | — | CSS classes per split type |
@@ -124,21 +117,15 @@ Inline elements like `<a>`, `<em>`, `<strong>`, `<u>`, `<i>`, and `<b>` are pres
124
117
 
125
118
  ### Masking
126
119
 
127
- Masks wrap split elements in `overflow: hidden` containers, useful for reveal animations:
120
+ Masks wrap split elements in `overflow: hidden` containers, useful for reveal animations. Like `type`, you specify which split levels to mask:
128
121
 
129
122
  ```ts
130
123
  const split = new SplitText("#text", {
131
124
  type: ["words", "lines"],
132
- mask: ["lines"],
125
+ mask: ["lines"], // only mask lines
133
126
  });
134
127
 
135
- // Slide words up from behind line masks
136
- split.lines.forEach((line, i) => {
137
- line.animate(
138
- [{ transform: "translateY(100%)" }, { transform: "translateY(0)" }],
139
- { duration: 500, delay: i * 60, easing: "ease", fill: "both" }
140
- );
141
- });
128
+ split.masks.lines; // HTMLElement[] - overflow:hidden wrappers
142
129
  ```
143
130
 
144
131
  ## License
package/dist/index.js CHANGED
@@ -1 +1 @@
1
- import{a as b}from"./chunk-fqr7g8fv.js";export{b as SplitText};
1
+ function I(z,q){return typeof globalThis.getComputedStyle==="function"?globalThis.getComputedStyle(z,q??null):null}var x=1,y=2,B=4,L="inline-block",h="nowrap",f="baseline",_="0px",g="block",m="maskChar",E="maskWord",w="maskLine",s=/^\s+$/,o=/(\s+)/,d=",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 a{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|=x;else if(b==="words")V|=y;else if(b==="lines")V|=B;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|=x;else if(b==="words")Q|=y;else if(b==="lines")Q|=B}if(this._e=Q,this._b=q.style,this._c=q.class,this._t(),(q.resize??!0)&&V&B)this._u()}_m(z,q){let F=document.createElement(this._h);if(z)F.dataset[z]="";if(F.style.display=L,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=I(z),F=q?parseFloat(q.letterSpacing)||0:0;if(this._a=q?q.textIndent:"",this._a&&this._a!==_)z.style.textIndent="0";let $=this._k,V=!!($&x),Q=!!($&y),b=!!($&B),N=Q||b,j=!!(this._e&x),Z=new Map,U=(D)=>{for(let H of Array.from(D.childNodes))if(H.nodeType===1){let X=H.tagName.toLowerCase();if(i[X]){let Y=I(H)?.textDecorationColor;if(Y)Z.set(H,Y)}U(H)}};U(z);let v=Array.from(z.childNodes),R=document.createDocumentFragment();z.replaceChildren();let k=(D,H,X,Y)=>{if(D.nodeType===3){let T=(D.textContent??"").split(o);for(let G of T){if(!G)continue;if(s.test(G)){R.appendChild(document.createTextNode(G));continue}let J=N?this._m(Q?"word":""):null;if(J){if(J.style.whiteSpace=h,X&&!V)this._n(J,X,Y)}if(V){let u=[...G],n=this.chars.length;for(let M=0;M<u.length;M++){let O=this._m("char",u[M]);if(F&&M<u.length-1)O.style.marginRight=`${F}px`;if(X)this._n(O,X,Y);if(this.chars.push(O),this._b?.chars)Object.assign(O.style,this._b.chars);if(this._c?.chars)O.classList.add(this._c.chars);let S=j?this._o(O,x,L,m,this.masks.chars):O;if(J)J.appendChild(S)}if(!J){let M=H?H():null,O=M?M.inner:R;for(let S=n;S<this.chars.length;S++){let C=this.chars[S];O.appendChild(j&&C.parentElement?.dataset?.[m]!==void 0?C.parentElement:C)}if(M)R.appendChild(M.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 u=this._e&y?this._o(J,y,L,E,this.masks.words):J;this._j(R,u,H,J)}else if(!V)this._j(R,document.createTextNode(G),H)}return}if(D.nodeType!==1)return;let P=D,W=P.tagName.toLowerCase();if(d.includes(","+W+",")){let T=P.cloneNode(!0);if(X)this._n(T,X,Y);let G=I(P)?.verticalAlign;if(G&&G!==f)T.style.verticalAlign=G;if(N){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 u=this._e&y?this._o(J,y,L,E,this.masks.words):J;this._j(R,u,H,J)}else this._j(R,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],r=K?X?`${X} ${K}`:K:X,c=K?Z.get(P)||Y:Y;for(let T of Array.from(P.childNodes))k(T,p,r,c)};for(let D of v)k(D,null,"","");z.appendChild(R);let A=!!(this._a&&this._a!==_);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 Z=j.offsetTop,U=Z+j.offsetHeight;if(Z<F&&U>q)q=Math.min(q,Z),F=Math.max(F,U);else V.push($),$=[],q=Z,F=U;$.push(j)}if($.length)V.push($);let Q=!!(this._a&&this._a!==_);if(Q&&z[0])z[0].style.marginLeft="";let b=!!(this._e&B),N=document.createDocumentFragment();for(let j=0;j<V.length;j++){let Z=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 v=0;v<Z.length;v++){if(v>0)U.appendChild(document.createTextNode(" "));U.appendChild(this._s(Z[v]))}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 v=this._q(g,w);v.appendChild(U),this.masks.lines.push(v),N.appendChild(v)}else N.appendChild(U)}this.dom.replaceChildren(N)}_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&B)||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!==_&&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}}export{a as SplitText};
@@ -1 +1 @@
1
- import{a}from"../chunk-fqr7g8fv.js";export{a as SplitText};
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}}export{d as SplitText};
package/package.json CHANGED
@@ -1,7 +1,8 @@
1
1
  {
2
2
  "name": "situs-kit",
3
- "version": "0.1.2",
3
+ "version": "0.1.4",
4
4
  "description": "A creative developer helper library",
5
+ "license": "MIT",
5
6
  "module": "./dist/index.js",
6
7
  "main": "./dist/index.js",
7
8
  "types": "./dist/index.d.ts",
@@ -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};