@tamagui/create-theme 1.4.0 → 1.5.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.
@@ -0,0 +1,113 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+ var createTheme_exports = {};
20
+ __export(createTheme_exports, {
21
+ addChildren: () => addChildren,
22
+ applyMask: () => applyMask,
23
+ createStrengthenMask: () => createStrengthenMask,
24
+ createTheme: () => createTheme,
25
+ createWeakenMask: () => createWeakenMask
26
+ });
27
+ module.exports = __toCommonJS(createTheme_exports);
28
+ const THEME_INFO = /* @__PURE__ */ new WeakMap();
29
+ function createTheme(palette, definition, options) {
30
+ const theme = {
31
+ ...Object.fromEntries(
32
+ Object.entries(definition).map(([key, offset]) => {
33
+ return [key, getValue(palette, offset)];
34
+ })
35
+ ),
36
+ ...options == null ? void 0 : options.nonInheritedValues
37
+ };
38
+ THEME_INFO.set(theme, { palette, definition, cache: /* @__PURE__ */ new WeakMap() });
39
+ return theme;
40
+ }
41
+ const getValue = (palette, value) => {
42
+ if (typeof value === "string")
43
+ return value;
44
+ const max = palette.length - 1;
45
+ const isPositive = value === 0 ? !isMinusZero(value) : value >= 0;
46
+ const next = isPositive ? value : max + value;
47
+ const index = Math.min(Math.max(0, next), max);
48
+ return palette[index];
49
+ };
50
+ function addChildren(themes, getChildren) {
51
+ const out = { ...themes };
52
+ for (const key in themes) {
53
+ const subThemes = getChildren(key, themes[key]);
54
+ for (const sKey in subThemes) {
55
+ out[`${key}_${sKey}`] = subThemes[sKey];
56
+ }
57
+ }
58
+ return out;
59
+ }
60
+ const createWeakenMask = ({
61
+ by = 1,
62
+ max,
63
+ min = 0,
64
+ inverseNegatives
65
+ }) => {
66
+ return (template, { skip }) => {
67
+ const values = Object.entries(template);
68
+ const out = {};
69
+ for (const [key, value] of values) {
70
+ if (typeof value === "string")
71
+ continue;
72
+ if (skip && key in skip) {
73
+ out[key] = value;
74
+ continue;
75
+ }
76
+ const isPositive = value === 0 ? !isMinusZero(value) : value >= 0;
77
+ const direction = isPositive ? 1 : -1;
78
+ const invert = inverseNegatives && !isPositive ? -1 : 1;
79
+ const next = value + by * direction * invert;
80
+ const clamped = isPositive ? Math.max(min, Math.min(max, next)) : Math.min(-min, Math.max(-max, next));
81
+ out[key] = clamped;
82
+ }
83
+ return out;
84
+ };
85
+ };
86
+ function isMinusZero(value) {
87
+ return 1 / value === -Infinity;
88
+ }
89
+ const createStrengthenMask = (props) => createWeakenMask({ ...props, inverseNegatives: true });
90
+ function applyMask(theme, mask, options = {}) {
91
+ const info = THEME_INFO.get(theme);
92
+ if (!info) {
93
+ throw new Error(
94
+ process.env.NODE_ENV !== "production" ? `No info found for theme, you must pass the theme created by createThemeFromPalette directly to extendTheme` : `\u274C Err2`
95
+ );
96
+ }
97
+ if (info.cache.has(mask)) {
98
+ return info.cache.get(mask);
99
+ }
100
+ const template = mask(info.definition, options);
101
+ const next = createTheme(info.palette, template);
102
+ info.cache.set(mask, next);
103
+ return next;
104
+ }
105
+ // Annotate the CommonJS export names for ESM import in node:
106
+ 0 && (module.exports = {
107
+ addChildren,
108
+ applyMask,
109
+ createStrengthenMask,
110
+ createTheme,
111
+ createWeakenMask
112
+ });
113
+ //# sourceMappingURL=createTheme.js.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../src/createTheme.tsx"],
4
+ "sourcesContent": ["import type { Variable } from '@tamagui/web'\n\nexport type ThemeMask = Record<string, string | number>\nexport type Palette = string[]\nexport type ShiftMaskProps = { by: number; max: number; min?: number }\nexport type MaskOptions = { skip?: Partial<ThemeMask> }\n\ntype GenericTheme = { [key: string]: string | Variable }\ntype CreateMask = <A extends ThemeMask>(template: A, options: MaskOptions) => A\n\nconst THEME_INFO = new WeakMap<\n any,\n { palette: Palette; definition: ThemeMask; cache: WeakMap<any, any> }\n>()\n\nexport function createTheme<\n Definition extends ThemeMask,\n Extras extends Record<string, string> = {}\n>(\n palette: Palette,\n definition: Definition,\n options?: {\n nonInheritedValues?: Extras\n }\n): {\n [key in keyof Definition | keyof Extras]: string\n} {\n const theme = {\n ...(Object.fromEntries(\n Object.entries(definition).map(([key, offset]) => {\n return [key, getValue(palette, offset)]\n })\n ) as any),\n ...options?.nonInheritedValues,\n }\n THEME_INFO.set(theme, { palette, definition, cache: new WeakMap() })\n return theme\n}\n\nconst getValue = (palette: Palette, value: string | number) => {\n if (typeof value === 'string') return value\n const max = palette.length - 1\n const isPositive = value === 0 ? !isMinusZero(value) : value >= 0\n const next = isPositive ? value : max + value\n const index = Math.min(Math.max(0, next), max)\n return palette[index]\n}\n\ntype SubThemeKeys<ParentKeys, ChildKeys> = `${ParentKeys extends string\n ? ParentKeys\n : never}_${ChildKeys extends string ? ChildKeys : never}`\n\nexport function addChildren<\n Theme extends GenericTheme,\n Themes extends { [key: string]: Theme },\n GetChildren extends (name: keyof Themes, theme: Theme) => { [key: string]: Theme }\n>(\n themes: Themes,\n getChildren: GetChildren\n): Themes & {\n [key in SubThemeKeys<keyof Themes, keyof ReturnType<GetChildren>>]: Theme\n} {\n const out = { ...themes }\n for (const key in themes) {\n const subThemes = getChildren(key, themes[key])\n for (const sKey in subThemes) {\n out[`${key}_${sKey}`] = subThemes[sKey] as any\n }\n }\n return out as any\n}\n\nexport const createWeakenMask = ({\n by = 1,\n max,\n min = 0,\n inverseNegatives,\n}: ShiftMaskProps & { inverseNegatives?: boolean }) => {\n return ((template, { skip }) => {\n const values = Object.entries(template) // .filter(Number)\n const out = {}\n for (const [key, value] of values) {\n if (typeof value === 'string') continue\n if (skip && key in skip) {\n out[key] = value\n continue\n }\n const isPositive = value === 0 ? !isMinusZero(value) : value >= 0\n const direction = isPositive ? 1 : -1\n const invert = inverseNegatives && !isPositive ? -1 : 1\n const next = value + by * direction * invert\n const clamped = isPositive\n ? Math.max(min, Math.min(max, next))\n : Math.min(-min, Math.max(-max, next))\n\n out[key] = clamped\n }\n return out as typeof template\n }) as CreateMask\n}\n\nfunction isMinusZero(value) {\n return 1 / value === -Infinity\n}\n\nexport const createStrengthenMask = (props: ShiftMaskProps) =>\n createWeakenMask({ ...props, inverseNegatives: true })\n\nexport function applyMask<Theme extends GenericTheme>(\n theme: Theme,\n mask: CreateMask,\n options: MaskOptions = {}\n): Theme {\n const info = THEME_INFO.get(theme)\n if (!info) {\n throw new Error(\n process.env.NODE_ENV !== 'production'\n ? `No info found for theme, you must pass the theme created by createThemeFromPalette directly to extendTheme`\n : `\u274C Err2`\n )\n }\n if (info.cache.has(mask)) {\n return info.cache.get(mask)\n }\n\n const template = mask(info.definition, options)\n const next = createTheme(info.palette, template) as Theme\n\n info.cache.set(mask, next)\n\n return next\n}\n"],
5
+ "mappings": ";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAUA,MAAM,aAAa,oBAAI,QAGrB;AAEK,SAAS,YAId,SACA,YACA,SAKA;AACA,QAAM,QAAQ;AAAA,IACZ,GAAI,OAAO;AAAA,MACT,OAAO,QAAQ,UAAU,EAAE,IAAI,CAAC,CAAC,KAAK,MAAM,MAAM;AAChD,eAAO,CAAC,KAAK,SAAS,SAAS,MAAM,CAAC;AAAA,MACxC,CAAC;AAAA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AAK,IAAI,KAAK,KAAK,IAAI,KAAK,IAAI,CAAC,IACjC,KAAK,IAAI,CAAC,KAAK,KAAK,IAAI,CAAC,KAAK,IAAI,CAAC;AAEvC,UAAI,GAAG,IAAI;AAAA,IACb;AACA,WAAO;AAAA,EACT;AACF;AAEA,SAAS,YAAY,OAAO;AAC1B,SAAO,IAAI,UAAU;AACvB;AAEO,MAAM,uBAAuB,CAAC,UACnC,iBAAiB,EAAE,GAAG,OAAO,kBAAkB,KAAK,CAAC;AAEhD,SAAS,UACd,OACA,MACA,UAAuB,CAAC,GACjB;AACP,QAAM,OAAO,WAAW,IAAI,KAAK;AACjC,MAAI,CAAC,MAAM;AACT,UAAM,IAAI;AAAA,MACR,QAAQ,IAAI,aAAa,eACrB,+GACA;AAAA,IACN;AAAA,EACF;AACA,MAAI,KAAK,MAAM,IAAI,IAAI,GAAG;AACxB,WAAO,KAAK,MAAM,IAAI,IAAI;AAAA,EAC5B;AAEA,QAAM,WAAW,KAAK,KAAK,YAAY,OAAO;AAC9C,QAAM,OAAO,YAAY,KAAK,SAAS,QAAQ;AAE/C,OAAK,MAAM,IAAI,MAAM,IAAI;AAEzB,SAAO;AACT;",
6
+ "names": []
7
+ }
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../src/index.tsx"],
4
- "sourcesContent": ["import type { Variable } from '@tamagui/web'\n\nexport type ThemeMask = Record<string, string | number>\nexport type Palette = string[]\nexport type ShiftMaskProps = { by: number; max: number; min?: number }\nexport type MaskOptions = { skip?: Partial<ThemeMask> }\n\ntype GenericTheme = { [key: string]: string | Variable }\ntype CreateMask = <A extends ThemeMask>(template: A, options: MaskOptions) => A\n\nconst THEME_INFO = new WeakMap<\n any,\n { palette: Palette; definition: ThemeMask; cache: WeakMap<any, any> }\n>()\n\nexport function createTheme<\n Definition extends ThemeMask,\n Extras extends Record<string, string> = {}\n>(\n palette: Palette,\n definition: Definition,\n options?: {\n nonInheritedValues?: Extras\n }\n): {\n [key in keyof Definition | keyof Extras]: string\n} {\n const theme = {\n ...(Object.fromEntries(\n Object.entries(definition).map(([key, offset]) => {\n return [key, getValue(palette, offset)]\n })\n ) as any),\n ...options?.nonInheritedValues,\n }\n THEME_INFO.set(theme, { palette, definition, cache: new WeakMap() })\n return theme\n}\n\nconst getValue = (palette: Palette, value: string | number) => {\n if (typeof value === 'string') return value\n const max = palette.length - 1\n const isPositive = value === 0 ? !isMinusZero(value) : value >= 0\n const next = isPositive ? value : max + value\n const index = Math.min(Math.max(0, next), max)\n return palette[index]\n}\n\ntype SubThemeKeys<ParentKeys, ChildKeys> = `${ParentKeys extends string\n ? ParentKeys\n : never}_${ChildKeys extends string ? ChildKeys : never}`\n\nexport function addChildren<\n Theme extends GenericTheme,\n Themes extends { [key: string]: Theme },\n GetChildren extends (name: keyof Themes, theme: Theme) => { [key: string]: Theme }\n>(\n themes: Themes,\n getChildren: GetChildren\n): Themes & {\n [key in SubThemeKeys<keyof Themes, keyof ReturnType<GetChildren>>]: Theme\n} {\n const out = { ...themes }\n for (const key in themes) {\n const subThemes = getChildren(key, themes[key])\n for (const sKey in subThemes) {\n out[`${key}_${sKey}`] = subThemes[sKey] as any\n }\n }\n return out as any\n}\n\nexport const createWeakenMask = ({\n by = 1,\n max,\n min = 0,\n inverseNegatives,\n}: ShiftMaskProps & { inverseNegatives?: boolean }) => {\n return ((template, { skip }) => {\n const values = Object.entries(template) // .filter(Number)\n const out = {}\n for (const [key, value] of values) {\n if (typeof value === 'string') continue\n if (skip && key in skip) {\n out[key] = value\n continue\n }\n const isPositive = value === 0 ? !isMinusZero(value) : value >= 0\n const direction = isPositive ? 1 : -1\n const invert = inverseNegatives && !isPositive ? -1 : 1\n const next = value + by * direction * invert\n const clamped = isPositive\n ? Math.max(min, Math.min(max, next))\n : Math.min(-min, Math.max(-max, next))\n\n out[key] = clamped\n }\n return out as typeof template\n }) as CreateMask\n}\n\nfunction isMinusZero(value) {\n return 1 / value === -Infinity\n}\n\nexport const createStrengthenMask = (props: ShiftMaskProps) =>\n createWeakenMask({ ...props, inverseNegatives: true })\n\nexport function applyMask<Theme extends GenericTheme>(\n theme: Theme,\n mask: CreateMask,\n options: MaskOptions = {}\n): Theme {\n const info = THEME_INFO.get(theme)\n if (!info) {\n throw new Error(\n process.env.NODE_ENV !== 'production'\n ? `No info found for theme, you must pass the theme created by createThemeFromPalette directly to extendTheme`\n : `\u274C Err2`\n )\n }\n if (info.cache.has(mask)) {\n return info.cache.get(mask)\n }\n\n const template = mask(info.definition, options)\n const next = createTheme(info.palette, template) as Theme\n\n info.cache.set(mask, next)\n\n return next\n}\n"],
5
- "mappings": ";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAUA,MAAM,aAAa,oBAAI,QAGrB;AAEK,SAAS,YAId,SACA,YACA,SAKA;AACA,QAAM,QAAQ;AAAA,IACZ,GAAI,OAAO;AAAA,MACT,OAAO,QAAQ,UAAU,EAAE,IAAI,CAAC,CAAC,KAAK,MAAM,MAAM;AAChD,eAAO,CAAC,KAAK,SAAS,SAAS,MAAM,CAAC;AAAA,MACxC,CAAC;AAAA,IACH;AAAA,IACA,GAAG,mCAAS;AAAA,EACd;AACA,aAAW,IAAI,OAAO,EAAE,SAAS,YAAY,OAAO,oBAAI,QAAQ,EAAE,CAAC;AACnE,SAAO;AACT;AAEA,MAAM,WAAW,CAAC,SAAkB,UAA2B;AAC7D,MAAI,OAAO,UAAU;AAAU,WAAO;AACtC,QAAM,MAAM,QAAQ,SAAS;AAC7B,QAAM,aAAa,UAAU,IAAI,CAAC,YAAY,KAAK,IAAI,SAAS;AAChE,QAAM,OAAO,aAAa,QAAQ,MAAM;AACxC,QAAM,QAAQ,KAAK,IAAI,KAAK,IAAI,GAAG,IAAI,GAAG,GAAG;AAC7C,SAAO,QAAQ,KAAK;AACtB;AAMO,SAAS,YAKd,QACA,aAGA;AACA,QAAM,MAAM,EAAE,GAAG,OAAO;AACxB,aA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AAK,MAAM,IAAI,IAAI,GAAG;AACxB,WAAO,KAAK,MAAM,IAAI,IAAI;AAAA,EAC5B;AAEA,QAAM,WAAW,KAAK,KAAK,YAAY,OAAO;AAC9C,QAAM,OAAO,YAAY,KAAK,SAAS,QAAQ;AAE/C,OAAK,MAAM,IAAI,MAAM,IAAI;AAEzB,SAAO;AACT;",
4
+ "sourcesContent": ["import type { Variable } from '@tamagui/web'\n\nexport type ThemeMask = Record<string, string | number>\nexport type Palette = string[]\nexport type ShiftMaskProps = { by: number; max: number; min?: number }\nexport type MaskOptions = { skip?: Partial<ThemeMask> }\n\ntype GenericTheme = { [key: string]: string | Variable }\ntype CreateMask = <A extends ThemeMask>(template: A, options: MaskOptions) => A\n\nconst THEME_INFO = new WeakMap<\n any,\n { palette: Palette; definition: ThemeMask; cache: WeakMap<any, any> }\n>()\n\nexport function createTheme<\n Definition extends ThemeMask,\n Extras extends Record<string, string> = {}\n>(\n palette: Palette,\n definition: Definition,\n options?: {\n nonInheritedValues?: Extras\n }\n): {\n [key in keyof Definition | keyof Extras]: string\n} {\n const theme = {\n ...(Object.fromEntries(\n Object.entries(definition).map(([key, offset]) => {\n return [key, getValue(palette, offset)]\n })\n ) as any),\n ...options?.nonInheritedValues,\n }\n THEME_INFO.set(theme, { palette, definition, cache: new WeakMap() })\n return theme\n}\n\nconst getValue = (palette: Palette, value: string | number) => {\n if (typeof value === 'string') return value\n const max = palette.length - 1\n const isPositive = value === 0 ? !isMinusZero(value) : value >= 0\n const next = isPositive ? value : max + value\n const index = Math.min(Math.max(0, next), max)\n return palette[index]\n}\n\ntype SubThemeKeys<ParentKeys, ChildKeys> = `${ParentKeys extends string\n ? ParentKeys\n : never}_${ChildKeys extends string ? ChildKeys : never}`\n\ntype ChildGetter<Name extends string | number | symbol, Theme extends GenericTheme> = (\n name: Name,\n theme: Theme\n) => { [key: string]: Theme }\n\nexport function addChildren<\n Themes extends { [key: string]: GenericTheme },\n GetChildren extends ChildGetter<keyof Themes, Themes[keyof Themes]>\n>(\n themes: Themes,\n getChildren: GetChildren\n): Themes & {\n [key in SubThemeKeys<keyof Themes, keyof ReturnType<GetChildren>>]: Themes[keyof Themes]\n} {\n const out = { ...themes }\n for (const key in themes) {\n const subThemes = getChildren(key, themes[key])\n for (const sKey in subThemes) {\n out[`${key}_${sKey}`] = subThemes[sKey] as any\n }\n }\n return out as any\n}\n\n// const x = createTheme([], { bg: 1 })\n// const y = addChildren({ x }, (_, x2) => ({\n// y: x,\n// }))\n\nexport const createWeakenMask = ({\n by = 1,\n max,\n min = 0,\n inverseNegatives,\n}: ShiftMaskProps & { inverseNegatives?: boolean }) => {\n return ((template, { skip }) => {\n const values = Object.entries(template) // .filter(Number)\n const out = {}\n for (const [key, value] of values) {\n if (typeof value === 'string') continue\n if (skip && key in skip) {\n out[key] = value\n continue\n }\n const isPositive = value === 0 ? !isMinusZero(value) : value >= 0\n const direction = isPositive ? 1 : -1\n const invert = inverseNegatives && !isPositive ? -1 : 1\n const next = value + by * direction * invert\n const clamped = isPositive\n ? Math.max(min, Math.min(max, next))\n : Math.min(-min, Math.max(-max, next))\n\n out[key] = clamped\n }\n return out as typeof template\n }) as CreateMask\n}\n\nfunction isMinusZero(value) {\n return 1 / value === -Infinity\n}\n\nexport const createStrengthenMask = (props: ShiftMaskProps) =>\n createWeakenMask({ ...props, inverseNegatives: true })\n\nexport function applyMask<Theme extends GenericTheme>(\n theme: Theme,\n mask: CreateMask,\n options: MaskOptions = {}\n): Theme {\n const info = THEME_INFO.get(theme)\n if (!info) {\n throw new Error(\n process.env.NODE_ENV !== 'production'\n ? `No info found for theme, you must pass the theme created by createThemeFromPalette directly to extendTheme`\n : `\u274C Err2`\n )\n }\n if (info.cache.has(mask)) {\n return info.cache.get(mask)\n }\n\n const template = mask(info.definition, options)\n const next = createTheme(info.palette, template) as Theme\n\n info.cache.set(mask, next)\n\n return next\n}\n"],
5
+ "mappings": ";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;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AAU;AAC/B,UAAI,QAAQ,OAAO,MAAM;AACvB,YAAI,GAAG,IAAI;AACX;AAAA,MACF;AACA,YAAM,aAAa,UAAU,IAAI,CAAC,YAAY,KAAK,IAAI,SAAS;AAChE,YAAM,YAAY,aAAa,IAAI;AACnC,YAAM,SAAS,oBAAoB,CAAC,aAAa,KAAK;AACtD,YAAM,OAAO,QAAQ,KAAK,YAAY;AACtC,YAAM,UAAU,aACZ,KAAK,IAAI,KAAK,KAAK,IAAI,KAAK,IAAI,CAAC,IACjC,KAAK,IAAI,CAAC,KAAK,KAAK,IAAI,CAAC,KAAK,IAAI,CAAC;AAEvC,UAAI,GAAG,IAAI;AAAA,IACb;AACA,WAAO;AAAA,EACT;AACF;AAEA,SAAS,YAAY,OAAO;AAC1B,SAAO,IAAI,UAAU;AACvB;AAEO,MAAM,uBAAuB,CAAC,UACnC,iBAAiB,EAAE,GAAG,OAAO,kBAAkB,KAAK,CAAC;AAEhD,SAAS,UACd,OACA,MACA,UAAuB,CAAC,GACjB;AACP,QAAM,OAAO,WAAW,IAAI,KAAK;AACjC,MAAI,CAAC,MAAM;AACT,UAAM,IAAI;AAAA,MACR,QAAQ,IAAI,aAAa,eACrB,+GACA;AAAA,IACN;AAAA,EACF;AACA,MAAI,KAAK,MAAM,IAAI,IAAI,GAAG;AACxB,WAAO,KAAK,MAAM,IAAI,IAAI;AAAA,EAC5B;AAEA,QAAM,WAAW,KAAK,KAAK,YAAY,OAAO;AAC9C,QAAM,OAAO,YAAY,KAAK,SAAS,QAAQ;AAE/C,OAAK,MAAM,IAAI,MAAM,IAAI;AAEzB,SAAO;AACT;",
6
6
  "names": []
