@alex.radulescu/styled-static 0.2.0 → 0.7.1

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/dist/hash.js CHANGED
@@ -1,46 +1 @@
1
- /**
2
- * Murmurhash2 implementation for generating short, deterministic hashes.
3
- * Used to create unique class names from CSS content.
4
- *
5
- * Based on https://github.com/garycourt/murmurhash-js
6
- * This is a well-known, fast, non-cryptographic hash function.
7
- */
8
- export function hash(str = "") {
9
- let l = str.length;
10
- let h = l ^ l;
11
- let i = 0;
12
- let k;
13
- while (l >= 4) {
14
- k =
15
- (str.charCodeAt(i) & 0xff) |
16
- ((str.charCodeAt(++i) & 0xff) << 8) |
17
- ((str.charCodeAt(++i) & 0xff) << 16) |
18
- ((str.charCodeAt(++i) & 0xff) << 24);
19
- k =
20
- (k & 0xffff) * 0x5bd1e995 + ((((k >>> 16) * 0x5bd1e995) & 0xffff) << 16);
21
- k ^= k >>> 24;
22
- k =
23
- (k & 0xffff) * 0x5bd1e995 + ((((k >>> 16) * 0x5bd1e995) & 0xffff) << 16);
24
- h =
25
- ((h & 0xffff) * 0x5bd1e995 +
26
- ((((h >>> 16) * 0x5bd1e995) & 0xffff) << 16)) ^
27
- k;
28
- l -= 4;
29
- ++i;
30
- }
31
- // Handle remaining bytes (1-3) without switch fallthrough
32
- if (l >= 3)
33
- h ^= (str.charCodeAt(i + 2) & 0xff) << 16;
34
- if (l >= 2)
35
- h ^= (str.charCodeAt(i + 1) & 0xff) << 8;
36
- if (l >= 1) {
37
- h ^= str.charCodeAt(i) & 0xff;
38
- h =
39
- (h & 0xffff) * 0x5bd1e995 + ((((h >>> 16) * 0x5bd1e995) & 0xffff) << 16);
40
- }
41
- h ^= h >>> 13;
42
- h = (h & 0xffff) * 0x5bd1e995 + ((((h >>> 16) * 0x5bd1e995) & 0xffff) << 16);
43
- h ^= h >>> 15;
44
- return (h >>> 0).toString(36);
45
- }
46
- //# sourceMappingURL=hash.js.map
1
+ function w(f=""){let v=f.length,b=v^v,q=0,d;while(v>=4)d=f.charCodeAt(q)&255|(f.charCodeAt(++q)&255)<<8|(f.charCodeAt(++q)&255)<<16|(f.charCodeAt(++q)&255)<<24,d=(d&65535)*1540483477+(((d>>>16)*1540483477&65535)<<16),d^=d>>>24,d=(d&65535)*1540483477+(((d>>>16)*1540483477&65535)<<16),b=(b&65535)*1540483477+(((b>>>16)*1540483477&65535)<<16)^d,v-=4,++q;if(v>=3)b^=(f.charCodeAt(q+2)&255)<<16;if(v>=2)b^=(f.charCodeAt(q+1)&255)<<8;if(v>=1)b^=f.charCodeAt(q)&255,b=(b&65535)*1540483477+(((b>>>16)*1540483477&65535)<<16);return b^=b>>>13,b=(b&65535)*1540483477+(((b>>>16)*1540483477&65535)<<16),b^=b>>>15,(b>>>0).toString(36)}export{w as hash};
package/dist/index.d.ts CHANGED
@@ -35,18 +35,28 @@
35
35
  * body { margin: 0; }
36
36
  * `;
37
37
  *
38
+ * // Polymorphism with withComponent
39
+ * import { Link } from 'react-router-dom';
40
+ * const LinkButton = withComponent(Link, Button);
41
+ *
38
42
  * // Usage
39
43
  * <GlobalStyle />
40
44
  * <Button>Click me</Button>
41
- * <Button as="a" href="/link">Link button</Button>
45
+ * <LinkButton to="/home">Link button</LinkButton>
42
46
  * <PrimaryButton className={activeClass}>Active</PrimaryButton>
47
+ *
48
+ * // Access className for manual composition
49
+ * <a className={Button.className} href="/link">Manual link</a>
43
50
  * ```
