@tamagui/create-theme 2.0.0-rc.3 → 2.0.0-rc.30

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (50) hide show
  1. package/dist/cjs/index.js +16 -13
  2. package/dist/esm/index.js +6 -6
  3. package/dist/esm/index.js.map +1 -6
  4. package/package.json +6 -9
  5. package/types/applyMask.d.ts.map +2 -2
  6. package/types/combineMasks.d.ts.map +2 -2
  7. package/types/createTheme.d.ts.map +2 -2
  8. package/types/createThemeTypes.d.ts.map +2 -2
  9. package/types/helpers.d.ts.map +2 -2
  10. package/types/index.d.ts.map +2 -2
  11. package/types/isMinusZero.d.ts.map +2 -2
  12. package/types/masks.d.ts.map +4 -7
  13. package/types/tests.d.ts.map +2 -2
  14. package/types/themeInfo.d.ts.map +2 -2
  15. package/dist/cjs/applyMask.js +0 -55
  16. package/dist/cjs/applyMask.js.map +0 -6
  17. package/dist/cjs/combineMasks.js +0 -40
  18. package/dist/cjs/combineMasks.js.map +0 -6
  19. package/dist/cjs/createTheme.js +0 -69
  20. package/dist/cjs/createTheme.js.map +0 -6
  21. package/dist/cjs/createThemeTypes.js +0 -14
  22. package/dist/cjs/createThemeTypes.js.map +0 -6
  23. package/dist/cjs/helpers.js +0 -29
  24. package/dist/cjs/helpers.js.map +0 -6
  25. package/dist/cjs/isMinusZero.js +0 -23
  26. package/dist/cjs/isMinusZero.js.map +0 -6
  27. package/dist/cjs/masks.js +0 -98
  28. package/dist/cjs/masks.js.map +0 -6
  29. package/dist/cjs/tests.js +0 -12
  30. package/dist/cjs/tests.js.map +0 -6
  31. package/dist/cjs/themeInfo.js +0 -28
  32. package/dist/cjs/themeInfo.js.map +0 -6
  33. package/dist/esm/applyMask.js +0 -40
  34. package/dist/esm/applyMask.js.map +0 -6
  35. package/dist/esm/combineMasks.js +0 -25
  36. package/dist/esm/combineMasks.js.map +0 -6
  37. package/dist/esm/createTheme.js +0 -54
  38. package/dist/esm/createTheme.js.map +0 -6
  39. package/dist/esm/createThemeTypes.js +0 -1
  40. package/dist/esm/createThemeTypes.js.map +0 -6
  41. package/dist/esm/helpers.js +0 -13
  42. package/dist/esm/helpers.js.map +0 -6
  43. package/dist/esm/isMinusZero.js +0 -7
  44. package/dist/esm/isMinusZero.js.map +0 -6
  45. package/dist/esm/masks.js +0 -83
  46. package/dist/esm/masks.js.map +0 -6
  47. package/dist/esm/tests.js +0 -14
  48. package/dist/esm/tests.js.map +0 -6
  49. package/dist/esm/themeInfo.js +0 -12
  50. package/dist/esm/themeInfo.js.map +0 -6
package/dist/cjs/index.js CHANGED
@@ -3,18 +3,21 @@ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
3
3
  var __getOwnPropNames = Object.getOwnPropertyNames;
4
4
  var __hasOwnProp = Object.prototype.hasOwnProperty;
5
5
  var __copyProps = (to, from, except, desc) => {
6
- if (from && typeof from == "object" || typeof from == "function")
7
- for (let key of __getOwnPropNames(from))
8
- !__hasOwnProp.call(to, key) && key !== except && __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
9
- return to;
10
- }, __reExport = (target, mod, secondTarget) => (__copyProps(target, mod, "default"), secondTarget && __copyProps(secondTarget, mod, "default"));
11
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: !0 }), mod);
6
+ if (from && typeof from == "object" || typeof from == "function") for (let key of __getOwnPropNames(from)) !__hasOwnProp.call(to, key) && key !== except && __defProp(to, key, {
7
+ get: () => from[key],
8
+ enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
9
+ });
10
+ return to;
11
+ },
12
+ __reExport = (target, mod, secondTarget) => (__copyProps(target, mod, "default"), secondTarget && __copyProps(secondTarget, mod, "default"));
13
+ var __toCommonJS = mod => __copyProps(__defProp({}, "__esModule", {
14
+ value: !0
15
+ }), mod);
12
16
  var index_exports = {};
13
17
  module.exports = __toCommonJS(index_exports);
14
- __reExport(index_exports, require("./createTheme"), module.exports);
15
- __reExport(index_exports, require("./masks"), module.exports);
16
- __reExport(index_exports, require("./combineMasks"), module.exports);
17
- __reExport(index_exports, require("./applyMask"), module.exports);
18
- __reExport(index_exports, require("./createThemeTypes"), module.exports);
19
- __reExport(index_exports, require("./helpers"), module.exports);
20
- //# sourceMappingURL=index.js.map
18
+ __reExport(index_exports, require("./createTheme.cjs"), module.exports);
19
+ __reExport(index_exports, require("./masks.cjs"), module.exports);
20
+ __reExport(index_exports, require("./combineMasks.cjs"), module.exports);
21
+ __reExport(index_exports, require("./applyMask.cjs"), module.exports);
22
+ __reExport(index_exports, require("./createThemeTypes.cjs"), module.exports);
23
+ __reExport(index_exports, require("./helpers.cjs"), module.exports);
package/dist/esm/index.js CHANGED
@@ -1,7 +1,7 @@
1
- export * from "./createTheme";
2
- export * from "./masks";
3
- export * from "./combineMasks";
4
- export * from "./applyMask";
5
- export * from "./createThemeTypes";
6
- export * from "./helpers";
1
+ export * from "./createTheme.mjs";
2
+ export * from "./masks.mjs";
3
+ export * from "./combineMasks.mjs";
4
+ export * from "./applyMask.mjs";
5
+ export * from "./createThemeTypes.mjs";
6
+ export * from "./helpers.mjs";
7
7
  //# sourceMappingURL=index.js.map
@@ -1,6 +1 @@
1
- {
2
- "version": 3,
3
- "sources": ["../../src/index.tsx"],
4
- "mappings": "AAAA,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;",
5
- "names": []
6
- }
1
+ {"version":3,"names":[],"sources":["../../src/index.tsx"],"sourcesContent":[null],"mappings":"AAAA,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc","ignoreList":[]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tamagui/create-theme",
3
- "version": "2.0.0-rc.3",
3
+ "version": "2.0.0-rc.30",
4
4
  "files": [
5
5
  "src",
6
6
  "types",
@@ -16,15 +16,12 @@
16
16
  "./package.json": "./package.json",
17
17
  ".": {
18
18
  "types": "./types/index.d.ts",
19
- "react-native": {
20
- "module": "./dist/esm/index.native.js",
21
- "import": "./dist/esm/index.native.js",
22
- "require": "./dist/cjs/index.native.js"
23
- },
19
+ "react-native": "./dist/esm/index.native.js",
20
+ "browser": "./dist/esm/index.mjs",
24
21
  "module": "./dist/esm/index.mjs",
25
22
  "import": "./dist/esm/index.mjs",
26
23
  "require": "./dist/cjs/index.cjs",
27
- "default": "./dist/cjs/index.native.js"
24
+ "default": "./dist/esm/index.mjs"
28
25
  }
29
26
  },
30
27
  "publishConfig": {
@@ -37,9 +34,9 @@
37
34
  "clean:build": "tamagui-build clean:build"
38
35
  },
39
36
  "dependencies": {
40
- "@tamagui/web": "2.0.0-rc.3"
37
+ "@tamagui/web": "2.0.0-rc.30"
41
38
  },
42
39
  "devDependencies": {
43
- "@tamagui/build": "2.0.0-rc.3"
40
+ "@tamagui/build": "2.0.0-rc.30"
44
41
  }
45
42
  }
@@ -4,8 +4,8 @@
4
4
  "sources": [
5
5
  "src/applyMask.tsx"
6
6
  ],
