@scarlett-player/gestures 1.8.1 → 1.10.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/dist/index.cjs +31 -16
- package/dist/index.d.cts +7 -1
- package/dist/index.d.ts +7 -1
- package/dist/index.js +31 -16
- package/package.json +3 -3
package/dist/index.cjs
CHANGED
|
@@ -178,6 +178,7 @@ function createRecognizer(options = {}) {
|
|
|
178
178
|
}
|
|
179
179
|
|
|
180
180
|
// src/overlay.ts
|
|
181
|
+
var import_core = require("@scarlett-player/core");
|
|
181
182
|
var STYLE_ID = "sp-gestures-styles";
|
|
182
183
|
var styles = `
|
|
183
184
|
.sp-gestures {
|
|
@@ -250,7 +251,7 @@ var GestureOverlay = class {
|
|
|
250
251
|
constructor(container, options) {
|
|
251
252
|
this.container = container;
|
|
252
253
|
this.options = options;
|
|
253
|
-
this.
|
|
254
|
+
this.releaseStyles = null;
|
|
254
255
|
this.hideTimer = null;
|
|
255
256
|
this.pointerHandler = (event) => {
|
|
256
257
|
if (event.pointerType !== "touch") return;
|
|
@@ -325,8 +326,8 @@ var GestureOverlay = class {
|
|
|
325
326
|
this.el.removeEventListener("pointerup", this.pointerHandler);
|
|
326
327
|
this.el.removeEventListener("pointercancel", this.pointerHandler);
|
|
327
328
|
this.el.remove();
|
|
328
|
-
this.
|
|
329
|
-
this.
|
|
329
|
+
this.releaseStyles?.();
|
|
330
|
+
this.releaseStyles = null;
|
|
330
331
|
}
|
|
331
332
|
/** Exposed for tests and for hosts that want to inspect the surface. */
|
|
332
333
|
getElement() {
|
|
@@ -341,17 +342,19 @@ var GestureOverlay = class {
|
|
|
341
342
|
zone.appendChild(label);
|
|
342
343
|
return { zone, label };
|
|
343
344
|
}
|
|
345
|
+
/**
|
|
346
|
+
* Claim the shared gesture stylesheet.
|
|
347
|
+
*
|
|
348
|
+
* Reference-counted: two players on one page share the sheet, and destroying
|
|
349
|
+
* either used to take it away from the other.
|
|
350
|
+
*/
|
|
344
351
|
injectStyles() {
|
|
345
|
-
|
|
346
|
-
this.styleEl = document.createElement("style");
|
|
347
|
-
this.styleEl.id = STYLE_ID;
|
|
348
|
-
this.styleEl.textContent = styles;
|
|
349
|
-
document.head.appendChild(this.styleEl);
|
|
352
|
+
this.releaseStyles = (0, import_core.injectSharedStyles)(STYLE_ID, styles);
|
|
350
353
|
}
|
|
351
354
|
};
|
|
352
355
|
|
|
353
356
|
// src/version.ts
|
|
354
|
-
var PKG_VERSION = true ? "1.
|
|
357
|
+
var PKG_VERSION = true ? "1.10.0" : "0.0.0-dev";
|
|
355
358
|
|
|
356
359
|
// src/index.ts
|
|
357
360
|
function hasCoarsePointer() {
|
|
@@ -474,6 +477,19 @@ function createGesturesPlugin(config = {}) {
|
|
|
474
477
|
}
|
|
475
478
|
}
|
|
476
479
|
};
|
|
480
|
+
const syncSurface = () => {
|
|
481
|
+
if (!active || !api) return;
|
|
482
|
+
const wantsSurface = api.getState("mediaType") !== "audio";
|
|
483
|
+
if (wantsSurface && !overlay) {
|
|
484
|
+
overlay = new GestureOverlay(api.container, { onPointer, feedback });
|
|
485
|
+
overlay.setZoneWidths(leftZone, rightZone);
|
|
486
|
+
} else if (!wantsSurface && overlay) {
|
|
487
|
+
clearPendingHide();
|
|
488
|
+
overlay.destroy();
|
|
489
|
+
overlay = null;
|
|
490
|
+
recognizer?.reset();
|
|
491
|
+
}
|
|
492
|
+
};
|
|
477
493
|
return {
|
|
478
494
|
id: "gestures",
|
|
479
495
|
name: "Gestures",
|
|
@@ -487,10 +503,6 @@ function createGesturesPlugin(config = {}) {
|
|
|
487
503
|
api.logger.debug("[gestures] no coarse pointer, gesture surface not installed");
|
|
488
504
|
return;
|
|
489
505
|
}
|
|
490
|
-
if (api.getState("mediaType") === "audio") {
|
|
491
|
-
active = false;
|
|
492
|
-
return;
|
|
493
|
-
}
|
|
494
506
|
recognizer = createRecognizer({
|
|
495
507
|
doubleTapWindowMs,
|
|
496
508
|
accumulationWindowMs: config.accumulationWindowMs,
|
|
@@ -498,9 +510,12 @@ function createGesturesPlugin(config = {}) {
|
|
|
498
510
|
rightZone,
|
|
499
511
|
slopPx: config.slopPx
|
|
500
512
|
});
|
|
501
|
-
|
|
502
|
-
|
|
513
|
+
syncSurface();
|
|
514
|
+
const unsubscribe = api.subscribeToState((event) => {
|
|
515
|
+
if (event.key === "mediaType") syncSurface();
|
|
516
|
+
});
|
|
503
517
|
api.onDestroy(() => {
|
|
518
|
+
unsubscribe();
|
|
504
519
|
clearPendingHide();
|
|
505
520
|
overlay?.destroy();
|
|
506
521
|
overlay = null;
|
|
@@ -519,7 +534,7 @@ function createGesturesPlugin(config = {}) {
|
|
|
519
534
|
api = null;
|
|
520
535
|
},
|
|
521
536
|
ownsTapInteraction() {
|
|
522
|
-
return active && tapToToggleControls;
|
|
537
|
+
return active && tapToToggleControls && overlay !== null;
|
|
523
538
|
}
|
|
524
539
|
};
|
|
525
540
|
}
|
package/dist/index.d.cts
CHANGED
|
@@ -201,7 +201,7 @@ declare class GestureOverlay {
|
|
|
201
201
|
private zones;
|
|
202
202
|
private labels;
|
|
203
203
|
private live;
|
|
204
|
-
private
|
|
204
|
+
private releaseStyles;
|
|
205
205
|
private hideTimer;
|
|
206
206
|
private readonly pointerHandler;
|
|
207
207
|
constructor(container: HTMLElement, options: OverlayOptions);
|
|
@@ -220,6 +220,12 @@ declare class GestureOverlay {
|
|
|
220
220
|
/** Exposed for tests and for hosts that want to inspect the surface. */
|
|
221
221
|
getElement(): HTMLElement;
|
|
222
222
|
private createZone;
|
|
223
|
+
/**
|
|
224
|
+
* Claim the shared gesture stylesheet.
|
|
225
|
+
*
|
|
226
|
+
* Reference-counted: two players on one page share the sheet, and destroying
|
|
227
|
+
* either used to take it away from the other.
|
|
228
|
+
*/
|
|
223
229
|
private injectStyles;
|
|
224
230
|
}
|
|
225
231
|
|
package/dist/index.d.ts
CHANGED
|
@@ -201,7 +201,7 @@ declare class GestureOverlay {
|
|
|
201
201
|
private zones;
|
|
202
202
|
private labels;
|
|
203
203
|
private live;
|
|
204
|
-
private
|
|
204
|
+
private releaseStyles;
|
|
205
205
|
private hideTimer;
|
|
206
206
|
private readonly pointerHandler;
|
|
207
207
|
constructor(container: HTMLElement, options: OverlayOptions);
|
|
@@ -220,6 +220,12 @@ declare class GestureOverlay {
|
|
|
220
220
|
/** Exposed for tests and for hosts that want to inspect the surface. */
|
|
221
221
|
getElement(): HTMLElement;
|
|
222
222
|
private createZone;
|
|
223
|
+
/**
|
|
224
|
+
* Claim the shared gesture stylesheet.
|
|
225
|
+
*
|
|
226
|
+
* Reference-counted: two players on one page share the sheet, and destroying
|
|
227
|
+
* either used to take it away from the other.
|
|
228
|
+
*/
|
|
223
229
|
private injectStyles;
|
|
224
230
|
}
|
|
225
231
|
|
package/dist/index.js
CHANGED
|
@@ -147,6 +147,7 @@ function createRecognizer(options = {}) {
|
|
|
147
147
|
}
|
|
148
148
|
|
|
149
149
|
// src/overlay.ts
|
|
150
|
+
import { injectSharedStyles } from "@scarlett-player/core";
|
|
150
151
|
var STYLE_ID = "sp-gestures-styles";
|
|
151
152
|
var styles = `
|
|
152
153
|
.sp-gestures {
|
|
@@ -219,7 +220,7 @@ var GestureOverlay = class {
|
|
|
219
220
|
constructor(container, options) {
|
|
220
221
|
this.container = container;
|
|
221
222
|
this.options = options;
|
|
222
|
-
this.
|
|
223
|
+
this.releaseStyles = null;
|
|
223
224
|
this.hideTimer = null;
|
|
224
225
|
this.pointerHandler = (event) => {
|
|
225
226
|
if (event.pointerType !== "touch") return;
|
|
@@ -294,8 +295,8 @@ var GestureOverlay = class {
|
|
|
294
295
|
this.el.removeEventListener("pointerup", this.pointerHandler);
|
|
295
296
|
this.el.removeEventListener("pointercancel", this.pointerHandler);
|
|
296
297
|
this.el.remove();
|
|
297
|
-
this.
|
|
298
|
-
this.
|
|
298
|
+
this.releaseStyles?.();
|
|
299
|
+
this.releaseStyles = null;
|
|
299
300
|
}
|
|
300
301
|
/** Exposed for tests and for hosts that want to inspect the surface. */
|
|
301
302
|
getElement() {
|
|
@@ -310,17 +311,19 @@ var GestureOverlay = class {
|
|
|
310
311
|
zone.appendChild(label);
|
|
311
312
|
return { zone, label };
|
|
312
313
|
}
|
|
314
|
+
/**
|
|
315
|
+
* Claim the shared gesture stylesheet.
|
|
316
|
+
*
|
|
317
|
+
* Reference-counted: two players on one page share the sheet, and destroying
|
|
318
|
+
* either used to take it away from the other.
|
|
319
|
+
*/
|
|
313
320
|
injectStyles() {
|
|
314
|
-
|
|
315
|
-
this.styleEl = document.createElement("style");
|
|
316
|
-
this.styleEl.id = STYLE_ID;
|
|
317
|
-
this.styleEl.textContent = styles;
|
|
318
|
-
document.head.appendChild(this.styleEl);
|
|
321
|
+
this.releaseStyles = injectSharedStyles(STYLE_ID, styles);
|
|
319
322
|
}
|
|
320
323
|
};
|
|
321
324
|
|
|
322
325
|
// src/version.ts
|
|
323
|
-
var PKG_VERSION = true ? "1.
|
|
326
|
+
var PKG_VERSION = true ? "1.10.0" : "0.0.0-dev";
|
|
324
327
|
|
|
325
328
|
// src/index.ts
|
|
326
329
|
function hasCoarsePointer() {
|
|
@@ -443,6 +446,19 @@ function createGesturesPlugin(config = {}) {
|
|
|
443
446
|
}
|
|
444
447
|
}
|
|
445
448
|
};
|
|
449
|
+
const syncSurface = () => {
|
|
450
|
+
if (!active || !api) return;
|
|
451
|
+
const wantsSurface = api.getState("mediaType") !== "audio";
|
|
452
|
+
if (wantsSurface && !overlay) {
|
|
453
|
+
overlay = new GestureOverlay(api.container, { onPointer, feedback });
|
|
454
|
+
overlay.setZoneWidths(leftZone, rightZone);
|
|
455
|
+
} else if (!wantsSurface && overlay) {
|
|
456
|
+
clearPendingHide();
|
|
457
|
+
overlay.destroy();
|
|
458
|
+
overlay = null;
|
|
459
|
+
recognizer?.reset();
|
|
460
|
+
}
|
|
461
|
+
};
|
|
446
462
|
return {
|
|
447
463
|
id: "gestures",
|
|
448
464
|
name: "Gestures",
|
|
@@ -456,10 +472,6 @@ function createGesturesPlugin(config = {}) {
|
|
|
456
472
|
api.logger.debug("[gestures] no coarse pointer, gesture surface not installed");
|
|
457
473
|
return;
|
|
458
474
|
}
|
|
459
|
-
if (api.getState("mediaType") === "audio") {
|
|
460
|
-
active = false;
|
|
461
|
-
return;
|
|
462
|
-
}
|
|
463
475
|
recognizer = createRecognizer({
|
|
464
476
|
doubleTapWindowMs,
|
|
465
477
|
accumulationWindowMs: config.accumulationWindowMs,
|
|
@@ -467,9 +479,12 @@ function createGesturesPlugin(config = {}) {
|
|
|
467
479
|
rightZone,
|
|
468
480
|
slopPx: config.slopPx
|
|
469
481
|
});
|
|
470
|
-
|
|
471
|
-
|
|
482
|
+
syncSurface();
|
|
483
|
+
const unsubscribe = api.subscribeToState((event) => {
|
|
484
|
+
if (event.key === "mediaType") syncSurface();
|
|
485
|
+
});
|
|
472
486
|
api.onDestroy(() => {
|
|
487
|
+
unsubscribe();
|
|
473
488
|
clearPendingHide();
|
|
474
489
|
overlay?.destroy();
|
|
475
490
|
overlay = null;
|
|
@@ -488,7 +503,7 @@ function createGesturesPlugin(config = {}) {
|
|
|
488
503
|
api = null;
|
|
489
504
|
},
|
|
490
505
|
ownsTapInteraction() {
|
|
491
|
-
return active && tapToToggleControls;
|
|
506
|
+
return active && tapToToggleControls && overlay !== null;
|
|
492
507
|
}
|
|
493
508
|
};
|
|
494
509
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@scarlett-player/gestures",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.10.0",
|
|
4
4
|
"description": "Gestures Plugin for Scarlett Player - double-tap seek zones and tap to toggle controls",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "dist/index.cjs",
|
|
@@ -22,7 +22,7 @@
|
|
|
22
22
|
"dist"
|
|
23
23
|
],
|
|
24
24
|
"peerDependencies": {
|
|
25
|
-
"@scarlett-player/core": "^1.
|
|
25
|
+
"@scarlett-player/core": "^1.9.0"
|
|
26
26
|
},
|
|
27
27
|
"devDependencies": {
|
|
28
28
|
"@vitest/coverage-v8": "^1.6.0",
|
|
@@ -30,7 +30,7 @@
|
|
|
30
30
|
"tsup": "^8.5.1",
|
|
31
31
|
"typescript": "^5.3.0",
|
|
32
32
|
"vitest": "^1.6.0",
|
|
33
|
-
"@scarlett-player/core": "1.
|
|
33
|
+
"@scarlett-player/core": "1.10.0"
|
|
34
34
|
},
|
|
35
35
|
"keywords": [
|
|
36
36
|
"video",
|