@multiplatform.one/storybook 9.16.1 → 10.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (47) hide show
  1. package/dist/cjs/CreatePreview.cjs +554 -589
  2. package/dist/cjs/CreatePreview.native.cjs +802 -0
  3. package/dist/cjs/CreatePreview.native.js +744 -823
  4. package/dist/cjs/CreatePreview.native.js.map +1 -1
  5. package/dist/cjs/index.cjs +17 -19
  6. package/dist/cjs/index.native.cjs +35 -0
  7. package/dist/cjs/index.native.js +22 -25
  8. package/dist/cjs/index.native.js.map +1 -1
  9. package/dist/cjs/safeAction.cjs +53 -57
  10. package/dist/cjs/safeAction.native.cjs +98 -0
  11. package/dist/cjs/safeAction.native.js +79 -98
  12. package/dist/cjs/safeAction.native.js.map +1 -1
  13. package/dist/esm/CreatePreview.mjs +533 -559
  14. package/dist/esm/CreatePreview.mjs.map +1 -1
  15. package/dist/esm/CreatePreview.native.js +723 -794
  16. package/dist/esm/CreatePreview.native.js.map +1 -1
  17. package/dist/esm/index.mjs +4 -3
  18. package/dist/esm/index.native.js +9 -8
  19. package/dist/esm/index.native.js.map +1 -1
  20. package/dist/esm/safeAction.mjs +42 -40
  21. package/dist/esm/safeAction.mjs.map +1 -1
  22. package/dist/esm/safeAction.native.js +67 -81
  23. package/dist/esm/safeAction.native.js.map +1 -1
  24. package/dist/jsx/CreatePreview.mjs +533 -559
  25. package/dist/jsx/CreatePreview.mjs.map +1 -1
  26. package/dist/jsx/CreatePreview.native.cjs +802 -0
  27. package/dist/jsx/CreatePreview.native.js +744 -823
  28. package/dist/jsx/CreatePreview.native.js.map +1 -1
  29. package/dist/jsx/index.js +4 -3
  30. package/dist/jsx/index.mjs +4 -3
  31. package/dist/jsx/index.native.cjs +35 -0
  32. package/dist/jsx/index.native.js +22 -25
  33. package/dist/jsx/index.native.js.map +1 -1
  34. package/dist/jsx/safeAction.mjs +42 -40
  35. package/dist/jsx/safeAction.mjs.map +1 -1
  36. package/dist/jsx/safeAction.native.cjs +98 -0
  37. package/dist/jsx/safeAction.native.js +79 -98
  38. package/dist/jsx/safeAction.native.js.map +1 -1
  39. package/package.json +14 -14
  40. package/src/CreatePreview.consoleErrors.spec.ts +49 -0
  41. package/src/CreatePreview.spec.tsx +1 -1
  42. package/src/CreatePreview.tsx +5 -30
  43. package/types/CreatePreview.d.ts +6 -0
  44. package/types/CreatePreview.d.ts.map +1 -1
  45. package/dist/esm/index.mjs.map +0 -1
  46. package/dist/jsx/index.js.map +0 -1
  47. package/dist/jsx/index.mjs.map +0 -1
@@ -5,43 +5,36 @@ var __getOwnPropNames = Object.getOwnPropertyNames;
5
5
  var __getProtoOf = Object.getPrototypeOf;
6
6
  var __hasOwnProp = Object.prototype.hasOwnProperty;
7
7
  var __export = (target, all) => {
8
- for (var name in all) __defProp(target, name, {
9
- get: all[name],
10
- enumerable: true
11
- });
8
+ for (var name in all) __defProp(target, name, {
9
+ get: all[name],
10
+ enumerable: true
11
+ });
12
12
  };
13
13
  var __copyProps = (to, from, except, desc) => {
14
- if (from && typeof from === "object" || typeof from === "function") {
15
- for (let key of __getOwnPropNames(from)) if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
16
- get: () => from[key],
17
- enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
18
- });
19
- }
20
- return to;
14
+ if (from && typeof from === "object" || typeof from === "function") {
15
+ for (let key of __getOwnPropNames(from)) if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
16
+ get: () => from[key],
17
+ enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
18
+ });
19
+ }
20
+ return to;
21
21
  };
22
- var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
23
- // If the importer is in node compatibility mode or this is not an ESM
24
- // file that has been converted to a CommonJS file using a Babel-
25
- // compatible transform (i.e. "__esModule" has not been set), then set
26
- // "default" to the CommonJS "module.exports" for node compatibility.
27
- isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", {
28
- value: mod,
29
- enumerable: true
22
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", {
23
+ value: mod,
24
+ enumerable: true
30
25
  }) : target, mod));
31
- var __toCommonJS = mod => __copyProps(__defProp({}, "__esModule", {
32
- value: true
33
- }), mod);
26
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
34
27
  var CreatePreview_exports = {};
35
28
  __export(CreatePreview_exports, {
36
- accentColorsChannelEvent: () => accentColorsChannelEvent,
37
- accentOppositeChannelEvent: () => accentOppositeChannelEvent,
38
- animationNamesChannelEvent: () => animationNamesChannelEvent,
39
- baseOppositeChannelEvent: () => baseOppositeChannelEvent,
40
- baseThemeColorsChannelEvent: () => baseThemeColorsChannelEvent,
41
- createPreview: () => createPreview,
42
- frappeDebugChannelEvent: () => frappeDebugChannelEvent,
43
- themeColorsChannelEvent: () => themeColorsChannelEvent,
44
- themeColorsOppositeChannelEvent: () => themeColorsOppositeChannelEvent
29
+ accentColorsChannelEvent: () => accentColorsChannelEvent,
30
+ accentOppositeChannelEvent: () => accentOppositeChannelEvent,
31
+ animationNamesChannelEvent: () => animationNamesChannelEvent,
32
+ baseOppositeChannelEvent: () => baseOppositeChannelEvent,
33
+ baseThemeColorsChannelEvent: () => baseThemeColorsChannelEvent,
34
+ createPreview: () => createPreview,
35
+ frappeDebugChannelEvent: () => frappeDebugChannelEvent,
36
+ themeColorsChannelEvent: () => themeColorsChannelEvent,
37
+ themeColorsOppositeChannelEvent: () => themeColorsOppositeChannelEvent
45
38
  });
46
39
  module.exports = __toCommonJS(CreatePreview_exports);
47
40
  var import_react = require("react");
@@ -60,582 +53,554 @@ const animationNamesChannelEvent = "theme-addon/animation-names";
60
53
  const frappeDebugChannelEvent = "frappe-addon/debug-state";
61
54
  const defaultThemeConfigName = "full";
