situs-kit 0.2.8 → 0.2.9
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 +39 -5
- package/dist/chunk-77ab0s89.js +2 -0
- package/dist/index.js +1 -1
- package/dist/split-text/index.d.ts +29 -15
- package/dist/split-text/index.js +1 -1
- package/package.json +1 -1
- package/dist/chunk-34xh7zzz.js +0 -2
package/README.md
CHANGED
|
@@ -31,7 +31,7 @@ split.lines; // HTMLElement[]
|
|
|
31
31
|
```ts
|
|
32
32
|
new SplitText(
|
|
33
33
|
element: HTMLElement | HTMLElement[] | ArrayLike<HTMLElement> | string,
|
|
34
|
-
options?: SplitTextOptions
|
|
34
|
+
options?: SplitTextOptions<T>
|
|
35
35
|
)
|
|
36
36
|
```
|
|
37
37
|
|
|
@@ -54,13 +54,15 @@ new SplitText(element, {
|
|
|
54
54
|
chars: { color: "red" },
|
|
55
55
|
words: {},
|
|
56
56
|
lines: {},
|
|
57
|
-
mask: {},
|
|
57
|
+
mask: {}, // flat: applies to all masks
|
|
58
|
+
// mask: { chars: {}, lines: {} }, // per-type: target specific masks
|
|
58
59
|
},
|
|
59
60
|
class: {
|
|
60
61
|
chars: "my-char",
|
|
61
62
|
words: "my-word",
|
|
62
63
|
lines: "my-line",
|
|
63
|
-
mask: "my-mask",
|
|
64
|
+
mask: "my-mask", // flat: applies to all masks
|
|
65
|
+
// mask: { chars: "c", lines: "l" }, // per-type: target specific masks
|
|
64
66
|
},
|
|
65
67
|
});
|
|
66
68
|
```
|
|
@@ -72,8 +74,10 @@ new SplitText(element, {
|
|
|
72
74
|
| `children` | `boolean` | `false` | Split the target's child elements instead of the target itself |
|
|
73
75
|
| `mask` | `boolean \| SplitType[]` | `false` | Create overflow-hidden wrappers. `true` masks all requested types; array masks only specified types |
|
|
74
76
|
| `resize` | `boolean` | `true` | Auto-reflow lines on window resize (only applies when lines are split) |
|
|
75
|
-
| `style` | `object` | — | Inline styles per split type (`chars
|
|
76
|
-
| `class` | `object` | — | CSS classes per split type (`chars
|
|
77
|
+
| `style` | `object` | — | Inline styles per split type. `mask` accepts a flat object (all masks) or per-type `{ chars?, words?, lines? }` |
|
|
78
|
+
| `class` | `object` | — | CSS classes per split type. `mask` accepts a string (all masks) or per-type `{ chars?, words?, lines? }` |
|
|
79
|
+
|
|
80
|
+
> **Type safety:** `style`, `class`, and `mask` are constrained by `type`. Setting `style: { words: {} }` when `type: ["chars"]` is a compile-time error.
|
|
77
81
|
|
|
78
82
|
### Types
|
|
79
83
|
|
|
@@ -176,6 +180,36 @@ const split2 = new SplitText("#text", {
|
|
|
176
180
|
});
|
|
177
181
|
```
|
|
178
182
|
|
|
183
|
+
### Per-Type Mask Styles
|
|
184
|
+
|
|
185
|
+
Apply different styles or classes to mask wrappers depending on their split level:
|
|
186
|
+
|
|
187
|
+
```ts
|
|
188
|
+
new SplitText("#text", {
|
|
189
|
+
type: ["chars", "words", "lines"],
|
|
190
|
+
mask: true,
|
|
191
|
+
style: {
|
|
192
|
+
mask: {
|
|
193
|
+
chars: { perspective: "500px" },
|
|
194
|
+
lines: { clipPath: "inset(0)" },
|
|
195
|
+
},
|
|
196
|
+
},
|
|
197
|
+
class: {
|
|
198
|
+
mask: {
|
|
199
|
+
chars: "char-mask",
|
|
200
|
+
lines: "line-mask",
|
|
201
|
+
},
|
|
202
|
+
},
|
|
203
|
+
});
|
|
204
|
+
```
|
|
205
|
+
|
|
206
|
+
A flat value still applies to all masks:
|
|
207
|
+
|
|
208
|
+
```ts
|
|
209
|
+
style: { mask: { overflow: "visible" } } // all masks
|
|
210
|
+
class: { mask: "my-mask" } // all masks
|
|
211
|
+
```
|
|
212
|
+
|
|
179
213
|
## Children Mode
|
|
180
214
|
|
|
181
215
|
When `children: true`, SplitText splits each direct child element of the target instead of the target itself. Useful when a container holds multiple blocks (headings, paragraphs) that should all be split with one call.
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
import{d as _,g as a,h as r}from"./chunk-fh0qxmf2.js";var L=1,B=2,K=4,C="inline-block",f="nowrap",E="baseline",S="0px",g="block",p="maskChar",c="maskWord",l="maskLine",t=/^\s+$/,e=/(\s+)/,w=",div,span,svg,img,br,hr,canvas,video,audio,iframe,input,textarea,select,button,picture,figure,",m={u:"underline",ins:"underline",s:"line-through",strike:"line-through",del:"line-through"};class i{dom;chars;words;lines;masks;_n;_k;_g;_j;_f=[];_q=new Map;_i=null;_h=0;_l=!1;_c="";_d;_e;_o=null;_p=null;_a;_b=null;constructor(z,F={}){let J;if(typeof z==="string"){let V=r(z);if(V.length>1)J=V;else{let H=V[0]??a(z);if(!H)throw Error("SplitText: element not found");J=H}}else J=z;if(F.children){if(Array.isArray(J)||typeof J==="object"&&J!==null&&"length"in J&&typeof J.item==="function")J=Array.from(J).flatMap((U)=>Array.from(U.children));else J=Array.from(J.children);let{children:V,...H}=F;F=H}if(Array.isArray(J)||typeof J==="object"&&J!==null&&"length"in J&&typeof J.item==="function"){let V=Array.from(J);if(V.length===0)throw Error("SplitText: empty element array");this._b=V.map((H)=>new i(H,F)),this.dom=V,this.chars=this._b.flatMap((H)=>H.chars),this.words=this._b.flatMap((H)=>H.words),this.lines=this._b.flatMap((H)=>H.lines),this.masks={chars:this._b.flatMap((H)=>H.masks.chars),words:this._b.flatMap((H)=>H.masks.words),lines:this._b.flatMap((H)=>H.masks.lines)},this._n="",this._k=0,this._g=0,this._j="";return}let G=J;this._a=G,this.dom=G,this._n=G.innerHTML,this.chars=[],this.words=[],this.lines=[],this.masks={chars:[],words:[],lines:[]};let Q=F.type?Array.isArray(F.type)?F.type:[F.type]:["chars","words","lines"],N=0;for(let V of Q)if(V==="chars")N|=L;else if(V==="words")N|=B;else if(V==="lines")N|=K;this._k=N,this._j=F.tag??"span";let M=0;if(F.mask===!0)M=N;else if(Array.isArray(F.mask)){for(let V of F.mask)if(V==="chars")M|=L;else if(V==="words")M|=B;else if(V==="lines")M|=K}if(this._g=M,this._d=F.style,this._e=F.class,this._d?.mask){let V=this._d.mask;if(typeof V.chars==="object"||typeof V.words==="object"||typeof V.lines==="object")this._o=V;else this._o={chars:V,words:V,lines:V}}if(this._e?.mask){let V=this._e.mask;if(typeof V==="string")this._p={chars:V,words:V,lines:V};else this._p=V}if(this._y(),(F.resize??!0)&&N&K)this._z()}_r(z,F){let J=document.createElement(this._j);if(z)J.dataset[z]="";if(J.style.display=C,F!==void 0)J.textContent=F;return J}_u(z,F,J){let $=document.createElement(this._j);$.dataset[F]="",$.style.overflow="hidden",$.style.display=z;let G=this._o?.[J];if(G)Object.assign($.style,G);let Q=this._p?.[J];if(Q)$.classList.add(Q);return $}_t(z,F,J,$,G,Q){if(this._g&F){let N=this._u(J,$,Q);return N.appendChild(z),G.push(N),N}return z}_m(z,F,J,$){if(J){let{outer:G,inner:Q}=J();if(Q.appendChild(F),$)this._q.set($,G);z.appendChild(G)}else z.appendChild(F)}_s(z,F,J){if(z.style.textDecoration=F,J)z.style.textDecorationColor=J}_y(){this._l=!0;let z=this._a,F=_(z),J=F?parseFloat(F.letterSpacing)||0:0;if(this._c=F?F.textIndent:"",this._c&&this._c!==S)z.style.textIndent="0";let $=this._k,G=!!($&L),Q=!!($&B),N=!!($&K),M=Q||N,V=!!(this._g&L),H=new Map,U=new Set,O=(R)=>{for(let j of Array.from(R.childNodes))if(j.nodeType===1){let Z=j.tagName.toLowerCase();if(m[Z]){let b=_(j)?.textDecorationColor;if(b)H.set(j,b)}if(w.includes(","+Z+",")&&_(j)?.display==="contents")U.add(j);O(j)}};O(z);let d=Array.from(z.childNodes),Y=document.createDocumentFragment();z.replaceChildren();let W=(R,j,Z,b)=>{if(R.nodeType===3){let D=(R.textContent??"").split(e);for(let X of D){if(!X)continue;if(t.test(X)){Y.appendChild(document.createTextNode(X));continue}let q=M?this._r(Q?"word":""):null;if(q){if(q.style.whiteSpace=f,Z&&!G)this._s(q,Z,b)}if(G){let P=[...X],y=this.chars.length;for(let T=0;T<P.length;T++){let x=this._r("char",P[T]);if(J&&T<P.length-1)x.style.marginRight=`${J}px`;if(Z)this._s(x,Z,b);if(this.chars.push(x),this._d?.chars)Object.assign(x.style,this._d.chars);if(this._e?.chars)x.classList.add(this._e.chars);let I=V?this._t(x,L,C,p,this.masks.chars,"chars"):x;if(q)q.appendChild(I)}if(!q){let T=j?j():null,x=T?T.inner:Y;for(let I=y;I<this.chars.length;I++){let k=this.chars[I];x.appendChild(V&&k.parentElement?.dataset?.[p]!==void 0?k.parentElement:k)}if(T)Y.appendChild(T.outer)}}else if(q){if(q.textContent=X,J)q.style.letterSpacing=`${J}px`}if(q){if(Q){if(this.words.push(q),this._d?.words)Object.assign(q.style,this._d.words);if(this._e?.words)q.classList.add(this._e.words)}this._f.push(q);let P=this._g&B?this._t(q,B,C,c,this.masks.words,"words"):q;this._m(Y,P,j,q)}else if(!G)this._m(Y,document.createTextNode(X),j)}return}if(R.nodeType!==1)return;let v=R,h=v.tagName.toLowerCase();if(w.includes(","+h+",")){if(U.has(v)){let q=Y,P=document.createDocumentFragment();Y=P;for(let T of Array.from(v.childNodes))W(T,j,Z,b);Y=q;let y=v.cloneNode(!1);y.appendChild(P),Y.appendChild(y);return}let D=v.cloneNode(!0);if(Z)this._s(D,Z,b);let X=_(v)?.verticalAlign;if(X&&X!==E)D.style.verticalAlign=X;if(M){let q=this._r(Q?"word":"");if(q.style.whiteSpace=f,X&&X!==E)q.style.verticalAlign=X;if(q.appendChild(D),Q){if(this.words.push(q),this._d?.words)Object.assign(q.style,this._d.words);if(this._e?.words)q.classList.add(this._e.words)}this._f.push(q);let P=this._g&B?this._t(q,B,C,c,this.masks.words,"words"):q;this._m(Y,P,j,q)}else this._m(Y,D,j);return}let s=()=>{let D=v.cloneNode(!1);if(j){let{outer:X,inner:q}=j();return q.appendChild(D),{outer:X,inner:D}}return{outer:D,inner:D}},u=m[h],n=u?Z?`${Z} ${u}`:u:Z,o=u?H.get(v)||b:b;for(let D of Array.from(v.childNodes))W(D,s,n,o)};for(let R of d)W(R,null,"","");z.appendChild(Y);let A=!!(this._c&&this._c!==S);if(N)this._A(A);else if(A){let R=Q?this.words[0]:G?this.chars[0]:null;if(R)R.style.marginLeft=this._c,z.style.textIndent="0"}this._l=!1}_A(z){if(z&&this._f[0])this._f[0].style.marginLeft=this._c;this._v();let F=[];if(typeof document.fonts?.status==="string"&&document.fonts.status!=="loaded")F.push(document.fonts.ready);let J=this._a.querySelectorAll("img");for(let $=0;$<J.length;$++){let G=J[$];if(!G.complete)F.push(new Promise((Q)=>{G.addEventListener("load",Q,{once:!0}),G.addEventListener("error",Q,{once:!0})}))}if(F.length){let $=this._a.offsetHeight===0&&this._a.parentElement?this._a.parentElement:this._a,G=$.offsetHeight;Promise.all(F).then(()=>{if($.offsetHeight!==G)this.reflow()})}}_w(z){return this._q.get(z)??z}_v(){let z=this._f;if(!z.length)return;let F=z[0].offsetTop,J=F+z[0].offsetHeight,$=[],G=[];for(let V of z){let H=V.offsetTop,U=H+V.offsetHeight;if(H<J&&U>F)F=Math.min(F,H),J=Math.max(J,U);else G.push($),$=[],F=H,J=U;$.push(V)}if($.length)G.push($);let Q=!!(this._c&&this._c!==S);if(Q&&z[0])z[0].style.marginLeft="";let N=!!(this._g&K),M=document.createDocumentFragment();for(let V=0;V<G.length;V++){let H=G[V],U=document.createElement(this._j);if(U.dataset.line="",U.style.display=g,V===0&&Q)U.style.paddingLeft=this._c;for(let O=0;O<H.length;O++){if(O>0)U.appendChild(document.createTextNode(" "));U.appendChild(this._w(H[O]))}if(this.lines.push(U),this._d?.lines)Object.assign(U.style,this._d.lines);if(this._e?.lines)U.classList.add(this._e.lines);if(N){let O=this._u(g,l,"lines");O.appendChild(U),this.masks.lines.push(O),M.appendChild(O)}else M.appendChild(U)}this._a.replaceChildren(M)}_z(){let z=this._a.offsetParent?this._a.offsetParent.offsetWidth:window.innerWidth,F=()=>{if(this._l)return;let $=this._a.offsetParent,G=$?$.offsetWidth:window.innerWidth;if(G===z)return;if(z=G,this._h)cancelAnimationFrame(this._h);this._h=requestAnimationFrame(()=>this.reflow())};this._i=new ResizeObserver(F);let J=this._a.offsetParent??this._a.parentElement;if(J)this._i.observe(J);else this._i.observe(this._a)}reflow(){if(this._b){this._b.forEach((F)=>F.reflow()),this._x();return}if(!(this._k&K)||this._l)return;let z=document.createDocumentFragment();for(let F=0;F<this._f.length;F++){if(F>0)z.appendChild(document.createTextNode(" "));z.appendChild(this._w(this._f[F]))}if(this._a.replaceChildren(z),this.lines.length=0,this.masks.lines.length=0,this._c&&this._c!==S&&this._f[0])this._f[0].style.marginLeft=this._c;this._v()}revert(){if(this._b){this._b.forEach((z)=>z.revert()),this._x();return}this.destroy(),this._a.innerHTML=this._n,this.chars.length=0,this.words.length=0,this._f.length=0,this._q.clear(),this.lines.length=0,this.masks.chars.length=0,this.masks.words.length=0,this.masks.lines.length=0}destroy(){if(this._b){this._b.forEach((z)=>z.destroy());return}if(this._h)cancelAnimationFrame(this._h),this._h=0;if(this._i)this._i.disconnect(),this._i=null}_x(){if(!this._b)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 z of this._b)this.chars.push(...z.chars),this.words.push(...z.words),this.lines.push(...z.lines),this.masks.chars.push(...z.masks.chars),this.masks.words.push(...z.masks.words),this.masks.lines.push(...z.masks.lines)}}
|
|
2
|
+
export{i as a};
|
package/dist/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{a as e}from"./chunk-
|
|
1
|
+
import{a as e}from"./chunk-77ab0s89.js";import{b as r,c as l}from"./chunk-dmf84kzz.js";import"./chunk-fh0qxmf2.js";import{i as t,j as o}from"./chunk-zdhnw183.js";export{t as getDeltaFrame,o as Ticker,e as SplitText,l as SmoothScroll,r as Resize};
|
|
@@ -1,30 +1,34 @@
|
|
|
1
1
|
export type SplitType = "chars" | "words" | "lines";
|
|
2
2
|
/** Valid ordered combinations of split types (chars → words → lines). */
|
|
3
3
|
export type SplitTypeOption = SplitType | ["chars"] | ["words"] | ["lines"] | ["chars", "words"] | ["chars", "lines"] | ["words", "lines"] | ["chars", "words", "lines"];
|
|
4
|
-
|
|
5
|
-
|
|
4
|
+
/** Extract individual SplitType members from a SplitTypeOption. */
|
|
5
|
+
type InferTypes<T extends SplitTypeOption> = T extends SplitType ? T : T extends readonly (infer U)[] ? U extends SplitType ? U : never : never;
|
|
6
|
+
export interface SplitTextOptions<T extends SplitTypeOption = ["chars", "words", "lines"]> {
|
|
7
|
+
type?: T;
|
|
6
8
|
tag?: string;
|
|
7
9
|
children?: boolean;
|
|
8
|
-
mask?: boolean |
|
|
10
|
+
mask?: boolean | NoInfer<InferTypes<T>>[];
|
|
9
11
|
resize?: boolean;
|
|
10
12
|
style?: {
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
13
|
+
[K in NoInfer<InferTypes<T>>]?: Partial<CSSStyleDeclaration>;
|
|
14
|
+
} & {
|
|
15
|
+
mask?: Partial<CSSStyleDeclaration> | {
|
|
16
|
+
[K in NoInfer<InferTypes<T>>]?: Partial<CSSStyleDeclaration>;
|
|
17
|
+
};
|
|
15
18
|
};
|
|
16
19
|
class?: {
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
20
|
+
[K in NoInfer<InferTypes<T>>]?: string;
|
|
21
|
+
} & {
|
|
22
|
+
mask?: string | {
|
|
23
|
+
[K in NoInfer<InferTypes<T>>]?: string;
|
|
24
|
+
};
|
|
21
25
|
};
|
|
22
26
|
}
|
|
23
27
|
type WF = () => {
|
|
24
28
|
outer: Node;
|
|
25
29
|
inner: HTMLElement;
|
|
26
30
|
};
|
|
27
|
-
export declare class SplitText {
|
|
31
|
+
export declare class SplitText<T extends SplitTypeOption = ["chars", "words", "lines"]> {
|
|
28
32
|
readonly dom: HTMLElement | HTMLElement[];
|
|
29
33
|
readonly chars: HTMLElement[];
|
|
30
34
|
readonly words: HTMLElement[];
|
|
@@ -46,15 +50,25 @@ export declare class SplitText {
|
|
|
46
50
|
/** @internal */ _textIndent: string;
|
|
47
51
|
/** @internal */ _styles: SplitTextOptions["style"];
|
|
48
52
|
/** @internal */ _classes: SplitTextOptions["class"];
|
|
53
|
+
/** @internal */ _maskStyleMap: {
|
|
54
|
+
chars?: Partial<CSSStyleDeclaration>;
|
|
55
|
+
words?: Partial<CSSStyleDeclaration>;
|
|
56
|
+
lines?: Partial<CSSStyleDeclaration>;
|
|
57
|
+
} | null;
|
|
58
|
+
/** @internal */ _maskClassMap: {
|
|
59
|
+
chars?: string;
|
|
60
|
+
words?: string;
|
|
61
|
+
lines?: string;
|
|
62
|
+
} | null;
|
|
49
63
|
/** @internal */ _el: HTMLElement;
|
|
50
64
|
/** @internal */ _instances: SplitText[] | null;
|
|
51
|
-
constructor(target: HTMLElement | HTMLElement[] | ArrayLike<HTMLElement> | string, options?: SplitTextOptions);
|
|
65
|
+
constructor(target: HTMLElement | HTMLElement[] | ArrayLike<HTMLElement> | string, options?: SplitTextOptions<T>);
|
|
52
66
|
/** @internal — create a styled inline-block element. */
|
|
53
67
|
_makeEl(dataAttr: string, text?: string): HTMLElement;
|
|
54
68
|
/** @internal — create a mask wrapper element. */
|
|
55
|
-
_makeMask(display: string, key: string): HTMLElement;
|
|
69
|
+
_makeMask(display: string, key: string, type: SplitType): HTMLElement;
|
|
56
70
|
/** @internal — wrap element in mask if needed, return the outermost node. */
|
|
57
|
-
_wrapMask(el: HTMLElement, flag: number, display: string, key: string, maskArr: HTMLElement[]): HTMLElement;
|
|
71
|
+
_wrapMask(el: HTMLElement, flag: number, display: string, key: string, maskArr: HTMLElement[], type: SplitType): HTMLElement;
|
|
58
72
|
/** @internal — append node into parent, optionally wrapping via factory. */
|
|
59
73
|
_append(parent: Node, node: Node, wf: WF | null, wordEl?: HTMLElement): void;
|
|
60
74
|
/** @internal — apply text-decoration + color to an element. */
|
package/dist/split-text/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{a}from"../chunk-
|
|
1
|
+
import{a}from"../chunk-77ab0s89.js";import"../chunk-fh0qxmf2.js";export{a as SplitText};
|
package/package.json
CHANGED
package/dist/chunk-34xh7zzz.js
DELETED
|
@@ -1,2 +0,0 @@
|
|
|
1
|
-
import{d as L,g as a,h as r}from"./chunk-fh0qxmf2.js";var I=1,B=2,K=4,C="inline-block",f="nowrap",E="baseline",S="0px",g="block",m="maskChar",p="maskWord",l="maskLine",t=/^\s+$/,e=/(\s+)/,c=",div,span,svg,img,br,hr,canvas,video,audio,iframe,input,textarea,select,button,picture,figure,",w={u:"underline",ins:"underline",s:"line-through",strike:"line-through",del:"line-through"};class i{dom;chars;words;lines;masks;_n;_k;_g;_j;_f=[];_o=new Map;_i=null;_h=0;_l=!1;_c="";_d;_e;_a;_b=null;constructor(z,J={}){let F;if(typeof z==="string"){let q=r(z);if(q.length>1)F=q;else{let $=q[0]??a(z);if(!$)throw Error("SplitText: element not found");F=$}}else F=z;if(J.children){if(Array.isArray(F)||typeof F==="object"&&F!==null&&"length"in F&&typeof F.item==="function")F=Array.from(F).flatMap((U)=>Array.from(U.children));else F=Array.from(F.children);let{children:q,...$}=J;J=$}if(Array.isArray(F)||typeof F==="object"&&F!==null&&"length"in F&&typeof F.item==="function"){let q=Array.from(F);if(q.length===0)throw Error("SplitText: empty element array");this._b=q.map(($)=>new i($,J)),this.dom=q,this.chars=this._b.flatMap(($)=>$.chars),this.words=this._b.flatMap(($)=>$.words),this.lines=this._b.flatMap(($)=>$.lines),this.masks={chars:this._b.flatMap(($)=>$.masks.chars),words:this._b.flatMap(($)=>$.masks.words),lines:this._b.flatMap(($)=>$.masks.lines)},this._n="",this._k=0,this._g=0,this._j="";return}let G=F;this._a=G,this.dom=G,this._n=G.innerHTML,this.chars=[],this.words=[],this.lines=[],this.masks={chars:[],words:[],lines:[]};let Q=J.type?Array.isArray(J.type)?J.type:[J.type]:["chars","words","lines"],Y=0;for(let q of Q)if(q==="chars")Y|=I;else if(q==="words")Y|=B;else if(q==="lines")Y|=K;this._k=Y,this._j=J.tag??"span";let D=0;if(J.mask===!0)D=Y;else if(Array.isArray(J.mask)){for(let q of J.mask)if(q==="chars")D|=I;else if(q==="words")D|=B;else if(q==="lines")D|=K}if(this._g=D,this._d=J.style,this._e=J.class,this._w(),(J.resize??!0)&&Y&K)this._x()}_p(z,J){let F=document.createElement(this._j);if(z)F.dataset[z]="";if(F.style.display=C,J!==void 0)F.textContent=J;return F}_s(z,J){let F=document.createElement(this._j);if(F.dataset[J]="",F.style.overflow="hidden",F.style.display=z,this._d?.mask)Object.assign(F.style,this._d.mask);if(this._e?.mask)F.classList.add(this._e.mask);return F}_r(z,J,F,H,G){if(this._g&J){let Q=this._s(F,H);return Q.appendChild(z),G.push(Q),Q}return z}_m(z,J,F,H){if(F){let{outer:G,inner:Q}=F();if(Q.appendChild(J),H)this._o.set(H,G);z.appendChild(G)}else z.appendChild(J)}_q(z,J,F){if(z.style.textDecoration=J,F)z.style.textDecorationColor=F}_w(){this._l=!0;let z=this._a,J=L(z),F=J?parseFloat(J.letterSpacing)||0:0;if(this._c=J?J.textIndent:"",this._c&&this._c!==S)z.style.textIndent="0";let H=this._k,G=!!(H&I),Q=!!(H&B),Y=!!(H&K),D=Q||Y,q=!!(this._g&I),$=new Map,U=new Set,O=(R)=>{for(let j of Array.from(R.childNodes))if(j.nodeType===1){let X=j.tagName.toLowerCase();if(w[X]){let b=L(j)?.textDecorationColor;if(b)$.set(j,b)}if(c.includes(","+X+",")&&L(j)?.display==="contents")U.add(j);O(j)}};O(z);let d=Array.from(z.childNodes),M=document.createDocumentFragment();z.replaceChildren();let W=(R,j,X,b)=>{if(R.nodeType===3){let Z=(R.textContent??"").split(e);for(let N of Z){if(!N)continue;if(t.test(N)){M.appendChild(document.createTextNode(N));continue}let V=D?this._p(Q?"word":""):null;if(V){if(V.style.whiteSpace=f,X&&!G)this._q(V,X,b)}if(G){let P=[...N],u=this.chars.length;for(let T=0;T<P.length;T++){let x=this._p("char",P[T]);if(F&&T<P.length-1)x.style.marginRight=`${F}px`;if(X)this._q(x,X,b);if(this.chars.push(x),this._d?.chars)Object.assign(x.style,this._d.chars);if(this._e?.chars)x.classList.add(this._e.chars);let y=q?this._r(x,I,C,m,this.masks.chars):x;if(V)V.appendChild(y)}if(!V){let T=j?j():null,x=T?T.inner:M;for(let y=u;y<this.chars.length;y++){let k=this.chars[y];x.appendChild(q&&k.parentElement?.dataset?.[m]!==void 0?k.parentElement:k)}if(T)M.appendChild(T.outer)}}else if(V){if(V.textContent=N,F)V.style.letterSpacing=`${F}px`}if(V){if(Q){if(this.words.push(V),this._d?.words)Object.assign(V.style,this._d.words);if(this._e?.words)V.classList.add(this._e.words)}this._f.push(V);let P=this._g&B?this._r(V,B,C,p,this.masks.words):V;this._m(M,P,j,V)}else if(!G)this._m(M,document.createTextNode(N),j)}return}if(R.nodeType!==1)return;let v=R,h=v.tagName.toLowerCase();if(c.includes(","+h+",")){if(U.has(v)){let V=M,P=document.createDocumentFragment();M=P;for(let T of Array.from(v.childNodes))W(T,j,X,b);M=V;let u=v.cloneNode(!1);u.appendChild(P),M.appendChild(u);return}let Z=v.cloneNode(!0);if(X)this._q(Z,X,b);let N=L(v)?.verticalAlign;if(N&&N!==E)Z.style.verticalAlign=N;if(D){let V=this._p(Q?"word":"");if(V.style.whiteSpace=f,N&&N!==E)V.style.verticalAlign=N;if(V.appendChild(Z),Q){if(this.words.push(V),this._d?.words)Object.assign(V.style,this._d.words);if(this._e?.words)V.classList.add(this._e.words)}this._f.push(V);let P=this._g&B?this._r(V,B,C,p,this.masks.words):V;this._m(M,P,j,V)}else this._m(M,Z,j);return}let s=()=>{let Z=v.cloneNode(!1);if(j){let{outer:N,inner:V}=j();return V.appendChild(Z),{outer:N,inner:Z}}return{outer:Z,inner:Z}},_=w[h],n=_?X?`${X} ${_}`:_:X,o=_?$.get(v)||b:b;for(let Z of Array.from(v.childNodes))W(Z,s,n,o)};for(let R of d)W(R,null,"","");z.appendChild(M);let A=!!(this._c&&this._c!==S);if(Y)this._y(A);else if(A){let R=Q?this.words[0]:G?this.chars[0]:null;if(R)R.style.marginLeft=this._c,z.style.textIndent="0"}this._l=!1}_y(z){if(z&&this._f[0])this._f[0].style.marginLeft=this._c;this._t();let J=[];if(typeof document.fonts?.status==="string"&&document.fonts.status!=="loaded")J.push(document.fonts.ready);let F=this._a.querySelectorAll("img");for(let H=0;H<F.length;H++){let G=F[H];if(!G.complete)J.push(new Promise((Q)=>{G.addEventListener("load",Q,{once:!0}),G.addEventListener("error",Q,{once:!0})}))}if(J.length){let H=this._a.offsetHeight===0&&this._a.parentElement?this._a.parentElement:this._a,G=H.offsetHeight;Promise.all(J).then(()=>{if(H.offsetHeight!==G)this.reflow()})}}_u(z){return this._o.get(z)??z}_t(){let z=this._f;if(!z.length)return;let J=z[0].offsetTop,F=J+z[0].offsetHeight,H=[],G=[];for(let q of z){let $=q.offsetTop,U=$+q.offsetHeight;if($<F&&U>J)J=Math.min(J,$),F=Math.max(F,U);else G.push(H),H=[],J=$,F=U;H.push(q)}if(H.length)G.push(H);let Q=!!(this._c&&this._c!==S);if(Q&&z[0])z[0].style.marginLeft="";let Y=!!(this._g&K),D=document.createDocumentFragment();for(let q=0;q<G.length;q++){let $=G[q],U=document.createElement(this._j);if(U.dataset.line="",U.style.display=g,q===0&&Q)U.style.paddingLeft=this._c;for(let O=0;O<$.length;O++){if(O>0)U.appendChild(document.createTextNode(" "));U.appendChild(this._u($[O]))}if(this.lines.push(U),this._d?.lines)Object.assign(U.style,this._d.lines);if(this._e?.lines)U.classList.add(this._e.lines);if(Y){let O=this._s(g,l);O.appendChild(U),this.masks.lines.push(O),D.appendChild(O)}else D.appendChild(U)}this._a.replaceChildren(D)}_x(){let z=this._a.offsetParent?this._a.offsetParent.offsetWidth:window.innerWidth,J=()=>{if(this._l)return;let H=this._a.offsetParent,G=H?H.offsetWidth:window.innerWidth;if(G===z)return;if(z=G,this._h)cancelAnimationFrame(this._h);this._h=requestAnimationFrame(()=>this.reflow())};this._i=new ResizeObserver(J);let F=this._a.offsetParent??this._a.parentElement;if(F)this._i.observe(F);else this._i.observe(this._a)}reflow(){if(this._b){this._b.forEach((J)=>J.reflow()),this._v();return}if(!(this._k&K)||this._l)return;let z=document.createDocumentFragment();for(let J=0;J<this._f.length;J++){if(J>0)z.appendChild(document.createTextNode(" "));z.appendChild(this._u(this._f[J]))}if(this._a.replaceChildren(z),this.lines.length=0,this.masks.lines.length=0,this._c&&this._c!==S&&this._f[0])this._f[0].style.marginLeft=this._c;this._t()}revert(){if(this._b){this._b.forEach((z)=>z.revert()),this._v();return}this.destroy(),this._a.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._b){this._b.forEach((z)=>z.destroy());return}if(this._h)cancelAnimationFrame(this._h),this._h=0;if(this._i)this._i.disconnect(),this._i=null}_v(){if(!this._b)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 z of this._b)this.chars.push(...z.chars),this.words.push(...z.words),this.lines.push(...z.lines),this.masks.chars.push(...z.masks.chars),this.masks.words.push(...z.masks.words),this.masks.lines.push(...z.masks.lines)}}
|
|
2
|
-
export{i as a};
|