44
51
  */
45
- export type { StyledComponent, StyledFunction, HTMLTag, PropsOf } from './types';
52
+ export type { StyledComponent, StyledFunction, HTMLTag, PropsOf, VariantsConfig, VariantsDefinition, StyledVariantsDefinition, VariantProps, StyledVariantComponent, CssVariantsFunction, Keyframes, } from "./types";
53
+ export { getTheme, setTheme, initTheme, onSystemThemeChange, type InitThemeOptions, } from "./theme";
46
54
  /**
47
- * Create styled React components with zero runtime overhead.
55
+ * Create styled React components with near-zero runtime overhead.
48
56
  * CSS is extracted to static files at build time.
49
57
  *
58
+ * Every styled component exposes a `.className` property for composition.
59
+ *
50
60
  * @example
51
61
  * // Style HTML elements
52
62
  * const Button = styled.button`
@@ -59,11 +69,11 @@ export type { StyledComponent, StyledFunction, HTMLTag, PropsOf } from './types'
59
69
  * font-weight: bold;
60
70
  * `;
61
71
  *
62
- * // Use with `as` prop for polymorphism
63
- * <Button as="a" href="/link">Click</Button>
72
+ * // Access className for manual composition
73
+ * <a className={Button.className} href="/link">Link with button styles</a>
64
74
  *
65
- * // Use transient props (won't reach DOM)
66
- * <Button $primary={true}>Click</Button>
75
+ * // Use withComponent for polymorphism
76
+ * const LinkButton = withComponent(Link, Button);
67
77
  */
68
78
  export declare const styled: import("./types").StyledFunction;
69
79
  /**
@@ -84,6 +94,25 @@ export declare const styled: import("./types").StyledFunction;
84
94
  * <Button className={`${activeClass} ${highlightClass}`}>Mixed</Button>
85
95
  */
86
96
  export declare function css(_strings: TemplateStringsArray, ..._interpolations: never[]): string;
97
+ /**
98
+ * Create scoped keyframes for animations.
99
+ * The animation name is hashed to avoid conflicts between components.
100
+ *
101
+ * @example
102
+ * const spin = keyframes`
103
+ * from { transform: rotate(0deg); }
104
+ * to { transform: rotate(360deg); }
105
+ * `;
106
+ *
107
+ * const Spinner = styled.div`
108
+ * animation: ${spin} 1s linear infinite;
109
+ * `;
110
+ *
111
+ * // In CSS output:
112
+ * // @keyframes ss-abc123 { from { transform: rotate(0deg); } to { transform: rotate(360deg); } }
113
+ * // .ss-xyz789 { animation: ss-abc123 1s linear infinite; }
114
+ */
115
+ export declare function keyframes(_strings: TemplateStringsArray, ..._interpolations: never[]): string;
87
116
  /**
88
117
  * Create global (unscoped) styles.
89
118
  * Returns a component that should be rendered once at the root of your app.
@@ -115,4 +144,127 @@ export declare function css(_strings: TemplateStringsArray, ..._interpolations:
115
144
  * );
116
145
  */
117
146
  export declare function createGlobalStyle(_strings: TemplateStringsArray, ..._interpolations: never[]): () => null;
