onejs-core 0.3.5

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 (63) hide show
  1. package/.gitattributes +2 -0
  2. package/.github/workflows/jsr.yml +19 -0
  3. package/.prettierrc +5 -0
  4. package/3rdparty/preact/LICENSE +21 -0
  5. package/3rdparty/preact/clone-element.ts +45 -0
  6. package/3rdparty/preact/compat/Children.ts +21 -0
  7. package/3rdparty/preact/compat/forwardRef.ts +49 -0
  8. package/3rdparty/preact/compat/index.ts +3 -0
  9. package/3rdparty/preact/compat/memo.ts +34 -0
  10. package/3rdparty/preact/compat/util.ts +38 -0
  11. package/3rdparty/preact/component.ts +235 -0
  12. package/3rdparty/preact/constants.ts +3 -0
  13. package/3rdparty/preact/create-context.ts +71 -0
  14. package/3rdparty/preact/create-element.ts +98 -0
  15. package/3rdparty/preact/diff/catch-error.ts +40 -0
  16. package/3rdparty/preact/diff/children.ts +355 -0
  17. package/3rdparty/preact/diff/index.ts +563 -0
  18. package/3rdparty/preact/diff/props.ts +174 -0
  19. package/3rdparty/preact/hooks/index.ts +536 -0
  20. package/3rdparty/preact/hooks/internal.d.ts +85 -0
  21. package/3rdparty/preact/hooks.d.ts +145 -0
  22. package/3rdparty/preact/index.ts +13 -0
  23. package/3rdparty/preact/internal.d.ts +155 -0
  24. package/3rdparty/preact/jsx-runtime/index.ts +80 -0
  25. package/3rdparty/preact/jsx.d.ts +1008 -0
  26. package/3rdparty/preact/options.ts +16 -0
  27. package/3rdparty/preact/preact.d.ts +317 -0
  28. package/3rdparty/preact/render.ts +76 -0
  29. package/3rdparty/preact/signals/index.ts +443 -0
  30. package/3rdparty/preact/signals/internal.d.ts +36 -0
  31. package/3rdparty/preact/signals-core/index.ts +663 -0
  32. package/3rdparty/preact/style.d.ts +205 -0
  33. package/3rdparty/preact/util.ts +29 -0
  34. package/@DO_NOT_CHANGE.txt +3 -0
  35. package/README.md +33 -0
  36. package/definitions/app.d.ts +52048 -0
  37. package/definitions/augments.d.ts +16 -0
  38. package/definitions/globals.d.ts +34 -0
  39. package/definitions/index.d.ts +9 -0
  40. package/definitions/jsx.d.ts +517 -0
  41. package/definitions/modules.d.ts +29 -0
  42. package/definitions/onejs.d.ts +164 -0
  43. package/definitions/preact.jsx.d.ts +7 -0
  44. package/definitions/proto-overrides.d.ts +13 -0
  45. package/definitions/puerts.d.ts +31 -0
  46. package/definitions/unity-engine.d.ts +23 -0
  47. package/hooks/eventful.ts +56 -0
  48. package/import-transform.mjs +42 -0
  49. package/index.ts +44 -0
  50. package/jsr.json +10 -0
  51. package/onejs-tw-config.cjs +188 -0
  52. package/package.json +9 -0
  53. package/preloads/inject.ts +44 -0
  54. package/styling/index.tsx +80 -0
  55. package/styling/utils/generateAlphabeticName.ts +21 -0
  56. package/styling/utils/generateComponentId.ts +6 -0
  57. package/styling/utils/hash.ts +46 -0
  58. package/switch.cjs +185 -0
  59. package/uss-transform-plugin.cjs +83 -0
  60. package/utils/color-palettes.ts +3 -0
  61. package/utils/color-parser.ts +249 -0
  62. package/utils/float-parser.ts +31 -0
  63. package/utils/index.ts +12 -0