7
7
  }
@@ -0,0 +1,85 @@
1
+ const THEME_INFO = /* @__PURE__ */ new WeakMap();
2
+ function createTheme(palette, definition, options) {
3
+ const theme = {
4
+ ...Object.fromEntries(
5
+ Object.entries(definition).map(([key, offset]) => {
6
+ return [key, getValue(palette, offset)];
7
+ })
8
+ ),
9
+ ...options == null ? void 0 : options.nonInheritedValues
10
+ };
11
+ THEME_INFO.set(theme, { palette, definition, cache: /* @__PURE__ */ new WeakMap() });
12
+ return theme;
13
+ }
14
+ const getValue = (palette, value) => {
15
+ if (typeof value === "string")
16
+ return value;
17
+ const max = palette.length - 1;
18
+ const isPositive = value === 0 ? !isMinusZero(value) : value >= 0;
19
+ const next = isPositive ? value : max + value;
20
+ const index = Math.min(Math.max(0, next), max);
21
+ return palette[index];
22
+ };
23
+ function addChildren(themes, getChildren) {
24
+ const out = { ...themes };
25
+ for (const key in themes) {
26
+ const subThemes = getChildren(key, themes[key]);
27
+ for (const sKey in subThemes) {
28
+ out[`${key}_${sKey}`] = subThemes[sKey];
29
+ }
30
+ }
31
+ return out;
32
+ }
33
+ const createWeakenMask = ({
34
+ by = 1,
35
+ max,
36
+ min = 0,
37
+ inverseNegatives
38
+ }) => {
39
+ return (template, { skip }) => {
40
+ const values = Object.entries(template);
41
+ const out = {};
42
+ for (const [key, value] of values) {
43
+ if (typeof value === "string")
44
+ continue;
45
+ if (skip && key in skip) {
46
+ out[key] = value;
47
+ continue;
48
+ }
49
+ const isPositive = value === 0 ? !isMinusZero(value) : value >= 0;
50
+ const direction = isPositive ? 1 : -1;
51
+ const invert = inverseNegatives && !isPositive ? -1 : 1;
52
+ const next = value + by * direction * invert;
53
+ const clamped = isPositive ? Math.max(min, Math.min(max, next)) : Math.min(-min, Math.max(-max, next));
54
+ out[key] = clamped;
55
+ }
56
+ return out;
57
+ };
58
+ };
59
+ function isMinusZero(value) {
60
+ return 1 / value === -Infinity;
61
+ }
62
+ const createStrengthenMask = (props) => createWeakenMask({ ...props, inverseNegatives: true });
63
+ function applyMask(theme, mask, options = {}) {
64
+ const info = THEME_INFO.get(theme);
65
+ if (!info) {
66
+ throw new Error(
67
+ process.env.NODE_ENV !== "production" ? `No info found for theme, you must pass the theme created by createThemeFromPalette directly to extendTheme` : `\u274C Err2`
68
+ );
69
+ }
70
+ if (info.cache.has(mask)) {
71
+ return info.cache.get(mask);
72
+ }
73
+ const template = mask(info.definition, options);
74
+ const next = createTheme(info.palette, template);
75
+ info.cache.set(mask, next);
76
+ return next;
77
+ }
78
+ export {
79
+ addChildren,
80
+ applyMask,
81
+ createStrengthenMask,
82
+ createTheme,
83
+ createWeakenMask
84
+ };
85
+ //# sourceMappingURL=createTheme.js.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../src/createTheme.tsx"],
4
+ "sourcesContent": ["import type { Variable } from '@tamagui/web'\n\nexport type ThemeMask = Record<string, string | number>\nexport type Palette = string[]\nexport type ShiftMaskProps = { by: number; max: number; min?: number }\nexport type MaskOptions = { skip?: Partial<ThemeMask> }\n\ntype GenericTheme = { [key: string]: string | Variable }\ntype CreateMask = <A extends ThemeMask>(template: A, options: MaskOptions) => A\n\nconst THEME_INFO = new WeakMap<\n any,\n { palette: Palette; definition: ThemeMask; cache: WeakMap<any, any> }\n>()\n\nexport function createTheme<\n Definition extends ThemeMask,\n Extras extends Record<string, string> = {}\n>(\n palette: Palette,\n definition: Definition,\n options?: {\n nonInheritedValues?: Extras\n }\n): {\n [key in keyof Definition | keyof Extras]: string\n} {\n const theme = {\n ...(Object.fromEntries(\n Object.entries(definition).map(([key, offset]) => {\n return [key, getValue(palette, offset)]\n })\n ) as any),\n ...options?.nonInheritedValues,\n }\n THEME_INFO.set(theme, { palette, definition, cache: new WeakMap() })\n return theme\n}\n\nconst getValue = (palette: Palette, value: string | number) => {\n if (typeof value === 'string') return value\n const max = palette.length - 1\n const isPositive = value === 0 ? !isMinusZero(value) : value >= 0\n const next = isPositive ? value : max + value\n const index = Math.min(Math.max(0, next), max)\n return palette[index]\n}\n\ntype SubThemeKeys<ParentKeys, ChildKeys> = `${ParentKeys extends string\n ? ParentKeys\n : never}_${ChildKeys extends string ? ChildKeys : never}`\n\nexport function addChildren<\n Theme extends GenericTheme,\n Themes extends { [key: string]: Theme },\n GetChildren extends (name: keyof Themes, theme: Theme) => { [key: string]: Theme }\n>(\n themes: Themes,\n getChildren: GetChildren\n): Themes & {\n [key in SubThemeKeys<keyof Themes, keyof ReturnType<GetChildren>>]: Theme\n} {\n const out = { ...themes }\n for (const key in themes) {\n const subThemes = getChildren(key, themes[key])\n for (const sKey in subThemes) {\n out[`${key}_${sKey}`] = subThemes[sKey] as any\n }\n }\n return out as any\n}\n\nexport const createWeakenMask = ({\n by = 1,\n max,\n min = 0,\n inverseNegatives,\n}: ShiftMaskProps & { inverseNegatives?: boolean }) => {\n return ((template, { skip }) => {\n const values = Object.entries(template) // .filter(Number)\n const out = {}\n for (const [key, value] of values) {\n if (typeof value === 'string') continue\n if (skip && key in skip) {\n out[key] = value\n continue\n }\n const isPositive = value === 0 ? !isMinusZero(value) : value >= 0\n const direction = isPositive ? 1 : -1\n const invert = inverseNegatives && !isPositive ? -1 : 1\n const next = value + by * direction * invert\n const clamped = isPositive\n ? Math.max(min, Math.min(max, next))\n : Math.min(-min, Math.max(-max, next))\n\n out[key] = clamped\n }\n return out as typeof template\n }) as CreateMask\n}\n\nfunction isMinusZero(value) {\n return 1 / value === -Infinity\n}\n\nexport const createStrengthenMask = (props: ShiftMaskProps) =>\n createWeakenMask({ ...props, inverseNegatives: true })\n\nexport function applyMask<Theme extends GenericTheme>(\n theme: Theme,\n mask: CreateMask,\n options: MaskOptions = {}\n): Theme {\n const info = THEME_INFO.get(theme)\n if (!info) {\n throw new Error(\n process.env.NODE_ENV !== 'production'\n ? `No info found for theme, you must pass the theme created by createThemeFromPalette directly to extendTheme`\n : `\u274C Err2`\n )\n }\n if (info.cache.has(mask)) {\n return info.cache.get(mask)\n }\n\n const template = mask(info.definition, options)\n const next = createTheme(info.palette, template) as Theme\n\n info.cache.set(mask, next)\n\n return next\n}\n"],
5
+ "mappings": "AAUA,MAAM,aAAa,oBAAI,QAGrB;AAEK,SAAS,YAId,SACA,YACA,SAKA;AACA,QAAM,QAAQ;AAAA,IACZ,GAAI,OAAO;AAAA,MACT,OAAO,QAAQ,UAAU,EAAE,IAAI,C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AAM,SAAS,oBAAoB,CAAC,aAAa,KAAK;AACtD,YAAM,OAAO,QAAQ,KAAK,YAAY;AACtC,YAAM,UAAU,aACZ,KAAK,IAAI,KAAK,KAAK,IAAI,KAAK,IAAI,CAAC,IACjC,KAAK,IAAI,CAAC,KAAK,KAAK,IAAI,CAAC,KAAK,IAAI,CAAC;AAEvC,UAAI,GAAG,IAAI;AAAA,IACb;AACA,WAAO;AAAA,EACT;AACF;AAEA,SAAS,YAAY,OAAO;AAC1B,SAAO,IAAI,UAAU;AACvB;AAEO,MAAM,uBAAuB,CAAC,UACnC,iBAAiB,EAAE,GAAG,OAAO,kBAAkB,KAAK,CAAC;AAEhD,SAAS,UACd,OACA,MACA,UAAuB,CAAC,GACjB;AACP,QAAM,OAAO,WAAW,IAAI,KAAK;AACjC,MAAI,CAAC,MAAM;AACT,UAAM,IAAI;AAAA,MACR,QAAQ,IAAI,aAAa,eACrB,+GACA;AAAA,IACN;AAAA,EACF;AACA,MAAI,KAAK,MAAM,IAAI,IAAI,GAAG;AACxB,WAAO,KAAK,MAAM,IAAI,IAAI;AAAA,EAC5B;AAEA,QAAM,WAAW,KAAK,KAAK,YAAY,OAAO;AAC9C,QAAM,OAAO,YAAY,KAAK,SAAS,QAAQ;AAE/C,OAAK,MAAM,IAAI,MAAM,IAAI;AAEzB,SAAO;AACT;",
6
+ "names": []
7
+ }
@@ -0,0 +1,85 @@
1
+ const THEME_INFO = /* @__PURE__ */ new WeakMap();
2
+ function createTheme(palette, definition, options) {
3
+ const theme = {
4
+ ...Object.fromEntries(
5
+ Object.entries(definition).map(([key, offset]) => {
6
+ return [key, getValue(palette, offset)];
7
+ })
8
+ ),
9
+ ...options == null ? void 0 : options.nonInheritedValues
10
+ };
11
+ THEME_INFO.set(theme, { palette, definition, cache: /* @__PURE__ */ new WeakMap() });
12
+ return theme;
13
+ }
14
+ const getValue = (palette, value) => {
15
+ if (typeof value === "string")
16
+ return value;
17
+ const max = palette.length - 1;
18
+ const isPositive = value === 0 ? !isMinusZero(value) : value >= 0;
19
+ const next = isPositive ? value : max + value;
20
+ const index = Math.min(Math.max(0, next), max);
21
+ return palette[index];
22
+ };
23
+ function addChildren(themes, getChildren) {
24
+ const out = { ...themes };
25
+ for (const key in themes) {
26
+ const subThemes = getChildren(key, themes[key]);
27
+ for (const sKey in subThemes) {
28
+ out[`${key}_${sKey}`] = subThemes[sKey];
29
+ }
30
+ }
31
+ return out;
32
+ }
33
+ const createWeakenMask = ({
34
+ by = 1,
35
+ max,
36
+ min = 0,
37
+ inverseNegatives
38
+ }) => {
39
+ return (template, { skip }) => {
40
+ const values = Object.entries(template);
41
+ const out = {};
42
+ for (const [key, value] of values) {
43
+ if (typeof value === "string")
44
+ continue;
45
+ if (skip && key in skip) {
46
+ out[key] = value;
47
+ continue;
48
+ }
49
+ const isPositive = value === 0 ? !isMinusZero(value) : value >= 0;
50
+ const direction = isPositive ? 1 : -1;
51
+ const invert = inverseNegatives && !isPositive ? -1 : 1;
52
+ const next = value + by * direction * invert;
53
+ const clamped = isPositive ? Math.max(min, Math.min(max, next)) : Math.min(-min, Math.max(-max, next));
54
+ out[key] = clamped;
55
+ }
56
+ return out;
57
+ };
58
+ };
59
+ function isMinusZero(value) {
60
+ return 1 / value === -Infinity;
61
+ }
62
+ const createStrengthenMask = (props) => createWeakenMask({ ...props, inverseNegatives: true });
63
+ function applyMask(theme, mask, options = {}) {
64
+ const info = THEME_INFO.get(theme);
65
+ if (!info) {
66
+ throw new Error(
67
+ process.env.NODE_ENV !== "production" ? `No info found for theme, you must pass the theme created by createThemeFromPalette directly to extendTheme` : `\u274C Err2`
68
+ );
69
+ }
70
+ if (info.cache.has(mask)) {
71
+ return info.cache.get(mask);
72
+ }
73
+ const template = mask(info.definition, options);
74
+ const next = createTheme(info.palette, template);
75
+ info.cache.set(mask, next);
76
+ return next;
77
+ }
78
+ export {
79
+ addChildren,
80
+ applyMask,
81
+ createStrengthenMask,
82
+ createTheme,
83
+ createWeakenMask
84
+ };
85
+ //# sourceMappingURL=createTheme.mjs.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../src/createTheme.tsx"],
4
+ "sourcesContent": ["import type { Variable } from '@tamagui/web'\n\nexport type ThemeMask = Record<string, string | number>\nexport type Palette = string[]\nexport type ShiftMaskProps = { by: number; max: number; min?: number }\nexport type MaskOptions = { skip?: Partial<ThemeMask> }\n\ntype GenericTheme = { [key: string]: string | Variable }\ntype CreateMask = <A extends ThemeMask>(template: A, options: MaskOptions) => A\n\nconst THEME_INFO = new WeakMap<\n any,\n { palette: Palette; definition: ThemeMask; cache: WeakMap<any, any> }\n>()\n\nexport function createTheme<\n Definition extends ThemeMask,\n Extras extends Record<string, string> = {}\n>(\n palette: Palette,\n definition: Definition,\n options?: {\n nonInheritedValues?: Extras\n }\n): {\n [key in keyof Definition | keyof Extras]: string\n} {\n const theme = {\n ...(Object.fromEntries(\n Object.entries(definition).map(([key, offset]) => {\n return [key, getValue(palette, offset)]\n })\n ) as any),\n ...options?.nonInheritedValues,\n }\n THEME_INFO.set(theme, { palette, definition, cache: new WeakMap() })\n return theme\n}\n\nconst getValue = (palette: Palette, value: string | number) => {\n if (typeof value === 'string') return value\n const max = palette.length - 1\n const isPositive = value === 0 ? !isMinusZero(value) : value >= 0\n const next = isPositive ? value : max + value\n const index = Math.min(Math.max(0, next), max)\n return palette[index]\n}\n\ntype SubThemeKeys<ParentKeys, ChildKeys> = `${ParentKeys extends string\n ? ParentKeys\n : never}_${ChildKeys extends string ? ChildKeys : never}`\n\nexport function addChildren<\n Theme extends GenericTheme,\n Themes extends { [key: string]: Theme },\n GetChildren extends (name: keyof Themes, theme: Theme) => { [key: string]: Theme }\n>(\n themes: Themes,\n getChildren: GetChildren\n): Themes & {\n [key in SubThemeKeys<keyof Themes, keyof ReturnType<GetChildren>>]: Theme\n} {\n const out = { ...themes }\n for (const key in themes) {\n const subThemes = getChildren(key, themes[key])\n for (const sKey in subThemes) {\n out[`${key}_${sKey}`] = subThemes[sKey] as any\n }\n }\n return out as any\n}\n\nexport const createWeakenMask = ({\n by = 1,\n max,\n min = 0,\n inverseNegatives,\n}: ShiftMaskProps & { inverseNegatives?: boolean }) => {\n return ((template, { skip }) => {\n const values = Object.entries(template) // .filter(Number)\n const out = {}\n for (const [key, value] of values) {\n if (typeof value === 'string') continue\n if (skip && key in skip) {\n out[key] = value\n continue\n }\n const isPositive = value === 0 ? !isMinusZero(value) : value >= 0\n const direction = isPositive ? 1 : -1\n const invert = inverseNegatives && !isPositive ? -1 : 1\n const next = value + by * direction * invert\n const clamped = isPositive\n ? Math.max(min, Math.min(max, next))\n : Math.min(-min, Math.max(-max, next))\n\n out[key] = clamped\n }\n return out as typeof template\n }) as CreateMask\n}\n\nfunction isMinusZero(value) {\n return 1 / value === -Infinity\n}\n\nexport const createStrengthenMask = (props: ShiftMaskProps) =>\n createWeakenMask({ ...props, inverseNegatives: true })\n\nexport function applyMask<Theme extends GenericTheme>(\n theme: Theme,\n mask: CreateMask,\n options: MaskOptions = {}\n): Theme {\n const info = THEME_INFO.get(theme)\n if (!info) {\n throw new Error(\n process.env.NODE_ENV !== 'production'\n ? `No info found for theme, you must pass the theme created by createThemeFromPalette directly to extendTheme`\n : `\u274C Err2`\n )\n }\n if (info.cache.has(mask)) {\n return info.cache.get(mask)\n }\n\n const template = mask(info.definition, options)\n const next = createTheme(info.palette, template) as Theme\n\n info.cache.set(mask, next)\n\n return next\n}\n"],
5
+ "mappings": "AAUA,MAAM,aAAa,oBAAI,QAGrB;AAEK,SAAS,YAId,SACA,YACA,SAKA;AACA,QAAM,QAAQ;AAAA,IACZ,GAAI,OAAO;AAAA,MACT,OAAO,QAAQ,UAAU,EAAE,IAAI,CAAC,CAAC,KAAK,MAAM,MAAM;AAChD,eAAO,CAAC,KAAK,SAAS,SAAS,MAAM,CAAC;AAAA,MACxC,CAAC;AAAA,IACH;AAAA,IACA,GAAG,mCAAS;AAAA,EACd;AACA,aAAW,IAAI,OAAO,EAAE,SAA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AK,KAAK,IAAI,CAAC,KAAK,IAAI,CAAC;AAEvC,UAAI,GAAG,IAAI;AAAA,IACb;AACA,WAAO;AAAA,EACT;AACF;AAEA,SAAS,YAAY,OAAO;AAC1B,SAAO,IAAI,UAAU;AACvB;AAEO,MAAM,uBAAuB,CAAC,UACnC,iBAAiB,EAAE,GAAG,OAAO,kBAAkB,KAAK,CAAC;AAEhD,SAAS,UACd,OACA,MACA,UAAuB,CAAC,GACjB;AACP,QAAM,OAAO,WAAW,IAAI,KAAK;AACjC,MAAI,CAAC,MAAM;AACT,UAAM,IAAI;AAAA,MACR,QAAQ,IAAI,aAAa,eACrB,+GACA;AAAA,IACN;AAAA,EACF;AACA,MAAI,KAAK,MAAM,IAAI,IAAI,GAAG;AACxB,WAAO,KAAK,MAAM,IAAI,IAAI;AAAA,EAC5B;AAEA,QAAM,WAAW,KAAK,KAAK,YAAY,OAAO;AAC9C,QAAM,OAAO,YAAY,KAAK,SAAS,QAAQ;AAE/C,OAAK,MAAM,IAAI,MAAM,IAAI;AAEzB,SAAO;AACT;",
6
+ "names": []
7
+ }
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../src/index.tsx"],
4
- "sourcesContent": ["import type { Variable } from '@tamagui/web'\n\nexport type ThemeMask = Record<string, string | number>\nexport type Palette = string[]\nexport type ShiftMaskProps = { by: number; max: number; min?: number }\nexport type MaskOptions = { skip?: Partial<ThemeMask> }\n\ntype GenericTheme = { [key: string]: string | Variable }\ntype CreateMask = <A extends ThemeMask>(template: A, options: MaskOptions) => A\n\nconst THEME_INFO = new WeakMap<\n any,\n { palette: Palette; definition: ThemeMask; cache: WeakMap<any, any> }\n>()\n\nexport function createTheme<\n Definition extends ThemeMask,\n Extras extends Record<string, string> = {}\n>(\n palette: Palette,\n definition: Definition,\n options?: {\n nonInheritedValues?: Extras\n }\n): {\n [key in keyof Definition | keyof Extras]: string\n} {\n const theme = {\n ...(Object.fromEntries(\n Object.entries(definition).map(([key, offset]) => {\n return [key, getValue(palette, offset)]\n })\n ) as any),\n ...options?.nonInheritedValues,\n }\n THEME_INFO.set(theme, { palette, definition, cache: new WeakMap() })\n return theme\n}\n\nconst getValue = (palette: Palette, value: string | number) => {\n if (typeof value === 'string') return value\n const max = palette.length - 1\n const isPositive = value === 0 ? !isMinusZero(value) : value >= 0\n const next = isPositive ? value : max + value\n const index = Math.min(Math.max(0, next), max)\n return palette[index]\n}\n\ntype SubThemeKeys<ParentKeys, ChildKeys> = `${ParentKeys extends string\n ? ParentKeys\n : never}_${ChildKeys extends string ? ChildKeys : never}`\n\nexport function addChildren<\n Theme extends GenericTheme,\n Themes extends { [key: string]: Theme },\n GetChildren extends (name: keyof Themes, theme: Theme) => { [key: string]: Theme }\n>(\n themes: Themes,\n getChildren: GetChildren\n): Themes & {\n [key in SubThemeKeys<keyof Themes, keyof ReturnType<GetChildren>>]: Theme\n} {\n const out = { ...themes }\n for (const key in themes) {\n const subThemes = getChildren(key, themes[key])\n for (const sKey in subThemes) {\n out[`${key}_${sKey}`] = subThemes[sKey] as any\n }\n }\n return out as any\n}\n\nexport const createWeakenMask = ({\n by = 1,\n max,\n min = 0,\n inverseNegatives,\n}: ShiftMaskProps & { inverseNegatives?: boolean }) => {\n return ((template, { skip }) => {\n const values = Object.entries(template) // .filter(Number)\n const out = {}\n for (const [key, value] of values) {\n if (typeof value === 'string') continue\n if (skip && key in skip) {\n out[key] = value\n continue\n }\n const isPositive = value === 0 ? !isMinusZero(value) : value >= 0\n const direction = isPositive ? 1 : -1\n const invert = inverseNegatives && !isPositive ? -1 : 1\n const next = value + by * direction * invert\n const clamped = isPositive\n ? Math.max(min, Math.min(max, next))\n : Math.min(-min, Math.max(-max, next))\n\n out[key] = clamped\n }\n return out as typeof template\n }) as CreateMask\n}\n\nfunction isMinusZero(value) {\n return 1 / value === -Infinity\n}\n\nexport const createStrengthenMask = (props: ShiftMaskProps) =>\n createWeakenMask({ ...props, inverseNegatives: true })\n\nexport function applyMask<Theme extends GenericTheme>(\n theme: Theme,\n mask: CreateMask,\n options: MaskOptions = {}\n): Theme {\n const info = THEME_INFO.get(theme)\n if (!info) {\n throw new Error(\n process.env.NODE_ENV !== 'production'\n ? `No info found for theme, you must pass the theme created by createThemeFromPalette directly to extendTheme`\n : `\u274C Err2`\n )\n }\n if (info.cache.has(mask)) {\n return info.cache.get(mask)\n }\n\n const template = mask(info.definition, options)\n const next = createTheme(info.palette, template) as Theme\n\n info.cache.set(mask, next)\n\n return next\n}\n"],
5
- "mappings": "AAUA,MAAM,aAAa,oBAAI,QAGrB;AAEK,SAAS,YAId,SACA,YACA,SAKA;AACA,QAAM,QAAQ;AAAA,IACZ,GAAI,OAAO;AAAA,MACT,OAAO,QAAQ,UAAU,EAAE,IAAI,CAAC,CAAC,KAAK,MAAM,MAAM;AAChD,eAAO,CAAC,KAAK,SAAS,SAAS,MAAM,CAAC;AAAA,MACxC,CAAC;AAAA,IACH;AAAA,IACA,GAAG,mCAAS;AAAA,EACd;AACA,aAAW,IAAI,OAAO,EAAE,SAAS,YAAY,OAAO,oBAAI,QAAQ,EAAE,CAAC;AACnE,SAAO;AACT;AAEA,MAAM,WAAW,CAAC,SAAkB,UAA2B;AAC7D,MAAI,OAAO,UAAU;AAAU,WAAO;AACtC,QAAM,MAAM,QAAQ,SAAS;AAC7B,QAAM,aAAa,UAAU,IAAI,CAAC,YAAY,KAAK,IAAI,SAAS;AAChE,QAAM,OAAO,aAAa,QAAQ,MAAM;AACxC,QAAM,QAAQ,KAAK,IAAI,KAAK,IAAI,GAAG,IAAI,GAAG,GAAG;AAC7C,SAAO,QAAQ,KAAK;AACtB;AAMO,SAAS,YAKd,QACA,aAGA;AACA,QAAM,MAAM,EAAE,GAAG,OAAO;AACxB,aAAW,OAAO,QAAQ;AACxB,UAAM,YAAY,YAAY,KAAK,OAAO,GAAG,CAAC;AAC9C,eAAW,QAAQ,WAAW;AAC5B,UAAI,GAAG,OAAO,MAAM,IAAI,UAAU,IAAI;AAAA,IAC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K,SAAS,QAAQ;AAE/C,OAAK,MAAM,IAAI,MAAM,IAAI;AAEzB,SAAO;AACT;",
4
+ "sourcesContent": ["import type { Variable } from '@tamagui/web'\n\nexport type ThemeMask = Record<string, string | number>\nexport type Palette = string[]\nexport type ShiftMaskProps = { by: number; max: number; min?: number }\nexport type MaskOptions = { skip?: Partial<ThemeMask> }\n\ntype GenericTheme = { [key: string]: string | Variable }\ntype CreateMask = <A extends ThemeMask>(template: A, options: MaskOptions) => A\n\nconst THEME_INFO = new WeakMap<\n any,\n { palette: Palette; definition: ThemeMask; cache: WeakMap<any, any> }\n>()\n\nexport function createTheme<\n Definition extends ThemeMask,\n Extras extends Record<string, string> = {}\n>(\n palette: Palette,\n definition: Definition,\n options?: {\n nonInheritedValues?: Extras\n }\n): {\n [key in keyof Definition | keyof Extras]: string\n} {\n const theme = {\n ...(Object.fromEntries(\n Object.entries(definition).map(([key, offset]) => {\n return [key, getValue(palette, offset)]\n })\n ) as any),\n ...options?.nonInheritedValues,\n }\n THEME_INFO.set(theme, { palette, definition, cache: new WeakMap() })\n return theme\n}\n\nconst getValue = (palette: Palette, value: string | number) => {\n if (typeof value === 'string') return value\n const max = palette.length - 1\n const isPositive = value === 0 ? !isMinusZero(value) : value >= 0\n const next = isPositive ? value : max + value\n const index = Math.min(Math.max(0, next), max)\n return palette[index]\n}\n\ntype SubThemeKeys<ParentKeys, ChildKeys> = `${ParentKeys extends string\n ? ParentKeys\n : never}_${ChildKeys extends string ? ChildKeys : never}`\n\ntype ChildGetter<Name extends string | number | symbol, Theme extends GenericTheme> = (\n name: Name,\n theme: Theme\n) => { [key: string]: Theme }\n\nexport function addChildren<\n Themes extends { [key: string]: GenericTheme },\n GetChildren extends ChildGetter<keyof Themes, Themes[keyof Themes]>\n>(\n themes: Themes,\n getChildren: GetChildren\n): Themes & {\n [key in SubThemeKeys<keyof Themes, keyof ReturnType<GetChildren>>]: Themes[keyof Themes]\n} {\n const out = { ...themes }\n for (const key in themes) {\n const subThemes = getChildren(key, themes[key])\n for (const sKey in subThemes) {\n out[`${key}_${sKey}`] = subThemes[sKey] as any\n }\n }\n return out as any\n}\n\n// const x = createTheme([], { bg: 1 })\n// const y = addChildren({ x }, (_, x2) => ({\n// y: x,\n// }))\n\nexport const createWeakenMask = ({\n by = 1,\n max,\n min = 0,\n inverseNegatives,\n}: ShiftMaskProps & { inverseNegatives?: boolean }) => {\n return ((template, { skip }) => {\n const values = Object.entries(template) // .filter(Number)\n const out = {}\n for (const [key, value] of values) {\n if (typeof value === 'string') continue\n if (skip && key in skip) {\n out[key] = value\n continue\n }\n const isPositive = value === 0 ? !isMinusZero(value) : value >= 0\n const direction = isPositive ? 1 : -1\n const invert = inverseNegatives && !isPositive ? -1 : 1\n const next = value + by * direction * invert\n const clamped = isPositive\n ? Math.max(min, Math.min(max, next))\n : Math.min(-min, Math.max(-max, next))\n\n out[key] = clamped\n }\n return out as typeof template\n }) as CreateMask\n}\n\nfunction isMinusZero(value) {\n return 1 / value === -Infinity\n}\n\nexport const createStrengthenMask = (props: ShiftMaskProps) =>\n createWeakenMask({ ...props, inverseNegatives: true })\n\nexport function applyMask<Theme extends GenericTheme>(\n theme: Theme,\n mask: CreateMask,\n options: MaskOptions = {}\n): Theme {\n const info = THEME_INFO.get(theme)\n if (!info) {\n throw new Error(\n process.env.NODE_ENV !== 'production'\n ? `No info found for theme, you must pass the theme created by createThemeFromPalette directly to extendTheme`\n : `\u274C Err2`\n )\n }\n if (info.cache.has(mask)) {\n return info.cache.get(mask)\n }\n\n const template = mask(info.definition, options)\n const next = createTheme(info.palette, template) as Theme\n\n info.cache.set(mask, next)\n\n return next\n}\n"],
5
+ "mappings": "AAUA,MAAM,aAAa,oBAAI,QAGrB;AAEK,SAAS,YAId,SACA,YACA,SAKA;AACA,QAAM,QAAQ;AAAA,IACZ,GAAI,OAAO;AAAA,MACT,OAAO,QAAQ,UAAU,EAAE,IAAI,CAAC,CAAC,KAAK,MAAM,MAAM;AAChD,eAAO,CAAC,KAA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AO,QAAQ,KAAK,YAAY;AACtC,YAAM,UAAU,aACZ,KAAK,IAAI,KAAK,KAAK,IAAI,KAAK,IAAI,CAAC,IACjC,KAAK,IAAI,CAAC,KAAK,KAAK,IAAI,CAAC,KAAK,IAAI,CAAC;AAEvC,UAAI,GAAG,IAAI;AAAA,IACb;AACA,WAAO;AAAA,EACT;AACF;AAEA,SAAS,YAAY,OAAO;AAC1B,SAAO,IAAI,UAAU;AACvB;AAEO,MAAM,uBAAuB,CAAC,UACnC,iBAAiB,EAAE,GAAG,OAAO,kBAAkB,KAAK,CAAC;AAEhD,SAAS,UACd,OACA,MACA,UAAuB,CAAC,GACjB;AACP,QAAM,OAAO,WAAW,IAAI,KAAK;AACjC,MAAI,CAAC,MAAM;AACT,UAAM,IAAI;AAAA,MACR,QAAQ,IAAI,aAAa,eACrB,+GACA;AAAA,IACN;AAAA,EACF;AACA,MAAI,KAAK,MAAM,IAAI,IAAI,GAAG;AACxB,WAAO,KAAK,MAAM,IAAI,IAAI;AAAA,EAC5B;AAEA,QAAM,WAAW,KAAK,KAAK,YAAY,OAAO;AAC9C,QAAM,OAAO,YAAY,KAAK,SAAS,QAAQ;AAE/C,OAAK,MAAM,IAAI,MAAM,IAAI;AAEzB,SAAO;AACT;",
6
6
  "names": []
