@tamagui/create-theme 2.7.7 → 3.0.0-beta.637.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.
Files changed (115) hide show
  1. package/dist/cjs/createThemes.cjs +100 -0
  2. package/dist/cjs/createThemes.native.cjs +126 -0
  3. package/dist/cjs/createThemes.native.js +128 -0
  4. package/dist/cjs/createThemes.native.js.map +1 -0
  5. package/dist/cjs/index.cjs +10 -16
  6. package/dist/cjs/index.native.cjs +21 -0
  7. package/dist/cjs/index.native.js +11 -16
  8. package/dist/cjs/index.native.js.map +1 -1
  9. package/dist/esm/createThemes.mjs +79 -0
  10. package/dist/esm/createThemes.mjs.map +1 -0
  11. package/dist/esm/createThemes.native.js +103 -0
  12. package/dist/esm/createThemes.native.js.map +1 -0
  13. package/dist/esm/index.js +1 -7
  14. package/dist/esm/index.mjs +1 -7
  15. package/dist/esm/index.native.js +1 -7
  16. package/package.json +6 -7
  17. package/src/createThemes.tsx +328 -0
  18. package/src/index.tsx +1 -6
  19. package/types/createThemes.d.ts +122 -0
  20. package/types/createThemes.d.ts.map +11 -0
  21. package/types/index.d.ts +1 -6
  22. package/types/index.d.ts.map +2 -2
  23. package/dist/cjs/applyMask.cjs +0 -67
  24. package/dist/cjs/applyMask.native.js +0 -76
  25. package/dist/cjs/applyMask.native.js.map +0 -1
  26. package/dist/cjs/combineMasks.cjs +0 -48
  27. package/dist/cjs/combineMasks.native.js +0 -73
  28. package/dist/cjs/combineMasks.native.js.map +0 -1
  29. package/dist/cjs/createTheme.cjs +0 -105
  30. package/dist/cjs/createTheme.native.js +0 -111
  31. package/dist/cjs/createTheme.native.js.map +0 -1
  32. package/dist/cjs/createThemeTypes.cjs +0 -18
  33. package/dist/cjs/createThemeTypes.native.js +0 -21
  34. package/dist/cjs/createThemeTypes.native.js.map +0 -1
  35. package/dist/cjs/helpers.cjs +0 -36
  36. package/dist/cjs/helpers.native.js +0 -41
  37. package/dist/cjs/helpers.native.js.map +0 -1
  38. package/dist/cjs/isMinusZero.cjs +0 -30
  39. package/dist/cjs/isMinusZero.native.js +0 -33
  40. package/dist/cjs/isMinusZero.native.js.map +0 -1
  41. package/dist/cjs/masks.cjs +0 -146
  42. package/dist/cjs/masks.native.js +0 -192
  43. package/dist/cjs/masks.native.js.map +0 -1
  44. package/dist/cjs/tests.cjs +0 -26
  45. package/dist/cjs/tests.native.js +0 -29
  46. package/dist/cjs/tests.native.js.map +0 -1
  47. package/dist/cjs/themeInfo.cjs +0 -40
  48. package/dist/cjs/themeInfo.native.js +0 -43
  49. package/dist/cjs/themeInfo.native.js.map +0 -1
  50. package/dist/esm/applyMask.mjs +0 -41
  51. package/dist/esm/applyMask.mjs.map +0 -1
  52. package/dist/esm/applyMask.native.js +0 -47
  53. package/dist/esm/applyMask.native.js.map +0 -1
  54. package/dist/esm/combineMasks.mjs +0 -23
  55. package/dist/esm/combineMasks.mjs.map +0 -1
  56. package/dist/esm/combineMasks.native.js +0 -45
  57. package/dist/esm/combineMasks.native.js.map +0 -1
  58. package/dist/esm/createTheme.mjs +0 -78
  59. package/dist/esm/createTheme.mjs.map +0 -1
  60. package/dist/esm/createTheme.native.js +0 -81
  61. package/dist/esm/createTheme.native.js.map +0 -1
  62. package/dist/esm/createThemeTypes.mjs +0 -2
  63. package/dist/esm/createThemeTypes.mjs.map +0 -1
  64. package/dist/esm/createThemeTypes.native.js +0 -2
  65. package/dist/esm/createThemeTypes.native.js.map +0 -1
  66. package/dist/esm/helpers.mjs +0 -9
  67. package/dist/esm/helpers.mjs.map +0 -1
  68. package/dist/esm/helpers.native.js +0 -11
  69. package/dist/esm/helpers.native.js.map +0 -1
  70. package/dist/esm/index.js.map +0 -1
  71. package/dist/esm/index.mjs.map +0 -1
  72. package/dist/esm/index.native.js.map +0 -1
  73. package/dist/esm/isMinusZero.mjs +0 -5
  74. package/dist/esm/isMinusZero.mjs.map +0 -1
  75. package/dist/esm/isMinusZero.native.js +0 -5
  76. package/dist/esm/isMinusZero.native.js.map +0 -1
  77. package/dist/esm/masks.mjs +0 -114
  78. package/dist/esm/masks.mjs.map +0 -1
  79. package/dist/esm/masks.native.js +0 -157
  80. package/dist/esm/masks.native.js.map +0 -1
  81. package/dist/esm/tests.mjs +0 -27
  82. package/dist/esm/tests.mjs.map +0 -1
  83. package/dist/esm/tests.native.js +0 -27
  84. package/dist/esm/tests.native.js.map +0 -1
  85. package/dist/esm/themeInfo.mjs +0 -14
  86. package/dist/esm/themeInfo.mjs.map +0 -1
  87. package/dist/esm/themeInfo.native.js +0 -14
  88. package/dist/esm/themeInfo.native.js.map +0 -1
  89. package/src/applyMask.tsx +0 -69
  90. package/src/combineMasks.tsx +0 -29
  91. package/src/createTheme.tsx +0 -127
  92. package/src/createThemeTypes.tsx +0 -85
  93. package/src/helpers.tsx +0 -44
  94. package/src/isMinusZero.tsx +0 -3
  95. package/src/masks.tsx +0 -137
  96. package/src/tests.tsx +0 -28
  97. package/src/themeInfo.tsx +0 -36
  98. package/types/applyMask.d.ts +0 -8
  99. package/types/applyMask.d.ts.map +0 -11
  100. package/types/combineMasks.d.ts +0 -4
  101. package/types/combineMasks.d.ts.map +0 -11
  102. package/types/createTheme.d.ts +0 -28
  103. package/types/createTheme.d.ts.map +0 -11
  104. package/types/createThemeTypes.d.ts +0 -67
  105. package/types/createThemeTypes.d.ts.map +0 -11
  106. package/types/helpers.d.ts +0 -18
  107. package/types/helpers.d.ts.map +0 -11
  108. package/types/isMinusZero.d.ts +0 -3
  109. package/types/isMinusZero.d.ts.map +0 -11
  110. package/types/masks.d.ts +0 -15
  111. package/types/masks.d.ts.map +0 -11
  112. package/types/tests.d.ts +0 -3
  113. package/types/tests.d.ts.map +0 -11
  114. package/types/themeInfo.d.ts +0 -13
  115. package/types/themeInfo.d.ts.map +0 -11
