forked from Stability-AI/StableStudio
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.ts
109 lines (86 loc) · 2.92 KB
/
index.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
/* eslint-disable */
import { Buffer } from "buffer";
import { cx } from "@emotion/css";
import { css as cssImport } from "@emotion/react";
import immer, { Draft } from "immer";
import { default as throttle_ } from "lodash.throttle";
import ReactImport from "react";
import { twMerge } from "tailwind-merge";
declare global {
type CSSValue = string;
type Styleable = { className?: string };
type StyleableWithChildren = Styleable & React.PropsWithChildren;
type URLString = string;
type Mutable<T> = Draft<T>;
type ID = string;
type IDs = ID[];
var ID: typeof IDNamespace;
var React: typeof ReactImport;
var useState: typeof ReactImport.useState;
var useMemo: typeof ReactImport.useMemo;
var useCallback: typeof ReactImport.useCallback;
var useEffect: typeof ReactImport.useEffect;
var useRef: typeof ReactImport.useRef;
var useReducer: typeof ReactImport.useReducer;
var useContext: typeof ReactImport.useContext;
var useLayoutEffect: typeof ReactImport.useLayoutEffect;
var useDebugValue: typeof ReactImport.useDebugValue;
var keys: (...keys: (string | number | undefined)[]) => string;
var css: typeof cssImport;
var classes: typeof cx;
var spy: <A>(a: A) => A;
var spyJSON: <A>(a: A) => A;
var doNothing: (...args: unknown[]) => void;
var clamp: (min: number, value: number, max: number) => number;
var copy: typeof immer;
var throttle: typeof throttle_;
var toJSON: (value: unknown) => string;
}
namespace IDNamespace {
export const create = (): ID =>
"xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g, function (c) {
const r = (Math.random() * 16) | 0,
v = c == "x" ? r : (r & 0x3) | 0x8;
return v.toString(16);
});
}
globalThis.ID = IDNamespace;
globalThis.Buffer = Buffer;
globalThis.React = ReactImport;
globalThis.useState = ReactImport.useState;
globalThis.useMemo = ReactImport.useMemo;
globalThis.useCallback = ReactImport.useCallback;
globalThis.useEffect = ReactImport.useEffect;
globalThis.useRef = ReactImport.useRef;
globalThis.useReducer = ReactImport.useReducer;
globalThis.useContext = ReactImport.useContext;
globalThis.useLayoutEffect = ReactImport.useLayoutEffect;
globalThis.useDebugValue = ReactImport.useDebugValue;
globalThis.keys = function (...keys) {
return keys.map((key) => `${key}`).join(".");
};
globalThis.css = cssImport;
globalThis.classes = function (...classes) {
return twMerge(cx(...classes));
};
globalThis.spy = function (a) {
console.log(a);
return a;
};
globalThis.spyJSON = function (a) {
console.log(JSON.stringify(a, null, 2));
return a;
};
globalThis.doNothing = () => {};
globalThis.clamp = function (min, value, max) {
return Math.min(Math.max(min, value), max);
};
globalThis.copy = immer;
globalThis.throttle = throttle_;
globalThis.toJSON = function (value) {
try {
return JSON.stringify(value, null, 2);
} catch (ignored) {
return `{ "message": "Failed to parse JSON: \`${value}\`" }`;
}
};