onejs-core 3.0.3 → 3.0.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 (103) hide show
  1. package/.gitattributes +2 -2
  2. package/.prettierrc +5 -5
  3. package/.vscode/settings.json +5 -5
  4. package/LICENSE +20 -20
  5. package/README.md +102 -102
  6. package/bin/oj.js +252 -252
  7. package/definitions/Assemblies/OneJS.Runtime.Ext.d.ts +6 -6
  8. package/definitions/Assemblies/OneJS.Runtime.d.ts +826 -826
  9. package/definitions/Assemblies/OneJS.Samples.d.ts +20 -20
  10. package/definitions/Assemblies/Unity.Mathematics.d.ts +9221 -9221
  11. package/definitions/Assemblies/UnityEditor.CoreModule.d.ts +32614 -32614
  12. package/definitions/Assemblies/UnityEngine.AIModule.d.ts +998 -998
  13. package/definitions/Assemblies/UnityEngine.AnimationModule.d.ts +3308 -3308
  14. package/definitions/Assemblies/UnityEngine.AssetBundleModule.d.ts +337 -337
  15. package/definitions/Assemblies/UnityEngine.AudioModule.d.ts +1154 -1154
  16. package/definitions/Assemblies/UnityEngine.CoreModule.d.ts +29587 -29587
  17. package/definitions/Assemblies/UnityEngine.PhysicsModule.d.ts +3137 -3137
  18. package/definitions/Assemblies/UnityEngine.TerrainModule.d.ts +1270 -1270
  19. package/definitions/Assemblies/UnityEngine.UIElementsModule.d.ts +32718 -32718
  20. package/definitions/Assemblies/UnityEngine.UnityAnalyticsCommonModule.d.ts +274 -274
  21. package/definitions/Assemblies/index.d.ts +16 -16
  22. package/definitions/Assemblies/mscorlib.d.ts +19416 -19416
  23. package/definitions/augments.d.ts +66 -66
  24. package/definitions/globals.d.ts +53 -53
  25. package/definitions/index.d.ts +11 -11
  26. package/definitions/jsx.d.ts +570 -570
  27. package/definitions/modules.d.ts +32 -32
  28. package/definitions/onejs.d.ts +171 -171
  29. package/definitions/preact.jsx.d.ts +6 -6
  30. package/definitions/proto-overrides.d.ts +41 -41
  31. package/definitions/puerts.d.ts +30 -30
  32. package/definitions/unity-engine.d.ts +22 -22
  33. package/dist/dom/document.d.ts +30 -0
  34. package/dist/dom/document.js +89 -0
  35. package/dist/dom/dom-style.d.ts +9 -0
  36. package/dist/dom/dom-style.js +27 -0
  37. package/dist/dom/dom.d.ts +83 -0
  38. package/dist/dom/dom.js +313 -0
  39. package/dist/dom/index.d.ts +4 -0
  40. package/dist/dom/index.js +4 -0
  41. package/dist/index.d.ts +25 -0
  42. package/dist/index.js +45 -0
  43. package/dist/math/index.d.ts +86 -0
  44. package/dist/math/index.js +361 -0
  45. package/dist/preloads/inject.d.ts +3 -0
  46. package/dist/preloads/inject.js +36 -0
  47. package/dist/styling/index.d.ts +10 -0
  48. package/dist/styling/index.js +28 -0
  49. package/dist/styling/utils/generateAlphabeticName.d.ts +1 -0
  50. package/dist/styling/utils/generateAlphabeticName.js +16 -0
  51. package/dist/styling/utils/generateComponentId.d.ts +1 -0
  52. package/dist/styling/utils/generateComponentId.js +5 -0
  53. package/dist/styling/utils/hash.d.ts +5 -0
  54. package/dist/styling/utils/hash.js +34 -0
  55. package/dist/utils/arrays.d.ts +1 -0
  56. package/dist/utils/arrays.js +10 -0
  57. package/dist/utils/color-palettes.d.ts +2 -0
  58. package/dist/utils/color-palettes.js +2 -0
  59. package/dist/utils/color-parser.d.ts +161 -0
  60. package/dist/utils/color-parser.js +241 -0
  61. package/dist/utils/float-parser.d.ts +7 -0
  62. package/dist/utils/float-parser.js +23 -0
  63. package/dist/utils/index.d.ts +12 -0
  64. package/dist/utils/index.js +15 -0
  65. package/dist/utils/subscribe.d.ts +4 -0
  66. package/dist/utils/subscribe.js +10 -0
  67. package/dist/utils/system.d.ts +1 -0
  68. package/dist/utils/system.js +16 -0
  69. package/dom/document.ts +115 -115
  70. package/dom/dom-style.ts +36 -36
  71. package/dom/dom.ts +376 -376
  72. package/dom/index.ts +3 -3
  73. package/index.ts +59 -59
  74. package/jsr.json +9 -9
  75. package/math/README.md +212 -212
  76. package/math/index.ts +487 -487
  77. package/package.json +34 -33
  78. package/preloads/inject.ts +43 -43
  79. package/scripts/esbuild/copy-assets.mjs +94 -94
  80. package/scripts/esbuild/decorator-fix.mjs +17 -17
  81. package/scripts/esbuild/import-transform.mjs +100 -100
  82. package/scripts/esbuild/index.mjs +3 -3
  83. package/scripts/esbuild/watch-output.mjs +38 -38
  84. package/scripts/postcss/cleanup-plugin.cjs +89 -89
  85. package/scripts/postcss/onejs-tw-config.cjs +252 -252
  86. package/scripts/postcss/optional-import-plugin.cjs +26 -26
  87. package/scripts/postcss/tailwind-logging-plugin.cjs +11 -11
  88. package/scripts/postcss/unwrap-is-plugin.cjs +16 -16
  89. package/scripts/postcss/uss-transform-plugin.cjs +92 -92
  90. package/scripts/switch.cjs +321 -290
  91. package/styling/index.tsx +32 -32
  92. package/styling/utils/generateAlphabeticName.ts +20 -20
  93. package/styling/utils/generateComponentId.ts +5 -5
  94. package/styling/utils/hash.ts +46 -46
  95. package/tsconfig.json +24 -24
  96. package/typings.d.ts +5 -5
  97. package/utils/arrays.ts +10 -10
  98. package/utils/color-palettes.ts +2 -2
  99. package/utils/color-parser.ts +248 -248
  100. package/utils/float-parser.ts +30 -30
  101. package/utils/index.ts +15 -15
  102. package/utils/subscribe.ts +16 -16
  103. package/utils/system.ts +16 -16
