panelui-native 0.113.1 → 0.115.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/lib/module/components/camera/camera-model.js +142 -0
- package/lib/module/components/camera/camera-model.js.map +1 -0
- package/lib/module/components/camera/index.js +1546 -0
- package/lib/module/components/camera/index.js.map +1 -0
- package/lib/module/components/image-viewer/image-viewer-geometry.js +15 -0
- package/lib/module/components/image-viewer/image-viewer-geometry.js.map +1 -1
- package/lib/module/components/image-viewer/index.js +101 -37
- package/lib/module/components/image-viewer/index.js.map +1 -1
- package/lib/module/components/tabs/index.js +19 -7
- package/lib/module/components/tabs/index.js.map +1 -1
- package/lib/module/icons/index.js +20 -0
- package/lib/module/icons/index.js.map +1 -1
- package/lib/module/index.js +2 -1
- package/lib/module/index.js.map +1 -1
- package/lib/typescript/src/components/camera/camera-model.d.ts +79 -0
- package/lib/typescript/src/components/camera/camera-model.d.ts.map +1 -0
- package/lib/typescript/src/components/camera/index.d.ts +481 -0
- package/lib/typescript/src/components/camera/index.d.ts.map +1 -0
- package/lib/typescript/src/components/image-viewer/image-viewer-geometry.d.ts +9 -0
- package/lib/typescript/src/components/image-viewer/image-viewer-geometry.d.ts.map +1 -1
- package/lib/typescript/src/components/image-viewer/index.d.ts +10 -3
- package/lib/typescript/src/components/image-viewer/index.d.ts.map +1 -1
- package/lib/typescript/src/components/tabs/index.d.ts +24 -2
- package/lib/typescript/src/components/tabs/index.d.ts.map +1 -1
- package/lib/typescript/src/icons/index.d.ts +4 -0
- package/lib/typescript/src/icons/index.d.ts.map +1 -1
- package/lib/typescript/src/index.d.ts +2 -1
- package/lib/typescript/src/index.d.ts.map +1 -1
- package/package.json +5 -1
- package/src/components/camera/camera-model.ts +140 -0
- package/src/components/camera/index.tsx +1880 -0
- package/src/components/image-viewer/image-viewer-geometry.ts +15 -0
- package/src/components/image-viewer/index.tsx +122 -43
- package/src/components/tabs/index.tsx +48 -8
- package/src/icons/index.tsx +8 -0
- package/src/index.ts +36 -0
|
@@ -0,0 +1,142 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* The Camera's arithmetic, kept apart from the component so it can be tested
|
|
5
|
+
* without a device. Every function here is pure; the ones the gestures call on
|
|
6
|
+
* the UI thread are worklets.
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
/** Which camera the preview reads. */
|
|
10
|
+
|
|
11
|
+
/** What the shutter makes. */
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* The flash setting the control shows. `auto` lets the camera decide for a
|
|
15
|
+
* photo; a video has no auto, so there it reads as off.
|
|
16
|
+
*/
|
|
17
|
+
|
|
18
|
+
/** Seconds the self-timer counts down before a photo. `0` is off. */
|
|
19
|
+
|
|
20
|
+
/** The timer settings, in the order the control steps through them. */
|
|
21
|
+
export const CAMERA_TIMERS = [0, 3, 10];
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* How much of the zoom range a pinch's `scale - 1` is worth: pinching to twice
|
|
25
|
+
* the distance between the fingers moves half the range.
|
|
26
|
+
*/
|
|
27
|
+
export const PINCH_ZOOM_SENSITIVITY = 0.5;
|
|
28
|
+
|
|
29
|
+
/** How far one step of the screen reader's adjust moves the zoom. */
|
|
30
|
+
export const ZOOM_STEP = 0.1;
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* Zoom as expo-camera takes it: a fraction of the device's maximum, on `[0, 1]`.
|
|
34
|
+
* Anything else, `NaN` included, is pulled back onto that range.
|
|
35
|
+
*/
|
|
36
|
+
export function clampZoom(value) {
|
|
37
|
+
'worklet';
|
|
38
|
+
|
|
39
|
+
if (!Number.isFinite(value)) return 0;
|
|
40
|
+
return Math.min(1, Math.max(0, value));
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
/**
|
|
44
|
+
* The zoom a pinch reaches from the zoom it started at.
|
|
45
|
+
*
|
|
46
|
+
* Added to rather than multiplied, so a pinch that comes back to where the
|
|
47
|
+
* fingers started comes back to the zoom it started at, instead of compounding.
|
|
48
|
+
*/
|
|
49
|
+
export function zoomFromPinch(startZoom, scale) {
|
|
50
|
+
'worklet';
|
|
51
|
+
|
|
52
|
+
return clampZoom(startZoom + (scale - 1) * PINCH_ZOOM_SENSITIVITY);
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
/** The zoom a drag along the zoom bar points at, from where it is on the track. */
|
|
56
|
+
export function zoomFromTrack(x, width) {
|
|
57
|
+
'worklet';
|
|
58
|
+
|
|
59
|
+
if (!(width > 0)) return 0;
|
|
60
|
+
return clampZoom(x / width);
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
/** The zoom one adjust step up (`1`) or down (`-1`) from `zoom` lands on. */
|
|
64
|
+
export function stepZoom(zoom, direction) {
|
|
65
|
+
const next = Math.round((clampZoom(zoom) + direction * ZOOM_STEP) * 100) / 100;
|
|
66
|
+
return clampZoom(next);
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
/**
|
|
70
|
+
* Which of `stops` the zoom is at, or `-1` between them. Close enough counts,
|
|
71
|
+
* since a pinch rarely lands on a value exactly.
|
|
72
|
+
*/
|
|
73
|
+
export function activeStop(zoom, stops) {
|
|
74
|
+
for (let index = 0; index < stops.length; index += 1) {
|
|
75
|
+
if (Math.abs(clampZoom(stops[index].value) - zoom) < 0.005) return index;
|
|
76
|
+
}
|
|
77
|
+
return -1;
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
/**
|
|
81
|
+
* Milliseconds as a recording clock: `mm:ss`, and `h:mm:ss` past an hour.
|
|
82
|
+
* Leading zeros stay, so the clock does not change width as it runs, and
|
|
83
|
+
* `00:00` is what it reads before recording starts.
|
|
84
|
+
*/
|
|
85
|
+
export function formatDuration(ms) {
|
|
86
|
+
const total = Number.isFinite(ms) && ms > 0 ? Math.floor(ms / 1000) : 0;
|
|
87
|
+
const hours = Math.floor(total / 3600);
|
|
88
|
+
const minutes = Math.floor(total % 3600 / 60);
|
|
89
|
+
const seconds = total % 60;
|
|
90
|
+
const mm = String(minutes).padStart(2, '0');
|
|
91
|
+
const ss = String(seconds).padStart(2, '0');
|
|
92
|
+
return hours > 0 ? `${hours}:${mm}:${ss}` : `${mm}:${ss}`;
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
/** What the flash setting reads as in a mode: a video has no `auto`. */
|
|
96
|
+
export function flashIn(mode, flash) {
|
|
97
|
+
return mode === 'video' && flash === 'auto' ? 'off' : flash;
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
/**
|
|
101
|
+
* The setting the flash control moves to. A photo cycles off, auto, on; a
|
|
102
|
+
* video only has off and on.
|
|
103
|
+
*/
|
|
104
|
+
export function nextFlash(mode, flash) {
|
|
105
|
+
const current = flashIn(mode, flash);
|
|
106
|
+
if (mode === 'video') return current === 'on' ? 'off' : 'on';
|
|
107
|
+
if (current === 'off') return 'auto';
|
|
108
|
+
if (current === 'auto') return 'on';
|
|
109
|
+
return 'off';
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
/**
|
|
113
|
+
* The `flash` expo-camera is given. It drives stills only, so in video it is
|
|
114
|
+
* off and the torch does the lighting instead.
|
|
115
|
+
*/
|
|
116
|
+
export function stillFlash(mode, flash) {
|
|
117
|
+
return mode === 'video' ? 'off' : flash;
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
/**
|
|
121
|
+
* Whether the torch is lit: in video with the flash on, and only while a clip
|
|
122
|
+
* is being recorded, so it does not glare at the subject while they wait.
|
|
123
|
+
*/
|
|
124
|
+
export function torchFor(mode, flash, recording) {
|
|
125
|
+
return mode === 'video' && flash === 'on' && recording;
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
/** The timer setting after `timer`, wrapping back to off. */
|
|
129
|
+
export function nextTimer(timer) {
|
|
130
|
+
const index = CAMERA_TIMERS.indexOf(timer);
|
|
131
|
+
return CAMERA_TIMERS[(index + 1) % CAMERA_TIMERS.length] ?? 0;
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
/**
|
|
135
|
+
* How far a capped recording has run, on `[0, 1]`. Without a cap there is
|
|
136
|
+
* nothing to fill, so it stays `0`.
|
|
137
|
+
*/
|
|
138
|
+
export function recordingProgress(elapsedMs, maxDurationSeconds) {
|
|
139
|
+
if (!maxDurationSeconds || maxDurationSeconds <= 0) return 0;
|
|
140
|
+
return Math.min(1, Math.max(0, elapsedMs / (maxDurationSeconds * 1000)));
|
|
141
|
+
}
|
|
142
|
+
//# sourceMappingURL=camera-model.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["CAMERA_TIMERS","PINCH_ZOOM_SENSITIVITY","ZOOM_STEP","clampZoom","value","Number","isFinite","Math","min","max","zoomFromPinch","startZoom","scale","zoomFromTrack","x","width","stepZoom","zoom","direction","next","round","activeStop","stops","index","length","abs","formatDuration","ms","total","floor","hours","minutes","seconds","mm","String","padStart","ss","flashIn","mode","flash","nextFlash","current","stillFlash","torchFor","recording","nextTimer","timer","indexOf","recordingProgress","elapsedMs","maxDurationSeconds"],"sourceRoot":"../../../../src","sources":["components/camera/camera-model.ts"],"mappings":";;AAAA;AACA;AACA;AACA;AACA;;AAEA;;AAGA;;AAGA;AACA;AACA;AACA;;AAGA;;AAGA;AACA,OAAO,MAAMA,aAA0C,GAAG,CAAC,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC;;AAEpE;AACA;AACA;AACA;AACA,OAAO,MAAMC,sBAAsB,GAAG,GAAG;;AAEzC;AACA,OAAO,MAAMC,SAAS,GAAG,GAAG;;AAE5B;AACA;AACA;AACA;AACA,OAAO,SAASC,SAASA,CAACC,KAAa,EAAU;EAC/C,SAAS;;EACT,IAAI,CAACC,MAAM,CAACC,QAAQ,CAACF,KAAK,CAAC,EAAE,OAAO,CAAC;EACrC,OAAOG,IAAI,CAACC,GAAG,CAAC,CAAC,EAAED,IAAI,CAACE,GAAG,CAAC,CAAC,EAAEL,KAAK,CAAC,CAAC;AACxC;;AA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