onejs-core 0.3.5 → 0.3.7

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 (73) hide show
  1. package/.vscode/settings.json +6 -0
  2. package/definitions/app.d.ts +52050 -52048
  3. package/definitions/augments.d.ts +28 -0
  4. package/definitions/index.d.ts +5 -4
  5. package/definitions/jsx.d.ts +389 -369
  6. package/definitions/onejs.d.ts +2 -1
  7. package/definitions/preact.jsx.d.ts +6 -6
  8. package/dist/dom/document.d.ts +14 -0
  9. package/dist/dom/document.js +22 -0
  10. package/dist/dom/dom-style.d.ts +7 -0
  11. package/dist/dom/dom-style.js +18 -0
  12. package/dist/dom/dom.d.ts +32 -0
  13. package/dist/dom/dom.js +62 -0
  14. package/dist/index.d.ts +20 -0
  15. package/dist/index.js +36 -0
  16. package/dist/preloads/inject.d.ts +2 -0
  17. package/dist/preloads/inject.js +35 -0
  18. package/dist/styling/index.d.ts +9 -0
  19. package/dist/styling/index.js +23 -0
  20. package/dist/styling/utils/generateAlphabeticName.d.ts +1 -0
  21. package/dist/styling/utils/generateAlphabeticName.js +16 -0
  22. package/dist/styling/utils/generateComponentId.d.ts +1 -0
  23. package/dist/styling/utils/generateComponentId.js +5 -0
  24. package/dist/styling/utils/hash.d.ts +5 -0
  25. package/dist/styling/utils/hash.js +34 -0
  26. package/dist/utils/color-palettes.d.ts +2 -0
  27. package/dist/utils/color-palettes.js +2 -0
  28. package/dist/utils/color-parser.d.ts +161 -0
  29. package/dist/utils/color-parser.js +241 -0
  30. package/dist/utils/float-parser.d.ts +7 -0
  31. package/dist/utils/float-parser.js +23 -0
  32. package/dist/utils/index.d.ts +8 -0
  33. package/dist/utils/index.js +11 -0
  34. package/dom/document.ts +34 -0
  35. package/dom/dom-style.ts +25 -0
  36. package/dom/dom.ts +76 -0
  37. package/import-transform.mjs +21 -1
  38. package/index.ts +14 -9
  39. package/package.json +15 -3
  40. package/styling/index.tsx +1 -54
  41. package/tsconfig.json +28 -0
  42. package/typings.d.ts +4 -0
  43. package/3rdparty/preact/LICENSE +0 -21
  44. package/3rdparty/preact/clone-element.ts +0 -45
  45. package/3rdparty/preact/compat/Children.ts +0 -21
  46. package/3rdparty/preact/compat/forwardRef.ts +0 -49
  47. package/3rdparty/preact/compat/index.ts +0 -3
  48. package/3rdparty/preact/compat/memo.ts +0 -34
  49. package/3rdparty/preact/compat/util.ts +0 -38
  50. package/3rdparty/preact/component.ts +0 -235
  51. package/3rdparty/preact/constants.ts +0 -3
  52. package/3rdparty/preact/create-context.ts +0 -71
  53. package/3rdparty/preact/create-element.ts +0 -98
  54. package/3rdparty/preact/diff/catch-error.ts +0 -40
  55. package/3rdparty/preact/diff/children.ts +0 -355
  56. package/3rdparty/preact/diff/index.ts +0 -563
  57. package/3rdparty/preact/diff/props.ts +0 -174
  58. package/3rdparty/preact/hooks/index.ts +0 -536
  59. package/3rdparty/preact/hooks/internal.d.ts +0 -85
  60. package/3rdparty/preact/hooks.d.ts +0 -145
  61. package/3rdparty/preact/index.ts +0 -13
  62. package/3rdparty/preact/internal.d.ts +0 -155
  63. package/3rdparty/preact/jsx-runtime/index.ts +0 -80
  64. package/3rdparty/preact/jsx.d.ts +0 -1008
  65. package/3rdparty/preact/options.ts +0 -16
  66. package/3rdparty/preact/preact.d.ts +0 -317
  67. package/3rdparty/preact/render.ts +0 -76
  68. package/3rdparty/preact/signals/index.ts +0 -443
  69. package/3rdparty/preact/signals/internal.d.ts +0 -36
  70. package/3rdparty/preact/signals-core/index.ts +0 -663
  71. package/3rdparty/preact/style.d.ts +0 -205
  72. package/3rdparty/preact/util.ts +0 -29
  73. package/hooks/eventful.ts +0 -56
