@hzblj/kara-sx 0.0.0-stage → 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.
Files changed (79) hide show
  1. package/README.md +7 -2
  2. package/lib/module/flatten-sx.js +59 -0
  3. package/lib/module/flatten-sx.js.map +1 -0
  4. package/lib/module/index.js +19 -0
  5. package/lib/module/index.js.map +1 -0
  6. package/lib/module/package.json +1 -0
  7. package/lib/module/resolve-cache.js +79 -0
  8. package/lib/module/resolve-cache.js.map +1 -0
  9. package/lib/module/responsive-sx.js +66 -0
  10. package/lib/module/responsive-sx.js.map +1 -0
  11. package/lib/module/responsive.types.js +4 -0
  12. package/lib/module/responsive.types.js.map +1 -0
  13. package/lib/module/sx-key.js +25 -0
  14. package/lib/module/sx-key.js.map +1 -0
  15. package/lib/module/sx-keys.js +46 -0
  16. package/lib/module/sx-keys.js.map +1 -0
  17. package/lib/module/sx-padding.js +26 -0
  18. package/lib/module/sx-padding.js.map +1 -0
  19. package/lib/module/sx-to-modifiers.android.js +168 -0
  20. package/lib/module/sx-to-modifiers.android.js.map +1 -0
  21. package/lib/module/sx-to-modifiers.ios.js +266 -0
  22. package/lib/module/sx-to-modifiers.ios.js.map +1 -0
  23. package/lib/module/sx-to-style.js +137 -0
  24. package/lib/module/sx-to-style.js.map +1 -0
  25. package/lib/module/sx.types.js +4 -0
  26. package/lib/module/sx.types.js.map +1 -0
  27. package/lib/module/use-sx-modifiers.android.js +30 -0
  28. package/lib/module/use-sx-modifiers.android.js.map +1 -0
  29. package/lib/module/use-sx-modifiers.ios.js +30 -0
  30. package/lib/module/use-sx-modifiers.ios.js.map +1 -0
  31. package/lib/module/use-sx.js +30 -0
  32. package/lib/module/use-sx.js.map +1 -0
  33. package/lib/module/value-key.js +16 -0
  34. package/lib/module/value-key.js.map +1 -0
  35. package/lib/module/view-sx-to-style.js +159 -0
  36. package/lib/module/view-sx-to-style.js.map +1 -0
  37. package/lib/module/view-sx.types.js +4 -0
  38. package/lib/module/view-sx.types.js.map +1 -0
  39. package/lib/module/with-sx.js +50 -0
  40. package/lib/module/with-sx.js.map +1 -0
  41. package/lib/typescript/flatten-sx.d.ts +15 -0
  42. package/lib/typescript/index.d.ts +16 -0
  43. package/lib/typescript/resolve-cache.d.ts +14 -0
  44. package/lib/typescript/responsive-sx.d.ts +80 -0
  45. package/lib/typescript/responsive.types.d.ts +23 -0
  46. package/lib/typescript/sx-key.d.ts +7 -0
  47. package/lib/typescript/sx-keys.d.ts +6 -0
  48. package/lib/typescript/sx-padding.d.ts +5 -0
  49. package/lib/typescript/sx-to-modifiers.d.ts +1 -0
  50. package/lib/typescript/sx-to-modifiers.ios.d.ts +4 -0
  51. package/lib/typescript/sx-to-style.d.ts +4 -0
  52. package/lib/typescript/sx.types.d.ts +182 -0
  53. package/lib/typescript/use-sx-modifiers.d.ts +1 -0
  54. package/lib/typescript/use-sx-modifiers.ios.d.ts +14 -0
  55. package/lib/typescript/use-sx.d.ts +15 -0
  56. package/lib/typescript/value-key.d.ts +7 -0
  57. package/lib/typescript/view-sx-to-style.d.ts +17 -0
  58. package/lib/typescript/view-sx.types.d.ts +80 -0
  59. package/lib/typescript/with-sx.d.ts +28 -0
  60. package/package.json +78 -4
  61. package/src/flatten-sx.ts +70 -0
  62. package/src/index.ts +16 -0
  63. package/src/resolve-cache.ts +105 -0
  64. package/src/responsive-sx.ts +75 -0
  65. package/src/responsive.types.ts +23 -0
  66. package/src/sx-key.ts +32 -0
  67. package/src/sx-keys.ts +47 -0
  68. package/src/sx-padding.ts +27 -0
  69. package/src/sx-to-modifiers.android.ts +224 -0
  70. package/src/sx-to-modifiers.ios.ts +322 -0
  71. package/src/sx-to-style.ts +142 -0
  72. package/src/sx.types.ts +215 -0
  73. package/src/use-sx-modifiers.android.ts +29 -0
  74. package/src/use-sx-modifiers.ios.ts +29 -0
  75. package/src/use-sx.ts +34 -0
  76. package/src/value-key.ts +18 -0
  77. package/src/view-sx-to-style.ts +180 -0
  78. package/src/view-sx.types.ts +87 -0
  79. package/src/with-sx.tsx +51 -0
