ranui 0.1.7 → 0.1.9

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.
Files changed (73) hide show
  1. package/dist/components/button/index.d.ts +33 -0
  2. package/dist/components/button/index.js +3 -2
  3. package/dist/components/icon/index.js +2 -2
  4. package/dist/components/image/index.js +1 -1
  5. package/dist/components/input/index.d.ts +183 -0
  6. package/dist/components/input/index.js +2 -1
  7. package/dist/components/message/index.js +1 -1
  8. package/dist/components/option/index.js +1 -1
  9. package/dist/components/player/index.d.ts +179 -490
  10. package/dist/components/player/index.js +6 -5
  11. package/dist/components/preview/index.js +4 -4
  12. package/dist/components/progress/index.js +2 -2
  13. package/dist/components/radar/index.js +2 -2
  14. package/dist/components/scratch/index.d.ts +19 -0
  15. package/dist/components/select/index.d.ts +5 -1
  16. package/dist/components/select/index.js +4 -4
  17. package/dist/components/skeleton/index.js +1 -1
  18. package/dist/components/tab/index.d.ts +5 -0
  19. package/dist/components/tab/index.js +2 -2
  20. package/dist/components/tabpane/index.d.ts +5 -0
  21. package/dist/components/tabpane/index.js +1 -1
  22. package/dist/{index-aea75a9f.js → index-01b17e26.js} +1 -1
  23. package/dist/{index-48653b79.js → index-0d5b9435.js} +1 -1
  24. package/dist/index-1048a998.js +447 -0
  25. package/dist/{index-f6d6982d.js → index-1b73beee.js} +65 -13
  26. package/dist/index-2d16a084.js +197 -0
  27. package/dist/{index-0e7229ea.js → index-3cf72afd.js} +8 -6
  28. package/dist/{index-a43b144f.js → index-4443363f.js} +1 -1
  29. package/dist/{index-a1a53af6.js → index-458debf7.js} +2 -2
  30. package/dist/{index-7f513a14.js → index-7216d6b0.js} +2 -2
  31. package/dist/index-73ce455b.js +264 -0
  32. package/dist/{index-d2d69b06.js → index-7913ec46.js} +27 -13
  33. package/dist/{index-5975bbc0.js → index-b7790662.js} +1 -1
  34. package/dist/{index-a216f328.js → index-c14450a9.js} +1 -1
  35. package/dist/{index-b90299ca.js → index-e03d23e7.js} +1 -1
  36. package/dist/{index-b2be6bef.js → index-e2e5d725.js} +1087 -1069
  37. package/dist/index.js +15 -15
  38. package/dist/style.css +1 -1
  39. package/dist/umd/components/button/index.d.ts +33 -0
  40. package/dist/umd/components/input/index.d.ts +183 -0
  41. package/dist/umd/components/player/index.d.ts +179 -490
  42. package/dist/umd/components/scratch/index.d.ts +19 -0
  43. package/dist/umd/components/select/index.d.ts +5 -1
  44. package/dist/umd/components/tab/index.d.ts +5 -0
  45. package/dist/umd/components/tabpane/index.d.ts +5 -0
  46. package/dist/umd/index.umd.cjs +6 -6
  47. package/dist/umd/style.css +1 -1
  48. package/package.json +5 -8
  49. package/dist/hls/5_1700986031916/5.key +0 -1
  50. package/dist/hls/5_1700986031916/5.m3u8 +0 -12
  51. package/dist/hls/5_1700986031916/5_00000.ts +0 -0
  52. package/dist/hls/5_1700986031916/5_00001.ts +0 -0
  53. package/dist/hls/5_1700986031916/5_00002.ts +0 -0
  54. package/dist/hls/5_1700986110178/5.key +0 -1
  55. package/dist/hls/5_1700986110178/5.m3u8 +0 -12
  56. package/dist/hls/5_1700986110178/5_00000.ts +0 -0
  57. package/dist/hls/5_1700986110178/5_00001.ts +0 -0
  58. package/dist/hls/5_1700986110178/5_00002.ts +0 -0
  59. package/dist/hls/example.m3u8 +0 -5
  60. package/dist/index-183517e7.js +0 -265
  61. package/dist/index-4d873a42.js +0 -195
  62. package/dist/index-ecaed5cc.js +0 -439
  63. package/dist/umd/hls/5_1700986031916/5.key +0 -1
  64. package/dist/umd/hls/5_1700986031916/5.m3u8 +0 -12
  65. package/dist/umd/hls/5_1700986031916/5_00000.ts +0 -0
  66. package/dist/umd/hls/5_1700986031916/5_00001.ts +0 -0
  67. package/dist/umd/hls/5_1700986031916/5_00002.ts +0 -0
  68. package/dist/umd/hls/5_1700986110178/5.key +0 -1
  69. package/dist/umd/hls/5_1700986110178/5.m3u8 +0 -12
  70. package/dist/umd/hls/5_1700986110178/5_00000.ts +0 -0
  71. package/dist/umd/hls/5_1700986110178/5_00001.ts +0 -0
  72. package/dist/umd/hls/5_1700986110178/5_00002.ts +0 -0
  73. package/dist/umd/hls/example.m3u8 +0 -5
@@ -4,8 +4,8 @@ var __publicField = (obj, key, value) => {
4
4
  __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
5
5
  return value;
6
6
  };
