tailwind-styled-v4 5.0.35 → 5.0.37
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 +458 -339
- package/dist/analyzer.d.mts +152 -5
- package/dist/analyzer.d.ts +152 -5
- package/dist/animate.d.mts +30 -3
- package/dist/animate.d.ts +30 -3
- package/dist/cli.js +9 -6
- package/dist/cli.js.map +1 -1
- package/dist/cli.mjs +9 -6
- package/dist/cli.mjs.map +1 -1
- package/dist/compiler.d.mts +5 -0
- package/dist/compiler.d.ts +5 -0
- package/dist/compiler.js.map +1 -1
- package/dist/compiler.mjs.map +1 -1
- package/dist/devtools.d.mts +88 -2
- package/dist/devtools.d.ts +88 -2
- package/dist/engine.d.mts +557 -6
- package/dist/engine.d.ts +557 -6
- package/dist/engine.js.map +1 -1
- package/dist/engine.mjs.map +1 -1
- package/dist/index.browser.mjs +689 -508
- package/dist/index.browser.mjs.map +1 -1
- package/dist/index.d.mts +236 -9
- package/dist/index.d.ts +236 -9
- package/dist/index.js +38 -20
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +38 -20
- package/dist/index.mjs.map +1 -1
- package/dist/next.js +240 -170
- package/dist/next.js.map +1 -1
- package/dist/next.mjs +240 -170
- package/dist/next.mjs.map +1 -1
- package/dist/plugin-api.d.mts +4 -2
- package/dist/plugin-api.d.ts +4 -2
- package/dist/plugin-registry.js +39 -25
- package/dist/plugin-registry.js.map +1 -1
- package/dist/plugin-registry.mjs +39 -25
- package/dist/plugin-registry.mjs.map +1 -1
- package/dist/plugin.d.mts +165 -5
- package/dist/plugin.d.ts +165 -5
- package/dist/plugin.js +17 -0
- package/dist/plugin.js.map +1 -1
- package/dist/plugin.mjs +15 -1
- package/dist/plugin.mjs.map +1 -1
- package/dist/runtime.d.mts +38 -3
- package/dist/runtime.d.ts +38 -3
- package/dist/scanner.d.mts +58 -4
- package/dist/scanner.d.ts +58 -4
- package/dist/shared.d.mts +185 -3
- package/dist/shared.d.ts +185 -3
- package/dist/shared.js.map +1 -1
- package/dist/shared.mjs.map +1 -1
- package/dist/storybook-addon.d.mts +2 -2
- package/dist/storybook-addon.d.ts +2 -2
- package/dist/svelte.d.mts +2 -1
- package/dist/svelte.d.ts +2 -1
- package/dist/svelte.js +4 -4
- package/dist/svelte.js.map +1 -1
- package/dist/svelte.mjs +4 -4
- package/dist/svelte.mjs.map +1 -1
- package/dist/theme.d.mts +38 -3
- package/dist/theme.d.ts +38 -3
- package/dist/turbopackLoader.js.map +1 -1
- package/dist/turbopackLoader.mjs.map +1 -1
- package/dist/tw.js +9 -6
- package/dist/tw.js.map +1 -1
- package/dist/tw.mjs +9 -6
- package/dist/tw.mjs.map +1 -1
- package/dist/vite.js.map +1 -1
- package/dist/vite.mjs.map +1 -1
- package/dist/vue.d.mts +4 -1
- package/dist/vue.d.ts +4 -1
- package/dist/vue.js +4 -4
- package/dist/vue.js.map +1 -1
- package/dist/vue.mjs +4 -4
- package/dist/vue.mjs.map +1 -1
- package/native/tailwind-styled-native.linux-x64-gnu.node +0 -0
- package/native/tailwind-styled-native.node +0 -0
- package/package.json +7 -5
- package/dist/analyzeWorkspace-B1_XRfdl.d.ts +0 -134
- package/dist/analyzeWorkspace-hYfu4Hg3.d.mts +0 -134
- package/dist/index-DQI6O24n.d.mts +0 -464
- package/dist/index-NDINUhLN.d.mts +0 -90
- package/dist/index-NDINUhLN.d.ts +0 -90
- package/dist/index-UkYbyBkR.d.ts +0 -464
- package/dist/liveTokenEngine-CN9ian1R.d.ts +0 -38
- package/dist/liveTokenEngine-DKoWRtqH.d.mts +0 -38
- package/dist/schemas-DR-SLxZZ.d.mts +0 -59
- package/dist/schemas-DR-SLxZZ.d.ts +0 -59
- package/dist/trace-Dz4vmZdy.d.mts +0 -96
- package/dist/trace-Dz4vmZdy.d.ts +0 -96
- package/dist/types-DXr2PmGP.d.mts +0 -31
- package/dist/types-DXr2PmGP.d.ts +0 -31
package/dist/index.d.mts
CHANGED
|
@@ -1,12 +1,27 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
|
-
import {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
2
|
+
import { z } from 'zod';
|
|
3
|
+
|
|
4
|
+
type CSSFillMode = "none" | "forwards" | "backwards" | "both";
|
|
5
|
+
type CSSDirection = "normal" | "reverse" | "alternate" | "alternate-reverse";
|
|
6
|
+
type CSSIterationCount = number | "infinite";
|
|
7
|
+
type PresetEasing = "linear" | "ease" | "ease-in" | "ease-out" | "ease-in-out" | "step-start" | "step-end";
|
|
8
|
+
type CubicBezierEasing = `cubic-bezier(${string})`;
|
|
9
|
+
type StepsEasing = `steps(${string})`;
|
|
10
|
+
type CSSEasing = PresetEasing | CubicBezierEasing | StepsEasing;
|
|
11
|
+
interface AnimateOptions {
|
|
12
|
+
from: string;
|
|
13
|
+
to: string;
|
|
14
|
+
duration?: number;
|
|
15
|
+
easing?: CSSEasing;
|
|
16
|
+
delay?: number;
|
|
17
|
+
fill?: CSSFillMode;
|
|
18
|
+
iterations?: CSSIterationCount;
|
|
19
|
+
direction?: CSSDirection;
|
|
20
|
+
name?: string;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
type TokenMap = Record<string, string>;
|
|
24
|
+
type HtmlTagName = keyof HTMLElementTagNameMap;
|
|
10
25
|
|
|
11
26
|
/**
|
|
12
27
|
* tailwind-styled-v4 — Core Types
|
|
@@ -301,6 +316,40 @@ declare function cx(...inputs: (ClassValue | ClassValue[])[]): string;
|
|
|
301
316
|
/** @deprecated Use cx() instead. */
|
|
302
317
|
declare const cxm: typeof cx;
|
|
303
318
|
|
|
319
|
+
type TokenSubscriber = (tokens: TokenMap) => void;
|
|
320
|
+
interface LiveTokenSet {
|
|
321
|
+
vars: Record<string, string>;
|
|
322
|
+
get(name: string): string | undefined;
|
|
323
|
+
set(name: string, value: string): void;
|
|
324
|
+
setAll(tokens: TokenMap): void;
|
|
325
|
+
snapshot(): TokenMap;
|
|
326
|
+
}
|
|
327
|
+
interface LiveTokenEngineBridge {
|
|
328
|
+
getToken(name: string): string | undefined;
|
|
329
|
+
getTokens(): TokenMap;
|
|
330
|
+
setToken(name: string, value: string): void;
|
|
331
|
+
setTokens(tokens: TokenMap): void;
|
|
332
|
+
applyTokenSet(tokens: TokenMap): void;
|
|
333
|
+
subscribeTokens(fn: TokenSubscriber): () => void;
|
|
334
|
+
subscribe?(fn: TokenSubscriber): () => void;
|
|
335
|
+
}
|
|
336
|
+
declare function tokenVar(name: string): string;
|
|
337
|
+
declare function tokenRef(name: string): string;
|
|
338
|
+
declare function liveToken(tokens: TokenMap): LiveTokenSet;
|
|
339
|
+
declare function setToken(name: string, value: string): void;
|
|
340
|
+
declare function setTokens(tokens: TokenMap): void;
|
|
341
|
+
declare function applyTokenSet(tokens: TokenMap): void;
|
|
342
|
+
declare function getToken(name: string): string | undefined;
|
|
343
|
+
declare function getTokens(): TokenMap;
|
|
344
|
+
declare function subscribeTokens(fn: TokenSubscriber): () => void;
|
|
345
|
+
declare function generateTokenCssString(): string;
|
|
346
|
+
declare function createUseTokens(): () => TokenMap;
|
|
347
|
+
declare global {
|
|
348
|
+
interface Window {
|
|
349
|
+
__TW_TOKEN_ENGINE__?: LiveTokenEngineBridge;
|
|
350
|
+
}
|
|
351
|
+
}
|
|
352
|
+
|
|
304
353
|
interface ThemeConfig$1 {
|
|
305
354
|
colors: Record<string, string>;
|
|
306
355
|
spacing: Record<string, string>;
|
|
@@ -675,4 +724,182 @@ declare const v4Tokens: {
|
|
|
675
724
|
readonly fontMono: string;
|
|
676
725
|
};
|
|
677
726
|
|
|
678
|
-
|
|
727
|
+
declare const ScanWorkspaceOptionsSchema: z.ZodObject<{
|
|
728
|
+
includeExtensions: z.ZodOptional<z.ZodArray<z.ZodString>>;
|
|
729
|
+
ignoreDirectories: z.ZodOptional<z.ZodArray<z.ZodString>>;
|
|
730
|
+
useCache: z.ZodOptional<z.ZodBoolean>;
|
|
731
|
+
cacheDir: z.ZodOptional<z.ZodString>;
|
|
732
|
+
smartInvalidation: z.ZodOptional<z.ZodBoolean>;
|
|
733
|
+
}, z.core.$strip>;
|
|
734
|
+
type ScanWorkspaceOptions = z.infer<typeof ScanWorkspaceOptionsSchema>;
|
|
735
|
+
declare const ScanWorkspaceResultSchema: z.ZodObject<{
|
|
736
|
+
files: z.ZodArray<z.ZodObject<{
|
|
737
|
+
file: z.ZodString;
|
|
738
|
+
classes: z.ZodArray<z.ZodString>;
|
|
739
|
+
hash: z.ZodOptional<z.ZodString>;
|
|
740
|
+
}, z.core.$strip>>;
|
|
741
|
+
totalFiles: z.ZodNumber;
|
|
742
|
+
uniqueClasses: z.ZodArray<z.ZodString>;
|
|
743
|
+
}, z.core.$strip>;
|
|
744
|
+
type ScanWorkspaceResult = z.infer<typeof ScanWorkspaceResultSchema>;
|
|
745
|
+
|
|
746
|
+
/**
|
|
747
|
+
* Public type contracts for @tailwind-styled/analyzer.
|
|
748
|
+
* Keep this file aligned with the runtime report shape exposed by src/index.ts.
|
|
749
|
+
*/
|
|
750
|
+
|
|
751
|
+
interface ClassUsage {
|
|
752
|
+
readonly name: string;
|
|
753
|
+
readonly count: number;
|
|
754
|
+
readonly isUnused?: boolean;
|
|
755
|
+
readonly isConflict?: boolean;
|
|
756
|
+
}
|
|
757
|
+
interface ClassConflict {
|
|
758
|
+
readonly className: string;
|
|
759
|
+
readonly variants: readonly string[];
|
|
760
|
+
readonly classes: readonly string[];
|
|
761
|
+
readonly message: string;
|
|
762
|
+
}
|
|
763
|
+
interface AnalyzerClassStats {
|
|
764
|
+
readonly all: readonly ClassUsage[];
|
|
765
|
+
readonly top: readonly ClassUsage[];
|
|
766
|
+
readonly frequent: readonly ClassUsage[];
|
|
767
|
+
readonly unique: readonly ClassUsage[];
|
|
768
|
+
readonly distribution: Readonly<Record<string, number>>;
|
|
769
|
+
}
|
|
770
|
+
interface TailwindConfigSummary {
|
|
771
|
+
readonly path: string;
|
|
772
|
+
readonly loaded: boolean;
|
|
773
|
+
readonly safelistCount: number;
|
|
774
|
+
readonly customUtilityCount: number;
|
|
775
|
+
readonly warning?: string;
|
|
776
|
+
}
|
|
777
|
+
interface AnalyzerSemanticReport {
|
|
778
|
+
readonly unusedClasses: readonly ClassUsage[];
|
|
779
|
+
readonly unknownClasses: readonly ClassUsage[];
|
|
780
|
+
readonly conflicts: readonly ClassConflict[];
|
|
781
|
+
readonly tailwindConfig?: TailwindConfigSummary;
|
|
782
|
+
}
|
|
783
|
+
interface AnalyzerReport {
|
|
784
|
+
readonly root: string;
|
|
785
|
+
readonly totalFiles: number;
|
|
786
|
+
readonly uniqueClassCount: number;
|
|
787
|
+
readonly totalClassOccurrences: number;
|
|
788
|
+
readonly classStats: AnalyzerClassStats;
|
|
789
|
+
/** Alias for classStats.top — backward compat & test contract */
|
|
790
|
+
readonly topClasses: readonly ClassUsage[];
|
|
791
|
+
readonly safelist: readonly string[];
|
|
792
|
+
readonly semantic?: AnalyzerSemanticReport;
|
|
793
|
+
}
|
|
794
|
+
interface AnalyzerOptions {
|
|
795
|
+
readonly scanner?: ScanWorkspaceOptions;
|
|
796
|
+
readonly classStats?: {
|
|
797
|
+
readonly top?: number;
|
|
798
|
+
readonly frequentThreshold?: number;
|
|
799
|
+
};
|
|
800
|
+
readonly includeClass?: (className: string) => boolean;
|
|
801
|
+
readonly semantic?: boolean | {
|
|
802
|
+
readonly tailwindConfigPath?: string;
|
|
803
|
+
};
|
|
804
|
+
}
|
|
805
|
+
|
|
806
|
+
/**
|
|
807
|
+
* Analyze Tailwind class usage in a workspace and return usage statistics.
|
|
808
|
+
* Set `semantic.tailwindConfigPath` to override Tailwind config lookup.
|
|
809
|
+
* @example
|
|
810
|
+
* const report = await analyzeWorkspace("./src", {
|
|
811
|
+
* classStats: { top: 20, frequentThreshold: 2 },
|
|
812
|
+
* semantic: { tailwindConfigPath: "tailwind.config.js" },
|
|
813
|
+
* })
|
|
814
|
+
*/
|
|
815
|
+
declare function analyzeWorkspace(root: string, options?: AnalyzerOptions): Promise<AnalyzerReport>;
|
|
816
|
+
|
|
817
|
+
interface EngineMetricsSnapshot {
|
|
818
|
+
eventsReceived: number;
|
|
819
|
+
eventsProcessed: number;
|
|
820
|
+
batchesProcessed: number;
|
|
821
|
+
incrementalUpdates: number;
|
|
822
|
+
fullRescans: number;
|
|
823
|
+
skippedLargeFiles: number;
|
|
824
|
+
queueMaxSize: number;
|
|
825
|
+
lastBuildMs: number;
|
|
826
|
+
avgBuildMs: number;
|
|
827
|
+
}
|
|
828
|
+
|
|
829
|
+
interface EnginePluginContext {
|
|
830
|
+
root: string;
|
|
831
|
+
timestamp: number;
|
|
832
|
+
}
|
|
833
|
+
interface EngineWatchContext {
|
|
834
|
+
root: string;
|
|
835
|
+
timestamp: number;
|
|
836
|
+
}
|
|
837
|
+
interface EnginePlugin {
|
|
838
|
+
name: string;
|
|
839
|
+
beforeScan?(context: EnginePluginContext): void | Promise<void>;
|
|
840
|
+
afterScan?(scan: ScanWorkspaceResult, context: EnginePluginContext): ScanWorkspaceResult | undefined | Promise<ScanWorkspaceResult | undefined>;
|
|
841
|
+
transformClasses?(classes: string[], context: EnginePluginContext): string[] | undefined | Promise<string[] | undefined>;
|
|
842
|
+
beforeBuild?(scan: ScanWorkspaceResult, context: EnginePluginContext): void | Promise<void>;
|
|
843
|
+
afterBuild?(result: BuildResult, context: EnginePluginContext): BuildResult | undefined | Promise<BuildResult | undefined>;
|
|
844
|
+
onError?(error: Error, context: EnginePluginContext): void | Promise<void>;
|
|
845
|
+
beforeWatch?(context: EngineWatchContext): void | Promise<void>;
|
|
846
|
+
afterWatch?(context: EngineWatchContext): void | Promise<void>;
|
|
847
|
+
}
|
|
848
|
+
|
|
849
|
+
interface EngineOptions {
|
|
850
|
+
root?: string;
|
|
851
|
+
scanner?: ScanWorkspaceOptions;
|
|
852
|
+
compileCss?: boolean;
|
|
853
|
+
tailwindConfigPath?: string;
|
|
854
|
+
plugins?: EnginePlugin[];
|
|
855
|
+
/** Enable analyzer integration - provides semantic report (unused classes, conflicts). Default: false */
|
|
856
|
+
analyze?: boolean;
|
|
857
|
+
}
|
|
858
|
+
interface EngineWatchOptions {
|
|
859
|
+
debounceMs?: number;
|
|
860
|
+
maxEventsPerFlush?: number;
|
|
861
|
+
largeFileThreshold?: number;
|
|
862
|
+
}
|
|
863
|
+
interface BuildResult {
|
|
864
|
+
scan: ScanWorkspaceResult;
|
|
865
|
+
mergedClassList: string;
|
|
866
|
+
css: string;
|
|
867
|
+
/** Analyzer semantic report - present when analyze: true in options */
|
|
868
|
+
analysis?: {
|
|
869
|
+
unusedClasses: string[];
|
|
870
|
+
classConflicts: Array<{
|
|
871
|
+
className: string;
|
|
872
|
+
files: string[];
|
|
873
|
+
classes?: string[];
|
|
874
|
+
message?: string;
|
|
875
|
+
}>;
|
|
876
|
+
classUsage: Record<string, number>;
|
|
877
|
+
semantic?: AnalyzerSemanticReport;
|
|
878
|
+
report: AnalyzerReport;
|
|
879
|
+
};
|
|
880
|
+
}
|
|
881
|
+
type EngineBuildWatchEventType = "initial" | "change" | "unlink" | "full-rescan";
|
|
882
|
+
type EngineWatchEvent = {
|
|
883
|
+
type: EngineBuildWatchEventType;
|
|
884
|
+
filePath?: string;
|
|
885
|
+
result: BuildResult;
|
|
886
|
+
metrics?: EngineMetricsSnapshot;
|
|
887
|
+
} | {
|
|
888
|
+
type: "error";
|
|
889
|
+
filePath?: string;
|
|
890
|
+
error: string;
|
|
891
|
+
metrics?: EngineMetricsSnapshot;
|
|
892
|
+
};
|
|
893
|
+
interface TailwindStyledEngine {
|
|
894
|
+
scan(): Promise<ScanWorkspaceResult>;
|
|
895
|
+
scanWorkspace(): Promise<ScanWorkspaceResult>;
|
|
896
|
+
analyzeWorkspace(): Promise<Awaited<ReturnType<typeof analyzeWorkspace>>>;
|
|
897
|
+
generateSafelist(): Promise<string[]>;
|
|
898
|
+
build(): Promise<BuildResult>;
|
|
899
|
+
watch(onEvent: (event: EngineWatchEvent) => void, options?: EngineWatchOptions): Promise<{
|
|
900
|
+
close(): void;
|
|
901
|
+
}>;
|
|
902
|
+
}
|
|
903
|
+
declare function createEngine(rawOptions?: EngineOptions): Promise<TailwindStyledEngine>;
|
|
904
|
+
|
|
905
|
+
export { type ComponentConfig, type ContainerConfig, type ContainerEntry, type CvFn, type HtmlTagName, type InferVariantProps, type LiveTokenSet, type MergeOptions, type ParsedClass, type ParsedClassModifier, type ResolvedThemeTokens, type StateComponentEntry, type StateConfig, type StyledComponentProps, type StyledOptions, type StyledProps, type StyledSystemConfig, type StyledSystemInstance, type SubComponentEntry, type SubComponentMap, type SubComponentProps, type SystemComponentConfig, type SystemComponentFactory, type SystemTokenMap, type ThemeConfig, type ThemeTokenMap, type TokenMap, type TokenSubscriber, type TwComponentFactory, type TwObject, type TwStyledComponent, type TwSubComponent, type TwTagFactory, type TwTagFactoryAny, type VariantLiterals, applyTokenSet, cn, tokenRef as containerRef, createComponent, createEngine, createStyledSystem, createTheme, createTwMerge, createUseTokens, cssVar, cv, cx, cxm, generateContainerCss, generateStateCss, generateTokenCssString, getAllSubComponents, getContainerRegistry, getStateRegistry, getSubComponent, getToken, getTokens, liveToken, mergeWithRules, processContainer, processState, registerSubComponent, resolveStyledClassName, server, setToken, setTokens, styled, subscribeTokens, t, tokenRef, tokenVar, tw, twMerge, twVar, v4Tokens, withSubComponents };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,12 +1,27 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
|
-
import {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
2
|
+
import { z } from 'zod';
|
|
3
|
+
|
|
4
|
+
type CSSFillMode = "none" | "forwards" | "backwards" | "both";
|
|
5
|
+
type CSSDirection = "normal" | "reverse" | "alternate" | "alternate-reverse";
|
|
6
|
+
type CSSIterationCount = number | "infinite";
|
|
7
|
+
type PresetEasing = "linear" | "ease" | "ease-in" | "ease-out" | "ease-in-out" | "step-start" | "step-end";
|
|
8
|
+
type CubicBezierEasing = `cubic-bezier(${string})`;
|
|
9
|
+
type StepsEasing = `steps(${string})`;
|
|
10
|
+
type CSSEasing = PresetEasing | CubicBezierEasing | StepsEasing;
|
|
11
|
+
interface AnimateOptions {
|
|
12
|
+
from: string;
|
|
13
|
+
to: string;
|
|
14
|
+
duration?: number;
|
|
15
|
+
easing?: CSSEasing;
|
|
16
|
+
delay?: number;
|
|
17
|
+
fill?: CSSFillMode;
|
|
18
|
+
iterations?: CSSIterationCount;
|
|
19
|
+
direction?: CSSDirection;
|
|
20
|
+
name?: string;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
type TokenMap = Record<string, string>;
|
|
24
|
+
type HtmlTagName = keyof HTMLElementTagNameMap;
|
|
10
25
|
|
|
11
26
|
/**
|
|
12
27
|
* tailwind-styled-v4 — Core Types
|
|
@@ -301,6 +316,40 @@ declare function cx(...inputs: (ClassValue | ClassValue[])[]): string;
|
|
|
301
316
|
/** @deprecated Use cx() instead. */
|
|
302
317
|
declare const cxm: typeof cx;
|
|
303
318
|
|
|
319
|
+
type TokenSubscriber = (tokens: TokenMap) => void;
|
|
320
|
+
interface LiveTokenSet {
|
|
321
|
+
vars: Record<string, string>;
|
|
322
|
+
get(name: string): string | undefined;
|
|
323
|
+
set(name: string, value: string): void;
|
|
324
|
+
setAll(tokens: TokenMap): void;
|
|
325
|
+
snapshot(): TokenMap;
|
|
326
|
+
}
|
|
327
|
+
interface LiveTokenEngineBridge {
|
|
328
|
+
getToken(name: string): string | undefined;
|
|
329
|
+
getTokens(): TokenMap;
|
|
330
|
+
setToken(name: string, value: string): void;
|
|
331
|
+
setTokens(tokens: TokenMap): void;
|
|
332
|
+
applyTokenSet(tokens: TokenMap): void;
|
|
333
|
+
subscribeTokens(fn: TokenSubscriber): () => void;
|
|
334
|
+
subscribe?(fn: TokenSubscriber): () => void;
|
|
335
|
+
}
|
|
336
|
+
declare function tokenVar(name: string): string;
|
|
337
|
+
declare function tokenRef(name: string): string;
|
|
338
|
+
declare function liveToken(tokens: TokenMap): LiveTokenSet;
|
|
339
|
+
declare function setToken(name: string, value: string): void;
|
|
340
|
+
declare function setTokens(tokens: TokenMap): void;
|
|
341
|
+
declare function applyTokenSet(tokens: TokenMap): void;
|
|
342
|
+
declare function getToken(name: string): string | undefined;
|
|
343
|
+
declare function getTokens(): TokenMap;
|
|
344
|
+
declare function subscribeTokens(fn: TokenSubscriber): () => void;
|
|
345
|
+
declare function generateTokenCssString(): string;
|
|
346
|
+
declare function createUseTokens(): () => TokenMap;
|
|
347
|
+
declare global {
|
|
348
|
+
interface Window {
|
|
349
|
+
__TW_TOKEN_ENGINE__?: LiveTokenEngineBridge;
|
|
350
|
+
}
|
|
351
|
+
}
|
|
352
|
+
|
|
304
353
|
interface ThemeConfig$1 {
|
|
305
354
|
colors: Record<string, string>;
|
|
306
355
|
spacing: Record<string, string>;
|
|
@@ -675,4 +724,182 @@ declare const v4Tokens: {
|
|
|
675
724
|
readonly fontMono: string;
|
|
676
725
|
};
|
|
677
726
|
|
|
678
|
-
|
|
727
|
+
declare const ScanWorkspaceOptionsSchema: z.ZodObject<{
|
|
728
|
+
includeExtensions: z.ZodOptional<z.ZodArray<z.ZodString>>;
|
|
729
|
+
ignoreDirectories: z.ZodOptional<z.ZodArray<z.ZodString>>;
|
|
730
|
+
useCache: z.ZodOptional<z.ZodBoolean>;
|
|
731
|
+
cacheDir: z.ZodOptional<z.ZodString>;
|
|
732
|
+
smartInvalidation: z.ZodOptional<z.ZodBoolean>;
|
|
733
|
+
}, z.core.$strip>;
|
|
734
|
+
type ScanWorkspaceOptions = z.infer<typeof ScanWorkspaceOptionsSchema>;
|
|
735
|
+
declare const ScanWorkspaceResultSchema: z.ZodObject<{
|
|
736
|
+
files: z.ZodArray<z.ZodObject<{
|
|
737
|
+
file: z.ZodString;
|
|
738
|
+
classes: z.ZodArray<z.ZodString>;
|
|
739
|
+
hash: z.ZodOptional<z.ZodString>;
|
|
740
|
+
}, z.core.$strip>>;
|
|
741
|
+
totalFiles: z.ZodNumber;
|
|
742
|
+
uniqueClasses: z.ZodArray<z.ZodString>;
|
|
743
|
+
}, z.core.$strip>;
|
|
744
|
+
type ScanWorkspaceResult = z.infer<typeof ScanWorkspaceResultSchema>;
|
|
745
|
+
|
|
746
|
+
/**
|
|
747
|
+
* Public type contracts for @tailwind-styled/analyzer.
|
|
748
|
+
* Keep this file aligned with the runtime report shape exposed by src/index.ts.
|
|
749
|
+
*/
|
|
750
|
+
|
|
751
|
+
interface ClassUsage {
|
|
752
|
+
readonly name: string;
|
|
753
|
+
readonly count: number;
|
|
754
|
+
readonly isUnused?: boolean;
|
|
755
|
+
readonly isConflict?: boolean;
|
|
756
|
+
}
|
|
757
|
+
interface ClassConflict {
|
|
758
|
+
readonly className: string;
|
|
759
|
+
readonly variants: readonly string[];
|
|
760
|
+
readonly classes: readonly string[];
|
|
761
|
+
readonly message: string;
|
|
762
|
+
}
|
|
763
|
+
interface AnalyzerClassStats {
|
|
764
|
+
readonly all: readonly ClassUsage[];
|
|
765
|
+
readonly top: readonly ClassUsage[];
|
|
766
|
+
readonly frequent: readonly ClassUsage[];
|
|
767
|
+
readonly unique: readonly ClassUsage[];
|
|
768
|
+
readonly distribution: Readonly<Record<string, number>>;
|
|
769
|
+
}
|
|
770
|
+
interface TailwindConfigSummary {
|
|
771
|
+
readonly path: string;
|
|
772
|
+
readonly loaded: boolean;
|
|
773
|
+
readonly safelistCount: number;
|
|
774
|
+
readonly customUtilityCount: number;
|
|
775
|
+
readonly warning?: string;
|
|
776
|
+
}
|
|
777
|
+
interface AnalyzerSemanticReport {
|
|
778
|
+
readonly unusedClasses: readonly ClassUsage[];
|
|
779
|
+
readonly unknownClasses: readonly ClassUsage[];
|
|
780
|
+
readonly conflicts: readonly ClassConflict[];
|
|
781
|
+
readonly tailwindConfig?: TailwindConfigSummary;
|
|
782
|
+
}
|
|
783
|
+
interface AnalyzerReport {
|
|
784
|
+
readonly root: string;
|
|
785
|
+
readonly totalFiles: number;
|
|
786
|
+
readonly uniqueClassCount: number;
|
|
787
|
+
readonly totalClassOccurrences: number;
|
|
788
|
+
readonly classStats: AnalyzerClassStats;
|
|
789
|
+
/** Alias for classStats.top — backward compat & test contract */
|
|
790
|
+
readonly topClasses: readonly ClassUsage[];
|
|
791
|
+
readonly safelist: readonly string[];
|
|
792
|
+
readonly semantic?: AnalyzerSemanticReport;
|
|
793
|
+
}
|
|
794
|
+
interface AnalyzerOptions {
|
|
795
|
+
readonly scanner?: ScanWorkspaceOptions;
|
|
796
|
+
readonly classStats?: {
|
|
797
|
+
readonly top?: number;
|
|
798
|
+
readonly frequentThreshold?: number;
|
|
799
|
+
};
|
|
800
|
+
readonly includeClass?: (className: string) => boolean;
|
|
801
|
+
readonly semantic?: boolean | {
|
|
802
|
+
readonly tailwindConfigPath?: string;
|
|
803
|
+
};
|
|
804
|
+
}
|
|
805
|
+
|
|
806
|
+
/**
|
|
807
|
+
* Analyze Tailwind class usage in a workspace and return usage statistics.
|
|
808
|
+
* Set `semantic.tailwindConfigPath` to override Tailwind config lookup.
|
|
809
|
+
* @example
|
|
810
|
+
* const report = await analyzeWorkspace("./src", {
|
|
811
|
+
* classStats: { top: 20, frequentThreshold: 2 },
|
|
812
|
+
* semantic: { tailwindConfigPath: "tailwind.config.js" },
|
|
813
|
+
* })
|
|
814
|
+
*/
|
|
815
|
+
declare function analyzeWorkspace(root: string, options?: AnalyzerOptions): Promise<AnalyzerReport>;
|
|
816
|
+
|
|
817
|
+
interface EngineMetricsSnapshot {
|
|
818
|
+
eventsReceived: number;
|
|
819
|
+
eventsProcessed: number;
|
|
820
|
+
batchesProcessed: number;
|
|
821
|
+
incrementalUpdates: number;
|
|
822
|
+
fullRescans: number;
|
|
823
|
+
skippedLargeFiles: number;
|
|
824
|
+
queueMaxSize: number;
|
|
825
|
+
lastBuildMs: number;
|
|
826
|
+
avgBuildMs: number;
|
|
827
|
+
}
|
|
828
|
+
|
|
829
|
+
interface EnginePluginContext {
|
|
830
|
+
root: string;
|
|
831
|
+
timestamp: number;
|
|
832
|
+
}
|
|
833
|
+
interface EngineWatchContext {
|
|
834
|
+
root: string;
|
|
835
|
+
timestamp: number;
|
|
836
|
+
}
|
|
837
|
+
interface EnginePlugin {
|
|
838
|
+
name: string;
|
|
839
|
+
beforeScan?(context: EnginePluginContext): void | Promise<void>;
|
|
840
|
+
afterScan?(scan: ScanWorkspaceResult, context: EnginePluginContext): ScanWorkspaceResult | undefined | Promise<ScanWorkspaceResult | undefined>;
|
|
841
|
+
transformClasses?(classes: string[], context: EnginePluginContext): string[] | undefined | Promise<string[] | undefined>;
|
|
842
|
+
beforeBuild?(scan: ScanWorkspaceResult, context: EnginePluginContext): void | Promise<void>;
|
|
843
|
+
afterBuild?(result: BuildResult, context: EnginePluginContext): BuildResult | undefined | Promise<BuildResult | undefined>;
|
|
844
|
+
onError?(error: Error, context: EnginePluginContext): void | Promise<void>;
|
|
845
|
+
beforeWatch?(context: EngineWatchContext): void | Promise<void>;
|
|
846
|
+
afterWatch?(context: EngineWatchContext): void | Promise<void>;
|
|
847
|
+
}
|
|
848
|
+
|
|
849
|
+
interface EngineOptions {
|
|
850
|
+
root?: string;
|
|
851
|
+
scanner?: ScanWorkspaceOptions;
|
|
852
|
+
compileCss?: boolean;
|
|
853
|
+
tailwindConfigPath?: string;
|
|
854
|
+
plugins?: EnginePlugin[];
|
|
855
|
+
/** Enable analyzer integration - provides semantic report (unused classes, conflicts). Default: false */
|
|
856
|
+
analyze?: boolean;
|
|
857
|
+
}
|
|
858
|
+
interface EngineWatchOptions {
|
|
859
|
+
debounceMs?: number;
|
|
860
|
+
maxEventsPerFlush?: number;
|
|
861
|
+
largeFileThreshold?: number;
|
|
862
|
+
}
|
|
863
|
+
interface BuildResult {
|
|
864
|
+
scan: ScanWorkspaceResult;
|
|
865
|
+
mergedClassList: string;
|
|
866
|
+
css: string;
|
|
867
|
+
/** Analyzer semantic report - present when analyze: true in options */
|
|
868
|
+
analysis?: {
|
|
869
|
+
unusedClasses: string[];
|
|
870
|
+
classConflicts: Array<{
|
|
871
|
+
className: string;
|
|
872
|
+
files: string[];
|
|
873
|
+
classes?: string[];
|
|
874
|
+
message?: string;
|
|
875
|
+
}>;
|
|
876
|
+
classUsage: Record<string, number>;
|
|
877
|
+
semantic?: AnalyzerSemanticReport;
|
|
878
|
+
report: AnalyzerReport;
|
|
879
|
+
};
|
|
880
|
+
}
|
|
881
|
+
type EngineBuildWatchEventType = "initial" | "change" | "unlink" | "full-rescan";
|
|
882
|
+
type EngineWatchEvent = {
|
|
883
|
+
type: EngineBuildWatchEventType;
|
|
884
|
+
filePath?: string;
|
|
885
|
+
result: BuildResult;
|
|
886
|
+
metrics?: EngineMetricsSnapshot;
|
|
887
|
+
} | {
|
|
888
|
+
type: "error";
|
|
889
|
+
filePath?: string;
|
|
890
|
+
error: string;
|
|
891
|
+
metrics?: EngineMetricsSnapshot;
|
|
892
|
+
};
|
|
893
|
+
interface TailwindStyledEngine {
|
|
894
|
+
scan(): Promise<ScanWorkspaceResult>;
|
|
895
|
+
scanWorkspace(): Promise<ScanWorkspaceResult>;
|
|
896
|
+
analyzeWorkspace(): Promise<Awaited<ReturnType<typeof analyzeWorkspace>>>;
|
|
897
|
+
generateSafelist(): Promise<string[]>;
|
|
898
|
+
build(): Promise<BuildResult>;
|
|
899
|
+
watch(onEvent: (event: EngineWatchEvent) => void, options?: EngineWatchOptions): Promise<{
|
|
900
|
+
close(): void;
|
|
901
|
+
}>;
|
|
902
|
+
}
|
|
903
|
+
declare function createEngine(rawOptions?: EngineOptions): Promise<TailwindStyledEngine>;
|
|
904
|
+
|
|
905
|
+
export { type ComponentConfig, type ContainerConfig, type ContainerEntry, type CvFn, type HtmlTagName, type InferVariantProps, type LiveTokenSet, type MergeOptions, type ParsedClass, type ParsedClassModifier, type ResolvedThemeTokens, type StateComponentEntry, type StateConfig, type StyledComponentProps, type StyledOptions, type StyledProps, type StyledSystemConfig, type StyledSystemInstance, type SubComponentEntry, type SubComponentMap, type SubComponentProps, type SystemComponentConfig, type SystemComponentFactory, type SystemTokenMap, type ThemeConfig, type ThemeTokenMap, type TokenMap, type TokenSubscriber, type TwComponentFactory, type TwObject, type TwStyledComponent, type TwSubComponent, type TwTagFactory, type TwTagFactoryAny, type VariantLiterals, applyTokenSet, cn, tokenRef as containerRef, createComponent, createEngine, createStyledSystem, createTheme, createTwMerge, createUseTokens, cssVar, cv, cx, cxm, generateContainerCss, generateStateCss, generateTokenCssString, getAllSubComponents, getContainerRegistry, getStateRegistry, getSubComponent, getToken, getTokens, liveToken, mergeWithRules, processContainer, processState, registerSubComponent, resolveStyledClassName, server, setToken, setTokens, styled, subscribeTokens, t, tokenRef, tokenVar, tw, twMerge, twVar, v4Tokens, withSubComponents };
|
package/dist/index.js
CHANGED
|
@@ -5228,17 +5228,12 @@ function hashState(tag, state) {
|
|
|
5228
5228
|
_hashStateCache.set(sortedKey, id);
|
|
5229
5229
|
return id;
|
|
5230
5230
|
}
|
|
5231
|
-
|
|
5232
|
-
function twClassesToCss(classes) {
|
|
5233
|
-
const cached = _twClassesToCssCache.get(classes);
|
|
5234
|
-
if (cached !== void 0) return cached;
|
|
5231
|
+
function generateStateRules(id, state) {
|
|
5235
5232
|
const native = getNativeBinding();
|
|
5236
|
-
if (!native?.
|
|
5237
|
-
throw new Error("FATAL: Native binding '
|
|
5233
|
+
if (!native?.generateRuntimeStateCss) {
|
|
5234
|
+
throw new Error("FATAL: Native binding 'generateRuntimeStateCss' is required but not available.");
|
|
5238
5235
|
}
|
|
5239
|
-
|
|
5240
|
-
_twClassesToCssCache.set(classes, result);
|
|
5241
|
-
return result;
|
|
5236
|
+
return native.generateRuntimeStateCss(id, JSON.stringify(state), null).map((rule) => rule.cssRule);
|
|
5242
5237
|
}
|
|
5243
5238
|
var _staticCssDetected = /* @__PURE__ */ new Set();
|
|
5244
5239
|
var _batchedInjectFn = null;
|
|
@@ -5270,10 +5265,7 @@ function injectStateStyles(id, state) {
|
|
|
5270
5265
|
}
|
|
5271
5266
|
}
|
|
5272
5267
|
}
|
|
5273
|
-
const rules =
|
|
5274
|
-
const css = twClassesToCss(classes);
|
|
5275
|
-
return css ? `.${id}[data-${stateName}="true"]{${css}}` : null;
|
|
5276
|
-
}).filter(Boolean);
|
|
5268
|
+
const rules = generateStateRules(id, state);
|
|
5277
5269
|
if (rules.length === 0) return;
|
|
5278
5270
|
if (_batchedInjectFn) {
|
|
5279
5271
|
for (const rule of rules) _batchedInjectFn(rule);
|
|
@@ -5303,11 +5295,7 @@ function processState(tag, state, precomputedHash) {
|
|
|
5303
5295
|
}
|
|
5304
5296
|
function generateStateCss(tag, state) {
|
|
5305
5297
|
const id = hashState(tag, state);
|
|
5306
|
-
|
|
5307
|
-
const css = twClassesToCss(classes);
|
|
5308
|
-
return css ? `.${id}[data-${stateName}="true"]{${css}}` : null;
|
|
5309
|
-
}).filter(Boolean);
|
|
5310
|
-
return rules.join("\n");
|
|
5298
|
+
return generateStateRules(id, state).join("\n");
|
|
5311
5299
|
}
|
|
5312
5300
|
function getStateRegistry() {
|
|
5313
5301
|
return stateRegistry;
|
|
@@ -5712,7 +5700,13 @@ function lookupGenerated(componentId, props, defaultVariants, variantKeys) {
|
|
|
5712
5700
|
}
|
|
5713
5701
|
const binding = getNativeBinding();
|
|
5714
5702
|
if (!binding?.buildVariantLookupKey) {
|
|
5715
|
-
|
|
5703
|
+
const parts = [];
|
|
5704
|
+
for (const k of sortedKeys) {
|
|
5705
|
+
const v = props[k] ?? defaultVariants?.[k];
|
|
5706
|
+
if (v != null) parts.push(`${k}:${String(v)}`);
|
|
5707
|
+
}
|
|
5708
|
+
const key2 = parts.join("|");
|
|
5709
|
+
return table[key2];
|
|
5716
5710
|
}
|
|
5717
5711
|
const relevantDefaults = {};
|
|
5718
5712
|
const relevantProps = {};
|
|
@@ -5755,7 +5749,31 @@ function resolveVariantsNative(config, props) {
|
|
|
5755
5749
|
const { variants = {}, defaultVariants = {} } = config;
|
|
5756
5750
|
const binding = getNativeBinding();
|
|
5757
5751
|
if (!binding?.resolveVariants) {
|
|
5758
|
-
|
|
5752
|
+
const variantKeys2 = Object.keys(variants);
|
|
5753
|
+
const classes = [];
|
|
5754
|
+
for (const key of variantKeys2) {
|
|
5755
|
+
const value = props[key] ?? defaultVariants[key];
|
|
5756
|
+
if (value != null) {
|
|
5757
|
+
const variantClass = variants[key]?.[String(value)];
|
|
5758
|
+
if (variantClass) classes.push(variantClass);
|
|
5759
|
+
}
|
|
5760
|
+
}
|
|
5761
|
+
if (config.compoundVariants) {
|
|
5762
|
+
for (const compound of config.compoundVariants) {
|
|
5763
|
+
const { class: compoundClass, ...conditions } = compound;
|
|
5764
|
+
const resolved = {};
|
|
5765
|
+
for (const key of variantKeys2) {
|
|
5766
|
+
resolved[key] = String(
|
|
5767
|
+
props[key] ?? defaultVariants[key] ?? ""
|
|
5768
|
+
);
|
|
5769
|
+
}
|
|
5770
|
+
const matches = Object.entries(conditions).every(
|
|
5771
|
+
([k, v]) => resolved[k] === v
|
|
5772
|
+
);
|
|
5773
|
+
if (matches) classes.push(compoundClass);
|
|
5774
|
+
}
|
|
5775
|
+
}
|
|
5776
|
+
return classes.join(" ");
|
|
5759
5777
|
}
|
|
5760
5778
|
const variantKeys = Object.keys(variants);
|
|
5761
5779
|
const configJson = _getConfigJson(config);
|