jsbox-cview 1.0.0 → 1.1.0

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 (47) hide show
  1. package/dist/components/alert/input-alert.js +39 -0
  2. package/dist/components/alert/login-alert.js +45 -0
  3. package/dist/components/alert/plain-alert.js +25 -0
  4. package/dist/components/alert/uialert.js +89 -0
  5. package/dist/components/artificial-flowlayout.js +258 -0
  6. package/dist/components/base.js +43 -0
  7. package/dist/components/custom-navigation-bar.js +519 -0
  8. package/dist/components/dialogs/dialog-sheet.js +67 -0
  9. package/dist/components/dialogs/form-dialog.js +24 -0
  10. package/dist/components/dialogs/list-dialog.js +87 -0
  11. package/dist/components/dialogs/text-dialog.js +31 -0
  12. package/dist/components/dynamic-itemsize-matrix.js +129 -0
  13. package/dist/components/dynamic-preference-listview.js +557 -0
  14. package/dist/components/dynamic-rowheight-list.js +44 -0
  15. package/dist/components/enhanced-imageview.js +114 -0
  16. package/dist/components/image-pager.js +157 -0
  17. package/dist/components/page-control.js +76 -0
  18. package/dist/components/pageviewer-titlebar.js +143 -0
  19. package/dist/components/pageviewer.js +96 -0
  20. package/dist/components/rotating-view.js +102 -0
  21. package/dist/components/searchbar.js +322 -0
  22. package/dist/components/sheet.js +82 -0
  23. package/dist/components/single-views.js +429 -0
  24. package/dist/components/spinners/loading-double-rings.js +104 -0
  25. package/dist/components/spinners/loading-dual-ring.js +82 -0
  26. package/dist/components/spinners/loading-wedges.js +104 -0
  27. package/dist/components/spinners/spinner-androidstyle.js +248 -0
  28. package/dist/components/static-preference-listview.js +798 -0
  29. package/dist/components/symbol-button.js +79 -0
  30. package/dist/components/tabbar.js +357 -0
  31. package/dist/controller/base-controller.js +178 -0
  32. package/dist/controller/controller-router.js +68 -0
  33. package/dist/controller/pageviewer-controller.js +63 -0
  34. package/dist/controller/presented-page-controller.js +48 -0
  35. package/dist/controller/splitview-controller.js +252 -0
  36. package/dist/controller/tabbar-controller.js +74 -0
  37. package/dist/index.js +58 -0
  38. package/dist/test.js +1 -0
  39. package/dist/utils/colors.js +15 -0
  40. package/dist/utils/cvid.js +28 -0
  41. package/dist/utils/l10n.js +44 -0
  42. package/dist/utils/path.js +107 -0
  43. package/dist/utils/rect.js +72 -0
  44. package/dist/utils/uitools.js +95 -0
  45. package/index.ts +42 -0
  46. package/package.json +4 -3
  47. package/tsconfig.json +5 -3
