kplayer-ts 1.0.2 → 1.0.4

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,2 @@
1
+ Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:`Module`}});var e=Object.create,t=Object.defineProperty,n=Object.getOwnPropertyDescriptor,r=Object.getOwnPropertyNames,i=Object.getPrototypeOf,a=Object.prototype.hasOwnProperty,o=(e,i,o,s)=>{if(i&&typeof i==`object`||typeof i==`function`)for(var c=r(i),l=0,u=c.length,d;l<u;l++)d=c[l],!a.call(e,d)&&d!==o&&t(e,d,{get:(e=>i[e]).bind(null,d),enumerable:!(s=n(i,d))||s.enumerable});return e},s=(n,r,a)=>(a=n==null?{}:e(i(n)),o(r||!n||!n.__esModule?t(a,`default`,{value:n,enumerable:!0}):a,n));let c=require("react"),l=require("kplayer-ts");l=s(l,1);let u=require("react/jsx-runtime");function d(e,t){typeof e==`function`?e(t):e&&(e.current=t)}var f=(0,c.forwardRef)(function({options:e,onReady:t,...n},r){let i=(0,c.useRef)(null),a=(0,c.useRef)(e),o=(0,c.useRef)(t);return a.current=e,o.current=t,(0,c.useEffect)(()=>{if(!i.current)return;let e=new l.default({...a.current,container:i.current});return d(r,e),o.current?.(e),()=>{e.destroy(),d(r,null)}},[]),(0,u.jsx)(`div`,{ref:i,...n})});exports.KPlayer=f,exports.default=f;
2
+ //# sourceMappingURL=index.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.cjs","names":[],"sources":["../../src/react/index.tsx"],"sourcesContent":["import {\n forwardRef,\n useEffect,\n useRef,\n type ForwardedRef,\n type HTMLAttributes,\n} from \"react\";\nimport KPlayerCore from \"kplayer-ts\";\nimport type { KPlayerOptions } from \"kplayer-ts\";\n\n/** The underlying vanilla player instance (same as `new KPlayer(...)`). */\nexport type KPlayerInstance = KPlayerCore;\n\nexport interface KPlayerProps extends HTMLAttributes<HTMLDivElement> {\n /**\n * Player options — same as the vanilla `KPlayer` options, but WITHOUT\n * `container` (the component provides its own `<div>` as the container).\n */\n options: Omit<KPlayerOptions, \"container\">;\n /** Called once with the player instance right after it is created. */\n onReady?: (player: KPlayerInstance) => void;\n}\n\nfunction assignRef(\n ref: ForwardedRef<KPlayerInstance>,\n value: KPlayerInstance | null,\n): void {\n if (typeof ref === \"function\") ref(value);\n else if (ref) ref.current = value;\n}\n\n/**\n * React/Next.js wrapper around KPlayer.\n *\n * The player is created in `useEffect` (browser only) and destroyed on unmount,\n * so it is SSR-safe. Access the underlying instance via a ref or `onReady`.\n *\n * ```tsx\n * import { KPlayer } from \"kplayer-ts/react\";\n *\n * <KPlayer options={{ video: { url: \"demo.m3u8\", type: \"hls\" } }} />\n * ```\n *\n * Options are read once on mount — to load a different video, give the component\n * a new `key` (to remount it) or drive it imperatively through the ref / `onReady`.\n */\nexport const KPlayer = forwardRef<KPlayerInstance, KPlayerProps>(\n function KPlayer({ options, onReady, ...divProps }, ref) {\n const containerRef = useRef<HTMLDivElement>(null);\n // Keep latest options/callback in refs so re-renders never recreate the player.\n const optionsRef = useRef(options);\n const onReadyRef = useRef(onReady);\n optionsRef.current = options;\n onReadyRef.current = onReady;\n\n useEffect(() => {\n if (!containerRef.current) return;\n const player = new KPlayerCore({\n ...optionsRef.current,\n container: containerRef.current,\n } as KPlayerOptions);\n assignRef(ref, player);\n onReadyRef.current?.(player);\n\n return () => {\n player.destroy();\n assignRef(ref, null);\n };\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, []);\n\n return <div ref={containerRef} {...divProps} />;\n },\n);\n\nexport default KPlayer;\n\nexport type { KPlayerOptions } from \"kplayer-ts\";\n"],"mappings":"wpBAuBA,SAAS,EACP,EACA,EACM,CACF,OAAO,GAAQ,WAAY,EAAI,CAAK,EAC/B,IAAK,EAAI,QAAU,EAC9B,CAiBA,IAAa,GAAA,EAAA,EAAA,YACX,SAAiB,CAAE,UAAS,UAAS,GAAG,GAAY,EAAK,CACvD,IAAM,GAAA,EAAA,EAAA,QAAsC,IAAI,EAE1C,GAAA,EAAA,EAAA,QAAoB,CAAO,EAC3B,GAAA,EAAA,EAAA,QAAoB,CAAO,EAoBjC,MAnBA,GAAW,QAAU,EACrB,EAAW,QAAU,GAErB,EAAA,EAAA,eAAgB,CACd,GAAI,CAAC,EAAa,QAAS,OAC3B,IAAM,EAAS,IAAI,EAAA,QAAY,CAC7B,GAAG,EAAW,QACd,UAAW,EAAa,OAC1B,CAAmB,EAInB,OAHA,EAAU,EAAK,CAAM,EACrB,EAAW,UAAU,CAAM,MAEd,CACX,EAAO,QAAQ,EACf,EAAU,EAAK,IAAI,CACrB,CAEF,EAAG,CAAC,CAAC,GAEE,EAAA,EAAA,KAAC,MAAD,CAAK,IAAK,EAAc,GAAI,CAAW,CAAA,CAChD,CACF"}
@@ -0,0 +1,31 @@
1
+ import { HTMLAttributes } from 'react';
2
+ import { default as KPlayerCore, KPlayerOptions } from '../ts/index';
3
+ /** The underlying vanilla player instance (same as `new KPlayer(...)`). */
4
+ export type KPlayerInstance = KPlayerCore;
5
+ export interface KPlayerProps extends HTMLAttributes<HTMLDivElement> {
6
+ /**
7
+ * Player options — same as the vanilla `KPlayer` options, but WITHOUT
8
+ * `container` (the component provides its own `<div>` as the container).
9
+ */
10
+ options: Omit<KPlayerOptions, "container">;
11
+ /** Called once with the player instance right after it is created. */
12
+ onReady?: (player: KPlayerInstance) => void;
13
+ }
14
+ /**
15
+ * React/Next.js wrapper around KPlayer.
16
+ *
17
+ * The player is created in `useEffect` (browser only) and destroyed on unmount,
18
+ * so it is SSR-safe. Access the underlying instance via a ref or `onReady`.
19
+ *
20
+ * ```tsx
21
+ * import { KPlayer } from "kplayer-ts/react";
22
+ *
23
+ * <KPlayer options={{ video: { url: "demo.m3u8", type: "hls" } }} />
24
+ * ```
25
+ *
26
+ * Options are read once on mount — to load a different video, give the component
27
+ * a new `key` (to remount it) or drive it imperatively through the ref / `onReady`.
28
+ */
29
+ export declare const KPlayer: import('react').ForwardRefExoticComponent<KPlayerProps & import('react').RefAttributes<KPlayerCore>>;
30
+ export default KPlayer;
31
+ export type { KPlayerOptions } from '../ts/index';
@@ -0,0 +1,27 @@
1
+ import { forwardRef as e, useEffect as t, useRef as n } from "react";
2
+ import r from "kplayer-ts";
3
+ import { jsx as i } from "react/jsx-runtime";
4
+ //#region src/react/index.tsx
5
+ function a(e, t) {
6
+ typeof e == "function" ? e(t) : e && (e.current = t);
7
+ }
8
+ var o = e(function({ options: e, onReady: o, ...s }, c) {
9
+ let l = n(null), u = n(e), d = n(o);
10
+ return u.current = e, d.current = o, t(() => {
11
+ if (!l.current) return;
12
+ let e = new r({
13
+ ...u.current,
14
+ container: l.current
15
+ });
16
+ return a(c, e), d.current?.(e), () => {
17
+ e.destroy(), a(c, null);
18
+ };
19
+ }, []), /* @__PURE__ */ i("div", {
20
+ ref: l,
21
+ ...s
22
+ });
23
+ });
24
+ //#endregion
25
+ export { o as KPlayer, o as default };
26
+
27
+ //# sourceMappingURL=index.es.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.es.js","names":[],"sources":["../../src/react/index.tsx"],"sourcesContent":["import {\n forwardRef,\n useEffect,\n useRef,\n type ForwardedRef,\n type HTMLAttributes,\n} from \"react\";\nimport KPlayerCore from \"kplayer-ts\";\nimport type { KPlayerOptions } from \"kplayer-ts\";\n\n/** The underlying vanilla player instance (same as `new KPlayer(...)`). */\nexport type KPlayerInstance = KPlayerCore;\n\nexport interface KPlayerProps extends HTMLAttributes<HTMLDivElement> {\n /**\n * Player options — same as the vanilla `KPlayer` options, but WITHOUT\n * `container` (the component provides its own `<div>` as the container).\n */\n options: Omit<KPlayerOptions, \"container\">;\n /** Called once with the player instance right after it is created. */\n onReady?: (player: KPlayerInstance) => void;\n}\n\nfunction assignRef(\n ref: ForwardedRef<KPlayerInstance>,\n value: KPlayerInstance | null,\n): void {\n if (typeof ref === \"function\") ref(value);\n else if (ref) ref.current = value;\n}\n\n/**\n * React/Next.js wrapper around KPlayer.\n *\n * The player is created in `useEffect` (browser only) and destroyed on unmount,\n * so it is SSR-safe. Access the underlying instance via a ref or `onReady`.\n *\n * ```tsx\n * import { KPlayer } from \"kplayer-ts/react\";\n *\n * <KPlayer options={{ video: { url: \"demo.m3u8\", type: \"hls\" } }} />\n * ```\n *\n * Options are read once on mount — to load a different video, give the component\n * a new `key` (to remount it) or drive it imperatively through the ref / `onReady`.\n */\nexport const KPlayer = forwardRef<KPlayerInstance, KPlayerProps>(\n function KPlayer({ options, onReady, ...divProps }, ref) {\n const containerRef = useRef<HTMLDivElement>(null);\n // Keep latest options/callback in refs so re-renders never recreate the player.\n const optionsRef = useRef(options);\n const onReadyRef = useRef(onReady);\n optionsRef.current = options;\n onReadyRef.current = onReady;\n\n useEffect(() => {\n if (!containerRef.current) return;\n const player = new KPlayerCore({\n ...optionsRef.current,\n container: containerRef.current,\n } as KPlayerOptions);\n assignRef(ref, player);\n onReadyRef.current?.(player);\n\n return () => {\n player.destroy();\n assignRef(ref, null);\n };\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, []);\n\n return <div ref={containerRef} {...divProps} />;\n },\n);\n\nexport default KPlayer;\n\nexport type { KPlayerOptions } from \"kplayer-ts\";\n"],"mappings":";;;;AAuBA,SAAS,EACP,GACA,GACM;CACN,AAAI,OAAO,KAAQ,aAAY,EAAI,CAAK,IAC/B,MAAK,EAAI,UAAU;AAC9B;AAiBA,IAAa,IAAU,EACrB,SAAiB,EAAE,YAAS,YAAS,GAAG,KAAY,GAAK;CACvD,IAAM,IAAe,EAAuB,IAAI,GAE1C,IAAa,EAAO,CAAO,GAC3B,IAAa,EAAO,CAAO;CAoBjC,OAnBA,EAAW,UAAU,GACrB,EAAW,UAAU,GAErB,QAAgB;EACd,IAAI,CAAC,EAAa,SAAS;EAC3B,IAAM,IAAS,IAAI,EAAY;GAC7B,GAAG,EAAW;GACd,WAAW,EAAa;EAC1B,CAAmB;EAInB,OAHA,EAAU,GAAK,CAAM,GACrB,EAAW,UAAU,CAAM,SAEd;GAEX,AADA,EAAO,QAAQ,GACf,EAAU,GAAK,IAAI;EACrB;CAEF,GAAG,CAAC,CAAC,GAEE,kBAAC,OAAD;EAAK,KAAK;EAAc,GAAI;CAAW,CAAA;AAChD,CACF"}
@@ -10,6 +10,11 @@ declare class Controller {
10
10
  private _skipTarget;
11
11
  private session;
12
12
  private currentMedia;
13
+ private _tapTime;
14
+ private _tapSide;
15
+ private _tapTimer;
16
+ private _seekAccum;
17
+ private _rippleTimer;
13
18
  constructor(player: KPlayer);
14
19
  initPlayButton(): void;
15
20
  initSeekButtons(): void;
@@ -33,6 +38,8 @@ declare class Controller {
33
38
  hide(): void;
34
39
  isShow(): boolean;
35
40
  toggle(): void;
41
+ private _setupMobileTapSeek;
42
+ private _showSeekRipple;
36
43
  destroy(): void;
37
44
  }
38
45
  export default Controller;
@@ -74,12 +74,14 @@ declare class KPlayer {
74
74
  switchingQuality: boolean;
75
75
  prevIndex?: number;
76
76
  prevVideo?: HTMLVideoElement;
77
+ resizeObserver?: ResizeObserver;
77
78
  constructor(options: Partial<KPlayerOptions> & {
78
79
  video: KPlayerOptions["video"];
79
80
  });
80
81
  seek(time: number): void;
81
82
  play(fromNative?: boolean): void;
82
83
  pause(fromNative?: boolean): void;
84
+ private _setPlayLabel;
83
85
  switchVolumeIcon(): void;
84
86
  volume(percentage?: number, nostorage?: boolean, nonotice?: boolean): number;
85
87
  toggle(): void;
@@ -101,6 +103,7 @@ declare class KPlayer {
101
103
  speed(rate: number): void;
102
104
  destroy(): void;
103
105
  static get version(): string;
106
+ private _resolveSubtitleCrypto;
104
107
  private _loadSubtitleTexts;
105
108
  loadSubtitleByIndex(index: number): Promise<void>;
106
109
  }
@@ -8,6 +8,7 @@ declare class Setting {
8
8
  chromecastEntry: HTMLElement | null;
9
9
  screenshotEntry: HTMLElement | null;
10
10
  constructor(player: KPlayer);
11
+ private _setupMenuA11y;
11
12
  hide(): void;
12
13
  show(): void;
13
14
  }
@@ -24,6 +24,23 @@ export interface SubtitleOptions {
24
24
  encrypt?: boolean;
25
25
  iv?: string;
26
26
  key?: string;
27
+ /**
28
+ * `key`/`iv`-г статикаар bundle/page-д бичихийн оронд ажиллах үед (жишээ нь
29
+ * нэвтрэлт шаардсан backend-ээс) татаж авах async provider. Өгсөн бол `key`/
30
+ * `iv`-ийн оронд үүнийг ашиглана.
31
+ *
32
+ * ⚠️ Аюулгүй байдлын анхааруулга: тайлалт нь browser талд хийгддэг тул
33
+ * түлхүүрийг хэрэглэгчээс БҮРЭН нуух боломжгүй — DevTools / Network tab-аас
34
+ * үргэлж олж болно. Энэ нь зөвхөн casual scraping-ийг хүндрүүлэх зорилготой.
35
+ * Жинхэнэ контент хамгаалалт хэрэгтэй бол DRM (EME/Widevine/FairPlay) ашигла.
36
+ */
37
+ keyProvider?: () => {
38
+ key: string;
39
+ iv: string;
40
+ } | Promise<{
41
+ key: string;
42
+ iv: string;
43
+ }>;
27
44
  }
28
45
  export interface AdItem {
29
46
  name?: string;
package/package.json CHANGED
@@ -1,25 +1,57 @@
1
1
  {
2
2
  "name": "kplayer-ts",
3
- "version": "1.0.2",
3
+ "version": "1.0.4",
4
4
  "description": "Kenji video player - TypeScript",
5
- "main": "dist/kplayer-ts.cjs.js",
6
- "module": "dist/kplayer-ts.es.js",
7
- "types": "dist/kplayer-ts.d.ts",
5
+ "type": "module",
6
+ "main": "./dist/kplayer-ts.cjs",
7
+ "module": "./dist/kplayer-ts.es.js",
8
+ "types": "./dist/kplayer-ts.d.ts",
9
+ "unpkg": "./dist/kplayer-ts.umd.js",
10
+ "jsdelivr": "./dist/kplayer-ts.umd.js",
11
+ "exports": {
12
+ ".": {
13
+ "types": "./dist/kplayer-ts.d.ts",
14
+ "import": "./dist/kplayer-ts.es.js",
15
+ "require": "./dist/kplayer-ts.cjs"
16
+ },
17
+ "./react": {
18
+ "types": "./dist/react/index.d.ts",
19
+ "import": "./dist/react/index.es.js",
20
+ "require": "./dist/react/index.cjs"
21
+ },
22
+ "./package.json": "./package.json"
23
+ },
8
24
  "files": [
9
25
  "dist"
10
26
  ],
11
27
  "scripts": {
12
- "build": "vite build",
28
+ "build": "vite build && vite build --mode react",
13
29
  "dev": "vite",
14
30
  "typecheck": "tsc --noEmit"
15
31
  },
32
+ "homepage": "https://github.com/kenji-07",
33
+ "author": "Kenji",
34
+ "peerDependencies": {
35
+ "react": ">=17.0.0",
36
+ "react-dom": ">=17.0.0"
37
+ },
38
+ "peerDependenciesMeta": {
39
+ "react": {
40
+ "optional": true
41
+ },
42
+ "react-dom": {
43
+ "optional": true
44
+ }
45
+ },
16
46
  "devDependencies": {
17
- "@types/node": "^25.5.0",
47
+ "@types/node": "^25.9.3",
48
+ "@types/react": "^19.2.17",
18
49
  "less": "^4.6.4",
19
- "typescript": "^5.9.3",
20
- "vite": "^5.0.0",
21
- "vite-plugin-css-injected-by-js": "^4.0.1",
22
- "vite-plugin-dts": "^4.5.4"
50
+ "react": "^19.2.7",
51
+ "typescript": "^6.0.3",
52
+ "vite": "^8.0.16",
53
+ "vite-plugin-css-injected-by-js": "^5.0.1",
54
+ "vite-plugin-dts": "^5.0.2"
23
55
  },
24
56
  "keywords": [
25
57
  "video",
@@ -33,12 +65,12 @@
33
65
  "screenshot",
34
66
  "hls",
35
67
  "custom ad",
36
- "fullseceen",
68
+ "fullscreen",
37
69
  "kplayer"
38
70
  ],
39
71
  "license": "MIT",
40
72
  "dependencies": {
41
73
  "balloon-css": "^1.2.0",
42
- "hls.js": "^1.6.15"
74
+ "hls.js": "^1.6.16"
43
75
  }
44
76
  }