@@ -0,0 +1,100 @@
1
+
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all) __defProp(target, name, {
8
+ get: all[name],
9
+ enumerable: true
10
+ });
11
+ };
12
+ var __copyProps = (to, from, except, desc) => {
13
+ if (from && typeof from === "object" || typeof from === "function") {
14
+ for (let key of __getOwnPropNames(from)) if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
15
+ get: () => from[key],
16
+ enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
17
+ });
18
+ }
19
+ return to;
20
+ };
21
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
22
+ var createThemes_exports = {};
23
+ __export(createThemes_exports, { createThemes: () => createThemes });
24
+ module.exports = __toCommonJS(createThemes_exports);
25
+ function createThemes(tokens, tree, options) {
26
+ const rootKeys = Object.keys(tree).filter((key) => key !== "children");
27
+ if (rootKeys.length !== 2 || !Object.prototype.hasOwnProperty.call(tree, "light") || !Object.prototype.hasOwnProperty.call(tree, "dark")) {
28
+ throw new Error("createThemes tree must have exactly the roots \"light\" and \"dark\"");
29
+ }
30
+ const themes = {};
31
+ const deduped = /* @__PURE__ */ new Map();
32
+ const add = (name, definition, parent, inheritedChildren) => {
33
+ const resolvedDefinition = typeof definition === "function" ? definition({ parent }) : definition;
34
+ if (resolvedDefinition === null) return;
35
+ const { values, children, ...recipeFields } = resolvedDefinition;
36
+ const recipe = {
37
+ ...parent,
38
+ ...recipeFields
39
+ };
40
+ const unresolved = {
41
+ ...options?.getTheme?.({
42
+ recipe,
43
+ name,
44
+ tokens
45
+ }),
46
+ ...values
47
+ };
48
+ const resolved = {};
49
+ for (const key in unresolved) {
50
+ const value = unresolved[key];
51
+ const token = tokens.color[value];
52
+ if (token !== void 0) {
53
+ resolved[key] = token;
54
+ continue;
55
+ }
56
+ 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);
57
+ if (isColor) {
58
+ resolved[key] = value;
59
+ continue;
60
+ }
61
+ let nearest = "";
62
+ let nearestDistance = Number.POSITIVE_INFINITY;
63
+ for (const tokenName in tokens.color) {
64
+ const previous = Array.from({ length: tokenName.length + 1 }, (_, index) => index);
65
+ for (let valueIndex = 0; valueIndex < value.length; valueIndex++) {
66
+ let diagonal = previous[0];
67
+ previous[0] = valueIndex + 1;
68
+ for (let tokenIndex = 0; tokenIndex < tokenName.length; tokenIndex++) {
69
+ const above = previous[tokenIndex + 1];
70
+ previous[tokenIndex + 1] = Math.min(previous[tokenIndex] + 1, above + 1, diagonal + (value[valueIndex] === tokenName[tokenIndex] ? 0 : 1));
71
+ diagonal = above;
72
+ }
73
+ }
74
+ const distance = previous[tokenName.length];
75
+ if (distance < nearestDistance) {
76
+ nearest = tokenName;
77
+ nearestDistance = distance;
78
+ }
79
+ }
80
+ throw new Error(`Invalid color value "${value}" for theme "${name}" key "${key}".${nearest ? ` Did you mean token "${nearest}"?` : ""}`);
81
+ }
82
+ const identity = JSON.stringify(Object.keys(resolved).sort().map((key) => [key, resolved[key]]));
83
+ themes[name] = deduped.get(identity) || resolved;
84
+ deduped.set(identity, themes[name]);
85
+ const childSets = [inheritedChildren, children];
86
+ for (const childSet of childSets) {
87
+ if (!childSet) continue;
88
+ for (const childName in childSet) {
89
+ const fullName = `${name}_${childName}`;
90
+ if (Object.prototype.hasOwnProperty.call(themes, fullName)) {
91
+ throw new Error(`Duplicate generated theme name "${fullName}"`);
92
+ }
93
+ add(fullName, childSet[childName], recipe);
94
+ }
95
+ }
96
+ };
97
+ add("light", tree.light, {}, tree.children);
98
+ add("dark", tree.dark, {}, tree.children);
99
+ return themes;
100
+ }
@@ -0,0 +1,126 @@
1
+ "use strict";
2
+
3
+
4
+ var __defProp = Object.defineProperty;
5
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
6
+ var __getOwnPropNames = Object.getOwnPropertyNames;
7
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
8
+ var __export = (target, all) => {
9
+ for (var name in all) __defProp(target, name, {
10
+ get: all[name],
11
+ enumerable: true
12
+ });
13
+ };
14
+ var __copyProps = (to, from, except, desc) => {
15
+ if (from && typeof from === "object" || typeof from === "function") {
16
+ for (let key of __getOwnPropNames(from)) if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
17
+ get: () => from[key],
18
+ enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
19
+ });
20
+ }
21
+ return to;
22
+ };
23
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
24
+ var createThemes_exports = {};
25
+ __export(createThemes_exports, { createThemes: () => createThemes });
26
+ module.exports = __toCommonJS(createThemes_exports);
27
+ function createThemes(tokens, tree, options) {
28
+ var rootKeys = Object.keys(tree).filter(function(key) {
29
+ return key !== "children";
30
+ });
31
+ if (rootKeys.length !== 2 || !Object.prototype.hasOwnProperty.call(tree, "light") || !Object.prototype.hasOwnProperty.call(tree, "dark")) {
32
+ throw new Error("createThemes tree must have exactly the roots \"light\" and \"dark\"");
33
+ }
34
+ var themes = {};
35
+ var deduped = /* @__PURE__ */ new Map();
36
+ var add = function(name, definition, parent, inheritedChildren) {
37
+ var _options_getTheme;
38
+ var resolvedDefinition = typeof definition === "function" ? definition({ parent }) : definition;
39
+ if (resolvedDefinition === null) return;
40
+ var { values, children, ...recipeFields } = resolvedDefinition;
41
+ var recipe = {
42
+ ...parent,
43
+ ...recipeFields
44
+ };
45
+ var unresolved = {
46
+ ...options === null || options === void 0 ? void 0 : (_options_getTheme = options.getTheme) === null || _options_getTheme === void 0 ? void 0 : _options_getTheme.call(options, {
47
+ recipe,
48
+ name,
49
+ tokens
50
+ }),
51
+ ...values
52
+ };
53
+ var resolved = {};
54
+ for (var key in unresolved) {
55
+ var value = unresolved[key];
56
+ var token = tokens.color[value];
57
+ if (token !== void 0) {
58
+ resolved[key] = token;
59
+ continue;
60
+ }
61
+ 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);
62
+ if (isColor) {
63
+ resolved[key] = value;
64
+ continue;
65
+ }
66
+ var nearest = "";
67
+ var nearestDistance = Number.POSITIVE_INFINITY;
68
+ for (var tokenName in tokens.color) {
69
+ var previous = Array.from({ length: tokenName.length + 1 }, function(_, index) {
70
+ return index;
71
+ });
72
+ for (var valueIndex = 0; valueIndex < value.length; valueIndex++) {
73
+ var diagonal = previous[0];
74
+ previous[0] = valueIndex + 1;
75
+ for (var tokenIndex = 0; tokenIndex < tokenName.length; tokenIndex++) {
76
+ var above = previous[tokenIndex + 1];
77
+ previous[tokenIndex + 1] = Math.min(previous[tokenIndex] + 1, above + 1, diagonal + (value[valueIndex] === tokenName[tokenIndex] ? 0 : 1));
78
+ diagonal = above;
79
+ }
80
+ }
81
+ var distance = previous[tokenName.length];
82
+ if (distance < nearestDistance) {
83
+ nearest = tokenName;
84
+ nearestDistance = distance;
85
+ }
86
+ }
87
+ throw new Error(`Invalid color value "${value}" for theme "${name}" key "${key}".${nearest ? ` Did you mean token "${nearest}"?` : ""}`);
88
+ }
89
+ var identity = JSON.stringify(Object.keys(resolved).sort().map(function(key2) {
90
+ return [key2, resolved[key2]];
91
+ }));
92
+ themes[name] = deduped.get(identity) || resolved;
93
+ deduped.set(identity, themes[name]);
94
+ var childSets = [inheritedChildren, children];
95
+ var _iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = void 0;
96
+ try {
97
+ for (var _iterator = childSets[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) {
98
+ var childSet = _step.value;
99
+ if (!childSet) continue;
100
+ for (var childName in childSet) {
101
+ var fullName = `${name}_${childName}`;
102
+ if (Object.prototype.hasOwnProperty.call(themes, fullName)) {
103
+ throw new Error(`Duplicate generated theme name "${fullName}"`);
104
+ }
105
+ add(fullName, childSet[childName], recipe);
106
+ }
107
+ }
108
+ } catch (err) {
109
+ _didIteratorError = true;
110
+ _iteratorError = err;
111
+ } finally {
112
+ try {
113
+ if (!_iteratorNormalCompletion && _iterator.return != null) {
114
+ _iterator.return();
115
+ }
116
+ } finally {
117
+ if (_didIteratorError) {
118
+ throw _iteratorError;
119
+ }
120
+ }
121
+ }
122
+ };
123
+ add("light", tree.light, {}, tree.children);
124
+ add("dark", tree.dark, {}, tree.children);
125
+ return themes;
126
+ }
@@ -0,0 +1,128 @@
1
+ "use strict";
2
+
3
+
4
+ var __defProp = Object.defineProperty;
5
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
6
+ var __getOwnPropNames = Object.getOwnPropertyNames;
7
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
8
+ var __export = (target, all) => {
9
+ for (var name in all) __defProp(target, name, {
10
+ get: all[name],
11
+ enumerable: true
12
+ });
13
+ };
14
+ var __copyProps = (to, from, except, desc) => {
15
+ if (from && typeof from === "object" || typeof from === "function") {
16
+ for (let key of __getOwnPropNames(from)) if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
17
+ get: () => from[key],
18
+ enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
19
+ });
20
+ }
21
+ return to;
22
+ };
23
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
24
+ var createThemes_exports = {};
25
+ __export(createThemes_exports, { createThemes: () => createThemes });
26
+ module.exports = __toCommonJS(createThemes_exports);
27
+ function createThemes(tokens, tree, options) {
28
+ var rootKeys = Object.keys(tree).filter(function(key) {
29
+ return key !== "children";
30
+ });
31
+ if (rootKeys.length !== 2 || !Object.prototype.hasOwnProperty.call(tree, "light") || !Object.prototype.hasOwnProperty.call(tree, "dark")) {
32
+ throw new Error("createThemes tree must have exactly the roots \"light\" and \"dark\"");
33
+ }
34
+ var themes = {};
35
+ var deduped = /* @__PURE__ */ new Map();
36
+ var add = function(name, definition, parent, inheritedChildren) {
37
+ var _options_getTheme;
38
+ var resolvedDefinition = typeof definition === "function" ? definition({ parent }) : definition;
39
+ if (resolvedDefinition === null) return;
40
+ var { values, children, ...recipeFields } = resolvedDefinition;
41
+ var recipe = {
42
+ ...parent,
43
+ ...recipeFields
44
+ };
45
+ var unresolved = {
46
+ ...options === null || options === void 0 ? void 0 : (_options_getTheme = options.getTheme) === null || _options_getTheme === void 0 ? void 0 : _options_getTheme.call(options, {
47
+ recipe,
48
+ name,
49
+ tokens
50
+ }),
51
+ ...values
52
+ };
53
+ var resolved = {};
54
+ for (var key in unresolved) {
55
+ var value = unresolved[key];
56
+ var token = tokens.color[value];
57
+ if (token !== void 0) {
58
+ resolved[key] = token;
59
+ continue;
60
+ }
61
+ 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);
62
+ if (isColor) {
63
+ resolved[key] = value;
64
+ continue;
65
+ }
66
+ var nearest = "";
67
+ var nearestDistance = Number.POSITIVE_INFINITY;
68
+ for (var tokenName in tokens.color) {
69
+ var previous = Array.from({ length: tokenName.length + 1 }, function(_, index) {
70
+ return index;
71
+ });
72
+ for (var valueIndex = 0; valueIndex < value.length; valueIndex++) {
73
+ var diagonal = previous[0];
74
+ previous[0] = valueIndex + 1;
75
+ for (var tokenIndex = 0; tokenIndex < tokenName.length; tokenIndex++) {
76
+ var above = previous[tokenIndex + 1];
77
+ previous[tokenIndex + 1] = Math.min(previous[tokenIndex] + 1, above + 1, diagonal + (value[valueIndex] === tokenName[tokenIndex] ? 0 : 1));
78
+ diagonal = above;
79
+ }
80
+ }
81
+ var distance = previous[tokenName.length];
82
+ if (distance < nearestDistance) {
83
+ nearest = tokenName;
84
+ nearestDistance = distance;
85
+ }
86
+ }
87
+ throw new Error(`Invalid color value "${value}" for theme "${name}" key "${key}".${nearest ? ` Did you mean token "${nearest}"?` : ""}`);
88
+ }
89
+ var identity = JSON.stringify(Object.keys(resolved).sort().map(function(key2) {
90
+ return [key2, resolved[key2]];
91
+ }));
92
+ themes[name] = deduped.get(identity) || resolved;
93
+ deduped.set(identity, themes[name]);
94
+ var childSets = [inheritedChildren, children];
95
+ var _iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = void 0;
96
+ try {
97
+ for (var _iterator = childSets[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) {
98
+ var childSet = _step.value;
99
+ if (!childSet) continue;
100
+ for (var childName in childSet) {
101
+ var fullName = `${name}_${childName}`;
102
+ if (Object.prototype.hasOwnProperty.call(themes, fullName)) {
103
+ throw new Error(`Duplicate generated theme name "${fullName}"`);
104
+ }
105
+ add(fullName, childSet[childName], recipe);
106
+ }
107
+ }
108
+ } catch (err) {
109
+ _didIteratorError = true;
110
+ _iteratorError = err;
111
+ } finally {
112
+ try {
113
+ if (!_iteratorNormalCompletion && _iterator.return != null) {
114
+ _iterator.return();
115
+ }
116
+ } finally {
117
+ if (_didIteratorError) {
118
+ throw _iteratorError;
119
+ }
120
+ }
121
+ }
122
+ };
123
+ add("light", tree.light, {}, tree.children);
124
+ add("dark", tree.dark, {}, tree.children);
125
+ return themes;
126
+ }
127
+
128
+ //# sourceMappingURL=createThemes.native.js.map
@@ -0,0 +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 || !Object.prototype.hasOwnProperty.call(tree, \"light\") || !Object.prototype.hasOwnProperty.call(tree, \"dark\")) {\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 return [\n key2,\n resolved[key2]\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 (Object.prototype.hasOwnProperty.call(themes, fullName)) {\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,U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AAS,MAAM;GAC5E,OAAO,CACL,MACA,SAAS,KACX;EACF,CAAC,CAAC;EACF,OAAO,QAAQ,QAAQ,IAAI,QAAQ,KAAK;EACxC,QAAQ,IAAI,UAAU,OAAO,KAAK;EAClC,IAAI,YAAY,CACd,mBACA,QACF;EACA,IAAI,4BAA4B,MAAM,oBAAoB,OAAO,iBAAiB,KAAK;EACvF,IAAI;GACF,KAAK,IAAI,YAAY,UAAU,OAAO,UAAU,GAAG,OAAO,EAAE,6BAA6B,QAAQ,UAAU,KAAK,GAAG,OAAO,4BAA4B,MAAM;IAC1J,IAAI,WAAW,MAAM;IACrB,IAAI,CAAC,UAAU;IACf,KAAK,IAAI,aAAa,UAAU;KAC9B,IAAI,WAAW,GAAG,KAAK,GAAG;KAC1B,IAAI,OAAO,UAAU,eAAe,KAAK,QAAQ,QAAQ,GAAG;MAC1D,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"}
@@ -1,25 +1,19 @@
1
+
1
2
  var __defProp = Object.defineProperty;
