@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.
- package/dist/TeleBox/index.d.ts +40 -38
- package/dist/TeleBox/typings.d.ts +14 -8
- package/dist/TeleBox/utils.d.ts +5 -0
- package/dist/TeleBoxManager/index.d.ts +8 -2
- package/dist/TeleBoxManager/typings.d.ts +10 -4
- package/dist/style.css +1 -1
- package/dist/telebox-insider.cjs.js +1 -1
- package/dist/telebox-insider.cjs.js.map +1 -1
- package/dist/telebox-insider.es.js +1 -1
- package/dist/telebox-insider.es.js.map +1 -1
- package/package.json +67 -67
- package/src/TeleBox/index.ts +216 -251
- package/src/TeleBox/style.scss +14 -2
- package/src/TeleBox/typings.ts +14 -8
- package/src/TeleBox/utils.ts +32 -0
- package/src/TeleBoxManager/index.ts +85 -36
- package/src/TeleBoxManager/style.scss +39 -0
- package/src/TeleBoxManager/typings.ts +10 -4
- package/src/scss/variables.scss +9 -0
- package/dist/TeleStage/index.d.ts +0 -21
- package/src/TeleStage/index.ts +0 -174
- package/src/TeleStage/style.scss +0 -49
package/src/TeleBox/style.scss
CHANGED
|
@@ -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
|
}
|
package/src/TeleBox/typings.ts
CHANGED
|
@@ -51,12 +51,12 @@ 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
|
|
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. */
|
|
59
|
+
/** Box content stage ratio. Follow manager stage ratio if null. Default null. */
|
|
60
60
|
readonly stageRatio?: number | null;
|
|
61
61
|
/** Classname Prefix. For CSS styling. Default "telebox". */
|
|
62
62
|
readonly namespace?: string;
|
|
@@ -69,9 +69,13 @@ export interface TeleBoxConfig {
|
|
|
69
69
|
/** Box footer element. */
|
|
70
70
|
readonly footer?: HTMLElement;
|
|
71
71
|
/** Box content styles. */
|
|
72
|
-
readonly styles?:
|
|
73
|
-
/**
|
|
74
|
-
readonly
|
|
72
|
+
readonly styles?: string;
|
|
73
|
+
/** Box content styles from end users. */
|
|
74
|
+
readonly userStyles?: string;
|
|
75
|
+
/** Custom styles for box content container. Inherit from manager container style if null. Default null. */
|
|
76
|
+
readonly bodyStyle?: string | null;
|
|
77
|
+
/** Custom styles for box content stage. Inherit from manager stage style if null. Default null. */
|
|
78
|
+
readonly stageStyle?: string | null;
|
|
75
79
|
/** Actual Box Dark Mode */
|
|
76
80
|
readonly darkMode$: ReadonlyVal<boolean, boolean>;
|
|
77
81
|
/** Restrict box to always be within the stage area. Default false. */
|
|
@@ -83,17 +87,19 @@ export interface TeleBoxConfig {
|
|
|
83
87
|
/** Is box readonly */
|
|
84
88
|
readonly readonly$: ReadonlyVal<boolean, boolean>;
|
|
85
89
|
/** Root element to mount boxes */
|
|
86
|
-
readonly root
|
|
90
|
+
readonly root: HTMLElement;
|
|
87
91
|
/** Position and dimension of root element */
|
|
88
92
|
readonly rootRect$: ReadonlyVal<TeleBoxRect>;
|
|
89
93
|
/** Position and dimension of stage area */
|
|
90
94
|
readonly managerStageRect$: ReadonlyVal<TeleBoxRect>;
|
|
91
95
|
/** Stage area height/with ratio. No ratio if <= 0. */
|
|
92
96
|
readonly managerStageRatio$: ReadonlyVal<number, boolean>;
|
|
97
|
+
/** Default content styles for all boxes */
|
|
98
|
+
readonly defaultBoxBodyStyle$: ReadonlyVal<string | null>;
|
|
99
|
+
/** Default stage styles for all boxes */
|
|
100
|
+
readonly defaultBoxStageStyle$: ReadonlyVal<string | null>;
|
|
93
101
|
/** Position and dimension of collector */
|
|
94
102
|
readonly collectorRect$: ReadonlyVal<TeleBoxRect | undefined>;
|
|
95
|
-
/** highlight stage settings from manager */
|
|
96
|
-
readonly managerHighlightStage$: ReadonlyVal<boolean>;
|
|
97
103
|
}
|
|
98
104
|
|
|
99
105
|
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
|
+
}
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import "./style.scss";
|
|
2
|
+
|
|
1
3
|
import shallowequal from "shallowequal";
|
|
2
4
|
import { ResizeObserver as ResizeObserverPolyfill } from "@juggle/resize-observer";
|
|
3
5
|
import { SideEffectManager } from "side-effect-manager";
|
|
@@ -38,7 +40,7 @@ import type {
|
|
|
38
40
|
TeleBoxManagerUpdateConfig,
|
|
39
41
|
} from "./typings";
|
|
40
42
|
import { MaxTitleBar } from "./MaxTitleBar";
|
|
41
|
-
import {
|
|
43
|
+
import { calcStageRect } from "../TeleBox/utils";
|
|
42
44
|
|
|
43
45
|
export * from "./typings";
|
|
44
46
|
export * from "./constants";
|
|
@@ -60,7 +62,10 @@ type ValConfig = {
|
|
|
60
62
|
maximized: Val<boolean, boolean>;
|
|
61
63
|
fence: Val<boolean, boolean>;
|
|
62
64
|
stageRatio: Val<number, boolean>;
|
|
63
|
-
|
|
65
|
+
containerStyle: Val<string>;
|
|
66
|
+
stageStyle: Val<string>;
|
|
67
|
+
defaultBoxBodyStyle: Val<string | null>;
|
|
68
|
+
defaultBoxStageStyle: Val<string | null>;
|
|
64
69
|
};
|
|
65
70
|
|
|
66
71
|
type CombinedValEnhancedResult = ValEnhancedResult<ValConfig> &
|
|
@@ -74,12 +79,15 @@ export class TeleBoxManager {
|
|
|
74
79
|
prefersColorScheme = TELE_BOX_COLOR_SCHEME.Light,
|
|
75
80
|
minimized = false,
|
|
76
81
|
maximized = false,
|
|
77
|
-
fence =
|
|
82
|
+
fence = true,
|
|
78
83
|
collector,
|
|
79
84
|
namespace = "telebox",
|
|
80
85
|
readonly = false,
|
|
81
86
|
stageRatio = -1,
|
|
82
|
-
|
|
87
|
+
containerStyle = "",
|
|
88
|
+
stageStyle = "",
|
|
89
|
+
defaultBoxBodyStyle = null,
|
|
90
|
+
defaultBoxStageStyle = null,
|
|
83
91
|
}: TeleBoxManagerConfig = {}) {
|
|
84
92
|
this._sideEffect = new SideEffectManager();
|
|
85
93
|
|
|
@@ -93,8 +101,11 @@ export class TeleBoxManager {
|
|
|
93
101
|
const minimized$ = new Val(minimized);
|
|
94
102
|
const maximized$ = new Val(maximized);
|
|
95
103
|
const fence$ = new Val(fence);
|
|
104
|
+
const containerStyle$ = new Val(containerStyle);
|
|
105
|
+
const stageStyle$ = new Val(stageStyle);
|
|
96
106
|
const stageRatio$ = new Val(stageRatio);
|
|
97
|
-
const
|
|
107
|
+
const defaultBoxBodyStyle$ = new Val(defaultBoxBodyStyle);
|
|
108
|
+
const defaultBoxStageStyle$ = new Val(defaultBoxStageStyle);
|
|
98
109
|
|
|
99
110
|
const rootRect$ = new Val<TeleBoxRect>(
|
|
100
111
|
{
|
|
@@ -126,6 +137,10 @@ export class TeleBoxManager {
|
|
|
126
137
|
})
|
|
127
138
|
);
|
|
128
139
|
|
|
140
|
+
const stageRect$ = combine([rootRect$, stageRatio$], calcStageRect, {
|
|
141
|
+
compare: shallowequal,
|
|
142
|
+
});
|
|
143
|
+
|
|
129
144
|
this.boxes$ = new Val<TeleBox[]>([]);
|
|
130
145
|
this.topBox$ = new Val<TeleBox | undefined>(undefined);
|
|
131
146
|
this._sideEffect.addDisposer(
|
|
@@ -197,25 +212,12 @@ export class TeleBoxManager {
|
|
|
197
212
|
root$,
|
|
198
213
|
});
|
|
199
214
|
|
|
200
|
-
const teleStage = new TeleStage({
|
|
201
|
-
namespace,
|
|
202
|
-
rootRect$,
|
|
203
|
-
ratio$: stageRatio$,
|
|
204
|
-
root$,
|
|
205
|
-
highlightStage$: combine(
|
|
206
|
-
[highlightStage$, maximized$, minimized$],
|
|
207
|
-
([highlightStage, maximized, minimized]) =>
|
|
208
|
-
highlightStage && (minimized || !maximized)
|
|
209
|
-
),
|
|
210
|
-
});
|
|
211
|
-
this._sideEffect.addDisposer(() => teleStage.destroy());
|
|
212
|
-
|
|
213
215
|
const readonlyValConfig: ReadonlyValConfig = {
|
|
214
216
|
darkMode: darkMode$,
|
|
215
217
|
state: state$,
|
|
216
218
|
root: root$,
|
|
217
219
|
rootRect: rootRect$,
|
|
218
|
-
stageRect:
|
|
220
|
+
stageRect: stageRect$,
|
|
219
221
|
};
|
|
220
222
|
|
|
221
223
|
withReadonlyValueEnhancer(this, readonlyValConfig, valManager);
|
|
@@ -227,7 +229,10 @@ export class TeleBoxManager {
|
|
|
227
229
|
minimized: minimized$,
|
|
228
230
|
maximized: maximized$,
|
|
229
231
|
stageRatio: stageRatio$,
|
|
230
|
-
|
|
232
|
+
containerStyle: containerStyle$,
|
|
233
|
+
stageStyle: stageStyle$,
|
|
234
|
+
defaultBoxBodyStyle: defaultBoxBodyStyle$,
|
|
235
|
+
defaultBoxStageStyle: defaultBoxStageStyle$,
|
|
231
236
|
};
|
|
232
237
|
|
|
233
238
|
withValueEnhancer(this, valConfig, valManager);
|
|
@@ -336,8 +341,57 @@ export class TeleBoxManager {
|
|
|
336
341
|
}
|
|
337
342
|
}),
|
|
338
343
|
]);
|
|
344
|
+
|
|
345
|
+
this.$container = document.createElement("div");
|
|
346
|
+
this.$container.className = this.wrapClassName("manager-container");
|
|
347
|
+
|
|
348
|
+
this.$stage = document.createElement("div");
|
|
349
|
+
this.$stage.className = this.wrapClassName("manager-stage");
|
|
350
|
+
this.$container.appendChild(this.$stage);
|
|
351
|
+
|
|
352
|
+
this._sideEffect.addDisposer([
|
|
353
|
+
darkMode$.subscribe((darkMode) => {
|
|
354
|
+
this.$container.classList.toggle(
|
|
355
|
+
this.wrapClassName("color-scheme-dark"),
|
|
356
|
+
darkMode
|
|
357
|
+
);
|
|
358
|
+
this.$container.classList.toggle(
|
|
359
|
+
this.wrapClassName("color-scheme-light"),
|
|
360
|
+
!darkMode
|
|
361
|
+
);
|
|
362
|
+
}),
|
|
363
|
+
maximized$.subscribe((maximized) => {
|
|
364
|
+
this.$container.classList.toggle("is-maximized", maximized);
|
|
365
|
+
}),
|
|
366
|
+
minimized$.subscribe((minimized) => {
|
|
367
|
+
this.$container.classList.toggle("is-minimized", minimized);
|
|
368
|
+
}),
|
|
369
|
+
containerStyle$.subscribe((containerStyle) => {
|
|
370
|
+
this.$container.style.cssText = containerStyle;
|
|
371
|
+
}),
|
|
372
|
+
stageStyle$.subscribe((stageStyle) => {
|
|
373
|
+
this.$stage.style.cssText = stageStyle;
|
|
374
|
+
this.$stage.style.width = stageRect$.value.width + "px";
|
|
375
|
+
this.$stage.style.height = stageRect$.value.height + "px";
|
|
376
|
+
}),
|
|
377
|
+
stageRect$.subscribe((stageRect) => {
|
|
378
|
+
this.$stage.style.width = stageRect.width + "px";
|
|
379
|
+
this.$stage.style.height = stageRect.height + "px";
|
|
380
|
+
}),
|
|
381
|
+
root$.subscribe((root) => {
|
|
382
|
+
if (root) {
|
|
383
|
+
root.appendChild(this.$container);
|
|
384
|
+
} else if (this.$container.parentElement) {
|
|
385
|
+
this.$container.remove();
|
|
386
|
+
}
|
|
387
|
+
}),
|
|
388
|
+
]);
|
|
339
389
|
}
|
|
340
390
|
|
|
391
|
+
public readonly $container: HTMLDivElement;
|
|
392
|
+
|
|
393
|
+
public readonly $stage: HTMLDivElement;
|
|
394
|
+
|
|
341
395
|
public get boxes(): ReadonlyArray<TeleBox> {
|
|
342
396
|
return this.boxes$.value;
|
|
343
397
|
}
|
|
@@ -386,7 +440,7 @@ export class TeleBoxManager {
|
|
|
386
440
|
...config,
|
|
387
441
|
...(smartPosition ? this.smartPosition(config) : {}),
|
|
388
442
|
namespace: this.namespace,
|
|
389
|
-
root
|
|
443
|
+
root: this.$stage,
|
|
390
444
|
darkMode$: this._darkMode$,
|
|
391
445
|
maximized$: this._maximized$,
|
|
392
446
|
minimized$: this._minimized$,
|
|
@@ -396,7 +450,8 @@ export class TeleBoxManager {
|
|
|
396
450
|
managerStageRatio$: this._stageRatio$,
|
|
397
451
|
readonly$: this._readonly$,
|
|
398
452
|
collectorRect$: this.collector._rect$,
|
|
399
|
-
|
|
453
|
+
defaultBoxBodyStyle$: this._defaultBoxBodyStyle$,
|
|
454
|
+
defaultBoxStageStyle$: this._defaultBoxStageStyle$,
|
|
400
455
|
});
|
|
401
456
|
|
|
402
457
|
if (box.focus) {
|
|
@@ -663,8 +718,8 @@ export class TeleBoxManager {
|
|
|
663
718
|
if (config.draggable != null) {
|
|
664
719
|
box._draggable$.setValue(config.draggable, skipUpdate);
|
|
665
720
|
}
|
|
666
|
-
if (config.
|
|
667
|
-
box.
|
|
721
|
+
if (config.boxRatio != null) {
|
|
722
|
+
box._boxRatio$.setValue(config.boxRatio, skipUpdate);
|
|
668
723
|
}
|
|
669
724
|
if (config.zIndex != null) {
|
|
670
725
|
box._zIndex$.setValue(config.zIndex, skipUpdate);
|
|
@@ -697,33 +752,27 @@ export class TeleBoxManager {
|
|
|
697
752
|
const topBox = this.topBox;
|
|
698
753
|
|
|
699
754
|
if (x == null) {
|
|
700
|
-
let pxX =
|
|
755
|
+
let pxX = 20;
|
|
701
756
|
if (topBox) {
|
|
702
757
|
const pxPreferredX = topBox.pxIntrinsicCoord.x + 20;
|
|
703
758
|
const pxIntrinsicWidth = width * stageRect.width;
|
|
704
|
-
if (
|
|
705
|
-
pxPreferredX + pxIntrinsicWidth <=
|
|
706
|
-
stageRect.x + stageRect.width
|
|
707
|
-
) {
|
|
759
|
+
if (pxPreferredX + pxIntrinsicWidth <= stageRect.width) {
|
|
708
760
|
pxX = pxPreferredX;
|
|
709
761
|
}
|
|
710
762
|
}
|
|
711
|
-
x =
|
|
763
|
+
x = pxX / stageRect.width;
|
|
712
764
|
}
|
|
713
765
|
|
|
714
766
|
if (y == null) {
|
|
715
|
-
let pxY =
|
|
767
|
+
let pxY = 20;
|
|
716
768
|
if (topBox) {
|
|
717
769
|
const pxPreferredY = topBox.pxIntrinsicCoord.y + 20;
|
|
718
770
|
const pxIntrinsicHeight = height * stageRect.height;
|
|
719
|
-
if (
|
|
720
|
-
pxPreferredY + pxIntrinsicHeight <=
|
|
721
|
-
stageRect.y + stageRect.height
|
|
722
|
-
) {
|
|
771
|
+
if (pxPreferredY + pxIntrinsicHeight <= stageRect.height) {
|
|
723
772
|
pxY = pxPreferredY;
|
|
724
773
|
}
|
|
725
774
|
}
|
|
726
|
-
y =
|
|
775
|
+
y = pxY / stageRect.height;
|
|
727
776
|
}
|
|
728
777
|
|
|
729
778
|
return { x, y, width, height };
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
@import "../scss/variables.scss";
|
|
2
|
+
|
|
3
|
+
.#{$namespace}-manager-container {
|
|
4
|
+
position: relative;
|
|
5
|
+
overflow: hidden;
|
|
6
|
+
width: 100%;
|
|
7
|
+
height: 100%;
|
|
8
|
+
display: flex;
|
|
9
|
+
justify-content: center;
|
|
10
|
+
align-items: center;
|
|
11
|
+
background: $color-container-background;
|
|
12
|
+
|
|
13
|
+
&.is-maximized,
|
|
14
|
+
&.is-minimized {
|
|
15
|
+
& > .#{$namespace}-manager-stage {
|
|
16
|
+
overflow: visible;
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
.#{$namespace}-manager-stage {
|
|
22
|
+
position: relative;
|
|
23
|
+
overflow: hidden;
|
|
24
|
+
background: $color-stage-background;
|
|
25
|
+
box-shadow: $color-stage-shadow;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
.#{$namespace}-color-scheme-dark {
|
|
29
|
+
color-scheme: dark;
|
|
30
|
+
|
|
31
|
+
&.#{$namespace}-manager-container {
|
|
32
|
+
background: $color-container-background-dark;
|
|
33
|
+
|
|
34
|
+
& > .#{$namespace}-manager-stage {
|
|
35
|
+
background: $color-stage-background-dark;
|
|
36
|
+
box-shadow: $color-stage-shadow-dark;
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
}
|
|
@@ -21,8 +21,14 @@ export interface TeleBoxManagerConfig extends Pick<TeleBoxConfig, "namespace"> {
|
|
|
21
21
|
readonly minimized?: boolean;
|
|
22
22
|
/** Is box readonly */
|
|
23
23
|
readonly readonly?: boolean;
|
|
24
|
-
/**
|
|
25
|
-
readonly
|
|
24
|
+
/** Custom styles for telebox manager container */
|
|
25
|
+
readonly containerStyle?: string;
|
|
26
|
+
/** Custom styles for telebox manager stage */
|
|
27
|
+
readonly stageStyle?: string;
|
|
28
|
+
/** Custom `style` attribute value for content area of all boxes. Can be overwritten by box. */
|
|
29
|
+
readonly defaultBoxBodyStyle?: string | null;
|
|
30
|
+
/** Custom `style` attribute value for stage area of all boxes. Can be overwritten by box. */
|
|
31
|
+
readonly defaultBoxStageStyle?: string | null;
|
|
26
32
|
}
|
|
27
33
|
|
|
28
34
|
type TeleBoxManagerBoxConfigBaseProps =
|
|
@@ -36,7 +42,7 @@ type TeleBoxManagerBoxConfigBaseProps =
|
|
|
36
42
|
| "y"
|
|
37
43
|
| "resizable"
|
|
38
44
|
| "draggable"
|
|
39
|
-
| "
|
|
45
|
+
| "boxRatio"
|
|
40
46
|
| "zIndex"
|
|
41
47
|
| "stageRatio";
|
|
42
48
|
|
|
@@ -56,7 +62,7 @@ export type TeleBoxManagerQueryConfig = Pick<
|
|
|
56
62
|
| "visible"
|
|
57
63
|
| "resizable"
|
|
58
64
|
| "draggable"
|
|
59
|
-
| "
|
|
65
|
+
| "boxRatio"
|
|
60
66
|
| "stageRatio"
|
|
61
67
|
| "zIndex"
|
|
62
68
|
| "id"
|
package/src/scss/variables.scss
CHANGED
|
@@ -1,5 +1,14 @@
|
|
|
1
1
|
$namespace: "telebox";
|
|
2
|
+
|
|
2
3
|
$base-z-index: 100;
|
|
3
4
|
$max-titlebar-z-index: $base-z-index + 5000;
|
|
4
5
|
$stage-z-index: $max-titlebar-z-index + 10;
|
|
5
6
|
$collector-z-index: $stage-z-index + 10;
|
|
7
|
+
|
|
8
|
+
$color-container-background: #f9f9f9;
|
|
9
|
+
$color-stage-background: #fff;
|
|
10
|
+
$color-stage-shadow: 0px 0px 16px rgba(0, 0, 0, 0.08);
|
|
11
|
+
|
|
12
|
+
$color-container-background-dark: #25282e;
|
|
13
|
+
$color-stage-background-dark: #272a30;
|
|
14
|
+
$color-stage-shadow-dark: 0px 0px 16px rgba(0, 0, 0, 0.24);
|
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
import "./style.scss";
|
|
2
|
-
import type { ReadonlyVal } from "value-enhancer";
|
|
3
|
-
import type { TeleBoxRect } from "../TeleBox/typings";
|
|
4
|
-
export interface TeleStageConfig {
|
|
5
|
-
namespace: string;
|
|
6
|
-
root$: ReadonlyVal<HTMLElement | null>;
|
|
7
|
-
rootRect$: ReadonlyVal<TeleBoxRect>;
|
|
8
|
-
ratio$: ReadonlyVal<number>;
|
|
9
|
-
highlightStage$: ReadonlyVal<boolean>;
|
|
10
|
-
}
|
|
11
|
-
export declare class TeleStage {
|
|
12
|
-
private readonly _sideEffect;
|
|
13
|
-
readonly namespace: string;
|
|
14
|
-
readonly stageRect$: ReadonlyVal<TeleBoxRect>;
|
|
15
|
-
readonly highlightStage$: ReadonlyVal<boolean>;
|
|
16
|
-
$boxStage?: HTMLDivElement;
|
|
17
|
-
constructor({ namespace, rootRect$, ratio$, highlightStage$, root$, }: TeleStageConfig);
|
|
18
|
-
private render;
|
|
19
|
-
destroy(): void;
|
|
20
|
-
wrapClassName(className: string): string;
|
|
21
|
-
}
|
package/src/TeleStage/index.ts
DELETED
|
@@ -1,174 +0,0 @@
|
|
|
1
|
-
import "./style.scss";
|
|
2
|
-
|
|
3
|
-
import shallowequal from "shallowequal";
|
|
4
|
-
import { SideEffectManager } from "side-effect-manager";
|
|
5
|
-
import type { ReadonlyVal } from "value-enhancer";
|
|
6
|
-
import { combine } from "value-enhancer";
|
|
7
|
-
import type { TeleBoxRect } from "../TeleBox/typings";
|
|
8
|
-
|
|
9
|
-
export interface TeleStageConfig {
|
|
10
|
-
namespace: string;
|
|
11
|
-
root$: ReadonlyVal<HTMLElement | null>;
|
|
12
|
-
rootRect$: ReadonlyVal<TeleBoxRect>;
|
|
13
|
-
ratio$: ReadonlyVal<number>;
|
|
14
|
-
highlightStage$: ReadonlyVal<boolean>;
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
export class TeleStage {
|
|
18
|
-
private readonly _sideEffect = new SideEffectManager();
|
|
19
|
-
|
|
20
|
-
public readonly namespace: string;
|
|
21
|
-
public readonly stageRect$: ReadonlyVal<TeleBoxRect>;
|
|
22
|
-
public readonly highlightStage$: ReadonlyVal<boolean>;
|
|
23
|
-
|
|
24
|
-
public $boxStage?: HTMLDivElement;
|
|
25
|
-
|
|
26
|
-
constructor({
|
|
27
|
-
namespace,
|
|
28
|
-
rootRect$,
|
|
29
|
-
ratio$,
|
|
30
|
-
highlightStage$,
|
|
31
|
-
root$,
|
|
32
|
-
}: TeleStageConfig) {
|
|
33
|
-
this.namespace = namespace;
|
|
34
|
-
this.highlightStage$ = highlightStage$;
|
|
35
|
-
|
|
36
|
-
this.stageRect$ = combine(
|
|
37
|
-
[rootRect$, ratio$],
|
|
38
|
-
([rootRect, ratio]) => {
|
|
39
|
-
if (ratio <= 0 || rootRect.width <= 0 || rootRect.height <= 0) {
|
|
40
|
-
return rootRect;
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
const preferredHeight = rootRect.width * ratio;
|
|
44
|
-
if (preferredHeight === rootRect.height) {
|
|
45
|
-
return rootRect;
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
if (preferredHeight < rootRect.height) {
|
|
49
|
-
return {
|
|
50
|
-
x: 0,
|
|
51
|
-
y: (rootRect.height - preferredHeight) / 2,
|
|
52
|
-
width: rootRect.width,
|
|
53
|
-
height: preferredHeight,
|
|
54
|
-
};
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
const preferredWidth = rootRect.height / ratio;
|
|
58
|
-
return {
|
|
59
|
-
x: (rootRect.width - preferredWidth) / 2,
|
|
60
|
-
y: 0,
|
|
61
|
-
width: preferredWidth,
|
|
62
|
-
height: rootRect.height,
|
|
63
|
-
};
|
|
64
|
-
},
|
|
65
|
-
{ compare: shallowequal }
|
|
66
|
-
);
|
|
67
|
-
|
|
68
|
-
this._sideEffect.addDisposer(
|
|
69
|
-
combine([root$, highlightStage$]).subscribe(
|
|
70
|
-
([root, highlightStage]) => {
|
|
71
|
-
if (root && highlightStage) {
|
|
72
|
-
root.appendChild(this.render());
|
|
73
|
-
} else if (this.$boxStage?.parentNode) {
|
|
74
|
-
this.$boxStage.remove();
|
|
75
|
-
}
|
|
76
|
-
}
|
|
77
|
-
)
|
|
78
|
-
);
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
private render(): HTMLDivElement {
|
|
82
|
-
if (this.$boxStage) {
|
|
83
|
-
return this.$boxStage;
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
const $boxStage = document.createElement("div");
|
|
87
|
-
$boxStage.className = this.wrapClassName("box-stage-container");
|
|
88
|
-
const $boxStageMask1 = document.createElement("div");
|
|
89
|
-
$boxStageMask1.className = this.wrapClassName("box-stage-mask");
|
|
90
|
-
const $boxStageMask2 = document.createElement("div");
|
|
91
|
-
$boxStageMask2.className = this.wrapClassName("box-stage-mask");
|
|
92
|
-
const $boxStageFrame = document.createElement("div");
|
|
93
|
-
$boxStageFrame.className = this.wrapClassName("box-stage-frame");
|
|
94
|
-
|
|
95
|
-
const [
|
|
96
|
-
$topLeftCorner,
|
|
97
|
-
$topRightCorner,
|
|
98
|
-
$bottomLeftCorner,
|
|
99
|
-
$bottomRightCorner,
|
|
100
|
-
] = [
|
|
101
|
-
"M0 8V0h8v2H2v6H0Z",
|
|
102
|
-
"M8 8V0H0v2h6v6h2Z",
|
|
103
|
-
"M0 0v8h8V6H2V0H0Z",
|
|
104
|
-
"M8 0v8H0V6h6V0h2Z",
|
|
105
|
-
].map((path, i) => {
|
|
106
|
-
const $svg = document.createElementNS(
|
|
107
|
-
"http://www.w3.org/2000/svg",
|
|
108
|
-
"svg"
|
|
109
|
-
);
|
|
110
|
-
$svg.setAttribute("viewBox", "0 0 8 8");
|
|
111
|
-
$svg.setAttribute(
|
|
112
|
-
"class",
|
|
113
|
-
`${this.wrapClassName("box-stage-frame-corner")} is-${i}`
|
|
114
|
-
);
|
|
115
|
-
const $path = document.createElementNS(
|
|
116
|
-
"http://www.w3.org/2000/svg",
|
|
117
|
-
"path"
|
|
118
|
-
);
|
|
119
|
-
$path.setAttribute("d", path);
|
|
120
|
-
$path.setAttribute("fill", "#3381FF");
|
|
121
|
-
$svg.appendChild($path);
|
|
122
|
-
return $svg;
|
|
123
|
-
});
|
|
124
|
-
|
|
125
|
-
$boxStageFrame.appendChild($topLeftCorner);
|
|
126
|
-
$boxStageFrame.appendChild($bottomLeftCorner);
|
|
127
|
-
$boxStageFrame.appendChild($topRightCorner);
|
|
128
|
-
$boxStageFrame.appendChild($bottomRightCorner);
|
|
129
|
-
|
|
130
|
-
$boxStage.appendChild($boxStageMask1);
|
|
131
|
-
$boxStage.appendChild($boxStageFrame);
|
|
132
|
-
$boxStage.appendChild($boxStageMask2);
|
|
133
|
-
|
|
134
|
-
this._sideEffect.addDisposer(
|
|
135
|
-
this.highlightStage$.subscribe((highlightStage) => {
|
|
136
|
-
$boxStage.classList.toggle("is-active", highlightStage);
|
|
137
|
-
})
|
|
138
|
-
);
|
|
139
|
-
|
|
140
|
-
this._sideEffect.addDisposer(
|
|
141
|
-
combine([this.highlightStage$, this.stageRect$]).subscribe(
|
|
142
|
-
([highlightStage, stageRect]) => {
|
|
143
|
-
if (!highlightStage) {
|
|
144
|
-
return;
|
|
145
|
-
}
|
|
146
|
-
if (stageRect.x > 0) {
|
|
147
|
-
$boxStage.style.flexDirection = "row";
|
|
148
|
-
$boxStageMask1.style.width = `${stageRect.x}px`;
|
|
149
|
-
$boxStageMask1.style.height = "";
|
|
150
|
-
$boxStageMask2.style.width = `${stageRect.x}px`;
|
|
151
|
-
$boxStageMask2.style.height = "";
|
|
152
|
-
} else if (stageRect.y > 0) {
|
|
153
|
-
$boxStage.style.flexDirection = "column";
|
|
154
|
-
$boxStageMask1.style.width = "";
|
|
155
|
-
$boxStageMask1.style.height = `${stageRect.y}px`;
|
|
156
|
-
$boxStageMask2.style.width = "";
|
|
157
|
-
$boxStageMask2.style.height = `${stageRect.y}px`;
|
|
158
|
-
}
|
|
159
|
-
}
|
|
160
|
-
)
|
|
161
|
-
);
|
|
162
|
-
|
|
163
|
-
this.$boxStage = $boxStage;
|
|
164
|
-
return $boxStage;
|
|
165
|
-
}
|
|
166
|
-
|
|
167
|
-
public destroy(): void {
|
|
168
|
-
this._sideEffect.flushAll();
|
|
169
|
-
}
|
|
170
|
-
|
|
171
|
-
public wrapClassName(className: string): string {
|
|
172
|
-
return `${this.namespace}-${className}`;
|
|
173
|
-
}
|
|
174
|
-
}
|