@@ -0,0 +1,266 @@
1
+ "use strict";
2
+
3
+ import { aspectRatio, background, blur, brightness, clipped, clipShape, colorInvert, containerRelativeFrame, contentTransition, contrast, controlSize, fixedSize, frame, glassEffect, grayscale, hidden, hueRotation, ignoreSafeArea, layoutPriority, luminanceToAlpha, offset, opacity as opacityModifier, padding, privacySensitive, redacted, rotationEffect, saturation, scaleEffect, shadow, strokeBorder, tint, unredacted, zIndex as zIndexModifier } from '@expo/ui/swift-ui/modifiers';
4
+ import { opacity, radii, resolvePaletteColor, resolveShadow, zIndex } from '@hzblj/kara-theme';
5
+ import { sxPadding } from "./sx-padding.js";
6
+
7
+ /**
8
+ * The one shape every decoration traces — clip, strokes, drop shadow and glass all take it, so the
9
+ * box reads as a single surface. The `full` radius token maps to a real capsule: SwiftUI's
10
+ * `RoundedRectangle` degenerates when the radius outgrows the box, where `Capsule` stays clean.
11
+ */
12
+
13
+ const boxShape = sx => {
14
+ if (sx.borderRadius === 'full') {
15
+ return {
16
+ shape: 'capsule'
17
+ };
18
+ }
19
+ return sx.borderRadius ? {
20
+ cornerRadius: radii[sx.borderRadius],
21
+ shape: 'roundedRectangle'
22
+ } : {
23
+ shape: 'rectangle'
24
+ };
25
+ };
26
+
27
+ /**
28
+ * A stroke that traces the box's own shape. `.border` always draws a square, so on a rounded box the
29
+ * following `.clipShape` cuts its corners off — `strokeBorder` follows the shape and stays inside.
30
+ */
31
+ const outline = (color, width, box) => strokeBorder({
32
+ color,
33
+ cornerRadius: box.cornerRadius,
34
+ shape: box.shape,
35
+ style: {
36
+ lineWidth: width
37
+ }
38
+ });
39
+
40
+ /**
41
+ * `inset` is Android-only: SwiftUI has no inner-shadow modifier, and standing in with `.glassEffect`
42
+ * paints a whole Liquid Glass material over the box — a washed-out plate, not a shadow.
43
+ */
44
+ const shadowModifiers = (sx, theme, box) => {
45
+ if (!sx.shadow) {
46
+ return [];
47
+ }
48
+ const {
49
+ colors,
50
+ geometry
51
+ } = resolveShadow(theme, sx.shadow);
52
+ const modifiers = [];
53
+ if (geometry.ring && colors.ring) {
54
+ modifiers.push(outline(resolvePaletteColor(theme, colors.ring), geometry.ring.width, box));
55
+ }
56
+ if (geometry.drop && colors.drop) {
57
+ modifiers.push(shadow({
58
+ color: resolvePaletteColor(theme, colors.drop),
59
+ radius: geometry.drop.radius,
60
+ y: geometry.drop.y
61
+ }));
62
+ }
63
+ return modifiers;
64
+ };
65
+
66
+ /**
67
+ * The native `FrameModifier` applies either the exact `width`/`height` pair or the min/max set —
68
+ * never both, so one call mixing them would silently drop its min/max half. Each set therefore gets
69
+ * its own `frame`: the exact one first, then the flexible one for the axes left free.
70
+ */
71
+ const frameModifiers = (sx, alignment) => {
72
+ const modifiers = [];
73
+ if (sx.w !== undefined || sx.h !== undefined) {
74
+ modifiers.push(frame({
75
+ alignment,
76
+ height: sx.h,
77
+ width: sx.w
78
+ }));
79
+ }
80
+ if (sx.wide || sx.tall || sx.minW !== undefined || sx.minH !== undefined) {
81
+ modifiers.push(frame({
82
+ alignment,
83
+ maxHeight: sx.tall ? Infinity : undefined,
84
+ maxWidth: sx.wide ? Infinity : undefined,
85
+ minHeight: sx.minH,
86
+ minWidth: sx.minW
87
+ }));
88
+ }
89
+ return modifiers;
90
+ };
91
+
92
+ /** Transforms and filters, which SwiftUI applies to the box after it has been laid out and painted. */
93
+ const effectModifiers = sx => {
94
+ const modifiers = [];
95
+ if (sx.offsetX !== undefined || sx.offsetY !== undefined) {
96
+ modifiers.push(offset({
97
+ x: sx.offsetX,
98
+ y: sx.offsetY
99
+ }));
100
+ }
101
+ if (sx.rotate !== undefined) {
102
+ modifiers.push(rotationEffect(sx.rotate));
103
+ }
104
+ if (sx.scale !== undefined) {
105
+ modifiers.push(scaleEffect(typeof sx.scale === 'number' ? sx.scale : {
106
+ x: sx.scale.x ?? 1,
107
+ y: sx.scale.y ?? 1
108
+ }));
109
+ }
110
+ if (sx.blur !== undefined) {
111
+ modifiers.push(blur(sx.blur));
112
+ }
113
+ if (sx.opacity) {
114
+ modifiers.push(opacityModifier(opacity[sx.opacity]));
115
+ }
116
+ if (sx.zIndex) {
117
+ modifiers.push(zIndexModifier(zIndex[sx.zIndex]));
118
+ }
119
+ return modifiers;
120
+ };
121
+ const FIXED_SIZE_AXES = {
122
+ both: {
123
+ horizontal: true,
124
+ vertical: true
125
+ },
126
+ horizontal: {
127
+ horizontal: true
128
+ },
129
+ vertical: {
130
+ vertical: true
131
+ }
132
+ };
133
+
134
+ /**
135
+ * Liquid Glass from either form of the `glass` key. With no shape of its own, the glass follows the
136
+ * box's `borderRadius` — a plate that ignored the box's corners would read as a different surface.
137
+ */
138
+ const glassModifier = (glass, theme, box) => {
139
+ const config = typeof glass === 'string' ? {
140
+ variant: glass
141
+ } : glass;
142
+ const followsBox = config.shape === undefined && box.shape !== 'rectangle';
143
+ return glassEffect({
144
+ cornerRadius: config.cornerRadius ?? (followsBox ? box.cornerRadius : undefined),
145
+ glass: {
146
+ interactive: config.interactive,
147
+ tint: config.tint === undefined ? undefined : theme.color(config.tint),
148
+ variant: config.variant
149
+ },
150
+ shape: followsBox ? box.shape : config.shape
151
+ });
152
+ };
153
+
154
+ /** The `ios` bucket: SwiftUI-only modifiers, which the Compose resolver has no counterpart for. */
155
+ const iosModifiers = (ios, theme, box) => {
156
+ if (!ios) {
157
+ return [];
158
+ }
159
+ const modifiers = [];
160
+ if (ios.aspectRatio !== undefined) {
161
+ modifiers.push(aspectRatio({
162
+ contentMode: 'fit',
163
+ ratio: ios.aspectRatio
164
+ }));
165
+ }
166
+
167
+ // The ideal sizes live in the native frame modifier's min/max branch, so they need their own
168
+ // `frame` call — one with an exact width or height would never reach them.
169
+ if (ios.idealW !== undefined || ios.idealH !== undefined) {
170
+ modifiers.push(frame({
171
+ idealHeight: ios.idealH,
172
+ idealWidth: ios.idealW
173
+ }));
174
+ }
175
+ if (ios.containerRelativeFrame) {
176
+ modifiers.push(containerRelativeFrame(ios.containerRelativeFrame));
177
+ }
178
+ if (ios.ignoreSafeArea) {
179
+ modifiers.push(ignoreSafeArea(ios.ignoreSafeArea === true ? undefined : ios.ignoreSafeArea));
180
+ }
181
+ if (ios.glass) {
182
+ modifiers.push(glassModifier(ios.glass, theme, box));
183
+ }
184
+ if (ios.tint) {
185
+ modifiers.push(tint(theme.color(ios.tint)));
186
+ }
187
+ if (ios.controlSize) {
188
+ modifiers.push(controlSize(ios.controlSize));
189
+ }
190
+ if (ios.layoutPriority !== undefined) {
191
+ modifiers.push(layoutPriority(ios.layoutPriority));
192
+ }
193
+ if (ios.fixedSize) {
194
+ modifiers.push(fixedSize(FIXED_SIZE_AXES[ios.fixedSize]));
195
+ }
196
+ if (ios.clipped) {
197
+ modifiers.push(clipped(true));
198
+ }
199
+ if (ios.hidden) {
200
+ modifiers.push(hidden(true));
201
+ }
202
+ if (ios.redacted) {
203
+ modifiers.push(redacted(ios.redacted));
204
+ }
205
+ if (ios.unredacted) {
206
+ modifiers.push(unredacted());
207
+ }
208
+ if (ios.privacySensitive) {
209
+ modifiers.push(privacySensitive(true));
210
+ }
211
+ if (ios.saturation !== undefined) {
212
+ modifiers.push(saturation(ios.saturation));
213
+ }
214
+ if (ios.brightness !== undefined) {
215
+ modifiers.push(brightness(ios.brightness));
216
+ }
217
+ if (ios.contrast !== undefined) {
218
+ modifiers.push(contrast(ios.contrast));
219
+ }
220
+ if (ios.grayscale !== undefined) {
221
+ modifiers.push(grayscale(ios.grayscale));
222
+ }
223
+ if (ios.hueRotation !== undefined) {
224
+ modifiers.push(hueRotation(ios.hueRotation));
225
+ }
226
+ if (ios.colorInvert) {
227
+ modifiers.push(colorInvert(true));
228
+ }
229
+ if (ios.luminanceToAlpha) {
230
+ modifiers.push(luminanceToAlpha());
231
+ }
232
+ if (ios.contentTransition) {
233
+ modifiers.push(contentTransition(ios.contentTransition.type, {
234
+ countsDown: ios.contentTransition.countsDown
235
+ }));
236
+ }
237
+ if (ios.modifiers) {
238
+ modifiers.push(...ios.modifiers);
239
+ }
240
+ return modifiers;
241
+ };
242
+ export const sxToModifiers = (sx, theme, alignment = 'topLeading') => {
243
+ const modifiers = [];
244
+ const boxPadding = sxPadding(sx);
245
+ const box = boxShape(sx);
246
+ if (boxPadding) {
247
+ modifiers.push(padding(boxPadding));
248
+ }
249
+ modifiers.push(...frameModifiers(sx, alignment));
250
+ if (sx.bg) {
251
+ modifiers.push(background(theme.color(sx.bg)));
252
+ }
253
+
254
+ // Clip before the strokes and the drop shadow, so all three trace the rounded box, not its bounds.
255
+ if (box.shape !== 'rectangle') {
256
+ modifiers.push(clipShape(box.shape, box.cornerRadius));
257
+ }
258
+ if (sx.borderWidth !== undefined && sx.borderColor) {
259
+ modifiers.push(outline(theme.color(sx.borderColor), sx.borderWidth, box));
260
+ }
261
+ modifiers.push(...shadowModifiers(sx, theme, box));
262
+ modifiers.push(...effectModifiers(sx));
263
+ modifiers.push(...iosModifiers(sx.ios, theme, box));
264
+ return modifiers;
265
+ };
266
+ //# sourceMappingURL=sx-to-modifiers.ios.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["aspectRatio","background","blur","brightness","clipped","clipShape","colorInvert","containerRelativeFrame","contentTransition","contrast","controlSize","fixedSize","frame","glassEffect","grayscale","hidden","hueRotation","ignoreSafeArea","layoutPriority","luminanceToAlpha","offset","opacity","opacityModifier","padding","privacySensitive","redacted","rotationEffect","saturation","scaleEffect","shadow","strokeBorder","tint","unredacted","zIndex","zIndexModifier","radii","resolvePaletteColor","resolveShadow","sxPadding","boxShape","sx","borderRadius","shape","cornerRadius","outline","color","width","box","style","lineWidth","shadowModifiers","theme","colors","geometry","modifiers","ring","push","drop","radius","y","frameModifiers","alignment","w","undefined","h","height","wide","tall","minW","minH","maxHeight","Infinity","maxWidth","minHeight","minWidth","effectModifiers","offsetX","offsetY","x","rotate","scale","FIXED_SIZE_AXES","both","horizontal","vertical","glassModifier","glass","config","variant","followsBox","interactive","iosModifiers","ios","contentMode","ratio","idealW","idealH","idealHeight","idealWidth","type","countsDown","sxToModifiers","boxPadding","bg","borderWidth","borderColor"],"sourceRoot":"../../src","sources":["sx-to-modifiers.ios.ts"],"mappings":";;AAAA,SACEA,WAAW,EACXC,UAAU,EACVC,IAAI,EACJC,UAAU,EACVC,OAAO,EACPC,SAAS,EACTC,WAAW,EACXC,sBAAsB,EACtBC,iBAAiB,EACjBC,QAAQ,EACRC,WAAW,EACXC,SAAS,EACTC,KAAK,EACLC,WAAW,EACXC,SAAS,EACTC,MAAM,EACNC,WAAW,EACXC,cAAc,EACdC,cAAc,EACdC,gBAAgB,EAEhBC,MAAM,EACNC,OAAO,IAAIC,eAAe,EAC1BC,OAAO,EACPC,gBAAgB,EAChBC,QAAQ,EACRC,cAAc,EACdC,UAAU,EACVC,WAAW,EACXC,MAAM,EACNC,YAAY,EACZC,IAAI,EACJC,UAAU,EACVC,MAAM,IAAIC,cAAc,QACnB,6BAA6B;AACpC,SAAQb,OAAO,EAAEc,KAAK,EAAEC,mBAAmB,EAAEC,aAAa,EAAcJ,MAAM,QAAO,mBAAmB;AAGxG,SAAQK,SAAS,QAAO,iBAAc;;AAEtC;AACA;AACA;AACA;AACA;;AAMA,MAAMC,QAAQ,GAAIC,EAAM,IAAe;EACrC,IAAIA,EAAE,CAACC,YAAY,KAAK,MAAM,EAAE;IAC9B,OAAO;MAACC,KAAK,EAAE;IAAS,CAAC;EAC3B;EAEA,OAAOF,EAAE,CAACC,YAAY,GAAG;IAACE,YAAY,EAAER,KAAK,CAACK,EAAE,CAACC,YAAY,CAAC;IAAEC,KAAK,EAAE;EAAkB,CAAC,GAAG;IAACA,KAAK,EAAE;EAAW,CAAC;AACnH,CAAC;;AAED;AACA;AACA;AACA;AACA,MAAME,OAAO,GAAGA,CAACC,KAAiB,EAAEC,KAAa,EAAEC,GAAa,KAC9DjB,YAAY,CAAC;EACXe,KAAK;EACLF,YAAY,EAAEI,GAAG,CAACJ,YAAY;EAC9BD,KAAK,EAAEK,GAAG,CAACL,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AGmB,eAAe,CAACnC,EAAE,CAAC,CAAC;EACtCc,SAAS,CAACE,IAAI,CAAC,GAAGmC,YAAY,CAACnD,EAAE,CAACoD,GAAG,EAAEzC,KAAK,EAAEJ,GAAG,CAAC,CAAC;EAEnD,OAAOO,SAAS;AAClB,CAAC","ignoreList":[]}
@@ -0,0 +1,137 @@
1
+ "use strict";
2
+
3
+ import { opacity, radii, resolvePaletteColor, resolveShadow, zIndex } from '@hzblj/kara-theme';
4
+ import { StyleSheet } from 'react-native';
5
+ import { sxPadding } from "./sx-padding.js";
6
+
7
+ /**
8
+ * React Native takes transforms as one ordered array, so — unlike the modifier paths, where each is
9
+ * its own entry — they have to be collected before any of them can be written to the style.
10
+ */
11
+ /** React Native also accepts `transform` as a CSS string; `Extract` keeps the array form's element. */
12
+
13
+ const transform = sx => {
14
+ const transforms = [];
15
+ if (sx.offsetX !== undefined) {
16
+ transforms.push({
17
+ translateX: sx.offsetX
18
+ });
19
+ }
20
+ if (sx.offsetY !== undefined) {
21
+ transforms.push({
22
+ translateY: sx.offsetY
23
+ });
24
+ }
25
+ if (sx.rotate !== undefined) {
26
+ transforms.push({
27
+ rotate: `${sx.rotate}deg`
28
+ });
29
+ }
30
+ if (typeof sx.scale === 'number') {
31
+ transforms.push({
32
+ scale: sx.scale
33
+ });
34
+ } else if (sx.scale !== undefined) {
35
+ if (sx.scale.x !== undefined) {
36
+ transforms.push({
37
+ scaleX: sx.scale.x
38
+ });
39
+ }
40
+ if (sx.scale.y !== undefined) {
41
+ transforms.push({
42
+ scaleY: sx.scale.y
43
+ });
44
+ }
45
+ }
46
+ return transforms.length > 0 ? transforms : undefined;
47
+ };
48
+
49
+ /**
50
+ * A React Native view has a single border slot, so a ring shadow rides it — an explicit
51
+ * `borderColor`/`borderWidth` on the same box is written later and wins, where the modifier paths
52
+ * draw the ring and the border as two separate strokes.
53
+ */
54
+ const shadowStyle = (sx, theme) => {
55
+ if (!sx.shadow) {
56
+ return {};
57
+ }
58
+ const {
59
+ colors,
60
+ geometry
61
+ } = resolveShadow(theme, sx.shadow);
62
+ const style = {};
63
+ if (geometry.ring && colors.ring) {
64
+ style.borderColor = resolvePaletteColor(theme, colors.ring);
65
+ style.borderWidth = Math.max(geometry.ring.width, StyleSheet.hairlineWidth);
66
+ }
67
+ if (geometry.drop && colors.drop) {
68
+ style.elevation = geometry.drop.y * 2;
69
+ style.shadowColor = resolvePaletteColor(theme, colors.drop);
70
+ style.shadowOffset = {
71
+ height: geometry.drop.y,
72
+ width: 0
73
+ };
74
+ style.shadowOpacity = 1;
75
+ style.shadowRadius = geometry.drop.radius;
76
+ }
77
+ return style;
78
+ };
79
+ export const sxToStyle = (sx, theme) => {
80
+ const style = {
81
+ ...shadowStyle(sx, theme)
82
+ };
83
+ const padding = sxPadding(sx);
84
+ if (padding) {
85
+ style.paddingTop = padding.top;
86
+ style.paddingBottom = padding.bottom;
87
+ style.paddingLeft = padding.leading;
88
+ style.paddingRight = padding.trailing;
89
+ }
90
+ if (sx.wide) {
91
+ style.width = '100%';
92
+ }
93
+ if (sx.tall) {
94
+ style.height = '100%';
95
+ }
96
+ if (sx.w !== undefined) {
97
+ style.width = sx.w;
98
+ }
99
+ if (sx.h !== undefined) {
100
+ style.height = sx.h;
101
+ }
102
+ if (sx.minW !== undefined) {
103
+ style.minWidth = sx.minW;
104
+ }
105
+ if (sx.minH !== undefined) {
106
+ style.minHeight = sx.minH;
107
+ }
108
+ if (sx.bg) {
109
+ style.backgroundColor = theme.color(sx.bg);
110
+ }
111
+ if (sx.borderColor) {
112
+ style.borderColor = theme.color(sx.borderColor);
113
+ }
114
+ if (sx.borderWidth !== undefined) {
115
+ style.borderWidth = sx.borderWidth;
116
+ }
117
+ if (sx.borderRadius) {
118
+ style.borderRadius = radii[sx.borderRadius];
119
+ }
120
+ if (sx.opacity) {
121
+ style.opacity = opacity[sx.opacity];
122
+ }
123
+ if (sx.zIndex) {
124
+ style.zIndex = zIndex[sx.zIndex];
125
+ }
126
+ if (sx.blur !== undefined) {
127
+ style.filter = [{
128
+ blur: sx.blur
129
+ }];
130
+ }
131
+ const transforms = transform(sx);
132
+ if (transforms) {
133
+ style.transform = transforms;
134
+ }
135
+ return style;
136
+ };
137
+ //# sourceMappingURL=sx-to-style.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["opacity","radii","resolvePaletteColor","resolveShadow","zIndex","StyleSheet","sxPadding","transform","sx","transforms","offsetX","undefined","push","translateX","offsetY","translateY","rotate","scale","x","scaleX","y","scaleY","length","shadowStyle","theme","shadow","colors","geometry","style","ring","borderColor","borderWidth","Math","max","width","hairlineWidth","drop","elevation","shadowColor","shadowOffset","height","shadowOpacity","shadowRadius","radius","sxToStyle","padding","paddingTop","top","paddingBottom","bottom","paddingLeft","leading","paddingRight","trailing","wide","tall","w","h","minW","minWidth","minH","minHeight","bg","backgroundColor","color","borderRadius","blur","filter"],"sourceRoot":"../../src","sources":["sx-to-style.ts"],"mappings":";;AAAA,SAAQA,OAAO,EAAEC,KAAK,EAAEC,mBAAmB,EAAEC,aAAa,EAAcC,MAAM,QAAO,mBAAmB;AACxG,SAAQC,UAAU,QAAuB,cAAc;AAEvD,SAAQC,SAAS,QAAO,iBAAc;;AAEtC;AACA;AACA;AACA;AACA;;AAGA,MAAMC,SAAS,GAAIC,EAAW,IAA6B;EACzD,MAAMC,UAAuB,GAAG,EAAE;EAElC,IAAID,EAAE,CAACE,OAAO,KAAKC,SAAS,EAAE;IAC5BF,UAAU,CAACG,IAAI,CAAC;MAACC,UAAU,EAAEL,EAAE,CAACE;IAAO,CAAC,CAAC;EAC3C;EAEA,IAAIF,EAAE,CAACM,OAAO,KAAKH,SAAS,EAAE;IAC5BF,UAAU,CAACG,IAAI,CAAC;MAACG,UAAU,EAAEP,EAAE,CAACM;IAAO,CAAC,CAAC;EAC3C;EAEA,IAAIN,EAAE,CAACQ,MAAM,KAAKL,SAAS,EAAE;IAC3BF,UAAU,CAACG,IAAI,CAAC;MAACI,MAAM,EAAE,GAAGR,EAA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D,UAAU,GAAGF,SAAS,CAACC,EAAE,CAAC;EAEhC,IAAIC,UAAU,EAAE;IACdmB,KAAK,CAACrB,SAAS,GAAGE,UAAU;EAC9B;EAEA,OAAOmB,KAAK;AACd,CAAC","ignoreList":[]}
@@ -0,0 +1,4 @@
1
+ "use strict";
2
+
3
+ export {};
4
+ //# sourceMappingURL=sx.types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":[],"sourceRoot":"../../src","sources":["sx.types.ts"],"mappings":"","ignoreList":[]}
@@ -0,0 +1,30 @@
1
+ "use strict";
2
+
3
+ import { useAppTheme, useBreakpoint } from '@hzblj/kara-theme';
4
+ import { useMemo } from 'react';
5
+ import { flattenSx } from "./flatten-sx.js";
6
+ import { SX_RESPONSIVE_KEYS } from "./responsive-sx.js";
7
+ import { sxKey } from "./sx-key.js";
8
+ import { sxToModifiers } from './sx-to-modifiers';
9
+
10
+ /**
11
+ * `sxToModifiers` behind a `useMemo`, so a re-render hands the native view the modifier array it is
12
+ * already holding instead of an equal-but-new one to diff.
13
+ *
14
+ * The responsive flattening happens before `sxKey`, so the key describes the values actually applied
15
+ * at this breakpoint — a rotation to a wider window changes it, and nothing else does.
16
+ *
17
+ * `android.modifiers` is depended on by identity, because `sxKey` cannot flatten opaque modifier
18
+ * configs into a string. A call site that builds that array inline therefore re-resolves every render.
19
+ */
20
+ export const useSxModifiers = (sx, alignment) => {
21
+ const theme = useAppTheme();
22
+ const breakpoint = useBreakpoint();
23
+ const flat = flattenSx(sx, SX_RESPONSIVE_KEYS, breakpoint);
24
+ const key = sxKey(flat);
25
+ const escapeHatch = sx.android?.modifiers;
26
+
27
+ // biome-ignore lint/correctness/useExhaustiveDependencies: `key` stands in for `flat` — see `sxKey`
28
+ return useMemo(() => sxToModifiers(flat, theme, alignment), [alignment, escapeHatch, key, theme]);
29
+ };
30
+ //# sourceMappingURL=use-sx-modifiers.android.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["useAppTheme","useBreakpoint","useMemo","flattenSx","SX_RESPONSIVE_KEYS","sxKey","sxToModifiers","useSxModifiers","sx","alignment","theme","breakpoint","flat","key","escapeHatch","android","modifiers"],"sourceRoot":"../../src","sources":["use-sx-modifiers.android.ts"],"mappings":";;AACA,SAAQA,WAAW,EAAEC,aAAa,QAAO,mBAAmB;AAC5D,SAAQC,OAAO,QAAO,OAAO;AAC7B,SAAQC,SAAS,QAAO,iBAAc;AACtC,SAAiDC,kBAAkB,QAAO,oBAAiB;AAE3F,SAAQC,KAAK,QAAO,aAAU;AAC9B,SAAQC,aAAa,QAAO,mBAAmB;;AAE/C;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,MAAMC,cAAc,GAAGA,CAACC,EAAgB,EAAEC,SAA0B,KAAuB;EAChG,MAAMC,KAAK,GAAGV,WAAW,CAAC,CAAC;EAC3B,MAAMW,UAAU,GAAGV,aAAa,CAAC,CAAC;EAClC,MAAMW,IAAI,GAAGT,SAAS,CAAsBK,EAAE,EAAEJ,kBAAkB,EAAEO,UAAU,CAAC;EAC/E,MAAME,GAAG,GAAGR,KAAK,CAACO,IAAI,CAAC;EACvB,MAAME,WAAW,GAAGN,EAAE,CAACO,OAAO,EAAEC,SAAS;;EAEzC;EACA,OAAOd,OAAO,CAAC,MAAMI,aAAa,CAACM,IAAI,EAAEF,KAAK,EAAED,SAAS,CAAC,EAAE,CAACA,SAAS,EAAEK,WAAW,EAAED,GAAG,EAAEH,KAAK,CAAC,CAAC;AACnG,CAAC","ignoreList":[]}
@@ -0,0 +1,30 @@
1
+ "use strict";
2
+
3
+ import { useAppTheme, useBreakpoint } from '@hzblj/kara-theme';
4
+ import { useMemo } from 'react';
5
+ import { flattenSx } from "./flatten-sx.js";
6
+ import { SX_RESPONSIVE_KEYS } from "./responsive-sx.js";
7
+ import { sxKey } from "./sx-key.js";
8
+ import { sxToModifiers } from './sx-to-modifiers';
9
+
10
+ /**
11
+ * `sxToModifiers` behind a `useMemo`, so a re-render hands the native view the modifier array it is
12
+ * already holding instead of an equal-but-new one to diff.
13
+ *
14
+ * The responsive flattening happens before `sxKey`, so the key describes the values actually applied
15
+ * at this breakpoint — a rotation to a wider window changes it, and nothing else does.
16
+ *
17
+ * `ios.modifiers` is depended on by identity, because `sxKey` cannot flatten opaque modifier configs
18
+ * into a string. A call site that builds that array inline therefore re-resolves every render.
19
+ */
20
+ export const useSxModifiers = (sx, alignment) => {
21
+ const theme = useAppTheme();
22
+ const breakpoint = useBreakpoint();
23
+ const flat = flattenSx(sx, SX_RESPONSIVE_KEYS, breakpoint);
24
+ const key = sxKey(flat);
25
+ const escapeHatch = sx.ios?.modifiers;
26
+
27
+ // biome-ignore lint/correctness/useExhaustiveDependencies: `key` stands in for `flat` — see `sxKey`
28
+ return useMemo(() => sxToModifiers(flat, theme, alignment), [alignment, escapeHatch, key, theme]);
29
+ };
30
+ //# sourceMappingURL=use-sx-modifiers.ios.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["useAppTheme","useBreakpoint","useMemo","flattenSx","SX_RESPONSIVE_KEYS","sxKey","sxToModifiers","useSxModifiers","sx","alignment","theme","breakpoint","flat","key","escapeHatch","ios","modifiers"],"sourceRoot":"../../src","sources":["use-sx-modifiers.ios.ts"],"mappings":";;AACA,SAAQA,WAAW,EAAEC,aAAa,QAAO,mBAAmB;AAC5D,SAAQC,OAAO,QAAO,OAAO;AAC7B,SAAQC,SAAS,QAAO,iBAAc;AACtC,SAAiDC,kBAAkB,QAAO,oBAAiB;AAE3F,SAAQC,KAAK,QAAO,aAAU;AAC9B,SAAQC,aAAa,QAAO,mBAAmB;;AAE/C;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,MAAMC,cAAc,GAAGA,CAACC,EAAgB,EAAEC,SAA0B,KAAuB;EAChG,MAAMC,KAAK,GAAGV,WAAW,CAAC,CAAC;EAC3B,MAAMW,UAAU,GAAGV,aAAa,CAAC,CAAC;EAClC,MAAMW,IAAI,GAAGT,SAAS,CAAsBK,EAAE,EAAEJ,kBAAkB,EAAEO,UAAU,CAAC;EAC/E,MAAME,GAAG,GAAGR,KAAK,CAACO,IAAI,CAAC;EACvB,MAAME,WAAW,GAAGN,EAAE,CAACO,GAAG,EAAEC,SAAS;;EAErC;EACA,OAAOd,OAAO,CAAC,MAAMI,aAAa,CAACM,IAAI,EAAEF,KAAK,EAAED,SAAS,CAAC,EAAE,CAACA,SAAS,EAAEK,WAAW,EAAED,GAAG,EAAEH,KAAK,CAAC,CAAC;AACnG,CAAC","ignoreList":[]}
@@ -0,0 +1,30 @@
1
+ "use strict";
2
+
3
+ import { useAppTheme, useBreakpoint } from '@hzblj/kara-theme';
4
+ import { flattenSx } from "./flatten-sx.js";
5
+ import { VIEW_RESPONSIVE_KEYS } from "./responsive-sx.js";
6
+ import { viewSxCache } from "./view-sx-to-style.js";
7
+
8
+ /**
9
+ * Resolves an `sx` object into a React Native style. Needs no `useMemo`: the cache keys on the
10
+ * flattened sx values, so the same sx at the same breakpoint hands back the very same object every
11
+ * render — and across components.
12
+ */
13
+ export const useSx = sx => {
14
+ const theme = useAppTheme();
15
+ const breakpoint = useBreakpoint();
16
+ return viewSxCache.resolve(flattenSx(sx, VIEW_RESPONSIVE_KEYS, breakpoint), theme);
17
+ };
18
+
19
+ /**
20
+ * `useSx` for a component whose own props arrive mixed in with the `sx` ones: the `sx` keys are split
21
+ * off and resolved, and the rest is handed back untouched. What `sx()` does internally, exposed for the
22
+ * components that cannot be built on it because they own their `style` prop — an animated one, or a
23
+ * `ScrollView` styling two boxes at once.
24
+ */
25
+ export const useSplitSx = props => {
26
+ const [own, rest] = viewSxCache.split(props);
27
+ const style = useSx(own);
28
+ return [style, rest];
29
+ };
30
+ //# sourceMappingURL=use-sx.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["useAppTheme","useBreakpoint","flattenSx","VIEW_RESPONSIVE_KEYS","viewSxCache","useSx","sx","theme","breakpoint","resolve","useSplitSx","props","own","rest","split","style"],"sourceRoot":"../../src","sources":["use-sx.ts"],"mappings":";;AAAA,SAAQA,WAAW,EAAEC,aAAa,QAAO,mBAAmB;AAG5D,SAAQC,SAAS,QAAO,iBAAc;AACtC,SAAyDC,oBAAoB,QAAO,oBAAiB;AAErG,SAAQC,WAAW,QAAO,uBAAoB;;AAE9C;AACA;AACA;AACA;AACA;AACA,OAAO,MAAMC,KAAK,GAAIC,EAAoB,IAAgB;EACxD,MAAMC,KAAK,GAAGP,WAAW,CAAC,CAAC;EAC3B,MAAMQ,UAAU,GAAGP,aAAa,CAAC,CAAC;EAElC,OAAOG,WAAW,CAACK,OAAO,CAACP,SAAS,CAA8BI,EAAE,EAAEH,oBAAoB,EAAEK,UAAU,CAAC,EAAED,KAAK,CAAC;AACjH,CAAC;;AAED;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,MAAMG,UAAU,GACrBC,KAAa,IAC4B;EACzC,MAAM,CAACC,GAAG,EAAEC,IAAI,CAAC,GAAGT,WAAW,CAACU,KAAK,CAACH,KAAK,CAAC;EAC5C,MAAMI,KAAK,GAAGV,KAAK,CAACO,GAAG,CAAC;EAExB,OAAO,CAACG,KAAK,EAAEF,IAAI,CAAC;AACtB,CAAC","ignoreList":[]}
@@ -0,0 +1,16 @@
1
+ "use strict";
2
+
3
+ /**
4
+ * Flattens a value into a cache-key fragment. Objects are walked one level — with keys sorted, so
5
+ * two configs holding the same values key alike — rather than left to `String`, which turns every
6
+ * object into the same `[object Object]` and would have two different ones share a cache entry.
7
+ * One level is all the `Bucket` constraint admits, so deeper nesting cannot reach this.
8
+ */
9
+ export const valueKey = value => {
10
+ if (typeof value !== 'object' || value === null) {
11
+ return String(value);
12
+ }
13
+ const entries = value;
14
+ return `{${Object.keys(entries).sort().map(name => `${name}:${String(entries[name])}`).join(',')}}`;
15
+ };
16
+ //# sourceMappingURL=value-key.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["valueKey","value","String","entries","Object","keys","sort","map","name","join"],"sourceRoot":"../../src","sources":["value-key.ts"],"mappings":";;AAAA;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,MAAMA,QAAQ,GAAIC,KAAc,IAAa;EAClD,IAAI,OAAOA,KAAK,KAAK,QAAQ,IAAIA,KAAK,KAAK,IAAI,EAAE;IAC/C,OAAOC,MAAM,CAACD,KAAK,CAAC;EACtB;EAEA,MAAME,OAAO,GAAGF,KAAgC;EAEhD,OAAO,IAAIG,MAAM,CAACC,IAAI,CAACF,OAAO,CAAC,CAC5BG,IAAI,CAAC,CAAC,CACNC,GAAG,CAACC,IAAI,IAAI,GAAGA,IAAI,IAAIN,MAAM,CAACC,OAAO,CAACK,IAAI,CAAC,CAAC,EAAE,CAAC,CAC/CC,IAAI,CAAC,GAAG,CAAC,GAAG;AACjB,CAAC","ignoreList":[]}