@sigx/lynx-zero 0.4.9 → 0.5.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.
@@ -1,82 +1,82 @@
1
- /**
2
- * Box-model style helpers shared by layout primitives and design-system
3
- * components. Color values resolve through the semantic token contract
4
- * (`resolveColorToken`), so `<Col background="base-100">` works identically
5
- * under every design system's active theme.
6
- */
7
- import { resolveColorToken, type BackgroundValue } from '../contract.js';
8
-
9
- export type SpacingValue = number | {
10
- x?: number;
11
- y?: number;
12
- top?: number;
13
- right?: number;
14
- bottom?: number;
15
- left?: number;
16
- };
17
-
18
- export interface BoxProps {
19
- width?: number | string;
20
- height?: number | string;
21
- flex?: number;
22
- background?: BackgroundValue;
23
- borderRadius?: number;
24
- padding?: SpacingValue;
25
- margin?: SpacingValue;
26
- }
27
-
28
- export function resolveSpacing(
29
- value: SpacingValue | undefined,
30
- prefix: 'padding' | 'margin'
31
- ): Record<string, number> {
32
- if (value === undefined) return {};
33
-
34
- if (typeof value === 'number') {
35
- return {
36
- [`${prefix}Top`]: value,
37
- [`${prefix}Right`]: value,
38
- [`${prefix}Bottom`]: value,
39
- [`${prefix}Left`]: value,
40
- };
41
- }
42
-
43
- const style: Record<string, number> = {};
44
-
45
- if (value.top !== undefined) style[`${prefix}Top`] = value.top;
46
- else if (value.y !== undefined) style[`${prefix}Top`] = value.y;
47
-
48
- if (value.bottom !== undefined) style[`${prefix}Bottom`] = value.bottom;
49
- else if (value.y !== undefined) style[`${prefix}Bottom`] = value.y;
50
-
51
- if (value.right !== undefined) style[`${prefix}Right`] = value.right;
52
- else if (value.x !== undefined) style[`${prefix}Right`] = value.x;
53
-
54
- if (value.left !== undefined) style[`${prefix}Left`] = value.left;
55
- else if (value.x !== undefined) style[`${prefix}Left`] = value.x;
56
-
57
- return style;
58
- }
59
-
60
- export function resolveBoxStyle(props: BoxProps): Record<string, unknown> {
61
- const style: Record<string, unknown> = {};
62
-
63
- if (props.width !== undefined) style.width = props.width;
64
- if (props.height !== undefined) style.height = props.height;
65
- if (props.flex !== undefined) {
66
- // Lynx (like React Native) expands `flex: n` shorthand to
67
- // `flex: n n auto`, where `flexBasis: 'auto'` means "size to content
68
- // first" — which collapses the layout chain. Write the long-form so
69
- // `<Center flex={1}>` etc. actually fill remaining space.
70
- style.flexGrow = props.flex;
71
- style.flexShrink = 1;
72
- style.flexBasis = 0;
73
- style.minHeight = 0;
74
- }
75
- if (props.background !== undefined) style.backgroundColor = resolveColorToken(props.background);
76
- if (props.borderRadius !== undefined) style.borderRadius = props.borderRadius;
77
-
78
- Object.assign(style, resolveSpacing(props.padding, 'padding'));
79
- Object.assign(style, resolveSpacing(props.margin, 'margin'));
80
-
81
- return style;
82
- }
1
+ /**
2
+ * Box-model style helpers shared by layout primitives and design-system
3
+ * components. Color values resolve through the semantic token contract
4
+ * (`resolveColorToken`), so `<Col background="base-100">` works identically
5
+ * under every design system's active theme.
6
+ */
7
+ import { resolveColorToken, type BackgroundValue } from '../contract.js';
8
+
9
+ export type SpacingValue = number | {
10
+ x?: number;
11
+ y?: number;
12
+ top?: number;
13
+ right?: number;
14
+ bottom?: number;
15
+ left?: number;
16
+ };
17
+
18
+ export interface BoxProps {
19
+ width?: number | string;
20
+ height?: number | string;
21
+ flex?: number;
22
+ background?: BackgroundValue;
23
+ borderRadius?: number;
24
+ padding?: SpacingValue;
25
+ margin?: SpacingValue;
26
+ }
27
+
28
+ export function resolveSpacing(
29
+ value: SpacingValue | undefined,
30
+ prefix: 'padding' | 'margin'
31
+ ): Record<string, number> {
32
+ if (value === undefined) return {};
33
+
34
+ if (typeof value === 'number') {
35
+ return {
36
+ [`${prefix}Top`]: value,
37
+ [`${prefix}Right`]: value,
38
+ [`${prefix}Bottom`]: value,
39
+ [`${prefix}Left`]: value,
40
+ };
41
+ }
42
+
43
+ const style: Record<string, number> = {};
44
+
45
+ if (value.top !== undefined) style[`${prefix}Top`] = value.top;
46
+ else if (value.y !== undefined) style[`${prefix}Top`] = value.y;
47
+
48
+ if (value.bottom !== undefined) style[`${prefix}Bottom`] = value.bottom;
49
+ else if (value.y !== undefined) style[`${prefix}Bottom`] = value.y;
50
+
51
+ if (value.right !== undefined) style[`${prefix}Right`] = value.right;
52
+ else if (value.x !== undefined) style[`${prefix}Right`] = value.x;
53
+
54
+ if (value.left !== undefined) style[`${prefix}Left`] = value.left;
55
+ else if (value.x !== undefined) style[`${prefix}Left`] = value.x;
56
+
57
+ return style;
58
+ }
59
+
60
+ export function resolveBoxStyle(props: BoxProps): Record<string, unknown> {
61
+ const style: Record<string, unknown> = {};
62
+
63
+ if (props.width !== undefined) style.width = props.width;
64
+ if (props.height !== undefined) style.height = props.height;
65
+ if (props.flex !== undefined) {
66
+ // Lynx (like React Native) expands `flex: n` shorthand to
67
+ // `flex: n n auto`, where `flexBasis: 'auto'` means "size to content
68
+ // first" — which collapses the layout chain. Write the long-form so
69
+ // `<Center flex={1}>` etc. actually fill remaining space.
70
+ style.flexGrow = props.flex;
71
+ style.flexShrink = 1;
72
+ style.flexBasis = 0;
73
+ style.minHeight = 0;
74
+ }
75
+ if (props.background !== undefined) style.backgroundColor = resolveColorToken(props.background);
76
+ if (props.borderRadius !== undefined) style.borderRadius = props.borderRadius;
77
+
78
+ Object.assign(style, resolveSpacing(props.padding, 'padding'));
79
+ Object.assign(style, resolveSpacing(props.margin, 'margin'));
80
+
81
+ return style;
82
+ }
@@ -1,57 +1,57 @@
1
- /**
2
- * Headless tabs selection — the shared behavior behind every design system's
3
- * `Tabs`/`Tab` pair (extracted once daisy and hero both duplicated it; the
4
- * #219 pilot was the evidence gate).
5
- *
6
- * The DS's `Tabs` container provides a `TabsSelection` built from its
7
- * `activeTab`/`onChange` props; each `Tab` injects it to derive its active
8
- * state from its `value` and to report presses. Explicit per-tab
9
- * `active`/`onPress` props take precedence in the DS components, so the
10
- * fully-controlled per-tab style keeps working.
11
- *
12
- * Reactivity: `provideTabsSelection` is called once at the container's setup
13
- * with *getters* into the container's reactive props, so `isActive()` reads
14
- * track the current `activeTab` value on every render.
15
- */
16
- import { defineInjectable, defineProvide } from '@sigx/lynx';
17
-
18
- export interface TabsSelection {
19
- /** Whether the tab with this `value` is the selected one. Reactive. */
20
- isActive(value: string): boolean;
21
- /** Report a press on the tab with this `value` (drives `onChange`). */
22
- select(value: string): void;
23
- }
24
-
25
- const NO_SELECTION: TabsSelection = {
26
- isActive: () => false,
27
- select: () => {},
28
- };
29
-
30
- /**
31
- * Inject the nearest enclosing `Tabs` container's selection. Outside any
32
- * container this resolves to an inert selection (never active, presses
33
- * no-op), so a bare `Tab` driven purely by `active`/`onPress` still works.
34
- */
35
- export const useTabsSelection = defineInjectable<TabsSelection>(() => NO_SELECTION);
36
-
37
- /**
38
- * Provide a selection for the subtree. Call from the DS `Tabs` container's
39
- * setup with getters into its reactive props:
40
- *
41
- * ```ts
42
- * provideTabsSelection(
43
- * () => props.activeTab,
44
- * (v) => props.onChange?.(v),
45
- * );
46
- * ```
47
- */
48
- export function provideTabsSelection(
49
- getActive: () => string | undefined,
50
- onSelect: (value: string) => void,
51
- ): void {
52
- const selection: TabsSelection = {
53
- isActive: (value) => getActive() === value,
54
- select: onSelect,
55
- };
56
- defineProvide(useTabsSelection, () => selection);
57
- }
1
+ /**
2
+ * Headless tabs selection — the shared behavior behind every design system's
3
+ * `Tabs`/`Tab` pair (extracted once daisy and hero both duplicated it; the
4
+ * #219 pilot was the evidence gate).
5
+ *
6
+ * The DS's `Tabs` container provides a `TabsSelection` built from its
7
+ * `activeTab`/`onChange` props; each `Tab` injects it to derive its active
8
+ * state from its `value` and to report presses. Explicit per-tab
9
+ * `active`/`onPress` props take precedence in the DS components, so the
10
+ * fully-controlled per-tab style keeps working.
11
+ *
12
+ * Reactivity: `provideTabsSelection` is called once at the container's setup
13
+ * with *getters* into the container's reactive props, so `isActive()` reads
14
+ * track the current `activeTab` value on every render.
15
+ */
16
+ import { defineInjectable, defineProvide } from '@sigx/lynx';
17
+
18
+ export interface TabsSelection {
19
+ /** Whether the tab with this `value` is the selected one. Reactive. */
20
+ isActive(value: string): boolean;
21
+ /** Report a press on the tab with this `value` (drives `onChange`). */
22
+ select(value: string): void;
23
+ }
24
+
25
+ const NO_SELECTION: TabsSelection = {
26
+ isActive: () => false,
27
+ select: () => {},
28
+ };
29
+
30
+ /**
31
+ * Inject the nearest enclosing `Tabs` container's selection. Outside any
32
+ * container this resolves to an inert selection (never active, presses
33
+ * no-op), so a bare `Tab` driven purely by `active`/`onPress` still works.
34
+ */
35
+ export const useTabsSelection = defineInjectable<TabsSelection>(() => NO_SELECTION);
36
+
37
+ /**
38
+ * Provide a selection for the subtree. Call from the DS `Tabs` container's
39
+ * setup with getters into its reactive props:
40
+ *
41
+ * ```ts
42
+ * provideTabsSelection(
43
+ * () => props.activeTab,
44
+ * (v) => props.onChange?.(v),
45
+ * );
46
+ * ```
47
+ */
48
+ export function provideTabsSelection(
49
+ getActive: () => string | undefined,
50
+ onSelect: (value: string) => void,
51
+ ): void {
52
+ const selection: TabsSelection = {
53
+ isActive: (value) => getActive() === value,
54
+ select: onSelect,
55
+ };
56
+ defineProvide(useTabsSelection, () => selection);
57
+ }
@@ -1,98 +1,98 @@
1
- /* Theme-agnostic structural design tokens.
2
- *
3
- * Theme COLORS come from the theme registry (seeded by the design-system package) and are
4
- * applied as inline CSS custom properties by <ThemeProvider>. These
5
- * radius / sizing / component tokens are identical across themes, so they
6
- * ship once here under the `.lynx-zero` base class that <ThemeProvider> puts on
7
- * its host view; CSS inheritance propagates them to every descendant. A theme
8
- * may still override roundness via its `radius` field. */
9
-
10
- .lynx-zero {
11
- /* ── Roundness (DaisyUI v5 contract) ── */
12
- --radius-selector: 8px;
13
- --radius-field: 8px;
14
- --radius-box: 16px;
15
-
16
- /* ── Base size units (DaisyUI v5 contract) ──
17
- * A theme's `sizes` ({ field, selector }) overrides these; <ThemeProvider>
18
- * re-derives the component dimensions below from them in JS. We deliberately
19
- * do NOT use `calc(var() * n)` in CSS — it's unproven in Lynx's runtime CSS
20
- * engine. Defaults below are base 4px × the per-token multiples shown. */
21
- --size-selector: 4px;
22
- --size-field: 4px;
23
-
24
- /* ── Field sizing scale (button / input / select) — field × 6/8/12/16 ── */
25
- --size-xs: 24px;
26
- --size-sm: 32px;
27
- --size-md: 48px;
28
- --size-lg: 64px;
29
-
30
- /* ── Text ramp (public <Text> / <Heading> sizes) ──
31
- * The xs→3xl scale the `text-*` utilities resolve to (the daisy preset maps
32
- * Tailwind's fontSize keys onto these vars). Literal px so they resolve on
33
- * the first paint, like every other structural token. Anchored on a 17px
34
- * base — the iOS HIG Body size, so bare <Text> (the default) reads as native
35
- * body — and stepped as an even ~1.2 modular scale (each step ≈1.17–1.21×).
36
- *
37
- * The controller's `fontScale` multiplies this ramp app-wide; <ThemeProvider>
38
- * re-emits the literals in JS (no `calc(var() * n)` — unproven in Lynx).
39
- * NOTE: keep in sync with FONT_DEFAULTS in theme/ThemeProvider.tsx. */
40
- --text-xs: 12px;
41
- --text-sm: 14px;
42
- --text-base: 17px;
43
- --text-lg: 20px;
44
- --text-xl: 24px;
45
- --text-2xl: 28px;
46
- --text-3xl: 34px;
47
-
48
- /* ── Font sizes (control-internal: button / input / badge labels) ──
49
- * A separate axis from the text ramp above and deliberately NOT scaled with
50
- * it — control chrome stays fixed. Kept as independent literals (no
51
- * var→var indirection; unproven in Lynx) even though values mirror the ramp. */
52
- --font-xs: 12px;
53
- --font-sm: 14px;
54
- --font-md: 14px;
55
- --font-lg: 18px;
56
-
57
- /* ── Spacing ── */
58
- --padding-btn-xs: 8px;
59
- --padding-btn-sm: 12px;
60
- --padding-btn-md: 16px;
61
- --padding-btn-lg: 24px;
62
- --padding-box: 16px;
63
- --padding-box-compact: 8px;
64
- --gap-box: 8px;
65
-
66
- /* ── Borders ── */
67
- --border-btn: 1px;
68
- --border-card: 1px;
69
-
70
- /* ── Selector-driven sizes (checkbox / toggle / badge) — selector × the
71
- * multiples shown; <ThemeProvider> re-derives these from `sizes.selector`. ── */
72
- --checkbox-xs: 16px; /* ×4 */
73
- --checkbox-sm: 20px; /* ×5 */
74
- --checkbox-md: 24px; /* ×6 */
75
- --checkbox-lg: 32px; /* ×8 */
76
- --toggle-width-xs: 32px; /* ×8 */
77
- --toggle-width-sm: 40px; /* ×10 */
78
- --toggle-width-md: 48px; /* ×12 */
79
- --toggle-width-lg: 56px; /* ×14 */
80
- --toggle-height-xs: 24px; /* ×6 */
81
- --toggle-height-sm: 24px; /* ×6 */
82
- --toggle-height-md: 28px; /* ×7 */
83
- --toggle-height-lg: 32px; /* ×8 */
84
- --toggle-thumb-xs: 16px; /* ×4 */
85
- --toggle-thumb-sm: 16px; /* ×4 */
86
- --toggle-thumb-md: 20px; /* ×5 */
87
- --toggle-thumb-lg: 24px; /* ×6 */
88
- --badge-xs: 16px; /* ×4 */
89
- --badge-sm: 20px; /* ×5 */
90
- --badge-md: 24px; /* ×6 */
91
- --badge-lg: 32px; /* ×8 */
92
- --step-indicator: 32px;
93
- --progress-height: 8px;
94
- --modal-max-width: 400px;
95
-
96
- /* ── Opacity ── */
97
- --disabled-opacity: 0.5;
98
- }
1
+ /* Theme-agnostic structural design tokens.
2
+ *
3
+ * Theme COLORS come from the theme registry (seeded by the design-system package) and are
4
+ * applied as inline CSS custom properties by <ThemeProvider>. These
5
+ * radius / sizing / component tokens are identical across themes, so they
6
+ * ship once here under the `.lynx-zero` base class that <ThemeProvider> puts on
7
+ * its host view; CSS inheritance propagates them to every descendant. A theme
8
+ * may still override roundness via its `radius` field. */
9
+
10
+ .lynx-zero {
11
+ /* ── Roundness (DaisyUI v5 contract) ── */
12
+ --radius-selector: 8px;
13
+ --radius-field: 8px;
14
+ --radius-box: 16px;
15
+
16
+ /* ── Base size units (DaisyUI v5 contract) ──
17
+ * A theme's `sizes` ({ field, selector }) overrides these; <ThemeProvider>
18
+ * re-derives the component dimensions below from them in JS. We deliberately
19
+ * do NOT use `calc(var() * n)` in CSS — it's unproven in Lynx's runtime CSS
20
+ * engine. Defaults below are base 4px × the per-token multiples shown. */
21
+ --size-selector: 4px;
22
+ --size-field: 4px;
23
+
24
+ /* ── Field sizing scale (button / input / select) — field × 6/8/12/16 ── */
25
+ --size-xs: 24px;
26
+ --size-sm: 32px;
27
+ --size-md: 48px;
28
+ --size-lg: 64px;
29
+
30
+ /* ── Text ramp (public <Text> / <Heading> sizes) ──
31
+ * The xs→3xl scale the `text-*` utilities resolve to (the daisy preset maps
32
+ * Tailwind's fontSize keys onto these vars). Literal px so they resolve on
33
+ * the first paint, like every other structural token. Anchored on a 17px
34
+ * base — the iOS HIG Body size, so bare <Text> (the default) reads as native
35
+ * body — and stepped as an even ~1.2 modular scale (each step ≈1.17–1.21×).
36
+ *
37
+ * The controller's `fontScale` multiplies this ramp app-wide; <ThemeProvider>
38
+ * re-emits the literals in JS (no `calc(var() * n)` — unproven in Lynx).
39
+ * NOTE: keep in sync with FONT_DEFAULTS in theme/ThemeProvider.tsx. */
40
+ --text-xs: 12px;
41
+ --text-sm: 14px;
42
+ --text-base: 17px;
43
+ --text-lg: 20px;
44
+ --text-xl: 24px;
45
+ --text-2xl: 28px;
46
+ --text-3xl: 34px;
47
+
48
+ /* ── Font sizes (control-internal: button / input / badge labels) ──
49
+ * A separate axis from the text ramp above and deliberately NOT scaled with
50
+ * it — control chrome stays fixed. Kept as independent literals (no
51
+ * var→var indirection; unproven in Lynx) even though values mirror the ramp. */
52
+ --font-xs: 12px;
53
+ --font-sm: 14px;
54
+ --font-md: 14px;
55
+ --font-lg: 18px;
56
+
57
+ /* ── Spacing ── */
58
+ --padding-btn-xs: 8px;
59
+ --padding-btn-sm: 12px;
60
+ --padding-btn-md: 16px;
61
+ --padding-btn-lg: 24px;
62
+ --padding-box: 16px;
63
+ --padding-box-compact: 8px;
64
+ --gap-box: 8px;
65
+
66
+ /* ── Borders ── */
67
+ --border-btn: 1px;
68
+ --border-card: 1px;
69
+
70
+ /* ── Selector-driven sizes (checkbox / toggle / badge) — selector × the
71
+ * multiples shown; <ThemeProvider> re-derives these from `sizes.selector`. ── */
72
+ --checkbox-xs: 16px; /* ×4 */
73
+ --checkbox-sm: 20px; /* ×5 */
74
+ --checkbox-md: 24px; /* ×6 */
75
+ --checkbox-lg: 32px; /* ×8 */
76
+ --toggle-width-xs: 32px; /* ×8 */
77
+ --toggle-width-sm: 40px; /* ×10 */
78
+ --toggle-width-md: 48px; /* ×12 */
79
+ --toggle-width-lg: 56px; /* ×14 */
80
+ --toggle-height-xs: 24px; /* ×6 */
81
+ --toggle-height-sm: 24px; /* ×6 */
82
+ --toggle-height-md: 28px; /* ×7 */
83
+ --toggle-height-lg: 32px; /* ×8 */
84
+ --toggle-thumb-xs: 16px; /* ×4 */
85
+ --toggle-thumb-sm: 16px; /* ×4 */
86
+ --toggle-thumb-md: 20px; /* ×5 */
87
+ --toggle-thumb-lg: 24px; /* ×6 */
88
+ --badge-xs: 16px; /* ×4 */
89
+ --badge-sm: 20px; /* ×5 */
90
+ --badge-md: 24px; /* ×6 */
91
+ --badge-lg: 32px; /* ×8 */
92
+ --step-indicator: 32px;
93
+ --progress-height: 8px;
94
+ --modal-max-width: 400px;
95
+
96
+ /* ── Opacity ── */
97
+ --disabled-opacity: 0.5;
98
+ }