bare-ui-kit 0.2.0 → 0.3.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 (89) hide show
  1. package/CMakeLists.txt +7 -1
  2. package/README.md +42 -1
  3. package/binding.m +558 -2
  4. package/index.d.ts +41 -0
  5. package/index.js +16 -0
  6. package/lib/activity-indicator-view.d.ts +29 -0
  7. package/lib/activity-indicator-view.h +181 -0
  8. package/lib/activity-indicator-view.js +56 -0
  9. package/lib/alert-action.d.ts +33 -0
  10. package/lib/alert-action.js +48 -0
  11. package/lib/alert-controller.d.ts +20 -0
  12. package/lib/alert-controller.h +199 -0
  13. package/lib/alert-controller.js +33 -0
  14. package/lib/attributed-string.d.ts +45 -0
  15. package/lib/attributed-string.h +176 -0
  16. package/lib/attributed-string.js +51 -0
  17. package/lib/attributes.js +34 -0
  18. package/lib/bezier-path.d.ts +26 -0
  19. package/lib/bezier-path.h +145 -0
  20. package/lib/bezier-path.js +51 -0
  21. package/lib/bridging.h +600 -2
  22. package/lib/color.d.ts +86 -0
  23. package/lib/color.h +286 -0
  24. package/lib/color.js +170 -0
  25. package/lib/events.js +35 -0
  26. package/lib/font-descriptor.d.ts +30 -0
  27. package/lib/font-descriptor.h +96 -0
  28. package/lib/font-descriptor.js +47 -0
  29. package/lib/font-metrics.d.ts +38 -0
  30. package/lib/font-metrics.h +109 -0
  31. package/lib/font-metrics.js +58 -0
  32. package/lib/font.d.ts +59 -0
  33. package/lib/font.h +424 -0
  34. package/lib/font.js +100 -0
  35. package/lib/handle.d.ts +5 -0
  36. package/lib/handle.js +6 -0
  37. package/lib/image-view.d.ts +15 -0
  38. package/lib/image-view.h +75 -0
  39. package/lib/image-view.js +27 -0
  40. package/lib/image.d.ts +37 -0
  41. package/lib/image.h +205 -0
  42. package/lib/image.js +60 -0
  43. package/lib/label.d.ts +51 -0
  44. package/lib/label.h +331 -0
  45. package/lib/label.js +94 -0
  46. package/lib/paragraph-style.d.ts +20 -0
  47. package/lib/paragraph-style.h +94 -0
  48. package/lib/paragraph-style.js +42 -0
  49. package/lib/pasteboard.d.ts +31 -0
  50. package/lib/pasteboard.h +123 -0
  51. package/lib/pasteboard.js +63 -0
  52. package/lib/retain.js +12 -0
  53. package/lib/runtime.m +92 -15
  54. package/lib/scene.d.ts +30 -0
  55. package/lib/scene.h +87 -0
  56. package/lib/scene.js +48 -0
  57. package/lib/scratch.js +4 -0
  58. package/lib/screen.d.ts +26 -0
  59. package/lib/screen.h +194 -0
  60. package/lib/screen.js +52 -0
  61. package/lib/scroll-view.d.ts +39 -0
  62. package/lib/scroll-view.h +246 -0
  63. package/lib/scroll-view.js +64 -0
  64. package/lib/switch.d.ts +22 -0
  65. package/lib/switch.h +166 -0
  66. package/lib/switch.js +42 -0
  67. package/lib/text-field.d.ts +103 -0
  68. package/lib/text-field.h +562 -0
  69. package/lib/text-field.js +183 -0
  70. package/lib/text-view.d.ts +59 -0
  71. package/lib/text-view.h +497 -0
  72. package/lib/text-view.js +138 -0
  73. package/lib/view-controller.d.ts +37 -0
  74. package/lib/view-controller.h +108 -20
  75. package/lib/view-controller.js +50 -5
  76. package/lib/view.d.ts +158 -0
  77. package/lib/view.h +1385 -20
  78. package/lib/view.js +276 -7
  79. package/lib/window.d.ts +44 -0
  80. package/lib/window.h +167 -27
  81. package/lib/window.js +62 -9
  82. package/lib/wrap.js +7 -0
  83. package/package.json +12 -3
  84. package/prebuilds/ios-arm64/bare +0 -0
  85. package/prebuilds/ios-arm64/bare-ui-kit.bare +0 -0
  86. package/prebuilds/ios-arm64-simulator/bare +0 -0
  87. package/prebuilds/ios-arm64-simulator/bare-ui-kit.bare +0 -0
  88. package/prebuilds/ios-x64-simulator/bare +0 -0
  89. package/prebuilds/ios-x64-simulator/bare-ui-kit.bare +0 -0