147
+ /**
148
+ * Utility for conditionally joining class names.
149
+ * A minimal (~40B) alternative to clsx/classnames.
150
+ *
151
+ * @example
152
+ * // Multiple class names
153
+ * cx('base', 'active') // → 'base active'
154
+ *
155
+ * // Conditional classes
156
+ * cx('btn', isActive && 'active') // → 'btn active' or 'btn'
157
+ *
158
+ * // With css helper
159
+ * const activeClass = css`color: blue;`;
160
+ * cx('btn', isActive && activeClass)
161
+ *
162
+ * // Falsy values are filtered
163
+ * cx('a', null, undefined, false, 'b') // → 'a b'
164
+ */
165
+ export declare function cx(...args: (string | false | null | undefined)[]): string;
166
+ /**
167
+ * Create a styled component with variant support.
168
+ * CSS for base and all variants is extracted at build time.
169
+ * Variant props are mapped to modifier classes at runtime.
170
+ *
171
+ * @example
172
+ * // With css`` for IDE syntax highlighting (recommended)
173
+ * const Button = styledVariants({
174
+ * component: 'button',
175
+ * css: css`
176
+ * padding: 0.5rem 1rem;
177
+ * border: none;
178
+ * border-radius: 4px;
179
+ * `,
180
+ * variants: {
181
+ * color: {
182
+ * primary: css`background: blue; color: white;`,
183
+ * danger: css`background: red; color: white;`,
184
+ * },
185
+ * size: {
186
+ * sm: css`font-size: 0.875rem;`,
187
+ * lg: css`font-size: 1.125rem;`,
188
+ * },
189
+ * },
190
+ * });
191
+ *
192
+ * // Plain strings also work (no highlighting)
193
+ * const SimpleButton = styledVariants({
194
+ * component: 'button',
195
+ * css: `padding: 0.5rem;`,
196
+ * variants: { size: { sm: `font-size: 0.875rem;` } },
197
+ * });
198
+ *
199
+ * // Usage - variant props become modifier classes
200
+ * <Button color="primary" size="lg">Click me</Button>
201
+ * // Renders: <button class="ss-abc ss-abc--color-primary ss-abc--size-lg">
202
+ */
203
+ export declare function styledVariants<T extends import("./types").HTMLTag | import("react").ComponentType<any>, V extends import("./types").VariantsConfig>(_config: import("./types").StyledVariantsDefinition<V> & {
204
+ component: T;
205
+ }): import("./types").StyledVariantComponent<T, V>;
206
+ /**
207
+ * Create a variant function that returns class strings.
208
+ * CSS for base and all variants is extracted at build time.
209
+ * The function maps variant selections to class names at runtime.
210
+ *
211
+ * @example
212
+ * // With css`` for IDE syntax highlighting (recommended)
213
+ * const buttonCss = cssVariants({
214
+ * css: css`
215
+ * padding: 0.5rem 1rem;
216
+ * border-radius: 4px;
217
+ * `,
218
+ * variants: {
219
+ * color: {
220
+ * primary: css`background: blue;`,
221
+ * danger: css`background: red;`,
222
+ * },
223
+ * },
224
+ * });
225
+ *
226
+ * // Usage - returns class string
227
+ * <div className={buttonCss({ color: 'primary' })}>
228
+ * // Returns: "ss-xyz ss-xyz--color-primary"
229
+ *
230
+ * // Combine with cx
231
+ * <div className={cx(buttonCss({ color: 'primary' }), isActive && activeClass)}>
232
+ */
233
+ export declare function cssVariants<V extends import("./types").VariantsConfig>(_config: import("./types").VariantsDefinition<V>): import("./types").CssVariantsFunction<V>;
234
+ /**
235
+ * Create a component that renders one element with another's styles.
236
+ * This is a build-time alternative to the runtime `as` prop.
237
+ *
238
+ * @param toComponent - The component or HTML tag to render
239
+ * @param fromComponent - The styled component whose styles to use
240
+ *
241
+ * @example
242
+ * import { Link } from 'react-router-dom';
243
+ *
244
+ * const Button = styled.button`
245
+ * padding: 1rem;
246
+ * background: blue;
247
+ * `;
248
+ *
249
+ * // Create a Link that looks like a Button
250
+ * const LinkButton = withComponent(Link, Button);
251
+ *
252
+ * // Usage
253
+ * <LinkButton to="/home">Go Home</LinkButton>
254
+ *
255
+ * // Can extend further
256
+ * const PrimaryLinkButton = styled(LinkButton)`
257
+ * font-weight: bold;
258
+ * `;
259
+ *
260
+ * @example
261
+ * // Also works with HTML tags
262
+ * const ButtonAsAnchor = withComponent('a', Button);
263
+ * <ButtonAsAnchor href="/link">Click</ButtonAsAnchor>
264
+ */
265
+ export declare function withComponent<T extends import("./types").HTMLTag | import("react").ComponentType<any>, F extends {
266
+ className: string;
267
+ }>(_toComponent: T, _fromComponent: F): import("./types").StyledComponent<T> & {
268
+ className: string;
269
+ };
118
270
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2CG;AAEH,YAAY,EAAE,eAAe,EAAE,cAAc,EAAE,OAAO,EAAE,OAAO,EAAE,MAAM,SAAS,CAAC;AAcjF;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,eAAO,MAAM,MAAM,EAGb,OAAO,SAAS,EAAE,cAAc,CAAC;AAEvC;;;;;;;;;;;;;;;;GAgBG;AACH,wBAAgB,GAAG,CACjB,QAAQ,EAAE,oBAAoB,EAC9B,GAAG,eAAe,EAAE,KAAK,EAAE,GAC1B,MAAM,CAER;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA6BG;AACH,wBAAgB,iBAAiB,CAC/B,QAAQ,EAAE,oBAAoB,EAC9B,GAAG,eAAe,EAAE,KAAK,EAAE,GAC1B,MAAM,IAAI,CAEZ"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAkDG;AAEH,YAAY,EACV,eAAe,EACf,cAAc,EACd,OAAO,EACP,OAAO,EACP,cAAc,EACd,kBAAkB,EAClB,wBAAwB,EACxB,YAAY,EACZ,sBAAsB,EACtB,mBAAmB,EACnB,SAAS,GACV,MAAM,SAAS,CAAC;AAGjB,OAAO,EACL,QAAQ,EACR,QAAQ,EACR,SAAS,EACT,mBAAmB,EACnB,KAAK,gBAAgB,GACtB,MAAM,SAAS,CAAC;AAcjB;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AACH,eAAO,MAAM,MAAM,EAGb,OAAO,SAAS,EAAE,cAAc,CAAC;AAEvC;;;;;;;;;;;;;;;;GAgBG;AACH,wBAAgB,GAAG,CACjB,QAAQ,EAAE,oBAAoB,EAC9B,GAAG,eAAe,EAAE,KAAK,EAAE,GAC1B,MA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AC,SAAS;IAAE,SAAS,EAAE,MAAM,CAAA;CAAE,EAC/B,YAAY,EAAE,CAAC,EAAE,cAAc,EAAE,CAAC,GAAG,OAAO,SAAS,EAAE,eAAe,CAAC,CAAC,CAAC,GAAG;IAAE,SAAS,EAAE,MAAM,CAAA;CAAE,CAElG"}
package/dist/index.js CHANGED
@@ -1,133 +1,8 @@
1
- /**
2
- * styled-static
3
- *
4
- * Zero-runtime styled components for React 19+ with Vite.
5
- * CSS is extracted to static files at build time.
6
- *
7
- * @example
8
- * ```tsx
9
- * import { styled, css, createGlobalStyle } from 'styled-static';
10
- *
11
- * // Style HTML elements
12
- * const Button = styled.button`
13
- * padding: 0.5rem 1rem;
14
- * background: blue;
15
- * color: white;
16
- *
17
- * &:hover {
18
- * background: darkblue;
19
- * }
20
- * `;
21
- *
22
- * // Extend existing styled components
23
- * const PrimaryButton = styled(Button)`
24
- * font-weight: bold;
25
- * `;
26
- *
27
- * // Get a class name for mixing
28
- * const activeClass = css`
29
- * outline: 2px solid blue;
30
- * `;
31
- *
32
- * // Global styles
33
- * const GlobalStyle = createGlobalStyle`
34
- * * { box-sizing: border-box; }
35
- * body { margin: 0; }
36
- * `;
37
- *
38
- * // Usage
39
- * <GlobalStyle />
40
- * <Button>Click me</Button>
41
- * <Button as="a" href="/link">Link button</Button>
42
- * <PrimaryButton className={activeClass}>Active</PrimaryButton>
43
- * ```
44
- */
45
- function throwConfigError(name) {
46
- throw new Error(`${name} was not transformed at build time. ` +
47
- `Ensure the styled-static plugin is configured in vite.config.ts:\n\n` +
48
- ` import { styledStatic } from 'styled-static/vite';\n` +
49
- ` import react from '@vitejs/plugin-react';\n\n` +
50
- ` export default defineConfig({\n` +
51
- ` plugins: [styledStatic(), react()],\n` +
52
- ` });`);
53
- }
54
- /**
55
- * Create styled React components with zero runtime overhead.
56
- * CSS is extracted to static files at build time.
57
- *
58
- * @example
59
- * // Style HTML elements
60
- * const Button = styled.button`
61
- * padding: 0.5rem 1rem;
62
- * background: blue;
63
- * `;
64
- *
65
- * // Extend existing styled components
66
- * const PrimaryButton = styled(Button)`
67
- * font-weight: bold;
68
- * `;
69
- *
70
- * // Use with `as` prop for polymorphism
71
- * <Button as="a" href="/link">Click</Button>
72
- *
73
- * // Use transient props (won't reach DOM)
74
- * <Button $primary={true}>Click</Button>
75
- */
76
- export const styled = new Proxy({}, {
77
- get: () => () => throwConfigError('styled'),
78
- apply: () => throwConfigError('styled'),
79
- });
80
- /**
81
- * Get a scoped class name for CSS.
82
- * Useful for conditional classes or mixing with styled components.
83
- *
84
- * @example
85
- * const activeClass = css`
86
- * background: blue;
87
- * color: white;
88
- * `;
89
- *
90
- * const highlightClass = css`
91
- * box-shadow: 0 0 10px yellow;
92
- * `;
93
- *
94
- * <div className={isActive ? activeClass : ''} />
95
- * <Button className={`${activeClass} ${highlightClass}`}>Mixed</Button>
96
- */
97
- export function css(_strings, ..._interpolations) {
98
- throwConfigError('css');
99
- }
100
- /**
101
- * Create global (unscoped) styles.
102
- * Returns a component that should be rendered once at the root of your app.
103
- * The component renders nothing - CSS is extracted at build time.
104
- *
105
- * @example
106
- * const GlobalStyle = createGlobalStyle`
107
- * * {
108
- * box-sizing: border-box;
109
- * }
110
- *
111
- * body {
112
- * margin: 0;
113
- * font-family: system-ui, sans-serif;
114
- * }
115
- *
116
- * :root {
117
- * --color-primary: #3b82f6;
118
- * --color-text: #1a1a1a;
119
- * }
120
- * `;
121
- *
122
- * // In your app entry point
123
- * createRoot(document.getElementById('root')!).render(
124
- * <StrictMode>
125
- * <GlobalStyle />
126
- * <App />
127
- * </StrictMode>
128
- * );
129
- */
130
- export function createGlobalStyle(_strings, ..._interpolations) {
131
- throwConfigError('createGlobalStyle');
132
- }
133
- //# sourceMappingURL=index.js.map
1
+ function d(e="data-theme"){if(typeof document>"u")return"light";if(e.startsWith("data-")){let t=e.slice(5);return document.documentElement.dataset[t]||"light"}return document.documentElement.getAttribute(e)||"light"}function i(e,t=!0,a={}){let{storageKey:m="theme",attribute:n="data-theme"}=a;if(typeof document>"u")return;if(n.startsWith("data-")){let u=n.slice(5);document.documentElement.dataset[u]=e}else document.documentElement.setAttribute(n,e);if(t&&typeof localStorage<"u")try{localStorage.setItem(m,e)}catch{}}function l(e={}){let{defaultTheme:t="light",storageKey:a="theme",useSystemPreference:m=!1,attribute:n="data-theme"}=e;if(typeof document>"u")return t;let u=null;if(typeof localStorage<"u")try{u=localStorage.getItem(a)}catch{}if(u)return i(u,!1,{storageKey:a,attribute:n}),u;if(m&&typeof matchMedia<"u")return u=matchMedia("(prefers-color-scheme: dark)").matches?"dark":"light",i(u,!1,{storageKey:a,attribute:n}),u;return i(t,!1,{storageKey:a,attribute:n}),t}function s(e){if(typeof matchMedia>"u")return()=>{};let t=matchMedia("(prefers-color-scheme: dark)"),a=(m)=>{e(m.matches)};if(t.addEventListener)return t.addEventListener("change",a),()=>t.removeEventListener("change",a);return t.addListener(a),()=>t.removeListener(a)}function c(e){throw Error(`${e} was not transformed at build time. Ensure the styled-static plugin is configured in vite.config.ts:
2
+
3
+ import { styledStatic } from 'styled-static/vite';
4
+ import react from '@vitejs/plugin-react';
5
+
6
+ export default defineConfig({
7
+ plugins: [styledStatic(), react()],
8
+ });`)}var h=new Proxy({},{get:()=>()=>c("styled"),apply:()=>c("styled")});function f(e,...t){c("css")}function o(e,...t){c("keyframes")}function y(e,...t){c("createGlobalStyle")}function g(...e){return e.filter(Boolean).join(" ")}function b(e){c("styledVariants")}function p(e){c("cssVariants")}function S(e,t){c("withComponent")}export{S as withComponent,b as styledVariants,h as styled,i as setTheme,s as onSystemThemeChange,o as keyframes,l as initTheme,d as getTheme,g as cx,p as cssVariants,f as css,y as createGlobalStyle};
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2CG;AAIH,SAAS,gBAAgB,CAAC,IAAY;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AAU,aAAa,CAG3B,YAAe,EAAE,cAAiB;IAClC,gBAAgB,CAAC,eAAe,CAAC,CAAC;AACpC,CAAC"}
@@ -0,0 +1,27 @@
1
+ /**
2
+ * styled-static minimal runtime
3
+ *
4
+ * This is the entire runtime for styled-static (~50 bytes minified).
5
+ * All component creation happens at build time via the Vite plugin.
6
+ *
7
+ * ## Why so small?
8
+ *
9
+ * The Vite plugin generates inline component functions at build time.
10
+ * The only runtime operation needed is merging className strings.
11
+ *
12
+ * ## The `m` function (merge)
13
+ *
14
+ * Merges the styled component's base class with any user-provided className.
15
+ * Order: base class first, user class last (allows user to override).
16
+ *
17
+ * @example
18
+ * m("ss-btn", undefined) // → "ss-btn"
19
+ * m("ss-btn", "custom") // → "ss-btn custom"
20
+ * m("ss-btn ss-primary", "") // → "ss-btn ss-primary"
21
+ */
22
+ /**
23
+ * Merge base className with user className.
24
+ * Returns base class if no user class, otherwise combines them.
25
+ */
26
+ export declare const m: (b: string, u?: string) => string;
27
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/runtime/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;GAoBG;AAEH;;;GAGG;AACH,eAAO,MAAM,CAAC,GAAI,GAAG,MAAM,EAAE,IAAI,MAAM,KAAG,MAA+B,CAAC"}
@@ -0,0 +1 @@
1
+ var k=(f,h)=>h?`${f} ${h}`:f;export{k as m};
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/runtime/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;GAoBG;AAEH;;;GAGG;AACH,MAAM,CAAC,MAAM,CAAC,GAAG,CAAC,CAAS,EAAE,CAAU,EAAU,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC"}
@@ -0,0 +1,122 @@
1
+ /**
2
+ * Theme helpers for styled-static
3
+ *
4
+ * Provides simple, framework-agnostic utilities for theme switching.
5
+ * Uses CSS custom properties with data-theme attribute on documentElement.
6
+ *
7
+ * @example
8
+ * ```tsx
9
+ * import { initTheme, setTheme, getTheme } from 'styled-static';
10
+ *
11
+ * // Initialize on app load
12
+ * initTheme({ defaultTheme: 'light', useSystemPreference: true });
13
+ *
14
+ * // Get current theme
15
+ * const current = getTheme(); // 'light' | 'dark' | etc.
16
+ *
17
+ * // Change theme
18
+ * setTheme('dark');
19
+ * setTheme('pokemon', false); // Don't persist to localStorage
20
+ * ```
21
+ */
22
+ /**
23
+ * Options for initializing the theme system.
24
+ */
25
+ export interface InitThemeOptions {
26
+ /**
27
+ * The default theme to use when no stored preference exists.
28
+ * @default 'light'
29
+ */
30
+ defaultTheme?: string;
31
+ /**
32
+ * The localStorage key used to persist the theme.
33
+ * @default 'theme'
34
+ */
35
+ storageKey?: string;
36
+ /**
37
+ * Whether to use the system's color scheme preference as a fallback.
38
+ * When enabled, checks `prefers-color-scheme: dark` media query.
39
+ * @default false
40
+ */
41
+ useSystemPreference?: boolean;
42
+ /**
43
+ * Custom attribute name to set on documentElement.
44
+ * @default 'data-theme'
45
+ */
46
+ attribute?: string;
47
+ }
48
+ /**
49
+ * Get the current theme from the document.
50
+ *
51
+ * @param attribute - The attribute to read from (default: 'data-theme')
52
+ * @returns The current theme name, or 'light' if not set
53
+ *
54
+ * @example
55
+ * const theme = getTheme(); // 'light', 'dark', 'pokemon', etc.
56
+ */
57
+ export declare function getTheme(attribute?: string): string;
58
+ /**
59
+ * Set the theme on the document and optionally persist to localStorage.
60
+ *
61
+ * @param theme - The theme name to set (e.g., 'dark', 'pokemon', 'star-trek')
62
+ * @param persist - Whether to save to localStorage (default: true)
63
+ * @param options - Additional options for attribute and storage key
64
+ *
65
+ * @example
66
+ * // Set theme and persist
67
+ * setTheme('dark');
68
+ *
69
+ * // Set theme without persisting (e.g., for preview)
70
+ * setTheme('pokemon', false);
71
+ */
72
+ export declare function setTheme(theme: string, persist?: boolean, options?: {
73
+ storageKey?: string;
74
+ attribute?: string;
75
+ }): void;
76
+ /**
77
+ * Initialize the theme system on page load.
78
+ *
79
+ * Applies the theme in this priority order:
80
+ * 1. Stored theme from localStorage
81
+ * 2. System preference (if `useSystemPreference` is true)
82
+ * 3. Default theme
83
+ *
84
+ * @param options - Configuration options
85
+ * @returns The theme that was applied
86
+ *
87
+ * @example
88
+ * // Basic usage
89
+ * initTheme();
90
+ *
91
+ * // With system preference detection
92
+ * initTheme({ useSystemPreference: true });
93
+ *
94
+ * // Full configuration
95
+ * initTheme({
96
+ * defaultTheme: 'light',
97
+ * storageKey: 'my-app-theme',
98
+ * useSystemPreference: true,
99
+ * });
100
+ */
101
+ export declare function initTheme(options?: InitThemeOptions): string;
102
+ /**
103
+ * Subscribe to system theme changes.
104
+ *
105
+ * Useful when `useSystemPreference` is enabled and you want to
106
+ * react to the user changing their OS theme.
107
+ *
108
+ * @param callback - Function called when system preference changes
109
+ * @returns Unsubscribe function
110
+ *
111
+ * @example
112
+ * const unsubscribe = onSystemThemeChange((isDark) => {
113
+ * if (!localStorage.getItem('theme')) {
114
+ * setTheme(isDark ? 'dark' : 'light', false);
115
+ * }
116
+ * });
117
+ *
118
+ * // Later: stop listening
119
+ * unsubscribe();
120
+ */
121
+ export declare function onSystemThemeChange(callback: (prefersDark: boolean) => void): () => void;
122
+ //# sourceMappingURL=theme.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"theme.d.ts","sourceRoot":"","sources":["../src/theme.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;GAoBG;AAKH;;GAEG;AACH,MAAM,WAAW,gBAAgB;IAC/B;;;OAGG;IACH,YAAY,CAAC,EAAE,MAAM,CAAC;IAEtB;;;OAGG;IACH,UAAU,CAAC,EAAE,MAAM,CAAC;IAEpB;;;;OAIG;IACH,mBAAmB,CAAC,EAAE,OAAO,CAAC;IAE9B;;;OAGG;IACH,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB;AAED;;;;;;;;GAQG;AACH,wBAAgB,QAAQ,CAAC,SAAS,SAAe,GAAG,MAAM,CASzD;AAED;;;;;;;;;;;;;GAaG;AACH,wBAAgB,QAAQ,CACtB,KAAK,EAAE,MAAM,EACb,OAAO,UAAO,EACd,OAAO,GAAE;IAAE,UAAU,CAAC,EAAE,MAAM,CAAC;IAAC,SAAS,CAAC,EAAE,MAAM,CAAA;CAAO,GACxD,IAAI,CAqBN;AAED;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;AACH,wBAAgB,SAAS,CAAC,OAAO,GAAE,gBAAqB,GAAG,MAAM,CAoChE;AAED;;;;;;;;;;;;;;;;;;GAkBG;AACH,wBAAgB,mBAAmB,CACjC,QAAQ,EAAE,CAAC,WAAW,EAAE,OAAO,KAAK,IAAI,GACvC,MAAM,IAAI,CAoBZ"}
package/dist/theme.js ADDED
@@ -0,0 +1 @@
1
+ function D(v="data-theme"){if(typeof document>"u")return"light";if(v.startsWith("data-")){let q=v.slice(5);return document.documentElement.dataset[q]||"light"}return document.documentElement.getAttribute(v)||"light"}function B(v,q=!0,w={}){let{storageKey:A="theme",attribute:z="data-theme"}=w;if(typeof document>"u")return;if(z.startsWith("data-")){let x=z.slice(5);document.documentElement.dataset[x]=v}else document.documentElement.setAttribute(z,v);if(q&&typeof localStorage<"u")try{localStorage.setItem(A,v)}catch{}}function E(v={}){let{defaultTheme:q="light",storageKey:w="theme",useSystemPreference:A=!1,attribute:z="data-theme"}=v;if(typeof document>"u")return q;let x=null;if(typeof localStorage<"u")try{x=localStorage.getItem(w)}catch{}if(x)return B(x,!1,{storageKey:w,attribute:z}),x;if(A&&typeof matchMedia<"u")return x=matchMedia("(prefers-color-scheme: dark)").matches?"dark":"light",B(x,!1,{storageKey:w,attribute:z}),x;return B(q,!1,{storageKey:w,attribute:z}),q}function F(v){if(typeof matchMedia>"u")return()=>{};let q=matchMedia("(prefers-color-scheme: dark)"),w=(A)=>{v(A.matches)};if(q.addEventListener)return q.addEventListener("change",w),()=>q.removeEventListener("change",w);return q.addListener(w),()=>q.removeListener(w)}export{B as setTheme,F as onSystemThemeChange,E as initTheme,D as getTheme};
@@ -0,0 +1 @@
1
+ {"version":3,"file":"theme.js","sourceRoot":"","sources":["../src/theme.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;GAoBG;AAEH,MAAM,mBAAmB,GAAG,OAAO,CAAC;AACpC,MAAM,aAAa,GAAG,OAAO,CAAC;AAgC9B;;;;;;;;GAQG;AACH,MAAM,UAAU,QAAQ,CAAC,SAAS,GAAG,YAAY;IAC/C,IAAI,OAAO,QAAQ,KAAK,WAAW;QAAE,OAAO,aAAa,CAAC;IAE1D,4CAA4C;IAC5C,IAAI,SAAS,CAAC,UAAU,CAAC,OAAO,CAAC,EAAE,CAAC;QAClC,MAAM,GAAG,GAAG,SAAS,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,wBAAwB;QACxD,OAAO,QAAQ,CAAC,eAAe,CAAC,OAAO,CAAC,GAAG,CAAC,IAAI,aAAa,CAAC;IAChE,CAAC;IACD,OAAO,QAAQ,CAAC,eAAe,CAAC,YAAY,CAAC,SAAS,CAAC,IAAI,aAAa,CAAC;AAC3E,CAAC;AAED;;;;;;;;;;;;;GAaG;AACH,MAAM,UAAU,QAAQ,CACtB,KAAa,EACb,OAAO,GAAG,IAAI,EACd,UAAuD,EAAE;IAEzD,MAAM,EAAE,UAAU,GAAG,mBAAmB,EAAE,SAAS,GAAG,YAAY,EAAE,GAClE,OAAO,CAAC;IAEV,IAAI,OAAO,QAAQ,KAAK,WAAW;QAAE,OAAO;IAE5C,4CAA4C;IAC5C,IAAI,SAAS,CAAC,UAAU,CAAC,OAAO,CAAC,EAAE,CAAC;QAClC,MAAM,GAAG,GAAG,SAAS,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC;QAC/B,QAAQ,CAAC,eAAe,CAAC,OAA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