@tamagui/create-theme 1.15.13 → 1.15.15

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.
@@ -1,7 +1,6 @@
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[]\n\nexport type MaskOptions = {\n palette?: Palette\n override?: Partial<ThemeMask>\n skip?: Partial<ThemeMask>\n strength?: number\n max?: number\n min?: number\n}\n\ntype GenericTheme = { [key: string]: string | Variable }\n\nexport type CreateMask = <A extends ThemeMask>(template: A, options: MaskOptions) => A\n\nconst THEME_INFO = new WeakMap<\n any,\n { palette: Palette; definition: ThemeMask; cache: Map<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 Map() })\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\nexport const skipMask: CreateMask = (template, { skip }) => {\n if (!skip) return template\n return Object.fromEntries(\n Object.entries(template).filter(([k]) => !(k in skip))\n ) as typeof template\n}\n\nexport const createShiftMask = ({ inverse }: { inverse?: boolean } = {}) => {\n return ((template, opts) => {\n const { override, max: maxIn, palette, min = 0, strength = 1 } = opts\n const values = Object.entries(template)\n const max = maxIn ?? (palette ? Object.values(palette).length - 1 : Infinity)\n const out = {}\n for (const [key, value] of values) {\n if (typeof value === 'string') continue\n if (typeof override?.[key] === 'number') {\n const overrideShift = override[key] as number\n out[key] = value + overrideShift\n continue\n }\n const isPositive = value === 0 ? !isMinusZero(value) : value >= 0\n const direction = isPositive ? 1 : -1\n const invert = inverse ? -1 : 1\n const next = value + strength * 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\n return skipMask(out, opts) as typeof template\n }) as CreateMask\n}\n\nexport const createWeakenMask = () => createShiftMask()\nexport const createStrengthenMask = () => createShiftMask({ inverse: true })\n\nfunction isMinusZero(value) {\n return 1 / value === -Infinity\n}\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\n const template = mask(info.definition, {\n palette: info.palette,\n ...options,\n })\n const next = createTheme(info.palette, template) as Theme\n\n return next\n}\n\n// --- tests ---\n\nif (process.env.NODE_ENV === 'development') {\n const palette = ['0', '1', '2', '3', '-3', '-2', '-1', '-0']\n const template = { bg: 1, fg: -1 }\n\n const stongerMask = createStrengthenMask()\n const weakerMask = createWeakenMask()\n\n const theme = createTheme(palette, template)\n if (theme.bg !== '1') throw `\u274C`\n if (theme.fg !== '-1') throw `\u274C`\n\n const str = applyMask(theme, stongerMask)\n if (str.bg !== '0') throw `\u274C`\n if (str.fg !== '-0') throw `\u274C`\n\n const weak = applyMask(theme, weakerMask)\n if (weak.bg !== '2') throw `\u274C`\n if (weak.fg !== '-2') throw `\u274C`\n\n const weak2 = applyMask(theme, weakerMask, { strength: 2 })\n if (weak2.bg !== '3') throw `\u274C`\n if (weak2.fg !== '-3') throw `\u274C`\n}\n"],
5
4
  "mappings": ";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAkBA,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,IAAI,EAAE,CAAC;AAC/D,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,K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UAAM;AAC5B,MAAI,MAAM,OAAO;AAAM,UAAM;AAC/B;",
6
5
  "names": []
7
6
  }
