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
package/utils/path.ts ADDED
@@ -0,0 +1,100 @@
1
+ // 用于处理路径的工具函数
2
+
3
+ function _splitProtocol(path: string): [string, string]{
4
+ const regex = /^\w+:\/\//;
5
+ const result = regex.exec(path);
6
+ if (result) {
7
+ const protocol = result[0];
8
+ return [protocol, path.slice(protocol.length)];
9
+ } else {
10
+ return ["", path];
11
+ }
12
+ }
13
+
14
+ // 正规化
15
+ function _normalize(path: string): string {
16
+ if (!path) return "";
17
+ path = path.trim();
18
+ if (!path) return "";
19
+ const [protocol, remainingPath] = _splitProtocol(path);
20
+ return protocol + remainingPath.replace(/\/{2,}/g, "/");
21
+ }
22
+
23
+ export function split(path: string): [string, string]{
24
+ path = _normalize(path);
25
+ const [protocol, remainingPath] = _splitProtocol(path);
26
+ const lastIndex = remainingPath.lastIndexOf("/");
27
+ if (lastIndex === -1) {
28
+ return [protocol, remainingPath];
29
+ } else if (lastIndex === 0) {
30
+ return [protocol + "/", remainingPath.slice(1)];
31
+ } else {
32
+ return [
33
+ protocol + remainingPath.slice(0, lastIndex),
34
+ remainingPath.slice(lastIndex + 1)
35
+ ];
36
+ }
37
+ }
38
+
39
+ export function dirname(path: string): string{
40
+ return split(path)[0];
41
+ }
42
+
43
+ export function basename(path: string): string {
44
+ return split(path)[1];
45
+ }
46
+
47
+ export function extname(path: string): string{
48
+ const _basename = basename(path);
49
+ if (!_basename) return "";
50
+ const components = _basename.split(".");
51
+ if (components.length === 1) {
52
+ return "";
53
+ } else {
54
+ return "." + components.slice(-1)[0];
55
+ }
56
+ }
57
+
58
+ // 拼接目录
59
+ export function join(...args: string[]): string {
60
+ return args
61
+ .map((part, i) => {
62
+ if (i === 0) {
63
+ return part.trim().replace(/[/]*$/g, "");
64
+ } else {
65
+ return part.trim().replace(/(^[/]*|[/]*$)/g, "");
66
+ }
67
+ })
68
+ .filter(x => x.length)
69
+ .join("/");
70
+ }
71
+
72
+ function _getAttributes(path: string): {
73
+ NSFileCreationDate?: Date;
74
+ NSFileModificationDate?: Date;
75
+ NSFileSize?: number;
76
+ } {
77
+ if (!$file.exists(path)) throw new Error("invalid path");
78
+ path = $file.absolutePath(path);
79
+ const attributesOfItemAtPath = $objc("NSFileManager")
80
+ .invoke("defaultManager")
81
+ .invoke("attributesOfItemAtPath:error", path, null);
82
+ return attributesOfItemAtPath.jsValue();
83
+ }
84
+
85
+ export function getCreationDate(path: string): number{
86
+ const { NSFileCreationDate } = _getAttributes(path);
87
+ if (!NSFileCreationDate) return 0;
88
+ return NSFileCreationDate.getTime();
89
+ }
90
+
91
+ export function getModificationDate(path: string): number{
92
+ const { NSFileModificationDate } = _getAttributes(path);
93
+ if (!NSFileModificationDate) return 0;
94
+ return NSFileModificationDate.getTime();
95
+ }
96
+
97
+ export function getFileSize(path: string): number{
98
+ const { NSFileSize } = _getAttributes(path);
99
+ return NSFileSize || 0;
100
+ }
package/utils/rect.ts ADDED
@@ -0,0 +1,67 @@
1
+ // 用于处理矩形的工具函数
2
+
3
+ // When called without arguments, return the center of the rectangle. When a Point is passed as an argument, the rectangle’s x and y values are adjusted, so that the new center of the rectangle is p.
4
+ export function center(rect: JBRect, point?: JBPoint): JBPoint {
5
+ const { x = 0, y = 0, width: w, height: h } = rect;
6
+ if (!point) return $point(x + w / 2, y + h / 2);
7
+ const { x: px, y: py } = point;
8
+ rect.x = px - w / 2;
9
+ rect.y = py - h / 2;
10
+ return point;
11
+ }
12
+
13
+ // Return true if the given point lies within the bounds of the rectangle, false otherwise.
14
+ export function containsPoint(rect: JBRect, point: JBPoint): boolean {
15
+ const { x, y, width: w, height: h } = rect;
16
+ const { x: px, y: py } = point;
17
+ return x <= px && px <= x + w && y <= py && py <= y + h;
18
+ }
19
+
20
+ // Return true if the given rectangle lies entirely within the bounds of this rectangle, false otherwise.
21
+ export function containsRect(rect: JBRect, otherRect: JBRect): boolean {
22
+ const { x, y, width: w, height: h } = rect;
23
+ const { x: x1, y: y1, width: w1, height: h1 } = otherRect;
24
+ return x <= x1 && y <= y1 && x1 + w1 <= x + w && y1 + h1 <= y + h;
25
+ }
26
+
27
+ // Return true if this rectangle intersects with the other rectangle, false otherwise.
28
+ export function intersects(rect: JBRect, otherRect: JBRect): boolean {
29
+ const { x, y, width: w, height: h } = rect;
30
+ const { x: x1, y: y1, width: w1, height: h1 } = otherRect;
31
+ return x < x1 + w1 && x1 < x + w && y < y1 + h1 && y1 < y + h;
32
+ }
33
+
34
+ // Return a $rect that corresponds to the intersection of this rectangle with the other one.
35
+ export function intersection(rect: JBRect, otherRect: JBRect): JBRect {
36
+ const { x, y, width: w, height: h } = rect;
37
+ const { x: x1, y: y1, width: w1, height: h1 } = otherRect;
38
+ const nx = Math.max(x, x1);
39
+ const nw = Math.min(x + w, x1 + w1) - nx;
40
+ const ny = Math.max(y, y1);
41
+ const nh = Math.min(y + h, y1 + h1) - ny;
42
+ return $rect(nx, ny, nw, nh);
43
+ }
44
+
45
+ // Return the smallest $rect that encloses both rectangles.
46
+ export function union(rect: JBRect, otherRect: JBRect): JBRect {
47
+ const { x, y, width: w, height: h } = rect;
48
+ const { x: x1, y: y1, width: w1, height: h1 } = otherRect;
49
+ const nx = Math.min(x, x1);
50
+ const nw = Math.max(x + w, x1 + w1) - nx;
51
+ const ny = Math.min(y, y1);
52
+ const nh = Math.max(y + h, y1 + h1) - ny;
53
+ return $rect(nx, ny, nw, nh);
54
+ }
55
+ // Equivalent to $rect(r.x + x, r.y + y, r.w, r.h)
56
+ export function translate(rect: JBRect, point: JBPoint): JBRect {
57
+ const { x, y, width, height } = rect;
58
+ const { x: x1, y: y1 } = point;
59
+ return $rect(x + x1, y + y1, width, height);
60
+ }
61
+
62
+ // Return a $rect that is adjusted by the given edge insets.
63
+ export function inset(rect: JBRect, insets: JBInsets): JBRect {
64
+ const { x, y, width, height } = rect;
65
+ const { top, left, bottom, right } = insets;
66
+ return $rect(x + left, y + top, width - left - right, height - top - bottom);
67
+ }
@@ -0,0 +1,117 @@
1
+ // 用于UI相关的工具函数
2
+
3
+ // 立即获得window size
4
+ export function getWindowSize(): JBSize {
5
+ const window = $objc("UIWindow").$keyWindow().jsValue();
6
+ return window.size;
7
+ }
8
+
9
+ // 获取单行字符串应有的宽度
10
+ // 默认额外添加3 inset
11
+ export function getTextWidth(
12
+ text: string,
13
+ { font = $font(17), inset = 3 } = {}
14
+ ): number {
15
+ return (
16
+ Math.ceil(
17
+ $text.sizeThatFits({
18
+ text,
19
+ width: 10000,
20
+ font,
21
+ lineSpacing: 0
22
+ }).width
23
+ ) + inset
24
+ );
25
+ }
26
+
27
+ // 获取字符串指定宽度后应有的高度
28
+ // 默认额外添加3 inset
29
+ export function getTextHeight(
30
+ text: string,
31
+ { width = 300, font = $font(17), inset = 3 } = {}
32
+ ): number {
33
+ return (
34
+ Math.ceil(
35
+ $text.sizeThatFits({
36
+ text,
37
+ width,
38
+ font,
39
+ lineSpacing: 0
40
+ }).height
41
+ ) + inset
42
+ );
43
+ }
44
+
45
+ // 计算某个view在某个上级view(若不指定则为UIWindow)上的绝对frame
46
+ // 此方法不考虑旋转变形等特殊情况
47
+ export function absoluteFrame(view: AllUIView, endView?: AllUIView): JBRect {
48
+ const frame = view.frame;
49
+ let superView = view.super;
50
+ while (superView) {
51
+ frame.x += superView.frame.x - superView.bounds.x;
52
+ frame.y += superView.frame.y - superView.bounds.y;
53
+ if (endView && superView === endView) break;
54
+ superView = superView.super;
55
+ }
56
+ return frame;
57
+ }
58
+
59
+ export const layerCommonOptions = {
60
+ none: {
61
+ cornerRadius: 0,
62
+ shadowRadius: 0,
63
+ shadowOpacity: 0,
64
+ shadowOffset: $size(0, 0),
65
+ shadowColor: $color("clear")
66
+ },
67
+ roundedShadow: {
68
+ cornerRadius: 12,
69
+ shadowRadius: 10,
70
+ shadowOpacity: 1,
71
+ shadowOffset: $size(0, 0),
72
+ shadowColor: $color("black")
73
+ },
74
+ textShadow: {
75
+ cornerRadius: 0,
76
+ shadowRadius: 1.2,
77
+ shadowOpacity: 1,
78
+ shadowOffset: $size(0, 1),
79
+ shadowColor: $color("black")
80
+ },
81
+ circleViewShadow: {
82
+ cornerRadius: 25,
83
+ shadowRadius: 3,
84
+ shadowOpacity: 0.6,
85
+ shadowOffset: $size(0, 3),
86
+ shadowColor: $color("black")
87
+ },
88
+ toastShadows: {
89
+ cornerRadius: 15,
90
+ shadowRadius: 8,
91
+ shadowOpacity: 0.35,
92
+ shadowOffset: $size(0, 0),
93
+ shadowColor: $color("black")
94
+ }
95
+ };
96
+
97
+ // 在layout中使用
98
+ // 所应用的view不可以指定radius和clipTobounds,否则无效
99
+ export function setLayer(
100
+ view: AllUIView,
101
+ {
102
+ cornerRadius = 0,
103
+ shadowRadius = 0,
104
+ shadowOpacity = 0,
105
+ shadowOffset = $size(0, 0),
106
+ shadowColor = $color("clear")
107
+ } = {}
108
+ ): void {
109
+ const layer = view.ocValue().invoke("layer");
110
+ layer.invoke("setCornerRadius", cornerRadius);
111
+ layer.invoke("setShadowRadius", shadowRadius);
112
+ layer.invoke("setShadowOpacity", shadowOpacity);
113
+ layer.invoke("setShadowOffset", shadowOffset);
114
+ layer.invoke("setShadowColor", shadowColor.ocValue().invoke("CGColor"));
115
+ }
116
+
117
+