@netless/telebox-insider 1.0.0-alpha.2 → 1.0.0-alpha.22

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.
Files changed (35) hide show
  1. package/dist/TeleBox/index.d.ts +49 -34
  2. package/dist/TeleBox/typings.d.ts +22 -10
  3. package/dist/TeleBox/utils.d.ts +5 -0
  4. package/dist/TeleBoxCollector/index.d.ts +7 -6
  5. package/dist/TeleBoxManager/MaxTitleBar/index.d.ts +1 -1
  6. package/dist/TeleBoxManager/index.d.ts +8 -2
  7. package/dist/TeleBoxManager/typings.d.ts +12 -6
  8. package/dist/TeleTitleBar/DefaultTitleBar/index.d.ts +3 -5
  9. package/dist/TeleTitleBar/typings.d.ts +1 -1
  10. package/dist/style.css +1 -1
  11. package/dist/telebox-insider.cjs.js +2 -1
  12. package/dist/telebox-insider.cjs.js.map +1 -1
  13. package/dist/telebox-insider.es.js +1647 -1
  14. package/dist/telebox-insider.es.js.map +1 -1
  15. package/package.json +3 -3
  16. package/src/TeleBox/index.ts +373 -261
  17. package/src/TeleBox/style.scss +9 -29
  18. package/src/TeleBox/style.shadow.scss +87 -0
  19. package/src/TeleBox/typings.ts +22 -10
  20. package/src/TeleBox/utils.ts +32 -0
  21. package/src/TeleBoxCollector/index.ts +33 -18
  22. package/src/TeleBoxCollector/style.scss +10 -4
  23. package/src/TeleBoxManager/MaxTitleBar/index.ts +3 -28
  24. package/src/TeleBoxManager/MaxTitleBar/style.scss +38 -16
  25. package/src/TeleBoxManager/index.ts +106 -54
  26. package/src/TeleBoxManager/style.scss +56 -0
  27. package/src/TeleBoxManager/typings.ts +24 -7
  28. package/src/TeleTitleBar/DefaultTitleBar/index.ts +4 -12
  29. package/src/TeleTitleBar/DefaultTitleBar/style.scss +68 -11
  30. package/src/TeleTitleBar/typings.ts +1 -1
  31. package/src/scss/mixins.scss +5 -0
  32. package/src/scss/variables.scss +46 -0
  33. package/dist/TeleStage/index.d.ts +0 -21
  34. package/src/TeleStage/index.ts +0 -178
  35. package/src/TeleStage/style.scss +0 -49
@@ -1,6 +1,8 @@
1
1
  @import "../scss/variables.scss";
2
2
  @import "../scss/mixins.scss";
3
3
 
4
+ @import "./style.shadow.scss";
5
+
4
6
  .#{$namespace}-box {
5
7
  position: absolute;
6
8
  top: 0;
@@ -12,16 +14,16 @@
12
14
  }
13
15
 
14
16
  .#{$namespace}-box-main {
17
+ @include v(border, box-border, $box-border);
18
+ @include v(box-shadow, box-shadow, $box-shadow);
19
+
15
20
  position: relative;
16
21
  width: 100%;
17
22
  height: 100%;
18
23
  display: flex;
19
24
  flex-direction: column;
20
25
  overflow: hidden;
21
- background: #f9f9fc;
22
- box-shadow: 0px 4px 10px 0px rgba(47, 65, 146, 0.15);
23
26
  border-radius: 6px;
24
- border: 1px solid #e3e3ec;
25
27
  }
26
28
 
27
29
  .#{$namespace}-titlebar-wrap {
@@ -30,32 +32,11 @@
30
32
  z-index: 1;
31
33
  }
32
34
 
33
- .#{$namespace}-content-wrap {
35
+ .#{$namespace}-quarantine-wrap {
36
+ all: initial;
34
37
  flex: 1;
35
38
  width: 100%;
36
39
  overflow: hidden;