@@ -1,7 +1,6 @@
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[]\n\nexport type MaskOptions = {\n palette?: Palette\n override?: Partial<ThemeMask>\n skip?: Partial<ThemeMask>\n strength?: number\n max?: number\n min?: number\n}\n\ntype GenericTheme = { [key: string]: string | Variable }\n\nexport type CreateMask = <A extends ThemeMask>(template: A, options: MaskOptions) => A\n\nconst THEME_INFO = new WeakMap<\n any,\n { palette: Palette; definition: ThemeMask; cache: Map<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 Map() })\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\nexport const skipMask: CreateMask = (template, { skip }) => {\n if (!skip) return template\n return Object.fromEntries(\n Object.entries(template).filter(([k]) => !(k in skip))\n ) as typeof template\n}\n\nexport const createShiftMask = ({ inverse }: { inverse?: boolean } = {}) => {\n return ((template, opts) => {\n const { override, max: maxIn, palette, min = 0, strength = 1 } = opts\n const values = Object.entries(template)\n const max = maxIn ?? (palette ? Object.values(palette).length - 1 : Infinity)\n const out = {}\n for (const [key, value] of values) {\n if (typeof value === 'string') continue\n if (typeof override?.[key] === 'number') {\n const overrideShift = override[key] as number\n out[key] = value + overrideShift\n continue\n }\n const isPositive = value === 0 ? !isMinusZero(value) : value >= 0\n const direction = isPositive ? 1 : -1\n const invert = inverse ? -1 : 1\n const next = value + strength * 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\n return skipMask(out, opts) as typeof template\n }) as CreateMask\n}\n\nexport const createWeakenMask = () => createShiftMask()\nexport const createStrengthenMask = () => createShiftMask({ inverse: true })\n\nfunction isMinusZero(value) {\n return 1 / value === -Infinity\n}\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\n const template = mask(info.definition, {\n palette: info.palette,\n ...options,\n })\n const next = createTheme(info.palette, template) as Theme\n\n return next\n}\n\n// --- tests ---\n\nif (process.env.NODE_ENV === 'development') {\n const palette = ['0', '1', '2', '3', '-3', '-2', '-1', '-0']\n const template = { bg: 1, fg: -1 }\n\n const stongerMask = createStrengthenMask()\n const weakerMask = createWeakenMask()\n\n const theme = createTheme(palette, template)\n if (theme.bg !== '1') throw `\u274C`\n if (theme.fg !== '-1') throw `\u274C`\n\n const str = applyMask(theme, stongerMask)\n if (str.bg !== '0') throw `\u274C`\n if (str.fg !== '-0') throw `\u274C`\n\n const weak = applyMask(theme, weakerMask)\n if (weak.bg !== '2') throw `\u274C`\n if (weak.fg !== '-2') throw `\u274C`\n\n const weak2 = applyMask(theme, weakerMask, { strength: 2 })\n if (weak2.bg !== '3') throw `\u274C`\n if (weak2.fg !== '-3') throw `\u274C`\n}\n"],
5
4
  "mappings": "AAkBA,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,IAAI,EAAE,CAAC;AAC/D,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;AAWO,SAAS,YAId,QACA,aAGA;AACA,QAAM,MAAM,EAAE,GAAG,OAAO;AACxB,aAAW,OAAO,QAAQ;AACxB,UAAM,YAAY,YAAY,KAAK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["../../src/index.tsx"],