2
3
  var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
3
4
  var __getOwnPropNames = Object.getOwnPropertyNames;
4
5
  var __hasOwnProp = Object.prototype.hasOwnProperty;
5
6
  var __copyProps = (to, from, except, desc) => {
6
- if (from && typeof from === "object" || typeof from === "function") {
7
- for (let key of __getOwnPropNames(from)) if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
8
- get: () => from[key],
9
- enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
10
- });
11
- }
12
- return to;
7
+ if (from && typeof from === "object" || typeof from === "function") {
8
+ for (let key of __getOwnPropNames(from)) if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
9
+ get: () => from[key],
10
+ enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
11
+ });
12
+ }
13
+ return to;
13
14
  };
14
15
  var __reExport = (target, mod, secondTarget) => (__copyProps(target, mod, "default"), secondTarget && __copyProps(secondTarget, mod, "default"));
15
- var __toCommonJS = mod => __copyProps(__defProp({}, "__esModule", {
16
- value: true
17
- }), mod);
16
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
18
17
  var index_exports = {};
19
18
  module.exports = __toCommonJS(index_exports);
20
- __reExport(index_exports, require("./createTheme.cjs"), module.exports);
21
- __reExport(index_exports, require("./masks.cjs"), module.exports);
22
- __reExport(index_exports, require("./combineMasks.cjs"), module.exports);
23
- __reExport(index_exports, require("./applyMask.cjs"), module.exports);
24
- __reExport(index_exports, require("./createThemeTypes.cjs"), module.exports);
25
- __reExport(index_exports, require("./helpers.cjs"), module.exports);
19
+ __reExport(index_exports, require("./createThemes.cjs"), module.exports);
@@ -0,0 +1,21 @@
1
+ "use strict";
2
+
3
+
4
+ var __defProp = Object.defineProperty;
5
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
6
+ var __getOwnPropNames = Object.getOwnPropertyNames;
7
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
8
+ var __copyProps = (to, from, except, desc) => {
9
+ if (from && typeof from === "object" || typeof from === "function") {
10
+ for (let key of __getOwnPropNames(from)) if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
11
+ get: () => from[key],
12
+ enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
13
+ });
14
+ }
15
+ return to;
16
+ };
17
+ var __reExport = (target, mod, secondTarget) => (__copyProps(target, mod, "default"), secondTarget && __copyProps(secondTarget, mod, "default"));
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+ var index_exports = {};
20
+ module.exports = __toCommonJS(index_exports);
21
+ __reExport(index_exports, require("./createThemes.native.js"), module.exports);
@@ -1,28 +1,23 @@
1
1
  "use strict";
