jsbox-cview 1.0.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/LICENSE +21 -0
  2. package/README.md +19 -0
  3. package/components/alert/input-alert.ts +73 -0
  4. package/components/alert/login-alert.ts +75 -0
  5. package/components/alert/plain-alert.ts +49 -0
  6. package/components/alert/uialert.ts +110 -0
  7. package/components/artificial-flowlayout.ts +321 -0
  8. package/components/base.ts +47 -0
  9. package/components/custom-navigation-bar.ts +570 -0
  10. package/components/dialogs/dialog-sheet.ts +87 -0
  11. package/components/dialogs/form-dialog.ts +23 -0
  12. package/components/dialogs/list-dialog.ts +87 -0
  13. package/components/dialogs/text-dialog.ts +34 -0
  14. package/components/dynamic-itemsize-matrix.ts +190 -0
  15. package/components/dynamic-preference-listview.ts +691 -0
  16. package/components/dynamic-rowheight-list.ts +62 -0
  17. package/components/enhanced-imageview.ts +128 -0
  18. package/components/image-pager.ts +177 -0
  19. package/components/page-control.ts +91 -0
  20. package/components/pageviewer-titlebar.ts +170 -0
  21. package/components/pageviewer.ts +124 -0
  22. package/components/rotating-view.ts +126 -0
  23. package/components/searchbar.ts +373 -0
  24. package/components/sheet.ts +113 -0
  25. package/components/single-views.ts +828 -0
  26. package/components/spinners/loading-double-rings.ts +121 -0
  27. package/components/spinners/loading-dual-ring.ts +90 -0
  28. package/components/spinners/loading-wedges.ts +112 -0
  29. package/components/spinners/spinner-androidstyle.ts +264 -0
  30. package/components/static-preference-listview.ts +991 -0
  31. package/components/symbol-button.ts +105 -0
  32. package/components/tabbar.ts +451 -0
  33. package/controller/base-controller.ts +216 -0
  34. package/controller/controller-router.ts +74 -0
  35. package/controller/pageviewer-controller.ts +86 -0
  36. package/controller/presented-page-controller.ts +57 -0
  37. package/controller/splitview-controller.ts +323 -0
  38. package/controller/tabbar-controller.ts +99 -0
  39. package/package.json +23 -0
  40. package/test.ts +0 -0
  41. package/tsconfig.json +121 -0
  42. package/utils/colors.ts +13 -0
  43. package/utils/cvid.ts +34 -0
  44. package/utils/l10n.ts +42 -0
  45. package/utils/path.ts +100 -0
  46. package/utils/rect.ts +67 -0
  47. package/utils/uitools.ts +117 -0