4
- "sourcesContent": ["import type { Variable } from '@tamagui/web'\n\nexport type ThemeMask = Record<string, string | number>\nexport type Palette = string[]\n\nexport type MaskOptions = {\n palette?: Palette\n override?: Partial<ThemeMask>\n skip?: Partial<ThemeMask>\n strength?: number\n max?: number\n min?: number\n}\n\ntype GenericTheme = { [key: string]: string | Variable }\n\nexport type CreateMask = <A extends ThemeMask>(template: A, options: MaskOptions) => A\n\nconst THEME_INFO = new WeakMap<\n any,\n { palette: Palette; definition: ThemeMask; cache: Map<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 Map() })\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\nexport const skipMask: CreateMask = (template, { skip }) => {\n if (!skip) return template\n return Object.fromEntries(\n Object.entries(template).filter(([k]) => !(k in skip))\n ) as typeof template\n}\n\nexport const createShiftMask = ({ inverse }: { inverse?: boolean } = {}) => {\n return ((template, opts) => {\n const { override, max: maxIn, palette, min = 0, strength = 1 } = opts\n const values = Object.entries(template)\n const max = maxIn ?? (palette ? Object.values(palette).length - 1 : Infinity)\n const out = {}\n for (const [key, value] of values) {\n if (typeof value === 'string') continue\n if (typeof override?.[key] === 'number') {\n const overrideShift = override[key] as number\n out[key] = value + overrideShift\n continue\n }\n const isPositive = value === 0 ? !isMinusZero(value) : value >= 0\n const direction = isPositive ? 1 : -1\n const invert = inverse ? -1 : 1\n const next = value + strength * 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\n return skipMask(out, opts) as typeof template\n }) as CreateMask\n}\n\nexport const createWeakenMask = () => createShiftMask()\nexport const createStrengthenMask = () => createShiftMask({ inverse: true })\n\nfunction isMinusZero(value) {\n return 1 / value === -Infinity\n}\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\n const template = mask(info.definition, {\n palette: info.palette,\n ...options,\n })\n const next = createTheme(info.palette, template) as Theme\n\n return next\n}\n\n// --- tests ---\n\nif (process.env.NODE_ENV === 'development') {\n const palette = ['0', '1', '2', '3', '-3', '-2', '-1', '-0']\n const template = { bg: 1, fg: -1 }\n\n const stongerMask = createStrengthenMask()\n const weakerMask = createWeakenMask()\n\n const theme = createTheme(palette, template)\n if (theme.bg !== '1') throw `\u274C`\n if (theme.fg !== '-1') throw `\u274C`\n\n const str = applyMask(theme, stongerMask)\n if (str.bg !== '0') throw `\u274C`\n if (str.fg !== '-0') throw `\u274C`\n\n const weak = applyMask(theme, weakerMask)\n if (weak.bg !== '2') throw `\u274C`\n if (weak.fg !== '-2') throw `\u274C`\n\n const weak2 = applyMask(theme, weakerMask, { strength: 2 })\n if (weak2.bg !== '3') throw `\u274C`\n if (weak2.fg !== '-3') throw `\u274C`\n}\n"],
5
4
  "mappings": "AAkBA,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,IAAI,EAAE,CAAC;AAC/D,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;AAWO,SAAS,YAId,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,IACxC;AAAA,EACF;AACA,SAAO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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;AAEA,QAAM,WAAW,KAAK,KAAK,YAAY;AAAA,IACrC,SAAS,KAAK;AAAA,IACd,GAAG;AAAA,EACL,CAAC;AACD,QAAM,OAAO,YAAY,KAAK,SAAS,QAAQ;AAE/C,SAAO;AACT;AAIA,IAAI,QAAQ,IAAI,aAAa,eAAe;AAC1C,QAAM,UAAU,CAAC,KAAK,KAAK,KAAK,KAAK,MAAM,MAAM,MAAM,IAAI;AAC3D,QAAM,WAAW,EAAE,IAAI,GAAG,IAAI,GAAG;AAEjC,QAAM,cAAc,qBAAqB;AACzC,QAAM,aAAa,iBAAiB;AAEpC,QAAM,QAAQ,YAAY,SAAS,QAAQ;AAC3C,MAAI,MAAM,OAAO;AAAK,UAAM;AAC5B,MAAI,MAAM,OAAO;AAAM,UAAM;AAE7B,QAAM,MAAM,UAAU,OAAO,WAAW;AACxC,MAAI,IAAI,OAAO;AAAK,UAAM;AAC1B,MAAI,IAAI,OAAO;AAAM,UAAM;AAE3B,QAAM,OAAO,UAAU,OAAO,UAAU;AACxC,MAAI,KAAK,OAAO;AAAK,UAAM;AAC3B,MAAI,KAAK,OAAO;AAAM,UAAM;AAE5B,QAAM,QAAQ,UAAU,OAAO,YAAY,EAAE,UAAU,EAAE,CAAC;AAC1D,MAAI,MAAM,OAAO;AAAK,UAAM;AAC5B,MAAI,MAAM,OAAO;AAAM,UAAM;AAC/B;",
6
5
  "names": []
7
6
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tamagui/create-theme",
3
- "version": "1.15.13",
3
+ "version": "1.15.15",
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.15.13"
30
+ "@tamagui/web": "1.15.15"
31
31
  },
32
32
  "devDependencies": {
33
- "@tamagui/build": "1.15.13"
33
+ "@tamagui/build": "1.15.15"
34
34
  },
35
35
  "publishConfig": {
36
36
  "access": "public"