native-fn 1.1.8 → 1.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.
- package/README.md +2705 -21
- package/dist/index.d.ts +130 -117
- package/dist/native.cjs +581 -563
- package/dist/native.min.cjs +1 -1
- package/dist/native.min.mjs +1 -1
- package/dist/native.mjs +581 -563
- package/dist/native.umd.js +581 -563
- package/dist/native.umd.min.js +1 -1
- package/dist/plugin/appearance/src/errors/invalid-state-error.d.ts +2 -0
- package/dist/plugin/appearance/src/plugin/badge/types/badge.d.ts +1 -1
- package/dist/plugin/appearance/src/plugin/battery/types/battery.d.ts +1 -1
- package/dist/plugin/appearance/src/plugin/fullscreen/cores/index.d.ts +3 -3
- package/dist/plugin/appearance/src/plugin/fullscreen/types/fullscreen.d.ts +9 -3
- package/dist/plugin/appearance/src/plugin/geolocation/types/geolocation.d.ts +1 -1
- package/dist/plugin/appearance/src/plugin/open/types/open.d.ts +1 -1
- package/dist/plugin/appearance/src/plugin/permission/types/permission.d.ts +1 -0
- package/dist/plugin/appearance/src/plugin/pip/cores/index.d.ts +6 -6
- package/dist/plugin/appearance/src/plugin/pip/types/pip.d.ts +12 -6
- package/dist/plugin/appearance/src/plugin/vibration/types/vibration.d.ts +1 -1
- package/dist/plugin/badge/index.cjs +2 -2
- package/dist/plugin/badge/index.d.ts +1 -1
- package/dist/plugin/badge/index.mjs +2 -2
- package/dist/plugin/badge/src/errors/invalid-state-error.d.ts +2 -0
- package/dist/plugin/badge/src/plugin/badge/types/badge.d.ts +1 -1
- package/dist/plugin/badge/src/plugin/battery/types/battery.d.ts +1 -1
- package/dist/plugin/badge/src/plugin/fullscreen/cores/index.d.ts +3 -3
- package/dist/plugin/badge/src/plugin/fullscreen/types/fullscreen.d.ts +9 -3
- package/dist/plugin/badge/src/plugin/geolocation/types/geolocation.d.ts +1 -1
- package/dist/plugin/badge/src/plugin/open/types/open.d.ts +1 -1
- package/dist/plugin/badge/src/plugin/permission/types/permission.d.ts +1 -0
- package/dist/plugin/badge/src/plugin/pip/cores/index.d.ts +6 -6
- package/dist/plugin/badge/src/plugin/pip/types/pip.d.ts +12 -6
- package/dist/plugin/badge/src/plugin/vibration/types/vibration.d.ts +1 -1
- package/dist/plugin/battery/index.cjs +3 -3
- package/dist/plugin/battery/index.d.ts +1 -1
- package/dist/plugin/battery/index.mjs +3 -3
- package/dist/plugin/battery/src/errors/invalid-state-error.d.ts +2 -0
- package/dist/plugin/battery/src/plugin/badge/types/badge.d.ts +1 -1
- package/dist/plugin/battery/src/plugin/battery/types/battery.d.ts +1 -1
- package/dist/plugin/battery/src/plugin/fullscreen/cores/index.d.ts +3 -3
- package/dist/plugin/battery/src/plugin/fullscreen/types/fullscreen.d.ts +9 -3
- package/dist/plugin/battery/src/plugin/geolocation/types/geolocation.d.ts +1 -1
- package/dist/plugin/battery/src/plugin/open/types/open.d.ts +1 -1
- package/dist/plugin/battery/src/plugin/permission/types/permission.d.ts +1 -0
- package/dist/plugin/battery/src/plugin/pip/cores/index.d.ts +6 -6
- package/dist/plugin/battery/src/plugin/pip/types/pip.d.ts +12 -6
- package/dist/plugin/battery/src/plugin/vibration/types/vibration.d.ts +1 -1
- package/dist/plugin/clipboard/src/errors/invalid-state-error.d.ts +2 -0
- package/dist/plugin/clipboard/src/plugin/badge/types/badge.d.ts +1 -1
- package/dist/plugin/clipboard/src/plugin/battery/types/battery.d.ts +1 -1
- package/dist/plugin/clipboard/src/plugin/fullscreen/cores/index.d.ts +3 -3
- package/dist/plugin/clipboard/src/plugin/fullscreen/types/fullscreen.d.ts +9 -3
- package/dist/plugin/clipboard/src/plugin/geolocation/types/geolocation.d.ts +1 -1
- package/dist/plugin/clipboard/src/plugin/open/types/open.d.ts +1 -1
- package/dist/plugin/clipboard/src/plugin/permission/types/permission.d.ts +1 -0
- package/dist/plugin/clipboard/src/plugin/pip/cores/index.d.ts +6 -6
- package/dist/plugin/clipboard/src/plugin/pip/types/pip.d.ts +12 -6
- package/dist/plugin/clipboard/src/plugin/vibration/types/vibration.d.ts +1 -1
- package/dist/plugin/dimension/src/errors/invalid-state-error.d.ts +2 -0
- package/dist/plugin/dimension/src/plugin/badge/types/badge.d.ts +1 -1
- package/dist/plugin/dimension/src/plugin/battery/types/battery.d.ts +1 -1
- package/dist/plugin/dimension/src/plugin/fullscreen/cores/index.d.ts +3 -3
- package/dist/plugin/dimension/src/plugin/fullscreen/types/fullscreen.d.ts +9 -3
- package/dist/plugin/dimension/src/plugin/geolocation/types/geolocation.d.ts +1 -1
- package/dist/plugin/dimension/src/plugin/open/types/open.d.ts +1 -1
- package/dist/plugin/dimension/src/plugin/permission/types/permission.d.ts +1 -0
- package/dist/plugin/dimension/src/plugin/pip/cores/index.d.ts +6 -6
- package/dist/plugin/dimension/src/plugin/pip/types/pip.d.ts +12 -6
- package/dist/plugin/dimension/src/plugin/vibration/types/vibration.d.ts +1 -1
- package/dist/plugin/fullscreen/index.cjs +499 -265
- package/dist/plugin/fullscreen/index.d.ts +14 -7
- package/dist/plugin/fullscreen/index.mjs +499 -265
- package/dist/plugin/fullscreen/src/errors/invalid-state-error.d.ts +2 -0
- package/dist/plugin/fullscreen/src/plugin/badge/types/badge.d.ts +1 -1
- package/dist/plugin/fullscreen/src/plugin/battery/types/battery.d.ts +1 -1
- package/dist/plugin/fullscreen/src/plugin/fullscreen/cores/index.d.ts +3 -3
- package/dist/plugin/fullscreen/src/plugin/fullscreen/types/fullscreen.d.ts +9 -3
- package/dist/plugin/fullscreen/src/plugin/geolocation/types/geolocation.d.ts +1 -1
- package/dist/plugin/fullscreen/src/plugin/open/types/open.d.ts +1 -1
- package/dist/plugin/fullscreen/src/plugin/permission/types/permission.d.ts +1 -0
- package/dist/plugin/fullscreen/src/plugin/pip/cores/index.d.ts +6 -6
- package/dist/plugin/fullscreen/src/plugin/pip/types/pip.d.ts +12 -6
- package/dist/plugin/fullscreen/src/plugin/vibration/types/vibration.d.ts +1 -1
- package/dist/plugin/geolocation/index.cjs +6 -0
- package/dist/plugin/geolocation/index.d.ts +1 -1
- package/dist/plugin/geolocation/index.mjs +6 -0
- package/dist/plugin/geolocation/src/errors/invalid-state-error.d.ts +2 -0
- package/dist/plugin/geolocation/src/plugin/badge/types/badge.d.ts +1 -1
- package/dist/plugin/geolocation/src/plugin/battery/types/battery.d.ts +1 -1
- package/dist/plugin/geolocation/src/plugin/fullscreen/cores/index.d.ts +3 -3
- package/dist/plugin/geolocation/src/plugin/fullscreen/types/fullscreen.d.ts +9 -3
- package/dist/plugin/geolocation/src/plugin/geolocation/types/geolocation.d.ts +1 -1
- package/dist/plugin/geolocation/src/plugin/open/types/open.d.ts +1 -1
- package/dist/plugin/geolocation/src/plugin/permission/types/permission.d.ts +1 -0
- package/dist/plugin/geolocation/src/plugin/pip/cores/index.d.ts +6 -6
- package/dist/plugin/geolocation/src/plugin/pip/types/pip.d.ts +12 -6
- package/dist/plugin/geolocation/src/plugin/vibration/types/vibration.d.ts +1 -1
- package/dist/plugin/notification/index.cjs +6 -0
- package/dist/plugin/notification/index.mjs +6 -0
- package/dist/plugin/notification/src/errors/invalid-state-error.d.ts +2 -0
- package/dist/plugin/notification/src/plugin/badge/types/badge.d.ts +1 -1
- package/dist/plugin/notification/src/plugin/battery/types/battery.d.ts +1 -1
- package/dist/plugin/notification/src/plugin/fullscreen/cores/index.d.ts +3 -3
- package/dist/plugin/notification/src/plugin/fullscreen/types/fullscreen.d.ts +9 -3
- package/dist/plugin/notification/src/plugin/geolocation/types/geolocation.d.ts +1 -1
- package/dist/plugin/notification/src/plugin/open/types/open.d.ts +1 -1
- package/dist/plugin/notification/src/plugin/permission/types/permission.d.ts +1 -0
- package/dist/plugin/notification/src/plugin/pip/cores/index.d.ts +6 -6
- package/dist/plugin/notification/src/plugin/pip/types/pip.d.ts +12 -6
- package/dist/plugin/notification/src/plugin/vibration/types/vibration.d.ts +1 -1
- package/dist/plugin/open/index.cjs +120 -120
- package/dist/plugin/open/index.d.ts +35 -35
- package/dist/plugin/open/index.mjs +120 -120
- package/dist/plugin/open/src/errors/invalid-state-error.d.ts +2 -0
- package/dist/plugin/open/src/plugin/badge/types/badge.d.ts +1 -1
- package/dist/plugin/open/src/plugin/battery/types/battery.d.ts +1 -1
- package/dist/plugin/open/src/plugin/fullscreen/cores/index.d.ts +3 -3
- package/dist/plugin/open/src/plugin/fullscreen/types/fullscreen.d.ts +9 -3
- package/dist/plugin/open/src/plugin/geolocation/types/geolocation.d.ts +1 -1
- package/dist/plugin/open/src/plugin/open/types/open.d.ts +1 -1
- package/dist/plugin/open/src/plugin/permission/types/permission.d.ts +1 -0
- package/dist/plugin/open/src/plugin/pip/cores/index.d.ts +6 -6
- package/dist/plugin/open/src/plugin/pip/types/pip.d.ts +12 -6
- package/dist/plugin/open/src/plugin/vibration/types/vibration.d.ts +1 -1
- package/dist/plugin/permission/index.cjs +6 -0
- package/dist/plugin/permission/index.d.ts +1 -0
- package/dist/plugin/permission/index.mjs +6 -0
- package/dist/plugin/permission/src/errors/invalid-state-error.d.ts +2 -0
- package/dist/plugin/permission/src/plugin/badge/types/badge.d.ts +1 -1
- package/dist/plugin/permission/src/plugin/battery/types/battery.d.ts +1 -1
- package/dist/plugin/permission/src/plugin/fullscreen/cores/index.d.ts +3 -3
- package/dist/plugin/permission/src/plugin/fullscreen/types/fullscreen.d.ts +9 -3
- package/dist/plugin/permission/src/plugin/geolocation/types/geolocation.d.ts +1 -1
- package/dist/plugin/permission/src/plugin/open/types/open.d.ts +1 -1
- package/dist/plugin/permission/src/plugin/permission/types/permission.d.ts +1 -0
- package/dist/plugin/permission/src/plugin/pip/cores/index.d.ts +6 -6
- package/dist/plugin/permission/src/plugin/pip/types/pip.d.ts +12 -6
- package/dist/plugin/permission/src/plugin/vibration/types/vibration.d.ts +1 -1
- package/dist/plugin/pip/index.cjs +255 -273
- package/dist/plugin/pip/index.d.ts +20 -13
- package/dist/plugin/pip/index.mjs +255 -273
- package/dist/plugin/pip/src/errors/invalid-state-error.d.ts +2 -0
- package/dist/plugin/pip/src/plugin/badge/types/badge.d.ts +1 -1
- package/dist/plugin/pip/src/plugin/battery/types/battery.d.ts +1 -1
- package/dist/plugin/pip/src/plugin/fullscreen/cores/index.d.ts +3 -3
- package/dist/plugin/pip/src/plugin/fullscreen/types/fullscreen.d.ts +9 -3
- package/dist/plugin/pip/src/plugin/geolocation/types/geolocation.d.ts +1 -1
- package/dist/plugin/pip/src/plugin/open/types/open.d.ts +1 -1
- package/dist/plugin/pip/src/plugin/permission/types/permission.d.ts +1 -0
- package/dist/plugin/pip/src/plugin/pip/cores/index.d.ts +6 -6
- package/dist/plugin/pip/src/plugin/pip/types/pip.d.ts +12 -6
- package/dist/plugin/pip/src/plugin/vibration/types/vibration.d.ts +1 -1
- package/dist/plugin/platform/index.d.ts +5 -5
- package/dist/plugin/platform/src/errors/invalid-state-error.d.ts +2 -0
- package/dist/plugin/platform/src/plugin/badge/types/badge.d.ts +1 -1
- package/dist/plugin/platform/src/plugin/battery/types/battery.d.ts +1 -1
- package/dist/plugin/platform/src/plugin/fullscreen/cores/index.d.ts +3 -3
- package/dist/plugin/platform/src/plugin/fullscreen/types/fullscreen.d.ts +9 -3
- package/dist/plugin/platform/src/plugin/geolocation/types/geolocation.d.ts +1 -1
- package/dist/plugin/platform/src/plugin/open/types/open.d.ts +1 -1
- package/dist/plugin/platform/src/plugin/permission/types/permission.d.ts +1 -0
- package/dist/plugin/platform/src/plugin/pip/cores/index.d.ts +6 -6
- package/dist/plugin/platform/src/plugin/pip/types/pip.d.ts +12 -6
- package/dist/plugin/platform/src/plugin/vibration/types/vibration.d.ts +1 -1
- package/dist/plugin/theme/src/errors/invalid-state-error.d.ts +2 -0
- package/dist/plugin/theme/src/plugin/badge/types/badge.d.ts +1 -1
- package/dist/plugin/theme/src/plugin/battery/types/battery.d.ts +1 -1
- package/dist/plugin/theme/src/plugin/fullscreen/cores/index.d.ts +3 -3
- package/dist/plugin/theme/src/plugin/fullscreen/types/fullscreen.d.ts +9 -3
- package/dist/plugin/theme/src/plugin/geolocation/types/geolocation.d.ts +1 -1
- package/dist/plugin/theme/src/plugin/open/types/open.d.ts +1 -1
- package/dist/plugin/theme/src/plugin/permission/types/permission.d.ts +1 -0
- package/dist/plugin/theme/src/plugin/pip/cores/index.d.ts +6 -6
- package/dist/plugin/theme/src/plugin/pip/types/pip.d.ts +12 -6
- package/dist/plugin/theme/src/plugin/vibration/types/vibration.d.ts +1 -1
- package/dist/plugin/vibration/index.cjs +5 -5
- package/dist/plugin/vibration/index.d.ts +1 -1
- package/dist/plugin/vibration/index.mjs +5 -5
- package/dist/plugin/vibration/src/errors/invalid-state-error.d.ts +2 -0
- package/dist/plugin/vibration/src/plugin/badge/types/badge.d.ts +1 -1
- package/dist/plugin/vibration/src/plugin/battery/types/battery.d.ts +1 -1
- package/dist/plugin/vibration/src/plugin/fullscreen/cores/index.d.ts +3 -3
- package/dist/plugin/vibration/src/plugin/fullscreen/types/fullscreen.d.ts +9 -3
- package/dist/plugin/vibration/src/plugin/geolocation/types/geolocation.d.ts +1 -1
- package/dist/plugin/vibration/src/plugin/open/types/open.d.ts +1 -1
- package/dist/plugin/vibration/src/plugin/permission/types/permission.d.ts +1 -0
- package/dist/plugin/vibration/src/plugin/pip/cores/index.d.ts +6 -6
- package/dist/plugin/vibration/src/plugin/pip/types/pip.d.ts +12 -6
- package/dist/plugin/vibration/src/plugin/vibration/types/vibration.d.ts +1 -1
- package/dist/src/errors/invalid-state-error.d.ts +2 -0
- package/dist/src/plugin/badge/types/badge.d.ts +1 -1
- package/dist/src/plugin/battery/types/battery.d.ts +1 -1
- package/dist/src/plugin/fullscreen/cores/index.d.ts +3 -3
- package/dist/src/plugin/fullscreen/types/fullscreen.d.ts +9 -3
- package/dist/src/plugin/geolocation/types/geolocation.d.ts +1 -1
- package/dist/src/plugin/open/types/open.d.ts +1 -1
- package/dist/src/plugin/permission/types/permission.d.ts +1 -0
- package/dist/src/plugin/pip/cores/index.d.ts +6 -6
- package/dist/src/plugin/pip/types/pip.d.ts +12 -6
- package/dist/src/plugin/vibration/types/vibration.d.ts +1 -1
- package/package.json +21 -13
|
@@ -348,301 +348,283 @@ function createCustomError(name, Base) {
|
|
|
348
348
|
|
|
349
349
|
var NotSupportedError = createCustomError('NotSupportedError');
|
|
350
350
|
|
|
351
|
-
var
|
|
351
|
+
var InvalidStateError = createCustomError('InvalidStateError');
|
|
352
|
+
|
|
352
353
|
var PIP_PRESENTATION_MODE = 'picture-in-picture';
|
|
353
354
|
var INLINE_PRESENTATION_MODE = 'inline';
|
|
354
|
-
|
|
355
|
+
var lastPipVideo = null;
|
|
356
|
+
var eventsBridged = false;
|
|
357
|
+
var PIP_BRIDGE_KEY = (function () {
|
|
358
|
+
if (typeof Symbol === 'function') {
|
|
359
|
+
var existing = globalThis.__nativeFnPipBridgeKey__;
|
|
360
|
+
if (typeof existing === 'symbol')
|
|
361
|
+
return existing;
|
|
362
|
+
return globalThis.__nativeFnPipBridgeKey__ = Symbol('native.fn.pip.bridged');
|
|
363
|
+
}
|
|
364
|
+
return '__nativeFnPipBridged__';
|
|
365
|
+
}());
|
|
366
|
+
var onChangeSubscriptionManager = createSubscriptionManager(attachOnChange, detachOnChange);
|
|
367
|
+
var onErrorSubscriptionManager = createSubscriptionManager(attachOnError, detachOnError);
|
|
368
|
+
var Pip = {
|
|
369
|
+
get supported() {
|
|
370
|
+
return getEnabled();
|
|
371
|
+
},
|
|
372
|
+
get element() {
|
|
373
|
+
return getElement();
|
|
374
|
+
},
|
|
375
|
+
get isPip() {
|
|
376
|
+
return getIsPip();
|
|
377
|
+
},
|
|
378
|
+
request: request,
|
|
379
|
+
exit: exit,
|
|
380
|
+
onChange: onChangeSubscriptionManager.subscribe,
|
|
381
|
+
onError: onErrorSubscriptionManager.subscribe,
|
|
382
|
+
Constants: {},
|
|
383
|
+
Errors: {
|
|
384
|
+
NotSupportedError: NotSupportedError,
|
|
385
|
+
InvalidStateError: InvalidStateError,
|
|
386
|
+
},
|
|
387
|
+
};
|
|
388
|
+
function hasStandardApi() {
|
|
355
389
|
return typeof globalThis.document.pictureInPictureEnabled !== 'undefined';
|
|
356
390
|
}
|
|
357
|
-
function
|
|
358
|
-
var
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
return
|
|
391
|
+
function getDefaultTarget() {
|
|
392
|
+
var video = globalThis.document.querySelector('video');
|
|
393
|
+
return video !== null ? video : undefined;
|
|
394
|
+
}
|
|
395
|
+
function createPipEventPayload(nativeEvent, element, isPip) {
|
|
396
|
+
return {
|
|
397
|
+
nativeEvent: nativeEvent,
|
|
398
|
+
element: element,
|
|
399
|
+
isPip: isPip
|
|
400
|
+
};
|
|
401
|
+
}
|
|
402
|
+
function emitChange(nativeEvent, element, isPip) {
|
|
403
|
+
onChangeSubscriptionManager.emit(createPipEventPayload(nativeEvent, element, isPip));
|
|
404
|
+
}
|
|
405
|
+
function emitError(nativeEvent, element, isPip) {
|
|
406
|
+
onErrorSubscriptionManager.emit(createPipEventPayload(nativeEvent, element, isPip));
|
|
407
|
+
}
|
|
408
|
+
function onEnterPictureInPicture(event) {
|
|
409
|
+
var target = event.target;
|
|
410
|
+
if (target instanceof globalThis.HTMLVideoElement)
|
|
411
|
+
emitChange(event, target, true);
|
|
412
|
+
}
|
|
413
|
+
function onLeavePictureInPicture(event) {
|
|
414
|
+
var target = event.target;
|
|
415
|
+
if (target instanceof globalThis.HTMLVideoElement)
|
|
416
|
+
emitChange(event, target, false);
|
|
417
|
+
}
|
|
418
|
+
function onPictureInPictureError(event) {
|
|
419
|
+
var target = event.target;
|
|
420
|
+
if (target instanceof globalThis.HTMLVideoElement)
|
|
421
|
+
emitError(event, target, getIsPip());
|
|
422
|
+
}
|
|
423
|
+
function onWebkitPresentationModeChanged(event) {
|
|
424
|
+
if (this.webkitPresentationMode === PIP_PRESENTATION_MODE) {
|
|
425
|
+
lastPipVideo = this;
|
|
426
|
+
emitChange(event, this, true);
|
|
427
|
+
return;
|
|
394
428
|
}
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
429
|
+
if (this.webkitPresentationMode === INLINE_PRESENTATION_MODE && lastPipVideo === this) {
|
|
430
|
+
lastPipVideo = null;
|
|
431
|
+
emitChange(event, this, false);
|
|
398
432
|
}
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
433
|
+
}
|
|
434
|
+
function bridgeSingleVideoNode(video) {
|
|
435
|
+
if (video[PIP_BRIDGE_KEY])
|
|
436
|
+
return;
|
|
437
|
+
if (typeof video.webkitSetPresentationMode === 'undefined' && typeof video.onwebkitpresentationmodechanged === 'undefined')
|
|
438
|
+
return;
|
|
439
|
+
EventListener.add(video, { type: 'webkitpresentationmodechanged', callback: onWebkitPresentationModeChanged, options: false });
|
|
440
|
+
video[PIP_BRIDGE_KEY] = true;
|
|
441
|
+
}
|
|
442
|
+
function bridgeWebkitVideoEvents() {
|
|
443
|
+
var videos = globalThis.document.querySelectorAll('video');
|
|
444
|
+
for (var i = 0; i < videos.length; i++)
|
|
445
|
+
bridgeSingleVideoNode(videos[i]);
|
|
446
|
+
}
|
|
447
|
+
function bridgeEvents() {
|
|
448
|
+
if (eventsBridged)
|
|
449
|
+
return;
|
|
450
|
+
eventsBridged = true;
|
|
451
|
+
if (hasStandardApi())
|
|
452
|
+
return;
|
|
453
|
+
bridgeWebkitVideoEvents();
|
|
454
|
+
if (typeof globalThis.MutationObserver === 'undefined')
|
|
455
|
+
return;
|
|
456
|
+
var observer = new globalThis.MutationObserver(function (records) {
|
|
457
|
+
if (lastPipVideo !== null) {
|
|
458
|
+
var removed = false;
|
|
459
|
+
for (var i = 0; i < records.length; i++) {
|
|
460
|
+
var removedNodes = records[i].removedNodes;
|
|
461
|
+
for (var j = 0; j < removedNodes.length; j++) {
|
|
462
|
+
var node = removedNodes[j];
|
|
463
|
+
if (node === lastPipVideo || (node.nodeType === Node.ELEMENT_NODE && node.contains(lastPipVideo))) {
|
|
464
|
+
removed = true;
|
|
465
|
+
break;
|
|
466
|
+
}
|
|
467
|
+
}
|
|
468
|
+
if (removed)
|
|
469
|
+
break;
|
|
413
470
|
}
|
|
471
|
+
if (removed && !globalThis.document.contains(lastPipVideo))
|
|
472
|
+
lastPipVideo = null;
|
|
414
473
|
}
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
});
|
|
430
|
-
}
|
|
431
|
-
function attachOnChange() {
|
|
432
|
-
if (hasStandardPipEvents()) {
|
|
433
|
-
var changeEvents = ['enterpictureinpicture', 'leavepictureinpicture'];
|
|
434
|
-
for (var i = 0; i < changeEvents.length; i++) {
|
|
435
|
-
EventListener.add(globalThis.document, {
|
|
436
|
-
type: changeEvents[i],
|
|
437
|
-
callback: onChangeSubscriptionManager.emit,
|
|
438
|
-
options: false,
|
|
439
|
-
});
|
|
474
|
+
for (var i = 0; i < records.length; i++) {
|
|
475
|
+
var addedNodes = records[i].addedNodes;
|
|
476
|
+
for (var j = 0; j < addedNodes.length; j++) {
|
|
477
|
+
var node = addedNodes[j];
|
|
478
|
+
if (node.nodeType !== Node.ELEMENT_NODE)
|
|
479
|
+
continue;
|
|
480
|
+
var element = node;
|
|
481
|
+
if (element.tagName === 'VIDEO') {
|
|
482
|
+
bridgeSingleVideoNode(element);
|
|
483
|
+
continue;
|
|
484
|
+
}
|
|
485
|
+
var nested = element.querySelectorAll('video');
|
|
486
|
+
for (var k = 0; k < nested.length; k++)
|
|
487
|
+
bridgeSingleVideoNode(nested[k]);
|
|
440
488
|
}
|
|
441
|
-
return;
|
|
442
489
|
}
|
|
443
|
-
|
|
490
|
+
});
|
|
491
|
+
observer.observe(globalThis.document.documentElement, { childList: true, subtree: true });
|
|
492
|
+
}
|
|
493
|
+
function attachOnChange() {
|
|
494
|
+
if (hasStandardApi()) {
|
|
495
|
+
EventListener.add(globalThis.document, { type: 'enterpictureinpicture', callback: onEnterPictureInPicture, options: false });
|
|
496
|
+
EventListener.add(globalThis.document, { type: 'leavepictureinpicture', callback: onLeavePictureInPicture, options: false });
|
|
497
|
+
return;
|
|
498
|
+
}
|
|
499
|
+
bridgeWebkitVideoEvents();
|
|
500
|
+
}
|
|
501
|
+
function detachOnChange() {
|
|
502
|
+
if (hasStandardApi()) {
|
|
503
|
+
EventListener.remove(globalThis.document, { type: 'enterpictureinpicture', callback: onEnterPictureInPicture, options: false });
|
|
504
|
+
EventListener.remove(globalThis.document, { type: 'leavepictureinpicture', callback: onLeavePictureInPicture, options: false });
|
|
505
|
+
return;
|
|
444
506
|
}
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
507
|
+
var videos = globalThis.document.querySelectorAll('video');
|
|
508
|
+
for (var i = 0; i < videos.length; i++) {
|
|
509
|
+
EventListener.remove(videos[i], { type: 'webkitpresentationmodechanged', callback: onWebkitPresentationModeChanged, options: false });
|
|
510
|
+
videos[i][PIP_BRIDGE_KEY] = false;
|
|
511
|
+
}
|
|
512
|
+
}
|
|
513
|
+
function attachOnError() {
|
|
514
|
+
EventListener.add(globalThis.document, { type: 'pictureinpictureerror', callback: onPictureInPictureError, options: false });
|
|
515
|
+
}
|
|
516
|
+
function detachOnError() {
|
|
517
|
+
EventListener.remove(globalThis.document, { type: 'pictureinpictureerror', callback: onPictureInPictureError, options: false });
|
|
518
|
+
}
|
|
519
|
+
function getEnabled() {
|
|
520
|
+
if (typeof globalThis.document.pictureInPictureEnabled === 'boolean')
|
|
521
|
+
return globalThis.document.pictureInPictureEnabled;
|
|
522
|
+
var video;
|
|
523
|
+
var selected = globalThis.document.querySelector('video');
|
|
524
|
+
if (selected !== null)
|
|
525
|
+
video = selected;
|
|
526
|
+
else
|
|
527
|
+
video = globalThis.document.createElement('video');
|
|
528
|
+
return typeof video.webkitSupportsPresentationMode === 'function' && video.webkitSupportsPresentationMode(PIP_PRESENTATION_MODE);
|
|
529
|
+
}
|
|
530
|
+
function getElement() {
|
|
531
|
+
var currentElement = globalThis.document.pictureInPictureElement;
|
|
532
|
+
if (currentElement !== null && typeof currentElement !== 'undefined')
|
|
533
|
+
return currentElement;
|
|
534
|
+
if (lastPipVideo !== null && lastPipVideo.webkitPresentationMode === PIP_PRESENTATION_MODE)
|
|
535
|
+
return lastPipVideo;
|
|
536
|
+
return null;
|
|
537
|
+
}
|
|
538
|
+
function getIsPip() {
|
|
539
|
+
return getElement() !== null;
|
|
540
|
+
}
|
|
541
|
+
function request(target) {
|
|
542
|
+
return new Promise(function (resolve, reject) {
|
|
543
|
+
if (typeof target === 'undefined')
|
|
544
|
+
target = getDefaultTarget();
|
|
545
|
+
if (typeof target === 'undefined')
|
|
546
|
+
return reject(new NotSupportedError('Failed to enter Picture-in-Picture mode.'));
|
|
547
|
+
var tagName = target.tagName.toLowerCase();
|
|
548
|
+
if (tagName !== 'video')
|
|
549
|
+
return reject(new NotSupportedError('The "' + tagName + '" element does not support Picture-in-Picture requests.'));
|
|
550
|
+
var method = target.requestPictureInPicture;
|
|
551
|
+
var isWebkitPipActive = lastPipVideo !== null && lastPipVideo.webkitPresentationMode === PIP_PRESENTATION_MODE;
|
|
552
|
+
if (typeof method === 'function' && !isWebkitPipActive) {
|
|
553
|
+
var result = method.call(target);
|
|
554
|
+
if (typeof result !== 'undefined' && typeof result.then === 'function') {
|
|
555
|
+
result
|
|
556
|
+
.then(resolve)
|
|
557
|
+
.catch(function () {
|
|
558
|
+
try {
|
|
559
|
+
fallbackToWebkit();
|
|
560
|
+
}
|
|
561
|
+
catch (e) {
|
|
562
|
+
reject(new NotSupportedError('The "' + tagName + '" element does not support Picture-in-Picture requests.'));
|
|
563
|
+
}
|
|
453
564
|
});
|
|
565
|
+
return;
|
|
454
566
|
}
|
|
455
|
-
return;
|
|
567
|
+
return resolve();
|
|
456
568
|
}
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
video[PIP_BRIDGED_KEY] = undefined;
|
|
569
|
+
function fallbackToWebkit() {
|
|
570
|
+
if (typeof target !== 'undefined' && typeof target.webkitSupportsPresentationMode === 'function' && target.webkitSupportsPresentationMode(PIP_PRESENTATION_MODE) && typeof target.webkitSetPresentationMode === 'function') {
|
|
571
|
+
if (target.disablePictureInPicture)
|
|
572
|
+
return reject(new NotSupportedError('Picture-in-Picture is disabled on this element.'));
|
|
573
|
+
if (!hasStandardApi())
|
|
574
|
+
bridgeSingleVideoNode(target);
|
|
575
|
+
target.webkitSetPresentationMode(PIP_PRESENTATION_MODE);
|
|
576
|
+
if (target.webkitPresentationMode !== PIP_PRESENTATION_MODE)
|
|
577
|
+
return reject(new InvalidStateError('Picture-in-Picture transition is already in progress.'));
|
|
578
|
+
lastPipVideo = target;
|
|
579
|
+
return resolve();
|
|
469
580
|
}
|
|
470
|
-
|
|
471
|
-
}
|
|
472
|
-
function attachOnError() {
|
|
473
|
-
EventListener.add(globalThis.document, {
|
|
474
|
-
type: 'pictureinpictureerror',
|
|
475
|
-
callback: onErrorSubscriptionManager.emit,
|
|
476
|
-
options: false,
|
|
477
|
-
});
|
|
478
|
-
}
|
|
479
|
-
function detachOnError() {
|
|
480
|
-
EventListener.remove(globalThis.document, {
|
|
481
|
-
type: 'pictureinpictureerror',
|
|
482
|
-
callback: onErrorSubscriptionManager.emit,
|
|
483
|
-
options: false,
|
|
484
|
-
});
|
|
485
|
-
}
|
|
486
|
-
function drainPendingOperation() {
|
|
487
|
-
var entry = pendingQueue.shift();
|
|
488
|
-
if (typeof entry === 'undefined') {
|
|
489
|
-
activeOperation = null;
|
|
490
|
-
return;
|
|
581
|
+
reject(new NotSupportedError('The "' + tagName + '" element does not support Picture-in-Picture requests.'));
|
|
491
582
|
}
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
.then(drainPendingOperation)
|
|
513
|
-
.catch(drainPendingOperation);
|
|
514
|
-
return next;
|
|
515
|
-
}
|
|
516
|
-
return new Promise(function (resolve, reject) {
|
|
517
|
-
pendingQueue.push({
|
|
518
|
-
operation: 'request',
|
|
519
|
-
target: target,
|
|
520
|
-
resolve: resolve,
|
|
521
|
-
reject: reject,
|
|
522
|
-
});
|
|
523
|
-
});
|
|
524
|
-
}
|
|
525
|
-
function exit() {
|
|
526
|
-
lastIntendedOperation = 'exit';
|
|
527
|
-
if (activeOperation === null) {
|
|
528
|
-
var next = exitImmediately();
|
|
529
|
-
activeOperation = next
|
|
530
|
-
.then(drainPendingOperation)
|
|
531
|
-
.catch(drainPendingOperation);
|
|
532
|
-
return next;
|
|
533
|
-
}
|
|
534
|
-
return new Promise(function (resolve, reject) {
|
|
535
|
-
pendingQueue.push({
|
|
536
|
-
operation: 'exit',
|
|
537
|
-
target: undefined,
|
|
538
|
-
resolve: resolve,
|
|
539
|
-
reject: reject,
|
|
540
|
-
});
|
|
541
|
-
});
|
|
542
|
-
}
|
|
543
|
-
function requestImmediately(target) {
|
|
544
|
-
return new Promise(function (resolve, reject) {
|
|
545
|
-
if (typeof target === 'undefined')
|
|
546
|
-
target = getDefaultTarget();
|
|
547
|
-
if (typeof target === 'undefined')
|
|
548
|
-
return reject(new NotSupportedError('Failed to enter Picture-in-Picture mode.'));
|
|
549
|
-
var tagName = target.tagName.toLowerCase();
|
|
550
|
-
if (tagName !== 'video')
|
|
551
|
-
return reject(new NotSupportedError('The "' + tagName + '" element does not support Picture-in-Picture requests.'));
|
|
552
|
-
function fallbackToWebkitVideo() {
|
|
553
|
-
if (typeof target !== 'undefined' && typeof target.webkitSupportsPresentationMode === 'function' && target.webkitSupportsPresentationMode(PIP_PRESENTATION_MODE) && typeof target.webkitSetPresentationMode === 'function') {
|
|
554
|
-
if (target.disablePictureInPicture)
|
|
555
|
-
return reject(new NotSupportedError('Picture-in-Picture is disabled on this video element.'));
|
|
556
|
-
lastPipVideo = target;
|
|
557
|
-
bridgeWebkitVideoEvents();
|
|
558
|
-
target.webkitSetPresentationMode(PIP_PRESENTATION_MODE);
|
|
559
|
-
return resolve();
|
|
560
|
-
}
|
|
561
|
-
reject(new NotSupportedError('The "' + tagName + '" element does not support Picture-in-Picture requests.'));
|
|
583
|
+
fallbackToWebkit();
|
|
584
|
+
});
|
|
585
|
+
}
|
|
586
|
+
function exit() {
|
|
587
|
+
return new Promise(function (resolve, reject) {
|
|
588
|
+
var method = globalThis.document.exitPictureInPicture;
|
|
589
|
+
if (typeof method === 'function') {
|
|
590
|
+
var result = method.call(globalThis.document);
|
|
591
|
+
if (typeof result !== 'undefined' && typeof result.then === 'function') {
|
|
592
|
+
result
|
|
593
|
+
.then(resolve)
|
|
594
|
+
.catch(function () {
|
|
595
|
+
try {
|
|
596
|
+
fallbackToWebkit();
|
|
597
|
+
}
|
|
598
|
+
catch (e) {
|
|
599
|
+
reject(new NotSupportedError('Failed to exit Picture-in-Picture mode.'));
|
|
600
|
+
}
|
|
601
|
+
});
|
|
602
|
+
return;
|
|
562
603
|
}
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
resolve();
|
|
570
|
-
})
|
|
571
|
-
.catch(function () {
|
|
572
|
-
fallbackToWebkitVideo();
|
|
573
|
-
});
|
|
574
|
-
return;
|
|
575
|
-
}
|
|
604
|
+
return resolve();
|
|
605
|
+
}
|
|
606
|
+
function fallbackToWebkit() {
|
|
607
|
+
if (lastPipVideo !== null && typeof lastPipVideo.webkitSetPresentationMode === 'function' && lastPipVideo.webkitPresentationMode === PIP_PRESENTATION_MODE) {
|
|
608
|
+
lastPipVideo.webkitSetPresentationMode(INLINE_PRESENTATION_MODE);
|
|
609
|
+
lastPipVideo = null;
|
|
576
610
|
return resolve();
|
|
577
611
|
}
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
return resolve();
|
|
585
|
-
function fallbackToWebkitVideo() {
|
|
586
|
-
var candidates;
|
|
587
|
-
if (lastPipVideo !== null && lastPipVideo.webkitPresentationMode === PIP_PRESENTATION_MODE)
|
|
588
|
-
candidates = [lastPipVideo];
|
|
589
|
-
else
|
|
590
|
-
candidates = globalThis.document.querySelectorAll('video');
|
|
591
|
-
for (var i = 0; i < candidates.length; i++) {
|
|
592
|
-
var video = candidates[i];
|
|
593
|
-
if (typeof video.webkitSetPresentationMode === 'function' && video.webkitPresentationMode === PIP_PRESENTATION_MODE) {
|
|
594
|
-
video.webkitSetPresentationMode(INLINE_PRESENTATION_MODE);
|
|
595
|
-
lastPipVideo = null;
|
|
596
|
-
return resolve();
|
|
597
|
-
}
|
|
598
|
-
}
|
|
599
|
-
if (getElement() === null)
|
|
612
|
+
var videos = globalThis.document.querySelectorAll('video');
|
|
613
|
+
for (var i = 0; i < videos.length; i++) {
|
|
614
|
+
var video = videos[i];
|
|
615
|
+
if (typeof video.webkitSetPresentationMode === 'function' && video.webkitPresentationMode === PIP_PRESENTATION_MODE) {
|
|
616
|
+
video.webkitSetPresentationMode(INLINE_PRESENTATION_MODE);
|
|
617
|
+
lastPipVideo = null;
|
|
600
618
|
return resolve();
|
|
601
|
-
reject(new NotSupportedError('Failed to exit Picture-in-Picture mode.'));
|
|
602
|
-
}
|
|
603
|
-
var method = globalThis.document.exitPictureInPicture;
|
|
604
|
-
if (typeof method === 'function') {
|
|
605
|
-
var result = method.call(globalThis.document);
|
|
606
|
-
if (typeof result !== 'undefined' && typeof result.then === 'function') {
|
|
607
|
-
result
|
|
608
|
-
.then(resolve)
|
|
609
|
-
.catch(function () {
|
|
610
|
-
fallbackToWebkitVideo();
|
|
611
|
-
});
|
|
612
|
-
return;
|
|
613
619
|
}
|
|
614
|
-
return resolve();
|
|
615
620
|
}
|
|
616
|
-
|
|
617
|
-
|
|
618
|
-
|
|
619
|
-
|
|
620
|
-
|
|
621
|
-
|
|
622
|
-
return request(target);
|
|
623
|
-
}
|
|
624
|
-
bridgeEvents();
|
|
625
|
-
return {
|
|
626
|
-
get supported() {
|
|
627
|
-
return getEnabled();
|
|
628
|
-
},
|
|
629
|
-
get element() {
|
|
630
|
-
return getElement();
|
|
631
|
-
},
|
|
632
|
-
get isPip() {
|
|
633
|
-
return getIsPip();
|
|
634
|
-
},
|
|
635
|
-
request: request,
|
|
636
|
-
exit: exit,
|
|
637
|
-
toggle: toggle,
|
|
638
|
-
onChange: onChangeSubscriptionManager.subscribe,
|
|
639
|
-
onError: onErrorSubscriptionManager.subscribe,
|
|
640
|
-
Constants: {},
|
|
641
|
-
Errors: {
|
|
642
|
-
NotSupportedError: NotSupportedError,
|
|
643
|
-
},
|
|
644
|
-
};
|
|
621
|
+
if (globalThis.document.pictureInPictureElement === null || typeof globalThis.document.pictureInPictureElement === 'undefined')
|
|
622
|
+
return resolve();
|
|
623
|
+
reject(new NotSupportedError('Failed to exit Picture-in-Picture mode.'));
|
|
624
|
+
}
|
|
625
|
+
fallbackToWebkit();
|
|
626
|
+
});
|
|
645
627
|
}
|
|
646
|
-
|
|
628
|
+
bridgeEvents();
|
|
647
629
|
|
|
648
630
|
module.exports = Pip;
|
|
@@ -1,30 +1,37 @@
|
|
|
1
1
|
declare const NotSupportedError: ErrorConstructor;
|
|
2
2
|
|
|
3
|
+
declare const InvalidStateError: ErrorConstructor;
|
|
4
|
+
|
|
3
5
|
declare interface PipInstance {
|
|
4
|
-
supported: boolean;
|
|
5
|
-
element: HTMLVideoElement | null;
|
|
6
|
-
isPip: boolean;
|
|
6
|
+
get supported(): boolean;
|
|
7
|
+
get element(): HTMLVideoElement | null;
|
|
8
|
+
get isPip(): boolean;
|
|
7
9
|
request(target?: HTMLVideoElement): Promise<void>;
|
|
8
10
|
exit(): Promise<void>;
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
onError(listener: (event: Event) => void, options?: AddEventListenerOptions): () => void;
|
|
11
|
+
onChange(listener: (payload: PipEventPayload) => void, options?: AddEventListenerOptions): () => void;
|
|
12
|
+
onError(listener: (payload: PipEventPayload) => void, options?: AddEventListenerOptions): () => void;
|
|
12
13
|
Constants: {};
|
|
13
14
|
Errors: {
|
|
14
15
|
NotSupportedError: typeof NotSupportedError;
|
|
16
|
+
InvalidStateError: typeof InvalidStateError;
|
|
15
17
|
};
|
|
16
18
|
}
|
|
19
|
+
declare interface PipEventPayload {
|
|
20
|
+
nativeEvent: Event;
|
|
21
|
+
element: HTMLVideoElement;
|
|
22
|
+
isPip: boolean;
|
|
23
|
+
}
|
|
17
24
|
|
|
18
25
|
declare global {
|
|
19
26
|
interface HTMLVideoElement {
|
|
20
|
-
webkitSupportsPresentationMode
|
|
21
|
-
webkitSetPresentationMode
|
|
27
|
+
webkitSupportsPresentationMode?(mode: string): boolean;
|
|
28
|
+
webkitSetPresentationMode?(mode: string): void;
|
|
22
29
|
webkitPresentationMode?: string;
|
|
23
|
-
onwebkitpresentationmodechanged?: ((this:
|
|
24
|
-
[key: symbol]: boolean | undefined;
|
|
30
|
+
onwebkitpresentationmodechanged?: ((this: Element, ev: Event) => any) | null;
|
|
25
31
|
}
|
|
32
|
+
var __nativeFnPipBridgeKey__: symbol | undefined;
|
|
26
33
|
}
|
|
27
|
-
declare const
|
|
34
|
+
declare const Pip: PipInstance;
|
|
28
35
|
|
|
29
|
-
export {
|
|
30
|
-
export type { PipInstance };
|
|
36
|
+
export { Pip as default };
|
|
37
|
+
export type { PipEventPayload, PipInstance };
|