2
2
 
3
+
3
4
  var __defProp = Object.defineProperty;
4
5
  var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
6
  var __getOwnPropNames = Object.getOwnPropertyNames;
6
7
  var __hasOwnProp = Object.prototype.hasOwnProperty;
7
8
  var __copyProps = (to, from, except, desc) => {
8
- if (from && typeof from === "object" || typeof from === "function") {
9
- for (let key of __getOwnPropNames(from)) if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
10
- get: () => from[key],
11
- enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
12
- });
13
- }
14
- return to;
9
+ if (from && typeof from === "object" || typeof from === "function") {
10
+ for (let key of __getOwnPropNames(from)) if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
11
+ get: () => from[key],
12
+ enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
13
+ });
14
+ }
15
+ return to;
15
16
  };
16
17
  var __reExport = (target, mod, secondTarget) => (__copyProps(target, mod, "default"), secondTarget && __copyProps(secondTarget, mod, "default"));
17
- var __toCommonJS = mod => __copyProps(__defProp({}, "__esModule", {
18
- value: true
19
- }), mod);
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
20
19
  var index_exports = {};
21
20
  module.exports = __toCommonJS(index_exports);
22
- __reExport(index_exports, require("./createTheme.native.js"), module.exports);
23
- __reExport(index_exports, require("./masks.native.js"), module.exports);
24
- __reExport(index_exports, require("./combineMasks.native.js"), module.exports);
25
- __reExport(index_exports, require("./applyMask.native.js"), module.exports);
26
- __reExport(index_exports, require("./createThemeTypes.native.js"), module.exports);
27
- __reExport(index_exports, require("./helpers.native.js"), module.exports);
21
+ __reExport(index_exports, require("./createThemes.native.js"), module.exports);
22
+
28
23
  //# sourceMappingURL=index.native.js.map