37
- display: flex;
38
- justify-content: center;
39
- align-items: center;
40
- position: relative;
41
- }
42
-
43
- .#{$namespace}-content {
44
- width: 100%;
45
- height: 100%;
46
- position: relative;
47
- }
48
-
49
- .#{$namespace}-footer-wrap {
50
- flex-shrink: 0;
51
- display: flex;
52
- flex-direction: column;
53
-
54
- &::before {
55
- content: "";
56
- display: block;
57
- flex: 1;
58
- }
59
40
  }
60
41
 
61
42
  .#{$namespace}-resize-handle {
@@ -211,8 +192,7 @@
211
192
  color-scheme: dark;
212
193
 
213
194
  .#{$namespace}-box-main {
214
- color: #e9e9e9;
215
- background: #212126;
216
- border-color: #43434d;
195
+ @include v(border, box-border-dark, $box-border-dark);
196
+ @include v(box-shadow, box-shadow-dark, $box-shadow-dark);
217
197
  }
218
198
  }
@@ -0,0 +1,87 @@
1
+ @import "../scss/variables.scss";
2
+ @import "../scss/mixins.scss";
3
+
4
+ .#{$namespace}-quarantine {
5
+ position: relative;
6
+ width: 100%;
7
+ height: 100%;
8
+ display: flex;
9
+ flex-direction: column;
10
+ }
11
+
12
+ .#{$namespace}-body-wrap {
13
+ @include v(color, box-color, $box-color);
14
+
15
+ flex: 1;
16
+ width: 100%;
17
+ overflow: hidden;
18
+ display: flex;
19
+ justify-content: center;
20
+ align-items: center;
21
+ position: relative;
22
+ }
23
+
24
+ .#{$namespace}-content {
25
+ width: 100%;
26
+ height: 100%;
27
+ position: relative;
28
+ @include v(
29
+ background-color,
30
+ manager-container-background,
31
+ $manager-container-background
32
+ );
33
+ }
34
+
35
+ .#{$namespace}-box-stage {
36
+ position: absolute;
37
+ z-index: 1;
38
+ overflow: hidden;
39
+
40
+ @include v(
41
+ background-color,
42
+ manager-stage-background,
43
+ $manager-stage-background
44
+ );
45
+ @include v(box-shadow, manager-stage-shadow, $manager-stage-shadow);
46
+ }
47
+
48
+ .#{$namespace}-footer-wrap {
49
+ flex-shrink: 0;
50
+ display: flex;
51
+ flex-direction: column;
52
+
53
+ &::before {
54
+ content: "";
55
+ display: block;
56
+ flex: 1;
57
+ }
58
+ }
59
+
60
+ .#{$namespace}-color-scheme-dark {
61
+ color-scheme: dark;
62
+
63
+ .#{$namespace}-body-wrap {
64
+ @include v(color, box-color-dark, $box-color-dark);
65
+ }
66
+
67
+ .#{$namespace}-content {
68
+ @include v(
69
+ background-color,
70
+ manager-container-background-dark,
71
+ $manager-container-background-dark
72
+ );
73
+ }
74
+
75
+ .#{$namespace}-box-stage {
76
+ @include v(
77
+ background-color,
78
+ manager-stage-background-dark,
79
+ $manager-stage-background-dark
80
+ );
81
+ @include v(
82
+ box-shadow,
83
+ manager-stage-shadow-dark,
84
+ $manager-stage-shadow-dark
85
+ );
86
+ }
87
+ }
@@ -51,23 +51,33 @@ 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 content stage ratio. Follow manager stage ratio if null. Default null. */
60
+ readonly stageRatio?: number | null;
59
61
  /** Classname Prefix. For CSS styling. Default "telebox". */
60
62
  readonly namespace?: string;
63
+ /** Enable shadow DOM for box content. Default true. */
64
+ readonly enableShadowDOM?: boolean;
61
65
  /** TeleTitleBar Instance. */
