panelui-native 0.97.0 → 0.99.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 (32) hide show
  1. package/README.md +1 -0
  2. package/lib/module/components/image-viewer/image-viewer-geometry.js +203 -0
  3. package/lib/module/components/image-viewer/image-viewer-geometry.js.map +1 -0
  4. package/lib/module/components/image-viewer/index.js +1100 -0
  5. package/lib/module/components/image-viewer/index.js.map +1 -0
  6. package/lib/module/components/stack-card/index.js +1204 -0
  7. package/lib/module/components/stack-card/index.js.map +1 -0
  8. package/lib/module/components/stack-card/stack-card-geometry.js +261 -0
  9. package/lib/module/components/stack-card/stack-card-geometry.js.map +1 -0
  10. package/lib/module/index.js +2 -0
  11. package/lib/module/index.js.map +1 -1
  12. package/lib/module/primitives/scrim.js +65 -1
  13. package/lib/module/primitives/scrim.js.map +1 -1
  14. package/lib/typescript/src/components/image-viewer/image-viewer-geometry.d.ts +83 -0
  15. package/lib/typescript/src/components/image-viewer/image-viewer-geometry.d.ts.map +1 -0
  16. package/lib/typescript/src/components/image-viewer/index.d.ts +148 -0
  17. package/lib/typescript/src/components/image-viewer/index.d.ts.map +1 -0
  18. package/lib/typescript/src/components/stack-card/index.d.ts +472 -0
  19. package/lib/typescript/src/components/stack-card/index.d.ts.map +1 -0
  20. package/lib/typescript/src/components/stack-card/stack-card-geometry.d.ts +126 -0
  21. package/lib/typescript/src/components/stack-card/stack-card-geometry.d.ts.map +1 -0
  22. package/lib/typescript/src/index.d.ts +2 -0
  23. package/lib/typescript/src/index.d.ts.map +1 -1
  24. package/lib/typescript/src/primitives/scrim.d.ts +11 -1
  25. package/lib/typescript/src/primitives/scrim.d.ts.map +1 -1
  26. package/package.json +8 -1
  27. package/src/components/image-viewer/image-viewer-geometry.ts +205 -0
  28. package/src/components/image-viewer/index.tsx +1329 -0
  29. package/src/components/stack-card/index.tsx +1423 -0
  30. package/src/components/stack-card/stack-card-geometry.ts +279 -0
  31. package/src/index.ts +19 -0
  32. package/src/primitives/scrim.tsx +96 -1
package/README.md CHANGED
@@ -300,6 +300,7 @@ memory pressure the OS can end the process with nothing in the terminal to expla
300
300
  | `Spinner` | Indeterminate loading indicator |
301
301
  | `SplitView` | Two stacked panes whose seam settles on one of a few named heights |
302
302
  | `Splitter` | Panes that share a container, with a seam between them you can drag |
303
+ | `StackCard` | A pile of cards, taken one at a time by throwing the top one off |
303
304
  | `Steps` | Stepper for multi-step flows |
304
305
  | `Surface` | Elevated container with a variant ladder |
305
306
  | `Swipe` | A row that slides aside to reveal the things you can do to it |