@@ -1 +1 @@
1
- {"version":3,"names":["__toCommonJS","mod","__copyProps","__defProp","value","index_exports","module","exports","__reExport","require"],"sources":["../../src/index.tsx"],"sourcesContent":[null],"mappings":";;;;;;;;;;;;;;;;AAAA,IAAAA,YAAA,GAAAC,GAAA,IAAAC,WAAA,CAAAC,SAAA;EAAAC,KAAA;AAAA,IAAAH,GAAA;AAAA,IAAAI,aAAA;AAAAC,MAAA,CAAAC,OAAA,GAAAP,YAAc,CAAAK,aAAA;AACdG,UAAA,CAAAH,aAAA,EAAcI,OAAA,0BADd,GAAAH,MAAA,CAAAC,OAAA;AAEAC,UAAA,CAAAH,aAAA,EAAcI,OAAA,uBAAAH,MAAA,CAFdC,OAAA;AAGAC,UAAA,CAAAH,aAAA,EAAcI,OAAA,2BAHd,GAAAH,MAAA,CAAAC,OAAA;AAIAC,UAAA,CAAAH,aAAA,EAAcI,OAAA,2BAAAH,MAAA,CAJdC,OAAA;AAKAC,UAAA,CAAAH,aAAA,EAAcI,OAAA,+BALd,GAAAH,MAAA,CAAAC,OAAA","ignoreList":[]}
1
+ {"version":3,"file":"index.native.js","names":[],"sources":["cjs/index.native.js"],"sourcesContent":["\"use strict\";\nvar __defProp = Object.defineProperty;\nvar __getOwnPropDesc = Object.getOwnPropertyDescriptor;\nvar __getOwnPropNames = Object.getOwnPropertyNames;\nvar __hasOwnProp = Object.prototype.hasOwnProperty;\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 __reExport = (target, mod, secondTarget) => (__copyProps(target, mod, \"default\"), secondTarget && __copyProps(secondTarget, mod, \"default\"));\nvar __toCommonJS = (mod) => __copyProps(__defProp({}, \"__esModule\", { value: true }), mod);\nvar index_exports = {};\nmodule.exports = __toCommonJS(index_exports);\n__reExport(index_exports, require(\"./createThemes\"), module.exports);\n//# sourceMappingURL=index.js.map\n"],"mappings":";;;;AACA,IAAI,YAAY,OAAO;AACvB,IAAI,mBAAmB,OAAO;AAC9B,IAAI,oBAAoB,OAAO;AAC/B,IAAI,eAAe,OAAO,UAAU;AACpC,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,CAAC;CACvH;CACA,OAAO;AACT;AACA,IAAI,cAAc,QAAQ,KAAK,kBAAkB,YAAY,QAAQ,KAAK,SAAS,GAAG,gBAAgB,YAAY,cAAc,KAAK,SAAS;AAC9I,IAAI,gBAAgB,QAAQ,YAAY,UAAU,CAAC,GAAG,cAAc,EAAE,OAAO,KAAK,CAAC,GAAG,GAAG;AACzF,IAAI,gBAAgB,CAAC;AACrB,OAAO,UAAU,aAAa,aAAa;AAC3C,WAAW,eAAe,QAAQ,0BAAgB,GAAG,OAAO,OAAO"}
@@ -0,0 +1,79 @@
1
+ function createThemes(tokens, tree, options) {
2
+ const rootKeys = Object.keys(tree).filter((key) => key !== "children");
3
+ if (rootKeys.length !== 2 || !Object.prototype.hasOwnProperty.call(tree, "light") || !Object.prototype.hasOwnProperty.call(tree, "dark")) {
4
+ throw new Error("createThemes tree must have exactly the roots \"light\" and \"dark\"");
5
+ }
6
+ const themes = {};
7
+ const deduped = /* @__PURE__ */ new Map();
8
+ const add = (name, definition, parent, inheritedChildren) => {
9
+ const resolvedDefinition = typeof definition === "function" ? definition({ parent }) : definition;
10
+ if (resolvedDefinition === null) return;
11
+ const { values, children, ...recipeFields } = resolvedDefinition;
12
+ const recipe = {
13
+ ...parent,
14
+ ...recipeFields
15
+ };
16
+ const unresolved = {
17
+ ...options?.getTheme?.({
18
+ recipe,
19
+ name,
20
+ tokens
21
+ }),
22
+ ...values
23
+ };
24
+ const resolved = {};
25
+ for (const key in unresolved) {
26
+ const value = unresolved[key];
27
+ const token = tokens.color[value];
28
+ if (token !== void 0) {
29
+ resolved[key] = token;
30
+ continue;
31
+ }
32
+ 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);
33
+ if (isColor) {
34
+ resolved[key] = value;
35
+ continue;
36
+ }
37
+ let nearest = "";
38
+ let nearestDistance = Number.POSITIVE_INFINITY;
39
+ for (const tokenName in tokens.color) {
40
+ const previous = Array.from({ length: tokenName.length + 1 }, (_, index) => index);
41
+ for (let valueIndex = 0; valueIndex < value.length; valueIndex++) {
42
+ let diagonal = previous[0];
43
+ previous[0] = valueIndex + 1;
44
+ for (let tokenIndex = 0; tokenIndex < tokenName.length; tokenIndex++) {
45
+ const above = previous[tokenIndex + 1];
46
+ previous[tokenIndex + 1] = Math.min(previous[tokenIndex] + 1, above + 1, diagonal + (value[valueIndex] === tokenName[tokenIndex] ? 0 : 1));
47
+ diagonal = above;
48
+ }
49
+ }
50
+ const distance = previous[tokenName.length];
51
+ if (distance < nearestDistance) {
52
+ nearest = tokenName;
53
+ nearestDistance = distance;
54
+ }
55
+ }
56
+ throw new Error(`Invalid color value "${value}" for theme "${name}" key "${key}".${nearest ? ` Did you mean token "${nearest}"?` : ""}`);
57
+ }
58
+ const identity = JSON.stringify(Object.keys(resolved).sort().map((key) => [key, resolved[key]]));
59
+ themes[name] = deduped.get(identity) || resolved;
60
+ deduped.set(identity, themes[name]);
61
+ const childSets = [inheritedChildren, children];
62
+ for (const childSet of childSets) {
63
+ if (!childSet) continue;
64
+ for (const childName in childSet) {
65
+ const fullName = `${name}_${childName}`;
66
+ if (Object.prototype.hasOwnProperty.call(themes, fullName)) {
67
+ throw new Error(`Duplicate generated theme name "${fullName}"`);
68
+ }
69
+ add(fullName, childSet[childName], recipe);
70
+ }
71
+ }
72
+ };
73
+ add("light", tree.light, {}, tree.children);
74
+ add("dark", tree.dark, {}, tree.children);
75
+ return themes;
76
+ }
77
+
78
+ export { createThemes };
79
+ //# sourceMappingURL=createThemes.mjs.map
@@ -0,0 +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 || !Object.prototype.hasOwnProperty.call(tree, \"light\") || !Object.prototype.hasOwnProperty.call(tree, \"dark\")) {\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 (Object.prototype.hasOwnProperty.call(themes, fullName)) {\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,EAAE,QAAQ,QAAQ,QAAQ,UAAU;CACrE,IAAI,SAAS,WAAW,KAAK,CAAC,OAAO,UAAU,eAAe,KAAK,MAAM,OAAO,KAAK,CAAC,OAAO,UAAU,eAAe,KAAK,MAAM,MAAM,GAAG;EACxI,MAAM,IAAI,MAAM,sEAAkE;CACpF;CACA,MAAM,SAAS,CAAC;CAChB,MAAM,0BAA0B,IAAI,IAAI;CACxC,MAAM,OAAO,MAAM,YAAY,QAAQ,sBAA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