@octane-xplat/video 0.0.0 → 0.7.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.
@@ -0,0 +1,248 @@
1
+ import { cx } from "./cx.mobile.js";
2
+ import { applyEscapeProps, nativeAccessibilityRole, nativeAccessibilityState } from "./escape-props.js";
3
+ import { layoutChildProps } from "./layout-child.js";
4
+ import { VideoChrome } from "./video-chrome.tsrx.js";
5
+ import { defineUniversalComponent, hookSlots, registerElement, universalComponent, universalIf, universalPlan, universalProps, universalValue, useCallback, useEffect, useRef, useState } from "@nativescript-community/octane";
6
+ import { Video, VideoFill } from "@nstudio/nativescript-exoplayer";
7
+ //#region src/Video.tsrx
8
+ var _hs$ = /* @__PURE__ */ hookSlots(11);
9
+ var _h$0 = /* @__PURE__ */ Symbol(_hs$);
10
+ var _h$1 = /* @__PURE__ */ Symbol(_hs$ + 1);
11
+ var _h$2 = /* @__PURE__ */ Symbol(_hs$ + 2);
12
+ var _h$3 = /* @__PURE__ */ Symbol(_hs$ + 3);
13
+ var _h$4 = /* @__PURE__ */ Symbol(_hs$ + 4);
14
+ var _h$5 = /* @__PURE__ */ Symbol(_hs$ + 5);
15
+ var _h$6 = /* @__PURE__ */ Symbol(_hs$ + 6);
16
+ var _h$7 = /* @__PURE__ */ Symbol(_hs$ + 7);
17
+ var _h$8 = /* @__PURE__ */ Symbol(_hs$ + 8);
18
+ var _h$9 = /* @__PURE__ */ Symbol(_hs$ + 9);
19
+ var _h$10 = /* @__PURE__ */ Symbol(_hs$ + 10);
20
+ var __octaneUniversalPlan0 = universalPlan("nativescript", {
21
+ "kind": "slot",
22
+ "slot": 0
23
+ });
24
+ var __octaneUniversalPlan1 = universalPlan("nativescript", {
25
+ "kind": "host",
26
+ "type": "gridlayout",
27
+ "propsSlot": 0,
28
+ "children": [{
29
+ "kind": "host",
30
+ "type": "xplatvideo",
31
+ "props": { "controls": false },
32
+ "bindings": [
33
+ ["ref", 1],
34
+ ["autoplay", 2],
35
+ ["loop", 3],
36
+ ["muted", 4],
37
+ ["fill", 5],
38
+ ["observeCurrentTime", 6],
39
+ ["onFinished", 7],
40
+ ["onPlaybackReady", 8],
41
+ ["onPlaybackStart", 9],
42
+ ["onCurrentTimeUpdated", 10]
43
+ ]
44
+ }, {
45
+ "kind": "slot",
46
+ "slot": 11
47
+ }]
48
+ });
49
+ registerElement("xplatvideo", Video);
50
+ var FILLS = {
51
+ contain: VideoFill.aspect,
52
+ cover: VideoFill.aspectFill,
53
+ fill: VideoFill.fill
54
+ };
55
+ var Video$1 = defineUniversalComponent("nativescript", function Video(props) {
56
+ const host = useRef(null, _h$0);
57
+ const [playing, setPlaying] = useState(props.playing ?? props.autoPlay ?? false, _h$1);
58
+ const [started, setStarted] = useState(false, _h$2);
59
+ const [position, setPosition] = useState(0, _h$3);
60
+ const [duration, setDuration] = useState(0, _h$4);
61
+ const [internalMuted, setInternalMuted] = useState(false, _h$5);
62
+ const muted = props.muted ?? internalMuted;
63
+ const appliedSrc = useRef(void 0, _h$6);
64
+ const bindHost = useCallback((v) => {
65
+ host.current = v;
66
+ }, [], _h$7);
67
+ const drive = (v, next) => {
68
+ if (!v) return;
69
+ if (next) v.play();
70
+ else v.pause();
71
+ };
72
+ useEffect(() => {
73
+ const v = host.current;
74
+ if (!v) return;
75
+ applyEscapeProps(v, props);
76
+ props.bind?.(handle(v));
77
+ }, [], _h$8);
78
+ useEffect(() => {
79
+ const v = host.current;
80
+ if (!v || props.src === appliedSrc.current) return;
81
+ appliedSrc.current = props.src;
82
+ v.src = props.src;
83
+ }, [props.src], _h$9);
84
+ useEffect(() => {
85
+ if (props.playing === void 0) return;
86
+ setPlaying(props.playing);
87
+ drive(host.current, props.playing);
88
+ }, [props.playing], _h$10);
89
+ const togglePlay = () => {
90
+ const next = !playing;
91
+ setPlaying(next);
92
+ drive(host.current, next);
93
+ props.onPlayingChange?.(next);
94
+ };
95
+ const handle = (v) => ({
96
+ play: () => v.play(),
97
+ pause: () => v.pause(),
98
+ seekTo: (ms) => v.seekToTime(ms / 1e3),
99
+ currentTime: () => v.getCurrentTime(),
100
+ duration: () => v.getDuration(),
101
+ native: v
102
+ });
103
+ return universalValue(__octaneUniversalPlan1, [
104
+ universalProps([
105
+ [
106
+ "set",
107
+ "id",
108
+ props.id
109
+ ],
110
+ [
111
+ "set",
112
+ "rows",
113
+ "*"
114
+ ],
115
+ [
116
+ "set",
117
+ "columns",
118
+ "*"
119
+ ],
120
+ [
121
+ "set",
122
+ "className",
123
+ cx("vx-stack", "vx-video", props.className)
124
+ ],
125
+ [
126
+ "set",
127
+ "style",
128
+ props.style
129
+ ],
130
+ ["spread", layoutChildProps(props)],
131
+ [
132
+ "set",
133
+ "accessible",
134
+ props.accessible
135
+ ],
136
+ [
137
+ "set",
138
+ "accessibilityLabel",
139
+ props.accessibilityLabel
140
+ ],
141
+ [
142
+ "set",
143
+ "accessibilityRole",
144
+ nativeAccessibilityRole(props.accessibilityRole)
145
+ ],
146
+ [
147
+ "set",
148
+ "accessibilityHint",
149
+ props.accessibilityHint
150
+ ],
151
+ [
152
+ "set",
153
+ "accessibilityValue",
154
+ props.accessibilityValue
155
+ ],
156
+ [
157
+ "set",
158
+ "accessibilityState",
159
+ nativeAccessibilityState(props.accessibilityState)
160
+ ],
161
+ [
162
+ "set",
163
+ "accessibilityLiveRegion",
164
+ props.accessibilityLiveRegion
165
+ ]
166
+ ]),
167
+ bindHost,
168
+ props.playing ?? props.autoPlay ?? false,
169
+ props.loop,
170
+ muted,
171
+ FILLS[props.fit ?? "contain"],
172
+ props.controls !== false,
173
+ () => {
174
+ if (!props.loop) {
175
+ setPlaying(false);
176
+ props.onEnded?.();
177
+ }
178
+ },
179
+ () => {
180
+ const ms = host.current?.getDuration?.() ?? 0;
181
+ setDuration(ms);
182
+ props.onReady?.({ duration: ms });
183
+ },
184
+ () => setStarted(true),
185
+ (e) => setPosition(e.position ?? 0),
186
+ universalIf(props.controls !== false, () => {
187
+ return universalValue(__octaneUniversalPlan0, [universalComponent("nativescript", VideoChrome, universalProps([
188
+ [
189
+ "set",
190
+ "poster",
191
+ props.poster
192
+ ],
193
+ [
194
+ "set",
195
+ "started",
196
+ started
197
+ ],
198
+ [
199
+ "set",
200
+ "playing",
201
+ playing
202
+ ],
203
+ [
204
+ "set",
205
+ "position",
206
+ position
207
+ ],
208
+ [
209
+ "set",
210
+ "duration",
211
+ duration
212
+ ],
213
+ [
214
+ "set",
215
+ "muted",
216
+ muted
217
+ ],
218
+ [
219
+ "set",
220
+ "onTogglePlay",
221
+ togglePlay
222
+ ],
223
+ [
224
+ "set",
225
+ "onToggleMute",
226
+ () => {
227
+ const next = !muted;
228
+ setInternalMuted(next);
229
+ if (host.current) host.current.muted = next;
230
+ props.onMutedChange?.(next);
231
+ }
232
+ ],
233
+ [
234
+ "set",
235
+ "onSeek",
236
+ (ms) => {
237
+ if (host.current) {
238
+ host.current.seekToTime(ms / 1e3);
239
+ setPosition(ms);
240
+ }
241
+ }
242
+ ]
243
+ ]))]);
244
+ })
245
+ ]);
246
+ }, { "module": "@nativescript-community/octane" });
247
+ //#endregion
248
+ export { Video$1 as Video };
@@ -0,0 +1,11 @@
1
+ //#region src/cx.mobile.ts
2
+ /** NS `className` splits on ' ' only, and the universal driver applies the
3
+ * prop via `String(value)` — an array would arrive comma-joined and match
4
+ * no class at all. Native leaves normalize through cx() before handing
5
+ * className to an intrinsic. (The DOM renderer already flattens arrays,
6
+ * so web leaves don't need this.) */
7
+ function cx(...parts) {
8
+ return parts.flat(Infinity).filter(Boolean).join(" ");
9
+ }
10
+ //#endregion
11
+ export { cx };
@@ -0,0 +1,39 @@
1
+ import { isAndroid, isIOS } from "@nativescript/core";
2
+ //#region src/escape-props.ts
3
+ /** Apply only the active device's escape bag after the primitive's own props. */
4
+ function applyEscapeProps(view, props) {
5
+ if (!view) return;
6
+ const bag = isIOS ? props.ios : isAndroid ? props.android : void 0;
7
+ if (bag) Object.assign(view, bag);
8
+ }
9
+ var NATIVE_ACCESSIBILITY_ROLES = {
10
+ button: "button",
11
+ link: "link",
12
+ search: "search",
13
+ image: "image",
14
+ heading: "header",
15
+ adjustable: "adjustable",
16
+ summary: "summary",
17
+ text: "text",
18
+ none: "none",
19
+ progressbar: "progressBar",
20
+ checkbox: "checkbox",
21
+ switch: "switch",
22
+ radio: "radioButton",
23
+ spinbutton: "spinButton",
24
+ tab: "button"
25
+ };
26
+ /** Translate the shared/ARIA spelling to NativeScript's narrower role enum. */
27
+ function nativeAccessibilityRole(role) {
28
+ return role ? NATIVE_ACCESSIBILITY_ROLES[role] : void 0;
29
+ }
30
+ /** NativeScript's AccessibilityState is a single enum value, unlike the
31
+ * web's independent ARIA booleans. Priority follows the strongest state. */
32
+ function nativeAccessibilityState(state) {
33
+ if (state?.disabled) return "disabled";
34
+ if (state?.selected) return "selected";
35
+ if (state?.checked === true) return "checked";
36
+ if (state?.checked === false) return "unchecked";
37
+ }
38
+ //#endregion
39
+ export { applyEscapeProps, nativeAccessibilityRole, nativeAccessibilityState };
@@ -0,0 +1,2 @@
1
+ import { Video } from "./Video.tsrx.js";
2
+ export { Video };
@@ -0,0 +1,38 @@
1
+ //#region src/layout-child.ts
2
+ var FLEX_JUSTIFY = {
3
+ start: "flex-start",
4
+ end: "flex-end"
5
+ };
6
+ var FLEX_ALIGN = {
7
+ start: "flex-start",
8
+ end: "flex-end"
9
+ };
10
+ /** NativeScript reads these attributes from each child view during parent
11
+ * layout. Values are forwarded with NativeScript's own property names.
12
+ * The flex-container props (justifyContent/alignItems/flexWrap/gap) land on
13
+ * the host flexboxlayout itself — its own attributes, not child metadata. */
14
+ function layoutChildProps(props) {
15
+ const result = {};
16
+ for (const key of [
17
+ "row",
18
+ "col",
19
+ "rowSpan",
20
+ "colSpan",
21
+ "dock",
22
+ "left",
23
+ "top",
24
+ "flexGrow",
25
+ "flexShrink",
26
+ "alignSelf",
27
+ "order"
28
+ ]) if (props[key] !== void 0) result[key] = props[key];
29
+ if (props.justifyContent !== void 0) result.justifyContent = FLEX_JUSTIFY[props.justifyContent] ?? props.justifyContent;
30
+ if (props.alignItems !== void 0) result.alignItems = FLEX_ALIGN[props.alignItems] ?? props.alignItems;
31
+ if (props.flexWrap !== void 0) result.flexWrap = props.flexWrap === true ? "wrap" : props.flexWrap === false ? "nowrap" : props.flexWrap;
32
+ if (props.gap !== void 0) result.gap = props.gap;
33
+ if (props.rowGap !== void 0) result.rowGap = props.rowGap;
34
+ if (props.columnGap !== void 0) result.columnGap = props.columnGap;
35
+ return result;
36
+ }
37
+ //#endregion
38
+ export { layoutChildProps };
@@ -0,0 +1,8 @@
1
+ {
2
+ "version": 1,
3
+ "buildId": "c46144e7-caa2-46d1-aeca-5dc907c075f3",
4
+ "mode": "production",
5
+ "capabilities": {
6
+ "independentHydration": false
7
+ }
8
+ }
@@ -0,0 +1,359 @@
1
+ import { defineUniversalComponent, hookSlots, universalChildren, universalComponent, universalIf, universalPlan, universalProps, universalValue, useEffect, useState } from "@nativescript-community/octane";
2
+ import { Icon, Image, Pressable, Row, Slider, Text, View } from "@octane-xplat/ui";
3
+ //#region src/video-chrome.tsrx
4
+ var _hs$ = /* @__PURE__ */ hookSlots(2);
5
+ var _h$0 = /* @__PURE__ */ Symbol(_hs$);
6
+ var _h$1 = /* @__PURE__ */ Symbol(_hs$ + 1);
7
+ var __octaneUniversalPlan0 = universalPlan("nativescript", {
8
+ "kind": "slot",
9
+ "slot": 0
10
+ });
11
+ var __octaneUniversalPlan1 = universalPlan("nativescript", {
12
+ "kind": "slot",
13
+ "slot": 0
14
+ });
15
+ var __octaneUniversalPlan2 = universalPlan("nativescript", {
16
+ "kind": "slot",
17
+ "slot": 0
18
+ });
19
+ var __octaneUniversalPlan3 = universalPlan("nativescript", {
20
+ "kind": "slot",
21
+ "slot": 0
22
+ });
23
+ var __octaneUniversalPlan4 = universalPlan("nativescript", {
24
+ "kind": "slot",
25
+ "slot": 0
26
+ });
27
+ var __octaneUniversalPlan5 = universalPlan("nativescript", {
28
+ "kind": "slot",
29
+ "slot": 0
30
+ });
31
+ var __octaneUniversalPlan6 = universalPlan("nativescript", {
32
+ "kind": "range",
33
+ "children": [
34
+ {
35
+ "kind": "slot",
36
+ "slot": 0
37
+ },
38
+ {
39
+ "kind": "slot",
40
+ "slot": 1
41
+ },
42
+ {
43
+ "kind": "slot",
44
+ "slot": 2
45
+ },
46
+ {
47
+ "kind": "slot",
48
+ "slot": 3
49
+ },
50
+ {
51
+ "kind": "slot",
52
+ "slot": 4
53
+ }
54
+ ]
55
+ });
56
+ var __octaneUniversalPlan7 = universalPlan("nativescript", {
57
+ "kind": "slot",
58
+ "slot": 0
59
+ });
60
+ var __octaneUniversalPlan8 = universalPlan("nativescript", {
61
+ "kind": "range",
62
+ "children": [{
63
+ "kind": "slot",
64
+ "slot": 0
65
+ }, {
66
+ "kind": "slot",
67
+ "slot": 1
68
+ }]
69
+ });
70
+ var __octaneUniversalPlan9 = universalPlan("nativescript", {
71
+ "kind": "range",
72
+ "children": [
73
+ {
74
+ "kind": "slot",
75
+ "slot": 0
76
+ },
77
+ {
78
+ "kind": "slot",
79
+ "slot": 1
80
+ },
81
+ {
82
+ "kind": "slot",
83
+ "slot": 2
84
+ }
85
+ ]
86
+ });
87
+ function stamp(ms) {
88
+ const total = Math.max(0, Math.floor(ms / 1e3));
89
+ return `${Math.floor(total / 60)}:${String(total % 60).padStart(2, "0")}`;
90
+ }
91
+ var VideoChrome = defineUniversalComponent("nativescript", function VideoChrome(props) {
92
+ const [visible, setVisible] = useState(true, _h$0);
93
+ useEffect(() => {
94
+ if (!props.playing || !visible) return;
95
+ const t = setTimeout(() => setVisible(false), 2500);
96
+ return () => clearTimeout(t);
97
+ }, [props.playing, visible], _h$1);
98
+ return universalValue(__octaneUniversalPlan9, [
99
+ universalIf(props.poster && !props.started, () => {
100
+ return universalValue(__octaneUniversalPlan0, [universalComponent("nativescript", Image, universalProps([
101
+ [
102
+ "set",
103
+ "className",
104
+ "vx-video-poster"
105
+ ],
106
+ [
107
+ "set",
108
+ "src",
109
+ props.poster
110
+ ],
111
+ [
112
+ "set",
113
+ "ios",
114
+ { stretch: "aspectFill" }
115
+ ],
116
+ [
117
+ "set",
118
+ "android",
119
+ { stretch: "aspectFill" }
120
+ ]
121
+ ]))]);
122
+ }),
123
+ universalComponent("nativescript", Pressable, universalProps([
124
+ [
125
+ "set",
126
+ "className",
127
+ "vx-video-tap"
128
+ ],
129
+ [
130
+ "set",
131
+ "accessibilityRole",
132
+ "button"
133
+ ],
134
+ [
135
+ "set",
136
+ "accessibilityLabel",
137
+ visible ? "Hide video controls" : "Show video controls"
138
+ ],
139
+ [
140
+ "set",
141
+ "onPress",
142
+ () => setVisible(props.playing ? !visible : true)
143
+ ]
144
+ ])),
145
+ universalIf(visible, () => {
146
+ return universalValue(__octaneUniversalPlan8, [universalIf(!props.playing, () => {
147
+ return universalValue(__octaneUniversalPlan3, [universalComponent("nativescript", Pressable, universalProps([
148
+ [
149
+ "set",
150
+ "className",
151
+ "vx-video-center"
152
+ ],
153
+ [
154
+ "set",
155
+ "justifyContent",
156
+ "center"
157
+ ],
158
+ [
159
+ "set",
160
+ "alignItems",
161
+ "center"
162
+ ],
163
+ [
164
+ "set",
165
+ "accessibilityRole",
166
+ "button"
167
+ ],
168
+ [
169
+ "set",
170
+ "accessibilityLabel",
171
+ "Play"
172
+ ],
173
+ [
174
+ "set",
175
+ "onPress",
176
+ props.onTogglePlay
177
+ ]
178
+ ], universalChildren("nativescript", () => {
179
+ return universalValue(__octaneUniversalPlan2, [universalComponent("nativescript", View, universalProps([[
180
+ "set",
181
+ "className",
182
+ "vx-video-centerbtn"
183
+ ]], universalChildren("nativescript", () => {
184
+ return universalValue(__octaneUniversalPlan1, [universalComponent("nativescript", Icon, universalProps([
185
+ [
186
+ "set",
187
+ "name",
188
+ "xplat-play"
189
+ ],
190
+ [
191
+ "set",
192
+ "size",
193
+ 28
194
+ ],
195
+ [
196
+ "set",
197
+ "color",
198
+ "#fff"
199
+ ]
200
+ ]))]);
201
+ })))]);
202
+ })))]);
203
+ }), universalComponent("nativescript", View, universalProps([[
204
+ "set",
205
+ "className",
206
+ "vx-video-barwrap"
207
+ ], [
208
+ "set",
209
+ "justifyContent",
210
+ "end"
211
+ ]], universalChildren("nativescript", () => {
212
+ return universalValue(__octaneUniversalPlan7, [universalComponent("nativescript", Row, universalProps([
213
+ [
214
+ "set",
215
+ "className",
216
+ "vx-video-bar"
217
+ ],
218
+ [
219
+ "set",
220
+ "alignItems",
221
+ "center"
222
+ ],
223
+ [
224
+ "set",
225
+ "gap",
226
+ 8
227
+ ]
228
+ ], universalChildren("nativescript", () => {
229
+ return universalValue(__octaneUniversalPlan6, [
230
+ universalComponent("nativescript", Pressable, universalProps([
231
+ [
232
+ "set",
233
+ "className",
234
+ "vx-video-btn"
235
+ ],
236
+ [
237
+ "set",
238
+ "accessibilityRole",
239
+ "button"
240
+ ],
241
+ [
242
+ "set",
243
+ "accessibilityLabel",
244
+ props.playing ? "Pause" : "Play"
245
+ ],
246
+ [
247
+ "set",
248
+ "onPress",
249
+ props.onTogglePlay
250
+ ]
251
+ ], universalChildren("nativescript", () => {
252
+ return universalValue(__octaneUniversalPlan4, [universalComponent("nativescript", Icon, universalProps([
253
+ [
254
+ "set",
255
+ "name",
256
+ props.playing ? "xplat-pause" : "xplat-play"
257
+ ],
258
+ [
259
+ "set",
260
+ "size",
261
+ 20
262
+ ],
263
+ [
264
+ "set",
265
+ "color",
266
+ "#fff"
267
+ ]
268
+ ]))]);
269
+ }))),
270
+ universalComponent("nativescript", Text, universalProps([[
271
+ "set",
272
+ "className",
273
+ "vx-video-time"
274
+ ]], stamp(props.position))),
275
+ universalComponent("nativescript", Slider, universalProps([
276
+ [
277
+ "set",
278
+ "className",
279
+ "vx-video-slider"
280
+ ],
281
+ [
282
+ "set",
283
+ "style",
284
+ { flexGrow: 1 }
285
+ ],
286
+ [
287
+ "set",
288
+ "value",
289
+ props.position
290
+ ],
291
+ [
292
+ "set",
293
+ "minValue",
294
+ 0
295
+ ],
296
+ [
297
+ "set",
298
+ "maxValue",
299
+ props.duration > 0 ? props.duration : 1
300
+ ],
301
+ [
302
+ "set",
303
+ "onValueChange",
304
+ props.onSeek
305
+ ]
306
+ ])),
307
+ universalComponent("nativescript", Text, universalProps([[
308
+ "set",
309
+ "className",
310
+ "vx-video-time"
311
+ ]], stamp(props.duration))),
312
+ universalComponent("nativescript", Pressable, universalProps([
313
+ [
314
+ "set",
315
+ "className",
316
+ "vx-video-btn"
317
+ ],
318
+ [
319
+ "set",
320
+ "accessibilityRole",
321
+ "button"
322
+ ],
323
+ [
324
+ "set",
325
+ "accessibilityLabel",
326
+ props.muted ? "Unmute" : "Mute"
327
+ ],
328
+ [
329
+ "set",
330
+ "onPress",
331
+ props.onToggleMute
332
+ ]
333
+ ], universalChildren("nativescript", () => {
334
+ return universalValue(__octaneUniversalPlan5, [universalComponent("nativescript", Icon, universalProps([
335
+ [
336
+ "set",
337
+ "name",
338
+ props.muted ? "xplat-volume-off" : "xplat-volume"
339
+ ],
340
+ [
341
+ "set",
342
+ "size",
343
+ 20
344
+ ],
345
+ [
346
+ "set",
347
+ "color",
348
+ "#fff"
349
+ ]
350
+ ]))]);
351
+ })))
352
+ ]);
353
+ })))]);
354
+ })))]);
355
+ })
356
+ ]);
357
+ }, { "module": "@nativescript-community/octane" });
358
+ //#endregion
359
+ export { VideoChrome };