@bamboocss/token-dictionary 1.58.1 → 1.58.3
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 +49 -0
- package/dist/index.d.cts +29 -0
- package/dist/index.d.mts +29 -0
- package/dist/index.mjs +49 -0
- package/package.json +4 -4
package/dist/index.cjs
CHANGED
|
@@ -836,6 +836,12 @@ const expandTokenReferences = (str, resolve) => {
|
|
|
836
836
|
return resolve(trimmed) ?? (0, _bamboocss_shared.esc)(trimmed);
|
|
837
837
|
});
|
|
838
838
|
};
|
|
839
|
+
const NONE = [];
|
|
840
|
+
/** The path of every `token(path)` reference in a string, trimmed — the ones `expandTokenReferences` expands. */
|
|
841
|
+
const tokenReferencePaths = (str) => {
|
|
842
|
+
if (!str.includes("token(")) return NONE;
|
|
843
|
+
return Array.from(str.matchAll(REFERENCE), (match) => match[1].trim());
|
|
844
|
+
};
|
|
839
845
|
//#endregion
|
|
840
846
|
//#region src/dictionary.ts
|
|
841
847
|
function expandBreakpoints(breakpoints) {
|
|
@@ -1139,6 +1145,49 @@ var TokenDictionary = class {
|
|
|
1139
1145
|
});
|
|
1140
1146
|
}
|
|
1141
1147
|
/**
|
|
1148
|
+
* Whether `expandReferenceInValue` resolves a `token()` path to a variable.
|
|
1149
|
+
*
|
|
1150
|
+
* A `path/opacity` resolves when its colour does. `colorMix` fails loudly on an opacity it
|
|
1151
|
+
* cannot read, but hands an unknown colour through as text:
|
|
1152
|
+
* `color-mix(in srgb, colors.nope 50%, transparent)`.
|
|
1153
|
+
*/
|
|
1154
|
+
resolvesReference(path) {
|
|
1155
|
+
const slash = path.indexOf("/");
|
|
1156
|
+
return Boolean(this.view.getVar(slash === -1 ? path : path.slice(0, slash)));
|
|
1157
|
+
}
|
|
1158
|
+
/**
|
|
1159
|
+
* Whether `expandReferenceInValue` takes a `token()` path without complaint: it resolves, and a
|
|
1160
|
+
* colour's opacity is a number or an `opacity` token, which `colorMix` fails the build on
|
|
1161
|
+
* otherwise. For a lint rule, which has nothing else to say it.
|
|
1162
|
+
*/
|
|
1163
|
+
isValidReference(path) {
|
|
1164
|
+
if (!this.resolvesReference(path)) return false;
|
|
1165
|
+
return !path.includes("/") || !this.colorMix(path, this.view.getVar.bind(this.view)).invalid;
|
|
1166
|
+
}
|
|
1167
|
+
/**
|
|
1168
|
+
* The `token()` paths in a value that name no token.
|
|
1169
|
+
*
|
|
1170
|
+
* `expandReferenceInValue` writes each one into the css as the escaped path, so
|
|
1171
|
+
* `calc(token(sizes.nope) + 2px)` ships as `calc(sizes\.nope + 2px)` and the declaration never
|
|
1172
|
+
* takes a token's value. Where the property accepts a name — a custom property, `font-family`,
|
|
1173
|
+
* `animation-name` — nothing downstream objects at all. The build's report and the lint rule
|
|
1174
|
+
* both ask this, so they cannot disagree about which references resolve.
|
|
1175
|
+
*/
|
|
1176
|
+
unresolvedReferences(value) {
|
|
1177
|
+
const cached = this.unresolvedReferenceCache.get(value);
|
|
1178
|
+
if (cached) return cached;
|
|
1179
|
+
const paths = tokenReferencePaths(value);
|
|
1180
|
+
if (!paths.length) return paths;
|
|
1181
|
+
const found = paths.filter((path) => !this.resolvesReference(path));
|
|
1182
|
+
this.unresolvedReferenceCache.set(value, found);
|
|
1183
|
+
return found;
|
|
1184
|
+
}
|
|
1185
|
+
/**
|
|
1186
|
+
* By value, because the build asks again of every atom in the sheet on every build, and a
|
|
1187
|
+
* dictionary does not change under its context: a config edit builds a new one.
|
|
1188
|
+
*/
|
|
1189
|
+
unresolvedReferenceCache = /* @__PURE__ */ new Map();
|
|
1190
|
+
/**
|
|
1142
1191
|
* Get the value of a token reference
|
|
1143
1192
|
*/
|
|
1144
1193
|
resolveReference(value) {
|
package/dist/index.d.cts
CHANGED
|
@@ -193,6 +193,35 @@ declare class TokenDictionary {
|
|
|
193
193
|
* Expand token references to their CSS variable
|
|
194
194
|
*/
|
|
195
195
|
expandReferenceInValue(value: string): string;
|
|
196
|
+
/**
|
|
197
|
+
* Whether `expandReferenceInValue` resolves a `token()` path to a variable.
|
|
198
|
+
*
|
|
199
|
+
* A `path/opacity` resolves when its colour does. `colorMix` fails loudly on an opacity it
|
|
200
|
+
* cannot read, but hands an unknown colour through as text:
|
|
201
|
+
* `color-mix(in srgb, colors.nope 50%, transparent)`.
|
|
202
|
+
*/
|
|
203
|
+
resolvesReference(path: string): boolean;
|
|
204
|
+
/**
|
|
205
|
+
* Whether `expandReferenceInValue` takes a `token()` path without complaint: it resolves, and a
|
|
206
|
+
* colour's opacity is a number or an `opacity` token, which `colorMix` fails the build on
|
|
207
|
+
* otherwise. For a lint rule, which has nothing else to say it.
|
|
208
|
+
*/
|
|
209
|
+
isValidReference(path: string): boolean;
|
|
210
|
+
/**
|
|
211
|
+
* The `token()` paths in a value that name no token.
|
|
212
|
+
*
|
|
213
|
+
* `expandReferenceInValue` writes each one into the css as the escaped path, so
|
|
214
|
+
* `calc(token(sizes.nope) + 2px)` ships as `calc(sizes\.nope + 2px)` and the declaration never
|
|
215
|
+
* takes a token's value. Where the property accepts a name — a custom property, `font-family`,
|
|
216
|
+
* `animation-name` — nothing downstream objects at all. The build's report and the lint rule
|
|
217
|
+
* both ask this, so they cannot disagree about which references resolve.
|
|
218
|
+
*/
|
|
219
|
+
unresolvedReferences(value: string): readonly string[];
|
|
220
|
+
/**
|
|
221
|
+
* By value, because the build asks again of every atom in the sheet on every build, and a
|
|
222
|
+
* dictionary does not change under its context: a config edit builds a new one.
|
|
223
|
+
*/
|
|
224
|
+
private unresolvedReferenceCache;
|
|
196
225
|
/**
|
|
197
226
|
* Get the value of a token reference
|
|
198
227
|
*/
|
package/dist/index.d.mts
CHANGED
|
@@ -193,6 +193,35 @@ declare class TokenDictionary {
|
|
|
193
193
|
* Expand token references to their CSS variable
|
|
194
194
|
*/
|
|
195
195
|
expandReferenceInValue(value: string): string;
|
|
196
|
+
/**
|
|
197
|
+
* Whether `expandReferenceInValue` resolves a `token()` path to a variable.
|
|
198
|
+
*
|
|
199
|
+
* A `path/opacity` resolves when its colour does. `colorMix` fails loudly on an opacity it
|
|
200
|
+
* cannot read, but hands an unknown colour through as text:
|
|
201
|
+
* `color-mix(in srgb, colors.nope 50%, transparent)`.
|
|
202
|
+
*/
|
|
203
|
+
resolvesReference(path: string): boolean;
|
|
204
|
+
/**
|
|
205
|
+
* Whether `expandReferenceInValue` takes a `token()` path without complaint: it resolves, and a
|
|
206
|
+
* colour's opacity is a number or an `opacity` token, which `colorMix` fails the build on
|
|
207
|
+
* otherwise. For a lint rule, which has nothing else to say it.
|
|
208
|
+
*/
|
|
209
|
+
isValidReference(path: string): boolean;
|
|
210
|
+
/**
|
|
211
|
+
* The `token()` paths in a value that name no token.
|
|
212
|
+
*
|
|
213
|
+
* `expandReferenceInValue` writes each one into the css as the escaped path, so
|
|
214
|
+
* `calc(token(sizes.nope) + 2px)` ships as `calc(sizes\.nope + 2px)` and the declaration never
|
|
215
|
+
* takes a token's value. Where the property accepts a name — a custom property, `font-family`,
|
|
216
|
+
* `animation-name` — nothing downstream objects at all. The build's report and the lint rule
|
|
217
|
+
* both ask this, so they cannot disagree about which references resolve.
|
|
218
|
+
*/
|
|
219
|
+
unresolvedReferences(value: string): readonly string[];
|
|
220
|
+
/**
|
|
221
|
+
* By value, because the build asks again of every atom in the sheet on every build, and a
|
|
222
|
+
* dictionary does not change under its context: a config edit builds a new one.
|
|
223
|
+
*/
|
|
224
|
+
private unresolvedReferenceCache;
|
|
196
225
|
/**
|
|
197
226
|
* Get the value of a token reference
|
|
198
227
|
*/
|
package/dist/index.mjs
CHANGED
|
@@ -812,6 +812,12 @@ const expandTokenReferences = (str, resolve) => {
|
|
|
812
812
|
return resolve(trimmed) ?? esc(trimmed);
|
|
813
813
|
});
|
|
814
814
|
};
|
|
815
|
+
const NONE = [];
|
|
816
|
+
/** The path of every `token(path)` reference in a string, trimmed — the ones `expandTokenReferences` expands. */
|
|
817
|
+
const tokenReferencePaths = (str) => {
|
|
818
|
+
if (!str.includes("token(")) return NONE;
|
|
819
|
+
return Array.from(str.matchAll(REFERENCE), (match) => match[1].trim());
|
|
820
|
+
};
|
|
815
821
|
//#endregion
|
|
816
822
|
//#region src/dictionary.ts
|
|
817
823
|
function expandBreakpoints(breakpoints) {
|
|
@@ -1115,6 +1121,49 @@ var TokenDictionary = class {
|
|
|
1115
1121
|
});
|
|
1116
1122
|
}
|
|
1117
1123
|
/**
|
|
1124
|
+
* Whether `expandReferenceInValue` resolves a `token()` path to a variable.
|
|
1125
|
+
*
|
|
1126
|
+
* A `path/opacity` resolves when its colour does. `colorMix` fails loudly on an opacity it
|
|
1127
|
+
* cannot read, but hands an unknown colour through as text:
|
|
1128
|
+
* `color-mix(in srgb, colors.nope 50%, transparent)`.
|
|
1129
|
+
*/
|
|
1130
|
+
resolvesReference(path) {
|
|
1131
|
+
const slash = path.indexOf("/");
|
|
1132
|
+
return Boolean(this.view.getVar(slash === -1 ? path : path.slice(0, slash)));
|
|
1133
|
+
}
|
|
1134
|
+
/**
|
|
1135
|
+
* Whether `expandReferenceInValue` takes a `token()` path without complaint: it resolves, and a
|
|
1136
|
+
* colour's opacity is a number or an `opacity` token, which `colorMix` fails the build on
|
|
1137
|
+
* otherwise. For a lint rule, which has nothing else to say it.
|
|
1138
|
+
*/
|
|
1139
|
+
isValidReference(path) {
|
|
1140
|
+
if (!this.resolvesReference(path)) return false;
|
|
1141
|
+
return !path.includes("/") || !this.colorMix(path, this.view.getVar.bind(this.view)).invalid;
|
|
1142
|
+
}
|
|
1143
|
+
/**
|
|
1144
|
+
* The `token()` paths in a value that name no token.
|
|
1145
|
+
*
|
|
1146
|
+
* `expandReferenceInValue` writes each one into the css as the escaped path, so
|
|
1147
|
+
* `calc(token(sizes.nope) + 2px)` ships as `calc(sizes\.nope + 2px)` and the declaration never
|
|
1148
|
+
* takes a token's value. Where the property accepts a name — a custom property, `font-family`,
|
|
1149
|
+
* `animation-name` — nothing downstream objects at all. The build's report and the lint rule
|
|
1150
|
+
* both ask this, so they cannot disagree about which references resolve.
|
|
1151
|
+
*/
|
|
1152
|
+
unresolvedReferences(value) {
|
|
1153
|
+
const cached = this.unresolvedReferenceCache.get(value);
|
|
1154
|
+
if (cached) return cached;
|
|
1155
|
+
const paths = tokenReferencePaths(value);
|
|
1156
|
+
if (!paths.length) return paths;
|
|
1157
|
+
const found = paths.filter((path) => !this.resolvesReference(path));
|
|
1158
|
+
this.unresolvedReferenceCache.set(value, found);
|
|
1159
|
+
return found;
|
|
1160
|
+
}
|
|
1161
|
+
/**
|
|
1162
|
+
* By value, because the build asks again of every atom in the sheet on every build, and a
|
|
1163
|
+
* dictionary does not change under its context: a config edit builds a new one.
|
|
1164
|
+
*/
|
|
1165
|
+
unresolvedReferenceCache = /* @__PURE__ */ new Map();
|
|
1166
|
+
/**
|
|
1118
1167
|
* Get the value of a token reference
|
|
1119
1168
|
*/
|
|
1120
1169
|
resolveReference(value) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@bamboocss/token-dictionary",
|
|
3
|
-
"version": "1.58.
|
|
3
|
+
"version": "1.58.3",
|
|
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.58.
|
|
39
|
-
"@bamboocss/types": "1.58.
|
|
40
|
-
"@bamboocss/shared": "1.58.
|
|
38
|
+
"@bamboocss/logger": "^1.58.3",
|
|
39
|
+
"@bamboocss/types": "1.58.3",
|
|
40
|
+
"@bamboocss/shared": "1.58.3"
|
|
41
41
|
},
|
|
42
42
|
"devDependencies": {
|
|
43
43
|
"@types/picomatch": "4.0.2"
|