@bamboocss/token-dictionary 1.48.5 → 1.50.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
@@ -843,7 +843,33 @@ var TokenDictionary = class {
843
843
  return this.byName.get(path);
844
844
  };
845
845
  formatTokenName = (path) => path.join(".");
846
- formatCssVar = (path, options) => (0, _bamboocss_shared.cssVar)(path.join("-"), options);
846
+ /** Hashed custom-property name -> the token path that claimed it. Only used under `hash.cssVar`. */
847
+ hashedCssVars = /* @__PURE__ */ new Map();
848
+ /**
849
+ * The custom property a token path resolves to, refusing to give one property to two paths.
850
+ *
851
+ * Under `hash.cssVar` the name is a 32-bit hash of the path, so distinct tokens can land on
852
+ * the same custom property. Only one definition then survives in `:root`, and every token
853
+ * that lost silently takes the winner's value — `sizes.t36050` declared as `111px` resolving
854
+ * to `222px` because `spacing.t125265` hashed to the same `--kQArEY`. Nothing is reported,
855
+ * and the symptom is a token rendering as a value that appears nowhere near its definition.
856
+ *
857
+ * Worse than the same accident on a class name, which affects the elements carrying it; this
858
+ * one follows the token everywhere it is referenced.
859
+ *
860
+ * References resolve through here too, with the same path as the definition, so they reclaim
861
+ * their own name rather than colliding with it.
862
+ */
863
+ formatCssVar = (path, options) => {
864
+ const identity = path.join("-");
865
+ const result = (0, _bamboocss_shared.cssVar)(identity, options);
866
+ if (options.hash) {
867
+ const claimed = this.hashedCssVars.get(result.var);
868
+ if (claimed === void 0) this.hashedCssVars.set(result.var, identity);
869
+ else if (claimed !== identity) throw new _bamboocss_shared.BambooError("HASH_COLLISION", `Two different tokens hash to the same css variable \`${result.var}\`:\n ${claimed.replaceAll("-", ".")}\n ${identity.replaceAll("-", ".")}\nOnly one of them can be defined, and the other would silently take its value.`, { hint: "A rare accident of a 32-bit hash, not a mistake in your theme. Renaming either token moves one of them off it. `prefix` will not: it is applied after hashing, so both names carry it and both still collide." });
870
+ }
871
+ return result;
872
+ };
847
873
  registerTokens() {
848
874
  const { tokens = {}, semanticTokens = {}, breakpoints, themes = {} } = this.options;
849
875
  const breakpointTokens = expandBreakpoints(breakpoints);
package/dist/index.d.cts CHANGED
@@ -146,6 +146,23 @@ declare class TokenDictionary {
146
146
  get colorPalette(): ColorPaletteOptions | undefined;
147
147
  getByName: (path: string) => Token | undefined;
148
148
  formatTokenName: (path: string[]) => string;
149
+ /** Hashed custom-property name -> the token path that claimed it. Only used under `hash.cssVar`. */
150
+ private hashedCssVars;
151
+ /**
152
+ * The custom property a token path resolves to, refusing to give one property to two paths.
153
+ *
154
+ * Under `hash.cssVar` the name is a 32-bit hash of the path, so distinct tokens can land on
155
+ * the same custom property. Only one definition then survives in `:root`, and every token
156
+ * that lost silently takes the winner's value — `sizes.t36050` declared as `111px` resolving
157
+ * to `222px` because `spacing.t125265` hashed to the same `--kQArEY`. Nothing is reported,
158
+ * and the symptom is a token rendering as a value that appears nowhere near its definition.
159
+ *
160
+ * Worse than the same accident on a class name, which affects the elements carrying it; this
161
+ * one follows the token everywhere it is referenced.
162
+ *
163
+ * References resolve through here too, with the same path as the definition, so they reclaim
164
+ * their own name rather than colliding with it.
165
+ */
149
166
  formatCssVar: (path: string[], options: CssVarOptions) => CssVar;
150
167
  registerTokens(): this;
151
168
  registerToken: (token: Token, transformPhase?: "pre" | "post") => void;
package/dist/index.d.mts CHANGED
@@ -146,6 +146,23 @@ declare class TokenDictionary {
146
146
  get colorPalette(): ColorPaletteOptions | undefined;
147
147
  getByName: (path: string) => Token | undefined;
148
148
  formatTokenName: (path: string[]) => string;
149
+ /** Hashed custom-property name -> the token path that claimed it. Only used under `hash.cssVar`. */
150
+ private hashedCssVars;
151
+ /**
152
+ * The custom property a token path resolves to, refusing to give one property to two paths.
153
+ *
154
+ * Under `hash.cssVar` the name is a 32-bit hash of the path, so distinct tokens can land on
155
+ * the same custom property. Only one definition then survives in `:root`, and every token
156
+ * that lost silently takes the winner's value — `sizes.t36050` declared as `111px` resolving
157
+ * to `222px` because `spacing.t125265` hashed to the same `--kQArEY`. Nothing is reported,
158
+ * and the symptom is a token rendering as a value that appears nowhere near its definition.
159
+ *
160
+ * Worse than the same accident on a class name, which affects the elements carrying it; this
161
+ * one follows the token everywhere it is referenced.
162
+ *
163
+ * References resolve through here too, with the same path as the definition, so they reclaim
164
+ * their own name rather than colliding with it.
165
+ */
149
166
  formatCssVar: (path: string[], options: CssVarOptions) => CssVar;
150
167
  registerTokens(): this;
151
168
  registerToken: (token: Token, transformPhase?: "pre" | "post") => void;
package/dist/index.mjs CHANGED
@@ -819,7 +819,33 @@ var TokenDictionary = class {
819
819
  return this.byName.get(path);
820
820
  };
821
821
  formatTokenName = (path) => path.join(".");
822
- formatCssVar = (path, options) => cssVar(path.join("-"), options);
822
+ /** Hashed custom-property name -> the token path that claimed it. Only used under `hash.cssVar`. */
823
+ hashedCssVars = /* @__PURE__ */ new Map();
824
+ /**
825
+ * The custom property a token path resolves to, refusing to give one property to two paths.
826
+ *
827
+ * Under `hash.cssVar` the name is a 32-bit hash of the path, so distinct tokens can land on
828
+ * the same custom property. Only one definition then survives in `:root`, and every token
829
+ * that lost silently takes the winner's value — `sizes.t36050` declared as `111px` resolving
830
+ * to `222px` because `spacing.t125265` hashed to the same `--kQArEY`. Nothing is reported,
831
+ * and the symptom is a token rendering as a value that appears nowhere near its definition.
832
+ *
833
+ * Worse than the same accident on a class name, which affects the elements carrying it; this
834
+ * one follows the token everywhere it is referenced.
835
+ *
836
+ * References resolve through here too, with the same path as the definition, so they reclaim
837
+ * their own name rather than colliding with it.
838
+ */
839
+ formatCssVar = (path, options) => {
840
+ const identity = path.join("-");
841
+ const result = cssVar(identity, options);
842
+ if (options.hash) {
843
+ const claimed = this.hashedCssVars.get(result.var);
844
+ if (claimed === void 0) this.hashedCssVars.set(result.var, identity);
845
+ else if (claimed !== identity) throw new BambooError("HASH_COLLISION", `Two different tokens hash to the same css variable \`${result.var}\`:\n ${claimed.replaceAll("-", ".")}\n ${identity.replaceAll("-", ".")}\nOnly one of them can be defined, and the other would silently take its value.`, { hint: "A rare accident of a 32-bit hash, not a mistake in your theme. Renaming either token moves one of them off it. `prefix` will not: it is applied after hashing, so both names carry it and both still collide." });
846
+ }
847
+ return result;
848
+ };
823
849
  registerTokens() {
824
850
  const { tokens = {}, semanticTokens = {}, breakpoints, themes = {} } = this.options;
825
851
  const breakpointTokens = expandBreakpoints(breakpoints);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bamboocss/token-dictionary",
3
- "version": "1.48.5",
3
+ "version": "1.50.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.48.5",
39
- "@bamboocss/shared": "1.48.5",
40
- "@bamboocss/types": "1.48.5"
38
+ "@bamboocss/logger": "^1.50.0",
39
+ "@bamboocss/shared": "1.50.0",
40
+ "@bamboocss/types": "1.50.0"
41
41
  },
42
42
  "devDependencies": {
43
43
  "@types/picomatch": "4.0.2"