@tamagui/create-theme 1.125.21 → 1.125.22
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +3 -3
- package/types/applyMask.d.ts.map +18 -0
- package/types/combineMasks.d.ts.map +11 -0
- package/types/createTheme.d.ts.map +22 -0
- package/types/createThemeTypes.d.ts.map +14 -0
- package/types/helpers.d.ts.map +17 -0
- package/types/index.d.ts.map +11 -0
- package/types/isMinusZero.d.ts.map +13 -0
- package/types/masks.d.ts.map +16 -0
- package/types/tests.d.ts.map +11 -0
- package/types/themeInfo.d.ts.map +15 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tamagui/create-theme",
|
|
3
|
-
"version": "1.125.
|
|
3
|
+
"version": "1.125.22",
|
|
4
4
|
"types": "./types/index.d.ts",
|
|
5
5
|
"main": "dist/cjs",
|
|
6
6
|
"module": "dist/esm",
|
|
@@ -33,10 +33,10 @@
|
|
|
33
33
|
}
|
|
34
34
|
},
|
|
35
35
|
"dependencies": {
|
|
36
|
-
"@tamagui/web": "1.125.
|
|
36
|
+
"@tamagui/web": "1.125.22"
|
|
37
37
|
},
|
|
38
38
|
"devDependencies": {
|
|
39
|
-
"@tamagui/build": "1.125.
|
|
39
|
+
"@tamagui/build": "1.125.22"
|
|
40
40
|
},
|
|
41
41
|
"publishConfig": {
|
|
42
42
|
"access": "public"
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
{
|
|
2
|
+
"mappings": "AACA,cAAc,YAAY,cAAc,aAAa,iBAAiB,oBAAoB;AAC1F,cAAc,iBAAiB,aAAa;AAG5C,OAAO,iBAAS,UAAU,cAAc,eAAe,WACrDA,OAAO,OACPC,MAAM,YACNC,UAAS,aACTC,qBACAC,oBACC;AAqBH,OAAO,iBAAS,mBAAmB,cAAc,eAAe,WAC9DC,MAAM,WACNJ,MAAM,YACNC,UAAS,aACTC,sBACC,YAAY,EACb,OAAO,MACR",
|
|
3
|
+
"names": [
|
|
4
|
+
"theme: Theme",
|
|
5
|
+
"mask: CreateMask",
|
|
6
|
+
"options: MaskOptions",
|
|
7
|
+
"parentName?: string",
|
|
8
|
+
"nextName?: string",
|
|
9
|
+
"info: ThemeInfo"
|
|
10
|
+
],
|
|
11
|
+
"sources": [
|
|
12
|
+
"src/applyMask.tsx"
|
|
13
|
+
],
|
|
14
|
+
"sourcesContent": [
|
|
15
|
+
"import { createTheme } from './createTheme'\nimport type { CreateMask, GenericTheme, MaskOptions, ThemeMask } from './createThemeTypes'\nimport type { ThemeInfo } from './themeInfo'\nimport { getThemeInfo, setThemeInfo } from './themeInfo'\n\nexport function applyMask<Theme extends GenericTheme | ThemeMask>(\n theme: Theme,\n mask: CreateMask,\n options: MaskOptions = {},\n parentName?: string,\n nextName?: string\n): Theme {\n const info = getThemeInfo(theme, parentName)\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 : `❌ Err2`\n )\n }\n\n const next = applyMaskStateless(info, mask, options, parentName)\n\n setThemeInfo(next.theme, {\n definition: next.definition,\n palette: info.palette,\n name: nextName,\n })\n\n return next.theme as Theme\n}\n\nexport function applyMaskStateless<Theme extends GenericTheme | ThemeMask>(\n info: ThemeInfo,\n mask: CreateMask,\n options: MaskOptions = {},\n parentName?: string\n): ThemeInfo & {\n theme: Theme\n} {\n const skip = {\n ...options.skip,\n }\n\n // skip nonInheritedValues from parent theme\n if (info.options?.nonInheritedValues) {\n for (const key in info.options.nonInheritedValues) {\n skip[key] = 1\n }\n }\n\n // convert theme back to template first\n const maskOptions = {\n parentName,\n palette: info.palette,\n ...options,\n skip,\n }\n\n const template = mask.mask(info.definition, maskOptions)\n const theme = createTheme(info.palette, template) as Theme\n\n return {\n ...info,\n cache: new Map(),\n definition: template,\n theme,\n }\n}\n"
|
|
16
|
+
],
|
|
17
|
+
"version": 3
|
|
18
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
{
|
|
2
|
+
"mappings": "AACA,cAAc,kBAAkB,oBAAoB;AAGpD,OAAO,cAAM,eAAgB,GAAG,OAAO,iBAAe",
|
|
3
|
+
"names": [],
|
|
4
|
+
"sources": [
|
|
5
|
+
"src/combineMasks.tsx"
|
|
6
|
+
],
|
|
7
|
+
"sourcesContent": [
|
|
8
|
+
"import { applyMaskStateless } from './applyMask'\nimport type { CreateMask } from './createThemeTypes'\nimport { getThemeInfo } from './themeInfo'\n\nexport const combineMasks = (...masks: CreateMask[]): CreateMask => {\n const mask: CreateMask = {\n name: 'combine-mask',\n mask: (template, opts) => {\n let current = getThemeInfo(template, opts.parentName)\n let theme: any\n for (const mask of masks) {\n if (!current) {\n throw new Error(\n `Nothing returned from mask: ${current}, for template: ${template} and mask: ${mask.toString()}, given opts ${JSON.stringify(\n opts,\n null,\n 2\n )}`\n )\n }\n const next = applyMaskStateless(current, mask, opts)\n current = next\n theme = next.theme\n }\n return theme\n },\n }\n return mask\n}\n"
|
|
9
|
+
],
|
|
10
|
+
"version": 3
|
|
11
|
+
}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
{
|
|
2
|
+
"mappings": "AAAA,cACE,oBACA,oBACA,cACA,iBACK,oBAAoB;AAM3B,OAAO,iBAAS;CACd,mBAAmB;CACnB,eAAe,eAAe,CAAE;EAEhCA,UAAU,eAAe,qBACzBC,wBACAC,YAAY,YACZC,UAAU,oBACVC,eACA,yBAEC,aAAa,mBAAmB;AA2BnC,OAAO,iBAAS;CACd,mBAAmB;CACnB,eAAe,eAAe,CAAE;EAEhCC,SAAS,oBACTH,YAAY,YACZC,UAAU,oBACVC,eACA,yBAEC,aAAa,mBAAmB;KAyC9B;CAAa;CAAY;OAAgB,4BAC1C,sBACS,2BAA2B;KAEnC;CAAY;CAAuC,cAAc;KACpEE,MAAM,MACNC,OAAO,UACJ,iBAAiB,MAAO;AAE7B,OAAO,iBAAS;CACd,eAAe,iBAAiB,aAAc;CAC9C,oBAAoB,kBAAkB,QAAQ,aAAa;EAE3DC,QAAQ,QACRC,aAAa,cACZ,YACA,OAAO,mBAAmB,cAAc,WAAW,iBAAgB,aAAa",
|
|
3
|
+
"names": [
|
|
4
|
+
"palettes: Record<string, CreateThemePalette>",
|
|
5
|
+
"defaultPalette: string",
|
|
6
|
+
"definition: Definition",
|
|
7
|
+
"options?: CreateThemeOptions",
|
|
8
|
+
"name?: string",
|
|
9
|
+
"palette: CreateThemePalette",
|
|
10
|
+
"name: Name",
|
|
11
|
+
"theme: Theme",
|
|
12
|
+
"themes: Themes",
|
|
13
|
+
"getChildren: GetChildren"
|
|
14
|
+
],
|
|
15
|
+
"sources": [
|
|
16
|
+
"src/createTheme.tsx"
|
|
17
|
+
],
|
|
18
|
+
"sourcesContent": [
|
|
19
|
+
"import type {\n CreateThemeOptions,\n CreateThemePalette,\n GenericTheme,\n ThemeMask,\n} from './createThemeTypes'\nimport { isMinusZero } from './isMinusZero'\nimport { setThemeInfo } from './themeInfo'\n\nconst identityCache = new Map()\n\nexport function createThemeWithPalettes<\n Definition extends ThemeMask,\n Extras extends GenericTheme = {},\n>(\n palettes: Record<string, CreateThemePalette>,\n defaultPalette: string,\n definition: Definition,\n options?: CreateThemeOptions,\n name?: string,\n skipCache = false\n): {\n [key in keyof Definition | keyof Extras]: string\n} {\n if (!palettes[defaultPalette]) {\n throw new Error(`No pallete: ${defaultPalette}`)\n }\n const newDef = { ...definition }\n for (const key in definition) {\n let val = definition[key]\n if (typeof val === 'string' && val[0] === '$') {\n const [altPaletteName$, altPaletteIndex] = val.split('.')\n const altPaletteName = altPaletteName$.slice(1)\n const parentName = defaultPalette.split('_')[0]\n const altPalette =\n palettes[altPaletteName] || palettes[`${parentName}_${altPaletteName}`]\n\n if (altPalette) {\n const next = getValue(altPalette, +altPaletteIndex)\n if (typeof next !== 'undefined') {\n newDef[key] = next as any\n }\n }\n }\n }\n\n return createTheme(palettes[defaultPalette], newDef, options, name, skipCache)\n}\n\nexport function createTheme<\n Definition extends ThemeMask,\n Extras extends GenericTheme = {},\n>(\n palette: CreateThemePalette,\n definition: Definition,\n options?: CreateThemeOptions,\n name?: string,\n skipCache = false\n): {\n [key in keyof Definition | keyof Extras]: string\n} {\n const cacheKey = skipCache ? '' : JSON.stringify([name, palette, definition, options])\n if (!skipCache) {\n if (identityCache.has(cacheKey)) {\n return identityCache.get(cacheKey)\n }\n }\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\n setThemeInfo(theme, { palette, definition, options, name })\n\n if (cacheKey) {\n identityCache.set(cacheKey, theme)\n }\n\n return theme\n}\n\nconst getValue = (palette: CreateThemePalette, value: string | number) => {\n if (!palette) {\n throw new Error(`No palette!`)\n }\n if (typeof value === 'string') {\n return value\n }\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"
|
|
20
|
+
],
|
|
21
|
+
"version": 3
|
|
22
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
{
|
|
2
|
+
"mappings": "AAAA,cAAc,gBAAgB,cAAc;AAE5C,YAAY,+BAA+B;AAE3C,YAAY,YAAY;AAExB,YAAY,cAAc;CACxB,UAAU;CACV,WAAW,QAAQ;CACnB,mBAAmB,UAAU;CAC7B,eAAe,QAAQ;CACvB,gBAAgB,QAAQ;CACxB,OAAO,QAAQ;CACf;CACA;CACA;CACA;AACD;AAED,YAAY,eAAe,0BAA0B,SAAU;AAE/D,YAAY,gBAAgB,UAAU,WAAWA,UAAU,GAAGC,SAAS,gBAAgB;AAEvF,YAAY,aAAa;CACvB;CACA,MAAM;AACP;AAED,YAAY,qBAAqB,EAC/B,qBAAqB,aACtB;AAED,YAAY;AAEZ,YAAY,WAAW,iCAEtB;AAED,YAAY,eAAe,kBAAkB,cAAc;CACzD,MAAM;CACN;CACA,eAAe,cAAc,EAC3B,OAAO,MACR;AACF;AAED,YAAY,qBAAqB,qBAAqB;CACpD;CACA;AACD;KAEI,kBAAkB,EACrB,OAAO,wBAAyB,EACjC;AAED,YAAY,MAAM,kBACd,kBACA,qBACA,eAAe;AAEnB,YAAY,gBAAgB,kBAAkB,MAAM,SAAS,EAC3D,eACD;AAED,YAAY,qBAAqB,iBAChB,QAChB;AAED,YAAY,gBAAgB,iCACxB,MAAM,SACN,gBAAgB;KAEf,2BAA2B,CAAE;AAElC,YAAY,iBAAiB,iCAAiC,iBAC7C,gBAAgB,QAAQ,iBACxC;AAED,YAAY,sBAAsB,iBACjB,SAChB;AAED,YAAY,kBAAkB,iBACb,aAAa,WAAW,QACxC",
|
|
3
|
+
"names": [
|
|
4
|
+
"template: A",
|
|
5
|
+
"options: MaskOptions"
|
|
6
|
+
],
|
|
7
|
+
"sources": [
|
|
8
|
+
"src/createThemeTypes.tsx"
|
|
9
|
+
],
|
|
10
|
+
"sourcesContent": [
|
|
11
|
+
"import type { Variable } from '@tamagui/web'\n\nexport type CreateThemePalette = (string | Variable)[]\n\nexport type ThemeMask = Record<string, string | number>\n\nexport type MaskOptions = {\n palette?: CreateThemePalette\n override?: Partial<ThemeMask>\n overrideStrategy?: 'shift' | 'swap'\n overrideSwap?: Partial<ThemeMask>\n overrideShift?: Partial<ThemeMask>\n skip?: Partial<ThemeMask>\n strength?: number\n max?: number\n min?: number\n parentName?: string\n}\n\nexport type GenericTheme = { [key: string]: string | Variable }\n\nexport type MaskFunction = <A extends ThemeMask>(template: A, options: MaskOptions) => A\n\nexport type CreateMask = {\n name: string\n mask: MaskFunction\n}\n\nexport type CreateThemeOptions = {\n nonInheritedValues?: GenericTheme\n}\n\nexport type Palette = string[]\n\nexport type Template = {\n [key: string]: number | string\n}\n\nexport type ThemeUsingMask<Masks = string> = MaskOptions & {\n mask: Masks\n avoidNestingWithin?: string[]\n childOptions?: MaskOptions & {\n mask?: Masks\n }\n}\n\nexport type ThemeUsingTemplate = CreateThemeOptions & {\n palette?: string\n template: string\n}\n\ntype ThemePreDefined = {\n theme: { [key: string]: string }\n}\n\nexport type Theme<Masks = string> =\n | ThemePreDefined\n | ThemeUsingTemplate\n | ThemeUsingMask<Masks>\n\nexport type ThemeWithParent<Masks = string> = Theme<Masks> & {\n parent: string\n}\n\nexport type PaletteDefinitions = {\n [key: string]: Palette\n}\n\nexport type ThemeDefinition<Masks extends string = string> =\n | Theme<Masks>\n | ThemeWithParent<Masks>[]\n\ntype UnionableString = string & {}\n\nexport type ThemeDefinitions<Masks extends string = string> = {\n [key: string]: ThemeDefinition<Masks | UnionableString>\n}\n\nexport type TemplateDefinitions = {\n [key: string]: Template\n}\n\nexport type MaskDefinitions = {\n [key: string]: CreateMask | CreateMask['mask']\n}\n"
|
|
12
|
+
],
|
|
13
|
+
"version": 3
|
|
14
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
{
|
|
2
|
+
"mappings": "KAAK,aAAa,OAAO;KAEpB;CAAY;CAAO;IACtB,KAAK,UAAU,WAAW,SAAQ,MAAM,WAAW,UAAU,kBAAkB;KAE5E,cAAc,YACd,WAAW,gBAAe,YAAY,OAAO,MAAM,KAAK,MAAM,YAAY;AAE/E,OAAO,cAAM,aAAc,UAAU,QAAQA,KAAK,MAA0B,YAAY;AAExF,OAAO,iBAAS,cAAc,cAAc,YAC1CC,KAAK,QACJ,cAAc;KAIZ,eACA,0BACD,wBAAwB;KAGvB,aAAa,sBAAsB,WAAW,SAAQ,aAAa,MAAM;KACzE,oBAAoB,YACtB,uBAAuBC,GAAG,mCAAmCC,SAAS,aACnE;KAID,4BAA4B,cAAc,eAC7C,aAAa,sBAAsB,OAC/B,iBAAiB,WAAW,UACvB,QAAQ,MAAM,eAAc;KAGlC,yBAAyB,WAAW,aAAa,QAAO,KAAK;KAC7D,gBAAgB,cAAc,eAAe,yBAChD,oBAAoB,4BAA4B;AAGlD,OAAO,iBAAS,kBAAkB,cAAc,aAC9CC,KAAK,QACJ,gBAAgB",
|
|
3
|
+
"names": [
|
|
4
|
+
"obj: O",
|
|
5
|
+
"obj: OBJ_T",
|
|
6
|
+
"k: UNION_T",
|
|
7
|
+
"k: infer I",
|
|
8
|
+
"arr: ARR_T"
|
|
9
|
+
],
|
|
10
|
+
"sources": [
|
|
11
|
+
"src/helpers.tsx"
|
|
12
|
+
],
|
|
13
|
+
"sourcesContent": [
|
|
14
|
+
"type ObjectType = Record<PropertyKey, unknown>\n\ntype PickByValue<OBJ_T, VALUE_T> = // From https://stackoverflow.com/a/55153000\n Pick<OBJ_T, { [K in keyof OBJ_T]: OBJ_T[K] extends VALUE_T ? K : never }[keyof OBJ_T]>\n\ntype ObjectEntries<OBJ_T> = // From https://stackoverflow.com/a/60142095\n { [K in keyof OBJ_T]: [keyof PickByValue<OBJ_T, OBJ_T[K]>, OBJ_T[K]] }[keyof OBJ_T][]\n\nexport const objectKeys = <O extends Object>(obj: O) => Object.keys(obj) as Array<keyof O>\n\nexport function objectEntries<OBJ_T extends ObjectType>(\n obj: OBJ_T\n): ObjectEntries<OBJ_T> {\n return Object.entries(obj) as ObjectEntries<OBJ_T>\n}\n\ntype EntriesType =\n | [PropertyKey, unknown][]\n | ReadonlyArray<readonly [PropertyKey, unknown]>\n\n// Existing Utils\ntype DeepWritable<OBJ_T> = { -readonly [P in keyof OBJ_T]: DeepWritable<OBJ_T[P]> }\ntype UnionToIntersection<UNION_T> = // From https://stackoverflow.com/a/50375286\n (UNION_T extends any ? (k: UNION_T) => void : never) extends (k: infer I) => void\n ? I\n : never\n\n// New Utils\ntype UnionObjectFromArrayOfPairs<ARR_T extends EntriesType> =\n DeepWritable<ARR_T> extends (infer R)[]\n ? R extends [infer key, infer val]\n ? { [prop in key & PropertyKey]: val }\n : never\n : never\ntype MergeIntersectingObjects<ObjT> = { [key in keyof ObjT]: ObjT[key] }\ntype EntriesToObject<ARR_T extends EntriesType> = MergeIntersectingObjects<\n UnionToIntersection<UnionObjectFromArrayOfPairs<ARR_T>>\n>\n\nexport function objectFromEntries<ARR_T extends EntriesType>(\n arr: ARR_T\n): EntriesToObject<ARR_T> {\n return Object.fromEntries(arr) as EntriesToObject<ARR_T>\n}\n"
|
|
15
|
+
],
|
|
16
|
+
"version": 3
|
|
17
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
{
|
|
2
|
+
"mappings": "AAAA,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc",
|
|
3
|
+
"names": [],
|
|
4
|
+
"sources": [
|
|
5
|
+
"src/index.tsx"
|
|
6
|
+
],
|
|
7
|
+
"sourcesContent": [
|
|
8
|
+
"export * from './createTheme'\nexport * from './masks'\nexport * from './combineMasks'\nexport * from './applyMask'\nexport * from './createThemeTypes'\nexport * from './helpers'\n"
|
|
9
|
+
],
|
|
10
|
+
"version": 3
|
|
11
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
{
|
|
2
|
+
"mappings": "AAAA,OAAO,iBAAS,YAAYA",
|
|
3
|
+
"names": [
|
|
4
|
+
"value: number"
|
|
5
|
+
],
|
|
6
|
+
"sources": [
|
|
7
|
+
"src/isMinusZero.tsx"
|
|
8
|
+
],
|
|
9
|
+
"sourcesContent": [
|
|
10
|
+
"export function isMinusZero(value: number): boolean {\n return 1 / value === Number.NEGATIVE_INFINITY\n}\n"
|
|
11
|
+
],
|
|
12
|
+
"version": 3
|
|
13
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
{
|
|
2
|
+
"mappings": "AAAA,cAAc,YAAY,cAAc,mBAAmB,oBAAoB;AAI/E,OAAO,cAAM,aAAc,UAAU,aAAa,cAChDA,YAAY,MACX;AAKH,OAAO,cAAMC,UAAU;AA8CvB,OAAO,cAAM,0BAAyB;AAKtC,OAAO,cAAM,yBAAwB;KAahC,mBAAmB,EAAE,kBAAmB;AAE7C,OAAO,cAAM,kBACX,EAAE,SAA2B,GAAhB,kBACbC,iBAAiB,gBAChB;AA6CH,OAAO,cAAM,mBAAoBA,iBAAiB,gBAAc;AAKhE,OAAO,cAAMC,mBAAmBD,iBAAiB,gBAAgB;AAGjE,OAAO,cAAM,uBAAwBA,iBAAiB,gBAAc",
|
|
3
|
+
"names": [
|
|
4
|
+
"createMask: C",
|
|
5
|
+
"skipMask: CreateMask",
|
|
6
|
+
"defaultOptions?: MaskOptions",
|
|
7
|
+
"createSoftenMask: (defaultOptions?: MaskOptions) => CreateMask"
|
|
8
|
+
],
|
|
9
|
+
"sources": [
|
|
10
|
+
"src/masks.tsx"
|
|
11
|
+
],
|
|
12
|
+
"sourcesContent": [
|
|
13
|
+
"import type { CreateMask, MaskFunction, MaskOptions } from './createThemeTypes'\nimport { objectEntries, objectFromEntries } from './helpers'\nimport { isMinusZero } from './isMinusZero'\n\nexport const createMask = <C extends CreateMask | MaskFunction>(\n createMask: C\n): CreateMask =>\n typeof createMask === 'function'\n ? { name: createMask.name || 'unnamed', mask: createMask }\n : createMask\n\nexport const skipMask: CreateMask = {\n name: 'skip-mask',\n mask: (template, opts) => {\n const { skip } = opts\n const result = Object.fromEntries(\n Object.entries(template)\n .filter(([k]) => !skip || !(k in skip))\n .map(([k, v]) => [k, applyOverrides(k, v, opts)])\n ) as typeof template\n\n return result\n },\n}\n\nfunction applyOverrides(key: string, value: number | string, opts: MaskOptions) {\n let override: string | number | undefined\n let strategy = opts.overrideStrategy\n\n const overrideSwap = opts.overrideSwap?.[key]\n if (typeof overrideSwap !== 'undefined') {\n override = overrideSwap\n strategy = 'swap'\n } else {\n const overrideShift = opts.overrideShift?.[key]\n if (typeof overrideShift !== 'undefined') {\n override = overrideShift\n strategy = 'shift'\n } else {\n const overrideDefault = opts.override?.[key]\n if (typeof overrideDefault !== 'undefined') {\n override = overrideDefault\n strategy = opts.overrideStrategy\n }\n }\n }\n\n if (typeof override === 'undefined') return value\n if (typeof override === 'string') return value\n\n if (strategy === 'swap') {\n return override\n }\n\n return value\n}\n\nexport const createIdentityMask = (): CreateMask => ({\n name: 'identity-mask',\n mask: (template, opts) => skipMask.mask(template, opts),\n})\n\nexport const createInverseMask = (): CreateMask => {\n const mask: CreateMask = {\n name: 'inverse-mask',\n mask: (template, opts) => {\n const inversed = objectFromEntries(\n objectEntries(template).map(([k, v]) => [k, -v])\n ) as any\n return skipMask.mask(inversed, opts)\n },\n }\n return mask\n}\n\ntype ShiftMaskOptions = { inverse?: boolean }\n\nexport const createShiftMask = (\n { inverse }: ShiftMaskOptions = {},\n defaultOptions?: MaskOptions\n): CreateMask => {\n const mask: CreateMask = {\n name: 'shift-mask',\n mask: (template, opts) => {\n const {\n override,\n overrideStrategy = 'shift',\n max: maxIn,\n palette,\n min = 0,\n strength = 1,\n } = { ...defaultOptions, ...opts }\n const values = Object.entries(template)\n const max =\n maxIn ?? (palette ? Object.values(palette).length - 1 : Number.POSITIVE_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 overrideVal = override[key] as number\n out[key] = overrideStrategy === 'shift' ? value + overrideVal : overrideVal\n continue\n }\n if (typeof override?.[key] === 'string') {\n out[key] = override[key]\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 const skipped = skipMask.mask(out, opts) as typeof template\n return skipped\n },\n }\n return mask\n}\n\nexport const createWeakenMask = (defaultOptions?: MaskOptions): CreateMask => ({\n name: 'soften-mask',\n mask: createShiftMask({}, defaultOptions).mask,\n})\n\nexport const createSoftenMask: (defaultOptions?: MaskOptions) => CreateMask =\n createWeakenMask\n\nexport const createStrengthenMask = (defaultOptions?: MaskOptions): CreateMask => ({\n name: 'strengthen-mask',\n mask: createShiftMask({ inverse: true }, defaultOptions).mask,\n})\n"
|
|
14
|
+
],
|
|
15
|
+
"version": 3
|
|
16
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
{
|
|
2
|
+
"mappings": "",
|
|
3
|
+
"names": [],
|
|
4
|
+
"sources": [
|
|
5
|
+
"src/tests.tsx"
|
|
6
|
+
],
|
|
7
|
+
"sourcesContent": [
|
|
8
|
+
"import { applyMask } from './applyMask'\nimport { createTheme } from './createTheme'\nimport { createStrengthenMask, createWeakenMask } from './masks'\n\n// --- tests ---\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 `❌`\n if (theme.fg !== '-1') throw `❌`\n\n const str = applyMask(theme, stongerMask)\n if (str.bg !== '0') throw `❌`\n if (str.fg !== '-0') throw `❌`\n\n const weak = applyMask(theme, weakerMask)\n if (weak.bg !== '2') throw `❌`\n if (weak.fg !== '-2') throw `❌`\n\n const weak2 = applyMask(theme, weakerMask, { strength: 2 })\n if (weak2.bg !== '3') throw `❌`\n if (weak2.fg !== '-3') throw `❌`\n}\n"
|
|
9
|
+
],
|
|
10
|
+
"version": 3
|
|
11
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
{
|
|
2
|
+
"mappings": "AAAA,cACE,oBACA,oBACA,cACA,iBACK,oBAAoB;AAE3B,YAAY,YAAY;CACtB,SAAS;CACT,YAAY;CACZ,UAAU;CACV,OAAO;AACR;AAID,OAAO,cAAM,eACXA,OAAO,eAAe,WACtBC,kBACC;AAIH,OAAO,cAAM,eACXD,OAAO,eAAe,WACtBE,MAAM,KAAK,WAAW,YAAY,eAAe,aAAa,EAC5D,cACD",
|
|
3
|
+
"names": [
|
|
4
|
+
"theme: GenericTheme | ThemeMask",
|
|
5
|
+
"name?: string",
|
|
6
|
+
"info: Pick<ThemeInfo, 'palette' | 'definition' | 'options'> & {\n name?: string\n }"
|
|
7
|
+
],
|
|
8
|
+
"sources": [
|
|
9
|
+
"src/themeInfo.tsx"
|
|
10
|
+
],
|
|
11
|
+
"sourcesContent": [
|
|
12
|
+
"import type {\n CreateThemeOptions,\n CreateThemePalette,\n GenericTheme,\n ThemeMask,\n} from './createThemeTypes'\n\nexport type ThemeInfo = {\n palette: CreateThemePalette\n definition: ThemeMask\n options?: CreateThemeOptions\n cache: Map<any, any>\n}\n\nconst THEME_INFO = new Map<string, ThemeInfo>()\n\nexport const getThemeInfo = (\n theme: GenericTheme | ThemeMask,\n name?: string\n): ThemeInfo | undefined => {\n return THEME_INFO.get(name || JSON.stringify(theme))\n}\n\nexport const setThemeInfo = (\n theme: GenericTheme | ThemeMask,\n info: Pick<ThemeInfo, 'palette' | 'definition' | 'options'> & {\n name?: string\n }\n): void => {\n const next = {\n ...info,\n cache: new Map(),\n }\n THEME_INFO.set(info.name || JSON.stringify(theme), next)\n THEME_INFO.set(JSON.stringify(info.definition), next)\n}\n"
|
|
13
|
+
],
|
|
14
|
+
"version": 3
|
|
15
|
+
}
|