@netless/telebox-insider 1.0.0-alpha.18 → 1.0.0-alpha.20

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.
@@ -43,7 +43,7 @@ import type {
43
43
  TeleBoxDelegateEventConfig,
44
44
  TeleBoxRect,
45
45
  } from "./typings";
46
- import { TeleStage } from "../TeleStage";
46
+ import { calcStageRect } from "./utils";
47
47
 
48
48
  export * from "./constants";
49
49
  export * from "./typings";
@@ -57,8 +57,10 @@ type ValConfig = {
57
57
  visible: Val<RequiredTeleBoxConfig["visible"], boolean>;
58
58
  resizable: Val<RequiredTeleBoxConfig["resizable"], boolean>;
59
59
  draggable: Val<RequiredTeleBoxConfig["draggable"], boolean>;
60
- ratio: Val<RequiredTeleBoxConfig["ratio"], boolean>;
61
- stageRatio: Val<number | null>;
60
+ boxRatio: Val<RequiredTeleBoxConfig["boxRatio"], boolean>;
61
+ stageRatio: Val<RequiredTeleBoxConfig["stageRatio"], boolean>;
62
+ stageStyle: Val<RequiredTeleBoxConfig["stageStyle"], boolean>;
63
+ bodyStyle: Val<RequiredTeleBoxConfig["bodyStyle"], boolean>;
62
64
  };
63
65
 
