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
package/LICENSE.md
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
# The MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Keith J. Grant
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy of
|
|
6
|
+
this software and associated documentation files (the “Software”), to deal in
|
|
7
|
+
the Software without restriction, including without limitation the rights to
|
|
8
|
+
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
|
|
9
|
+
the Software, and to permit persons to whom the Software is furnished to do so,
|
|
10
|
+
subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
|
|
17
|
+
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
|
|
18
|
+
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
|
|
19
|
+
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
|
20
|
+
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,3 +1,260 @@
|
|
|
1
|
-
#
|
|
1
|
+
# Argot
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
A CSS preprocessor, streamlined for an era when we barely need preprocessors
|
|
4
|
+
anymore.
|
|
5
|
+
|
|
6
|
+
Usage:
|
|
7
|
+
|
|
8
|
+
```
|
|
9
|
+
argot <input.css> <output.css> [--lint-config="path/to/stylelint-config"]
|
|
10
|
+
```
|
|
11
|
+
|
|
12
|
+
What the processor does:
|
|
13
|
+
|
|
14
|
+
- Assemble — Embed CSS file partials using `@import`
|
|
15
|
+
- Lint — uses [stylelint](https://stylelint.io/)
|
|
16
|
+
- Minify — uses[cssnano](https://cssnano.github.io/cssnano/)
|
|
17
|
+
|
|
18
|
+
The `@import` at-rule can be used anywhere in your stylesheets. It supports all
|
|
19
|
+
_preludes_ the native CSS `@import` supports:
|
|
20
|
+
|
|
21
|
+
```
|
|
22
|
+
@import 'partial.css';
|
|
23
|
+
@import 'partial.css' layer(modules);
|
|
24
|
+
@import 'partial.css' supports(contrast-color(#ccc));
|
|
25
|
+
@import 'partial.css' scope(.aside);
|
|
26
|
+
@import 'partial.css' (min-width: 500px);
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
Layer, supports, and scope may be specified in any order. Media queries must be
|
|
30
|
+
listed last.
|
|
31
|
+
|
|
32
|
+
## Project scaffolding
|
|
33
|
+
|
|
34
|
+
In addition to the preprocessor, Argot offers a number of tools for project
|
|
35
|
+
scaffolding and design. The full pipeline is still very much under construction,
|
|
36
|
+
but some of the pieces below are working.
|
|
37
|
+
|
|
38
|
+
## Semantic CSS custom properties
|
|
39
|
+
|
|
40
|
+
A standardized set of **semantic design token names**, plus headless **primitive
|
|
41
|
+
color palette generation**, packaged for modern CSS projects. Use either
|
|
42
|
+
independently, or generate a palette and map semantic properties to it.
|
|
43
|
+
|
|
44
|
+
See the [public API and CLI reference](./docs/api.md) for package imports,
|
|
45
|
+
portable definitions, options, return values, and file-writing behavior.
|
|
46
|
+
|
|
47
|
+
Argot is ready for beta use. The token set is deliberately defined; real-world
|
|
48
|
+
adoption will help prove it out and refine it. Names may change during beta.
|
|
49
|
+
|
|
50
|
+
## Why this exists
|
|
51
|
+
|
|
52
|
+
With modern CSS, preprocessors do less of the work we once needed them for.
|
|
53
|
+
What’s still hard is _design architecture_: agreeing on which tokens mean what,
|
|
54
|
+
and using them consistently.
|
|
55
|
+
|
|
56
|
+
The expectation here is for CSS custom properties to
|
|
57
|
+
[fall into three tiers](https://keithjgrant.com/posts/2024/06/a-structured-approach-to-custom-properties/):
|
|
58
|
+
|
|
59
|
+
1. **Primitive** — raw values providing theme colors, fonts, etc.
|
|
60
|
+
2. **Semantic** — building blocks applying primitive values to specific design
|
|
61
|
+
intent
|
|
62
|
+
3. **Module** — variables scoped to a single component
|
|
63
|
+
|
|
64
|
+
The semantic layer provides a carefully chosen set of names that could cover
|
|
65
|
+
most of what most projects need, with only the _values_ changing per design. The
|
|
66
|
+
palette engine supplies primitive color scales from numeric OKLCH seeds.
|
|
67
|
+
Scaffold generation and CSS processing are planned, not currently shipped.
|
|
68
|
+
|
|
69
|
+
## What’s in this repo
|
|
70
|
+
|
|
71
|
+
| Path | Purpose |
|
|
72
|
+
| -------------------------- | -------------------------------------------------------------------------------------------------- |
|
|
73
|
+
| [`tokens/`](./tokens/) | **Source of truth** — DTCG-shaped JSON for semantic token names, descriptions, and core/extended |
|
|
74
|
+
| [`src/`](./src/) | TypeScript library and CLI source (+ optional Stylelint plugin) |
|
|
75
|
+
| [`examples/`](./examples/) | Variable names pulled from existing frameworks for comparison/inspiration |
|
|
76
|
+
| [`docs/`](./docs/) | [Public API](./docs/api.md) and planning notes, including [product scope](./docs/product-scope.md) |
|
|
77
|
+
|
|
78
|
+
Tokens are grouped for backgrounds, text, brand/accent, status, typography,
|
|
79
|
+
spacing, borders, shadow, focus, motion, layout, and charts. Tokens are marked
|
|
80
|
+
with either "core" or "extended" tier.
|
|
81
|
+
|
|
82
|
+
The examples are **reference material only** — Bootstrap, Bulma, PatternFly,
|
|
83
|
+
Materialize, and others — to see how established systems name similar concepts.
|
|
84
|
+
They are not dependencies and are not meant to be copied wholesale into the
|
|
85
|
+
template.
|
|
86
|
+
|
|
87
|
+
## How to use the template (for now)
|
|
88
|
+
|
|
89
|
+
The CLI requires Node.js 22.18 or newer. Argot uses native ES modules; no
|
|
90
|
+
CommonJS build is provided. Published entrypoints contain JavaScript and
|
|
91
|
+
TypeScript declarations, so consumers do not need a TypeScript compiler.
|
|
92
|
+
|
|
93
|
+
1. Emit a template into your project:
|
|
94
|
+
|
|
95
|
+
```bash
|
|
96
|
+
npx argot-css semantics # core tokens → ./semantics.css
|
|
97
|
+
npx argot-css semantics --extended # core + extended
|
|
98
|
+
npx argot-css semantics ./tokens.css # custom output path
|
|
99
|
+
```
|
|
100
|
+
|
|
101
|
+
2. Assign values — typically by mapping to your own primitive palette.
|
|
102
|
+
3. Style with semantic names (`var(--text-primary)`) instead of primitives
|
|
103
|
+
(`var(--gray-6)`).
|
|
104
|
+
|
|
105
|
+
### Stylelint rule
|
|
106
|
+
|
|
107
|
+
Noop lint rule for now. Functionality remains TODO.
|
|
108
|
+
|
|
109
|
+
Requires Stylelint 16. This example uses an ESM configuration (a `.js` file in a
|
|
110
|
+
project with `"type": "module"`, or a `stylelint.config.mjs` file).
|
|
111
|
+
|
|
112
|
+
```js
|
|
113
|
+
// stylelint.config.js
|
|
114
|
+
export default {
|
|
115
|
+
extends: ['argot-css/stylelint/config'],
|
|
116
|
+
};
|
|
117
|
+
```
|
|
118
|
+
|
|
119
|
+
Example shape:
|
|
120
|
+
|
|
121
|
+
```css
|
|
122
|
+
:root {
|
|
123
|
+
/* primitives (yours) */
|
|
124
|
+
--gray-3: oklch(93% 0.006 245deg);
|
|
125
|
+
--gray-6: oklch(55% 0.02 245deg);
|
|
126
|
+
|
|
127
|
+
/* semantic (shared names) */
|
|
128
|
+
--text-primary: var(--gray-3);
|
|
129
|
+
--text-secondary: var(--gray-6);
|
|
130
|
+
--bg-body: /* … */;
|
|
131
|
+
}
|
|
132
|
+
```
|
|
133
|
+
|
|
134
|
+
## Primitive palette definitions
|
|
135
|
+
|
|
136
|
+
Palette inputs use numeric OKLCH coordinates. Each color has a required name and
|
|
137
|
+
`l`, `c`, `h`:
|
|
138
|
+
|
|
139
|
+
- `l`: finite lightness from 0 through 1 (not 0 through 100).
|
|
140
|
+
- `c`: finite, nonnegative chroma (0.0 through 0.42 for reasonable range).
|
|
141
|
+
- `h`: a finite hue angle in degrees, including for neutral colors.
|
|
142
|
+
|
|
143
|
+
Coordinates are retained as supplied, without hue wrapping, chroma thresholding,
|
|
144
|
+
or rounding. Gamut mapping and final precision limiting happen during CSS
|
|
145
|
+
output.
|
|
146
|
+
|
|
147
|
+
```json
|
|
148
|
+
{
|
|
149
|
+
"version": 1,
|
|
150
|
+
"colors": [{ "name": "brand", "l": 0.6, "c": 0.2, "h": 250 }],
|
|
151
|
+
"options": {
|
|
152
|
+
"lightnessCurve": "inclusive",
|
|
153
|
+
"chromaCurve": "weighted"
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
```
|
|
157
|
+
|
|
158
|
+
In a checkout, try
|
|
159
|
+
`npm run dev -- palette scripts/fixtures/palette.json ./primitives.css` using
|
|
160
|
+
the [sample definition](./scripts/fixtures/palette.json). Existing output
|
|
161
|
+
requires `--force` to replace; `--dry-run` validates without writing.
|
|
162
|
+
|
|
163
|
+
The browser-safe `argot-css/palette` entrypoint exports `SeedColor`,
|
|
164
|
+
`OklchColor`, `PaletteDefinition`, and the generation functions. If an input
|
|
165
|
+
interface accepts CSS strings, call the separate `parseCssColor()` helper and
|
|
166
|
+
compose a numeric seed such as `{ name: 'brand', ...parseCssColor('#663399') }`.
|
|
167
|
+
Definitions themselves do not accept CSS strings. JSON loading and serialization
|
|
168
|
+
preserve numeric generation inputs rather than converting them to CSS and
|
|
169
|
+
reparsing them.
|
|
170
|
+
|
|
171
|
+
## Development
|
|
172
|
+
|
|
173
|
+
Library source lives in `src/*.ts` and `src/` subdirectories. Node 22.18+
|
|
174
|
+
executes this source natively by stripping types; it does not check types. Use
|
|
175
|
+
`.ts` extensions for relative source imports, `import type` for type-only
|
|
176
|
+
imports, and erasable syntax (no runtime enums or parameter properties).
|
|
177
|
+
|
|
178
|
+
- `npm run dev -- help` — run the CLI from TypeScript source, without a build.
|
|
179
|
+
- `npm run dev -- generate ./semantics.css` — generate a semantic template
|
|
180
|
+
directly from source.
|
|
181
|
+
- `npm run typecheck` — strictly check the library without emitting files.
|
|
182
|
+
- `npm run build` — emit ESM JavaScript, declarations, and source maps into
|
|
183
|
+
ignored `dist/`. Relative runtime imports are rewritten to `.js`.
|
|
184
|
+
- `npm test` — build, check public declarations, and run runtime and
|
|
185
|
+
packed-package tests, including the palette curve regressions.
|
|
186
|
+
- `npm run test:types` — check Node and browser consumer types against an
|
|
187
|
+
existing build.
|
|
188
|
+
- `npm run test:package` — build through the pack hook and check the archive
|
|
189
|
+
outside the checkout; no publishing or registry access is involved.
|
|
190
|
+
- `npm run build:template` — regenerate checked-in semantic CSS using native
|
|
191
|
+
TypeScript execution.
|
|
192
|
+
- `npm run prettier` / `npm run prettier:fix` — check or apply formatting.
|
|
193
|
+
|
|
194
|
+
`npm pack` and publishing run the build automatically through `prepack`.
|
|
195
|
+
Published exports and `bin/argot.js` use `dist/`; run the build before invoking
|
|
196
|
+
that executable directly from a checkout. For normal development use
|
|
197
|
+
`npm run dev -- ...` instead. Tests and website files remain JavaScript. The
|
|
198
|
+
`./palette` entrypoint is browser-safe and exports its public types; filesystem
|
|
199
|
+
adapters live separately at `./palette/node`.
|
|
200
|
+
|
|
201
|
+
## Documentation website
|
|
202
|
+
|
|
203
|
+
The Eleventy site lives in `website/`. Token reference pages are generated at
|
|
204
|
+
build time from `tokens/*.json`, using the same loader as the CSS generator.
|
|
205
|
+
Group introductions and CSS examples live separately in `website/lib/guides.js`.
|
|
206
|
+
The site imports the token loader directly from TypeScript source: website
|
|
207
|
+
development, tests, and builds do not require `dist/` or a compiler-watch
|
|
208
|
+
process. An explicit watch hook reloads the native token loader when TypeScript
|
|
209
|
+
source changes, avoiding Eleventy's JavaScript-only dependency parser.
|
|
210
|
+
|
|
211
|
+
- `npm run website:dev` — serve locally with live reload, including token edits.
|
|
212
|
+
- `npm run website:build` — build static files into `website/_site/`.
|
|
213
|
+
- `npm run website:test` — check metadata, token coverage, links, URL prefixes,
|
|
214
|
+
and filtering behavior.
|
|
215
|
+
- `npm run website:format` — format supported website files with Prettier.
|
|
216
|
+
- `npm run website:lint` — check website CSS with Stylelint.
|
|
217
|
+
- `npm run website:lint:fix` — apply available Stylelint fixes.
|
|
218
|
+
|
|
219
|
+
Edit CSS in `website/content/assets/`. The entrypoint, `site.css`, imports
|
|
220
|
+
underscore-prefixed partials such as `_theme.css` and `_base.css` in cascade
|
|
221
|
+
order. Add a partial with a local import such as `@import './_buttons.css';`.
|
|
222
|
+
The PostCSS plugin recognizes the underscore prefix and does not emit partials
|
|
223
|
+
as separate stylesheets.
|
|
224
|
+
|
|
225
|
+
`@jgarber/eleventy-plugin-postcss` processes the CSS entrypoint using the root
|
|
226
|
+
`postcss.config.js` and `postcss-import`, producing a single `assets/site.css`.
|
|
227
|
+
Partial edits rebuild automatically during `website:dev`; missing imports fail
|
|
228
|
+
the CSS build. Restart the dev server after changing the PostCSS config.
|
|
229
|
+
|
|
230
|
+
Stylelint runs separately via `website:lint`, and automatically before
|
|
231
|
+
`npm run website:build` using an npm pre-script. Dev builds do not run lint on
|
|
232
|
+
every save. Prettier handles formatting; CSS is otherwise left native, without
|
|
233
|
+
prefixing, transpilation, or minification.
|
|
234
|
+
|
|
235
|
+
To build for hosting under `/argot/`, run
|
|
236
|
+
`npm run website:build -- --pathprefix=/argot/`. This prefixes internal URLs;
|
|
237
|
+
place the contents of `website/_site/` in the host's `argot/` directory.
|
|
238
|
+
`WEBSITE_PATH_PREFIX` can also supply the prefix in build environments.
|
|
239
|
+
|
|
240
|
+
The reference works without JavaScript; JavaScript adds search and tier
|
|
241
|
+
filtering. Website files and dependencies are not included in the published
|
|
242
|
+
library package.
|
|
243
|
+
|
|
244
|
+
## Contributing / discussion
|
|
245
|
+
|
|
246
|
+
Help is welcome — especially bikeshedding names, deciding what belongs in the
|
|
247
|
+
“core” set vs. project-specific extras, and comparing against real design
|
|
248
|
+
systems.
|
|
249
|
+
|
|
250
|
+
Open a [GitHub issue](https://github.com/keithjgrant/argot/issues) or
|
|
251
|
+
[discussion](https://github.com/keithjgrant/argot/discussions). Useful feedback
|
|
252
|
+
includes:
|
|
253
|
+
|
|
254
|
+
- Tokens that are missing for common UI needs
|
|
255
|
+
- Tokens that feel too vague, redundant, or framework-specific
|
|
256
|
+
- Naming that collides with how you already think about a design
|
|
257
|
+
- Gaps revealed by comparing against the files in `examples/`
|
|
258
|
+
|
|
259
|
+
The aim is a list general enough for many projects, not tailored to one person’s
|
|
260
|
+
stylesheet. Feedback grounded in real-world use is especially helpful.
|
package/bin/argot.js
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
export declare const ANSI_RED = "\u001B[31m";
|
|
2
|
+
export declare const ANSI_GREEN = "\u001B[32m";
|
|
3
|
+
export declare const ANSI_YELLOW = "\u001B[33m";
|
|
4
|
+
export declare const ANSI_BLUE = "\u001B[34m";
|
|
5
|
+
export declare const ANSI_MAGENTA = "\u001B[35m";
|
|
6
|
+
export declare const ANSI_CYAN = "\u001B[36m";
|
|
7
|
+
export declare const ANSI_WHITE = "\u001B[37m";
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
export const ANSI_RED = '\x1b[31m';
|
|
2
|
+
export const ANSI_GREEN = '\x1b[32m';
|
|
3
|
+
export const ANSI_YELLOW = '\x1b[33m';
|
|
4
|
+
export const ANSI_BLUE = '\x1b[34m';
|
|
5
|
+
export const ANSI_MAGENTA = '\x1b[35m';
|
|
6
|
+
export const ANSI_CYAN = '\x1b[36m';
|
|
7
|
+
export const ANSI_WHITE = '\x1b[37m';
|
|
8
|
+
//# sourceMappingURL=ansiColors.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ansiColors.js","sourceRoot":"","sources":["../../src/cli/ansiColors.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,MAAM,QAAQ,GAAG,UAAU,CAAC;AACnC,MAAM,CAAC,MAAM,UAAU,GAAG,UAAU,CAAC;AACrC,MAAM,CAAC,MAAM,WAAW,GAAG,UAAU,CAAC;AACtC,MAAM,CAAC,MAAM,SAAS,GAAG,UAAU,CAAC;AACpC,MAAM,CAAC,MAAM,YAAY,GAAG,UAAU,CAAC;AACvC,MAAM,CAAC,MAAM,SAAS,GAAG,UAAU,CAAC;AACpC,MAAM,CAAC,MAAM,UAAU,GAAG,UAAU,CAAC","sourcesContent":["export const ANSI_RED = '\\x1b[31m';\nexport const ANSI_GREEN = '\\x1b[32m';\nexport const ANSI_YELLOW = '\\x1b[33m';\nexport const ANSI_BLUE = '\\x1b[34m';\nexport const ANSI_MAGENTA = '\\x1b[35m';\nexport const ANSI_CYAN = '\\x1b[36m';\nexport const ANSI_WHITE = '\\x1b[37m';\n"]}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { ANSI_WHITE, ANSI_RED } from "./ansiColors.js";
|
|
2
|
+
export function print(message, color = ANSI_WHITE) {
|
|
3
|
+
console.log(`${color}${message}${ANSI_WHITE}\n`);
|
|
4
|
+
}
|
|
5
|
+
export function printError(error) {
|
|
6
|
+
const isError = error instanceof Error;
|
|
7
|
+
const message = isError ? `${error.name}: ${error.message}` : error;
|
|
8
|
+
console.error(`${ANSI_RED}argot: ${message}${ANSI_WHITE}\n`);
|
|
9
|
+
if (isError && process.argv.includes('--verbose')) {
|
|
10
|
+
console.log(error);
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
//# sourceMappingURL=print.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"print.js","sourceRoot":"","sources":["../../src/cli/print.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,QAAQ,EAAE,MAAM,iBAAiB,CAAC;AAEvD,MAAM,UAAU,KAAK,CAAC,OAAe,EAAE,QAAgB,UAAU;IAC/D,OAAO,CAAC,GAAG,CAAC,GAAG,KAAK,GAAG,OAAO,GAAG,UAAU,IAAI,CAAC,CAAC;AACnD,CAAC;AAED,MAAM,UAAU,UAAU,CAAC,KAAc;IACvC,MAAM,OAAO,GAAG,KAAK,YAAY,KAAK,CAAC;IACvC,MAAM,OAAO,GAAG,OAAO,CAAC,CAAC,CAAC,GAAG,KAAK,CAAC,IAAI,KAAK,KAAK,CAAC,OAAO,EAAE,CAAC,CAAC,CAAC,KAAK,CAAC;IAEpE,OAAO,CAAC,KAAK,CAAC,GAAG,QAAQ,UAAU,OAAO,GAAG,UAAU,IAAI,CAAC,CAAC;IAE7D,IAAI,OAAO,IAAI,OAAO,CAAC,IAAI,CAAC,QAAQ,CAAC,WAAW,CAAC,EAAE,CAAC;QAClD,OAAO,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC;IACrB,CAAC;AACH,CAAC","sourcesContent":["import { ANSI_WHITE, ANSI_RED } from './ansiColors.ts';\n\nexport function print(message: string, color: string = ANSI_WHITE): void {\n console.log(`${color}${message}${ANSI_WHITE}\\n`);\n}\n\nexport function printError(error: unknown): void {\n const isError = error instanceof Error;\n const message = isError ? `${error.name}: ${error.message}` : error;\n\n console.error(`${ANSI_RED}argot: ${message}${ANSI_WHITE}\\n`);\n\n if (isError && process.argv.includes('--verbose')) {\n console.log(error);\n }\n}\n"]}
|
package/dist/cli/run.js
ADDED
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { USAGE } from "./usage.js";
|
|
2
|
+
import { runSemantics } from "../semantics/cli.js";
|
|
3
|
+
import { runPalette } from "../palette/cli.js";
|
|
4
|
+
import { runProcessor } from "../processor/cli.js";
|
|
5
|
+
import { printError } from "./print.js";
|
|
6
|
+
async function run() {
|
|
7
|
+
try {
|
|
8
|
+
await handleArgs(process.argv.slice(2));
|
|
9
|
+
}
|
|
10
|
+
catch (e) {
|
|
11
|
+
printError(e);
|
|
12
|
+
process.exit(1);
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
async function handleArgs(args) {
|
|
16
|
+
const [command, ...rest] = args;
|
|
17
|
+
if (!command || ['help', '--help', '-h'].includes(command)) {
|
|
18
|
+
process.stdout.write(USAGE);
|
|
19
|
+
return;
|
|
20
|
+
}
|
|
21
|
+
if (command === 'semantics') {
|
|
22
|
+
return await runSemantics(rest);
|
|
23
|
+
}
|
|
24
|
+
if (command === 'palette') {
|
|
25
|
+
return await runPalette(rest);
|
|
26
|
+
}
|
|
27
|
+
if (command.endsWith('.css')) {
|
|
28
|
+
return await runProcessor(args);
|
|
29
|
+
}
|
|
30
|
+
printError(`Unknown command: ${command}`);
|
|
31
|
+
process.exit(1);
|
|
32
|
+
}
|
|
33
|
+
export { run };
|
|
34
|
+
//# sourceMappingURL=run.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"run.js","sourceRoot":"","sources":["../../src/cli/run.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,YAAY,CAAC;AACnC,OAAO,EAAE,YAAY,EAAE,MAAM,qBAAqB,CAAC;AACnD,OAAO,EAAE,UAAU,EAAE,MAAM,mBAAmB,CAAC;AAC/C,OAAO,EAAE,YAAY,EAAE,MAAM,qBAAqB,CAAC;AACnD,OAAO,EAAE,UAAU,EAAE,MAAM,YAAY,CAAC;AAExC,KAAK,UAAU,GAAG;IAChB,IAAI,CAAC;QACH,MAAM,UAAU,CAAC,OAAO,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC;IAC1C,CAAC;IAAC,OAAO,CAAC,EAAE,CAAC;QACX,UAAU,CAAC,CAAC,CAAC,CAAC;QACd,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;IAClB,CAAC;AACH,CAAC;AAED,KAAK,UAAU,UAAU,CAAC,IAAc;IACtC,MAAM,CAAC,OAAO,EAAE,GAAG,IAAI,CAAC,GAAG,IAAI,CAAC;IAEhC,IAAI,CAAC,OAAO,IAAI,CAAC,MAAM,EAAE,QAAQ,EAAE,IAAI,CAAC,CAAC,QAAQ,CAAC,OAAO,CAAC,EAAE,CAAC;QAC3D,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC;QAC5B,OAAO;IACT,CAAC;IAED,IAAI,OAAO,KAAK,WAAW,EAAE,CAAC;QAC5B,OAAO,MAAM,YAAY,CAAC,IAAI,CAAC,CAAC;IAClC,CAAC;IAED,IAAI,OAAO,KAAK,SAAS,EAAE,CAAC;QAC1B,OAAO,MAAM,UAAU,CAAC,IAAI,CAAC,CAAC;IAChC,CAAC;IAED,IAAI,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAC,EAAE,CAAC;QAC7B,OAAO,MAAM,YAAY,CAAC,IAAI,CAAC,CAAC;IAClC,CAAC;IAED,UAAU,CAAC,oBAAoB,OAAO,EAAE,CAAC,CAAC;IAC1C,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;AAClB,CAAC;AAED,OAAO,EAAE,GAAG,EAAE,CAAC","sourcesContent":["import { USAGE } from './usage.ts';\nimport { runSemantics } from '../semantics/cli.ts';\nimport { runPalette } from '../palette/cli.ts';\nimport { runProcessor } from '../processor/cli.ts';\nimport { printError } from './print.ts';\n\nasync function run() {\n try {\n await handleArgs(process.argv.slice(2));\n } catch (e) {\n printError(e);\n process.exit(1);\n }\n}\n\nasync function handleArgs(args: string[]) {\n const [command, ...rest] = args;\n\n if (!command || ['help', '--help', '-h'].includes(command)) {\n process.stdout.write(USAGE);\n return;\n }\n\n if (command === 'semantics') {\n return await runSemantics(rest);\n }\n\n if (command === 'palette') {\n return await runPalette(rest);\n }\n\n if (command.endsWith('.css')) {\n return await runProcessor(args);\n }\n\n printError(`Unknown command: ${command}`);\n process.exit(1);\n}\n\nexport { run };\n"]}
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
declare const USAGE = "Usage:\n argot [sourceFile.css] [destFile.css] Process CSS\n argot semantics [path] [--extended] Write semantic CSS template (default: ./semantics.css)\n argot palette <definition.json> [output.css] [--force] [--dry-run]\n Write primitive CSS (default: ./primitives.css)\n argot help Show this help\n\nOptions:\n --extended Include extended-tier tokens (default: core only)\n\nExamples:\n npx argot-css semantics\n npx argot-css semantics --extended\n npx argot-css semantics ./styles/tokens.css --extended\n";
|
|
2
|
+
export { USAGE };
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
const USAGE = `Usage:
|
|
2
|
+
argot [sourceFile.css] [destFile.css] Process CSS
|
|
3
|
+
argot semantics [path] [--extended] Write semantic CSS template (default: ./semantics.css)
|
|
4
|
+
argot palette <definition.json> [output.css] [--force] [--dry-run]
|
|
5
|
+
Write primitive CSS (default: ./primitives.css)
|
|
6
|
+
argot help Show this help
|
|
7
|
+
|
|
8
|
+
Options:
|
|
9
|
+
--extended Include extended-tier tokens (default: core only)
|
|
10
|
+
|
|
11
|
+
Examples:
|
|
12
|
+
npx argot-css semantics
|
|
13
|
+
npx argot-css semantics --extended
|
|
14
|
+
npx argot-css semantics ./styles/tokens.css --extended
|
|
15
|
+
`;
|
|
16
|
+
export { USAGE };
|
|
17
|
+
//# sourceMappingURL=usage.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"usage.js","sourceRoot":"","sources":["../../src/cli/usage.ts"],"names":[],"mappings":"AAAA,MAAM,KAAK,GAAG;;;;;;;;;;;;;;CAcb,CAAC;AAEF,OAAO,EAAE,KAAK,EAAE,CAAC","sourcesContent":["const USAGE = `Usage:\n argot [sourceFile.css] [destFile.css] Process CSS\n argot semantics [path] [--extended] Write semantic CSS template (default: ./semantics.css)\n argot palette <definition.json> [output.css] [--force] [--dry-run]\n Write primitive CSS (default: ./primitives.css)\n argot help Show this help\n\nOptions:\n --extended Include extended-tier tokens (default: core only)\n\nExamples:\n npx argot-css semantics\n npx argot-css semantics --extended\n npx argot-css semantics ./styles/tokens.css --extended\n`;\n\nexport { USAGE };\n"]}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import path from 'node:path';
|
|
2
|
+
import { parseArgs } from 'node:util';
|
|
3
|
+
import { loadPaletteDefinition, writePalette } from "./node.js";
|
|
4
|
+
function runPalette(args) {
|
|
5
|
+
const { values, positionals } = parseArgs({
|
|
6
|
+
args,
|
|
7
|
+
allowPositionals: true,
|
|
8
|
+
options: {
|
|
9
|
+
force: { type: 'boolean', default: false },
|
|
10
|
+
'dry-run': { type: 'boolean', default: false },
|
|
11
|
+
help: { type: 'boolean', short: 'h', default: false },
|
|
12
|
+
},
|
|
13
|
+
});
|
|
14
|
+
if (values.help) {
|
|
15
|
+
console.log('Usage: argot palette <definition.json> [output.css] [--force] [--dry-run]');
|
|
16
|
+
return;
|
|
17
|
+
}
|
|
18
|
+
if (positionals.length < 1 || positionals.length > 2) {
|
|
19
|
+
throw new Error('Usage: argot palette <definition.json> [output.css] [--force] [--dry-run]');
|
|
20
|
+
}
|
|
21
|
+
const [input, output = 'primitives.css'] = positionals;
|
|
22
|
+
if (path.resolve(input) === path.resolve(output)) {
|
|
23
|
+
throw new Error('Palette input and output paths must be different');
|
|
24
|
+
}
|
|
25
|
+
const definition = loadPaletteDefinition(input);
|
|
26
|
+
const result = writePalette(output, definition, {
|
|
27
|
+
force: values.force,
|
|
28
|
+
dryRun: values['dry-run'],
|
|
29
|
+
});
|
|
30
|
+
console.log(`${result.written ? 'Wrote' : 'Would write'} ${result.path}`);
|
|
31
|
+
}
|
|
32
|
+
export { runPalette };
|
|
33
|
+
//# sourceMappingURL=cli.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"cli.js","sourceRoot":"","sources":["../../src/palette/cli.ts"],"names":[],"mappings":"AAAA,OAAO,IAAI,MAAM,WAAW,CAAC;AAC7B,OAAO,EAAE,SAAS,EAAE,MAAM,WAAW,CAAC;AACtC,OAAO,EAAE,qBAAqB,EAAE,YAAY,EAAE,MAAM,WAAW,CAAC;AAEhE,SAAS,UAAU,CAAC,IAAc;IAChC,MAAM,EAAE,MAAM,EAAE,WAAW,EAAE,GAAG,SAAS,CAAC;QACxC,IAAI;QACJ,gBAAgB,EAAE,IAAI;QACtB,OAAO,EAAE;YACP,KAAK,EAAE,EAAE,IAAI,EAAE,SAAS,EAAE,OAAO,EAAE,KAAK,EAAE;YAC1C,SAAS,EAAE,EAAE,IAAI,EAAE,SAAS,EAAE,OAAO,EAAE,KAAK,EAAE;YAC9C,IAAI,EAAE,EAAE,IAAI,EAAE,SAAS,EAAE,KAAK,EAAE,GAAG,EAAE,OAAO,EAAE,KAAK,EAAE;SACtD;KACF,CAAC,CAAC;IACH,IAAI,MAAM,CAAC,IAAI,EAAE,CAAC;QAChB,OAAO,CAAC,GAAG,CACT,2EAA2E,CAC5E,CAAC;QACF,OAAO;IACT,CAAC;IACD,IAAI,WAAW,CAAC,MAAM,GAAG,CAAC,IAAI,WAAW,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;QACrD,MAAM,IAAI,KAAK,CACb,2EAA2E,CAC5E,CAAC;IACJ,CAAC;IACD,MAAM,CAAC,KAAK,EAAE,MAAM,GAAG,gBAAgB,CAAC,GAAG,WAAW,CAAC;IACvD,IAAI,IAAI,CAAC,OAAO,CAAC,KAAK,CAAC,KAAK,IAAI,CAAC,OAAO,CAAC,MAAM,CAAC,EAAE,CAAC;QACjD,MAAM,IAAI,KAAK,CAAC,kDAAkD,CAAC,CAAC;IACtE,CAAC;IACD,MAAM,UAAU,GAAG,qBAAqB,CAAC,KAAK,CAAC,CAAC;IAChD,MAAM,MAAM,GAAG,YAAY,CAAC,MAAM,EAAE,UAAU,EAAE;QAC9C,KAAK,EAAE,MAAM,CAAC,KAAK;QACnB,MAAM,EAAE,MAAM,CAAC,SAAS,CAAC;KAC1B,CAAC,CAAC;IACH,OAAO,CAAC,GAAG,CAAC,GAAG,MAAM,CAAC,OAAO,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,aAAa,IAAI,MAAM,CAAC,IAAI,EAAE,CAAC,CAAC;AAC5E,CAAC;AAED,OAAO,EAAE,UAAU,EAAE,CAAC","sourcesContent":["import path from 'node:path';\nimport { parseArgs } from 'node:util';\nimport { loadPaletteDefinition, writePalette } from './node.ts';\n\nfunction runPalette(args: string[]): void {\n const { values, positionals } = parseArgs({\n args,\n allowPositionals: true,\n options: {\n force: { type: 'boolean', default: false },\n 'dry-run': { type: 'boolean', default: false },\n help: { type: 'boolean', short: 'h', default: false },\n },\n });\n if (values.help) {\n console.log(\n 'Usage: argot palette <definition.json> [output.css] [--force] [--dry-run]',\n );\n return;\n }\n if (positionals.length < 1 || positionals.length > 2) {\n throw new Error(\n 'Usage: argot palette <definition.json> [output.css] [--force] [--dry-run]',\n );\n }\n const [input, output = 'primitives.css'] = positionals;\n if (path.resolve(input) === path.resolve(output)) {\n throw new Error('Palette input and output paths must be different');\n }\n const definition = loadPaletteDefinition(input);\n const result = writePalette(output, definition, {\n force: values.force,\n dryRun: values['dry-run'],\n });\n console.log(`${result.written ? 'Wrote' : 'Would write'} ${result.path}`);\n}\n\nexport { runPalette };\n"]}
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
const NAMES = {
|
|
2
|
+
0: 'raspberry',
|
|
3
|
+
15: 'cherry',
|
|
4
|
+
30: 'red',
|
|
5
|
+
45: 'sienna',
|
|
6
|
+
60: 'orange',
|
|
7
|
+
75: 'gold',
|
|
8
|
+
90: 'lemon',
|
|
9
|
+
105: 'yellow',
|
|
10
|
+
120: 'avocado',
|
|
11
|
+
135: 'jungle',
|
|
12
|
+
150: 'green',
|
|
13
|
+
165: 'mint',
|
|
14
|
+
180: 'seafoam',
|
|
15
|
+
195: 'teal',
|
|
16
|
+
210: 'cyan',
|
|
17
|
+
225: 'sapphire',
|
|
18
|
+
240: 'azure',
|
|
19
|
+
255: 'blue',
|
|
20
|
+
270: 'indigo',
|
|
21
|
+
285: 'violet',
|
|
22
|
+
300: 'lilac',
|
|
23
|
+
315: 'purple',
|
|
24
|
+
330: 'grape',
|
|
25
|
+
345: 'pink',
|
|
26
|
+
360: 'raspberry',
|
|
27
|
+
};
|
|
28
|
+
const NEUTRAL_NAMES = {
|
|
29
|
+
0: 'dust',
|
|
30
|
+
60: 'sand',
|
|
31
|
+
120: 'stone',
|
|
32
|
+
180: 'sage',
|
|
33
|
+
240: 'slate',
|
|
34
|
+
300: 'ash',
|
|
35
|
+
360: 'dust',
|
|
36
|
+
};
|
|
37
|
+
export function generateName(color) {
|
|
38
|
+
const { c, h } = color;
|
|
39
|
+
let rounded, names;
|
|
40
|
+
if (c >= 0.05) {
|
|
41
|
+
names = NAMES;
|
|
42
|
+
rounded = Math.round(h / 15) * 15;
|
|
43
|
+
}
|
|
44
|
+
else {
|
|
45
|
+
names = NEUTRAL_NAMES;
|
|
46
|
+
rounded = Math.round(h / 60) * 60;
|
|
47
|
+
}
|
|
48
|
+
return names[rounded] || 'unnamed';
|
|
49
|
+
}
|
|
50
|
+
export function dedupeNames(colors) {
|
|
51
|
+
const names = [];
|
|
52
|
+
const all = [...colors];
|
|
53
|
+
all.forEach((color) => {
|
|
54
|
+
if (!color.name) {
|
|
55
|
+
return;
|
|
56
|
+
}
|
|
57
|
+
names.push(color.name);
|
|
58
|
+
const count = names.filter((n) => n === color.name).length;
|
|
59
|
+
if (count > 1) {
|
|
60
|
+
color.name = `${color.name}${count}`;
|
|
61
|
+
}
|
|
62
|
+
});
|
|
63
|
+
return colors;
|
|
64
|
+
}
|
|
65
|
+
//# sourceMappingURL=generateName.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"generateName.js","sourceRoot":"","sources":["../../src/palette/generateName.ts"],"names":[],"mappings":"AAEA,MAAM,KAAK,GAAG;IACZ,CAAC,EAAE,WAAW;IACd,EAAE,EAAE,QAAQ;IACZ,EAAE,EAAE,KAAK;IACT,EAAE,EAAE,QAAQ;IACZ,EAAE,EAAE,QAAQ;IACZ,EAAE,EAAE,MAAM;IACV,EAAE,EAAE,OAAO;IACX,GAAG,EAAE,QAAQ;IACb,GAAG,EAAE,SAAS;IACd,GAAG,EAAE,QAAQ;IACb,GAAG,EAAE,OAAO;IACZ,GAAG,EAAE,MAAM;IACX,GAAG,EAAE,SAAS;IACd,GAAG,EAAE,MAAM;IACX,GAAG,EAAE,MAAM;IACX,GAAG,EAAE,UAAU;IACf,GAAG,EAAE,OAAO;IACZ,GAAG,EAAE,MAAM;IACX,GAAG,EAAE,QAAQ;IACb,GAAG,EAAE,QAAQ;IACb,GAAG,EAAE,OAAO;IACZ,GAAG,EAAE,QAAQ;IACb,GAAG,EAAE,OAAO;IACZ,GAAG,EAAE,MAAM;IACX,GAAG,EAAE,WAAW;CACjB,CAAC;AACF,MAAM,aAAa,GAAG;IACpB,CAAC,EAAE,MAAM;IACT,EAAE,EAAE,MAAM;IACV,GAAG,EAAE,OAAO;IACZ,GAAG,EAAE,MAAM;IACX,GAAG,EAAE,OAAO;IACZ,GAAG,EAAE,KAAK;IACV,GAAG,EAAE,MAAM;CACZ,CAAC;AAEF,MAAM,UAAU,YAAY,CAAC,KAAiB;IAC5C,MAAM,EAAE,CAAC,EAAE,CAAC,EAAE,GAAG,KAAK,CAAC;IACvB,IAAI,OAAe,EAAE,KAA8B,CAAC;IACpD,IAAI,CAAC,IAAI,IAAI,EAAE,CAAC;QACd,KAAK,GAAG,KAAK,CAAC;QACd,OAAO,GAAG,IAAI,CAAC,KAAK,CAAC,CAAC,GAAG,EAAE,CAAC,GAAG,EAAE,CAAC;IACpC,CAAC;SAAM,CAAC;QACN,KAAK,GAAG,aAAa,CAAC;QACtB,OAAO,GAAG,IAAI,CAAC,KAAK,CAAC,CAAC,GAAG,EAAE,CAAC,GAAG,EAAE,CAAC;IACpC,CAAC;IAED,OAAO,KAAK,CAAC,OAAO,CAAC,IAAI,SAAS,CAAC;AACrC,CAAC;AAED,MAAM,UAAU,WAAW,CAAC,MAA6B;IACvD,MAAM,KAAK,GAAa,EAAE,CAAC;IAC3B,MAAM,GAAG,GAAG,CAAC,GAAG,MAAM,CAAC,CAAC;IACxB,GAAG,CAAC,OAAO,CAAC,CAAC,KAAK,EAAE,EAAE;QACpB,IAAI,CAAC,KAAK,CAAC,IAAI,EAAE,CAAC;YAChB,OAAO;QACT,CAAC;QAED,KAAK,CAAC,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;QACvB,MAAM,KAAK,GAAG,KAAK,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,KAAK,KAAK,CAAC,IAAI,CAAC,CAAC,MAAM,CAAC;QAE3D,IAAI,KAAK,GAAG,CAAC,EAAE,CAAC;YACd,KAAK,CAAC,IAAI,GAAG,GAAG,KAAK,CAAC,IAAI,GAAG,KAAK,EAAE,CAAC;QACvC,CAAC;IACH,CAAC,CAAC,CAAC;IACH,OAAO,MAAM,CAAC;AAChB,CAAC","sourcesContent":["import type { OklchColor, NormalizedSeedColor } from './types.ts';\n\nconst NAMES = {\n 0: 'raspberry',\n 15: 'cherry',\n 30: 'red',\n 45: 'sienna',\n 60: 'orange',\n 75: 'gold',\n 90: 'lemon',\n 105: 'yellow',\n 120: 'avocado',\n 135: 'jungle',\n 150: 'green',\n 165: 'mint',\n 180: 'seafoam',\n 195: 'teal',\n 210: 'cyan',\n 225: 'sapphire',\n 240: 'azure',\n 255: 'blue',\n 270: 'indigo',\n 285: 'violet',\n 300: 'lilac',\n 315: 'purple',\n 330: 'grape',\n 345: 'pink',\n 360: 'raspberry',\n};\nconst NEUTRAL_NAMES = {\n 0: 'dust',\n 60: 'sand',\n 120: 'stone',\n 180: 'sage',\n 240: 'slate',\n 300: 'ash',\n 360: 'dust',\n};\n\nexport function generateName(color: OklchColor): string {\n const { c, h } = color;\n let rounded: number, names: { [k: number]: string };\n if (c >= 0.05) {\n names = NAMES;\n rounded = Math.round(h / 15) * 15;\n } else {\n names = NEUTRAL_NAMES;\n rounded = Math.round(h / 60) * 60;\n }\n\n return names[rounded] || 'unnamed';\n}\n\nexport function dedupeNames(colors: NormalizedSeedColor[]) {\n const names: string[] = [];\n const all = [...colors];\n all.forEach((color) => {\n if (!color.name) {\n return;\n }\n\n names.push(color.name);\n const count = names.filter((n) => n === color.name).length;\n\n if (count > 1) {\n color.name = `${color.name}${count}`;\n }\n });\n return colors;\n}\n"]}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type { Palette, PaletteDefinition } from './types.ts';
|
|
2
|
+
/**
|
|
3
|
+
* Generate serializable raw OKLCH scales, before gamut mapping or rounding.
|
|
4
|
+
* Steps and baseStep are one-based; input order is preserved without mutation.
|
|
5
|
+
*/
|
|
6
|
+
declare function generatePalette(definition: PaletteDefinition): Palette;
|
|
7
|
+
export { generatePalette };
|
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
import { normalizePaletteDefinition } from "./validation.js";
|
|
2
|
+
const LIGHTNESS = Object.freeze([
|
|
3
|
+
0.98, 0.97, 0.93, 0.84, 0.8, 0.71, 0.66, 0.58, 0.53, 0.49, 0.42, 0.35, 0.27,
|
|
4
|
+
0.2, 0.16, 0.1,
|
|
5
|
+
]);
|
|
6
|
+
const CHROMA = Object.freeze([
|
|
7
|
+
0.14, 0.29, 0.48, 0.57, 0.76, 0.9, 0.95, 1, 0.95, 0.9, 0.81, 0.71, 0.57, 0.43,
|
|
8
|
+
0.33, 0.24,
|
|
9
|
+
]);
|
|
10
|
+
/**
|
|
11
|
+
* Generate serializable raw OKLCH scales, before gamut mapping or rounding.
|
|
12
|
+
* Steps and baseStep are one-based; input order is preserved without mutation.
|
|
13
|
+
*/
|
|
14
|
+
function generatePalette(definition) {
|
|
15
|
+
const normalized = normalizePaletteDefinition(definition);
|
|
16
|
+
const colors = normalized.seedColors.map((seed) => generateScale(seed, definition.options || {}));
|
|
17
|
+
return { version: 1, options: normalized.options, colors };
|
|
18
|
+
}
|
|
19
|
+
// TODO skip normalizing, just fill in defaults here
|
|
20
|
+
function generateScale(seed, options) {
|
|
21
|
+
const { lightnessCurve = 'uniform', chromaCurve = 'centered' } = options;
|
|
22
|
+
const index = findTargetIndex(seed.l);
|
|
23
|
+
const chromaScale = chromaCurve === 'weighted' ? buildChromaCurve(index, seed.c) : CHROMA;
|
|
24
|
+
const anchor = lightnessCurve === 'centered' ? 8 : index;
|
|
25
|
+
// Centered lightness rescales the original chroma curve at step 9; it does
|
|
26
|
+
// not rebuild the weighted curve around that step.
|
|
27
|
+
let chromaMultiplier = 1;
|
|
28
|
+
if (lightnessCurve === 'centered') {
|
|
29
|
+
chromaMultiplier = seed.c / chromaScale[8];
|
|
30
|
+
}
|
|
31
|
+
else if (chromaCurve === 'centered') {
|
|
32
|
+
chromaMultiplier = seed.c / chromaScale[index];
|
|
33
|
+
}
|
|
34
|
+
if (!Number.isFinite(chromaMultiplier)) {
|
|
35
|
+
// handle divide by zero for 0-chroma values
|
|
36
|
+
chromaMultiplier = 0;
|
|
37
|
+
}
|
|
38
|
+
const lightness = lightnessCurve === 'uniform'
|
|
39
|
+
? LIGHTNESS
|
|
40
|
+
: buildInclusiveLightnessCurve(seed.l, anchor);
|
|
41
|
+
return {
|
|
42
|
+
name: seed.name,
|
|
43
|
+
baseStep: anchor + 1,
|
|
44
|
+
steps: lightness.map((l, index) => ({
|
|
45
|
+
step: index + 1,
|
|
46
|
+
l,
|
|
47
|
+
c: chromaScale[index] * chromaMultiplier,
|
|
48
|
+
h: seed.h,
|
|
49
|
+
})),
|
|
50
|
+
};
|
|
51
|
+
}
|
|
52
|
+
function findTargetIndex(lightness) {
|
|
53
|
+
const after = LIGHTNESS.findIndex((value) => value < lightness);
|
|
54
|
+
const before = after !== -1 ? after - 1 : 15;
|
|
55
|
+
if (after === -1)
|
|
56
|
+
return before;
|
|
57
|
+
if (before === -1)
|
|
58
|
+
return after;
|
|
59
|
+
const beforeDiff = LIGHTNESS[before] - lightness;
|
|
60
|
+
const afterDiff = lightness - LIGHTNESS[after];
|
|
61
|
+
return beforeDiff < afterDiff ? before : after;
|
|
62
|
+
}
|
|
63
|
+
function buildChromaCurve(index, peakValue) {
|
|
64
|
+
const endValue = peakValue < 0.04 ? 0 : 0.01;
|
|
65
|
+
const beforeSteps = index;
|
|
66
|
+
const afterSteps = 15 - index;
|
|
67
|
+
const beforeInterval = (peakValue - endValue) / beforeSteps;
|
|
68
|
+
const afterInterval = (peakValue - endValue) / afterSteps;
|
|
69
|
+
const scale = [];
|
|
70
|
+
for (let i = beforeSteps; i > 0; i--) {
|
|
71
|
+
scale.push(peakValue - i * beforeInterval);
|
|
72
|
+
}
|
|
73
|
+
scale.push(peakValue);
|
|
74
|
+
for (let i = 1; i <= afterSteps; i++) {
|
|
75
|
+
scale.push(peakValue - i * afterInterval);
|
|
76
|
+
}
|
|
77
|
+
return scale;
|
|
78
|
+
}
|
|
79
|
+
function buildInclusiveLightnessCurve(lightness, index) {
|
|
80
|
+
const maxLightness = LIGHTNESS[0];
|
|
81
|
+
const minLightness = LIGHTNESS[15];
|
|
82
|
+
const lSteps = index;
|
|
83
|
+
const dSteps = 15 - index;
|
|
84
|
+
const lInterval = (maxLightness - lightness) / lSteps;
|
|
85
|
+
const dInterval = (lightness - minLightness) / dSteps;
|
|
86
|
+
const lightnessScale = [];
|
|
87
|
+
for (let i = 0; i < lSteps; i++) {
|
|
88
|
+
lightnessScale.push(maxLightness - i * lInterval);
|
|
89
|
+
}
|
|
90
|
+
lightnessScale.push(lightness);
|
|
91
|
+
for (let i = 1; i <= dSteps; i++) {
|
|
92
|
+
lightnessScale.push(lightness - i * dInterval);
|
|
93
|
+
}
|
|
94
|
+
return lightnessScale;
|
|
95
|
+
}
|
|
96
|
+
export { generatePalette };
|
|
97
|
+
//# sourceMappingURL=generatePalette.js.map
|