shweet 0.0.33 → 0.0.35
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/README.md +992 -1
- package/dist/index.d.ts +367 -381
- package/dist/index.js +11 -11
- package/package.json +8 -9
package/README.md
CHANGED
|
@@ -1,3 +1,994 @@
|
|
|
1
1
|
# Shweet CSS
|
|
2
2
|
|
|
3
|
-
CSS
|
|
3
|
+
TypeScript-first CSS authoring. Shweet provides a Proxy-based assignment API for
|
|
4
|
+
writing styles in TypeScript, then compiles those assignments to a CSS file and,
|
|
5
|
+
optionally, a class/id export map.
|
|
6
|
+
|
|
7
|
+
Shweet is published on npm as `shweet` and is currently at `0.0.x`. The published
|
|
8
|
+
package ships compiled `dist/index.js` with declarations at `dist/index.d.ts`.
|
|
9
|
+
The declarations are bundled into a single self-contained file, so consumers do
|
|
10
|
+
not need Shweet's build-time helper packages.
|
|
11
|
+
|
|
12
|
+
## Install
|
|
13
|
+
|
|
14
|
+
```bash
|
|
15
|
+
bun add shweet
|
|
16
|
+
```
|
|
17
|
+
|
|
18
|
+
TypeScript `^5.8.2` is a peer dependency. The examples and test suite in this
|
|
19
|
+
repository run with Bun.
|
|
20
|
+
|
|
21
|
+
## Supported toolchain matrix
|
|
22
|
+
|
|
23
|
+
Shweet's supported range is the TypeScript `^5.8.2` peer dependency plus the
|
|
24
|
+
Node and Bun versions in the table below. The matrix is deliberately bounded:
|
|
25
|
+
other combinations may work, but they are not validated here.
|
|
26
|
+
|
|
27
|
+
| Tool | Validated values | What was checked |
|
|
28
|
+
| --- | --- | --- |
|
|
29
|
+
| Bun | `1.4.4` | Complete `bun test` suite, including the isolated builder used by the packed-package smoke test |
|
|
30
|
+
| Node | `24.22.3` and `26.13.1` | Node ESM root/deep imports of the packed archive and the strict consumer typecheck |
|
|
31
|
+
| TypeScript | `5.8.2` (peer minimum) and `5.9.3` | Project typecheck and the packed-package consumer typecheck with `skipLibCheck: false` |
|
|
32
|
+
|
|
33
|
+
The evidence behind this table is local: Bun `1.4.4` ran the full suite, and
|
|
34
|
+
Node `24.22.3` and `26.13.1` were each crossed with TypeScript `5.8.2` and
|
|
35
|
+
`5.9.3` for the project typecheck and the packed-package smoke test. Those runs
|
|
36
|
+
were executed on a developer machine, not in hosted CI. The repository ships no
|
|
37
|
+
always-on workflow, so no hosted result is claimed and no combination outside
|
|
38
|
+
this table is implied to be supported. A local run can only cover the Node, Bun,
|
|
39
|
+
and TypeScript versions installed on that machine.
|
|
40
|
+
|
|
41
|
+
Reproduce the Bun suite and the project typecheck:
|
|
42
|
+
|
|
43
|
+
```bash
|
|
44
|
+
bun test
|
|
45
|
+
bunx tsc --noEmit --incremental false --typeRoots node_modules/@types
|
|
46
|
+
```
|
|
47
|
+
|
|
48
|
+
Reproduce one Node × TypeScript matrix entry by installing that compiler
|
|
49
|
+
outside the checkout, then typechecking and running the packed-package smoke
|
|
50
|
+
test with the same binary:
|
|
51
|
+
|
|
52
|
+
```bash
|
|
53
|
+
# Example: TypeScript 5.8.2 under the active Node release
|
|
54
|
+
compiler_dir="${TMPDIR:-/tmp}/shweet-ts-5.8.2"
|
|
55
|
+
npm install --prefix "$compiler_dir" --no-save --no-audit --no-fund \
|
|
56
|
+
--ignore-scripts --save-exact typescript@5.8.2
|
|
57
|
+
node "$compiler_dir/node_modules/typescript/lib/tsc.js" --version
|
|
58
|
+
|
|
59
|
+
node "$compiler_dir/node_modules/typescript/lib/tsc.js" \
|
|
60
|
+
--noEmit --incremental false --typeRoots node_modules/@types
|
|
61
|
+
|
|
62
|
+
bun test/package-smoke.ts \
|
|
63
|
+
--tsc "$compiler_dir/node_modules/typescript/lib/tsc.js" \
|
|
64
|
+
--typescript-version 5.8.2
|
|
65
|
+
```
|
|
66
|
+
|
|
67
|
+
Repeat with TypeScript `5.9.3` and with the `node` binary for Node `24.22.3`
|
|
68
|
+
and `26.13.1` on `PATH`. The smoke test builds and packs the project, installs
|
|
69
|
+
the archive into a fresh consumer, checks the packed root and deep ESM imports
|
|
70
|
+
under the active Node, and typechecks the consumer against the packed
|
|
71
|
+
declarations. The compiler override is described with the package smoke test
|
|
72
|
+
commands below.
|
|
73
|
+
|
|
74
|
+
The checked-in `tsconfig.json` spells `typeRoots` as `node_module/@types`
|
|
75
|
+
(missing the `s`). On a clean checkout with no ambient `node_modules` in an
|
|
76
|
+
ancestor directory, pass `--typeRoots node_modules/@types` explicitly as shown
|
|
77
|
+
above so the installed Node and Bun types are used. `tsconfig.json` itself is
|
|
78
|
+
left unchanged.
|
|
79
|
+
|
|
80
|
+
Local linked helpers: `package.json` declares `@ohmyqt/oven` and `@ohmyqt/u` as
|
|
81
|
+
`link:` specifiers. Both helpers are available in this local workspace as
|
|
82
|
+
siblings of the Shweet checkout, at `../@ohmyqt/oven` and `../@ohmyqt/u`.
|
|
83
|
+
`node_modules/@ohmyqt/u` is a symlink that resolves to `../@ohmyqt/u`, and
|
|
84
|
+
`node_modules/@ohmyqt/oven` resolves to `../@ohmyqt/oven`. Their `src/` and
|
|
85
|
+
`dist/` directories exist here, so the project install and test suite resolve
|
|
86
|
+
locally without missing helpers.
|
|
87
|
+
|
|
88
|
+
Limitation for clean checkouts and future CI: the helper source is not committed
|
|
89
|
+
to the public helper repository in a form a clean runner can provision. In the
|
|
90
|
+
local helper Git checkout, `u/src` is untracked (as are `u/types`), and the
|
|
91
|
+
public `master` branch has no committed `u/src` or `u/dist`; only `u/builder.ts`,
|
|
92
|
+
package metadata, lockfiles, and TypeScript config are tracked. The local
|
|
93
|
+
sibling package is present and usable, but a hosted runner that clones the public
|
|
94
|
+
repository would not receive those sources, so a workflow would fail during
|
|
95
|
+
helper provisioning on every push and pull request. No workflow is committed for
|
|
96
|
+
that reason. Automation becomes possible only if the helper sources are published
|
|
97
|
+
or otherwise made available to a clean checkout; until then, the matrix above is
|
|
98
|
+
the available evidence. This is a stated limitation, not a commitment to publish
|
|
99
|
+
the helpers.
|
|
100
|
+
|
|
101
|
+
## Quick start
|
|
102
|
+
|
|
103
|
+
```ts
|
|
104
|
+
// styles.ts
|
|
105
|
+
import { Shweet, med, ps } from "shweet";
|
|
106
|
+
|
|
107
|
+
const app = new Shweet({
|
|
108
|
+
__filename,
|
|
109
|
+
prefix: "app",
|
|
110
|
+
exportMap: true,
|
|
111
|
+
mediaFeature: {
|
|
112
|
+
standalone: "(display-mode: standalone)",
|
|
113
|
+
},
|
|
114
|
+
});
|
|
115
|
+
|
|
116
|
+
// Keep the instance for saving and media helpers, and destructure the
|
|
117
|
+
// assignment handlers once.
|
|
118
|
+
const { c, i, d, kf } = app;
|
|
119
|
+
|
|
120
|
+
// `c.name` creates a class rule; the prefix is applied at compile time.
|
|
121
|
+
c.card = {
|
|
122
|
+
display: "grid",
|
|
123
|
+
gap: 1,
|
|
124
|
+
padding: 1,
|
|
125
|
+
fontSize: med(1, { md: 1.25 }),
|
|
126
|
+
color: med("black", { dark: "white", standalone: "navy" }),
|
|
127
|
+
};
|
|
128
|
+
|
|
129
|
+
// Names that are not valid identifiers use bracket notation.
|
|
130
|
+
c["card-title"] = { fontWeight: "bold" };
|
|
131
|
+
|
|
132
|
+
// `i` and `d` write id rules and arbitrary selectors.
|
|
133
|
+
i.main = { maxWidth: 60 };
|
|
134
|
+
d["body"] = { margin: "0 auto" };
|
|
135
|
+
|
|
136
|
+
// `kf` writes keyframes; matching animation names are prefixed too.
|
|
137
|
+
kf.pulse = {
|
|
138
|
+
from: { opacity: 1 },
|
|
139
|
+
"50%": { opacity: 0.5 },
|
|
140
|
+
to: { opacity: 1 },
|
|
141
|
+
};
|
|
142
|
+
c.pulse = { animation: "pulse 2s infinite" };
|
|
143
|
+
|
|
144
|
+
// Arrays combine declarations, nested selectors, and conditional blocks.
|
|
145
|
+
c.grid = [
|
|
146
|
+
{ display: "grid" },
|
|
147
|
+
ps.child(".cell")({ minHeight: 2 }),
|
|
148
|
+
];
|
|
149
|
+
|
|
150
|
+
app.save({
|
|
151
|
+
dir: "./generated",
|
|
152
|
+
mapDir: "./generated",
|
|
153
|
+
minify: false,
|
|
154
|
+
});
|
|
155
|
+
```
|
|
156
|
+
|
|
157
|
+
Run it with Bun:
|
|
158
|
+
|
|
159
|
+
```bash
|
|
160
|
+
bun styles.ts
|
|
161
|
+
```
|
|
162
|
+
|
|
163
|
+
This writes `generated/styles.css` plus `generated/index.js`. The export map is a
|
|
164
|
+
JavaScript module of named exports: each key is unprefixed and uses `_` in place
|
|
165
|
+
of `-`, while each value carries the prefix (for example `card="app_card"`).
|
|
166
|
+
|
|
167
|
+
## The assignment API
|
|
168
|
+
|
|
169
|
+
`new Shweet(options)` returns an instance whose handlers are Proxies. Assigning a
|
|
170
|
+
property creates a rule in assignment order:
|
|
171
|
+
|
|
172
|
+
| Handler | Writes | Example |
|
|
173
|
+
| --- | --- | --- |
|
|
174
|
+
| `c` | class selectors | `c.card = { color: "red" }` → `.app_card` |
|
|
175
|
+
| `i` | id selectors | `i.main = { ... }` → `#app_main` |
|
|
176
|
+
| `d` | arbitrary selectors | `d["#app"] = { ... }` |
|
|
177
|
+
| `kf` | `@keyframes` | `kf.pulse = { from: { opacity: 1 } }` |
|
|
178
|
+
| `at` | simple at-rules | `at.import = "theme.css"` → `@import "theme.css";` |
|
|
179
|
+
| `font` | `@font-face` | `font.Inter = { src: "url(inter.woff2)", fontDisplay: "swap" }` |
|
|
180
|
+
|
|
181
|
+
Values are plain CSS declarations. Bare numbers become `rem` by default; use the
|
|
182
|
+
`unit` option to select `rem`, `em`, `px`, `pt`, or `pc`. Known unitless
|
|
183
|
+
properties such as `lineHeight`, `fontWeight`, `zIndex`, and `tabSize` keep the
|
|
184
|
+
bare number, and time properties receive seconds. Legacy
|
|
185
|
+
`"property: value; ..."` strings are also accepted, and arrays or `c.__({...})`
|
|
186
|
+
can be used for bulk assignment. Nested keys such as `":hover"` and `" .child"`
|
|
187
|
+
create nested selectors; `ps` provides typed helpers for the same forms
|
|
188
|
+
(`ps.hover()`, `ps.child(".cell")`, `ps.before()`, and so on). The accepted
|
|
189
|
+
declaration, selector, media, import, animation, and custom-property forms are
|
|
190
|
+
collected in the [Supported input reference](#supported-input-reference).
|
|
191
|
+
|
|
192
|
+
### Media conditions with `med`
|
|
193
|
+
|
|
194
|
+
`med` describes one value across media buckets. The first argument is the
|
|
195
|
+
default value; the optional second argument maps named buckets to overrides:
|
|
196
|
+
|
|
197
|
+
```ts
|
|
198
|
+
app.c.panel = {
|
|
199
|
+
display: med("block", { md: "flex" }),
|
|
200
|
+
padding: med(1, { md: 1.5, print: 0 }),
|
|
201
|
+
};
|
|
202
|
+
```
|
|
203
|
+
|
|
204
|
+
`xs` is the default bucket and is emitted without a media wrapper. The built-in
|
|
205
|
+
named keys are:
|
|
206
|
+
|
|
207
|
+
| Keys | Condition |
|
|
208
|
+
| --- | --- |
|
|
209
|
+
| `sm`, `smd`, `md`, `lg`, `xl`, `xxl` | `min-width` breakpoints at 480, 624, 768, 1024, 1280, and 1536 pixels |
|
|
210
|
+
| `dark`, `light` | `(prefers-color-scheme: ...)` |
|
|
211
|
+
| `no_hover`, `mobile` | `(pointer: coarse)` |
|
|
212
|
+
| `print`, `screen` | media types |
|
|
213
|
+
|
|
214
|
+
The object-only form `med({ md: "flex" })` skips the default value. Custom
|
|
215
|
+
features are declared with the instance's `mediaFeature` option, then
|
|
216
|
+
referenced by key:
|
|
217
|
+
|
|
218
|
+
```ts
|
|
219
|
+
new Shweet({
|
|
220
|
+
__filename,
|
|
221
|
+
mediaFeature: { standalone: "(display-mode: standalone)" },
|
|
222
|
+
});
|
|
223
|
+
|
|
224
|
+
app.c.shell = {
|
|
225
|
+
minHeight: med("100vh", { standalone: "100dvh" }),
|
|
226
|
+
};
|
|
227
|
+
```
|
|
228
|
+
|
|
229
|
+
Media features are resolved by the instance that saves. When styles are
|
|
230
|
+
imported through `shweets`, repeat any custom feature keys those imported
|
|
231
|
+
styles use on the saving instance.
|
|
232
|
+
|
|
233
|
+
Reference: [Media and supports](#media-and-supports).
|
|
234
|
+
|
|
235
|
+
### Reusable presets with `Medyas`
|
|
236
|
+
|
|
237
|
+
Subclass `Medyas` to package reusable declarations. Getters write through
|
|
238
|
+
`_value` and return `this`, so they chain like the built-in accessors. Media
|
|
239
|
+
accessors such as `.MD`, `.MOBILE`, or `.DARK` create a new instance that
|
|
240
|
+
shares the subclass `data` and the declaration buckets, and scope only the
|
|
241
|
+
declarations written after them:
|
|
242
|
+
|
|
243
|
+
```ts
|
|
244
|
+
import { Shweet, Medyas, type MedyasOptions } from "shweet";
|
|
245
|
+
|
|
246
|
+
const app = new Shweet({ __filename, prefix: "app" });
|
|
247
|
+
const { c } = app;
|
|
248
|
+
|
|
249
|
+
interface SurfaceData {
|
|
250
|
+
tone: "plain" | "dark";
|
|
251
|
+
}
|
|
252
|
+
|
|
253
|
+
class Surface extends Medyas<Surface, SurfaceData> {
|
|
254
|
+
constructor(options: MedyasOptions<SurfaceData> = {}) {
|
|
255
|
+
super({ data: { tone: "plain" }, ...options });
|
|
256
|
+
}
|
|
257
|
+
|
|
258
|
+
get card() {
|
|
259
|
+
const dark = this.data.tone === "dark";
|
|
260
|
+
this._value = {
|
|
261
|
+
display: "block",
|
|
262
|
+
padding: 2,
|
|
263
|
+
backgroundColor: dark ? "black" : "white",
|
|
264
|
+
color: dark ? "white" : "black",
|
|
265
|
+
};
|
|
266
|
+
return this;
|
|
267
|
+
}
|
|
268
|
+
|
|
269
|
+
get compact() {
|
|
270
|
+
this._value = { padding: 1 };
|
|
271
|
+
return this;
|
|
272
|
+
}
|
|
273
|
+
|
|
274
|
+
get outlined() {
|
|
275
|
+
this._value = { border: "1px solid currentColor" };
|
|
276
|
+
return this;
|
|
277
|
+
}
|
|
278
|
+
}
|
|
279
|
+
|
|
280
|
+
// `card` writes xs declarations; `compact` runs after `.MD`, so it only
|
|
281
|
+
// overrides `padding` in the md bucket.
|
|
282
|
+
c.surface = new Surface().card.MD.compact;
|
|
283
|
+
|
|
284
|
+
// Constructor data survives media accessor chaining.
|
|
285
|
+
c["surface-inverse"] = new Surface({
|
|
286
|
+
data: { tone: "dark" },
|
|
287
|
+
}).card.outlined;
|
|
288
|
+
```
|
|
289
|
+
|
|
290
|
+
`MedyasOptions<Q>` has optional `prefix`, `data`, and `values` fields, so
|
|
291
|
+
`new Surface()`, `new Surface({ prefix: "md" })`, and fully supplied options
|
|
292
|
+
all work. `prefix` names the bucket written by direct `_value` assignments on
|
|
293
|
+
that instance: `new Surface({ prefix: "md" }).card` writes md values only.
|
|
294
|
+
`values` is the shared bucket record used internally for chaining; omit it
|
|
295
|
+
unless you are deliberately sharing buckets between instances.
|
|
296
|
+
|
|
297
|
+
The `MOBILE` accessor targets the `mobile` bucket, while `NO_HOVER` targets
|
|
298
|
+
`no_hover`; both currently compile to `(pointer: coarse)`.
|
|
299
|
+
|
|
300
|
+
### Variables with `Var` and `Vars`
|
|
301
|
+
|
|
302
|
+
Custom properties use `Var` for a single token and `Vars` for a named map.
|
|
303
|
+
Declare them on `:root` through `d`, then reference them with `.__()`:
|
|
304
|
+
|
|
305
|
+
```ts
|
|
306
|
+
import { Shweet, Var, Vars, med } from "shweet";
|
|
307
|
+
|
|
308
|
+
const theme = Vars({
|
|
309
|
+
ink: "#1f2933",
|
|
310
|
+
surface: "#ffffff",
|
|
311
|
+
accent: med("#2563eb", { dark: "#60a5fa" }),
|
|
312
|
+
});
|
|
313
|
+
|
|
314
|
+
const { c, d } = new Shweet({ __filename, prefix: "app" });
|
|
315
|
+
|
|
316
|
+
d[":root"] = theme;
|
|
317
|
+
|
|
318
|
+
c.card = {
|
|
319
|
+
color: theme.ink.__(),
|
|
320
|
+
backgroundColor: theme.surface.__(),
|
|
321
|
+
borderColor: theme.accent.__(),
|
|
322
|
+
};
|
|
323
|
+
```
|
|
324
|
+
|
|
325
|
+
`Vars` maps each key to a token; camelCase keys become kebab-case custom
|
|
326
|
+
properties (`fontSize` becomes `--font-size`). `Var` takes a single-entry
|
|
327
|
+
object:
|
|
328
|
+
|
|
329
|
+
```ts
|
|
330
|
+
const radius = Var({ radius: "0.75rem" });
|
|
331
|
+
d[":root"] = radius;
|
|
332
|
+
c.card = { borderRadius: radius.__() };
|
|
333
|
+
```
|
|
334
|
+
|
|
335
|
+
`.__()` accepts a fallback for when the property may be absent:
|
|
336
|
+
|
|
337
|
+
```ts
|
|
338
|
+
color: theme.ink.__("#111827"); // var(--ink, #111827)
|
|
339
|
+
```
|
|
340
|
+
|
|
341
|
+
When a token is defined with `med`, the default value is written in the normal
|
|
342
|
+
declaration bucket and each named bucket writes the same custom property inside
|
|
343
|
+
its `@media` block. The `accent` token above produces `--accent: #2563eb` on
|
|
344
|
+
`:root` plus `:root { --accent: #60a5fa }` inside
|
|
345
|
+
`@media (prefers-color-scheme: dark)`.
|
|
346
|
+
|
|
347
|
+
Reference: [Custom properties](#custom-properties).
|
|
348
|
+
|
|
349
|
+
### Pseudo selectors with `ps`
|
|
350
|
+
|
|
351
|
+
`ps` builds nested-selector declaration blocks. Call a helper, then call the
|
|
352
|
+
returned function with declarations (or an array of them); the result is placed
|
|
353
|
+
in the assignment array:
|
|
354
|
+
|
|
355
|
+
```ts
|
|
356
|
+
c.button = [
|
|
357
|
+
{ padding: "0.5rem 1rem" },
|
|
358
|
+
ps.hover()({ backgroundColor: "#e5e7eb" }),
|
|
359
|
+
ps.focusVisible()({ outline: "2px solid currentColor" }),
|
|
360
|
+
];
|
|
361
|
+
|
|
362
|
+
c.card = [
|
|
363
|
+
{ padding: 1 },
|
|
364
|
+
ps.child(".card-title")({ margin: 0 }),
|
|
365
|
+
ps.is(".featured")({ borderColor: "gold" }),
|
|
366
|
+
ps.has("> .card-media")({ gridTemplateColumns: "1fr 2fr" }),
|
|
367
|
+
ps.attr({ "data-state": "open" })({ display: "block" }),
|
|
368
|
+
];
|
|
369
|
+
```
|
|
370
|
+
|
|
371
|
+
Many pseudo-class and pseudo-element helpers accept an optional selector suffix,
|
|
372
|
+
for example `ps.hover(".is-active")`. `ps.attr` currently reads the first entry of one
|
|
373
|
+
attribute/value object and renders `[name="value"]`. These helpers cover a
|
|
374
|
+
curated set of selectors, not the entire CSS selector grammar; remaining
|
|
375
|
+
selectors can still be written as `":..."` keys or arbitrary `d` rules.
|
|
376
|
+
|
|
377
|
+
Reference: [Selector handling and prefixing](#selector-handling-and-prefixing).
|
|
378
|
+
|
|
379
|
+
Available helpers are grouped by role:
|
|
380
|
+
|
|
381
|
+
- **Pseudo-classes**: `active`, `checked`, `disabled`, `enabled`, `empty`,
|
|
382
|
+
`firstChild`, `lastChild`, `onlyChild`, `focus`, `focusVisible`,
|
|
383
|
+
`focusWithin`, `hover`, `visited`, `target`, `fullscreen`, `modal`, and
|
|
384
|
+
related state helpers.
|
|
385
|
+
- **Pseudo-elements**: `before`, `after`, `placeholder`, `selection`, `marker`,
|
|
386
|
+
`backdrop`, `firstLine`, `firstLetter`, `part(...)`, `slotted(...)`, `cue`,
|
|
387
|
+
plus the scrollbar helpers `scrollbar`, `scrollbarThumb`, `scrollbarTrack`,
|
|
388
|
+
and `scrollbarCorner`.
|
|
389
|
+
- **Selector functions**: `has(...)`, `is(...)`, `where(...)`, `not(...)`,
|
|
390
|
+
`dir(...)`, `lang(...)`, `nthChild(...)`, `nthLastChild(...)`,
|
|
391
|
+
`nthOfType(...)`, `nthLastOfType(...)`, `state(...)`, `host_(...)`,
|
|
392
|
+
`hostContext(...)`, and `webkit(...)`.
|
|
393
|
+
- **Combinators and selector lists**: `child(".x")` (`>`), `desc(".x")`
|
|
394
|
+
(descendant), `next(".x")` (`+`), `general(".x")` (`~`), `and(".x")` (adds to
|
|
395
|
+
the selector list), and `withClass(".x")`.
|
|
396
|
+
|
|
397
|
+
### Supports blocks
|
|
398
|
+
|
|
399
|
+
```ts
|
|
400
|
+
import { med, supports } from "shweet";
|
|
401
|
+
|
|
402
|
+
app.c.grid = [
|
|
403
|
+
supports({ display: "grid" })({
|
|
404
|
+
display: "grid",
|
|
405
|
+
grid: med(1, { lg: 3 }),
|
|
406
|
+
}),
|
|
407
|
+
supports("selector(:has(*))")({ padding: 1 }),
|
|
408
|
+
];
|
|
409
|
+
```
|
|
410
|
+
|
|
411
|
+
`supports` emits a conditional feature query around its declarations. An
|
|
412
|
+
object is converted to `property:value` query text (`@supports(display:grid)`),
|
|
413
|
+
while a string is used verbatim as the condition
|
|
414
|
+
(`@supports(selector(:has(*)))`). Pass one or more declaration objects to the
|
|
415
|
+
returned function; `med` values inside them work like other assignment blocks.
|
|
416
|
+
|
|
417
|
+
Reference: [Media and supports](#media-and-supports).
|
|
418
|
+
|
|
419
|
+
### Keyframes
|
|
420
|
+
|
|
421
|
+
```ts
|
|
422
|
+
app.kf.pulse = {
|
|
423
|
+
from: { opacity: 1 },
|
|
424
|
+
"50%": { opacity: 0.5 },
|
|
425
|
+
to: { opacity: 1 },
|
|
426
|
+
};
|
|
427
|
+
|
|
428
|
+
app.c.pulse = { animation: "pulse 2s infinite" };
|
|
429
|
+
```
|
|
430
|
+
|
|
431
|
+
Animation names in `animation`/`animationName` are prefixed alongside the
|
|
432
|
+
keyframes rule, producing `@keyframes app_pulse` and
|
|
433
|
+
`animation: app_pulse 2s infinite`. Set `webkitKeyframes: true` to also emit
|
|
434
|
+
`@-webkit-keyframes`.
|
|
435
|
+
|
|
436
|
+
Reference: [Animation values](#animation-values).
|
|
437
|
+
|
|
438
|
+
### Prefixing
|
|
439
|
+
|
|
440
|
+
`prefix: "app"` prefixes class and id tokens (including those inside arbitrary
|
|
441
|
+
`d` selectors), keyframe names, and animation name references. Imported
|
|
442
|
+
instances keep their own prefix independently.
|
|
443
|
+
|
|
444
|
+
Reference: [Selector handling and prefixing](#selector-handling-and-prefixing).
|
|
445
|
+
|
|
446
|
+
### Composing instances
|
|
447
|
+
|
|
448
|
+
Pass existing instances through `shweets` to merge their declarations, keyframes,
|
|
449
|
+
and export-map entries:
|
|
450
|
+
|
|
451
|
+
```ts
|
|
452
|
+
const base = new Shweet({ __filename, prefix: "base" });
|
|
453
|
+
base.c.panel = { padding: 1 };
|
|
454
|
+
|
|
455
|
+
const app = new Shweet({
|
|
456
|
+
__filename,
|
|
457
|
+
prefix: "app",
|
|
458
|
+
shweets: [base],
|
|
459
|
+
// Media features are resolved by the instance that saves, so repeat any
|
|
460
|
+
// feature keys that imported styles use.
|
|
461
|
+
mediaFeature: { standalone: "(display-mode: standalone)" },
|
|
462
|
+
});
|
|
463
|
+
```
|
|
464
|
+
|
|
465
|
+
Imported styles are collected after local styles, in import order. The composed
|
|
466
|
+
stylesheet keeps each instance's prefix.
|
|
467
|
+
|
|
468
|
+
Reference: [Imports, at-rules, and font faces](#imports-at-rules-and-font-faces).
|
|
469
|
+
|
|
470
|
+
## Supported input reference
|
|
471
|
+
|
|
472
|
+
This section consolidates the input forms the compiler accepts today.
|
|
473
|
+
**Guaranteed** describes behavior implemented in the current compiler and covered
|
|
474
|
+
by the CSS-string tests; it does not establish browser computed-style
|
|
475
|
+
equivalence. Examples illustrate syntax rather than adding guarantees. Anything
|
|
476
|
+
not listed here is either passed through unchanged or called out in
|
|
477
|
+
[Known boundaries](#known-boundaries).
|
|
478
|
+
|
|
479
|
+
### Declarations
|
|
480
|
+
|
|
481
|
+
**Guaranteed**
|
|
482
|
+
|
|
483
|
+
- Assign a declaration object to a `c`, `i`, `d`, or `kf` rule. Property names
|
|
484
|
+
may be camelCase (`fontSize`) or kebab-case (`font-size`); output uses
|
|
485
|
+
kebab-case. This conversion also applies to custom-property names
|
|
486
|
+
(`--gapSize` → `--gap-size`), including names written in a legacy declaration
|
|
487
|
+
string.
|
|
488
|
+
- Assignment and declaration order are preserved inside a rule. Reassigning the
|
|
489
|
+
same property keeps the last value, including across repeated assignments to
|
|
490
|
+
the same rule.
|
|
491
|
+
- Arrays are flattened in order, so declaration objects, `ps.*` blocks,
|
|
492
|
+
`supports(...)` blocks, and nested arrays can be combined.
|
|
493
|
+
- A legacy string `"property: value; ..."` is split at top-level semicolons and
|
|
494
|
+
the first top-level colon. Duplicate properties keep the last value, and a
|
|
495
|
+
fragment without a top-level colon is dropped. Separators inside quoted
|
|
496
|
+
strings, escapes, `url(...)`, nested functions, and braces are preserved.
|
|
497
|
+
- `undefined` declaration values are skipped. Strings are written as-is and are
|
|
498
|
+
not CSS-validated. Arrays of values are joined with spaces, except for
|
|
499
|
+
comma-separated properties such as `transitionProperty`.
|
|
500
|
+
- A JavaScript `number` receives the configured `unit` (`rem`, `em`, `px`, `pt`,
|
|
501
|
+
or `pc`; default `rem`) unless the property is a known unitless or time
|
|
502
|
+
property. Common unitless numeric properties include `lineHeight`,
|
|
503
|
+
`fontWeight`, `opacity`, `zIndex`, `tabSize`, `zoom`, `orphans`, `widows`, and
|
|
504
|
+
the numeric `borderImageOutset`, `borderImageSlice`, and `borderImageWidth`
|
|
505
|
+
factors. Time properties take seconds (`transitionDuration: 2` → `2s`).
|
|
506
|
+
- A numeric string in an object is not unit-converted. In a legacy declaration
|
|
507
|
+
string, a complete finite numeric literal is converted to a number first, so
|
|
508
|
+
`"width: 10"` becomes `10rem`; hex forms and `Infinity` stay text.
|
|
509
|
+
- String `content` values are wrapped in single quotes. Values containing `(`
|
|
510
|
+
are passed through.
|
|
511
|
+
|
|
512
|
+
```ts
|
|
513
|
+
c.card = {
|
|
514
|
+
padding: 1, // 1rem
|
|
515
|
+
lineHeight: 1.5, // 1.5 (unitless)
|
|
516
|
+
fontWeight: 700, // 700 (unitless)
|
|
517
|
+
zIndex: 2, // unitless
|
|
518
|
+
transitionDuration: 2, // 2s
|
|
519
|
+
width: "10", // 10 (not 10rem)
|
|
520
|
+
"--gap": "0", // --gap: 0
|
|
521
|
+
};
|
|
522
|
+
c.legacy = "color: red; width: 10; --shadow: 0 0 10px rgba(0,0,0,.5)";
|
|
523
|
+
```
|
|
524
|
+
|
|
525
|
+
**Limits**
|
|
526
|
+
|
|
527
|
+
- An empty string, a boolean, or an unsupported nested object is not converted
|
|
528
|
+
and can serialize as an empty declaration such as `color: ;`. Shweet does not
|
|
529
|
+
report a syntax error for these values.
|
|
530
|
+
- `null` is not accepted and throws during assignment.
|
|
531
|
+
- There is no complete property/value grammar, shorthand expansion, or value
|
|
532
|
+
validation.
|
|
533
|
+
- Unitless handling is based on property names, not value types. The built-in
|
|
534
|
+
set covers common standard unitless numeric properties, including `lineHeight`,
|
|
535
|
+
`fontWeight`, `tabSize`, `zoom`, `orphans`, `widows`, and numeric border-image
|
|
536
|
+
factors. Properties outside the built-in unitless/time sets receive the
|
|
537
|
+
configured unit, so `outlineWidth: 2` becomes `2rem`; use a string
|
|
538
|
+
(`outlineWidth: "2px"`) for the intended CSS value.
|
|
539
|
+
|
|
540
|
+
### Selector handling and prefixing
|
|
541
|
+
|
|
542
|
+
**Guaranteed**
|
|
543
|
+
|
|
544
|
+
- `c.name` writes a class selector, `i.name` writes an id selector, and
|
|
545
|
+
`d[selector]` writes an arbitrary selector. Class and id tokens are prefixed
|
|
546
|
+
at compile time (`app` + `.card` → `.app_card`).
|
|
547
|
+
- Nested keys starting with `:`, `[`, `,`, `.`, or `#` are appended to the
|
|
548
|
+
parent selector. Keys starting with whitespace add a descendant or combinator
|
|
549
|
+
suffix (`" > .child"`), and a comma list in the suffix is split at top-level
|
|
550
|
+
commas so each target receives the parent.
|
|
551
|
+
- The prefixer walks class and id tokens only. It does not prefix tag names,
|
|
552
|
+
quoted strings, attribute-selector contents, comments, escaped punctuation
|
|
553
|
+
(`\.`, `\#`), or a dot/hash followed by a digit.
|
|
554
|
+
- `:is()`, `:not()`, `:has()`, attribute selectors, and escaped identifiers stay
|
|
555
|
+
intact as one expression. Grouping never splits them at inner commas.
|
|
556
|
+
- Grouping merges only adjacent rules with an identical serialized declaration
|
|
557
|
+
sequence, preserving first-seen selector order within the group. It does not
|
|
558
|
+
move a rule across an intervening one or across media/supports contexts.
|
|
559
|
+
|
|
560
|
+
```ts
|
|
561
|
+
c.panel = [
|
|
562
|
+
{ display: "grid" },
|
|
563
|
+
ps.hover()({ backgroundColor: "gray" }),
|
|
564
|
+
ps.child(".cell")({ minHeight: 2 }),
|
|
565
|
+
];
|
|
566
|
+
d['[data-state="open"] .menu'] = { display: "block" };
|
|
567
|
+
```
|
|
568
|
+
|
|
569
|
+
**Limits**
|
|
570
|
+
|
|
571
|
+
- `ps` exposes a curated helper set; other selectors are written as `":..."`,
|
|
572
|
+
`"[...]"`, or `d` rules.
|
|
573
|
+
- The prefixer is a bounded scanner, not a selector parser. Syntax it does not
|
|
574
|
+
recognize is copied through and may remain unprefixed.
|
|
575
|
+
- Grouping is string-level. It does not evaluate specificity, cascade overlap,
|
|
576
|
+
or invalid-selector list behavior.
|
|
577
|
+
|
|
578
|
+
### Media and supports
|
|
579
|
+
|
|
580
|
+
**Guaranteed**
|
|
581
|
+
|
|
582
|
+
- `med(default, buckets)` writes the default in `xs` and each named bucket in
|
|
583
|
+
its own `@media` block. `xs` has no wrapper, and the object-only form skips
|
|
584
|
+
the default. The built-in bucket names are listed in
|
|
585
|
+
[Media conditions with `med`](#media-conditions-with-med).
|
|
586
|
+
- Buckets are emitted in the configured media order. Rules inside a bucket keep
|
|
587
|
+
source order after conservative grouping, except that animation and
|
|
588
|
+
transition groups are hoisted to the front of that bucket.
|
|
589
|
+
- Custom feature keys are resolved per compilation. `save` uses the instance's
|
|
590
|
+
`mediaFeature`; direct `Loader.load` callers pass the feature record as its
|
|
591
|
+
second argument. Features are not inherited from imported instances.
|
|
592
|
+
- `supports(object)` renders `@supports(property:value)`, while
|
|
593
|
+
`supports("...")` uses the string verbatim. Pass one or more plain declaration
|
|
594
|
+
objects to the returned function; `med` values inside them are supported.
|
|
595
|
+
Supports blocks are emitted inside their media bucket after keyframes.
|
|
596
|
+
- `@supports` inside `@keyframes` is not supported; it is logged and skipped.
|
|
597
|
+
|
|
598
|
+
**Limits**
|
|
599
|
+
|
|
600
|
+
- A custom feature key containing `-` cannot be used reliably as a media bucket
|
|
601
|
+
name, because bucket names are split on `-` when the media query is rendered.
|
|
602
|
+
- A bucket whose custom feature key is not configured for that compilation is
|
|
603
|
+
omitted from the output.
|
|
604
|
+
- Media conditions are not evaluated; Shweet only serializes the configured
|
|
605
|
+
strings.
|
|
606
|
+
|
|
607
|
+
### Imports, at-rules, and font faces
|
|
608
|
+
|
|
609
|
+
**Guaranteed**
|
|
610
|
+
|
|
611
|
+
- `at.import = "theme.css"` writes `@import "theme.css";`. A value containing
|
|
612
|
+
`(` (for example `url("theme.css")`) is written without added quotes.
|
|
613
|
+
`at.charset` follows the same quoting rule.
|
|
614
|
+
- At-rules are emitted before style rules. Identical at-rule text is emitted
|
|
615
|
+
once; different values for the same at-rule are all kept.
|
|
616
|
+
- `font.<family> = { ... }` writes an `@font-face` block with a quoted
|
|
617
|
+
`font-family` and the supplied descriptors in assignment order.
|
|
618
|
+
- `shweets: [base]` merges the imported handlers. Local rules are collected
|
|
619
|
+
first, then imported rules in import order and depth-first for nested imports.
|
|
620
|
+
Each instance keeps its own prefix, and export-map collection follows the
|
|
621
|
+
active compilation rather than an imported instance's creation-time flag.
|
|
622
|
+
- Repeated imports of the same `Shweet` object are deduplicated by identity and
|
|
623
|
+
keep their first-seen position. Two distinct `Shweet` objects that share a
|
|
624
|
+
source path remain distinct and both compile with their own options.
|
|
625
|
+
- Imports passed to the constructor form an acyclic graph because an instance
|
|
626
|
+
must exist before it can be imported. Internal traversal also carries
|
|
627
|
+
identity guards, so cycles created by mutating handler links terminate
|
|
628
|
+
predictably instead of repeating output.
|
|
629
|
+
- Shaker filtering considers animation references from imported selectors, so
|
|
630
|
+
an imported keyframe is kept when a retained imported class references it.
|
|
631
|
+
|
|
632
|
+
**Limits**
|
|
633
|
+
|
|
634
|
+
- Media features are not inherited from imports; repeat keys on the saving
|
|
635
|
+
instance.
|
|
636
|
+
- `imported` reports paths as a set: distinct instances that share a path are
|
|
637
|
+
both compiled but report that path once.
|
|
638
|
+
- Import cycles are unsupported as a public construction path. The traversal
|
|
639
|
+
guards in the bullet above only make internally mutated cycles finite.
|
|
640
|
+
- Only keyframes, supports, font faces, and simple statement at-rules are
|
|
641
|
+
modeled. Other block at-rules are not.
|
|
642
|
+
- Plain at-rule strings are quoted unless they contain `(`; there is no
|
|
643
|
+
at-rule-specific formatting.
|
|
644
|
+
|
|
645
|
+
### Animation values
|
|
646
|
+
|
|
647
|
+
**Guaranteed**
|
|
648
|
+
|
|
649
|
+
- Keyframe names are prefixed (`kf.pulse` → `@keyframes app_pulse`), and
|
|
650
|
+
`animation`/`animationName` values are prefixed when the declaration is
|
|
651
|
+
assigned. Recompiling, or reusing one `med` value across rules, does not
|
|
652
|
+
double-prefix.
|
|
653
|
+
- `animation` accepts a comma-separated list. Each item is split on top-level
|
|
654
|
+
whitespace; time values, numbers, timing functions and keywords, direction,
|
|
655
|
+
fill, play-state, `infinite`, `none`, and CSS-wide keywords are skipped.
|
|
656
|
+
Quoted tokens are treated as names. An item with an unknown function
|
|
657
|
+
(`var()`, `env()`, ...), more than one name candidate, or a leading, trailing,
|
|
658
|
+
or double comma is left unchanged.
|
|
659
|
+
- `animationName` accepts one name per comma-separated item, optionally with a
|
|
660
|
+
trailing `!important`. Functions and non-name tokens are left unchanged.
|
|
661
|
+
- Only `animation` and `animationName` are rewritten. Custom properties and all
|
|
662
|
+
other properties are not.
|
|
663
|
+
- Numeric keyframe step keys become percentages (`50` → `50%`).
|
|
664
|
+
`webkitKeyframes: true` also emits `@-webkit-keyframes`.
|
|
665
|
+
- With a shaker, a keyframe is kept only when a retained selector references it.
|
|
666
|
+
|
|
667
|
+
**Limits**
|
|
668
|
+
|
|
669
|
+
- Value recognition is a bounded token scanner, not a full `animation` grammar.
|
|
670
|
+
Ambiguous values are deliberately left untouched rather than guessed.
|
|
671
|
+
|
|
672
|
+
### Custom properties
|
|
673
|
+
|
|
674
|
+
**Guaranteed**
|
|
675
|
+
|
|
676
|
+
- A `--name` key goes through the normal kebab-case conversion
|
|
677
|
+
(`--gapSize` → `--gap-size`, `--Gap` → `--gap`). Its value uses the normal
|
|
678
|
+
declaration serialization, so a JavaScript number receives the configured unit
|
|
679
|
+
(`"--gap": 0` → `--gap: 0rem`); use a string (`"--gap": "0"`) to keep the
|
|
680
|
+
token text.
|
|
681
|
+
- In a legacy declaration string, the declaration parser preserves the `--name`
|
|
682
|
+
token while parsing, but the serializer still applies the same kebab-case
|
|
683
|
+
conversion to the property name. A numeric-looking custom-property value is
|
|
684
|
+
not converted.
|
|
685
|
+
- `Var({ name: value })` and `Vars({ ... })` create tokens. `Vars` converts
|
|
686
|
+
camelCase keys to kebab-case custom-property names. `Var` uses the first entry
|
|
687
|
+
only. `.__()` returns `var(--name)` or `var(--name, fallback)`. Token values
|
|
688
|
+
follow the same numeric/unit rules as other declarations.
|
|
689
|
+
- A token defined with `med` writes the default on the declaration's selector
|
|
690
|
+
and each bucket's value in its `@media` block.
|
|
691
|
+
- Minification preserves custom-property token content verbatim, including
|
|
692
|
+
internal whitespace and quoted separators.
|
|
693
|
+
|
|
694
|
+
**Limits**
|
|
695
|
+
|
|
696
|
+
- `Var` ignores entries after the first. Token values are not validated, and
|
|
697
|
+
custom properties are not registered with `@property`.
|
|
698
|
+
|
|
699
|
+
### Malformed and ambiguous input
|
|
700
|
+
|
|
701
|
+
The guaranteed recovery behavior for malformed input is intentionally small:
|
|
702
|
+
|
|
703
|
+
- Legacy declaration strings keep valid fragments around a fragment that has no
|
|
704
|
+
top-level colon. Empty fragments are skipped, and later duplicates win.
|
|
705
|
+
- Declaration values are not syntax-checked. `undefined` is skipped, while an
|
|
706
|
+
empty string, a boolean, or an unsupported object can produce an empty
|
|
707
|
+
declaration such as `color: ;`; `null` throws.
|
|
708
|
+
- An unbalanced quote, bracket, brace, or comment makes the bounded scanners
|
|
709
|
+
treat the remainder as part of that region; output may copy it through rather
|
|
710
|
+
than recover a useful split.
|
|
711
|
+
- Unrecognized selector or at-rule syntax is passed through. Unsupported nested
|
|
712
|
+
objects are not recursively interpreted as CSS.
|
|
713
|
+
- Unsupported or ambiguous animation items are left unchanged, and no keyframe
|
|
714
|
+
reference is recorded for them.
|
|
715
|
+
|
|
716
|
+
These are string-level diagnostics only. They do not assert browser
|
|
717
|
+
computed-style equivalence; see [Known boundaries](#known-boundaries).
|
|
718
|
+
|
|
719
|
+
## Saving
|
|
720
|
+
|
|
721
|
+
`save` compiles the instance and returns it for chaining:
|
|
722
|
+
|
|
723
|
+
```ts
|
|
724
|
+
app.save({
|
|
725
|
+
dir: "./generated", // string or string[]
|
|
726
|
+
mapDir: "./generated", // string or string[]
|
|
727
|
+
mapName: "index", // export-map file name, default "index"
|
|
728
|
+
name: "app", // CSS file base name, default instance name
|
|
729
|
+
minify: true, // default true
|
|
730
|
+
});
|
|
731
|
+
```
|
|
732
|
+
|
|
733
|
+
`dir` writes `<name>.css`. `mapDir` writes the export map as `<mapName>.js`.
|
|
734
|
+
Passing `mapDir` enables export-map collection when `exportMap` was not set
|
|
735
|
+
explicitly; `exportMap: true` enables it independently. `save({ name })`
|
|
736
|
+
overrides the CSS file base name; without it, the instance `name` is used, which
|
|
737
|
+
defaults to the source file name derived from `__filename`.
|
|
738
|
+
|
|
739
|
+
`shaker` limits output to matching class/id names; `include` adds extra names
|
|
740
|
+
that must be kept while shaking. Keyframes referenced by retained animation
|
|
741
|
+
rules are kept as well.
|
|
742
|
+
|
|
743
|
+
## Conservative grouping
|
|
744
|
+
|
|
745
|
+
Shweet performs only conservative rule grouping. Adjacent style rules with an
|
|
746
|
+
exactly identical serialized declaration sequence are merged into one selector
|
|
747
|
+
list; any rule with different declarations ends the group. Rules are never
|
|
748
|
+
merged across media or supports contexts, and a later rule with matching
|
|
749
|
+
declarations is not moved past an intervening one. Within each media block,
|
|
750
|
+
`animation`/`transition` rules are emitted before other style rules, followed by
|
|
751
|
+
keyframes and supports blocks. This preserves source order rather than
|
|
752
|
+
maximizing deduplication.
|
|
753
|
+
|
|
754
|
+
## Helper families
|
|
755
|
+
|
|
756
|
+
The root entry point also exports value builders and lower-level utilities.
|
|
757
|
+
|
|
758
|
+
### `f` — CSS function builders
|
|
759
|
+
|
|
760
|
+
`f` builds CSS function values as strings: `calc`, `clamp`, `min`, `max`,
|
|
761
|
+
`minmax`, `repeat`, gradients, transforms, filters, colors, `attr`, `url`, and
|
|
762
|
+
`var`. They are value helpers, not a CSS validator; unsupported syntax is passed
|
|
763
|
+
through as written.
|
|
764
|
+
|
|
765
|
+
```ts
|
|
766
|
+
import { f } from "shweet";
|
|
767
|
+
|
|
768
|
+
c.hero = {
|
|
769
|
+
width: f.min("100%", "60rem"),
|
|
770
|
+
padding: f.calc("100%", "-", 2), // calc(100% - 2rem)
|
|
771
|
+
fontSize: f.clamp(1, "4vw", 2), // clamp(1rem, 4vw, 2rem)
|
|
772
|
+
gridTemplateColumns: f.repeat(3, f.minmax(0, "1fr")),
|
|
773
|
+
backgroundImage: f.linearGradient("to right", "#2563eb", "#60a5fa"),
|
|
774
|
+
color: f.rgb(31, 41, 51),
|
|
775
|
+
borderColor: f.var("ink", "#111827"), // var(--ink, #111827)
|
|
776
|
+
};
|
|
777
|
+
```
|
|
778
|
+
|
|
779
|
+
Numbers are converted by each helper: length functions generally add `rem`,
|
|
780
|
+
angle functions add `deg`, and percentage-oriented helpers such as `polygon`
|
|
781
|
+
add `%`. Values that already include units or functions are kept as strings.
|
|
782
|
+
|
|
783
|
+
### `v` — keyword constants
|
|
784
|
+
|
|
785
|
+
`v` collects common CSS keyword strings so declarations avoid repeated quoted
|
|
786
|
+
literals. `v.important` is `" !important"` for appending to a value.
|
|
787
|
+
|
|
788
|
+
```ts
|
|
789
|
+
import { v } from "shweet";
|
|
790
|
+
|
|
791
|
+
c.overlay = {
|
|
792
|
+
display: v.none,
|
|
793
|
+
position: v.absolute,
|
|
794
|
+
inset: 0,
|
|
795
|
+
cursor: v.pointer,
|
|
796
|
+
};
|
|
797
|
+
|
|
798
|
+
c.hidden = { display: v.none + v.important };
|
|
799
|
+
```
|
|
800
|
+
|
|
801
|
+
The predefined groups include layout and flex keywords (`flex`, `center`,
|
|
802
|
+
`space_between`, `wrap`, `column`, `row`), positioning (`relative`, `absolute`,
|
|
803
|
+
`fixed`, `sticky`), display (`block`, `none`), sizes (`pr100`, `pr50`,
|
|
804
|
+
`i100vh`, `i100vw`), borders (`solid`, `inset`), cursors, font weight
|
|
805
|
+
(`bold`), and shared keywords such as `auto`, `initial`, and `inherit`.
|
|
806
|
+
|
|
807
|
+
### `X`, `Z`, `XX`, `XY` — legacy composition helpers
|
|
808
|
+
|
|
809
|
+
These helpers compose declarations in plain CSS maps, not on a `Shweet`
|
|
810
|
+
instance. `Z(cx, entries)` writes a main declaration block and related
|
|
811
|
+
`${main}_${key}` entries, where a key starting with `$` keeps its name without
|
|
812
|
+
the main prefix. `X(cx, entries, prefix?)` writes each entry into the map,
|
|
813
|
+
optionally prefixing the key. `XX(record)` and `XY(record)` wrap a nested
|
|
814
|
+
record so `X` expands it instead of storing the wrapper as a declaration value;
|
|
815
|
+
`XY` inherits the current main key as a prefix, while `XX` writes its keys as
|
|
816
|
+
given. They are kept for existing code and are not required for normal
|
|
817
|
+
assignment usage.
|
|
818
|
+
|
|
819
|
+
### Lower-level utilities
|
|
820
|
+
|
|
821
|
+
Several root exports are lower-level building blocks. Their shapes follow the
|
|
822
|
+
current source rather than a separate stable abstraction:
|
|
823
|
+
|
|
824
|
+
- `media` — the class behind `med`, holding a default value and named media
|
|
825
|
+
buckets.
|
|
826
|
+
- `Medyas` — generic base for objects with named buckets and `XS`/`SM`/... /
|
|
827
|
+
`DARK` accessors; `MedyasOptions<Q>` is its public constructor options type.
|
|
828
|
+
- `Value` — serializes a value or array to CSS text with unit, quote, and
|
|
829
|
+
delimiter options.
|
|
830
|
+
- `Var`, `Vars` — custom-property token helpers; see
|
|
831
|
+
[Variables with `Var` and `Vars`](#variables-with-var-and-vars).
|
|
832
|
+
- `fileName` — derives a base file name from a path.
|
|
833
|
+
- `log` — logger re-exported from the helper barrel.
|
|
834
|
+
- `__` — miscellaneous utility namespace (random helpers, DOM creation, and
|
|
835
|
+
formatting) from the helper barrel.
|
|
836
|
+
|
|
837
|
+
## Examples
|
|
838
|
+
|
|
839
|
+
- [`test/a/index.ts`](test/a/index.ts) — the shared design kit: `Vars` tokens on
|
|
840
|
+
`:root`, `med` breakpoints, a custom media feature, keyframes, and `ps`
|
|
841
|
+
nesting.
|
|
842
|
+
- [`test/b/index.ts`](test/b/index.ts) — a blog fixture composed from `test/a`,
|
|
843
|
+
repeating its media feature and adding `supports` blocks.
|
|
844
|
+
- [`test/c/index.ts`](test/c/index.ts) — the final page fixture with a
|
|
845
|
+
three-level composition chain, `ps.has`, and targeted media features.
|
|
846
|
+
- [`test/example/index.ts`](test/example/index.ts) — a composed instance with
|
|
847
|
+
imported declarations, custom media features, nested selectors, supports,
|
|
848
|
+
keyframes, and export-map assertions.
|
|
849
|
+
- [`test/example/base.ts`](test/example/base.ts) — the imported base instance.
|
|
850
|
+
|
|
851
|
+
Run the composed example:
|
|
852
|
+
|
|
853
|
+
```bash
|
|
854
|
+
bun test/example/index.ts
|
|
855
|
+
```
|
|
856
|
+
|
|
857
|
+
Run the test suite:
|
|
858
|
+
|
|
859
|
+
```bash
|
|
860
|
+
bun test
|
|
861
|
+
```
|
|
862
|
+
|
|
863
|
+
Run the non-gating input/compile diagnostics:
|
|
864
|
+
|
|
865
|
+
```bash
|
|
866
|
+
bun test/benchmarks.ts
|
|
867
|
+
```
|
|
868
|
+
|
|
869
|
+
The benchmark uses deterministic synthetic inputs and reports raw/gzip bytes,
|
|
870
|
+
compile duration, and heap/RSS figures. It has no thresholds or pass/fail
|
|
871
|
+
claims, and writes only to a temporary output directory.
|
|
872
|
+
|
|
873
|
+
Run the manual package smoke test:
|
|
874
|
+
|
|
875
|
+
```bash
|
|
876
|
+
bun test/package-smoke.ts
|
|
877
|
+
```
|
|
878
|
+
|
|
879
|
+
It builds the current source with `builder.ts` in a temporary copy, packs the
|
|
880
|
+
archive, installs it into a fresh consumer, and checks the packed root and the
|
|
881
|
+
`shweet/dist/index.js` deep import through Node ESM before typechecking a
|
|
882
|
+
consumer against the packed declarations with `skipLibCheck: false`. The
|
|
883
|
+
consumer installs only the packed archive, so the check also verifies that the
|
|
884
|
+
declarations do not need `@ohmyqt/u` or any other helper package. It uses the
|
|
885
|
+
locally installed `bun`, `node`, `npm`, and `tar` commands without network
|
|
886
|
+
access, writes under the system temporary directory, and removes its workspace
|
|
887
|
+
on exit. It is not part of `bun test`.
|
|
888
|
+
|
|
889
|
+
By default the smoke test uses the project's installed TypeScript when that
|
|
890
|
+
version satisfies `^5.8.2`. To use a separately installed compiler without
|
|
891
|
+
changing `package.json`, `bun.lock`, or the checkout's `node_modules`:
|
|
892
|
+
|
|
893
|
+
```bash
|
|
894
|
+
bun test/package-smoke.ts \
|
|
895
|
+
--tsc /path/to/typescript/lib/tsc.js \
|
|
896
|
+
--typescript-version 5.9.3
|
|
897
|
+
```
|
|
898
|
+
|
|
899
|
+
Both flags are required together. The script runs the supplied binary with
|
|
900
|
+
`--version` and fails unless the reported version exactly matches
|
|
901
|
+
`--typescript-version`, so a matrix run checks the compiler it actually
|
|
902
|
+
invoked.
|
|
903
|
+
|
|
904
|
+
Run the optional browser cascade regression harness:
|
|
905
|
+
|
|
906
|
+
```bash
|
|
907
|
+
SHWEET_WEBDRIVER_URL=http://localhost:4444 bun test/browser-cascade.ts
|
|
908
|
+
```
|
|
909
|
+
|
|
910
|
+
The harness drives a real browser over the W3C WebDriver HTTP protocol using
|
|
911
|
+
the endpoint in `SHWEET_WEBDRIVER_URL`. Any compatible endpoint works; a local
|
|
912
|
+
driver is enough. Start one of these separately if it is already installed, for
|
|
913
|
+
example:
|
|
914
|
+
|
|
915
|
+
```bash
|
|
916
|
+
chromedriver --port=4444 # Chrome
|
|
917
|
+
geckodriver --port=4444 # Firefox
|
|
918
|
+
safaridriver --port 4444 # Safari, after enabling Remote Automation yourself
|
|
919
|
+
```
|
|
920
|
+
|
|
921
|
+
Then point `SHWEET_WEBDRIVER_URL` at that driver (`http://localhost:4444`
|
|
922
|
+
above). The harness does not install, start, or configure a driver, and there
|
|
923
|
+
is no other environment variable to set.
|
|
924
|
+
|
|
925
|
+
When the variable is absent, the script prints a skipped status and exits
|
|
926
|
+
successfully, so it is safe to run without a browser. When it is present, the
|
|
927
|
+
script compiles a representative stylesheet through `Shweet.save` into a
|
|
928
|
+
temporary directory, embeds the CSS and DOM fixtures in one self-contained
|
|
929
|
+
`data:` page, creates a browser session, sizes the window, navigates to the
|
|
930
|
+
page, and compares `getComputedStyle` results obtained with one synchronous
|
|
931
|
+
`execute/sync` call. It always deletes the session and removes temporary files.
|
|
932
|
+
It uses no sleeps, retries, or polling, and adds no dependency. Because the page
|
|
933
|
+
is loaded from a `data:` URL, a remote WebDriver endpoint must permit data-URL
|
|
934
|
+
navigation; local browsers normally do.
|
|
935
|
+
|
|
936
|
+
Coverage:
|
|
937
|
+
|
|
938
|
+
- overlapping class declarations, including the case where identical
|
|
939
|
+
declarations must not move ahead of an intervening rule;
|
|
940
|
+
- adjacent identical declarations merged into one selector list;
|
|
941
|
+
- specificity between a class and an id;
|
|
942
|
+
- shorthand versus longhand declaration order;
|
|
943
|
+
- `!important` against a later normal declaration;
|
|
944
|
+
- `min-width` media conditions (the window is resized first; if the viewport
|
|
945
|
+
does not reach the breakpoint, that branch is reported as skipped);
|
|
946
|
+
- `@supports` when `CSS.supports` reports the tested declaration as supported,
|
|
947
|
+
otherwise that assertion is reported as skipped and only the fallback is
|
|
948
|
+
checked;
|
|
949
|
+
- comma-containing selectors (`[title="a,b"]` and `:is(...)`) that must stay
|
|
950
|
+
one selector expression.
|
|
951
|
+
|
|
952
|
+
A `PASS` line means every checked assertion succeeded for the browser that was
|
|
953
|
+
actually connected. Skipped feature assertions are listed explicitly, and a
|
|
954
|
+
run without a configured endpoint establishes no browser evidence. The harness
|
|
955
|
+
is not part of `bun test`; it emits only its own status output and never edits
|
|
956
|
+
project files.
|
|
957
|
+
|
|
958
|
+
Type-check the project:
|
|
959
|
+
|
|
960
|
+
```bash
|
|
961
|
+
bunx tsc --noEmit --incremental false
|
|
962
|
+
```
|
|
963
|
+
|
|
964
|
+
The checked-in `tsconfig.json` currently spells `typeRoots` as
|
|
965
|
+
`node_module/@types` (missing the `s`). On a clean checkout with no ambient
|
|
966
|
+
`node_modules` in an ancestor directory, add
|
|
967
|
+
`--typeRoots node_modules/@types` so the installed Node and Bun types are used.
|
|
968
|
+
The matrix commands in [Supported toolchain matrix](#supported-toolchain-matrix)
|
|
969
|
+
pass that flag explicitly and do not rely on types outside the checkout.
|
|
970
|
+
|
|
971
|
+
## Known boundaries
|
|
972
|
+
|
|
973
|
+
- Generated CSS targets the API shown above: property declarations, class/id and
|
|
974
|
+
arbitrary selectors, media/supports conditions, keyframes, simple at-rules,
|
|
975
|
+
font faces, and variables. Block at-rules other than keyframes, supports, and
|
|
976
|
+
font faces are not modeled.
|
|
977
|
+
- Grouping preserves source order conservatively and merges only adjacent exact
|
|
978
|
+
matches. It does not attempt global deduplication or cascade equivalence.
|
|
979
|
+
- Shweet is not a complete CSS parser. Prefixing, declaration-string handling,
|
|
980
|
+
and minification use bounded token scanners that protect quoted strings,
|
|
981
|
+
`url(...)`, custom properties, and math functions, but unhandled or ambiguous
|
|
982
|
+
syntax is passed through rather than interpreted.
|
|
983
|
+
- The [Supported input reference](#supported-input-reference) records which
|
|
984
|
+
behaviors are covered today, but its assertions are string-level only. The
|
|
985
|
+
regular test suite does not claim browser computed-style equivalence; the
|
|
986
|
+
optional harness in `test/browser-cascade.ts` checks it only when a
|
|
987
|
+
`SHWEET_WEBDRIVER_URL` endpoint is connected.
|
|
988
|
+
- The packed declarations are bundled into a single self-contained file. They do
|
|
989
|
+
not import `@ohmyqt/u` or any other package, so a consumer can typecheck them
|
|
990
|
+
with `skipLibCheck: false` without installing Shweet's build-time helpers.
|
|
991
|
+
They reference standard DOM types, so the consumer's `lib` should include
|
|
992
|
+
`DOM` (as TypeScript's default libraries do).
|
|
993
|
+
|
|
994
|
+
Source and issue tracker: [MARKjotep/sweetss](https://github.com/MARKjotep/sweetss).
|