@@ -0,0 +1,121 @@
1
+ /**
2
+ * # cview LoadingDoubleRings
3
+ */
4
+
5
+ import { Base } from "../base";
6
+
7
+ class CanvasComponet extends Base<UICanvasView, UiTypes.CanvasOptions> {
8
+ _tintColor: UIColor;
9
+ startAngle: number;
10
+ _radiusReduction: number;
11
+ _defineView: () => UiTypes.CanvasOptions;
12
+ constructor({
13
+ tintColor,
14
+ startAngle,
15
+ radiusReduction
16
+ }: {
17
+ tintColor: UIColor;
18
+ startAngle: number;
19
+ radiusReduction: number;
20
+ }) {
21
+ super();
22
+ this._tintColor = tintColor;
23
+ this.startAngle = startAngle;
24
+ this._radiusReduction = radiusReduction;
25
+ this._defineView = () => {
26
+ return {
27
+ type: "canvas",
28
+ props: {
29
+ id: this.id
30
+ },
31
+ layout: $layout.fill,
32
+ events: {
33
+ draw: (view, ctx) => {
34
+ ctx.strokeColor = this._tintColor;
35
+ const radius = Math.min(view.frame.width, view.frame.height);
36
+ ctx.setLineWidth(20);
37
+ ctx.setLineCap(1);
38
+ ctx.setLineJoin(1);
39
+ ctx.addArc(
40
+ radius / 2,
41
+ radius / 2,
42
+ radius / 2 - 20 - this._radiusReduction,
43
+ this.startAngle,
44
+ this.startAngle + (Math.PI * 2 * 1) / 4,
45
+ true
46
+ );
47
+ ctx.strokePath();
48
+ }
49
+ }
50
+ };
51
+ }
52
+ }
53
+
54
+ redraw() {
55
+ this.view.ocValue().invoke("setNeedsDisplay");
56
+ }
57
+ }
58
+
59
+ export class DoubleRings extends Base<UIView, UiTypes.ViewOptions> {
60
+ _defineView: () => UiTypes.ViewOptions;
61
+ constructor({
62
+ colors = [$color("#f5542e"), $color("#f2c327")],
63
+ layout
64
+ }: {
65
+ colors?: UIColor[];
66
+ layout: (make: MASConstraintMaker, view: UIView) => void;
67
+ }) {
68
+ super();
69
+ const interval = 1 / 60;
70
+ this._defineView = () => {
71
+ const canvas1 = new CanvasComponet({
72
+ tintColor: colors[0],
73
+ radiusReduction: 0,
74
+ startAngle: (-Math.PI * 3) / 4
75
+ });
76
+ const canvas2 = new CanvasComponet({
77
+ tintColor: colors[0],
78
+ radiusReduction: 0,
79
+ startAngle: Math.PI / 4
80
+ });
81
+ const canvas3 = new CanvasComponet({
82
+ tintColor: colors[1],
83
+ radiusReduction: 25,
84
+ startAngle: -Math.PI / 4
85
+ });
86
+ const canvas4 = new CanvasComponet({
87
+ tintColor: colors[1],
88
+ radiusReduction: 25,
89
+ startAngle: (Math.PI * 3) / 4
90
+ });
91
+ return {
92
+ type: "view",
93
+ props: {
94
+ id: this.id
95
+ },
96
+ views: [
97
+ canvas1.definition,
98
+ canvas2.definition,
99
+ canvas3.definition,
100
+ canvas4.definition
101
+ ],
102
+ layout,
103
+ events: {
104
+ ready: async sender => {
105
+ while (sender.super) {
106
+ canvas1.startAngle += Math.PI * interval * -2;
107
+ canvas1.redraw();
108
+ canvas2.startAngle += Math.PI * interval * -2;
109
+ canvas2.redraw();
110
+ canvas3.startAngle += Math.PI * interval * 2;
111
+ canvas3.redraw();
112
+ canvas4.startAngle += Math.PI * interval * 2;
113
+ canvas4.redraw();
114
+ await $wait(interval);
115
+ }
116
+ }
117
+ }
118
+ };
119
+ }
120
+ }
121
+ }
@@ -0,0 +1,90 @@
1
+ /**
2
+ * # cview LoadingDualRing
3
+ */
4
+
5
+ import { Base } from "../base";
6
+
7
+ class CanvasComponet extends Base<UICanvasView, UiTypes.CanvasOptions> {
8
+ _tintColor: UIColor;
9
+ startAngle: number;
10
+ _defineView: () => UiTypes.CanvasOptions;
11
+ constructor({ tintColor, startAngle }: { tintColor: UIColor; startAngle: number }) {
12
+ super();
13
+ this._tintColor = tintColor;
14
+ this.startAngle = startAngle;
15
+ this._defineView = () => {
16
+ return {
17
+ type: "canvas",
18
+ props: {
19
+ id: this.id
20
+ },
21
+ layout: $layout.fill,
22
+ events: {
23
+ draw: (view, ctx) => {
24
+ ctx.strokeColor = this._tintColor;
25
+ const radius = Math.min(view.frame.width, view.frame.height);
26
+ ctx.setLineWidth(20);
27
+ ctx.setLineCap(1);
28
+ ctx.setLineJoin(1);
29
+ ctx.addArc(
30
+ radius / 2,
31
+ radius / 2,
32
+ radius / 2 - 20,
33
+ this.startAngle,
34
+ this.startAngle + (Math.PI * 2 * 1) / 4,
35
+ true
36
+ );
37
+ ctx.strokePath();
38
+ }
39
+ }
40
+ };
41
+ }
42
+ }
43
+
44
+ redraw() {
45
+ this.view.ocValue().invoke("setNeedsDisplay");
46
+ }
47
+ }
48
+
49
+ export class DualRing extends Base<UIView, UiTypes.ViewOptions> {
50
+ _defineView: () => UiTypes.ViewOptions;
51
+ constructor({
52
+ colors = [$color("#f5542e"), $color("#f2c327")],
53
+ layout
54
+ }: {
55
+ colors?: UIColor[];
56
+ layout: (make: MASConstraintMaker, view: UIView) => void;
57
+ }) {
58
+ super();
59
+ const interval = 1 / 60;
60
+ this._defineView = () => {
61
+ const canvas1 = new CanvasComponet({
62
+ tintColor: colors[0],
63
+ startAngle: (-Math.PI * 3) / 4
64
+ });
65
+ const canvas2 = new CanvasComponet({
66
+ tintColor: colors[1],
67
+ startAngle: Math.PI / 4
68
+ });
69
+ return {
70
+ type: "view",
71
+ props: {
72
+ id: this.id
73
+ },
74
+ views: [canvas1.definition, canvas2.definition],
75
+ layout,
76
+ events: {
77
+ ready: async sender => {
78
+ while (sender.super) {
79
+ canvas1.startAngle += Math.PI * interval * 2;
80
+ canvas1.redraw();
81
+ canvas2.startAngle += Math.PI * interval * 2;
82
+ canvas2.redraw();
83
+ await $wait(interval);
84
+ }
85
+ }
86
+ }
87
+ };
88
+ }
89
+ }
90
+ }
@@ -0,0 +1,112 @@
1
+ /**
2
+ * # cview LoadingWedges
3
+ */
4
+
5
+ import { Base } from "../base";
6
+
7
+ class CanvasComponet extends Base<UICanvasView, UiTypes.CanvasOptions> {
8
+ _tintColor: UIColor;
9
+ startAngle: number;
10
+ _defineView: () => UiTypes.CanvasOptions;
11
+ constructor({ tintColor, startAngle }: { tintColor: UIColor; startAngle: number }) {
12
+ super();
13
+ this._tintColor = tintColor;
14
+ this.startAngle = startAngle;
15
+ this._defineView = () => {
16
+ return {
17
+ type: "canvas",
18
+ props: {
19
+ id: this.id,
20
+ alpha: 0.8
21
+ },
22
+ layout: $layout.fill,
23
+ events: {
24
+ draw: (view, ctx) => {
25
+ ctx.fillColor = this._tintColor;
26
+ const radius = Math.min(view.frame.width, view.frame.height);
27
+ ctx.addArc(
28
+ radius / 2,
29
+ radius / 2,
30
+ radius / 2,
31
+ this.startAngle,
32
+ this.startAngle + (Math.PI * 2 * 1) / 4,
33
+ true
34
+ );
35
+ ctx.addLineToPoint(radius / 2, radius / 2);
36
+ ctx.closePath();
37
+ ctx.fillPath();
38
+ }
39
+ }
40
+ };
41
+ }
42
+ }
43
+
44
+ redraw() {
45
+ this.view.ocValue().invoke("setNeedsDisplay");
46
+ }
47
+ }
48
+
49
+ export class Wedges extends Base<UIView, UiTypes.ViewOptions> {
50
+ _defineView: () => UiTypes.ViewOptions;
51
+ constructor({
52
+ colors = [
53
+ $color("#f5542e"),
54
+ $color("#f2c327"),
55
+ $color("#008b6e"),
56
+ $color("#00aede")
57
+ ],
58
+ layout
59
+ }: {
60
+ colors?: UIColor[];
61
+ layout: (make: MASConstraintMaker, view: UIView) => void;
62
+ }) {
63
+ super();
64
+ const interval = 1 / 60;
65
+ this._defineView = () => {
66
+ const canvas1 = new CanvasComponet({
67
+ tintColor: colors[0],
68
+ startAngle: -Math.PI / 2
69
+ });
70
+ const canvas2 = new CanvasComponet({
71
+ tintColor: colors[1],
72
+ startAngle: 0
73
+ });
74
+ const canvas3 = new CanvasComponet({
75
+ tintColor: colors[2],
76
+ startAngle: Math.PI / 2
77
+ });
78
+ const canvas4 = new CanvasComponet({
79
+ tintColor: colors[3],
80
+ startAngle: Math.PI
81
+ });
82
+ return {
83
+ type: "view",
84
+ props: {
85
+ id: this.id
86
+ },
87
+ views: [
88
+ canvas1.definition,
89
+ canvas2.definition,
90
+ canvas3.definition,
91
+ canvas4.definition
92
+ ],
93
+ layout,
94
+ events: {
95
+ ready: async sender => {
96
+ while (sender.super) {
97
+ canvas1.startAngle += Math.PI * interval * 4;
98
+ canvas1.redraw();
99
+ canvas2.startAngle += Math.PI * interval * 3;
100
+ canvas2.redraw();
101
+ canvas3.startAngle += Math.PI * interval * 2;
102
+ canvas3.redraw();
103
+ canvas4.startAngle += Math.PI * interval * 1;
104
+ canvas4.redraw();
105
+ await $wait(interval);
106
+ }
107
+ }
108
+ }
109
+ };
110
+ }
111
+ }
112
+ }
@@ -0,0 +1,264 @@
1
+ /**
2
+ * 安卓风格的加载指示器,基于Lottie实现
3
+ *
4
+ * Props:
5
+ *
6
+ * - id 可以重新指定 id,以供 list 或者 matrix 的 template 使用
7
+ * - weight = 2
8
+ * - diameter = 24
9
+ * - color = $color("gray")
10
+ * - bgcolor = $color("clear")
11
+ *
12
+ * Layout 默认居中
13
+ *
14
+ */
15
+
16
+ import { Base } from "../base";
17
+
18
+ interface AndroidStyleSpinnerProps {
19
+ weight: number;
20
+ diameter: number;
21
+ color: UIColor;
22
+ bgcolor: UIColor;
23
+ }
24
+
25
+ export class AndroidStyleSpinner extends Base<UILottieView, UiTypes.LottieOptions> {
26
+ private _props: AndroidStyleSpinnerProps;
27
+ _defineView: () => UiTypes.LottieOptions;
28
+ constructor({ props, layout }: {
29
+ props: Partial<AndroidStyleSpinnerProps>;
30
+ layout?: (make: MASConstraintMaker, view: UILottieView) => void;
31
+ }) {
32
+ super();
33
+ this._props = {
34
+ weight: 2,
35
+ diameter: 24,
36
+ color: $color("gray"),
37
+ bgcolor: $color("clear"),
38
+ ...props
39
+ };
40
+ this._defineView = () => {
41
+ const weight = this._props.weight;
42
+ const color = this._props.color;
43
+ const r = color.components.red / 255;
44
+ const g = color.components.green / 255;
45
+ const b = color.components.blue / 255;
46
+ const a = color.components.alpha;
47
+ const json = {
48
+ v: "5.5.7",
49
+ fr: 60,
50
+ ip: 0,
51
+ op: 120,
52
+ w: 24,
53
+ h: 24,
54
+ nm: "spinner",
55
+ ddd: 0,
56
+ assets: [],
57
+ layers: [
58
+ {
59
+ ddd: 0,
60
+ ind: 1,
61
+ ty: 4,
62
+ nm: "circle",
63
+ sr: 1,
64
+ ks: {
65
+ o: { a: 0, k: 100, ix: 11 },
66
+ r: {
67
+ a: 1,
68
+ k: [
69
+ {
70
+ i: { x: [0.833], y: [0.833] },
71
+ o: { x: [0.167], y: [0.167] },
72
+ t: 0,
73
+ s: [0]
74
+ },
75
+ {
76
+ t: 119,
77
+ s: [720]
78
+ }
79
+ ],
80
+ ix: 10
81
+ },
82
+ p: { a: 0, k: [12, 12, 0], ix: 2 },
83
+ a: { a: 0, k: [1, 1, 0], ix: 1 },
84
+ s: { a: 0, k: [100, 100, 100], ix: 6 }
85
+ },
86
+ ao: 0,
87
+ shapes: [
88
+ {
89
+ ty: "gr",
90
+ it: [
91
+ {
92
+ ind: 0,
93
+ ty: "sh",
94
+ ix: 1,
95
+ ks: {
96
+ a: 0,
97
+ k: {
98
+ i: [
99
+ [0, -5.523],
100
+ [5.523, 0],
101
+ [0, 5.523],
102
+ [-5.523, 0]
103
+ ],
104
+ o: [
105
+ [0, 5.523],
106
+ [-5.523, 0],
107
+ [0, -5.523],
108
+ [5.523, 0]
109
+ ],
110
+ v: [
111
+ [11, 1],
112
+ [1, 11],
113
+ [-9, 1],
114
+ [1, -9]
115
+ ],
116
+ c: true
117
+ },
118
+ ix: 2
119
+ },
120
+ nm: "Path 1",
121
+ mn: "ADBE Vector Shape - Group",
122
+ hd: false
123
+ },
124
+ {
125
+ ty: "mm",
126
+ mm: 3,
127
+ nm: "Merge Paths 1",
128
+ mn: "ADBE Vector Filter - Merge",
129
+ hd: false
130
+ },
131
+ {
132
+ ty: "tm",
133
+ s: {
134
+ a: 1,
135
+ k: [
136
+ {
137
+ i: { x: [0.833], y: [0.833] },
138
+ o: { x: [0.167], y: [0.167] },
139
+ t: 0,
140
+ s: [0]
141
+ },
142
+ {
143
+ i: { x: [0.833], y: [0.833] },
144
+ o: { x: [0.167], y: [0.167] },
145
+ t: 60,
146
+ s: [0]
147
+ },
148
+ {
149
+ i: { x: [0.833], y: [0.833] },
150
+ o: { x: [0.167], y: [0.167] },
151
+ t: 90,
152
+ s: [60]
153
+ },
154
+ {
155
+ t: 119,
156
+ s: [100]
157
+ }
158
+ ],
159
+ ix: 1
160
+ },
161
+ e: {
162
+ a: 1,
163
+ k: [
164
+ {
165
+ i: { x: [0.833], y: [0.833] },
166
+ o: { x: [0.167], y: [0.167] },
167
+ t: 0,
168
+ s: [0]
169
+ },
170
+ {
171
+ i: { x: [0.833], y: [0.833] },
172
+ o: { x: [0.167], y: [0.167] },
173
+ t: 30,
174
+ s: [70]
175
+ },
176
+ {
177
+ i: { x: [0.833], y: [0.833] },
178
+ o: { x: [0.167], y: [0.167] },
179
+ t: 60,
180
+ s: [90]
181
+ },
182
+ {
183
+ i: { x: [0.833], y: [0.833] },
184
+ o: { x: [0.167], y: [0.167] },
185
+ t: 90,
186
+ s: [90]
187
+ },
188
+ {
189
+ t: 119,
190
+ s: [99]
191
+ }
192
+ ],
193
+ ix: 2
194
+ },
195
+ o: { a: 0, k: 0, ix: 3 },
196
+ m: 1,
197
+ ix: 3,
198
+ nm: "Trim Paths 1",
199
+ mn: "ADBE Vector Filter - Trim",
200
+ hd: false
201
+ },
202
+ {
203
+ ty: "st",
204
+ c: { a: 0, k: [r, g, b, a], ix: 3 },
205
+ o: { a: 0, k: 100, ix: 4 },
206
+ w: { a: 0, k: weight, ix: 5 },
207
+ lc: 2,
208
+ lj: 1,
209
+ ml: 4,
210
+ bm: 0,
211
+ nm: "Stroke 1",
212
+ mn: "ADBE Vector Graphic - Stroke",
213
+ hd: false
214
+ },
215
+ {
216
+ ty: "tr",
217
+ p: { a: 0, k: [0, 0], ix: 2 },
218
+ a: { a: 0, k: [0, 0], ix: 1 },
219
+ s: { a: 0, k: [100, 100], ix: 3 },
220
+ r: { a: 0, k: 0, ix: 6 },
221
+ o: { a: 0, k: 100, ix: 7 },
222
+ sk: { a: 0, k: 0, ix: 4 },
223
+ sa: { a: 0, k: 0, ix: 5 },
224
+ nm: "Transform"
225
+ }
226
+ ],
227
+ nm: "circle",
228
+ np: 4,
229
+ cix: 2,
230
+ bm: 0,
231
+ ix: 1,
232
+ mn: "ADBE Vector Group",
233
+ hd: false
234
+ }
235
+ ],
236
+ ip: 0,
237
+ op: 120,
238
+ st: 0,
239
+ bm: 0
240
+ }
241
+ ],
242
+ markers: []
243
+ };
244
+ return {
245
+ type: "lottie",
246
+ props: {
247
+ loop: true,
248
+ contentMode: 1,
249
+ circular: true,
250
+ json,
251
+ bgcolor: this._props.bgcolor,
252
+ id: this.id
253
+ },
254
+ layout: layout || ((make, view) => {
255
+ make.size.equalTo($size(this._props.diameter, this._props.diameter));
256
+ make.center.equalTo(view.super);
257
+ }),
258
+ events: {
259
+ ready: sender => sender.play({})
260
+ }
261
+ };
262
+ }
263
+ }
264
+ }