@@ -1,249 +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
- const 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
-
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
+ const 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
249
  export { parseCSSColor, namedColor, namedColors }
@@ -1,31 +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)
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
31
  }
package/utils/index.ts CHANGED
@@ -1,16 +1,16 @@
1
- /// <reference path="../definitions/index.d.ts" />
2
- /**
3
- * @module utils
4
- *
5
- * This module contains some commonly-used utility functions.
6
- */
7
-
8
- // @ts-ignore - prevent `allowImportingTsExtensions` error
9
- export { parseColor, parseCSSColor, colorStrToF4, namedColor, namedColors } from "./color-parser"
10
- // @ts-ignore - prevent `allowImportingTsExtensions` error
11
- export { palettes } from "./color-palettes"
12
- // @ts-ignore - prevent `allowImportingTsExtensions` error
13
- export { parseFloat2, parseFloat3, parseFloat4 } from "./float-parser"
14
- export { subscribe } from "./subscribe"
15
- export { toJsArray } from "./arrays"
1
+ /// <reference path="../definitions/index.d.ts" />
2
+ /**
3
+ * @module utils
4
+ *
5
+ * This module contains some commonly-used utility functions.
6
+ */
7
+
8
+ // @ts-ignore - prevent `allowImportingTsExtensions` error
9
+ export { parseColor, parseCSSColor, colorStrToF4, namedColor, namedColors } from "./color-parser"
10
+ // @ts-ignore - prevent `allowImportingTsExtensions` error
11
+ export { palettes } from "./color-palettes"
12
+ // @ts-ignore - prevent `allowImportingTsExtensions` error
13
+ export { parseFloat2, parseFloat3, parseFloat4 } from "./float-parser"
14
+ export { subscribe } from "./subscribe"
15
+ export { toJsArray } from "./arrays"
16
16
  export { logSystemInfo } from "./system"
@@ -1,17 +1,17 @@
1
- import { Action, Delegate } from "System"
2
-
3
-
4
- export function subscribe<T, K extends keyof T>(target: T, eventName: K, callback: () => void): () => void
5
- export function subscribe<T, K extends keyof T>(target: { new(): T }, eventName: K, callback: () => void): () => void
6
- export function subscribe(target: any, eventName: any, callback: () => void): () => void {
7
- var action = new Action(callback)
8
- target[eventName] = Delegate.Combine(target[eventName] as any, action) as any
9
-
10
- const unsubscribe = () => {
11
- target[eventName] = Delegate.Remove(target[eventName] as any, action) as any
12
- }
13
-
14
- onejs.add_onReload(unsubscribe)
15
-
16
- return unsubscribe
1
+ import { Action, Delegate } from "System"
2
+
3
+
4
+ export function subscribe<T, K extends keyof T>(target: T, eventName: K, callback: () => void): () => void
5
+ export function subscribe<T, K extends keyof T>(target: { new(): T }, eventName: K, callback: () => void): () => void
6
+ export function subscribe(target: any, eventName: any, callback: () => void): () => void {
7
+ var action = new Action(callback)
8
+ target[eventName] = Delegate.Combine(target[eventName] as any, action) as any
9
+
10
+ const unsubscribe = () => {
11
+ target[eventName] = Delegate.Remove(target[eventName] as any, action) as any
12
+ }
13
+
14
+ onejs.add_onReload(unsubscribe)
15
+
16
+ return unsubscribe
17
17
  }