onejs-core 0.3.12 → 0.3.13
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.
- package/dist/dom/document.d.ts +14 -0
- package/dist/dom/document.js +22 -0
- package/dist/dom/dom-style.d.ts +7 -0
- package/dist/dom/dom-style.js +18 -0
- package/dist/dom/dom.d.ts +32 -0
- package/dist/dom/dom.js +62 -0
- package/dist/index.d.ts +22 -0
- package/dist/index.js +36 -0
- package/dist/preloads/inject.d.ts +2 -0
- package/dist/preloads/inject.js +35 -0
- package/dist/styling/index.d.ts +9 -0
- package/dist/styling/index.js +23 -0
- package/dist/styling/utils/generateAlphabeticName.d.ts +1 -0
- package/dist/styling/utils/generateAlphabeticName.js +16 -0
- package/dist/styling/utils/generateComponentId.d.ts +1 -0
- package/dist/styling/utils/generateComponentId.js +5 -0
- package/dist/styling/utils/hash.d.ts +5 -0
- package/dist/styling/utils/hash.js +34 -0
- package/dist/utils/color-palettes.d.ts +2 -0
- package/dist/utils/color-palettes.js +2 -0
- package/dist/utils/color-parser.d.ts +161 -0
- package/dist/utils/color-parser.js +241 -0
- package/dist/utils/float-parser.d.ts +7 -0
- package/dist/utils/float-parser.js +23 -0
- package/dist/utils/index.d.ts +8 -0
- package/dist/utils/index.js +11 -0
- package/package.json +1 -1
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { DomWrapper } from "./dom";
|
|
2
|
+
interface ElementCreationOptions {
|
|
3
|
+
is?: string;
|
|
4
|
+
}
|
|
5
|
+
export declare class DocumentWrapper {
|
|
6
|
+
#private;
|
|
7
|
+
get body(): DomWrapper;
|
|
8
|
+
constructor(doc: CS.OneJS.Dom.Document);
|
|
9
|
+
addRuntimeUSS(uss: string): void;
|
|
10
|
+
createElement(tagName: string, options?: ElementCreationOptions): DomWrapper;
|
|
11
|
+
createElementNS(ns: string, tagName: string, options: ElementCreationOptions): DomWrapper;
|
|
12
|
+
createTextNode(text: string): DomWrapper;
|
|
13
|
+
}
|
|
14
|
+
export {};
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { DomWrapper } from "./dom";
|
|
2
|
+
export class DocumentWrapper {
|
|
3
|
+
#doc;
|
|
4
|
+
#body;
|
|
5
|
+
get body() { return this.#body; }
|
|
6
|
+
constructor(doc) {
|
|
7
|
+
this.#doc = doc;
|
|
8
|
+
this.#body = new DomWrapper(doc.body);
|
|
9
|
+
}
|
|
10
|
+
addRuntimeUSS(uss) {
|
|
11
|
+
this.#doc.addRuntimeUSS(uss);
|
|
12
|
+
}
|
|
13
|
+
createElement(tagName, options) {
|
|
14
|
+
return new DomWrapper(this.#doc.createElement(tagName));
|
|
15
|
+
}
|
|
16
|
+
createElementNS(ns, tagName, options) {
|
|
17
|
+
return new DomWrapper(this.#doc.createElement(tagName));
|
|
18
|
+
}
|
|
19
|
+
createTextNode(text) {
|
|
20
|
+
return new DomWrapper(this.#doc.createTextNode(text));
|
|
21
|
+
}
|
|
22
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
export class DomStyleWrapper {
|
|
2
|
+
#domStyle;
|
|
3
|
+
constructor(domStyle) {
|
|
4
|
+
this.#domStyle = domStyle;
|
|
5
|
+
return new Proxy(this, {
|
|
6
|
+
set(target, prop, value) {
|
|
7
|
+
target.setProperty(prop, value);
|
|
8
|
+
return true;
|
|
9
|
+
},
|
|
10
|
+
get(target, prop) {
|
|
11
|
+
return target[prop];
|
|
12
|
+
}
|
|
13
|
+
});
|
|
14
|
+
}
|
|
15
|
+
setProperty(name, value) {
|
|
16
|
+
this.#domStyle.setProperty(name, value);
|
|
17
|
+
}
|
|
18
|
+
}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { DomStyleWrapper } from "./dom-style";
|
|
2
|
+
export declare class DomWrapper {
|
|
3
|
+
#private;
|
|
4
|
+
get _dom(): CS.OneJS.Dom.Dom;
|
|
5
|
+
get ve(): CS.UnityEngine.UIElements.VisualElement;
|
|
6
|
+
get childNodes(): DomWrapper[];
|
|
7
|
+
get firstChild(): DomWrapper | null;
|
|
8
|
+
get parentNode(): DomWrapper | null;
|
|
9
|
+
get nextSibling(): DomWrapper | null;
|
|
10
|
+
get nodeType(): number;
|
|
11
|
+
get Id(): string;
|
|
12
|
+
set Id(value: string);
|
|
13
|
+
get key(): string;
|
|
14
|
+
set key(value: string);
|
|
15
|
+
get style(): DomStyleWrapper;
|
|
16
|
+
get value(): any;
|
|
17
|
+
get checked(): boolean;
|
|
18
|
+
get data(): any;
|
|
19
|
+
set data(value: any);
|
|
20
|
+
get classname(): string;
|
|
21
|
+
set classname(value: string);
|
|
22
|
+
constructor(dom: CS.OneJS.Dom.Dom);
|
|
23
|
+
appendChild(child: DomWrapper): void;
|
|
24
|
+
removeChild(child: DomWrapper): void;
|
|
25
|
+
insertBefore(a: DomWrapper, b: DomWrapper): void;
|
|
26
|
+
clearChildren(): void;
|
|
27
|
+
focus(): void;
|
|
28
|
+
addEventListener(type: string, listener: (event: Event) => void, useCapture?: boolean): void;
|
|
29
|
+
removeEventListener(type: string, listener: (event: Event) => void, useCapture?: boolean): void;
|
|
30
|
+
setAttribute(name: string, value: any): void;
|
|
31
|
+
removeAttribute(name: string): void;
|
|
32
|
+
}
|
package/dist/dom/dom.js
ADDED
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
import { DomStyleWrapper } from "./dom-style";
|
|
2
|
+
export class DomWrapper {
|
|
3
|
+
get _dom() { return this.#dom; }
|
|
4
|
+
get ve() { return this.#dom.ve; }
|
|
5
|
+
get childNodes() { return this.#dom.childNodes.map((child) => new DomWrapper(child)); }
|
|
6
|
+
get firstChild() {
|
|
7
|
+
return this.#dom.firstChild ? new DomWrapper(this.#dom.firstChild) : null;
|
|
8
|
+
}
|
|
9
|
+
get parentNode() {
|
|
10
|
+
return this.#dom.parentNode ? new DomWrapper(this.#dom.parentNode) : null;
|
|
11
|
+
}
|
|
12
|
+
get nextSibling() {
|
|
13
|
+
return this.#dom.nextSibling ? new DomWrapper(this.#dom.nextSibling) : null;
|
|
14
|
+
}
|
|
15
|
+
get nodeType() { return this.#dom.nodeType; }
|
|
16
|
+
get Id() { return this.#dom.Id; }
|
|
17
|
+
set Id(value) { this.#dom.Id = value; }
|
|
18
|
+
get key() { return this.#dom.key; }
|
|
19
|
+
set key(value) { this.#dom.key = value; }
|
|
20
|
+
get style() { return this.#domStyleWrapper; }
|
|
21
|
+
get value() { return this.#dom.value; }
|
|
22
|
+
get checked() { return this.#dom.checked; }
|
|
23
|
+
get data() { return this.#dom.data; }
|
|
24
|
+
set data(value) { this.#dom.data = value; }
|
|
25
|
+
get classname() { return this.#dom.classname; }
|
|
26
|
+
set classname(value) { this.#dom.classname = value; }
|
|
27
|
+
#dom;
|
|
28
|
+
#domStyleWrapper;
|
|
29
|
+
constructor(dom) {
|
|
30
|
+
this.#dom = dom;
|
|
31
|
+
this.#domStyleWrapper = new DomStyleWrapper(dom.style);
|
|
32
|
+
}
|
|
33
|
+
appendChild(child) {
|
|
34
|
+
this.#dom.appendChild(child.#dom);
|
|
35
|
+
}
|
|
36
|
+
removeChild(child) {
|
|
37
|
+
this.#dom.removeChild(child.#dom);
|
|
38
|
+
}
|
|
39
|
+
insertBefore(a, b) {
|
|
40
|
+
this.#dom.insertBefore(a?._dom, b?._dom);
|
|
41
|
+
}
|
|
42
|
+
clearChildren() {
|
|
43
|
+
this.#dom.clearChildren();
|
|
44
|
+
}
|
|
45
|
+
focus() {
|
|
46
|
+
this.#dom.focus();
|
|
47
|
+
}
|
|
48
|
+
addEventListener(type, listener, useCapture) {
|
|
49
|
+
// @ts-ignore
|
|
50
|
+
this.#dom.addEventListener(type, listener.bind(this), useCapture);
|
|
51
|
+
}
|
|
52
|
+
removeEventListener(type, listener, useCapture) {
|
|
53
|
+
// @ts-ignore
|
|
54
|
+
this.#dom.removeEventListener(type, listener.bind(this), useCapture);
|
|
55
|
+
}
|
|
56
|
+
setAttribute(name, value) {
|
|
57
|
+
this.#dom.setAttribute(name, value);
|
|
58
|
+
}
|
|
59
|
+
removeAttribute(name) {
|
|
60
|
+
this.#dom.removeAttribute(name);
|
|
61
|
+
}
|
|
62
|
+
}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { DocumentWrapper } from "./dom/document";
|
|
2
|
+
import { DomWrapper } from "./dom/dom";
|
|
3
|
+
/**
|
|
4
|
+
* OneJS's own h function. Use this to quickly create elements in jsx-like syntax
|
|
5
|
+
* @param type
|
|
6
|
+
* @param props
|
|
7
|
+
* @param children
|
|
8
|
+
* @returns
|
|
9
|
+
*/
|
|
10
|
+
export declare function h(type: any, props: any, ...children: any[]): any;
|
|
11
|
+
export { emo } from "./styling/index";
|
|
12
|
+
declare global {
|
|
13
|
+
interface Document extends DocumentWrapper {
|
|
14
|
+
}
|
|
15
|
+
interface Element extends DomWrapper {
|
|
16
|
+
classname: string;
|
|
17
|
+
nodeType: number;
|
|
18
|
+
ve: CS.UnityEngine.UIElements.VisualElement;
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
declare const document: Document
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { DocumentWrapper } from "./dom/document";
|
|
2
|
+
/**
|
|
3
|
+
* OneJS's own h function. Use this to quickly create elements in jsx-like syntax
|
|
4
|
+
* @param type
|
|
5
|
+
* @param props
|
|
6
|
+
* @param children
|
|
7
|
+
* @returns
|
|
8
|
+
*/
|
|
9
|
+
export function h(type, props, ...children) {
|
|
10
|
+
const element = typeof type === "string" ? document.createElement(type) : type;
|
|
11
|
+
// Assign properties to the element
|
|
12
|
+
for (const [key, value] of Object.entries(props || {})) {
|
|
13
|
+
if (key.startsWith("on") && typeof value === "function") {
|
|
14
|
+
element.addEventListener(key.substring(2).toLowerCase(), value);
|
|
15
|
+
}
|
|
16
|
+
else if (key === "style" && typeof value === "object") {
|
|
17
|
+
Object.assign(element.style, value);
|
|
18
|
+
}
|
|
19
|
+
else {
|
|
20
|
+
element.setAttribute(key, value);
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
// Append children
|
|
24
|
+
for (const child of children) {
|
|
25
|
+
if (typeof child === "string") {
|
|
26
|
+
element.appendChild(document.createTextNode(child));
|
|
27
|
+
}
|
|
28
|
+
else {
|
|
29
|
+
element.appendChild(child);
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
return element;
|
|
33
|
+
}
|
|
34
|
+
export { emo } from "./styling/index";
|
|
35
|
+
// @ts-ignore
|
|
36
|
+
globalThis.document = new DocumentWrapper(___document);
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
export function btoa(text) {
|
|
2
|
+
// return CS.OneJS.CommonGlobals.btoa(text);
|
|
3
|
+
const chars = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/';
|
|
4
|
+
let str = text;
|
|
5
|
+
let output = '';
|
|
6
|
+
for (let i = 0; i < str.length; i += 3) {
|
|
7
|
+
let block = (str.charCodeAt(i) << 16) | ((i + 1 < str.length ? str.charCodeAt(i + 1) : 0) << 8) | (i + 2 < str.length ? str.charCodeAt(i + 2) : 0);
|
|
8
|
+
output += chars[(block >> 18) & 0x3F] +
|
|
9
|
+
chars[(block >> 12) & 0x3F] +
|
|
10
|
+
(i + 1 < str.length ? chars[(block >> 6) & 0x3F] : '=') +
|
|
11
|
+
(i + 2 < str.length ? chars[block & 0x3F] : '=');
|
|
12
|
+
}
|
|
13
|
+
return output;
|
|
14
|
+
}
|
|
15
|
+
// function uint8ArrayToString(uint8Array) {
|
|
16
|
+
// const chars: any = [];
|
|
17
|
+
// for (let i = 0; i < uint8Array.length; i++) {
|
|
18
|
+
// chars.push(String.fromCharCode(uint8Array[i]));
|
|
19
|
+
// }
|
|
20
|
+
// return chars.join('');
|
|
21
|
+
// }
|
|
22
|
+
export function atob(base64) {
|
|
23
|
+
// return CS.OneJS.CommonGlobals.atob(base64);
|
|
24
|
+
// return CS.System.Text.Encoding.UTF8.GetString(CS.System.Convert.FromBase64String(base64))
|
|
25
|
+
const chars = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/';
|
|
26
|
+
let str = base64.replace(/=+$/, '');
|
|
27
|
+
let output = '';
|
|
28
|
+
if (str.length % 4 == 1) {
|
|
29
|
+
throw new Error('Invalid base64 string');
|
|
30
|
+
}
|
|
31
|
+
for (let bc = 0, bs = 0, buffer, idx = 0; buffer = str.charAt(idx++); ~buffer && (bs = bc % 4 ? bs * 64 + buffer : buffer, bc++ % 4) ? output += String.fromCharCode(255 & bs >> (-2 * bc & 6)) : 0) {
|
|
32
|
+
buffer = chars.indexOf(buffer);
|
|
33
|
+
}
|
|
34
|
+
return output;
|
|
35
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
export declare function hashAndAddRuntimeUSS(style: string): string;
|
|
2
|
+
/**
|
|
3
|
+
* Similar to the Emotion api, this function takes a template string and returns
|
|
4
|
+
* a class name that can be used to style an element.
|
|
5
|
+
* @param strings
|
|
6
|
+
* @param values
|
|
7
|
+
* @returns
|
|
8
|
+
*/
|
|
9
|
+
export declare const emo: (strings: TemplateStringsArray, ...values: any[]) => string;
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import flatten from "css-flatten";
|
|
2
|
+
import generateComponentId from "./utils/generateComponentId";
|
|
3
|
+
export function hashAndAddRuntimeUSS(style) {
|
|
4
|
+
let compId = generateComponentId(style);
|
|
5
|
+
style = `.${compId} {${style}}`;
|
|
6
|
+
style = flatten(style);
|
|
7
|
+
document.addRuntimeUSS(style);
|
|
8
|
+
return compId;
|
|
9
|
+
}
|
|
10
|
+
/**
|
|
11
|
+
* Similar to the Emotion api, this function takes a template string and returns
|
|
12
|
+
* a class name that can be used to style an element.
|
|
13
|
+
* @param strings
|
|
14
|
+
* @param values
|
|
15
|
+
* @returns
|
|
16
|
+
*/
|
|
17
|
+
export const emo = function (strings, ...values) {
|
|
18
|
+
let style = values.reduce((result, expr, index) => {
|
|
19
|
+
const value = expr;
|
|
20
|
+
return result + (value ? value : "") + strings[index + 1];
|
|
21
|
+
}, strings[0]);
|
|
22
|
+
return hashAndAddRuntimeUSS(style);
|
|
23
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export default function generateAlphabeticName(code: number): string;
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
const AD_REPLACER_R = /(a)(d)/gi;
|
|
2
|
+
/* This is the "capacity" of our alphabet i.e. 2x26 for all letters plus their capitalised
|
|
3
|
+
* counterparts */
|
|
4
|
+
const charsLength = 52;
|
|
5
|
+
/* start at 75 for 'a' until 'z' (25) and then start at 65 for capitalised letters */
|
|
6
|
+
const getAlphabeticChar = (code) => String.fromCharCode(code + (code > 25 ? 39 : 97));
|
|
7
|
+
/* input a number, usually a hash and convert it to base-52 */
|
|
8
|
+
export default function generateAlphabeticName(code) {
|
|
9
|
+
let name = '';
|
|
10
|
+
let x;
|
|
11
|
+
/* get a char and divide by alphabet-length */
|
|
12
|
+
for (x = Math.abs(code); x > charsLength; x = (x / charsLength) | 0) {
|
|
13
|
+
name = getAlphabeticChar(x % charsLength) + name;
|
|
14
|
+
}
|
|
15
|
+
return (getAlphabeticChar(x % charsLength) + name).replace(AD_REPLACER_R, '$1-$2');
|
|
16
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export default function generateComponentId(str: string): string;
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
export declare const SEED = 5381;
|
|
2
|
+
export declare const phash: (h: number, x: string) => number;
|
|
3
|
+
export declare const hash: (x: string) => number;
|
|
4
|
+
export declare function generateAlphabeticName(code: number): string;
|
|
5
|
+
export default function generateComponentId(str: string): string;
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
export const SEED = 5381;
|
|
2
|
+
// When we have separate strings it's useful to run a progressive
|
|
3
|
+
// version of djb2 where we pretend that we're still looping over
|
|
4
|
+
// the same string
|
|
5
|
+
export const phash = (h, x) => {
|
|
6
|
+
let i = x.length;
|
|
7
|
+
while (i) {
|
|
8
|
+
h = (h * 33) ^ x.charCodeAt(--i);
|
|
9
|
+
}
|
|
10
|
+
return h;
|
|
11
|
+
};
|
|
12
|
+
// This is a djb2 hashing function
|
|
13
|
+
export const hash = (x) => {
|
|
14
|
+
return phash(SEED, x);
|
|
15
|
+
};
|
|
16
|
+
const AD_REPLACER_R = /(a)(d)/gi;
|
|
17
|
+
/* This is the "capacity" of our alphabet i.e. 2x26 for all letters plus their capitalised
|
|
18
|
+
* counterparts */
|
|
19
|
+
const charsLength = 52;
|
|
20
|
+
/* start at 75 for 'a' until 'z' (25) and then start at 65 for capitalised letters */
|
|
21
|
+
const getAlphabeticChar = (code) => String.fromCharCode(code + (code > 25 ? 39 : 97));
|
|
22
|
+
/* input a number, usually a hash and convert it to base-52 */
|
|
23
|
+
export function generateAlphabeticName(code) {
|
|
24
|
+
let name = '';
|
|
25
|
+
let x;
|
|
26
|
+
/* get a char and divide by alphabet-length */
|
|
27
|
+
for (x = Math.abs(code); x > charsLength; x = (x / charsLength) | 0) {
|
|
28
|
+
name = getAlphabeticChar(x % charsLength) + name;
|
|
29
|
+
}
|
|
30
|
+
return (getAlphabeticChar(x % charsLength) + name).replace(AD_REPLACER_R, '$1-$2');
|
|
31
|
+
}
|
|
32
|
+
export default function generateComponentId(str) {
|
|
33
|
+
return generateAlphabeticName(hash(str) >>> 0);
|
|
34
|
+
}
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
let palettes = [["#69d2e7", "#a7dbd8", "#e0e4cc", "#f38630", "#fa6900"], ["#fe4365", "#fc9d9a", "#f9cdad", "#c8c8a9", "#83af9b"], ["#ecd078", "#d95b43", "#c02942", "#542437", "#53777a"], ["#556270", "#4ecdc4", "#c7f464", "#ff6b6b", "#c44d58"], ["#774f38", "#e08e79", "#f1d4af", "#ece5ce", "#c5e0dc"], ["#e8ddcb", "#cdb380", "#036564", "#033649", "#031634"], ["#490a3d", "#bd1550", "#e97f02", "#f8ca00", "#8a9b0f"], ["#594f4f", "#547980", "#45ada8", "#9de0ad", "#e5fcc2"], ["#00a0b0", "#6a4a3c", "#cc333f", "#eb6841", "#edc951"], ["#e94e77", "#d68189", "#c6a49a", "#c6e5d9", "#f4ead5"], ["#3fb8af", "#7fc7af", "#dad8a7", "#ff9e9d", "#ff3d7f"], ["#d9ceb2", "#948c75", "#d5ded9", "#7a6a53", "#99b2b7"], ["#ffffff", "#cbe86b", "#f2e9e1", "#1c140d", "#cbe86b"], ["#efffcd", "#dce9be", "#555152", "#2e2633", "#99173c"], ["#343838", "#005f6b", "#008c9e", "#00b4cc", "#00dffc"], ["#413e4a", "#73626e", "#b38184", "#f0b49e", "#f7e4be"], ["#ff4e50", "#fc913a", "#f9d423", "#ede574", "#e1f5c4"], ["#99b898", "#fecea8", "#ff847c", "#e84a5f", "#2a363b"], ["#655643", "#80bca3", "#f6f7bd", "#e6ac27", "#bf4d28"], ["#00a8c6", "#40c0cb", "#f9f2e7", "#aee239", "#8fbe00"], ["#351330", "#424254", "#64908a", "#e8caa4", "#cc2a41"], ["#554236", "#f77825", "#d3ce3d", "#f1efa5", "#60b99a"], ["#5d4157", "#838689", "#a8caba", "#cad7b2", "#ebe3aa"], ["#8c2318", "#5e8c6a", "#88a65e", "#bfb35a", "#f2c45a"], ["#fad089", "#ff9c5b", "#f5634a", "#ed303c", "#3b8183"], ["#ff4242", "#f4fad2", "#d4ee5e", "#e1edb9", "#f0f2eb"], ["#f8b195", "#f67280", "#c06c84", "#6c5b7b", "#355c7d"], ["#d1e751", "#ffffff", "#000000", "#4dbce9", "#26ade4"], ["#1b676b", "#519548", "#88c425", "#bef202", "#eafde6"], ["#5e412f", "#fcebb6", "#78c0a8", "#f07818", "#f0a830"], ["#bcbdac", "#cfbe27", "#f27435", "#f02475", "#3b2d38"], ["#452632", "#91204d", "#e4844a", "#e8bf56", "#e2f7ce"], ["#eee6ab", "#c5bc8e", "#696758", "#45484b", "#36393b"], ["#f0d8a8", "#3d1c00", "#86b8b1", "#f2d694", "#fa2a00"], ["#2a044a", "#0b2e59", "#0d6759", "#7ab317", "#a0c55f"], ["#f04155", "#ff823a", "#f2f26f", "#fff7bd", "#95cfb7"], ["#b9d7d9", "#668284", "#2a2829", "#493736", "#7b3b3b"], ["#bbbb88", "#ccc68d", "#eedd99", "#eec290", "#eeaa88"], ["#b3cc57", "#ecf081", "#ffbe40", "#ef746f", "#ab3e5b"], ["#a3a948", "#edb92e", "#f85931", "#ce1836", "#009989"], ["#300030", "#480048", "#601848", "#c04848", "#f07241"], ["#67917a", "#170409", "#b8af03", "#ccbf82", "#e33258"], ["#aab3ab", "#c4cbb7", "#ebefc9", "#eee0b7", "#e8caaf"], ["#e8d5b7", "#0e2430", "#fc3a51", "#f5b349", "#e8d5b9"], ["#ab526b", "#bca297", "#c5ceae", "#f0e2a4", "#f4ebc3"], ["#607848", "#789048", "#c0d860", "#f0f0d8", "#604848"], ["#b6d8c0", "#c8d9bf", "#dadabd", "#ecdbbc", "#fedcba"], ["#a8e6ce", "#dcedc2", "#ffd3b5", "#ffaaa6", "#ff8c94"], ["#3e4147", "#fffedf", "#dfba69", "#5a2e2e", "#2a2c31"], ["#fc354c", "#29221f", "#13747d", "#0abfbc", "#fcf7c5"], ["#cc0c39", "#e6781e", "#c8cf02", "#f8fcc1", "#1693a7"], ["#1c2130", "#028f76", "#b3e099", "#ffeaad", "#d14334"], ["#a7c5bd", "#e5ddcb", "#eb7b59", "#cf4647", "#524656"], ["#dad6ca", "#1bb0ce", "#4f8699", "#6a5e72", "#563444"], ["#5c323e", "#a82743", "#e15e32", "#c0d23e", "#e5f04c"], ["#edebe6", "#d6e1c7", "#94c7b6", "#403b33", "#d3643b"], ["#fdf1cc", "#c6d6b8", "#987f69", "#e3ad40", "#fcd036"], ["#230f2b", "#f21d41", "#ebebbc", "#bce3c5", "#82b3ae"], ["#b9d3b0", "#81bda4", "#b28774", "#f88f79", "#f6aa93"], ["#3a111c", "#574951", "#83988e", "#bcdea5", "#e6f9bc"], ["#5e3929", "#cd8c52", "#b7d1a3", "#dee8be", "#fcf7d3"], ["#1c0113", "#6b0103", "#a30006", "#c21a01", "#f03c02"], ["#000000", "#9f111b", "#b11623", "#292c37", "#cccccc"], ["#382f32", "#ffeaf2", "#fcd9e5", "#fbc5d8", "#f1396d"], ["#e3dfba", "#c8d6bf", "#93ccc6", "#6cbdb5", "#1a1f1e"], ["#f6f6f6", "#e8e8e8", "#333333", "#990100", "#b90504"], ["#1b325f", "#9cc4e4", "#e9f2f9", "#3a89c9", "#f26c4f"], ["#a1dbb2", "#fee5ad", "#faca66", "#f7a541", "#f45d4c"], ["#c1b398", "#605951", "#fbeec2", "#61a6ab", "#accec0"], ["#5e9fa3", "#dcd1b4", "#fab87f", "#f87e7b", "#b05574"], ["#951f2b", "#f5f4d7", "#e0dfb1", "#a5a36c", "#535233"], ["#8dccad", "#988864", "#fea6a2", "#f9d6ac", "#ffe9af"], ["#2d2d29", "#215a6d", "#3ca2a2", "#92c7a3", "#dfece6"], ["#413d3d", "#040004", "#c8ff00", "#fa023c", "#4b000f"], ["#eff3cd", "#b2d5ba", "#61ada0", "#248f8d", "#605063"], ["#ffefd3", "#fffee4", "#d0ecea", "#9fd6d2", "#8b7a5e"], ["#cfffdd", "#b4dec1", "#5c5863", "#a85163", "#ff1f4c"], ["#9dc9ac", "#fffec7", "#f56218", "#ff9d2e", "#919167"], ["#4e395d", "#827085", "#8ebe94", "#ccfc8e", "#dc5b3e"], ["#a8a7a7", "#cc527a", "#e8175d", "#474747", "#363636"], ["#f8edd1", "#d88a8a", "#474843", "#9d9d93", "#c5cfc6"], ["#046d8b", "#309292", "#2fb8ac", "#93a42a", "#ecbe13"], ["#f38a8a", "#55443d", "#a0cab5", "#cde9ca", "#f1edd0"], ["#a70267", "#f10c49", "#fb6b41", "#f6d86b", "#339194"], ["#ff003c", "#ff8a00", "#fabe28", "#88c100", "#00c176"], ["#ffedbf", "#f7803c", "#f54828", "#2e0d23", "#f8e4c1"], ["#4e4d4a", "#353432", "#94ba65", "#2790b0", "#2b4e72"], ["#0ca5b0", "#4e3f30", "#fefeeb", "#f8f4e4", "#a5b3aa"], ["#4d3b3b", "#de6262", "#ffb88c", "#ffd0b3", "#f5e0d3"], ["#fffbb7", "#a6f6af", "#66b6ab", "#5b7c8d", "#4f2958"], ["#edf6ee", "#d1c089", "#b3204d", "#412e28", "#151101"], ["#9d7e79", "#ccac95", "#9a947c", "#748b83", "#5b756c"], ["#fcfef5", "#e9ffe1", "#cdcfb7", "#d6e6c3", "#fafbe3"], ["#9cddc8", "#bfd8ad", "#ddd9ab", "#f7af63", "#633d2e"], ["#30261c", "#403831", "#36544f", "#1f5f61", "#0b8185"], ["#aaff00", "#ffaa00", "#ff00aa", "#aa00ff", "#00aaff"], ["#d1313d", "#e5625c", "#f9bf76", "#8eb2c5", "#615375"], ["#ffe181", "#eee9e5", "#fad3b2", "#ffba7f", "#ff9c97"], ["#73c8a9", "#dee1b6", "#e1b866", "#bd5532", "#373b44"], ["#805841", "#dcf7f3", "#fffcdd", "#ffd8d8", "#f5a2a2"]];
|
|
2
|
+
export { palettes };
|
|
@@ -0,0 +1,161 @@
|
|
|
1
|
+
type float4 = CS.Unity.Mathematics.float4;
|
|
2
|
+
declare var kCSSColorTable: {
|
|
3
|
+
transparent: number[];
|
|
4
|
+
aliceblue: number[];
|
|
5
|
+
antiquewhite: number[];
|
|
6
|
+
aqua: number[];
|
|
7
|
+
aquamarine: number[];
|
|
8
|
+
azure: number[];
|
|
9
|
+
beige: number[];
|
|
10
|
+
bisque: number[];
|
|
11
|
+
black: number[];
|
|
12
|
+
blanchedalmond: number[];
|
|
13
|
+
blue: number[];
|
|
14
|
+
blueviolet: number[];
|
|
15
|
+
brown: number[];
|
|
16
|
+
burlywood: number[];
|
|
17
|
+
cadetblue: number[];
|
|
18
|
+
chartreuse: number[];
|
|
19
|
+
chocolate: number[];
|
|
20
|
+
coral: number[];
|
|
21
|
+
cornflowerblue: number[];
|
|
22
|
+
cornsilk: number[];
|
|
23
|
+
crimson: number[];
|
|
24
|
+
cyan: number[];
|
|
25
|
+
darkblue: number[];
|
|
26
|
+
darkcyan: number[];
|
|
27
|
+
darkgoldenrod: number[];
|
|
28
|
+
darkgray: number[];
|
|
29
|
+
darkgreen: number[];
|
|
30
|
+
darkgrey: number[];
|
|
31
|
+
darkkhaki: number[];
|
|
32
|
+
darkmagenta: number[];
|
|
33
|
+
darkolivegreen: number[];
|
|
34
|
+
darkorange: number[];
|
|
35
|
+
darkorchid: number[];
|
|
36
|
+
darkred: number[];
|
|
37
|
+
darksalmon: number[];
|
|
38
|
+
darkseagreen: number[];
|
|
39
|
+
darkslateblue: number[];
|
|
40
|
+
darkslategray: number[];
|
|
41
|
+
darkslategrey: number[];
|
|
42
|
+
darkturquoise: number[];
|
|
43
|
+
darkviolet: number[];
|
|
44
|
+
deeppink: number[];
|
|
45
|
+
deepskyblue: number[];
|
|
46
|
+
dimgray: number[];
|
|
47
|
+
dimgrey: number[];
|
|
48
|
+
dodgerblue: number[];
|
|
49
|
+
firebrick: number[];
|
|
50
|
+
floralwhite: number[];
|
|
51
|
+
forestgreen: number[];
|
|
52
|
+
fuchsia: number[];
|
|
53
|
+
gainsboro: number[];
|
|
54
|
+
ghostwhite: number[];
|
|
55
|
+
gold: number[];
|
|
56
|
+
goldenrod: number[];
|
|
57
|
+
gray: number[];
|
|
58
|
+
green: number[];
|
|
59
|
+
greenyellow: number[];
|
|
60
|
+
grey: number[];
|
|
61
|
+
honeydew: number[];
|
|
62
|
+
hotpink: number[];
|
|
63
|
+
indianred: number[];
|
|
64
|
+
indigo: number[];
|
|
65
|
+
ivory: number[];
|
|
66
|
+
khaki: number[];
|
|
67
|
+
lavender: number[];
|
|
68
|
+
lavenderblush: number[];
|
|
69
|
+
lawngreen: number[];
|
|
70
|
+
lemonchiffon: number[];
|
|
71
|
+
lightblue: number[];
|
|
72
|
+
lightcoral: number[];
|
|
73
|
+
lightcyan: number[];
|
|
74
|
+
lightgoldenrodyellow: number[];
|
|
75
|
+
lightgray: number[];
|
|
76
|
+
lightgreen: number[];
|
|
77
|
+
lightgrey: number[];
|
|
78
|
+
lightpink: number[];
|
|
79
|
+
lightsalmon: number[];
|
|
80
|
+
lightseagreen: number[];
|
|
81
|
+
lightskyblue: number[];
|
|
82
|
+
lightslategray: number[];
|
|
83
|
+
lightslategrey: number[];
|
|
84
|
+
lightsteelblue: number[];
|
|
85
|
+
lightyellow: number[];
|
|
86
|
+
lime: number[];
|
|
87
|
+
limegreen: number[];
|
|
88
|
+
linen: number[];
|
|
89
|
+
magenta: number[];
|
|
90
|
+
maroon: number[];
|
|
91
|
+
mediumaquamarine: number[];
|
|
92
|
+
mediumblue: number[];
|
|
93
|
+
mediumorchid: number[];
|
|
94
|
+
mediumpurple: number[];
|
|
95
|
+
mediumseagreen: number[];
|
|
96
|
+
mediumslateblue: number[];
|
|
97
|
+
mediumspringgreen: number[];
|
|
98
|
+
mediumturquoise: number[];
|
|
99
|
+
mediumvioletred: number[];
|
|
100
|
+
midnightblue: number[];
|
|
101
|
+
mintcream: number[];
|
|
102
|
+
mistyrose: number[];
|
|
103
|
+
moccasin: number[];
|
|
104
|
+
navajowhite: number[];
|
|
105
|
+
navy: number[];
|
|
106
|
+
oldlace: number[];
|
|
107
|
+
olive: number[];
|
|
108
|
+
olivedrab: number[];
|
|
109
|
+
orange: number[];
|
|
110
|
+
orangered: number[];
|
|
111
|
+
orchid: number[];
|
|
112
|
+
palegoldenrod: number[];
|
|
113
|
+
palegreen: number[];
|
|
114
|
+
paleturquoise: number[];
|
|
115
|
+
palevioletred: number[];
|
|
116
|
+
papayawhip: number[];
|
|
117
|
+
peachpuff: number[];
|
|
118
|
+
peru: number[];
|
|
119
|
+
pink: number[];
|
|
120
|
+
plum: number[];
|
|
121
|
+
powderblue: number[];
|
|
122
|
+
purple: number[];
|
|
123
|
+
rebeccapurple: number[];
|
|
124
|
+
red: number[];
|
|
125
|
+
rosybrown: number[];
|
|
126
|
+
royalblue: number[];
|
|
127
|
+
saddlebrown: number[];
|
|
128
|
+
salmon: number[];
|
|
129
|
+
sandybrown: number[];
|
|
130
|
+
seagreen: number[];
|
|
131
|
+
seashell: number[];
|
|
132
|
+
sienna: number[];
|
|
133
|
+
silver: number[];
|
|
134
|
+
skyblue: number[];
|
|
135
|
+
slateblue: number[];
|
|
136
|
+
slategray: number[];
|
|
137
|
+
slategrey: number[];
|
|
138
|
+
snow: number[];
|
|
139
|
+
springgreen: number[];
|
|
140
|
+
steelblue: number[];
|
|
141
|
+
tan: number[];
|
|
142
|
+
teal: number[];
|
|
143
|
+
thistle: number[];
|
|
144
|
+
tomato: number[];
|
|
145
|
+
turquoise: number[];
|
|
146
|
+
violet: number[];
|
|
147
|
+
wheat: number[];
|
|
148
|
+
white: number[];
|
|
149
|
+
whitesmoke: number[];
|
|
150
|
+
yellow: number[];
|
|
151
|
+
yellowgreen: number[];
|
|
152
|
+
};
|
|
153
|
+
declare function parseCSSColor(css_str: string): number[] | null;
|
|
154
|
+
declare function namedColor(name: keyof typeof kCSSColorTable): Color;
|
|
155
|
+
declare function namedColors(...names: (keyof typeof kCSSColorTable)[]): Color[];
|
|
156
|
+
export declare function colorStrToF4(str: string): float4;
|
|
157
|
+
/**
|
|
158
|
+
* Can parse any css color, array of 4 values [0 to 1.0], or a plain float4
|
|
159
|
+
*/
|
|
160
|
+
export declare function parseColor(input: string | number[] | float4): Color;
|
|
161
|
+
export { parseCSSColor, namedColor, namedColors };
|
|
@@ -0,0 +1,241 @@
|
|
|
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
|
+
const { float4: f4, float3: f3, PI } = CS.Unity.Mathematics.math;
|
|
4
|
+
const { Color } = CS.UnityEngine;
|
|
5
|
+
/*
|
|
6
|
+
https://github.com/deanm/css-color-parser-js
|
|
7
|
+
|
|
8
|
+
Minor changes were made for TS compatibility. Original License below:
|
|
9
|
+
|
|
10
|
+
(c) Dean McNamee <dean@gmail.com>, 2012.
|
|
11
|
+
|
|
12
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
13
|
+
of this software and associated documentation files (the "Software"), to
|
|
14
|
+
deal in the Software without restriction, including without limitation the
|
|
15
|
+
rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
|
|
16
|
+
sell copies of the Software, and to permit persons to whom the Software is
|
|
17
|
+
furnished to do so, subject to the following conditions:
|
|
18
|
+
|
|
19
|
+
The above copyright notice and this permission notice shall be included in
|
|
20
|
+
all copies or substantial portions of the Software.
|
|
21
|
+
|
|
22
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
23
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
24
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
25
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
26
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
|
27
|
+
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
|
|
28
|
+
IN THE SOFTWARE.
|
|
29
|
+
*/
|
|
30
|
+
var kCSSColorTable = {
|
|
31
|
+
"transparent": [0, 0, 0, 0], "aliceblue": [240, 248, 255, 1],
|
|
32
|
+
"antiquewhite": [250, 235, 215, 1], "aqua": [0, 255, 255, 1],
|
|
33
|
+
"aquamarine": [127, 255, 212, 1], "azure": [240, 255, 255, 1],
|
|
34
|
+
"beige": [245, 245, 220, 1], "bisque": [255, 228, 196, 1],
|
|
35
|
+
"black": [0, 0, 0, 1], "blanchedalmond": [255, 235, 205, 1],
|
|
36
|
+
"blue": [0, 0, 255, 1], "blueviolet": [138, 43, 226, 1],
|
|
37
|
+
"brown": [165, 42, 42, 1], "burlywood": [222, 184, 135, 1],
|
|
38
|
+
"cadetblue": [95, 158, 160, 1], "chartreuse": [127, 255, 0, 1],
|
|
39
|
+
"chocolate": [210, 105, 30, 1], "coral": [255, 127, 80, 1],
|
|
40
|
+
"cornflowerblue": [100, 149, 237, 1], "cornsilk": [255, 248, 220, 1],
|
|
41
|
+
"crimson": [220, 20, 60, 1], "cyan": [0, 255, 255, 1],
|
|
42
|
+
"darkblue": [0, 0, 139, 1], "darkcyan": [0, 139, 139, 1],
|
|
43
|
+
"darkgoldenrod": [184, 134, 11, 1], "darkgray": [169, 169, 169, 1],
|
|
44
|
+
"darkgreen": [0, 100, 0, 1], "darkgrey": [169, 169, 169, 1],
|
|
45
|
+
"darkkhaki": [189, 183, 107, 1], "darkmagenta": [139, 0, 139, 1],
|
|
46
|
+
"darkolivegreen": [85, 107, 47, 1], "darkorange": [255, 140, 0, 1],
|
|
47
|
+
"darkorchid": [153, 50, 204, 1], "darkred": [139, 0, 0, 1],
|
|
48
|
+
"darksalmon": [233, 150, 122, 1], "darkseagreen": [143, 188, 143, 1],
|
|
49
|
+
"darkslateblue": [72, 61, 139, 1], "darkslategray": [47, 79, 79, 1],
|
|
50
|
+
"darkslategrey": [47, 79, 79, 1], "darkturquoise": [0, 206, 209, 1],
|
|
51
|
+
"darkviolet": [148, 0, 211, 1], "deeppink": [255, 20, 147, 1],
|
|
52
|
+
"deepskyblue": [0, 191, 255, 1], "dimgray": [105, 105, 105, 1],
|
|
53
|
+
"dimgrey": [105, 105, 105, 1], "dodgerblue": [30, 144, 255, 1],
|
|
54
|
+
"firebrick": [178, 34, 34, 1], "floralwhite": [255, 250, 240, 1],
|
|
55
|
+
"forestgreen": [34, 139, 34, 1], "fuchsia": [255, 0, 255, 1],
|
|
56
|
+
"gainsboro": [220, 220, 220, 1], "ghostwhite": [248, 248, 255, 1],
|
|
57
|
+
"gold": [255, 215, 0, 1], "goldenrod": [218, 165, 32, 1],
|
|
58
|
+
"gray": [128, 128, 128, 1], "green": [0, 128, 0, 1],
|
|
59
|
+
"greenyellow": [173, 255, 47, 1], "grey": [128, 128, 128, 1],
|
|
60
|
+
"honeydew": [240, 255, 240, 1], "hotpink": [255, 105, 180, 1],
|
|
61
|
+
"indianred": [205, 92, 92, 1], "indigo": [75, 0, 130, 1],
|
|
62
|
+
"ivory": [255, 255, 240, 1], "khaki": [240, 230, 140, 1],
|
|
63
|
+
"lavender": [230, 230, 250, 1], "lavenderblush": [255, 240, 245, 1],
|
|
64
|
+
"lawngreen": [124, 252, 0, 1], "lemonchiffon": [255, 250, 205, 1],
|
|
65
|
+
"lightblue": [173, 216, 230, 1], "lightcoral": [240, 128, 128, 1],
|
|
66
|
+
"lightcyan": [224, 255, 255, 1], "lightgoldenrodyellow": [250, 250, 210, 1],
|
|
67
|
+
"lightgray": [211, 211, 211, 1], "lightgreen": [144, 238, 144, 1],
|
|
68
|
+
"lightgrey": [211, 211, 211, 1], "lightpink": [255, 182, 193, 1],
|
|
69
|
+
"lightsalmon": [255, 160, 122, 1], "lightseagreen": [32, 178, 170, 1],
|
|
70
|
+
"lightskyblue": [135, 206, 250, 1], "lightslategray": [119, 136, 153, 1],
|
|
71
|
+
"lightslategrey": [119, 136, 153, 1], "lightsteelblue": [176, 196, 222, 1],
|
|
72
|
+
"lightyellow": [255, 255, 224, 1], "lime": [0, 255, 0, 1],
|
|
73
|
+
"limegreen": [50, 205, 50, 1], "linen": [250, 240, 230, 1],
|
|
74
|
+
"magenta": [255, 0, 255, 1], "maroon": [128, 0, 0, 1],
|
|
75
|
+
"mediumaquamarine": [102, 205, 170, 1], "mediumblue": [0, 0, 205, 1],
|
|
76
|
+
"mediumorchid": [186, 85, 211, 1], "mediumpurple": [147, 112, 219, 1],
|
|
77
|
+
"mediumseagreen": [60, 179, 113, 1], "mediumslateblue": [123, 104, 238, 1],
|
|
78
|
+
"mediumspringgreen": [0, 250, 154, 1], "mediumturquoise": [72, 209, 204, 1],
|
|
79
|
+
"mediumvioletred": [199, 21, 133, 1], "midnightblue": [25, 25, 112, 1],
|
|
80
|
+
"mintcream": [245, 255, 250, 1], "mistyrose": [255, 228, 225, 1],
|
|
81
|
+
"moccasin": [255, 228, 181, 1], "navajowhite": [255, 222, 173, 1],
|
|
82
|
+
"navy": [0, 0, 128, 1], "oldlace": [253, 245, 230, 1],
|
|
83
|
+
"olive": [128, 128, 0, 1], "olivedrab": [107, 142, 35, 1],
|
|
84
|
+
"orange": [255, 165, 0, 1], "orangered": [255, 69, 0, 1],
|
|
85
|
+
"orchid": [218, 112, 214, 1], "palegoldenrod": [238, 232, 170, 1],
|
|
86
|
+
"palegreen": [152, 251, 152, 1], "paleturquoise": [175, 238, 238, 1],
|
|
87
|
+
"palevioletred": [219, 112, 147, 1], "papayawhip": [255, 239, 213, 1],
|
|
88
|
+
"peachpuff": [255, 218, 185, 1], "peru": [205, 133, 63, 1],
|
|
89
|
+
"pink": [255, 192, 203, 1], "plum": [221, 160, 221, 1],
|
|
90
|
+
"powderblue": [176, 224, 230, 1], "purple": [128, 0, 128, 1],
|
|
91
|
+
"rebeccapurple": [102, 51, 153, 1],
|
|
92
|
+
"red": [255, 0, 0, 1], "rosybrown": [188, 143, 143, 1],
|
|
93
|
+
"royalblue": [65, 105, 225, 1], "saddlebrown": [139, 69, 19, 1],
|
|
94
|
+
"salmon": [250, 128, 114, 1], "sandybrown": [244, 164, 96, 1],
|
|
95
|
+
"seagreen": [46, 139, 87, 1], "seashell": [255, 245, 238, 1],
|
|
96
|
+
"sienna": [160, 82, 45, 1], "silver": [192, 192, 192, 1],
|
|
97
|
+
"skyblue": [135, 206, 235, 1], "slateblue": [106, 90, 205, 1],
|
|
98
|
+
"slategray": [112, 128, 144, 1], "slategrey": [112, 128, 144, 1],
|
|
99
|
+
"snow": [255, 250, 250, 1], "springgreen": [0, 255, 127, 1],
|
|
100
|
+
"steelblue": [70, 130, 180, 1], "tan": [210, 180, 140, 1],
|
|
101
|
+
"teal": [0, 128, 128, 1], "thistle": [216, 191, 216, 1],
|
|
102
|
+
"tomato": [255, 99, 71, 1], "turquoise": [64, 224, 208, 1],
|
|
103
|
+
"violet": [238, 130, 238, 1], "wheat": [245, 222, 179, 1],
|
|
104
|
+
"white": [255, 255, 255, 1], "whitesmoke": [245, 245, 245, 1],
|
|
105
|
+
"yellow": [255, 255, 0, 1], "yellowgreen": [154, 205, 50, 1]
|
|
106
|
+
};
|
|
107
|
+
function clamp_css_byte(i) {
|
|
108
|
+
i = Math.round(i); // Seems to be what Chrome does (vs truncation).
|
|
109
|
+
return i < 0 ? 0 : i > 255 ? 255 : i;
|
|
110
|
+
}
|
|
111
|
+
function clamp_css_float(f) {
|
|
112
|
+
return f < 0 ? 0 : f > 1 ? 1 : f;
|
|
113
|
+
}
|
|
114
|
+
function parse_css_int(str) {
|
|
115
|
+
if (str[str.length - 1] === '%')
|
|
116
|
+
return clamp_css_byte(parseFloat(str) / 100 * 255);
|
|
117
|
+
return clamp_css_byte(parseInt(str));
|
|
118
|
+
}
|
|
119
|
+
function parse_css_float(str) {
|
|
120
|
+
if (str[str.length - 1] === '%')
|
|
121
|
+
return clamp_css_float(parseFloat(str) / 100);
|
|
122
|
+
return clamp_css_float(parseFloat(str));
|
|
123
|
+
}
|
|
124
|
+
function css_hue_to_rgb(m1, m2, h) {
|
|
125
|
+
if (h < 0)
|
|
126
|
+
h += 1;
|
|
127
|
+
else if (h > 1)
|
|
128
|
+
h -= 1;
|
|
129
|
+
if (h * 6 < 1)
|
|
130
|
+
return m1 + (m2 - m1) * h * 6;
|
|
131
|
+
if (h * 2 < 1)
|
|
132
|
+
return m2;
|
|
133
|
+
if (h * 3 < 2)
|
|
134
|
+
return m1 + (m2 - m1) * (2 / 3 - h) * 6;
|
|
135
|
+
return m1;
|
|
136
|
+
}
|
|
137
|
+
function parseCSSColor(css_str) {
|
|
138
|
+
// Remove all whitespace, not compliant, but should just be more accepting.
|
|
139
|
+
var str = css_str.replace(/ /g, '').toLowerCase();
|
|
140
|
+
// Color keywords (and transparent) lookup.
|
|
141
|
+
if (str in kCSSColorTable)
|
|
142
|
+
return kCSSColorTable[str].slice(); // dup.
|
|
143
|
+
// #abc and #abc123 syntax.
|
|
144
|
+
if (str[0] === '#') {
|
|
145
|
+
if (str.length === 4) {
|
|
146
|
+
var iv = parseInt(str.substr(1), 16); // TODO(deanm): Stricter parsing.
|
|
147
|
+
if (!(iv >= 0 && iv <= 0xfff))
|
|
148
|
+
return null; // Covers NaN.
|
|
149
|
+
return [((iv & 0xf00) >> 4) | ((iv & 0xf00) >> 8),
|
|
150
|
+
(iv & 0xf0) | ((iv & 0xf0) >> 4),
|
|
151
|
+
(iv & 0xf) | ((iv & 0xf) << 4),
|
|
152
|
+
1];
|
|
153
|
+
}
|
|
154
|
+
else if (str.length === 7) {
|
|
155
|
+
var iv = parseInt(str.substr(1), 16); // TODO(deanm): Stricter parsing.
|
|
156
|
+
if (!(iv >= 0 && iv <= 0xffffff))
|
|
157
|
+
return null; // Covers NaN.
|
|
158
|
+
return [(iv & 0xff0000) >> 16,
|
|
159
|
+
(iv & 0xff00) >> 8,
|
|
160
|
+
iv & 0xff,
|
|
161
|
+
1];
|
|
162
|
+
}
|
|
163
|
+
return null;
|
|
164
|
+
}
|
|
165
|
+
var op = str.indexOf('('), ep = str.indexOf(')');
|
|
166
|
+
if (op !== -1 && ep + 1 === str.length) {
|
|
167
|
+
var fname = str.substr(0, op);
|
|
168
|
+
var params = str.substr(op + 1, ep - (op + 1)).split(',');
|
|
169
|
+
var alpha = 1; // To allow case fallthrough.
|
|
170
|
+
switch (fname) {
|
|
171
|
+
case 'rgba':
|
|
172
|
+
if (params.length !== 4)
|
|
173
|
+
return null;
|
|
174
|
+
alpha = parse_css_float(params.pop());
|
|
175
|
+
// Fall through.
|
|
176
|
+
case 'rgb':
|
|
177
|
+
if (params.length !== 3)
|
|
178
|
+
return null;
|
|
179
|
+
return [parse_css_int(params[0]),
|
|
180
|
+
parse_css_int(params[1]),
|
|
181
|
+
parse_css_int(params[2]),
|
|
182
|
+
alpha];
|
|
183
|
+
case 'hsla':
|
|
184
|
+
if (params.length !== 4)
|
|
185
|
+
return null;
|
|
186
|
+
alpha = parse_css_float(params.pop());
|
|
187
|
+
// Fall through.
|
|
188
|
+
case 'hsl':
|
|
189
|
+
if (params.length !== 3)
|
|
190
|
+
return null;
|
|
191
|
+
var h = (((parseFloat(params[0]) % 360) + 360) % 360) / 360; // 0 .. 1
|
|
192
|
+
// NOTE(deanm): According to the CSS spec s/l should only be
|
|
193
|
+
// percentages, but we don't bother and let float or percentage.
|
|
194
|
+
var s = parse_css_float(params[1]);
|
|
195
|
+
var l = parse_css_float(params[2]);
|
|
196
|
+
var m2 = l <= 0.5 ? l * (s + 1) : l + s - l * s;
|
|
197
|
+
var m1 = l * 2 - m2;
|
|
198
|
+
return [clamp_css_byte(css_hue_to_rgb(m1, m2, h + 1 / 3) * 255),
|
|
199
|
+
clamp_css_byte(css_hue_to_rgb(m1, m2, h) * 255),
|
|
200
|
+
clamp_css_byte(css_hue_to_rgb(m1, m2, h - 1 / 3) * 255),
|
|
201
|
+
alpha];
|
|
202
|
+
default:
|
|
203
|
+
return null;
|
|
204
|
+
}
|
|
205
|
+
}
|
|
206
|
+
return null;
|
|
207
|
+
}
|
|
208
|
+
function namedColor(name) {
|
|
209
|
+
var c = kCSSColorTable[name];
|
|
210
|
+
return new Color(c[0] / 255, c[1] / 255, c[2] / 255, c[3]);
|
|
211
|
+
}
|
|
212
|
+
function namedColors(...names) {
|
|
213
|
+
let res = [];
|
|
214
|
+
for (const name of names) {
|
|
215
|
+
res.push(namedColor(name));
|
|
216
|
+
}
|
|
217
|
+
return res;
|
|
218
|
+
}
|
|
219
|
+
export function colorStrToF4(str) {
|
|
220
|
+
var c = parseCSSColor(str);
|
|
221
|
+
if (c == null)
|
|
222
|
+
throw `Color ${str} cannot be parsed`;
|
|
223
|
+
return f4(c[0] / 255, c[1] / 255, c[2] / 255, c[3]);
|
|
224
|
+
}
|
|
225
|
+
/**
|
|
226
|
+
* Can parse any css color, array of 4 values [0 to 1.0], or a plain float4
|
|
227
|
+
*/
|
|
228
|
+
export function parseColor(input) {
|
|
229
|
+
if (Array.isArray(input)) {
|
|
230
|
+
return new Color(input[0], input[1], input[2], input[3]);
|
|
231
|
+
}
|
|
232
|
+
else if (typeof input === "string") {
|
|
233
|
+
var c = parseCSSColor(input);
|
|
234
|
+
if (c !== null) {
|
|
235
|
+
return new Color(c[0] / 255, c[1] / 255, c[2] / 255, c[3]);
|
|
236
|
+
}
|
|
237
|
+
return new Color(0, 0, 0, 0);
|
|
238
|
+
}
|
|
239
|
+
return new Color(input.x, input.y, input.z, input.w);
|
|
240
|
+
}
|
|
241
|
+
export { parseCSSColor, namedColor, namedColors };
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
type float2 = CS.Unity.Mathematics.float2;
|
|
2
|
+
type float3 = CS.Unity.Mathematics.float3;
|
|
3
|
+
type float4 = CS.Unity.Mathematics.float4;
|
|
4
|
+
export declare function parseFloat2(input: any): float2;
|
|
5
|
+
export declare function parseFloat3(input: any): float3;
|
|
6
|
+
export declare function parseFloat4(input: any): float4;
|
|
7
|
+
export {};
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
// import { float2, float3, float4 } from "Unity/Mathematics" // JSR prepends a "./" to this, which messes things up
|
|
2
|
+
const { clamp, float2: f2, float3: f3, float4: f4 } = CS.Unity.Mathematics.math;
|
|
3
|
+
export function parseFloat2(input) {
|
|
4
|
+
if (!input)
|
|
5
|
+
return f2(0, 0);
|
|
6
|
+
if (Array.isArray(input))
|
|
7
|
+
input = f2(input[0] ?? 0, input[1] ?? 0);
|
|
8
|
+
return f2(input.x ?? 0, input.y ?? 0);
|
|
9
|
+
}
|
|
10
|
+
export function parseFloat3(input) {
|
|
11
|
+
if (!input)
|
|
12
|
+
return f3(0, 0, 0);
|
|
13
|
+
if (Array.isArray(input))
|
|
14
|
+
input = f3(input[0] ?? 0, input[1] ?? 0, input[2] ?? 0);
|
|
15
|
+
return f3(input.x ?? 0, input.y ?? 0, input.z ?? 0);
|
|
16
|
+
}
|
|
17
|
+
export function parseFloat4(input) {
|
|
18
|
+
if (!input)
|
|
19
|
+
return f4(0, 0, 0, 0);
|
|
20
|
+
if (Array.isArray(input))
|
|
21
|
+
input = f4(input[0] ?? 0, input[1] ?? 0, input[2] ?? 0, input[3] ?? 0);
|
|
22
|
+
return f4(input.x ?? 0, input.y ?? 0, input.z ?? 0, input.w ?? 0);
|
|
23
|
+
}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @module utils
|
|
3
|
+
*
|
|
4
|
+
* This module contains some commonly-used utility functions.
|
|
5
|
+
*/
|
|
6
|
+
export { parseColor, parseCSSColor, colorStrToF4, namedColor, namedColors } from "./color-parser";
|
|
7
|
+
export { palettes } from "./color-palettes";
|
|
8
|
+
export { parseFloat2, parseFloat3, parseFloat4 } from "./float-parser";
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @module utils
|
|
3
|
+
*
|
|
4
|
+
* This module contains some commonly-used utility functions.
|
|
5
|
+
*/
|
|
6
|
+
// @ts-ignore - prevent `allowImportingTsExtensions` error
|
|
7
|
+
export { parseColor, parseCSSColor, colorStrToF4, namedColor, namedColors } from "./color-parser";
|
|
8
|
+
// @ts-ignore - prevent `allowImportingTsExtensions` error
|
|
9
|
+
export { palettes } from "./color-palettes";
|
|
10
|
+
// @ts-ignore - prevent `allowImportingTsExtensions` error
|
|
11
|
+
export { parseFloat2, parseFloat3, parseFloat4 } from "./float-parser";
|
package/package.json
CHANGED