nitrowind 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.
Files changed (155) hide show
  1. package/CHANGELOG.md +23 -0
  2. package/LICENSE +21 -0
  3. package/README.md +44 -2
  4. package/css.d.ts +6 -0
  5. package/dist/color.d.ts +24 -0
  6. package/dist/color.d.ts.map +1 -0
  7. package/dist/color.js +158 -0
  8. package/dist/color.js.map +1 -0
  9. package/dist/core.d.ts +121 -0
  10. package/dist/core.d.ts.map +1 -0
  11. package/dist/core.js +1026 -0
  12. package/dist/core.js.map +1 -0
  13. package/dist/css/compile.d.ts +18 -0
  14. package/dist/css/compile.d.ts.map +1 -0
  15. package/dist/css/compile.js +1018 -0
  16. package/dist/css/compile.js.map +1 -0
  17. package/dist/css/declarations.d.ts +18 -0
  18. package/dist/css/declarations.d.ts.map +1 -0
  19. package/dist/css/declarations.js +1173 -0
  20. package/dist/css/declarations.js.map +1 -0
  21. package/dist/css/index.d.ts +7 -0
  22. package/dist/css/index.d.ts.map +1 -0
  23. package/dist/css/index.js +7 -0
  24. package/dist/css/index.js.map +1 -0
  25. package/dist/css/parser.d.ts +9 -0
  26. package/dist/css/parser.d.ts.map +1 -0
  27. package/dist/css/parser.js +188 -0
  28. package/dist/css/parser.js.map +1 -0
  29. package/dist/css/tokenizer.d.ts +14 -0
  30. package/dist/css/tokenizer.d.ts.map +1 -0
  31. package/dist/css/tokenizer.js +200 -0
  32. package/dist/css/tokenizer.js.map +1 -0
  33. package/dist/css/types.d.ts +128 -0
  34. package/dist/css/types.d.ts.map +1 -0
  35. package/dist/css/types.js +19 -0
  36. package/dist/css/types.js.map +1 -0
  37. package/dist/css/values.d.ts +37 -0
  38. package/dist/css/values.d.ts.map +1 -0
  39. package/dist/css/values.js +343 -0
  40. package/dist/css/values.js.map +1 -0
  41. package/dist/environment.d.ts +5 -0
  42. package/dist/environment.d.ts.map +1 -0
  43. package/dist/environment.js +99 -0
  44. package/dist/environment.js.map +1 -0
  45. package/dist/hooks.d.ts +22 -0
  46. package/dist/hooks.d.ts.map +1 -0
  47. package/dist/hooks.js +140 -0
  48. package/dist/hooks.js.map +1 -0
  49. package/dist/index.d.ts +26 -0
  50. package/dist/index.d.ts.map +1 -0
  51. package/dist/index.js +16 -0
  52. package/dist/index.js.map +1 -0
  53. package/dist/jsx-dev-runtime.d.ts +17 -0
  54. package/dist/jsx-dev-runtime.d.ts.map +1 -0
  55. package/dist/jsx-dev-runtime.js +12 -0
  56. package/dist/jsx-dev-runtime.js.map +1 -0
  57. package/dist/jsx-namespace.d.ts +29 -0
  58. package/dist/jsx-namespace.d.ts.map +1 -0
  59. package/dist/jsx-namespace.js +2 -0
  60. package/dist/jsx-namespace.js.map +1 -0
  61. package/dist/jsx-runtime.d.ts +22 -0
  62. package/dist/jsx-runtime.d.ts.map +1 -0
  63. package/dist/jsx-runtime.js +21 -0
  64. package/dist/jsx-runtime.js.map +1 -0
  65. package/dist/math.d.ts +50 -0
  66. package/dist/math.d.ts.map +1 -0
  67. package/dist/math.js +442 -0
  68. package/dist/math.js.map +1 -0
  69. package/dist/plugin.d.ts +45 -0
  70. package/dist/plugin.d.ts.map +1 -0
  71. package/dist/plugin.js +172 -0
  72. package/dist/plugin.js.map +1 -0
  73. package/dist/props.d.ts +29 -0
  74. package/dist/props.d.ts.map +1 -0
  75. package/dist/props.js +163 -0
  76. package/dist/props.js.map +1 -0
  77. package/dist/scope.d.ts +99 -0
  78. package/dist/scope.d.ts.map +1 -0
  79. package/dist/scope.js +228 -0
  80. package/dist/scope.js.map +1 -0
  81. package/dist/store.d.ts +18 -0
  82. package/dist/store.d.ts.map +1 -0
  83. package/dist/store.js +244 -0
  84. package/dist/store.js.map +1 -0
  85. package/dist/tokens/index.d.ts +12 -0
  86. package/dist/tokens/index.d.ts.map +1 -0
  87. package/dist/tokens/index.js +237 -0
  88. package/dist/tokens/index.js.map +1 -0
  89. package/dist/tokens/tailwind.generated.d.ts +3 -0
  90. package/dist/tokens/tailwind.generated.d.ts.map +1 -0
  91. package/dist/tokens/tailwind.generated.js +610 -0
  92. package/dist/tokens/tailwind.generated.js.map +1 -0
  93. package/dist/tokens/types.d.ts +95 -0
  94. package/dist/tokens/types.d.ts.map +1 -0
  95. package/dist/tokens/types.js +2 -0
  96. package/dist/tokens/types.js.map +1 -0
  97. package/dist/transform.d.ts +22 -0
  98. package/dist/transform.d.ts.map +1 -0
  99. package/dist/transform.js +79 -0
  100. package/dist/transform.js.map +1 -0
  101. package/dist/transition.d.ts +7 -0
  102. package/dist/transition.d.ts.map +1 -0
  103. package/dist/transition.js +355 -0
  104. package/dist/transition.js.map +1 -0
  105. package/dist/types.d.ts +214 -0
  106. package/dist/types.d.ts.map +1 -0
  107. package/dist/types.js +2 -0
  108. package/dist/types.js.map +1 -0
  109. package/dist/utilities.d.ts +109 -0
  110. package/dist/utilities.d.ts.map +1 -0
  111. package/dist/utilities.js +2000 -0
  112. package/dist/utilities.js.map +1 -0
  113. package/dist/variables.d.ts +65 -0
  114. package/dist/variables.d.ts.map +1 -0
  115. package/dist/variables.js +408 -0
  116. package/dist/variables.js.map +1 -0
  117. package/dist/version.d.ts +3 -0
  118. package/dist/version.d.ts.map +1 -0
  119. package/dist/version.js +3 -0
  120. package/dist/version.js.map +1 -0
  121. package/dist/withNitroWind.d.ts +11 -0
  122. package/dist/withNitroWind.d.ts.map +1 -0
  123. package/dist/withNitroWind.js +27 -0
  124. package/dist/withNitroWind.js.map +1 -0
  125. package/package.json +89 -4
  126. package/src/color.ts +164 -0
  127. package/src/core.ts +1248 -0
  128. package/src/css/compile.ts +1198 -0
  129. package/src/css/declarations.ts +1141 -0
  130. package/src/css/index.ts +22 -0
  131. package/src/css/parser.ts +196 -0
  132. package/src/css/tokenizer.ts +227 -0
  133. package/src/css/types.ts +178 -0
  134. package/src/css/values.ts +330 -0
  135. package/src/environment.ts +112 -0
  136. package/src/hooks.ts +190 -0
  137. package/src/index.ts +61 -0
  138. package/src/jsx-dev-runtime.ts +43 -0
  139. package/src/jsx-namespace.ts +23 -0
  140. package/src/jsx-runtime.ts +39 -0
  141. package/src/math.ts +488 -0
  142. package/src/plugin.ts +230 -0
  143. package/src/props.ts +173 -0
  144. package/src/scope.ts +331 -0
  145. package/src/store.ts +288 -0
  146. package/src/tokens/index.ts +252 -0
  147. package/src/tokens/tailwind.generated.ts +613 -0
  148. package/src/tokens/types.ts +99 -0
  149. package/src/transform.ts +115 -0
  150. package/src/transition.ts +414 -0
  151. package/src/types.ts +248 -0
  152. package/src/utilities.ts +1992 -0
  153. package/src/variables.ts +509 -0
  154. package/src/version.ts +2 -0
  155. package/src/withNitroWind.ts +36 -0