62
66
  readonly titleBar?: TeleTitleBar;
63
- /** Box content. */
67
+ /** Box content element. */
64
68
  readonly content?: HTMLElement;
65
- /** Box footer. */
69
+ /** Stage element. */
70
+ readonly stage?: HTMLElement;
71
+ /** Box footer element. */
66
72
  readonly footer?: HTMLElement;
67
73
  /** Box content styles. */
68
- readonly styles?: HTMLStyleElement;
69
- /** Show stage frame and grey-out the non-stage area. Inherit setting from manager if null. Default null. */
70
- readonly highlightStage?: boolean | null;
74
+ readonly styles?: string;
75
+ /** Box content styles from end users. */
76
+ readonly userStyles?: string;
77
+ /** Custom styles for box content container. Inherit from manager container style if null. Default null. */
78
+ readonly bodyStyle?: string | null;
79
+ /** Custom styles for box content stage. Inherit from manager stage style if null. Default null. */
80
+ readonly stageStyle?: string | null;
71
81
  /** Actual Box Dark Mode */
72
82
  readonly darkMode$: ReadonlyVal<boolean, boolean>;
73
83
  /** Restrict box to always be within the stage area. Default false. */
@@ -79,17 +89,19 @@ export interface TeleBoxConfig {
79
89
  /** Is box readonly */
80
90
  readonly readonly$: ReadonlyVal<boolean, boolean>;
81
91
  /** Root element to mount boxes */
82
- readonly root$: ReadonlyVal<HTMLElement | null>;
92
+ readonly root: HTMLElement;
83
93
  /** Position and dimension of root element */
84
94
  readonly rootRect$: ReadonlyVal<TeleBoxRect>;
85
95
  /** Position and dimension of stage area */
86
96
  readonly managerStageRect$: ReadonlyVal<TeleBoxRect>;
87
97
  /** Stage area height/with ratio. No ratio if <= 0. */
88
- readonly stageRatio$: ReadonlyVal<number, boolean>;
98
+ readonly managerStageRatio$: ReadonlyVal<number, boolean>;
99
+ /** Default content styles for all boxes */
100
+ readonly defaultBoxBodyStyle$: ReadonlyVal<string | null>;
101
+ /** Default stage styles for all boxes */
102
+ readonly defaultBoxStageStyle$: ReadonlyVal<string | null>;
89
103
  /** Position and dimension of collector */
90
104
  readonly collectorRect$: ReadonlyVal<TeleBoxRect | undefined>;
91
- /** highlight stage settings from manager */
92
- readonly managerHighlightStage$: ReadonlyVal<boolean>;
93
105
  }
94
106
 
95
107
  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
+ }
@@ -6,10 +6,14 @@ import type {
6
6
  ReadonlyValEnhancedResult,
7
7
  ValEnhancedResult,
8
8
  } from "value-enhancer";
9
- import { withValueEnhancer } from "value-enhancer";
10
- import { combine } from "value-enhancer";
11
- import { Val } from "value-enhancer";
12
- import { withReadonlyValueEnhancer } from "value-enhancer";
9
+ import { derive } from "value-enhancer";
10
+ import {
11
+ withValueEnhancer,
12
+ combine,
13
+ Val,
14
+ withReadonlyValueEnhancer,
15
+ ValManager,
16
+ } from "value-enhancer";
13
17
  import { SideEffectManager } from "side-effect-manager";
14
18
  import type { TeleBoxRect } from "../TeleBox/typings";
15
19
 
@@ -20,22 +24,24 @@ export interface TeleBoxCollectorConfig {
20
24
  minimized$: Val<boolean>;
21
25
  readonly$: ReadonlyVal<boolean>;
22
26
  darkMode$: ReadonlyVal<boolean>;
23
- rootRect$: ReadonlyVal<TeleBoxRect>;
24
27
  }
25
28
 
