@netless/app-slide 0.0.26 → 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.26",
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",
@@ -12,6 +12,8 @@
12
12
  "devDependencies": {
13
13
  "@netless/app-shared": "^0.1.1",
14
14
  "@netless/slide": "^0.1.32",
15
+ "@types/color-string": "^1.5.0",
16
+ "color-string": "^1.6.0",
15
17
  "side-effect-manager": "^0.1.5",
16
18
  "vanilla-lazyload": "^17.5.0"
17
19
  },
@@ -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";
@@ -249,7 +250,7 @@ export class SlideController {
249
250
  autoFPS: true,
250
251
  autoResolution: true,
251
252
  resolution: this.context.getAppOptions()?.resolution,
252
- transactionBgColor: this.context.getAppOptions()?.bgColor || "#f9f9fc",
253
+ transactionBgColor: this.context.getAppOptions()?.bgColor || cachedGetBgColor(anchor),
253
254
  },
254
255
  timestamp: this.timestamp,
255
256
  });
@@ -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
 
@@ -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
+ }