7
7
  }
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../src/index.tsx"],
4
- "sourcesContent": ["import type { Variable } from '@tamagui/web'\n\nexport type ThemeMask = Record<string, string | number>\nexport type Palette = string[]\nexport type ShiftMaskProps = { by: number; max: number; min?: number }\nexport type MaskOptions = { skip?: Partial<ThemeMask> }\n\ntype GenericTheme = { [key: string]: string | Variable }\ntype CreateMask = <A extends ThemeMask>(template: A, options: MaskOptions) => A\n\nconst THEME_INFO = new WeakMap<\n any,\n { palette: Palette; definition: ThemeMask; cache: WeakMap<any, any> }\n>()\n\nexport function createTheme<\n Definition extends ThemeMask,\n Extras extends Record<string, string> = {}\n>(\n palette: Palette,\n definition: Definition,\n options?: {\n nonInheritedValues?: Extras\n }\n): {\n [key in keyof Definition | keyof Extras]: string\n} {\n const theme = {\n ...(Object.fromEntries(\n Object.entries(definition).map(([key, offset]) => {\n return [key, getValue(palette, offset)]\n })\n ) as any),\n ...options?.nonInheritedValues,\n }\n THEME_INFO.set(theme, { palette, definition, cache: new WeakMap() })\n return theme\n}\n\nconst getValue = (palette: Palette, value: string | number) => {\n if (typeof value === 'string') return value\n const max = palette.length - 1\n const isPositive = value === 0 ? !isMinusZero(value) : value >= 0\n const next = isPositive ? value : max + value\n const index = Math.min(Math.max(0, next), max)\n return palette[index]\n}\n\ntype SubThemeKeys<ParentKeys, ChildKeys> = `${ParentKeys extends string\n ? ParentKeys\n : never}_${ChildKeys extends string ? ChildKeys : never}`\n\nexport function addChildren<\n Theme extends GenericTheme,\n Themes extends { [key: string]: Theme },\n GetChildren extends (name: keyof Themes, theme: Theme) => { [key: string]: Theme }\n>(\n themes: Themes,\n getChildren: GetChildren\n): Themes & {\n [key in SubThemeKeys<keyof Themes, keyof ReturnType<GetChildren>>]: Theme\n} {\n const out = { ...themes }\n for (const key in themes) {\n const subThemes = getChildren(key, themes[key])\n for (const sKey in subThemes) {\n out[`${key}_${sKey}`] = subThemes[sKey] as any\n }\n }\n return out as any\n}\n\nexport const createWeakenMask = ({\n by = 1,\n max,\n min = 0,\n inverseNegatives,\n}: ShiftMaskProps & { inverseNegatives?: boolean }) => {\n return ((template, { skip }) => {\n const values = Object.entries(template) // .filter(Number)\n const out = {}\n for (const [key, value] of values) {\n if (typeof value === 'string') continue\n if (skip && key in skip) {\n out[key] = value\n continue\n }\n const isPositive = value === 0 ? !isMinusZero(value) : value >= 0\n const direction = isPositive ? 1 : -1\n const invert = inverseNegatives && !isPositive ? -1 : 1\n const next = value + by * direction * invert\n const clamped = isPositive\n ? Math.max(min, Math.min(max, next))\n : Math.min(-min, Math.max(-max, next))\n\n out[key] = clamped\n }\n return out as typeof template\n }) as CreateMask\n}\n\nfunction isMinusZero(value) {\n return 1 / value === -Infinity\n}\n\nexport const createStrengthenMask = (props: ShiftMaskProps) =>\n createWeakenMask({ ...props, inverseNegatives: true })\n\nexport function applyMask<Theme extends GenericTheme>(\n theme: Theme,\n mask: CreateMask,\n options: MaskOptions = {}\n): Theme {\n const info = THEME_INFO.get(theme)\n if (!info) {\n throw new Error(\n process.env.NODE_ENV !== 'production'\n ? `No info found for theme, you must pass the theme created by createThemeFromPalette directly to extendTheme`\n : `\u274C Err2`\n )\n }\n if (info.cache.has(mask)) {\n return info.cache.get(mask)\n }\n\n const template = mask(info.definition, options)\n const next = createTheme(info.palette, template) as Theme\n\n info.cache.set(mask, next)\n\n return next\n}\n"],
5
- "mappings": "AAUA,MAAM,aAAa,oBAAI,QAGrB;AAEK,SAAS,YAId,SACA,YACA,SAKA;AACA,QAAM,QAAQ;AAAA,IACZ,GAAI,OAAO;AAAA,MACT,OAAO,QAAQ,UAAU,EAAE,IAAI,CAAC,CAAC,KAAK,MAAM,MAAM;AAChD,eAAO,CAAC,KAAK,SAAS,SAAS,MAAM,CAAC;AAAA,MACxC,CAAC;AAAA,IACH;AAAA,IACA,GAAG,mCAAS;AAAA,EACd;AACA,aAAW,IAAI,OAAO,EAAE,SAAS,YAAY,OAAO,oBAAI,QAAQ,EAAE,CAAC;AACnE,SAAO;AACT;AAEA,MAAM,WAAW,CAAC,SAAkB,UAA2B;AAC7D,MAAI,OAAO,UAAU;AAAU,WAAO;AACtC,QAAM,MAAM,QAAQ,SAAS;AAC7B,QAAM,aAAa,UAAU,IAAI,CAAC,YAAY,KAAK,IAAI,SAAS;AAChE,QAAM,OAAO,aAAa,QAAQ,MAAM;AACxC,QAAM,QAAQ,KAAK,IAAI,KAAK,IAAI,GAAG,IAAI,GAAG,GAAG;AAC7C,SAAO,QAAQ,KAAK;AACtB;AAMO,SAAS,YAKd,QACA,aAGA;AACA,QAAM,MAAM,EAAE,GAAG,OAAO;AACxB,aAAW,OAAO,QAAQ;AACxB,UA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AG;AACxB,WAAO,KAAK,MAAM,IAAI,IAAI;AAAA,EAC5B;AAEA,QAAM,WAAW,KAAK,KAAK,YAAY,OAAO;AAC9C,QAAM,OAAO,YAAY,KAAK,SAAS,QAAQ;AAE/C,OAAK,MAAM,IAAI,MAAM,IAAI;AAEzB,SAAO;AACT;",
4
+ "sourcesContent": ["import type { Variable } from '@tamagui/web'\n\nexport type ThemeMask = Record<string, string | number>\nexport type Palette = string[]\nexport type ShiftMaskProps = { by: number; max: number; min?: number }\nexport type MaskOptions = { skip?: Partial<ThemeMask> }\n\ntype GenericTheme = { [key: string]: string | Variable }\ntype CreateMask = <A extends ThemeMask>(template: A, options: MaskOptions) => A\n\nconst THEME_INFO = new WeakMap<\n any,\n { palette: Palette; definition: ThemeMask; cache: WeakMap<any, any> }\n>()\n\nexport function createTheme<\n Definition extends ThemeMask,\n Extras extends Record<string, string> = {}\n>(\n palette: Palette,\n definition: Definition,\n options?: {\n nonInheritedValues?: Extras\n }\n): {\n [key in keyof Definition | keyof Extras]: string\n} {\n const theme = {\n ...(Object.fromEntries(\n Object.entries(definition).map(([key, offset]) => {\n return [key, getValue(palette, offset)]\n })\n ) as any),\n ...options?.nonInheritedValues,\n }\n THEME_INFO.set(theme, { palette, definition, cache: new WeakMap() })\n return theme\n}\n\nconst getValue = (palette: Palette, value: string | number) => {\n if (typeof value === 'string') return value\n const max = palette.length - 1\n const isPositive = value === 0 ? !isMinusZero(value) : value >= 0\n const next = isPositive ? value : max + value\n const index = Math.min(Math.max(0, next), max)\n return palette[index]\n}\n\ntype SubThemeKeys<ParentKeys, ChildKeys> = `${ParentKeys extends string\n ? ParentKeys\n : never}_${ChildKeys extends string ? ChildKeys : never}`\n\ntype ChildGetter<Name extends string | number | symbol, Theme extends GenericTheme> = (\n name: Name,\n theme: Theme\n) => { [key: string]: Theme }\n\nexport function addChildren<\n Themes extends { [key: string]: GenericTheme },\n GetChildren extends ChildGetter<keyof Themes, Themes[keyof Themes]>\n>(\n themes: Themes,\n getChildren: GetChildren\n): Themes & {\n [key in SubThemeKeys<keyof Themes, keyof ReturnType<GetChildren>>]: Themes[keyof Themes]\n} {\n const out = { ...themes }\n for (const key in themes) {\n const subThemes = getChildren(key, themes[key])\n for (const sKey in subThemes) {\n out[`${key}_${sKey}`] = subThemes[sKey] as any\n }\n }\n return out as any\n}\n\n// const x = createTheme([], { bg: 1 })\n// const y = addChildren({ x }, (_, x2) => ({\n// y: x,\n// }))\n\nexport const createWeakenMask = ({\n by = 1,\n max,\n min = 0,\n inverseNegatives,\n}: ShiftMaskProps & { inverseNegatives?: boolean }) => {\n return ((template, { skip }) => {\n const values = Object.entries(template) // .filter(Number)\n const out = {}\n for (const [key, value] of values) {\n if (typeof value === 'string') continue\n if (skip && key in skip) {\n out[key] = value\n continue\n }\n const isPositive = value === 0 ? !isMinusZero(value) : value >= 0\n const direction = isPositive ? 1 : -1\n const invert = inverseNegatives && !isPositive ? -1 : 1\n const next = value + by * direction * invert\n const clamped = isPositive\n ? Math.max(min, Math.min(max, next))\n : Math.min(-min, Math.max(-max, next))\n\n out[key] = clamped\n }\n return out as typeof template\n }) as CreateMask\n}\n\nfunction isMinusZero(value) {\n return 1 / value === -Infinity\n}\n\nexport const createStrengthenMask = (props: ShiftMaskProps) =>\n createWeakenMask({ ...props, inverseNegatives: true })\n\nexport function applyMask<Theme extends GenericTheme>(\n theme: Theme,\n mask: CreateMask,\n options: MaskOptions = {}\n): Theme {\n const info = THEME_INFO.get(theme)\n if (!info) {\n throw new Error(\n process.env.NODE_ENV !== 'production'\n ? `No info found for theme, you must pass the theme created by createThemeFromPalette directly to extendTheme`\n : `\u274C Err2`\n )\n }\n if (info.cache.has(mask)) {\n return info.cache.get(mask)\n }\n\n const template = mask(info.definition, options)\n const next = createTheme(info.palette, template) as Theme\n\n info.cache.set(mask, next)\n\n return next\n}\n"],
5
+ "mappings": "AAUA,MAAM,aAAa,oBAAI,QAGrB;AAEK,SAAS,YAId,SACA,YACA,SAKA;AACA,QAAM,Q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AAI,CAAC,YAAY,KAAK,IAAI,SAAS;AAChE,YAAM,YAAY,aAAa,IAAI;AACnC,YAAM,SAAS,oBAAoB,CAAC,aAAa,KAAK;AACtD,YAAM,OAAO,QAAQ,KAAK,YAAY;AACtC,YAAM,UAAU,aACZ,KAAK,IAAI,KAAK,KAAK,IAAI,KAAK,IAAI,CAAC,IACjC,KAAK,IAAI,CAAC,KAAK,KAAK,IAAI,CAAC,KAAK,IAAI,CAAC;AAEvC,UAAI,GAAG,IAAI;AAAA,IACb;AACA,WAAO;AAAA,EACT;AACF;AAEA,SAAS,YAAY,OAAO;AAC1B,SAAO,IAAI,UAAU;AACvB;AAEO,MAAM,uBAAuB,CAAC,UACnC,iBAAiB,EAAE,GAAG,OAAO,kBAAkB,KAAK,CAAC;AAEhD,SAAS,UACd,OACA,MACA,UAAuB,CAAC,GACjB;AACP,QAAM,OAAO,WAAW,IAAI,KAAK;AACjC,MAAI,CAAC,MAAM;AACT,UAAM,IAAI;AAAA,MACR,QAAQ,IAAI,aAAa,eACrB,+GACA;AAAA,IACN;AAAA,EACF;AACA,MAAI,KAAK,MAAM,IAAI,IAAI,GAAG;AACxB,WAAO,KAAK,MAAM,IAAI,IAAI;AAAA,EAC5B;AAEA,QAAM,WAAW,KAAK,KAAK,YAAY,OAAO;AAC9C,QAAM,OAAO,YAAY,KAAK,SAAS,QAAQ;AAE/C,OAAK,MAAM,IAAI,MAAM,IAAI;AAEzB,SAAO;AACT;",
6
6
  "names": []
