argot-css 0.0.0-stage → 0.0.1
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/LICENSE.md +20 -0
- package/README.md +259 -2
- package/bin/argot.js +4 -0
- package/dist/cli/ansiColors.d.ts +7 -0
- package/dist/cli/ansiColors.js +8 -0
- package/dist/cli/ansiColors.js.map +1 -0
- package/dist/cli/print.d.ts +2 -0
- package/dist/cli/print.js +13 -0
- package/dist/cli/print.js.map +1 -0
- package/dist/cli/run.d.ts +2 -0
- package/dist/cli/run.js +34 -0
- package/dist/cli/run.js.map +1 -0
- package/dist/cli/usage.d.ts +2 -0
- package/dist/cli/usage.js +17 -0
- package/dist/cli/usage.js.map +1 -0
- package/dist/palette/cli.d.ts +2 -0
- package/dist/palette/cli.js +33 -0
- package/dist/palette/cli.js.map +1 -0
- package/dist/palette/generateName.d.ts +3 -0
- package/dist/palette/generateName.js +65 -0
- package/dist/palette/generateName.js.map +1 -0
- package/dist/palette/generatePalette.d.ts +7 -0
- package/dist/palette/generatePalette.js +97 -0
- package/dist/palette/generatePalette.js.map +1 -0
- package/dist/palette/index.d.ts +5 -0
- package/dist/palette/index.js +6 -0
- package/dist/palette/index.js.map +1 -0
- package/dist/palette/node.d.ts +19 -0
- package/dist/palette/node.js +70 -0
- package/dist/palette/node.js.map +1 -0
- package/dist/palette/parseCssColor.d.ts +7 -0
- package/dist/palette/parseCssColor.js +41 -0
- package/dist/palette/parseCssColor.js.map +1 -0
- package/dist/palette/render.d.ts +8 -0
- package/dist/palette/render.js +49 -0
- package/dist/palette/render.js.map +1 -0
- package/dist/palette/types.d.ts +50 -0
- package/dist/palette/types.js +2 -0
- package/dist/palette/types.js.map +1 -0
- package/dist/palette/validation.d.ts +13 -0
- package/dist/palette/validation.js +110 -0
- package/dist/palette/validation.js.map +1 -0
- package/dist/processor/atImport.d.ts +4 -0
- package/dist/processor/atImport.js +149 -0
- package/dist/processor/atImport.js.map +1 -0
- package/dist/processor/cli.d.ts +1 -0
- package/dist/processor/cli.js +32 -0
- package/dist/processor/cli.js.map +1 -0
- package/dist/processor/index.d.ts +7 -0
- package/dist/processor/index.js +47 -0
- package/dist/processor/index.js.map +1 -0
- package/dist/processor/parseImportParams.d.ts +19 -0
- package/dist/processor/parseImportParams.js +139 -0
- package/dist/processor/parseImportParams.js.map +1 -0
- package/dist/processor/stylelintDefault.d.ts +4 -0
- package/dist/processor/stylelintDefault.js +19 -0
- package/dist/processor/stylelintDefault.js.map +1 -0
- package/dist/semantics/cli.d.ts +2 -0
- package/dist/semantics/cli.js +34 -0
- package/dist/semantics/cli.js.map +1 -0
- package/dist/semantics/generate.d.ts +16 -0
- package/dist/semantics/generate.js +53 -0
- package/dist/semantics/generate.js.map +1 -0
- package/dist/semantics/load-tokens.d.ts +29 -0
- package/dist/semantics/load-tokens.js +74 -0
- package/dist/semantics/load-tokens.js.map +1 -0
- package/dist/semantics/token-index.d.ts +14 -0
- package/dist/semantics/token-index.js +30 -0
- package/dist/semantics/token-index.js.map +1 -0
- package/dist/stylelint/config.d.ts +16 -0
- package/dist/stylelint/config.js +19 -0
- package/dist/stylelint/config.js.map +1 -0
- package/dist/stylelint/index.d.ts +3 -0
- package/dist/stylelint/index.js +4 -0
- package/dist/stylelint/index.js.map +1 -0
- package/dist/stylelint/rules/valid-token.d.ts +3 -0
- package/dist/stylelint/rules/valid-token.js +32 -0
- package/dist/stylelint/rules/valid-token.js.map +1 -0
- package/docs/api.md +514 -0
- package/package.json +115 -4
- package/templates/base.css +53 -0
- package/templates/modules/index.css +0 -0
- package/templates/semantics-extended.css +115 -0
- package/templates/semantics.css +94 -0
- package/templates/styles.css +7 -0
- package/tokens/borders.json +37 -0
- package/tokens/color-bg.json +104 -0
- package/tokens/color-border.json +59 -0
- package/tokens/color-chart.json +40 -0
- package/tokens/color-icon.json +53 -0
- package/tokens/color-text.json +107 -0
- package/tokens/layout.json +66 -0
- package/tokens/misc.json +16 -0
- package/tokens/motion.json +40 -0
- package/tokens/spacing.json +41 -0
- package/tokens/typography.json +107 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"atImport.js","sourceRoot":"","sources":["../../src/processor/atImport.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,kBAAkB,CAAC;AAClC,OAAO,IAAI,MAAM,WAAW,CAAC;AAC7B,OAAO,OAAO,EAAE,EAA8C,MAAM,SAAS,CAAC;AAC9E,OAAO,EAAE,iBAAiB,EAAqB,MAAM,wBAAwB,CAAC;AAI9E,MAAM,UAAU,GAAG,oBAAoB,CAAC;AACxC,MAAM,QAAQ,GAAG,SAAS,CAAC;AAE3B,MAAM,QAAQ,GAAwC,GAAG,EAAE,CAAC,CAAC;IAC3D,aAAa,EAAE,cAAc;IAC7B,KAAK,CAAC,IAAI,CAAC,IAAI,EAAE,EAAE,MAAM,EAAE;QACzB,MAAM,QAAQ,GAAG,IAAI,CAAC,MAAM,EAAE,KAAK,CAAC,IAAI,IAAI,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC;QAC7D,IAAI,CAAC,QAAQ,EAAE,CAAC;YACd,MAAM,IAAI,CAAC,KAAK,CACd,6GAA6G,CAC9G,CAAC;QACJ,CAAC;QAED,MAAM,YAAY,GAAG,IAAI,CAAC,OAAO,CAAC,QAAQ,CAAC,CAAC;QAC5C,MAAM,aAAa,GAAG,IAAI,GAAG,CAAS,CAAC,YAAY,CAAC,CAAC,CAAC;QACtD,MAAM,WAAW,CAAC,IAAI,EAAE,YAAY,EAAE,CAAC,YAAY,CAAC,EAAE,aAAa,CAAC,CAAC;IACvE,CAAC;CACF,CAAC,CAAC;AACH,QAAQ,CAAC,OAAO,GAAG,IAAI,CAAC;AAExB,KAAK,UAAU,WAAW,CACxB,IAAU,EACV,QAAgB,EAChB,KAAe,EACf,aAA0B;IAE1B,MAAM,OAAO,GAAa,EAAE,CAAC;IAC7B,IAAI,CAAC,WAAW,CAAC,QAAQ,EAAE,CAAC,MAAM,EAAE,EA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AO;IACT,CAAC;IAED,gEAAgE;IAChE,aAAa,CAAC,MAAM,CAAC,CAAC;IACtB,MAAM,CAAC,WAAW,CAAC,QAAQ,CAAC,CAAC;AAC/B,CAAC;AAED,SAAS,QAAQ,CAAC,GAAW;IAC3B,OAAO,UAAU,CAAC,IAAI,CAAC,GAAG,CAAC,IAAI,QAAQ,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;AACpD,CAAC;AAED,SAAS,cAAc,CAAC,KAA+B;IACrD,IAAI,KAAK,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;QACvB,OAAO;IACT,CAAC;IACD,KAAK,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,MAAM,GAAG,IAAI,CAAC;AAC9B,CAAC;AAED,SAAS,aAAa,CAAC,MAAc;IACnC,2EAA2E;IAC3E,4EAA4E;IAC5E,MAAM,IAAI,GAAG,MAAM,CAAC,IAAI,EAAE,CAAC;IAC3B,IAAI,IAAI,EAAE,CAAC;QACT,IAAI,CAAC,IAAI,CAAC,MAAM,GAAG,KAAK,IAAI,CAAC,IAAI,CAAC,MAAM,IAAI,EAAE,EAAE,CAAC;QACjD,OAAO;IACT,CAAC;IACD,MAAM,MAAM,GAAG,MAAM,CAAC,MAAM,CAAC;IAC7B,IAAI,MAAM,EAAE,CAAC;QACX,MAAM,CAAC,IAAI,CAAC,KAAK,GAAG,KAAK,MAAM,CAAC,IAAI,CAAC,KAAK,IAAI,EAAE,EAAE,CAAC;IACrD,CAAC;AACH,CAAC;AAED,eAAe,QAAQ,CAAC","sourcesContent":["import fs from 'node:fs/promises';\nimport path from 'node:path';\nimport postcss, { type AtRule, type PluginCreator, type Root } from 'postcss';\nimport { parseImportParams, type ParsedImport } from './parseImportParams.ts';\n\nexport type ImportOptions = Record<string, never>;\n\nconst REMOTE_URI = /^(?:[a-z]+:)?\\/\\//i;\nconst DATA_URI = /^data:/i;\n\nconst atImport: PluginCreator<ImportOptions | void> = () => ({\n postcssPlugin: 'argot-import',\n async Once(root, { result }) {\n const fromFile = root.source?.input.file ?? result.opts.from;\n if (!fromFile) {\n throw root.error(\n 'argot-import requires the PostCSS `from` option (or a file input) so relative @import paths can be resolved',\n );\n }\n\n const resolvedFrom = path.resolve(fromFile);\n const importedFiles = new Set<string>([resolvedFrom]);\n await processRoot(root, resolvedFrom, [resolvedFrom], importedFiles);\n },\n});\natImport.postcss = true;\n\nasync function processRoot(\n root: Root,\n fromFile: string,\n stack: string[],\n importedFiles: Set<string>,\n): Promise<void> {\n const imports: AtRule[] = [];\n root.walkAtRules('import', (atRule) => {\n imports.push(atRule);\n });\n\n for (const atRule of imports) {\n if (!atRule.parent) {\n // Skip if already detached from the tree\n continue;\n }\n await processImport(atRule, fromFile, stack, importedFiles);\n }\n}\n\nasync function processImport(\n atRule: AtRule,\n fromFile: string,\n stack: string[],\n importedFiles: Set<string>,\n): Promise<void> {\n const importParams = parseImportParams(atRule.params);\n if (!importParams) {\n throw atRule.error(\n `Invalid @import parameters '${atRule.params}'. ` +\n `Expected a local path or url(), optionally followed by layer, scope, supports, and media conditions.`,\n );\n }\n if (isRemote(importParams.uri)) {\n return;\n }\n\n const importFile = path.resolve(path.dirname(fromFile), importParams.uri);\n\n if (stack.includes(importFile)) {\n const chain = [...stack, importFile]\n .map((file) => path.relative(process.cwd(), file) || file)\n .join(' -> ');\n throw atRule.error(`Circular @import: ${chain}`);\n }\n\n if (importedFiles.has(importFile)) {\n atRule.remove();\n return;\n }\n\n let css: string;\n try {\n css = await fs.readFile(importFile, 'utf8');\n } catch {\n throw atRule.error(\n `Failed to find CSS file to import: ${importParams.uri}`,\n {\n word: importParams.uri,\n },\n );\n }\n\n importedFiles.add(importFile);\n stack.push(importFile);\n\n let childRoot: Root;\n try {\n childRoot = postcss.parse(css, { from: importFile });\n await processRoot(childRoot, importFile, stack, importedFiles);\n } finally {\n stack.pop();\n }\n\n replaceImportWithContents(atRule, childRoot.nodes, importParams);\n}\n\nfunction replaceImportWithContents(\n atRule: AtRule,\n nodes: Root['nodes'],\n importParams: ParsedImport,\n): void {\n const { layer, scope, supports, media } = importParams;\n let contents: Root['nodes'] | AtRule[] = nodes;\n\n // Nest outside-in as layer → scope → supports → media → content.\n if (media !== undefined) {\n const mediaRule = postcss.atRule({\n name: 'media',\n params: media,\n source: atRule.source,\n });\n prependNewline(contents);\n mediaRule.append(contents);\n contents = [mediaRule];\n }\n if (supports !== undefined) {\n const supportsRule = postcss.atRule({\n name: 'supports',\n params: `(${supports})`,\n source: atRule.source,\n });\n prependNewline(contents);\n supportsRule.append(contents);\n contents = [supportsRule];\n }\n if (scope !== undefined) {\n const scopeRule = postcss.atRule({\n name: 'scope',\n params: scope,\n source: atRule.source,\n });\n prependNewline(contents);\n scopeRule.append(contents);\n contents = [scopeRule];\n }\n if (layer !== undefined) {\n const layerRule = postcss.atRule({\n name: 'layer',\n params: layer,\n source: atRule.source,\n });\n prependNewline(contents);\n layerRule.append(contents);\n contents = [layerRule];\n }\n\n if (contents.length === 0) {\n atRule.remove();\n return;\n }\n\n // keep pretty formatting to lint rule isn't triggered by output\n appendNewline(atRule);\n atRule.replaceWith(contents);\n}\n\nfunction isRemote(uri: string): boolean {\n return REMOTE_URI.test(uri) || DATA_URI.test(uri);\n}\n\nfunction prependNewline(nodes: Root['nodes'] | AtRule[]): void {\n if (nodes.length === 0) {\n return;\n }\n nodes[0].raws.before = '\\n';\n}\n\nfunction appendNewline(atRule: AtRule): void {\n // Space after a node lives on the next sibling's `before`, or the parent's\n // `after` when this is the last child (Root trailing newline / before `}`).\n const next = atRule.next();\n if (next) {\n next.raws.before = `\\n${next.raws.before ?? ''}`;\n return;\n }\n const parent = atRule.parent;\n if (parent) {\n parent.raws.after = `\\n${parent.raws.after ?? ''}`;\n }\n}\n\nexport default atImport;\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function runProcessor(args: string[]): Promise<void>;
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import fs from 'node:fs/promises';
|
|
2
|
+
import { parseArgs } from 'node:util';
|
|
3
|
+
import path from 'node:path';
|
|
4
|
+
import { processStylesheet } from "./index.js";
|
|
5
|
+
import { print, printError } from "../cli/print.js";
|
|
6
|
+
import { ANSI_YELLOW } from "../cli/ansiColors.js";
|
|
7
|
+
const USAGE = 'Usage: argot <input.css> <output.css> [--lint-config="path/to/config.js"]';
|
|
8
|
+
export async function runProcessor(args) {
|
|
9
|
+
// TODO: helper for parseArgs. catches TypeError and prints help string
|
|
10
|
+
const { positionals, values } = parseArgs({
|
|
11
|
+
args,
|
|
12
|
+
allowPositionals: true,
|
|
13
|
+
options: {
|
|
14
|
+
'lint-config': { type: 'string', short: 'c' },
|
|
15
|
+
help: { type: 'boolean', short: 'h', default: false },
|
|
16
|
+
verbose: { type: 'boolean' },
|
|
17
|
+
},
|
|
18
|
+
});
|
|
19
|
+
if (positionals.length !== 2) {
|
|
20
|
+
printError(`Error: Expected 2 positional arguments but got ${positionals.length}`);
|
|
21
|
+
print(USAGE, ANSI_YELLOW);
|
|
22
|
+
return;
|
|
23
|
+
}
|
|
24
|
+
if (values.help) {
|
|
25
|
+
print(USAGE, ANSI_YELLOW);
|
|
26
|
+
}
|
|
27
|
+
const source = path.resolve(process.cwd(), positionals[0]);
|
|
28
|
+
const dest = path.resolve(process.cwd(), positionals[1]);
|
|
29
|
+
await fs.mkdir(path.dirname(dest), { recursive: true });
|
|
30
|
+
return await processStylesheet(source, dest, values['lint-config']);
|
|
31
|
+
}
|
|
32
|
+
//# sourceMappingURL=cli.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"cli.js","sourceRoot":"","sources":["../../src/processor/cli.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,kBAAkB,CAAC;AAClC,OAAO,EAAE,SAAS,EAAE,MAAM,WAAW,CAAC;AACtC,OAAO,IAAI,MAAM,WAAW,CAAC;AAC7B,OAAO,EAAE,iBAAiB,EAAE,MAAM,YAAY,CAAC;AAC/C,OAAO,EAAE,KAA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AE,IAAI,EAAE,MAAM,CAAC,aAAa,CAAC,CAAC,CAAC;AACtE,CAAC","sourcesContent":["import fs from 'node:fs/promises';\nimport { parseArgs } from 'node:util';\nimport path from 'node:path';\nimport { processStylesheet } from './index.ts';\nimport { print, printError } from '../cli/print.ts';\nimport { ANSI_YELLOW } from '../cli/ansiColors.ts';\n\nconst USAGE =\n 'Usage: argot <input.css> <output.css> [--lint-config=\"path/to/config.js\"]';\n\nexport async function runProcessor(args: string[]) {\n // TODO: helper for parseArgs. catches TypeError and prints help string\n const { positionals, values } = parseArgs({\n args,\n allowPositionals: true,\n options: {\n 'lint-config': { type: 'string', short: 'c' },\n help: { type: 'boolean', short: 'h', default: false },\n verbose: { type: 'boolean' },\n },\n });\n if (positionals.length !== 2) {\n printError(\n `Error: Expected 2 positional arguments but got ${positionals.length}`,\n );\n print(USAGE, ANSI_YELLOW);\n return;\n }\n if (values.help) {\n print(USAGE, ANSI_YELLOW);\n }\n\n const source = path.resolve(process.cwd(), positionals[0]);\n const dest = path.resolve(process.cwd(), positionals[1]);\n await fs.mkdir(path.dirname(dest), { recursive: true });\n\n return await processStylesheet(source, dest, values['lint-config']);\n}\n"]}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Processes stylesheet and outputs destination css
|
|
3
|
+
* @param sourceFile fully-qualified source filename
|
|
4
|
+
* @param destFile fully-qualified destination filename
|
|
5
|
+
*/
|
|
6
|
+
declare function processStylesheet(sourceFile: string, destFile: string, lintConfigFile?: string): Promise<void>;
|
|
7
|
+
export { processStylesheet };
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import fs from 'node:fs/promises';
|
|
2
|
+
import postcss from 'postcss';
|
|
3
|
+
import reporter from 'postcss-reporter';
|
|
4
|
+
import cssnano from 'cssnano';
|
|
5
|
+
import stylelint from 'stylelint';
|
|
6
|
+
import atImport from "./atImport.js";
|
|
7
|
+
import { print } from "../cli/print.js";
|
|
8
|
+
import { ANSI_GREEN } from "../cli/ansiColors.js";
|
|
9
|
+
import defaultLintConfig from "./stylelintDefault.js";
|
|
10
|
+
/**
|
|
11
|
+
* Processes stylesheet and outputs destination css
|
|
12
|
+
* @param sourceFile fully-qualified source filename
|
|
13
|
+
* @param destFile fully-qualified destination filename
|
|
14
|
+
*/
|
|
15
|
+
async function processStylesheet(sourceFile, destFile, lintConfigFile) {
|
|
16
|
+
let css;
|
|
17
|
+
try {
|
|
18
|
+
css = await fs.readFile(sourceFile, 'utf8');
|
|
19
|
+
}
|
|
20
|
+
catch (error) {
|
|
21
|
+
throw new Error(`Cannot read stylesheet "${sourceFile}": ${error.code}`, { cause: error });
|
|
22
|
+
}
|
|
23
|
+
const result = await postcss([
|
|
24
|
+
atImport(),
|
|
25
|
+
getStylelint(lintConfigFile),
|
|
26
|
+
cssnano(),
|
|
27
|
+
reporter({ clearReportedMessages: true }),
|
|
28
|
+
]).process(css, {
|
|
29
|
+
from: sourceFile,
|
|
30
|
+
to: destFile,
|
|
31
|
+
});
|
|
32
|
+
try {
|
|
33
|
+
await fs.writeFile(destFile, result.css);
|
|
34
|
+
print(`Wrote output CSS: ${destFile}`, ANSI_GREEN);
|
|
35
|
+
}
|
|
36
|
+
catch (error) {
|
|
37
|
+
throw new Error(`Cannot write stylesheet ${destFile}: ${error.code}`, { cause: error });
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
function getStylelint(userConfigFile) {
|
|
41
|
+
if (userConfigFile) {
|
|
42
|
+
return stylelint({ configFile: userConfigFile });
|
|
43
|
+
}
|
|
44
|
+
return stylelint({ config: defaultLintConfig });
|
|
45
|
+
}
|
|
46
|
+
export { processStylesheet };
|
|
47
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/processor/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,kBAAkB,CAAC;AAClC,OAAO,OAAO,MAAM,SAAS,CAAC;AAC9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,KAAK,EAAE,KAAK,EAAE,CACjB,CAAC;IACJ,CAAC;AACH,CAAC;AAED,SAAS,YAAY,CAAC,cAAuB;IAC3C,IAAI,cAAc,EAAE,CAAC;QACnB,OAAO,SAAS,CAAC,EAAE,UAAU,EAAE,cAAc,EAAE,CAAC,CAAC;IACnD,CAAC;IAED,OAAO,SAAS,CAAC,EAAE,MAAM,EAAE,iBAAiB,EAAE,CAAC,CAAC;AAClD,CAAC;AAED,OAAO,EAAE,iBAAiB,EAAE,CAAC","sourcesContent":["import fs from 'node:fs/promises';\nimport postcss from 'postcss';\nimport reporter from 'postcss-reporter';\nimport cssnano from 'cssnano';\nimport stylelint from 'stylelint';\nimport atImport from './atImport.ts';\nimport { print } from '../cli/print.ts';\nimport { ANSI_GREEN } from '../cli/ansiColors.ts';\nimport defaultLintConfig from './stylelintDefault.ts';\n\n/**\n * Processes stylesheet and outputs destination css\n * @param sourceFile fully-qualified source filename\n * @param destFile fully-qualified destination filename\n */\nasync function processStylesheet(\n sourceFile: string,\n destFile: string,\n lintConfigFile?: string,\n) {\n let css;\n try {\n css = await fs.readFile(sourceFile, 'utf8');\n } catch (error) {\n throw new Error(\n `Cannot read stylesheet \"${sourceFile}\": ${(error as NodeJS.ErrnoException).code}`,\n { cause: error },\n );\n }\n\n const result = await postcss([\n atImport(),\n getStylelint(lintConfigFile),\n cssnano(),\n reporter({ clearReportedMessages: true }),\n ]).process(css, {\n from: sourceFile,\n to: destFile,\n });\n\n try {\n await fs.writeFile(destFile, result.css);\n print(`Wrote output CSS: ${destFile}`, ANSI_GREEN);\n } catch (error) {\n throw new Error(\n `Cannot write stylesheet ${destFile}: ${(error as NodeJS.ErrnoException).code}`,\n { cause: error },\n );\n }\n}\n\nfunction getStylelint(userConfigFile?: string) {\n if (userConfigFile) {\n return stylelint({ configFile: userConfigFile });\n }\n\n return stylelint({ config: defaultLintConfig });\n}\n\nexport { processStylesheet };\n"]}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
export type ParsedImport = {
|
|
2
|
+
uri: string;
|
|
3
|
+
/** Present when `layer` or `layer(name)` appears; empty string is anonymous. */
|
|
4
|
+
layer?: string;
|
|
5
|
+
/**
|
|
6
|
+
* Present when `scope` or `scope(...)` appears; empty string is bare `@scope`.
|
|
7
|
+
*/
|
|
8
|
+
scope?: string;
|
|
9
|
+
/** Inner condition from `supports(...)`, when present. */
|
|
10
|
+
supports?: string;
|
|
11
|
+
/** Comma-separated media queries, when present */
|
|
12
|
+
media?: string;
|
|
13
|
+
};
|
|
14
|
+
/**
|
|
15
|
+
* Parse `@import` params per CSS Cascade Level 6:
|
|
16
|
+
* uri/path, then layer / scope / supports in any order, then media.
|
|
17
|
+
* Returns null when the prelude is empty or not a string/url form.
|
|
18
|
+
*/
|
|
19
|
+
export declare function parseImportParams(params: string): ParsedImport | null;
|
|
@@ -0,0 +1,139 @@
|
|
|
1
|
+
const STRING_PATH_PATTERN = /^(['"])([\s\S]*?)\1\s*([\s\S]*)$/;
|
|
2
|
+
const URL_PATH_PATTERN = /^url\(\s*(['"]?)([\s\S]*?)\1\s*\)\s*([\s\S]*)$/i;
|
|
3
|
+
const FUNCTION_PATTERN = /[A-Za-z0-9]+\(/i;
|
|
4
|
+
/**
|
|
5
|
+
* Parse `@import` params per CSS Cascade Level 6:
|
|
6
|
+
* uri/path, then layer / scope / supports in any order, then media.
|
|
7
|
+
* Returns null when the prelude is empty or not a string/url form.
|
|
8
|
+
*/
|
|
9
|
+
export function parseImportParams(params) {
|
|
10
|
+
const trimmed = params.trim();
|
|
11
|
+
if (!trimmed)
|
|
12
|
+
return null;
|
|
13
|
+
let uri;
|
|
14
|
+
let rest;
|
|
15
|
+
// find uri path
|
|
16
|
+
const stringMatch = STRING_PATH_PATTERN.exec(trimmed);
|
|
17
|
+
if (stringMatch) {
|
|
18
|
+
uri = stringMatch[2];
|
|
19
|
+
rest = stringMatch[3] ?? '';
|
|
20
|
+
}
|
|
21
|
+
else {
|
|
22
|
+
const urlMatch = URL_PATH_PATTERN.exec(trimmed);
|
|
23
|
+
if (!urlMatch)
|
|
24
|
+
return null;
|
|
25
|
+
uri = urlMatch[2];
|
|
26
|
+
rest = urlMatch[3] ?? '';
|
|
27
|
+
}
|
|
28
|
+
if (!uri)
|
|
29
|
+
return null;
|
|
30
|
+
rest = rest.trim();
|
|
31
|
+
if (!rest) {
|
|
32
|
+
return { uri };
|
|
33
|
+
}
|
|
34
|
+
let layer = null;
|
|
35
|
+
let scope = null;
|
|
36
|
+
let supports = null;
|
|
37
|
+
// layer || scope || supports, at most once each, any order.
|
|
38
|
+
while (rest) {
|
|
39
|
+
const layerMatch = matchKeywordOrFunction(rest, 'layer', {
|
|
40
|
+
allowBare: true,
|
|
41
|
+
});
|
|
42
|
+
if (layerMatch) {
|
|
43
|
+
if (layer !== null)
|
|
44
|
+
return null;
|
|
45
|
+
layer = layerMatch.args === null ? '' : layerMatch.args.trim();
|
|
46
|
+
rest = layerMatch.rest.trim();
|
|
47
|
+
continue;
|
|
48
|
+
}
|
|
49
|
+
const scopeMatch = matchKeywordOrFunction(rest, 'scope', {
|
|
50
|
+
allowBare: true,
|
|
51
|
+
});
|
|
52
|
+
if (scopeMatch) {
|
|
53
|
+
if (scope !== null)
|
|
54
|
+
return null;
|
|
55
|
+
scope = normalizeScopePrelude(scopeMatch.args);
|
|
56
|
+
rest = scopeMatch.rest.trim();
|
|
57
|
+
continue;
|
|
58
|
+
}
|
|
59
|
+
const supportsMatch = matchKeywordOrFunction(rest, 'supports', {
|
|
60
|
+
allowBare: false,
|
|
61
|
+
});
|
|
62
|
+
if (supportsMatch) {
|
|
63
|
+
if (supports !== null)
|
|
64
|
+
return null;
|
|
65
|
+
supports = supportsMatch.args ?? '';
|
|
66
|
+
rest = supportsMatch.rest.trim();
|
|
67
|
+
continue;
|
|
68
|
+
}
|
|
69
|
+
break;
|
|
70
|
+
}
|
|
71
|
+
// Reject remaining function-like syntax (unknown modifiers before media).
|
|
72
|
+
if (FUNCTION_PATTERN.exec(rest)) {
|
|
73
|
+
return null;
|
|
74
|
+
}
|
|
75
|
+
return {
|
|
76
|
+
uri,
|
|
77
|
+
...(layer !== null && { layer }),
|
|
78
|
+
...(scope !== null && { scope }),
|
|
79
|
+
...(supports !== null && { supports }),
|
|
80
|
+
...(rest && { media: rest }),
|
|
81
|
+
};
|
|
82
|
+
}
|
|
83
|
+
/**
|
|
84
|
+
* If `input` starts with `name` or `name(...)`, return args and the remainder.
|
|
85
|
+
* `args` is null for a bare keyword; a string for the function form.
|
|
86
|
+
* Nested parentheses are counted so `oklch(…)` / `scope((…) to (…))` work.
|
|
87
|
+
*/
|
|
88
|
+
function matchKeywordOrFunction(input, name, { allowBare }) {
|
|
89
|
+
if (!input.toLowerCase().startsWith(name.toLowerCase()))
|
|
90
|
+
return null;
|
|
91
|
+
const afterName = input.slice(name.length);
|
|
92
|
+
// Require a complete ident token (`layer` not `layerfoo`).
|
|
93
|
+
if (afterName.length > 0 && /[A-Za-z0-9_-]/.test(afterName[0])) {
|
|
94
|
+
return null;
|
|
95
|
+
}
|
|
96
|
+
let i = name.length;
|
|
97
|
+
while (i < input.length && /\s/.test(input[i]))
|
|
98
|
+
i++;
|
|
99
|
+
if (input[i] !== '(') {
|
|
100
|
+
if (!allowBare)
|
|
101
|
+
return null;
|
|
102
|
+
return { args: null, rest: input.slice(name.length).trimStart() };
|
|
103
|
+
}
|
|
104
|
+
i++;
|
|
105
|
+
const start = i;
|
|
106
|
+
let depth = 1;
|
|
107
|
+
while (i < input.length && depth > 0) {
|
|
108
|
+
const ch = input[i];
|
|
109
|
+
if (ch === '(')
|
|
110
|
+
depth++;
|
|
111
|
+
else if (ch === ')')
|
|
112
|
+
depth--;
|
|
113
|
+
i++;
|
|
114
|
+
}
|
|
115
|
+
if (depth !== 0)
|
|
116
|
+
return null;
|
|
117
|
+
return {
|
|
118
|
+
args: input.slice(start, i - 1),
|
|
119
|
+
rest: input.slice(i).trimStart(),
|
|
120
|
+
};
|
|
121
|
+
}
|
|
122
|
+
/**
|
|
123
|
+
* Map `scope(...)` args to an `@scope` prelude.
|
|
124
|
+
* - bare `scope` → empty prelude
|
|
125
|
+
* - `scope(.card)` → `(.card)`
|
|
126
|
+
* - `scope((.a) to (.b))` → `(.a) to (.b)`
|
|
127
|
+
*/
|
|
128
|
+
function normalizeScopePrelude(args) {
|
|
129
|
+
if (args === null)
|
|
130
|
+
return '';
|
|
131
|
+
const trimmed = args.trim();
|
|
132
|
+
if (!trimmed)
|
|
133
|
+
return '';
|
|
134
|
+
if (trimmed.startsWith('(')) {
|
|
135
|
+
return trimmed;
|
|
136
|
+
}
|
|
137
|
+
return `(${trimmed})`;
|
|
138
|
+
}
|
|
139
|
+
//# sourceMappingURL=parseImportParams.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"parseImportParams.js","sourceRoot":"","sources":["../../src/processor/parseImportParams.ts"],"names":[],"mappings":"AAcA,MAAM,mBAAmB,GAAG,kCAAkC,CAAC;AAC/D,MAAM,gBAAgB,GAAG,iDAAiD,CAAC;AAC3E,MAAM,gBAAgB,GAAG,iBAAiB,CAAC;AAE3C;;;;GAIG;AACH,MAAM,UAAU,iBAAiB,CAAC,MAAc;IAC9C,MAAM,OAAO,GAAG,MAAM,CAAC,IAAI,EAAE,CAAC;IAC9B,IAAI,CAAC,OAAO;QAAE,OAAO,IAAI,CAAC;IAE1B,IAAI,GAAuB,CAAC;IAC5B,IAAI,IAAY,CAAC;IAEjB,gBAAgB;IAChB,MAAM,WAAW,GAAG,mBAAmB,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;IACtD,IAAI,WAAW,EAAE,CAAC;QAChB,GAAG,GAAG,WAAW,CAAC,CAAC,CAAC,CAAC;QACrB,IAAI,GAAG,WAAW,CAAC,CAAC,CAAC,IAAI,EAAE,CAAC;IAC9B,CAAC;SAAM,CAAC;QACN,MAAM,QAAQ,GAAG,gBAAgB,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;QAChD,IAAI,CAAC,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IAExB,IAAI,OAAO,CAAC,UAAU,CAAC,GAAG,CAAC,EAAE,CAAC;QAC5B,OAAO,OAAO,CAAC;IACjB,CAAC;IACD,OAAO,IAAI,OAAO,GAAG,CAAC;AACxB,CAAC","sourcesContent":["export type ParsedImport = {\n uri: string;\n /** Present when `layer` or `layer(name)` appears; empty string is anonymous. */\n layer?: string;\n /**\n * Present when `scope` or `scope(...)` appears; empty string is bare `@scope`.\n */\n scope?: string;\n /** Inner condition from `supports(...)`, when present. */\n supports?: string;\n /** Comma-separated media queries, when present */\n media?: string;\n};\n\nconst STRING_PATH_PATTERN = /^(['\"])([\\s\\S]*?)\\1\\s*([\\s\\S]*)$/;\nconst URL_PATH_PATTERN = /^url\\(\\s*(['\"]?)([\\s\\S]*?)\\1\\s*\\)\\s*([\\s\\S]*)$/i;\nconst FUNCTION_PATTERN = /[A-Za-z0-9]+\\(/i;\n\n/**\n * Parse `@import` params per CSS Cascade Level 6:\n * uri/path, then layer / scope / supports in any order, then media.\n * Returns null when the prelude is empty or not a string/url form.\n */\nexport function parseImportParams(params: string): ParsedImport | null {\n const trimmed = params.trim();\n if (!trimmed) return null;\n\n let uri: string | undefined;\n let rest: string;\n\n // find uri path\n const stringMatch = STRING_PATH_PATTERN.exec(trimmed);\n if (stringMatch) {\n uri = stringMatch[2];\n rest = stringMatch[3] ?? '';\n } else {\n const urlMatch = URL_PATH_PATTERN.exec(trimmed);\n if (!urlMatch) return null;\n uri = urlMatch[2];\n rest = urlMatch[3] ?? '';\n }\n\n if (!uri) return null;\n\n rest = rest.trim();\n if (!rest) {\n return { uri };\n }\n\n let layer: string | null = null;\n let scope: string | null = null;\n let supports: string | null = null;\n\n // layer || scope || supports, at most once each, any order.\n while (rest) {\n const layerMatch = matchKeywordOrFunction(rest, 'layer', {\n allowBare: true,\n });\n if (layerMatch) {\n if (layer !== null) return null;\n layer = layerMatch.args === null ? '' : layerMatch.args.trim();\n rest = layerMatch.rest.trim();\n continue;\n }\n\n const scopeMatch = matchKeywordOrFunction(rest, 'scope', {\n allowBare: true,\n });\n if (scopeMatch) {\n if (scope !== null) return null;\n scope = normalizeScopePrelude(scopeMatch.args);\n rest = scopeMatch.rest.trim();\n continue;\n }\n\n const supportsMatch = matchKeywordOrFunction(rest, 'supports', {\n allowBare: false,\n });\n if (supportsMatch) {\n if (supports !== null) return null;\n supports = supportsMatch.args ?? '';\n rest = supportsMatch.rest.trim();\n continue;\n }\n\n break;\n }\n\n // Reject remaining function-like syntax (unknown modifiers before media).\n if (FUNCTION_PATTERN.exec(rest)) {\n return null;\n }\n\n return {\n uri,\n ...(layer !== null && { layer }),\n ...(scope !== null && { scope }),\n ...(supports !== null && { supports }),\n ...(rest && { media: rest }),\n };\n}\n\n/**\n * If `input` starts with `name` or `name(...)`, return args and the remainder.\n * `args` is null for a bare keyword; a string for the function form.\n * Nested parentheses are counted so `oklch(…)` / `scope((…) to (…))` work.\n */\nfunction matchKeywordOrFunction(\n input: string,\n name: string,\n { allowBare }: { allowBare: boolean },\n): { args: string | null; rest: string } | null {\n if (!input.toLowerCase().startsWith(name.toLowerCase())) return null;\n\n const afterName = input.slice(name.length);\n // Require a complete ident token (`layer` not `layerfoo`).\n if (afterName.length > 0 && /[A-Za-z0-9_-]/.test(afterName[0]!)) {\n return null;\n }\n\n let i = name.length;\n while (i < input.length && /\\s/.test(input[i]!)) i++;\n\n if (input[i] !== '(') {\n if (!allowBare) return null;\n return { args: null, rest: input.slice(name.length).trimStart() };\n }\n\n i++;\n const start = i;\n let depth = 1;\n while (i < input.length && depth > 0) {\n const ch = input[i]!;\n if (ch === '(') depth++;\n else if (ch === ')') depth--;\n i++;\n }\n if (depth !== 0) return null;\n\n return {\n args: input.slice(start, i - 1),\n rest: input.slice(i).trimStart(),\n };\n}\n\n/**\n * Map `scope(...)` args to an `@scope` prelude.\n * - bare `scope` → empty prelude\n * - `scope(.card)` → `(.card)`\n * - `scope((.a) to (.b))` → `(.a) to (.b)`\n */\nfunction normalizeScopePrelude(args: string | null): string {\n if (args === null) return '';\n const trimmed = args.trim();\n if (!trimmed) return '';\n\n if (trimmed.startsWith('(')) {\n return trimmed;\n }\n return `(${trimmed})`;\n}\n"]}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
// export const strict = {
|
|
2
|
+
// extends: ['stylelint-config-standard'],
|
|
3
|
+
// rules: {
|
|
4
|
+
// 'alpha-value-notation': 'number',
|
|
5
|
+
// 'at-rule-empty-line-before': [
|
|
6
|
+
// 'always',
|
|
7
|
+
// {
|
|
8
|
+
// except: ['blockless-after-same-name-blockless', 'first-nested'],
|
|
9
|
+
// ignore: ['after-comment', 'blockless-after-same-name-blockless'],
|
|
10
|
+
// },
|
|
11
|
+
// ],
|
|
12
|
+
// 'custom-property-pattern': ['^_?([a-z][a-z0-9]*)([-_]{1,2}[a-z0-9]+)*$'],
|
|
13
|
+
// },
|
|
14
|
+
// };
|
|
15
|
+
import recommended from 'stylelint-config-recommended';
|
|
16
|
+
export default {
|
|
17
|
+
extends: [recommended],
|
|
18
|
+
};
|
|
19
|
+
//# sourceMappingURL=stylelintDefault.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"stylelintDefault.js","sourceRoot":"","sources":["../../src/processor/stylelintDefault.ts"],"names":[],"mappings":"AAAA,0BAA0B;AAC1B,4CAA4C;AAC5C,aAAa;AACb,wCAAwC;AACxC,qCAAqC;AACrC,kBAAkB;AAClB,UAAU;AACV,2EAA2E;AAC3E,4EAA4E;AAC5E,WAAW;AACX,SAAS;AACT,gFAAgF;AAChF,OAAO;AACP,KAAK;AAEL,OAAO,WAAW,MAAM,8BAA8B,CAAC;AAEvD,eAAe;IACb,OAAO,EAAE,CAAC,WAAW,CAAC;CACvB,CAAC","sourcesContent":["// export const strict = {\n// extends: ['stylelint-config-standard'],\n// rules: {\n// 'alpha-value-notation': 'number',\n// 'at-rule-empty-line-before': [\n// 'always',\n// {\n// except: ['blockless-after-same-name-blockless', 'first-nested'],\n// ignore: ['after-comment', 'blockless-after-same-name-blockless'],\n// },\n// ],\n// 'custom-property-pattern': ['^_?([a-z][a-z0-9]*)([-_]{1,2}[a-z0-9]+)*$'],\n// },\n// };\n\nimport recommended from 'stylelint-config-recommended';\n\nexport default {\n extends: [recommended],\n};\n"]}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import fs from 'node:fs';
|
|
2
|
+
import path from 'node:path';
|
|
3
|
+
import { writeTemplate } from "./generate.js";
|
|
4
|
+
function runSemantics(args) {
|
|
5
|
+
const flags = args.reduce((acc, arg) => {
|
|
6
|
+
if (arg.startsWith('--')) {
|
|
7
|
+
const [key, value] = arg.slice(2).split('=');
|
|
8
|
+
acc[key] = parseFlagValue(value);
|
|
9
|
+
}
|
|
10
|
+
else if (arg.startsWith('-')) {
|
|
11
|
+
acc[arg.slice(1)] = true;
|
|
12
|
+
}
|
|
13
|
+
return acc;
|
|
14
|
+
}, {});
|
|
15
|
+
const outArg = args.find((a) => !a.startsWith('-'));
|
|
16
|
+
const outPath = path.resolve(process.cwd(), outArg || 'semantics.css');
|
|
17
|
+
if (fs.existsSync(outPath) && fs.statSync(outPath).isDirectory()) {
|
|
18
|
+
throw new Error(`Refusing to overwrite directory: ${outPath}`);
|
|
19
|
+
}
|
|
20
|
+
writeTemplate(outPath, { extended: flags.extended === true });
|
|
21
|
+
console.log(`Wrote ${outPath}`);
|
|
22
|
+
}
|
|
23
|
+
function parseFlagValue(value) {
|
|
24
|
+
if (value === undefined)
|
|
25
|
+
return true;
|
|
26
|
+
const normalized = String(value).toLowerCase();
|
|
27
|
+
if (normalized === 'true' || normalized === '1')
|
|
28
|
+
return true;
|
|
29
|
+
if (normalized === 'false' || normalized === '0')
|
|
30
|
+
return false;
|
|
31
|
+
return value;
|
|
32
|
+
}
|
|
33
|
+
export { runSemantics };
|
|
34
|
+
//# sourceMappingURL=cli.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"cli.js","sourceRoot":"","sources":["../../src/semantics/cli.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AK,IAAI,EAAE,CAAC,CAAC;IAC9D,OAAO,CAAC,GAAG,CAAC,SAAS,OAAO,EAAE,CAAC,CAAC;AAClC,CAAC;AAED,SAAS,cAAc,CAAC,KAAyB;IAC/C,IAAI,KAAK,KAAK,SAAS;QAAE,OAAO,IAAI,CAAC;IACrC,MAAM,UAAU,GAAG,MAAM,CAAC,KAAK,CAAC,CAAC,WAAW,EAAE,CAAC;IAC/C,IAAI,UAAU,KAAK,MAAM,IAAI,UAAU,KAAK,GAAG;QAAE,OAAO,IAAI,CAAC;IAC7D,IAAI,UAAU,KAAK,OAAO,IAAI,UAAU,KAAK,GAAG;QAAE,OAAO,KAAK,CAAC;IAC/D,OAAO,KAAK,CAAC;AACf,CAAC;AAED,OAAO,EAAE,YAAY,EAAE,CAAC","sourcesContent":["import fs from 'node:fs';\nimport path from 'node:path';\nimport { writeTemplate } from './generate.ts';\n\nfunction runSemantics(args: string[]): void {\n const flags = args.reduce<Record<string, string | boolean>>((acc, arg) => {\n if (arg.startsWith('--')) {\n const [key, value] = arg.slice(2).split('=');\n acc[key] = parseFlagValue(value);\n } else if (arg.startsWith('-')) {\n acc[arg.slice(1)] = true;\n }\n return acc;\n }, {});\n const outArg = args.find((a) => !a.startsWith('-'));\n const outPath = path.resolve(process.cwd(), outArg || 'semantics.css');\n\n if (fs.existsSync(outPath) && fs.statSync(outPath).isDirectory()) {\n throw new Error(`Refusing to overwrite directory: ${outPath}`);\n }\n\n writeTemplate(outPath, { extended: flags.extended === true });\n console.log(`Wrote ${outPath}`);\n}\n\nfunction parseFlagValue(value: string | undefined): string | boolean {\n if (value === undefined) return true;\n const normalized = String(value).toLowerCase();\n if (normalized === 'true' || normalized === '1') return true;\n if (normalized === 'false' || normalized === '0') return false;\n return value;\n}\n\nexport { runSemantics };\n"]}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import type { TokenOptions, TokenSection } from './load-tokens.ts';
|
|
2
|
+
export type { TokenOptions, TokenRecord, TokenSection } from './load-tokens.ts';
|
|
3
|
+
/**
|
|
4
|
+
* Write the CSS template to disk.
|
|
5
|
+
*/
|
|
6
|
+
declare function writeTemplate(outPath: string, options?: TokenOptions): string;
|
|
7
|
+
/**
|
|
8
|
+
* Generate CSS text from the package tokens directory.
|
|
9
|
+
* @param {{ extended?: boolean }} [options]
|
|
10
|
+
*/
|
|
11
|
+
declare function generateCss(options?: TokenOptions): string;
|
|
12
|
+
/**
|
|
13
|
+
* Build a :root CSS template from loaded sections.
|
|
14
|
+
*/
|
|
15
|
+
declare function renderCss(sections: readonly TokenSection[]): string;
|
|
16
|
+
export { generateCss, renderCss, writeTemplate };
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import fs from 'node:fs';
|
|
2
|
+
import path from 'node:path';
|
|
3
|
+
import { loadTokens } from "./load-tokens.js";
|
|
4
|
+
/**
|
|
5
|
+
* Write the CSS template to disk.
|
|
6
|
+
*/
|
|
7
|
+
function writeTemplate(outPath, options = {}) {
|
|
8
|
+
const css = generateCss(options);
|
|
9
|
+
const resolved = path.resolve(outPath);
|
|
10
|
+
fs.mkdirSync(path.dirname(resolved), { recursive: true });
|
|
11
|
+
fs.writeFileSync(resolved, css, 'utf8');
|
|
12
|
+
return resolved;
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* Generate CSS text from the package tokens directory.
|
|
16
|
+
* @param {{ extended?: boolean }} [options]
|
|
17
|
+
*/
|
|
18
|
+
function generateCss(options = {}) {
|
|
19
|
+
return renderCss(loadTokens(options));
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* Build a :root CSS template from loaded sections.
|
|
23
|
+
*/
|
|
24
|
+
function renderCss(sections) {
|
|
25
|
+
const blocks = [];
|
|
26
|
+
for (const section of sections) {
|
|
27
|
+
const { label, tokens } = section;
|
|
28
|
+
if (tokens.length === 0)
|
|
29
|
+
continue;
|
|
30
|
+
const lines = [` /* ${label} */`];
|
|
31
|
+
lines.push(...formatTokenRun(tokens));
|
|
32
|
+
blocks.push(lines.join('\n'));
|
|
33
|
+
}
|
|
34
|
+
return [':root {', blocks.join('\n\n'), '}', ''].join('\n');
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* Emit tokens in source order.
|
|
38
|
+
*/
|
|
39
|
+
function formatTokenRun(tokens) {
|
|
40
|
+
const lines = [];
|
|
41
|
+
for (const token of tokens) {
|
|
42
|
+
lines.push(formatDeclaration(token));
|
|
43
|
+
}
|
|
44
|
+
return lines;
|
|
45
|
+
}
|
|
46
|
+
function formatDeclaration(token) {
|
|
47
|
+
const value = token.value === '' || token.value === null || token.value === undefined
|
|
48
|
+
? ' '
|
|
49
|
+
: ` ${token.value}`;
|
|
50
|
+
return ` ${token.name}:${value};`;
|
|
51
|
+
}
|
|
52
|
+
export { generateCss, renderCss, writeTemplate };
|
|
53
|
+
//# sourceMappingURL=generate.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"generate.js","sourceRoot":"","sources":["../../src/semantics/generate.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,SAAS,CAAC;AACzB,OAAO,IAAI,MAAM,WAAW,CAAC;AAC7B,OAAO,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AAK9C;;GAEG;AACH,SAAS,aAAa,CAAC,OAAe,EAAE,UAAwB,EAAE;IAChE,MAAM,GAAG,GAAG,WAAW,CAAC,OAAO,CAAC,CAAC;IACjC,MAAM,QAAQ,GAAG,IAAI,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC;IACvC,EAAE,CAAC,SAAS,CAAC,IAAI,CAAC,OAAO,CAAC,QAAQ,CAAC,EAAE,EAAE,SAAS,EAAE,IAAI,EAAE,CAAC,CAAC;IAC1D,EAAE,CAAC,aAAa,CAAC,QAAQ,EAAE,GAAG,EAAE,MAAM,CAAC,CAAC;IACxC,OAAO,QAAQ,CAAC;AAClB,CAAC;AAED;;;GAGG;AACH,SAAS,WAAW,CAAC,UAAwB,EAAE;IAC7C,OA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OAAO,EAAE,WAAW,EAAE,SAAS,EAAE,aAAa,EAAE,CAAC","sourcesContent":["import fs from 'node:fs';\nimport path from 'node:path';\nimport { loadTokens } from './load-tokens.ts';\nimport type { TokenOptions, TokenRecord, TokenSection } from './load-tokens.ts';\n\nexport type { TokenOptions, TokenRecord, TokenSection } from './load-tokens.ts';\n\n/**\n * Write the CSS template to disk.\n */\nfunction writeTemplate(outPath: string, options: TokenOptions = {}): string {\n const css = generateCss(options);\n const resolved = path.resolve(outPath);\n fs.mkdirSync(path.dirname(resolved), { recursive: true });\n fs.writeFileSync(resolved, css, 'utf8');\n return resolved;\n}\n\n/**\n * Generate CSS text from the package tokens directory.\n * @param {{ extended?: boolean }} [options]\n */\nfunction generateCss(options: TokenOptions = {}): string {\n return renderCss(loadTokens(options));\n}\n\n/**\n * Build a :root CSS template from loaded sections.\n */\nfunction renderCss(sections: readonly TokenSection[]): string {\n const blocks = [];\n\n for (const section of sections) {\n const { label, tokens } = section;\n if (tokens.length === 0) continue;\n\n const lines = [` /* ${label} */`];\n lines.push(...formatTokenRun(tokens));\n\n blocks.push(lines.join('\\n'));\n }\n\n return [':root {', blocks.join('\\n\\n'), '}', ''].join('\\n');\n}\n\n/**\n * Emit tokens in source order.\n */\nfunction formatTokenRun(tokens: readonly TokenRecord[]): string[] {\n const lines = [];\n\n for (const token of tokens) {\n lines.push(formatDeclaration(token));\n }\n return lines;\n}\n\nfunction formatDeclaration(token: TokenRecord): string {\n const value =\n token.value === '' || token.value === null || token.value === undefined\n ? ' '\n : ` ${token.value}`;\n return ` ${token.name}:${value};`;\n}\n\nexport { generateCss, renderCss, writeTemplate };\n"]}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
export interface TokenOptions {
|
|
2
|
+
extended?: boolean;
|
|
3
|
+
}
|
|
4
|
+
export interface TokenRecord {
|
|
5
|
+
name: string;
|
|
6
|
+
value: string | null;
|
|
7
|
+
description: string;
|
|
8
|
+
tier: 'core' | 'extended';
|
|
9
|
+
type: string;
|
|
10
|
+
usage: string;
|
|
11
|
+
pairsWith: string[];
|
|
12
|
+
related: string[];
|
|
13
|
+
}
|
|
14
|
+
export interface TokenSection {
|
|
15
|
+
file: string;
|
|
16
|
+
label: string;
|
|
17
|
+
tokens: TokenRecord[];
|
|
18
|
+
}
|
|
19
|
+
/** Ordered token groups shared by CSS generation and documentation. */
|
|
20
|
+
declare const SECTIONS: {
|
|
21
|
+
file: string;
|
|
22
|
+
label: string;
|
|
23
|
+
}[];
|
|
24
|
+
/**
|
|
25
|
+
* Load all token files into ordered sections of flat token records.
|
|
26
|
+
*/
|
|
27
|
+
declare function loadTokens(options?: TokenOptions): TokenSection[];
|
|
28
|
+
declare function getTokensDir(packageRoot?: string): string;
|
|
29
|
+
export { SECTIONS, loadTokens, getTokensDir };
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
import fs from 'node:fs';
|
|
2
|
+
import path from 'node:path';
|
|
3
|
+
/** Ordered token groups shared by CSS generation and documentation. */
|
|
4
|
+
const SECTIONS = [
|
|
5
|
+
{ file: 'color-bg.json', label: 'color — surfaces' },
|
|
6
|
+
{ file: 'color-text.json', label: 'color — text' },
|
|
7
|
+
{ file: 'color-border.json', label: 'color — borders' },
|
|
8
|
+
{ file: 'color-icon.json', label: 'color — icons' },
|
|
9
|
+
{ file: 'color-chart.json', label: 'color — charts' },
|
|
10
|
+
{ file: 'typography.json', label: 'typography' },
|
|
11
|
+
{ file: 'spacing.json', label: 'spacing' },
|
|
12
|
+
{ file: 'borders.json', label: 'borders' },
|
|
13
|
+
{ file: 'motion.json', label: 'motion' },
|
|
14
|
+
{ file: 'layout.json', label: 'layout' },
|
|
15
|
+
{ file: 'misc.json', label: 'misc' },
|
|
16
|
+
];
|
|
17
|
+
/**
|
|
18
|
+
* Load all token files into ordered sections of flat token records.
|
|
19
|
+
*/
|
|
20
|
+
function loadTokens(options = {}) {
|
|
21
|
+
const dir = getTokensDir();
|
|
22
|
+
return SECTIONS.map(({ file, label }) => {
|
|
23
|
+
const filePath = path.join(dir, file);
|
|
24
|
+
if (!fs.existsSync(filePath)) {
|
|
25
|
+
throw new Error(`Missing token file: ${filePath}`);
|
|
26
|
+
}
|
|
27
|
+
const tokens = [];
|
|
28
|
+
walk(JSON.parse(fs.readFileSync(filePath, 'utf8')), [], tokens);
|
|
29
|
+
return {
|
|
30
|
+
file,
|
|
31
|
+
label,
|
|
32
|
+
tokens: tokens.filter((t) => {
|
|
33
|
+
if (t.tier === 'core') {
|
|
34
|
+
return true;
|
|
35
|
+
}
|
|
36
|
+
if (options.extended) {
|
|
37
|
+
return true;
|
|
38
|
+
}
|
|
39
|
+
return false;
|
|
40
|
+
}),
|
|
41
|
+
};
|
|
42
|
+
});
|
|
43
|
+
}
|
|
44
|
+
function getTokensDir(packageRoot = path.join(import.meta.dirname, '../..')) {
|
|
45
|
+
return path.join(packageRoot, 'tokens');
|
|
46
|
+
}
|
|
47
|
+
function walk(node, parts, out) {
|
|
48
|
+
if (!node || typeof node !== 'object' || Array.isArray(node))
|
|
49
|
+
return;
|
|
50
|
+
if (isToken(node)) {
|
|
51
|
+
out.push({
|
|
52
|
+
name: `--${parts.join('-')}`,
|
|
53
|
+
value: node.$value === undefined || node.$value === '' ? '' : node.$value,
|
|
54
|
+
description: node.$description || '',
|
|
55
|
+
tier: node.tier === 'extended' ? 'extended' : 'core',
|
|
56
|
+
type: node.$type || '',
|
|
57
|
+
usage: node.usage || '',
|
|
58
|
+
pairsWith: node.pairsWith || [],
|
|
59
|
+
related: node.related || [],
|
|
60
|
+
});
|
|
61
|
+
return;
|
|
62
|
+
}
|
|
63
|
+
for (const [key, child] of Object.entries(node)) {
|
|
64
|
+
walk(child, parts.concat(key), out);
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
function isToken(node) {
|
|
68
|
+
return (node !== null &&
|
|
69
|
+
typeof node === 'object' &&
|
|
70
|
+
!Array.isArray(node) &&
|
|
71
|
+
('$value' in node || '$type' in node));
|
|
72
|
+
}
|
|
73
|
+
export { SECTIONS, loadTokens, getTokensDir };
|
|
74
|
+
//# sourceMappingURL=load-tokens.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"load-tokens.js","sourceRoot":"","sources":["../../src/semantics/load-tokens.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,SAAS,CAAC;AACzB,OAAO,IAAI,MAAM,WAAW,CAAC;AAkC7B,uEAAuE;AACvE,MAAM,QAAQ,GAAG;IACf,EAAE,IAAI,EAAE,eAAe,EAAE,KAAK,EAAE,kBAAkB,EAAE;IACpD,EAAE,IAAI,EAAE,iBAAiB,EAAE,KAAK,EAAE,cAAc,EAAE;IAClD,EAAE,IAAI,EAAE,mBAAmB,EAAE,KAAK,EAAE,iBAAiB,EAAE;IACvD,EAAE,IAAI,EAAE,iBAAiB,EAAE,KAAK,EAAE,eAAe,EAAE;IACnD,EAAE,IAAI,EAAE,kBAAkB,EAAE,KAAK,EAAE,gBAAgB,EAAE;IACrD,EAAE,IAAI,EAAE,iBAAiB,EAAE,KAAK,EAAE,YAAY,EAAE;IAChD,EAAE,IAAI,EAAE,cAAc,EAAE,KAAK,EAAE,SAAS,EAAE;IAC1C,EAAE,IAAI,EAAE,cAAc,EAAE,KAAK,EAAE,SAAS,EAAE;IAC1C,EAAE,IAAI,EAAE,aAAa,EAAE,KAAK,EAAE,QAAQ,EAAE;IACxC,EAAE,IAAI,EAAE,aAAa,EAAE,KAAK,EAAE,QAAQ,EAAE;IACxC,EAAE,IAAI,EAAE,WAAW,EAAE,KAAK,EAAE,MAAM,EAAE;CACrC,CAAC;AAEF;;GAEG;AACH,SAAS,UAAU,CAAC,UAAwB,EAAE;IAC5C,MAAM,GAAG,GAAG,YAAY,EAAE,CAAC;IAE3B,OAAO,QAAQ,CAAC,GAAG,CAAC,CAAC,EAAE,IAAI,EAAE,KAAK,EAAE,EAAE,EAAE;QACtC,MAAM,QAAQ,GAAG,IAAI,CAAC,IAAI,CAAC,GAAG,EAAE,I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AAS,IAAI,IAAI,CAAC,MAAM,KAAK,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC,MAAM;YACzE,WAAW,EAAE,IAAI,CAAC,YAAY,IAAI,EAAE;YACpC,IAAI,EAAE,IAAI,CAAC,IAAI,KAAK,UAAU,CAAC,CAAC,CAAC,UAAU,CAAC,CAAC,CAAC,MAAM;YACpD,IAAI,EAAE,IAAI,CAAC,KAAK,IAAI,EAAE;YACtB,KAAK,EAAE,IAAI,CAAC,KAAK,IAAI,EAAE;YACvB,SAAS,EAAE,IAAI,CAAC,SAAS,IAAI,EAAE;YAC/B,OAAO,EAAE,IAAI,CAAC,OAAO,IAAI,EAAE;SAC5B,CAAC,CAAC;QACH,OAAO;IACT,CAAC;IACD,KAAK,MAAM,CAAC,GAAG,EAAE,KAAK,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,IAAI,CAAC,EAAE,CAAC;QAChD,IAAI,CAAC,KAAK,EAAE,KAAK,CAAC,MAAM,CAAC,GAAG,CAAC,EAAE,GAAG,CAAC,CAAC;IACtC,CAAC;AACH,CAAC;AAED,SAAS,OAAO,CAAC,IAAa;IAC5B,OAAO,CACL,IAAI,KAAK,IAAI;QACb,OAAO,IAAI,KAAK,QAAQ;QACxB,CAAC,KAAK,CAAC,OAAO,CAAC,IAAI,CAAC;QACpB,CAAC,QAAQ,IAAI,IAAI,IAAI,OAAO,IAAI,IAAI,CAAC,CACtC,CAAC;AACJ,CAAC;AAED,OAAO,EAAE,QAAQ,EAAE,UAAU,EAAE,YAAY,EAAE,CAAC","sourcesContent":["import fs from 'node:fs';\nimport path from 'node:path';\n\nexport interface TokenOptions {\n extended?: boolean;\n}\n\nexport interface TokenRecord {\n name: string;\n value: string | null;\n description: string;\n tier: 'core' | 'extended';\n type: string;\n usage: string;\n pairsWith: string[];\n related: string[];\n}\n\nexport interface TokenSection {\n file: string;\n label: string;\n tokens: TokenRecord[];\n}\n\n/** Packaged DTCG-shaped source records; not a general token interchange format. */\ninterface TokenSource extends Record<string, unknown> {\n $value?: string | null;\n $type?: string;\n $description?: string;\n tier?: string;\n usage?: string;\n pairsWith?: string[];\n related?: string[];\n}\n\n/** Ordered token groups shared by CSS generation and documentation. */\nconst SECTIONS = [\n { file: 'color-bg.json', label: 'color — surfaces' },\n { file: 'color-text.json', label: 'color — text' },\n { file: 'color-border.json', label: 'color — borders' },\n { file: 'color-icon.json', label: 'color — icons' },\n { file: 'color-chart.json', label: 'color — charts' },\n { file: 'typography.json', label: 'typography' },\n { file: 'spacing.json', label: 'spacing' },\n { file: 'borders.json', label: 'borders' },\n { file: 'motion.json', label: 'motion' },\n { file: 'layout.json', label: 'layout' },\n { file: 'misc.json', label: 'misc' },\n];\n\n/**\n * Load all token files into ordered sections of flat token records.\n */\nfunction loadTokens(options: TokenOptions = {}): TokenSection[] {\n const dir = getTokensDir();\n\n return SECTIONS.map(({ file, label }) => {\n const filePath = path.join(dir, file);\n if (!fs.existsSync(filePath)) {\n throw new Error(`Missing token file: ${filePath}`);\n }\n const tokens: TokenRecord[] = [];\n walk(JSON.parse(fs.readFileSync(filePath, 'utf8')), [], tokens);\n return {\n file,\n label,\n tokens: tokens.filter((t) => {\n if (t.tier === 'core') {\n return true;\n }\n if (options.extended) {\n return true;\n }\n return false;\n }),\n };\n });\n}\n\nfunction getTokensDir(packageRoot = path.join(import.meta.dirname, '../..')) {\n return path.join(packageRoot, 'tokens');\n}\n\nfunction walk(node: unknown, parts: string[], out: TokenRecord[]): void {\n if (!node || typeof node !== 'object' || Array.isArray(node)) return;\n if (isToken(node)) {\n out.push({\n name: `--${parts.join('-')}`,\n value: node.$value === undefined || node.$value === '' ? '' : node.$value,\n description: node.$description || '',\n tier: node.tier === 'extended' ? 'extended' : 'core',\n type: node.$type || '',\n usage: node.usage || '',\n pairsWith: node.pairsWith || [],\n related: node.related || [],\n });\n return;\n }\n for (const [key, child] of Object.entries(node)) {\n walk(child, parts.concat(key), out);\n }\n}\n\nfunction isToken(node: unknown): node is TokenSource {\n return (\n node !== null &&\n typeof node === 'object' &&\n !Array.isArray(node) &&\n ('$value' in node || '$type' in node)\n );\n}\n\nexport { SECTIONS, loadTokens, getTokensDir };\n"]}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import type { TokenOptions } from './load-tokens.ts';
|
|
2
|
+
/**
|
|
3
|
+
* Build lookup data from packaged token JSON.
|
|
4
|
+
*/
|
|
5
|
+
declare function getTokenIndex(options?: TokenOptions): {
|
|
6
|
+
names: Set<string>;
|
|
7
|
+
prefixes: string[];
|
|
8
|
+
};
|
|
9
|
+
/**
|
|
10
|
+
* True when a custom-property name (without leading --) sits in an Argot
|
|
11
|
+
* namespace prefix (e.g. text-*, bg-*, space-*), whether or not it is known.
|
|
12
|
+
*/
|
|
13
|
+
declare function looksLikeArgotToken(name: string, prefixes: readonly string[]): boolean;
|
|
14
|
+
export { getTokenIndex, looksLikeArgotToken };
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { loadTokens } from "./load-tokens.js";
|
|
2
|
+
/**
|
|
3
|
+
* Build lookup data from packaged token JSON.
|
|
4
|
+
*/
|
|
5
|
+
function getTokenIndex(options = { extended: true }) {
|
|
6
|
+
const names = new Set();
|
|
7
|
+
for (const section of loadTokens(options)) {
|
|
8
|
+
for (const token of section.tokens) {
|
|
9
|
+
names.add(token.name.slice(2));
|
|
10
|
+
}
|
|
11
|
+
}
|
|
12
|
+
const prefixes = new Set();
|
|
13
|
+
for (const name of names) {
|
|
14
|
+
const dash = name.indexOf('-');
|
|
15
|
+
prefixes.add(dash === -1 ? name : name.slice(0, dash));
|
|
16
|
+
}
|
|
17
|
+
return {
|
|
18
|
+
names,
|
|
19
|
+
prefixes: [...prefixes].sort(),
|
|
20
|
+
};
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* True when a custom-property name (without leading --) sits in an Argot
|
|
24
|
+
* namespace prefix (e.g. text-*, bg-*, space-*), whether or not it is known.
|
|
25
|
+
*/
|
|
26
|
+
function looksLikeArgotToken(name, prefixes) {
|
|
27
|
+
return prefixes.some((prefix) => name === prefix || name.startsWith(`${prefix}-`));
|
|
28
|
+
}
|
|
29
|
+
export { getTokenIndex, looksLikeArgotToken };
|
|
30
|
+
//# sourceMappingURL=token-index.js.map
|