@npo/player 2.0.0-beta.2 → 2.0.0-beta.3

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,7 @@
1
+ export { getImageSize } from './utilities.images';
2
+ export { generateRandomId } from './utilities.random';
3
+ export { replaceSpecialCharacters } from './utilities.text';
4
+ export { isUrl, removeTrailingSlash } from './utilities.url';
5
+ export { logMediaEvents } from './utilities.logging';
6
+ export { isChrome } from './utilities.browser';
7
+ export { isValidNumber, clamp } from './utilities.numbers';
@@ -0,0 +1,10 @@
1
+ /**
2
+ * Lightweight EventTarget implementation for environments where the native constructor
3
+ * is either unavailable or throws when instantiated (older Chrome versions).
4
+ */
5
+ export declare class SimpleEventTarget implements EventTarget {
6
+ private listeners;
7
+ addEventListener(type: string, listener: EventListenerOrEventListenerObject | null): void;
8
+ removeEventListener(type: string, listener: EventListenerOrEventListenerObject | null): void;
9
+ dispatchEvent(event: Event): boolean;
10
+ }
@@ -0,0 +1,3 @@
1
+ export declare function isChrome(): boolean;
2
+ export type BrowserName = 'chrome' | 'chromium' | 'edge' | 'firefox' | 'safari' | 'opera';
3
+ export declare function isBrowser(browser: BrowserName): boolean;
@@ -0,0 +1,6 @@
1
+ import { NpoPlayerConfig, IStreamObjectMetadata, StreamOptions } from '@npo/player-types';
2
+ export declare const decideThumbnailSrc: ({ playerConfig, streamObjectMetaData, streamOptions }: {
3
+ playerConfig: NpoPlayerConfig;
4
+ streamObjectMetaData: IStreamObjectMetadata;
5
+ streamOptions: StreamOptions;
6
+ }) => string;
@@ -0,0 +1,15 @@
1
+ export type CreateOrReplaceElementQuery = {
2
+ tag: string;
3
+ className: string;
4
+ parentElement?: HTMLElement;
5
+ textContent?: string;
6
+ };
7
+ export declare function createOrReplaceElement(query: CreateOrReplaceElementQuery): HTMLElement;
8
+ export declare function appendToElement(element: HTMLElement, targetElement: HTMLElement): void;
9
+ export declare function getHTMLElement(parent: ParentNode, selector: string): HTMLElement | null;
10
+ export declare function setAriaLabel(element: HTMLElement, value: string): void;
11
+ export declare function setDataAttribute({ element, attribute, value }: {
12
+ element: HTMLElement;
13
+ attribute: string;
14
+ value: string;
15
+ }): void;
@@ -0,0 +1,4 @@
1
+ export declare function getImageSize(url: string, callback: (size: {
2
+ width: number;
3
+ height: number;
4
+ }) => void): void;
@@ -0,0 +1 @@
1
+ export declare function isJWTToken(token: string): boolean;
@@ -0,0 +1 @@
1
+ export declare function logMediaEvents(mediaElement: HTMLMediaElement): void;
@@ -0,0 +1,6 @@
1
+ export declare function isValidNumber(value: any): boolean;
2
+ export declare function clamp(number: number, bounds: {
3
+ min: number;
4
+ max: number;
5
+ }): number;
6
+ export declare function toOptionalNumber(value: unknown): number | undefined;
@@ -0,0 +1,28 @@
1
+ /**
2
+ * utilities.observables.ts
3
+ * A utility class that represents an observable property.
4
+ * It will poll the value returned by the `getValue` function at a given interval (defaults to 1000ms).
5
+ * If the value changes, it will dispatch an event with the new value.
6
+ * The event name can be customized by passing the `eventName` option (defaults to 'change').
7
+ * This can be used to observe changes in a value that is not observable in Shaka by default.
8
+ */
9
+ interface ObservablePropertyOptions<T> {
10
+ pollingInterval?: number;
11
+ equals?: (a: T, b: T) => boolean;
12
+ eventName?: string;
13
+ }
14
+ export declare class ObservableProperty<T> implements EventTarget {
15
+ private readonly getValue;
16
+ private lastValue;
17
+ private readonly intervalId;
18
+ private readonly pollingInterval;
19
+ private readonly equals;
20
+ private readonly eventName;
21
+ private readonly eventTarget;
22
+ constructor(getValue: () => T, options?: ObservablePropertyOptions<T>);
23
+ dispose(): void;
24
+ addEventListener(type: string, listener: EventListenerOrEventListenerObject | null): void;
25
+ removeEventListener(type: string, listener: EventListenerOrEventListenerObject | null): void;
26
+ dispatchEvent(event: Event): boolean;
27
+ }
28
+ export {};
@@ -0,0 +1 @@
1
+ export declare function generateRandomId(): string;
@@ -0,0 +1,8 @@
1
+ interface StreamDurationInSecondsParams {
2
+ duration: string | number | undefined;
3
+ durationIsInMs?: boolean;
4
+ }
5
+ export declare function getStreamDurationInSeconds(params: StreamDurationInSecondsParams): number;
6
+ export declare function validatePrid(prid: string | undefined): string;
7
+ export declare function getMimeType(urlString: string): string | undefined;
8
+ export {};
@@ -0,0 +1,7 @@
1
+ /**
2
+ * @function replaceSpecialCharacters
3
+ * @description Replaces special characters in the given text with their corresponding hexadecimal representation
4
+ * @param text - The input text containing special characters to be replaced
5
+ * @returns {string} - The text with special characters replaced by their hexadecimal representation
6
+ */
7
+ export declare function replaceSpecialCharacters(text: string): string;
@@ -0,0 +1,14 @@
1
+ /**
2
+ * @function isUrl
3
+ * @description Checks if the provided url is a valid url
4
+ * @param {string} url - The url to check
5
+ * @returns {boolean} True if the url is valid, false if not
6
+ */
7
+ export declare function isUrl(url: string): boolean;
8
+ /**
9
+ * @function removeTrailingSlash
10
+ * @description Removes the trailing slash from the provided url if it exists.
11
+ * @param {string} url - The url to remove the trailing slash from.
12
+ * @returns {string} The url without the trailing slash.
13
+ */
14
+ export declare const removeTrailingSlash: (url: string) => string;
@@ -0,0 +1,2 @@
1
+ import { MediaType } from '@npo/player-types';
2
+ export declare function normalizeStreamAvType(streamAvType: string): MediaType;
@@ -0,0 +1,93 @@
1
+ const r = Object.freeze({
2
+ BeforeUnload: "beforeunload",
3
+ Cancel: "cancel",
4
+ Change: "change",
5
+ Click: "click",
6
+ Error: "error",
7
+ Focus: "focus",
8
+ FocusIn: "focusin",
9
+ FocusOut: "focusout",
10
+ FullscreenChange: "fullscreenchange",
11
+ EnterPictureInPicture: "enterpictureinpicture",
12
+ KeyDown: "keydown",
13
+ LeavePictureInPicture: "leavepictureinpicture",
14
+ Load: "load",
15
+ MouseDown: "mousedown",
16
+ MouseLeave: "mouseleave",
17
+ MouseMove: "mousemove",
18
+ UnhandledRejection: "unhandledrejection"
19
+ });
20
+ function o(e, n) {
21
+ const t = new Image();
22
+ t.addEventListener(r.Load, () => {
23
+ n({ width: t.width, height: t.height });
24
+ }), t.src = e;
25
+ }
26
+ function a() {
27
+ return Math.random().toString(36).slice(2, 10);
28
+ }
29
+ function i(e) {
30
+ return e.replace(/['()*]/g, (n) => {
31
+ var t;
32
+ return `%${(t = n.codePointAt(0)) == null ? void 0 : t.toString(16).toUpperCase()}`;
33
+ });
34
+ }
35
+ function c(e) {
36
+ return /^(http|https):\/\/(?:www\.)?[\dA-Za-z-]+(?:\.[A-Za-z]{2,})+(?:\/[^ "]+)?(?:\?.*)?$/.test(e);
37
+ }
38
+ const s = (e) => e.endsWith("/") ? e.slice(0, -1) : e;
39
+ function u(e) {
40
+ const n = [
41
+ "loadstart",
42
+ "progress",
43
+ "suspend",
44
+ "abort",
45
+ "error",
46
+ "emptied",
47
+ "stalled",
48
+ "loadedmetadata",
49
+ "loadeddata",
50
+ "canplay",
51
+ "canplaythrough",
52
+ "playing",
53
+ "waiting",
54
+ "seeking",
55
+ "seeked",
56
+ "ended",
57
+ "durationchange",
58
+ "timeupdate",
59
+ "play",
60
+ "pause",
61
+ "ratechange",
62
+ "buffering",
63
+ "resize",
64
+ "volumechange"
65
+ ];
66
+ if (e)
67
+ for (const t of n)
68
+ e.addEventListener(t, () => {
69
+ console.log(`Event: ${t}`);
70
+ });
71
+ else
72
+ console.error("mediaElement is null. Cannot add event listeners.");
73
+ }
74
+ function d() {
75
+ return /Chrom(e|ium)/.test(navigator.userAgent);
76
+ }
77
+ function l(e) {
78
+ return !Number.isNaN(e) && Number.isFinite(e);
79
+ }
80
+ function g(e, n) {
81
+ return Number.isNaN(e) ? n.min : Math.max(n.min, Math.min(e, n.max));
82
+ }
83
+ export {
84
+ g as clamp,
85
+ a as generateRandomId,
86
+ o as getImageSize,
87
+ d as isChrome,
88
+ c as isUrl,
89
+ l as isValidNumber,
90
+ u as logMediaEvents,
91
+ s as removeTrailingSlash,
92
+ i as replaceSpecialCharacters
93
+ };
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@npo/player",
3
- "version": "2.0.0-beta.2",
4
- "description": "A library for creating and managing an audio player designed for playing content serviced by NPO (Nederlandse Publieke Omroep) in it's digital products",
3
+ "version": "2.0.0-beta.3",
4
+ "description": "A library for creating and managing a player designed for playing content serviced by NPO (Nederlandse Publieke Omroep) in it's digital products",
5
5
  "author": "NPO",
6
6
  "contributors": [
7
7
  "Sven van der Leest",
@@ -9,13 +9,17 @@
9
9
  "Michel Groot"
10
10
  ],
11
11
  "type": "module",
12
- "main": "./dist/npoplayer-audio",
12
+ "main": "./dist/npoplayer.umd.js",
13
13
  "types": "./dist/main.d.ts",
14
14
  "exports": {
15
15
  ".": {
16
- "import": "./dist/npoplayer-audio.es.js",
17
- "require": "./dist/npoplayer-audio.umd.js",
16
+ "import": "./dist/npoplayer.es.js",
17
+ "require": "./dist/npoplayer.umd.js",
18
18
  "types": "./dist/main.d.ts"
19
+ },
20
+ "./utilities": {
21
+ "import": "./dist/utilities.es.js",
22
+ "types": "./dist/utilities/index.d.ts"
19
23
  }
20
24
  },
21
25
  "files": [
@@ -25,7 +29,7 @@
25
29
  "test": "jest --runInBand",
26
30
  "test:ci": "jest --collectCoverage",
27
31
  "dev": "vite build --watch --mode watch",
28
- "build": "tsc && vite build && npm run build:legacy",
32
+ "build": "tsc && vite build && vite build --config vite.utilities.config.js && npm run build:legacy",
29
33
  "build:legacy": "tsc && vite build --config vite.legacy.config.js",
30
34
  "postinstall": "node -e \"var p=require('path'),f=require('fs'),d=p.join('node_modules','shaka-player','dist');try{f.readdirSync(d).filter(x=>x.endsWith('.d.ts')).forEach(x=>f.unlinkSync(p.join(d,x)))}catch(e){}\"",
31
35
  "lint": "eslint src --fix"