branch-video-player-sdk 0.2.0 → 0.2.2

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.js CHANGED
@@ -20,14 +20,14 @@ const w = "/branch-video-runtime/player.html", h = (e) => /^\d+$/.test(e) && Num
20
20
  if (t === -1) return E(e);
21
21
  const n = e.slice(0, t);
22
22
  return E(n) && !n.includes(":") && h(e.slice(t + 1));
23
- }, S = (e) => {
23
+ }, U = (e) => {
24
24
  const t = /^(https?):\/\/([^\s/?#]+)([/\?#].*)?$/i.exec(e);
25
25
  return !t || !V(t[2]) ? null : { authority: t[2], suffix: t[3] || "" };
26
- }, W = (e) => S(e) !== null, _ = (e, t) => {
26
+ }, W = (e) => U(e) !== null, _ = (e, t) => {
27
27
  if (!W(t) || e === "runtimeUrl" && t.includes("#")) throw new TypeError(`${e} must be an absolute HTTP(S) URL`);
28
28
  return t;
29
29
  }, $ = (e) => {
30
- const t = S(e);
30
+ const t = U(e);
31
31
  if (!t || t.suffix && t.suffix !== "/") throw new TypeError("parentOrigin must be an HTTP(S) origin");
32
32
  return e.endsWith("/") ? e.slice(0, -1) : e;
33
33
  };
@@ -51,15 +51,15 @@ const O = {
51
51
  WPS_EVT_BUFFER_CHANGE: "bufferchange",
52
52
  WPS_EVT_MILESTONE: "milestone",
53
53
  WPS_EVT_EXIT_REQUESTED: "exitrequested"
54
- }, y = (e) => {
54
+ }, R = (e) => {
55
55
  if (typeof e != "string") return e;
56
56
  const t = document.querySelector(e);
57
57
  if (!t) throw new Error(`BranchVideo player container not found: ${e}`);
58
58
  return t;
59
59
  };
60
- function N(e) {
61
- const t = e.parentOrigin ?? window.location.origin, n = e.runtimeUrl || w, i = b({ ...e, parentOrigin: t, runtimeUrl: n }), o = new URL(n, window.location.href).origin, r = document.createElement("iframe");
62
- r.src = i, r.allow = "autoplay; fullscreen", r.title = e.title || "BranchVideo player", e.className && (r.className = e.className), y(e.container).appendChild(r);
60
+ function y(e) {
61
+ const t = e.parentOrigin ?? window.location.origin, n = new URL(e.runtimeUrl || w, window.location.href).href, i = b({ ...e, parentOrigin: t, runtimeUrl: n }), o = new URL(n).origin, r = document.createElement("iframe");
62
+ r.src = i, r.allow = "autoplay; fullscreen", r.title = e.title || "BranchVideo player", e.className && (r.className = e.className), R(e.container).appendChild(r);
63
63
  const f = /* @__PURE__ */ new Map(), d = [];
64
64
  let l = "pending", u = !1;
65
65
  const m = (s, c) => {
@@ -70,7 +70,7 @@ function N(e) {
70
70
  }
71
71
  l !== "failed" && r.contentWindow?.postMessage({ eventName: s, data: c, timestamp: Date.now() }, o);
72
72
  }
73
- }, U = () => {
73
+ }, S = () => {
74
74
  for (; d.length; ) {
75
75
  const s = d.shift();
76
76
  r.contentWindow?.postMessage({ ...s, timestamp: Date.now() }, o);
@@ -87,7 +87,7 @@ function N(e) {
87
87
  return;
88
88
  }
89
89
  if (l !== "pending") return;
90
- l = "ready", U();
90
+ l = "ready", S();
91
91
  }
92
92
  a === "error" && l === "pending" && (l = "failed", d.length = 0), f.get(a)?.forEach((g) => g(c.data));
93
93
  }
@@ -111,5 +111,5 @@ function N(e) {
111
111
  export {
112
112
  w as DEFAULT_RUNTIME_PATH,
113
113
  b as buildBranchVideoPlayerUrl,
114
- N as createBranchVideoPlayer
114
+ y as createBranchVideoPlayer
115
115
  };
@@ -1 +1 @@
1
- (function(l,f){typeof exports=="object"&&typeof module<"u"?f(exports):typeof define=="function"&&define.amd?define(["exports"],f):(l=typeof globalThis<"u"?globalThis:l||self,f(l.BranchVideoPlayerSDK={}))})(this,(function(l){"use strict";const f="/branch-video-runtime/player.html",h=e=>/^\d+$/.test(e)&&Number(e)>0&&Number(e)<=65535,w=e=>{const n=e.split(".");return n.length===4&&n.every(t=>/^\d+$/.test(t)&&Number(t)<=255)},V=e=>{if(!/^[0-9a-f:]+$/i.test(e))return!1;const n=e.split("::");if(n.length>2)return!1;const t=n.flatMap(i=>i?i.split(":"):[]);return t.every(i=>/^[0-9a-f]{1,4}$/i.test(i))?n.length===2?t.length<8:t.length===8:!1},E=e=>{const n=e.endsWith(".")?e.slice(0,-1):e;return/^[\d.]+$/.test(n)?w(n):!!n&&!n.includes("..")&&n.split(".").every(t=>/^[a-z0-9](?:[a-z0-9-]*[a-z0-9])?$/i.test(t))},y=e=>{if(!e||e.includes("@"))return!1;if(e.startsWith("[")){const i=e.indexOf("]"),o=e.slice(1,i),r=e.slice(i+1);return i<=1||!V(o)?!1:!r||r.startsWith(":")&&h(r.slice(1))}const n=e.lastIndexOf(":");if(n===-1)return E(e);const t=e.slice(0,n);return E(t)&&!t.includes(":")&&h(e.slice(n+1))},_=e=>{const n=/^(https?):\/\/([^\s/?#]+)([/\?#].*)?$/i.exec(e);return!n||!y(n[2])?null:{authority:n[2],suffix:n[3]||""}},b=e=>_(e)!==null,T=(e,n)=>{if(!b(n)||e==="runtimeUrl"&&n.includes("#"))throw new TypeError(`${e} must be an absolute HTTP(S) URL`);return n},W=e=>{const n=_(e);if(!n||n.suffix&&n.suffix!=="/")throw new TypeError("parentOrigin must be an HTTP(S) origin");return e.endsWith("/")?e.slice(0,-1):e};function P(e){const n=e.runtimeUrl?T("runtimeUrl",e.runtimeUrl):f,t=T("scriptUrl",e.scriptUrl),i=e.parentOrigin===void 0?void 0:W(e.parentOrigin),o=[`script=${encodeURIComponent(t)}`,"embedPlatform=web_player_sdk","sdkProtocol=1"];i&&o.push(`parentOrigin=${encodeURIComponent(i)}`),e.cshost&&o.push(`cshost=${encodeURIComponent(e.cshost)}`),e.controls!==void 0&&o.push(`controls=${e.controls}`),e.debug!==void 0&&o.push(`debug=${e.debug}`);const r=n.includes("?")?"&":"?";return`${n}${r}${o.join("&")}`}const $={WPS_EVT_LOADED:"loaded",WPS_EVT_READY:"ready",WPS_EVT_STATE_CHANGE:"statechange",WPS_EVT_PROGRESS:"progress",WPS_EVT_ENDED:"ended",WPS_EVT_ERROR:"error",WPS_EVT_BUFFER_CHANGE:"bufferchange",WPS_EVT_MILESTONE:"milestone",WPS_EVT_EXIT_REQUESTED:"exitrequested"},O=e=>{if(typeof e!="string")return e;const n=document.querySelector(e);if(!n)throw new Error(`BranchVideo player container not found: ${e}`);return n};function N(e){const n=e.parentOrigin??window.location.origin,t=e.runtimeUrl||f,i=P({...e,parentOrigin:n,runtimeUrl:t}),o=new URL(t,window.location.href).origin,r=document.createElement("iframe");r.src=i,r.allow="autoplay; fullscreen",r.title=e.title||"BranchVideo player",e.className&&(r.className=e.className),O(e.container).appendChild(r);const m=new Map,u=[];let a="pending",p=!1;const g=(s,c)=>{if(!p){if(a==="pending"){u.push({eventName:s,data:c});return}a!=="failed"&&r.contentWindow?.postMessage({eventName:s,data:c,timestamp:Date.now()},o)}},R=()=>{for(;u.length;){const s=u.shift();r.contentWindow?.postMessage({...s,timestamp:Date.now()},o)}},S=s=>{if(p||s.source!==r.contentWindow||s.origin!==o)return;const c=s.data;if(!c||typeof c.eventName!="string")return;const d=$[c.eventName];if(d){if(d==="ready"){if(c.data?.protocolVersion!==1){a==="pending"&&(a="failed",u.length=0);return}if(a!=="pending")return;a="ready",R()}d==="error"&&a==="pending"&&(a="failed",u.length=0),m.get(d)?.forEach(U=>U(c.data))}};return window.addEventListener("message",S),{iframe:r,play:()=>g("WPS_CMD_PLAY"),pause:()=>g("WPS_CMD_PAUSE"),seek:s=>{Number.isFinite(s)&&g("WPS_CMD_SEEK",{position:Math.max(0,s)})},on:(s,c)=>{const d=m.get(s)||new Set;return d.add(c),m.set(s,d),()=>d.delete(c)},destroy:()=>{p||(p=!0,u.length=0,m.clear(),window.removeEventListener("message",S),r.remove())}}}l.DEFAULT_RUNTIME_PATH=f,l.buildBranchVideoPlayerUrl=P,l.createBranchVideoPlayer=N,Object.defineProperty(l,Symbol.toStringTag,{value:"Module"})}));
1
+ (function(l,f){typeof exports=="object"&&typeof module<"u"?f(exports):typeof define=="function"&&define.amd?define(["exports"],f):(l=typeof globalThis<"u"?globalThis:l||self,f(l.BranchVideoPlayerSDK={}))})(this,(function(l){"use strict";const f="/branch-video-runtime/player.html",h=e=>/^\d+$/.test(e)&&Number(e)>0&&Number(e)<=65535,w=e=>{const n=e.split(".");return n.length===4&&n.every(t=>/^\d+$/.test(t)&&Number(t)<=255)},V=e=>{if(!/^[0-9a-f:]+$/i.test(e))return!1;const n=e.split("::");if(n.length>2)return!1;const t=n.flatMap(i=>i?i.split(":"):[]);return t.every(i=>/^[0-9a-f]{1,4}$/i.test(i))?n.length===2?t.length<8:t.length===8:!1},E=e=>{const n=e.endsWith(".")?e.slice(0,-1):e;return/^[\d.]+$/.test(n)?w(n):!!n&&!n.includes("..")&&n.split(".").every(t=>/^[a-z0-9](?:[a-z0-9-]*[a-z0-9])?$/i.test(t))},y=e=>{if(!e||e.includes("@"))return!1;if(e.startsWith("[")){const i=e.indexOf("]"),o=e.slice(1,i),r=e.slice(i+1);return i<=1||!V(o)?!1:!r||r.startsWith(":")&&h(r.slice(1))}const n=e.lastIndexOf(":");if(n===-1)return E(e);const t=e.slice(0,n);return E(t)&&!t.includes(":")&&h(e.slice(n+1))},_=e=>{const n=/^(https?):\/\/([^\s/?#]+)([/\?#].*)?$/i.exec(e);return!n||!y(n[2])?null:{authority:n[2],suffix:n[3]||""}},b=e=>_(e)!==null,T=(e,n)=>{if(!b(n)||e==="runtimeUrl"&&n.includes("#"))throw new TypeError(`${e} must be an absolute HTTP(S) URL`);return n},W=e=>{const n=_(e);if(!n||n.suffix&&n.suffix!=="/")throw new TypeError("parentOrigin must be an HTTP(S) origin");return e.endsWith("/")?e.slice(0,-1):e};function P(e){const n=e.runtimeUrl?T("runtimeUrl",e.runtimeUrl):f,t=T("scriptUrl",e.scriptUrl),i=e.parentOrigin===void 0?void 0:W(e.parentOrigin),o=[`script=${encodeURIComponent(t)}`,"embedPlatform=web_player_sdk","sdkProtocol=1"];i&&o.push(`parentOrigin=${encodeURIComponent(i)}`),e.cshost&&o.push(`cshost=${encodeURIComponent(e.cshost)}`),e.controls!==void 0&&o.push(`controls=${e.controls}`),e.debug!==void 0&&o.push(`debug=${e.debug}`);const r=n.includes("?")?"&":"?";return`${n}${r}${o.join("&")}`}const $={WPS_EVT_LOADED:"loaded",WPS_EVT_READY:"ready",WPS_EVT_STATE_CHANGE:"statechange",WPS_EVT_PROGRESS:"progress",WPS_EVT_ENDED:"ended",WPS_EVT_ERROR:"error",WPS_EVT_BUFFER_CHANGE:"bufferchange",WPS_EVT_MILESTONE:"milestone",WPS_EVT_EXIT_REQUESTED:"exitrequested"},O=e=>{if(typeof e!="string")return e;const n=document.querySelector(e);if(!n)throw new Error(`BranchVideo player container not found: ${e}`);return n};function R(e){const n=e.parentOrigin??window.location.origin,t=new URL(e.runtimeUrl||f,window.location.href).href,i=P({...e,parentOrigin:n,runtimeUrl:t}),o=new URL(t).origin,r=document.createElement("iframe");r.src=i,r.allow="autoplay; fullscreen",r.title=e.title||"BranchVideo player",e.className&&(r.className=e.className),O(e.container).appendChild(r);const m=new Map,u=[];let a="pending",p=!1;const g=(s,c)=>{if(!p){if(a==="pending"){u.push({eventName:s,data:c});return}a!=="failed"&&r.contentWindow?.postMessage({eventName:s,data:c,timestamp:Date.now()},o)}},N=()=>{for(;u.length;){const s=u.shift();r.contentWindow?.postMessage({...s,timestamp:Date.now()},o)}},U=s=>{if(p||s.source!==r.contentWindow||s.origin!==o)return;const c=s.data;if(!c||typeof c.eventName!="string")return;const d=$[c.eventName];if(d){if(d==="ready"){if(c.data?.protocolVersion!==1){a==="pending"&&(a="failed",u.length=0);return}if(a!=="pending")return;a="ready",N()}d==="error"&&a==="pending"&&(a="failed",u.length=0),m.get(d)?.forEach(S=>S(c.data))}};return window.addEventListener("message",U),{iframe:r,play:()=>g("WPS_CMD_PLAY"),pause:()=>g("WPS_CMD_PAUSE"),seek:s=>{Number.isFinite(s)&&g("WPS_CMD_SEEK",{position:Math.max(0,s)})},on:(s,c)=>{const d=m.get(s)||new Set;return d.add(c),m.set(s,d),()=>d.delete(c)},destroy:()=>{p||(p=!0,u.length=0,m.clear(),window.removeEventListener("message",U),r.remove())}}}l.DEFAULT_RUNTIME_PATH=f,l.buildBranchVideoPlayerUrl=P,l.createBranchVideoPlayer=R,Object.defineProperty(l,Symbol.toStringTag,{value:"Module"})}));
package/dist/vite.cjs CHANGED
@@ -1 +1 @@
1
- "use strict";Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const o=require("node:path"),l=require("node:url"),e=require("node:fs");var i=typeof document<"u"?document.currentScript:null;const p=o.dirname(l.fileURLToPath(typeof document>"u"?require("url").pathToFileURL(__filename).href:i&&i.tagName.toUpperCase()==="SCRIPT"&&i.src||new URL("vite.cjs",document.baseURI).href));function c(u={}){const s=u.publicPath||"branch-video-runtime",r=o.resolve(p,"../runtime");return{name:"branch-video-player-sdk",config(t){const a=typeof t.publicDir=="string"?t.publicDir:"public",d=t.root??process.cwd(),n=o.resolve(d,a,s);if(!e.existsSync(r))throw new Error(`[branch-video-player-sdk] Runtime 静态资源不存在:${r}。请确认 npm 包已正确安装。`);(!e.existsSync(n)||e.statSync(r).mtime>e.statSync(n).mtime)&&e.cpSync(r,n,{recursive:!0,force:!0})}}}exports.branchVideoPlayerSdkPlugin=c;exports.default=c;
1
+ "use strict";Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const o=require("node:path"),l=require("node:url"),e=require("node:fs");var i=typeof document<"u"?document.currentScript:null;const p=o.dirname(l.fileURLToPath(typeof document>"u"?require("url").pathToFileURL(__filename).href:i&&i.tagName.toUpperCase()==="SCRIPT"&&i.src||new URL("vite.cjs",document.baseURI).href));function c(u={}){const s=u.publicPath||"branch-video-runtime",r=o.resolve(p,"./runtime");return{name:"branch-video-player-sdk",config(t){const a=typeof t.publicDir=="string"?t.publicDir:"public",d=t.root??process.cwd(),n=o.resolve(d,a,s);if(!e.existsSync(r))throw new Error(`[branch-video-player-sdk] Runtime 静态资源不存在:${r}。请确认 npm 包已正确安装。`);(!e.existsSync(n)||e.statSync(r).mtime>e.statSync(n).mtime)&&e.cpSync(r,n,{recursive:!0,force:!0})}}}exports.branchVideoPlayerSdkPlugin=c;exports.default=c;
package/dist/vite.js CHANGED
@@ -3,7 +3,7 @@ import { fileURLToPath as p } from "node:url";
3
3
  import { existsSync as o, statSync as n, cpSync as a } from "node:fs";
4
4
  const l = i.dirname(p(import.meta.url));
5
5
  function y(c = {}) {
6
- const s = c.publicPath || "branch-video-runtime", r = i.resolve(l, "../runtime");
6
+ const s = c.publicPath || "branch-video-runtime", r = i.resolve(l, "./runtime");
7
7
  return {
8
8
  name: "branch-video-player-sdk",
9
9
  config(e) {
package/package.json CHANGED
@@ -1,16 +1,30 @@
1
1
  {
2
2
  "name": "branch-video-player-sdk",
3
- "version": "0.2.0",
3
+ "version": "0.2.2",
4
4
  "type": "module",
5
5
  "main": "./dist/index.umd.cjs",
6
6
  "module": "./dist/index.js",
7
7
  "types": "./dist/index.d.ts",
8
8
  "unpkg": "./dist/index.umd.cjs",
9
9
  "exports": {
10
- ".": { "types": "./dist/index.d.ts", "import": "./dist/index.js", "require": "./dist/index.umd.cjs" },
11
- "./url": { "types": "./dist/url.d.ts", "import": "./dist/url.js", "require": "./dist/url.cjs" },
12
- "./vite": { "types": "./dist/vite.d.ts", "import": "./dist/vite.js", "require": "./dist/vite.cjs" }
10
+ ".": {
11
+ "types": "./dist/index.d.ts",
12
+ "import": "./dist/index.js",
13
+ "require": "./dist/index.umd.cjs"
14
+ },
15
+ "./url": {
16
+ "types": "./dist/url.d.ts",
17
+ "import": "./dist/url.js",
18
+ "require": "./dist/url.cjs"
19
+ },
20
+ "./vite": {
21
+ "types": "./dist/vite.d.ts",
22
+ "import": "./dist/vite.js",
23
+ "require": "./dist/vite.cjs"
24
+ }
13
25
  },
14
- "files": ["dist", "README.md"]
26
+ "files": [
27
+ "dist",
28
+ "README.md"
29
+ ]
15
30
  }
16
-