@@ -0,0 +1,79 @@
1
+ "use strict";
2
+ /**
3
+ * #cview symbolButton
4
+ *
5
+ * 创建可以自动规范symbol大小的button,兼容image,可以设定insets
6
+ *
7
+ * props:
8
+ * - symbol
9
+ * - image
10
+ * - tintColor
11
+ * - insets
12
+ *
13
+ * events:
14
+ * - tapped
15
+ */
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ exports.SymbolButton = void 0;
18
+ const base_1 = require("./base");
19
+ /**
20
+ * 创建可以自动规范symbol大小的button,兼容image,可以设定insets
21
+ * props:
22
+ * - symbol
23
+ * - image
24
+ * - tintColor
25
+ * - insets
26
+ * events:
27
+ * - tapped
28
+ */
29
+ class SymbolButton extends base_1.Base {
30
+ constructor({ props, layout, events = {} }) {
31
+ super();
32
+ this._props = Object.assign({ insets: $insets(12.5, 12.5, 12.5, 12.5), tintColor: $color("primaryText") }, props);
33
+ this._layout = layout;
34
+ this._events = events;
35
+ this._defineView = () => {
36
+ return {
37
+ type: "button",
38
+ props: {
39
+ radius: 0,
40
+ bgcolor: $color("clear"),
41
+ id: this.id
42
+ },
43
+ views: [
44
+ {
45
+ type: "image",
46
+ props: {
47
+ id: "image",
48
+ symbol: this._props.symbol,
49
+ image: this._props.image,
50
+ src: this._props.src,
51
+ tintColor: this._props.tintColor,
52
+ contentMode: 1
53
+ },
54
+ layout: (make, view) => {
55
+ make.edges.insets(this._props.insets);
56
+ make.centerX.equalTo(view.super);
57
+ make.width.equalTo(view.height);
58
+ }
59
+ }
60
+ ],
61
+ layout: this._layout,
62
+ events: Object.assign({}, this._events)
63
+ };
64
+ };
65
+ }
66
+ set tintColor(tintColor) {
67
+ const image = this.view.get("image");
68
+ image.tintColor = tintColor;
69
+ }
70
+ set symbol(symbol) {
71
+ this._props.symbol = symbol;
72
+ const image = this.view.get("image");
73
+ image.symbol = symbol;
74
+ }
75
+ get symbol() {
76
+ return this._props.symbol;
77
+ }
78
+ }
79
+ exports.SymbolButton = SymbolButton;
@@ -0,0 +1,357 @@
1
+ "use strict";
2
+ /**
3
+ * 本组件是为了仿制 UITabBar
4
+ * 本组件不能指定布局而是应该指定 height(如果需要的话)
5
+ * 典型的使用方式是添加在布局为$layout.fill的视图中,并指定 items
6
+ *
7
+ * props:
8
+ *
9
+ * - 只写 height: number = 50
10
+ * - 只写 items: {symbol?: string, image?:UIImage, title?: string}[]
11
+ * - 只写 bgcolor?: UIColor 如果不指定则背景使用blur(style 10),若指定则使用纯色视图
12
+ * - 读写 index: number = 0
13
+ * - 只写 selectedSegmentTintColor = $color("tintColor")
14
+ * - 只写 defaultSegmentTintColor = colors.footBarDefaultSegmentColor
15
+ *
16
+ * events:
17
+ *
18
+ * - changed: (cview, index) => void
19
+ * - doubleTapped: (cview, index) => void
20
+ *
21
+ * methods:
22
+ *
23
+ * - hide(animated=true) 隐藏
24
+ * - show(animated=true) 显示
25
+ */
26
+ Object.defineProperty(exports, "__esModule", { value: true });
27
+ exports.TabBar = void 0;
28
+ const colors_1 = require("../utils/colors");
29
+ const base_1 = require("./base");
30
+ class ImageLabelCell extends base_1.Base {
31
+ constructor({ props, events = {} }) {
32
+ super();
33
+ this._props = props;
34
+ this.layouts = {
35
+ image_tightened: (make, view) => {
36
+ make.centerX.equalTo(view.super);
37
+ make.size.equalTo($size(25, 25));
38
+ make.top.inset(7);
39
+ },
40
+ label_tightened: (make, view) => {
41
+ make.centerX.equalTo(view.super);
42
+ make.top.equalTo(view.prev.bottom);
43
+ },
44
+ image_loosed: (make, view) => {
45
+ make.centerX.equalTo(view.super).offset(-35);
46
+ make.centerY.equalTo(view.super);
47
+ make.size.equalTo($size(25, 25));
48
+ },
49
+ label_loosed: (make, view) => {
50
+ make.left.equalTo(view.prev.right).inset(10);
51
+ make.centerY.equalTo(view.super);
52
+ }
53
+ };
54
+ this._defineView = () => {
55
+ return {
56
+ type: "view",
57
+ props: {
58
+ id: this.id,
59
+ userInteractionEnabled: true
60
+ },
61
+ views: [
62
+ {
63
+ type: "image",
64
+ props: {
65
+ id: "image",
66
+ symbol: this._props.symbol,
67
+ image: this._props.image,
68
+ contentMode: 1
69
+ }
70
+ },
71
+ {
72
+ type: "label",
73
+ props: {
74
+ id: "label",
75
+ text: this._props.text,
76
+ align: $align.center
77
+ }
78
+ }
79
+ ],
80
+ events: {
81
+ tapped: sender => {
82
+ if (events.tapped)
83
+ events.tapped(this._props.index);
84
+ }
85
+ }
86
+ };
87
+ };
88
+ }
89
+ set selected(selected) {
90
+ this._props.selected = selected;
91
+ const color = selected
92
+ ? this._props.selectedSegmentTintColor
93
+ : this._props.defaultSegmentTintColor;
94
+ this.view.get("image").tintColor = color;
95
+ const label = this.view.get("label");
96
+ label.textColor = color;
97
+ }
98
+ get selected() {
99
+ return this._props.selected;
100
+ }
101
+ _useTightenedLayout() {
102
+ this.view.get("image").remakeLayout(this.layouts.image_tightened);
103
+ this.view.get("label").remakeLayout(this.layouts.label_tightened);
104
+ const label = this.view.get("label");
105
+ label.font = $font(10);
106
+ }
107
+ _useLoosedLayout() {
108
+ this.view.get("image").remakeLayout(this.layouts.image_loosed);
109
+ this.view.get("label").remakeLayout(this.layouts.label_loosed);
110
+ const label = this.view.get("label");
111
+ label.font = $font(14);
112
+ }
113
+ }
114
+ class ImageCell extends base_1.Base {
115
+ constructor({ props, events = {} }) {
116
+ super();
117
+ this._props = props;
118
+ this.layouts = {
119
+ image_tightened: (make, view) => {
120
+ make.center.equalTo(view.super);
121
+ make.size.equalTo($size(30, 30));
122
+ },
123
+ image_loosed: (make, view) => {
124
+ make.center.equalTo(view.super);
125
+ make.size.equalTo($size(30, 30));
126
+ }
127
+ };
128
+ this._defineView = () => {
129
+ return {
130
+ type: "view",
131
+ props: {
132
+ id: this.id,
133
+ userInteractionEnabled: true
134
+ },
135
+ views: [
136
+ {
137
+ type: "image",
138
+ props: {
139
+ id: "image",
140
+ symbol: this._props.symbol,
141
+ image: this._props.image,
142
+ contentMode: 1
143
+ }
144
+ }
145
+ ],
146
+ events: {
147
+ tapped: sender => {
148
+ if (events.tapped)
149
+ events.tapped(this._props.index);
150
+ }
151
+ }
152
+ };
153
+ };
154
+ }
155
+ set selected(selected) {
156
+ this._props.selected = selected;
157
+ const color = selected
158
+ ? this._props.selectedSegmentTintColor
159
+ : this._props.defaultSegmentTintColor;
160
+ this.view.get("image").tintColor = color;
161
+ }
162
+ get selected() {
163
+ return this._props.selected;
164
+ }
165
+ _useTightenedLayout() {
166
+ this.view.get("image").remakeLayout(this.layouts.image_tightened);
167
+ }
168
+ _useLoosedLayout() {
169
+ this.view.get("image").remakeLayout(this.layouts.image_loosed);
170
+ }
171
+ }
172
+ class TabBar extends base_1.Base {
173
+ constructor({ props, events = {} }) {
174
+ super();
175
+ this._props = Object.assign({ height: 50, index: 0, selectedSegmentTintColor: $color("systemLink"), defaultSegmentTintColor: colors_1.footBarDefaultSegmentColor }, props);
176
+ this._index = this._props.index;
177
+ this._events = events;
178
+ this._cells = this._defineCells();
179
+ this._defineView = () => {
180
+ const stack = {
181
+ type: "stack",
182
+ props: {
183
+ axis: $stackViewAxis.horizontal,
184
+ distribution: $stackViewDistribution.fillEqually,
185
+ spacing: 0,
186
+ stack: {
187
+ views: this._cells.map(n => n.definition)
188
+ }
189
+ },
190
+ layout: (make, view) => {
191
+ make.height.equalTo(this._props.height - 0.5);
192
+ make.left.right.equalTo(view.super.safeArea);
193
+ make.top.equalTo(view.prev.bottom);
194
+ }
195
+ };
196
+ const line = {
197
+ type: "view",
198
+ props: {
199
+ bgcolor: $color("separatorColor")
200
+ },
201
+ layout: (make, view) => {
202
+ make.top.left.right.inset(0);
203
+ make.height.equalTo(0.5);
204
+ }
205
+ };
206
+ if (this._props.bgcolor) {
207
+ return {
208
+ type: "view",
209
+ props: {
210
+ id: this.id,
211
+ bgcolor: this._props.bgcolor
212
+ },
213
+ layout: (make, view) => {
214
+ make.left.right.bottom.inset(0);
215
+ make.top.equalTo(view.super.safeAreaBottom).inset(-this._props.height);
216
+ },
217
+ views: [line, stack],
218
+ events: {
219
+ ready: sender => (this.index = this._index),
220
+ layoutSubviews: sender => {
221
+ const windowWidth = sender.frame.width;
222
+ if (windowWidth > 600) {
223
+ this._useLoosedLayout();
224
+ }
225
+ else {
226
+ this._useTightenedLayout();
227
+ }
228
+ }
229
+ }
230
+ };
231
+ }
232
+ else {
233
+ return {
234
+ type: "blur",
235
+ props: {
236
+ id: this.id,
237
+ style: 10
238
+ },
239
+ layout: (make, view) => {
240
+ make.left.right.bottom.inset(0);
241
+ make.top.equalTo(view.super.safeAreaBottom).inset(-this._props.height);
242
+ },
243
+ views: [line, stack],
244
+ events: {
245
+ ready: sender => (this.index = this._index),
246
+ layoutSubviews: sender => {
247
+ const windowWidth = sender.frame.width;
248
+ if (windowWidth > 600) {
249
+ this._useLoosedLayout();
250
+ }
251
+ else {
252
+ this._useTightenedLayout();
253
+ }
254
+ }
255
+ }
256
+ };
257
+ }
258
+ };
259
+ }
260
+ _defineCells() {
261
+ return this._props.items.map((n, i) => {
262
+ if (n.title) {
263
+ return new ImageLabelCell({
264
+ props: {
265
+ symbol: n.symbol,
266
+ image: n.image ? n.image.alwaysTemplate : undefined,
267
+ text: n.title,
268
+ index: i,
269
+ selectedSegmentTintColor: this._props.selectedSegmentTintColor,
270
+ defaultSegmentTintColor: this._props.defaultSegmentTintColor
271
+ },
272
+ events: {
273
+ tapped: index => {
274
+ if (index !== this.index) {
275
+ this.index = index;
276
+ if (this._events.changed)
277
+ this._events.changed(this, index);
278
+ }
279
+ else {
280
+ if (this._events.doubleTapped)
281
+ this._events.doubleTapped(this, index);
282
+ }
283
+ }
284
+ }
285
+ });
286
+ }
287
+ else {
288
+ return new ImageCell({
289
+ props: {
290
+ symbol: n.symbol,
291
+ image: n.image ? n.image.alwaysTemplate : undefined,
292
+ index: i,
293
+ selectedSegmentTintColor: this._props.selectedSegmentTintColor,
294
+ defaultSegmentTintColor: this._props.defaultSegmentTintColor
295
+ },
296
+ events: {
297
+ tapped: index => {
298
+ if (index !== this.index) {
299
+ this.index = index;
300
+ if (this._events.changed)
301
+ this._events.changed(this, index);
302
+ }
303
+ else {
304
+ if (this._events.doubleTapped)
305
+ this._events.doubleTapped(this, index);
306
+ }
307
+ }
308
+ }
309
+ });
310
+ }
311
+ });
312
+ }
313
+ get index() {
314
+ return this._index;
315
+ }
316
+ set index(index) {
317
+ this._index = index;
318
+ this._cells.forEach((n, i) => {
319
+ n.selected = i === this._index;
320
+ });
321
+ }
322
+ hide(animated = true) {
323
+ this.view.remakeLayout((make, view) => {
324
+ make.left.right.bottom.inset(0);
325
+ make.height.equalTo(0);
326
+ });
327
+ if (animated) {
328
+ $ui.animate({
329
+ duration: 0.3,
330
+ animation: () => this.view.relayout()
331
+ });
332
+ }
333
+ }
334
+ show(animated = true) {
335
+ this.view.remakeLayout((make, view) => {
336
+ make.left.right.bottom.inset(0);
337
+ make.top.equalTo(view.super.safeAreaBottom).inset(-this._props.height);
338
+ });
339
+ if (animated) {
340
+ $ui.animate({
341
+ duration: 0.3,
342
+ animation: () => this.view.relayout()
343
+ });
344
+ }
345
+ }
346
+ _useTightenedLayout() {
347
+ this._cells.forEach(n => {
348
+ n._useTightenedLayout();
349
+ });
350
+ }
351
+ _useLoosedLayout() {
352
+ this._cells.forEach(n => {
353
+ n._useLoosedLayout();
354
+ });
355
+ }
356
+ }
357
+ exports.TabBar = TabBar;
@@ -0,0 +1,178 @@
1
+ "use strict";
2
+ /**
3
+ * # CView Base Controller
4
+ *
5
+ * Cview 控件尽量保持非侵入性和功能专注。而控制器负责控件之间的关联和数据更新。
6
+ * 另外,控制器可以实现一些常用的页面构建形式,比如底部Tab分页,左侧滑动分页,弹出式页面等。
7
+ *
8
+ * ## 属性
9
+ *
10
+ * - id?: string 可以指定 id,如不指定,会自动赋值全局唯一 id
11
+ * - 只写 bgcolor?: UIColor = $color("primarySurface") rootView 的 bgcolor
12
+ * - 只读 cviews: {}
13
+ * - 只读 rootView
14
+ * - 只读 status
15
+ * - created = 0 被创建,未被加载
16
+ * - loaded = 1 被加载,显示状态未知
17
+ * - appearing = 2 处于可显示状态
18
+ * - disappearing = 3 处于不显示状态
19
+ * - removed = 4 根视图被移除
20
+ *
21
+ * ## 事件
22
+ *
23
+ * 5 个生命周期节点:创建、加载、显示、隐藏、销毁。后面四个具有生命周期事件。
24
+ *
25
+ * 创建阶段没有对应事件,此阶段适合为 rootView 添加子 view,不能涉及对 UIView 的任何操作,因为此时 rootView 还未加载。
26
+ *
27
+ * 生命周期事件:
28
+ *
29
+ * 1. didLoad: controller => void 在 rootView 被加载之后执行
30
+ * - 可以在 rootView 的 ready 事件中自动执行,也可以手动执行加快速度
31
+ * - 也可以在这个节点为 rootView 添加子 view
32
+ * - 这个节点可以对 UIView 进行操作了
33
+ * - 可以向 Model 层请求初始数据
34
+ * 2. didAppear: controller => void 在 rootView 显现的时候执行
35
+ * - 向 Model 层请求刷新数据
36
+ * 3. didDisappear: controller => void 在 rootView 不可见的时候执行
37
+ * - 如果是持续执行的刷新行为,可以在此处转为暂停
38
+ * 4. didRemove: controller => void 在 rootView 被移除的时候执行
39
+ * - 应该在此节点释放自定义的 objc
40
+ * - 数据持久化
41
+ *
42
+ * ## 方法
43
+ *
44
+ * 加载方法:
45
+ *
46
+ * 1. uirender(props) 此方法只能使用一次,对应的 Controller 将成为顶级 Controller
47
+ * 2. uipush(props)
48
+ * 3. 直接让 rootView.definition 包含在其他 View 的 views 参数中
49
+ *
50
+ * 生命周期管理:
51
+ *
52
+ * 1. load() 会在 rootView 的 ready 事件中自动调用,也可以手动调用,以加速运行
53
+ * 2. appear()
54
+ * 3. disappear()
55
+ * 4. remove() 用来移除 Router 中的当前 Controller,**请注意此方法和 rootView 的移除无关**,如果通过 uirender 和 uipush,可以在销毁时自动执行 remove()
56
+ *
57
+ * ## 其他
58
+ *
59
+ * - rootView 可以直接通过 rootView.views 设置其_views 属性,其中元素可以为 view 定义也可以为 cview
60
+ */
61
+ Object.defineProperty(exports, "__esModule", { value: true });
62
+ exports.BaseController = exports.ControllerRootView = void 0;
63
+ const base_1 = require("../components/base");
64
+ const single_views_1 = require("../components/single-views");
65
+ const cvid_1 = require("../utils/cvid");
66
+ const controller_router_1 = require("./controller-router");
67
+ /**
68
+ * status
69
+ * - created = 0 被创建,未被加载
70
+ * - loaded = 1 被加载,显示状态未知
71
+ * - appeared= 2 处于可显示状态
72
+ * - disappeared = 3 处于不显示状态
73
+ * - removed = 4 根视图被移除
74
+ * 其中只有 2 和 3 可以相互转化,其他不可以
75
+ */
76
+ const controllerStatus = {
77
+ created: 0,
78
+ loaded: 1,
79
+ appeared: 2,
80
+ disappeared: 3,
81
+ removed: 4
82
+ };
83
+ class ControllerRootView extends single_views_1.ContentView {
84
+ constructor({ props, layout, events }) {
85
+ super({ props, layout, events });
86
+ }
87
+ set views(views) {
88
+ const _views = views.map(v => {
89
+ if (v instanceof base_1.Base)
90
+ return v.definition;
91
+ return v;
92
+ });
93
+ this._views = _views;
94
+ }
95
+ }
96
+ exports.ControllerRootView = ControllerRootView;
97
+ class BaseController {
98
+ constructor({ props, layout = $layout.fill, events = {} } = {}) {
99
+ this._props = props || {};
100
+ this._events = events;
101
+ this.id = this._props.id || cvid_1.cvid.newId;
102
+ this._status = controllerStatus.created; // status使用额外的get来使其只读
103
+ this.rootView = new ControllerRootView({
104
+ props: {
105
+ bgcolor: this._props.bgcolor || $color("primarySurface")
106
+ },
107
+ layout,
108
+ events: {
109
+ ready: sender => this.load()
110
+ }
111
+ });
112
+ this.cviews = {};
113
+ }
114
+ load() {
115
+ // 只有status为created才可以运行
116
+ if (this._status !== controllerStatus.created)
117
+ return;
118
+ this._status = controllerStatus.loaded;
119
+ if (this._events.didLoad)
120
+ this._events.didLoad(this);
121
+ controller_router_1.router.add(this);
122
+ }
123
+ appear() {
124
+ // 只有status为loaded或者disappeared,才可以运行
125
+ if (this._status !== controllerStatus.loaded &&
126
+ this._status !== controllerStatus.disappeared)
127
+ return;
128
+ if (this._events.didAppear)
129
+ this._events.didAppear(this);
130
+ this._status = controllerStatus.appeared;
131
+ }
132
+ disappear() {
133
+ // 只有status为loaded或者appeared,才可以运行
134
+ if (this._status !== controllerStatus.loaded &&
135
+ this._status !== controllerStatus.appeared)
136
+ return;
137
+ if (this._events.didDisappear)
138
+ this._events.didDisappear(this);
139
+ this._status = controllerStatus.disappeared;
140
+ }
141
+ // 此方法不能用于移除rootView,其作用是将控制器从Router中移除,并触发didRemove事件
142
+ remove() {
143
+ // 如果已经移除,不可以再次运行
144
+ if (this._status === controllerStatus.removed)
145
+ return;
146
+ if (this._events.didRemove)
147
+ this._events.didRemove(this);
148
+ controller_router_1.router.delete(this);
149
+ this._status = controllerStatus.removed;
150
+ }
151
+ uirender(props) {
152
+ controller_router_1.router.root = this;
153
+ $ui.render({
154
+ props,
155
+ views: [this.rootView.definition],
156
+ events: {
157
+ appeared: () => this.appear(),
158
+ disappeared: () => this.disappear(),
159
+ dealloc: () => this.remove()
160
+ }
161
+ });
162
+ }
163
+ uipush(props) {
164
+ $ui.push({
165
+ props,
166
+ views: [this.rootView.definition],
167
+ events: {
168
+ appeared: () => this.appear(),
169
+ disappeared: () => this.disappear(),
170
+ dealloc: () => this.remove()
171
+ }
172
+ });
173
+ }
174
+ get status() {
175
+ return this._status;
176
+ }
177
+ }
178
+ exports.BaseController = BaseController;
@@ -0,0 +1,68 @@
1
+ "use strict";
2
+ /**
3
+ * 控制器的路由器,用于管理控制器的集合和操作。
4
+ *
5
+ * ## 属性
6
+ * - `root`:根控制器。
7
+ * - `appeared`:状态为appeared的控制器列表。
8
+ * - `controllerSet`:控制器集合。
9
+ *
10
+ * ## 方法
11
+ * - `add(controller: BaseController)`:添加控制器到路由器中。
12
+ * - `delete(controller: BaseController)`:从路由器中删除控制器。
13
+ * - `get(id: string)`:根据控制器的ID获取控制器。
14
+ *
15
+ */
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ exports.router = void 0;
18
+ class Router {
19
+ constructor() {
20
+ this._set = new Set();
21
+ }
22
+ /**
23
+ * 添加控制器到路由器中。
24
+ * @param controller 要添加的控制器。
25
+ */
26
+ add(controller) {
27
+ this._set.add(controller);
28
+ }
29
+ /**
30
+ * 从路由器中删除控制器。
31
+ * @param controller 要删除的控制器。
32
+ */
33
+ delete(controller) {
34
+ this._set.delete(controller);
35
+ }
36
+ /**
37
+ * 根据控制器的ID获取控制器。
38
+ * @param id 控制器的ID。
39
+ * @returns 匹配的控制器,如果找不到则返回undefined。
40
+ */
41
+ get(id) {
42
+ for (const c of this._set) {
43
+ if (c.id === id)
44
+ return c;
45
+ }
46
+ return;
47
+ }
48
+ /**
49
+ * 获取状态为appeared的控制器集合。
50
+ * @returns 控制器集合。
51
+ */
52
+ get appeared() {
53
+ const appearedControllers = [];
54
+ for (const c of this._set) {
55
+ if (c.status === 2)
56
+ appearedControllers.push(c);
57
+ }
58
+ return appearedControllers;
59
+ }
60
+ /**
61
+ * 获取控制器集合。
62
+ * @returns 控制器集合。
63
+ */
64
+ get controllerSet() {
65
+ return this._set;
66
+ }
67
+ }
68
+ exports.router = new Router();