@@ -1,205 +0,0 @@
1
-
2
-
3
-
4
- declare module "preact/jsx" {
5
- import { Color, Font, Texture, Texture2D, FontStyle, ScaleMode, TextAnchor, Sprite } from "UnityEngine"
6
- import { float2, float3, float4 } from "Unity/Mathematics"
7
- import { Align, BackgroundRepeat, DisplayStyle, EasingFunction, EasingMode, FlexDirection, FontDefinition, Justify, Overflow, OverflowClipBox, Position, TextOverflow, TextOverflowPosition, Visibility, WhiteSpace, Wrap } from "UnityEngine/UIElements"
8
-
9
- export type ColorInfo = float4 | number[] | string | Color
10
- type TextShadowInfo = { offset: float2 | number[], blurRadius: number, color: ColorInfo }
11
- type CursorInfo = { hotspot: float2 | number[], texture: Texture2D }
12
-
13
- export type Style = {
14
- alignContent?: keyof typeof Align
15
- alignItems?: keyof typeof Align
16
- alignSelf?: keyof typeof Align
17
- backgroundColor?: ColorInfo // StyleColor
18
- backgroundImage?: Sprite | Texture | string // StyleBackground
19
- backgroundSize?: BackgroundSize | string // StyleBackgroundSize
20
- backgroundRepeat?: BackgroundRepeat | string // StyleBackgroundRepeat
21
- // backgroundPosition?: string // TODO StyleBackgroundPosition (Custom)
22
- backgroundPositionX?: BackgroundPosition | string // StyleBackgroundPosition
23
- backgroundPositionY?: BackgroundPosition | string // StyleBackgroundPosition
24
-
25
- borderColor?: ColorInfo // StyleBorderColor (Custom)
26
- borderWidth?: number | number[] // StyleBorderWidth (Custom)
27
- borderRadius?: number | number[] // StyleBorderRadius (Custom)
28
- borderBottomColor?: ColorInfo // StyleColor
29
- borderBottomLeftRadius?: number | string // StyleLength
30
- borderBottomRightRadius?: number | string // StyleLength
31
- borderBottomWidth?: number // StyleFloat
32
- borderLeftColor?: ColorInfo // StyleColor
33
- borderLeftWidth?: number // StyleFloat
34
- borderRightColor?: ColorInfo // StyleColor
35
- borderRightWidth?: number // StyleFloat
36
- borderTopColor?: ColorInfo // StyleColor
37
- borderTopLeftRadius?: number | string // StyleLength
38
- borderTopRightRadius?: number | string // StyleLength
39
- borderTopWidth?: number // StyleFloat
40
-
41
- bottom?: number | string // StyleLength
42
- color?: ColorInfo // StyleColor
43
- cursor?: CursorInfo // StyleCursor
44
- display?: keyof typeof DisplayStyle
45
- flexBasis?: number | string // StyleLength
46
- flexDirection?: keyof typeof FlexDirection
47
- flexGrow?: number // StyleFloat
48
- flexShrink?: number // StyleFloat
49
- flexWrap?: keyof typeof Wrap
50
- fontSize?: number | string // StyleLength
51
- height?: number | string // StyleLength
52
-
53
- justifyContent?: keyof typeof Justify
54
- left?: number | string // StyleLength
55
- letterSpacing?: number | string // StyleLength
56
- margin?: number | number[] // StyleMargin (Custom)
57
- marginBottom?: number | string // StyleLength
58
- marginLeft?: number | string // StyleLength
59
- marginRight?: number | string // StyleLength
60
- marginTop?: number | string // StyleLength
61
- maxHeight?: number | string // StyleLength
62
- maxWidth?: number | string // StyleLength
63
- minHeight?: number | string // StyleLength
64
- minWidth?: number | string // StyleLength
65
- opacity?: number // StyleFloat
66
- overflow?: keyof typeof Overflow
67
- padding?: number | number[] // StylePadding (Custom)
68
- paddingBottom?: number | string // StyleLength
69
- paddingLeft?: number | string // StyleLength
70
- paddingRight?: number | string // StyleLength
71
- paddingTop?: number | string // StyleLength
72
- position?: keyof typeof Position
73
- right?: number | string // StyleLength
74
- rotate?: number | string // StyleRotate
75
- scale?: float2 | number[] // StyleScale
76
- textOverflow?: keyof typeof TextOverflow
77
- textShadow?: TextShadowInfo // StyleTextShadow
78
-
79
- top?: number | string // StyleLength
80
- transformOrigin?: float2 | number[] | string[] // StyleTransformOrigin
81
- transitionDelay?: number[] // StyleList<TimeValue>
82
- transitionDuration?: number[] // StyleList<TimeValue>
83
- transitionProperty?: (keyof StyleKeys)[] // StyleList<StylePropertyName>
84
- transitionTimingFunction?: (keyof typeof EasingMode)[] // StyleList<EasingFunction>
85
- translate?: float2 | number[] | string // StyleTranslate
86
- unityBackgroundImageTintColor?: ColorInfo // StyleColor
87
- unityBackgroundScaleMode?: keyof typeof ScaleMode
88
-
89
- unityFont?: Font | string // StyleFont
90
- unityFontDefinition?: FontDefinition | string // StyleFontDefinition
91
- unityFontStyleAndWeight?: keyof typeof FontStyle
92
- unityOverflowClipBox?: keyof typeof OverflowClipBox
93
- unityParagraphSpacing?: number | string // StyleLength
94
- unitySliceBottom?: number // StyleInt
95
- unitySliceLeft?: number // StyleInt
96
- unitySliceRight?: number // StyleInt
97
- unitySliceTop?: number // StyleInt
98
- unitySliceScale?: number // StyleFloat
99
-
100
- unityTextAlign?: keyof typeof TextAnchor
101
- unityTextOutlineColor?: ColorInfo // StyleColor
102
- unityTextOutlineWidth?: number // StyleFloat
103
- unityTextOverflowPosition?: keyof typeof TextOverflowPosition
104
- visibility?: keyof typeof Visibility
105
- whiteSpace?: keyof typeof WhiteSpace
106
- width?: number | string // StyleLength
107
- wordSpacing?: number | string // StyleLength
108
- }
109
-
110
- // UnityEngine.UIElements.StyleSheets.StylePropertyUtil
111
- export type StyleKeys = {
112
- "align-content": any,
113
- "align-items": any,
114
- "align-self": any,
115
- "all": any,
116
- "background-color": any,
117
- "background-image": any,
118
- "background-size": any,
119
- "background-repeat": any,
120
- "background-position-x": any,
121
- "background-position-y": any,
122
- "border-bottom-color": any,
123
- "border-bottom-left-radius": any,
124
- "border-bottom-right-radius": any,
125
- "border-bottom-width": any,
126
- "border-color": any,
127
- "border-left-color": any,
128
- "border-left-width": any,
129
- "border-radius": any,
130
- "border-right-color": any,
131
- "border-right-width": any,
132
- "border-top-color": any,
133
- "border-top-left-radius": any,
134
- "border-top-right-radius": any,
135
- "border-top-width": any,
136
- "border-width": any,
137
- "bottom": any,
138
- "color": any,
139
- "cursor": any,
140
- "display": any,
141
- "flex": any,
142
- "flex-basis": any,
143
- "flex-direction": any,
144
- "flex-grow": any,
145
- "flex-shrink": any,
146
- "flex-wrap": any,
147
- "font-size": any,
148
- "height": any,
149
- "justify-content": any,
150
- "left": any,
151
- "letter-spacing": any,
152
- "margin": any,
153
- "margin-bottom": any,
154
- "margin-left": any,
155
- "margin-right": any,
156
- "margin-top": any,
157
- "max-height": any,
158
- "max-width": any,
159
- "min-height": any,
160
- "min-width": any,
161
- "opacity": any,
162
- "overflow": any,
163
- "padding": any,
164
- "padding-bottom": any,
165
- "padding-left": any,
166
- "padding-right": any,
167
- "padding-top": any,
168
- "position": any,
169
- "right": any,
170
- "rotate": any,
171
- "scale": any,
172
- "text-overflow": any,
173
- "text-shadow": any,
174
- "top": any,
175
- "transform-origin": any,
176
- "transition": any,
177
- "transition-delay": any,
178
- "transition-duration": any,
179
- "transition-property": any,
180
- "transition-timing-function": any,
181
- "translate": any,
182
- "-unity-background-image-tint-color": any,
183
- "-unity-background-scale-mode": any,
184
- "-unity-font": any,
185
- "-unity-font-definition": any,
186
- "-unity-font-style": any,
187
- "-unity-overflow-clip-box": any,
188
- "-unity-paragraph-spacing": any,
189
- "-unity-slice-bottom": any,
190
- "-unity-slice-left": any,
191
- "-unity-slice-right": any,
192
- "-unity-slice-top": any,
193
- "-unity-slice-scale": any,
194
- "-unity-text-align": any,
195
- "-unity-text-outline": any,
196
- "-unity-text-outline-color": any,
197
- "-unity-text-outline-width": any,
198
- "-unity-text-overflow-position": any,
199
- "visibility": any,
200
- "white-space": any,
201
- "width": any,
202
- "word-spacing": any,
203
- }
204
-
205
- }
@@ -1,29 +0,0 @@
1
- import { EMPTY_ARR } from "./constants";
2
-
3
- export const isArray = Array.isArray;
4
-
5
- /**
6
- * Assign properties from `props` to `obj`
7
- * @template O, P The obj and props types
8
- * @param {O} obj The object to copy properties to
9
- * @param {P} props The object to copy properties from
10
- * @returns {O & P}
11
- */
12
- export function assign(obj, props) {
13
- // @ts-ignore We change the type of `obj` to be `O & P`
14
- for (let i in props) obj[i] = props[i];
15
- return /** @type {O & P} */ (obj);
16
- }
17
-
18
- /**
19
- * Remove a child node from its parent if attached. This is a workaround for
20
- * IE11 which doesn't support `Element.prototype.remove()`. Using this function
21
- * is smaller than including a dedicated polyfill.
22
- * @param {Node} node The node to remove
23
- */
24
- export function removeNode(node) {
25
- let parentNode = node.parentNode;
26
- if (parentNode) parentNode.removeChild(node);
27
- }
28
-
29
- export const slice = EMPTY_ARR.slice;
package/hooks/eventful.ts DELETED
@@ -1,56 +0,0 @@
1
- import { Dom } from "OneJS/Dom"
2
- import { VisualElement } from "UnityEngine/UIElements"
3
- import { MutableRef, StateUpdater, useCallback, useEffect, useState } from "preact/hooks"
4
-
5
- /**
6
- * A convenience hook that, like useState(), returns a stateful value and a function to update it.
7
- * This one ties the value to a property on a C# object.
8
- * It takes care of setting up and cleaning up the C# value changed event automatically.
9
- * Refer here for more info: https://onejs.com/docs/uiworkflow#reducing-boilerplates
10
- *
11
- * @param obj The C# object containing the property to be observed
12
- * @param propertyName The name of the property to be observed
13
- * @param eventName The name of the event to be observed. If not specified, it defaults to "On{propertyName}Changed"
14
- * @returns
15
- */
16
- export function useEventfulState<
17
- T extends { [k in `On${K}Changed`]: OneJS.Event<(value: T[K]) => void> },
18
- K extends string & keyof T
19
- >(obj: T, propertyName: K): [T[K], StateUpdater<T[K]>]
20
- export function useEventfulState<T, K extends string & keyof T, E extends OneJS.EventKeys<T>>(
21
- obj: T,
22
- propertyName: K,
23
- eventName: E
24
- ): [T[K], StateUpdater<T[K]>]
25
- export function useEventfulState<
26
- T extends { [k in keyof T]: k extends E ? OneJS.Event<(value: T[K]) => void> : any },
27
- K extends string & keyof T,
28
- E extends OneJS.EventKeys<T>
29
- >(obj: T, propertyName: K, eventName?: E): [T[K], StateUpdater<T[K]>] {
30
- // Guarantee the component is re-rendered on changed event,
31
- // by ensuring that the state is always updated with a different identity
32
- // to handle the case where the object property is an array
33
- // and the changed event is raised with the same array instance.
34
- const [state, setState] = useState({ value: obj?.[propertyName] })
35
- const setValue = useCallback((value) => setState({ value }), [])
36
-
37
- useEffect(() => {
38
- if (obj == null) return
39
-
40
- eventName ??= `On${propertyName}Changed` as E
41
- setValue(obj[propertyName])
42
- return onejs.subscribe(obj, eventName, setValue as OneJS.EventGenericType<T[E]>)
43
- }, [obj])
44
-
45
- const setValWrapper = useCallback(
46
- (v: T[K]) => {
47
- if (obj == null) return
48
-
49
- obj[propertyName] = v
50
- // setVal(v) // No need to set the state here in JS. The event handling stuff above will do.
51
- },
52
- [obj]
53
- )
54
-
55
- return [state.value as T[K], setValWrapper]
56
- }