@netless/app-slide 0.0.29 → 0.0.34

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/main.es.js CHANGED
@@ -29882,7 +29882,7 @@ void main() {
29882
29882
  this.scaleExt = { x: 1, y: 1 }, this.scaleOrigin = { x: 1, y: 1 }, this.designScale = { x: 1, y: 1 }, this.bound = new fe(0, 0, 1, 1), this.pptX = 0, this.pptY = 0, this.presetSubType = 0, this.designWidth = 0, this.designHeight = 0, this.designX = 0, this.designY = 0, this.hasPreset = false, this.container = new Fe(), this.ctx = e3, this.style = new uu(this.container, t3.hardHidden), this.designGlobalPosition = { x: n2.x + ((r3 = (i2 = t3.position) === null || i2 === void 0 ? void 0 : i2.x) !== null && r3 !== void 0 ? r3 : 0), y: n2.y + ((s3 = (o3 = t3.position) === null || o3 === void 0 ? void 0 : o3.y) !== null && s3 !== void 0 ? s3 : 0) }, (t3.hlinkClick || t3.hlinkHover) && (this.hyperlink = new lu(this.container, this.ctx), t3.hlinkHover && ((a2 = this.hyperlink) === null || a2 === void 0 || a2.addAction(t3.hlinkHover, "hover")), t3.hlinkClick && ((u2 = this.hyperlink) === null || u2 === void 0 || u2.addAction(t3.hlinkClick, "click")));
29883
29883
  }
29884
29884
  updateScale() {
29885
- this.container.scale.x = this.designScale.x * this.scaleExt.x * this.scaleOrigin.x, this.container.scale.y = this.designScale.y * this.scaleExt.y * this.scaleOrigin.y;
29885
+ this.container && (this.container.scale.x = this.designScale.x * this.scaleExt.x * this.scaleOrigin.x, this.container.scale.y = this.designScale.y * this.scaleExt.y * this.scaleOrigin.y);
29886
29886
  }