26
29
  type ValConfig = {
27
30
  styles: Val<TeleStyles>;
28
- el: Val<HTMLElement>;
31
+ $collector: Val<HTMLElement>;
32
+ };
33
+
34
+ type PropsValConfig = {
35
+ root: TeleBoxCollectorConfig["root$"];
29
36
  };
30
37
 
31
- type ReadonlyValConfig = {
38
+ type MyReadonlyValConfig = {
32
39
  rect: ReadonlyVal<TeleBoxRect | undefined>;
33
40
  visible: ReadonlyVal<boolean>;
34
- root: ReadonlyVal<HTMLElement | null>;
35
41
  };
36
42
 
37
43
  type CombinedValEnhancedResult = ValEnhancedResult<ValConfig> &
38
- ReadonlyValEnhancedResult<ReadonlyValConfig>;
44
+ ReadonlyValEnhancedResult<PropsValConfig & MyReadonlyValConfig>;
39
45
 
40
46
  export interface TeleBoxCollector extends CombinedValEnhancedResult {}
41
47
 
@@ -44,32 +50,39 @@ export class TeleBoxCollector {
44
50
  minimized$,
45
51
  readonly$,
46
52
  darkMode$,
47
- rootRect$,
48
53
  namespace = "telebox",
49
54
  styles = {},
50
55
  root$,
51
56
  }: TeleBoxCollectorConfig) {
52
57
  this.namespace = namespace;
53
58
 
59
+ const valManager = new ValManager();
60
+ this._sideEffect.addDisposer(() => valManager.destroy());
61
+
54
62
  const rect$ = new Val<TeleBoxRect | undefined>(void 0);
55
- const visible$ = minimized$;
63
+ const visible$ = derive(minimized$);
56
64
  const styles$ = new Val(styles);
57
65
  const el$ = new Val<HTMLElement>(document.createElement("button"));
58
66
 
59
67
  const valConfig: ValConfig = {
60
68
  styles: styles$,
61
- el: el$,
69
+ $collector: el$,
62
70
  };
63
71
 
64
- withValueEnhancer(this, valConfig);
72
+ withValueEnhancer(this, valConfig, valManager);
65
73
 
66
- const readonlyValConfig: ReadonlyValConfig = {
74
+ const propsValConfig: PropsValConfig = {
75
+ root: root$,
76
+ };
77
+
78
+ withReadonlyValueEnhancer(this, propsValConfig);
79
+
80
+ const myReadonlyValConfig: MyReadonlyValConfig = {
67
81
  rect: rect$,
68
82
  visible: visible$,
69
- root: root$,
70
83
  };
71
84
 
72
- withReadonlyValueEnhancer(this, readonlyValConfig);
85
+ withReadonlyValueEnhancer(this, myReadonlyValConfig, valManager);
73
86
 
74
87
  el$.value.className = this.wrapClassName("collector");
75
88
  el$.value.style.backgroundImage = `url('${collectorSVG}')`;
@@ -129,11 +142,13 @@ export class TeleBoxCollector {
129
142
  }
130
143
  }),
131
144
  // Place after $collector appended to the DOM so that rect calc works
