@netless/telebox-insider 1.0.0-alpha.16 → 1.0.0-alpha.19

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
+ contentStageRatio: Val<number | null>;
62
+ contentStageStyle: Val<string | null>;
63
+ contentStyle: Val<string | null>;
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
+ managerStageStyle: RequiredTeleBoxConfig["managerStageStyle$"];
75
+ managerContainerStyle: RequiredTeleBoxConfig["managerContainerStyle$"];
72
76
  collectorRect: RequiredTeleBoxConfig["collectorRect$"];
73
77
  };
74
78
 
@@ -77,7 +81,7 @@ type MyReadonlyValConfig = {
77
81
  focus: Val<RequiredTeleBoxConfig["focus"], boolean>;
78
82
 
79
83
  $userContent: Val<TeleBoxConfig["content"], boolean>;
80
- $userStage: Val<TeleBoxConfig["content"], boolean>;
84
+ $userStage: Val<TeleBoxConfig["stage"], boolean>;
81
85
  $userFooter: Val<TeleBoxConfig["footer"], boolean>;
82
86
  $userStyles: Val<TeleBoxConfig["styles"], boolean>;
83
87
 
@@ -88,10 +92,8 @@ type MyReadonlyValConfig = {
88
92
  pxIntrinsicSize: ReadonlyVal<TeleBoxSize, boolean>;
89
93
  pxIntrinsicCoord: ReadonlyVal<TeleBoxCoord, boolean>;
90
94
  state: ReadonlyVal<TeleBoxState, boolean>;
91
- highlightStage: ReadonlyVal<boolean, boolean>;
92
- boxHighlightStage: Val<boolean | null, boolean>;
93
95
  contentRect: Val<TeleBoxRect>;
94
- contentStageRect: ReadonlyVal<TeleBoxRect | null>;
96
+ contentStageRect: ReadonlyVal<TeleBoxRect>;
95
97
  };
96
98
 
97
99
  type CombinedValEnhancedResult = ReadonlyValEnhancedResult<
@@ -115,27 +117,29 @@ export class TeleBox {
115
117
  y = 0.1,
116
118
  resizable = true,
117
119
  draggable = true,
118
- ratio = -1,
120
+ boxRatio = -1,
119
121
  focus = false,
120
122
  zIndex = 100,
121
- stageRatio = null,
123
+ contentStageRatio = null,
122
124
  titleBar,
123
125
  content,
124
126
  stage,
125
127
  footer,
126
128
  styles,
127
- highlightStage = null,
129
+ contentStyle = null,
130
+ contentStageStyle = null,
128
131
  darkMode$,
129
132
  fence$,
130
133
  minimized$,
131
134
  maximized$,
132
135
  readonly$,
133
- root$,
136
+ root,
134
137
  rootRect$,
135
138
  managerStageRect$,
136
139
  managerStageRatio$,
140
+ managerContainerStyle$,
141
+ managerStageStyle$,
137
142
  collectorRect$,
138
- managerHighlightStage$,
139
143
  }: TeleBoxConfig) {
140
144
  this._sideEffect = new SideEffectManager();
141
145
 
@@ -149,7 +153,7 @@ export class TeleBox {
149
153
  const visible$ = new Val(visible);
150
154
  const resizable$ = new Val(resizable);
151
155
  const draggable$ = new Val(draggable);
152
- const ratio$ = new Val(ratio);
156
+ const boxRatio$ = new Val(boxRatio);
153
157
  const zIndex$ = new Val(zIndex);
154
158
  const focus$ = new Val(focus);
155
159
  const $userContent$ = new Val(content);
@@ -216,46 +220,30 @@ export class TeleBox {
216
220
  const pxIntrinsicCoord$ = combine(
217
221
  [intrinsicCoord$, managerStageRect$],
218
222
  ([intrinsicCoord, managerStageRect]) => ({
219
- x:
220
- intrinsicCoord.x * managerStageRect.width +
221
- managerStageRect.x,
222
- y:
223
- intrinsicCoord.y * managerStageRect.height +
224
- managerStageRect.y,
223
+ x: intrinsicCoord.x * managerStageRect.width,
224
+ y: intrinsicCoord.y * managerStageRect.height,
225
225
  }),
226
226
  { compare: shallowequal }
227
227
  );
228
228
 
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
- );
229
+ const contentStyle$ = new Val<string | null>(contentStyle);
230
+ const contentStageStyle$ = new Val<string | null>(contentStageStyle);
238
231
 
239
232
  const contentRoot$ = new Val<HTMLElement | null>(null);
240
-
241
- const contentRect$ = new Val<TeleBoxRect>(rootRect$.value, {
233
+ const contentRect$ = new Val<TeleBoxRect>(managerStageRect$.value, {
242
234
  compare: shallowequal,
243
235
  });
244
-
245
- 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());
236
+ const contentStageRatio$ = new Val(contentStageRatio);
237
+ const finalStageRatio$ = combine(
238
+ [contentStageRatio$, managerStageRatio$],
239
+ ([contentStageRatio, managerStageRatio]) =>
240
+ contentStageRatio ?? managerStageRatio
241
+ );
242
+ const contentStageRect$ = combine(
243
+ [contentRect$, finalStageRatio$],
244
+ calcStageRect,
245
+ { compare: shallowequal }
246
+ );
259
247
 
260
248
  const propsValConfig: PropsValConfig = {
261
249
  darkMode: darkMode$,
@@ -265,6 +253,8 @@ export class TeleBox {
265
253
  readonly: readonly$,
266
254
  rootRect: rootRect$,
267
255
  managerStageRect: managerStageRect$,
256
+ managerContainerStyle: managerContainerStyle$,
257
+ managerStageStyle: managerStageStyle$,
268
258
  collectorRect: collectorRect$,
269
259
  };
270
260
 
@@ -286,10 +276,8 @@ export class TeleBox {
286
276
  intrinsicCoord: intrinsicCoord$,
287
277
  pxIntrinsicSize: pxIntrinsicSize$,
288
278
  pxIntrinsicCoord: pxIntrinsicCoord$,
289
- highlightStage: highlightStage$,
290
- boxHighlightStage: boxHighlightStage$,
291
279
  contentRect: contentRect$,
292
- contentStageRect: teleStage.stageRect$,
280
+ contentStageRect: contentStageRect$,
293
281
  };
294
282
 
295
283
  withReadonlyValueEnhancer(this, myReadonlyValConfig, valManager);
@@ -299,8 +287,10 @@ export class TeleBox {
299
287
  visible: visible$,
300
288
  resizable: resizable$,
301
289
  draggable: draggable$,
302
- ratio: ratio$,
303
- stageRatio: stageRatio$,
290
+ boxRatio: boxRatio$,
291
+ contentStageRatio: contentStageRatio$,
292
+ contentStyle: contentStyle$,
293
+ contentStageStyle: contentStageStyle$,
304
294
  };
305
295
 
306
296
  withValueEnhancer(this, valConfig, valManager);
@@ -317,14 +307,13 @@ export class TeleBox {
317
307
  });
318
308
 
319
309
  this._sideEffect.addDisposer(
320
- ratio$.subscribe((ratio) => {
321
- if (ratio > 0) {
310
+ boxRatio$.subscribe((boxRatio) => {
311
+ if (boxRatio > 0) {
322
312
  this.transform(
323
313
  pxIntrinsicCoord$.value.x,
324
314
  pxIntrinsicCoord$.value.y,
325
315
  pxIntrinsicSize$.value.width,
326
- pxIntrinsicSize$.value.height,
327
- true
316
+ pxIntrinsicSize$.value.height
328
317
  );
329
318
  }
330
319
  })
@@ -335,15 +324,15 @@ export class TeleBox {
335
324
  if (fence) {
336
325
  this.move(
337
326
  pxIntrinsicCoord$.value.x,
338
- pxIntrinsicCoord$.value.y,
339
- true
327
+ pxIntrinsicCoord$.value.y
340
328
  );
341
329
  }
342
330
  })
343
331
  );
344
332
 
345
- this.$box = this.render();
333
+ this.$box = this._render();
346
334
  contentRoot$.setValue(this.$content.parentElement);
335
+ root.appendChild(this.$box);
347
336
 
348
337
  const watchValEvent = <E extends TeleBoxEvent>(
349
338
  val: ReadonlyVal<TeleBoxEventConfig[E], boolean>,
@@ -380,13 +369,6 @@ export class TeleBox {
380
369
  );
381
370
  }
382
371
  }),
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
372
  ]);
391
373
  }