29887
29887
  updateTransform(t3) {
29888
29888
  var e3, n2, i2, r3, o3, s3, a2, u2;
@@ -29904,7 +29904,7 @@ void main() {
29904
29904
  return cu(this.designWidth / this.ctx.stageWidth);
29905
29905
  }
29906
29906
  get design_ppt_h() {
29907
- return cu(this.designHeight / this.ctx.stageHeight);
29907
+ return cu((this.designHeight || this.container.height) / this.ctx.stageHeight);
29908
29908
  }
29909
29909
  get design_ppt_x() {
29910
29910
  return cu(this.designX / this.ctx.stageWidth);
@@ -29919,10 +29919,12 @@ void main() {
29919
29919
  this.scaleExt.x = t3 * this.ctx.stageWidth / this.designWidth, this.updateScale();
29920
29920
  }
29921
29921
  get ppt_h() {
29922
- return this.scaleExt.y * this.scaleOrigin.y * this.designHeight / this.ctx.stageHeight;
29922
+ const t3 = this.designHeight || this.container.height;
29923
+ return this.scaleExt.y * this.scaleOrigin.y * t3 / this.ctx.stageHeight;
29923
29924
  }
29924
29925
  set ppt_h(t3) {
29925
- this.scaleExt.y = t3 * this.ctx.stageHeight / this.designHeight, this.updateScale();
29926
+ const e3 = this.designHeight || this.container.height;
29927
+ this.scaleExt.y = t3 * this.ctx.stageHeight / e3, this.updateScale();
29926
29928
  }
29927
29929
  get ppt_x() {
29928
29930
  return (this.container.position.x - this.container.pivot.x) / this.ctx.stageWidth;
@@ -30788,8 +30790,9 @@ void main() {
30788
30790
  }, this.targetId = t3.targetId, this.ctx = t3.ctx, this.height = t3.height, this.width = t3.width, this.sprite = t3.sprite, this.media = t3.media, this.info = t3.info, this.canvasElement = t3.canvasElement, this.getMedianContainer(), this.createMediaController(), this.info.cut && (this.start = (e3 = this.info.cut.start) !== null && e3 !== void 0 ? e3 : 0, this.end = (n2 = this.info.cut.end) !== null && n2 !== void 0 ? n2 : 0);
30789
30791
  }
30790
30792
  getMedianContainer() {
30791
- let t3 = document.getElementById("median-container");
30792
- t3 || (t3 = document.createElement("div"), t3.id = "median-container", this.canvasElement.parentElement.appendChild(t3)), this.container = t3;
30793
+ var t3;
30794
+ let e3 = (t3 = this.canvasElement.parentElement) === null || t3 === void 0 ? void 0 : t3.querySelector(".median-container");
30795
+ e3 || (e3 = document.createElement("div"), e3.className = "median-container", this.canvasElement.parentElement.appendChild(e3)), this.container = e3;
30793
30796
  }
30794
30797
  static formatTime(t3) {
30795
30798
  let e3 = "00:00";
@@ -31075,7 +31078,7 @@ void main() {
31075
31078
  var t3, e3, n2;
31076
31079
  return sl(this, void 0, void 0, function* () {
31077
31080
  const i2 = this.ctx.fillTexture.getTexture(this.picTextureId);
31078
- i2.texture && (this.picSprite.texture = i2.texture), this.picMask.texture = this.backgroundMask.texture, this.picSprite.mask = this.picMask, this.picSprite.width = this.designWidth, this.picSprite.height = this.designHeight, this.container.addChild(this.picSprite), this.container.addChild(this.picMask), ((t3 = this.media) === null || t3 === void 0 ? void 0 : t3.type) === "video" ? (this.mediaPlayer = new il({ id: this.json.id + "-video", ctx: this.ctx, video: this.media, height: this.designHeight, width: this.designWidth, sprite: this.picSprite, container: this.container, canvasElement: this.ctx.view }), ((e3 = this.mediaPlayer) === null || e3 === void 0 ? void 0 : e3.sprite) && (this.mediaPlayer.sprite.mask = this.picMask)) : ((n2 = this.media) === null || n2 === void 0 ? void 0 : n2.type) === "audio" && (this.mediaPlayer = new ol({ id: this.json.id + "-audio", ctx: this.ctx, audio: this.media, height: this.designHeight, width: this.designWidth, sprite: this.picSprite, container: this.container, canvasElement: this.ctx.view })), this.mediaPlayer && (this.picSprite.interactive = true, this.picSprite.on("mouseover", () => {
31081
+ i2.texture && (this.picSprite.texture = i2.texture), this.picMask.texture = this.backgroundMask.texture, this.picSprite.mask = this.picMask, this.picSprite.width = this.designWidth, this.picSprite.height = this.designHeight, this.container.addChild(this.picSprite), this.container.addChild(this.picMask), ((t3 = this.media) === null || t3 === void 0 ? void 0 : t3.type) === "video" && this.media.src ? (this.mediaPlayer = new il({ id: this.json.id + "-video", ctx: this.ctx, video: this.media, height: this.designHeight, width: this.designWidth, sprite: this.picSprite, container: this.container, canvasElement: this.ctx.view }), ((e3 = this.mediaPlayer) === null || e3 === void 0 ? void 0 : e3.sprite) && (this.mediaPlayer.sprite.mask = this.picMask)) : ((n2 = this.media) === null || n2 === void 0 ? void 0 : n2.type) === "audio" && this.media.src && (this.mediaPlayer = new ol({ id: this.json.id + "-audio", ctx: this.ctx, audio: this.media, height: this.designHeight, width: this.designWidth, sprite: this.picSprite, container: this.container, canvasElement: this.ctx.view })), this.mediaPlayer && (this.picSprite.interactive = true, this.picSprite.on("mouseover", () => {
31079
31082
  this.mediaPlayer.showController();
31080
31083
  }), this.picSprite.on("mouseout", () => {
31081
31084
  this.mediaPlayer.hideController();
@@ -31798,7 +31801,7 @@ void main() {
31798
31801
  };
31799
31802
  class Hl extends s2.a {
31800
31803
  constructor(t3) {
31801
- super(), this.uuid = Date.now().toString(32) + Math.random().toString(32).substring(2), this.isSub = false, this.isShadow = false, this.startCount = 0, this.applyCount = 0, this.isReverse = false, this.isConflictDispose = false, this.isIterateEnd = false, this.parentTimeNode = null, this.isActive = false, this.isDestroy = false, this.shouldSeekOnStart = false, this.repeatTimeoutId = "", this.iterateShadows = [], this.isIterate = false, this.iterateType = "el", this.iterateIndex = 0, this.children = [], this.subList = [], this.duration = 0, this.timeDelta = 0, this.isNegativeSpeed = false, this.handleEndCond = () => {
31804
+ super(), this.uuid = Date.now().toString(32) + Math.random().toString(32).substring(2), this.isSub = false, this.isShadow = false, this.startCount = 0, this.applyCount = 0, this.isReverse = false, this.isConflictDispose = false, this.isIterateEnd = false, this.parentTimeNode = null, this.isActive = false, this.isDestroy = false, this.shouldSeekOnStart = false, this.repeatTimeoutId = "", this.iterateShadows = [], this.isEndEventsEmitted = false, this.isIterate = false, this.iterateType = "el", this.iterateIndex = 0, this.children = [], this.subList = [], this.duration = 0, this.timeDelta = 0, this.isNegativeSpeed = false, this.handleEndCond = () => {
31802
31805
  this.isActive && (this.isActive = false, this.dispose());
31803
31806
  }, this.handleActive = (t4 = true) => {
31804
31807
  if (this.isActive = true, this.applyCount += 1, this.json.iterate || this.emit("timeNodeStart", { id: this.uuid, activeCount: this.applyCount, isReverse: this.isReverse }), this.startCount > 0 && this.json.restart) {
@@ -31914,7 +31917,7 @@ void main() {
31914
31917
  this.duration <= t3 && this.duration > 0 ? (this.emit("timeUpdate", { delta: this.duration, duration: this.duration, isReverse: this.isReverse }), this.ctx.eventHub.emit(Uh.animateEnd), this.ctx.ticker.remove(this.updateTimeLine)) : this.duration > t3 && (this.ctx.eventHub.emit(Uh.animateStart), this.ctx.ticker.add(this.updateTimeLine));
31915
31918
  }
31916
31919
  startTimeLine(t3 = true) {
31917
- if (t3 && (this.eventHubs.global.emit(`time ${this.json.id} begin`), this.eventHubs.global.emit(`time ${this.json.id} onBegin`), this.eventHubs.runtime.emit(`runtime ${this.json.id} begin`)), this.json.iterate)
31920
+ if (t3 && (this.isEndEventsEmitted = false, this.eventHubs.global.emit(`time ${this.json.id} begin`), this.eventHubs.global.emit(`time ${this.json.id} onBegin`), this.eventHubs.runtime.emit(`runtime ${this.json.id} begin`)), this.json.iterate)
31918
31921
  return void this.startIterate();
31919
31922
  this.timeDelta = 0, this.emit("timelineStart", { id: this.uuid, activeCount: this.applyCount, isReverse: this.isReverse });
31920
31923
  const e3 = 1e3 / this.ctx.ticker.maxFPS;
@@ -31995,7 +31998,7 @@ void main() {
31995
31998
  });
31996
31999
  }
31997
32000
  seekToStart(t3 = true) {
31998
- if (this.isActive = false, this.dispose(), this.timeDelta = 0, this.emit("seekToStart"), this.json.iterate && !this.isIterate)
32001
+ if (this.isEndEventsEmitted = false, this.isActive = false, this.dispose(), this.timeDelta = 0, this.emit("seekToStart"), this.json.iterate && !this.isIterate)
31999
32002
  return this.isIterateEnd = true, void this.iterateShadows.forEach((e3) => e3.seekToStart(t3));
32000
32003
  if (t3)
32001
32004
  for (let t4 = this.subList.length - 1; t4 >= 0; t4--) {
@@ -32028,7 +32031,7 @@ void main() {
32028
32031
  return this.children.length > 0 && (t3 = t3 && this.children.every((t4) => t4.commonTimeNode.isTimeNodeEnd())), this.json.repeatCount && (t3 = t3 && this.applyCount >= this.json.repeatCount), this.json.autoRev && (t3 = t3 && !this.isReverse), t3 = t3 && this.isNatureTimeEnd(), !!this.isConflictDispose || (!(!this.isIterateEnd || !this.json.iterate) || t3);
32029
32032
  }
32030
32033
  emitEndEvents() {
32031
- this.eventHubs.global.emit(`time ${this.json.id} end`), this.eventHubs.global.emit(`time ${this.json.id} onEnd`), this.eventHubs.runtime.emit(`runtime ${this.json.id} end`), this.emit("timeNodeEnd", { id: this.uuid, activeCount: this.applyCount, isReverse: this.isReverse });
32034
+ this.isEndEventsEmitted || (this.isEndEventsEmitted = true, this.eventHubs.global.emit(`time ${this.json.id} end`), this.eventHubs.global.emit(`time ${this.json.id} onEnd`), this.eventHubs.runtime.emit(`runtime ${this.json.id} end`), this.emit("timeNodeEnd", { id: this.uuid, activeCount: this.applyCount, isReverse: this.isReverse }));
32032
32035
  }
32033
32036
  collectStartValue() {
32034
32037
  this.emit("timeNodeCreate"), this.children.forEach((t3) => t3.commonTimeNode.collectStartValue());
@@ -32215,7 +32218,7 @@ void main() {
32215
32218
  }
32216
32219
  destroy() {
32217
32220
  var t3;
32218
- super.destroy(), this.ctx.eventHub.removeAllListeners(), this.ctx.graphicsTexture.destroy(), this.ctx.fillTexture.destroy(), this.globalEventHub.removeAllListeners(), (t3 = this.timing) === null || t3 === void 0 || t3.destroy();
32221
+ this.ctx.eventHub.removeAllListeners(), this.ctx.graphicsTexture.destroy(), this.ctx.fillTexture.destroy(), this.globalEventHub.removeAllListeners(), (t3 = this.timing) === null || t3 === void 0 || t3.destroy(), super.destroy();
32219
32222
  }
32220
32223
  mainSeqStep() {
32221
32224
  var t3, e3;
@@ -35016,7 +35019,7 @@ void main(void){
35016
35019
  }, e3.prototype.createController = function() {
35017
35020
  this.player && (this.playerController = new kd({ player: this.player, params: this.player.config || {}, target: this.frame }));
35018
35021
  }, e3.prototype.setMedianControllerAttribute = function() {
35019
- this.medianController.id = "median-container", this.medianController.style.position = "absolute", this.medianController.style.left = "0", this.medianController.style.top = "0", this.medianController.style.zIndex = "2";
35022
+ this.medianController.className = "median-container", this.medianController.style.position = "absolute", this.medianController.style.left = "0", this.medianController.style.top = "0", this.medianController.style.zIndex = "2";
35020
35023
  }, e3.prototype.frameResizeHandler = function() {
35021
35024
  var t4 = this.frame.getBoundingClientRect(), e4 = t4.width, n2 = t4.height;
35022
35025
  this.frameWidth = e4, this.frameHeight = n2, this.resizeView();
@@ -35428,9 +35431,10 @@ swizzle$1.wrap = function(fn) {
35428
35431
  };
35429
35432
  var colorNames = colorName;
35430
35433
  var swizzle2 = simpleSwizzle.exports;
35434
+ var hasOwnProperty = Object.hasOwnProperty;
35431
35435
  var reverseNames = {};
35432
35436
  for (var name in colorNames) {
35433
- if (colorNames.hasOwnProperty(name)) {
35437
+ if (hasOwnProperty.call(colorNames, name)) {
35434
35438
  reverseNames[colorNames[name]] = name;
35435
35439
  }
35436
35440
  }
@@ -35467,9 +35471,9 @@ cs.get.rgb = function(string) {
35467
35471
  }
35468
35472
  var abbr = /^#([a-f0-9]{3,4})$/i;
35469
35473
  var hex = /^#([a-f0-9]{6})([a-f0-9]{2})?$/i;
35470
- var rgba = /^rgba?\(\s*([+-]?\d+)\s*,?\s*([+-]?\d+)\s*,?\s*([+-]?\d+)\s*(?:[,|\/]\s*([+-]?[\d\.]+)(%?)\s*)?\)$/;
35474
+ var rgba = /^rgba?\(\s*([+-]?\d+)(?=[\s,])\s*(?:,\s*)?([+-]?\d+)(?=[\s,])\s*(?:,\s*)?([+-]?\d+)\s*(?:[,|\/]\s*([+-]?[\d\.]+)(%?)\s*)?\)$/;
35471
35475
  var per = /^rgba?\(\s*([+-]?[\d\.]+)\%\s*,?\s*([+-]?[\d\.]+)\%\s*,?\s*([+-]?[\d\.]+)\%\s*(?:[,|\/]\s*([+-]?[\d\.]+)(%?)\s*)?\)$/;
35472
- var keyword = /(\w+)/;
35476
+ var keyword = /^(\w+)$/;
35473
35477
  var rgb = [0, 0, 0, 1];
35474
35478
  var match;
35475
35479
  var i;
@@ -35499,7 +35503,7 @@ cs.get.rgb = function(string) {
35499
35503
  }
35500
35504
  if (match[4]) {
35501
35505
  if (match[5]) {
35502
- rgb[3] = parseInt(match[4], 0) * 0.01;
35506
+ rgb[3] = parseFloat(match[4]) * 0.01;
35503
35507
  } else {
35504
35508
  rgb[3] = parseFloat(match[4]);
35505
35509
  }
@@ -35510,7 +35514,7 @@ cs.get.rgb = function(string) {
35510
35514
  }
35511
35515
  if (match[4]) {
35512
35516
  if (match[5]) {
35513
- rgb[3] = parseInt(match[4], 0) * 0.01;
35517
+ rgb[3] = parseFloat(match[4]) * 0.01;
35514
35518
  } else {
35515
35519
  rgb[3] = parseFloat(match[4]);
35516
35520
  }
@@ -35519,10 +35523,10 @@ cs.get.rgb = function(string) {
35519
35523
  if (match[1] === "transparent") {
35520
35524
  return [0, 0, 0, 0];
35521
35525
  }
35522
- rgb = colorNames[match[1]];
35523
- if (!rgb) {
35526
+ if (!hasOwnProperty.call(colorNames, match[1])) {
35524
35527
  return null;
35525
35528
  }
35529
+ rgb = colorNames[match[1]];
35526
35530
  rgb[3] = 1;
35527
35531
  return rgb;
35528
35532
  } else {
@@ -35542,7 +35546,7 @@ cs.get.hsl = function(string) {
35542
35546
  var match = string.match(hsl);
35543
35547
  if (match) {
35544
35548
  var alpha = parseFloat(match[4]);
35545
- var h = (parseFloat(match[1]) + 360) % 360;
35549
+ var h = (parseFloat(match[1]) % 360 + 360) % 360;
35546
35550
  var s2 = clamp(parseFloat(match[2]), 0, 100);
35547
35551
  var l = clamp(parseFloat(match[3]), 0, 100);
35548
35552
  var a = clamp(isNaN(alpha) ? 1 : alpha, 0, 1);
@@ -35600,10 +35604,45 @@ function clamp(num, min, max) {
35600
35604
  return Math.min(Math.max(min, num), max);
35601
35605
  }
35602
35606
  function hexDouble(num) {
35603
- var str = num.toString(16).toUpperCase();
35607
+ var str = Math.round(num).toString(16).toUpperCase();
35604
35608
  return str.length < 2 ? "0" + str : str;
35605
35609
  }
35606
35610
  var ColorString = colorString.exports;
35611
+ class Logger {
35612
+ constructor(enable) {
35613
+ this.enable = enable;
35614
+ this.apps = {};
35615
+ this.level = "debug";
35616
+ this._onMessage = (ev) => {
35617
+ if (isObj(ev.data)) {
35618
+ if (typeof ev.data.slide === "boolean") {
35619
+ this.enable = ev.data.slide;
35620
+ } else if (ev.data.slide === "__instance") {
35621
+ console.log(this);
35622
+ }
35623
+ }
35624
+ };
35625
+ window.addEventListener("message", this._onMessage);
35626
+ }
35627
+ log(...args) {
35628
+ if (this.enable) {
35629
+ console.log(...args);
35630
+ }
35631
+ }
35632
+ verbose(...args) {
35633
+ if (this.enable && this.level === "verbose") {
35634
+ console.log(...args);
35635
+ }
35636
+ }
35637
+ dispose(appId) {
35638
+ this.enable = false;
35639
+ delete this.apps[appId];
35640
+ window.removeEventListener("message", this._onMessage);
35641
+ }
35642
+ }
35643
+ const logger = new Logger(false);
35644
+ const log = logger.log.bind(logger);
35645
+ const verbose = logger.verbose.bind(logger);
35607
35646
  function guessBgColor(el) {
35608
35647
  try {
35609
35648
  const bg = window.getComputedStyle(el).backgroundColor;
@@ -35632,6 +35671,7 @@ let cachedBgColor = "";
35632
35671
  function cachedGetBgColor(el) {
35633
35672
  if (!cachedBgColor) {
35634
35673
  cachedBgColor = toHex(guessBgColor(el));
35674
+ log("[Slide] guess bg color", cachedBgColor);
35635
35675
  }
35636
35676
  return cachedBgColor;
35637
35677
  }
@@ -35684,7 +35724,6 @@ class SlideController {
35684
35724
  onTransitionEnd,
35685
35725
  onError
35686
35726
  }) {
35687
- var _a;
35688
35727
  this.sideEffect = new o();
35689
35728
  this.ready = false;
35690
35729
  this.readyPromise = new Promise((resolve) => {
@@ -35699,9 +35738,7 @@ class SlideController {
35699
35738
  type: Slide.SLIDE_EVENTS.syncDispatch,
35700
35739
  payload: event
35701
35740
  };
35702
- if (this.debug) {
35703
- console.log("[Slide] dispatch", event);
35704
- }
35741
+ log("[Slide] dispatch", event);
35705
35742
  this.room.dispatchMagixEvent(this.channel, payload);
35706
35743
  }
35707
35744
  };
@@ -35710,9 +35747,7 @@ class SlideController {
35710
35747
  const { type, payload } = ev.payload;
35711
35748
  if (type === Slide.SLIDE_EVENTS.syncDispatch) {
35712
35749
  this.syncStateOnce();
35713
- if (this.debug) {
35714
- console.log("[Slide] receive", payload);
35715
- }
35750
+ log("[Slide] receive", payload);
35716
35751
  if (!this.syncStateOnceFlag) {
35717
35752
  this.slide.emit(Slide.SLIDE_EVENTS.syncReceive, payload);
35718
35753
  }
@@ -35721,6 +35756,7 @@ class SlideController {
35721
35756
  };
35722
35757
  this.onStateChange = (state) => {
35723
35758
  if (this.context.getIsWritable()) {
35759
+ verbose("[Slide] state change", JSON.stringify(state, null, 2));
35724
35760
  this.context.updateAttributes(["state"], state);
35725
35761
  }
35726
35762
  };
@@ -35743,9 +35779,7 @@ class SlideController {
35743
35779
  setTimeout(this.pollReadyState, 500);
35744
35780
  } else {
35745
35781
  this.pollCount = 0;
35746
- if (this.debug) {
35747
- console.log("[Slide] renderSlide (retry after timeout)", 1);
35748
- }
35782
+ log("[Slide] renderSlide (retry after timeout)", 1);
35749
35783
  this.slide.renderSlide(1);
35750
35784
  }
35751
35785
  };
@@ -35765,9 +35799,7 @@ class SlideController {
35765
35799
  this.freezePromise = null;
35766
35800
  this.freeze = () => {
35767
35801
  if (this.ready) {
35768
- if (this.debug) {
35769
- console.log("[Slide] freeze", this.context.appId);
35770
- }
35802
+ log("[Slide] freeze", this.context.appId);
35771
35803
  if (this.freezePromise) {
35772
35804
  this._toFreeze = 1;
35773
35805
  } else if (!this.isFrozen) {
@@ -35780,9 +35812,7 @@ class SlideController {
35780
35812
  };
35781
35813
  this.unfreeze = async () => {
35782
35814
  if (this.ready) {
35783
- if (this.debug) {
35784
- console.log("[Slide] unfreeze", this.context.appId);
35785
- }
35815
+ log("[Slide] unfreeze", this.context.appId);
35786
35816
  if (this.freezePromise) {
35787
35817
  this._toFreeze = -1;
35788
35818
  } else if (this.isFrozen) {
@@ -35801,7 +35831,6 @@ class SlideController {
35801
35831
  this.channel = `channel-${context.appId}`;
35802
35832
  this.room = context.getRoom();
35803
35833
  this.player = this.room ? void 0 : context.getDisplayer();
35804
- this.debug = !!((_a = context.getAppOptions()) == null ? void 0 : _a.debug);
35805
35834
  this.slide = this.createSlide(anchor);
35806
35835
  this.syncStateOnceFlag = !this.context.isAddApp;
35807
35836
  this.initialize();
@@ -35821,15 +35850,11 @@ class SlideController {
35821
35850
  const { taskId, url, state } = __spreadValues(__spreadValues({}, EmptyAttributes), this.context.getAttributes());
35822
35851
  slide.setResource(taskId, url || DefaultUrl);
35823
35852
  if (state) {
35824
- if (this.debug) {
35825
- console.log("[Slide] init with state", deepClone(state));
35826
- }
35853
+ log("[Slide] init with state", deepClone(state));
35827
35854
  this.syncStateOnceFlag = false;
35828
35855
  slide.setSlideState(deepClone(state));
35829
35856
  } else if (context.isAddApp) {
35830
- if (this.debug) {
35831
- console.log("[Slide] init by renderSlide", 1);
35832
- }
35857
+ log("[Slide] init by renderSlide", 1);
35833
35858
  slide.renderSlide(1);
35834
35859
  }
35835
35860
  this.pollReadyState();
@@ -35868,9 +35893,7 @@ class SlideController {
35868
35893
  if (this.syncStateOnceFlag) {
35869
35894
  const { state } = __spreadValues(__spreadValues({}, EmptyAttributes), this.context.getAttributes());
35870
35895
  if (state) {
35871
- if (this.debug) {
35872
- console.log("[Slide] sync with state (once)", deepClone(state));
35873
- }
35896
+ log("[Slide] sync with state (once)", deepClone(state));
35874
35897
  this.slide.setSlideState(deepClone(state));
35875
35898
  this.syncStateOnceFlag = false;
35876
35899
  }
@@ -35892,7 +35915,7 @@ class SlideController {
35892
35915
  interactive: true,
35893
35916
  mode: "interactive",
35894
35917
  resize: true,
35895
- controller: this.debug,
35918
+ controller: logger.enable,
35896
35919
  renderOptions: {
35897
35920
  minFPS: 25,
35898
35921
  maxFPS: 30,
@@ -35903,17 +35926,12 @@ class SlideController {
35903
35926
  },
35904
35927
  timestamp: this.timestamp
35905
35928
  });
35906
- if (this.debug) {
35907
- window.slide = slide;
35908
- }
35909
35929
  return slide;
35910
35930
  }
35911
35931
  destroy() {
35912
35932
  this.sideEffect.flushAll();
35913
35933
  if (!this.destroyed) {
35914
- if (this.debug) {
35915
- console.log("[Slide] destroy slide (once)");
35916
- }
35934
+ log("[Slide] destroy slide (once)");
35917
35935
  this.slide.destroy();
35918
35936
  this.destroyed = true;
35919
35937
  }
@@ -36620,7 +36638,7 @@ if (runningOnBrowser) {
36620
36638
  autoInitialize(LazyLoad, window.lazyLoadOptions);
36621
36639
  }
36622
36640
  class DocsViewer {
36623
- constructor({ readonly, box, onNewPageIndex, onPlay }) {
36641
+ constructor({ readonly, onNewPageIndex, onPlay }) {
36624
36642
  this._pages = [];
36625
36643
  this.pageIndex = 0;
36626
36644
  this.setPaused = () => {
@@ -36634,7 +36652,6 @@ class DocsViewer {
36634
36652
  this.isSmallBox = false;
36635
36653
  this.sideEffect = new o();
36636
36654
  this.readonly = readonly;
36637
- this.box = box;
36638
36655
  this.onNewPageIndex = onNewPageIndex;
36639
36656
  this.onPlay = onPlay;
36640
36657
  this.render();
@@ -36648,10 +36665,6 @@ class DocsViewer {
36648
36665
  get pages() {
36649
36666
  return this._pages;
36650
36667
  }
36651
- mount() {
36652
- this.box.mountContent(this.$content);
36653
- this.box.mountFooter(this.$footer);
36654
- }
36655
36668
  unmount() {
36656
36669
  this.$content.remove();
36657
36670
  this.$footer.remove();
@@ -36892,7 +36905,7 @@ class DocsViewer {
36892
36905
  return `${this.namespace}-${className}`;
36893
36906
  }
36894
36907
  }
36895
- const ClickThroughAppliances = new Set(["clicker", "selector"]);
36908
+ const ClickThroughAppliances = new Set(["clicker"]);
36896
36909
  class SlideDocsViewer {
36897
36910
  constructor({ box, view, mountSlideController, mountWhiteboard }) {
36898
36911
  this.slideController = null;
@@ -36944,7 +36957,6 @@ class SlideDocsViewer {
36944
36957
  this.mountSlideController = mountSlideController;
36945
36958
  this.mountWhiteboard = mountWhiteboard;
36946
36959
  this.viewer = new DocsViewer({
36947
- box,
36948
36960
  readonly: box.readonly,
36949
36961
  onNewPageIndex: this.onNewPageIndex,
36950
36962
  onPlay: this.onPlay
@@ -36995,7 +37007,8 @@ class SlideDocsViewer {
36995
37007
  return this.$whiteboardView;
36996
37008
  }
36997
37009
  mount() {
36998
- this.viewer.mount();
37010
+ this.box.mountContent(this.viewer.$content);
37011
+ this.box.mountFooter(this.viewer.$footer);
36999
37012
  this.slideController = this.mountSlideController({
37000
37013
  anchor: this.$slide,
37001
37014
  onTransitionStart: this.viewer.setPlaying,
@@ -37041,15 +37054,18 @@ const apps = {
37041
37054
  map: new Map(),
37042
37055
  queue: [],
37043
37056
  validateQueue() {
37057
+ log("[Slide] freezer: validate", this.queue);
37044
37058
  while (this.queue.length > FreezerLength) {
37045
37059
  const appId = this.queue.pop();
37046
37060
  const slide = this.map.get(appId);
37047
37061
  if (slide) {
37062
+ log("[Slide] freezer: validate-freeze", appId, this.queue);
37048
37063
  slide.freeze();
37049
37064
  }
37050
37065
  }
37051
37066
  },
37052
37067
  set(appId, slide) {
37068
+ log("[Slide] freezer: add", appId, this.queue);
37053
37069
  this.map.set(appId, slide);
37054
37070
  if (!this.queue.includes(appId)) {
37055
37071
  this.queue.unshift(appId);
@@ -37057,6 +37073,7 @@ const apps = {
37057
37073
  this.validateQueue();
37058
37074
  },
37059
37075
  delete(appId) {
37076
+ log("[Slide] freezer: delete", appId, this.queue);
37060
37077
  this.map.delete(appId);
37061
37078
  this.queue = this.queue.filter((id) => id !== appId);
37062
37079
  },
@@ -37068,6 +37085,7 @@ const apps = {
37068
37085
  }
37069
37086
  this.queue.unshift(appId);
37070
37087
  this.validateQueue();
37088
+ log("[Slide] freezer: focus", appId, this.queue);
37071
37089
  if (slide) {
37072
37090
  slide.unfreeze();
37073
37091
  }
@@ -37079,6 +37097,139 @@ const addHooks = (emitter) => {
37079
37097
  });
37080
37098
  };
37081
37099
  var styles = ".netless-app-slide-content{position:relative;height:100%;overflow:hidden}.netless-app-slide-preview-mask{display:none;position:absolute;z-index:200;top:0;left:0;width:100%;height:100%}.netless-app-slide-preview{display:flex;flex-direction:column;align-items:center;position:absolute;z-index:300;top:0;left:0;width:33%;max-width:200px;height:100%;padding-top:10px;transform:translate(-100%);background:rgba(237,237,240,.9);box-shadow:inset -1px 0 #0000001c;transition:transform .4s}.netless-app-slide-preview-active .netless-app-slide-preview-mask{display:block}.netless-app-slide-preview-active .netless-app-slide-preview{transform:translate(0)}.netless-app-slide-preview-page{position:relative;display:block;width:55%;margin-bottom:10px;font-size:0;color:transparent;outline:none;border:7px solid transparent;border-radius:4px;transition:border-color .3s;user-select:none}.netless-app-slide-preview-page:hover,.netless-app-slide-preview-page.netless-app-slide-preview-page-active{border-color:#444e601a}.netless-app-slide-preview-page>img{width:100%;height:auto;box-sizing:border-box;border:1px solid rgba(0,0,0,.5);border-radius:1px;background-color:#fff;box-shadow:0 2px 8px #0000004d}.netless-app-slide-preview-page-name{position:absolute;top:1px;left:-10px;transform:translate(-100%);text-align:right;font-size:12px;color:#5f5f5f;user-select:none}.netless-app-slide-footer{box-sizing:border-box;height:26px;display:flex;align-items:center;padding:0 16px;border-top:1px solid #eeeef7;color:#191919}.netless-app-slide-float-footer{width:100%;min-height:26px;position:absolute;left:0;bottom:0;z-index:2000;background:rgba(249,249,252,.9);transition:opacity .4s}.netless-app-slide-footer-btn{box-sizing:border-box;width:26px;height:26px;font-size:0;margin:0;padding:3px;border:none;border-radius:1px;outline:none;color:currentColor;background:transparent;transition:background .4s;cursor:pointer;user-select:none}.netless-app-slide-footer-btn:hover{background:rgba(237,237,240,.9)}.netless-app-slide-footer-btn>svg{width:100%;height:100%}.netless-app-slide-footer-btn>svg:nth-of-type(2){display:none}.netless-app-slide-footer-btn.netless-app-slide-footer-btn-playing>svg:nth-of-type(1){display:none}.netless-app-slide-footer-btn.netless-app-slide-footer-btn-playing>svg:nth-of-type(2){display:initial}.netless-app-slide-footer-btn~.netless-app-slide-footer-btn{margin-left:15px}.netless-app-slide-page-jumps{flex:1;display:flex;justify-content:center;align-items:center}.netless-app-slide-page-number{margin-left:auto;font-size:13px;user-select:none;white-space:nowrap;word-break:keep-all}.netless-app-slide-page-number-input{border:none;outline:none;width:1.5em;text-align:right;border-radius:2px;color:currentColor;background:transparent;transition:background .4s;user-select:text}.netless-app-slide-page-number-input:hover,.netless-app-slide-page-number-input:focus,.netless-app-slide-page-number-input:active{background:#fff;box-shadow:#63636333 0 2px 8px}.netless-app-slide-readonly .netless-app-slide-footer-btn{cursor:not-allowed}.netless-app-slide-readonly .netless-app-slide-footer-btn:hover{background:transparent}.netless-app-slide-readonly .netless-app-slide-page-number-input{cursor:not-allowed}.netless-app-slide-readonly .netless-app-slide-page-number-input:hover,.netless-app-slide-readonly .netless-app-slide-page-number-input:focus,.netless-app-slide-readonly .netless-app-slide-page-number-input:active{background:transparent;box-shadow:none}.netless-app-slide-readonly .netless-app-slide-page-number-input:disabled{color:inherit}.netless-app-slide-readonly.netless-app-slide-float-footer{display:none}.netless-app-slide-wb-view{position:absolute;top:0;left:0;width:100%;height:100%;z-index:100;overflow:hidden}.netless-app-slide-slide{width:100%;height:100%;display:flex;align-items:center;justify-content:center}.netless-app-slide-slide canvas{transform:scale(var(--netless-app-slide-scale, 1))}\n";
37100
+ function previewSlide({
37101
+ container,
37102
+ taskId,
37103
+ url = DefaultUrl,
37104
+ debug = false
37105
+ }) {
37106
+ if (!taskId) {
37107
+ throw new Error("[Slide] taskId is required");
37108
+ }
37109
+ container.style.cssText += `display:flex;flex-direction:column`;
37110
+ const previewer = new SlidePreviewer({ target: container });
37111
+ previewer.debug = !!debug;
37112
+ previewer.mount(taskId, url);
37113
+ return previewer;
37114
+ }
37115
+ class SlidePreviewer {
37116
+ constructor(config) {
37117
+ this.slide = null;
37118
+ this.debug = false;
37119
+ this.ready = false;
37120
+ this.readyPromise = new Promise((resolve) => {
37121
+ this.resolveReady = () => {
37122
+ this.ready = true;
37123
+ resolve();
37124
+ };
37125
+ });
37126
+ this.onPageChanged = (page) => {
37127
+ this.viewer.setPageIndex(page - 1);
37128
+ };
37129
+ this.onTransitionStart = () => {
37130
+ this.viewer.setPlaying();
37131
+ };
37132
+ this.onTransitionEnd = () => {
37133
+ this.viewer.setPaused();
37134
+ };
37135
+ this.onError = ({ error }) => {
37136
+ this.viewer.setPaused();
37137
+ console.warn("[Slide] render error", error);
37138
+ };
37139
+ this.destroyed = false;
37140
+ this.refreshPages = () => {
37141
+ if (this.slide) {
37142
+ this.viewer.pages = createDocsViewerPages(this.slide);
37143
+ this.viewer.setPageIndex(this.getPageIndex(this.slide.slideCount));
37144
+ }
37145
+ };
37146
+ this.onPlay = () => {
37147
+ if (this.slide) {
37148
+ this.slide.nextStep();
37149
+ }
37150
+ };
37151
+ this.onNewPageIndex = (index) => {
37152
+ if (this.slide && this.slide.slideCount > 0) {
37153
+ this.slide.renderSlide(clamp$1(index + 1, 1, this.slide.slideCount));
37154
+ }
37155
+ };
37156
+ this.namespace = "netless-app-slide";
37157
+ this.target = config.target;
37158
+ this.bgColor = cachedGetBgColor(this.target);
37159
+ this.viewer = new DocsViewer({
37160
+ readonly: false,
37161
+ onNewPageIndex: this.onNewPageIndex,
37162
+ onPlay: this.onPlay
37163
+ });
37164
+ this.render();
37165
+ }
37166
+ render() {
37167
+ this.viewer.$content.appendChild(this.renderSlideContainer());
37168
+ }
37169
+ mount(taskId, url) {
37170
+ this.target.appendChild(this.renderStyle());
37171
+ this.target.appendChild(this.viewer.$content);
37172
+ this.target.appendChild(this.viewer.$footer);
37173
+ this.slide = new Slide.Slide({
37174
+ anchor: this.$slide,
37175
+ interactive: false,
37176
+ mode: "local",
37177
+ resize: true,
37178
+ controller: this.debug,
37179
+ renderOptions: {
37180
+ minFPS: 25,
37181
+ maxFPS: 30,
37182
+ autoFPS: true,
37183
+ autoResolution: true,
37184
+ transactionBgColor: this.bgColor
37185
+ }
37186
+ });
37187
+ this.registerEventListeners();
37188
+ this.slide.setResource(taskId, url);
37189
+ this.slide.renderSlide(1);
37190
+ }
37191
+ renderStyle() {
37192
+ const element = document.createElement("style");
37193
+ element.appendChild(document.createTextNode(styles));
37194
+ return element;
37195
+ }
37196
+ registerEventListeners() {
37197
+ if (!this.slide)
37198
+ return;
37199
+ const { slide } = this;
37200
+ slide.on(Slide.SLIDE_EVENTS.slideChange, this.onPageChanged);
37201
+ slide.on(Slide.SLIDE_EVENTS.renderStart, this.onTransitionStart);
37202
+ slide.on(Slide.SLIDE_EVENTS.renderEnd, this.onTransitionEnd);
37203
+ slide.on(Slide.SLIDE_EVENTS.mainSeqStepStart, this.onTransitionStart);
37204
+ slide.on(Slide.SLIDE_EVENTS.mainSeqStepEnd, this.onTransitionEnd);
37205
+ slide.on(Slide.SLIDE_EVENTS.renderError, this.onError);
37206
+ slide.on(Slide.SLIDE_EVENTS.renderEnd, this.resolveReady);
37207
+ this.readyPromise.then(this.refreshPages);
37208
+ }
37209
+ destroy() {
37210
+ if (this.slide && !this.destroyed) {
37211
+ log("[Slide] destroy slide (once)");
37212
+ this.slide.destroy();
37213
+ this.destroyed = true;
37214
+ }
37215
+ this.viewer.destroy();
37216
+ }
37217
+ getPageIndex(page) {
37218
+ return (page > 0 ? page : 1) - 1;
37219
+ }
37220
+ renderSlideContainer() {
37221
+ if (!this.$slide) {
37222
+ const $slide = document.createElement("div");
37223
+ $slide.className = this.wrapClassName("slide");
37224
+ $slide.dataset.appKind = "Slide";
37225
+ this.$slide = $slide;
37226
+ }
37227
+ return this.$slide;
37228
+ }
37229
+ wrapClassName(className) {
37230
+ return `${this.namespace}-${className}`;
37231
+ }
37232
+ }
37082
37233
  const SlideApp = {
37083
37234
  kind: "Slide",
37084
37235
  setup(context) {
@@ -37099,23 +37250,26 @@ const SlideApp = {
37099
37250
  const baseScenePath = context.getInitScenePath();
37100
37251
  let docsViewer = null;
37101
37252
  const onPageChanged = (page) => {
37102
- var _a;
37103
37253
  const room2 = context.getRoom();
37104
- if (docsViewer && docsViewer.slideController && room2 && context.getIsWritable()) {
37105
- syncSceneWithSlide(room2, context, docsViewer.slideController.slide, baseScenePath);
37106
- if (((_a = context.getAppOptions()) == null ? void 0 : _a.debug) || false) {
37107
- console.log("[Slide] page to", page);
37254
+ if (docsViewer && docsViewer.slideController) {
37255
+ let synced = false;
37256
+ if (room2 && context.getIsWritable()) {
37257
+ syncSceneWithSlide(room2, context, docsViewer.slideController.slide, baseScenePath);
37258
+ synced = true;
37108
37259
  }
37260
+ log("[Slide] page to", page, synced);
37109
37261
  docsViewer.viewer.setPageIndex(page - 1);
37110
37262
  }
37111
37263
  };
37112
37264
  const mountSlideController = (options) => {
37265
+ var _a, _b;
37113
37266
  const slideController = new SlideController(__spreadProps(__spreadValues({
37114
37267
  context
37115
37268
  }, options), {
37116
37269
  onPageChanged
37117
37270
  }));
37118
37271
  apps.set(context.appId, slideController);
37272
+ ((_a = logger.apps)[_b = context.appId] || (_a[_b] = {})).controller = slideController;
37119
37273
  slideController.readyPromise.then(options.onReady);
37120
37274
  return slideController;
37121
37275
  };
@@ -37127,6 +37281,13 @@ const SlideApp = {
37127
37281
  });
37128
37282
  const room = context.getRoom();
37129
37283
  const sideEffect = new o();
37284
+ sideEffect.add(() => {
37285
+ var _a, _b, _c;
37286
+ ((_a = logger.apps)[_b = context.appId] || (_a[_b] = {})).context = context;
37287
+ logger.enable = ((_c = context.getAppOptions()) == null ? void 0 : _c.debug) || false;
37288
+ logger.level = "debug";
37289
+ return () => logger.dispose(context.appId);
37290
+ });
37130
37291
  if (room) {
37131
37292
  docsViewer.toggleClickThrough(room.state.memberState.currentApplianceName);
37132
37293
  sideEffect.add(() => {
@@ -37140,7 +37301,7 @@ const SlideApp = {
37140
37301
  });
37141
37302
  }
37142
37303
  context.emitter.on("destroy", () => {
37143
- console.log("[Slide]: destroy");
37304
+ log("[Slide]: destroy");
37144
37305
  apps.delete(context.appId);
37145
37306
  sideEffect.flushAll();
37146
37307
  if (docsViewer) {
@@ -37151,5 +37312,5 @@ const SlideApp = {
37151
37312
  docsViewer.mount();
37152
37313
  }
37153
37314
  };
37154
- export { DefaultUrl, FreezerLength, addHooks, apps, SlideApp as default };
37315
+ export { DefaultUrl, FreezerLength, SlidePreviewer, addHooks, apps, SlideApp as default, previewSlide };
37155
37316
  //# sourceMappingURL=main.es.js.map