@js-toolkit/web-utils 1.61.0 → 1.62.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 -1
- package/media/getMediaSource.d.ts +7 -1
- package/media/getSourceBuffer.d.ts +17 -0
- package/media/getSourceBuffer.js +1 -0
- package/media/parseCueText.d.ts +2 -2
- package/media/parseCueText.js +1 -1
- package/package.json +3 -3
- package/platform/isMSESupported.d.ts +4 -1
- package/platform/isMSESupported.js +1 -1
- package/webrtc/PeerConnection.d.ts +2 -2
- package/ws/WSController.d.ts +2 -2
|
@@ -54,7 +54,7 @@ export declare namespace FullscreenController {
|
|
|
54
54
|
type: FullscreenType;
|
|
55
55
|
}];
|
|
56
56
|
}>;
|
|
57
|
-
type EventHandler<T extends Events = Events> = EventEmitter.
|
|
57
|
+
type EventHandler<T extends Events = Events> = EventEmitter.EventListener<EventMap, T, FullscreenController>;
|
|
58
58
|
type EventHandlerMap<T extends Events = Events> = {
|
|
59
59
|
[P in T]: EventHandler<P>;
|
|
60
60
|
};
|
|
@@ -14,4 +14,10 @@ declare global {
|
|
|
14
14
|
ManagedMediaSource?: ManagedMediaSource & typeof MediaSource;
|
|
15
15
|
}
|
|
16
16
|
}
|
|
17
|
-
export declare function getMediaSource(
|
|
17
|
+
export declare function getMediaSource(
|
|
18
|
+
/**
|
|
19
|
+
* `prefer` - If has support.
|
|
20
|
+
* `maybe` - If has support but mse is unsupported.
|
|
21
|
+
* Otherwise returns mse MediaSource.
|
|
22
|
+
*/
|
|
23
|
+
managedMediaSource?: 'prefer' | 'maybe'): typeof MediaSource | undefined;
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import type { getMediaSource } from './getMediaSource';
|
|
2
|
+
declare global {
|
|
3
|
+
interface ManagedSourceBufferEventMap extends SourceBufferEventMap {
|
|
4
|
+
bufferedchange: Event;
|
|
5
|
+
}
|
|
6
|
+
interface ManagedSourceBuffer extends SourceBuffer {
|
|
7
|
+
onbufferedchange: ((this: ManagedSourceBuffer, ev: Event) => any) | null;
|
|
8
|
+
addEventListener<K extends keyof ManagedSourceBufferEventMap>(type: K, listener: (this: ManagedSourceBuffer, ev: ManagedSourceBufferEventMap[K]) => any, options?: boolean | AddEventListenerOptions): void;
|
|
9
|
+
removeEventListener<K extends keyof ManagedSourceBufferEventMap>(type: K, listener: (this: ManagedSourceBuffer, ev: ManagedSourceBufferEventMap[K]) => any, options?: boolean | EventListenerOptions): void;
|
|
10
|
+
}
|
|
11
|
+
interface Window {
|
|
12
|
+
ManagedSourceBuffer?: ManagedSourceBuffer & typeof SourceBuffer;
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
type ManagedMediaSourceOption = Parameters<typeof getMediaSource>[0];
|
|
16
|
+
export declare function getSourceBuffer(managedSourceBuffer?: ManagedMediaSourceOption): typeof SourceBuffer | undefined;
|
|
17
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export function getSourceBuffer(e){return"prefer"===e&&window.ManagedSourceBuffer||"maybe"===e&&window.ManagedSourceBuffer&&!window.SourceBuffer?window.ManagedSourceBuffer:window.SourceBuffer}
|
package/media/parseCueText.d.ts
CHANGED
|
@@ -7,11 +7,11 @@ export interface CueSegment {
|
|
|
7
7
|
declare const TAG_NAME: Record<string, string>;
|
|
8
8
|
export interface ParseCueTextOptions {
|
|
9
9
|
/** Defaults to `0`. */
|
|
10
|
-
readonly
|
|
10
|
+
readonly preferLineLength?: number | undefined;
|
|
11
11
|
}
|
|
12
12
|
export interface ParseCueTextResult<P> {
|
|
13
13
|
readonly segments: P[][];
|
|
14
14
|
readonly rawText: string[];
|
|
15
15
|
}
|
|
16
|
-
export declare function parseCueText<P = CueSegment>(input0: string, map?: (segment: CueSegment, prevSegment: P | undefined) => P, {
|
|
16
|
+
export declare function parseCueText<P = CueSegment>(input0: string, map?: (segment: CueSegment, prevSegment: P | undefined) => P, { preferLineLength }?: ParseCueTextOptions): ParseCueTextResult<P>;
|
|
17
17
|
export {};
|
package/media/parseCueText.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{splitRows}from"./TextTracksController/utils";const ESCAPE={"&":"&","<":"<",">":">","‎":"","‏":""," ":" "},TAG_NAME={c:"span",i:"i",b:"b",u:"u",ruby:"ruby",rt:"rt",lang:"span"},TAG_ANNOTATION={v:"title",lang:"lang"},NEEDS_PARENT={rt:"ruby"};function computeSeconds(e,t,n,o){return 3600*(+e||0)+60*(+t||0)+(+n||0)+(+o||0)/1e3}function parseTimeStamp(e){const t=e.match(/^(\d+):(\d{2})(:\d{2})?\.(\d{3})/);if(!t)return;const[,n,o,r,l]=t;return l?computeSeconds(n,o,r.replace(":",""),l):+n>59?computeSeconds(n,o,"",l):computeSeconds("",n,o,l)}function unescape(e){let t,n=e;for(;t=n.match(/&(amp|lt|gt|lrm|rlm|nbsp);/);)n=n.replace(t[0],(e=>ESCAPE[e]));return n}function nextToken(e){if(!e)return[e,void 0];const t=e.match(/^([^<]*)(<[^>]*>?)?/);if(!t)return[e,void 0];const n=t[1]?t[1]:t[2];return null==n?[e,n]:[e.substring(n.length),n]}function shouldAdd(e,t){return!NEEDS_PARENT[t.localName]||NEEDS_PARENT[t.localName]===e.localName}function createHtmlNode(e,t){const n=TAG_NAME[e];if(!n)return;const o=window.document.createElement(n),r=TAG_ANNOTATION[e];return r&&t&&(o[r]=t.trim()),o}export function parseCueText(e,t,{
|
|
1
|
+
import{splitRows}from"./TextTracksController/utils";const ESCAPE={"&":"&","<":"<",">":">","‎":"","‏":""," ":" "},TAG_NAME={c:"span",i:"i",b:"b",u:"u",ruby:"ruby",rt:"rt",lang:"span"},TAG_ANNOTATION={v:"title",lang:"lang"},NEEDS_PARENT={rt:"ruby"};function computeSeconds(e,t,n,o){return 3600*(+e||0)+60*(+t||0)+(+n||0)+(+o||0)/1e3}function parseTimeStamp(e){const t=e.match(/^(\d+):(\d{2})(:\d{2})?\.(\d{3})/);if(!t)return;const[,n,o,r,l]=t;return l?computeSeconds(n,o,r.replace(":",""),l):+n>59?computeSeconds(n,o,"",l):computeSeconds("",n,o,l)}function unescape(e){let t,n=e;for(;t=n.match(/&(amp|lt|gt|lrm|rlm|nbsp);/);)n=n.replace(t[0],(e=>ESCAPE[e]));return n}function nextToken(e){if(!e)return[e,void 0];const t=e.match(/^([^<]*)(<[^>]*>?)?/);if(!t)return[e,void 0];const n=t[1]?t[1]:t[2];return null==n?[e,n]:[e.substring(n.length),n]}function shouldAdd(e,t){return!NEEDS_PARENT[t.localName]||NEEDS_PARENT[t.localName]===e.localName}function createHtmlNode(e,t){const n=TAG_NAME[e];if(!n)return;const o=window.document.createElement(n),r=TAG_ANNOTATION[e];return r&&t&&(o[r]=t.trim()),o}export function parseCueText(e,t,{preferLineLength:n=0}={}){let o,r,l,s=e,c=-1;const a=[],u=[],i=[],d=e=>{0===u.length&&u.push([]),u.at(-1).push(t?t(e,(u.at(-1)??u.at(-2))?.at(-1)):e)},p=e=>{const t=a.pop()??"",n=o;if(o=n.parentElement||void 0,null==o){d({id:e,startTime:c>=0?c:void 0,tag:t,node:n}),r=n}},m=()=>`${u.length}-${(u.at(-1)?.length??0)+1}`,h=(e,t)=>{t?i.push(e):i[i.length-1]+=e,t&&u.push([]),null==o?0===e.trim().length&&!t&&r?r.appendChild(window.document.createTextNode(unescape(e))):(e=>{const t=createHtmlNode("c","");t.appendChild(window.document.createTextNode(unescape(e)));const n={id:m(),node:t,tag:"c",startTime:c>=0?c:void 0};d(n)})(e):o.appendChild(window.document.createTextNode(unescape(e)))};for(;null!=([s,l]=nextToken(s),l);)if("<"===l[0])if("/"===l[1])a.at(-1)===l.substring(2).replace(">","")&&p(m());else{const e=parseTimeStamp(l.substring(1,l.length-1));if(e)c=e;else{const e=l.match(/^<([^.\s/0-9>]+)(\.[^\s\\>]+)?([^>\\]+)?(\\?)>?$/),t=e&&createHtmlNode(e[1],e[3]);!t||o&&!shouldAdd(o,t)||(e[2]&&(t.className=e[2].substring(1).replace("."," ")),a.push(e[1]),o?.appendChild(t),o=t)}}else if(0===i.length||n>0&&i.at(-1).length+l.length>n){const e=splitRows(l,n);for(let t=0;t<e.length;t+=1)h(e[t],!0)}else h(l,!1);return{segments:u,rawText:i}}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@js-toolkit/web-utils",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.62.0",
|
|
4
4
|
"description": "Web utils",
|
|
5
5
|
"author": "VZH",
|
|
6
6
|
"license": "MIT",
|
|
@@ -24,7 +24,7 @@
|
|
|
24
24
|
"@eslint/eslintrc": "^3.2.0",
|
|
25
25
|
"@eslint/js": "^9.20.0",
|
|
26
26
|
"@js-toolkit/configs": "^3.94.0",
|
|
27
|
-
"@js-toolkit/utils": "^1.59.
|
|
27
|
+
"@js-toolkit/utils": "^1.59.1",
|
|
28
28
|
"@types/eslint": "^9.6.1",
|
|
29
29
|
"@types/eslint__eslintrc": "^2.1.2",
|
|
30
30
|
"@types/eslint__js": "^8.42.3",
|
|
@@ -41,7 +41,7 @@
|
|
|
41
41
|
"rimraf": "^6.0.1",
|
|
42
42
|
"terser": "^5.39.0",
|
|
43
43
|
"typescript": "^5.7.3",
|
|
44
|
-
"typescript-eslint": "^8.24.
|
|
44
|
+
"typescript-eslint": "^8.24.1",
|
|
45
45
|
"ua-parser-js": "^2.0.2",
|
|
46
46
|
"uuid": "^11.0.5",
|
|
47
47
|
"webpack": "^5.98.0",
|
|
@@ -1,2 +1,5 @@
|
|
|
1
|
+
import { getMediaSource } from '../media/getMediaSource';
|
|
2
|
+
type ManagedMediaSourceOption = Parameters<typeof getMediaSource>[0];
|
|
1
3
|
/** Media Source Extensions */
|
|
2
|
-
export declare function isMSESupported(): boolean;
|
|
4
|
+
export declare function isMSESupported(managedMediaSource?: ManagedMediaSourceOption): boolean;
|
|
5
|
+
export {};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{getMediaSource}from"../media/getMediaSource";
|
|
1
|
+
import{getMediaSource}from"../media/getMediaSource";import{getSourceBuffer}from"../media/getSourceBuffer";export function isMSESupported(e){if(!getMediaSource(e)?.isTypeSupported)return!1;const o=getSourceBuffer(e);return!o||o.prototype&&"function"==typeof o.prototype.appendBuffer&&"function"==typeof o.prototype.remove}
|
|
@@ -54,7 +54,7 @@ export declare namespace PeerConnection {
|
|
|
54
54
|
ReinitializingConnectionRequired = "ReinitializingConnectionRequired",
|
|
55
55
|
Closed = "Closed"
|
|
56
56
|
}
|
|
57
|
-
type EventMap = EventEmitter.
|
|
57
|
+
type EventMap = EventEmitter.EventMap<DefineAll<Events, {
|
|
58
58
|
[Events.LocalIceCandidate]: [RTCIceCandidate];
|
|
59
59
|
[Events.EndOfIceCandidates]: [];
|
|
60
60
|
[Events.Connected]: [];
|
|
@@ -63,7 +63,7 @@ export declare namespace PeerConnection {
|
|
|
63
63
|
[Events.ReinitializingConnectionRequired]: [];
|
|
64
64
|
[Events.Closed]: [];
|
|
65
65
|
}>, PeerConnection>;
|
|
66
|
-
type EventHandler<T extends Events = Events> = EventEmitter.
|
|
66
|
+
type EventHandler<T extends Events = Events> = EventEmitter.EventListener<EventMap, T, PeerConnection>;
|
|
67
67
|
type EventHandlerMap<T extends Events = Events> = {
|
|
68
68
|
[P in T]: EventHandler<P>;
|
|
69
69
|
};
|
package/ws/WSController.d.ts
CHANGED
|
@@ -37,7 +37,7 @@ export declare namespace WSController {
|
|
|
37
37
|
/** If connection was closed and the object will not to try to reconnect */
|
|
38
38
|
Closed = "Closed"
|
|
39
39
|
}
|
|
40
|
-
type EventMap<TData = unknown> = EventEmitter.
|
|
40
|
+
type EventMap<TData = unknown> = EventEmitter.EventMap<DefineAll<Events, {
|
|
41
41
|
[Events.Connected]: [];
|
|
42
42
|
[Events.Message]: [
|
|
43
43
|
event: OmitStrict<MessageEvent<TData>, keyof Event | 'initMessageEvent'>
|
|
@@ -47,5 +47,5 @@ export declare namespace WSController {
|
|
|
47
47
|
readonly reason: string;
|
|
48
48
|
} | undefined];
|
|
49
49
|
}>, WSController<TData>>;
|
|
50
|
-
type EventHandler<T extends Events = Events, TData = unknown> = EventEmitter.
|
|
50
|
+
type EventHandler<T extends Events = Events, TData = unknown> = EventEmitter.EventListener<EventMap<TData>, T, WSController<TData>>;
|
|
51
51
|
}
|