@pantoken/utils 1.2.1 → 1.3.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/example-targets.d.mts +12 -0
- package/dist/example-targets.mjs +43 -0
- package/package.json +6 -5
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
//#region src/example-targets.d.ts
|
|
2
|
+
/** Consumer supported by a cssdoc example's audience flag. */
|
|
3
|
+
export type ExampleAudience = "automatica11y" | "canvas-rce" | "docs";
|
|
4
|
+
/** Example indexes selected for each cssdoc consumer. */
|
|
5
|
+
export interface ExampleTargetSelection {
|
|
6
|
+
automatica11y: number[];
|
|
7
|
+
canvasRce: number[];
|
|
8
|
+
docs: number[];
|
|
9
|
+
}
|
|
10
|
+
/** Resolve example indexes for each consumer while preserving the pre-flag defaults. */
|
|
11
|
+
export declare function resolveExampleTargets(examples: readonly string[]): ExampleTargetSelection;
|
|
12
|
+
//#endregion
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
//#region src/example-targets.ts
|
|
2
|
+
const AUDIENCE_FLAGS = /* @__PURE__ */ new Map([
|
|
3
|
+
["-automatica11y", "automatica11y"],
|
|
4
|
+
["-canvas-rce", "canvas-rce"],
|
|
5
|
+
["-docs", "docs"]
|
|
6
|
+
]);
|
|
7
|
+
function audienceFlags(example) {
|
|
8
|
+
const fenceStart = example.indexOf("```");
|
|
9
|
+
const metadata = fenceStart < 0 ? example : example.slice(0, fenceStart);
|
|
10
|
+
const fenceInfo = fenceStart < 0 ? "" : example.slice(fenceStart + 3).split(/\r?\n/u, 1)[0] ?? "";
|
|
11
|
+
const metadataTokens = metadata.trim().split(/\s+/u).filter(Boolean);
|
|
12
|
+
const metadataIsFlags = metadataTokens.every((token) => /^-[a-z][a-z0-9-]*$/u.test(token));
|
|
13
|
+
const flags = /* @__PURE__ */ new Set();
|
|
14
|
+
for (const token of [...metadataIsFlags ? metadataTokens : [], ...fenceInfo.split(/\s+/u)]) {
|
|
15
|
+
const audience = AUDIENCE_FLAGS.get(token);
|
|
16
|
+
if (audience) flags.add(audience);
|
|
17
|
+
}
|
|
18
|
+
return flags;
|
|
19
|
+
}
|
|
20
|
+
/** Resolve example indexes for each consumer while preserving the pre-flag defaults. */
|
|
21
|
+
function resolveExampleTargets(examples) {
|
|
22
|
+
const flags = examples.map(audienceFlags);
|
|
23
|
+
const explicit = (audience) => flags.flatMap((exampleFlags, index) => exampleFlags.has(audience) ? [index] : []);
|
|
24
|
+
const automatica11y = explicit("automatica11y");
|
|
25
|
+
const canvasRce = explicit("canvas-rce");
|
|
26
|
+
const docs = explicit("docs");
|
|
27
|
+
if (automatica11y.length + canvasRce.length + docs.length === 0) return {
|
|
28
|
+
automatica11y: [],
|
|
29
|
+
canvasRce: examples.length === 0 ? [] : [0],
|
|
30
|
+
docs: examples.map((_, index) => index)
|
|
31
|
+
};
|
|
32
|
+
const unassigned = flags.flatMap((exampleFlags, index) => exampleFlags.size === 0 ? [index] : []);
|
|
33
|
+
const fallbackCanvas = canvasRce.length === 0 ? unassigned.slice(0, 1) : [];
|
|
34
|
+
const assignedCanvas = canvasRce.length > 0 ? canvasRce : fallbackCanvas;
|
|
35
|
+
const fallbackDocs = docs.length > 0 ? [] : unassigned.filter((index) => !fallbackCanvas.includes(index));
|
|
36
|
+
return {
|
|
37
|
+
automatica11y,
|
|
38
|
+
canvasRce: assignedCanvas,
|
|
39
|
+
docs: docs.length > 0 ? docs : fallbackDocs
|
|
40
|
+
};
|
|
41
|
+
}
|
|
42
|
+
//#endregion
|
|
43
|
+
export { resolveExampleTargets };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@pantoken/utils",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.3.0",
|
|
4
4
|
"description": "Shared pantoken helpers: token reference resolver, typed regexes (arkregex), name-case, and hex-colour parsing.",
|
|
5
5
|
"homepage": "https://pantoken.app",
|
|
6
6
|
"bugs": "https://github.com/thedannywahl/pantoken/issues",
|
|
@@ -18,6 +18,7 @@
|
|
|
18
18
|
"exports": {
|
|
19
19
|
".": "./dist/index.mjs",
|
|
20
20
|
"./token-syntax": "./dist/token-syntax.mjs",
|
|
21
|
+
"./example-targets": "./dist/example-targets.mjs",
|
|
21
22
|
"./scope": "./dist/scope.mjs",
|
|
22
23
|
"./package.json": "./package.json"
|
|
23
24
|
},
|
|
@@ -27,15 +28,15 @@
|
|
|
27
28
|
},
|
|
28
29
|
"dependencies": {
|
|
29
30
|
"@pantoken/model": "0.5.0",
|
|
30
|
-
"arkregex": "^0.0.
|
|
31
|
+
"arkregex": "^0.0.12",
|
|
31
32
|
"css-tree": "^3.2.1"
|
|
32
33
|
},
|
|
33
34
|
"devDependencies": {
|
|
34
35
|
"@types/css-tree": "^3.2.0",
|
|
35
|
-
"@types/node": "^26.6.
|
|
36
|
+
"@types/node": "^26.6.5",
|
|
36
37
|
"typescript": "^7.0.2",
|
|
37
|
-
"vite": "npm:@voidzero-dev/vite-plus-core@1.
|
|
38
|
-
"vite-plus": "1.
|
|
38
|
+
"vite": "npm:@voidzero-dev/vite-plus-core@1.2.0",
|
|
39
|
+
"vite-plus": "1.2.0"
|
|
39
40
|
},
|
|
40
41
|
"engines": {
|
|
41
42
|
"node": ">=22.18.0"
|