package/src/types.ts ADDED
@@ -0,0 +1,248 @@
1
+ import type { EdgeInsets, ImageStyleProps, LayoutLength, StyleProps, TextProps, ViewProps } from 'nitro-ui-renderer'
2
+
3
+ export type { EdgeInsets, LayoutLength }
4
+
5
+ /** NitroUI's `layout` prop. */
6
+ export type LayoutProps = NonNullable<ViewProps['layout']>
7
+
8
+ /** NitroUI's `style` prop, including the `View`-only and `Image`-only keys. */
9
+ export type StyleOutput = StyleProps & Pick<ImageStyleProps, 'tintColor' | 'filter'>
10
+
11
+ /** Typography props that live directly on NitroUI's `Text`. */
12
+ export type TextOutput = Pick<
13
+ TextProps,
14
+ 'color' | 'fontSize' | 'fontWeight' | 'lineHeight' | 'textAlign' | 'numberOfLines' | 'ellipsizeMode'
15
+ >
16
+
17
+ /** What a class string compiles to. Empty groups are omitted. */
18
+ export interface ResolvedClasses {
19
+ layout?: LayoutProps
20
+ style?: StyleOutput
21
+ text?: TextOutput
22
+ }
23
+
24
+ /** Describes how a `*ClassName` prop maps its compiled classes onto target component props. */
25
+ export interface ClassNameTargetMap {
26
+ /** Target prop name to receive `resolved.layout` (shallow-merged, explicit wins). */
27
+ readonly layout?: string
28
+ /** Target prop name to receive `resolved.style` (shallow-merged, explicit wins). */
29
+ readonly style?: string
30
+ /** When true, `resolved.text` properties are spread onto top-level props (explicit wins). */
31
+ readonly text?: boolean
32
+ /** Target prop name to receive `Partial<EdgeInsets>` extracted from padding utilities (shallow-merged, explicit wins). */
33
+ readonly edgeInsets?: string
34
+ }
35
+
36
+ /** Custom mapper function that turns compiled classes into props to merge onto the wrapped component. */
37
+ export type ClassNamePropMapper = (resolved: ResolvedClasses) => Record<string, unknown>
38
+
39
+ /**
40
+ * Target for a `*ClassName` prop in `withNitroWind(Component, propMapping)`:
41
+ * - `'layout'` or `'style'`: merges the matching group into that prop.
42
+ * - Any other string: merges `{ ...resolved.layout, ...resolved.style }` into that target prop.
43
+ * - `ClassNameTargetMap`: maps `layout`, `style`, `text`, and/or `edgeInsets` to explicit prop names.
44
+ * - `ClassNamePropMapper`: custom function returning props to merge (explicit props win).
45
+ */
46
+ export type PropMappingTarget = string | ClassNameTargetMap | ClassNamePropMapper
47
+
48
+ /** Maps `*ClassName` prop names to their target prop specifications. */
49
+ export type PropMapping = Readonly<Record<string, PropMappingTarget>>
50
+
51
+ /** Props of a component wrapped with `withNitroWind(Component, propMapping)`. */
52
+ export type WithNitroWindProps<P, K extends string = never> = P & {
53
+ /** Tailwind classes, compiled by NitroWind into `layout` and `style` props. */
54
+ className?: string
55
+ } & Partial<Record<K, string>>
56
+
57
+ export type ColorScheme = 'light' | 'dark'
58
+ export type Platform = 'ios' | 'android'
59
+
60
+ /**
61
+ * Augment this interface via module declaration merging to type custom theme names:
62
+ * ```ts
63
+ * declare module 'nitrowind' {
64
+ * interface NitroWindThemes {
65
+ * premium: true
66
+ * ocean: true
67
+ * }
68
+ * }
69
+ * ```
70
+ */
71
+ // biome-ignore lint/suspicious/noEmptyInterface: users augment it through declaration merging.
72
+ export interface NitroWindThemes {}
73
+
74
+ export type BuiltInThemeName = 'light' | 'dark'
75
+ export type ThemeName = BuiltInThemeName | (keyof NitroWindThemes & string)
76
+ export type ThemePreference = ThemeName | 'system'
77
+
78
+ /**
79
+ * Augment this interface via module declaration merging to type custom CSS variable names:
80
+ * ```ts
81
+ * declare module 'nitrowind' {
82
+ * interface NitroWindVariables {
83
+ * '--brand': string
84
+ * '--radius-card': number | string
85
+ * }
86
+ * }
87
+ * ```
88
+ */
89
+ // biome-ignore lint/suspicious/noEmptyInterface: users augment it through declaration merging.
90
+ export interface NitroWindVariables {}
91
+
92
+ export type CSSVariableValue = string | number
93
+ export type CSSVariableName = (keyof NitroWindVariables & `--${string}`) | (`--${string}` & {})
94
+ export type CSSVariables = {
95
+ [K in keyof NitroWindVariables]?: CSSVariableValue
96
+ } & {
97
+ [K: `--${string}`]: CSSVariableValue | undefined
98
+ }
99
+
100
+ /** Options for `updateCSSVariables(variables, options)`. */
101
+ export interface UpdateCSSVariablesOptions {
102
+ /** Theme to update. Omit to update the shared layer. */
103
+ readonly theme?: ThemeName
104
+ }
105
+
106
+ /** Registration options for a named theme. */
107
+ export interface ThemeDefinition {
108
+ readonly colorScheme: ColorScheme
109
+ readonly variables?: Readonly<CSSVariables>
110
+ }
111
+
112
+ /** Snapshot of the active theme, its color scheme, and the configured preference. */
113
+ export interface ThemeState {
114
+ readonly theme: ThemeName
115
+ readonly colorScheme: ColorScheme
116
+ readonly preference: ThemePreference
117
+ }
118
+
119
+ /** The environment that variants such as `dark:`, `ios:`, `<theme>:`, `md:`, `portrait:` and `motion-reduce:` are matched against. */
120
+ export interface ResolveContext {
121
+ theme?: ThemeName | (string & {})
122
+ colorScheme?: ColorScheme
123
+ platform?: Platform
124
+ reducedMotion?: boolean
125
+ viewport?: ViewportSize
126
+ /** The merged variables of the enclosing variable scopes inside the nearest `ScopedTheme`. They win over the theme's and the shared layer's values. */
127
+ variables?: Readonly<CSSVariables>
128
+ /**
129
+ * The merged variables of variable scopes outside the nearest `ScopedTheme`.
130
+ * The theme's own values win over these; variables not declared by the theme inherit from here
131
+ * before falling back to the shared layer.
132
+ */
133
+ outerVariables?: Readonly<CSSVariables>
134
+ }
135
+
136
+ /** What to do with a class NitroWind can't map onto NitroUI. */
137
+ export type UnknownClassBehavior = 'warn' | 'ignore' | 'throw'
138
+
139
+ /** Which context channels a class string depends on. */
140
+ export interface ClassDependencies {
141
+ readonly colorScheme: boolean
142
+ readonly themes: readonly string[]
143
+ readonly reducedMotion: boolean
144
+ /** Sorted unique breakpoint widths (in points) tested by this class string. */
145
+ readonly breakpoints: readonly number[]
146
+ /** Sorted unique CSS variable names read by this class string. */
147
+ readonly variables: readonly string[]
148
+ readonly orientation: boolean
149
+ /** True when the class string uses viewport-relative units (`vw`/`vh`) or `*-screen` sizing. */
150
+ readonly viewport: boolean
151
+ }
152
+
153
+ export interface ViewportSize {
154
+ readonly width: number
155
+ readonly height: number
156
+ }
157
+
158
+ export type Unsubscribe = () => void
159
+
160
+ export type ThemeTransitionStyle = 'fade' | 'circle' | 'slide' | 'blur'
161
+ export type ThemeTransitionDirection = 'left' | 'right'
162
+ /** Transition values accepted by `setTheme` and `configure({ transition })`. */
163
+ export type ThemeTransition = ThemeTransitionStyle | false
164
+
165
+ /** A point in root-view coordinates (points on iOS, dp on Android). */
166
+ export interface ThemeTransitionPoint {
167
+ readonly x: number
168
+ readonly y: number
169
+ }
170
+
171
+ /** A NitroUI `View` (or any object exposing `getFrameInWindow`) whose center is used as a transition origin. */
172
+ export interface ThemeTransitionOriginView {
173
+ getFrameInWindow(): {
174
+ readonly x: number
175
+ readonly y: number
176
+ readonly width: number
177
+ readonly height: number
178
+ }
179
+ }
180
+
181
+ /** Origin for a `'circle'` theme transition: a point in root-view points, or a NitroUI `View`. */
182
+ export type ThemeTransitionOrigin = ThemeTransitionPoint | ThemeTransitionOriginView
183
+
184
+ /** Default transition settings for `configure({ transition })`. */
185
+ export interface ThemeTransitionConfig {
186
+ /** Default transition style. Defaults to `false` (no animation). */
187
+ readonly style?: ThemeTransition
188
+ /** Default transition duration in milliseconds. Defaults to `400`. */
189
+ readonly duration?: number
190
+ }
191
+
192
+ /** Per-call options for `setTheme(preference, options)`. */
193
+ export interface SetThemeOptions {
194
+ /** Override the configured transition style (`'fade' | 'circle' | 'slide' | 'blur'` or `false` for instant). */
195
+ readonly transition?: ThemeTransition
196
+ /** Override the configured transition duration in milliseconds. */
197
+ readonly duration?: number
198
+ /** Starting point for `'circle'` transitions: a root-view point or a NitroUI `View` (uses its center). */
199
+ readonly origin?: ThemeTransitionOrigin
200
+ /** Slide direction for `'slide'` transitions (`'left'` or `'right'`). Defaults to `'left'`. */
201
+ readonly direction?: ThemeTransitionDirection
202
+ }
203
+
204
+ export interface CaptureCoverOptions {
205
+ readonly style: ThemeTransitionStyle
206
+ readonly duration: number
207
+ readonly origin?: ThemeTransitionPoint
208
+ readonly direction?: ThemeTransitionDirection
209
+ }
210
+
211
+ /** Optional native capabilities provided by `nitrowind-native`. */
212
+ export interface NitroWindNative {
213
+ /** Package version of `nitrowind-native`, checked against `nitrowind` in development. */
214
+ readonly version: string
215
+ /** Whether the user has enabled "reduce motion" in OS settings. */
216
+ getReducedMotion(): boolean
217
+ /** Subscribes to changes in the OS "reduce motion" setting. */
218
+ subscribeReducedMotion(listener: (reducedMotion: boolean) => void): Unsubscribe
219
+ /** Captures the current screen into a native cover overlay before a theme switch. */
220
+ captureCover?(options: CaptureCoverOptions): boolean | Promise<boolean>
221
+ /** Animates the native cover overlay away and removes it. */
222
+ finishCover?(): Promise<void>
223
+ /** Immediately removes any active native cover overlay. */
224
+ cancelCover?(): void
225
+ /** Reports whether a native cover overlay is currently on screen. */
226
+ isCoverActive?(): boolean
227
+ }
228
+
229
+ /** Platform and runtime signals injected into a NitroWind instance. */
230
+ export interface NitroWindEnvironment {
231
+ readonly platform: Platform
232
+ getColorScheme(): ColorScheme
233
+ setColorScheme(colorScheme: ColorScheme | 'auto'): void
234
+ subscribeColorScheme(listener: (colorScheme: ColorScheme) => void): Unsubscribe
235
+ getViewportSize(): ViewportSize | undefined
236
+ subscribeViewportSize(listener: (size: ViewportSize) => void): Unsubscribe
237
+ /** Optional React hook called by the render wrapper to bind to the host root view controller. */
238
+ readonly useRoot?: () => void
239
+ /** Optional frame scheduler used to wait for commit + paint before animating a cover away. */
240
+ readonly scheduleFrame?: (callback: () => void) => Unsubscribe
241
+ /**
242
+ * Optional safety timeout (ms) before a stuck transition cover is removed automatically. Defaults to `1000`.
243
+ * It applies to each step: the capture, the re-render and scheme change, and the first frame in the new theme.
244
+ * The finish animation gets its duration plus this timeout.
245
+ */
246
+ readonly transitionTimeoutMs?: number
247
+ readonly native?: NitroWindNative
248
+ }