64
66
  type PropsValConfig = {
@@ -69,6 +71,8 @@ type PropsValConfig = {
69
71
  readonly: RequiredTeleBoxConfig["readonly$"];
70
72
  rootRect: RequiredTeleBoxConfig["rootRect$"];
71
73
  managerStageRect: RequiredTeleBoxConfig["managerStageRect$"];
74
+ defaultBoxStageStyle: RequiredTeleBoxConfig["defaultBoxStageStyle$"];
75
+ defaultBoxBodyStyle: RequiredTeleBoxConfig["defaultBoxBodyStyle$"];
72
76
  collectorRect: RequiredTeleBoxConfig["collectorRect$"];
73
77
  };
74
78
 
@@ -76,11 +80,6 @@ type MyReadonlyValConfig = {
76
80
  zIndex: Val<RequiredTeleBoxConfig["zIndex"], boolean>;
77
81
  focus: Val<RequiredTeleBoxConfig["focus"], boolean>;
78
82
 
79
- $userContent: Val<TeleBoxConfig["content"], boolean>;
80
- $userStage: Val<TeleBoxConfig["content"], boolean>;
81
- $userFooter: Val<TeleBoxConfig["footer"], boolean>;
82
- $userStyles: Val<TeleBoxConfig["styles"], boolean>;
83
-
84
83
  minSize: Val<TeleBoxSize, boolean>;
85
84
  intrinsicSize: Val<TeleBoxSize, boolean>;
86
85
  intrinsicCoord: Val<TeleBoxCoord, boolean>;
@@ -88,10 +87,8 @@ type MyReadonlyValConfig = {
88
87
  pxIntrinsicSize: ReadonlyVal<TeleBoxSize, boolean>;
89
88
  pxIntrinsicCoord: ReadonlyVal<TeleBoxCoord, boolean>;
90
89
  state: ReadonlyVal<TeleBoxState, boolean>;
91
- highlightStage: ReadonlyVal<boolean, boolean>;
92
- boxHighlightStage: Val<boolean | null, boolean>;
93
- contentRect: Val<TeleBoxRect>;
94
- contentStageRect: ReadonlyVal<TeleBoxRect>;
90
+ bodyRect: Val<TeleBoxRect>;
91
+ stageRect: ReadonlyVal<TeleBoxRect>;
95
92
  };
96
93
 
97
94
  type CombinedValEnhancedResult = ReadonlyValEnhancedResult<
@@ -115,7 +112,7 @@ export class TeleBox {
115
112
  y = 0.1,
116
113
  resizable = true,
117
114
  draggable = true,
118
- ratio = -1,
115
+ boxRatio = -1,
119
116
  focus = false,
120
117
  zIndex = 100,
121
118
  stageRatio = null,
@@ -124,18 +121,21 @@ export class TeleBox {
124
121
  stage,
125
122
  footer,
126
123
  styles,
127
- highlightStage = null,
124
+ userStyles,
125
+ bodyStyle = null,
126
+ stageStyle = null,
128
127
  darkMode$,
129
128
  fence$,
130
129
  minimized$,
131
130
  maximized$,
132
131
  readonly$,
133
- root$,
132
+ root,
134
133
  rootRect$,
135
134
  managerStageRect$,
136
135
  managerStageRatio$,
136
+ defaultBoxBodyStyle$,
137
+ defaultBoxStageStyle$,
137
138
  collectorRect$,
138
- managerHighlightStage$,
139
139
  }: TeleBoxConfig) {
140
140
  this._sideEffect = new SideEffectManager();
141
141
 
@@ -149,13 +149,9 @@ export class TeleBox {
149
149
  const visible$ = new Val(visible);
150
150
  const resizable$ = new Val(resizable);
151
151
  const draggable$ = new Val(draggable);
152
- const ratio$ = new Val(ratio);
152
+ const boxRatio$ = new Val(boxRatio);
153
153
  const zIndex$ = new Val(zIndex);
154
154
  const focus$ = new Val(focus);
155
- const $userContent$ = new Val(content);
156
- const $userStage$ = new Val(stage);
157
- const $userFooter$ = new Val(footer);
158
- const $userStyles$ = new Val(styles);
159
155
 
160
156
  const state$ = combine(
161
157
  [minimized$, maximized$],
@@ -216,46 +212,29 @@ export class TeleBox {
216
212
  const pxIntrinsicCoord$ = combine(
217
213
  [intrinsicCoord$, managerStageRect$],
218
214
  ([intrinsicCoord, managerStageRect]) => ({
219
- x:
220
- intrinsicCoord.x * managerStageRect.width +
221
- managerStageRect.x,
222
- y:
223
- intrinsicCoord.y * managerStageRect.height +
224
- managerStageRect.y,
215
+ x: intrinsicCoord.x * managerStageRect.width,
216
+ y: intrinsicCoord.y * managerStageRect.height,
225
217
  }),
226
218
  { compare: shallowequal }
227
219
  );
228
220
 
229
- const boxHighlightStage$ = new Val<boolean | null, boolean>(
230
- highlightStage
231
- );
232
-
233
- const highlightStage$ = combine(
234
- [boxHighlightStage$, managerHighlightStage$],
235
- ([boxHighlightStage, managerHighlightStage]) =>
236
- boxHighlightStage ?? managerHighlightStage
237
- );
221
+ const bodyStyle$ = new Val<string | null>(bodyStyle);
222
+ const stageStyle$ = new Val<string | null>(stageStyle);
238
223
 
239
224
  const contentRoot$ = new Val<HTMLElement | null>(null);
240
-
241
- const contentRect$ = new Val<TeleBoxRect>(rootRect$.value, {
225
+ const bodyRect$ = new Val<TeleBoxRect>(managerStageRect$.value, {
242
226
  compare: shallowequal,
243
227
  });
244
-
245
228
  const stageRatio$ = new Val(stageRatio);
246
-
247
- const teleStage = new TeleStage({
248
- namespace,
249
- root$: contentRoot$,
250
- rootRect$: contentRect$,
251
- ratio$: combine(
252
- [stageRatio$, managerStageRatio$],
253
- ([stageRatio, managerStageRatio]) =>
254
- stageRatio ?? managerStageRatio
255
- ),
256
- highlightStage$,
257
- });
258
- this._sideEffect.addDisposer(() => teleStage.destroy());
229
+ const finalStageRatio$ = combine(
230
+ [stageRatio$, managerStageRatio$],
231
+ ([stageRatio, managerStageRatio]) => stageRatio ?? managerStageRatio
232
+ );
233
+ const stageRect$ = combine(
234
+ [bodyRect$, finalStageRatio$],
235
+ calcStageRect,
236
+ { compare: shallowequal }
237
+ );
259
238
 
260
239
  const propsValConfig: PropsValConfig = {
261
240
  darkMode: darkMode$,
@@ -265,6 +244,8 @@ export class TeleBox {
265
244
  readonly: readonly$,
266
245
  rootRect: rootRect$,
267
246
  managerStageRect: managerStageRect$,
247
+ defaultBoxBodyStyle: defaultBoxBodyStyle$,
248
+ defaultBoxStageStyle: defaultBoxStageStyle$,
268
249
  collectorRect: collectorRect$,
269
250
  };
270
251
 
@@ -274,11 +255,6 @@ export class TeleBox {
274
255
  zIndex: zIndex$,
275
256
  focus: focus$,
276
257
 
277
- $userContent: $userContent$,
278
- $userStage: $userStage$,
279
- $userFooter: $userFooter$,
280
- $userStyles: $userStyles$,
281
-
282
258
  state: state$,
283
259
  minSize: minSize$,
284
260
  pxMinSize: pxMinSize$,
@@ -286,10 +262,8 @@ export class TeleBox {
286
262
  intrinsicCoord: intrinsicCoord$,
287
263
  pxIntrinsicSize: pxIntrinsicSize$,
288
264
  pxIntrinsicCoord: pxIntrinsicCoord$,
289
- highlightStage: highlightStage$,
290
- boxHighlightStage: boxHighlightStage$,
291
- contentRect: contentRect$,
292
- contentStageRect: teleStage.stageRect$,
265
+ bodyRect: bodyRect$,
266
+ stageRect: stageRect$,
293
267
  };
294
268
 
295
269
  withReadonlyValueEnhancer(this, myReadonlyValConfig, valManager);
@@ -299,8 +273,10 @@ export class TeleBox {
299
273
  visible: visible$,
300
274
  resizable: resizable$,
301
275
  draggable: draggable$,
302
- ratio: ratio$,
276
+ boxRatio: boxRatio$,
303
277
  stageRatio: stageRatio$,
278
+ bodyStyle: bodyStyle$,
279
+ stageStyle: stageStyle$,
304
280
  };
305
281
 
306
282
  withValueEnhancer(this, valConfig, valManager);
@@ -317,14 +293,13 @@ export class TeleBox {
317
293
  });
318
294
 
319
295
  this._sideEffect.addDisposer(
320
- ratio$.subscribe((ratio) => {
321
- if (ratio > 0) {
296
+ boxRatio$.subscribe((boxRatio) => {
297
+ if (boxRatio > 0) {
322
298
  this.transform(
323
299
  pxIntrinsicCoord$.value.x,
324
300
  pxIntrinsicCoord$.value.y,
325
301
  pxIntrinsicSize$.value.width,
326
- pxIntrinsicSize$.value.height,
327
- true
302
+ pxIntrinsicSize$.value.height
328
303
  );
329
304
  }
330
305
  })
@@ -335,15 +310,20 @@ export class TeleBox {
335
310
  if (fence) {
336
311
  this.move(
337
312
  pxIntrinsicCoord$.value.x,
338
- pxIntrinsicCoord$.value.y,
339
- true
313
+ pxIntrinsicCoord$.value.y
340
314
  );
341
315
  }
342
316
  })
343
317
  );
344
318
 
345
- this.$box = this.render();
319
+ this.$box = this._render();
346
320
  contentRoot$.setValue(this.$content.parentElement);
321
+ content && this.mountContent(content);
322
+ stage && this.mountStage(stage);
323
+ footer && this.mountFooter(footer);
324
+ styles && this.mountStyles(styles);
325
+ userStyles && this.mountUserStyles(userStyles);
326
+ root.appendChild(this.$box);
347
327
 
348
328
  const watchValEvent = <E extends TeleBoxEvent>(
349
329
  val: ReadonlyVal<TeleBoxEventConfig[E], boolean>,
@@ -380,13 +360,6 @@ export class TeleBox {
380
360
  );
381
361
  }
382
362
  }),
383
- root$.subscribe((root) => {
384
- if (root) {
385
- root.appendChild(this.$box);
386
- } else if (this.$box.parentNode) {
387
- this.$box.remove();
388
- }
389
- }),
390
363
  ]);
391
364
  }
392
365
 
@@ -492,34 +465,25 @@ export class TeleBox {
492
465
  const pxIntrinsicSize = this.pxIntrinsicSize;
493
466
 
494
467
  if (this.fence) {
495
- safeX = clamp(
496
- x,
497
- managerStageRect.x,
498
- managerStageRect.x +
499
- managerStageRect.width -
500
- pxIntrinsicSize.width
501
- );
468
+ safeX = clamp(x, 0, managerStageRect.width - pxIntrinsicSize.width);
502
469
  safeY = clamp(
503
470
  y,
504
- managerStageRect.y,
505
- managerStageRect.y +
506
- managerStageRect.height -
507
- pxIntrinsicSize.height
471
+ 0,
472
+ managerStageRect.height - pxIntrinsicSize.height
508
473
  );
509
474
  } else {
510
- const rootRect = this.rootRect;
511
475
  safeX = clamp(
512
476
  x,
513
- 0 - pxIntrinsicSize.width + 20,
514
- 0 + rootRect.width - 20
477
+ -(pxIntrinsicSize.width - 120),
478
+ 0 + managerStageRect.width - 20
515
479
  );
516
- safeY = clamp(y, 0, 0 + rootRect.height - 20);
480
+ safeY = clamp(y, 0, 0 + managerStageRect.height - 20);
517
481
  }
518
482
 
519
483
  this._intrinsicCoord$.setValue(
520
484
  {
521
- x: (safeX - managerStageRect.x) / managerStageRect.width,
522
- y: (safeY - managerStageRect.y) / managerStageRect.height,
485
+ x: safeX / managerStageRect.width,
486
+ y: safeY / managerStageRect.height,
523
487
  },
524
488
  skipUpdate
525
489
  );
@@ -542,21 +506,20 @@ export class TeleBox {
542
506
  skipUpdate = false
543
507
  ): void {
544
508
  const managerStageRect = this.managerStageRect;
545
- const rootRect = this.rootRect;
546
509
 
547
510
  width = Math.max(width, this.pxMinSize.width);
548
511
  height = Math.max(height, this.pxMinSize.height);
549
512
 
550
- if (this.ratio > 0) {
551
- const newHeight = this.ratio * width;
513
+ if (this.boxRatio > 0) {
514
+ const newHeight = this.boxRatio * width;
552
515
  if (y !== this.pxIntrinsicCoord.y) {
553
516
  y -= newHeight - height;
554
517
  }
555
518
  height = newHeight;
556
519
  }
557
520
 
558
- if (y < rootRect.y) {
559
- y = rootRect.y;
521
+ if (y < 0) {
522
+ y = 0;
560
523
  height = this.pxIntrinsicSize.height;
561
524
  }
562
525
 
@@ -570,85 +533,109 @@ export class TeleBox {
570
533
  );
571
534
  }
572
535
 
573
- /**
574
- * Mount dom to box content.
575
- */
536
+ private $authorContent?: HTMLElement;
537
+
538
+ /** Mount dom to box content. */
576
539
  public mountContent(content: HTMLElement): void {
577
- this._$userContent$.setValue(content);
540
+ this.$authorContent?.remove();
541
+ this.$authorContent = content;
542
+ this.$content.appendChild(content);
578
543
  }
579
544
 
580
- /**
581
- * Unmount content from the box.
582
- */
545
+ /** Unmount content from the box. */
583
546
  public unmountContent(): void {
584
- this._$userContent$.setValue(undefined);
547
+ if (this.$authorContent) {
548
+ this.$authorContent.remove();
549
+ this.$authorContent = undefined;
550
+ }
585
551
  }
586
552
 
553
+ private $authorStage?: HTMLElement;
554
+
555
+ /** Mount dom to box stage. */
587
556
  public mountStage(stage: HTMLElement): void {
588
- this._$userStage$.setValue(stage);
557
+ this.$authorStage?.remove();
558
+ this.$authorStage = stage;
559
+ if (!this.$stage) {
560
+ this.$stage = this._renderStage();
561
+ }
562
+ this.$stage.appendChild(stage);
563
+ if (!this.$stage.parentElement) {
564
+ this.$body.appendChild(this.$stage);
565
+ }
589
566
  }
590
567
 
591
- /**
592
- * Unmount content from the box.
593
- */
568
+ /** Unmount content from the box. */
594
569
  public unmountStage(): void {
595
- this._$userStage$.setValue(undefined);
570
+ if (this.$authorStage) {
571
+ this.$authorStage.remove();
572
+ this.$authorStage = undefined;
573
+ }
574
+ this.$stage?.remove();
596
575
  }
597
576
 
598
- /**
599
- * Mount dom to box Footer.
600
- */
577
+ private $authorFooter?: HTMLElement;
578
+
579
+ /** Mount dom to box Footer. */
601
580
  public mountFooter(footer: HTMLElement): void {
602
- this._$userFooter$.setValue(footer);
581
+ this.$authorFooter?.remove();
582
+ this.$authorFooter = footer;
583
+ this.$footer.appendChild(footer);
603
584
  }
604
585
 
605
- /**
606
- * Unmount Footer from the box.
607
- */
586
+ /** Unmount Footer from the box. */
608
587
  public unmountFooter(): void {
609
- this._$userFooter$.setValue(undefined);
588
+ if (this.$authorFooter) {
589
+ this.$authorFooter.remove();
590
+ this.$authorFooter = undefined;
591
+ }
610
592
  }
611
593
 
612
- public getUserStyles(): HTMLStyleElement | undefined {
613
- return this.$userStyles;
594
+ /** Mount styles for box content */
595
+ public mountStyles(styles: string): void {
596
+ this.$styles.textContent = styles;
614
597
  }
615
598
 
616
- public mountStyles(styles: string | HTMLStyleElement): void {
617
- let $styles: HTMLStyleElement;
618
- if (typeof styles === "string") {
619
- $styles = document.createElement("style");
620
- $styles.textContent = styles;
621
- } else {
622
- $styles = styles;
623
- }
624
- this._$userStyles$.setValue($styles);
599
+ /** Umount styles for box content */
600
+ public unmountStyles(): void {
601
+ this.$styles.textContent = "";
625
602
  }
626
603
 
627
- public unmountStyles(): void {
628
- this._$userStyles$.setValue(undefined);
604
+ /** Mount user styles for box content */
605
+ public mountUserStyles(styles: string): void {
606
+ this.$userStyles.textContent = styles;
629
607
  }
630
608
 
631
- /** Show stage frame and grey-out the non-stage area. Inherit setting from manager if null. */
632
- public setHighlightStage(highlightStage: boolean | null): void {
633
- this._boxHighlightStage$.setValue(highlightStage);
609
+ /** Umount user styles for box content */
610
+ public unmountUserStyles(): void {
611
+ this.$userStyles.textContent = "";
634
612
  }
635
613
 
636
614
  /** DOM of the box */
637
615
  public $box: HTMLElement;
638
616
 
639
- /** DOM of the box content */
617
+ /** DOM of the box body */
618
+ public $body!: HTMLElement;
619
+
620
+ /** DOM of the box content container inside box body */
640
621
  public $content!: HTMLElement;
641
622
 
642
- /** DOM of the box stage area */
623
+ /** DOM of the box stage area inside box body */
643
624
  public $stage?: HTMLElement;
644
625
 
645
- /** DOM of the box title bar */
626
+ /** DOM of custom box content styles */
627
+ public $styles!: HTMLStyleElement;
628
+
629
+ /** DOM of end user custom box content styles */
630
+ public $userStyles!: HTMLStyleElement;
631
+
632
+ /** DOM of the box title bar container */
646
633
  public $titleBar!: HTMLElement;
647
634
 
648
- /** DOM of the box footer */
635
+ /** DOM of the box footer container */
649
636
  public $footer!: HTMLElement;
650
637
 
651
- protected render(): HTMLElement {
638
+ private _render(): HTMLElement {
652
639
  if (this.$box) {
653
640
  return this.$box;
654
641
  }
@@ -736,6 +723,8 @@ export class TeleBox {
736
723
  this._pxIntrinsicSize$,
737
724
  this._pxIntrinsicCoord$,
738
725
  this._collectorRect$,
726
+ this._rootRect$,
727
+ this._managerStageRect$,
739
728
  ],
740
729
  ([
741
730
  maximized,
@@ -743,28 +732,30 @@ export class TeleBox {
743
732
  pxIntrinsicSize,
744
733
  pxIntrinsicCoord,
745
734
  collectorRect,
735
+ rootRect,
736
+ managerStageRect,
746
737
  ]) => {
747
738
  const styles: {
748
739
  x: number;
749
740
  y: number;
750
- width: string;
751
- height: string;
741
+ width: number;
742
+ height: number;
752
743
  scaleX: number;
753
744
  scaleY: number;
754
745
  } = maximized
755
746
  ? {
756
- x: 0,
757
- y: 0,
758
- width: "100%",
759
- height: "100%",
747
+ x: -managerStageRect.x,
748
+ y: -managerStageRect.y,
749
+ width: rootRect.width,
750
+ height: rootRect.height,
760
751
  scaleX: 1,
761
752
  scaleY: 1,
762
753
  }
763
754
  : {
764
755
  x: pxIntrinsicCoord.x,
765
756
  y: pxIntrinsicCoord.y,
766
- width: pxIntrinsicSize.width + "px",
767
- height: pxIntrinsicSize.height + "px",
757
+ width: pxIntrinsicSize.width,
758
+ height: pxIntrinsicSize.height,
768
759
  scaleX: 1,
769
760
  scaleY: 1,
770
761
  };
@@ -775,11 +766,13 @@ export class TeleBox {
775
766
  styles.x =
776
767
  collectorRect.x -
777
768
  boxWidth / 2 +
778
- collectorRect.width / 2;
769
+ collectorRect.width / 2 -
770
+ managerStageRect.x;
779
771
  styles.y =
780
772
  collectorRect.y -
781
773
  boxHeight / 2 +
782
- collectorRect.height / 2;
774
+ collectorRect.height / 2 -
775
+ managerStageRect.y;
783
776
  styles.scaleX = collectorRect.width / boxWidth;
784
777
  styles.scaleY = collectorRect.height / boxHeight;
785
778
  }
@@ -789,8 +782,8 @@ export class TeleBox {
789
782
  );
790
783
 
791
784
  const boxStyles = boxStyles$.value;
792
- this.$box.style.width = boxStyles.width;
793
- this.$box.style.height = boxStyles.height;
785
+ this.$box.style.width = boxStyles.width + "px";
786
+ this.$box.style.height = boxStyles.height + "px";
794
787
  // Add 10px offset on first frame
795
788
  // which creates a subtle moving effect
796
789
  this.$box.style.transform = `translate(${boxStyles.x - 10}px,${
@@ -812,17 +805,45 @@ export class TeleBox {
812
805
  $titleBar.appendChild(this.titleBar.render());
813
806
  this.$titleBar = $titleBar;
814
807
 
815
- const $contentWrap = document.createElement("div");
816
- $contentWrap.className = this.wrapClassName("content-wrap");
808
+ const $body = document.createElement("div");
809
+ $body.className = this.wrapClassName("content-wrap");
810
+ this.$body = $body;
811
+
812
+ const $styles = document.createElement("style");
813
+ this.$styles = $styles;
814
+ $body.appendChild($styles);
815
+
816
+ const $userStyles = document.createElement("style");
817
+ this.$userStyles = $userStyles;
818
+ $body.appendChild($userStyles);
817
819
 
818
820
  const $content = document.createElement("div");
819
821
  $content.className =
820
822
  this.wrapClassName("content") + " tele-fancy-scrollbar";
821
823
  this.$content = $content;
824
+ this._sideEffect.addDisposer(
825
+ combine(
826
+ [this._bodyStyle$, this._defaultBoxBodyStyle$],
827
+ ([bodyStyle, defaultBoxBodyStyle]) =>
828
+ bodyStyle ?? defaultBoxBodyStyle
829
+ ).subscribe((style) => ($content.style.cssText = style || ""))
830
+ );
831
+
832
+ $body.appendChild($content);
833
+
834
+ const $footer = document.createElement("div");
835
+ $footer.className = this.wrapClassName("footer-wrap");
836
+ this.$footer = $footer;
822
837
 
823
- const updateContentRect = (): void => {
824
- const rect = $content.getBoundingClientRect();
825
- this._contentRect$.setValue({
838
+ $boxMain.appendChild($titleBar);
839
+ $boxMain.appendChild($body);
840
+ $boxMain.appendChild($footer);
841
+
842
+ this._renderResizeHandlers();
843
+
844
+ const updateBodyRect = (): void => {
845
+ const rect = $body.getBoundingClientRect();
846
+ this._bodyRect$.setValue({
826
847
  x: 0,
827
848
  y: 0,
828
849
  width: rect.width,
@@ -832,10 +853,10 @@ export class TeleBox {
832
853
  this._sideEffect.add(() => {
833
854
  const observer = new ResizeObserver(() => {
834
855
  if (!this.minimized) {
835
- updateContentRect();
856
+ updateBodyRect();
836
857
  }
837
858
  });
838
- observer.observe($content);
859
+ observer.observe($body);
839
860
  return () => observer.disconnect();
840
861
  });
841
862
  this._sideEffect.addDisposer(
@@ -843,7 +864,7 @@ export class TeleBox {
843
864
  // correct content size when restoring from minimized
844
865
  if (!minimized) {
845
866
  this._sideEffect.setTimeout(
846
- updateContentRect,
867
+ updateBodyRect,
847
868
  400,
848
869
  "minimized-content-rect-fix"
849
870
  );
@@ -851,100 +872,43 @@ export class TeleBox {
851
872
  })
852
873
  );
853
874
 
854
- this._sideEffect.add(() => {
855
- let last$userStyles: HTMLStyleElement | undefined;
856
- return this._$userStyles$.subscribe(($userStyles) => {
857
- if (last$userStyles) {
858
- last$userStyles.remove();
859
- }
860
- last$userStyles = $userStyles;
861
- if ($userStyles) {
862
- $contentWrap.appendChild($userStyles);
863
- }
864
- });
865
- });
866
-
867
- this._sideEffect.add(() => {
868
- let last$userContent: HTMLElement | undefined;
869
- return this._$userContent$.subscribe(($userContent) => {
870
- if (last$userContent) {
871
- last$userContent.remove();
872
- }
873
- last$userContent = $userContent;
874
- if ($userContent) {
875
- $content.appendChild($userContent);
876
- }
877
- });
878
- });
879
-
880
- this._sideEffect.add(() => {
881
- let last$userStage: HTMLElement | undefined;
882
- return this._$userStage$.subscribe(($userStage) => {
883
- if (last$userStage) {
884
- last$userStage.remove();
885
- }
886
- last$userStage = $userStage;
887
- if ($userStage) {
888
- if (!this.$stage) {
889
- const $stage = document.createElement("div");
890
- this.$stage = $stage;
891
- $stage.className = this.wrapClassName("content-stage");
892
- this._sideEffect.addDisposer(
893
- this._contentStageRect$.subscribe((rect) => {
894
- $stage.style.top = rect.y + "px";
895
- $stage.style.left = rect.x + "px";
896
- $stage.style.width = rect.width + "px";
897
- $stage.style.height = rect.height + "px";
898
- }),
899
- "content-stage-rect"
900
- );
901
- $content.appendChild($stage);
902
- }
903
- if (!this.$stage.parentElement) {
904
- $content.appendChild(this.$stage);
905
- }
906
- this.$stage.appendChild($userStage);
907
- } else if (this.$stage?.parentElement) {
908
- this.$stage.remove();
909
- }
910
- });
911
- });
912
-
913
- $contentWrap.appendChild($content);
914
-
915
- const $footer = document.createElement("div");
916
- $footer.className = this.wrapClassName("footer-wrap");
917
- this.$footer = $footer;
918
-
919
- this._sideEffect.add(() => {
920
- let last$userFooter: HTMLElement | undefined;
921
- return this._$userFooter$.subscribe(($userFooter) => {
922
- if (last$userFooter) {
923
- last$userFooter.remove();
924
- }
925
- last$userFooter = $userFooter;
926
- if ($userFooter) {
927
- $footer.appendChild($userFooter);
928
- }
929
- });
930
- });
931
-
932
- $boxMain.appendChild($titleBar);
933
- $boxMain.appendChild($contentWrap);
934
- $boxMain.appendChild($footer);
875
+ return this.$box;
876
+ }
935
877
 
936
- this._renderResizeHandlers();
878
+ private _renderStage(): HTMLDivElement {
879
+ const $stage = document.createElement("div");
937
880
 
938
- return this.$box;
881
+ $stage.className = this.wrapClassName("content-stage");
882
+ const updateStageRect = (stageRect: TeleBoxRect): void => {
883
+ $stage.style.top = stageRect.y + "px";
884
+ $stage.style.left = stageRect.x + "px";
885
+ $stage.style.width = stageRect.width + "px";
886
+ $stage.style.height = stageRect.height + "px";
887
+ };
888
+ this._sideEffect.addDisposer(
889
+ [
890
+ combine(
891
+ [this._stageStyle$, this._defaultBoxStageStyle$],
892
+ ([stageStyle, defaultBoxStageStyle]) =>
893
+ stageStyle ?? defaultBoxStageStyle
894
+ ).subscribe((styles) => {
895
+ $stage.style.cssText = styles || "";
896
+ updateStageRect(this._stageRect$.value);
897
+ }),
898
+ this._stageRect$.subscribe(updateStageRect),
899
+ ],
900
+ "content-stage-styles"
901
+ );
902
+ return $stage;
939
903
  }
940
904
 
941
- protected _handleTrackStart?: (ev: MouseEvent | TouchEvent) => void;
905
+ private _handleTrackStart?: (ev: MouseEvent | TouchEvent) => void;
942
906
 
943
907
  public handleTrackStart: (ev: MouseEvent | TouchEvent) => void = (ev) => {
944
908
  return this._handleTrackStart?.(ev);
945
909
  };
946
910
 
947
- protected _renderResizeHandlers(): void {
911
+ private _renderResizeHandlers(): void {
948
912
  const $resizeHandles = document.createElement("div");
949
913
  $resizeHandles.className = this.wrapClassName("resize-handles");
950
914
 
@@ -985,8 +949,8 @@ export class TeleBox {
985
949
  preventEvent(ev);
986
950
 
987
951
  let { pageX, pageY } = flattenEvent(ev);
988
- if (pageY < this.rootRect.y) {
989
- pageY = this.rootRect.y;
952
+ if (pageY < 0) {
953
+ pageY = 0;
990
954
  }
991
955
 
992
956
  const offsetX = pageX - trackStartPageX;
@@ -1198,13 +1162,14 @@ export type ReadonlyTeleBox = Pick<
1198
1162
  | "unmountStage"
1199
1163
  | "mountStyles"
1200
1164
  | "unmountStyles"
1201
- | "setStageRatio"
1165
+ | "setTitle"
1202
1166
  | "setDraggable"
1203
1167
  | "setResizable"
1204
- | "setHighlightStage"
1205
- | "setTitle"
1206
- | "setRatio"
1207
1168
  | "setVisible"
1169
+ | "setBoxRatio"
1170
+ | "setStageRatio"
1171
+ | "setStageStyle"
1172
+ | "setBodyStyle"
1208
1173
  | "handleTrackStart"
1209
1174
  | "onValChanged"
1210
1175
  >;