@rojaostudio/ds-core 1.1.0-next.1 → 1.1.0-next.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/{chunk-CFOS2RAD.js → chunk-XEVAQPW7.js} +40 -2
- package/dist/generate.d.ts +20 -2
- package/dist/generate.js +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +1 -1
- package/dist/themes.js +1 -1
- package/figma/export-brand.js +58 -0
- package/package.json +3 -2
|
@@ -1092,7 +1092,7 @@ ${lines.join("\n")}
|
|
|
1092
1092
|
const scopes = scope.split(",").map((s) => s.trim());
|
|
1093
1093
|
const darkSel = scopes.map((s) => s === ":root" ? `:root${dark}, ${dark}` : `${s}${dark}, ${dark} ${s}`).join(", ");
|
|
1094
1094
|
return [
|
|
1095
|
-
block2(scope, theme.light),
|
|
1095
|
+
block2(scope, __spreadValues(__spreadValues({}, theme.light), theme.vars)),
|
|
1096
1096
|
block2(darkSel, theme.dark, theme.light),
|
|
1097
1097
|
block2(plate, theme.brand, theme.light)
|
|
1098
1098
|
].join("\n\n") + "\n";
|
|
@@ -1102,6 +1102,44 @@ function rdsContrast(theme, mode, fg, bg) {
|
|
|
1102
1102
|
if (!/^#[0-9a-f]{6}$/i.test(a) || !/^#[0-9a-f]{6}$/i.test(c)) return null;
|
|
1103
1103
|
return contrastRatio(a, c);
|
|
1104
1104
|
}
|
|
1105
|
+
var isColourRef = (v) => /^[a-z][a-z0-9-]*\/[a-z]?\d+$/i.test(v);
|
|
1106
|
+
function rdsThemeFromTable(table) {
|
|
1107
|
+
var _a;
|
|
1108
|
+
const out = { light: {}, dark: {}, brand: {} };
|
|
1109
|
+
const problems = [];
|
|
1110
|
+
for (const mode of ["light", "dark", "brand"]) {
|
|
1111
|
+
const roles = (_a = table.modes) == null ? void 0 : _a[mode];
|
|
1112
|
+
if (!roles) {
|
|
1113
|
+
problems.push(`mode "${mode}" is missing`);
|
|
1114
|
+
continue;
|
|
1115
|
+
}
|
|
1116
|
+
for (const [role] of ROLES) {
|
|
1117
|
+
const ref2 = roles[role];
|
|
1118
|
+
if (ref2 === void 0) problems.push(`${mode}: role "${role}" is missing`);
|
|
1119
|
+
else if (isColourRef(ref2)) {
|
|
1120
|
+
const value = table.primitives[ref2];
|
|
1121
|
+
if (value === void 0) problems.push(`${mode}: "${role}" points to unknown primitive "${ref2}"`);
|
|
1122
|
+
else out[mode][roleVar(role)] = value.toLowerCase();
|
|
1123
|
+
} else out[mode][roleVar(role)] = ref2;
|
|
1124
|
+
}
|
|
1125
|
+
}
|
|
1126
|
+
const valueOf = (where, ref2) => {
|
|
1127
|
+
if (!isColourRef(ref2)) return ref2;
|
|
1128
|
+
const value = table.primitives[ref2];
|
|
1129
|
+
if (value === void 0) problems.push(`${where} points to unknown primitive "${ref2}"`);
|
|
1130
|
+
return value == null ? void 0 : value.toLowerCase();
|
|
1131
|
+
};
|
|
1132
|
+
if (table.vars) {
|
|
1133
|
+
out.vars = {};
|
|
1134
|
+
for (const [name, ref2] of Object.entries(table.vars)) {
|
|
1135
|
+
const value = valueOf(`var "${name}"`, ref2);
|
|
1136
|
+
if (value !== void 0) out.vars[roleVar(name)] = value;
|
|
1137
|
+
}
|
|
1138
|
+
}
|
|
1139
|
+
if (problems.length) throw new Error(`rdsThemeFromTable(${table.name}):
|
|
1140
|
+
${problems.join("\n ")}`);
|
|
1141
|
+
return out;
|
|
1142
|
+
}
|
|
1105
1143
|
|
|
1106
1144
|
// generate/emitCss.ts
|
|
1107
1145
|
var SECTIONS = [
|
|
@@ -1323,4 +1361,4 @@ neutral 50 ${neutral[50]} \xB7 500 ${neutral[500]} \xB7 900 ${neutral[900]}
|
|
|
1323
1361
|
`;
|
|
1324
1362
|
}
|
|
1325
1363
|
|
|
1326
|
-
export { ROLES, SCALE_STEPS, brandTones, buildScale, contrastRatio, emitClaudeMd, emitCss, emitRdsCss, generateRdsTheme, generateTheme, hexToHsl, hslToHex, isHex, isNeutralBrand, onColor, rdsContrast, refToHex, relativeLuminance, resolveTheme, roleVar };
|
|
1364
|
+
export { ROLES, SCALE_STEPS, brandTones, buildScale, contrastRatio, emitClaudeMd, emitCss, emitRdsCss, generateRdsTheme, generateTheme, hexToHsl, hslToHex, isHex, isNeutralBrand, onColor, rdsContrast, rdsThemeFromTable, refToHex, relativeLuminance, resolveTheme, roleVar };
|
package/dist/generate.d.ts
CHANGED
|
@@ -3,7 +3,10 @@ import { a as BrandDef } from './recipe.schema-Cq7e82nx.js';
|
|
|
3
3
|
export { A as Archetype, B as BrandColors, C as ColorRef, D as DarkStrategy, F as FontDef, P as PaletteRef, S as ScaleToken, T as TextStyle, b as TextStyleName, c as TypeScale } from './recipe.schema-Cq7e82nx.js';
|
|
4
4
|
|
|
5
5
|
type RdsMode = "light" | "dark" | "brand";
|
|
6
|
-
type RdsTheme = Record<RdsMode, Record<string, string
|
|
6
|
+
type RdsTheme = Record<RdsMode, Record<string, string>> & {
|
|
7
|
+
/** The brand's own variables (Figma `brand` collection, `<brand>/<name>`), one value for every mode. */
|
|
8
|
+
vars?: Record<string, string>;
|
|
9
|
+
};
|
|
7
10
|
/**
|
|
8
11
|
* Roles of the [RDS] theme collection, in Figma order: [name, dark source, brand source].
|
|
9
12
|
* The light mode always reads the plain base token. In dark and brand, Figma points either to the
|
|
@@ -28,6 +31,21 @@ type RdsCssOptions = {
|
|
|
28
31
|
declare function emitRdsCss(theme: RdsTheme, opts?: RdsCssOptions): string;
|
|
29
32
|
/** Contrast of a role pair in one mode (alpha colours are not measured: they depend on what is below). */
|
|
30
33
|
declare function rdsContrast(theme: RdsTheme, mode: RdsMode, fg: string, bg: string): number | null;
|
|
34
|
+
/**
|
|
35
|
+
* A brand as drawn in the [RDS] Base Tokens file: for each theme mode, every role points to a primitive of the
|
|
36
|
+
* [RDS] Primitives library by name ("accyan/400"), and `primitives` holds the colour Figma resolves for each.
|
|
37
|
+
* Exported by `figma/export-brand.js`. The theme comes out one to one with the Figma brand mode.
|
|
38
|
+
*/
|
|
39
|
+
type RdsBrandTable = {
|
|
40
|
+
$schema?: "rds-brand-table/1";
|
|
41
|
+
name: string;
|
|
42
|
+
primitives: Record<string, string>;
|
|
43
|
+
modes: Record<RdsMode, Record<string, string>>;
|
|
44
|
+
/** The brand's own variables of the `brand` collection, by Figma path ("acassius/cyan") → primitive or value. */
|
|
45
|
+
vars?: Record<string, string>;
|
|
46
|
+
};
|
|
47
|
+
/** The theme of a brand table. Fails on a missing role or an unknown primitive, listing them all. */
|
|
48
|
+
declare function rdsThemeFromTable(table: RdsBrandTable): RdsTheme;
|
|
31
49
|
|
|
32
50
|
/**
|
|
33
51
|
* emitCss.ts — formata o output do generateTheme num theme.css legível.
|
|
@@ -110,4 +128,4 @@ declare function isNeutralBrand(def: {
|
|
|
110
128
|
palettes?: PaletteDefs;
|
|
111
129
|
}): boolean;
|
|
112
130
|
|
|
113
|
-
export { BrandDef, type ClaudeMdOptions, type ClaudeMdTarget, ROLES as RDS_ROLES, type RdsCssOptions, type RdsMode, type RdsTheme, SCALE_STEPS, type Scale, type ScaleStep, brandTones, buildScale, contrastRatio, emitClaudeMd, emitCss, emitRdsCss, generateRdsTheme, hexToHsl, hslToHex, isHex, isNeutralBrand, onColor, rdsContrast, refToHex, relativeLuminance, roleVar };
|
|
131
|
+
export { BrandDef, type ClaudeMdOptions, type ClaudeMdTarget, ROLES as RDS_ROLES, type RdsBrandTable, type RdsCssOptions, type RdsMode, type RdsTheme, SCALE_STEPS, type Scale, type ScaleStep, brandTones, buildScale, contrastRatio, emitClaudeMd, emitCss, emitRdsCss, generateRdsTheme, hexToHsl, hslToHex, isHex, isNeutralBrand, onColor, rdsContrast, rdsThemeFromTable, refToHex, relativeLuminance, roleVar };
|
package/dist/generate.js
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
export { ROLES as RDS_ROLES, SCALE_STEPS, brandTones, buildScale, contrastRatio, emitClaudeMd, emitCss, emitRdsCss, generateRdsTheme, generateTheme, hexToHsl, hslToHex, isHex, isNeutralBrand, onColor, rdsContrast, refToHex, relativeLuminance, resolveTheme, roleVar } from './chunk-
|
|
1
|
+
export { ROLES as RDS_ROLES, SCALE_STEPS, brandTones, buildScale, contrastRatio, emitClaudeMd, emitCss, emitRdsCss, generateRdsTheme, generateTheme, hexToHsl, hslToHex, isHex, isNeutralBrand, onColor, rdsContrast, rdsThemeFromTable, refToHex, relativeLuminance, resolveTheme, roleVar } from './chunk-XEVAQPW7.js';
|
|
2
2
|
import './chunk-FRWRLCYM.js';
|
|
3
3
|
import './chunk-ORMEWXMH.js';
|
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
export { G as GenResult, R as ResolvedTheme, T as TokenMap, g as generateTheme, r as resolveTheme } from './generateTheme-CUfNpsKs.js';
|
|
2
|
-
export { ClaudeMdOptions, ClaudeMdTarget, RDS_ROLES, RdsCssOptions, RdsMode, RdsTheme, SCALE_STEPS, Scale, ScaleStep, brandTones, buildScale, contrastRatio, emitClaudeMd, emitCss, emitRdsCss, generateRdsTheme, hexToHsl, hslToHex, isHex, isNeutralBrand, onColor, rdsContrast, refToHex, relativeLuminance, roleVar } from './generate.js';
|
|
2
|
+
export { ClaudeMdOptions, ClaudeMdTarget, RDS_ROLES, RdsBrandTable, RdsCssOptions, RdsMode, RdsTheme, SCALE_STEPS, Scale, ScaleStep, brandTones, buildScale, contrastRatio, emitClaudeMd, emitCss, emitRdsCss, generateRdsTheme, hexToHsl, hslToHex, isHex, isNeutralBrand, onColor, rdsContrast, rdsThemeFromTable, refToHex, relativeLuminance, roleVar } from './generate.js';
|
|
3
3
|
export { A as Archetype, B as BrandColors, a as BrandDef, C as ColorRef, D as DarkStrategy, F as FontDef, P as PaletteRef, S as ScaleToken, T as TextStyle, b as TextStyleName, c as TypeScale } from './recipe.schema-Cq7e82nx.js';
|
|
4
4
|
export { primitives, tokens } from './tokens.js';
|
|
5
5
|
export { RecipeName, recipes } from './recipes.js';
|
package/dist/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
export { recipes } from './chunk-3QTDO2HW.js';
|
|
2
|
-
export { ROLES as RDS_ROLES, SCALE_STEPS, brandTones, buildScale, contrastRatio, emitClaudeMd, emitCss, emitRdsCss, generateRdsTheme, generateTheme, hexToHsl, hslToHex, isHex, isNeutralBrand, onColor, rdsContrast, refToHex, relativeLuminance, resolveTheme, roleVar } from './chunk-
|
|
2
|
+
export { ROLES as RDS_ROLES, SCALE_STEPS, brandTones, buildScale, contrastRatio, emitClaudeMd, emitCss, emitRdsCss, generateRdsTheme, generateTheme, hexToHsl, hslToHex, isHex, isNeutralBrand, onColor, rdsContrast, rdsThemeFromTable, refToHex, relativeLuminance, resolveTheme, roleVar } from './chunk-XEVAQPW7.js';
|
|
3
3
|
export { primitives, tokens } from './chunk-FRWRLCYM.js';
|
|
4
4
|
import './chunk-ORMEWXMH.js';
|
package/dist/themes.js
CHANGED
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
/* global figma */
|
|
2
|
+
// Exports one brand of the [RDS] Base Tokens file as a brand table for rdsThemeFromTable().
|
|
3
|
+
// Run inside the Base Tokens file with the Figma Plugin API (a plugin console or an agent with use_figma),
|
|
4
|
+
// after setting BRAND to the mode name of the `base` collection. The return value is the JSON to save.
|
|
5
|
+
//
|
|
6
|
+
// Each theme role is followed through the aliases of the `base` collection (in the brand's mode) down to a
|
|
7
|
+
// primitive of the [RDS] Primitives library, kept by name ("accyan/400") with the colour Figma resolves.
|
|
8
|
+
// The brand's own variables in the `brand` collection (`<brand>/<name>`, as acassius/cyan) come along in `vars`.
|
|
9
|
+
const BRAND = "rojao";
|
|
10
|
+
|
|
11
|
+
const cols = await figma.variables.getLocalVariableCollectionsAsync();
|
|
12
|
+
const base = cols.find((c) => c.name === "base");
|
|
13
|
+
const theme = cols.find((c) => c.name === "theme");
|
|
14
|
+
if (!base || !theme) throw new Error("open the [RDS] Base Tokens file");
|
|
15
|
+
const brandMode = base.modes.find((m) => m.name === BRAND);
|
|
16
|
+
if (!brandMode) throw new Error(`no brand "${BRAND}" in base: ${base.modes.map((m) => m.name).join(", ")}`);
|
|
17
|
+
const local = new Set(cols.map((c) => c.id));
|
|
18
|
+
|
|
19
|
+
const hex = (c) =>
|
|
20
|
+
"#" +
|
|
21
|
+
[c.r, c.g, c.b].map((x) => Math.round(x * 255).toString(16).padStart(2, "0")).join("") +
|
|
22
|
+
(c.a !== undefined && c.a < 1 ? Math.round(c.a * 255).toString(16).padStart(2, "0") : "");
|
|
23
|
+
const literal = (v, val) => (v.resolvedType === "COLOR" ? hex(val) : String(val));
|
|
24
|
+
const isAlias = (val) => val && typeof val === "object" && val.type === "VARIABLE_ALIAS";
|
|
25
|
+
|
|
26
|
+
const primitives = {};
|
|
27
|
+
async function resolve(v, themeMode) {
|
|
28
|
+
if (!local.has(v.variableCollectionId)) {
|
|
29
|
+
// A Primitives library variable: keep its name, record what it resolves to.
|
|
30
|
+
const val = Object.values(v.valuesByMode)[0];
|
|
31
|
+
if (isAlias(val)) return resolve(await figma.variables.getVariableByIdAsync(val.id), themeMode);
|
|
32
|
+
primitives[v.name] = literal(v, val);
|
|
33
|
+
return v.name;
|
|
34
|
+
}
|
|
35
|
+
const modeId = v.variableCollectionId === base.id ? brandMode.modeId
|
|
36
|
+
: v.variableCollectionId === theme.id ? themeMode : Object.keys(v.valuesByMode)[0];
|
|
37
|
+
const val = v.valuesByMode[modeId] ?? Object.values(v.valuesByMode)[0];
|
|
38
|
+
if (isAlias(val)) return resolve(await figma.variables.getVariableByIdAsync(val.id), themeMode);
|
|
39
|
+
return literal(v, val);
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
const modes = {};
|
|
43
|
+
for (const m of theme.modes) {
|
|
44
|
+
const roles = {};
|
|
45
|
+
for (const id of theme.variableIds) {
|
|
46
|
+
const v = await figma.variables.getVariableByIdAsync(id);
|
|
47
|
+
roles[v.name] = await resolve(v, m.modeId);
|
|
48
|
+
}
|
|
49
|
+
modes[m.name] = roles;
|
|
50
|
+
}
|
|
51
|
+
const vars = {};
|
|
52
|
+
const brandCol = cols.find((c) => c.name === "brand");
|
|
53
|
+
for (const id of brandCol?.variableIds ?? []) {
|
|
54
|
+
const v = await figma.variables.getVariableByIdAsync(id);
|
|
55
|
+
if (v.name.startsWith(`${BRAND}/`)) vars[v.name] = await resolve(v, theme.modes[0].modeId);
|
|
56
|
+
}
|
|
57
|
+
const sorted = Object.fromEntries(Object.entries(primitives).sort(([a], [b]) => a.localeCompare(b)));
|
|
58
|
+
return { $schema: "rds-brand-table/1", name: BRAND, primitives: sorted, modes, vars };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@rojaostudio/ds-core",
|
|
3
|
-
"version": "1.1.0-next.
|
|
3
|
+
"version": "1.1.0-next.3",
|
|
4
4
|
"description": "O motor do Rojão DS — tokens, derivação de tema e emissores. Sem React, sem Tailwind, sem CSS.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"author": "Rojão Studio (https://rojao.studio)",
|
|
@@ -54,7 +54,8 @@
|
|
|
54
54
|
"files": [
|
|
55
55
|
"LICENSE",
|
|
56
56
|
"README.md",
|
|
57
|
-
"dist"
|
|
57
|
+
"dist",
|
|
58
|
+
"figma/export-brand.js"
|
|
58
59
|
],
|
|
59
60
|
"devDependencies": {
|
|
60
61
|
"eslint": "^9.18.0",
|