@tamagui/create-theme 3.0.0-beta.1604.1 → 3.0.0-beta.1670.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/createThemes.cjs +5 -1
- package/dist/cjs/createThemes.native.cjs +6 -2
- package/dist/cjs/createThemes.native.js +6 -2
- package/dist/cjs/createThemes.native.js.map +1 -1
- package/dist/esm/createThemes.mjs +5 -1
- package/dist/esm/createThemes.mjs.map +1 -1
- package/dist/esm/createThemes.native.js +6 -2
- package/dist/esm/createThemes.native.js.map +1 -1
- package/package.json +3 -3
- package/src/createThemes.tsx +12 -3
- package/types/createThemes.d.ts.map +1 -1
|
@@ -78,7 +78,11 @@ function createThemes(tokens, tree, options) {
|
|
|
78
78
|
}
|
|
79
79
|
throw new Error(`Invalid color value "${value}" for theme "${name}" key "${key}".${nearest ? ` Did you mean token "${nearest}"?` : ""}`);
|
|
80
80
|
}
|
|
81
|
-
const
|
|
81
|
+
const scheme = recipe.scheme;
|
|
82
|
+
if (scheme === "light" || scheme === "dark") {
|
|
83
|
+
Object.defineProperty(resolved, /* @__PURE__ */ Symbol.for("tamagui.theme.scheme"), { value: scheme });
|
|
84
|
+
}
|
|
85
|
+
const identity = JSON.stringify([scheme === "light" || scheme === "dark" ? scheme : void 0, Object.keys(resolved).sort().map((key) => [key, resolved[key]])]);
|
|
82
86
|
themes[name] = deduped.get(identity) || resolved;
|
|
83
87
|
deduped.set(identity, themes[name]);
|
|
84
88
|
const childSets = [inheritedChildren, children];
|
|
@@ -85,9 +85,13 @@ function createThemes(tokens, tree, options) {
|
|
|
85
85
|
}
|
|
86
86
|
throw new Error(`Invalid color value "${value}" for theme "${name}" key "${key}".${nearest ? ` Did you mean token "${nearest}"?` : ""}`);
|
|
87
87
|
}
|
|
88
|
-
var
|
|
88
|
+
var scheme = recipe.scheme;
|
|
89
|
+
if (scheme === "light" || scheme === "dark") {
|
|
90
|
+
Object.defineProperty(resolved, /* @__PURE__ */ Symbol.for("tamagui.theme.scheme"), { value: scheme });
|
|
91
|
+
}
|
|
92
|
+
var identity = JSON.stringify([scheme === "light" || scheme === "dark" ? scheme : void 0, Object.keys(resolved).sort().map(function(key2) {
|
|
89
93
|
return [key2, resolved[key2]];
|
|
90
|
-
}));
|
|
94
|
+
})]);
|
|
91
95
|
themes[name] = deduped.get(identity) || resolved;
|
|
92
96
|
deduped.set(identity, themes[name]);
|
|
93
97
|
var childSets = [inheritedChildren, children];
|
|
@@ -85,9 +85,13 @@ function createThemes(tokens, tree, options) {
|
|
|
85
85
|
}
|
|
86
86
|
throw new Error(`Invalid color value "${value}" for theme "${name}" key "${key}".${nearest ? ` Did you mean token "${nearest}"?` : ""}`);
|
|
87
87
|
}
|
|
88
|
-
var
|
|
88
|
+
var scheme = recipe.scheme;
|
|
89
|
+
if (scheme === "light" || scheme === "dark") {
|
|
90
|
+
Object.defineProperty(resolved, /* @__PURE__ */ Symbol.for("tamagui.theme.scheme"), { value: scheme });
|
|
91
|
+
}
|
|
92
|
+
var identity = JSON.stringify([scheme === "light" || scheme === "dark" ? scheme : void 0, Object.keys(resolved).sort().map(function(key2) {
|
|
89
93
|
return [key2, resolved[key2]];
|
|
90
|
-
}));
|
|
94
|
+
})]);
|
|
91
95
|
themes[name] = deduped.get(identity) || resolved;
|
|
92
96
|
deduped.set(identity, themes[name]);
|
|
93
97
|
var childSets = [inheritedChildren, children];
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"createThemes.native.js","names":[],"sources":["cjs/createThemes.native.js"],"sourcesContent":["\"use strict\";\nvar __defProp = Object.defineProperty;\nvar __getOwnPropDesc = Object.getOwnPropertyDescriptor;\nvar __getOwnPropNames = Object.getOwnPropertyNames;\nvar __hasOwnProp = Object.prototype.hasOwnProperty;\nvar __export = (target, all) => {\n for (var name in all)\n __defProp(target, name, { get: all[name], enumerable: true });\n};\nvar __copyProps = (to, from, except, desc) => {\n if (from && typeof from === \"object\" || typeof from === \"function\") {\n for (let key of __getOwnPropNames(from))\n if (!__hasOwnProp.call(to, key) && key !== except)\n __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });\n }\n return to;\n};\nvar __toCommonJS = (mod) => __copyProps(__defProp({}, \"__esModule\", { value: true }), mod);\nvar createThemes_exports = {};\n__export(createThemes_exports, {\n createThemes: () => createThemes\n});\nmodule.exports = __toCommonJS(createThemes_exports);\nfunction createThemes(tokens, tree, options) {\n var rootKeys = Object.keys(tree).filter(function(key) {\n return key !== \"children\";\n });\n if (rootKeys.length !== 2 || !(\"light\" in tree) || !(\"dark\" in tree)) {\n throw new Error('createThemes tree must have exactly the roots \"light\" and \"dark\"');\n }\n var themes = {};\n var deduped = /* @__PURE__ */ new Map();\n var add = function(name, definition, parent, inheritedChildren) {\n var _options_getTheme;\n var resolvedDefinition = typeof definition === \"function\" ? definition({\n parent\n }) : definition;\n if (resolvedDefinition === null) return;\n var { values, children, ...recipeFields } = resolvedDefinition;\n var recipe = {\n ...parent,\n ...recipeFields\n };\n var unresolved = {\n ...options === null || options === void 0 ? void 0 : (_options_getTheme = options.getTheme) === null || _options_getTheme === void 0 ? void 0 : _options_getTheme.call(options, {\n recipe,\n name,\n tokens\n }),\n ...values\n };\n var resolved = {};\n for (var key in unresolved) {\n var value = unresolved[key];\n var token = tokens.color[value];\n if (token !== void 0) {\n resolved[key] = token;\n continue;\n }\n var isColor = value === \"transparent\" || /^#(?:[\\da-f]{3,4}|[\\da-f]{6}|[\\da-f]{8})$/i.test(value) || /^(?:rgb|rgba|hsl|hsla)\\(\\s*[^)]+\\)$/i.test(value);\n if (isColor) {\n resolved[key] = value;\n continue;\n }\n var nearest = \"\";\n var nearestDistance = Number.POSITIVE_INFINITY;\n for (var tokenName in tokens.color) {\n var previous = Array.from({\n length: tokenName.length + 1\n }, function(_, index) {\n return index;\n });\n for (var valueIndex = 0; valueIndex < value.length; valueIndex++) {\n var diagonal = previous[0];\n previous[0] = valueIndex + 1;\n for (var tokenIndex = 0; tokenIndex < tokenName.length; tokenIndex++) {\n var above = previous[tokenIndex + 1];\n previous[tokenIndex + 1] = Math.min(previous[tokenIndex] + 1, above + 1, diagonal + (value[valueIndex] === tokenName[tokenIndex] ? 0 : 1));\n diagonal = above;\n }\n }\n var distance = previous[tokenName.length];\n if (distance < nearestDistance) {\n nearest = tokenName;\n nearestDistance = distance;\n }\n }\n throw new Error(`Invalid color value \"${value}\" for theme \"${name}\" key \"${key}\".${nearest ? ` Did you mean token \"${nearest}\"?` : \"\"}`);\n }\n var identity = JSON.stringify(Object.keys(resolved).sort().map(function(key2) {\n
|
|
1
|
+
{"version":3,"file":"createThemes.native.js","names":[],"sources":["cjs/createThemes.native.js"],"sourcesContent":["\"use strict\";\nvar __defProp = Object.defineProperty;\nvar __getOwnPropDesc = Object.getOwnPropertyDescriptor;\nvar __getOwnPropNames = Object.getOwnPropertyNames;\nvar __hasOwnProp = Object.prototype.hasOwnProperty;\nvar __export = (target, all) => {\n for (var name in all)\n __defProp(target, name, { get: all[name], enumerable: true });\n};\nvar __copyProps = (to, from, except, desc) => {\n if (from && typeof from === \"object\" || typeof from === \"function\") {\n for (let key of __getOwnPropNames(from))\n if (!__hasOwnProp.call(to, key) && key !== except)\n __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });\n }\n return to;\n};\nvar __toCommonJS = (mod) => __copyProps(__defProp({}, \"__esModule\", { value: true }), mod);\nvar createThemes_exports = {};\n__export(createThemes_exports, {\n createThemes: () => createThemes\n});\nmodule.exports = __toCommonJS(createThemes_exports);\nfunction createThemes(tokens, tree, options) {\n var rootKeys = Object.keys(tree).filter(function(key) {\n return key !== \"children\";\n });\n if (rootKeys.length !== 2 || !(\"light\" in tree) || !(\"dark\" in tree)) {\n throw new Error('createThemes tree must have exactly the roots \"light\" and \"dark\"');\n }\n var themes = {};\n var deduped = /* @__PURE__ */ new Map();\n var add = function(name, definition, parent, inheritedChildren) {\n var _options_getTheme;\n var resolvedDefinition = typeof definition === \"function\" ? definition({\n parent\n }) : definition;\n if (resolvedDefinition === null) return;\n var { values, children, ...recipeFields } = resolvedDefinition;\n var recipe = {\n ...parent,\n ...recipeFields\n };\n var unresolved = {\n ...options === null || options === void 0 ? void 0 : (_options_getTheme = options.getTheme) === null || _options_getTheme === void 0 ? void 0 : _options_getTheme.call(options, {\n recipe,\n name,\n tokens\n }),\n ...values\n };\n var resolved = {};\n for (var key in unresolved) {\n var value = unresolved[key];\n var token = tokens.color[value];\n if (token !== void 0) {\n resolved[key] = token;\n continue;\n }\n var isColor = value === \"transparent\" || /^#(?:[\\da-f]{3,4}|[\\da-f]{6}|[\\da-f]{8})$/i.test(value) || /^(?:rgb|rgba|hsl|hsla)\\(\\s*[^)]+\\)$/i.test(value);\n if (isColor) {\n resolved[key] = value;\n continue;\n }\n var nearest = \"\";\n var nearestDistance = Number.POSITIVE_INFINITY;\n for (var tokenName in tokens.color) {\n var previous = Array.from({\n length: tokenName.length + 1\n }, function(_, index) {\n return index;\n });\n for (var valueIndex = 0; valueIndex < value.length; valueIndex++) {\n var diagonal = previous[0];\n previous[0] = valueIndex + 1;\n for (var tokenIndex = 0; tokenIndex < tokenName.length; tokenIndex++) {\n var above = previous[tokenIndex + 1];\n previous[tokenIndex + 1] = Math.min(previous[tokenIndex] + 1, above + 1, diagonal + (value[valueIndex] === tokenName[tokenIndex] ? 0 : 1));\n diagonal = above;\n }\n }\n var distance = previous[tokenName.length];\n if (distance < nearestDistance) {\n nearest = tokenName;\n nearestDistance = distance;\n }\n }\n throw new Error(`Invalid color value \"${value}\" for theme \"${name}\" key \"${key}\".${nearest ? ` Did you mean token \"${nearest}\"?` : \"\"}`);\n }\n var scheme = recipe.scheme;\n if (scheme === \"light\" || scheme === \"dark\") {\n Object.defineProperty(resolved, /* @__PURE__ */ Symbol.for(\"tamagui.theme.scheme\"), {\n value: scheme\n });\n }\n var identity = JSON.stringify([\n scheme === \"light\" || scheme === \"dark\" ? scheme : void 0,\n Object.keys(resolved).sort().map(function(key2) {\n return [\n key2,\n resolved[key2]\n ];\n })\n ]);\n themes[name] = deduped.get(identity) || resolved;\n deduped.set(identity, themes[name]);\n var childSets = [\n inheritedChildren,\n children\n ];\n var _iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = void 0;\n try {\n for (var _iterator = childSets[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) {\n var childSet = _step.value;\n if (!childSet) continue;\n for (var childName in childSet) {\n var fullName = `${name}_${childName}`;\n if (fullName in themes) {\n throw new Error(`Duplicate generated theme name \"${fullName}\"`);\n }\n add(fullName, childSet[childName], recipe);\n }\n }\n } catch (err) {\n _didIteratorError = true;\n _iteratorError = err;\n } finally {\n try {\n if (!_iteratorNormalCompletion && _iterator.return != null) {\n _iterator.return();\n }\n } finally {\n if (_didIteratorError) {\n throw _iteratorError;\n }\n }\n }\n };\n add(\"light\", tree.light, {}, tree.children);\n add(\"dark\", tree.dark, {}, tree.children);\n return themes;\n}\n//# sourceMappingURL=createThemes.js.map\n"],"mappings":";;;AACA,IAAI,YAAY,OAAO;AACvB,IAAI,mBAAmB,OAAO;AAC9B,IAAI,oBAAoB,OAAO;AAC/B,IAAI,eAAe,OAAO,UAAU;AACpC,IAAI,YAAY,QAAQ,QAAQ;CAC9B,KAAK,IAAI,QAAQ,KACf,UAAU,QAAQ,MAAM;EAAE,KAAK,IAAI;EAAO,YAAY;CAAK,CAAC;AAChE;AACA,IAAI,eAAe,IAAI,MAAM,QAAQ,SAAS;CAC5C,IAAI,QAAQ,OAAO,SAAS,YAAY,OAAO,SAAS,YAAY;EAClE,KAAK,IAAI,OAAO,kBAAkB,IAAI,GACpC,IAAI,CAAC,aAAa,KAAK,IAAI,GAAG,KAAK,QAAQ,QACzC,UAAU,IAAI,KAAK;GAAE,WAAW,KAAK;GAAM,YAAY,EAAE,OAAO,iBAAiB,MAAM,GAAG,MAAM,KAAK;EAAW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B,OAAO,iBAAiB,KAAK;EACvF,IAAI;GACF,KAAK,IAAI,YAAY,UAAU,OAAO,SAAS,CAAC,GAAG,OAAO,EAAE,6BAA6B,QAAQ,UAAU,KAAK,EAAC,CAAE,OAAO,4BAA4B,MAAM;IAC1J,IAAI,WAAW,MAAM;IACrB,IAAI,CAAC,UAAU;IACf,KAAK,IAAI,aAAa,UAAU;KAC9B,IAAI,WAAW,GAAG,KAAK,GAAG;KAC1B,IAAI,YAAY,QAAQ;MACtB,MAAM,IAAI,MAAM,mCAAmC,SAAS,EAAE;KAChE;KACA,IAAI,UAAU,SAAS,YAAY,MAAM;IAC3C;GACF;EACF,SAAS,KAAK;GACZ,oBAAoB;GACpB,iBAAiB;EACnB,UAAU;GACR,IAAI;IACF,IAAI,CAAC,6BAA6B,UAAU,UAAU,MAAM;KAC1D,UAAU,OAAO;IACnB;GACF,UAAU;IACR,IAAI,mBAAmB;KACrB,MAAM;IACR;GACF;EACF;CACF;CACA,IAAI,SAAS,KAAK,OAAO,CAAC,GAAG,KAAK,QAAQ;CAC1C,IAAI,QAAQ,KAAK,MAAM,CAAC,GAAG,KAAK,QAAQ;CACxC,OAAO;AACT"}
|
|
@@ -55,7 +55,11 @@ function createThemes(tokens, tree, options) {
|
|
|
55
55
|
}
|
|
56
56
|
throw new Error(`Invalid color value "${value}" for theme "${name}" key "${key}".${nearest ? ` Did you mean token "${nearest}"?` : ""}`);
|
|
57
57
|
}
|
|
58
|
-
const
|
|
58
|
+
const scheme = recipe.scheme;
|
|
59
|
+
if (scheme === "light" || scheme === "dark") {
|
|
60
|
+
Object.defineProperty(resolved, /* @__PURE__ */ Symbol.for("tamagui.theme.scheme"), { value: scheme });
|
|
61
|
+
}
|
|
62
|
+
const identity = JSON.stringify([scheme === "light" || scheme === "dark" ? scheme : void 0, Object.keys(resolved).sort().map((key) => [key, resolved[key]])]);
|
|
59
63
|
themes[name] = deduped.get(identity) || resolved;
|
|
60
64
|
deduped.set(identity, themes[name]);
|
|
61
65
|
const childSets = [inheritedChildren, children];
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"createThemes.js","names":[],"sources":["esm/createThemes.js"],"sourcesContent":["function createThemes(tokens, tree, options) {\n const rootKeys = Object.keys(tree).filter((key) => key !== \"children\");\n if (rootKeys.length !== 2 || !(\"light\" in tree) || !(\"dark\" in tree)) {\n throw new Error('createThemes tree must have exactly the roots \"light\" and \"dark\"');\n }\n const themes = {};\n const deduped = /* @__PURE__ */ new Map();\n const add = (name, definition, parent, inheritedChildren) => {\n const resolvedDefinition = typeof definition === \"function\" ? definition({ parent }) : definition;\n if (resolvedDefinition === null) return;\n const { values, children, ...recipeFields } = resolvedDefinition;\n const recipe = { ...parent, ...recipeFields };\n const unresolved = {\n ...options?.getTheme?.({ recipe, name, tokens }),\n ...values\n };\n const resolved = {};\n for (const key in unresolved) {\n const value = unresolved[key];\n const token = tokens.color[value];\n if (token !== void 0) {\n resolved[key] = token;\n continue;\n }\n const isColor = value === \"transparent\" || /^#(?:[\\da-f]{3,4}|[\\da-f]{6}|[\\da-f]{8})$/i.test(value) || /^(?:rgb|rgba|hsl|hsla)\\(\\s*[^)]+\\)$/i.test(value);\n if (isColor) {\n resolved[key] = value;\n continue;\n }\n let nearest = \"\";\n let nearestDistance = Number.POSITIVE_INFINITY;\n for (const tokenName in tokens.color) {\n const previous = Array.from({ length: tokenName.length + 1 }, (_, index) => index);\n for (let valueIndex = 0; valueIndex < value.length; valueIndex++) {\n let diagonal = previous[0];\n previous[0] = valueIndex + 1;\n for (let tokenIndex = 0; tokenIndex < tokenName.length; tokenIndex++) {\n const above = previous[tokenIndex + 1];\n previous[tokenIndex + 1] = Math.min(\n previous[tokenIndex] + 1,\n above + 1,\n diagonal + (value[valueIndex] === tokenName[tokenIndex] ? 0 : 1)\n );\n diagonal = above;\n }\n }\n const distance = previous[tokenName.length];\n if (distance < nearestDistance) {\n nearest = tokenName;\n nearestDistance = distance;\n }\n }\n throw new Error(\n `Invalid color value \"${value}\" for theme \"${name}\" key \"${key}\".${nearest ? ` Did you mean token \"${nearest}\"?` : \"\"}`\n );\n }\n const identity = JSON.stringify(\n Object.keys(resolved).sort().map((key) => [key, resolved[key]])\n );\n themes[name] = deduped.get(identity) || resolved;\n deduped.set(identity, themes[name]);\n const childSets = [inheritedChildren, children];\n for (const childSet of childSets) {\n if (!childSet) continue;\n for (const childName in childSet) {\n const fullName = `${name}_${childName}`;\n if (fullName in themes) {\n throw new Error(`Duplicate generated theme name \"${fullName}\"`);\n }\n add(fullName, childSet[childName], recipe);\n }\n }\n };\n add(\"light\", tree.light, {}, tree.children);\n add(\"dark\", tree.dark, {}, tree.children);\n return themes;\n}\nexport {\n createThemes\n};\n//# sourceMappingURL=createThemes.js.map\n"],"mappings":";AAAA,SAAS,aAAa,QAAQ,MAAM,SAAS;CAC3C,MAAM,WAAW,OAAO,KAAK,IAAI,CAAC,CAAC,QAAQ,QAAQ,QAAQ,UAAU;CACrE,IAAI,SAAS,WAAW,KAAK,EAAE,WAAW,SAAS,EAAE,UAAU,OAAO;EACpE,MAAM,IAAI,MAAM,sEAAkE;CACpF;CACA,MAAM,SAAS,CAAC;CAChB,MAAM,0BAA0B,IAAI,IAAI;CACxC,MAAM,OAAO,MAAM,YAAY,QAAQ,sBAAsB;EAC3D,MAAM,qBAAqB,OAAO,eAAe,aAAa,WAAW,EAAE,OAAO,CAAC,IAAI;EACvF,IAAI,uBAAuB,MAAM;EACjC,MAAM,EAAE,QAAQ,UAAU,GAAG,iBAAiB;EAC9C,MAAM,SAAS;GAAE,GAAG;GAAQ,GAAG;EAAa;EAC5C,MAAM,aAAa;GACjB,GAAG,SAAS,WAAW;IAAE;IAAQ;IAAM;GAAO,CAAC;GAC/C,GAAG;EACL;EACA,MAAM,WAAW,CAAC;EAClB,KAAK,MAAM,OAAO,YAAY;GAC5B,MAAM,QAAQ,WAAW;GACzB,MAAM,QAAQ,OAAO,MAAM;GAC3B,IAAI,UAAU,KAAK,GAAG;IACpB,SAAS,OAAO;IAChB;GACF;GACA,MAAM,UAAU,UAAU,iBAAiB,6CAA6C,KAAK,KAAK,KAAK,uCAAuC,KAAK,KAAK;GACxJ,IAAI,SAAS;IACX,SAAS,OAAO;IAChB;GACF;GACA,IAAI,UAAU;GACd,IAAI,kBAAkB,OAAO;GAC7B,KAAK,MAAM,aAAa,OAAO,OAAO;IACpC,MAAM,WAAW,MAAM,KAAK,EAAE,QAAQ,UAAU,SAAS,EAAE,IAAI,GAAG,UAAU,KAAK;IACjF,KAAK,IAAI,aAAa,GAAG,aAAa,MAAM,QAAQ,cAAc;KAChE,IAAI,WAAW,SAAS;KACxB,SAAS,KAAK,aAAa;KAC3B,KAAK,IAAI,aAAa,GAAG,aAAa,UAAU,QAAQ,cAAc;MACpE,MAAM,QAAQ,SAAS,aAAa;MACpC,SAAS,aAAa,KAAK,KAAK,IAC9B,SAAS,cAAc,GACvB,QAAQ,GACR,YAAY,MAAM,gBAAgB,UAAU,cAAc,IAAI,EAChE;MACA,WAAW;KACb;IACF;IACA,MAAM,WAAW,SAAS,UAAU;IACpC,IAAI,WAAW,iBAAiB;KAC9B,UAAU;KACV,kBAAkB;IACpB;GACF;GACA,MAAM,IAAI,MACR,wBAAwB,MAAM,eAAe,KAAK,SAAS,IAAI,IAAI,UAAU,wBAAwB,QAAQ,MAAM,IACrH;EACF;EACA,MAAM,WAAW,KAAK,
|
|
1
|
+
{"version":3,"file":"createThemes.js","names":[],"sources":["esm/createThemes.js"],"sourcesContent":["function createThemes(tokens, tree, options) {\n const rootKeys = Object.keys(tree).filter((key) => key !== \"children\");\n if (rootKeys.length !== 2 || !(\"light\" in tree) || !(\"dark\" in tree)) {\n throw new Error('createThemes tree must have exactly the roots \"light\" and \"dark\"');\n }\n const themes = {};\n const deduped = /* @__PURE__ */ new Map();\n const add = (name, definition, parent, inheritedChildren) => {\n const resolvedDefinition = typeof definition === \"function\" ? definition({ parent }) : definition;\n if (resolvedDefinition === null) return;\n const { values, children, ...recipeFields } = resolvedDefinition;\n const recipe = { ...parent, ...recipeFields };\n const unresolved = {\n ...options?.getTheme?.({ recipe, name, tokens }),\n ...values\n };\n const resolved = {};\n for (const key in unresolved) {\n const value = unresolved[key];\n const token = tokens.color[value];\n if (token !== void 0) {\n resolved[key] = token;\n continue;\n }\n const isColor = value === \"transparent\" || /^#(?:[\\da-f]{3,4}|[\\da-f]{6}|[\\da-f]{8})$/i.test(value) || /^(?:rgb|rgba|hsl|hsla)\\(\\s*[^)]+\\)$/i.test(value);\n if (isColor) {\n resolved[key] = value;\n continue;\n }\n let nearest = \"\";\n let nearestDistance = Number.POSITIVE_INFINITY;\n for (const tokenName in tokens.color) {\n const previous = Array.from({ length: tokenName.length + 1 }, (_, index) => index);\n for (let valueIndex = 0; valueIndex < value.length; valueIndex++) {\n let diagonal = previous[0];\n previous[0] = valueIndex + 1;\n for (let tokenIndex = 0; tokenIndex < tokenName.length; tokenIndex++) {\n const above = previous[tokenIndex + 1];\n previous[tokenIndex + 1] = Math.min(\n previous[tokenIndex] + 1,\n above + 1,\n diagonal + (value[valueIndex] === tokenName[tokenIndex] ? 0 : 1)\n );\n diagonal = above;\n }\n }\n const distance = previous[tokenName.length];\n if (distance < nearestDistance) {\n nearest = tokenName;\n nearestDistance = distance;\n }\n }\n throw new Error(\n `Invalid color value \"${value}\" for theme \"${name}\" key \"${key}\".${nearest ? ` Did you mean token \"${nearest}\"?` : \"\"}`\n );\n }\n const scheme = recipe.scheme;\n if (scheme === \"light\" || scheme === \"dark\") {\n Object.defineProperty(resolved, /* @__PURE__ */ Symbol.for(\"tamagui.theme.scheme\"), {\n value: scheme\n });\n }\n const identity = JSON.stringify([\n scheme === \"light\" || scheme === \"dark\" ? scheme : void 0,\n Object.keys(resolved).sort().map((key) => [key, resolved[key]])\n ]);\n themes[name] = deduped.get(identity) || resolved;\n deduped.set(identity, themes[name]);\n const childSets = [inheritedChildren, children];\n for (const childSet of childSets) {\n if (!childSet) continue;\n for (const childName in childSet) {\n const fullName = `${name}_${childName}`;\n if (fullName in themes) {\n throw new Error(`Duplicate generated theme name \"${fullName}\"`);\n }\n add(fullName, childSet[childName], recipe);\n }\n }\n };\n add(\"light\", tree.light, {}, tree.children);\n add(\"dark\", tree.dark, {}, tree.children);\n return themes;\n}\nexport {\n createThemes\n};\n//# sourceMappingURL=createThemes.js.map\n"],"mappings":";AAAA,SAAS,aAAa,QAAQ,MAAM,SAAS;CAC3C,MAAM,WAAW,OAAO,KAAK,IAAI,CAAC,CAAC,QAAQ,QAAQ,QAAQ,UAAU;CACrE,IAAI,SAAS,WAAW,KAAK,EAAE,WAAW,SAAS,EAAE,UAAU,OAAO;EACpE,MAAM,IAAI,MAAM,sEAAkE;CACpF;CACA,MAAM,SAAS,CAAC;CAChB,MAAM,0BAA0B,IAAI,IAAI;CACxC,MAAM,OAAO,MAAM,YAAY,QAAQ,sBAAsB;EAC3D,MAAM,qBAAqB,OAAO,eAAe,aAAa,WAAW,EAAE,OAAO,CAAC,IAAI;EACvF,IAAI,uBAAuB,MAAM;EACjC,MAAM,EAAE,QAAQ,UAAU,GAAG,iBAAiB;EAC9C,MAAM,SAAS;GAAE,GAAG;GAAQ,GAAG;EAAa;EAC5C,MAAM,aAAa;GACjB,GAAG,SAAS,WAAW;IAAE;IAAQ;IAAM;GAAO,CAAC;GAC/C,GAAG;EACL;EACA,MAAM,WAAW,CAAC;EAClB,KAAK,MAAM,OAAO,YAAY;GAC5B,MAAM,QAAQ,WAAW;GACzB,MAAM,QAAQ,OAAO,MAAM;GAC3B,IAAI,UAAU,KAAK,GAAG;IACpB,SAAS,OAAO;IAChB;GACF;GACA,MAAM,UAAU,UAAU,iBAAiB,6CAA6C,KAAK,KAAK,KAAK,uCAAuC,KAAK,KAAK;GACxJ,IAAI,SAAS;IACX,SAAS,OAAO;IAChB;GACF;GACA,IAAI,UAAU;GACd,IAAI,kBAAkB,OAAO;GAC7B,KAAK,MAAM,aAAa,OAAO,OAAO;IACpC,MAAM,WAAW,MAAM,KAAK,EAAE,QAA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,YAAY,MAAM;GAC3C;EACF;CACF;CACA,IAAI,SAAS,KAAK,OAAO,CAAC,GAAG,KAAK,QAAQ;CAC1C,IAAI,QAAQ,KAAK,MAAM,CAAC,GAAG,KAAK,QAAQ;CACxC,OAAO;AACT"}
|
|
@@ -60,9 +60,13 @@ function createThemes(tokens, tree, options) {
|
|
|
60
60
|
}
|
|
61
61
|
throw new Error(`Invalid color value "${value}" for theme "${name}" key "${key}".${nearest ? ` Did you mean token "${nearest}"?` : ""}`);
|
|
62
62
|
}
|
|
63
|
-
var
|
|
63
|
+
var scheme = recipe.scheme;
|
|
64
|
+
if (scheme === "light" || scheme === "dark") {
|
|
65
|
+
Object.defineProperty(resolved, /* @__PURE__ */ Symbol.for("tamagui.theme.scheme"), { value: scheme });
|
|
66
|
+
}
|
|
67
|
+
var identity = JSON.stringify([scheme === "light" || scheme === "dark" ? scheme : void 0, Object.keys(resolved).sort().map(function(key2) {
|
|
64
68
|
return [key2, resolved[key2]];
|
|
65
|
-
}));
|
|
69
|
+
})]);
|
|
66
70
|
themes[name] = deduped.get(identity) || resolved;
|
|
67
71
|
deduped.set(identity, themes[name]);
|
|
68
72
|
var childSets = [inheritedChildren, children];
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"createThemes.native.js","names":[],"sources":["esm/createThemes.native.js"],"sourcesContent":["function createThemes(tokens, tree, options) {\n var rootKeys = Object.keys(tree).filter(function(key) {\n return key !== \"children\";\n });\n if (rootKeys.length !== 2 || !(\"light\" in tree) || !(\"dark\" in tree)) {\n throw new Error('createThemes tree must have exactly the roots \"light\" and \"dark\"');\n }\n var themes = {};\n var deduped = /* @__PURE__ */ new Map();\n var add = function(name, definition, parent, inheritedChildren) {\n var _options_getTheme;\n var resolvedDefinition = typeof definition === \"function\" ? definition({\n parent\n }) : definition;\n if (resolvedDefinition === null) return;\n var { values, children, ...recipeFields } = resolvedDefinition;\n var recipe = {\n ...parent,\n ...recipeFields\n };\n var unresolved = {\n ...options === null || options === void 0 ? void 0 : (_options_getTheme = options.getTheme) === null || _options_getTheme === void 0 ? void 0 : _options_getTheme.call(options, {\n recipe,\n name,\n tokens\n }),\n ...values\n };\n var resolved = {};\n for (var key in unresolved) {\n var value = unresolved[key];\n var token = tokens.color[value];\n if (token !== void 0) {\n resolved[key] = token;\n continue;\n }\n var isColor = value === \"transparent\" || /^#(?:[\\da-f]{3,4}|[\\da-f]{6}|[\\da-f]{8})$/i.test(value) || /^(?:rgb|rgba|hsl|hsla)\\(\\s*[^)]+\\)$/i.test(value);\n if (isColor) {\n resolved[key] = value;\n continue;\n }\n var nearest = \"\";\n var nearestDistance = Number.POSITIVE_INFINITY;\n for (var tokenName in tokens.color) {\n var previous = Array.from({\n length: tokenName.length + 1\n }, function(_, index) {\n return index;\n });\n for (var valueIndex = 0; valueIndex < value.length; valueIndex++) {\n var diagonal = previous[0];\n previous[0] = valueIndex + 1;\n for (var tokenIndex = 0; tokenIndex < tokenName.length; tokenIndex++) {\n var above = previous[tokenIndex + 1];\n previous[tokenIndex + 1] = Math.min(previous[tokenIndex] + 1, above + 1, diagonal + (value[valueIndex] === tokenName[tokenIndex] ? 0 : 1));\n diagonal = above;\n }\n }\n var distance = previous[tokenName.length];\n if (distance < nearestDistance) {\n nearest = tokenName;\n nearestDistance = distance;\n }\n }\n throw new Error(`Invalid color value \"${value}\" for theme \"${name}\" key \"${key}\".${nearest ? ` Did you mean token \"${nearest}\"?` : \"\"}`);\n }\n var identity = JSON.stringify(Object.keys(resolved).sort().map(function(key2) {\n
|
|
1
|
+
{"version":3,"file":"createThemes.native.js","names":[],"sources":["esm/createThemes.native.js"],"sourcesContent":["function createThemes(tokens, tree, options) {\n var rootKeys = Object.keys(tree).filter(function(key) {\n return key !== \"children\";\n });\n if (rootKeys.length !== 2 || !(\"light\" in tree) || !(\"dark\" in tree)) {\n throw new Error('createThemes tree must have exactly the roots \"light\" and \"dark\"');\n }\n var themes = {};\n var deduped = /* @__PURE__ */ new Map();\n var add = function(name, definition, parent, inheritedChildren) {\n var _options_getTheme;\n var resolvedDefinition = typeof definition === \"function\" ? definition({\n parent\n }) : definition;\n if (resolvedDefinition === null) return;\n var { values, children, ...recipeFields } = resolvedDefinition;\n var recipe = {\n ...parent,\n ...recipeFields\n };\n var unresolved = {\n ...options === null || options === void 0 ? void 0 : (_options_getTheme = options.getTheme) === null || _options_getTheme === void 0 ? void 0 : _options_getTheme.call(options, {\n recipe,\n name,\n tokens\n }),\n ...values\n };\n var resolved = {};\n for (var key in unresolved) {\n var value = unresolved[key];\n var token = tokens.color[value];\n if (token !== void 0) {\n resolved[key] = token;\n continue;\n }\n var isColor = value === \"transparent\" || /^#(?:[\\da-f]{3,4}|[\\da-f]{6}|[\\da-f]{8})$/i.test(value) || /^(?:rgb|rgba|hsl|hsla)\\(\\s*[^)]+\\)$/i.test(value);\n if (isColor) {\n resolved[key] = value;\n continue;\n }\n var nearest = \"\";\n var nearestDistance = Number.POSITIVE_INFINITY;\n for (var tokenName in tokens.color) {\n var previous = Array.from({\n length: tokenName.length + 1\n }, function(_, index) {\n return index;\n });\n for (var valueIndex = 0; valueIndex < value.length; valueIndex++) {\n var diagonal = previous[0];\n previous[0] = valueIndex + 1;\n for (var tokenIndex = 0; tokenIndex < tokenName.length; tokenIndex++) {\n var above = previous[tokenIndex + 1];\n previous[tokenIndex + 1] = Math.min(previous[tokenIndex] + 1, above + 1, diagonal + (value[valueIndex] === tokenName[tokenIndex] ? 0 : 1));\n diagonal = above;\n }\n }\n var distance = previous[tokenName.length];\n if (distance < nearestDistance) {\n nearest = tokenName;\n nearestDistance = distance;\n }\n }\n throw new Error(`Invalid color value \"${value}\" for theme \"${name}\" key \"${key}\".${nearest ? ` Did you mean token \"${nearest}\"?` : \"\"}`);\n }\n var scheme = recipe.scheme;\n if (scheme === \"light\" || scheme === \"dark\") {\n Object.defineProperty(resolved, /* @__PURE__ */ Symbol.for(\"tamagui.theme.scheme\"), {\n value: scheme\n });\n }\n var identity = JSON.stringify([\n scheme === \"light\" || scheme === \"dark\" ? scheme : void 0,\n Object.keys(resolved).sort().map(function(key2) {\n return [\n key2,\n resolved[key2]\n ];\n })\n ]);\n themes[name] = deduped.get(identity) || resolved;\n deduped.set(identity, themes[name]);\n var childSets = [\n inheritedChildren,\n children\n ];\n var _iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = void 0;\n try {\n for (var _iterator = childSets[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) {\n var childSet = _step.value;\n if (!childSet) continue;\n for (var childName in childSet) {\n var fullName = `${name}_${childName}`;\n if (fullName in themes) {\n throw new Error(`Duplicate generated theme name \"${fullName}\"`);\n }\n add(fullName, childSet[childName], recipe);\n }\n }\n } catch (err) {\n _didIteratorError = true;\n _iteratorError = err;\n } finally {\n try {\n if (!_iteratorNormalCompletion && _iterator.return != null) {\n _iterator.return();\n }\n } finally {\n if (_didIteratorError) {\n throw _iteratorError;\n }\n }\n }\n };\n add(\"light\", tree.light, {}, tree.children);\n add(\"dark\", tree.dark, {}, tree.children);\n return themes;\n}\nexport {\n createThemes\n};\n//# sourceMappingURL=createThemes.js.map\n"],"mappings":";AAAA,SAAS,aAAa,QAAQ,MAAM,SAAS;CAC3C,IAAI,WAAW,OAAO,KAAK,IAAI,CAAC,CAAC,OAAO,SAAS,KAAK;EACpD,OAAO,QAAQ;CACjB,CAAC;CACD,IAAI,SAAS,WAAW,KAAK,EAAE,WAAW,SAAS,EAAE,UAAU,OAAO;EACpE,MAAM,IAAI,MAAM,sEAAkE;CACpF;CACA,IAAI,SAAS,CAAC;CACd,IAAI,0BAA0B,IAAI,IAAI;CACtC,IAAI,MAAM,SAAS,MAAM,YAAY,QAAQ,mBAAmB;EAC9D,IAAI;EACJ,IAAI,qBAAqB,OAAO,eAAe,aAAa,WAAW,EACrE,OACF,CAAC,IAAI;EACL,IAAI,uBAAuB,MAAM;EACjC,IAAI,EAAE,QAAQ,UAAU,GAAG,iBAAiB;EAC5C,I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package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tamagui/create-theme",
|
|
3
|
-
"version": "3.0.0-beta.
|
|
3
|
+
"version": "3.0.0-beta.1670.1",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"files": [
|
|
6
6
|
"src",
|
|
@@ -36,7 +36,7 @@
|
|
|
36
36
|
"clean:build": "tamagui-build clean:build"
|
|
37
37
|
},
|
|
38
38
|
"devDependencies": {
|
|
39
|
-
"@tamagui/build": "3.0.0-beta.
|
|
39
|
+
"@tamagui/build": "3.0.0-beta.1670.1",
|
|
40
40
|
"vitest": "4.1.0"
|
|
41
41
|
},
|
|
42
42
|
"repository": {
|
|
@@ -44,5 +44,5 @@
|
|
|
44
44
|
"url": "git+https://github.com/tamagui/tamagui.git",
|
|
45
45
|
"directory": "code/core/create-theme"
|
|
46
46
|
},
|
|
47
|
-
"releaseSourceCommit": "
|
|
47
|
+
"releaseSourceCommit": "23b9b37ef498bb7ebe306138c1d635a807db8ac1"
|
|
48
48
|
}
|
package/src/createThemes.tsx
CHANGED
|
@@ -296,11 +296,20 @@ export function createThemes(
|
|
|
296
296
|
)
|
|
297
297
|
}
|
|
298
298
|
|
|
299
|
-
const
|
|
299
|
+
const scheme = recipe.scheme
|
|
300
|
+
if (scheme === 'light' || scheme === 'dark') {
|
|
301
|
+
// metadata stays out of theme tokens and survives the generated theme boundary.
|
|
302
|
+
Object.defineProperty(resolved, Symbol.for('tamagui.theme.scheme'), {
|
|
303
|
+
value: scheme,
|
|
304
|
+
})
|
|
305
|
+
}
|
|
306
|
+
|
|
307
|
+
const identity = JSON.stringify([
|
|
308
|
+
scheme === 'light' || scheme === 'dark' ? scheme : undefined,
|
|
300
309
|
Object.keys(resolved)
|
|
301
310
|
.sort()
|
|
302
|
-
.map((key) => [key, resolved[key]])
|
|
303
|
-
)
|
|
311
|
+
.map((key) => [key, resolved[key]]),
|
|
312
|
+
])
|
|
304
313
|
themes[name] = deduped.get(identity) || resolved
|
|
305
314
|
deduped.set(identity, themes[name]!)
|
|
306
315
|
|
|
@@ -6,6 +6,6 @@
|
|
|
6
6
|
],
|
|
7
7
|
"version": 3,
|
|
8
8
|
"sourcesContent": [
|
|
9
|
-
"export type ThemeValue = string\n\nexport type ThemeTokens = {\n color: Record<string, ThemeValue>\n}\n\nexport type ThemeRecipe = Record<string, unknown>\n\nexport type ThemeDefinitionContext<Parent extends ThemeRecipe = ThemeRecipe> = {\n parent: Parent\n}\n\nexport type ThemeDefinitionObject = {\n values?: Record<string, ThemeValue>\n children?: ThemeChildren\n [key: string]: unknown\n}\n\nexport type ThemeTreeDefinition<Parent extends ThemeRecipe = ThemeRecipe> =\n | ThemeDefinitionObject\n | ((context: ThemeDefinitionContext<Parent>) => ThemeDefinitionObject | null)\n\nexport type ThemeChildren = Record<string, ThemeTreeDefinition>\n\nexport type ThemeTree = {\n light: ThemeTreeDefinition\n dark: ThemeTreeDefinition\n children?: ThemeChildren\n}\n\ntype ColorLiteral = `#${string}` | `rgb${string}` | `hsl${string}` | 'transparent'\n\nexport type ThemeInputValue<Tokens extends ThemeTokens> =\n | Extract<keyof Tokens['color'], string>\n | ColorLiteral\n\ntype ResolvedDefinition<Definition> = Definition extends (...args: any[]) => infer Result\n ? Exclude<Result, null>\n : Definition\n\ntype DefinitionChildren<Definition> =\n ResolvedDefinition<Definition> extends {\n children?: infer Children\n }\n ? Children\n : never\n\ntype ChildThemeNames<Parent extends string, Children> =\n Children extends Record<string, unknown>\n ? {\n [Name in Extract<keyof Children, string>]:\n | `${Parent}_${Name}`\n | ChildThemeNames<`${Parent}_${Name}`, DefinitionChildren<Children[Name]>>\n }[Extract<keyof Children, string>]\n : never\n\nexport type ThemeNames<Tree extends ThemeTree> =\n | 'light'\n | 'dark'\n | ChildThemeNames<'light', Tree['children']>\n | ChildThemeNames<'dark', Tree['children']>\n | ChildThemeNames<'light', DefinitionChildren<Tree['light']>>\n | ChildThemeNames<'dark', DefinitionChildren<Tree['dark']>>\n\ntype RecipeFields<Definition> = Omit<\n ResolvedDefinition<Definition>,\n 'children' | 'values'\n>\n\ntype ChildDefinitions<\n Children,\n Depth extends readonly unknown[],\n> = Depth extends readonly [unknown, ...infer Rest]\n ? Children extends Record<string, unknown>\n ? Children[keyof Children] | DefinitionsWithin<Children[keyof Children], Rest>\n : never\n : never\n\ntype DefinitionsWithin<Definition, Depth extends readonly unknown[]> =\n | Definition\n | ChildDefinitions<DefinitionChildren<Definition>, Depth>\n\ntype DefinitionsInTree<Tree extends ThemeTree> =\n | DefinitionsWithin<Tree['light'], [1, 1, 1, 1, 1, 1]>\n | DefinitionsWithin<Tree['dark'], [1, 1, 1, 1, 1, 1]>\n | ChildDefinitions<Tree['children'], [1, 1, 1, 1, 1, 1]>\n\ntype KeysOfUnion<Union> = Union extends Union ? keyof Union : never\n\ntype ValueOfUnion<Union, Key extends PropertyKey> = Union extends Union\n ? Key extends keyof Union\n ? Union[Key]\n : never\n : never\n\ntype MergeRecipeUnion<Union> = {\n [Key in KeysOfUnion<Union>]: ValueOfUnion<Union, Key>\n}\n\ntype RootRecipe<Tree extends ThemeTree> =\n | RecipeFields<Tree['light']>\n | RecipeFields<Tree['dark']>\n\ntype RecipeForTree<Tree extends ThemeTree> = {\n [Key in keyof RootRecipe<Tree>]: ValueOfUnion<RootRecipe<Tree>, Key>\n} & Partial<MergeRecipeUnion<RecipeFields<DefinitionsInTree<Tree>>>>\n\nexport type GetThemeContext<\n Tokens extends ThemeTokens = ThemeTokens,\n Recipe extends ThemeRecipe = ThemeRecipe,\n> = {\n recipe: Recipe\n name: string\n tokens: Tokens\n}\n\ntype InvalidValueKeys<Values, Theme> = Exclude<keyof Values, keyof Theme>\n\ntype ValidatedValues<Values, Theme, Tokens extends ThemeTokens> =\n Values extends Record<string, unknown>\n ? Values & {\n [Key in InvalidValueKeys<Values, Theme>]: never\n } & {\n [Key in keyof Values]: Values[Key] extends ThemeInputValue<Tokens>\n ? Values[Key]\n : never\n }\n : never\n\ntype ValidatedChildren<Children, Theme, Tokens extends ThemeTokens> =\n Children extends Record<string, unknown>\n ? {\n [Name in keyof Children]: ValidatedDefinition<Children[Name], Theme, Tokens>\n }\n : never\n\ntype ValidatedDefinition<\n Definition,\n Theme,\n Tokens extends ThemeTokens,\n> = Definition extends (...args: infer Args) => infer Result\n ? (\n ...args: Args\n ) => Result extends null ? null : ValidatedDefinitionObject<Result, Theme, Tokens>\n : ValidatedDefinitionObject<Definition, Theme, Tokens>\n\ntype ValidatedDefinitionObject<Definition, Theme, Tokens extends ThemeTokens> =\n Definition extends Record<string, unknown>\n ? Definition &\n ('values' extends keyof Definition\n ? {\n values: ValidatedValues<Definition['values'], Theme, Tokens>\n }\n : unknown) &\n ('children' extends keyof Definition\n ? {\n children: ValidatedChildren<Definition['children'], Theme, Tokens>\n }\n : unknown)\n : never\n\ntype ValidatedTree<Tree extends ThemeTree, Theme, Tokens extends ThemeTokens> = Tree & {\n light: ValidatedDefinition<Tree['light'], Theme, Tokens>\n dark: ValidatedDefinition<Tree['dark'], Theme, Tokens>\n children?: ValidatedChildren<Tree['children'], Theme, Tokens>\n}\n\ntype ValuesInDefinition<Definition> =\n ResolvedDefinition<Definition> extends {\n values?: infer Values\n }\n ? Values\n : never\n\ntype ValueDefinitionsWithin<Definition, Depth extends readonly unknown[]> =\n | ValuesInDefinition<Definition>\n | (Depth extends readonly [unknown, ...infer Rest]\n ? DefinitionChildren<Definition> extends infer Children\n ? Children extends Record<string, unknown>\n ? ValueDefinitionsWithin<Children[keyof Children], Rest>\n : never\n : never\n : never)\n\ntype ExplicitTheme<Tree extends ThemeTree> = MergeRecipeUnion<\n | ValueDefinitionsWithin<Tree['light'], [1, 1, 1, 1, 1, 1]>\n | ValueDefinitionsWithin<Tree['dark'], [1, 1, 1, 1, 1, 1]>\n | (Tree['children'] extends infer Children\n ? Children extends Record<string, unknown>\n ? ValueDefinitionsWithin<Children[keyof Children], [1, 1, 1, 1, 1, 1]>\n : never\n : never)\n>\n\nexport type CreatedThemes<Names extends string, Theme extends Record<string, string>> = {\n [Name in Names]: { [Key in keyof Theme]: string }\n}\n\nexport function createThemes<\n const Tokens extends ThemeTokens,\n const Tree extends ThemeTree,\n const Theme extends Record<string, ThemeInputValue<Tokens>>,\n>(\n tokens: Tokens,\n tree: ValidatedTree<Tree, Theme, Tokens>,\n options: {\n getTheme: (context: GetThemeContext<Tokens, RecipeForTree<Tree>>) => Theme\n }\n): CreatedThemes<ThemeNames<Tree>, Theme>\n\nexport function createThemes<\n const Tokens extends ThemeTokens,\n const Tree extends ThemeTree,\n>(\n tokens: Tokens,\n tree: ValidatedTree<Tree, Record<string, string>, Tokens>,\n options?: { getTheme?: undefined }\n): CreatedThemes<ThemeNames<Tree>, ExplicitTheme<Tree>>\n\nexport function createThemes(\n tokens: ThemeTokens,\n tree: ThemeTree,\n options?: {\n getTheme?: (context: GetThemeContext) => Record<string, string>\n }\n): Record<string, Record<string, string>> {\n const rootKeys = Object.keys(tree).filter((key) => key !== 'children')\n if (rootKeys.length !== 2 || !('light' in tree) || !('dark' in tree)) {\n throw new Error('createThemes tree must have exactly the roots \"light\" and \"dark\"')\n }\n\n const themes: Record<string, Record<string, string>> = {}\n const deduped = new Map<string, Record<string, string>>()\n\n const add = (\n name: string,\n definition: ThemeTreeDefinition,\n parent: ThemeRecipe,\n inheritedChildren?: ThemeChildren\n ): void => {\n const resolvedDefinition =\n typeof definition === 'function' ? definition({ parent }) : definition\n if (resolvedDefinition === null) return\n\n const { values, children, ...recipeFields } = resolvedDefinition\n const recipe = { ...parent, ...recipeFields }\n const unresolved = {\n ...options?.getTheme?.({ recipe, name, tokens }),\n ...values,\n }\n const resolved: Record<string, string> = {}\n\n for (const key in unresolved) {\n const value = unresolved[key]\n const token = tokens.color[value]\n if (token !== undefined) {\n resolved[key] = token\n continue\n }\n\n const isColor =\n value === 'transparent' ||\n /^#(?:[\\da-f]{3,4}|[\\da-f]{6}|[\\da-f]{8})$/i.test(value) ||\n /^(?:rgb|rgba|hsl|hsla)\\(\\s*[^)]+\\)$/i.test(value)\n if (isColor) {\n resolved[key] = value\n continue\n }\n\n let nearest = ''\n let nearestDistance = Number.POSITIVE_INFINITY\n for (const tokenName in tokens.color) {\n const previous = Array.from({ length: tokenName.length + 1 }, (_, index) => index)\n for (let valueIndex = 0; valueIndex < value.length; valueIndex++) {\n let diagonal = previous[0]!\n previous[0] = valueIndex + 1\n for (let tokenIndex = 0; tokenIndex < tokenName.length; tokenIndex++) {\n const above = previous[tokenIndex + 1]!\n previous[tokenIndex + 1] = Math.min(\n previous[tokenIndex]! + 1,\n above + 1,\n diagonal + (value[valueIndex] === tokenName[tokenIndex] ? 0 : 1)\n )\n diagonal = above\n }\n }\n const distance = previous[tokenName.length]!\n if (distance < nearestDistance) {\n nearest = tokenName\n nearestDistance = distance\n }\n }\n\n throw new Error(\n `Invalid color value \"${value}\" for theme \"${name}\" key \"${key}\".${nearest ? ` Did you mean token \"${nearest}\"?` : ''}`\n )\n }\n\n const identity = JSON.stringify(\n Object.keys(resolved)\n .sort()\n .map((key) => [key, resolved[key]])\n )\n themes[name] = deduped.get(identity) || resolved\n deduped.set(identity, themes[name]!)\n\n const childSets = [inheritedChildren, children]\n for (const childSet of childSets) {\n if (!childSet) continue\n for (const childName in childSet) {\n const fullName = `${name}_${childName}`\n if (fullName in themes) {\n throw new Error(`Duplicate generated theme name \"${fullName}\"`)\n }\n add(fullName, childSet[childName]!, recipe)\n }\n }\n }\n\n add('light', tree.light, {}, tree.children)\n add('dark', tree.dark, {}, tree.children)\n\n return themes\n}\n"
|
|
9
|
+
"export type ThemeValue = string\n\nexport type ThemeTokens = {\n color: Record<string, ThemeValue>\n}\n\nexport type ThemeRecipe = Record<string, unknown>\n\nexport type ThemeDefinitionContext<Parent extends ThemeRecipe = ThemeRecipe> = {\n parent: Parent\n}\n\nexport type ThemeDefinitionObject = {\n values?: Record<string, ThemeValue>\n children?: ThemeChildren\n [key: string]: unknown\n}\n\nexport type ThemeTreeDefinition<Parent extends ThemeRecipe = ThemeRecipe> =\n | ThemeDefinitionObject\n | ((context: ThemeDefinitionContext<Parent>) => ThemeDefinitionObject | null)\n\nexport type ThemeChildren = Record<string, ThemeTreeDefinition>\n\nexport type ThemeTree = {\n light: ThemeTreeDefinition\n dark: ThemeTreeDefinition\n children?: ThemeChildren\n}\n\ntype ColorLiteral = `#${string}` | `rgb${string}` | `hsl${string}` | 'transparent'\n\nexport type ThemeInputValue<Tokens extends ThemeTokens> =\n | Extract<keyof Tokens['color'], string>\n | ColorLiteral\n\ntype ResolvedDefinition<Definition> = Definition extends (...args: any[]) => infer Result\n ? Exclude<Result, null>\n : Definition\n\ntype DefinitionChildren<Definition> =\n ResolvedDefinition<Definition> extends {\n children?: infer Children\n }\n ? Children\n : never\n\ntype ChildThemeNames<Parent extends string, Children> =\n Children extends Record<string, unknown>\n ? {\n [Name in Extract<keyof Children, string>]:\n | `${Parent}_${Name}`\n | ChildThemeNames<`${Parent}_${Name}`, DefinitionChildren<Children[Name]>>\n }[Extract<keyof Children, string>]\n : never\n\nexport type ThemeNames<Tree extends ThemeTree> =\n | 'light'\n | 'dark'\n | ChildThemeNames<'light', Tree['children']>\n | ChildThemeNames<'dark', Tree['children']>\n | ChildThemeNames<'light', DefinitionChildren<Tree['light']>>\n | ChildThemeNames<'dark', DefinitionChildren<Tree['dark']>>\n\ntype RecipeFields<Definition> = Omit<\n ResolvedDefinition<Definition>,\n 'children' | 'values'\n>\n\ntype ChildDefinitions<\n Children,\n Depth extends readonly unknown[],\n> = Depth extends readonly [unknown, ...infer Rest]\n ? Children extends Record<string, unknown>\n ? Children[keyof Children] | DefinitionsWithin<Children[keyof Children], Rest>\n : never\n : never\n\ntype DefinitionsWithin<Definition, Depth extends readonly unknown[]> =\n | Definition\n | ChildDefinitions<DefinitionChildren<Definition>, Depth>\n\ntype DefinitionsInTree<Tree extends ThemeTree> =\n | DefinitionsWithin<Tree['light'], [1, 1, 1, 1, 1, 1]>\n | DefinitionsWithin<Tree['dark'], [1, 1, 1, 1, 1, 1]>\n | ChildDefinitions<Tree['children'], [1, 1, 1, 1, 1, 1]>\n\ntype KeysOfUnion<Union> = Union extends Union ? keyof Union : never\n\ntype ValueOfUnion<Union, Key extends PropertyKey> = Union extends Union\n ? Key extends keyof Union\n ? Union[Key]\n : never\n : never\n\ntype MergeRecipeUnion<Union> = {\n [Key in KeysOfUnion<Union>]: ValueOfUnion<Union, Key>\n}\n\ntype RootRecipe<Tree extends ThemeTree> =\n | RecipeFields<Tree['light']>\n | RecipeFields<Tree['dark']>\n\ntype RecipeForTree<Tree extends ThemeTree> = {\n [Key in keyof RootRecipe<Tree>]: ValueOfUnion<RootRecipe<Tree>, Key>\n} & Partial<MergeRecipeUnion<RecipeFields<DefinitionsInTree<Tree>>>>\n\nexport type GetThemeContext<\n Tokens extends ThemeTokens = ThemeTokens,\n Recipe extends ThemeRecipe = ThemeRecipe,\n> = {\n recipe: Recipe\n name: string\n tokens: Tokens\n}\n\ntype InvalidValueKeys<Values, Theme> = Exclude<keyof Values, keyof Theme>\n\ntype ValidatedValues<Values, Theme, Tokens extends ThemeTokens> =\n Values extends Record<string, unknown>\n ? Values & {\n [Key in InvalidValueKeys<Values, Theme>]: never\n } & {\n [Key in keyof Values]: Values[Key] extends ThemeInputValue<Tokens>\n ? Values[Key]\n : never\n }\n : never\n\ntype ValidatedChildren<Children, Theme, Tokens extends ThemeTokens> =\n Children extends Record<string, unknown>\n ? {\n [Name in keyof Children]: ValidatedDefinition<Children[Name], Theme, Tokens>\n }\n : never\n\ntype ValidatedDefinition<\n Definition,\n Theme,\n Tokens extends ThemeTokens,\n> = Definition extends (...args: infer Args) => infer Result\n ? (\n ...args: Args\n ) => Result extends null ? null : ValidatedDefinitionObject<Result, Theme, Tokens>\n : ValidatedDefinitionObject<Definition, Theme, Tokens>\n\ntype ValidatedDefinitionObject<Definition, Theme, Tokens extends ThemeTokens> =\n Definition extends Record<string, unknown>\n ? Definition &\n ('values' extends keyof Definition\n ? {\n values: ValidatedValues<Definition['values'], Theme, Tokens>\n }\n : unknown) &\n ('children' extends keyof Definition\n ? {\n children: ValidatedChildren<Definition['children'], Theme, Tokens>\n }\n : unknown)\n : never\n\ntype ValidatedTree<Tree extends ThemeTree, Theme, Tokens extends ThemeTokens> = Tree & {\n light: ValidatedDefinition<Tree['light'], Theme, Tokens>\n dark: ValidatedDefinition<Tree['dark'], Theme, Tokens>\n children?: ValidatedChildren<Tree['children'], Theme, Tokens>\n}\n\ntype ValuesInDefinition<Definition> =\n ResolvedDefinition<Definition> extends {\n values?: infer Values\n }\n ? Values\n : never\n\ntype ValueDefinitionsWithin<Definition, Depth extends readonly unknown[]> =\n | ValuesInDefinition<Definition>\n | (Depth extends readonly [unknown, ...infer Rest]\n ? DefinitionChildren<Definition> extends infer Children\n ? Children extends Record<string, unknown>\n ? ValueDefinitionsWithin<Children[keyof Children], Rest>\n : never\n : never\n : never)\n\ntype ExplicitTheme<Tree extends ThemeTree> = MergeRecipeUnion<\n | ValueDefinitionsWithin<Tree['light'], [1, 1, 1, 1, 1, 1]>\n | ValueDefinitionsWithin<Tree['dark'], [1, 1, 1, 1, 1, 1]>\n | (Tree['children'] extends infer Children\n ? Children extends Record<string, unknown>\n ? ValueDefinitionsWithin<Children[keyof Children], [1, 1, 1, 1, 1, 1]>\n : never\n : never)\n>\n\nexport type CreatedThemes<Names extends string, Theme extends Record<string, string>> = {\n [Name in Names]: { [Key in keyof Theme]: string }\n}\n\nexport function createThemes<\n const Tokens extends ThemeTokens,\n const Tree extends ThemeTree,\n const Theme extends Record<string, ThemeInputValue<Tokens>>,\n>(\n tokens: Tokens,\n tree: ValidatedTree<Tree, Theme, Tokens>,\n options: {\n getTheme: (context: GetThemeContext<Tokens, RecipeForTree<Tree>>) => Theme\n }\n): CreatedThemes<ThemeNames<Tree>, Theme>\n\nexport function createThemes<\n const Tokens extends ThemeTokens,\n const Tree extends ThemeTree,\n>(\n tokens: Tokens,\n tree: ValidatedTree<Tree, Record<string, string>, Tokens>,\n options?: { getTheme?: undefined }\n): CreatedThemes<ThemeNames<Tree>, ExplicitTheme<Tree>>\n\nexport function createThemes(\n tokens: ThemeTokens,\n tree: ThemeTree,\n options?: {\n getTheme?: (context: GetThemeContext) => Record<string, string>\n }\n): Record<string, Record<string, string>> {\n const rootKeys = Object.keys(tree).filter((key) => key !== 'children')\n if (rootKeys.length !== 2 || !('light' in tree) || !('dark' in tree)) {\n throw new Error('createThemes tree must have exactly the roots \"light\" and \"dark\"')\n }\n\n const themes: Record<string, Record<string, string>> = {}\n const deduped = new Map<string, Record<string, string>>()\n\n const add = (\n name: string,\n definition: ThemeTreeDefinition,\n parent: ThemeRecipe,\n inheritedChildren?: ThemeChildren\n ): void => {\n const resolvedDefinition =\n typeof definition === 'function' ? definition({ parent }) : definition\n if (resolvedDefinition === null) return\n\n const { values, children, ...recipeFields } = resolvedDefinition\n const recipe = { ...parent, ...recipeFields }\n const unresolved = {\n ...options?.getTheme?.({ recipe, name, tokens }),\n ...values,\n }\n const resolved: Record<string, string> = {}\n\n for (const key in unresolved) {\n const value = unresolved[key]\n const token = tokens.color[value]\n if (token !== undefined) {\n resolved[key] = token\n continue\n }\n\n const isColor =\n value === 'transparent' ||\n /^#(?:[\\da-f]{3,4}|[\\da-f]{6}|[\\da-f]{8})$/i.test(value) ||\n /^(?:rgb|rgba|hsl|hsla)\\(\\s*[^)]+\\)$/i.test(value)\n if (isColor) {\n resolved[key] = value\n continue\n }\n\n let nearest = ''\n let nearestDistance = Number.POSITIVE_INFINITY\n for (const tokenName in tokens.color) {\n const previous = Array.from({ length: tokenName.length + 1 }, (_, index) => index)\n for (let valueIndex = 0; valueIndex < value.length; valueIndex++) {\n let diagonal = previous[0]!\n previous[0] = valueIndex + 1\n for (let tokenIndex = 0; tokenIndex < tokenName.length; tokenIndex++) {\n const above = previous[tokenIndex + 1]!\n previous[tokenIndex + 1] = Math.min(\n previous[tokenIndex]! + 1,\n above + 1,\n diagonal + (value[valueIndex] === tokenName[tokenIndex] ? 0 : 1)\n )\n diagonal = above\n }\n }\n const distance = previous[tokenName.length]!\n if (distance < nearestDistance) {\n nearest = tokenName\n nearestDistance = distance\n }\n }\n\n throw new Error(\n `Invalid color value \"${value}\" for theme \"${name}\" key \"${key}\".${nearest ? ` Did you mean token \"${nearest}\"?` : ''}`\n )\n }\n\n const scheme = recipe.scheme\n if (scheme === 'light' || scheme === 'dark') {\n // metadata stays out of theme tokens and survives the generated theme boundary.\n Object.defineProperty(resolved, Symbol.for('tamagui.theme.scheme'), {\n value: scheme,\n })\n }\n\n const identity = JSON.stringify([\n scheme === 'light' || scheme === 'dark' ? scheme : undefined,\n Object.keys(resolved)\n .sort()\n .map((key) => [key, resolved[key]]),\n ])\n themes[name] = deduped.get(identity) || resolved\n deduped.set(identity, themes[name]!)\n\n const childSets = [inheritedChildren, children]\n for (const childSet of childSets) {\n if (!childSet) continue\n for (const childName in childSet) {\n const fullName = `${name}_${childName}`\n if (fullName in themes) {\n throw new Error(`Duplicate generated theme name \"${fullName}\"`)\n }\n add(fullName, childSet[childName]!, recipe)\n }\n }\n }\n\n add('light', tree.light, {}, tree.children)\n add('dark', tree.dark, {}, tree.children)\n\n return themes\n}\n"
|
|
10
10
|
]
|
|
11
11
|
}
|