@stonedogcode/style 0.13.0 → 0.16.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.
@@ -0,0 +1,101 @@
1
+ /**
2
+ * The stacking-order vocabulary: names for the layers a UI actually has.
3
+ *
4
+ * ## The bug this exists to fix
5
+ *
6
+ * `drawerRecipe` has said `zIndex: "modal"` since it was extracted, and there
7
+ * has never been a `zIndex` token scale for `"modal"` to resolve against —
8
+ * neither here nor in either base Panda preset. Panda passes an unknown token
9
+ * through as a **literal**, so the generated stylesheet said
10
+ *
11
+ * .drawer { position: fixed; z-index: modal; }
12
+ *
13
+ * `modal` is not a valid `z-index` value, so the browser discards the whole
14
+ * declaration. **The drawer panel has never had a z-index at all.** No build
15
+ * error, no console warning, no type error — the class is in the DOM and the
16
+ * rule behind it is one line shorter than it looks.
17
+ *
18
+ * This is precisely the defect class CLAUDE.md records under "Token
19
+ * compliance", one property along from `bg: "buttonBgHover"`. The colour half
20
+ * is guarded by `token-contract.test.ts`; the z-index half is now guarded
21
+ * beside it.
22
+ *
23
+ * ## This package owns the NAMES. The host owns the NUMBERS
24
+ *
25
+ * A z-index ladder is an application concern — it encodes which of *that
26
+ * product's* surfaces may cover which, and no two products agree. So the
27
+ * values below are conventional defaults chosen to be sane for a fresh
28
+ * consumer, and a host is expected to override them:
29
+ *
30
+ * ```ts
31
+ * // the host's panda.config.ts
32
+ * theme: { extend: { tokens: { zIndex: { modal: { value: 99999 } } } } }
33
+ * ```
34
+ *
35
+ * Overriding a value keeps the name, and the name is the part that makes the
36
+ * order reviewable. A literal at a call site expresses nothing; `zIndex:
37
+ * "menu"` says what the element *is*, and a reader can check it against this
38
+ * table without opening a second file.
39
+ *
40
+ * ## The ladder
41
+ *
42
+ * Ascending, and the ORDER is the contract — not the numbers:
43
+ *
44
+ * hide behind its own box (decorative pseudo-elements)
45
+ * base the ordinary flow
46
+ * raised lifted within its own stacking context
47
+ * docked a bar or rail pinned inside a region
48
+ * sticky a sticky header inside a scroll region
49
+ * banner page-level chrome above sticky content
50
+ * surface a page surface that fills the viewport
51
+ * dialog a modal dialog and its scrim
52
+ * menu menus, drawer scrims, docked panels — the floating band's floor
53
+ * popover a popover that has to clear an open menu
54
+ * overlay a full-viewport cover: a splash, a loading shade
55
+ * toast toasts, pickers, transient chrome
56
+ * modal a drawer or modal panel that must clear everything but a tip
57
+ * tooltip the top of the application
58
+ *
59
+ * **A dialog sits LOW on purpose.** Menus, toasts, tooltips and dropdowns all
60
+ * have to be able to open *on* a dialog, so every one of them is above it.
61
+ * Raising the dialog to "win" is the change that looks right and breaks every
62
+ * control opened inside one.
63
+ */
64
+
65
+ /**
66
+ * The layer names, in ascending order, with this package's default values.
67
+ *
68
+ * Exported as plain numbers as well as tokens because a **portalled** element
69
+ * usually sets its z-index from an inline `style`, and an inline style cannot
70
+ * name a Panda token. Both readings have to come from one place or they drift.
71
+ */
72
+ export const Z_LAYERS = {
73
+ hide: -1,
74
+ base: 0,
75
+ raised: 1,
76
+ docked: 10,
77
+ sticky: 20,
78
+ banner: 50,
79
+ surface: 100,
80
+ dialog: 200,
81
+ menu: 300,
82
+ popover: 400,
83
+ overlay: 500,
84
+ toast: 600,
85
+ modal: 700,
86
+ tooltip: 800,
87
+ } as const;
88
+
89
+ export type ZLayerName = keyof typeof Z_LAYERS;
90
+
91
+ /** Every layer name. Useful to a consumer's guard test. */
92
+ export function zIndexTokenNames(): ZLayerName[] {
93
+ return Object.keys(Z_LAYERS) as ZLayerName[];
94
+ }
95
+
96
+ /** The scale in the shape Panda's `theme.extend.tokens.zIndex` wants. */
97
+ export function createZIndexTokens(): Record<string, { value: number }> {
98
+ return Object.fromEntries(
99
+ Object.entries(Z_LAYERS).map(([token, value]) => [token, { value }]),
100
+ );
101
+ }