7
+ "version": 3,
7
8
  "sourcesContent": [
8
9
  "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"
9
- ],
10
- "version": 3
10
+ ]
11
11
  }
@@ -4,8 +4,8 @@
4
4
  "sources": [
5
5
  "src/combineMasks.tsx"
6
6
  ],
7
+ "version": 3,
7
8
  "sourcesContent": [
8
9
  "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
10
+ ]
11
11
  }
@@ -4,8 +4,8 @@
4
4
  "sources": [
5
5
  "src/createTheme.tsx"
6
6
  ],
7
+ "version": 3,
7
8
  "sourcesContent": [
8
9
  "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 palette: ${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"
9
- ],
10
- "version": 3
10
+ ]
11
11
  }
@@ -4,8 +4,8 @@
4
4
  "sources": [
5
5
  "src/createThemeTypes.tsx"
6
6
  ],
7
+ "version": 3,
7
8
  "sourcesContent": [
8
9
  "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"
9
- ],
10
- "version": 3
10
+ ]
11
11
  }
@@ -4,8 +4,8 @@
4
4
  "sources": [
5
5
  "src/helpers.tsx"
6
6
  ],
7
+ "version": 3,
7
8
  "sourcesContent": [
8
9
  "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"
9
- ],
10
- "version": 3
10
+ ]
11
11
  }
@@ -4,8 +4,8 @@
4
4
  "sources": [
5
5
  "src/index.tsx"
6
6
  ],
7
+ "version": 3,
7
8
  "sourcesContent": [
8
9
  "export * from './createTheme'\nexport * from './masks'\nexport * from './combineMasks'\nexport * from './applyMask'\nexport * from './createThemeTypes'\nexport * from './helpers'\n"
9
- ],
10
- "version": 3
10
+ ]
11
11
  }
@@ -4,8 +4,8 @@
4
4
  "sources": [
5
5
  "src/isMinusZero.tsx"
6
6
  ],
7
+ "version": 3,
7
8
  "sourcesContent": [
8
9
  "export function isMinusZero(value: number): boolean {\n return 1 / value === Number.NEGATIVE_INFINITY\n}\n"
9
- ],
10
- "version": 3
10
+ ]
11
11
  }
@@ -1,14 +1,11 @@
1
1
  {
2
- "mappings": "AAAA,cAAc,YAAY,cAAc,mBAAmB;AAI3D,OAAO,cAAM,aAAc,UAAU,aAAa,cAChD,YAAY,MACX;AAKH,OAAO,cAAMA,UAAU;AA8CvB,OAAO,cAAM,0BAAyB;AAKtC,OAAO,cAAM,yBAAwB;KAahC,mBAAmB;CAAE;;AAE1B,OAAO,cAAM,kBACX,EAAE,YAAW,kBACb,iBAAiB,gBAChB;AA6CH,OAAO,cAAM,mBAAoB,iBAAiB,gBAAc;AAKhE,OAAO,cAAMC,mBAAmB,iBAAiB,gBAAgB;AAGjE,OAAO,cAAM,uBAAwB,iBAAiB,gBAAc",
3
- "names": [
4
- "skipMask: CreateMask",
5
- "createSoftenMask: (defaultOptions?: MaskOptions) => CreateMask"
6
- ],
2
+ "mappings": "AAAA,cAAc,YAAY,cAAc,mBAAmB;AAI3D,OAAO,cAAM,aAAc,UAAU,aAAa,cAChD,YAAY,MACX;AAKH,OAAO,cAAM,UAAU;AA8CvB,OAAO,cAAM,0BAAyB;AAKtC,OAAO,cAAM,yBAAwB;KAahC,mBAAmB;CAAE;;AAE1B,OAAO,cAAM,kBACX,EAAE,YAAW,kBACb,iBAAiB,gBAChB;AA6CH,OAAO,cAAM,mBAAoB,iBAAiB,gBAAc;AAKhE,OAAO,cAAM,mBAAmB,iBAAiB,gBAAgB;AAGjE,OAAO,cAAM,uBAAwB,iBAAiB,gBAAc",
3
+ "names": [],
7
4
  "sources": [
8
5
  "src/masks.tsx"
9
6
  ],
7
+ "version": 3,
10
8
  "sourcesContent": [
11
9
  "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"
12
- ],
13
- "version": 3
10
+ ]
14
11
  }
@@ -4,8 +4,8 @@
4
4
  "sources": [
5
5
  "src/tests.tsx"
6
6
  ],
7
+ "version": 3,
7
8
  "sourcesContent": [
8
9
  "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
10
+ ]
11
11
  }
@@ -4,8 +4,8 @@
4
4
  "sources": [
5
5
  "src/themeInfo.tsx"
6
6
  ],
7
+ "version": 3,
7
8
  "sourcesContent": [
8
9
  "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"
9
- ],
10
- "version": 3
10
+ ]
11
11
  }
