@bamboocss/token-dictionary 1.55.8 → 1.56.0

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/index.cjs CHANGED
@@ -58,6 +58,15 @@ const isCompositeTokenValue = (value) => {
58
58
  //#endregion
59
59
  //#region src/utils.ts
60
60
  /**
61
+ * An opacity token's value (`0.07`) as the percentage a `color-mix()` takes (`7%`).
62
+ *
63
+ * Multiplying by 100 in binary floating point is not exact: `0.07 * 100` is `7.000000000000001`
64
+ * and `0.29 * 100` is `28.999999999999996`, which reached the stylesheet verbatim. Twelve
65
+ * significant digits is far beyond what a color can resolve and well short of where the error
66
+ * lives, so rounding there removes the noise without touching any intended value.
67
+ */
68
+ const opacityPercent = (value) => `${Number((Number(value) * 100).toPrecision(12))}%`;
69
+ /**
61
70
  * A reference to another token inside a string value: `token(colors.red.300)`.
62
71
  *
63
72
  * The comma exclusion keeps a fallback form — `token(spacing.4, 4)` — out of this pass
@@ -1071,7 +1080,7 @@ var TokenDictionary = class {
1071
1080
  invalid: true,
1072
1081
  value: colorPath
1073
1082
  };
1074
- const percent = opacityToken ? Number(opacityToken) * 100 + "%" : `${rawOpacity}%`;
1083
+ const percent = opacityToken ? opacityPercent(opacityToken) : `${rawOpacity}%`;
1075
1084
  const color = colorToken ?? colorPath;
1076
1085
  return {
1077
1086
  invalid: false,
@@ -1289,5 +1298,6 @@ exports.getReferences = getReferences;
1289
1298
  exports.hasReference = hasReference;
1290
1299
  exports.isToken = isToken;
1291
1300
  exports.mapToJson = mapToJson;
1301
+ exports.opacityPercent = opacityPercent;
1292
1302
  exports.referenceOf = referenceOf;
1293
1303
  exports.replaceReference = replaceReference;
package/dist/index.d.cts CHANGED
@@ -232,6 +232,15 @@ declare class TokenDictionaryView {
232
232
  }
233
233
  //#endregion
234
234
  //#region src/utils.d.ts
235
+ /**
236
+ * An opacity token's value (`0.07`) as the percentage a `color-mix()` takes (`7%`).
237
+ *
238
+ * Multiplying by 100 in binary floating point is not exact: `0.07 * 100` is `7.000000000000001`
239
+ * and `0.29 * 100` is `28.999999999999996`, which reached the stylesheet verbatim. Twelve
240
+ * significant digits is far beyond what a color can resolve and well short of where the error
241
+ * lives, so rounding there removes the noise without touching any intended value.
242
+ */
243
+ declare const opacityPercent: (value: unknown) => string;
235
244
  /**
236
245
  * How a reference to `key` is spelled, for a caller building one rather than reading one.
237
246
  *
@@ -265,4 +274,4 @@ declare function mapToJson(map: Map<string, any>): Record<string, unknown>;
265
274
  declare const isToken: (value: any) => value is Token$1;
266
275
  declare function assertTokenFormat(token: any): asserts token is Token$1;
267
276
  //#endregion
268
- export { TOKEN_CATEGORIES, Token, type TokenCategory, TokenDictionary, type TokenExtensions, assertTokenFormat, curlyReferenceMessage, expandReferences, fallbackReferenceMessage, findCurlyReference, findFallbackReference, getReferences, hasReference, isToken, mapToJson, referenceOf, replaceReference };
277
+ export { TOKEN_CATEGORIES, Token, type TokenCategory, TokenDictionary, type TokenExtensions, assertTokenFormat, curlyReferenceMessage, expandReferences, fallbackReferenceMessage, findCurlyReference, findFallbackReference, getReferences, hasReference, isToken, mapToJson, opacityPercent, referenceOf, replaceReference };
package/dist/index.d.mts CHANGED
@@ -232,6 +232,15 @@ declare class TokenDictionaryView {
232
232
  }
233
233
  //#endregion
234
234
  //#region src/utils.d.ts
235
+ /**
236
+ * An opacity token's value (`0.07`) as the percentage a `color-mix()` takes (`7%`).
237
+ *
238
+ * Multiplying by 100 in binary floating point is not exact: `0.07 * 100` is `7.000000000000001`
239
+ * and `0.29 * 100` is `28.999999999999996`, which reached the stylesheet verbatim. Twelve
240
+ * significant digits is far beyond what a color can resolve and well short of where the error
241
+ * lives, so rounding there removes the noise without touching any intended value.
242
+ */
243
+ declare const opacityPercent: (value: unknown) => string;
235
244
  /**
236
245
  * How a reference to `key` is spelled, for a caller building one rather than reading one.
237
246
  *
@@ -265,4 +274,4 @@ declare function mapToJson(map: Map<string, any>): Record<string, unknown>;
265
274
  declare const isToken: (value: any) => value is Token$1;
266
275
  declare function assertTokenFormat(token: any): asserts token is Token$1;
267
276
  //#endregion
268
- export { TOKEN_CATEGORIES, Token, type TokenCategory, TokenDictionary, type TokenExtensions, assertTokenFormat, curlyReferenceMessage, expandReferences, fallbackReferenceMessage, findCurlyReference, findFallbackReference, getReferences, hasReference, isToken, mapToJson, referenceOf, replaceReference };
277
+ export { TOKEN_CATEGORIES, Token, type TokenCategory, TokenDictionary, type TokenExtensions, assertTokenFormat, curlyReferenceMessage, expandReferences, fallbackReferenceMessage, findCurlyReference, findFallbackReference, getReferences, hasReference, isToken, mapToJson, opacityPercent, referenceOf, replaceReference };
package/dist/index.mjs CHANGED
@@ -34,6 +34,15 @@ const isCompositeTokenValue = (value) => {
34
34
  //#endregion
35
35
  //#region src/utils.ts
36
36
  /**
37
+ * An opacity token's value (`0.07`) as the percentage a `color-mix()` takes (`7%`).
38
+ *
39
+ * Multiplying by 100 in binary floating point is not exact: `0.07 * 100` is `7.000000000000001`
40
+ * and `0.29 * 100` is `28.999999999999996`, which reached the stylesheet verbatim. Twelve
41
+ * significant digits is far beyond what a color can resolve and well short of where the error
42
+ * lives, so rounding there removes the noise without touching any intended value.
43
+ */
44
+ const opacityPercent = (value) => `${Number((Number(value) * 100).toPrecision(12))}%`;
45
+ /**
37
46
  * A reference to another token inside a string value: `token(colors.red.300)`.
38
47
  *
39
48
  * The comma exclusion keeps a fallback form — `token(spacing.4, 4)` — out of this pass
@@ -1047,7 +1056,7 @@ var TokenDictionary = class {
1047
1056
  invalid: true,
1048
1057
  value: colorPath
1049
1058
  };
1050
- const percent = opacityToken ? Number(opacityToken) * 100 + "%" : `${rawOpacity}%`;
1059
+ const percent = opacityToken ? opacityPercent(opacityToken) : `${rawOpacity}%`;
1051
1060
  const color = colorToken ?? colorPath;
1052
1061
  return {
1053
1062
  invalid: false,
@@ -1252,4 +1261,4 @@ function replaceRootWithColorPalette(path, colorPaletteRoot) {
1252
1261
  }
1253
1262
  const tokenPathRegex = /\w+\.\w+/;
1254
1263
  //#endregion
1255
- export { TOKEN_CATEGORIES, Token, TokenDictionary, assertTokenFormat, curlyReferenceMessage, expandReferences, fallbackReferenceMessage, findCurlyReference, findFallbackReference, getReferences, hasReference, isToken, mapToJson, referenceOf, replaceReference };
1264
+ export { TOKEN_CATEGORIES, Token, TokenDictionary, assertTokenFormat, curlyReferenceMessage, expandReferences, fallbackReferenceMessage, findCurlyReference, findFallbackReference, getReferences, hasReference, isToken, mapToJson, opacityPercent, referenceOf, replaceReference };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bamboocss/token-dictionary",
3
- "version": "1.55.8",
3
+ "version": "1.56.0",
4
4
  "description": "Common error messages for css bamboo",
5
5
  "homepage": "https://bamboocss.com",
6
6
  "license": "MIT",
@@ -35,9 +35,9 @@
35
35
  "dependencies": {
36
36
  "picomatch": "4.0.5",
37
37
  "ts-pattern": "5.9.0",
38
- "@bamboocss/logger": "^1.55.8",
39
- "@bamboocss/shared": "1.55.8",
40
- "@bamboocss/types": "1.55.8"
38
+ "@bamboocss/logger": "^1.56.0",
39
+ "@bamboocss/shared": "1.56.0",
40
+ "@bamboocss/types": "1.56.0"
41
41
  },
42
42
  "devDependencies": {
43
43
  "@types/picomatch": "4.0.2"