@js-toolkit/web-utils 1.55.0 → 1.56.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/FullscreenController.d.ts +1 -2
- package/FullscreenController.js +1 -1
- package/fullscreen.js +1 -1
- package/getEventAwaiter.js +1 -1
- package/loadScript.js +1 -1
- package/media/BaseMediaController.d.ts +3 -3
- package/package.json +9 -9
- package/platform/isScreenHDR.d.ts +1 -0
- package/platform/isScreenHDR.js +1 -0
- package/viewableTracker.d.ts +1 -1
- package/viewableTracker.js +1 -1
|
@@ -39,8 +39,7 @@ export declare namespace FullscreenController {
|
|
|
39
39
|
/** Used for iOS. */
|
|
40
40
|
readonly toggleNativeSubtitles?: boolean | undefined;
|
|
41
41
|
};
|
|
42
|
-
|
|
43
|
-
}
|
|
42
|
+
type RequestOptions = Readonly<FullscreenOptions>;
|
|
44
43
|
enum Events {
|
|
45
44
|
Change = "change",
|
|
46
45
|
Error = "error"
|
package/FullscreenController.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{EventEmitter}from"eventemitter3";import{hasIn}from"@js-toolkit/utils/hasIn";import{fullscreen}from"./fullscreen";import{toggleNativeSubtitles}from"./media/toggleNativeSubtitles";export function enterPseudoFullscreen(e){let t,
|
|
1
|
+
import{EventEmitter}from"eventemitter3";import{hasIn}from"@js-toolkit/utils/hasIn";import{fullscreen}from"./fullscreen";import{toggleNativeSubtitles}from"./media/toggleNativeSubtitles";export function enterPseudoFullscreen(e){let t,i;return t={position:e.style.position,left:e.style.left,top:e.style.top,width:e.style.width,height:e.style.height,maxWidth:e.style.maxWidth,maxHeight:e.style.maxHeight,zIndex:e.style.zIndex},i=e,i.style.position="fixed",i.style.left="0px",i.style.top="0px",i.style.width="100%",i.style.height="100%",i.style.maxWidth="100%",i.style.maxHeight="100%",i.style.zIndex="99999",()=>{t&&i&&(i.style.position=t.position,i.style.left=t.left,i.style.top=t.top,i.style.width=t.width,i.style.height=t.height,i.style.maxWidth=t.maxWidth,i.style.maxHeight=t.maxHeight,i.style.zIndex=t.zIndex),t=void 0,i=void 0}}export class FullscreenController extends EventEmitter{static isApiAvailable(){return fullscreen.isApiEnabled()}get Events(){return FullscreenController.Events}constructor(e,t={}){super(),this.element=e,this.options=t,this.nativeChangeHandler=()=>{this.emit(this.Events.Change,{fullscreen:this.isFullscreen(),type:"native"})},this.nativeErrorHandler=e=>{this.emit(this.Events.Error,{error:e,type:"native"})},this.videoBeginFullscreenHandler=(()=>{const e=()=>{const t=this.fallback;e.controls=t.controls,e.nativeSubtitles=hasIn(this.options,"toggleNativeSubtitles")&&this.options.toggleNativeSubtitles&&t.textTracks.length>0,e.nativeSubtitles&&toggleNativeSubtitles(!0,t.textTracks),this.emit(this.Events.Change,{fullscreen:!0,type:"video"})};return e.nativeSubtitles=void 0,e.controls=void 0,e})(),this.videoEndFullscreenHandler=()=>{const e=this.fallback;null!=this.videoBeginFullscreenHandler.controls&&(e.controls=this.videoBeginFullscreenHandler.controls),this.videoBeginFullscreenHandler.nativeSubtitles&&toggleNativeSubtitles(!1,e.textTracks),this.emit(this.Events.Change,{fullscreen:!1,type:"video"})},this.setOptions(t)}unbind(){if(fullscreen.names){const{names:e}=fullscreen;this.element.removeEventListener(e.changeEventName,this.nativeChangeHandler),this.element.removeEventListener(e.errorEventName,this.nativeErrorHandler)}this.fallback instanceof HTMLVideoElement&&(this.fallback.removeEventListener("webkitbeginfullscreen",this.videoBeginFullscreenHandler),this.fallback.removeEventListener("webkitendfullscreen",this.videoEndFullscreenHandler),this.fallback=void 0)}setOptions(e){if(this.unbind(),this.options=null!=e?e:{},this.fallback=this.options.fallback,fullscreen.names&&fullscreen.isApiEnabled()){const{names:e}=fullscreen;this.element.addEventListener(e.changeEventName,this.nativeChangeHandler),this.element.addEventListener(e.errorEventName,this.nativeErrorHandler)}else this.fallback instanceof HTMLVideoElement&&(this.fallback.addEventListener("webkitbeginfullscreen",this.videoBeginFullscreenHandler),this.fallback.addEventListener("webkitendfullscreen",this.videoEndFullscreenHandler))}destroy(){return this.exit().then((()=>new Promise((e=>{requestAnimationFrame((()=>{this.removeAllListeners(),this.unbind(),e()}))}))))}isAvailable(){return fullscreen.isApiEnabled()||"pseudo"===this.fallback||this.fallback instanceof HTMLVideoElement&&!!this.fallback.webkitEnterFullscreen&&!!this.fallback.webkitSupportsFullscreen}isFullscreen(){return!!this.getCurrentElement()}isPseudoFullscreen(){return this.isFullscreen()&&!!this.exitPseudoFullscreen}getCurrentElement(){if(fullscreen.isApiEnabled()){if(fullscreen.getElement()===this.element)return this.element}else{if(this.exitPseudoFullscreen)return this.element;if(this.fallback instanceof HTMLVideoElement&&this.fallback.webkitDisplayingFullscreen)return this.fallback}return null}request(e={}){return new Promise(((t,i)=>{if(this.isFullscreen())return void t();if(fullscreen.isApiEnabled())return void fullscreen.request(this.element,e).then(t).catch(i);if("pseudo"===this.fallback)return this.exitPseudoFullscreen=enterPseudoFullscreen(this.element),this.emit(this.Events.Change,{fullscreen:!0,type:"pseudo"}),void t();const l=this.fallback instanceof HTMLVideoElement&&this.fallback||void 0;if((null==l?void 0:l.webkitEnterFullscreen)&&l.webkitSupportsFullscreen){const e=()=>{l.removeEventListener("webkitbeginfullscreen",e),t()};return l.addEventListener("webkitbeginfullscreen",e),void l.webkitEnterFullscreen()}i(new fullscreen.UnavailableError)}))}exit(){return new Promise(((e,t)=>{if(!this.isFullscreen())return void e();if(fullscreen.isApiEnabled())return void fullscreen.exit().then(e).catch(t);if(this.exitPseudoFullscreen)return this.exitPseudoFullscreen(),this.exitPseudoFullscreen=void 0,this.emit(this.Events.Change,{fullscreen:!1,type:"pseudo"}),void e();const i=this.fallback instanceof HTMLVideoElement&&this.fallback||void 0;if((null==i?void 0:i.webkitExitFullscreen)&&i.webkitSupportsFullscreen){const t=()=>{i.removeEventListener("webkitendfullscreen",t),e()};return i.addEventListener("webkitendfullscreen",t),void i.webkitExitFullscreen()}t(new fullscreen.UnavailableError)}))}}!function(e){let t;!function(e){e.Change="change",e.Error="error"}(t=e.Events||(e.Events={}))}(FullscreenController||(FullscreenController={}));
|
package/fullscreen.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{es5ErrorCompat}from"@js-toolkit/utils/es5ErrorCompat";import{promisify}from"@js-toolkit/utils/promisify";export class FullscreenUnavailableError extends Error{constructor(){super("Fullscreen is not available"),es5ErrorCompat(this,FullscreenUnavailableError)}}export var fullscreen;!function(e){e.names=[{requestFullscreenName:"requestFullscreen",exitFullscreenName:"exitFullscreen",fullscreenElementName:"fullscreenElement",fullscreenEnabledName:"fullscreenEnabled",changeEventName:"fullscreenchange",errorEventName:"fullscreenerror"},{requestFullscreenName:"webkitRequestFullscreen",exitFullscreenName:"webkitExitFullscreen",fullscreenElementName:"webkitFullscreenElement",fullscreenEnabledName:"webkitFullscreenEnabled",changeEventName:"webkitfullscreenchange",errorEventName:"webkitfullscreenerror"},{requestFullscreenName:"webkitRequestFullScreen",exitFullscreenName:"webkitCancelFullScreen",fullscreenElementName:"webkitCurrentFullScreenElement",fullscreenEnabledName:"webkitCancelFullScreen",changeEventName:"webkitfullscreenchange",errorEventName:"webkitfullscreenerror"},{requestFullscreenName:"mozRequestFullScreen",exitFullscreenName:"mozCancelFullScreen",fullscreenElementName:"mozFullScreenElement",fullscreenEnabledName:"mozFullScreenEnabled",changeEventName:"mozfullscreenchange",errorEventName:"mozfullscreenerror"},{requestFullscreenName:"msRequestFullscreen",exitFullscreenName:"msExitFullscreen",fullscreenElementName:"msFullscreenElement",fullscreenEnabledName:"msFullscreenEnabled",changeEventName:"MSFullscreenChange",errorEventName:"MSFullscreenError"}].find((({exitFullscreenName:e})=>e in document));const n={change:null===e.names||void 0===e.names?void 0:e.names.changeEventName,error:null===e.names||void 0===e.names?void 0:e.names.errorEventName};function r(){if(!e.names)throw new e.UnavailableError;return Boolean(document[e.names.fullscreenElementName])}function l(e,r,l){const a=n[e];a&&document.addEventListener(a,r,l)}function a(e,r,l){const a=n[e];a&&document.removeEventListener(a,r,l)}function t(n,r){return new Promise(((t,s)=>{if(!e.names)throw new e.UnavailableError;const c=()=>{a("change",c),a("error",u),t()},u=e=>{a("change",c),a("error",u),s(e)};l("change",c),l("error",u);const o=n[e.names.requestFullscreenName](r);o instanceof Promise&&o.then(c
|
|
1
|
+
import{es5ErrorCompat}from"@js-toolkit/utils/es5ErrorCompat";import{promisify}from"@js-toolkit/utils/promisify";export class FullscreenUnavailableError extends Error{constructor(){super("Fullscreen is not available"),es5ErrorCompat(this,FullscreenUnavailableError)}}export var fullscreen;!function(e){e.names=[{requestFullscreenName:"requestFullscreen",exitFullscreenName:"exitFullscreen",fullscreenElementName:"fullscreenElement",fullscreenEnabledName:"fullscreenEnabled",changeEventName:"fullscreenchange",errorEventName:"fullscreenerror"},{requestFullscreenName:"webkitRequestFullscreen",exitFullscreenName:"webkitExitFullscreen",fullscreenElementName:"webkitFullscreenElement",fullscreenEnabledName:"webkitFullscreenEnabled",changeEventName:"webkitfullscreenchange",errorEventName:"webkitfullscreenerror"},{requestFullscreenName:"webkitRequestFullScreen",exitFullscreenName:"webkitCancelFullScreen",fullscreenElementName:"webkitCurrentFullScreenElement",fullscreenEnabledName:"webkitCancelFullScreen",changeEventName:"webkitfullscreenchange",errorEventName:"webkitfullscreenerror"},{requestFullscreenName:"mozRequestFullScreen",exitFullscreenName:"mozCancelFullScreen",fullscreenElementName:"mozFullScreenElement",fullscreenEnabledName:"mozFullScreenEnabled",changeEventName:"mozfullscreenchange",errorEventName:"mozfullscreenerror"},{requestFullscreenName:"msRequestFullscreen",exitFullscreenName:"msExitFullscreen",fullscreenElementName:"msFullscreenElement",fullscreenEnabledName:"msFullscreenEnabled",changeEventName:"MSFullscreenChange",errorEventName:"MSFullscreenError"}].find((({exitFullscreenName:e})=>e in document));const n={change:null===e.names||void 0===e.names?void 0:e.names.changeEventName,error:null===e.names||void 0===e.names?void 0:e.names.errorEventName};function r(){if(!e.names)throw new e.UnavailableError;return Boolean(document[e.names.fullscreenElementName])}function l(e,r,l){const a=n[e];a&&document.addEventListener(a,r,l)}function a(e,r,l){const a=n[e];a&&document.removeEventListener(a,r,l)}function t(n,r){return new Promise(((t,s)=>{if(!e.names)throw new e.UnavailableError;const c=()=>{a("change",c),a("error",u),t()},u=e=>{a("change",c),a("error",u),s(e)};l("change",c),l("error",u);const o=n[e.names.requestFullscreenName](r);o instanceof Promise&&o.then(c).catch(u)}))}function s(){return new Promise(((n,t)=>{if(!e.names)throw new e.UnavailableError;if(!r)return void n();const s=()=>{a("change",s),a("error",c),n()},c=e=>{a("change",s),a("error",c),t(e)};l("change",s),l("error",c);const u=document[e.names.exitFullscreenName]();u instanceof Promise&&u.then(s).catch(c)}))}e.UnavailableError=FullscreenUnavailableError,e.isApiAvailable=function(){return!!e.names},e.isApiEnabled=function(){return!!e.names&&Boolean(document[e.names.fullscreenEnabledName])},e.isFullscreen=r,e.getElement=function(){if(!e.names)throw new e.UnavailableError;return document[e.names.fullscreenElementName]},e.on=l,e.off=a,e.request=t,e.exit=s,e.toggle=function(e){return promisify((()=>r()?s():t(e)))},e.onChange=function(e){l("change",e)},e.onError=function(e){l("error",e)}}(fullscreen||(fullscreen={}));
|
package/getEventAwaiter.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{getAwaiter}from"@js-toolkit/utils/getAwaiter";import{EventEmitterListener}from"./EventEmitterListener";import{isEventEmitterLike}from"./EventEmitterListener.utils";export function getEventAwaiter(t,e,r,i){const o=getAwaiter({lazy:!0}),n=Array.isArray(e)?e:[e],s=Array.isArray(r)?r:[r],E=isEventEmitterLike(t)?t:new EventEmitterListener(t),a=()=>{n.forEach((t=>E.off(t,
|
|
1
|
+
import{getAwaiter}from"@js-toolkit/utils/getAwaiter";import{EventEmitterListener}from"./EventEmitterListener";import{isEventEmitterLike}from"./EventEmitterListener.utils";export function getEventAwaiter(t,e,r,i){const o=getAwaiter({lazy:!0}),n=Array.isArray(e)?e:[e],s=Array.isArray(r)?r:[r],E=isEventEmitterLike(t)?t:new EventEmitterListener(t),a=()=>{o.resolve()},f=t=>{const e=i?i(t):t;null!=e&&o.reject(e)},m=()=>{n.forEach((t=>E.off(t,a))),s.forEach((t=>E.off(t,f)))},c=o.resolve;o.resolve=(...t)=>{m(),c(...t)};const v=o.reject;return o.reject=(...t)=>{v(...t),m()},n.forEach((t=>E.on(t,a))),s.forEach((t=>E.on(t,f))),o}
|
package/loadScript.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{onDOMReady}from"./onDOMReady";function isScriptAdded(e){const r=e.startsWith("//")?window.location.protocol+e:e;for(let e=0;e<document.scripts.length;e+=1)if(document.scripts[e].src===r)return!0;return!1}export function loadScript(e,{keepScript:r,id:t,async:n=!0,defer:o=!1}={}){return new Promise(((d,
|
|
1
|
+
import{onDOMReady}from"./onDOMReady";function isScriptAdded(e){const r=e.startsWith("//")?window.location.protocol+e:e;for(let e=0;e<document.scripts.length;e+=1)if(document.scripts[e].src===r)return!0;return!1}export function loadScript(e,{keepScript:r,id:t,async:n=!0,defer:o=!1}={}){return new Promise(((d,c)=>{onDOMReady((()=>{try{if(t){if(document.scripts.namedItem(t))return void d()}else if(isScriptAdded(e))return void d();const i=document.createElement("script"),s=()=>{i.removeEventListener("load",a),i.removeEventListener("error",p),r||i.remove()},a=()=>{s(),d()},p=r=>{s();const t=r instanceof ErrorEvent?r:new Error(`Unable to load script by url ${e}.`,{cause:r});c(t)};t&&(i.id=t),i.async=n,i.defer=o,i.src=e,i.addEventListener("load",a,{once:!0}),i.addEventListener("error",p,{once:!0}),document.head.appendChild(i)}catch(e){c(e)}}))}))}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@js-toolkit/web-utils",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.56.0",
|
|
4
4
|
"description": "Web utils",
|
|
5
5
|
"author": "VZH",
|
|
6
6
|
"license": "MIT",
|
|
@@ -22,16 +22,16 @@
|
|
|
22
22
|
"devDependencies": {
|
|
23
23
|
"@eslint/compat": "^1.1.1",
|
|
24
24
|
"@eslint/eslintrc": "^3.1.0",
|
|
25
|
-
"@eslint/js": "^9.
|
|
26
|
-
"@js-toolkit/configs": "^3.93.
|
|
27
|
-
"@js-toolkit/utils": "^1.54.
|
|
28
|
-
"@types/eslint": "^9.6.
|
|
25
|
+
"@eslint/js": "^9.9.1",
|
|
26
|
+
"@js-toolkit/configs": "^3.93.5",
|
|
27
|
+
"@js-toolkit/utils": "^1.54.2",
|
|
28
|
+
"@types/eslint": "^9.6.1",
|
|
29
29
|
"@types/eslint__eslintrc": "^2.1.2",
|
|
30
30
|
"@types/eslint__js": "^8.42.3",
|
|
31
31
|
"@types/lodash.throttle": "^4.1.9",
|
|
32
32
|
"@types/uuid": "^10.0.0",
|
|
33
33
|
"copyfiles": "^2.4.1",
|
|
34
|
-
"eslint": "^9.
|
|
34
|
+
"eslint": "^9.9.1",
|
|
35
35
|
"eslint-config-prettier": "^9.1.0",
|
|
36
36
|
"eslint-plugin-import": "^2.29.1",
|
|
37
37
|
"eslint-plugin-prettier": "^5.2.1",
|
|
@@ -40,12 +40,12 @@
|
|
|
40
40
|
"prettier": "^3.3.3",
|
|
41
41
|
"reconnecting-websocket": "^4.4.0",
|
|
42
42
|
"rimraf": "^6.0.1",
|
|
43
|
-
"terser": "^5.31.
|
|
43
|
+
"terser": "^5.31.6",
|
|
44
44
|
"typescript": "^5.5.4",
|
|
45
|
-
"typescript-eslint": "^
|
|
45
|
+
"typescript-eslint": "^8.3.0",
|
|
46
46
|
"ua-parser-js": "^2.0.0-beta.3",
|
|
47
47
|
"uuid": "^10.0.0",
|
|
48
|
-
"webpack": "^5.
|
|
48
|
+
"webpack": "^5.94.0",
|
|
49
49
|
"yargs": "^17.7.2"
|
|
50
50
|
}
|
|
51
51
|
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function isScreenHDR(): boolean;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export function isScreenHDR(){return window.matchMedia("(dynamic-range: high)").matches}
|
package/viewableTracker.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
export interface ViewableTrackerOptions {
|
|
2
|
-
/** Visibility part to detect state as viewable. */
|
|
2
|
+
/** Visibility part to detect state as viewable. Up to 1. */
|
|
3
3
|
readonly visiblePart?: boolean | number | undefined;
|
|
4
4
|
readonly scrollThrottle?: number | undefined;
|
|
5
5
|
readonly documentVisibility?: boolean | undefined;
|
package/viewableTracker.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import throttleFn from"lodash.throttle";export function getViewableTracker(t,{visiblePart:e=.8,scrollThrottle:i=200,documentVisibility:n=!0,onChange:o}){const r
|
|
1
|
+
import throttleFn from"lodash.throttle";export function getViewableTracker(t,{visiblePart:e=.8,scrollThrottle:i=200,documentVisibility:n=!0,onChange:o}){const r=Math.min(+e,1);let s,l=0,c="visible"===document.visibilityState;const a=()=>{if(n&&"visible"!==document.visibilityState)return;const{top:e,bottom:i,height:l}=t.getBoundingClientRect(),c=l*r,a=e+c,d=window.innerHeight>=a&&i>c;s!==d&&(s=d,o(d))},d=()=>{const t="visible"===document.visibilityState;c!==t&&(c=t,t?(s=void 0,a()):s!==t&&o(t))},v=i&&i>0?throttleFn(a,i):()=>{n&&"visible"!==document.visibilityState||(l=window.requestAnimationFrame(a))};window.addEventListener("scroll",v,{capture:!1,passive:!0}),n&&document.addEventListener("visibilitychange",d);return{check:()=>{a(),n&&d()},destroy:()=>{cancelAnimationFrame(l),window.removeEventListener("scroll",v,{capture:!1}),document.removeEventListener("visibilitychange",d)}}}
|