onejs-core 0.3.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (63) hide show
  1. package/.gitattributes +2 -0
  2. package/.github/workflows/jsr.yml +19 -0
  3. package/.prettierrc +5 -0
  4. package/3rdparty/preact/LICENSE +21 -0
  5. package/3rdparty/preact/clone-element.ts +45 -0
  6. package/3rdparty/preact/compat/Children.ts +21 -0
  7. package/3rdparty/preact/compat/forwardRef.ts +49 -0
  8. package/3rdparty/preact/compat/index.ts +3 -0
  9. package/3rdparty/preact/compat/memo.ts +34 -0
  10. package/3rdparty/preact/compat/util.ts +38 -0
  11. package/3rdparty/preact/component.ts +235 -0
  12. package/3rdparty/preact/constants.ts +3 -0
  13. package/3rdparty/preact/create-context.ts +71 -0
  14. package/3rdparty/preact/create-element.ts +98 -0
  15. package/3rdparty/preact/diff/catch-error.ts +40 -0
  16. package/3rdparty/preact/diff/children.ts +355 -0
  17. package/3rdparty/preact/diff/index.ts +563 -0
  18. package/3rdparty/preact/diff/props.ts +174 -0
  19. package/3rdparty/preact/hooks/index.ts +536 -0
  20. package/3rdparty/preact/hooks/internal.d.ts +85 -0
  21. package/3rdparty/preact/hooks.d.ts +145 -0
  22. package/3rdparty/preact/index.ts +13 -0
  23. package/3rdparty/preact/internal.d.ts +155 -0
  24. package/3rdparty/preact/jsx-runtime/index.ts +80 -0
  25. package/3rdparty/preact/jsx.d.ts +1008 -0
  26. package/3rdparty/preact/options.ts +16 -0
  27. package/3rdparty/preact/preact.d.ts +317 -0
  28. package/3rdparty/preact/render.ts +76 -0
  29. package/3rdparty/preact/signals/index.ts +443 -0
  30. package/3rdparty/preact/signals/internal.d.ts +36 -0
  31. package/3rdparty/preact/signals-core/index.ts +663 -0
  32. package/3rdparty/preact/style.d.ts +205 -0
  33. package/3rdparty/preact/util.ts +29 -0
  34. package/@DO_NOT_CHANGE.txt +3 -0
  35. package/README.md +33 -0
  36. package/definitions/app.d.ts +52048 -0
  37. package/definitions/augments.d.ts +16 -0
  38. package/definitions/globals.d.ts +34 -0
  39. package/definitions/index.d.ts +9 -0
  40. package/definitions/jsx.d.ts +517 -0
  41. package/definitions/modules.d.ts +29 -0
  42. package/definitions/onejs.d.ts +164 -0
  43. package/definitions/preact.jsx.d.ts +7 -0
  44. package/definitions/proto-overrides.d.ts +13 -0
  45. package/definitions/puerts.d.ts +31 -0
  46. package/definitions/unity-engine.d.ts +23 -0
  47. package/hooks/eventful.ts +56 -0
  48. package/import-transform.mjs +42 -0
  49. package/index.ts +44 -0
  50. package/jsr.json +10 -0
  51. package/onejs-tw-config.cjs +188 -0
  52. package/package.json +9 -0
  53. package/preloads/inject.ts +44 -0
  54. package/styling/index.tsx +80 -0
  55. package/styling/utils/generateAlphabeticName.ts +21 -0
  56. package/styling/utils/generateComponentId.ts +6 -0
  57. package/styling/utils/hash.ts +46 -0
  58. package/switch.cjs +185 -0
  59. package/uss-transform-plugin.cjs +83 -0
  60. package/utils/color-palettes.ts +3 -0
  61. package/utils/color-parser.ts +249 -0
  62. package/utils/float-parser.ts +31 -0
  63. package/utils/index.ts +12 -0
@@ -0,0 +1,205 @@
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
+ }
@@ -0,0 +1,29 @@
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;
@@ -0,0 +1,3 @@
1
+ This onejs-core folder is managed by OneJS. It may get overriden during OneJS version updates. If you make any changes in here and would like to keep them, please back them up!
2
+
3
+ However, you may replace this folder with the actual repository at https://github.com/DragonGround/onejs-core if that fits your workflow better. OneJS won't delete/replace any folder with a .git folder inside.
package/README.md ADDED
@@ -0,0 +1,33 @@
1
+ This is the Core JS Lib for OneJS V2.
2
+
3
+ ---
4
+
5
+ ## h()
6
+
7
+ ```tsx
8
+ import { h } from "@onejs/core"
9
+
10
+ export default function (target) {
11
+ return <div>
12
+ <div>{target.make}</div>
13
+ <div>{target.year}</div>
14
+ <div>{target.color}</div>
15
+ </div>
16
+ }
17
+ ```
18
+
19
+ ## emo
20
+
21
+ ```ts
22
+ import { emo } from "onejs/styled"
23
+ import { h, render } from "preact"
24
+
25
+ const Foo = (props) => {
26
+ return <div class={emo`
27
+ font-size: ${props.size ?? 10}px;
28
+ color: red;
29
+ `}>Hello</div>
30
+ }
31
+
32
+ render(<Foo size={30} />, document.body)
33
+ ```