nitrowind 0.0.0-stage → 0.1.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/CHANGELOG.md +29 -0
- package/LICENSE +21 -0
- package/README.md +51 -2
- package/css.d.ts +6 -0
- package/dist/color.d.ts +24 -0
- package/dist/color.d.ts.map +1 -0
- package/dist/color.js +158 -0
- package/dist/color.js.map +1 -0
- package/dist/core.d.ts +121 -0
- package/dist/core.d.ts.map +1 -0
- package/dist/core.js +1026 -0
- package/dist/core.js.map +1 -0
- package/dist/css/compile.d.ts +18 -0
- package/dist/css/compile.d.ts.map +1 -0
- package/dist/css/compile.js +1018 -0
- package/dist/css/compile.js.map +1 -0
- package/dist/css/declarations.d.ts +18 -0
- package/dist/css/declarations.d.ts.map +1 -0
- package/dist/css/declarations.js +1173 -0
- package/dist/css/declarations.js.map +1 -0
- package/dist/css/index.d.ts +7 -0
- package/dist/css/index.d.ts.map +1 -0
- package/dist/css/index.js +7 -0
- package/dist/css/index.js.map +1 -0
- package/dist/css/parser.d.ts +9 -0
- package/dist/css/parser.d.ts.map +1 -0
- package/dist/css/parser.js +188 -0
- package/dist/css/parser.js.map +1 -0
- package/dist/css/tokenizer.d.ts +14 -0
- package/dist/css/tokenizer.d.ts.map +1 -0
- package/dist/css/tokenizer.js +200 -0
- package/dist/css/tokenizer.js.map +1 -0
- package/dist/css/types.d.ts +128 -0
- package/dist/css/types.d.ts.map +1 -0
- package/dist/css/types.js +19 -0
- package/dist/css/types.js.map +1 -0
- package/dist/css/values.d.ts +37 -0
- package/dist/css/values.d.ts.map +1 -0
- package/dist/css/values.js +343 -0
- package/dist/css/values.js.map +1 -0
- package/dist/environment.d.ts +5 -0
- package/dist/environment.d.ts.map +1 -0
- package/dist/environment.js +99 -0
- package/dist/environment.js.map +1 -0
- package/dist/hooks.d.ts +22 -0
- package/dist/hooks.d.ts.map +1 -0
- package/dist/hooks.js +140 -0
- package/dist/hooks.js.map +1 -0
- package/dist/index.d.ts +26 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +16 -0
- package/dist/index.js.map +1 -0
- package/dist/jsx-dev-runtime.d.ts +17 -0
- package/dist/jsx-dev-runtime.d.ts.map +1 -0
- package/dist/jsx-dev-runtime.js +12 -0
- package/dist/jsx-dev-runtime.js.map +1 -0
- package/dist/jsx-namespace.d.ts +29 -0
- package/dist/jsx-namespace.d.ts.map +1 -0
- package/dist/jsx-namespace.js +2 -0
- package/dist/jsx-namespace.js.map +1 -0
- package/dist/jsx-runtime.d.ts +22 -0
- package/dist/jsx-runtime.d.ts.map +1 -0
- package/dist/jsx-runtime.js +21 -0
- package/dist/jsx-runtime.js.map +1 -0
- package/dist/math.d.ts +50 -0
- package/dist/math.d.ts.map +1 -0
- package/dist/math.js +442 -0
- package/dist/math.js.map +1 -0
- package/dist/plugin.d.ts +45 -0
- package/dist/plugin.d.ts.map +1 -0
- package/dist/plugin.js +172 -0
- package/dist/plugin.js.map +1 -0
- package/dist/props.d.ts +29 -0
- package/dist/props.d.ts.map +1 -0
- package/dist/props.js +163 -0
- package/dist/props.js.map +1 -0
- package/dist/scope.d.ts +99 -0
- package/dist/scope.d.ts.map +1 -0
- package/dist/scope.js +228 -0
- package/dist/scope.js.map +1 -0
- package/dist/store.d.ts +18 -0
- package/dist/store.d.ts.map +1 -0
- package/dist/store.js +244 -0
- package/dist/store.js.map +1 -0
- package/dist/tokens/index.d.ts +12 -0
- package/dist/tokens/index.d.ts.map +1 -0
- package/dist/tokens/index.js +237 -0
- package/dist/tokens/index.js.map +1 -0
- package/dist/tokens/tailwind.generated.d.ts +3 -0
- package/dist/tokens/tailwind.generated.d.ts.map +1 -0
- package/dist/tokens/tailwind.generated.js +610 -0
- package/dist/tokens/tailwind.generated.js.map +1 -0
- package/dist/tokens/types.d.ts +95 -0
- package/dist/tokens/types.d.ts.map +1 -0
- package/dist/tokens/types.js +2 -0
- package/dist/tokens/types.js.map +1 -0
- package/dist/transform.d.ts +22 -0
- package/dist/transform.d.ts.map +1 -0
- package/dist/transform.js +79 -0
- package/dist/transform.js.map +1 -0
- package/dist/transition.d.ts +7 -0
- package/dist/transition.d.ts.map +1 -0
- package/dist/transition.js +355 -0
- package/dist/transition.js.map +1 -0
- package/dist/types.d.ts +214 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +2 -0
- package/dist/types.js.map +1 -0
- package/dist/utilities.d.ts +109 -0
- package/dist/utilities.d.ts.map +1 -0
- package/dist/utilities.js +2000 -0
- package/dist/utilities.js.map +1 -0
- package/dist/variables.d.ts +65 -0
- package/dist/variables.d.ts.map +1 -0
- package/dist/variables.js +408 -0
- package/dist/variables.js.map +1 -0
- package/dist/version.d.ts +3 -0
- package/dist/version.d.ts.map +1 -0
- package/dist/version.js +3 -0
- package/dist/version.js.map +1 -0
- package/dist/withNitroWind.d.ts +11 -0
- package/dist/withNitroWind.d.ts.map +1 -0
- package/dist/withNitroWind.js +27 -0
- package/dist/withNitroWind.js.map +1 -0
- package/package.json +89 -4
- package/src/color.ts +164 -0
- package/src/core.ts +1248 -0
- package/src/css/compile.ts +1198 -0
- package/src/css/declarations.ts +1141 -0
- package/src/css/index.ts +22 -0
- package/src/css/parser.ts +196 -0
- package/src/css/tokenizer.ts +227 -0
- package/src/css/types.ts +178 -0
- package/src/css/values.ts +330 -0
- package/src/environment.ts +112 -0
- package/src/hooks.ts +190 -0
- package/src/index.ts +61 -0
- package/src/jsx-dev-runtime.ts +43 -0
- package/src/jsx-namespace.ts +23 -0
- package/src/jsx-runtime.ts +39 -0
- package/src/math.ts +488 -0
- package/src/plugin.ts +230 -0
- package/src/props.ts +173 -0
- package/src/scope.ts +331 -0
- package/src/store.ts +288 -0
- package/src/tokens/index.ts +252 -0
- package/src/tokens/tailwind.generated.ts +613 -0
- package/src/tokens/types.ts +99 -0
- package/src/transform.ts +115 -0
- package/src/transition.ts +414 -0
- package/src/types.ts +248 -0
- package/src/utilities.ts +1992 -0
- package/src/variables.ts +509 -0
- package/src/version.ts +2 -0
- package/src/withNitroWind.ts +36 -0
package/dist/scope.js
ADDED
|
@@ -0,0 +1,228 @@
|
|
|
1
|
+
import { createContext, createElement, useContext, useLayoutEffect, useMemo, } from 'react';
|
|
2
|
+
import { getNitroWind } from './core';
|
|
3
|
+
import { mergeScopedVariables, referencedVariableNames } from './variables';
|
|
4
|
+
const NO_NAMES = Object.freeze([]);
|
|
5
|
+
function sameNames(a, b) {
|
|
6
|
+
return a.length === b.length && a.every((name, i) => name === b[i]);
|
|
7
|
+
}
|
|
8
|
+
export const ScopeContext = createContext(null);
|
|
9
|
+
/** Reads the nearest NitroWind scope, or `null` outside any scope. */
|
|
10
|
+
export function useNitroWindScope() {
|
|
11
|
+
return useContext(ScopeContext);
|
|
12
|
+
}
|
|
13
|
+
function sameValues(a, b) {
|
|
14
|
+
const aKeys = Object.keys(a);
|
|
15
|
+
if (aKeys.length !== Object.keys(b).length)
|
|
16
|
+
return false;
|
|
17
|
+
for (const key of aKeys) {
|
|
18
|
+
if (!Object.prototype.hasOwnProperty.call(b, key))
|
|
19
|
+
return false;
|
|
20
|
+
if (!Object.is(a[key], b[key]))
|
|
21
|
+
return false;
|
|
22
|
+
}
|
|
23
|
+
return true;
|
|
24
|
+
}
|
|
25
|
+
/** Creates the variable scope behind one `ScopedVariables`, merged over `parent` (innermost wins). */
|
|
26
|
+
export function createVariableScope(parent, initialOwn) {
|
|
27
|
+
let own = initialOwn;
|
|
28
|
+
let committed = initialOwn;
|
|
29
|
+
let committedNames = referencedVariableNames(committed);
|
|
30
|
+
const channels = new Map();
|
|
31
|
+
const subscribersByTheme = new Map();
|
|
32
|
+
let mergedFrom;
|
|
33
|
+
let merged;
|
|
34
|
+
let layersFrom;
|
|
35
|
+
let layers;
|
|
36
|
+
const getLayers = () => {
|
|
37
|
+
const parentLayers = parent?.getLayers();
|
|
38
|
+
if (layersFrom === undefined || layersFrom.parent !== parentLayers || layersFrom.own !== own) {
|
|
39
|
+
const inner = mergeScopedVariables(parentLayers?.inner, own);
|
|
40
|
+
layers =
|
|
41
|
+
parentLayers?.outer !== undefined
|
|
42
|
+
? Object.freeze({ inner, outer: parentLayers.outer })
|
|
43
|
+
: Object.freeze({ inner });
|
|
44
|
+
layersFrom = { parent: parentLayers, own };
|
|
45
|
+
}
|
|
46
|
+
return layers;
|
|
47
|
+
};
|
|
48
|
+
const getVariables = () => {
|
|
49
|
+
const currentLayers = getLayers();
|
|
50
|
+
const inner = currentLayers.inner;
|
|
51
|
+
const outer = currentLayers.outer;
|
|
52
|
+
if (outer === undefined)
|
|
53
|
+
return inner;
|
|
54
|
+
if (mergedFrom === undefined || mergedFrom.outer !== outer || mergedFrom.inner !== inner) {
|
|
55
|
+
merged = mergeScopedVariables(outer, inner);
|
|
56
|
+
mergedFrom = { outer, inner };
|
|
57
|
+
}
|
|
58
|
+
return merged;
|
|
59
|
+
};
|
|
60
|
+
const notifyChannel = (channel) => {
|
|
61
|
+
for (const listener of [...channel.listeners])
|
|
62
|
+
listener();
|
|
63
|
+
};
|
|
64
|
+
const notifyAll = () => {
|
|
65
|
+
const toNotify = new Set();
|
|
66
|
+
for (const channel of channels.values()) {
|
|
67
|
+
for (const listener of channel.listeners)
|
|
68
|
+
toNotify.add(listener);
|
|
69
|
+
}
|
|
70
|
+
for (const listener of toNotify)
|
|
71
|
+
listener();
|
|
72
|
+
};
|
|
73
|
+
// A scoped `--brand: var(--accent)` changes when `updateCSSVariables` changes `--accent`, but the
|
|
74
|
+
// store only notifies readers of `--accent`. So, while anyone listens in a theme (or the active
|
|
75
|
+
// theme), the scope listens to the store for the names its own values read in that theme and
|
|
76
|
+
// passes the change on. Enclosing scopes do the same for theirs, and a listener here is also
|
|
77
|
+
// subscribed to each of them.
|
|
78
|
+
const syncChannelStoreSubscription = (theme, channel) => {
|
|
79
|
+
const names = channel.listeners.size > 0 ? committedNames : NO_NAMES;
|
|
80
|
+
if (sameNames(names, channel.storeNames))
|
|
81
|
+
return;
|
|
82
|
+
channel.unsubscribeStore?.();
|
|
83
|
+
channel.unsubscribeStore =
|
|
84
|
+
names.length > 0 ? getNitroWind().store.subscribeVariables(names, () => notifyChannel(channel), theme) : undefined;
|
|
85
|
+
channel.storeNames = names;
|
|
86
|
+
};
|
|
87
|
+
const subscribe = (listener, theme) => {
|
|
88
|
+
let channel = channels.get(theme);
|
|
89
|
+
if (channel === undefined) {
|
|
90
|
+
channel = { listeners: new Set(), storeNames: NO_NAMES, unsubscribeStore: undefined };
|
|
91
|
+
channels.set(theme, channel);
|
|
92
|
+
}
|
|
93
|
+
channel.listeners.add(listener);
|
|
94
|
+
const unsubscribeParent = parent?.subscribe(listener, theme);
|
|
95
|
+
syncChannelStoreSubscription(theme, channel);
|
|
96
|
+
return () => {
|
|
97
|
+
channel.listeners.delete(listener);
|
|
98
|
+
unsubscribeParent?.();
|
|
99
|
+
syncChannelStoreSubscription(theme, channel);
|
|
100
|
+
if (channel.listeners.size === 0 && channels.get(theme) === channel) {
|
|
101
|
+
channels.delete(theme);
|
|
102
|
+
}
|
|
103
|
+
};
|
|
104
|
+
};
|
|
105
|
+
const getSubscriber = (theme) => {
|
|
106
|
+
if (theme === undefined)
|
|
107
|
+
return subscribe;
|
|
108
|
+
let subscriber = subscribersByTheme.get(theme);
|
|
109
|
+
if (subscriber === undefined) {
|
|
110
|
+
subscriber = (listener) => subscribe(listener, theme);
|
|
111
|
+
subscribersByTheme.set(theme, subscriber);
|
|
112
|
+
}
|
|
113
|
+
return subscriber;
|
|
114
|
+
};
|
|
115
|
+
const setOwn = (next) => {
|
|
116
|
+
if (next !== own && !sameValues(next, own))
|
|
117
|
+
own = next;
|
|
118
|
+
};
|
|
119
|
+
const commit = () => {
|
|
120
|
+
if (own === committed)
|
|
121
|
+
return;
|
|
122
|
+
const changed = !sameValues(own, committed);
|
|
123
|
+
committed = own;
|
|
124
|
+
if (!changed)
|
|
125
|
+
return;
|
|
126
|
+
committedNames = referencedVariableNames(committed);
|
|
127
|
+
for (const [theme, channel] of channels) {
|
|
128
|
+
syncChannelStoreSubscription(theme, channel);
|
|
129
|
+
}
|
|
130
|
+
notifyAll();
|
|
131
|
+
};
|
|
132
|
+
return { getVariables, getLayers, subscribe, getSubscriber, setOwn, commit };
|
|
133
|
+
}
|
|
134
|
+
/**
|
|
135
|
+
* Wraps an enclosing `VariableScope` at a `ScopedTheme` boundary so every variable declared
|
|
136
|
+
* outside the `ScopedTheme` moves to the `outer` layer (below the theme's own variables,
|
|
137
|
+
* above shared defaults) while keeping subscriptions wired through to the enclosing scopes.
|
|
138
|
+
*/
|
|
139
|
+
export function createThemeBoundaryScope(parent) {
|
|
140
|
+
let cachedParentVars;
|
|
141
|
+
let cachedLayers;
|
|
142
|
+
const getLayers = () => {
|
|
143
|
+
const parentVars = parent.getVariables();
|
|
144
|
+
if (cachedLayers === undefined || cachedParentVars !== parentVars) {
|
|
145
|
+
cachedParentVars = parentVars;
|
|
146
|
+
cachedLayers = Object.freeze({ outer: parentVars });
|
|
147
|
+
}
|
|
148
|
+
return cachedLayers;
|
|
149
|
+
};
|
|
150
|
+
return {
|
|
151
|
+
getVariables: parent.getVariables,
|
|
152
|
+
getLayers,
|
|
153
|
+
subscribe: parent.subscribe,
|
|
154
|
+
getSubscriber: parent.getSubscriber,
|
|
155
|
+
};
|
|
156
|
+
}
|
|
157
|
+
/**
|
|
158
|
+
* Validates that `theme` is a registered theme name (not `'system'`) and returns
|
|
159
|
+
* its resolved `{ theme, colorScheme }`.
|
|
160
|
+
*/
|
|
161
|
+
export function validateScopedTheme(theme) {
|
|
162
|
+
if (theme === 'system') {
|
|
163
|
+
throw new Error('[nitrowind] ScopedTheme requires a registered theme name, not "system"');
|
|
164
|
+
}
|
|
165
|
+
const nitroWind = getNitroWind();
|
|
166
|
+
if (!Object.prototype.hasOwnProperty.call(nitroWind.themes, theme)) {
|
|
167
|
+
throw new Error(`[nitrowind] Unregistered theme "${theme}"`);
|
|
168
|
+
}
|
|
169
|
+
return {
|
|
170
|
+
theme: theme,
|
|
171
|
+
colorScheme: nitroWind.themes[theme].colorScheme,
|
|
172
|
+
};
|
|
173
|
+
}
|
|
174
|
+
/**
|
|
175
|
+
* Renders a subtree in another registered theme without changing the rest of the app
|
|
176
|
+
* or the native color scheme. Inside the scope, `<name>:` matches `theme`, and
|
|
177
|
+
* `dark:` / `light:` match that theme's declared `colorScheme`.
|
|
178
|
+
*/
|
|
179
|
+
export function ScopedTheme({ theme, children }) {
|
|
180
|
+
const parent = useContext(ScopeContext);
|
|
181
|
+
const validated = validateScopedTheme(theme);
|
|
182
|
+
const parentVariables = parent?.variables;
|
|
183
|
+
const boundary = useMemo(() => (parentVariables !== undefined ? createThemeBoundaryScope(parentVariables) : undefined), [parentVariables]);
|
|
184
|
+
const value = useMemo(() => {
|
|
185
|
+
if (parent !== null &&
|
|
186
|
+
parent.theme === validated.theme &&
|
|
187
|
+
parent.colorScheme === validated.colorScheme &&
|
|
188
|
+
parentVariables === undefined) {
|
|
189
|
+
return parent;
|
|
190
|
+
}
|
|
191
|
+
return parent !== null
|
|
192
|
+
? Object.freeze({
|
|
193
|
+
...parent,
|
|
194
|
+
theme: validated.theme,
|
|
195
|
+
colorScheme: validated.colorScheme,
|
|
196
|
+
...(boundary !== undefined ? { variables: boundary } : undefined),
|
|
197
|
+
})
|
|
198
|
+
: Object.freeze({ theme: validated.theme, colorScheme: validated.colorScheme });
|
|
199
|
+
}, [parent, parentVariables, boundary, validated.theme, validated.colorScheme]);
|
|
200
|
+
return createElement(ScopeContext.Provider, { value }, children);
|
|
201
|
+
}
|
|
202
|
+
/**
|
|
203
|
+
* Overrides CSS variables for a subtree following the CSS cascade ("closest override wins"):
|
|
204
|
+
* nested scopes merge with the innermost winning, a `ScopedVariables` inside a `ScopedTheme`
|
|
205
|
+
* wins over that theme's values, and a `ScopedTheme` inside a `ScopedVariables` wins for
|
|
206
|
+
* variables the theme declares while outer scoped variables still inherit through for the rest.
|
|
207
|
+
* `useTw` and `useCSSVariable` see the scope; `tw()` and `getCSSVariable()` don't. Changing
|
|
208
|
+
* `variables` re-renders only the elements inside that read a variable whose value changed.
|
|
209
|
+
*/
|
|
210
|
+
export function ScopedVariables({ variables, children }) {
|
|
211
|
+
const parent = useContext(ScopeContext);
|
|
212
|
+
const parentVariables = parent?.variables;
|
|
213
|
+
// One scope per mount (and per enclosing variable scope): the context value stays stable
|
|
214
|
+
// while `variables` changes, so only subscribers whose signature changed re-render.
|
|
215
|
+
// biome-ignore lint/correctness/useExhaustiveDependencies: `variables` only seeds the scope; later values go through `setOwn`.
|
|
216
|
+
const scope = useMemo(() => createVariableScope(parentVariables, variables), [parentVariables]);
|
|
217
|
+
// Store this render's values before the children render, so a child that renders now
|
|
218
|
+
// (including one that mounts in this commit) reads them the first time. Subscribers that
|
|
219
|
+
// didn't re-render are notified after commit, before paint.
|
|
220
|
+
scope.setOwn(variables);
|
|
221
|
+
// biome-ignore lint/correctness/useExhaustiveDependencies: commit after every render that changed `variables`.
|
|
222
|
+
useLayoutEffect(() => {
|
|
223
|
+
scope.commit();
|
|
224
|
+
}, [scope, variables]);
|
|
225
|
+
const value = useMemo(() => Object.freeze({ ...parent, variables: scope }), [parent, scope]);
|
|
226
|
+
return createElement(ScopeContext.Provider, { value }, children);
|
|
227
|
+
}
|
|
228
|
+
//# sourceMappingURL=scope.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"scope.js","sourceRoot":"","sources":["../src/scope.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,aAAa,EACb,aAAa,EAGb,UAAU,EACV,eAAe,EACf,OAAO,GACR,MAAM,OAAO,CAAA;AACd,OAAO,EAAE,YAAY,EAAE,MAAM,QAAQ,CAAA;AAErC,OAAO,EAAE,oBAAoB,EAAE,uBAAuB,EAAE,MAAM,aAAa,CAAA;AA+C3E,MAAM,QAAQ,GAAsB,MAAM,CAAC,MAAM,CAAC,EAAE,CAAC,CAAA;AAErD,SAAS,SAAS,CAAC,CAAoB,EAAE,CAAoB;IAC3D,OAAO,CAAC,CAA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G,eAAe,CAAC,GAAG,EAAE;QACnB,KAAK,CAAC,MAAM,EAAE,CAAA;IAChB,CAAC,EAAE,CAAC,KAAK,EAAE,SAAS,CAAC,CAAC,CAAA;IAEtB,MAAM,KAAK,GAAG,OAAO,CAAsB,GAAG,EAAE,CAAC,MAAM,CAAC,MAAM,CAAC,EAAE,GAAG,MAAM,EAAE,SAAS,EAAE,KAAK,EAAE,CAAC,EAAE,CAAC,MAAM,EAAE,KAAK,CAAC,CAAC,CAAA;IAEjH,OAAO,aAAa,CAAC,YAAY,CAAC,QAAQ,EAAE,EAAE,KAAK,EAAE,EAAE,QAAQ,CAAC,CAAA;AAClE,CAAC"}
|
package/dist/store.d.ts
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import type { ColorScheme, NitroWindEnvironment, ThemeDefinition, ThemePreference, ThemeState, Unsubscribe, ViewportSize } from './types';
|
|
2
|
+
export interface NitroWindStore {
|
|
3
|
+
getTheme(): ThemeState;
|
|
4
|
+
getColorScheme(): ColorScheme;
|
|
5
|
+
setTheme(preference: ThemePreference): void;
|
|
6
|
+
getViewportSize(): ViewportSize | undefined;
|
|
7
|
+
getReducedMotion(): boolean;
|
|
8
|
+
readonly subscribeTheme: (listener: () => void) => Unsubscribe;
|
|
9
|
+
readonly subscribeViewport: (listener: () => void) => Unsubscribe;
|
|
10
|
+
readonly subscribeReducedMotion: (listener: () => void) => Unsubscribe;
|
|
11
|
+
readonly subscribeVariables: (names: readonly string[], listener: () => void, theme?: string) => Unsubscribe;
|
|
12
|
+
readonly getVariablesSubscriber: (names: readonly string[], theme?: string) => (listener: () => void) => Unsubscribe;
|
|
13
|
+
readonly getSubscribedVariableThemes: () => Iterable<string>;
|
|
14
|
+
notifyVariables(names: Iterable<string>, theme?: string): void;
|
|
15
|
+
}
|
|
16
|
+
/** Creates the channel store backed by an injected environment. */
|
|
17
|
+
export declare function createStore(environment: NitroWindEnvironment, themes: Readonly<Record<string, ThemeDefinition>>, initialTheme?: ThemePreference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mEAAmE;AACnE,wBAAgB,WAAW,CACzB,WAAW,EAAE,oBAAoB,EACjC,MAAM,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,eAAe,CAAC,CAAC,EACjD,YAAY,GAAE,eAA0B,GACvC,cAAc,CAsMhB"}
|
package/dist/store.js
ADDED
|
@@ -0,0 +1,244 @@
|
|
|
1
|
+
function createChannel(read, listen, isEqual, eagerListenOnRead = false) {
|
|
2
|
+
const listeners = new Set();
|
|
3
|
+
let hasValue = false;
|
|
4
|
+
let current;
|
|
5
|
+
let unsubscribeSource;
|
|
6
|
+
const attachSource = () => {
|
|
7
|
+
if (unsubscribeSource !== undefined)
|
|
8
|
+
return;
|
|
9
|
+
current = read();
|
|
10
|
+
hasValue = true;
|
|
11
|
+
unsubscribeSource = listen((next) => {
|
|
12
|
+
if (hasValue && isEqual(current, next))
|
|
13
|
+
return;
|
|
14
|
+
current = next;
|
|
15
|
+
hasValue = true;
|
|
16
|
+
for (const fn of [...listeners])
|
|
17
|
+
fn();
|
|
18
|
+
});
|
|
19
|
+
};
|
|
20
|
+
const subscribe = (listener) => {
|
|
21
|
+
if (listeners.size === 0)
|
|
22
|
+
attachSource();
|
|
23
|
+
listeners.add(listener);
|
|
24
|
+
return () => {
|
|
25
|
+
listeners.delete(listener);
|
|
26
|
+
if (listeners.size > 0 || eagerListenOnRead)
|
|
27
|
+
return;
|
|
28
|
+
unsubscribeSource?.();
|
|
29
|
+
unsubscribeSource = undefined;
|
|
30
|
+
hasValue = false;
|
|
31
|
+
};
|
|
32
|
+
};
|
|
33
|
+
return {
|
|
34
|
+
get: () => {
|
|
35
|
+
if (eagerListenOnRead)
|
|
36
|
+
attachSource();
|
|
37
|
+
return hasValue ? current : read();
|
|
38
|
+
},
|
|
39
|
+
subscribe,
|
|
40
|
+
};
|
|
41
|
+
}
|
|
42
|
+
function sameViewport(a, b) {
|
|
43
|
+
if (a === b)
|
|
44
|
+
return true;
|
|
45
|
+
return a !== undefined && b !== undefined && a.width === b.width && a.height === b.height;
|
|
46
|
+
}
|
|
47
|
+
function sameThemeState(a, b) {
|
|
48
|
+
return a.theme === b.theme && a.colorScheme === b.colorScheme && a.preference === b.preference;
|
|
49
|
+
}
|
|
50
|
+
/** Creates the channel store backed by an injected environment. */
|
|
51
|
+
export function createStore(environment, themes, initialTheme = 'system') {
|
|
52
|
+
const themeListeners = new Set();
|
|
53
|
+
let preference = initialTheme;
|
|
54
|
+
let currentTheme;
|
|
55
|
+
let unsubscribeColorScheme;
|
|
56
|
+
let suppressOsListener = false;
|
|
57
|
+
function makeThemeState(pref, osScheme) {
|
|
58
|
+
if (pref === 'system') {
|
|
59
|
+
const scheme = osScheme ?? environment.getColorScheme();
|
|
60
|
+
return Object.freeze({ theme: scheme, colorScheme: scheme, preference: 'system' });
|
|
61
|
+
}
|
|
62
|
+
const def = themes[pref];
|
|
63
|
+
return Object.freeze({ theme: pref, colorScheme: def.colorScheme, preference: pref });
|
|
64
|
+
}
|
|
65
|
+
function notifyTheme() {
|
|
66
|
+
for (const fn of [...themeListeners])
|
|
67
|
+
fn();
|
|
68
|
+
}
|
|
69
|
+
if (initialTheme !== 'system') {
|
|
70
|
+
currentTheme = makeThemeState(initialTheme);
|
|
71
|
+
environment.setColorScheme(currentTheme.colorScheme);
|
|
72
|
+
}
|
|
73
|
+
function getTheme() {
|
|
74
|
+
if (preference !== 'system')
|
|
75
|
+
return currentTheme;
|
|
76
|
+
if (themeListeners.size > 0 && currentTheme !== undefined)
|
|
77
|
+
return currentTheme;
|
|
78
|
+
const scheme = environment.getColorScheme();
|
|
79
|
+
if (currentTheme !== undefined && currentTheme.preference === 'system' && currentTheme.colorScheme === scheme) {
|
|
80
|
+
return currentTheme;
|
|
81
|
+
}
|
|
82
|
+
currentTheme = makeThemeState('system', scheme);
|
|
83
|
+
return currentTheme;
|
|
84
|
+
}
|
|
85
|
+
const subscribeTheme = (listener) => {
|
|
86
|
+
if (themeListeners.size === 0) {
|
|
87
|
+
if (preference === 'system') {
|
|
88
|
+
const scheme = environment.getColorScheme();
|
|
89
|
+
if (currentTheme === undefined || currentTheme.preference !== 'system' || currentTheme.colorScheme !== scheme) {
|
|
90
|
+
currentTheme = makeThemeState('system', scheme);
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
unsubscribeColorScheme = environment.subscribeColorScheme((nextScheme) => {
|
|
94
|
+
if (suppressOsListener || preference !== 'system')
|
|
95
|
+
return;
|
|
96
|
+
const next = makeThemeState('system', nextScheme);
|
|
97
|
+
if (currentTheme !== undefined && sameThemeState(currentTheme, next))
|
|
98
|
+
return;
|
|
99
|
+
currentTheme = next;
|
|
100
|
+
notifyTheme();
|
|
101
|
+
});
|
|
102
|
+
}
|
|
103
|
+
themeListeners.add(listener);
|
|
104
|
+
return () => {
|
|
105
|
+
themeListeners.delete(listener);
|
|
106
|
+
if (themeListeners.size > 0)
|
|
107
|
+
return;
|
|
108
|
+
unsubscribeColorScheme?.();
|
|
109
|
+
unsubscribeColorScheme = undefined;
|
|
110
|
+
};
|
|
111
|
+
};
|
|
112
|
+
function setTheme(nextPreference) {
|
|
113
|
+
if (nextPreference !== 'system' && !Object.prototype.hasOwnProperty.call(themes, nextPreference)) {
|
|
114
|
+
throw new Error(`[nitrowind] Unregistered theme "${nextPreference}"`);
|
|
115
|
+
}
|
|
116
|
+
const prev = currentTheme;
|
|
117
|
+
preference = nextPreference;
|
|
118
|
+
if (nextPreference === 'system') {
|
|
119
|
+
suppressOsListener = true;
|
|
120
|
+
try {
|
|
121
|
+
environment.setColorScheme('auto');
|
|
122
|
+
}
|
|
123
|
+
finally {
|
|
124
|
+
suppressOsListener = false;
|
|
125
|
+
}
|
|
126
|
+
const next = makeThemeState('system', environment.getColorScheme());
|
|
127
|
+
const changed = prev === undefined || !sameThemeState(prev, next);
|
|
128
|
+
currentTheme = next;
|
|
129
|
+
if (changed)
|
|
130
|
+
notifyTheme();
|
|
131
|
+
return;
|
|
132
|
+
}
|
|
133
|
+
const next = makeThemeState(nextPreference);
|
|
134
|
+
const changed = prev === undefined || !sameThemeState(prev, next);
|
|
135
|
+
currentTheme = next;
|
|
136
|
+
suppressOsListener = true;
|
|
137
|
+
try {
|
|
138
|
+
environment.setColorScheme(next.colorScheme);
|
|
139
|
+
}
|
|
140
|
+
finally {
|
|
141
|
+
suppressOsListener = false;
|
|
142
|
+
}
|
|
143
|
+
if (changed)
|
|
144
|
+
notifyTheme();
|
|
145
|
+
}
|
|
146
|
+
const viewport = createChannel(() => environment.getViewportSize(), (onChange) => environment.subscribeViewportSize(onChange), sameViewport, true);
|
|
147
|
+
const reducedMotion = createChannel(() => environment.native?.getReducedMotion() ?? false, (onChange) => environment.native?.subscribeReducedMotion(onChange) ?? (() => { }), Object.is);
|
|
148
|
+
const activeVariableListeners = new Map();
|
|
149
|
+
const scopedVariableListeners = new Map();
|
|
150
|
+
const variableSubscribersByRef = new WeakMap();
|
|
151
|
+
const variableSubscribersByKey = new Map();
|
|
152
|
+
const MAX_VARIABLE_SUBSCRIBER_KEYS = 256;
|
|
153
|
+
const subscribeVariables = (names, listener, theme) => {
|
|
154
|
+
if (names.length === 0)
|
|
155
|
+
return () => { };
|
|
156
|
+
let listenersMap;
|
|
157
|
+
if (theme === undefined) {
|
|
158
|
+
listenersMap = activeVariableListeners;
|
|
159
|
+
}
|
|
160
|
+
else {
|
|
161
|
+
let existing = scopedVariableListeners.get(theme);
|
|
162
|
+
if (existing === undefined) {
|
|
163
|
+
existing = new Map();
|
|
164
|
+
scopedVariableListeners.set(theme, existing);
|
|
165
|
+
}
|
|
166
|
+
listenersMap = existing;
|
|
167
|
+
}
|
|
168
|
+
for (const name of names) {
|
|
169
|
+
let set = listenersMap.get(name);
|
|
170
|
+
if (set === undefined) {
|
|
171
|
+
set = new Set();
|
|
172
|
+
listenersMap.set(name, set);
|
|
173
|
+
}
|
|
174
|
+
set.add(listener);
|
|
175
|
+
}
|
|
176
|
+
return () => {
|
|
177
|
+
for (const name of names) {
|
|
178
|
+
const set = listenersMap.get(name);
|
|
179
|
+
if (set === undefined)
|
|
180
|
+
continue;
|
|
181
|
+
set.delete(listener);
|
|
182
|
+
if (set.size === 0)
|
|
183
|
+
listenersMap.delete(name);
|
|
184
|
+
}
|
|
185
|
+
if (theme !== undefined && listenersMap.size === 0 && scopedVariableListeners.get(theme) === listenersMap) {
|
|
186
|
+
scopedVariableListeners.delete(theme);
|
|
187
|
+
}
|
|
188
|
+
};
|
|
189
|
+
};
|
|
190
|
+
const getVariablesSubscriber = (names, theme) => {
|
|
191
|
+
if (theme === undefined) {
|
|
192
|
+
const byRef = variableSubscribersByRef.get(names);
|
|
193
|
+
if (byRef !== undefined)
|
|
194
|
+
return byRef;
|
|
195
|
+
}
|
|
196
|
+
const key = theme === undefined ? names.join('\0') : `${theme}\x01${names.join('\0')}`;
|
|
197
|
+
let subscriber = variableSubscribersByKey.get(key);
|
|
198
|
+
if (subscriber === undefined) {
|
|
199
|
+
const snapshotNames = [...names];
|
|
200
|
+
subscriber = (listener) => subscribeVariables(snapshotNames, listener, theme);
|
|
201
|
+
if (variableSubscribersByKey.size >= MAX_VARIABLE_SUBSCRIBER_KEYS) {
|
|
202
|
+
const oldest = variableSubscribersByKey.keys().next().value;
|
|
203
|
+
if (oldest !== undefined)
|
|
204
|
+
variableSubscribersByKey.delete(oldest);
|
|
205
|
+
}
|
|
206
|
+
variableSubscribersByKey.set(key, subscriber);
|
|
207
|
+
}
|
|
208
|
+
if (theme === undefined) {
|
|
209
|
+
variableSubscribersByRef.set(names, subscriber);
|
|
210
|
+
}
|
|
211
|
+
return subscriber;
|
|
212
|
+
};
|
|
213
|
+
const getSubscribedVariableThemes = () => scopedVariableListeners.keys();
|
|
214
|
+
function notifyVariables(names, theme) {
|
|
215
|
+
const listenersMap = theme === undefined ? activeVariableListeners : scopedVariableListeners.get(theme);
|
|
216
|
+
if (listenersMap === undefined)
|
|
217
|
+
return;
|
|
218
|
+
const toNotify = new Set();
|
|
219
|
+
for (const name of names) {
|
|
220
|
+
const set = listenersMap.get(name);
|
|
221
|
+
if (set !== undefined) {
|
|
222
|
+
for (const fn of set)
|
|
223
|
+
toNotify.add(fn);
|
|
224
|
+
}
|
|
225
|
+
}
|
|
226
|
+
for (const fn of toNotify)
|
|
227
|
+
fn();
|
|
228
|
+
}
|
|
229
|
+
return {
|
|
230
|
+
getTheme,
|
|
231
|
+
getColorScheme: () => getTheme().colorScheme,
|
|
232
|
+
setTheme,
|
|
233
|
+
getViewportSize: viewport.get,
|
|
234
|
+
getReducedMotion: reducedMotion.get,
|
|
235
|
+
subscribeTheme,
|
|
236
|
+
subscribeViewport: viewport.subscribe,
|
|
237
|
+
subscribeReducedMotion: reducedMotion.subscribe,
|
|
238
|
+
subscribeVariables,
|
|
239
|
+
getVariablesSubscriber,
|
|
240
|
+
getSubscribedVariableThemes,
|
|
241
|
+
notifyVariables,
|
|
242
|
+
};
|
|
243
|
+
}
|
|
244
|
+
//# sourceMappingURL=store.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"store.js","sourceRoot":"","sources":["../src/store.ts"],"names":[],"mappings":"AA+BA,SAAS,aAAa,CACpB,IAAa,EACb,MAAoD,EACpD,OAAgC,EAChC,iBAAiB,GAAG,KAAK;IAEzB,MAAM,SAAS,GAAG,IAAI,GAAG,EAAc,CAAA;IACvC,IAAI,QAAQ,GAAG,KAAK,CAAA;IACpB,IAAI,OAAU,CAAA;IACd,IAAI,iBAA0C,CAAA;IAE9C,MAAM,YAAY,GAAG,GAAS,EAAE;QAC9B,IAAI,iBAAiB,KAAK,SAAS;YAAE,OAAM;QAC3C,OAAO,GAAG,IAAI,EAAE,CAAA;QAChB,QAAQ,GAAG,IAAI,CAAA;QACf,iBAAiB,GAAG,MAAM,CAAC,CAAC,IAAI,EAAE,EAAE;YAClC,IAAI,QAAQ,IAAI,OAAO,CAAC,OAAO,EAAE,IAAI,CAAC;gBAAE,OAAM;YAC9C,OAAO,GAAG,IAAI,CAAA;YACd,QAAQ,GAAG,IAAI,C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CAAC,CAAA;QACvG,IAAI,YAAY,KAAK,SAAS;YAAE,OAAM;QACtC,MAAM,QAAQ,GAAG,IAAI,GAAG,EAAc,CAAA;QACtC,KAAK,MAAM,IAAI,IAAI,KAAK,EAAE,CAAC;YACzB,MAAM,GAAG,GAAG,YAAY,CAAC,GAAG,CAAC,IAAI,CAAC,CAAA;YAClC,IAAI,GAAG,KAAK,SAAS,EAAE,CAAC;gBACtB,KAAK,MAAM,EAAE,IAAI,GAAG;oBAAE,QAAQ,CAAC,GAAG,CAAC,EAAE,CAAC,CAAA;YACxC,CAAC;QACH,CAAC;QACD,KAAK,MAAM,EAAE,IAAI,QAAQ;YAAE,EAAE,EAAE,CAAA;IACjC,CAAC;IAED,OAAO;QACL,QAAQ;QACR,cAAc,EAAE,GAAG,EAAE,CAAC,QAAQ,EAAE,CAAC,WAAW;QAC5C,QAAQ;QACR,eAAe,EAAE,QAAQ,CAAC,GAAG;QAC7B,gBAAgB,EAAE,aAAa,CAAC,GAAG;QACnC,cAAc;QACd,iBAAiB,EAAE,QAAQ,CAAC,SAAS;QACrC,sBAAsB,EAAE,aAAa,CAAC,SAAS;QAC/C,kBAAkB;QAClB,sBAAsB;QACtB,2BAA2B;QAC3B,eAAe;KAChB,CAAA;AACH,CAAC"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { tailwindTokens } from './tailwind.generated';
|
|
2
|
+
import type { Tokens, TokensConfig } from './types';
|
|
3
|
+
export * from './types';
|
|
4
|
+
export { tailwindTokens };
|
|
5
|
+
/** Parses a breakpoint length (`rem`, `px`, `pt`, or points) into points, or `null` if invalid. */
|
|
6
|
+
export declare function parseBreakpointLength(value: number | string): number | null;
|
|
7
|
+
/**
|
|
8
|
+
* Builds design tokens from Tailwind's defaults. Groups set directly on `config`
|
|
9
|
+
* replace the default group; groups under `config.extend` are merged into it.
|
|
10
|
+
*/
|
|
11
|
+
export declare function createTokens(config?: TokensConfig, base?: Tokens): Tokens;
|
|
12
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/tokens/index.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,cAAc,EAAE,MAAM,sBAAsB,CAAA;AACrD,OAAO,KAAK,EAKV,MAAM,EACN,YAAY,EAEb,MAAM,SAAS,CAAA;AAEhB,cAAc,SAAS,CAAA;AACvB,OAAO,EAAE,cAAc,EAAE,CAAA;AAKzB,mGAAmG;AACnG,wBAAgB,qBAAqB,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,GAAG,MAAM,GAAG,IAAI,CAU3E;AAmMD;;;GAGG;AACH,wBAAgB,YAAY,CAAC,MAAM,GAAE,YAAiB,EAAE,IAAI,GAAE,MAAuB,GAAG,MAAM,CAsB7F"}
|