62
55
  const knobOptions = {
63
- fillStyle: Object.values(import_theme.FillStyle),
64
- borderRadius: Object.values(import_theme.BorderRadius),
65
- cornerSmoothing: Object.values(import_theme.CornerSmoothing),
66
- borderWidth: Object.values(import_theme.BorderWidth),
67
- elevation: Object.values(import_theme.Elevation),
68
- textAccent: Object.values(import_theme.TextAccent),
69
- headingFont: Object.values(import_theme.HeadingFont),
70
- bodyFont: Object.values(import_theme.BodyFont),
71
- fontWeight: Object.values(import_theme.FontWeight),
72
- // D-11 hero-H1 dial: the page-title step is sweepable so the VERIFY probes
73
- // (and humans) can flip moderate/display from the toolbar or URL globals.
74
- pageTitleScale: Object.values(import_theme.PageTitleScale),
75
- animation: ["none", ...import_theme.motionStops],
76
- // LC-40 DISABLED-VISIBLE: the disabled-treatment dial is sweepable so the
77
- // VERIFY probes (and humans) can flip keepLabel/dimWhole from the toolbar
78
- // or via URL globals.
79
- disabledStyle: Object.values(import_theme.DisabledStyle),
80
- // K4: the one house knob a table sweep has to flip (MPO-132).
81
- tableZebra: Object.values(import_theme.TableZebra)
56
+ fillStyle: Object.values(import_theme.FillStyle),
57
+ borderRadius: Object.values(import_theme.BorderRadius),
58
+ cornerSmoothing: Object.values(import_theme.CornerSmoothing),
59
+ borderWidth: Object.values(import_theme.BorderWidth),
60
+ elevation: Object.values(import_theme.Elevation),
61
+ textAccent: Object.values(import_theme.TextAccent),
62
+ headingFont: Object.values(import_theme.HeadingFont),
63
+ bodyFont: Object.values(import_theme.BodyFont),
64
+ fontWeight: Object.values(import_theme.FontWeight),
65
+ pageTitleScale: Object.values(import_theme.PageTitleScale),
66
+ animation: ["none", ...import_theme.motionStops],
67
+ disabledStyle: Object.values(import_theme.DisabledStyle),
68
+ tableZebra: Object.values(import_theme.TableZebra)
82
69
  };
83
- const stateKnobFields = ["fillStyle", "borderRadius", "borderWidth", "elevation", "textAccent", "headingFont", "bodyFont", "fontWeight"];
70
+ const stateKnobFields = [
71
+ "fillStyle",
72
+ "borderRadius",
73
+ "borderWidth",
74
+ "elevation",
75
+ "textAccent",
76
+ "headingFont",
77
+ "bodyFont",
78
+ "fontWeight"
79
+ ];
84
80
  function parseValue(value) {
85
- if (typeof value !== "string") return value;
86
- try {
87
- return JSON.parse(value);
88
- } catch {
89
- return value;
90
- }
81
+ if (typeof value !== "string") return value;
82
+ try {
83
+ return JSON.parse(value);
84
+ } catch {
85
+ return value;
86
+ }
91
87
  }
92
- const toTitleCase = str => str.replace(/([A-Z])/g, " $1").replace(/^./, s => s.toUpperCase());
88
+ const toTitleCase = (str) => str.replace(/([A-Z])/g, " $1").replace(/^./, (s) => s.toUpperCase());
93
89
  function createControl(key) {
94
- const name = toTitleCase(key);
95
- const values = knobOptions[key] ?? [];
96
- const serialized = values.map(value => value);
97
- const labels = Object.fromEntries(serialized.map(v => [v, v.replace("$", "")]));
98
- const fallback = import_theme.defaultKnobs[key];
99
- return {
100
- name,
101
- description: name.toLowerCase(),
102
- options: serialized,
103
- control: {
104
- type: "select",
105
- labels
106
- },
107
- ...(fallback !== void 0 && {
108
- defaultValue: fallback
109
- })
110
- };
90
+ const name = toTitleCase(key);
91
+ const values = knobOptions[key] ?? [];
92
+ const serialized = values.map((value) => value);
93
+ const labels = Object.fromEntries(serialized.map((v) => [v, v.replace("$", "")]));
94
+ const fallback = import_theme.defaultKnobs[key];
95
+ return {
96
+ name,
97
+ description: name.toLowerCase(),
98
+ options: serialized,
99
+ control: {
100
+ type: "select",
101
+ labels
102
+ },
103
+ ...fallback !== void 0 && { defaultValue: fallback }
104
+ };
111
105
  }
112
- function CanvasBackground({
113
- children
114
- }) {
115
- const tamaguiTheme = (0, import_tamagui.useTheme)();
116
- const bg = tamaguiTheme.background?.val;
117
- (0, import_react.useLayoutEffect)(() => {
118
- if (bg && typeof document !== "undefined") {
119
- document.body.style.backgroundColor = bg;
120
- document.documentElement.style.backgroundColor = bg;
121
- }
122
- }, [bg]);
123
- return /* @__PURE__ */(0, import_jsx_runtime.jsx)(import_tamagui.YStack, {
124
- flex: 1,
125
- minHeight: "100vh",
126
- backgroundColor: "$background",
127
- id: "mpo-matrix-root",
128
- children
129
- });
106
+ function CanvasBackground({ children }) {
107
+ const tamaguiTheme = (0, import_tamagui.useTheme)();
108
+ const bg = tamaguiTheme.background?.val;
109
+ (0, import_react.useLayoutEffect)(() => {
110
+ if (bg && typeof document !== "undefined") {
111
+ document.body.style.backgroundColor = bg;
112
+ document.documentElement.style.backgroundColor = bg;
113
+ }
114
+ }, [bg]);
115
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_tamagui.YStack, {
116
+ flex: 1,
117
+ minHeight: "100vh",
118
+ backgroundColor: "background",
119
+ id: "mpo-matrix-root",
120
+ children
121
+ });
130
122
  }
131
123
  let _channelEmit = null;
132
124
  function getChannelEmit() {
133
- if (_channelEmit) return _channelEmit;
134
- try {
135
- const mod = require("storybook/preview-api");
136
- const channel = mod.addons.getChannel();
137
- _channelEmit = (event, data) => channel.emit(event, data);
138
- return _channelEmit;
139
- } catch {
140
- return null;
141
- }
125
+ if (_channelEmit) return _channelEmit;
126
+ try {
127
+ const mod = require("storybook/preview-api");
128
+ const channel = mod.addons.getChannel();
129
+ _channelEmit = (event, data) => channel.emit(event, data);
130
+ return _channelEmit;
131
+ } catch {
132
+ return null;
133
+ }
142
134
  }
143
135
  function AnimationNamesEmitter() {
144
- const emittedRef = (0, import_react.useRef)(false);
145
- (0, import_react.useEffect)(() => {
146
- if (emittedRef.current) return;
147
- emittedRef.current = true;
148
- getChannelEmit()?.(animationNamesChannelEvent, [...import_theme.motionStops]);
149
- }, []);
150
- return null;
136
+ const emittedRef = (0, import_react.useRef)(false);
137
+ (0, import_react.useEffect)(() => {
138
+ if (emittedRef.current) return;
139
+ emittedRef.current = true;
140
+ getChannelEmit()?.(animationNamesChannelEvent, [...import_theme.motionStops]);
141
+ }, []);
142
+ return null;
151
143
  }