132
- combine([minimized$, rootRect$, root$]).subscribe(
133
- ([minimized, rootRect, root]) => {
145
+ combine([minimized$, root$]).subscribe(
146
+ ([minimized, root]) => {
134
147
  if (minimized && root) {
135
148
  const { x, y, width, height } =
136
149
  $collector.getBoundingClientRect();
150
+ const rootRect =
151
+ root.getBoundingClientRect();
137
152
  rect$.setValue({
138
153
  x: x - rootRect.x,
139
154
  y: y - rootRect.y,
@@ -7,7 +7,7 @@
7
7
  visibility: hidden;
8
8
  display: block;
9
9
  position: absolute;
10
- z-index: $base-z-index * 2;
10
+ z-index: $collector-z-index;
11
11
  width: 40px;
12
12
  height: 40px;
13
13
  margin: 0;
@@ -16,8 +16,6 @@
16
16
  outline: none;
17
17
  font-size: 0;
18
18
  border-radius: 50%;
19
- background: #fff;
20
- box-shadow: 0px 2px 6px 0px rgba(47, 65, 146, 0.15);
21
19
  cursor: pointer;
22
20
  user-select: none;
23
21
  pointer-events: none;
@@ -25,6 +23,9 @@
25
23
  background-size: 18px 16px;
26
24
  background-position: center;
27
25
  -webkit-tap-highlight-color: transparent;
26
+
27
+ @include v(background-color, collector-background, $collector-background);
28
+ @include v(box-shadow, collector-shadow, $collector-shadow);
28
29
  }
29
30
 
30
31
  .#{$namespace}-collector-visible {
@@ -40,6 +41,11 @@
40
41
  color-scheme: dark;
41
42
 
42
43
  &.#{$namespace}-collector {
43
- background-color: #43434d;
44
+ @include v(
45
+ background-color,
46
+ collector-background-dark,
47
+ $collector-background-dark
48
+ );
49
+ @include v(box-shadow, collector-shadow-dark, $collector-shadow-dark);
44
50
  }
45
51
  }
@@ -14,7 +14,7 @@ export interface MaxTitleBarConfig extends DefaultTitleBarConfig {
14
14
  darkMode$: ReadonlyVal<boolean>;
15
15
  boxes$: ReadonlyVal<TeleBox[]>;
16
16
  rootRect$: ReadonlyVal<TeleBoxRect>;
17
- root$: ReadonlyVal<HTMLElement | null>;
17
+ root: HTMLElement;
18
18
  }
19
19
 
20
20
  export class MaxTitleBar extends DefaultTitleBar {
@@ -25,15 +25,7 @@ export class MaxTitleBar extends DefaultTitleBar {
25
25
  this.rootRect$ = config.rootRect$;
26
26
  this.darkMode$ = config.darkMode$;
27
27
 
28
- this.sideEffect.addDisposer(
29
- config.root$.subscribe((root) => {
30
- if (root) {
31
- root.appendChild(this.render());
32
- } else if (this.$titleBar?.parentNode) {
33
- this.$titleBar.remove();
34
- }
35
- })
36
- );
28
+ config.root.appendChild(this.render());
37
29
  }
38
30
 
39
31
  public focusBox(box?: TeleBox): void {
@@ -75,11 +67,6 @@ export class MaxTitleBar extends DefaultTitleBar {
75
67
 
76
68
  this.sideEffect.addDisposer(
77
69
  [
78
- this.rootRect$.subscribe((rootRect) => {
79
- const { x, y, width } = rootRect;
80
- $titleBar.style.transform = `translate(${x}px, ${y}px)`;
81
- $titleBar.style.width = width + "px";
82
- }),
83
70
  this.state$.subscribe((state) => {
84
71
  $titleBar.classList.toggle(
85
72
  this.wrapClassName("max-titlebar-maximized"),
@@ -92,16 +79,6 @@ export class MaxTitleBar extends DefaultTitleBar {
92
79
  readonly
93
80
  );
94
81
  }),
95
- this.darkMode$.subscribe((darkMode) => {
96
- $titleBar.classList.toggle(
97
- this.wrapClassName("color-scheme-dark"),
98
- darkMode
99
- );
100
- $titleBar.classList.toggle(
101
- this.wrapClassName("color-scheme-light"),
102
- !darkMode
103
- );
104
- }),
105
82
  combine([this.state$, this.boxes$]).subscribe(
106
83
  ([state, titles]) => {
107
84
  if (state === TELE_BOX_STATE.Maximized) {
@@ -109,9 +86,7 @@ export class MaxTitleBar extends DefaultTitleBar {
109
86
  this.wrapClassName("max-titlebar-single-title"),
110
87
  titles.length === 1
111
88
  );
112
- if (titles.length === 1) {
113
- this.setTitle(titles[0].title);
114
- } else {
89
+ if (titles.length !== 1) {
115
90
  $titleBar.replaceChild(
116
91
  this.renderTitles(),
117
92
  $titleBar.firstElementChild as HTMLElement
@@ -1,7 +1,7 @@
1
1
  @import "../../scss/variables.scss";
2
2
  @import "../../scss/mixins.scss";
3
3
 
4
- $scrollbar-size: 8px;
4
+ $scrollbar-size: 4px;
5
5
  $scrollbar-ff-width: auto; // FF-only accepts auto, thin, none
6
6
  $scrollbar-minlength: 50px; // Minimum length of scrollbar thumb
7
7
  $scrollbar-track-color: transparent;
@@ -16,7 +16,10 @@ $scrollbar-color-active: rgba(238, 238, 247, 1);
16
16
  position: absolute;
17
17
  top: 0;
18
18
  left: 0;
19
- z-index: $base-z-index * 500;
19
+ width: 100%;
20
+ z-index: $max-titlebar-z-index;
21
+ border-top-left-radius: 6px;
22
+ border-top-right-radius: 6px;
20
23
 
21
24
  .#{$namespace}-title {
22
25
  display: none;
@@ -95,7 +98,7 @@ $scrollbar-color-active: rgba(238, 238, 247, 1);
95
98
  height: 100%;
96
99
  overflow: hidden;
97
100
  max-width: 182px;
98
- min-width: 50px;
101
+ min-width: 150px;
99
102
  padding: 0 26px 0 16px;
100
103
  outline: none;
101
104
  font-size: 13px;
@@ -105,15 +108,26 @@ $scrollbar-color-active: rgba(238, 238, 247, 1);
105
108
  white-space: nowrap;
106
109
  word-break: keep-all;
107
110
  border: none;
108
- border-right: 1px solid #e5e5f0;
109
- color: #7b88a0;
110
- background: transparent;
111
+ border-right-width: 1px;
112
+ border-right-style: solid;
111
113
  cursor: pointer;
112
114
  user-select: none;
115
+
116
+ @include v(color, titlebar-tab-color, $titlebar-tab-color);
117
+ @include v(
118
+ background-color,
119
+ titlebar-tab-background,
120
+ $titlebar-tab-background
121
+ );
122
+ @include v(
123
+ border-right-color,
124
+ titlebar-tab-divider-color,
125
+ $titlebar-tab-divider-color
126
+ );
113
127
  }
114
128
 
115
129
  .#{$namespace}-titles-tab-focus {
116
- color: #357bf6;
130
+ @include v(color, titlebar-tab-focus-color, $titlebar-tab-focus-color);
117
131
  }
118
132
 
119
133
  .#{$namespace}-readonly {
@@ -125,17 +139,25 @@ $scrollbar-color-active: rgba(238, 238, 247, 1);
125
139
  .#{$namespace}-color-scheme-dark {
126
140
  color-scheme: dark;
127
141
 
128
- &.#{$namespace}-titlebar {
129
- color: #e9e9e9;
130
- background: #43434d;
131
- border-bottom: none;
132
- }
133
-
134
142
  .#{$namespace}-titles-tab {
135
- border-right-color: #7b88a0;
143
+ @include v(color, titlebar-tab-color-dark, $titlebar-tab-color-dark);
144
+ @include v(
145
+ background-color,
146
+ titlebar-tab-background-dark,
147
+ $titlebar-tab-background-dark
148
+ );
149
+ @include v(
150
+ border-right-color,
151
+ titlebar-tab-divider-color-dark,
152
+ $titlebar-tab-divider-color-dark
153
+ );
136
154
  }
137
155
 
138
- .#{$namespace}-title {
139
- color: #e9e9e9;
156
+ .#{$namespace}-titles-tab-focus {
157
+ @include v(
158
+ color,
159
+ titlebar-tab-focus-color-dark,
160
+ $titlebar-tab-focus-color-dark
161
+ );
140
162
  }
141
163
  }