svelte-prune 0.0.0 → 0.10.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.
@@ -0,0 +1,2 @@
1
+ import{F,_,w,e,t,n,r,h,a,i,Y}from"./index-k2z70ex7.js";import{u,V,j}from"./index-45rna84h.js";import{I,P,te}from"./index-fhqjbrb9.js";import{c,v,S}from"./index-jxng1156.js";import{readFile as oe}from"node:fs/promises";import z from"node:path";var fe={tables:new Map,readers:new Map,barrel:new Map},de=new Set(["tailwind-variants","tailwind-variants/lite"]),ue="tailwind-variants",me=new Set(["class","className"]);function B(s){let{start:p,end:l}=s;return{start:p,end:l}}var Z=new Map;async function ge(s){let p=await S(s.root,s.spec.srcDir),l=Z.get(s.src);if(l?.signature===p)return l.scan;let o=await he(s);return Z.set(s.src,{signature:p,scan:o}),o}function ye(s){let p=[];for(let l of s.ast.module?.content.body??[]){let o=l.type==="ExportNamedDeclaration"?l.declaration:l;if(o?.type!=="VariableDeclaration"||o.kind!=="const")continue;for(let{id:f,init:d}of o.declarations)if(f.type==="Identifier"&&d)p.push({id:f.name,init:d})}return p}function G(s){if(s.type!=="ObjectExpression")return;let p=new Map;for(let l of s.properties){if(l.type!=="Property"||l.kind!=="init")return;let o=w(l);if(o===void 0||l.computed)return;p.set(o,l)}return p}function Q(s){if(s.type==="Literal"&&!(("regex"in s)&&s.regex))return typeof s.value==="bigint"?e:s.value;if(s.type==="Identifier"&&s.name==="undefined")return;return e}function be(s,p,l){let o={module:s,name:p,config:l,variants:new Map,defaults:new Map,compounds:[],slots:!1},f=G(l);if(!f)return o.open="its config isn't an object literal",o;if(f.has("extend"))o.open="it extends another table";o.slots=f.has("slots");let d=(b)=>f.get(b)?.value,y=d("variants");if(y){let b=G(y);if(!b)return o.open="its variants aren't an object literal",o;for(let[g,M]of b){let E=M.value;o.variants.set(g,G(E)?E.properties:null)}}let T=d("defaultVariants");if(T){let b=G(T);if(b){let g=new Map;for(let[M,E]of b)g.set(M,Q(E.value));o.defaults=g}else o.defaults=e}let m=d("compoundVariants");if(m?.type==="ArrayExpression")o.compounds=m.elements.filter((b)=>b!==null);else if(m)o.compounds=[];return o}function re(s,p){let l={imports:[],exports:[]},o=(y,T)=>{for(let m of c(y)){if(!m.source||m.typeOnly)continue;let b=m.source.value;if(m.kind==="import")for(let g of m.specifiers){if(g.typeOnly)continue;l.imports.push({local:g.local,imported:g.kind==="namespace"?"*":g.kind==="default"?"default":g.imported,source:b,module:T})}else if(T)for(let g of m.specifiers){if(g.typeOnly)continue;l.exports.push({kind:g.kind,local:g.local,exported:g.exported,source:b})}}};if(!s.endsWith(".svelte"))return o(p,!0),l;let{instance:f,module:d}=I(p);if(d)o(p.slice(d.content.start,d.content.end),!0);if(f)o(p.slice(f.content.start,f.content.end),!1);return l}async function he(s){let{src:p}=s,l=await v(p),o=await Promise.all(l.map((N)=>oe(z.join(p,N),"utf8"))),f=new Map,d=new Map,y=(N,k,x)=>{let O=d.get(N)??new Map;if(d.set(N,O),O.has(k))return!1;return O.set(k,x),!0},T=(N,k)=>{let x=f.get(N);if(x&&!x.open)x.open=k};for(let[N,k]of l.entries()){if(!k.endsWith(".js")||!o[N].includes(ue))continue;let x=_(p,k);if(!x)continue;let O=new Set;for(let L of x.ast.module?.content.body??[]){if(L.type!=="ImportDeclaration"||!de.has(String(L.source.value)))continue;for(let C of L.specifiers)if(C.type==="ImportSpecifier"&&C.imported.type==="Identifier"&&C.imported.name==="tv")O.add(C.local.name)}if(O.size===0)continue;for(let{id:L,init:C}of ye(x)){if(C.type!=="CallExpression"||C.callee.type!=="Identifier"||!O.has(C.callee.name)||C.arguments.length===0||C.arguments[0].type==="SpreadElement")continue;let R=`${k}#${L}`;f.set(R,be(k,L,C.arguments[0]));let K=x.scopes.module.declarations.get(L);if(we(x,L))y(k,L,R);for(let J of K?.references??[]){let U=ae(J.parent);if(U===void 0)T(R,`${k} reads it`);else y(k,U,R)}}}if(f.size===0)return fe;let m=new Set(l),b=(N,k)=>{if(k===s.name)return s.barrelKey;if(!k.startsWith("."))return;let x=z.posix.join(z.posix.dirname(N),k);return[x,`${x}.js`,`${x}.svelte`,z.posix.join(x,"index.js")].find((O)=>m.has(O))},g={tables:f,readers:new Map,barrel:new Map,open:ie(s,l,o)},M=l.map((N,k)=>re(N,o[k])),E=new Set;for(let N=!0;N;){N=!1;for(let[k,x]of l.entries()){let{imports:O,exports:L}=M[k];for(let{kind:C,local:R,exported:K,source:J}of L){let U=b(x,J),D=U&&d.get(U);if(!D)continue;if(C==="all"){for(let[W,A]of D)if(W!=="default")N=y(x,W,A)||N}else if(C==="namespace")for(let W of D.values())T(W,`${x} re-exports it in a namespace`);else{let W=D.get(R);if(W&&K)N=y(x,K,W)||N}}for(let{local:C,imported:R,source:K,module:J}of O){let U=b(x,K),D=U&&d.get(U);if(!D)continue;let W=R==="*"?[...D.values()]:[D.get(R)];for(let A of W){if(!A)continue;let X=`${x}\x00${C}\x00${A}`;if(E.has(X))continue;if(E.add(X),R==="*"){if(x.endsWith(".svelte")||Ne(p,x,C))T(A,`${x} imports it in a namespace`)}else if(x.endsWith(".svelte")){if(J)T(A,`${x} imports it in \`<script module>\``);let q=g.readers.get(x)??new Map;q.set(C,A),g.readers.set(x,q)}else{let q=le(p,x,C);if(!q)T(A,`${x} reads it`);else for(let pe of q)N=y(x,pe,A)||N}}}}}for(let[N,k]of l.entries()){let x=k.endsWith(".svelte")?te(o[N]):P(o[N]);for(let{source:O}of x){if(O===null){g.open??=`${k} imports a module it computes`;continue}let L=b(k,O);for(let C of L&&d.get(L)?.values()||[])T(C,`${k} imports it dynamically`)}}for(let[N,k]of d.get(s.barrelKey)??[])g.barrel.set(N,k);return g}function ie(s,p,l){let o=F(s.src);for(let[f,d]of p.entries()){if(!d.endsWith(".js"))continue;for(let{source:y,local:T,imported:m}of re(d,l[f]).imports){if(s.isSpecifier(y)&&y!==s.name)return`${d} imports \`${y}\``;if(!y.startsWith(".")||y.endsWith(".css"))continue;if(o.importOf(d,y,m).kind!=="value"&&!Me(s.src,d,T))return`${d} uses a component`}}return}var ee=new Map;async function _e(s){let p=await S(s.root,s.spec.srcDir),l=ee.get(s.src);if(l?.signature===p)return l.reason;let o=(await v(s.src)).filter((y)=>y.endsWith(".js")),f=await Promise.all(o.map((y)=>oe(z.join(s.src,y),"utf8"))),d=ie(s,o,f);return ee.set(s.src,{signature:p,reason:d}),d}function we(s,p){return(s.ast.module?.content.body??[]).some((l)=>l.type==="ExportNamedDeclaration"&&l.declaration?.type==="VariableDeclaration"&&l.declaration.declarations.some(({id:o})=>o.type==="Identifier"&&o.name===p))}function ae(s){if(s.type!=="ExportSpecifier")return;let{exported:p}=s;return p.type==="Identifier"?p.name:String(p.value)}function ce(s,p,l){let o=_(s,p);if(!o)return;return o.scopes.module.declarations.get(l)??null}function le(s,p,l){let o=ce(s,p,l);if(o===void 0)return;let f=[];for(let d of o?.references??[]){let y=ae(d.parent);if(y===void 0)return;f.push(y)}return f}function Me(s,p,l){return le(s,p,l)!==void 0}function Ne(s,p,l){let o=ce(s,p,l);return o===void 0||(o?.references.length??0)>0}var ne=new WeakMap;function xe(s){let p=ne.get(s);if(!p){let l=new Map;u(s.ast,{enter(o,f){l.set(o,f)}}),p=l,ne.set(s,p)}return p}function ve(s){if(s===e)return;let p=[];for(let o of s)if(o===void 0||o===null)p.push(new Map);else if(h(o)&&o.kind==="object")p.push(o.props);else return;let l=new Map;for(let o of p)for(let[f,d]of o)l.set(f,r(l.get(f)??t(),d));for(let[o,f]of l)if(p.some((d)=>!d.has(o)))l.set(o,r(f,n));return l}function ke(s,p,l,o){let f=new Map,d=xe(s),y=s.ast.module,T=(g)=>y!=null&&B(g).start>=y.start&&B(g).end<=y.end,m=(g,M)=>{o(g).open??=M},b=s.key;for(let[g,M]of p){let E=l.get(M),N=s.scopes.instance.declarations.get(g)??s.scopes.module.declarations.get(g);if(!E||!N||N.kind!=="import"){m(M,`${b} can't be read`);continue}for(let{node:k,parent:x}of N.references){if(T(k)){m(M,`${b} reads it in \`<script module>\``);continue}if(x.type!=="CallExpression"||x.callee!==k){m(M,`${b} uses it other than by calling it`);continue}if(f.set(x,{id:M,slot:!1}),!Te(s,x,d,M,f)&&E.slots)m(M,`${b} hands on what it returns`)}}return f}function Te(s,p,l,o,f){let d=(M,E)=>{if(M?.type!=="MemberExpression"||M.object!==E||M.computed)return!1;let N=l.get(M);if(N?.type!=="CallExpression"||N.callee!==M)return!1;return f.set(N,{id:o,slot:!0}),!0},y=(M)=>{if(!M)return!1;for(let{node:E,parent:N}of M.references)if(N.type==="CallExpression"&&N.callee===E)f.set(N,{id:o,slot:!0});else return!1;return!0},T=p,m=l.get(p);if(m?.type==="CallExpression"&&m.callee.type==="Identifier"&&m.callee.name==="$derived"&&m.arguments[0]===T)T=m,m=l.get(m);if(d(m,T))return!0;if(m?.type!=="VariableDeclarator"||m.init!==T)return!1;let{id:b}=m;if(b.type==="ObjectPattern"){for(let M of b.properties)if(M.type!=="Property"||M.value.type!=="Identifier"||!y(s.scopes.bindingOf(M.value)))return!1;return!0}if(b.type!=="Identifier")return!1;return s.scopes.bindingOf(b)?.references.every(({node:M,parent:E})=>d(E,M))??!1}function Se(s){if(s===null)return;let p=s===!1?"false":s===!0?"true":s===0?"0":s;return p?String(p):"false"}function Ie(s){let p=new Map,l=new Set(s.calls.flatMap((f)=>[...f.keys()]));for(let f of l){let d=t();for(let y of s.calls)d=r(d,y.get(f)??n);p.set(f,d)}let o=new Map;for(let f of s.slotCalls)for(let[d,y]of f)o.set(d,r(o.get(d)??t(),y));return(f)=>r(p.get(f)??n,o.get(f)??t())}function Ee(s,p,l){if(l===e)return null;let o=new Set;for(let f of l){if(a(f))return null;let d=f;if(d===void 0){let T=s.defaults===e?e:s.defaults.get(p);if(T===e)return null;d=T}let y=Se(d);if(y!==void 0)o.add(y)}return o}function Ce(s,p){let l=(o)=>o==null||o===!1;return s===p||l(s)&&l(p)}function Oe(s,p,l){let o=G(p);if(!o)return!0;for(let[f,d]of o){if(me.has(f))continue;let y=d.value,T=y.type==="ArrayExpression"?y.elements.map((g)=>g?Q(g):e):[Q(y)];if(T.includes(e))continue;let m=l(f);if(m===e)continue;let b=[];for(let g of m)if(g!==void 0)b.push(g);else{let M=s.defaults===e?e:s.defaults.get(f);if(M===e)return!0;b.push(M)}if(!b.some((g)=>T.some((M)=>Ce(M,g))))return!1}return!0}function se(s,p){let l=[];for(let[o,f]of s.entries()){if(!p.has(f))continue;let d=s[o+1];l.push({start:B(f).start,end:d?B(d).start:B(f).end})}return l}function $e(s,p){if(s.open||p?.open)return;if(!p||p.calls.length===0){if(s.config.type==="ObjectExpression"&&s.config.properties.length===0)return;return{edits:[{...B(s.config),text:"{}"}],stats:{keys:0,compounds:0,emptied:!0}}}let l=Ie(p),o=[],f={keys:0,compounds:0,emptied:!1};for(let[y,T]of s.variants){if(!T)continue;let m=Ee(s,y,l(y));if(!m)continue;let b=new Set(T.filter((g)=>{let M=w(g);return M===void 0||!m.has(M)}));f.keys+=b.size,o.push(...se(T,b))}let d=new Set(s.compounds.filter((y)=>!Oe(s,y,l)));return f.compounds+=d.size,o.push(...se(s.compounds,d)),o.length>0?{edits:o,stats:f}:void 0}var H={modules:new Map,pruned:0,emptied:0,keys:0,compounds:0,kept:new Map};async function Xe(s,p,l){let o=await ge(s);if(o.tables.size===0||o.open)return H;let f=new Map,d=(m)=>{let b=f.get(m);if(!b)b={calls:[],slotCalls:[]},f.set(m,b);return b};for(let m of p){let b=m.file?z.basename(m.file):"an app module";if(m.openAll||m.libraryValues==="any")return H;for(let g of m.libraryValues??[]){let M=o.barrel.get(g);if(M)d(M).open??=`${b} imports it`}}for(let[m,b]of o.readers){let g=l(m);if(!g)continue;let M=ke(g.model,b,o.tables,d);if(M.size===0)continue;Y(g,s,{watched:M,call(E){let N=M.get(E);if(!N||E.type!=="CallExpression")return;let k=d(N.id),[x]=E.arguments,O=x===void 0?new Map:x.type==="SpreadElement"?void 0:ve(i(x,g));if(!O)k.open??=`${m} passes props it can't read`;else(N.slot?k.slotCalls:k.calls).push(O)}})}let y={...H,modules:new Map,kept:new Map};for(let[m,{open:b}]of f){let g=o.tables.get(m)?.open??b;if(g)y.kept.set(m.replace("#"," "),g)}let T=new Map;for(let m of o.tables.values()){let b=T.get(m.module)??[];b.push(m),T.set(m.module,b)}for(let[m,b]of T){let g=[];for(let N of b){let k=$e(N,f.get(`${N.module}#${N.name}`));if(!k)continue;if(g.push(...k.edits),k.stats.emptied)y.emptied++;else y.pruned++;y.keys+=k.stats.keys,y.compounds+=k.stats.compounds}if(g.length===0)continue;let M=_(s.src,m);if(!M)continue;let E=M.code;g.sort((N,k)=>N.start-k.start),y.modules.set(m,{source:E,mapped:j(V(E,0,E.length),g)})}return y}
2
+ export{_e,Xe};
@@ -0,0 +1,2 @@
1
+ var o=Symbol.for("svelte-prune.optimizers");function O(){let e=globalThis;return e[o]??=new Map,e[o]}function Ne(e,r){let t=O().get(this.getOptions().id);if(t?.rewritable(this.resourcePath))for(let n of t.analyzed)this.addDependency(n);let i=t?.load(this.resourcePath+this.resourceQuery);if(i)this.callback(null,i.code,i.map);else this.callback(null,e,r)}
2
+ export{O,Ne};
@@ -0,0 +1,2 @@
1
+ import{O}from"./index-v520xws8.js";import{G,H,X}from"./index-17bw6v3k.js";import{le,qe,p}from"./index-jxng1156.js";import{randomUUID as S}from"node:crypto";import{existsSync as E}from"node:fs";import h from"node:path";import{fileURLToPath as P}from"node:url";function Ee(e){return(e.options.mode??"production")==="production"}function ke(e){let o;try{o=e.originalSource?.()?.source()}catch{}return typeof o==="string"||Buffer.isBuffer(o)?o.toString():void 0}function Ae(e,o){let i=[];for(let{originModule:t,dependency:g}of o){let n=t?.resource,c=g?.request;if(typeof n==="string")i.push({id:e,importer:n,specifier:typeof c==="string"?c:void 0})}return i}function I(e){let o=(()=>{try{return e.resolverFactory?.get("normal")}catch{return}})();if(!o)return;return(i,t)=>new Promise((g)=>{try{o.resolve({},h.dirname(t),i,{},(n,c)=>g(n||!c?void 0:c))}catch{g(void 0)}})}var C=(()=>{let e=h.dirname(P(import.meta.url)),o=[h.join(e,"loader.js"),h.join(e,"loader.ts")];return o.find((i)=>E(i))??o[0]})();class Ce{spec;options;names;constructor(e,o,i={}){this.spec=e,this.options=o,this.names={...H,loader:C,...i}}apply(e){if(!Ee(e)){if(this.spec.tailwind!==!0)return;let r=async()=>{let d=await G(this.spec,e.context,this.names);if(d)e.getInfrastructureLogger(this.names.plugin).warn(d)};e.hooks.beforeRun.tapPromise(this.names.plugin,r),e.hooks.watchRun.tapPromise(this.names.plugin,r);return}let{WebpackError:o}=e.webpack,{spec:i}=this,t=this.names.plugin,g=p(i),n=X(i,this.options,this.names),c=S();O().set(c,n),e.hooks.shutdown?.tap(t,()=>{O().delete(c)}),e.options.module.rules.push({test:le,enforce:"pre",use:[{loader:this.names.loader,options:{id:c}}]},{test:qe,include:g.patterns.srcSegment,enforce:"pre",use:[{loader:this.names.loader,options:{id:c}}]});let y,k=async()=>{let r=await n.prepare(e.context,I(e));if(y=r.warning,r.info)e.getInfrastructureLogger(t).info(r.info);for(let d of r.report??[])console.log(d)};e.hooks.beforeRun.tapPromise(t,k),e.hooks.watchRun.tapPromise(t,k),e.hooks.thisCompilation.tap(t,(r)=>{if(y)r.warnings.push(new o(y));r.hooks.finishModules.tap(t,(d)=>{for(let l of d){let{resource:s}=l;if(typeof s!=="string")continue;let u=ke(l);if(u!==void 0)n.check(s,u);let{moduleGraph:a}=r;if(s.endsWith(".js")&&n.load(s))n.checkScriptImporters(s,[...a.getIncomingConnections(l)].map(({originModule:m})=>typeof m?.resource==="string"?m.resource:void 0));if(g.importKey(s))for(let m of Ae(s,a.getIncomingConnections(l)))n.checkLibraryImport(m);else if(n.isClosed(s)){let m=[],w=!1;for(let{originModule:b,dependency:v}of a.getIncomingConnections(l)){if(b===l)continue;m.push(typeof b?.resource==="string"?b.resource:void 0),w||=v?.type==="import()"}n.checkImporters(s,m,w)}}let f=n.error();if(f)r.errors.push(new o(f))}),r.hooks.processAssets.tap({name:t,stage:e.webpack.Compilation.PROCESS_ASSETS_STAGE_OPTIMIZE},(d)=>{let f=new Map;for(let u of Object.keys(d)){if(!u.endsWith(".css"))continue;let a=r.getAsset(u)?.source.source();if(a===void 0)continue;f.set(u,typeof a==="string"?a:new TextDecoder().decode(a))}if(f.size===0)return;let l=new Map(f),s=n.pruneStyles(f);for(let[u,a]of f){if(a===l.get(u))continue;r.updateAsset(u,new e.webpack.sources.RawSource(a))}if(s)e.getInfrastructureLogger(t).info(s)})})}}
2
+ export{Ee,ke,Ae,Ce};
package/index.d.ts ADDED
@@ -0,0 +1,209 @@
1
+ /** For a failed analysis's warning: the feature it turns off, and what happens instead. */
2
+ export type Failure = {
3
+ feature: string;
4
+ fallback: string;
5
+ };
6
+
7
+ type RewrittenSource = {
8
+ code: string;
9
+ map: SourceMap;
10
+ };
11
+
12
+ /** Library components rewritten for an app, by real path of their source. */
13
+ export type SpecializedComponents = {
14
+ sources: Map<string, RewrittenSource>;
15
+ edits: number;
16
+ /** App components whose props came from their analyzed call sites: nothing else may render them. */
17
+ closed: Set<string>;
18
+ /** How many of the app's own components `sources` holds. */
19
+ apps: number;
20
+ /** Module keys of the library components that can render. */
21
+ renderable: ReadonlySet<string>;
22
+ /** tailwind-variants tables rewritten (`sources` holds their modules). */
23
+ tables: Pick<RewrittenTables, "pruned" | "emptied" | "keys" | "compounds"> & {
24
+ modules: number;
25
+ };
26
+ report: () => string[];
27
+ /**
28
+ * Whether the analysis read `importer`'s import of library module `id` (real
29
+ * paths): `false` for one it can't see (an alias), `true` for a module whose
30
+ * imports it doesn't read (a script, a stylesheet).
31
+ */
32
+ readImport: (importer: string, id: string) => boolean;
33
+ /**
34
+ * With `styles` in the `LibrarySpec`: removes the rules of `css` that need
35
+ * a class the library's stylesheets define and nothing can render.
36
+ */
37
+ pruneStyles?: StylePruner;
38
+ };
39
+
40
+ /** Rewrites each library component `files` render, and each app component whose every call site they hold. */
41
+ export declare function specializeFiles(input: {
42
+ library: LibrarySpec;
43
+ projectRoot: string;
44
+ files: Array<{
45
+ file: string;
46
+ code: string;
47
+ }>;
48
+ options?: SpecializeOptions;
49
+ /** Aliased `.svelte` imports the bundler resolved, by `importKey`. */
50
+ resolvedImports?: ReadonlyMap<string, string>;
51
+ failure: Failure;
52
+ /** Classes `pruneStyles` keeps whatever renders: ones the app builds from data. */
53
+ safelist?: readonly SafelistEntry[];
54
+ }): Promise<SpecializedComponents | {
55
+ warning: string;
56
+ }>;
57
+
58
+ type ClassTokens = {
59
+ /** Text that may name a class contains it (`"x--"`). */
60
+ marker: string;
61
+ text(text: string): string[];
62
+ };
63
+
64
+ type LibraryClassTokens = ClassTokens & {
65
+ script(code: string, into: Set<string>): void;
66
+ };
67
+
68
+ /** A Svelte component library svelte-prune reads and rewrites. */
69
+ export type LibrarySpec = {
70
+ /** The package apps import: `"my-library"`. */
71
+ name: string;
72
+ /** The directory of its modules in the package: `"src"`. */
73
+ srcDir: string;
74
+ /** Its barrel, in `srcDir`: `"index.js"`. */
75
+ barrel: string;
76
+ /** Packages whose exports are components (an icon set): passing one as a prop passes an object. */
77
+ componentPackages: readonly string[];
78
+ /** Its context key prefix (`"my-library:"`): an app module holding one may use its contexts. */
79
+ contextKeyPrefix: string;
80
+ /** Names the library in messages: `"My Library"`. */
81
+ label: string;
82
+ /** Names the tool in messages, and starts each warning and error: `"my-plugin"`. */
83
+ tool: string;
84
+ /**
85
+ * Reads class names, for pruning the library's styles: `text` a string
86
+ * containing `marker`, `script` a whole script module. Omit to read none,
87
+ * or, with `styles`, every run of word characters and hyphens.
88
+ */
89
+ classTokens?: LibraryClassTokens;
90
+ /**
91
+ * The library's stylesheets. A production build drops the rules in the
92
+ * CSS it emits that need a class these stylesheets define and that
93
+ * nothing can render: no live component, none of the library's script
94
+ * modules, nothing in `content`. Omit to leave CSS as it is.
95
+ */
96
+ styles?: {
97
+ /**
98
+ * Files in installed packages, each `"<package>/<path>"`, where `*`
99
+ * matches within a path segment: `"my-library/css/*.css"`.
100
+ */
101
+ stylesheets: readonly string[];
102
+ /** Classes to keep whatever renders: ones the app's page sets (`"my-body"`). */
103
+ keep?: readonly string[];
104
+ };
105
+ /**
106
+ * `true` for a library whose classes are Tailwind's: its tailwind-variants
107
+ * tables are rewritten, and with Tailwind installed, every build (the dev
108
+ * server's included) writes what of it can render to
109
+ * `node_modules/.svelte-prune/<name>`, for Tailwind to scan. @default false
110
+ */
111
+ tailwind?: boolean;
112
+ };
113
+
114
+ type Run = readonly [number, number, number];
115
+
116
+ type MappedText = {
117
+ text: string;
118
+ runs: Run[];
119
+ };
120
+
121
+ type SourceMap = {
122
+ version: 3;
123
+ sources: string[];
124
+ sourcesContent: string[];
125
+ names: string[];
126
+ mappings: string;
127
+ };
128
+
129
+ type SpecializeOptions = {
130
+ /**
131
+ * Replaces an `{#if}` that renders nothing between whitespace (removing it
132
+ * would merge the two). Not empty: Svelte 3/4 warn; not text: Svelte 5
133
+ * rejects text in elements like `<colgroup>`.
134
+ */
135
+ emptyBlock?: string;
136
+ /** Remove top-level declarations nothing reads after the edits. */
137
+ dropUnused?: boolean;
138
+ /**
139
+ * Replace an `{#if}` whose only live branch is known with that branch's
140
+ * content. Only Svelte 5 renders it identically: block boundaries decide
141
+ * how Svelte 3/4 trim whitespace.
142
+ */
143
+ unwrap?: boolean;
144
+ /** Debugging: apply only the top-level edits this accepts (by index). */
145
+ editFilter?: (index: number, edit: {
146
+ start: number;
147
+ end: number;
148
+ }) => boolean;
149
+ };
150
+
151
+ type PrunedStyles = {
152
+ css: string;
153
+ /** Rules removed whole, `@keyframes` included. */
154
+ rules: number;
155
+ /** Selectors removed from rules that stay. */
156
+ selectors: number;
157
+ /** Custom property declarations removed. */
158
+ declarations: number;
159
+ };
160
+
161
+ type StylePruner = (css: string) => PrunedStyles;
162
+
163
+ type SafelistEntry = string | RegExp;
164
+
165
+ type RewrittenTables = {
166
+ /** Rewritten modules by key, with the source they were rewritten from. */
167
+ modules: Map<string, {
168
+ mapped: MappedText;
169
+ source: string;
170
+ }>;
171
+ pruned: number;
172
+ emptied: number;
173
+ keys: number;
174
+ compounds: number;
175
+ /** Tables a live component calls that keep every class, and why. */
176
+ kept: Map<string, string>;
177
+ };
178
+
179
+ export type SveltePruneOptions = {
180
+ /**
181
+ * Globs (relative to the project root) of every file that renders the
182
+ * library's components; a module outside them that imports one fails the
183
+ * build. Components imported from script, Markdown, MDX or Astro files
184
+ * keep every prop value. `node_modules` is skipped unless a pattern names it.
185
+ * @default ["src/**\/*.{svelte,svx,md,mdx,astro,js,jsx,ts,tsx,mjs,mts,cjs,cts}"]
186
+ */
187
+ content?: string[];
188
+ /**
189
+ * Replace an `{#if}` whose only live branch is known with that branch.
190
+ * Svelte 5 only: Svelte 3/4 render whitespace differently without the block.
191
+ * @default true when the installed Svelte is 5 or later
192
+ */
193
+ unwrap?: boolean;
194
+ /** Skip the per-build summary. @default false */
195
+ silent?: boolean;
196
+ /**
197
+ * Print what each build rewrote: edits, child components no longer rendered
198
+ * or bundled, and each call site's prop values. Independent of `silent`.
199
+ * @default false
200
+ */
201
+ report?: boolean;
202
+ /**
203
+ * Selectors of the library's stylesheets (`styles` in the `LibrarySpec`)
204
+ * to keep whatever renders, for classes the app builds from data at
205
+ * runtime: a class (`"x--tag--red"`, with or without its `.`) keeps every
206
+ * selector it's in, a RegExp every selector it matches (`/^\.x--tag--/`).
207
+ */
208
+ safelist?: Array<string | RegExp>;
209
+ };
package/index.js ADDED
@@ -0,0 +1 @@
1
+ import{fe}from"./index-k2z70ex7.js";export{fe as specializeFiles};