152
144
  function FrappeDebugEmitter() {
153
- const prevRef = (0, import_react.useRef)("");
154
- const syncRef = (0, import_react.useRef)(null);
155
- const [tick, setTick] = (0, import_react.useState)(0);
156
- (0, import_react.useEffect)(() => {
157
- let cancelled = false;
158
- async function resolve() {
159
- try {
160
- const {
161
- __getActiveSyncModule
162
- } = await import("@multiplatform.one/frappe");
163
- const sync = __getActiveSyncModule();
164
- if (sync && !cancelled) {
165
- syncRef.current = sync;
166
- setTick(t => t + 1);
167
- return sync.subscribeStore(() => {
168
- if (!cancelled) setTick(t => t + 1);
169
- });
170
- }
171
- } catch {}
172
- }
173
- const cleanupPromise = resolve();
174
- let attempts = 0;
175
- const interval = setInterval(async () => {
176
- attempts++;
177
- if (syncRef.current || cancelled || attempts >= 10) {
178
- clearInterval(interval);
179
- return;
180
- }
181
- await resolve();
182
- }, 2e3);
183
- return () => {
184
- cancelled = true;
185
- clearInterval(interval);
186
- cleanupPromise.then(unsub => unsub?.());
187
- };
188
- }, []);
189
- (0, import_react.useEffect)(() => {
190
- if (!syncRef.current) return;
191
- const emit = getChannelEmit();
192
- if (!emit) return;
193
- try {
194
- const state = syncRef.current.__debug();
195
- const key = JSON.stringify(state);
196
- if (key === prevRef.current) return;
197
- prevRef.current = key;
198
- emit(frappeDebugChannelEvent, state);
199
- } catch {}
200
- }, [tick]);
201
- return null;
145
+ const prevRef = (0, import_react.useRef)("");
146
+ const syncRef = (0, import_react.useRef)(null);
147
+ const [tick, setTick] = (0, import_react.useState)(0);
148
+ (0, import_react.useEffect)(() => {
149
+ let cancelled = false;
150
+ async function resolve() {
151
+ try {
152
+ const { __getActiveSyncModule } = await import("@multiplatform.one/frappe");
153
+ const sync = __getActiveSyncModule();
154
+ if (sync && !cancelled) {
155
+ syncRef.current = sync;
156
+ setTick((t) => t + 1);
157
+ return sync.subscribeStore(() => {
158
+ if (!cancelled) setTick((t) => t + 1);
159
+ });
160
+ }
161
+ } catch {}
162
+ }
163
+ const cleanupPromise = resolve();
164
+ let attempts = 0;
165
+ const interval = setInterval(async () => {
166
+ attempts++;
167
+ if (syncRef.current || cancelled || attempts >= 10) {
168
+ clearInterval(interval);
169
+ return;
170
+ }
171
+ await resolve();
172
+ }, 2e3);
173
+ return () => {
174
+ cancelled = true;
175
+ clearInterval(interval);
176
+ cleanupPromise.then((unsub) => unsub?.());
177
+ };
178
+ }, []);
179
+ (0, import_react.useEffect)(() => {
180
+ if (!syncRef.current) return;
181
+ const emit = getChannelEmit();
182
+ if (!emit) return;
183
+ try {
184
+ const state = syncRef.current.__debug();
185
+ const key = JSON.stringify(state);
186
+ if (key === prevRef.current) return;
187
+ prevRef.current = key;
188
+ emit(frappeDebugChannelEvent, state);
189
+ } catch {}
190
+ }, [tick]);
191
+ return null;
202
192
  }
203
193
  function ThemeColorEmitter() {
204
- const tamaguiTheme = (0, import_tamagui.useTheme)();
205
- const prevRef = (0, import_react.useRef)("");
206
- (0, import_react.useEffect)(() => {
207
- const colors = [];
208
- for (let i = 1; i <= 12; i++) {
209
- const token = tamaguiTheme[`color${i}`];
210
- colors.push(token?.val ?? "");
211
- }
212
- const key = colors.join("|");
213
- if (key === prevRef.current) return;
214
- prevRef.current = key;
215
- getChannelEmit()?.(themeColorsChannelEvent, colors);
216
- }, [tamaguiTheme]);
217
- return null;
194
+ const tamaguiTheme = (0, import_tamagui.useTheme)();
195
+ const prevRef = (0, import_react.useRef)("");
196
+ (0, import_react.useEffect)(() => {
197
+ const colors = [];
198
+ for (let i = 1; i <= 12; i++) {
199
+ const token = tamaguiTheme[`color-${i}`];
200
+ colors.push(token?.val ?? "");
201
+ }
202
+ const key = colors.join("|");
203
+ if (key === prevRef.current) return;
204
+ prevRef.current = key;
205
+ getChannelEmit()?.(themeColorsChannelEvent, colors);
206
+ }, [tamaguiTheme]);
207
+ return null;
218
208
  }
219
209
  function BaseThemeColorEmitter() {
220
- const tamaguiTheme = (0, import_tamagui.useTheme)();
221
- const prevRef = (0, import_react.useRef)("");
222
- (0, import_react.useEffect)(() => {
223
- const colors = [];
224
- for (let i = 1; i <= 12; i++) {
225
- const token = tamaguiTheme[`color${i}`];
226
- colors.push(token?.val ?? "");
227
- }
228
- const key = colors.join("|");
229
- if (key === prevRef.current) return;
230
- prevRef.current = key;
231
- getChannelEmit()?.(baseThemeColorsChannelEvent, colors);
232
- }, [tamaguiTheme]);
233
- return null;
210
+ const tamaguiTheme = (0, import_tamagui.useTheme)();
211
+ const prevRef = (0, import_react.useRef)("");
212
+ (0, import_react.useEffect)(() => {
213
+ const colors = [];
214
+ for (let i = 1; i <= 12; i++) {
215
+ const token = tamaguiTheme[`color-${i}`];
216
+ colors.push(token?.val ?? "");
217
+ }
218
+ const key = colors.join("|");
219
+ if (key === prevRef.current) return;
220
+ prevRef.current = key;
221
+ getChannelEmit()?.(baseThemeColorsChannelEvent, colors);
222
+ }, [tamaguiTheme]);
223
+ return null;
234
224
  }