7
7
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tamagui/create-theme",
3
- "version": "1.4.0",
3
+ "version": "1.5.1",
4
4
  "types": "./types/index.d.ts",
5
5
  "main": "dist/cjs",
6
6
  "module": "dist/esm",
@@ -27,10 +27,10 @@
27
27
  }
28
28
  },
29
29
  "dependencies": {
30
- "@tamagui/web": "^1.4.0"
30
+ "@tamagui/web": "^1.5.1"
31
31
  },
32
32
  "devDependencies": {
33
- "@tamagui/build": "^1.4.0"
33
+ "@tamagui/build": "^1.5.1"
34
34
  },
35
35
  "publishConfig": {
36
36
  "access": "public"
package/src/index.tsx CHANGED
@@ -50,15 +50,19 @@ type SubThemeKeys<ParentKeys, ChildKeys> = `${ParentKeys extends string
50
50
  ? ParentKeys
51
51
  : never}_${ChildKeys extends string ? ChildKeys : never}`
52
52
 
53
+ type ChildGetter<Name extends string | number | symbol, Theme extends GenericTheme> = (
54
+ name: Name,
55
+ theme: Theme
56
+ ) => { [key: string]: Theme }
57
+
53
58
  export function addChildren<
54
- Theme extends GenericTheme,
55
- Themes extends { [key: string]: Theme },
56
- GetChildren extends (name: keyof Themes, theme: Theme) => { [key: string]: Theme }
59
+ Themes extends { [key: string]: GenericTheme },
60
+ GetChildren extends ChildGetter<keyof Themes, Themes[keyof Themes]>
57
61
  >(
58
62
  themes: Themes,
59
63
  getChildren: GetChildren
60
64
  ): Themes & {
61
- [key in SubThemeKeys<keyof Themes, keyof ReturnType<GetChildren>>]: Theme
65
+ [key in SubThemeKeys<keyof Themes, keyof ReturnType<GetChildren>>]: Themes[keyof Themes]
62
66
  } {
63
67
  const out = { ...themes }
64
68
  for (const key in themes) {
@@ -70,6 +74,11 @@ export function addChildren<
70
74
  return out as any
71
75
  }
72
76
 
77
+ // const x = createTheme([], { bg: 1 })
78
+ // const y = addChildren({ x }, (_, x2) => ({
79
+ // y: x,
80
+ // }))
81
+
73
82
  export const createWeakenMask = ({
74
83
  by = 1,
75
84
  max,
@@ -0,0 +1,35 @@
1
+ import type { Variable } from '@tamagui/web';
2
+ export type ThemeMask = Record<string, string | number>;
3
+ export type Palette = string[];
4
+ export type ShiftMaskProps = {
5
+ by: number;
6
+ max: number;
7
+ min?: number;
8
+ };
9
+ export type MaskOptions = {
10
+ skip?: Partial<ThemeMask>;
11
+ };
12
+ type GenericTheme = {
13
+ [key: string]: string | Variable;
14
+ };
15
+ type CreateMask = <A extends ThemeMask>(template: A, options: MaskOptions) => A;
16
+ export declare function createTheme<Definition extends ThemeMask, Extras extends Record<string, string> = {}>(palette: Palette, definition: Definition, options?: {
17
+ nonInheritedValues?: Extras;
18
+ }): {
19
+ [key in keyof Definition | keyof Extras]: string;
20
+ };
21
+ type SubThemeKeys<ParentKeys, ChildKeys> = `${ParentKeys extends string ? ParentKeys : never}_${ChildKeys extends string ? ChildKeys : never}`;
22
+ export declare function addChildren<Theme extends GenericTheme, Themes extends {
23
+ [key: string]: Theme;
24
+ }, GetChildren extends (name: keyof Themes, theme: Theme) => {
25
+ [key: string]: Theme;
26
+ }>(themes: Themes, getChildren: GetChildren): Themes & {
27
+ [key in SubThemeKeys<keyof Themes, keyof ReturnType<GetChildren>>]: Theme;
28
+ };
29
+ export declare const createWeakenMask: ({ by, max, min, inverseNegatives, }: ShiftMaskProps & {
30
+ inverseNegatives?: boolean | undefined;
31
+ }) => CreateMask;
32
+ export declare const createStrengthenMask: (props: ShiftMaskProps) => CreateMask;
33
+ export declare function applyMask<Theme extends GenericTheme>(theme: Theme, mask: CreateMask, options?: MaskOptions): Theme;
34
+ export {};
35
+ //# sourceMappingURL=createTheme.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"createTheme.d.ts","sourceRoot":"","sources":["../src/createTheme.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,cAAc,CAAA;AAE5C,MAAM,MAAM,SAAS,GAAG,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,CAAC,CAAA;AACvD,MAAM,MAAM,OAAO,GAAG,MAAM,EAAE,CAAA;AAC9B,MAAM,MAAM,cAAc,GAAG;IAAE,EAAE,EAAE,MAAM,CAAC;IAAC,GAAG,EAAE,MAAM,CAAC;IAAC,GAAG,CAAC,EAAE,MAAM,CAAA;CAAE,CAAA;AACtE,MAAM,MAAM,WAAW,GAAG;IAAE,IAAI,CAAC,EAAE,OAAO,CAAC,SAAS,CAAC,CAAA;CAAE,CAAA;AAEvD,KAAK,YAAY,GAAG;IAAE,CA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IAAI,EAAE,UAAU,EAChB,OAAO,GAAE,WAAgB,GACxB,KAAK,CAmBP"}
package/types/index.d.ts CHANGED
@@ -19,12 +19,13 @@ export declare function createTheme<Definition extends ThemeMask, Extras extends
19
19
  [key in keyof Definition | keyof Extras]: string;
20
20
  };
21
21
  type SubThemeKeys<ParentKeys, ChildKeys> = `${ParentKeys extends string ? ParentKeys : never}_${ChildKeys extends string ? ChildKeys : never}`;
22
- export declare function addChildren<Theme extends GenericTheme, Themes extends {
22
+ type ChildGetter<Name extends string | number | symbol, Theme extends GenericTheme> = (name: Name, theme: Theme) => {
23
23
  [key: string]: Theme;
24
- }, GetChildren extends (name: keyof Themes, theme: Theme) => {
25
- [key: string]: Theme;
26
- }>(themes: Themes, getChildren: GetChildren): Themes & {
27
- [key in SubThemeKeys<keyof Themes, keyof ReturnType<GetChildren>>]: Theme;
24
+ };
25
+ export declare function addChildren<Themes extends {
26
+ [key: string]: GenericTheme;
27
+ }, GetChildren extends ChildGetter<keyof Themes, Themes[keyof Themes]>>(themes: Themes, getChildren: GetChildren): Themes & {
28
+ [key in SubThemeKeys<keyof Themes, keyof ReturnType<GetChildren>>]: Themes[keyof Themes];
28
29
  };
29
30
  export declare const createWeakenMask: ({ by, max, min, inverseNegatives, }: ShiftMaskProps & {
30
31
  inverseNegatives?: boolean | undefined;
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,cAAc,CAAA;AAE5C,MAAM,MAAM,SAAS,GAAG,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,CAAC,CAAA;AACvD,MAAM,MAAM,OAAO,GAAG,MAAM,EAAE,CAAA;AAC9B,MAAM,MAAM,cAAc,GAAG;IAAE,EAAE,EAAE,MAAM,CAAC;IAAC,GAAG,EAAE,MAAM,CAAC;IAAC,GAAG,CAAC,EAAE,MAAM,CAAA;CAAE,CAAA;A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