@@ -1,55 +0,0 @@
1
- var __defProp = Object.defineProperty;
2
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
3
- var __getOwnPropNames = Object.getOwnPropertyNames;
4
- var __hasOwnProp = Object.prototype.hasOwnProperty;
5
- var __export = (target, all) => {
6
- for (var name in all)
7
- __defProp(target, name, { get: all[name], enumerable: !0 });
8
- }, __copyProps = (to, from, except, desc) => {
9
- if (from && typeof from == "object" || typeof from == "function")
10
- for (let key of __getOwnPropNames(from))
11
- !__hasOwnProp.call(to, key) && key !== except && __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
12
- return to;
13
- };
14
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: !0 }), mod);
15
- var applyMask_exports = {};
16
- __export(applyMask_exports, {
17
- applyMask: () => applyMask,
18
- applyMaskStateless: () => applyMaskStateless
19
- });
20
- module.exports = __toCommonJS(applyMask_exports);
21
- var import_createTheme = require("./createTheme"), import_themeInfo = require("./themeInfo");
22
- function applyMask(theme, mask, options = {}, parentName, nextName) {
23
- const info = (0, import_themeInfo.getThemeInfo)(theme, parentName);
24
- if (!info)
25
- throw new Error(
26
- process.env.NODE_ENV !== "production" ? "No info found for theme, you must pass the theme created by createThemeFromPalette directly to extendTheme" : "\u274C Err2"
27
- );
28
- const next = applyMaskStateless(info, mask, options, parentName);
29
- return (0, import_themeInfo.setThemeInfo)(next.theme, {
30
- definition: next.definition,
31
- palette: info.palette,
32
- name: nextName
33
- }), next.theme;
34
- }
35
- function applyMaskStateless(info, mask, options = {}, parentName) {
36
- const skip = {
37
- ...options.skip
38
- };
39
- if (info.options?.nonInheritedValues)
40
- for (const key in info.options.nonInheritedValues)
41
- skip[key] = 1;
42
- const maskOptions = {
43
- parentName,
44
- palette: info.palette,
45
- ...options,
46
- skip
47
- }, template = mask.mask(info.definition, maskOptions), theme = (0, import_createTheme.createTheme)(info.palette, template);
48
- return {
49
- ...info,
50
- cache: /* @__PURE__ */ new Map(),
51
- definition: template,
52
- theme
53
- };
54
- }
55
- //# sourceMappingURL=applyMask.js.map
@@ -1,6 +0,0 @@
1
- {
2
- "version": 3,
3
- "sources": ["../../src/applyMask.tsx"],
4
- "mappings": ";;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,yBAA4B,0BAG5B,mBAA2C;AAEpC,SAAS,UACd,OACA,MACA,UAAuB,CAAC,GACxB,YACA,UACO;AACP,QAAM,WAAO,+BAAa,OAAO,UAAU;AAC3C,MAAI,CAAC;AACH,UAAM,IAAI;AAAA,MACR,QAAQ,IAAI,aAAa,eACrB,+GACA;AAAA,IACN;AAGF,QAAM,OAAO,mBAAmB,MAAM,MAAM,SAAS,UAAU;AAE/D,4CAAa,KAAK,OAAO;AAAA,IACvB,YAAY,KAAK;AAAA,IACjB,SAAS,KAAK;AAAA,IACd,MAAM;AAAA,EACR,CAAC,GAEM,KAAK;AACd;AAEO,SAAS,mBACd,MACA,MACA,UAAuB,CAAC,GACxB,YAGA;AACA,QAAM,OAAO;AAAA,IACX,GAAG,QAAQ;AAAA,EACb;AAGA,MAAI,KAAK,SAAS;AAChB,eAAW,OAAO,KAAK,QAAQ;AAC7B,WAAK,GAAG,IAAI;AAKhB,QAAM,cAAc;AAAA,IAClB;AAAA,IACA,SAAS,KAAK;AAAA,IACd,GAAG;AAAA,IACH;AAAA,EACF,GAEM,WAAW,KAAK,KAAK,KAAK,YAAY,WAAW,GACjD,YAAQ,gCAAY,KAAK,SAAS,QAAQ;AAEhD,SAAO;AAAA,IACL,GAAG;AAAA,IACH,OAAO,oBAAI,IAAI;AAAA,IACf,YAAY;AAAA,IACZ;AAAA,EACF;AACF;",
5
- "names": []
6
- }
@@ -1,40 +0,0 @@
1
- var __defProp = Object.defineProperty;
2
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
3
- var __getOwnPropNames = Object.getOwnPropertyNames;
4
- var __hasOwnProp = Object.prototype.hasOwnProperty;
5
- var __export = (target, all) => {
6
- for (var name in all)
7
- __defProp(target, name, { get: all[name], enumerable: !0 });
8
- }, __copyProps = (to, from, except, desc) => {
9
- if (from && typeof from == "object" || typeof from == "function")
10
- for (let key of __getOwnPropNames(from))
11
- !__hasOwnProp.call(to, key) && key !== except && __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
12
- return to;
13
- };
14
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: !0 }), mod);
15
- var combineMasks_exports = {};
16
- __export(combineMasks_exports, {
17
- combineMasks: () => combineMasks
18
- });
19
- module.exports = __toCommonJS(combineMasks_exports);
20
- var import_applyMask = require("./applyMask"), import_themeInfo = require("./themeInfo");
21
- const combineMasks = (...masks) => ({
22
- name: "combine-mask",
23
- mask: (template, opts) => {
24
- let current = (0, import_themeInfo.getThemeInfo)(template, opts.parentName), theme;
25
- for (const mask2 of masks) {
26
- if (!current)
27
- throw new Error(
28
- `Nothing returned from mask: ${current}, for template: ${template} and mask: ${mask2.toString()}, given opts ${JSON.stringify(
29
- opts,
30
- null,
31
- 2
32
- )}`
33
- );
34
- const next = (0, import_applyMask.applyMaskStateless)(current, mask2, opts);
35
- current = next, theme = next.theme;
36
- }
37
- return theme;
38
- }
39
- });
40
- //# sourceMappingURL=combineMasks.js.map
@@ -1,6 +0,0 @@
1
- {
2
- "version": 3,
3
- "sources": ["../../src/combineMasks.tsx"],
4
- "mappings": ";;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,uBAAmC,wBAEnC,mBAA6B;AAEtB,MAAM,eAAe,IAAI,WACL;AAAA,EACvB,MAAM;AAAA,EACN,MAAM,CAAC,UAAU,SAAS;AACxB,QAAI,cAAU,+BAAa,UAAU,KAAK,UAAU,GAChD;AACJ,eAAWA,SAAQ,OAAO;AACxB,UAAI,CAAC;AACH,cAAM,IAAI;AAAA,UACR,+BAA+B,OAAO,mBAAmB,QAAQ,cAAcA,MAAK,SAAS,CAAC,gBAAgB,KAAK;AAAA,YACjH;AAAA,YACA;AAAA,YACA;AAAA,UACF,CAAC;AAAA,QACH;AAEF,YAAM,WAAO,qCAAmB,SAASA,OAAM,IAAI;AACnD,gBAAU,MACV,QAAQ,KAAK;AAAA,IACf;AACA,WAAO;AAAA,EACT;AACF;",
5
- "names": ["mask"]
6
- }
@@ -1,69 +0,0 @@
1
- var __defProp = Object.defineProperty;
2
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
3
- var __getOwnPropNames = Object.getOwnPropertyNames;
4
- var __hasOwnProp = Object.prototype.hasOwnProperty;
5
- var __export = (target, all) => {
6
- for (var name in all)
7
- __defProp(target, name, { get: all[name], enumerable: !0 });
8
- }, __copyProps = (to, from, except, desc) => {
9
- if (from && typeof from == "object" || typeof from == "function")
10
- for (let key of __getOwnPropNames(from))
11
- !__hasOwnProp.call(to, key) && key !== except && __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
12
- return to;
13
- };
14
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: !0 }), mod);
15
- var createTheme_exports = {};
16
- __export(createTheme_exports, {
17
- addChildren: () => addChildren,
18
- createTheme: () => createTheme,
19
- createThemeWithPalettes: () => createThemeWithPalettes
20
- });
21
- module.exports = __toCommonJS(createTheme_exports);
22
- var import_isMinusZero = require("./isMinusZero"), import_themeInfo = require("./themeInfo");
23
- const identityCache = /* @__PURE__ */ new Map();
24
- function createThemeWithPalettes(palettes, defaultPalette, definition, options, name, skipCache = !1) {
25
- if (!palettes[defaultPalette])
26
- throw new Error(`No palette: ${defaultPalette}`);
27
- const newDef = { ...definition };
28
- for (const key in definition) {
29
- let val = definition[key];
30
- if (typeof val == "string" && val[0] === "$") {
31
- const [altPaletteName$, altPaletteIndex] = val.split("."), altPaletteName = altPaletteName$.slice(1), parentName = defaultPalette.split("_")[0], altPalette = palettes[altPaletteName] || palettes[`${parentName}_${altPaletteName}`];
32
- if (altPalette) {
33
- const next = getValue(altPalette, +altPaletteIndex);
34
- typeof next < "u" && (newDef[key] = next);
35
- }
36
- }
37
- }
38
- return createTheme(palettes[defaultPalette], newDef, options, name, skipCache);
39
- }
40
- function createTheme(palette, definition, options, name, skipCache = !1) {
41
- const cacheKey = skipCache ? "" : JSON.stringify([name, palette, definition, options]);
42
- if (!skipCache && identityCache.has(cacheKey))
43
- return identityCache.get(cacheKey);
44
- const theme = {
45
- ...Object.fromEntries(
46
- Object.entries(definition).map(([key, offset]) => [key, getValue(palette, offset)])
47
- ),
48
- ...options?.nonInheritedValues
49
- };
50
- return (0, import_themeInfo.setThemeInfo)(theme, { palette, definition, options, name }), cacheKey && identityCache.set(cacheKey, theme), theme;
51
- }
52
- const getValue = (palette, value) => {
53
- if (!palette)
54
- throw new Error("No palette!");
55
- if (typeof value == "string")
56
- return value;
57
- const max = palette.length - 1, next = (value === 0 ? !(0, import_isMinusZero.isMinusZero)(value) : value >= 0) ? value : max + value, index = Math.min(Math.max(0, next), max);
58
- return palette[index];
59
- };
60
- function addChildren(themes, getChildren) {
61
- const out = { ...themes };
62
- for (const key in themes) {
63
- const subThemes = getChildren(key, themes[key]);
64
- for (const sKey in subThemes)
65
- out[`${key}_${sKey}`] = subThemes[sKey];
66
- }
67
- return out;
68
- }
69
- //# sourceMappingURL=createTheme.js.map
@@ -1,6 +0,0 @@
1
- {
2
- "version": 3,
3
- "sources": ["../../src/createTheme.tsx"],
4
- "mappings": ";;;;;;;;;;;;;;AAAA;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,SAAS,KAAK,CAAC,GAEtD,YACF,cAAc,IAAI,UAAU,KAAK,GAG5B;AACT;AAEA,MAAM,WAAW,CAAC,SAA6B,UAA2B;AACxE,MAAI,CAAC;AACH,UAAM,IAAI,MAAM,aAAa;AAE/B,MAAI,OAAO,SAAU;AACnB,WAAO;AAET,QAAM,MAAM,QAAQ,SAAS,GAEvB,QADa,UAAU,IAAI,KAAC,gCAAY,KAAK,IAAI,SAAS,KACtC,QAAQ,MAAM,OAClC,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;AACjB,UAAI,GAAG,GAAG,IAAI,IAAI,EAAE,IAAI,UAAU,IAAI;AAAA,EAE1C;AACA,SAAO;AACT;",
5
- "names": []
6
- }
@@ -1,14 +0,0 @@
1
- var __defProp = Object.defineProperty;
2
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
3
- var __getOwnPropNames = Object.getOwnPropertyNames;
4
- var __hasOwnProp = Object.prototype.hasOwnProperty;
5
- var __copyProps = (to, from, except, desc) => {
6
- if (from && typeof from == "object" || typeof from == "function")
7
- for (let key of __getOwnPropNames(from))
8
- !__hasOwnProp.call(to, key) && key !== except && __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
9
- return to;
10
- };
11
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: !0 }), mod);
12
- var createThemeTypes_exports = {};
13
- module.exports = __toCommonJS(createThemeTypes_exports);
14
- //# sourceMappingURL=createThemeTypes.js.map
@@ -1,6 +0,0 @@
1
- {
2
- "version": 3,
3
- "sources": ["../../src/createThemeTypes.tsx"],
4
- "mappings": ";;;;;;;;;;;AAAA;AAAA;",
5
- "names": []
6
- }
@@ -1,29 +0,0 @@
1
- var __defProp = Object.defineProperty;
2
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
3
- var __getOwnPropNames = Object.getOwnPropertyNames;
4
- var __hasOwnProp = Object.prototype.hasOwnProperty;
5
- var __export = (target, all) => {
6
- for (var name in all)
7
- __defProp(target, name, { get: all[name], enumerable: !0 });
8
- }, __copyProps = (to, from, except, desc) => {
9
- if (from && typeof from == "object" || typeof from == "function")
10
- for (let key of __getOwnPropNames(from))
11
- !__hasOwnProp.call(to, key) && key !== except && __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
12
- return to;
13
- };
14
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: !0 }), mod);
15
- var helpers_exports = {};
16
- __export(helpers_exports, {
17
- objectEntries: () => objectEntries,
18
- objectFromEntries: () => objectFromEntries,
19
- objectKeys: () => objectKeys
20
- });
21
- module.exports = __toCommonJS(helpers_exports);
22
- const objectKeys = (obj) => Object.keys(obj);
23
- function objectEntries(obj) {
24
- return Object.entries(obj);
25
- }
26
- function objectFromEntries(arr) {
27
- return Object.fromEntries(arr);
28
- }
29
- //# sourceMappingURL=helpers.js.map
@@ -1,6 +0,0 @@
1
- {
2
- "version": 3,
3
- "sources": ["../../src/helpers.tsx"],
4
- "mappings": ";;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAQO,MAAM,aAAa,CAAmB,QAAW,OAAO,KAAK,GAAG;AAEhE,SAAS,cACd,KACsB;AACtB,SAAO,OAAO,QAAQ,GAAG;AAC3B;AAyBO,SAAS,kBACd,KACwB;AACxB,SAAO,OAAO,YAAY,GAAG;AAC/B;",
5
- "names": []
6
- }
@@ -1,23 +0,0 @@
1
- var __defProp = Object.defineProperty;
2
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
3
- var __getOwnPropNames = Object.getOwnPropertyNames;
4
- var __hasOwnProp = Object.prototype.hasOwnProperty;
5
- var __export = (target, all) => {
6
- for (var name in all)
7
- __defProp(target, name, { get: all[name], enumerable: !0 });
8
- }, __copyProps = (to, from, except, desc) => {
9
- if (from && typeof from == "object" || typeof from == "function")
10
- for (let key of __getOwnPropNames(from))
11
- !__hasOwnProp.call(to, key) && key !== except && __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
12
- return to;
13
- };
14
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: !0 }), mod);
15
- var isMinusZero_exports = {};
16
- __export(isMinusZero_exports, {
17
- isMinusZero: () => isMinusZero
18
- });
19
- module.exports = __toCommonJS(isMinusZero_exports);
20
- function isMinusZero(value) {
21
- return 1 / value === Number.NEGATIVE_INFINITY;
22
- }
23
- //# sourceMappingURL=isMinusZero.js.map
@@ -1,6 +0,0 @@
1
- {
2
- "version": 3,
3
- "sources": ["../../src/isMinusZero.tsx"],
4
- "mappings": ";;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAO,SAAS,YAAY,OAAwB;AAClD,SAAO,IAAI,UAAU,OAAO;AAC9B;",
5
- "names": []
6
- }
package/dist/cjs/masks.js DELETED
@@ -1,98 +0,0 @@
1
- var __defProp = Object.defineProperty;
2
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
3
- var __getOwnPropNames = Object.getOwnPropertyNames;
4
- var __hasOwnProp = Object.prototype.hasOwnProperty;
5
- var __export = (target, all) => {
6
- for (var name in all)
7
- __defProp(target, name, { get: all[name], enumerable: !0 });
8
- }, __copyProps = (to, from, except, desc) => {
9
- if (from && typeof from == "object" || typeof from == "function")
10
- for (let key of __getOwnPropNames(from))
11
- !__hasOwnProp.call(to, key) && key !== except && __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
12
- return to;
13
- };
14
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: !0 }), mod);
15
- var masks_exports = {};
16
- __export(masks_exports, {
17
- createIdentityMask: () => createIdentityMask,
18
- createInverseMask: () => createInverseMask,
19
- createMask: () => createMask,
20
- createShiftMask: () => createShiftMask,
21
- createSoftenMask: () => createSoftenMask,
22
- createStrengthenMask: () => createStrengthenMask,
23
- createWeakenMask: () => createWeakenMask,
24
- skipMask: () => skipMask
25
- });
26
- module.exports = __toCommonJS(masks_exports);
27
- var import_helpers = require("./helpers"), import_isMinusZero = require("./isMinusZero");
28
- const createMask = (createMask2) => typeof createMask2 == "function" ? { name: createMask2.name || "unnamed", mask: createMask2 } : createMask2, skipMask = {
29
- name: "skip-mask",
30
- mask: (template, opts) => {
31
- const { skip } = opts;
32
- return Object.fromEntries(
33
- Object.entries(template).filter(([k]) => !skip || !(k in skip)).map(([k, v]) => [k, applyOverrides(k, v, opts)])
34
- );
35
- }
36
- };
37
- function applyOverrides(key, value, opts) {
38
- let override, strategy = opts.overrideStrategy;
39
- const overrideSwap = opts.overrideSwap?.[key];
40
- if (typeof overrideSwap < "u")
41
- override = overrideSwap, strategy = "swap";
42
- else {
43
- const overrideShift = opts.overrideShift?.[key];
44
- if (typeof overrideShift < "u")
45
- override = overrideShift, strategy = "shift";
46
- else {
47
- const overrideDefault = opts.override?.[key];
48
- typeof overrideDefault < "u" && (override = overrideDefault, strategy = opts.overrideStrategy);
49
- }
50
- }
51
- return typeof override > "u" || typeof override == "string" ? value : strategy === "swap" ? override : value;
52
- }
53
- const createIdentityMask = () => ({
54
- name: "identity-mask",
55
- mask: (template, opts) => skipMask.mask(template, opts)
56
- }), createInverseMask = () => ({
57
- name: "inverse-mask",
58
- mask: (template, opts) => {
59
- const inversed = (0, import_helpers.objectFromEntries)(
60
- (0, import_helpers.objectEntries)(template).map(([k, v]) => [k, -v])
61
- );
62
- return skipMask.mask(inversed, opts);
63
- }
64
- }), createShiftMask = ({ inverse } = {}, defaultOptions) => ({
65
- name: "shift-mask",
66
- mask: (template, opts) => {
67
- const {
68
- override,
69
- overrideStrategy = "shift",
70
- max: maxIn,
71
- palette,
72
- min = 0,
73
- strength = 1
74
- } = { ...defaultOptions, ...opts }, values = Object.entries(template), max = maxIn ?? (palette ? Object.values(palette).length - 1 : Number.POSITIVE_INFINITY), out = {};
75
- for (const [key, value] of values) {
76
- if (typeof value == "string") continue;
77
- if (typeof override?.[key] == "number") {
78
- const overrideVal = override[key];
79
- out[key] = overrideStrategy === "shift" ? value + overrideVal : overrideVal;
80
- continue;
81
- }
82
- if (typeof override?.[key] == "string") {
83
- out[key] = override[key];
84
- continue;
85
- }
86
- const isPositive = value === 0 ? !(0, import_isMinusZero.isMinusZero)(value) : value >= 0, direction = isPositive ? 1 : -1, invert = inverse ? -1 : 1, next = value + strength * direction * invert, clamped = isPositive ? Math.max(min, Math.min(max, next)) : Math.min(-min, Math.max(-max, next));
87
- out[key] = clamped;
88
- }
89
- return skipMask.mask(out, opts);
90
- }
91
- }), createWeakenMask = (defaultOptions) => ({
92
- name: "soften-mask",
93
- mask: createShiftMask({}, defaultOptions).mask
94
- }), createSoftenMask = createWeakenMask, createStrengthenMask = (defaultOptions) => ({
95
- name: "strengthen-mask",
96
- mask: createShiftMask({ inverse: !0 }, defaultOptions).mask
97
- });
98
- //# sourceMappingURL=masks.js.map
@@ -1,6 +0,0 @@
1
- {
2
- "version": 3,
3
- "sources": ["../../src/masks.tsx"],
4
- "mappings": ";;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AACA,qBAAiD,sBACjD,qBAA4B;AAErB,MAAM,aAAa,CACxBA,gBAEA,OAAOA,eAAe,aAClB,EAAE,MAAMA,YAAW,QAAQ,WAAW,MAAMA,YAAW,IACvDA,aAEO,WAAuB;AAAA,EAClC,MAAM;AAAA,EACN,MAAM,CAAC,UAAU,SAAS;AACxB,UAAM,EAAE,KAAK,IAAI;AAOjB,WANe,OAAO;AAAA,MACpB,OAAO,QAAQ,QAAQ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WAAW;AAAA,IACb,IAAI,EAAE,GAAG,gBAAgB,GAAG,KAAK,GAC3B,SAAS,OAAO,QAAQ,QAAQ,GAChC,MACJ,UAAU,UAAU,OAAO,OAAO,OAAO,EAAE,SAAS,IAAI,OAAO,oBAC3D,MAAM,CAAC;AACb,eAAW,CAAC,KAAK,KAAK,KAAK,QAAQ;AACjC,UAAI,OAAO,SAAU,SAAU;AAC/B,UAAI,OAAO,WAAW,GAAG,KAAM,UAAU;AACvC,cAAM,cAAc,SAAS,GAAG;AAChC,YAAI,GAAG,IAAI,qBAAqB,UAAU,QAAQ,cAAc;AAChE;AAAA,MACF;AACA,UAAI,OAAO,WAAW,GAAG,KAAM,UAAU;AACvC,YAAI,GAAG,IAAI,SAAS,GAAG;AACvB;AAAA,MACF;AACA,YAAM,aAAa,UAAU,IAAI,KAAC,gCAAY,KAAK,IAAI,SAAS,GAC1D,YAAY,aAAa,IAAI,IAC7B,SAAS,UAAU,KAAK,GACxB,OAAO,QAAQ,WAAW,YAAY,QACtC,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;AAGA,WADgB,SAAS,KAAK,KAAK,IAAI;AAAA,EAEzC;AACF,IAIW,mBAAmB,CAAC,oBAA8C;AAAA,EAC7E,MAAM;AAAA,EACN,MAAM,gBAAgB,CAAC,GAAG,cAAc,EAAE;AAC5C,IAEa,mBACX,kBAEW,uBAAuB,CAAC,oBAA8C;AAAA,EACjF,MAAM;AAAA,EACN,MAAM,gBAAgB,EAAE,SAAS,GAAK,GAAG,cAAc,EAAE;AAC3D;",
5
- "names": ["createMask"]
6
- }
package/dist/cjs/tests.js DELETED
@@ -1,12 +0,0 @@
1
- var import_applyMask = require("./applyMask"), import_createTheme = require("./createTheme"), import_masks = require("./masks");
2
- if (process.env.NODE_ENV === "development") {
3
- const palette = ["0", "1", "2", "3", "-3", "-2", "-1", "-0"], template = { bg: 1, fg: -1 }, stongerMask = (0, import_masks.createStrengthenMask)(), weakerMask = (0, import_masks.createWeakenMask)(), theme = (0, import_createTheme.createTheme)(palette, template);
4
- if (theme.bg !== "1" || theme.fg !== "-1") throw "\u274C";
5
- const str = (0, import_applyMask.applyMask)(theme, stongerMask);
6
- if (str.bg !== "0" || str.fg !== "-0") throw "\u274C";
7
- const weak = (0, import_applyMask.applyMask)(theme, weakerMask);
8
- if (weak.bg !== "2" || weak.fg !== "-2") throw "\u274C";
9
- const weak2 = (0, import_applyMask.applyMask)(theme, weakerMask, { strength: 2 });
10
- if (weak2.bg !== "3" || weak2.fg !== "-3") throw "\u274C";
11
- }
12
- //# sourceMappingURL=tests.js.map
@@ -1,6 +0,0 @@
1
- {
2
- "version": 3,
3
- "sources": ["../../src/tests.tsx"],
4
- "mappings": "AAAA,uBAA0B,wBAC1B,qBAA4B,0BAC5B,eAAuD;AAGvD,IAAI,QAAQ,IAAI,aAAa,eAAe;AAC1C,QAAM,UAAU,CAAC,KAAK,KAAK,KAAK,KAAK,MAAM,MAAM,MAAM,IAAI,GACrD,WAAW,EAAE,IAAI,GAAG,IAAI,GAAG,GAE3B,kBAAc,mCAAqB,GACnC,iBAAa,+BAAiB,GAE9B,YAAQ,gCAAY,SAAS,QAAQ;AAE3C,MADI,MAAM,OAAO,OACb,MAAM,OAAO,KAAM,OAAM;AAE7B,QAAM,UAAM,4BAAU,OAAO,WAAW;AAExC,MADI,IAAI,OAAO,OACX,IAAI,OAAO,KAAM,OAAM;AAE3B,QAAM,WAAO,4BAAU,OAAO,UAAU;AAExC,MADI,KAAK,OAAO,OACZ,KAAK,OAAO,KAAM,OAAM;AAE5B,QAAM,YAAQ,4BAAU,OAAO,YAAY,EAAE,UAAU,EAAE,CAAC;AAE1D,MADI,MAAM,OAAO,OACb,MAAM,OAAO,KAAM,OAAM;AAC/B;",
5
- "names": []
6
- }
@@ -1,28 +0,0 @@
1
- var __defProp = Object.defineProperty;
2
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
3
- var __getOwnPropNames = Object.getOwnPropertyNames;
4
- var __hasOwnProp = Object.prototype.hasOwnProperty;
5
- var __export = (target, all) => {
6
- for (var name in all)
7
- __defProp(target, name, { get: all[name], enumerable: !0 });
8
- }, __copyProps = (to, from, except, desc) => {
9
- if (from && typeof from == "object" || typeof from == "function")
10
- for (let key of __getOwnPropNames(from))
11
- !__hasOwnProp.call(to, key) && key !== except && __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
12
- return to;
13
- };
14
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: !0 }), mod);
15
- var themeInfo_exports = {};
16
- __export(themeInfo_exports, {
17
- getThemeInfo: () => getThemeInfo,
18
- setThemeInfo: () => setThemeInfo
19
- });
20
- module.exports = __toCommonJS(themeInfo_exports);
21
- const THEME_INFO = /* @__PURE__ */ new Map(), getThemeInfo = (theme, name) => THEME_INFO.get(name || JSON.stringify(theme)), setThemeInfo = (theme, info) => {
22
- const next = {
23
- ...info,
24
- cache: /* @__PURE__ */ new Map()
25
- };
26
- THEME_INFO.set(info.name || JSON.stringify(theme), next), THEME_INFO.set(JSON.stringify(info.definition), next);
27
- };
28
- //# sourceMappingURL=themeInfo.js.map
@@ -1,6 +0,0 @@
1
- {
2
- "version": 3,
3
- "sources": ["../../src/themeInfo.tsx"],
4
- "mappings": ";;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAcA,MAAM,aAAa,oBAAI,IAAuB,GAEjC,eAAe,CAC1B,OACA,SAEO,WAAW,IAAI,QAAQ,KAAK,UAAU,KAAK,CAAC,GAGxC,eAAe,CAC1B,OACA,SAGS;AACT,QAAM,OAAO;AAAA,IACX,GAAG;AAAA,IACH,OAAO,oBAAI,IAAI;AAAA,EACjB;AACA,aAAW,IAAI,KAAK,QAAQ,KAAK,UAAU,KAAK,GAAG,IAAI,GACvD,WAAW,IAAI,KAAK,UAAU,KAAK,UAAU,GAAG,IAAI;AACtD;",
5
- "names": []
6
- }
@@ -1,40 +0,0 @@
1
- import { createTheme } from "./createTheme";
2
- import { getThemeInfo, setThemeInfo } from "./themeInfo";
3
- function applyMask(theme, mask, options = {}, parentName, nextName) {
4
- const info = getThemeInfo(theme, parentName);
5
- if (!info)
6
- throw new Error(
7
- process.env.NODE_ENV !== "production" ? "No info found for theme, you must pass the theme created by createThemeFromPalette directly to extendTheme" : "\u274C Err2"
8
- );
9
- const next = applyMaskStateless(info, mask, options, parentName);
10
- return setThemeInfo(next.theme, {
11
- definition: next.definition,
12
- palette: info.palette,
13
- name: nextName
14
- }), next.theme;
15
- }
16
- function applyMaskStateless(info, mask, options = {}, parentName) {
17
- const skip = {
18
- ...options.skip
19
- };
20
- if (info.options?.nonInheritedValues)
21
- for (const key in info.options.nonInheritedValues)
22
- skip[key] = 1;
23
- const maskOptions = {
24
- parentName,
25
- palette: info.palette,
26
- ...options,
27
- skip
28
- }, template = mask.mask(info.definition, maskOptions), theme = createTheme(info.palette, template);
29
- return {
30
- ...info,
31
- cache: /* @__PURE__ */ new Map(),
32
- definition: template,
33
- theme
34
- };
35
- }
36
- export {
37
- applyMask,
38
- applyMaskStateless
39
- };
40
- //# sourceMappingURL=applyMask.js.map
@@ -1,6 +0,0 @@
1
- {
2
- "version": 3,
3
- "sources": ["../../src/applyMask.tsx"],
4
- "mappings": "AAAA,SAAS,mBAAmB;AAG5B,SAAS,cAAc,oBAAoB;AAEpC,SAAS,UACd,OACA,MACA,UAAuB,CAAC,GACxB,YACA,UACO;AACP,QAAM,OAAO,aAAa,OAAO,UAAU;AAC3C,MAAI,CAAC;AACH,UAAM,IAAI;AAAA,MACR,QAAQ,IAAI,aAAa,eACrB,+GACA;AAAA,IACN;AAGF,QAAM,OAAO,mBAAmB,MAAM,MAAM,SAAS,UAAU;AAE/D,sBAAa,KAAK,OAAO;AAAA,IACvB,YAAY,KAAK;AAAA,IACjB,SAAS,KAAK;AAAA,IACd,MAAM;AAAA,EACR,CAAC,GAEM,KAAK;AACd;AAEO,SAAS,mBACd,MACA,MACA,UAAuB,CAAC,GACxB,YAGA;AACA,QAAM,OAAO;AAAA,IACX,GAAG,QAAQ;AAAA,EACb;AAGA,MAAI,KAAK,SAAS;AAChB,eAAW,OAAO,KAAK,QAAQ;AAC7B,WAAK,GAAG,IAAI;AAKhB,QAAM,cAAc;AAAA,IAClB;AAAA,IACA,SAAS,KAAK;AAAA,IACd,GAAG;AAAA,IACH;AAAA,EACF,GAEM,WAAW,KAAK,KAAK,KAAK,YAAY,WAAW,GACjD,QAAQ,YAAY,KAAK,SAAS,QAAQ;AAEhD,SAAO;AAAA,IACL,GAAG;AAAA,IACH,OAAO,oBAAI,IAAI;AAAA,IACf,YAAY;AAAA,IACZ;AAAA,EACF;AACF;",
5
- "names": []
6
- }
@@ -1,25 +0,0 @@
1
- import { applyMaskStateless } from "./applyMask";
2
- import { getThemeInfo } from "./themeInfo";
3
- const combineMasks = (...masks) => ({
4
- name: "combine-mask",
5
- mask: (template, opts) => {
6
- let current = getThemeInfo(template, opts.parentName), theme;
7
- for (const mask2 of masks) {
8
- if (!current)
9
- throw new Error(
10
- `Nothing returned from mask: ${current}, for template: ${template} and mask: ${mask2.toString()}, given opts ${JSON.stringify(
11
- opts,
12
- null,
13
- 2
14
- )}`
15
- );
16
- const next = applyMaskStateless(current, mask2, opts);
17
- current = next, theme = next.theme;
18
- }
19
- return theme;
20
- }
21
- });
22
- export {
23
- combineMasks
24
- };
25
- //# sourceMappingURL=combineMasks.js.map
@@ -1,6 +0,0 @@
1
- {
2
- "version": 3,
3
- "sources": ["../../src/combineMasks.tsx"],
4
- "mappings": "AAAA,SAAS,0BAA0B;AAEnC,SAAS,oBAAoB;AAEtB,MAAM,eAAe,IAAI,WACL;AAAA,EACvB,MAAM;AAAA,EACN,MAAM,CAAC,UAAU,SAAS;AACxB,QAAI,UAAU,aAAa,UAAU,KAAK,UAAU,GAChD;AACJ,eAAWA,SAAQ,OAAO;AACxB,UAAI,CAAC;AACH,cAAM,IAAI;AAAA,UACR,+BAA+B,OAAO,mBAAmB,QAAQ,cAAcA,MAAK,SAAS,CAAC,gBAAgB,KAAK;AAAA,YACjH;AAAA,YACA;AAAA,YACA;AAAA,UACF,CAAC;AAAA,QACH;AAEF,YAAM,OAAO,mBAAmB,SAASA,OAAM,IAAI;AACnD,gBAAU,MACV,QAAQ,KAAK;AAAA,IACf;AACA,WAAO;AAAA,EACT;AACF;",
5
- "names": ["mask"]
6
- }
@@ -1,54 +0,0 @@
1
- import { isMinusZero } from "./isMinusZero";
2
- import { setThemeInfo } from "./themeInfo";
3
- const identityCache = /* @__PURE__ */ new Map();
4
- function createThemeWithPalettes(palettes, defaultPalette, definition, options, name, skipCache = !1) {
5
- if (!palettes[defaultPalette])
6
- throw new Error(`No palette: ${defaultPalette}`);
7
- const newDef = { ...definition };
8
- for (const key in definition) {
9
- let val = definition[key];
10
- if (typeof val == "string" && val[0] === "$") {
11
- const [altPaletteName$, altPaletteIndex] = val.split("."), altPaletteName = altPaletteName$.slice(1), parentName = defaultPalette.split("_")[0], altPalette = palettes[altPaletteName] || palettes[`${parentName}_${altPaletteName}`];
12
- if (altPalette) {
13
- const next = getValue(altPalette, +altPaletteIndex);
14
- typeof next < "u" && (newDef[key] = next);
15
- }
16
- }
17
- }
18
- return createTheme(palettes[defaultPalette], newDef, options, name, skipCache);
19
- }
20
- function createTheme(palette, definition, options, name, skipCache = !1) {
21
- const cacheKey = skipCache ? "" : JSON.stringify([name, palette, definition, options]);
22
- if (!skipCache && identityCache.has(cacheKey))
23
- return identityCache.get(cacheKey);
24
- const theme = {
25
- ...Object.fromEntries(
26
- Object.entries(definition).map(([key, offset]) => [key, getValue(palette, offset)])
27
- ),
28
- ...options?.nonInheritedValues
29
- };
30
- return setThemeInfo(theme, { palette, definition, options, name }), cacheKey && identityCache.set(cacheKey, theme), theme;
31
- }
32
- const getValue = (palette, value) => {
33
- if (!palette)
34
- throw new Error("No palette!");
35
- if (typeof value == "string")
36
- return value;
37
- const max = palette.length - 1, next = (value === 0 ? !isMinusZero(value) : value >= 0) ? value : max + value, index = Math.min(Math.max(0, next), max);
38
- return palette[index];
39
- };
40
- function addChildren(themes, getChildren) {
41
- const out = { ...themes };
42
- for (const key in themes) {
43
- const subThemes = getChildren(key, themes[key]);
44
- for (const sKey in subThemes)
45
- out[`${key}_${sKey}`] = subThemes[sKey];
46
- }
47
- return out;
48
- }
49
- export {
50
- addChildren,
51
- createTheme,
52
- createThemeWithPalettes
53
- };
54
- //# sourceMappingURL=createTheme.js.map
@@ -1,6 +0,0 @@
1
- {
2
- "version": 3,
3
- "sources": ["../../src/createTheme.tsx"],
4
- "mappings": "AAMA,SAAS,mBAAmB;AAC5B,SAAS,oBAAoB;AAE7B,MAAM,gBAAgB,oBAAI,IAAI;AAEvB,SAAS,wBAId,UACA,gBACA,YACA,SACA,MACA,YAAY,IAGZ;AACA,MAAI,CAAC,SAAS,cAAc;AAC1B,UAAM,IAAI,MAAM,eAAe,cAAc,EAAE;AAEjD,QAAM,SAAS,EAAE,GAAG,WAAW;AAC/B,aAAW,OAAO,YAAY;AAC5B,QAAI,MAAM,WAAW,GAAG;AACxB,QAAI,OAAO,OAAQ,YAAY,IAAI,CAAC,MAAM,KAAK;AAC7C,YAAM,CAAC,iBAAiB,eAAe,IAAI,IAAI,MAAM,GAAG,GAClD,iBAAiB,gBAAgB,MAAM,CAAC,GACxC,aAAa,eAAe,MAAM,GAAG,EAAE,CAAC,GACxC,aACJ,SAAS,cAAc,KAAK,SAAS,GAAG,UAAU,IAAI,cAAc,EAAE;AAExE,UAAI,YAAY;AACd,cAAM,OAAO,SAAS,YAAY,CAAC,eAAe;AAClD,QAAI,OAAO,OAAS,QAClB,OAAO,GAAG,IAAI;AAAA,MAElB;AAAA,IACF;AAAA,EACF;AAEA,SAAO,YAAY,SAAS,cAAc,GAAG,QAAQ,SAAS,MAA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
@@ -1,13 +0,0 @@
1
- const objectKeys = (obj) => Object.keys(obj);
2
- function objectEntries(obj) {
3
- return Object.entries(obj);
4
- }
5
- function objectFromEntries(arr) {
6
- return Object.fromEntries(arr);
7
- }
8
- export {
9
- objectEntries,
10
- objectFromEntries,
11
- objectKeys
12
- };
13
- //# sourceMappingURL=helpers.js.map
@@ -1,6 +0,0 @@
1
- {
2
- "version": 3,
3
- "sources": ["../../src/helpers.tsx"],
4
- "mappings": "AAQO,MAAM,aAAa,CAAmB,QAAW,OAAO,KAAK,GAAG;AAEhE,SAAS,cACd,KACsB;AACtB,SAAO,OAAO,QAAQ,GAAG;AAC3B;AAyBO,SAAS,kBACd,KACwB;AACxB,SAAO,OAAO,YAAY,GAAG;AAC/B;",
5
- "names": []
6
- }
@@ -1,7 +0,0 @@
1
- function isMinusZero(value) {
2
- return 1 / value === Number.NEGATIVE_INFINITY;
3
- }
4
- export {
5
- isMinusZero
6
- };
7
- //# sourceMappingURL=isMinusZero.js.map
@@ -1,6 +0,0 @@
1
- {
2
- "version": 3,
3
- "sources": ["../../src/isMinusZero.tsx"],
4
- "mappings": "AAAO,SAAS,YAAY,OAAwB;AAClD,SAAO,IAAI,UAAU,OAAO;AAC9B;",
5
- "names": []
6
- }
package/dist/esm/masks.js DELETED
@@ -1,83 +0,0 @@
1
- import { objectEntries, objectFromEntries } from "./helpers";
2
- import { isMinusZero } from "./isMinusZero";
3
- const createMask = (createMask2) => typeof createMask2 == "function" ? { name: createMask2.name || "unnamed", mask: createMask2 } : createMask2, skipMask = {
4
- name: "skip-mask",
5
- mask: (template, opts) => {
6
- const { skip } = opts;
7
- return Object.fromEntries(
8
- Object.entries(template).filter(([k]) => !skip || !(k in skip)).map(([k, v]) => [k, applyOverrides(k, v, opts)])
9
- );
10
- }
11
- };
12
- function applyOverrides(key, value, opts) {
13
- let override, strategy = opts.overrideStrategy;
14
- const overrideSwap = opts.overrideSwap?.[key];
15
- if (typeof overrideSwap < "u")
16
- override = overrideSwap, strategy = "swap";
17
- else {
18
- const overrideShift = opts.overrideShift?.[key];
19
- if (typeof overrideShift < "u")
20
- override = overrideShift, strategy = "shift";
21
- else {
22
- const overrideDefault = opts.override?.[key];
23
- typeof overrideDefault < "u" && (override = overrideDefault, strategy = opts.overrideStrategy);
24
- }
25
- }
26
- return typeof override > "u" || typeof override == "string" ? value : strategy === "swap" ? override : value;
27
- }
28
- const createIdentityMask = () => ({
29
- name: "identity-mask",
30
- mask: (template, opts) => skipMask.mask(template, opts)
31
- }), createInverseMask = () => ({
32
- name: "inverse-mask",
33
- mask: (template, opts) => {
34
- const inversed = objectFromEntries(
35
- objectEntries(template).map(([k, v]) => [k, -v])
36
- );
37
- return skipMask.mask(inversed, opts);
38
- }
39
- }), createShiftMask = ({ inverse } = {}, defaultOptions) => ({
40
- name: "shift-mask",
41
- mask: (template, opts) => {
42
- const {
43
- override,
44
- overrideStrategy = "shift",
45
- max: maxIn,
46
- palette,
47
- min = 0,
48
- strength = 1
49
- } = { ...defaultOptions, ...opts }, values = Object.entries(template), max = maxIn ?? (palette ? Object.values(palette).length - 1 : Number.POSITIVE_INFINITY), out = {};
50
- for (const [key, value] of values) {
51
- if (typeof value == "string") continue;
52
- if (typeof override?.[key] == "number") {
53
- const overrideVal = override[key];
54
- out[key] = overrideStrategy === "shift" ? value + overrideVal : overrideVal;
55
- continue;
56
- }
57
- if (typeof override?.[key] == "string") {
58
- out[key] = override[key];
59
- continue;
60
- }
61
- const isPositive = value === 0 ? !isMinusZero(value) : value >= 0, direction = isPositive ? 1 : -1, invert = inverse ? -1 : 1, next = value + strength * direction * invert, clamped = isPositive ? Math.max(min, Math.min(max, next)) : Math.min(-min, Math.max(-max, next));
62
- out[key] = clamped;
63
- }
64
- return skipMask.mask(out, opts);
65
- }
66
- }), createWeakenMask = (defaultOptions) => ({
67
- name: "soften-mask",
68
- mask: createShiftMask({}, defaultOptions).mask
69
- }), createSoftenMask = createWeakenMask, createStrengthenMask = (defaultOptions) => ({
70
- name: "strengthen-mask",
71
- mask: createShiftMask({ inverse: !0 }, defaultOptions).mask
72
- });
73
- export {
74
- createIdentityMask,
75
- createInverseMask,
76
- createMask,
77
- createShiftMask,
78
- createSoftenMask,
79
- createStrengthenMask,
80
- createWeakenMask,
81
- skipMask
82
- };
83
- //# sourceMappingURL=masks.js.map
@@ -1,6 +0,0 @@
1
- {
2
- "version": 3,
3
- "sources": ["../../src/masks.tsx"],
4
- "mappings": "AACA,SAAS,eAAe,yBAAyB;AACjD,SAAS,mBAAmB;AAErB,MAAM,aAAa,CACxBA,gBAEA,OAAOA,eAAe,aAClB,EAAE,MAAMA,YAAW,QAAQ,WAAW,MAAMA,YAAW,IACvDA,aAEO,WAAuB;AAAA,EAClC,MAAM;AAAA,EACN,MAAM,CAAC,UAAU,SAAS;AACxB,UAAM,EAAE,KAAK,IAAI;AAOjB,WANe,OAAO;AAAA,MACpB,OAAO,QAAQ,QAAQ,EACpB,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,QAAQ,EAAE,KAAK,KAAK,EACrC,IAAI,CAAC,CAAC,GAAG,CAAC,MAAM,CAAC,GAAG,eAAe,GAAG,GAAG,IAAI,CAAC,CAAC;AAAA,IACpD;AAAA,EAGF;AACF;AAEA,SAAS,eAAe,KAAa,OAAwB,MAAmB;AAC9E,MAAI,UACA,WAAW,KAAK;AAEpB,QAAM,eAAe,KAAK,eAAe,GAAG;AAC5C,MAAI,OAAO,eAAiB;AAC1B,eAAW,cACX,WAAW;AAAA,OACN;AACL,UAAM,gBAAgB,KAAK,gBAAgB,GAAG;AAC9C,QAAI,OAAO,gBAAkB;AAC3B,iBAAW,eACX,WAAW;AAAA,SACN;AACL,YAAM,kBAAkB,KAAK,WAAW,GAAG;AAC3C,MAAI,OAAO,kBAAoB,QAC7B,WAAW,iBACX,WAAW,KAAK;AAAA,IAEpB;AAAA,EACF;AAGA,SADI,OAAO,WAAa,OACpB,OAAO,YAAa,WAAiB,QAErC,aAAa,SACR,WAGF;AACT;AAEO,MAA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,IAAI,KAAK,IAAI,CAAC,IACjC,KAAK,IAAI,CAAC,KAAK,KAAK,IAAI,CAAC,KAAK,IAAI,CAAC;AAEvC,UAAI,GAAG,IAAI;AAAA,IACb;AAGA,WADgB,SAAS,KAAK,KAAK,IAAI;AAAA,EAEzC;AACF,IAIW,mBAAmB,CAAC,oBAA8C;AAAA,EAC7E,MAAM;AAAA,EACN,MAAM,gBAAgB,CAAC,GAAG,cAAc,EAAE;AAC5C,IAEa,mBACX,kBAEW,uBAAuB,CAAC,oBAA8C;AAAA,EACjF,MAAM;AAAA,EACN,MAAM,gBAAgB,EAAE,SAAS,GAAK,GAAG,cAAc,EAAE;AAC3D;",
5
- "names": ["createMask"]
6
- }
package/dist/esm/tests.js DELETED
@@ -1,14 +0,0 @@
1
- import { applyMask } from "./applyMask";
2
- import { createTheme } from "./createTheme";
3
- import { createStrengthenMask, createWeakenMask } from "./masks";
4
- if (process.env.NODE_ENV === "development") {
5
- const palette = ["0", "1", "2", "3", "-3", "-2", "-1", "-0"], template = { bg: 1, fg: -1 }, stongerMask = createStrengthenMask(), weakerMask = createWeakenMask(), theme = createTheme(palette, template);
6
- if (theme.bg !== "1" || theme.fg !== "-1") throw "\u274C";
7
- const str = applyMask(theme, stongerMask);
8
- if (str.bg !== "0" || str.fg !== "-0") throw "\u274C";
9
- const weak = applyMask(theme, weakerMask);
10
- if (weak.bg !== "2" || weak.fg !== "-2") throw "\u274C";
11
- const weak2 = applyMask(theme, weakerMask, { strength: 2 });
12
- if (weak2.bg !== "3" || weak2.fg !== "-3") throw "\u274C";
13
- }
14
- //# sourceMappingURL=tests.js.map
@@ -1,6 +0,0 @@
1
- {
2
- "version": 3,
3
- "sources": ["../../src/tests.tsx"],
4
- "mappings": "AAAA,SAAS,iBAAiB;AAC1B,SAAS,mBAAmB;AAC5B,SAAS,sBAAsB,wBAAwB;AAGvD,IAAI,QAAQ,IAAI,aAAa,eAAe;AAC1C,QAAM,UAAU,CAAC,KAAK,KAAK,KAAK,KAAK,MAAM,MAAM,MAAM,IAAI,GACrD,WAAW,EAAE,IAAI,GAAG,IAAI,GAAG,GAE3B,cAAc,qBAAqB,GACnC,aAAa,iBAAiB,GAE9B,QAAQ,YAAY,SAAS,QAAQ;AAE3C,MADI,MAAM,OAAO,OACb,MAAM,OAAO,KAAM,OAAM;AAE7B,QAAM,MAAM,UAAU,OAAO,WAAW;AAExC,MADI,IAAI,OAAO,OACX,IAAI,OAAO,KAAM,OAAM;AAE3B,QAAM,OAAO,UAAU,OAAO,UAAU;AAExC,MADI,KAAK,OAAO,OACZ,KAAK,OAAO,KAAM,OAAM;AAE5B,QAAM,QAAQ,UAAU,OAAO,YAAY,EAAE,UAAU,EAAE,CAAC;AAE1D,MADI,MAAM,OAAO,OACb,MAAM,OAAO,KAAM,OAAM;AAC/B;",
5
- "names": []
6
- }
@@ -1,12 +0,0 @@
1
- const THEME_INFO = /* @__PURE__ */ new Map(), getThemeInfo = (theme, name) => THEME_INFO.get(name || JSON.stringify(theme)), setThemeInfo = (theme, info) => {
2
- const next = {
3
- ...info,
4
- cache: /* @__PURE__ */ new Map()
5
- };
6
- THEME_INFO.set(info.name || JSON.stringify(theme), next), THEME_INFO.set(JSON.stringify(info.definition), next);
7
- };
8
- export {
9
- getThemeInfo,
10
- setThemeInfo
11
- };
12
- //# sourceMappingURL=themeInfo.js.map
@@ -1,6 +0,0 @@
1
- {
2
- "version": 3,
3
- "sources": ["../../src/themeInfo.tsx"],
4
- "mappings": "AAcA,MAAM,aAAa,oBAAI,IAAuB,GAEjC,eAAe,CAC1B,OACA,SAEO,WAAW,IAAI,QAAQ,KAAK,UAAU,KAAK,CAAC,GAGxC,eAAe,CAC1B,OACA,SAGS;AACT,QAAM,OAAO;AAAA,IACX,GAAG;AAAA,IACH,OAAO,oBAAI,IAAI;AAAA,EACjB;AACA,aAAW,IAAI,KAAK,QAAQ,KAAK,UAAU,KAAK,GAAG,IAAI,GACvD,WAAW,IAAI,KAAK,UAAU,KAAK,UAAU,GAAG,IAAI;AACtD;",
5
- "names": []
6
- }