235
225
  function OppositeThemeColorEmitter() {
236
- const tamaguiTheme = (0, import_tamagui.useTheme)();
237
- const prevRef = (0, import_react.useRef)("");
238
- (0, import_react.useEffect)(() => {
239
- const colors = [];
240
- for (let i = 1; i <= 12; i++) {
241
- const token = tamaguiTheme[`color${i}`];
242
- colors.push(token?.val ?? "");
243
- }
244
- const key = colors.join("|");
245
- if (key === prevRef.current) return;
246
- prevRef.current = key;
247
- getChannelEmit()?.(themeColorsOppositeChannelEvent, colors);
248
- }, [tamaguiTheme]);
249
- return null;
226
+ const tamaguiTheme = (0, import_tamagui.useTheme)();
227
+ const prevRef = (0, import_react.useRef)("");
228
+ (0, import_react.useEffect)(() => {
229
+ const colors = [];
230
+ for (let i = 1; i <= 12; i++) {
231
+ const token = tamaguiTheme[`color-${i}`];
232
+ colors.push(token?.val ?? "");
233
+ }
234
+ const key = colors.join("|");
235
+ if (key === prevRef.current) return;
236
+ prevRef.current = key;
237
+ getChannelEmit()?.(themeColorsOppositeChannelEvent, colors);
238
+ }, [tamaguiTheme]);
239
+ return null;
250
240
  }
