@sobagu/core 0.0.0-stage → 0.1.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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Sobagu contributors
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md CHANGED
@@ -1,3 +1,37 @@
1
- # Temporary Holding Version
1
+ # @sobagu/core
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ The framework-agnostic engine behind Sobagu: design tokens, the `css()` function that turns a style
4
+ object into atomic class names, light and dark themes, recipes and server-side CSS collection.
5
+ It has no dependencies and imports no framework. The React, Vue, Svelte, Solid and Angular packages
6
+ are thin layers on top of it.
7
+
8
+ ## Install
9
+
10
+ ```bash
11
+ npm i @sobagu/core
12
+ ```
13
+
14
+ ## Usage
15
+
16
+ ```ts
17
+ import { css, cx, getCssText } from '@sobagu/core'
18
+
19
+ const card = css({ p: 'md', bg: 'surface', radius: 'lg', hover: { shadow: 'lg' }, md: { p: 'lg' } })
20
+ document.querySelector('#card')!.className = cx(card, 'my-own-class')
21
+
22
+ // The CSS is injected into the page the first time a style is used.
23
+ // During server-side rendering, put the collected CSS in the page head instead:
24
+ const styles = getCssText() // <style>{styles}</style>
25
+ ```
26
+
27
+ ## Docs
28
+
29
+ - [Introduction](https://sobagucss.com/docs) and [installation](https://sobagucss.com/docs/installation)
30
+ - [Style props](https://sobagucss.com/docs/style-props), [states](https://sobagucss.com/docs/states), [responsive design](https://sobagucss.com/docs/responsive)
31
+ - [Theme and tokens](https://sobagucss.com/docs/theme), [all style props](https://sobagucss.com/docs/props)
32
+
33
+ Sobagu is in 0.x: the API can still change between minor versions.
34
+
35
+ ## Licence
36
+
37
+ MIT © 2026 Sobagu contributors
@@ -0,0 +1,16 @@
1
+ export interface ContrastCheck {
2
+ /** e.g. "text on surface" */
3
+ pair: string;
4
+ fg: string;
5
+ bg: string;
6
+ /** WCAG level needed: 4.5 for text, 3 for UI parts (borders of inputs, focus rings) and large text. */
7
+ required: number;
8
+ light: number;
9
+ dark: number;
10
+ pass: boolean;
11
+ }
12
+ /**
13
+ * Check the built-in semantic colours against WCAG 2.2 contrast levels, in light and dark mode.
14
+ * auditContrast().filter(c => !c.pass)
15
+ */
16
+ export declare function auditContrast(): ContrastCheck[];
@@ -0,0 +1,14 @@
1
+ export interface Oklch {
2
+ l: number;
3
+ c: number;
4
+ h: number;
5
+ }
6
+ /** '#7c3aed' or '#7c3' → [r, g, b] in 0..1 */
7
+ export declare function parseHex(hex: string): [number, number, number];
8
+ export declare function rgbToOklch([r, g, b]: [number, number, number]): Oklch;
9
+ export declare function oklchToRgb({ l, c, h }: Oklch): [number, number, number];
10
+ /** WCAG 2 relative luminance of an sRGB colour (0..1 channels). */
11
+ export declare function luminance([r, g, b]: [number, number, number]): number;
12
+ /** WCAG 2 contrast ratio between two colours (1..21). Accepts hex strings or OKLCH objects. */
13
+ export declare function contrastRatio(a: string | Oklch, b: string | Oklch): number;
14
+ export declare const oklchCss: ({ l, c, h }: Oklch) => string;
@@ -0,0 +1,114 @@
1
+ /**
2
+ * How a condition changes the generated rule.
3
+ * - selector: a template where "&" is the element, e.g. "&:hover", ".sb-group:hover &", "&::before"
4
+ * - at: an at-rule wrapper, e.g. "@media (min-width: 840px)", "@container (min-width: 480px)"
5
+ * - dark: dark colour scheme (OS setting or data-theme="dark")
6
+ * The rank orders the cascade: higher ranks are emitted later, so they win.
7
+ */
8
+ export type ConditionDef = {
9
+ kind: 'selector';
10
+ template: string;
11
+ rank: number;
12
+ element?: boolean;
13
+ } | {
14
+ kind: 'at';
15
+ prelude: string;
16
+ group: 'media' | 'container' | 'other';
17
+ rank: number;
18
+ } | {
19
+ kind: 'dark';
20
+ };
21
+ /**
22
+ * Conditions: use them as object props, e.g. hover={{ bg: 'primaryHover' }} or md={{ cols: 2 }}.
23
+ * Names that are also HTML attributes start with "_" (_disabled, _checked, _placeholder, _required, _readOnly)
24
+ * so <Box as="button" disabled _disabled={{ opacity: 0.5 }}> can use both.
25
+ */
26
+ export declare const conditions: {
27
+ first: ConditionDef;
28
+ last: ConditionDef;
29
+ only: ConditionDef;
30
+ odd: ConditionDef;
31
+ even: ConditionDef;
32
+ firstOfType: ConditionDef;
33
+ lastOfType: ConditionDef;
34
+ empty: ConditionDef;
35
+ visited: ConditionDef;
36
+ target: ConditionDef;
37
+ open: ConditionDef;
38
+ _checked: ConditionDef;
39
+ indeterminate: ConditionDef;
40
+ _required: ConditionDef;
41
+ optional: ConditionDef;
42
+ _readOnly: ConditionDef;
43
+ valid: ConditionDef;
44
+ invalid: ConditionDef;
45
+ autofill: ConditionDef;
46
+ placeholderShown: ConditionDef;
47
+ focusWithin: ConditionDef;
48
+ hover: ConditionDef;
49
+ focus: ConditionDef;
50
+ focusVisible: ConditionDef;
51
+ active: ConditionDef;
52
+ _disabled: ConditionDef;
53
+ ariaExpanded: ConditionDef;
54
+ ariaSelected: ConditionDef;
55
+ ariaChecked: ConditionDef;
56
+ ariaPressed: ConditionDef;
57
+ ariaCurrent: ConditionDef;
58
+ ariaInvalid: ConditionDef;
59
+ ariaDisabled: ConditionDef;
60
+ dataOpen: ConditionDef;
61
+ dataClosed: ConditionDef;
62
+ groupHover: ConditionDef;
63
+ groupFocusWithin: ConditionDef;
64
+ groupActive: ConditionDef;
65
+ groupOpen: ConditionDef;
66
+ peerHover: ConditionDef;
67
+ peerFocus: ConditionDef;
68
+ peerChecked: ConditionDef;
69
+ peerInvalid: ConditionDef;
70
+ peerDisabled: ConditionDef;
71
+ rtl: ConditionDef;
72
+ ltr: ConditionDef;
73
+ before: ConditionDef;
74
+ after: ConditionDef;
75
+ _placeholder: ConditionDef;
76
+ selection: ConditionDef;
77
+ marker: ConditionDef;
78
+ file: ConditionDef;
79
+ backdrop: ConditionDef;
80
+ firstLine: ConditionDef;
81
+ firstLetter: ConditionDef;
82
+ mobile: ConditionDef;
83
+ sm: ConditionDef;
84
+ tablet: ConditionDef;
85
+ md: ConditionDef;
86
+ lg: ConditionDef;
87
+ desktop: ConditionDef;
88
+ xl: ConditionDef;
89
+ motionSafe: ConditionDef;
90
+ reduceMotion: ConditionDef;
91
+ contrastMore: ConditionDef;
92
+ forcedColors: ConditionDef;
93
+ touch: ConditionDef;
94
+ mouse: ConditionDef;
95
+ portrait: ConditionDef;
96
+ landscape: ConditionDef;
97
+ print: ConditionDef;
98
+ cqXs: ConditionDef;
99
+ cqSm: ConditionDef;
100
+ cqMd: ConditionDef;
101
+ cqLg: ConditionDef;
102
+ cqXl: ConditionDef;
103
+ starting: ConditionDef;
104
+ dark: {
105
+ kind: "dark";
106
+ };
107
+ };
108
+ export type ConditionName = keyof typeof conditions;
109
+ /** Marker props that add a plain class: <Box group> → "sb-group", <Box as="input" peer> → "sb-peer". */
110
+ export declare const markers: readonly ['group', 'peer'];
111
+ export type MarkerName = (typeof markers)[number];
112
+ /** Raw conditions: '&:has(img)', '& > li', '.theme-x &' (selectors) and '@supports (…)', '@media (…)' (at-rules). */
113
+ export declare const isRawSelector: (k: string) => boolean;
114
+ export declare const isRawAt: (k: string) => boolean;