7
- import { c as createDocumentFragment, S as SyncHook, r as removeClassToElement, a as addClassToElement, b as timeFormat, d as range, e as throttle$1 } from "./index-d2d69b06.js";
8
- import "./index-f6d6982d.js";
7
+ import { c as createDocumentFragment, S as SyncHook, r as removeClassToElement, a as addClassToElement, d as timeFormat, e as range, b as generateThrottle } from "./index-7913ec46.js";
8
+ import "./index-1b73beee.js";
9
9
  !function t(e) {
10
10
  var r, i;
11
11
  r = this, i = function() {
@@ -9314,1100 +9314,1116 @@ import "./index-f6d6982d.js";
9314
9314
  }(false);
9315
9315
  const index$2 = "";
9316
9316
  const PLAY_STATE_LIST = ["play", "playing", "timeupdate"];
9317
+ const throttle = generateThrottle();
9317
9318
  const SPEED = [
9318
9319
  { label: "2.0X", value: 2 },
9319
9320
  { label: "1.5X", value: 1.5 },
9320
9321
  { label: "1.0X", value: 1 },
9321
9322
  { label: "0.5X", value: 0.5 }
9322
9323
  ];
9323
- function Custom() {
9324
- if (typeof document !== "undefined" && !customElements.get("r-player")) {
9325
- class RanPlayer extends HTMLElement {
9326
- /**
9327
- * @description: 初始化view和video的全局上下文
9328
- * @return {*}
9329
- */
9330
- constructor() {
9331
- super();
9332
- __publicField(this, "ctx");
9333
- __publicField(this, "_player");
9334
- __publicField(this, "_container");
9335
- __publicField(this, "_slot");
9336
- __publicField(this, "_playerController");
9337
- __publicField(this, "_playerBtn");
9338
- __publicField(this, "_progress");
9339
- __publicField(this, "_progressDot");
9340
- __publicField(this, "_progressWrap");
9341
- __publicField(this, "_progressWrapValue");
9342
- __publicField(this, "requestAnimationFrameId");
9343
- __publicField(this, "moveProgress");
9344
- __publicField(this, "_playerControllerBottom");
9345
- __publicField(this, "_playerControllerBottomRight");
9346
- __publicField(this, "_playerControllerBottomLeft");
9347
- __publicField(this, "_playerControllerBottomPlayBtn");
9348
- __publicField(this, "_playerControllerBottomTimeCurrent");
9349
- __publicField(this, "_playerControllerBottomTimeDuration");
9350
- __publicField(this, "_playerControllerBottomTimeDivide");
9351
- __publicField(this, "_playControllerBottomClarity");
9352
- __publicField(this, "_playControllerBottomSpeed");
9353
- __publicField(this, "_playControllerBottomSpeedIcon");
9354
- __publicField(this, "_playControllerBottomVolumeProgress");
9355
- __publicField(this, "_playControllerBottomRightFullScreen");
9356
- __publicField(this, "_playControllerBottomVolume");
9357
- __publicField(this, "_playControllerBottomSpeedPopover");
9358
- __publicField(this, "controllerBarTimeId");
9359
- __publicField(this, "_playerTip");
9360
- __publicField(this, "_playerTipTime");
9361
- __publicField(this, "_playerTipText");
9362
- __publicField(this, "_volume");
9363
- __publicField(this, "_video");
9364
- __publicField(this, "_hls");
9365
- __publicField(this, "changeClarityToSetVideo", () => {
9366
- const { currentTime, playbackRate, volume, currentState } = this.ctx;
9367
- this.setCurrentTime(currentTime);
9368
- this.setPlaybackRate(playbackRate);
9369
- this.setVolume(volume);
9370
- if (PLAY_STATE_LIST.includes(currentState)) {
9371
- this.play();
9372
- } else {
9373
- this.pause();
9374
- }
9375
- });
9376
- __publicField(this, "changeClarity", (e) => {
9377
- this.ctx.clarity = e.detail.value;
9378
- const url = this.ctx.levelMap.get(e.detail.value);
9379
- if (url && this._hls) {
9380
- this._hls.loadSource(url);
9381
- this._hls.startLoad();
9382
- this.changeClarityToSetVideo();
9383
- }
9384
- });
9385
- __publicField(this, "createClaritySelect", () => {
9386
- const { levels, url } = this.ctx;
9387
- this._playControllerBottomClarity.innerHTML = "";
9388
- if (levels.length <= 0)
9324
+ class RanPlayer extends HTMLElement {
9325
+ /**
9326
+ * @description: 初始化view和video的全局上下文
9327
+ * @return {*}
9328
+ */
9329
+ constructor() {
9330
+ super();
9331
+ __publicField(this, "ctx");
9332
+ __publicField(this, "_player");
9333
+ __publicField(this, "_container");
9334
+ __publicField(this, "_slot");
9335
+ __publicField(this, "_playerController");
9336
+ __publicField(this, "_playerBtn");
9337
+ __publicField(this, "_progress");
9338
+ __publicField(this, "_progressDot");
9339
+ __publicField(this, "_progressWrap");
9340
+ __publicField(this, "_progressWrapValue");
9341
+ __publicField(this, "requestAnimationFrameId");
9342
+ __publicField(this, "moveProgress");
9343
+ __publicField(this, "_playerControllerBottom");
9344
+ __publicField(this, "_playerControllerBottomRight");
9345
+ __publicField(this, "_playerControllerBottomLeft");
9346
+ __publicField(this, "_playerControllerBottomPlayBtn");
9347
+ __publicField(this, "_playerControllerBottomTimeCurrent");
9348
+ __publicField(this, "_playerControllerBottomTimeDuration");
9349
+ __publicField(this, "_playerControllerBottomTimeDivide");
9350
+ __publicField(this, "_playControllerBottomClarity");
9351
+ __publicField(this, "_playControllerBottomSpeed");
9352
+ __publicField(this, "_playControllerBottomSpeedIcon");
9353
+ __publicField(this, "_playControllerBottomVolumeProgress");
9354
+ __publicField(this, "_playControllerBottomRightFullScreen");
9355
+ __publicField(this, "_playControllerBottomVolume");
9356
+ __publicField(this, "_playControllerBottomSpeedPopover");
9357
+ __publicField(this, "controllerBarTimeId");
9358
+ __publicField(this, "_playerTip");
9359
+ __publicField(this, "_playerTipTime");
9360
+ __publicField(this, "_playerTipText");
9361
+ __publicField(this, "_volume");
9362
+ __publicField(this, "_video");
9363
+ __publicField(this, "_hls");
9364
+ __publicField(this, "changeClarityToSetVideo", () => {
9365
+ const { currentTime, playbackRate, volume, currentState } = this.ctx;
9366
+ this.setCurrentTime(currentTime);
9367
+ this.setPlaybackRate(playbackRate);
9368
+ this.setVolume(volume);
9369
+ if (PLAY_STATE_LIST.includes(currentState)) {
9370
+ this.play();
9371
+ } else {
9372
+ this.pause();
9373
+ }
9374
+ });
9375
+ __publicField(this, "changeClarity", (e) => {
9376
+ this.ctx.clarity = e.detail.value;
9377
+ const url = this.ctx.levelMap.get(e.detail.value);
9378
+ if (url && this._hls) {
9379
+ this._hls.loadSource(url);
9380
+ this._hls.startLoad();
9381
+ this.changeClarityToSetVideo();
9382
+ }
9383
+ });
9384
+ __publicField(this, "createClaritySelect", () => {
9385
+ const { levels, url } = this.ctx;
9386
+ this._playControllerBottomClarity.innerHTML = "";
9387
+ if (levels.length <= 0)
9388
+ return;
9389
+ const Fragment = document.createDocumentFragment();
9390
+ levels.forEach((item) => {
9391
+ const { name, url: url2 } = item;
9392
+ if (!name || !url2)
9393
+ return;
9394
+ this.ctx.levelMap.set(name, url2);
9395
+ const option = document.createElement("r-option");
9396
+ option.setAttribute("value", name);
9397
+ option.innerHTML = name;
9398
+ Fragment.appendChild(option);
9399
+ });
9400
+ const select = document.createElement("r-select");
9401
+ select.setAttribute("value", this.ctx.clarity || "Auto");
9402
+ select.appendChild(Fragment);
9403
+ select.setAttribute("type", "text");
9404
+ select.setAttribute("action", "hover,click");
9405
+ select.setAttribute("placement", "top");
9406
+ const id = this._player.getAttribute("id");
9407
+ id && select.setAttribute("getPopupContainerId", id);
9408
+ select.setAttribute("dropdownclass", "video-clarity-dropdown");
9409
+ select.addEventListener("change", this.changeClarity);
9410
+ this._playControllerBottomClarity.appendChild(select);
9411
+ });
9412
+ __publicField(this, "manifestLoaded", (type, data) => {
9413
+ if (type === "hlsManifestLoaded") {
9414
+ const { url, levels = [] } = data;
9415
+ if (levels.length <= 0)
9416
+ return;
9417
+ levels.forEach((item) => {
9418
+ if (this.ctx.levelMap.get(item.name) === item.url)
9389
9419
  return;
9390
- const Fragment = document.createDocumentFragment();
9391
- levels.forEach((item) => {
9392
- const { name, url: url2 } = item;
9393
- if (!name || !url2)
9394
- return;
9395
- this.ctx.levelMap.set(name, url2);
9396
- const option = document.createElement("r-option");
9397
- option.setAttribute("value", name);
9398
- option.innerHTML = name;
9399
- Fragment.appendChild(option);
9400
- });
9401
- const select = document.createElement("r-select");
9402
- select.setAttribute("value", this.ctx.clarity || "Auto");
9403
- select.appendChild(Fragment);
9404
- select.setAttribute("type", "text");
9405
- select.setAttribute("action", "hover,click");
9406
- select.setAttribute("placement", "top");
9407
- const id = this._player.getAttribute("id");
9408
- id && select.setAttribute("getPopupContainerId", id);
9409
- select.setAttribute("dropdownclass", "video-clarity-dropdown");
9410
- select.addEventListener("change", this.changeClarity);
9411
- this._playControllerBottomClarity.appendChild(select);
9412
- });
9413
- __publicField(this, "manifestLoaded", (type, data) => {
9414
- if (type === "hlsManifestLoaded") {
9415
- const { url, levels = [] } = data;
9416
- if (levels.length <= 0)
9417
- return;
9418
- levels.forEach((item) => {
9419
- if (this.ctx.levelMap.get(item.name) === item.url)
9420
- return;
9421
- this.ctx.levels.push(item);
9422
- });
9423
- if (!this.ctx.levelMap.get("Auto")) {
9424
- this.ctx.levels.push({ name: "Auto", url });
9425
- this.ctx.levelMap.set("Auto", url);
9426
- }
9427
- this.ctx.url = url;
9428
- this.createClaritySelect();
9429
- }
9430
- });
9431
- /**
9432
- * @description: 初始化 video 和更新 video 方法
9433
- * @return {*}
9434
- */
9435
- __publicField(this, "updatePlayer", () => {
9436
- var _a;
9437
- const { Hls } = window;
9438
- if (!this.contains(this._player))
9439
- this.appendChild(this._player);
9440
- if (this._hls) {
9441
- this._hls.destroy();
9442
- this._hls = void 0;
9443
- }
9444
- this._video = document.createElement("video");
9445
- this._video.setAttribute("class", "ran-player-video");
9446
- this._video.setAttribute("preload", "auto");
9447
- this._video.setAttribute("x5-video-player-type", "h5");
9448
- this._video.setAttribute("x5-video-orientation", "portrait");
9449
- this._video.setAttribute("webkit-playsinline", "true");
9450
- this._video.setAttribute("playsinline", "true");
9451
- this._video.setAttribute("controls", "false");
9452
- this._video.controls = false;
9453
- this._video.setAttribute("initial-time", "0.01");
9454
- if ((Hls == null ? void 0 : Hls.isSupported()) && this.src) {
9455
- this._hls = new Hls();
9456
- if (this._hls) {
9457
- this._hls.off(Hls.Events.MANIFEST_LOADED, this.manifestLoaded);
9458
- this._hls.on(Hls.Events.MANIFEST_LOADED, this.manifestLoaded);
9459
- this._hls.loadSource(this.src);
9460
- this._hls.attachMedia(this._video);
9461
- }
9462
- this._container.appendChild(this._video);
9463
- (_a = this._video.parentElement) == null ? void 0 : _a.setAttribute(
9464
- "class",
9465
- "ran-player-contain"
9466
- );
9467
- }
9468
- this.listenEvent();
9469
- });
9470
- __publicField(this, "change", (name, value) => {
9471
- const currentTime = this.getCurrentTime();
9472
- const duration = this.getTotalTime();
9473
- this.dispatchEvent(
9474
- new CustomEvent("change", {
9475
- detail: {
9476
- type: name,
9477
- data: value,
9478
- currentTime,
9479
- duration,
9480
- tag: this
9481
- }
9482
- })
9483
- );
9484
- });
9485
- __publicField(this, "onCanplay", (e) => {
9486
- this.ctx.currentState = e.type;
9487
- removeClassToElement(
9488
- this._playerControllerBottomPlayBtn,
9489
- "ran-player-controller-bottom-left-btn-pause"
9490
- );
9491
- addClassToElement(
9492
- this._playerControllerBottomPlayBtn,
9493
- "ran-player-controller-bottom-left-btn-play"
9494
- );
9495
- this.change("canplay", e);
9496
- this.resize();
9497
- });
9498
- __publicField(this, "onCanplaythrough", (e) => {
9499
- this.ctx.currentState = e.type;
9500
- this.change("canplaythrough", e);
9501
- });
9502
- __publicField(this, "onComplete", (e) => {
9503
- this.ctx.currentState = e.type;
9504
- this.change("complete", e);
9505
- });
9506
- __publicField(this, "onDurationchange", (e) => {
9507
- this.ctx.currentState = e.type;
9508
- this.change("durationchange", e);
9509
- });
9510
- __publicField(this, "onEmptied", (e) => {
9511
- this.ctx.currentState = e.type;
9512
- this.change("emptied", e);
9420
+ this.ctx.levels.push(item);
9513
9421
  });
9514
- __publicField(this, "onEnded", (e) => {
9515
- this.ctx.currentState = e.type;
9516
- this.change("ended", e);
9517
- });
9518
- __publicField(this, "onError", (e) => {
9519
- this.ctx.currentState = e.type;
9520
- this.change("error", e);
9521
- });
9522
- __publicField(this, "onLoadedmetadata", (e) => {
9523
- this.ctx.currentState = e.type;
9524
- this.change("loadedmetadata", e);
9525
- });
9526
- __publicField(this, "onLoadstart", (e) => {
9527
- this.ctx.currentState = e.type;
9528
- this.change("loadstart", e);
9529
- });
9530
- __publicField(this, "onProgress", (e) => {
9531
- this.ctx.currentState = e.type;
9532
- this.change("progress", e);
9533
- });
9534
- __publicField(this, "onRatechange", (e) => {
9535
- this.ctx.currentState = e.type;
9536
- this.change("ratechange", e);
9537
- });
9538
- __publicField(this, "onSeeked", (e) => {
9539
- this.ctx.currentState = e.type;
9540
- this.change("seeked", e);
9541
- });
9542
- __publicField(this, "onSeeking", (e) => {
9543
- this.ctx.currentState = e.type;
9544
- this.change("seeking", e);
9545
- });
9546
- __publicField(this, "onStalled", (e) => {
9547
- this.ctx.currentState = e.type;
9548
- this.change("stalled", e);
9549
- });
9550
- __publicField(this, "onSuspend", (e) => {
9551
- this.ctx.currentState = e.type;
9552
- this.change("suspend", e);
9553
- });
9554
- __publicField(this, "onLoadeddata", (e) => {
9555
- this.ctx.currentState = e.type;
9556
- const duration = this.getTotalTime();
9557
- this.ctx.duration = duration;
9558
- this._playerControllerBottomTimeCurrent.innerText = "00:00";
9559
- this._playerControllerBottomTimeDivide.innerText = "/";
9560
- this._playerControllerBottomTimeDuration.innerText = timeFormat(
9561
- this.ctx.duration
9562
- );
9563
- this.change("loadeddata", e);
9564
- });
9565
- __publicField(this, "onTimeupdate", (e) => {
9566
- this.ctx.currentState = e.type;
9567
- this.change("timeupdate", e);
9568
- });
9569
- __publicField(this, "onVolumechange", (e) => {
9570
- this.ctx.currentState = e.type;
9571
- this.change("volumechange", e);
9572
- });
9573
- __publicField(this, "onWaiting", (e) => {
9574
- this.ctx.currentState = e.type;
9575
- this.change("waiting", e);
9576
- });
9577
- __publicField(this, "onPlay", (e) => {
9578
- this.ctx.currentState = e.type;
9579
- this.requestAnimationFrame(this.updateCurrentProgress);
9580
- removeClassToElement(
9581
- this._playerControllerBottomPlayBtn,
9582
- "ran-player-controller-bottom-left-btn-play"
9583
- );
9584
- addClassToElement(
9585
- this._playerControllerBottomPlayBtn,
9586
- "ran-player-controller-bottom-left-btn-pause"
9587
- );
9588
- this.showControllerBar();
9589
- this.change("play", e);
9590
- });
9591
- __publicField(this, "onPlaying", (e) => {
9592
- this.ctx.currentState = e.type;
9593
- this._playerBtn.style.setProperty("display", "none");
9594
- removeClassToElement(
9595
- this._playerControllerBottomPlayBtn,
9596
- "ran-player-controller-bottom-left-btn-play"
9597
- );
9598
- addClassToElement(
9599
- this._playerControllerBottomPlayBtn,
9600
- "ran-player-controller-bottom-left-btn-pause"
9601
- );
9602
- this.requestAnimationFrame(this.updateCurrentProgress);
9603
- this.showControllerBar();
9604
- this.change("playing", e);
9605
- });
9606
- __publicField(this, "onPause", (e) => {
9607
- this.ctx.currentState = e.type;
9608
- this._playerBtn.style.setProperty("display", "block");
9609
- this.change("pause", e);
9610
- removeClassToElement(
9611
- this._playerControllerBottomPlayBtn,
9612
- "ran-player-controller-bottom-left-btn-pause"
9613
- );
9614
- addClassToElement(
9615
- this._playerControllerBottomPlayBtn,
9616
- "ran-player-controller-bottom-left-btn-play"
9617
- );
9618
- this.cancelAnimationFrame();
9422
+ if (!this.ctx.levelMap.get("Auto")) {
9423
+ this.ctx.levels.push({ name: "Auto", url });
9424
+ this.ctx.levelMap.set("Auto", url);
9425
+ }
9426
+ this.ctx.url = url;
9427
+ this.createClaritySelect();
9428
+ }
9429
+ });
9430
+ /**
9431
+ * @description: 初始化 video 和更新 video 方法
9432
+ * @return {*}
9433
+ */
9434
+ __publicField(this, "updatePlayer", () => {
9435
+ var _a;
9436
+ const { Hls } = window;
9437
+ if (!this.contains(this._player))
9438
+ this.appendChild(this._player);
9439
+ if (this._hls) {
9440
+ this._hls.destroy();
9441
+ this._hls = void 0;
9442
+ }
9443
+ this._video = document.createElement("video");
9444
+ this._video.setAttribute("class", "ran-player-video");
9445
+ this._video.setAttribute("preload", "auto");
9446
+ this._video.setAttribute("x5-video-player-type", "h5");
9447
+ this._video.setAttribute("x5-video-orientation", "portrait");
9448
+ this._video.setAttribute("webkit-playsinline", "true");
9449
+ this._video.setAttribute("playsinline", "true");
9450
+ this._video.setAttribute("controls", "false");
9451
+ this._video.controls = false;
9452
+ this._video.setAttribute("initial-time", "0.01");
9453
+ if ((Hls == null ? void 0 : Hls.isSupported()) && this.src) {
9454
+ this._hls = new Hls();
9455
+ if (this._hls) {
9456
+ this._hls.off(Hls.Events.MANIFEST_LOADED, this.manifestLoaded);
9457
+ this._hls.on(Hls.Events.MANIFEST_LOADED, this.manifestLoaded);
9458
+ this._hls.loadSource(this.src);
9459
+ this._hls.attachMedia(this._video);
9460
+ }
9461
+ this._container.appendChild(this._video);
9462
+ (_a = this._video.parentElement) == null ? void 0 : _a.setAttribute(
9463
+ "class",
9464
+ "ran-player-contain"
9465
+ );
9466
+ }
9467
+ this.listenEvent();
9468
+ });
9469
+ __publicField(this, "change", (name, value) => {
9470
+ const currentTime = this.getCurrentTime();
9471
+ const duration = this.getTotalTime();
9472
+ this.dispatchEvent(
9473
+ new CustomEvent("change", {
9474
+ detail: {
9475
+ type: name,
9476
+ data: value,
9477
+ currentTime,
9478
+ duration,
9479
+ tag: this
9480
+ }
9481
+ })
9482
+ );
9483
+ });
9484
+ __publicField(this, "onCanplay", (e) => {
9485
+ this.ctx.currentState = e.type;
9486
+ removeClassToElement(
9487
+ this._playerControllerBottomPlayBtn,
9488
+ "ran-player-controller-bottom-left-btn-pause"
9489
+ );
9490
+ addClassToElement(
9491
+ this._playerControllerBottomPlayBtn,
9492
+ "ran-player-controller-bottom-left-btn-play"
9493
+ );
9494
+ this.change("canplay", e);
9495
+ this.resize();
9496
+ });
9497
+ __publicField(this, "onCanplaythrough", (e) => {
9498
+ this.ctx.currentState = e.type;
9499
+ this.change("canplaythrough", e);
9500
+ });
9501
+ __publicField(this, "onComplete", (e) => {
9502
+ this.ctx.currentState = e.type;
9503
+ this.change("complete", e);
9504
+ });
9505
+ __publicField(this, "onDurationchange", (e) => {
9506
+ this.ctx.currentState = e.type;
9507
+ this.change("durationchange", e);
9508
+ });
9509
+ __publicField(this, "onEmptied", (e) => {
9510
+ this.ctx.currentState = e.type;
9511
+ this.change("emptied", e);
9512
+ });
9513
+ __publicField(this, "onEnded", (e) => {
9514
+ this.ctx.currentState = e.type;
9515
+ this.change("ended", e);
9516
+ });
9517
+ __publicField(this, "onError", (e) => {
9518
+ this.ctx.currentState = e.type;
9519
+ this.change("error", e);
9520
+ });
9521
+ __publicField(this, "onLoadedmetadata", (e) => {
9522
+ this.ctx.currentState = e.type;
9523
+ this.change("loadedmetadata", e);
9524
+ });
9525
+ __publicField(this, "onLoadstart", (e) => {
9526
+ this.ctx.currentState = e.type;
9527
+ this.change("loadstart", e);
9528
+ });
9529
+ __publicField(this, "onProgress", (e) => {
9530
+ this.ctx.currentState = e.type;
9531
+ this.change("progress", e);
9532
+ });
9533
+ __publicField(this, "onRatechange", (e) => {
9534
+ this.ctx.currentState = e.type;
9535
+ this.change("ratechange", e);
9536
+ });
9537
+ __publicField(this, "onSeeked", (e) => {
9538
+ this.ctx.currentState = e.type;
9539
+ this.change("seeked", e);
9540
+ });
9541
+ __publicField(this, "onSeeking", (e) => {
9542
+ this.ctx.currentState = e.type;
9543
+ this.change("seeking", e);
9544
+ });
9545
+ __publicField(this, "onStalled", (e) => {
9546
+ this.ctx.currentState = e.type;
9547
+ this.change("stalled", e);
9548
+ });
9549
+ __publicField(this, "onSuspend", (e) => {
9550
+ this.ctx.currentState = e.type;
9551
+ this.change("suspend", e);
9552
+ });
9553
+ __publicField(this, "onLoadeddata", (e) => {
9554
+ this.ctx.currentState = e.type;
9555
+ const duration = this.getTotalTime();
9556
+ this.ctx.duration = duration;
9557
+ this._playerControllerBottomTimeCurrent.innerText = "00:00";
9558
+ this._playerControllerBottomTimeDivide.innerText = "/";
9559
+ this._playerControllerBottomTimeDuration.innerText = timeFormat(
9560
+ this.ctx.duration
9561
+ );
9562
+ this.change("loadeddata", e);
9563
+ });
9564
+ __publicField(this, "onTimeupdate", (e) => {
9565
+ this.ctx.currentState = e.type;
9566
+ this.change("timeupdate", e);
9567
+ });
9568
+ __publicField(this, "onVolumechange", (e) => {
9569
+ this.ctx.currentState = e.type;
9570
+ this.change("volumechange", e);
9571
+ });
9572
+ __publicField(this, "onWaiting", (e) => {
9573
+ this.ctx.currentState = e.type;
9574
+ this.change("waiting", e);
9575
+ });
9576
+ __publicField(this, "onPlay", (e) => {
9577
+ this.ctx.currentState = e.type;
9578
+ this.requestAnimationFrame(this.updateCurrentProgress);
9579
+ removeClassToElement(
9580
+ this._playerControllerBottomPlayBtn,
9581
+ "ran-player-controller-bottom-left-btn-play"
9582
+ );
9583
+ addClassToElement(
9584
+ this._playerControllerBottomPlayBtn,
9585
+ "ran-player-controller-bottom-left-btn-pause"
9586
+ );
9587
+ this.showControllerBar();
9588
+ this.change("play", e);
9589
+ });
9590
+ __publicField(this, "onPlaying", (e) => {
9591
+ this.ctx.currentState = e.type;
9592
+ this._playerBtn.style.setProperty("display", "none");
9593
+ removeClassToElement(
9594
+ this._playerControllerBottomPlayBtn,
9595
+ "ran-player-controller-bottom-left-btn-play"
9596
+ );
9597
+ addClassToElement(
9598
+ this._playerControllerBottomPlayBtn,
9599
+ "ran-player-controller-bottom-left-btn-pause"
9600
+ );
9601
+ this.requestAnimationFrame(this.updateCurrentProgress);
9602
+ this.showControllerBar();
9603
+ this.change("playing", e);
9604
+ });
9605
+ __publicField(this, "onPause", (e) => {
9606
+ this.ctx.currentState = e.type;
9607
+ this._playerBtn.style.setProperty("display", "block");
9608
+ this.change("pause", e);
9609
+ removeClassToElement(
9610
+ this._playerControllerBottomPlayBtn,
9611
+ "ran-player-controller-bottom-left-btn-pause"
9612
+ );
9613
+ addClassToElement(
9614
+ this._playerControllerBottomPlayBtn,
9615
+ "ran-player-controller-bottom-left-btn-play"
9616
+ );
9617
+ this.cancelAnimationFrame();
9618
+ this._playerController.style.setProperty("opacity", "1");
9619
+ if (this.controllerBarTimeId) {
9620
+ clearTimeout(this.controllerBarTimeId);
9621
+ this.controllerBarTimeId = void 0;
9622
+ }
9623
+ });
9624
+ __publicField(this, "clearListenerEvent", () => {
9625
+ if (!this._video)
9626
+ return;
9627
+ this._video.removeEventListener("canplay", this.onCanplay);
9628
+ this._video.removeEventListener(
9629
+ "canplaythrough",
9630
+ this.onCanplaythrough
9631
+ );
9632
+ this._video.removeEventListener("complete", this.onComplete);
9633
+ this._video.removeEventListener(
9634
+ "durationchange",
9635
+ this.onDurationchange
9636
+ );
9637
+ this._video.removeEventListener("emptied", this.onEmptied);
9638
+ this._video.removeEventListener("ended", this.onEnded);
9639
+ this._video.removeEventListener("error", this.onError);
9640
+ this._video.removeEventListener("loadeddata", this.onLoadeddata);
9641
+ this._video.removeEventListener(
9642
+ "loadedmetadata",
9643
+ this.onLoadedmetadata
9644
+ );
9645
+ this._video.removeEventListener("loadstart", this.onLoadstart);
9646
+ this._video.removeEventListener("pause", this.onPause);
9647
+ this._video.removeEventListener("play", this.onPlay);
9648
+ this._video.removeEventListener("playing", this.onPlaying);
9649
+ this._video.removeEventListener("progress", this.onProgress);
9650
+ this._video.removeEventListener("ratechange", this.onRatechange);
9651
+ this._video.removeEventListener("seeked", this.onSeeked);
9652
+ this._video.removeEventListener("seeking", this.onSeeking);
9653
+ this._video.removeEventListener("stalled", this.onStalled);
9654
+ this._video.removeEventListener("suspend", this.onSuspend);
9655
+ this._video.removeEventListener("timeupdate", this.onTimeupdate);
9656
+ this._video.removeEventListener("volumechange", this.onVolumechange);
9657
+ this._video.removeEventListener("waiting", this.onWaiting);
9658
+ });
9659
+ /**
9660
+ * @description: 用户行为和 video 之间的交互
9661
+ * @return {*}
9662
+ */
9663
+ __publicField(this, "listenEvent", () => {
9664
+ if (!this._video)
9665
+ return;
9666
+ this.clearListenerEvent();
9667
+ this._video.addEventListener("canplay", this.onCanplay);
9668
+ this._video.addEventListener("canplaythrough", this.onCanplaythrough);
9669
+ this._video.addEventListener("complete", this.onComplete);
9670
+ this._video.addEventListener("durationchange", this.onDurationchange);
9671
+ this._video.addEventListener("emptied", this.onEmptied);
9672
+ this._video.addEventListener("ended", this.onEnded);
9673
+ this._video.addEventListener("error", this.onError);
9674
+ this._video.addEventListener("loadeddata", this.onLoadeddata);
9675
+ this._video.addEventListener("loadedmetadata", this.onLoadedmetadata);
9676
+ this._video.addEventListener("loadstart", this.onLoadstart);
9677
+ this._video.addEventListener("pause", this.onPause);
9678
+ this._video.addEventListener("play", this.onPlay);
9679
+ this._video.addEventListener("playing", this.onPlaying);
9680
+ this._video.addEventListener("progress", this.onProgress);
9681
+ this._video.addEventListener("ratechange", this.onRatechange);
9682
+ this._video.addEventListener("seeked", this.onSeeked);
9683
+ this._video.addEventListener("seeking", this.onSeeking);
9684
+ this._video.addEventListener("stalled", this.onStalled);
9685
+ this._video.addEventListener("suspend", this.onSuspend);
9686
+ this._video.addEventListener("timeupdate", this.onTimeupdate);
9687
+ this._video.addEventListener("volumechange", this.onVolumechange);
9688
+ this._video.addEventListener("waiting", this.onWaiting);
9689
+ });
9690
+ __publicField(this, "showControllerBar", (e) => {
9691
+ if (e) {
9692
+ const dom = e.target;
9693
+ if (dom.classList.value.includes("ran-player-controller")) {
9619
9694
  this._playerController.style.setProperty("opacity", "1");
9620
9695
  if (this.controllerBarTimeId) {
9621
9696
  clearTimeout(this.controllerBarTimeId);
9622
9697
  this.controllerBarTimeId = void 0;
9623
9698
  }
9699
+ return;
9700
+ }
9701
+ }
9702
+ if (PLAY_STATE_LIST.includes(this.ctx.currentState)) {
9703
+ this._playerController.style.setProperty("opacity", "1");
9704
+ if (this.controllerBarTimeId) {
9705
+ clearTimeout(this.controllerBarTimeId);
9706
+ this.controllerBarTimeId = void 0;
9707
+ }
9708
+ this.controllerBarTimeId = setTimeout(() => {
9709
+ this._playerController.style.setProperty("opacity", "0");
9710
+ clearTimeout(this.controllerBarTimeId);
9711
+ this.controllerBarTimeId = void 0;
9712
+ }, 2e3);
9713
+ } else {
9714
+ this._playerController.style.setProperty("opacity", "1");
9715
+ if (this.controllerBarTimeId) {
9716
+ clearTimeout(this.controllerBarTimeId);
9717
+ this.controllerBarTimeId = void 0;
9718
+ }
9719
+ }
9720
+ });
9721
+ /**
9722
+ * @description: 进度条点击事件
9723
+ * @param {MouseEvent} e
9724
+ * @return {*}
9725
+ */
9726
+ __publicField(this, "progressClick", (e) => {
9727
+ const rect = this._progressWrap.getBoundingClientRect();
9728
+ const offsetX = e.clientX - rect.left;
9729
+ const percentage = range(offsetX / this._progress.offsetWidth);
9730
+ this.setCurrentTime(this.ctx.duration * percentage);
9731
+ this.updateCurrentProgress();
9732
+ });
9733
+ /**
9734
+ * @description: 进度条鼠标按下事件
9735
+ * @param {MouseEvent} e
9736
+ * @return {*}
9737
+ */
9738
+ __publicField(this, "progressDotMouseDown", (e) => {
9739
+ this._playerBtn.style.setProperty("display", "none");
9740
+ this.moveProgress.mouseDown = true;
9741
+ this.cancelAnimationFrame();
9742
+ });
9743
+ /**
9744
+ * @description: 进度条鼠标移动事件
9745
+ * @param {MouseEvent} e
9746
+ * @return {*}
9747
+ */
9748
+ __publicField(this, "progressDotMouseMove", (e) => {
9749
+ this.showControllerBar(e);
9750
+ if (!this.moveProgress.mouseDown)
9751
+ return;
9752
+ const rect = this._progress.getBoundingClientRect();
9753
+ const offsetX = e.clientX - rect.left - 9;
9754
+ const percentage = range(offsetX / this._progress.offsetWidth);
9755
+ this._progressWrapValue.style.setProperty(
9756
+ "transform",
9757
+ `scaleX(${percentage})`
9758
+ );
9759
+ this._progressDot.style.setProperty(
9760
+ "transform",
9761
+ `translateX(${percentage * this._progress.offsetWidth}px)`
9762
+ );
9763
+ this.moveProgress.percentage = Math.floor(percentage * 100) / 100;
9764
+ });
9765
+ /**
9766
+ * @description: 进度条鼠标松开事件
9767
+ * @param {MouseEvent} e
9768
+ * @return {*}
9769
+ */
9770
+ __publicField(this, "progressDotMouseUp", () => {
9771
+ if (!this.moveProgress.mouseDown)
9772
+ return;
9773
+ const percentage = this.moveProgress.percentage;
9774
+ this.setCurrentTime(this.ctx.duration * percentage);
9775
+ this.play();
9776
+ this.moveProgress.mouseDown = false;
9777
+ this.requestAnimationFrame(this.updateCurrentProgress);
9778
+ });
9779
+ /**
9780
+ * @description: 更新页面样式
9781
+ * @param {Function} fn
9782
+ * @return {*}
9783
+ */
9784
+ __publicField(this, "requestAnimationFrame", (fn) => {
9785
+ if (this.requestAnimationFrameId)
9786
+ return;
9787
+ this.requestAnimationFrameId = window.requestAnimationFrame(() => {
9788
+ fn();
9789
+ this.requestAnimationFrameId && cancelAnimationFrame(this.requestAnimationFrameId);
9790
+ this.requestAnimationFrameId = void 0;
9791
+ this.requestAnimationFrame(fn);
9792
+ });
9793
+ });
9794
+ /**
9795
+ * @description: 取消页面动画
9796
+ * @param {Function} fn
9797
+ * @return {*}
9798
+ */
9799
+ __publicField(this, "cancelAnimationFrame", () => {
9800
+ if (!this.requestAnimationFrameId)
9801
+ return;
9802
+ cancelAnimationFrame(this.requestAnimationFrameId);
9803
+ this.requestAnimationFrameId = void 0;
9804
+ });
9805
+ /**
9806
+ * @description: 更新进度条
9807
+ * @param {*} void
9808
+ * @return {*}
9809
+ */
9810
+ __publicField(this, "updateCurrentProgress", () => {
9811
+ const currentTime = this.getCurrentTime();
9812
+ this.ctx.currentTime = currentTime;
9813
+ const { duration } = this.ctx;
9814
+ this._progressWrapValue.style.setProperty(
9815
+ "transform",
9816
+ `scaleX(${currentTime / duration})`
9817
+ );
9818
+ this._progressDot.style.setProperty(
9819
+ "transform",
9820
+ `translateX(${currentTime / duration * this._progress.offsetWidth}px)`
9821
+ );
9822
+ if (currentTime >= 0) {
9823
+ this._playerControllerBottomTimeCurrent.innerText = timeFormat(currentTime);
9824
+ }
9825
+ });
9826
+ __publicField(this, "changeAttribute", (k, o, n, attribute, callback) => {
9827
+ if (k === attribute && o !== n)
9828
+ throttle(callback)();
9829
+ });
9830
+ /**
9831
+ * @description: 点击整个视频时,触发的事件
9832
+ * @param {*} void
9833
+ * @return {*}
9834
+ */
9835
+ __publicField(this, "dispatchClickPlayerContainerAction", (e) => {
9836
+ e.stopPropagation();
9837
+ e.preventDefault();
9838
+ if (PLAY_STATE_LIST.includes(this.ctx.currentState)) {
9839
+ this.pause();
9840
+ this._playerBtn.style.setProperty("display", "block");
9841
+ } else {
9842
+ this.play();
9843
+ this._playerBtn.style.setProperty("display", "none");
9844
+ }
9845
+ });
9846
+ /**
9847
+ * @description: 空格事件
9848
+ * @param {KeyboardEvent} e
9849
+ * @return {*}
9850
+ */
9851
+ __publicField(this, "SpaceKeyDown", (e) => {
9852
+ const { currentTime, duration } = this.ctx;
9853
+ if (e.code === "Space") {
9854
+ this.dispatchClickPlayerBtnAction(e);
9855
+ }
9856
+ if (e.code === "Escape") {
9857
+ this.customExitFullscreen().then(() => {
9858
+ this.ctx.fullScreen = false;
9859
+ }).catch((error) => {
9624
9860
  });
9625
- __publicField(this, "clearListenerEvent", () => {
9626
- if (!this._video)
9627
- return;
9628
- this._video.removeEventListener("canplay", this.onCanplay);
9629
- this._video.removeEventListener(
9630
- "canplaythrough",
9631
- this.onCanplaythrough
9632
- );
9633
- this._video.removeEventListener("complete", this.onComplete);
9634
- this._video.removeEventListener(
9635
- "durationchange",
9636
- this.onDurationchange
9637
- );
9638
- this._video.removeEventListener("emptied", this.onEmptied);
9639
- this._video.removeEventListener("ended", this.onEnded);
9640
- this._video.removeEventListener("error", this.onError);
9641
- this._video.removeEventListener("loadeddata", this.onLoadeddata);
9642
- this._video.removeEventListener(
9643
- "loadedmetadata",
9644
- this.onLoadedmetadata
9645
- );
9646
- this._video.removeEventListener("loadstart", this.onLoadstart);
9647
- this._video.removeEventListener("pause", this.onPause);
9648
- this._video.removeEventListener("play", this.onPlay);
9649
- this._video.removeEventListener("playing", this.onPlaying);
9650
- this._video.removeEventListener("progress", this.onProgress);
9651
- this._video.removeEventListener("ratechange", this.onRatechange);
9652
- this._video.removeEventListener("seeked", this.onSeeked);
9653
- this._video.removeEventListener("seeking", this.onSeeking);
9654
- this._video.removeEventListener("stalled", this.onStalled);
9655
- this._video.removeEventListener("suspend", this.onSuspend);
9656
- this._video.removeEventListener("timeupdate", this.onTimeupdate);
9657
- this._video.removeEventListener("volumechange", this.onVolumechange);
9658
- this._video.removeEventListener("waiting", this.onWaiting);
9659
- });
9660
- /**
9661
- * @description: 用户行为和 video 之间的交互
9662
- * @return {*}
9663
- */
9664
- __publicField(this, "listenEvent", () => {
9665
- if (!this._video)
9666
- return;
9667
- this.clearListenerEvent();
9668
- this._video.addEventListener("canplay", this.onCanplay);
9669
- this._video.addEventListener("canplaythrough", this.onCanplaythrough);
9670
- this._video.addEventListener("complete", this.onComplete);
9671
- this._video.addEventListener("durationchange", this.onDurationchange);
9672
- this._video.addEventListener("emptied", this.onEmptied);
9673
- this._video.addEventListener("ended", this.onEnded);
9674
- this._video.addEventListener("error", this.onError);
9675
- this._video.addEventListener("loadeddata", this.onLoadeddata);
9676
- this._video.addEventListener("loadedmetadata", this.onLoadedmetadata);
9677
- this._video.addEventListener("loadstart", this.onLoadstart);
9678
- this._video.addEventListener("pause", this.onPause);
9679
- this._video.addEventListener("play", this.onPlay);
9680
- this._video.addEventListener("playing", this.onPlaying);
9681
- this._video.addEventListener("progress", this.onProgress);
9682
- this._video.addEventListener("ratechange", this.onRatechange);
9683
- this._video.addEventListener("seeked", this.onSeeked);
9684
- this._video.addEventListener("seeking", this.onSeeking);
9685
- this._video.addEventListener("stalled", this.onStalled);
9686
- this._video.addEventListener("suspend", this.onSuspend);
9687
- this._video.addEventListener("timeupdate", this.onTimeupdate);
9688
- this._video.addEventListener("volumechange", this.onVolumechange);
9689
- this._video.addEventListener("waiting", this.onWaiting);
9690
- });
9691
- __publicField(this, "showControllerBar", (e) => {
9692
- if (e) {
9693
- const dom = e.target;
9694
- if (dom.classList.value.includes("ran-player-controller")) {
9695
- this._playerController.style.setProperty("opacity", "1");
9696
- if (this.controllerBarTimeId) {
9697
- clearTimeout(this.controllerBarTimeId);
9698
- this.controllerBarTimeId = void 0;
9699
- }
9700
- return;
9701
- }
9702
- }
9703
- if (PLAY_STATE_LIST.includes(this.ctx.currentState)) {
9704
- this._playerController.style.setProperty("opacity", "1");
9705
- if (this.controllerBarTimeId) {
9706
- clearTimeout(this.controllerBarTimeId);
9707
- this.controllerBarTimeId = void 0;
9708
- }
9709
- this.controllerBarTimeId = setTimeout(() => {
9710
- this._playerController.style.setProperty("opacity", "0");
9711
- clearTimeout(this.controllerBarTimeId);
9712
- this.controllerBarTimeId = void 0;
9713
- }, 2e3);
9714
- } else {
9715
- this._playerController.style.setProperty("opacity", "1");
9716
- if (this.controllerBarTimeId) {
9717
- clearTimeout(this.controllerBarTimeId);
9718
- this.controllerBarTimeId = void 0;
9719
- }
9720
- }
9721
- });
9722
- /**
9723
- * @description: 进度条点击事件
9724
- * @param {MouseEvent} e
9725
- * @return {*}
9726
- */
9727
- __publicField(this, "progressClick", (e) => {
9728
- const rect = this._progressWrap.getBoundingClientRect();
9729
- const offsetX = e.clientX - rect.left;
9730
- const percentage = range(offsetX / this._progress.offsetWidth);
9731
- this.setCurrentTime(this.ctx.duration * percentage);
9732
- this.updateCurrentProgress();
9733
- });
9734
- /**
9735
- * @description: 进度条鼠标按下事件
9736
- * @param {MouseEvent} e
9737
- * @return {*}
9738
- */
9739
- __publicField(this, "progressDotMouseDown", (e) => {
9740
- this._playerBtn.style.setProperty("display", "none");
9741
- this.moveProgress.mouseDown = true;
9742
- this.cancelAnimationFrame();
9743
- });
9744
- /**
9745
- * @description: 进度条鼠标移动事件
9746
- * @param {MouseEvent} e
9747
- * @return {*}
9748
- */
9749
- __publicField(this, "progressDotMouseMove", (e) => {
9750
- this.showControllerBar(e);
9751
- if (!this.moveProgress.mouseDown)
9752
- return;
9753
- const rect = this._progress.getBoundingClientRect();
9754
- const offsetX = e.clientX - rect.left - 9;
9755
- const percentage = range(offsetX / this._progress.offsetWidth);
9756
- this._progressWrapValue.style.setProperty(
9757
- "transform",
9758
- `scaleX(${percentage})`
9759
- );
9760
- this._progressDot.style.setProperty(
9761
- "transform",
9762
- `translateX(${percentage * this._progress.offsetWidth}px)`
9763
- );
9764
- this.moveProgress.percentage = Math.floor(percentage * 100) / 100;
9765
- });
9766
- /**
9767
- * @description: 进度条鼠标松开事件
9768
- * @param {MouseEvent} e
9769
- * @return {*}
9770
- */
9771
- __publicField(this, "progressDotMouseUp", () => {
9772
- if (!this.moveProgress.mouseDown)
9773
- return;
9774
- const percentage = this.moveProgress.percentage;
9775
- this.setCurrentTime(this.ctx.duration * percentage);
9776
- this.play();
9777
- this.moveProgress.mouseDown = false;
9778
- this.requestAnimationFrame(this.updateCurrentProgress);
9779
- });
9780
- /**
9781
- * @description: 更新页面样式
9782
- * @param {Function} fn
9783
- * @return {*}
9784
- */
9785
- __publicField(this, "requestAnimationFrame", (fn) => {
9786
- if (this.requestAnimationFrameId)
9787
- return;
9788
- this.requestAnimationFrameId = window.requestAnimationFrame(() => {
9789
- fn();
9790
- this.requestAnimationFrameId && cancelAnimationFrame(this.requestAnimationFrameId);
9791
- this.requestAnimationFrameId = void 0;
9792
- this.requestAnimationFrame(fn);
9793
- });
9794
- });
9795
- /**
9796
- * @description: 取消页面动画
9797
- * @param {Function} fn
9798
- * @return {*}
9799
- */
9800
- __publicField(this, "cancelAnimationFrame", () => {
9801
- if (!this.requestAnimationFrameId)
9802
- return;
9803
- cancelAnimationFrame(this.requestAnimationFrameId);
9804
- this.requestAnimationFrameId = void 0;
9805
- });
9806
- /**
9807
- * @description: 更新进度条
9808
- * @param {*} void
9809
- * @return {*}
9810
- */
9811
- __publicField(this, "updateCurrentProgress", () => {
9812
- const currentTime = this.getCurrentTime();
9813
- this.ctx.currentTime = currentTime;
9814
- const { duration } = this.ctx;
9815
- this._progressWrapValue.style.setProperty(
9816
- "transform",
9817
- `scaleX(${currentTime / duration})`
9818
- );
9819
- this._progressDot.style.setProperty(
9820
- "transform",
9821
- `translateX(${currentTime / duration * this._progress.offsetWidth}px)`
9822
- );
9823
- if (currentTime >= 0) {
9824
- this._playerControllerBottomTimeCurrent.innerText = timeFormat(currentTime);
9825
- }
9826
- });
9827
- __publicField(this, "changeAttribute", (k, o, n, attribute, callback) => {
9828
- if (k === attribute && o !== n)
9829
- throttle$1(callback)();
9830
- });
9831
- /**
9832
- * @description: 点击整个视频时,触发的事件
9833
- * @param {*} void
9834
- * @return {*}
9835
- */
9836
- __publicField(this, "dispatchClickPlayerContainerAction", (e) => {
9837
- e.stopPropagation();
9838
- e.preventDefault();
9839
- if (PLAY_STATE_LIST.includes(this.ctx.currentState)) {
9840
- this.pause();
9841
- this._playerBtn.style.setProperty("display", "block");
9842
- } else {
9843
- this.play();
9844
- this._playerBtn.style.setProperty("display", "none");
9845
- }
9846
- });
9847
- /**
9848
- * @description: 空格事件
9849
- * @param {KeyboardEvent} e
9850
- * @return {*}
9851
- */
9852
- __publicField(this, "SpaceKeyDown", (e) => {
9853
- e.stopPropagation();
9854
- e.preventDefault();
9855
- const { currentTime, duration } = this.ctx;
9856
- if (e.code === "Space") {
9857
- this.dispatchClickPlayerBtnAction(e);
9858
- }
9859
- if (e.code === "Escape") {
9860
- document.exitFullscreen().then(() => {
9861
- this.ctx.fullScreen = false;
9862
- }).catch((error) => {
9863
- });
9864
- }
9865
- if (e.code === "ArrowLeft") {
9866
- const time = range(currentTime - 5, 0, duration);
9867
- this.setCurrentTime(time);
9868
- this.play();
9869
- }
9870
- if (e.code === "ArrowRight") {
9871
- const time = range(currentTime + 5, 0, duration);
9872
- this.setCurrentTime(time);
9873
- this.play();
9874
- }
9875
- });
9876
- /**
9877
- * @description: 点击player-btn,触发的事件
9878
- * @param {*} void
9879
- * @return {*}
9880
- */
9881
- __publicField(this, "dispatchClickPlayerBtnAction", (e) => {
9882
- e.stopPropagation();
9883
- e.preventDefault();
9884
- if (PLAY_STATE_LIST.includes(this.ctx.currentState)) {
9885
- this.pause();
9886
- this._playerBtn.style.setProperty("display", "block");
9887
- } else {
9888
- this.play();
9889
- this._playerBtn.style.setProperty("display", "none");
9890
- }
9891
- });
9892
- __publicField(this, "changeVolumeProgress", (e) => {
9893
- if (this._video) {
9894
- this.setVolume(e.detail.value);
9895
- this.change("volume", e.detail.value);
9896
- if (e.detail.value > 0) {
9897
- this._volume = e.detail.value;
9898
- }
9899
- }
9900
- });
9901
- __publicField(this, "openFullScreen", () => {
9902
- if (!this.ctx.fullScreen) {
9903
- this._player.requestFullscreen().then(() => {
9904
- this.resize();
9905
- this.ctx.fullScreen = true;
9906
- }).catch((error) => {
9907
- });
9908
- } else {
9909
- document.exitFullscreen().then(() => {
9910
- this.resize();
9911
- this.ctx.fullScreen = false;
9912
- }).catch((error) => {
9913
- });
9914
- }
9915
- });
9916
- __publicField(this, "changeSpeed", (e) => {
9917
- this.change("speed", e.detail.value);
9918
- this.setPlaybackRate(e.detail.value);
9919
- });
9920
- __publicField(this, "progressMouseEnter", (e) => {
9921
- this._playerTip.style.setProperty("opacity", "1");
9922
- const rect = this._progress.getBoundingClientRect();
9923
- const offsetX = e.clientX - rect.left;
9924
- if (this._playerTipText.innerText) {
9925
- this._playerTip.style.setProperty(
9926
- "transform",
9927
- `translate(calc(${offsetX}px - 50%),-20px)`
9928
- );
9929
- } else {
9930
- this._playerTip.style.setProperty(
9931
- "transform",
9932
- `translateX(calc(${offsetX}px - 50%))`
9933
- );
9934
- }
9935
- this._playerTipTime.innerText = timeFormat(
9936
- offsetX / this._progress.clientWidth * this.ctx.duration
9937
- );
9938
- });
9939
- __publicField(this, "progressMouseLeave", (e) => {
9940
- if (e.target.classList.contains(
9941
- "ran-player-controller-progress-wrap-dot"
9942
- )) {
9943
- return;
9944
- }
9945
- this._playerTip.style.setProperty("opacity", "0");
9946
- });
9947
- __publicField(this, "progressMouseMove", (e) => {
9948
- const rect = this._progress.getBoundingClientRect();
9949
- this._playerTip.style.setProperty("opacity", "1");
9950
- const offsetX = e.clientX - rect.left;
9951
- if (this._playerTipText.innerText) {
9952
- this._playerTip.style.setProperty(
9953
- "transform",
9954
- `translate(calc(${offsetX}px - 50%),-20px)`
9955
- );
9956
- } else {
9957
- this._playerTip.style.setProperty(
9958
- "transform",
9959
- `translateX(calc(${offsetX}px - 50%))`
9960
- );
9961
- }
9962
- this._playerTipTime.innerText = timeFormat(
9963
- offsetX / this._progress.clientWidth * this.ctx.duration
9964
- );
9965
- });
9966
- __publicField(this, "changePlayerVolume", () => {
9967
- if (!this._video)
9968
- return;
9969
- const { volume } = this.ctx;
9970
- if (volume > 0) {
9971
- addClassToElement(
9972
- this._playControllerBottomSpeedIcon,
9973
- "ran-player-controller-bottom-right-volume-icon-mute"
9974
- );
9975
- removeClassToElement(
9976
- this._playControllerBottomSpeedIcon,
9977
- "ran-player-controller-bottom-right-volume-icon-volume"
9978
- );
9979
- this._playControllerBottomVolumeProgress.setAttribute("percent", "0");
9980
- this.setVolume(0);
9981
- this.change("volume", 0);
9982
- } else {
9983
- addClassToElement(
9984
- this._playControllerBottomSpeedIcon,
9985
- "ran-player-controller-bottom-right-volume-icon-volume"
9986
- );
9987
- removeClassToElement(
9988
- this._playControllerBottomSpeedIcon,
9989
- "ran-player-controller-bottom-right-volume-icon-mute"
9990
- );
9991
- this._playControllerBottomVolumeProgress.setAttribute(
9992
- "percent",
9993
- `${this._volume || 0.5}`
9994
- );
9995
- this.setVolume(0.5);
9996
- this.change("volume", this._volume || 0.5);
9997
- }
9998
- });
9999
- __publicField(this, "resize", () => {
10000
- if (this._video) {
10001
- const { width, height } = this._player.getBoundingClientRect();
10002
- this._video.style.setProperty("width", `${width}px`);
10003
- this._video.style.setProperty("height", `${height}px`);
10004
- }
10005
- this.updateCurrentProgress();
10006
- });
10007
- __publicField(this, "fullScreenChange", () => {
10008
- var _a;
10009
- if ((_a = document.fullscreenElement) == null ? void 0 : _a.classList.contains("ran-player")) {
10010
- this.change("fullscreen", true);
10011
- this.ctx.fullScreen = true;
10012
- } else {
10013
- this.change("fullscreen", false);
10014
- this.ctx.fullScreen = false;
10015
- }
10016
- });
10017
- __publicField(this, "getPlaybackRate", () => {
10018
- if (this._video) {
10019
- this.ctx.playbackRate = this._video.playbackRate || 0;
10020
- }
10021
- return this.ctx.playbackRate;
10022
- });
10023
- __publicField(this, "setPlaybackRate", (n) => {
10024
- if (this._video) {
10025
- this.ctx.playbackRate = n;
10026
- this._video.playbackRate = n;
10027
- }
10028
- return this.ctx.playbackRate;
10029
- });
10030
- __publicField(this, "setVolume", (n) => {
10031
- if (this._video) {
10032
- this.ctx.volume = n;
10033
- this._video.volume = n;
10034
- }
10035
- return this.ctx.volume;
10036
- });
10037
- __publicField(this, "getVolume", () => {
10038
- if (this._video) {
10039
- this.ctx.volume = this._video.volume || 0;
10040
- }
10041
- return this.ctx.volume;
10042
- });
10043
- __publicField(this, "setCurrentTime", (n) => {
10044
- if (this._video) {
10045
- this.ctx.currentTime = n;
10046
- this._video.currentTime = n;
10047
- }
10048
- return this.ctx.currentTime;
10049
- });
10050
- __publicField(this, "getCurrentTime", () => {
10051
- if (this._video) {
10052
- this.ctx.currentTime = this._video.currentTime || 0;
10053
- }
10054
- return this.ctx.currentTime;
10055
- });
10056
- __publicField(this, "getTotalTime", () => {
10057
- if (this._video) {
10058
- this.ctx.duration = this._video.duration || 0;
10059
- }
10060
- return this.ctx.duration;
10061
- });
10062
- __publicField(this, "play", (n) => {
10063
- if (this._video) {
10064
- if (n !== void 0 && n >= 0) {
10065
- this.ctx.currentTime = n;
10066
- this._video.currentTime = n;
10067
- }
10068
- this._video.play();
10069
- }
10070
- });
10071
- __publicField(this, "pause", () => {
10072
- if (this._video) {
10073
- this._video.pause();
10074
- }
9861
+ }
9862
+ if (e.code === "ArrowLeft") {
9863
+ const time = range(currentTime - 5, 0, duration);
9864
+ this.setCurrentTime(time);
9865
+ this.play();
9866
+ }
9867
+ if (e.code === "ArrowRight") {
9868
+ const time = range(currentTime + 5, 0, duration);
9869
+ this.setCurrentTime(time);
9870
+ this.play();
9871
+ }
9872
+ });
9873
+ /**
9874
+ * @description: 点击player-btn,触发的事件
9875
+ * @param {*} void
9876
+ * @return {*}
9877
+ */
9878
+ __publicField(this, "dispatchClickPlayerBtnAction", (e) => {
9879
+ e.stopPropagation();
9880
+ e.preventDefault();
9881
+ if (PLAY_STATE_LIST.includes(this.ctx.currentState)) {
9882
+ this.pause();
9883
+ this._playerBtn.style.setProperty("display", "block");
9884
+ } else {
9885
+ this.play();
9886
+ this._playerBtn.style.setProperty("display", "none");
9887
+ }
9888
+ });
9889
+ __publicField(this, "changeVolumeProgress", (e) => {
9890
+ if (this._video) {
9891
+ this.setVolume(e.detail.value);
9892
+ this.change("volume", e.detail.value);
9893
+ if (e.detail.value > 0) {
9894
+ this._volume = e.detail.value;
9895
+ }
9896
+ }
9897
+ });
9898
+ __publicField(this, "customRequestFullscreen", (options) => {
9899
+ return this._player.requestFullscreen() || this._player.mozRequestFullScreen() || this._player.msRequestFullscreen() || this._player.oRequestFullscreen() || this._player.webkitRequestFullscreen() || this._player.webkitEnterFullscreen();
9900
+ });
9901
+ __publicField(this, "customExitFullscreen", () => {
9902
+ return document.exitFullscreen() || document.msExitFullscreen() || document.mozCancelFullScreen() || document.oCancelFullScreen() || document.webkitExitFullscreen();
9903
+ });
9904
+ __publicField(this, "openFullScreen", () => {
9905
+ if (!this.ctx.fullScreen) {
9906
+ this.customRequestFullscreen().then(() => {
9907
+ this.resize();
9908
+ this.ctx.fullScreen = true;
9909
+ }).catch((error) => {
10075
9910
  });
10076
- this._player = document.createElement("div");
10077
- this._container = document.createElement("div");
10078
- this._slot = document.createElement("slot");
10079
- this._playerBtn = document.createElement("div");
10080
- this._progress = document.createElement("div");
10081
- this._progressWrap = document.createElement("div");
10082
- this._progressWrapValue = document.createElement("div");
10083
- this._progressDot = document.createElement("div");
10084
- this._playerControllerBottom = document.createElement("div");
10085
- this._playerControllerBottomRight = document.createElement("div");
10086
- this._playerControllerBottomLeft = document.createElement("div");
10087
- this._player.setAttribute("class", "ran-player");
10088
- this._player.setAttribute(
10089
- "id",
10090
- "ran-player" + `${performance.now()}`.replace(".", "")
10091
- );
10092
- this._playerBtn.setAttribute("class", "ran-player-play-btn");
10093
- this._progress.setAttribute("class", "ran-player-controller-progress");
10094
- this._progressWrap.setAttribute(
10095
- "class",
10096
- "ran-player-controller-progress-wrap"
10097
- );
10098
- this._progressWrapValue.setAttribute(
10099
- "class",
10100
- "ran-player-controller-progress-wrap-value"
10101
- );
10102
- this._progressDot.setAttribute(
10103
- "class",
10104
- "ran-player-controller-progress-dot"
10105
- );
10106
- this._playerControllerBottom.setAttribute(
10107
- "class",
10108
- "ran-player-controller-bottom"
10109
- );
10110
- this._playerControllerBottomRight.setAttribute(
10111
- "class",
10112
- "ran-player-controller-bottom-right"
10113
- );
10114
- this._playerControllerBottomLeft.setAttribute(
10115
- "class",
10116
- "ran-player-controller-bottom-left"
10117
- );
10118
- this._playerControllerBottomPlayBtn = document.createElement("div");
10119
- this._playerControllerBottomPlayBtn.setAttribute(
10120
- "class",
10121
- "ran-player-controller-bottom-left-btn"
10122
- );
10123
- this._playerControllerBottomTimeCurrent = document.createElement("div");
10124
- this._playerControllerBottomTimeCurrent.setAttribute(
10125
- "class",
10126
- "ran-player-controller-bottom-left-time-current"
10127
- );
10128
- this._playerControllerBottomTimeDivide = document.createElement("div");
10129
- this._playerControllerBottomTimeDivide.setAttribute(
10130
- "class",
10131
- "ran-player-controller-bottom-left-time-divide"
10132
- );
10133
- this._playerControllerBottomTimeDuration = document.createElement("div");
10134
- this._playerControllerBottomTimeDuration.setAttribute(
10135
- "class",
10136
- "ran-player-controller-bottom-left-time-duration"
10137
- );
10138
- this._playControllerBottomSpeed = document.createElement("div");
10139
- this._playControllerBottomSpeed.setAttribute(
10140
- "class",
10141
- "ran-player-controller-bottom-right-speed"
10142
- );
10143
- this._playControllerBottomSpeedPopover = document.createElement("r-select");
10144
- this._playControllerBottomSpeedPopover.setAttribute("value", "1");
10145
- this._playControllerBottomSpeedPopover.setAttribute(
10146
- "action",
10147
- "hover,click"
10148
- );
10149
- this._playControllerBottomSpeedPopover.setAttribute("type", "text");
10150
- this._playControllerBottomSpeedPopover.setAttribute("placement", "top");
10151
- const id = this._player.getAttribute("id");
10152
- id && this._playControllerBottomSpeedPopover.setAttribute(
10153
- "getPopupContainerId",
10154
- id
10155
- );
10156
- this._playControllerBottomSpeedPopover.setAttribute(
10157
- "dropdownclass",
10158
- "video-speed-dropdown"
10159
- );
10160
- this._playControllerBottomSpeedPopover.addEventListener(
10161
- "change",
10162
- this.changeSpeed
10163
- );
10164
- const Fragment = document.createDocumentFragment();
10165
- SPEED.forEach((item) => {
10166
- const { label, value } = item;
10167
- const option = document.createElement("r-option");
10168
- option.innerHTML = label;
10169
- option.setAttribute("value", `${value}`);
10170
- Fragment.appendChild(option);
9911
+ } else {
9912
+ this.customExitFullscreen().then(() => {
9913
+ this.resize();
9914
+ this.ctx.fullScreen = false;
9915
+ }).catch((error) => {
10171
9916
  });
10172
- this._playControllerBottomSpeedPopover.appendChild(Fragment);
10173
- this._playControllerBottomSpeed.appendChild(
10174
- this._playControllerBottomSpeedPopover
10175
- );
10176
- this._playControllerBottomVolume = document.createElement("div");
10177
- this._playControllerBottomVolume.setAttribute(
10178
- "class",
10179
- "ran-player-controller-bottom-right-volume"
10180
- );
10181
- this._playControllerBottomVolumeProgress = document.createElement("r-progress");
10182
- this._playControllerBottomVolumeProgress.setAttribute(
10183
- "class",
10184
- "ran-player-controller-bottom-right-volume-progress"
10185
- );
10186
- this._playControllerBottomVolumeProgress.setAttribute("percent", "0.5");
10187
- this._playControllerBottomVolumeProgress.setAttribute("type", "drag");
10188
- this._playControllerBottomSpeedIcon = document.createElement("div");
10189
- this._playControllerBottomSpeedIcon.setAttribute(
10190
- "class",
10191
- "ran-player-controller-bottom-right-volume-icon ran-player-controller-bottom-right-volume-icon-volume"
10192
- );
10193
- this._playControllerBottomClarity = document.createElement("div");
10194
- this._playControllerBottomClarity.setAttribute(
10195
- "class",
10196
- "ran-player-controller-bottom-right-clarity"
10197
- );
10198
- this._playControllerBottomRightFullScreen = document.createElement("div");
10199
- this._playControllerBottomRightFullScreen.setAttribute(
10200
- "class",
10201
- "ran-player-controller-bottom-right-full"
10202
- );
10203
- this._playerController = document.createElement("div");
10204
- this._playerController.setAttribute("class", "ran-player-controller");
10205
- this._playerTip = document.createElement("div");
10206
- this._playerTip.setAttribute("class", "ran-player-controller-tip");
10207
- this._playerTipTime = document.createElement("div");
10208
- this._playerTipTime.setAttribute(
10209
- "class",
10210
- "ran-player-controller-tip-time"
10211
- );
10212
- this._playerTipText = document.createElement("div");
10213
- this._playerTipText.setAttribute(
10214
- "class",
10215
- "ran-player-controller-tip-text"
10216
- );
10217
- this._playerTip.appendChild(
10218
- createDocumentFragment([this._playerTipTime, this._playerTipText])
10219
- );
10220
- this._playerController.appendChild(
10221
- createDocumentFragment([
10222
- this._playerTip,
10223
- this._progress,
10224
- this._playerControllerBottom
10225
- ])
10226
- );
10227
- this._player.appendChild(
10228
- createDocumentFragment([
10229
- this._container,
10230
- this._slot,
10231
- this._playerBtn,
10232
- this._playerController
10233
- ])
10234
- );
10235
- this._progressWrap.appendChild(this._progressWrapValue);
10236
- this._progress.appendChild(
10237
- createDocumentFragment([this._progressWrap, this._progressDot])
10238
- );
10239
- this._playerControllerBottom.appendChild(
10240
- createDocumentFragment([
10241
- this._playerControllerBottomLeft,
10242
- this._playerControllerBottomRight
10243
- ])
10244
- );
10245
- this._playerControllerBottomLeft.appendChild(
10246
- createDocumentFragment([
10247
- this._playerControllerBottomPlayBtn,
10248
- this._playerControllerBottomTimeCurrent,
10249
- this._playerControllerBottomTimeDivide,
10250
- this._playerControllerBottomTimeDuration
10251
- ])
10252
- );
10253
- this._playControllerBottomVolume.appendChild(
10254
- createDocumentFragment([
10255
- this._playControllerBottomSpeedIcon,
10256
- this._playControllerBottomVolumeProgress
10257
- ])
10258
- );
10259
- this._playerControllerBottomRight.appendChild(
10260
- createDocumentFragment([
10261
- this._playControllerBottomClarity,
10262
- this._playControllerBottomSpeed,
10263
- this._playControllerBottomVolume,
10264
- this._playControllerBottomRightFullScreen
10265
- ])
10266
- );
10267
- this.ctx = {
10268
- currentTime: 0,
10269
- // 当前时间
10270
- duration: 0,
10271
- // 总时长
10272
- currentState: "",
10273
- // 当前视频状态
10274
- action: new SyncHook(),
10275
- // 不同时期触发的状态
10276
- volume: 0.5,
10277
- // 当前音量
10278
- playbackRate: 1,
10279
- // 当前倍速
10280
- clarity: "",
10281
- // 当前清晰度
10282
- fullScreen: false,
10283
- // 是否全屏
10284
- levels: [],
10285
- // 清晰度列表
10286
- url: "",
10287
- // 当前播放的地址
10288
- levelMap: /* @__PURE__ */ new Map()
10289
- // 清晰度和名字的映射关系
10290
- };
10291
- this.moveProgress = {
10292
- percentage: 0,
10293
- mouseDown: false
10294
- };
10295
- }
10296
- static get observedAttributes() {
10297
- return ["src", "volume", "currentTime", "playbackRate"];
10298
- }
10299
- get src() {
10300
- return this.getAttribute("src") || "";
10301
- }
10302
- set src(value) {
10303
- this.setAttribute("src", value || "");
10304
- }
10305
- get volume() {
10306
- return this.getAttribute("volume") || "";
10307
9917
  }
10308
- set volume(value) {
10309
- this.setAttribute("volume", value || "");
10310
- }
10311
- get currentTime() {
10312
- return this.getAttribute("currentTime") || "";
10313
- }
10314
- set currentTime(value) {
10315
- this.setAttribute("currentTime", value || "");
10316
- }
10317
- get playbackRate() {
10318
- return this.getAttribute("playbackRate") || "";
10319
- }
10320
- set playbackRate(value) {
10321
- this.setAttribute("playbackRate", value || "");
10322
- }
10323
- connectedCallback() {
10324
- this._container.addEventListener(
10325
- "click",
10326
- this.dispatchClickPlayerContainerAction
10327
- );
10328
- this._playerBtn.addEventListener(
10329
- "click",
10330
- this.dispatchClickPlayerBtnAction
10331
- );
10332
- document.body.addEventListener("keydown", this.SpaceKeyDown);
10333
- this._progressDot.addEventListener(
10334
- "mousedown",
10335
- this.progressDotMouseDown
10336
- );
10337
- this._playerControllerBottomPlayBtn.addEventListener(
10338
- "click",
10339
- this.dispatchClickPlayerBtnAction
9918
+ });
9919
+ __publicField(this, "changeSpeed", (e) => {
9920
+ this.change("speed", e.detail.value);
9921
+ this.setPlaybackRate(e.detail.value);
9922
+ });
9923
+ __publicField(this, "progressMouseEnter", (e) => {
9924
+ this._playerTip.style.setProperty("opacity", "1");
9925
+ const rect = this._progress.getBoundingClientRect();
9926
+ const offsetX = e.clientX - rect.left;
9927
+ if (this._playerTipText.innerText) {
9928
+ this._playerTip.style.setProperty(
9929
+ "transform",
9930
+ `translate(calc(${offsetX}px - 50%),-20px)`
10340
9931
  );
10341
- this._progress.addEventListener("click", this.progressClick);
10342
- this._progress.addEventListener("mouseenter", this.progressMouseEnter);
10343
- this._progress.addEventListener("mousemove", this.progressMouseMove);
10344
- this._progress.addEventListener("mouseleave", this.progressMouseLeave);
10345
- this._player.addEventListener("mousemove", this.progressDotMouseMove);
10346
- this._player.addEventListener("mouseup", this.progressDotMouseUp);
10347
- this._playControllerBottomVolumeProgress.addEventListener(
10348
- "change",
10349
- this.changeVolumeProgress
9932
+ } else {
9933
+ this._playerTip.style.setProperty(
9934
+ "transform",
9935
+ `translateX(calc(${offsetX}px - 50%))`
10350
9936
  );
10351
- this._playControllerBottomRightFullScreen.addEventListener(
10352
- "click",
10353
- this.openFullScreen
10354
- );
10355
- this._playControllerBottomSpeedIcon.addEventListener(
10356
- "click",
10357
- this.changePlayerVolume
10358
- );
10359
- document.addEventListener("fullscreenchange", this.fullScreenChange);
10360
- window.addEventListener("resize", this.resize);
10361
- this.updatePlayer();
10362
- }
10363
- disconnectCallback() {
10364
- this._container.removeEventListener(
10365
- "click",
10366
- this.dispatchClickPlayerContainerAction
10367
- );
10368
- this._playerBtn.removeEventListener(
10369
- "click",
10370
- this.dispatchClickPlayerBtnAction
10371
- );
10372
- this._playerControllerBottomPlayBtn.removeEventListener(
10373
- "click",
10374
- this.dispatchClickPlayerBtnAction
9937
+ }
9938
+ this._playerTipTime.innerText = timeFormat(
9939
+ offsetX / this._progress.clientWidth * this.ctx.duration
9940
+ );
9941
+ });
9942
+ __publicField(this, "progressMouseLeave", (e) => {
9943
+ if (e.target.classList.contains(
9944
+ "ran-player-controller-progress-wrap-dot"
9945
+ )) {
9946
+ return;
9947
+ }
9948
+ this._playerTip.style.setProperty("opacity", "0");
9949
+ });
9950
+ __publicField(this, "progressMouseMove", (e) => {
9951
+ const rect = this._progress.getBoundingClientRect();
9952
+ this._playerTip.style.setProperty("opacity", "1");
9953
+ const offsetX = e.clientX - rect.left;
9954
+ if (this._playerTipText.innerText) {
9955
+ this._playerTip.style.setProperty(
9956
+ "transform",
9957
+ `translate(calc(${offsetX}px - 50%),-20px)`
10375
9958
  );
10376
- this.cancelAnimationFrame();
10377
- document.removeEventListener("keydown", this.SpaceKeyDown);
10378
- this._progress.removeEventListener("click", this.progressClick);
10379
- this._progress.removeEventListener(
10380
- "mouseenter",
10381
- this.progressMouseEnter
9959
+ } else {
9960
+ this._playerTip.style.setProperty(
9961
+ "transform",
9962
+ `translateX(calc(${offsetX}px - 50%))`
10382
9963
  );
10383
- this._progress.removeEventListener("mousemove", this.progressMouseMove);
10384
- this._progress.removeEventListener(
10385
- "mouseleave",
10386
- this.progressMouseLeave
9964
+ }
9965
+ this._playerTipTime.innerText = timeFormat(
9966
+ offsetX / this._progress.clientWidth * this.ctx.duration
9967
+ );
9968
+ });
9969
+ __publicField(this, "changePlayerVolume", () => {
9970
+ if (!this._video)
9971
+ return;
9972
+ const { volume } = this.ctx;
9973
+ if (volume > 0) {
9974
+ addClassToElement(
9975
+ this._playControllerBottomSpeedIcon,
9976
+ "ran-player-controller-bottom-right-volume-icon-mute"
10387
9977
  );
10388
- this._progressDot.removeEventListener(
10389
- "mousedown",
10390
- this.progressDotMouseDown
9978
+ removeClassToElement(
9979
+ this._playControllerBottomSpeedIcon,
9980
+ "ran-player-controller-bottom-right-volume-icon-volume"
10391
9981
  );
10392
- this._player.removeEventListener(
10393
- "mousemove",
10394
- this.progressDotMouseMove
9982
+ this._playControllerBottomVolumeProgress.setAttribute("percent", "0");
9983
+ this.setVolume(0);
9984
+ this.change("volume", 0);
9985
+ } else {
9986
+ addClassToElement(
9987
+ this._playControllerBottomSpeedIcon,
9988
+ "ran-player-controller-bottom-right-volume-icon-volume"
10395
9989
  );
10396
- this._player.removeEventListener("mouseup", this.progressDotMouseUp);
10397
- this._playControllerBottomVolumeProgress.removeEventListener(
10398
- "change",
10399
- this.changeVolumeProgress
9990
+ removeClassToElement(
9991
+ this._playControllerBottomSpeedIcon,
9992
+ "ran-player-controller-bottom-right-volume-icon-mute"
10400
9993
  );
10401
- this._playControllerBottomRightFullScreen.removeEventListener(
10402
- "click",
10403
- this.openFullScreen
9994
+ this._playControllerBottomVolumeProgress.setAttribute(
9995
+ "percent",
9996
+ `${this._volume || 0.5}`
10404
9997
  );
10405
- window.removeEventListener("resize", this.resize);
10406
- document.removeEventListener("fullscreenchange", this.fullScreenChange);
10407
- }
10408
- attributeChangedCallback(k, o, n) {
9998
+ this.setVolume(0.5);
9999
+ this.change("volume", this._volume || 0.5);
10000
+ }
10001
+ });
10002
+ __publicField(this, "resize", () => {
10003
+ if (this._video) {
10004
+ const { width, height } = this._player.getBoundingClientRect();
10005
+ this._video.style.setProperty("width", `${width}px`);
10006
+ this._video.style.setProperty("height", `${height}px`);
10007
+ if (document.body.clientWidth < 500) {
10008
+ this._playControllerBottomVolume.style.setProperty(
10009
+ "display",
10010
+ "none"
10011
+ );
10012
+ } else {
10013
+ this._playControllerBottomVolume.style.setProperty(
10014
+ "display",
10015
+ "flex"
10016
+ );
10017
+ }
10409
10018
  }
10410
- }
10019
+ this.updateCurrentProgress();
10020
+ });
10021
+ __publicField(this, "fullScreenChange", () => {
10022
+ var _a;
10023
+ if ((_a = document.fullscreenElement) == null ? void 0 : _a.classList.contains("ran-player")) {
10024
+ this.change("fullscreen", true);
10025
+ this.ctx.fullScreen = true;
10026
+ } else {
10027
+ this.change("fullscreen", false);
10028
+ this.ctx.fullScreen = false;
10029
+ }
10030
+ });
10031
+ __publicField(this, "getPlaybackRate", () => {
10032
+ if (this._video) {
10033
+ this.ctx.playbackRate = this._video.playbackRate || 0;
10034
+ }
10035
+ return this.ctx.playbackRate;
10036
+ });
10037
+ __publicField(this, "setPlaybackRate", (n) => {
10038
+ if (this._video) {
10039
+ this.ctx.playbackRate = n;
10040
+ this._video.playbackRate = n;
10041
+ }
10042
+ return this.ctx.playbackRate;
10043
+ });
10044
+ __publicField(this, "setVolume", (n) => {
10045
+ if (this._video) {
10046
+ this.ctx.volume = n;
10047
+ this._video.volume = n;
10048
+ }
10049
+ return this.ctx.volume;
10050
+ });
10051
+ __publicField(this, "getVolume", () => {
10052
+ if (this._video) {
10053
+ this.ctx.volume = this._video.volume || 0;
10054
+ }
10055
+ return this.ctx.volume;
10056
+ });
10057
+ __publicField(this, "setCurrentTime", (n) => {
10058
+ if (this._video) {
10059
+ this.ctx.currentTime = n;
10060
+ this._video.currentTime = n;
10061
+ }
10062
+ return this.ctx.currentTime;
10063
+ });
10064
+ __publicField(this, "getCurrentTime", () => {
10065
+ if (this._video) {
10066
+ this.ctx.currentTime = this._video.currentTime || 0;
10067
+ }
10068
+ return this.ctx.currentTime;
10069
+ });
10070
+ __publicField(this, "getTotalTime", () => {
10071
+ if (this._video) {
10072
+ this.ctx.duration = this._video.duration || 0;
10073
+ }
10074
+ return this.ctx.duration;
10075
+ });
10076
+ __publicField(this, "play", (n) => {
10077
+ if (this._video) {
10078
+ if (n !== void 0 && n >= 0) {
10079
+ this.ctx.currentTime = n;
10080
+ this._video.currentTime = n;
10081
+ }
10082
+ this._video.play();
10083
+ }
10084
+ });
10085
+ __publicField(this, "pause", () => {
10086
+ if (this._video) {
10087
+ this._video.pause();
10088
+ }
10089
+ });
10090
+ this._player = document.createElement("div");
10091
+ this._container = document.createElement("div");
10092
+ this._slot = document.createElement("slot");
10093
+ this._playerBtn = document.createElement("div");
10094
+ this._progress = document.createElement("div");
10095
+ this._progressWrap = document.createElement("div");
10096
+ this._progressWrapValue = document.createElement("div");
10097
+ this._progressDot = document.createElement("div");
10098
+ this._playerControllerBottom = document.createElement("div");
10099
+ this._playerControllerBottomRight = document.createElement("div");
10100
+ this._playerControllerBottomLeft = document.createElement("div");
10101
+ this._player.setAttribute("class", "ran-player");
10102
+ this._player.setAttribute(
10103
+ "id",
10104
+ "ran-player" + `${performance.now()}`.replace(".", "")
10105
+ );
10106
+ this._playerBtn.setAttribute("class", "ran-player-play-btn");
10107
+ this._progress.setAttribute("class", "ran-player-controller-progress");
10108
+ this._progressWrap.setAttribute(
10109
+ "class",
10110
+ "ran-player-controller-progress-wrap"
10111
+ );
10112
+ this._progressWrapValue.setAttribute(
10113
+ "class",
10114
+ "ran-player-controller-progress-wrap-value"
10115
+ );
10116
+ this._progressDot.setAttribute(
10117
+ "class",
10118
+ "ran-player-controller-progress-dot"
10119
+ );
10120
+ this._playerControllerBottom.setAttribute(
10121
+ "class",
10122
+ "ran-player-controller-bottom"
10123
+ );
10124
+ this._playerControllerBottomRight.setAttribute(
10125
+ "class",
10126
+ "ran-player-controller-bottom-right"
10127
+ );
10128
+ this._playerControllerBottomLeft.setAttribute(
10129
+ "class",
10130
+ "ran-player-controller-bottom-left"
10131
+ );
10132
+ this._playerControllerBottomPlayBtn = document.createElement("div");
10133
+ this._playerControllerBottomPlayBtn.setAttribute(
10134
+ "class",
10135
+ "ran-player-controller-bottom-left-btn"
10136
+ );
10137
+ this._playerControllerBottomTimeCurrent = document.createElement("div");
10138
+ this._playerControllerBottomTimeCurrent.setAttribute(
10139
+ "class",
10140
+ "ran-player-controller-bottom-left-time-current"
10141
+ );
10142
+ this._playerControllerBottomTimeDivide = document.createElement("div");
10143
+ this._playerControllerBottomTimeDivide.setAttribute(
10144
+ "class",
10145
+ "ran-player-controller-bottom-left-time-divide"
10146
+ );
10147
+ this._playerControllerBottomTimeDuration = document.createElement("div");
10148
+ this._playerControllerBottomTimeDuration.setAttribute(
10149
+ "class",
10150
+ "ran-player-controller-bottom-left-time-duration"
10151
+ );
10152
+ this._playControllerBottomSpeed = document.createElement("div");
10153
+ this._playControllerBottomSpeed.setAttribute(
10154
+ "class",
10155
+ "ran-player-controller-bottom-right-speed"
10156
+ );
10157
+ this._playControllerBottomSpeedPopover = document.createElement("r-select");
10158
+ this._playControllerBottomSpeedPopover.setAttribute("value", "1");
10159
+ this._playControllerBottomSpeedPopover.setAttribute(
10160
+ "action",
10161
+ "hover,click"
10162
+ );
10163
+ this._playControllerBottomSpeedPopover.setAttribute("type", "text");
10164
+ this._playControllerBottomSpeedPopover.setAttribute("placement", "top");
10165
+ const id = this._player.getAttribute("id");
10166
+ id && this._playControllerBottomSpeedPopover.setAttribute(
10167
+ "getPopupContainerId",
10168
+ id
10169
+ );
10170
+ this._playControllerBottomSpeedPopover.setAttribute(
10171
+ "dropdownclass",
10172
+ "video-speed-dropdown"
10173
+ );
10174
+ this._playControllerBottomSpeedPopover.addEventListener(
10175
+ "change",
10176
+ this.changeSpeed
10177
+ );
10178
+ const Fragment = document.createDocumentFragment();
10179
+ SPEED.forEach((item) => {
10180
+ const { label, value } = item;
10181
+ const option = document.createElement("r-option");
10182
+ option.innerHTML = label;
10183
+ option.setAttribute("value", `${value}`);
10184
+ Fragment.appendChild(option);
10185
+ });
10186
+ this._playControllerBottomSpeedPopover.appendChild(Fragment);
10187
+ this._playControllerBottomSpeed.appendChild(
10188
+ this._playControllerBottomSpeedPopover
10189
+ );
10190
+ this._playControllerBottomVolume = document.createElement("div");
10191
+ this._playControllerBottomVolume.setAttribute(
10192
+ "class",
10193
+ "ran-player-controller-bottom-right-volume"
10194
+ );
10195
+ this._playControllerBottomVolumeProgress = document.createElement("r-progress");
10196
+ this._playControllerBottomVolumeProgress.setAttribute(
10197
+ "class",
10198
+ "ran-player-controller-bottom-right-volume-progress"
10199
+ );
10200
+ this._playControllerBottomVolumeProgress.setAttribute("percent", "0.5");
10201
+ this._playControllerBottomVolumeProgress.setAttribute("type", "drag");
10202
+ this._playControllerBottomSpeedIcon = document.createElement("div");
10203
+ this._playControllerBottomSpeedIcon.setAttribute(
10204
+ "class",
10205
+ "ran-player-controller-bottom-right-volume-icon ran-player-controller-bottom-right-volume-icon-volume"
10206
+ );
10207
+ this._playControllerBottomClarity = document.createElement("div");
10208
+ this._playControllerBottomClarity.setAttribute(
10209
+ "class",
10210
+ "ran-player-controller-bottom-right-clarity"
10211
+ );
10212
+ this._playControllerBottomRightFullScreen = document.createElement("div");
10213
+ this._playControllerBottomRightFullScreen.setAttribute(
10214
+ "class",
10215
+ "ran-player-controller-bottom-right-full"
10216
+ );
10217
+ this._playerController = document.createElement("div");
10218
+ this._playerController.setAttribute("class", "ran-player-controller");
10219
+ this._playerTip = document.createElement("div");
10220
+ this._playerTip.setAttribute("class", "ran-player-controller-tip");
10221
+ this._playerTipTime = document.createElement("div");
10222
+ this._playerTipTime.setAttribute(
10223
+ "class",
10224
+ "ran-player-controller-tip-time"
10225
+ );
10226
+ this._playerTipText = document.createElement("div");
10227
+ this._playerTipText.setAttribute(
10228
+ "class",
10229
+ "ran-player-controller-tip-text"
10230
+ );
10231
+ this._playerTip.appendChild(
10232
+ createDocumentFragment([this._playerTipTime, this._playerTipText])
10233
+ );
10234
+ this._playerController.appendChild(
10235
+ createDocumentFragment([
10236
+ this._playerTip,
10237
+ this._progress,
10238
+ this._playerControllerBottom
10239
+ ])
10240
+ );
10241
+ this._player.appendChild(
10242
+ createDocumentFragment([
10243
+ this._container,
10244
+ this._slot,
10245
+ this._playerBtn,
10246
+ this._playerController
10247
+ ])
10248
+ );
10249
+ this._progressWrap.appendChild(this._progressWrapValue);
10250
+ this._progress.appendChild(
10251
+ createDocumentFragment([this._progressWrap, this._progressDot])
10252
+ );
10253
+ this._playerControllerBottom.appendChild(
10254
+ createDocumentFragment([
10255
+ this._playerControllerBottomLeft,
10256
+ this._playerControllerBottomRight
10257
+ ])
10258
+ );
10259
+ this._playerControllerBottomLeft.appendChild(
10260
+ createDocumentFragment([
10261
+ this._playerControllerBottomPlayBtn,
10262
+ this._playerControllerBottomTimeCurrent,
10263
+ this._playerControllerBottomTimeDivide,
10264
+ this._playerControllerBottomTimeDuration
10265
+ ])
10266
+ );
10267
+ this._playControllerBottomVolume.appendChild(
10268
+ createDocumentFragment([
10269
+ this._playControllerBottomSpeedIcon,
10270
+ this._playControllerBottomVolumeProgress
10271
+ ])
10272
+ );
10273
+ this._playerControllerBottomRight.appendChild(
10274
+ createDocumentFragment([
10275
+ this._playControllerBottomClarity,
10276
+ this._playControllerBottomSpeed,
10277
+ this._playControllerBottomVolume,
10278
+ this._playControllerBottomRightFullScreen
10279
+ ])
10280
+ );
10281
+ this.ctx = {
10282
+ currentTime: 0,
10283
+ // 当前时间
10284
+ duration: 0,
10285
+ // 总时长
10286
+ currentState: "",
10287
+ // 当前视频状态
10288
+ action: new SyncHook(),
10289
+ // 不同时期触发的状态
10290
+ volume: 0.5,
10291
+ // 当前音量
10292
+ playbackRate: 1,
10293
+ // 当前倍速
10294
+ clarity: "",
10295
+ // 当前清晰度
10296
+ fullScreen: false,
10297
+ // 是否全屏
10298
+ levels: [],
10299
+ // 清晰度列表
10300
+ url: "",
10301
+ // 当前播放的地址
10302
+ levelMap: /* @__PURE__ */ new Map()
10303
+ // 清晰度和名字的映射关系
10304
+ };
10305
+ this.moveProgress = {
10306
+ percentage: 0,
10307
+ mouseDown: false
10308
+ };
10309
+ }
10310
+ static get observedAttributes() {
10311
+ return ["src", "volume", "currentTime", "playbackRate"];
10312
+ }
10313
+ get src() {
10314
+ return this.getAttribute("src") || "";
10315
+ }
10316
+ set src(value) {
10317
+ this.setAttribute("src", value || "");
10318
+ }
10319
+ get volume() {
10320
+ return this.getAttribute("volume") || "";
10321
+ }
10322
+ set volume(value) {
10323
+ this.setAttribute("volume", value || "");
10324
+ }
10325
+ get currentTime() {
10326
+ return this.getAttribute("currentTime") || "";
10327
+ }
10328
+ set currentTime(value) {
10329
+ this.setAttribute("currentTime", value || "");
10330
+ }
10331
+ get playbackRate() {
10332
+ return this.getAttribute("playbackRate") || "";
10333
+ }
10334
+ set playbackRate(value) {
10335
+ this.setAttribute("playbackRate", value || "");
10336
+ }
10337
+ connectedCallback() {
10338
+ this._container.addEventListener(
10339
+ "click",
10340
+ this.dispatchClickPlayerContainerAction
10341
+ );
10342
+ this._playerBtn.addEventListener(
10343
+ "click",
10344
+ this.dispatchClickPlayerBtnAction
10345
+ );
10346
+ this.addEventListener("keydown", this.SpaceKeyDown);
10347
+ this._progressDot.addEventListener(
10348
+ "mousedown",
10349
+ this.progressDotMouseDown
10350
+ );
10351
+ this._playerControllerBottomPlayBtn.addEventListener(
10352
+ "click",
10353
+ this.dispatchClickPlayerBtnAction
10354
+ );
10355
+ this._progress.addEventListener("click", this.progressClick);
10356
+ this._progress.addEventListener("mouseenter", this.progressMouseEnter);
10357
+ this._progress.addEventListener("mousemove", this.progressMouseMove);
10358
+ this._progress.addEventListener("mouseleave", this.progressMouseLeave);
10359
+ this._player.addEventListener("mousemove", this.progressDotMouseMove);
10360
+ this._player.addEventListener("mouseup", this.progressDotMouseUp);
10361
+ this._playControllerBottomVolumeProgress.addEventListener(
10362
+ "change",
10363
+ this.changeVolumeProgress
10364
+ );
10365
+ this._playControllerBottomRightFullScreen.addEventListener(
10366
+ "click",
10367
+ this.openFullScreen
10368
+ );
10369
+ this._playControllerBottomSpeedIcon.addEventListener(
10370
+ "click",
10371
+ this.changePlayerVolume
10372
+ );
10373
+ document.addEventListener("fullscreenchange", this.fullScreenChange);
10374
+ window.addEventListener("resize", this.resize);
10375
+ this.updatePlayer();
10376
+ }
10377
+ disconnectCallback() {
10378
+ this._container.removeEventListener(
10379
+ "click",
10380
+ this.dispatchClickPlayerContainerAction
10381
+ );
10382
+ this._playerBtn.removeEventListener(
10383
+ "click",
10384
+ this.dispatchClickPlayerBtnAction
10385
+ );
10386
+ this._playerControllerBottomPlayBtn.removeEventListener(
10387
+ "click",
10388
+ this.dispatchClickPlayerBtnAction
10389
+ );
10390
+ this.cancelAnimationFrame();
10391
+ this.removeEventListener("keydown", this.SpaceKeyDown);
10392
+ this._progress.removeEventListener("click", this.progressClick);
10393
+ this._progress.removeEventListener(
10394
+ "mouseenter",
10395
+ this.progressMouseEnter
10396
+ );
10397
+ this._progress.removeEventListener("mousemove", this.progressMouseMove);
10398
+ this._progress.removeEventListener(
10399
+ "mouseleave",
10400
+ this.progressMouseLeave
10401
+ );
10402
+ this._progressDot.removeEventListener(
10403
+ "mousedown",
10404
+ this.progressDotMouseDown
10405
+ );
10406
+ this._player.removeEventListener(
10407
+ "mousemove",
10408
+ this.progressDotMouseMove
10409
+ );
10410
+ this._player.removeEventListener("mouseup", this.progressDotMouseUp);
10411
+ this._playControllerBottomVolumeProgress.removeEventListener(
10412
+ "change",
10413
+ this.changeVolumeProgress
10414
+ );
10415
+ this._playControllerBottomRightFullScreen.removeEventListener(
10416
+ "click",
10417
+ this.openFullScreen
10418
+ );
10419
+ window.removeEventListener("resize", this.resize);
10420
+ document.removeEventListener("fullscreenchange", this.fullScreenChange);
10421
+ }
10422
+ attributeChangedCallback(k, o, n) {
10423
+ }
10424
+ }
10425
+ function Custom() {
10426
+ if (typeof document !== "undefined" && !customElements.get("r-player")) {
10411
10427
  customElements.define("r-player", RanPlayer);
10412
10428
  return RanPlayer;
10413
10429
  }
@@ -10415,9 +10431,11 @@ function Custom() {
10415
10431
  const index = Custom();
10416
10432
  const index$1 = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
10417
10433
  __proto__: null,
10434
+ RanPlayer,
10418
10435
  default: index
10419
10436
  }, Symbol.toStringTag, { value: "Module" }));
10420
10437
  export {
10438
+ RanPlayer as R,
10421
10439
  index as a,
10422
10440
  index$1 as i
10423
10441
  };