251
- function ColorChannelEmitter({
252
- event,
253
- prefix = "color"
254
- }) {
255
- const tamaguiTheme = (0, import_tamagui.useTheme)();
256
- const prevRef = (0, import_react.useRef)("");
257
- (0, import_react.useEffect)(() => {
258
- const colors = [];
259
- let found = false;
260
- for (let i = 1; i <= 12; i++) {
261
- const token = tamaguiTheme[`${prefix}${i}`];
262
- const val = token?.val ?? "";
263
- colors.push(val);
264
- if (val) found = true;
265
- }
266
- if (!found) return;
267
- const key = colors.join("|");
268
- if (key === prevRef.current) return;
269
- prevRef.current = key;
270
- getChannelEmit()?.(event, colors);
271
- }, [tamaguiTheme, event, prefix]);
272
- return null;
241
+ function ColorChannelEmitter({ event, prefix = "color" }) {
242
+ const tamaguiTheme = (0, import_tamagui.useTheme)();
243
+ const prevRef = (0, import_react.useRef)("");
244
+ (0, import_react.useEffect)(() => {
245
+ const colors = [];
246
+ let found = false;
247
+ for (let i = 1; i <= 12; i++) {
248
+ const token = tamaguiTheme[`${prefix}${i}`];
249
+ const val = token?.val ?? "";
250
+ colors.push(val);
251
+ if (val) found = true;
252
+ }
253
+ if (!found) return;
254
+ const key = colors.join("|");
255
+ if (key === prevRef.current) return;
256
+ prevRef.current = key;
257
+ getChannelEmit()?.(event, colors);
258
+ }, [
259
+ tamaguiTheme,
260
+ event,
261
+ prefix
262
+ ]);
263
+ return null;
273
264
  }
274
- const tamaguiPropLeakPatterns = ["pressTheme", "scaleIcon", "borderTopRightRadius", "borderBottomRightRadius", "borderTopLeftRadius", "borderBottomLeftRadius"];
275
- function suppressTamaguiDomWarnings() {
276
- if (typeof window === "undefined") return;
277
- const origError = console.error;
278
- console.error = (...args) => {
279
- const msg = args.map(a => typeof a === "string" ? a : "").join(" ");
280
- if (msg.includes("React does not recognize the") && tamaguiPropLeakPatterns.some(p => msg.includes(p))) {
281
- return;
282
- }
283
- origError(...args);
284
- };
285
- }
286
- suppressTamaguiDomWarnings();
287
265
  function createPreview(options) {
288
- const {
289
- themeConfig,
290
- i18n,
291
- AppProvider,
292
- setUserScheme,
293
- decorators: extraDecorators = [],
294
- parameters: extraParameters = {},
295
- globalTypes: extraGlobalTypes = {}
296
- } = options;
297
- const themeConfigsByName = {
298
- ...options.themeConfigs,
299
- [defaultThemeConfigName]: themeConfig
300
- };
301
- const themeConfigNames = [defaultThemeConfigName, ...Object.keys(themeConfigsByName).filter(name => name !== defaultThemeConfigName)];
302
- const switchesThemeConfig = themeConfigNames.length > 1;
303
- if (switchesThemeConfig) (0, import_theme.activateThemeConfig)(themeConfig);
304
- let activeThemeConfigName = defaultThemeConfigName;
305
- function useActiveThemeConfigName(requested) {
306
- const [active, setActive] = (0, import_react.useState)(activeThemeConfigName);
307
- (0, import_react.useLayoutEffect)(() => {
308
- if (requested !== activeThemeConfigName) {
309
- (0, import_theme.activateThemeConfig)(themeConfigsByName[requested]);
310
- activeThemeConfigName = requested;
311
- }
312
- setActive(requested);
313
- }, [requested]);
314
- return active;
315
- }
316
- const enumKeys = Object.keys(knobOptions);
317
- const generatedGlobalTypes = {};
318
- for (const key of enumKeys) {
319
- generatedGlobalTypes[key] = createControl(key);
320
- }
321
- for (const state of ["hover", "press", "focus", "focusVisible"]) {
322
- for (const field of stateKnobFields) {
323
- const stateKey = `${state}.${field}`;
324
- const values = knobOptions[field] ?? [];
325
- const serialized = values.map(value => value);
326
- const labels = Object.fromEntries(serialized.map(v => [v, v.replace("$", "")]));
327
- generatedGlobalTypes[stateKey] = {
328
- name: `${toTitleCase(state)} ${toTitleCase(field)}`,
329
- description: `${state} override for ${field}`,
330
- options: serialized,
331
- control: {
332
- type: "select",
333
- labels
334
- },
335
- defaultValue: ""
336
- };
337
- }
338
- }
339
- const themeColorNames = ["", ...themeConfig.themeColors];
340
- const themeSwatches = {};
341
- const allThemes = themeConfig.tamagui.themes;
342
- if (allThemes) {
343
- for (const name of themeConfig.themeColors) {
344
- const theme = allThemes[`light_${name}`] ?? allThemes[name];
345
- if (!theme) continue;
346
- const token = theme.color7;
347
- if (typeof token === "string") {
348
- themeSwatches[name] = token;
349
- } else if (token && typeof token === "object" && "val" in token) {
350
- themeSwatches[name] = String(token.val);
351
- }
352
- }
353
- }
354
- generatedGlobalTypes.color = {
355
- name: "Theme",
356
- description: "Theme color palette",
357
- options: themeColorNames,
358
- control: {
359
- type: "select",
360
- labels: Object.fromEntries(themeColorNames.map(v => [v, v || "(none)"]))
361
- }
362
- };
363
- generatedGlobalTypes.scheme = {
364
- name: "Scheme",
365
- description: "Color scheme (light/dark/system)",
366
- options: ["system", "light", "dark"],
367
- control: {
368
- type: "select"
369
- }
370
- };
371
- generatedGlobalTypes.locale = {
372
- name: "Locale",
373
- description: "Controls internationalization language",
374
- options: [...i18n.languages],
375
- control: {
376
- type: "select"
377
- },
378
- toolbar: {
379
- title: "Locale",
380
- items: [...i18n.languages],
381
- dynamicTitle: true
382
- }
383
- };
384
- if (switchesThemeConfig) {
385
- generatedGlobalTypes.tamaguiConfig = {
386
- name: "Tamagui config",
387
- description: "Tamagui config the story renders under",
388
- options: themeConfigNames,
389
- control: {
390
- type: "select"
391
- },
392
- toolbar: {
393
- title: "Tamagui config",
394
- icon: "paintbrush",
395
- items: themeConfigNames.map(name => ({
396
- value: name,
397
- title: `${name} config`
398
- })),
399
- dynamicTitle: true
400
- }
401
- };
402
- }
403
- const globalTypes = {
404
- ...generatedGlobalTypes,
405
- ...extraGlobalTypes
406
- };
407
- const initialGlobals = {
408
- locale: import_platform.config.get("I18N_DEFAULT_LANGUAGE", i18n.defaultLanguage),
409
- color: "",
410
- scheme: "system",
411
- // Publish registered preset names so the manager-side ThemePanel can
412
- // render a preset selector without importing the theme package.
413
- __presetNames: (0, import_theme.getPresetNames)(),
414
- // Each preset's token scale (control / type px), so the picker can say
415
- // what a switch does to sizes and spacing.
416
- __presetScales: Object.fromEntries((0, import_theme.getPresetNames)().map(name => {
417
- const scale = (0, import_theme.getPreset)(name)?.scale ?? import_theme.defaultScaleInputs;
418
- return [name, {
419
- control: scale.control,
420
- type: scale.type
421
- }];
422
- })),
423
- // Publish available theme color names so the ThemePanel can show only
424
- // colors that actually have registered Tamagui sub-themes.
425
- __themeColors: themeColorNames,
426
- __themeSwatches: themeSwatches,
427
- preset: themeConfig.defaultPreset ?? "",
428
- ...(switchesThemeConfig && {
429
- tamaguiConfig: defaultThemeConfigName
430
- })
431
- };
432
- for (const key of enumKeys) {
433
- if (!(key in initialGlobals)) {
434
- initialGlobals[key] = "";
435
- }
436
- }
437
- for (const state of ["hover", "press", "focus", "focusVisible"]) {
438
- for (const field of stateKnobFields) {
439
- initialGlobals[`${state}.${field}`] = "";
440
- }
441
- }
442
- globalThis.__MPO_THEME_AXES__ = {
443
- schemes: ["light", "dark"],
444
- themeColors: themeColorNames,
445
- presets: ["", ...(0, import_theme.getPresetNames)()],
446
- presetThemes: Object.fromEntries((0, import_theme.getPresetNames)().flatMap(name => {
447
- const theme = (0, import_theme.getPreset)(name)?.theme;
448
- return theme ? [[name, theme]] : [];
449
- }))
450
- };
451
- const defaultParameters = {
452
- actions: {
453
- argTypesRegex: "^on[A-Z].*"
454
- },
455
- layout: "padded",
456
- viewMode: "story",
457
- controls: {
458
- expanded: true,
459
- hideNoControlsWarning: true,
460
- matchers: {
461
- color: /(background|color)$/i,
462
- date: /Date$/
463
- }
464
- },
465
- // Disable the built-in backgrounds addon — the CanvasBackground component
466
- // manages the preview background via the Tamagui $background token so it
467
- // stays in sync with the active color scheme.
468
- backgrounds: {
469
- disable: true
470
- },
471
- previewTabs: {
472
- "storybook/docs/panel": {
473
- hidden: true
474
- }
475
- },
476
- a11y: {
477
- test: false
478
- },
479
- docs: {
480
- codePanel: true
481
- },
482
- darkMode: {
483
- stylePreview: true
484
- }
485
- };
486
- function FrameworkDecoratorInner({
487
- Story,
488
- context
489
- }) {
490
- const [knobs, setKnobs] = (0, import_theme.useTheme)();
491
- const schemeGlobal = context.globals.scheme || "system";
492
- const [resolvedScheme, setResolvedScheme] = (0, import_react.useState)(() => {
493
- if (schemeGlobal === "light" || schemeGlobal === "dark") return schemeGlobal;
494
- if (typeof window !== "undefined" && window.matchMedia) {
495
- return window.matchMedia("(prefers-color-scheme: dark)").matches ? "dark" : "light";
496
- }
497
- return "light";
498
- });
499
- (0, import_react.useEffect)(() => {
500
- if (schemeGlobal === "light" || schemeGlobal === "dark") {
501
- setResolvedScheme(schemeGlobal);
502
- return;
503
- }
504
- if (typeof window === "undefined" || !window.matchMedia) {
505
- setResolvedScheme("light");
506
- return;
507
- }
508
- const mq = window.matchMedia("(prefers-color-scheme: dark)");
509
- const handler = () => setResolvedScheme(mq.matches ? "dark" : "light");
510
- handler();
511
- mq.addEventListener("change", handler);
512
- return () => mq.removeEventListener("change", handler);
513
- }, [schemeGlobal]);
514
- (0, import_react.useLayoutEffect)(() => {
515
- const setting = schemeGlobal === "light" || schemeGlobal === "dark" ? schemeGlobal : "system";
516
- setUserScheme?.(setting);
517
- (0, import_theme.setStoredScheme)(setting);
518
- }, [schemeGlobal]);
519
- const colorGlobal = context.globals.color || "";
520
- const requestedThemeConfig = context.globals.tamaguiConfig;
521
- const requestedThemeConfigName = requestedThemeConfig && themeConfigNames.includes(requestedThemeConfig) ? requestedThemeConfig : defaultThemeConfigName;
522
- const themeConfigName = useActiveThemeConfigName(requestedThemeConfigName);
523
- const storyThemeParams = context.parameters?.theme;
524
- const activePresetName = context.globals.preset || void 0;
525
- const activePreset = activePresetName ? (0, import_theme.getPreset)(activePresetName) : void 0;
526
- const presetTheme = colorGlobal || activePreset?.theme || import_theme.defaultPreset.theme;
527
- const scaleId = (0, import_theme.useActiveScale)(themeConfigsByName[requestedThemeConfigName], activePresetName);
528
- const knobUpdate = (0, import_react.useMemo)(() => {
529
- const result = {};
530
- const stateKeys = /* @__PURE__ */new Set(["hover", "press", "focus", "focusVisible"]);
531
- for (const key of Object.keys(knobs)) {
532
- if (stateKeys.has(key)) continue;
533
- if (storyThemeParams && key in storyThemeParams) {
534
- result[key] = storyThemeParams[key];
535
- } else if (key in context.globals && context.globals[key] !== void 0 && context.globals[key] !== "") {
536
- result[key] = parseValue(context.globals[key]);
537
- } else if (activePreset && key in activePreset.knobs) {
538
- result[key] = activePreset.knobs[key];
539
- } else {
540
- result[key] = import_theme.defaultKnobs[key];
541
- }
542
- }
543
- result.animation = (0, import_theme.normalizeAnimationKnob)(result.animation) ?? import_theme.defaultKnobs.animation;
544
- for (const state of stateKeys) {
545
- const stateObj = {};
546
- let hasValues = false;
547
- for (const field of stateKnobFields) {
548
- const globalKey = `${state}.${field}`;
549
- const val = context.globals[globalKey];
550
- if (val) {
551
- stateObj[field] = val;
552
- hasValues = true;
553
- }
554
- }
555
- if (hasValues) {
556
- result[state] = stateObj;
557
- }
558
- }
559
- return result;
560
- }, [knobs, context.globals, storyThemeParams, activePreset]);
561
- (0, import_react.useEffect)(() => {
562
- setKnobs(knobUpdate);
563
- }, [knobUpdate, setKnobs]);
564
- (0, import_react.useEffect)(() => {
565
- i18n.instance.changeLanguage(context.globals.locale);
566
- }, [context.globals.locale]);
567
- const presetCtxValue = (0, import_react.useMemo)(() => ({
568
- preset: {
569
- ...(0, import_theme.applyColorTheme)(activePreset ?? import_theme.defaultPreset, colorGlobal),
570
- theme: presetTheme,
571
- knobs: {
572
- ...import_theme.defaultKnobs,
573
- ...knobUpdate
574
- }
575
- },
576
- overrides: void 0,
577
- presetName: activePresetName,
578
- scaleId,
579
- color: colorGlobal || void 0
580
- }), [knobUpdate, presetTheme, activePreset, colorGlobal, activePresetName, scaleId]);
581
- const animationValue = presetCtxValue.preset.knobs.animation;
582
- (0, import_react.useEffect)(() => {
583
- if (typeof document === "undefined") return;
584
- const ms = `${animationValue === "none" ? 0 : import_theme.animationDurations[animationValue]}ms`;
585
- document.documentElement.style.setProperty("--mp-transition", ms);
586
- }, [animationValue]);
587
- const storyContent = /* @__PURE__ */(0, import_jsx_runtime.jsx)(CanvasBackground, {
588
- children: /* @__PURE__ */(0, import_jsx_runtime.jsx)(Story, {
589
- ...context
590
- })
591
- });
592
- const oppositeScheme = resolvedScheme === "dark" ? "light" : "dark";
593
- return /* @__PURE__ */(0, import_jsx_runtime.jsx)(import_theme.PresetContext.Provider, {
594
- value: presetCtxValue,
595
- children: /* @__PURE__ */(0, import_jsx_runtime.jsxs)(AppProvider, {
596
- themeConfig: themeConfigsByName[themeConfigName],
597
- systemTheme: resolvedScheme,
598
- children: [/* @__PURE__ */(0, import_jsx_runtime.jsx)(AnimationNamesEmitter, {}), /* @__PURE__ */(0, import_jsx_runtime.jsx)(FrappeDebugEmitter, {}), /* @__PURE__ */(0, import_jsx_runtime.jsx)(BaseThemeColorEmitter, {}), /* @__PURE__ */(0, import_jsx_runtime.jsxs)(import_tamagui.Theme, {
599
- name: presetTheme || resolvedScheme,
600
- children: [/* @__PURE__ */(0, import_jsx_runtime.jsx)(ThemeColorEmitter, {}), /* @__PURE__ */(0, import_jsx_runtime.jsx)(ColorChannelEmitter, {
601
- event: accentColorsChannelEvent,
602
- prefix: "accent"
603
- }), storyContent]
604
- }), /* @__PURE__ */(0, import_jsx_runtime.jsxs)(import_tamagui.Theme, {
605
- name: oppositeScheme,
606
- children: [/* @__PURE__ */(0, import_jsx_runtime.jsx)(OppositeThemeColorEmitter, {}), presetTheme ? /* @__PURE__ */(0, import_jsx_runtime.jsxs)(import_tamagui.Theme, {
607
- name: presetTheme,
608
- children: [/* @__PURE__ */(0, import_jsx_runtime.jsx)(ColorChannelEmitter, {
609
- event: baseOppositeChannelEvent
610
- }), /* @__PURE__ */(0, import_jsx_runtime.jsx)(ColorChannelEmitter, {
611
- event: accentOppositeChannelEvent,
612
- prefix: "accent"
613
- })]
614
- }) : /* @__PURE__ */(0, import_jsx_runtime.jsxs)(import_jsx_runtime.Fragment, {
615
- children: [/* @__PURE__ */(0, import_jsx_runtime.jsx)(ColorChannelEmitter, {
616
- event: baseOppositeChannelEvent
617
- }), /* @__PURE__ */(0, import_jsx_runtime.jsx)(ColorChannelEmitter, {
618
- event: accentOppositeChannelEvent,
619
- prefix: "accent"
620
- })]
621
- })]
622
- })]
623
- }, `${themeConfigName}:${scaleId}`)
624
- });
625
- }
626
- const frameworkDecorator = (Story, context) => /* @__PURE__ */(0, import_jsx_runtime.jsx)(import_react_cookie.CookiesProvider, {
627
- children: /* @__PURE__ */(0, import_jsx_runtime.jsx)(FrameworkDecoratorInner, {
628
- Story,
629
- context
630
- })
631
- });
632
- return {
633
- globalTypes,
634
- initialGlobals,
635
- parameters: {
636
- ...defaultParameters,
637
- ...extraParameters
638
- },
639
- decorators: [frameworkDecorator, ...extraDecorators]
640
- };
641
- }
266
+ const { themeConfig, i18n, AppProvider, setUserScheme, decorators: extraDecorators = [], parameters: extraParameters = {}, globalTypes: extraGlobalTypes = {} } = options;
267
+ const themeConfigsByName = {
268
+ ...options.themeConfigs,
269
+ [defaultThemeConfigName]: themeConfig
270
+ };
271
+ const themeConfigNames = [defaultThemeConfigName, ...Object.keys(themeConfigsByName).filter((name) => name !== defaultThemeConfigName)];
272
+ const switchesThemeConfig = themeConfigNames.length > 1;
273
+ if (switchesThemeConfig) (0, import_theme.activateThemeConfig)(themeConfig);
274
+ let activeThemeConfigName = defaultThemeConfigName;
275
+ function useActiveThemeConfigName(requested) {
276
+ const [active, setActive] = (0, import_react.useState)(activeThemeConfigName);
277
+ (0, import_react.useLayoutEffect)(() => {
278
+ if (requested !== activeThemeConfigName) {
279
+ (0, import_theme.activateThemeConfig)(themeConfigsByName[requested]);
280
+ activeThemeConfigName = requested;
281
+ }
282
+ setActive(requested);
283
+ }, [requested]);
284
+ return active;
285
+ }
286
+ const enumKeys = Object.keys(knobOptions);
287
+ const generatedGlobalTypes = {};
288
+ for (const key of enumKeys) {
289
+ generatedGlobalTypes[key] = createControl(key);
290
+ }
291
+ for (const state of [
292
+ "hover",
293
+ "press",
294
+ "focus",
295
+ "focusVisible"
296
+ ]) {
297
+ for (const field of stateKnobFields) {
298
+ const stateKey = `${state}.${field}`;
299
+ const values = knobOptions[field] ?? [];
300
+ const serialized = values.map((value) => value);
301
+ const labels = Object.fromEntries(serialized.map((v) => [v, v.replace("$", "")]));
302
+ generatedGlobalTypes[stateKey] = {
303
+ name: `${toTitleCase(state)} ${toTitleCase(field)}`,
304
+ description: `${state} override for ${field}`,
305
+ options: serialized,
306
+ control: {
307
+ type: "select",
308
+ labels
309
+ },
310
+ defaultValue: ""
311
+ };
312
+ }
313
+ }
314
+ const themeColorNames = ["", ...themeConfig.themeColors];
315
+ const themeSwatches = {};
316
+ const allThemes = themeConfig.tamagui.themes;
317
+ if (allThemes) {
318
+ for (const name of themeConfig.themeColors) {
319
+ const theme = allThemes[`light_${name}`] ?? allThemes[name];
320
+ if (!theme) continue;
321
+ const token = theme["color-7"];
322
+ if (typeof token === "string") {
323
+ themeSwatches[name] = token;
324
+ } else if (token && typeof token === "object" && "val" in token) {
325
+ themeSwatches[name] = String(token.val);
326
+ }
327
+ }
328
+ }
329
+ generatedGlobalTypes.color = {
330
+ name: "Theme",
331
+ description: "Theme color palette",
332
+ options: themeColorNames,
333
+ control: {
334
+ type: "select",
335
+ labels: Object.fromEntries(themeColorNames.map((v) => [v, v || "(none)"]))
336
+ }
337
+ };
338
+ generatedGlobalTypes.scheme = {
339
+ name: "Scheme",
340
+ description: "Color scheme (light/dark/system)",
341
+ options: [
342
+ "system",
343
+ "light",
344
+ "dark"
345
+ ],
346
+ control: { type: "select" }
347
+ };
348
+ generatedGlobalTypes.locale = {
349
+ name: "Locale",
350
+ description: "Controls internationalization language",
351
+ options: [...i18n.languages],
352
+ control: { type: "select" },
353
+ toolbar: {
354
+ title: "Locale",
355
+ items: [...i18n.languages],
356
+ dynamicTitle: true
357
+ }
358
+ };
359
+ if (switchesThemeConfig) {
360
+ generatedGlobalTypes.tamaguiConfig = {
361
+ name: "Tamagui config",
362
+ description: "Tamagui config the story renders under",
363
+ options: themeConfigNames,
364
+ control: { type: "select" },
365
+ toolbar: {
366
+ title: "Tamagui config",
367
+ icon: "paintbrush",
368
+ items: themeConfigNames.map((name) => ({
369
+ value: name,
370
+ title: `${name} config`
371
+ })),
372
+ dynamicTitle: true
373
+ }
374
+ };
375
+ }
376
+ const globalTypes = {
377
+ ...generatedGlobalTypes,
378
+ ...extraGlobalTypes
379
+ };
380
+ const initialGlobals = {
381
+ locale: import_platform.config.get("I18N_DEFAULT_LANGUAGE", i18n.defaultLanguage),
382
+ color: "",
383
+ scheme: "system",
384
+ __presetNames: (0, import_theme.getPresetNames)(),
385
+ __presetScales: Object.fromEntries((0, import_theme.getPresetNames)().map((name) => {
386
+ const scale = (0, import_theme.getPreset)(name)?.scale ?? import_theme.defaultScaleInputs;
387
+ return [name, {
388
+ control: scale.control,
389
+ type: scale.type
390
+ }];
391
+ })),
392
+ __themeColors: themeColorNames,
393
+ __themeSwatches: themeSwatches,
394
+ preset: themeConfig.defaultPreset ?? "",
395
+ ...switchesThemeConfig && { tamaguiConfig: defaultThemeConfigName }
396
+ };
397
+ for (const key of enumKeys) {
398
+ if (!(key in initialGlobals)) {
399
+ initialGlobals[key] = "";
400
+ }
401
+ }
402
+ for (const state of [
403
+ "hover",
404
+ "press",
405
+ "focus",
406
+ "focusVisible"
407
+ ]) {
408
+ for (const field of stateKnobFields) {
409
+ initialGlobals[`${state}.${field}`] = "";
410
+ }
411
+ }
412
+ globalThis.__MPO_THEME_AXES__ = {
413
+ schemes: ["light", "dark"],
414
+ themeColors: themeColorNames,
415
+ presets: ["", ...(0, import_theme.getPresetNames)()],
416
+ presetThemes: Object.fromEntries((0, import_theme.getPresetNames)().flatMap((name) => {
417
+ const theme = (0, import_theme.getPreset)(name)?.theme;
418
+ return theme ? [[name, theme]] : [];
419
+ }))
420
+ };
421
+ const defaultParameters = {
422
+ actions: { argTypesRegex: "^on[A-Z].*" },
423
+ layout: "padded",
424
+ viewMode: "story",
425
+ controls: {
426
+ expanded: true,
427
+ hideNoControlsWarning: true,
428
+ matchers: {
429
+ color: /(background|color)$/i,
430
+ date: /Date$/
431
+ }
432
+ },
433
+ backgrounds: { disable: true },
434
+ previewTabs: { "storybook/docs/panel": { hidden: true } },
435
+ a11y: { test: false },
436
+ docs: { codePanel: true },
437
+ darkMode: { stylePreview: true }
438
+ };
439
+ function FrameworkDecoratorInner({ Story, context }) {
440
+ const [knobs, setKnobs] = (0, import_theme.useTheme)();
441
+ const schemeGlobal = context.globals.scheme || "system";
442
+ const [resolvedScheme, setResolvedScheme] = (0, import_react.useState)(() => {
443
+ if (schemeGlobal === "light" || schemeGlobal === "dark") return schemeGlobal;
444
+ if (typeof window !== "undefined" && window.matchMedia) {
445
+ return window.matchMedia("(prefers-color-scheme: dark)").matches ? "dark" : "light";
446
+ }
447
+ return "light";
448
+ });
449
+ (0, import_react.useEffect)(() => {
450
+ if (schemeGlobal === "light" || schemeGlobal === "dark") {
451
+ setResolvedScheme(schemeGlobal);
452
+ return;
453
+ }
454
+ if (typeof window === "undefined" || !window.matchMedia) {
455
+ setResolvedScheme("light");
456
+ return;
457
+ }
458
+ const mq = window.matchMedia("(prefers-color-scheme: dark)");
459
+ const handler = () => setResolvedScheme(mq.matches ? "dark" : "light");
460
+ handler();
461
+ mq.addEventListener("change", handler);
462
+ return () => mq.removeEventListener("change", handler);
463
+ }, [schemeGlobal]);
464
+ (0, import_react.useLayoutEffect)(() => {
465
+ const setting = schemeGlobal === "light" || schemeGlobal === "dark" ? schemeGlobal : "system";
466
+ setUserScheme?.(setting);
467
+ (0, import_theme.setStoredScheme)(setting);
468
+ }, [schemeGlobal]);
469
+ const colorGlobal = context.globals.color || "";
470
+ const requestedThemeConfig = context.globals.tamaguiConfig;
471
+ const requestedThemeConfigName = requestedThemeConfig && themeConfigNames.includes(requestedThemeConfig) ? requestedThemeConfig : defaultThemeConfigName;
472
+ const themeConfigName = useActiveThemeConfigName(requestedThemeConfigName);
473
+ const storyThemeParams = context.parameters?.theme;
474
+ const activePresetName = context.globals.preset || void 0;
475
+ const activePreset = activePresetName ? (0, import_theme.getPreset)(activePresetName) : void 0;
476
+ const presetTheme = colorGlobal || activePreset?.theme || import_theme.defaultPreset.theme;
477
+ const scaleId = (0, import_theme.useActiveScale)(themeConfigsByName[requestedThemeConfigName], activePresetName);
478
+ const knobUpdate = (0, import_react.useMemo)(() => {
479
+ const result = {};
480
+ const stateKeys = /* @__PURE__ */ new Set([
481
+ "hover",
482
+ "press",
483
+ "focus",
484
+ "focusVisible"
485
+ ]);
486
+ for (const key of Object.keys(knobs)) {
487
+ if (stateKeys.has(key)) continue;
488
+ if (storyThemeParams && key in storyThemeParams) {
489
+ result[key] = storyThemeParams[key];
490
+ } else if (key in context.globals && context.globals[key] !== void 0 && context.globals[key] !== "") {
491
+ result[key] = parseValue(context.globals[key]);
492
+ } else if (activePreset && key in activePreset.knobs) {
493
+ result[key] = activePreset.knobs[key];
494
+ } else {
495
+ result[key] = import_theme.defaultKnobs[key];
496
+ }
497
+ }
498
+ result.animation = (0, import_theme.normalizeAnimationKnob)(result.animation) ?? import_theme.defaultKnobs.animation;
499
+ for (const state of stateKeys) {
500
+ const stateObj = {};
501
+ let hasValues = false;
502
+ for (const field of stateKnobFields) {
503
+ const globalKey = `${state}.${field}`;
504
+ const val = context.globals[globalKey];
505
+ if (val) {
506
+ stateObj[field] = val;
507
+ hasValues = true;
508
+ }
509
+ }
510
+ if (hasValues) {
511
+ result[state] = stateObj;
512
+ }
513
+ }
514
+ return result;
515
+ }, [
516
+ knobs,
517
+ context.globals,
518
+ storyThemeParams,
519
+ activePreset
520
+ ]);
521
+ (0, import_react.useEffect)(() => {
522
+ setKnobs(knobUpdate);
523
+ }, [knobUpdate, setKnobs]);
524
+ (0, import_react.useEffect)(() => {
525
+ i18n.instance.changeLanguage(context.globals.locale);
526
+ }, [context.globals.locale]);
527
+ const presetCtxValue = (0, import_react.useMemo)(() => ({
528
+ preset: {
529
+ ...(0, import_theme.applyColorTheme)(activePreset ?? import_theme.defaultPreset, colorGlobal),
530
+ theme: presetTheme,
531
+ knobs: {
532
+ ...import_theme.defaultKnobs,
533
+ ...knobUpdate
534
+ }
535
+ },
536
+ overrides: void 0,
537
+ presetName: activePresetName,
538
+ scaleId,
539
+ color: colorGlobal || void 0
540
+ }), [
541
+ knobUpdate,
542
+ presetTheme,
543
+ activePreset,
544
+ colorGlobal,
545
+ activePresetName,
546
+ scaleId
547
+ ]);
548
+ const animationValue = presetCtxValue.preset.knobs.animation;
549
+ (0, import_react.useEffect)(() => {
550
+ if (typeof document === "undefined") return;
551
+ const ms = `${animationValue === "none" ? 0 : import_theme.animationDurations[animationValue]}ms`;
552
+ document.documentElement.style.setProperty("--mp-transition", ms);
553
+ }, [animationValue]);
554
+ const storyContent = /* @__PURE__ */ (0, import_jsx_runtime.jsx)(CanvasBackground, { children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Story, { ...context }) });
555
+ const oppositeScheme = resolvedScheme === "dark" ? "light" : "dark";
556
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_theme.PresetContext.Provider, {
557
+ value: presetCtxValue,
558
+ children: /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(AppProvider, {
559
+ themeConfig: themeConfigsByName[themeConfigName],
560
+ systemTheme: resolvedScheme,
561
+ children: [
562
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)(AnimationNamesEmitter, {}),
563
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)(FrappeDebugEmitter, {}),
564
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)(BaseThemeColorEmitter, {}),
565
+ /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(import_tamagui.Theme, {
566
+ name: presetTheme || resolvedScheme,
567
+ children: [
568
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)(ThemeColorEmitter, {}),
569
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)(ColorChannelEmitter, {
570
+ event: accentColorsChannelEvent,
571
+ prefix: "accent"
572
+ }),
573
+ storyContent
574
+ ]
575
+ }),
576
+ /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(import_tamagui.Theme, {
577
+ name: oppositeScheme,
578
+ children: [/* @__PURE__ */ (0, import_jsx_runtime.jsx)(OppositeThemeColorEmitter, {}), presetTheme ? /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(import_tamagui.Theme, {
579
+ name: presetTheme,
580
+ children: [/* @__PURE__ */ (0, import_jsx_runtime.jsx)(ColorChannelEmitter, { event: baseOppositeChannelEvent }), /* @__PURE__ */ (0, import_jsx_runtime.jsx)(ColorChannelEmitter, {
581
+ event: accentOppositeChannelEvent,
582
+ prefix: "accent"
583
+ })]
584
+ }) : /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(import_jsx_runtime.Fragment, { children: [/* @__PURE__ */ (0, import_jsx_runtime.jsx)(ColorChannelEmitter, { event: baseOppositeChannelEvent }), /* @__PURE__ */ (0, import_jsx_runtime.jsx)(ColorChannelEmitter, {
585
+ event: accentOppositeChannelEvent,
586
+ prefix: "accent"
587
+ })] })]
588
+ })
589
+ ]
590
+ }, `${themeConfigName}:${scaleId}`)
591
+ });
592
+ }
593
+ const frameworkDecorator = (Story, context) => /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_react_cookie.CookiesProvider, { children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(FrameworkDecoratorInner, {
594
+ Story,
595
+ context
596
+ }) });
597
+ return {
598
+ globalTypes,
599
+ initialGlobals,
600
+ parameters: {
601
+ ...defaultParameters,
602
+ ...extraParameters
603
+ },
604
+ decorators: [frameworkDecorator, ...extraDecorators]
605
+ };
606
+ }