@@ -0,0 +1,249 @@
1
+ // import { float4, float3, quaternion } from "Unity/Mathematics" // JSR prepends a "./" to this, which messes things up
2
+ // import { Color } from "UnityEngine" // TODO Somehow this bypasses unity-import-transform and leads to esbuild error
3
+
4
+ type float4 = CS.Unity.Mathematics.float4
5
+ const { float4: f4, float3: f3, PI } = CS.Unity.Mathematics.math
6
+ const { Color } = CS.UnityEngine
7
+
8
+ /*
9
+ https://github.com/deanm/css-color-parser-js
10
+
11
+ Minor changes were made for TS compatibility. Original License below:
12
+
13
+ (c) Dean McNamee <dean@gmail.com>, 2012.
14
+
15
+ Permission is hereby granted, free of charge, to any person obtaining a copy
16
+ of this software and associated documentation files (the "Software"), to
17
+ deal in the Software without restriction, including without limitation the
18
+ rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
19
+ sell copies of the Software, and to permit persons to whom the Software is
20
+ furnished to do so, subject to the following conditions:
21
+
22
+ The above copyright notice and this permission notice shall be included in
23
+ all copies or substantial portions of the Software.
24
+
25
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
26
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
27
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
28
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
29
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
30
+ FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
31
+ IN THE SOFTWARE.
32
+ */
33
+
34
+ var kCSSColorTable = {
35
+ "transparent": [0, 0, 0, 0], "aliceblue": [240, 248, 255, 1],
36
+ "antiquewhite": [250, 235, 215, 1], "aqua": [0, 255, 255, 1],
37
+ "aquamarine": [127, 255, 212, 1], "azure": [240, 255, 255, 1],
38
+ "beige": [245, 245, 220, 1], "bisque": [255, 228, 196, 1],
39
+ "black": [0, 0, 0, 1], "blanchedalmond": [255, 235, 205, 1],
40
+ "blue": [0, 0, 255, 1], "blueviolet": [138, 43, 226, 1],
41
+ "brown": [165, 42, 42, 1], "burlywood": [222, 184, 135, 1],
42
+ "cadetblue": [95, 158, 160, 1], "chartreuse": [127, 255, 0, 1],
43
+ "chocolate": [210, 105, 30, 1], "coral": [255, 127, 80, 1],
44
+ "cornflowerblue": [100, 149, 237, 1], "cornsilk": [255, 248, 220, 1],
45
+ "crimson": [220, 20, 60, 1], "cyan": [0, 255, 255, 1],
46
+ "darkblue": [0, 0, 139, 1], "darkcyan": [0, 139, 139, 1],
47
+ "darkgoldenrod": [184, 134, 11, 1], "darkgray": [169, 169, 169, 1],
48
+ "darkgreen": [0, 100, 0, 1], "darkgrey": [169, 169, 169, 1],
49
+ "darkkhaki": [189, 183, 107, 1], "darkmagenta": [139, 0, 139, 1],
50
+ "darkolivegreen": [85, 107, 47, 1], "darkorange": [255, 140, 0, 1],
51
+ "darkorchid": [153, 50, 204, 1], "darkred": [139, 0, 0, 1],
52
+ "darksalmon": [233, 150, 122, 1], "darkseagreen": [143, 188, 143, 1],
53
+ "darkslateblue": [72, 61, 139, 1], "darkslategray": [47, 79, 79, 1],
54
+ "darkslategrey": [47, 79, 79, 1], "darkturquoise": [0, 206, 209, 1],
55
+ "darkviolet": [148, 0, 211, 1], "deeppink": [255, 20, 147, 1],
56
+ "deepskyblue": [0, 191, 255, 1], "dimgray": [105, 105, 105, 1],
57
+ "dimgrey": [105, 105, 105, 1], "dodgerblue": [30, 144, 255, 1],
58
+ "firebrick": [178, 34, 34, 1], "floralwhite": [255, 250, 240, 1],
59
+ "forestgreen": [34, 139, 34, 1], "fuchsia": [255, 0, 255, 1],
60
+ "gainsboro": [220, 220, 220, 1], "ghostwhite": [248, 248, 255, 1],
61
+ "gold": [255, 215, 0, 1], "goldenrod": [218, 165, 32, 1],
62
+ "gray": [128, 128, 128, 1], "green": [0, 128, 0, 1],
63
+ "greenyellow": [173, 255, 47, 1], "grey": [128, 128, 128, 1],
64
+ "honeydew": [240, 255, 240, 1], "hotpink": [255, 105, 180, 1],
65
+ "indianred": [205, 92, 92, 1], "indigo": [75, 0, 130, 1],
66
+ "ivory": [255, 255, 240, 1], "khaki": [240, 230, 140, 1],
67
+ "lavender": [230, 230, 250, 1], "lavenderblush": [255, 240, 245, 1],
68
+ "lawngreen": [124, 252, 0, 1], "lemonchiffon": [255, 250, 205, 1],
69
+ "lightblue": [173, 216, 230, 1], "lightcoral": [240, 128, 128, 1],
70
+ "lightcyan": [224, 255, 255, 1], "lightgoldenrodyellow": [250, 250, 210, 1],
71
+ "lightgray": [211, 211, 211, 1], "lightgreen": [144, 238, 144, 1],
72
+ "lightgrey": [211, 211, 211, 1], "lightpink": [255, 182, 193, 1],
73
+ "lightsalmon": [255, 160, 122, 1], "lightseagreen": [32, 178, 170, 1],
74
+ "lightskyblue": [135, 206, 250, 1], "lightslategray": [119, 136, 153, 1],
75
+ "lightslategrey": [119, 136, 153, 1], "lightsteelblue": [176, 196, 222, 1],
76
+ "lightyellow": [255, 255, 224, 1], "lime": [0, 255, 0, 1],
77
+ "limegreen": [50, 205, 50, 1], "linen": [250, 240, 230, 1],
78
+ "magenta": [255, 0, 255, 1], "maroon": [128, 0, 0, 1],
79
+ "mediumaquamarine": [102, 205, 170, 1], "mediumblue": [0, 0, 205, 1],
80
+ "mediumorchid": [186, 85, 211, 1], "mediumpurple": [147, 112, 219, 1],
81
+ "mediumseagreen": [60, 179, 113, 1], "mediumslateblue": [123, 104, 238, 1],
82
+ "mediumspringgreen": [0, 250, 154, 1], "mediumturquoise": [72, 209, 204, 1],
83
+ "mediumvioletred": [199, 21, 133, 1], "midnightblue": [25, 25, 112, 1],
84
+ "mintcream": [245, 255, 250, 1], "mistyrose": [255, 228, 225, 1],
85
+ "moccasin": [255, 228, 181, 1], "navajowhite": [255, 222, 173, 1],
86
+ "navy": [0, 0, 128, 1], "oldlace": [253, 245, 230, 1],
87
+ "olive": [128, 128, 0, 1], "olivedrab": [107, 142, 35, 1],
88
+ "orange": [255, 165, 0, 1], "orangered": [255, 69, 0, 1],
89
+ "orchid": [218, 112, 214, 1], "palegoldenrod": [238, 232, 170, 1],
90
+ "palegreen": [152, 251, 152, 1], "paleturquoise": [175, 238, 238, 1],
91
+ "palevioletred": [219, 112, 147, 1], "papayawhip": [255, 239, 213, 1],
92
+ "peachpuff": [255, 218, 185, 1], "peru": [205, 133, 63, 1],
93
+ "pink": [255, 192, 203, 1], "plum": [221, 160, 221, 1],
94
+ "powderblue": [176, 224, 230, 1], "purple": [128, 0, 128, 1],
95
+ "rebeccapurple": [102, 51, 153, 1],
96
+ "red": [255, 0, 0, 1], "rosybrown": [188, 143, 143, 1],
97
+ "royalblue": [65, 105, 225, 1], "saddlebrown": [139, 69, 19, 1],
98
+ "salmon": [250, 128, 114, 1], "sandybrown": [244, 164, 96, 1],
99
+ "seagreen": [46, 139, 87, 1], "seashell": [255, 245, 238, 1],
100
+ "sienna": [160, 82, 45, 1], "silver": [192, 192, 192, 1],
101
+ "skyblue": [135, 206, 235, 1], "slateblue": [106, 90, 205, 1],
102
+ "slategray": [112, 128, 144, 1], "slategrey": [112, 128, 144, 1],
103
+ "snow": [255, 250, 250, 1], "springgreen": [0, 255, 127, 1],
104
+ "steelblue": [70, 130, 180, 1], "tan": [210, 180, 140, 1],
105
+ "teal": [0, 128, 128, 1], "thistle": [216, 191, 216, 1],
106
+ "tomato": [255, 99, 71, 1], "turquoise": [64, 224, 208, 1],
107
+ "violet": [238, 130, 238, 1], "wheat": [245, 222, 179, 1],
108
+ "white": [255, 255, 255, 1], "whitesmoke": [245, 245, 245, 1],
109
+ "yellow": [255, 255, 0, 1], "yellowgreen": [154, 205, 50, 1]
110
+ }
111
+
112
+ function clamp_css_byte(i: number) { // Clamp to integer 0 .. 255.
113
+ i = Math.round(i); // Seems to be what Chrome does (vs truncation).
114
+ return i < 0 ? 0 : i > 255 ? 255 : i;
115
+ }
116
+
117
+ function clamp_css_float(f: number) { // Clamp to float 0.0 .. 1.0.
118
+ return f < 0 ? 0 : f > 1 ? 1 : f;
119
+ }
120
+
121
+ function parse_css_int(str: string) { // int or percentage.
122
+ if (str[str.length - 1] === '%')
123
+ return clamp_css_byte(parseFloat(str) / 100 * 255);
124
+ return clamp_css_byte(parseInt(str));
125
+ }
126
+
127
+ function parse_css_float(str: string) { // float or percentage.
128
+ if (str[str.length - 1] === '%')
129
+ return clamp_css_float(parseFloat(str) / 100);
130
+ return clamp_css_float(parseFloat(str));
131
+ }
132
+
133
+ function css_hue_to_rgb(m1: number, m2: number, h: number) {
134
+ if (h < 0) h += 1;
135
+ else if (h > 1) h -= 1;
136
+
137
+ if (h * 6 < 1) return m1 + (m2 - m1) * h * 6;
138
+ if (h * 2 < 1) return m2;
139
+ if (h * 3 < 2) return m1 + (m2 - m1) * (2 / 3 - h) * 6;
140
+ return m1;
141
+ }
142
+
143
+ function parseCSSColor(css_str: string): number[] | null {
144
+ // Remove all whitespace, not compliant, but should just be more accepting.
145
+ var str = css_str.replace(/ /g, '').toLowerCase();
146
+
147
+ // Color keywords (and transparent) lookup.
148
+ if (str in kCSSColorTable) return (kCSSColorTable as { [key: string]: number[] })[str].slice(); // dup.
149
+
150
+ // #abc and #abc123 syntax.
151
+ if (str[0] === '#') {
152
+ if (str.length === 4) {
153
+ var iv = parseInt(str.substr(1), 16); // TODO(deanm): Stricter parsing.
154
+ if (!(iv >= 0 && iv <= 0xfff)) return null; // Covers NaN.
155
+ return [((iv & 0xf00) >> 4) | ((iv & 0xf00) >> 8),
156
+ (iv & 0xf0) | ((iv & 0xf0) >> 4),
157
+ (iv & 0xf) | ((iv & 0xf) << 4),
158
+ 1];
159
+ } else if (str.length === 7) {
160
+ var iv = parseInt(str.substr(1), 16); // TODO(deanm): Stricter parsing.
161
+ if (!(iv >= 0 && iv <= 0xffffff)) return null; // Covers NaN.
162
+ return [(iv & 0xff0000) >> 16,
163
+ (iv & 0xff00) >> 8,
164
+ iv & 0xff,
165
+ 1];
166
+ }
167
+
168
+ return null;
169
+ }
170
+
171
+ var op = str.indexOf('('), ep = str.indexOf(')');
172
+ if (op !== -1 && ep + 1 === str.length) {
173
+ var fname = str.substr(0, op);
174
+ var params = str.substr(op + 1, ep - (op + 1)).split(',');
175
+ var alpha = 1; // To allow case fallthrough.
176
+ switch (fname) {
177
+ case 'rgba':
178
+ if (params.length !== 4) return null;
179
+ alpha = parse_css_float(params.pop() as string);
180
+ // Fall through.
181
+ case 'rgb':
182
+ if (params.length !== 3) return null;
183
+ return [parse_css_int(params[0]),
184
+ parse_css_int(params[1]),
185
+ parse_css_int(params[2]),
186
+ alpha];
187
+ case 'hsla':
188
+ if (params.length !== 4) return null;
189
+ alpha = parse_css_float(params.pop() as string);
190
+ // Fall through.
191
+ case 'hsl':
192
+ if (params.length !== 3) return null;
193
+ var h = (((parseFloat(params[0]) % 360) + 360) % 360) / 360; // 0 .. 1
194
+ // NOTE(deanm): According to the CSS spec s/l should only be
195
+ // percentages, but we don't bother and let float or percentage.
196
+ var s = parse_css_float(params[1]);
197
+ var l = parse_css_float(params[2]);
198
+ var m2 = l <= 0.5 ? l * (s + 1) : l + s - l * s;
199
+ var m1 = l * 2 - m2;
200
+ return [clamp_css_byte(css_hue_to_rgb(m1, m2, h + 1 / 3) * 255),
201
+ clamp_css_byte(css_hue_to_rgb(m1, m2, h) * 255),
202
+ clamp_css_byte(css_hue_to_rgb(m1, m2, h - 1 / 3) * 255),
203
+ alpha];
204
+ default:
205
+ return null;
206
+ }
207
+ }
208
+
209
+ return null;
210
+ }
211
+
212
+ function namedColor(name: keyof typeof kCSSColorTable): Color {
213
+ var c = kCSSColorTable[name]
214
+ return new Color(c[0] / 255, c[1] / 255, c[2] / 255, c[3])
215
+ }
216
+
217
+ function namedColors(...names: (keyof typeof kCSSColorTable)[]): Color[] {
218
+ let res = [] as Color[]
219
+ for (const name of names) {
220
+ res.push(namedColor(name))
221
+ }
222
+ return res
223
+ }
224
+
225
+ export function colorStrToF4(str: string): float4 {
226
+ var c = parseCSSColor(str)
227
+ if (c == null)
228
+ throw `Color ${str} cannot be parsed`
229
+
230
+ return f4(c[0] / 255, c[1] / 255, c[2] / 255, c[3])
231
+ }
232
+
233
+ /**
234
+ * Can parse any css color, array of 4 values [0 to 1.0], or a plain float4
235
+ */
236
+ export function parseColor(input: string | number[] | float4): Color {
237
+ if (Array.isArray(input)) {
238
+ return new Color(input[0], input[1], input[2], input[3])
239
+ } else if (typeof input === "string") {
240
+ var c = parseCSSColor(input)
241
+ if (c !== null) {
242
+ return new Color(c[0] / 255, c[1] / 255, c[2] / 255, c[3])
243
+ }
244
+ return new Color(0, 0, 0, 0)
245
+ }
246
+ return new Color(input.x, input.y, input.z, input.w)
247
+ }
248
+
249
+ export { parseCSSColor, namedColor, namedColors }
@@ -0,0 +1,31 @@
1
+ // import { float2, float3, float4 } from "Unity/Mathematics" // JSR prepends a "./" to this, which messes things up
2
+
3
+ type float2 = CS.Unity.Mathematics.float2
4
+ type float3 = CS.Unity.Mathematics.float3
5
+ type float4 = CS.Unity.Mathematics.float4
6
+
7
+ const { clamp, float2: f2, float3: f3, float4: f4 } = CS.Unity.Mathematics.math
8
+
9
+ export function parseFloat2(input: any): float2 {
10
+ if (!input)
11
+ return f2(0, 0)
12
+ if (Array.isArray(input))
13
+ input = f2(input[0] ?? 0, input[1] ?? 0)
14
+ return f2(input.x ?? 0, input.y ?? 0)
15
+ }
16
+
17
+ export function parseFloat3(input: any): float3 {
18
+ if (!input)
19
+ return f3(0, 0, 0)
20
+ if (Array.isArray(input))
21
+ input = f3(input[0] ?? 0, input[1] ?? 0, input[2] ?? 0)
22
+ return f3(input.x ?? 0, input.y ?? 0, input.z ?? 0)
23
+ }
24
+
25
+ export function parseFloat4(input: any): float4 {
26
+ if (!input)
27
+ return f4(0, 0, 0, 0)
28
+ if (Array.isArray(input))
29
+ input = f4(input[0] ?? 0, input[1] ?? 0, input[2] ?? 0, input[3] ?? 0)
30
+ return f4(input.x ?? 0, input.y ?? 0, input.z ?? 0, input.w ?? 0)
31
+ }
package/utils/index.ts ADDED
@@ -0,0 +1,12 @@
1
+ /**
2
+ * @module utils
3
+ *
4
+ * This module contains some commonly-used utility functions.
5
+ */
6
+
7
+ // @ts-ignore - prevent `allowImportingTsExtensions` error
8
+ export { parseColor, parseCSSColor, colorStrToF4, namedColor, namedColors } from "./color-parser"
9
+ // @ts-ignore - prevent `allowImportingTsExtensions` error
10
+ export { palettes } from "./color-palettes"
11
+ // @ts-ignore - prevent `allowImportingTsExtensions` error
12
+ export { parseFloat2, parseFloat3, parseFloat4 } from "./float-parser"