@netless/app-slide 0.0.23 → 0.0.27

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,3 @@
1
+ export declare function guessBgColor(el: HTMLElement): string;
2
+ export declare function toHex(color: string): string;
3
+ export declare function cachedGetBgColor(el: HTMLElement): string;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@netless/app-slide",
3
- "version": "0.0.23",
3
+ "version": "0.0.27",
4
4
  "main": "dist/main.cjs.js",
5
5
  "module": "dist/main.es.js",
6
6
  "types": "dist/index.d.ts",
@@ -11,8 +11,10 @@
11
11
  ],
12
12
  "devDependencies": {
13
13
  "@netless/app-shared": "^0.1.1",
14
- "@netless/slide": "^0.1.28",
15
- "side-effect-manager": "^0.1.4",
14
+ "@netless/slide": "^0.1.32",
15
+ "@types/color-string": "^1.5.0",
16
+ "color-string": "^1.6.0",
17
+ "side-effect-manager": "^0.1.5",
16
18
  "vanilla-lazyload": "^17.5.0"
17
19
  },
18
20
  "scripts": {
@@ -35,5 +35,14 @@ export function syncSceneWithSlide(
35
35
  room.putScenes(baseScenePath, scenes);
36
36
  }
37
37
 
38
- context.setScenePath(scenePath);
38
+ let currentScenePath: string;
39
+ if (context.getBox().focus) {
40
+ currentScenePath = room.state.sceneState.scenePath;
41
+ } else {
42
+ currentScenePath = context.getView()?.focusScenePath || "";
43
+ }
44
+
45
+ if (currentScenePath !== scenePath) {
46
+ context.setScenePath(scenePath);
47
+ }
39
48
  }
@@ -16,6 +16,7 @@ import type { Attributes, MagixPayload, SlideState } from "../typings";
16
16
  import { SideEffectManager } from "side-effect-manager";
17
17
  import { Slide, SLIDE_EVENTS } from "@netless/slide";
18
18
  import { clamp, deepClone, isObj } from "../utils/helpers";
19
+ import { cachedGetBgColor } from "../utils/bgcolor";
19
20
  export { syncSceneWithSlide, createDocsViewerPages } from "./helpers";
20
21
 
21
22
  export const DefaultUrl = "https://convertcdn.netless.link/dynamicConvert";
@@ -96,6 +97,7 @@ export class SlideController {
96
97
  if (this.debug) {
97
98
  console.log("[Slide] init with state", deepClone(state));
98
99
  }
100
+ this.syncStateOnceFlag = false;
99
101
  slide.setSlideState(deepClone(state));
100
102
  } else if (context.isAddApp) {
101
103
  // otherwise, maybe this slide is just added, let the adder kick start first render
@@ -195,6 +197,9 @@ export class SlideController {
195
197
 
196
198
  private onStateChange = (state: SlideState) => {
197
199
  if (this.context.getIsWritable()) {
200
+ if (import.meta.env.DEV) {
201
+ console.log("[Slide] state change", JSON.stringify(state, null, 2));
202
+ }
198
203
  this.context.updateAttributes(["state"], state);
199
204
  }
200
205
  };
@@ -245,7 +250,7 @@ export class SlideController {
245
250
  autoFPS: true,
246
251
  autoResolution: true,
247
252
  resolution: this.context.getAppOptions()?.resolution,
248
- transactionBgColor: "#f9f9fc",
253
+ transactionBgColor: this.context.getAppOptions()?.bgColor || cachedGetBgColor(anchor),
249
254
  },
250
255
  timestamp: this.timestamp,
251
256
  });
@@ -262,7 +267,7 @@ export class SlideController {
262
267
  this.sideEffect.flushAll();
263
268
  if (!this.destroyed) {
264
269
  if (this.debug) {
265
- console.log("[Slide] destroy (once)");
270
+ console.log("[Slide] destroy slide (once)");
266
271
  }
267
272
  this.slide.destroy();
268
273
  this.destroyed = true;
@@ -26,6 +26,7 @@ export class SlideDocsViewer {
26
26
  protected readonly whiteboardView: SlideDocsViewerConfig["view"];
27
27
  protected readonly mountSlideController: SlideDocsViewerConfig["mountSlideController"];
28
28
  protected readonly mountWhiteboard: SlideDocsViewerConfig["mountWhiteboard"];
29
+ private isViewMounted = false;
29
30
 
30
31
  public constructor({ box, view, mountSlideController, mountWhiteboard }: SlideDocsViewerConfig) {
31
32
  this.box = box;
@@ -92,7 +93,6 @@ export class SlideDocsViewer {
92
93
  if (!this.$whiteboardView) {
93
94
  this.$whiteboardView = document.createElement("div");
94
95
  this.$whiteboardView.className = this.wrapClassName("wb-view");
95
- this.mountWhiteboard(this.$whiteboardView);
96
96
  }
97
97
  return this.$whiteboardView;
98
98
  }
@@ -168,6 +168,11 @@ export class SlideDocsViewer {
168
168
  height,
169
169
  animationMode: "immediately" as AnimationMode.Immediately,
170
170
  });
171
+ if (!this.isViewMounted && width && height) {
172
+ this.isViewMounted = true;
173
+ console.log("[Slide] mount whiteboard view");
174
+ this.mountWhiteboard(this.$whiteboardView);
175
+ }
171
176
  }
172
177
  };
173
178
 
package/src/index.ts CHANGED
@@ -70,7 +70,7 @@ const SlideApp: NetlessApp<Attributes> = {
70
70
  box,
71
71
  view,
72
72
  mountSlideController,
73
- mountWhiteboard: dom => context.mountView(dom),
73
+ mountWhiteboard: context.mountView.bind(context),
74
74
  });
75
75
 
76
76
  if (import.meta.env.DEV) {
@@ -0,0 +1,46 @@
1
+ import ColorString from "color-string";
2
+
3
+ export function guessBgColor(el: HTMLElement): string {
4
+ try {
5
+ const bg = window.getComputedStyle(el).backgroundColor;
6
+ if (bg !== "rgba(0, 0, 0, 0)" && bg !== "transparent") {
7
+ return bg;
8
+ }
9
+ if (el.parentElement) {
10
+ return guessBgColor(el.parentElement);
11
+ }
12
+ } catch {
13
+ // ignore any error
14
+ }
15
+ return "#ffffff";
16
+ }
17
+
18
+ export function toHex(color: string): string {
19
+ const result = ColorString.get(color);
20
+ if (result && result.model === "rgb") {
21
+ const args = result.value;
22
+
23
+ // https://github.com/Qix-/color-convert/blob/8dfdbbc6b46fa6a305bf394d942cc1b08e23fca5/conversions.js#L616
24
+ const integer =
25
+ ((Math.round(args[0]) & 0xff) << 16) +
26
+ ((Math.round(args[1]) & 0xff) << 8) +
27
+ (Math.round(args[2]) & 0xff);
28
+
29
+ const string = integer.toString(16);
30
+ return "#" + "000000".substring(string.length) + string;
31
+ } else {
32
+ return color;
33
+ }
34
+ }
35
+
36
+ let cachedBgColor = "";
37
+
38
+ export function cachedGetBgColor(el: HTMLElement): string {
39
+ if (!cachedBgColor) {
40
+ cachedBgColor = toHex(guessBgColor(el));
41
+ if (import.meta.env.DEV) {
42
+ console.log("[Slide] guess bg color", cachedBgColor);
43
+ }
44
+ }
45
+ return cachedBgColor;
46
+ }