@atomic-ui/design-tokens 0.1.7 → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +2 -2
- package/dist/{chunk-7BKTXJHX.js → chunk-ZTASNIBX.js} +8 -1
- package/dist/chunk-ZTASNIBX.js.map +1 -0
- package/dist/contrast.d.ts +1 -1
- package/dist/css.js +1 -1
- package/dist/dtcg.d.ts +1 -1
- package/dist/fonts.d.ts +12 -4
- package/dist/index.d.ts +3 -2
- package/dist/index.js +232 -38
- package/dist/index.js.map +1 -1
- package/dist/inputs.d.ts +94 -9
- package/dist/motion.d.ts +118 -0
- package/dist/tailwind.js +1 -1
- package/package.json +8 -2
- package/dist/chunk-7BKTXJHX.js.map +0 -1
package/dist/inputs.d.ts
CHANGED
|
@@ -7,7 +7,7 @@
|
|
|
7
7
|
* question beyond that; the legacy Sanity CMS this replaces allowed everything
|
|
8
8
|
* and accumulated forty per-viewport override fields nobody could prune. The
|
|
9
9
|
* reasoning, with sources, is
|
|
10
|
-
* [ADR 0010](
|
|
10
|
+
* [ADR 0010](https://github.com/matthill8286/strata/blob/main/docs/decisions/0010-what-a-brand-may-set.md).
|
|
11
11
|
*
|
|
12
12
|
* Two absences are the point of the whole file. There is no foreground colour
|
|
13
13
|
* anywhere — text on a surface is computed, so a partner cannot pin white text
|
|
@@ -88,6 +88,18 @@ export declare const BrandInputsSchema: z.ZodObject<{
|
|
|
88
88
|
surfaceHeader: z.ZodString;
|
|
89
89
|
/** The footer band. */
|
|
90
90
|
surfaceFooter: z.ZodString;
|
|
91
|
+
/** Text in the header band. Unset, it is the accent on a light band and white or black on a dark one. */
|
|
92
|
+
textHeader: z.ZodOptional<z.ZodString>;
|
|
93
|
+
/** Text in the footer band. Unset, it follows the same rule as the header's. */
|
|
94
|
+
textFooter: z.ZodOptional<z.ZodString>;
|
|
95
|
+
/** Headings. Unset, they take the accent; a brand whose headings are set in ink names it here. */
|
|
96
|
+
textHeading: z.ZodOptional<z.ZodString>;
|
|
97
|
+
/**
|
|
98
|
+
* Colours for things told apart by colour alone: the lanes of a timeline,
|
|
99
|
+
* the branches of a list, the stripe along a footer. In order; unset, the
|
|
100
|
+
* accent and the status colours stand in.
|
|
101
|
+
*/
|
|
102
|
+
chart: z.ZodOptional<z.ZodArray<z.ZodString, "many">>;
|
|
91
103
|
/** Default body text, on `surfaceCard`. */
|
|
92
104
|
text: z.ZodString;
|
|
93
105
|
danger: z.ZodString;
|
|
@@ -106,6 +118,10 @@ export declare const BrandInputsSchema: z.ZodObject<{
|
|
|
106
118
|
success: string;
|
|
107
119
|
info: string;
|
|
108
120
|
accent?: string | undefined;
|
|
121
|
+
textHeader?: string | undefined;
|
|
122
|
+
textFooter?: string | undefined;
|
|
123
|
+
textHeading?: string | undefined;
|
|
124
|
+
chart?: string[] | undefined;
|
|
109
125
|
}, {
|
|
110
126
|
brand: string;
|
|
111
127
|
surfacePage: string;
|
|
@@ -118,11 +134,19 @@ export declare const BrandInputsSchema: z.ZodObject<{
|
|
|
118
134
|
success: string;
|
|
119
135
|
info: string;
|
|
120
136
|
accent?: string | undefined;
|
|
137
|
+
textHeader?: string | undefined;
|
|
138
|
+
textFooter?: string | undefined;
|
|
139
|
+
textHeading?: string | undefined;
|
|
140
|
+
chart?: string[] | undefined;
|
|
121
141
|
}>;
|
|
122
142
|
font: z.ZodObject<{
|
|
123
143
|
body: z.ZodString;
|
|
124
144
|
/** Defaults to `body` when unset — most brands have one typeface. */
|
|
125
145
|
heading: z.ZodOptional<z.ZodString>;
|
|
146
|
+
/** Code-like labels: hashes, branches, version lines. Unset, the device's own monospace face. */
|
|
147
|
+
mono: z.ZodOptional<z.ZodString>;
|
|
148
|
+
/** The face of the small line above a heading. `mono` sets it as a code label, as a changelog would. */
|
|
149
|
+
eyebrow: z.ZodDefault<z.ZodEnum<["body", "mono"]>>;
|
|
126
150
|
/** Root size in px. Everything else is `rem`, scaled from this. */
|
|
127
151
|
sizeBase: z.ZodDefault<z.ZodNumber>;
|
|
128
152
|
scale: z.ZodDefault<z.ZodNumber>;
|
|
@@ -148,6 +172,7 @@ export declare const BrandInputsSchema: z.ZodObject<{
|
|
|
148
172
|
}>, "many">>;
|
|
149
173
|
}, "strict", z.ZodTypeAny, {
|
|
150
174
|
body: string;
|
|
175
|
+
eyebrow: "body" | "mono";
|
|
151
176
|
sizeBase: number;
|
|
152
177
|
scale: number;
|
|
153
178
|
webFonts: {
|
|
@@ -158,9 +183,12 @@ export declare const BrandInputsSchema: z.ZodObject<{
|
|
|
158
183
|
display?: string | undefined;
|
|
159
184
|
}[];
|
|
160
185
|
heading?: string | undefined;
|
|
186
|
+
mono?: string | undefined;
|
|
161
187
|
}, {
|
|
162
188
|
body: string;
|
|
163
189
|
heading?: string | undefined;
|
|
190
|
+
mono?: string | undefined;
|
|
191
|
+
eyebrow?: "body" | "mono" | undefined;
|
|
164
192
|
sizeBase?: number | undefined;
|
|
165
193
|
scale?: number | undefined;
|
|
166
194
|
webFonts?: {
|
|
@@ -178,14 +206,25 @@ export declare const BrandInputsSchema: z.ZodObject<{
|
|
|
178
206
|
spaceBase: z.ZodDefault<z.ZodNumber>;
|
|
179
207
|
/** Default border weight in px. */
|
|
180
208
|
borderWidth: z.ZodDefault<z.ZodNumber>;
|
|
209
|
+
/** A form field: a card-coloured box with a border, or a box filled a shade off the page with a fainter one. */
|
|
210
|
+
fields: z.ZodDefault<z.ZodEnum<["outlined", "filled"]>>;
|
|
211
|
+
/**
|
|
212
|
+
* What a solid button does when pointed at: a shade darker, or turn the
|
|
213
|
+
* accent colour, its arrow lifting a quarter-turn up, as some brands do.
|
|
214
|
+
*/
|
|
215
|
+
buttonHover: z.ZodDefault<z.ZodEnum<["shade", "accent"]>>;
|
|
181
216
|
}, "strict", z.ZodTypeAny, {
|
|
182
217
|
radiusBase: number;
|
|
183
218
|
spaceBase: number;
|
|
184
219
|
borderWidth: number;
|
|
220
|
+
fields: "outlined" | "filled";
|
|
221
|
+
buttonHover: "accent" | "shade";
|
|
185
222
|
}, {
|
|
186
223
|
radiusBase?: number | undefined;
|
|
187
224
|
spaceBase?: number | undefined;
|
|
188
225
|
borderWidth?: number | undefined;
|
|
226
|
+
fields?: "outlined" | "filled" | undefined;
|
|
227
|
+
buttonHover?: "accent" | "shade" | undefined;
|
|
189
228
|
}>;
|
|
190
229
|
/**
|
|
191
230
|
* The page's frame and the spacing between columns.
|
|
@@ -253,7 +292,29 @@ export declare const BrandInputsSchema: z.ZodObject<{
|
|
|
253
292
|
lg?: "0" | "1" | "2" | "3" | "4" | "5" | "6" | "7" | "8" | "9" | "10" | undefined;
|
|
254
293
|
} | undefined;
|
|
255
294
|
}>>;
|
|
256
|
-
|
|
295
|
+
/**
|
|
296
|
+
* How the brand moves: a personality and a playback speed, and nothing else.
|
|
297
|
+
* Every duration, curve and spring is derived from these two
|
|
298
|
+
* ([ADR 0027](https://github.com/matthill8286/strata/blob/main/docs/decisions/0027-motion-is-states-transitions-and-timelines.md)).
|
|
299
|
+
* Defaults to calm at normal speed, so a brand that sets none of it is quiet.
|
|
300
|
+
*/
|
|
301
|
+
motion: z.ZodDefault<z.ZodObject<{
|
|
302
|
+
personality: z.ZodDefault<z.ZodEnum<["calm", "lively", "expressive"]>>;
|
|
303
|
+
speed: z.ZodDefault<z.ZodNumber>;
|
|
304
|
+
}, "strict", z.ZodTypeAny, {
|
|
305
|
+
personality: "calm" | "lively" | "expressive";
|
|
306
|
+
speed: number;
|
|
307
|
+
}, {
|
|
308
|
+
personality?: "calm" | "lively" | "expressive" | undefined;
|
|
309
|
+
speed?: number | undefined;
|
|
310
|
+
}>>;
|
|
311
|
+
/**
|
|
312
|
+
* The logo and favicon. A site made in the CMS before anyone uploads a logo
|
|
313
|
+
* has none, which is the house default's empty logo rather than a missing
|
|
314
|
+
* brand: without the default, delivery refused the whole brand and the site
|
|
315
|
+
* rendered in the generic look.
|
|
316
|
+
*/
|
|
317
|
+
assets: z.ZodDefault<z.ZodObject<{
|
|
257
318
|
logo: z.ZodString;
|
|
258
319
|
logoAlt: z.ZodString;
|
|
259
320
|
/** For use on dark surfaces, where the main logo would disappear. */
|
|
@@ -269,7 +330,7 @@ export declare const BrandInputsSchema: z.ZodObject<{
|
|
|
269
330
|
logoAlt: string;
|
|
270
331
|
logoDark?: string | undefined;
|
|
271
332
|
favicon?: string | undefined;
|
|
272
|
-
}
|
|
333
|
+
}>>;
|
|
273
334
|
}, "strip", z.ZodTypeAny, {
|
|
274
335
|
color: {
|
|
275
336
|
brand: string;
|
|
@@ -283,9 +344,14 @@ export declare const BrandInputsSchema: z.ZodObject<{
|
|
|
283
344
|
success: string;
|
|
284
345
|
info: string;
|
|
285
346
|
accent?: string | undefined;
|
|
347
|
+
textHeader?: string | undefined;
|
|
348
|
+
textFooter?: string | undefined;
|
|
349
|
+
textHeading?: string | undefined;
|
|
350
|
+
chart?: string[] | undefined;
|
|
286
351
|
};
|
|
287
352
|
font: {
|
|
288
353
|
body: string;
|
|
354
|
+
eyebrow: "body" | "mono";
|
|
289
355
|
sizeBase: number;
|
|
290
356
|
scale: number;
|
|
291
357
|
webFonts: {
|
|
@@ -296,11 +362,14 @@ export declare const BrandInputsSchema: z.ZodObject<{
|
|
|
296
362
|
display?: string | undefined;
|
|
297
363
|
}[];
|
|
298
364
|
heading?: string | undefined;
|
|
365
|
+
mono?: string | undefined;
|
|
299
366
|
};
|
|
300
367
|
shape: {
|
|
301
368
|
radiusBase: number;
|
|
302
369
|
spaceBase: number;
|
|
303
370
|
borderWidth: number;
|
|
371
|
+
fields: "outlined" | "filled";
|
|
372
|
+
buttonHover: "accent" | "shade";
|
|
304
373
|
};
|
|
305
374
|
layout: {
|
|
306
375
|
pageWidth: number;
|
|
@@ -315,6 +384,10 @@ export declare const BrandInputsSchema: z.ZodObject<{
|
|
|
315
384
|
lg: "0" | "1" | "2" | "3" | "4" | "5" | "6" | "7" | "8" | "9" | "10";
|
|
316
385
|
};
|
|
317
386
|
};
|
|
387
|
+
motion: {
|
|
388
|
+
personality: "calm" | "lively" | "expressive";
|
|
389
|
+
speed: number;
|
|
390
|
+
};
|
|
318
391
|
assets: {
|
|
319
392
|
logo: string;
|
|
320
393
|
logoAlt: string;
|
|
@@ -334,10 +407,16 @@ export declare const BrandInputsSchema: z.ZodObject<{
|
|
|
334
407
|
success: string;
|
|
335
408
|
info: string;
|
|
336
409
|
accent?: string | undefined;
|
|
410
|
+
textHeader?: string | undefined;
|
|
411
|
+
textFooter?: string | undefined;
|
|
412
|
+
textHeading?: string | undefined;
|
|
413
|
+
chart?: string[] | undefined;
|
|
337
414
|
};
|
|
338
415
|
font: {
|
|
339
416
|
body: string;
|
|
340
417
|
heading?: string | undefined;
|
|
418
|
+
mono?: string | undefined;
|
|
419
|
+
eyebrow?: "body" | "mono" | undefined;
|
|
341
420
|
sizeBase?: number | undefined;
|
|
342
421
|
scale?: number | undefined;
|
|
343
422
|
webFonts?: {
|
|
@@ -352,12 +431,8 @@ export declare const BrandInputsSchema: z.ZodObject<{
|
|
|
352
431
|
radiusBase?: number | undefined;
|
|
353
432
|
spaceBase?: number | undefined;
|
|
354
433
|
borderWidth?: number | undefined;
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
logo: string;
|
|
358
|
-
logoAlt: string;
|
|
359
|
-
logoDark?: string | undefined;
|
|
360
|
-
favicon?: string | undefined;
|
|
434
|
+
fields?: "outlined" | "filled" | undefined;
|
|
435
|
+
buttonHover?: "accent" | "shade" | undefined;
|
|
361
436
|
};
|
|
362
437
|
layout?: {
|
|
363
438
|
pageWidth?: number | undefined;
|
|
@@ -372,6 +447,16 @@ export declare const BrandInputsSchema: z.ZodObject<{
|
|
|
372
447
|
lg?: "0" | "1" | "2" | "3" | "4" | "5" | "6" | "7" | "8" | "9" | "10" | undefined;
|
|
373
448
|
} | undefined;
|
|
374
449
|
} | undefined;
|
|
450
|
+
motion?: {
|
|
451
|
+
personality?: "calm" | "lively" | "expressive" | undefined;
|
|
452
|
+
speed?: number | undefined;
|
|
453
|
+
} | undefined;
|
|
454
|
+
assets?: {
|
|
455
|
+
logo: string;
|
|
456
|
+
logoAlt: string;
|
|
457
|
+
logoDark?: string | undefined;
|
|
458
|
+
favicon?: string | undefined;
|
|
459
|
+
} | undefined;
|
|
375
460
|
}>;
|
|
376
461
|
export type BrandInputs = z.infer<typeof BrandInputsSchema>;
|
|
377
462
|
/**
|
package/dist/motion.d.ts
ADDED
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Motion tokens — the timing every transition names, derived from two inputs.
|
|
3
|
+
*
|
|
4
|
+
* [ADR 0027](https://github.com/matthill8286/strata/blob/main/docs/decisions/0027-motion-is-states-transitions-and-timelines.md)
|
|
5
|
+
* keeps motion inside the rule of ADR 0010: a brand chooses a personality and a
|
|
6
|
+
* speed, and nothing else. Durations, curves, springs, stagger gaps and travel
|
|
7
|
+
* distances are derived here. A partner who wants a different curve is asking
|
|
8
|
+
* for a change to this table, which is a product decision with a version number.
|
|
9
|
+
*
|
|
10
|
+
* Springs are described physically (stiffness, damping ratio, mass) and also
|
|
11
|
+
* baked into a CSS `linear()` easing with its own duration, so a compiled page
|
|
12
|
+
* can run a spring with no script. Interruptible transitions read the physical
|
|
13
|
+
* values instead and run on the motion runtime.
|
|
14
|
+
*/
|
|
15
|
+
import { z } from 'zod';
|
|
16
|
+
import type { TokenSet } from './derive';
|
|
17
|
+
export declare const MOTION_PERSONALITIES: readonly ["calm", "lively", "expressive"];
|
|
18
|
+
export type MotionPersonality = (typeof MOTION_PERSONALITIES)[number];
|
|
19
|
+
/**
|
|
20
|
+
* What a brand may set about motion.
|
|
21
|
+
*
|
|
22
|
+
* `speed` is a playback rate: 1.25 is a quarter faster, 0.75 a quarter slower.
|
|
23
|
+
* The bounds are where the derived durations stay inside the range the motion
|
|
24
|
+
* gate accepts for every personality.
|
|
25
|
+
*/
|
|
26
|
+
export declare const MotionInputsSchema: z.ZodObject<{
|
|
27
|
+
personality: z.ZodDefault<z.ZodEnum<["calm", "lively", "expressive"]>>;
|
|
28
|
+
speed: z.ZodDefault<z.ZodNumber>;
|
|
29
|
+
}, "strict", z.ZodTypeAny, {
|
|
30
|
+
personality: "calm" | "lively" | "expressive";
|
|
31
|
+
speed: number;
|
|
32
|
+
}, {
|
|
33
|
+
personality?: "calm" | "lively" | "expressive" | undefined;
|
|
34
|
+
speed?: number | undefined;
|
|
35
|
+
}>;
|
|
36
|
+
export type MotionInputs = z.infer<typeof MotionInputsSchema>;
|
|
37
|
+
export declare const DURATION_NAMES: readonly ["instant", "fast", "base", "slow", "scene"];
|
|
38
|
+
export declare const EASING_NAMES: readonly ["standard", "enter", "exit", "emphasis"];
|
|
39
|
+
export declare const SPRING_NAMES: readonly ["snappy", "gentle", "bouncy"];
|
|
40
|
+
export declare const STAGGER_NAMES: readonly ["tight", "base", "loose"];
|
|
41
|
+
export declare const DISTANCE_NAMES: readonly ["near", "far"];
|
|
42
|
+
export type DurationName = (typeof DURATION_NAMES)[number];
|
|
43
|
+
export type EasingName = (typeof EASING_NAMES)[number];
|
|
44
|
+
export type SpringName = (typeof SPRING_NAMES)[number];
|
|
45
|
+
export type StaggerName = (typeof STAGGER_NAMES)[number];
|
|
46
|
+
export type DistanceName = (typeof DISTANCE_NAMES)[number];
|
|
47
|
+
export type Bezier = readonly [number, number, number, number];
|
|
48
|
+
/** A spring by its physics. `dampingRatio` 1 settles with no overshoot; below 1 it bounces. */
|
|
49
|
+
export interface Spring {
|
|
50
|
+
stiffness: number;
|
|
51
|
+
dampingRatio: number;
|
|
52
|
+
mass: number;
|
|
53
|
+
}
|
|
54
|
+
interface Personality {
|
|
55
|
+
/** Milliseconds at speed 1. `instant` is always 0 and is not listed. */
|
|
56
|
+
duration: Record<Exclude<DurationName, 'instant'>, number>;
|
|
57
|
+
easing: Record<EasingName, Bezier>;
|
|
58
|
+
spring: Record<SpringName, Spring>;
|
|
59
|
+
/** Milliseconds between choreographed siblings, at speed 1. */
|
|
60
|
+
stagger: Record<StaggerName, number>;
|
|
61
|
+
/** How far an entering element travels, in steps of the spacing unit. */
|
|
62
|
+
distance: Record<DistanceName, number>;
|
|
63
|
+
}
|
|
64
|
+
/**
|
|
65
|
+
* The three personalities.
|
|
66
|
+
*
|
|
67
|
+
* `calm` is the house default and suits regulated products: short, no
|
|
68
|
+
* overshoot except in `bouncy`, small travel. `lively` is the marketing
|
|
69
|
+
* register. `expressive` is for studios and launches, with real bounce and
|
|
70
|
+
* longer scenes, and is still inside the gate's limits.
|
|
71
|
+
*/
|
|
72
|
+
export declare const PERSONALITIES: Record<MotionPersonality, Personality>;
|
|
73
|
+
/** The bounds the motion gate holds every derived duration to, in ms. */
|
|
74
|
+
export declare const DURATION_LIMITS: {
|
|
75
|
+
readonly min: 0;
|
|
76
|
+
readonly max: 2000;
|
|
77
|
+
};
|
|
78
|
+
/**
|
|
79
|
+
* A spring's position over time, from 0 at rest to 1 at the target.
|
|
80
|
+
*
|
|
81
|
+
* The closed-form solution of a damped harmonic oscillator released from 0
|
|
82
|
+
* with no initial velocity. Under-damped springs overshoot; critically damped
|
|
83
|
+
* ones approach 1 without passing it. Time is in seconds.
|
|
84
|
+
*/
|
|
85
|
+
export declare function springAt(spring: Spring, t: number): number;
|
|
86
|
+
/**
|
|
87
|
+
* How long a spring takes to settle, in ms: the last moment it is more than
|
|
88
|
+
* `tolerance` away from its target.
|
|
89
|
+
*/
|
|
90
|
+
export declare function springDuration(spring: Spring, tolerance?: number): number;
|
|
91
|
+
/**
|
|
92
|
+
* A spring baked into a CSS `linear()` easing and the duration it runs over.
|
|
93
|
+
*
|
|
94
|
+
* `linear()` interpolates straight lines between the listed points, so a spring
|
|
95
|
+
* sampled densely enough is visually indistinguishable from the physics. Forty
|
|
96
|
+
* points is where the overshoot of the bounciest spring stops showing facets.
|
|
97
|
+
*/
|
|
98
|
+
export declare function springToLinear(spring: Spring, points?: number): {
|
|
99
|
+
easing: string;
|
|
100
|
+
durationMs: number;
|
|
101
|
+
};
|
|
102
|
+
/** A spring sped up or slowed down: time scales by 1/speed, so stiffness scales by speed². */
|
|
103
|
+
export declare function scaleSpring(spring: Spring, speed: number): Spring;
|
|
104
|
+
/** The fully resolved motion values, for code that needs numbers rather than CSS strings. */
|
|
105
|
+
export interface ResolvedMotion {
|
|
106
|
+
personality: MotionPersonality;
|
|
107
|
+
speed: number;
|
|
108
|
+
duration: Record<DurationName, number>;
|
|
109
|
+
easing: Record<EasingName, Bezier>;
|
|
110
|
+
spring: Record<SpringName, Spring>;
|
|
111
|
+
stagger: Record<StaggerName, number>;
|
|
112
|
+
/** In px, after the spacing unit is applied. */
|
|
113
|
+
distance: Record<DistanceName, number>;
|
|
114
|
+
}
|
|
115
|
+
export declare function resolveMotion(input: Partial<MotionInputs> | undefined, spaceBase?: number): ResolvedMotion;
|
|
116
|
+
/** Motion as flat tokens, merged into the set `deriveTokens` returns. */
|
|
117
|
+
export declare function deriveMotionTokens(input: Partial<MotionInputs> | undefined, spaceBase?: number): TokenSet;
|
|
118
|
+
export {};
|
package/dist/tailwind.js
CHANGED
package/package.json
CHANGED
|
@@ -1,7 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@atomic-ui/design-tokens",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.2.0",
|
|
4
4
|
"description": "The design tokens every Impkt component reads, and the derivation that turns a partner's handful of brand inputs into the whole set.",
|
|
5
|
+
"repository": {
|
|
6
|
+
"type": "git",
|
|
7
|
+
"url": "git+https://github.com/matthill8286/impkt-design-system.git",
|
|
8
|
+
"directory": "packages/design-tokens"
|
|
9
|
+
},
|
|
5
10
|
"type": "module",
|
|
6
11
|
"main": "./dist/index.js",
|
|
7
12
|
"types": "./dist/index.d.ts",
|
|
@@ -32,6 +37,7 @@
|
|
|
32
37
|
"README.md"
|
|
33
38
|
],
|
|
34
39
|
"publishConfig": {
|
|
40
|
+
"registry": "https://registry.npmjs.org",
|
|
35
41
|
"access": "public"
|
|
36
42
|
},
|
|
37
43
|
"scripts": {
|
|
@@ -40,4 +46,4 @@
|
|
|
40
46
|
"test": "vitest run",
|
|
41
47
|
"emit": "tsx src/emit.ts"
|
|
42
48
|
}
|
|
43
|
-
}
|
|
49
|
+
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/css.ts"],"sourcesContent":["/**\n * Tokens → CSS custom properties.\n *\n * One emitter, used by both paths. The house theme is written to a stylesheet\n * at build time and a partner's brand is emitted at runtime from a published\n * document, and if those were two pieces of code they would drift — quietly,\n * because nothing would compare them. The same reasoning as the delivery API's\n * export command, which issues a real request rather than re-implementing the\n * response.\n */\nimport type { TokenSet } from './derive';\nimport type { WebFont } from './inputs';\n\n/** The namespace. Every property this package emits starts with it. */\nexport const PREFIX = '--impkt';\n\n/** `color.text.on-brand` → `--impkt-color-text-on-brand`. */\nexport const cssVarName = (path: string): string => `${PREFIX}-${path.replace(/\\./g, '-')}`;\n\n/** Tokens as a style object, for a runtime `style={}` or `element.style`. */\nexport function toStyleProperties(tokens: TokenSet): Record<string, string> {\n const out: Record<string, string> = {};\n for (const [path, value] of Object.entries(tokens)) out[cssVarName(path)] = value;\n return out;\n}\n\n/** Tokens as declarations, for a stylesheet or a `<style>` block. */\nexport function toCssDeclarations(tokens: TokenSet, indent = ' '): string {\n return Object.entries(tokens)\n .map(([path, value]) => `${indent}${cssVarName(path)}: ${value};`)\n .join('\\n');\n}\n\nexport interface StylesheetOptions {\n /** Defaults to `:root`. A preview frame or a brand switcher passes its own. */\n selector?: string;\n fonts?: WebFont[];\n}\n\n/**\n * A complete stylesheet: the faces the brand needs, then its properties.\n *\n * `@font-face` travels with the brand rather than being compiled into one\n * app's stylesheet, because a partner brings its own typeface and the shell\n * cannot know in advance what it is.\n */\n/**\n * The page frame a brand's layout describes, as a class an app puts on the\n * element its pages fill: the content no wider than the page width, centred,\n * with the brand's margin for each size of screen between it and the edge.\n * The breakpoints are the ones the grid stacks at.\n */\nexport const PAGE_FRAME = [\n `.impkt-page {\\n box-sizing: border-box;\\n inline-size: 100%;\\n max-inline-size: calc(${'var(--impkt-layout-page-width, 1200px)'} + 2 * ${'var(--impkt-layout-margin-desktop, 64px)'});\\n margin-inline: auto;\\n padding-inline: var(--impkt-layout-margin-phone, 16px);\\n}`,\n `@media (min-width: 40rem) {\\n .impkt-page { padding-inline: var(--impkt-layout-margin-tablet, 32px); }\\n}`,\n `@media (min-width: 64rem) {\\n .impkt-page { padding-inline: var(--impkt-layout-margin-desktop, 64px); }\\n}`,\n].join('\\n');\n\n/** The `@font-face` rules for a brand's font files. */\nexport function fontFaceCss(fonts: readonly WebFont[]): string {\n return fonts.filter((f) => f.url).map((f) => {\n const lines = [\n ` font-family: ${JSON.stringify(f.family)};`,\n ` src: url(${JSON.stringify(f.url)}) format(\"${/\\.woff(\\?|#|$)/i.test(f.url) ? 'woff' : 'woff2'}\");`,\n ` font-display: ${f.display ?? 'swap'};`,\n ];\n if (f.weight) lines.push(` font-weight: ${f.weight};`);\n if (f.style) lines.push(` font-style: ${f.style};`);\n return `@font-face {\\n${lines.join('\\n')}\\n}`;\n }).join('\\n\\n');\n}\n\nexport function toStylesheet(tokens: TokenSet, options: StylesheetOptions = {}): string {\n const { selector = ':root', fonts = [] } = options;\n const faces = fontFaceCss(fonts);\n return [...(faces ? [faces] : []), `${selector} {\\n${toCssDeclarations(tokens)}\\n}`, PAGE_FRAME].join('\\n\\n') + '\\n';\n}\n\n/**\n * Escape a stylesheet for inline injection.\n *\n * A brand is authored content, and authored content reaches a `<style>` block\n * here. `</style>` inside a font family name would close the element and start\n * an injection; the font-family value is already JSON-quoted above, and this is\n * the second line of defence for whoever writes the third emitter.\n */\nexport const escapeStyleText = (css: string): string => css.replace(/<\\/(style)/gi, '<\\\\/$1');\n"],"mappings":";AAcO,IAAM,SAAS;AAGf,IAAM,aAAa,CAAC,SAAyB,GAAG,MAAM,IAAI,KAAK,QAAQ,OAAO,GAAG,CAAC;AAGlF,SAAS,kBAAkB,QAA0C;AAC1E,QAAM,MAA8B,CAAC;AACrC,aAAW,CAAC,MAAM,KAAK,KAAK,OAAO,QAAQ,MAAM,EAAG,KAAI,WAAW,IAAI,CAAC,IAAI;AAC5E,SAAO;AACT;AAGO,SAAS,kBAAkB,QAAkB,SAAS,MAAc;AACzE,SAAO,OAAO,QAAQ,MAAM,EACzB,IAAI,CAAC,CAAC,MAAM,KAAK,MAAM,GAAG,MAAM,GAAG,WAAW,IAAI,CAAC,KAAK,KAAK,GAAG,EAChE,KAAK,IAAI;AACd;AAqBO,IAAM,aAAa;AAAA,EACxB;AAAA;AAAA;AAAA,0BAA2F,wCAAwC,UAAU,0CAA0C;AAAA;AAAA;AAAA;AAAA,EACvL;AAAA;AAAA;AAAA,EACA;AAAA;AAAA;AACF,EAAE,KAAK,IAAI;AAGJ,SAAS,YAAY,OAAmC;AAC7D,SAAO,MAAM,OAAO,CAAC,MAAM,EAAE,GAAG,EAAE,IAAI,CAAC,MAAM;AAC3C,UAAM,QAAQ;AAAA,MACZ,kBAAkB,KAAK,UAAU,EAAE,MAAM,CAAC;AAAA,MAC1C,cAAc,KAAK,UAAU,EAAE,GAAG,CAAC,aAAa,kBAAkB,KAAK,EAAE,GAAG,IAAI,SAAS,OAAO;AAAA,MAChG,mBAAmB,EAAE,WAAW,MAAM;AAAA,IACxC;AACA,QAAI,EAAE,OAAQ,OAAM,KAAK,kBAAkB,EAAE,MAAM,GAAG;AACtD,QAAI,EAAE,MAAO,OAAM,KAAK,iBAAiB,EAAE,KAAK,GAAG;AACnD,WAAO;AAAA,EAAiB,MAAM,KAAK,IAAI,CAAC;AAAA;AAAA,EAC1C,CAAC,EAAE,KAAK,MAAM;AAChB;AAEO,SAAS,aAAa,QAAkB,UAA6B,CAAC,GAAW;AACtF,QAAM,EAAE,WAAW,SAAS,QAAQ,CAAC,EAAE,IAAI;AAC3C,QAAM,QAAQ,YAAY,KAAK;AAC/B,SAAO,CAAC,GAAI,QAAQ,CAAC,KAAK,IAAI,CAAC,GAAI,GAAG,QAAQ;AAAA,EAAO,kBAAkB,MAAM,CAAC;AAAA,IAAO,UAAU,EAAE,KAAK,MAAM,IAAI;AAClH;AAUO,IAAM,kBAAkB,CAAC,QAAwB,IAAI,QAAQ,gBAAgB,QAAQ;","names":[]}
|