@@ -0,0 +1,45 @@
1
+ import { tag, handle, Handle, Wrapper } from 'bare-foundation-registry'
2
+ import UIKitColor = require('./color')
3
+ import UIKitFont = require('./font')
4
+ import UIKitParagraphStyle = require('./paragraph-style')
5
+
6
+ /** Text with styles, as an `NSMutableAttributedString`. */
7
+ interface UIKitAttributedString {
8
+ readonly string: string
9
+
10
+ readonly length: number
11
+
12
+ /** The styles of the character at `location`. */
13
+ attributesAt(location: number): UIKitAttributedString.Attributes
14
+
15
+ /** Add another attributed string at the end. It can come from another addon. */
16
+ append(other: Wrapper): this
17
+
18
+ /** Add `string` at the end, with `attributes`. */
19
+ appendString(string: string, attributes?: UIKitAttributedString.Attributes): this
20
+
21
+ readonly [tag]: number
22
+
23
+ readonly [handle]: Handle
24
+ }
25
+
26
+ declare class UIKitAttributedString {
27
+ constructor(opts?: { string?: string; attributes?: UIKitAttributedString.Attributes })
28
+ }
29
+
30
+ declare namespace UIKitAttributedString {
31
+ export interface Attributes {
32
+ font?: UIKitFont | null
33
+ foregroundColor?: UIKitColor | null
34
+ backgroundColor?: UIKitColor | null
35
+ paragraphStyle?: UIKitParagraphStyle | null
36
+
37
+ /** Extra space between characters, in points. */
38
+ kern?: number
39
+ baselineOffset?: number
40
+ underlineStyle?: number
41
+ strikethroughStyle?: number
42
+ }
43
+ }
44
+
45
+ export = UIKitAttributedString
@@ -0,0 +1,176 @@
1
+ #import <assert.h>
2
+ #import <bare.h>
3
+ #import <js.h>
4
+
5
+ #import <UIKit/UIKit.h>
6
+
7
+ #import "bridging.h"
8
+
9
+ static js_value_t *
10
+ bare_ui_kit_attributed_string_init(js_env_t *env, js_callback_info_t *info) {
11
+ int err;
12
+
13
+ size_t argc = 2;
14
+ js_value_t *argv[2];
15
+
16
+ bare_ui_kit_state_t *state;
17
+ err = js_get_callback_info(env, info, &argc, argv, NULL, (void **) &state);
18
+ assert(err == 0);
19
+
20
+ assert(argc == 2);
21
+
22
+ js_value_t *result;
23
+
24
+ @autoreleasepool {
25
+ NSString *string = bare_ui_kit__to_string(env, argv[0]);
26
+
27
+ NSDictionary<NSAttributedStringKey, id> *attributes = bare_ui_kit__to_attributes(env, state, argv[1]);
28
+
29
+ NSMutableAttributedString *handle = [[[NSMutableAttributedString alloc]
30
+ initWithString:string ? string : @"" attributes:attributes] autorelease];
31
+
32
+ result = bare_foundation_bridge(env, state->registry, handle);
33
+ }
34
+
35
+ return result;
36
+ }
37
+
38
+ static js_value_t *
39
+ bare_ui_kit_attributed_string_string(js_env_t *env, js_callback_info_t *info) {
40
+ int err;
41
+
42
+ size_t argc = 1;
43
+ js_value_t *argv[1];
44
+
45
+ bare_ui_kit_state_t *state;
46
+ err = js_get_callback_info(env, info, &argc, argv, NULL, (void **) &state);
47
+ assert(err == 0);
48
+
49
+ assert(argc == 1);
50
+
51
+ void *handle;
52
+ if (bare_foundation_read_tag(env, state->registry, argv[0], "handle", &handle) < 0) return NULL;
53
+
54
+ js_value_t *result;
55
+
56
+ @autoreleasepool {
57
+ NSAttributedString *string = (__bridge NSAttributedString *) handle;
58
+
59
+ result = bare_ui_kit__from_string(env, string.string);
60
+ }
61
+
62
+ return result;
63
+ }
64
+
65
+ static js_value_t *
66
+ bare_ui_kit_attributed_string_length(js_env_t *env, js_callback_info_t *info) {
67
+ int err;
68
+
69
+ size_t argc = 1;
70
+ js_value_t *argv[1];
71
+
72
+ bare_ui_kit_state_t *state;
73
+ err = js_get_callback_info(env, info, &argc, argv, NULL, (void **) &state);
74
+ assert(err == 0);
75
+
76
+ assert(argc == 1);
77
+
78
+ void *handle;
79
+ if (bare_foundation_read_tag(env, state->registry, argv[0], "handle", &handle) < 0) return NULL;
80
+
81
+ js_value_t *result;
82
+
83
+ @autoreleasepool {
84
+ NSAttributedString *string = (__bridge NSAttributedString *) handle;
85
+
86
+ err = js_create_uint32(env, (uint32_t) string.length, &result);
87
+ assert(err == 0);
88
+ }
89
+
90
+ return result;
91
+ }
92
+
93
+ static js_value_t *
94
+ bare_ui_kit_attributed_string_attributes_at(js_env_t *env, js_callback_info_t *info) {
95
+ int err;
96
+
97
+ size_t argc = 2;
98
+ js_value_t *argv[2];
99
+
100
+ bare_ui_kit_state_t *state;
101
+ err = js_get_callback_info(env, info, &argc, argv, NULL, (void **) &state);
102
+ assert(err == 0);
103
+
104
+ assert(argc == 2);
105
+
106
+ void *handle;
107
+ if (bare_foundation_read_tag(env, state->registry, argv[0], "handle", &handle) < 0) return NULL;
108
+
109
+ uint32_t location;
110
+ if (!bare_ui_kit__read_uint32(env, argv[1], "location", &location)) return NULL;
111
+
112
+ js_value_t *result;
113
+
114
+ @autoreleasepool {
115
+ NSAttributedString *string = (__bridge NSAttributedString *) handle;
116
+
117
+ result = bare_ui_kit__from_attributes(env, state, [string attributesAtIndex:location effectiveRange:NULL]);
118
+ }
119
+
120
+ return result;
121
+ }
122
+
123
+ static js_value_t *
124
+ bare_ui_kit_attributed_string_append(js_env_t *env, js_callback_info_t *info) {
125
+ int err;
126
+
127
+ size_t argc = 2;
128
+ js_value_t *argv[2];
129
+
130
+ bare_ui_kit_state_t *state;
131
+ err = js_get_callback_info(env, info, &argc, argv, NULL, (void **) &state);
132
+ assert(err == 0);
133
+
134
+ assert(argc == 2);
135
+
136
+ void *handle;
137
+ if (bare_foundation_read_tag(env, state->registry, argv[0], "handle", &handle) < 0) return NULL;
138
+
139
+ @autoreleasepool {
140
+ NSMutableAttributedString *string = (__bridge NSMutableAttributedString *) handle;
141
+
142
+ [string appendAttributedString:bare_foundation_to_object(env, state->registry, argv[1])];
143
+ }
144
+
145
+ return NULL;
146
+ }
147
+
148
+ static js_value_t *
149
+ bare_ui_kit_attributed_string_append_string(js_env_t *env, js_callback_info_t *info) {
150
+ int err;
151
+
152
+ size_t argc = 3;
153
+ js_value_t *argv[3];
154
+
155
+ bare_ui_kit_state_t *state;
156
+ err = js_get_callback_info(env, info, &argc, argv, NULL, (void **) &state);
157
+ assert(err == 0);
158
+
159
+ assert(argc == 3);
160
+
161
+ void *handle;
162
+ if (bare_foundation_read_tag(env, state->registry, argv[0], "handle", &handle) < 0) return NULL;
163
+
164
+ @autoreleasepool {
165
+ NSMutableAttributedString *string = (__bridge NSMutableAttributedString *) handle;
166
+
167
+ NSString *appended = bare_ui_kit__to_string(env, argv[1]);
168
+
169
+ NSDictionary<NSAttributedStringKey, id> *attributes = bare_ui_kit__to_attributes(env, state, argv[2]);
170
+
171
+ [string appendAttributedString:[[[NSAttributedString alloc]
172
+ initWithString:appended ? appended : @"" attributes:attributes] autorelease]];
173
+ }
174
+
175
+ return NULL;
176
+ }
@@ -0,0 +1,51 @@
1
+ const binding = require('../binding')
2
+ const registry = require('bare-foundation-registry')
3
+ const { adopt } = require('./handle')
4
+ const { wrapAttributes, unwrapAttributes } = require('./attributes')
5
+
6
+ module.exports = exports = class UIKitAttributedString {
7
+ constructor(opts = {}) {
8
+ const { tag = null, string = '', attributes = {} } = opts
9
+
10
+ this._tag =
11
+ tag === null ? binding.attributedStringInit(string, unwrapAttributes(attributes)) : tag
12
+
13
+ this._token = binding.claim(this._tag, this)
14
+ }
15
+
16
+ get [registry.tag]() {
17
+ return this._tag
18
+ }
19
+
20
+ get [registry.handle]() {
21
+ return binding.handle(this._tag)
22
+ }
23
+
24
+ get string() {
25
+ return binding.attributedStringString(this._tag)
26
+ }
27
+
28
+ get length() {
29
+ return binding.attributedStringLength(this._tag)
30
+ }
31
+
32
+ attributesAt(location) {
33
+ return wrapAttributes(binding.attributedStringAttributesAt(this._tag, location))
34
+ }
35
+
36
+ append(other) {
37
+ binding.attributedStringAppend(this._tag, adopt(other))
38
+ return this
39
+ }
40
+
41
+ appendString(string, attributes = {}) {
42
+ binding.attributedStringAppendString(this._tag, string, unwrapAttributes(attributes))
43
+ return this
44
+ }
45
+
46
+ [Symbol.for('bare.inspect')]() {
47
+ return {
48
+ __proto__: { constructor: UIKitAttributedString }
49
+ }
50
+ }
51
+ }
@@ -0,0 +1,34 @@
1
+ const UIKitColor = require('./color')
2
+ const UIKitFont = require('./font')
3
+ const UIKitParagraphStyle = require('./paragraph-style')
4
+ const wrap = require('./wrap')
5
+
6
+ // Attributes hold wrappers in JavaScript and tags in native code.
7
+ const WRAPPERS = {
8
+ font: UIKitFont,
9
+ foregroundColor: UIKitColor,
10
+ backgroundColor: UIKitColor,
11
+ paragraphStyle: UIKitParagraphStyle
12
+ }
13
+
14
+ exports.unwrapAttributes = function unwrapAttributes(attributes) {
15
+ const result = {}
16
+
17
+ for (const [key, value] of Object.entries(attributes)) {
18
+ result[key] = key in WRAPPERS && value !== null ? value._tag : value
19
+ }
20
+
21
+ return result
22
+ }
23
+
24
+ exports.wrapAttributes = function wrapAttributes(attributes) {
25
+ const result = {}
26
+
27
+ for (const [key, value] of Object.entries(attributes)) {
28
+ const Wrapper = WRAPPERS[key]
29
+
30
+ result[key] = Wrapper ? wrap(Wrapper, value) : value
31
+ }
32
+
33
+ return result
34
+ }
@@ -0,0 +1,26 @@
1
+ import { tag, handle, Handle, Wrapper } from 'bare-foundation-registry'
2
+
3
+ /** A path made of lines and curves, as a `UIBezierPath`. */
4
+ interface UIKitBezierPath {
5
+ moveTo(x: number, y: number): this
6
+
7
+ lineTo(x: number, y: number): this
8
+
9
+ /** Add a curve to `x`, `y`, with the control points `x1`, `y1` and `x2`, `y2`. */
10
+ curveTo(x: number, y: number, x1: number, y1: number, x2: number, y2: number): this
11
+
12
+ /** Add an arc around `x`, `y`. The angles are in radians. */
13
+ addArc(x: number, y: number, radius: number, startAngle: number, endAngle: number): this
14
+
15
+ closePath(): this
16
+
17
+ readonly [tag]: number
18
+
19
+ readonly [handle]: Handle
20
+ }
21
+
22
+ declare class UIKitBezierPath {
23
+ constructor()
24
+ }
25
+
26
+ export = UIKitBezierPath
@@ -0,0 +1,145 @@
1
+ #import <assert.h>
2
+ #import <bare.h>
3
+ #import <js.h>
4
+
5
+ #import <UIKit/UIKit.h>
6
+
7
+ #import "bridging.h"
8
+
9
+ static js_value_t *
10
+ bare_ui_kit_bezier_path_init(js_env_t *env, js_callback_info_t *info) {
11
+ int err;
12
+
13
+ bare_ui_kit_state_t *state;
14
+ err = js_get_callback_info(env, info, NULL, NULL, NULL, (void **) &state);
15
+ assert(err == 0);
16
+
17
+ js_value_t *result;
18
+
19
+ @autoreleasepool {
20
+ result = bare_foundation_bridge(env, state->registry, [UIBezierPath bezierPath]);
21
+ }
22
+
23
+ return result;
24
+ }
25
+
26
+ #define V(name, expr) \
27
+ static js_value_t * \
28
+ bare_ui_kit_bezier_path_##name(js_env_t *env, js_callback_info_t *info) { \
29
+ int err; \
30
+ size_t argc = 3; \
31
+ js_value_t *argv[3]; \
32
+ bare_ui_kit_state_t *state; \
33
+ err = js_get_callback_info(env, info, &argc, argv, NULL, (void **) &state); \
34
+ assert(err == 0); \
35
+ assert(argc == 3); \
36
+ void *handle; \
37
+ if (bare_foundation_read_tag(env, state->registry, argv[0], "handle", &handle) < 0) return NULL; \
38
+ double x, y; \
39
+ err = js_get_value_double(env, argv[1], &x); \
40
+ assert(err == 0); \
41
+ err = js_get_value_double(env, argv[2], &y); \
42
+ assert(err == 0); \
43
+ @autoreleasepool { \
44
+ UIBezierPath *path = (__bridge UIBezierPath *) handle; \
45
+ [path expr:CGPointMake(x, y)]; \
46
+ } \
47
+ return NULL; \
48
+ }
49
+
50
+ V(move_to, moveToPoint)
51
+ V(line_to, addLineToPoint)
52
+ #undef V
53
+
54
+ static js_value_t *
55
+ bare_ui_kit_bezier_path_curve_to(js_env_t *env, js_callback_info_t *info) {
56
+ int err;
57
+
58
+ size_t argc = 7;
59
+ js_value_t *argv[7];
60
+
61
+ bare_ui_kit_state_t *state;
62
+ err = js_get_callback_info(env, info, &argc, argv, NULL, (void **) &state);
63
+ assert(err == 0);
64
+
65
+ assert(argc == 7);
66
+
67
+ void *handle;
68
+ if (bare_foundation_read_tag(env, state->registry, argv[0], "handle", &handle) < 0) return NULL;
69
+
70
+ double values[6];
71
+
72
+ for (int i = 0; i < 6; i++) {
73
+ err = js_get_value_double(env, argv[i + 1], &values[i]);
74
+ assert(err == 0);
75
+ }
76
+
77
+ @autoreleasepool {
78
+ UIBezierPath *path = (__bridge UIBezierPath *) handle;
79
+
80
+ [path addCurveToPoint:CGPointMake(values[0], values[1])
81
+ controlPoint1:CGPointMake(values[2], values[3])
82
+ controlPoint2:CGPointMake(values[4], values[5])];
83
+ }
84
+
85
+ return NULL;
86
+ }
87
+
88
+ static js_value_t *
89
+ bare_ui_kit_bezier_path_add_arc(js_env_t *env, js_callback_info_t *info) {
90
+ int err;
91
+
92
+ size_t argc = 6;
93
+ js_value_t *argv[6];
94
+
95
+ bare_ui_kit_state_t *state;
96
+ err = js_get_callback_info(env, info, &argc, argv, NULL, (void **) &state);
97
+ assert(err == 0);
98
+
99
+ assert(argc == 6);
100
+
101
+ void *handle;
102
+ if (bare_foundation_read_tag(env, state->registry, argv[0], "handle", &handle) < 0) return NULL;
103
+
104
+ double values[5];
105
+
106
+ for (int i = 0; i < 5; i++) {
107
+ err = js_get_value_double(env, argv[i + 1], &values[i]);
108
+ assert(err == 0);
109
+ }
110
+
111
+ @autoreleasepool {
112
+ UIBezierPath *path = (__bridge UIBezierPath *) handle;
113
+
114
+ [path addArcWithCenter:CGPointMake(values[0], values[1])
115
+ radius:values[2]
116
+ startAngle:values[3]
117
+ endAngle:values[4]
118
+ clockwise:YES];
119
+ }
120
+
121
+ return NULL;
122
+ }
123
+
124
+ static js_value_t *
125
+ bare_ui_kit_bezier_path_close(js_env_t *env, js_callback_info_t *info) {
126
+ int err;
127
+
128
+ size_t argc = 1;
129
+ js_value_t *argv[1];
130
+
131
+ bare_ui_kit_state_t *state;
132
+ err = js_get_callback_info(env, info, &argc, argv, NULL, (void **) &state);
133
+ assert(err == 0);
134
+
135
+ assert(argc == 1);
136
+
137
+ void *handle;
138
+ if (bare_foundation_read_tag(env, state->registry, argv[0], "handle", &handle) < 0) return NULL;
139
+
140
+ @autoreleasepool {
141
+ [(__bridge UIBezierPath *) handle closePath];
142
+ }
143
+
144
+ return NULL;
145
+ }
@@ -0,0 +1,51 @@
1
+ const binding = require('../binding')
2
+ const registry = require('bare-foundation-registry')
3
+
4
+ module.exports = exports = class UIKitBezierPath {
5
+ constructor(opts = {}) {
6
+ const { tag = null } = opts
7
+
8
+ this._tag = tag === null ? binding.bezierPathInit() : tag
9
+
10
+ this._token = binding.claim(this._tag, this)
11
+ }
12
+
13
+ get [registry.tag]() {
14
+ return this._tag
15
+ }
16
+
17
+ get [registry.handle]() {
18
+ return binding.handle(this._tag)
19
+ }
20
+
21
+ moveTo(x, y) {
22
+ binding.bezierPathMoveTo(this._tag, x, y)
23
+ return this
24
+ }
25
+
26
+ lineTo(x, y) {
27
+ binding.bezierPathLineTo(this._tag, x, y)
28
+ return this
29
+ }
30
+
31
+ curveTo(x, y, x1, y1, x2, y2) {
32
+ binding.bezierPathCurveTo(this._tag, x, y, x1, y1, x2, y2)
33
+ return this
34
+ }
35
+
36
+ addArc(x, y, radius, startAngle, endAngle) {
37
+ binding.bezierPathAddArc(this._tag, x, y, radius, startAngle, endAngle)
38
+ return this
39
+ }
40
+
41
+ closePath() {
42
+ binding.bezierPathClose(this._tag)
43
+ return this
44
+ }
45
+
46
+ [Symbol.for('bare.inspect')]() {
47
+ return {
48
+ __proto__: { constructor: UIKitBezierPath }
49
+ }
50
+ }
51
+ }