392
374
 
@@ -492,34 +474,25 @@ export class TeleBox {
492
474
  const pxIntrinsicSize = this.pxIntrinsicSize;
493
475
 
494
476
  if (this.fence) {
495
- safeX = clamp(
496
- x,
497
- managerStageRect.x,
498
- managerStageRect.x +
499
- managerStageRect.width -
500
- pxIntrinsicSize.width
501
- );
477
+ safeX = clamp(x, 0, managerStageRect.width - pxIntrinsicSize.width);
502
478
  safeY = clamp(
503
479
  y,
504
- managerStageRect.y,
505
- managerStageRect.y +
506
- managerStageRect.height -
507
- pxIntrinsicSize.height
480
+ 0,
481
+ managerStageRect.height - pxIntrinsicSize.height
508
482
  );
509
483
  } else {
510
- const rootRect = this.rootRect;
511
484
  safeX = clamp(
512
485
  x,
513
- 0 - pxIntrinsicSize.width + 20,
514
- 0 + rootRect.width - 20
486
+ -(pxIntrinsicSize.width - 120),
487
+ 0 + managerStageRect.width - 20
515
488
  );
516
- safeY = clamp(y, 0, 0 + rootRect.height - 20);
489
+ safeY = clamp(y, 0, 0 + managerStageRect.height - 20);
517
490
  }
518
491
 
519
492
  this._intrinsicCoord$.setValue(
520
493
  {
521
- x: (safeX - managerStageRect.x) / managerStageRect.width,
522
- y: (safeY - managerStageRect.y) / managerStageRect.height,
494
+ x: safeX / managerStageRect.width,
495
+ y: safeY / managerStageRect.height,
523
496
  },
524
497
  skipUpdate
525
498
  );
@@ -542,21 +515,20 @@ export class TeleBox {
542
515
  skipUpdate = false
543
516
  ): void {
544
517
  const managerStageRect = this.managerStageRect;
545
- const rootRect = this.rootRect;
546
518
 
547
519
  width = Math.max(width, this.pxMinSize.width);
548
520
  height = Math.max(height, this.pxMinSize.height);
549
521
 
550
- if (this.ratio > 0) {
551
- const newHeight = this.ratio * width;
522
+ if (this.boxRatio > 0) {
523
+ const newHeight = this.boxRatio * width;
552
524
  if (y !== this.pxIntrinsicCoord.y) {
553
525
  y -= newHeight - height;
554
526
  }
555
527
  height = newHeight;
556
528
  }
557
529
 
558
- if (y < rootRect.y) {
559
- y = rootRect.y;
530
+ if (y < 0) {
531
+ y = 0;
560
532
  height = this.pxIntrinsicSize.height;
561
533
  }
562
534
 
@@ -628,11 +600,6 @@ export class TeleBox {
628
600
  this._$userStyles$.setValue(undefined);
629
601
  }
630
602
 
631
- /** Show stage frame and grey-out the non-stage area. Inherit setting from manager if null. */
632
- setHighlightStage(highlightStage: boolean | null): void {
633
- this._boxHighlightStage$.setValue(highlightStage);
634
- }
635
-
636
603
  /** DOM of the box */
637
604
  public $box: HTMLElement;
638
605
 
@@ -648,7 +615,7 @@ export class TeleBox {
648
615
  /** DOM of the box footer */
649
616
  public $footer!: HTMLElement;
650
617
 
651
- protected render(): HTMLElement {
618
+ private _render(): HTMLElement {
652
619
  if (this.$box) {
653
620
  return this.$box;
654
621
  }
@@ -736,6 +703,8 @@ export class TeleBox {
736
703
  this._pxIntrinsicSize$,
737
704
  this._pxIntrinsicCoord$,
738
705
  this._collectorRect$,
706
+ this._rootRect$,
707
+ this._managerStageRect$,
739
708
  ],
740
709
  ([
741
710
  maximized,
@@ -743,28 +712,30 @@ export class TeleBox {
743
712
  pxIntrinsicSize,
744
713
  pxIntrinsicCoord,
745
714
  collectorRect,
715
+ rootRect,
716
+ managerStageRect,
746
717
  ]) => {
747
718
  const styles: {
748
719
  x: number;
749
720
  y: number;
750
- width: string;
751
- height: string;
721
+ width: number;
722
+ height: number;
752
723
  scaleX: number;
753
724
  scaleY: number;
754
725
  } = maximized
755
726
  ? {
756
- x: 0,
757
- y: 0,
758
- width: "100%",
759
- height: "100%",
727
+ x: -managerStageRect.x,
728
+ y: -managerStageRect.y,
729
+ width: rootRect.width,
730
+ height: rootRect.height,
760
731
  scaleX: 1,
761
732
  scaleY: 1,
762
733
  }
763
734
  : {
764
735
  x: pxIntrinsicCoord.x,
765
736
  y: pxIntrinsicCoord.y,
766
- width: pxIntrinsicSize.width + "px",
767
- height: pxIntrinsicSize.height + "px",
737
+ width: pxIntrinsicSize.width,
738
+ height: pxIntrinsicSize.height,
768
739
  scaleX: 1,
769
740
  scaleY: 1,
770
741
  };
@@ -775,11 +746,13 @@ export class TeleBox {
775
746
  styles.x =
776
747
  collectorRect.x -
777
748
  boxWidth / 2 +
778
- collectorRect.width / 2;
749
+ collectorRect.width / 2 -
750
+ managerStageRect.x;
779
751
  styles.y =
780
752
  collectorRect.y -
781
753
  boxHeight / 2 +
782
- collectorRect.height / 2;
754
+ collectorRect.height / 2 -
755
+ managerStageRect.y;
783
756
  styles.scaleX = collectorRect.width / boxWidth;
784
757
  styles.scaleY = collectorRect.height / boxHeight;
785
758
  }
@@ -789,8 +762,8 @@ export class TeleBox {
789
762
  );
790
763
 
791
764
  const boxStyles = boxStyles$.value;
792
- this.$box.style.width = boxStyles.width;
793
- this.$box.style.height = boxStyles.height;
765
+ this.$box.style.width = boxStyles.width + "px";
766
+ this.$box.style.height = boxStyles.height + "px";
794
767
  // Add 10px offset on first frame
795
768
  // which creates a subtle moving effect
796
769
  this.$box.style.transform = `translate(${boxStyles.x - 10}px,${
@@ -819,20 +792,44 @@ export class TeleBox {
819
792
  $content.className =
820
793
  this.wrapClassName("content") + " tele-fancy-scrollbar";
821
794
  this.$content = $content;
795
+ this._sideEffect.addDisposer(
796
+ combine(
797
+ [this._contentStyle$, this._managerContainerStyle$],
798
+ ([contentStyle, managerContainerStyle]) =>
799
+ contentStyle ?? managerContainerStyle
800
+ ).subscribe((style) => ($content.style.cssText = style))
801
+ );
822
802
 
803
+ const updateContentRect = (): void => {
804
+ const rect = $content.getBoundingClientRect();
805
+ this._contentRect$.setValue({
806
+ x: 0,
807
+ y: 0,
808
+ width: rect.width,
809
+ height: rect.height,
810
+ });
811
+ };
823
812
  this._sideEffect.add(() => {
824
813
  const observer = new ResizeObserver(() => {
825
- const rect = $content.getBoundingClientRect();
826
- this._contentRect$.setValue({
827
- x: 0,
828
- y: 0,
829
- width: rect.width,
830
- height: rect.height,
831
- });
814
+ if (!this.minimized) {
815
+ updateContentRect();
816
+ }
832
817
  });
833
818
  observer.observe($content);
834
819
  return () => observer.disconnect();
835
820
  });
821
+ this._sideEffect.addDisposer(
822
+ this._minimized$.reaction((minimized) => {
823
+ // correct content size when restoring from minimized
824
+ if (!minimized) {
825
+ this._sideEffect.setTimeout(
826
+ updateContentRect,
827
+ 400,
828
+ "minimized-content-rect-fix"
829
+ );
830
+ }
831
+ })
832
+ );
836
833
 
837
834
  this._sideEffect.add(() => {
838
835
  let last$userStyles: HTMLStyleElement | undefined;
@@ -869,21 +866,8 @@ export class TeleBox {
869
866
  last$userStage = $userStage;
870
867
  if ($userStage) {
871
868
  if (!this.$stage) {
872
- const $stage = document.createElement("div");
873
- this.$stage = $stage;
874
- $stage.className = this.wrapClassName("content-stage");
875
- this._sideEffect.addDisposer(
876
- this._contentStageRect$.subscribe((rect) => {
877
- if (rect) {
878
- $stage.style.top = rect.y + "px";
879
- $stage.style.left = rect.x + "px";
880
- $stage.style.width = rect.width + "px";
881
- $stage.style.height = rect.height + "px";
882
- }
883
- }),
884
- "content-stage-rect"
885
- );
886
- $content.appendChild($stage);
869
+ this.$stage = this._renderStage();
870
+ $content.appendChild(this.$stage);
887
871
  }
888
872
  if (!this.$stage.parentElement) {
889
873
  $content.appendChild(this.$stage);
@@ -923,13 +907,42 @@ export class TeleBox {
923
907
  return this.$box;
924
908
  }
925
909
 
926
- protected _handleTrackStart?: (ev: MouseEvent | TouchEvent) => void;
910
+ private _renderStage(): HTMLDivElement {
911
+ const $stage = document.createElement("div");
912
+
913
+ $stage.className = this.wrapClassName("content-stage");
914
+ const updateContentStageRect = (
915
+ contentStageRect: TeleBoxRect
916
+ ): void => {
917
+ $stage.style.top = contentStageRect.y + "px";
918
+ $stage.style.left = contentStageRect.x + "px";
919
+ $stage.style.width = contentStageRect.width + "px";
920
+ $stage.style.height = contentStageRect.height + "px";
921
+ };
922
+ this._sideEffect.addDisposer(
923
+ [
924
+ combine(
925
+ [this._contentStageStyle$, this._managerStageStyle$],
926
+ ([contentStageStyle, managerStageStyle]) =>
927
+ contentStageStyle ?? managerStageStyle
928
+ ).subscribe((styles) => {
929
+ $stage.style.cssText = styles;
930
+ updateContentStageRect(this._contentStageRect$.value);
931
+ }),
932
+ this._contentStageRect$.subscribe(updateContentStageRect),
933
+ ],
934
+ "content-stage-styles"
935
+ );
936
+ return $stage;
937
+ }
938
+
939
+ private _handleTrackStart?: (ev: MouseEvent | TouchEvent) => void;
927
940
 
928
941
  public handleTrackStart: (ev: MouseEvent | TouchEvent) => void = (ev) => {
929
942
  return this._handleTrackStart?.(ev);
930
943
  };
931
944
 
932
- protected _renderResizeHandlers(): void {
945
+ private _renderResizeHandlers(): void {
933
946
  const $resizeHandles = document.createElement("div");
934
947
  $resizeHandles.className = this.wrapClassName("resize-handles");
935
948
 
@@ -970,8 +983,8 @@ export class TeleBox {
970
983
  preventEvent(ev);
971
984
 
972
985
  let { pageX, pageY } = flattenEvent(ev);
973
- if (pageY < this.rootRect.y) {
974
- pageY = this.rootRect.y;
986
+ if (pageY < 0) {
987
+ pageY = 0;
975
988
  }
976
989
 
977
990
  const offsetX = pageX - trackStartPageX;
@@ -1183,12 +1196,13 @@ export type ReadonlyTeleBox = Pick<
1183
1196
  | "unmountStage"
1184
1197
  | "mountStyles"
1185
1198
  | "unmountStyles"
1186
- | "setStageRatio"
1199
+ | "setContentStageRatio"
1200
+ | "setContentStageStyle"
1201
+ | "setContentStyle"
1187
1202
  | "setDraggable"
1188
1203
  | "setResizable"
1189
- | "setHighlightStage"
1190
1204
  | "setTitle"
1191
- | "setRatio"
1205
+ | "setBoxRatio"
1192
1206
  | "setVisible"
1193
1207
  | "handleTrackStart"
1194
1208
  | "onValChanged"
@@ -18,7 +18,6 @@
18
18
  display: flex;
19
19
  flex-direction: column;
20
20
  overflow: hidden;
21
- background: #f9f9fc;
22
21
  box-shadow: 0px 4px 10px 0px rgba(47, 65, 146, 0.15);
23
22
  border-radius: 6px;
24
23
  border: 1px solid #e3e3ec;
@@ -44,10 +43,15 @@
44
43
  width: 100%;
45
44
  height: 100%;
46
45
  position: relative;
46
+ background: $color-container-background;
47
47
  }
48
48
 
49
49
  .#{$namespace}-content-stage {
50
50
  position: absolute;
51
+ z-index: 1;
52
+ overflow: hidden;
53
+ background: $color-stage-background;
54
+ box-shadow: $color-stage-shadow;
51
55
  }
52
56
 
53
57
  .#{$namespace}-footer-wrap {
@@ -216,7 +220,15 @@
216
220
 
217
221
  .#{$namespace}-box-main {
218
222
  color: #e9e9e9;
219
- background: #212126;
220
223
  border-color: #43434d;
221
224
  }
225
+
226
+ .#{$namespace}-content {
227
+ background: $color-container-background-dark;
228
+ }
229
+
230
+ .#{$namespace}-content-stage {
231
+ background: $color-stage-background-dark;
232
+ box-shadow: $color-stage-shadow-dark;
233
+ }
222
234
  }
@@ -51,13 +51,13 @@ export interface TeleBoxConfig {
51
51
  /** Able to drag box window Default true. */
52
52
  readonly draggable?: boolean;
53
53
  /** Fixed height/width ratio for box window. No ratio limit if <= 0. Default -1. */
54
- readonly ratio?: number;
54
+ readonly boxRatio?: number;
55
55
  /** Box focused. */
56
56
  readonly focus?: boolean;
57
57
  /** Base z-index for box. */
58
58
  readonly zIndex?: number;
59
- /** Box stage ratio. Follow manager stage ratio if null. Default null. */
60
- readonly stageRatio?: number | null;
59
+ /** Box content stage ratio. Follow manager stage ratio if null. Default null. */
60
+ readonly contentStageRatio?: number | null;
61
61
  /** Classname Prefix. For CSS styling. Default "telebox". */
62
62
  readonly namespace?: string;
63
63
  /** TeleTitleBar Instance. */
@@ -70,8 +70,10 @@ export interface TeleBoxConfig {
70
70
  readonly footer?: HTMLElement;
71
71
  /** Box content styles. */
72
72
  readonly styles?: HTMLStyleElement;
73
- /** Show stage frame and grey-out the non-stage area. Inherit setting from manager if null. Default null. */
74
- readonly highlightStage?: boolean | null;
73
+ /** Custom styles for box content container. Inherit from manager container style if null. Default null. */
74
+ readonly contentStyle?: string | null;
75
+ /** Custom styles for box content stage. Inherit from manager stage style if null. Default null. */
76
+ readonly contentStageStyle?: string | null;
75
77
  /** Actual Box Dark Mode */
76
78
  readonly darkMode$: ReadonlyVal<boolean, boolean>;
77
79
  /** Restrict box to always be within the stage area. Default false. */
@@ -83,17 +85,19 @@ export interface TeleBoxConfig {
83
85
  /** Is box readonly */
84
86
  readonly readonly$: ReadonlyVal<boolean, boolean>;
85
87
  /** Root element to mount boxes */
86
- readonly root$: ReadonlyVal<HTMLElement | null>;
88
+ readonly root: HTMLElement;
87
89
  /** Position and dimension of root element */
88
90
  readonly rootRect$: ReadonlyVal<TeleBoxRect>;
89
91
  /** Position and dimension of stage area */
90
92
  readonly managerStageRect$: ReadonlyVal<TeleBoxRect>;
91
93
  /** Stage area height/with ratio. No ratio if <= 0. */
92
94
  readonly managerStageRatio$: ReadonlyVal<number, boolean>;
95
+ /** Custom container styles from manager */
96
+ readonly managerContainerStyle$: ReadonlyVal<string>;
97
+ /** Custom stage styles from manager */
98
+ readonly managerStageStyle$: ReadonlyVal<string>;
93
99
  /** Position and dimension of collector */
94
100
  readonly collectorRect$: ReadonlyVal<TeleBoxRect | undefined>;
95
- /** highlight stage settings from manager */
96
- readonly managerHighlightStage$: ReadonlyVal<boolean>;
97
101
  }
98
102
 
99
103
  type CheckTeleBoxConfig<T extends Record<`${TELE_BOX_EVENT}`, any>> = T;
@@ -0,0 +1,32 @@
1
+ import type { TeleBoxRect } from "./typings";
2
+
3
+ export function calcStageRect([rootRect, ratio]: [
4
+ TeleBoxRect,
5
+ number
6
+ ]): TeleBoxRect {
7
+ if (ratio <= 0 || rootRect.width <= 0 || rootRect.height <= 0) {
8
+ return rootRect;
9
+ }
10
+
11
+ const preferredHeight = rootRect.width * ratio;
12
+ if (preferredHeight === rootRect.height) {
13
+ return rootRect;
14
+ }
15
+
16
+ if (preferredHeight < rootRect.height) {
17
+ return {
18
+ x: 0,
19
+ y: (rootRect.height - preferredHeight) / 2,
20
+ width: rootRect.width,
21
+ height: preferredHeight,
22
+ };
23
+ }
24
+
25
+ const preferredWidth = rootRect.height / ratio;
26
+ return {
27
+ x: (rootRect.width - preferredWidth) / 2,
28
+ y: 0,
29
+ width: preferredWidth,
30
+ height: rootRect.height,
31
+ };
32
+ }