@@ -0,0 +1,203 @@
1
+ "use strict";
2
+
3
+ /**
4
+ * The arithmetic behind the image viewer, kept apart from the component.
5
+ *
6
+ * Every function here runs on the UI thread inside a gesture or an animated
7
+ * style, so each is a worklet. None of them touches React Native, which is what
8
+ * lets the contract tests run them in Node.
9
+ */
10
+
11
+ /** How much a rubber-banded overshoot gives. Lower is stiffer. */
12
+ export const RUBBER_BAND = 0.55;
13
+ export function clamp(value, min, max) {
14
+ 'worklet';
15
+
16
+ return Math.min(Math.max(value, min), max);
17
+ }
18
+ export function lerp(from, to, t) {
19
+ 'worklet';
20
+
21
+ return from + (to - from) * t;
22
+ }
23
+ export function lerpRect(from, to, t) {
24
+ 'worklet';
25
+
26
+ return {
27
+ x: lerp(from.x, to.x, t),
28
+ y: lerp(from.y, to.y, t),
29
+ width: lerp(from.width, to.width, t),
30
+ height: lerp(from.height, to.height, t)
31
+ };
32
+ }
33
+
34
+ /**
35
+ * The largest rect with the image's proportions that fits inside the box,
36
+ * centred in it. An image with no known size fills the box.
37
+ */
38
+ export function fitContain(image, box) {
39
+ 'worklet';
40
+
41
+ if (image.width <= 0 || image.height <= 0) {
42
+ return {
43
+ x: 0,
44
+ y: 0,
45
+ width: box.width,
46
+ height: box.height
47
+ };
48
+ }
49
+ const scale = Math.min(box.width / image.width, box.height / image.height);
50
+ const width = image.width * scale;
51
+ const height = image.height * scale;
52
+ return {
53
+ x: (box.width - width) / 2,
54
+ y: (box.height - height) / 2,
55
+ width,
56
+ height
57
+ };
58
+ }
59
+
60
+ /** `fitContain` inside a rect that does not start at the origin. */
61
+ export function fitWithin(image, box) {
62
+ 'worklet';
63
+
64
+ const fitted = fitContain(image, box);
65
+ return {
66
+ ...fitted,
67
+ x: box.x + fitted.x,
68
+ y: box.y + fitted.y
69
+ };
70
+ }
71
+
72
+ /**
73
+ * The smallest size with the image's proportions that covers the frame.
74
+ *
75
+ * A thumbnail crops its picture to its box; the viewer shows the whole of it.
76
+ * Drawing the image at this size inside a frame that grows from one to the
77
+ * other is what makes the crop open out instead of the picture jumping.
78
+ */
79
+ export function coverSize(image, frame) {
80
+ 'worklet';
81
+
82
+ if (image.width <= 0 || image.height <= 0) {
83
+ return {
84
+ width: frame.width,
85
+ height: frame.height
86
+ };
87
+ }
88
+ const scale = Math.max(frame.width / image.width, frame.height / image.height);
89
+ return {
90
+ width: image.width * scale,
91
+ height: image.height * scale
92
+ };
93
+ }
94
+
95
+ /**
96
+ * How far past its limit a value is allowed to travel, given how far it was
97
+ * pushed. The resistance grows with the push and never quite reaches `dimension`.
98
+ */
99
+ export function rubberBand(overshoot, dimension, coefficient) {
100
+ 'worklet';
101
+
102
+ if (dimension <= 0) return 0;
103
+ const give = coefficient ?? RUBBER_BAND;
104
+ return (1 - 1 / (overshoot * give / dimension + 1)) * dimension;
105
+ }
106
+
107
+ /** Clamps to `[min, max]`, letting the value stretch past either end with resistance. */
108
+ export function rubberBandClamp(value, min, max, dimension, coefficient) {
109
+ 'worklet';
110
+
111
+ const clamped = clamp(value, min, max);
112
+ const overshoot = Math.abs(value - clamped);
113
+ if (overshoot === 0) return clamped;
114
+ const sign = value < clamped ? -1 : 1;
115
+ return clamped + sign * rubberBand(overshoot, dimension, coefficient);
116
+ }
117
+
118
+ /**
119
+ * How far a zoomed image may be moved along one axis before its edge comes away
120
+ * from the screen's. Zero while the scaled image is smaller than the screen,
121
+ * which keeps it centred on that axis.
122
+ */
123
+ export function panBound(fitted, scale, viewport) {
124
+ 'worklet';
125
+
126
+ return Math.max(0, (fitted * scale - viewport) / 2);
127
+ }
128
+
129
+ /**
130
+ * The translation that keeps a point under the fingers while the scale changes.
131
+ *
132
+ * `offset` is where that point sat relative to the image's centre when the
133
+ * pinch began, at `fromScale`; `focal` is the fingers' position now, relative
134
+ * to the screen's centre. The result is measured from the screen's centre too.
135
+ */
136
+ export function focalTranslation(focal, offset, fromScale, toScale) {
137
+ 'worklet';
138
+
139
+ if (fromScale === 0) return focal;
140
+ return focal - offset * (toScale / fromScale);
141
+ }
142
+
143
+ /**
144
+ * The page a released pager settles on. Where it would have coasted to decides
145
+ * it rather than where it was let go, so a short flick still turns the page —
146
+ * but never by more than one, which is what a flick means.
147
+ */
148
+ export function snapPage(offset, velocity, current, count, pageWidth) {
149
+ 'worklet';
150
+
151
+ if (count <= 1 || pageWidth <= 0) return 0;
152
+ const projected = -(offset + velocity * 0.25) / pageWidth;
153
+ const target = Math.round(projected);
154
+ return clamp(clamp(target, current - 1, current + 1), 0, count - 1);
155
+ }
156
+
157
+ /** How far a drag has to travel, counting where it was flung, to close the viewer. */
158
+ export const DISMISS_DISTANCE = 110;
159
+
160
+ /**
161
+ * Whether a released drag closes the viewer.
162
+ *
163
+ * Measured on where the image was heading rather than where it was dropped, so
164
+ * a quick flick closes it from a short distance and a slow drag that is let go
165
+ * of carefully does not. A throw back towards the centre cancels.
166
+ */
167
+ export function shouldDismiss(translation, velocity) {
168
+ 'worklet';
169
+
170
+ const projected = translation + velocity * 0.2;
171
+ if (Math.abs(projected) <= DISMISS_DISTANCE) return false;
172
+ return translation === 0 || Math.sign(projected) === Math.sign(translation);
173
+ }
174
+
175
+ /**
176
+ * How much of the backdrop is left while the image is dragged away from the
177
+ * centre. It is mostly gone by the time the drag would close the viewer, so the
178
+ * page coming back into focus is the warning that letting go will close it.
179
+ */
180
+ export function dragFade(distance, viewport) {
181
+ 'worklet';
182
+
183
+ if (viewport <= 0) return 1;
184
+ return 1 - clamp(Math.abs(distance) / (viewport * 0.4), 0, 1) * 0.85;
185
+ }
186
+
187
+ /** How small the image gets while it is dragged. Never below 0.8 of its size. */
188
+ export function dragScale(distance, viewport) {
189
+ 'worklet';
190
+
191
+ if (viewport <= 0) return 1;
192
+ return 1 - clamp(Math.abs(distance) / viewport, 0, 1) * 0.2;
193
+ }
194
+
195
+ /** Whether a point lands on a rect that has been scaled about its centre and moved. */
196
+ export function hitsRect(px, py, rect, scale, tx, ty) {
197
+ 'worklet';
198
+
199
+ const cx = rect.x + rect.width / 2 + tx;
200
+ const cy = rect.y + rect.height / 2 + ty;
201
+ return Math.abs(px - cx) <= rect.width * scale / 2 && Math.abs(py - cy) <= rect.height * scale / 2;
202
+ }
203
+ //# sourceMappingURL=image-viewer-geometry.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["RUBBER_BAND","clamp","value","min","max","Math","lerp","from","to","t","lerpRect","x","y","width","height","fitContain","image","box","scale","fitWithin","fitted","coverSize","frame","rubberBand","overshoot","dimension","coefficient","give","rubberBandClamp","clamped","abs","sign","panBound","viewport","focalTranslation","focal","offset","fromScale","toScale","snapPage","velocity","current","count","pageWidth","projected","target","round","DISMISS_DISTANCE","shouldDismiss","translation","dragFade","distance","dragScale","hitsRect","px","py","rect","tx","ty","cx","cy"],"sourceRoot":"../../../../src","sources":["components/image-viewer/image-viewer-geometry.ts"],"mappings":";;AAAA;AACA;AACA;AACA;AACA;AACA;AACA;;AAYA;AACA,OAAO,MAAMA,WAAW,GAAG,IAAI;AAE/B,OAAO,SAASC,KAAKA,CAACC,KAAa,EAAEC,GAAW,EAAEC,GAAW,EAAU;EACrE,SAAS;;EACT,OAAOC,IAAI,CAACF,GAAG,CAACE,IAAI,CAACD,GAAG,CAACF,KAAK,EAAEC,GAAG,CAAC,EAAEC,GAAG,CAAC;AAC5C;AAEA,OAAO,SAASE,IAAIA,CAACC,IAAY,EAAEC,EAAU,EAAEC,CAAS,EAAU;EAChE,SAAS;;EACT,OAAO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