@reactunity/renderer 0.21.0 → 0.23.1

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 (242) hide show
  1. package/dist/base-BT2GMEbv.d.ts +17122 -0
  2. package/dist/components-Cbty8Ffc.d.ts +153 -0
  3. package/dist/editor/index.d.ts +15 -1
  4. package/dist/editor/index.js +1 -2
  5. package/dist/editor/jsx-dev-runtime.d.ts +3 -3
  6. package/dist/editor/jsx-dev-runtime.js +2 -2
  7. package/dist/editor/jsx-runtime.d.ts +3 -2
  8. package/dist/editor/jsx-runtime.js +2 -2
  9. package/dist/editor-Ds4U7pg6.d.ts +19438 -0
  10. package/dist/index-CBMYN8iy.d.ts +1 -0
  11. package/dist/index.d.ts +587 -19
  12. package/dist/index.js +1020 -17
  13. package/dist/index.js.map +1 -1
  14. package/dist/jsx-9V8cIFit.d.ts +114 -0
  15. package/dist/jsx-BZUfiU1y.d.ts +57 -0
  16. package/dist/jsx-DXzVL17E.d.ts +231 -0
  17. package/dist/objectSpread2-CDDvZyE7.js +62 -0
  18. package/dist/tests-DbTTvHZm.d.ts +5044 -0
  19. package/dist/tests.d.ts +15 -1
  20. package/dist/tests.js +1 -2
  21. package/dist/ugui/index.d.ts +3 -1
  22. package/dist/ugui/index.js +1 -2
  23. package/dist/ugui/jsx-dev-runtime.d.ts +3 -3
  24. package/dist/ugui/jsx-dev-runtime.js +2 -2
  25. package/dist/ugui/jsx-runtime.d.ts +3 -2
  26. package/dist/ugui/jsx-runtime.js +2 -2
  27. package/dist/uitoolkit/index.d.ts +3 -1
  28. package/dist/uitoolkit/index.js +1 -2
  29. package/dist/uitoolkit/jsx-dev-runtime.d.ts +3 -3
  30. package/dist/uitoolkit/jsx-dev-runtime.js +2 -2
  31. package/dist/uitoolkit/jsx-runtime.d.ts +3 -2
  32. package/dist/uitoolkit/jsx-runtime.js +2 -2
  33. package/dist/unity-BQNCBoTP.d.ts +86554 -0
  34. package/dist/webgl-compat.d.ts +64 -1
  35. package/dist/webgl-compat.js +184 -1
  36. package/dist/webgl-compat.js.map +1 -1
  37. package/package.json +29 -20
  38. package/dist/editor/index.js.map +0 -1
  39. package/dist/editor/jsx-dev-runtime.js.map +0 -1
  40. package/dist/editor/jsx-runtime.js.map +0 -1
  41. package/dist/src/helpers/dictionary-watcher.d.ts +0 -66
  42. package/dist/src/helpers/dictionary-watcher.js +0 -100
  43. package/dist/src/helpers/dictionary-watcher.js.map +0 -1
  44. package/dist/src/helpers/hooks/use-globals.d.ts +0 -6
  45. package/dist/src/helpers/hooks/use-globals.js +0 -7
  46. package/dist/src/helpers/hooks/use-globals.js.map +0 -1
  47. package/dist/src/helpers/hooks/use-reactive-value.d.ts +0 -4
  48. package/dist/src/helpers/hooks/use-reactive-value.js +0 -29
  49. package/dist/src/helpers/hooks/use-reactive-value.js.map +0 -1
  50. package/dist/src/helpers/icons.d.ts +0 -17
  51. package/dist/src/helpers/icons.js +0 -30
  52. package/dist/src/helpers/icons.js.map +0 -1
  53. package/dist/src/models/base.d.ts +0 -56
  54. package/dist/src/models/base.js +0 -2
  55. package/dist/src/models/base.js.map +0 -1
  56. package/dist/src/models/editor/components.d.ts +0 -22
  57. package/dist/src/models/editor/components.js +0 -2
  58. package/dist/src/models/editor/components.js.map +0 -1
  59. package/dist/src/models/editor/environment.d.ts +0 -9
  60. package/dist/src/models/editor/environment.js +0 -2
  61. package/dist/src/models/editor/environment.js.map +0 -1
  62. package/dist/src/models/editor/index.d.ts +0 -3
  63. package/dist/src/models/editor/index.js +0 -4
  64. package/dist/src/models/editor/index.js.map +0 -1
  65. package/dist/src/models/editor/jsx.d.ts +0 -105
  66. package/dist/src/models/editor/jsx.js +0 -2
  67. package/dist/src/models/editor/jsx.js.map +0 -1
  68. package/dist/src/models/environment/dom/common.d.ts +0 -98
  69. package/dist/src/models/environment/dom/common.js +0 -2
  70. package/dist/src/models/environment/dom/common.js.map +0 -1
  71. package/dist/src/models/environment/dom/fetch.d.ts +0 -111
  72. package/dist/src/models/environment/dom/fetch.js +0 -2
  73. package/dist/src/models/environment/dom/fetch.js.map +0 -1
  74. package/dist/src/models/environment/dom/global.d.ts +0 -14
  75. package/dist/src/models/environment/dom/global.js +0 -2
  76. package/dist/src/models/environment/dom/global.js.map +0 -1
  77. package/dist/src/models/environment/dom/xhr.d.ts +0 -161
  78. package/dist/src/models/environment/dom/xhr.js +0 -2
  79. package/dist/src/models/environment/dom/xhr.js.map +0 -1
  80. package/dist/src/models/environment/index.d.ts +0 -43
  81. package/dist/src/models/environment/index.js +0 -3
  82. package/dist/src/models/environment/index.js.map +0 -1
  83. package/dist/src/models/environment/interop.d.ts +0 -23
  84. package/dist/src/models/environment/interop.js +0 -2
  85. package/dist/src/models/environment/interop.js.map +0 -1
  86. package/dist/src/models/generated/editor.d.ts +0 -19444
  87. package/dist/src/models/generated/editor.js +0 -7
  88. package/dist/src/models/generated/editor.js.map +0 -1
  89. package/dist/src/models/generated/index.d.ts +0 -6
  90. package/dist/src/models/generated/index.js +0 -7
  91. package/dist/src/models/generated/index.js.map +0 -1
  92. package/dist/src/models/generated/react.d.ts +0 -16094
  93. package/dist/src/models/generated/react.js +0 -7
  94. package/dist/src/models/generated/react.js.map +0 -1
  95. package/dist/src/models/generated/system.d.ts +0 -36981
  96. package/dist/src/models/generated/system.js +0 -7
  97. package/dist/src/models/generated/system.js.map +0 -1
  98. package/dist/src/models/generated/tests.d.ts +0 -5045
  99. package/dist/src/models/generated/tests.js +0 -7
  100. package/dist/src/models/generated/tests.js.map +0 -1
  101. package/dist/src/models/generated/unity.d.ts +0 -49639
  102. package/dist/src/models/generated/unity.js +0 -7
  103. package/dist/src/models/generated/unity.js.map +0 -1
  104. package/dist/src/models/generated/yoga.d.ts +0 -426
  105. package/dist/src/models/generated/yoga.js +0 -7
  106. package/dist/src/models/generated/yoga.js.map +0 -1
  107. package/dist/src/models/properties/colors.d.ts +0 -150
  108. package/dist/src/models/properties/colors.js +0 -2
  109. package/dist/src/models/properties/colors.js.map +0 -1
  110. package/dist/src/models/properties/common.d.ts +0 -3
  111. package/dist/src/models/properties/common.js +0 -2
  112. package/dist/src/models/properties/common.js.map +0 -1
  113. package/dist/src/models/properties/index.d.ts +0 -7
  114. package/dist/src/models/properties/index.js +0 -8
  115. package/dist/src/models/properties/index.js.map +0 -1
  116. package/dist/src/models/properties/style.d.ts +0 -10
  117. package/dist/src/models/properties/style.js +0 -2
  118. package/dist/src/models/properties/style.js.map +0 -1
  119. package/dist/src/models/properties/styles-enums.d.ts +0 -23
  120. package/dist/src/models/properties/styles-enums.js +0 -2
  121. package/dist/src/models/properties/styles-enums.js.map +0 -1
  122. package/dist/src/models/properties/styles.d.ts +0 -127
  123. package/dist/src/models/properties/styles.js +0 -2
  124. package/dist/src/models/properties/styles.js.map +0 -1
  125. package/dist/src/models/properties/values.d.ts +0 -24
  126. package/dist/src/models/properties/values.js +0 -2
  127. package/dist/src/models/properties/values.js.map +0 -1
  128. package/dist/src/models/properties/yoga-enums.d.ts +0 -9
  129. package/dist/src/models/properties/yoga-enums.js +0 -2
  130. package/dist/src/models/properties/yoga-enums.js.map +0 -1
  131. package/dist/src/models/properties/yoga.d.ts +0 -67
  132. package/dist/src/models/properties/yoga.js +0 -2
  133. package/dist/src/models/properties/yoga.js.map +0 -1
  134. package/dist/src/models/renderer.d.ts +0 -23
  135. package/dist/src/models/renderer.js +0 -2
  136. package/dist/src/models/renderer.js.map +0 -1
  137. package/dist/src/models/richtext.d.ts +0 -69
  138. package/dist/src/models/richtext.js +0 -2
  139. package/dist/src/models/richtext.js.map +0 -1
  140. package/dist/src/models/svg.d.ts +0 -68
  141. package/dist/src/models/svg.js +0 -2
  142. package/dist/src/models/svg.js.map +0 -1
  143. package/dist/src/models/tests/index.d.ts +0 -12
  144. package/dist/src/models/tests/index.js +0 -2
  145. package/dist/src/models/tests/index.js.map +0 -1
  146. package/dist/src/models/ugui/components.d.ts +0 -85
  147. package/dist/src/models/ugui/components.js +0 -2
  148. package/dist/src/models/ugui/components.js.map +0 -1
  149. package/dist/src/models/ugui/events.d.ts +0 -74
  150. package/dist/src/models/ugui/events.js +0 -2
  151. package/dist/src/models/ugui/events.js.map +0 -1
  152. package/dist/src/models/ugui/index.d.ts +0 -4
  153. package/dist/src/models/ugui/index.js +0 -5
  154. package/dist/src/models/ugui/index.js.map +0 -1
  155. package/dist/src/models/ugui/input.d.ts +0 -26
  156. package/dist/src/models/ugui/input.js +0 -2
  157. package/dist/src/models/ugui/input.js.map +0 -1
  158. package/dist/src/models/ugui/jsx.d.ts +0 -67
  159. package/dist/src/models/ugui/jsx.js +0 -2
  160. package/dist/src/models/ugui/jsx.js.map +0 -1
  161. package/dist/src/models/uitoolkit/components.d.ts +0 -98
  162. package/dist/src/models/uitoolkit/components.js +0 -2
  163. package/dist/src/models/uitoolkit/components.js.map +0 -1
  164. package/dist/src/models/uitoolkit/events.d.ts +0 -64
  165. package/dist/src/models/uitoolkit/events.js +0 -2
  166. package/dist/src/models/uitoolkit/events.js.map +0 -1
  167. package/dist/src/models/uitoolkit/index.d.ts +0 -3
  168. package/dist/src/models/uitoolkit/index.js +0 -4
  169. package/dist/src/models/uitoolkit/index.js.map +0 -1
  170. package/dist/src/models/uitoolkit/jsx.d.ts +0 -67
  171. package/dist/src/models/uitoolkit/jsx.js +0 -2
  172. package/dist/src/models/uitoolkit/jsx.js.map +0 -1
  173. package/dist/src/renderer/async/callbacks.d.ts +0 -5
  174. package/dist/src/renderer/async/callbacks.js +0 -53
  175. package/dist/src/renderer/async/callbacks.js.map +0 -1
  176. package/dist/src/renderer/async/commands.d.ts +0 -71
  177. package/dist/src/renderer/async/commands.js +0 -2
  178. package/dist/src/renderer/async/commands.js.map +0 -1
  179. package/dist/src/renderer/async/objects.d.ts +0 -7
  180. package/dist/src/renderer/async/objects.js +0 -32
  181. package/dist/src/renderer/async/objects.js.map +0 -1
  182. package/dist/src/renderer/async/reconciler.d.ts +0 -2
  183. package/dist/src/renderer/async/reconciler.js +0 -321
  184. package/dist/src/renderer/async/reconciler.js.map +0 -1
  185. package/dist/src/renderer/async/serializer.d.ts +0 -6
  186. package/dist/src/renderer/async/serializer.js +0 -32
  187. package/dist/src/renderer/async/serializer.js.map +0 -1
  188. package/dist/src/renderer/async/types.d.ts +0 -45
  189. package/dist/src/renderer/async/types.js +0 -2
  190. package/dist/src/renderer/async/types.js.map +0 -1
  191. package/dist/src/renderer/constants.d.ts +0 -46
  192. package/dist/src/renderer/constants.js +0 -90
  193. package/dist/src/renderer/constants.js.map +0 -1
  194. package/dist/src/renderer/diffing.d.ts +0 -3
  195. package/dist/src/renderer/diffing.js +0 -79
  196. package/dist/src/renderer/diffing.js.map +0 -1
  197. package/dist/src/renderer/renderer.d.ts +0 -23
  198. package/dist/src/renderer/renderer.js +0 -124
  199. package/dist/src/renderer/renderer.js.map +0 -1
  200. package/dist/src/renderer/subcontexts/index.d.ts +0 -6
  201. package/dist/src/renderer/subcontexts/index.js +0 -7
  202. package/dist/src/renderer/subcontexts/index.js.map +0 -1
  203. package/dist/src/renderer/subcontexts/richtext.d.ts +0 -3
  204. package/dist/src/renderer/subcontexts/richtext.js +0 -53
  205. package/dist/src/renderer/subcontexts/richtext.js.map +0 -1
  206. package/dist/src/renderer/subcontexts/svg.d.ts +0 -3
  207. package/dist/src/renderer/subcontexts/svg.js +0 -71
  208. package/dist/src/renderer/subcontexts/svg.js.map +0 -1
  209. package/dist/src/renderer/sync/reconciler.d.ts +0 -2
  210. package/dist/src/renderer/sync/reconciler.js +0 -80
  211. package/dist/src/renderer/sync/reconciler.js.map +0 -1
  212. package/dist/src/version.d.ts +0 -1
  213. package/dist/src/version.js +0 -2
  214. package/dist/src/version.js.map +0 -1
  215. package/dist/src/views/default-view.d.ts +0 -8
  216. package/dist/src/views/default-view.js +0 -7
  217. package/dist/src/views/default-view.js.map +0 -1
  218. package/dist/src/views/error-boundary.d.ts +0 -10
  219. package/dist/src/views/error-boundary.js +0 -43
  220. package/dist/src/views/error-boundary.js.map +0 -1
  221. package/dist/src/webgl-compat/error-messages.d.ts +0 -9
  222. package/dist/src/webgl-compat/error-messages.js +0 -11
  223. package/dist/src/webgl-compat/error-messages.js.map +0 -1
  224. package/dist/src/webgl-compat/index.d.ts +0 -15
  225. package/dist/src/webgl-compat/index.js +0 -9
  226. package/dist/src/webgl-compat/index.js.map +0 -1
  227. package/dist/src/webgl-compat/types.d.ts +0 -21
  228. package/dist/src/webgl-compat/types.js +0 -2
  229. package/dist/src/webgl-compat/types.js.map +0 -1
  230. package/dist/src/webgl-compat/use-event-system.d.ts +0 -3
  231. package/dist/src/webgl-compat/use-event-system.js +0 -75
  232. package/dist/src/webgl-compat/use-event-system.js.map +0 -1
  233. package/dist/src/webgl-compat/use-unity-context.d.ts +0 -31
  234. package/dist/src/webgl-compat/use-unity-context.js +0 -91
  235. package/dist/src/webgl-compat/use-unity-context.js.map +0 -1
  236. package/dist/tests.js.map +0 -1
  237. package/dist/ugui/index.js.map +0 -1
  238. package/dist/ugui/jsx-dev-runtime.js.map +0 -1
  239. package/dist/ugui/jsx-runtime.js.map +0 -1
  240. package/dist/uitoolkit/index.js.map +0 -1
  241. package/dist/uitoolkit/jsx-dev-runtime.js.map +0 -1
  242. package/dist/uitoolkit/jsx-runtime.js.map +0 -1
package/dist/index.js CHANGED
@@ -1,18 +1,1021 @@
1
- export * from './src/helpers/dictionary-watcher';
2
- export * from './src/helpers/hooks/use-globals';
3
- export * from './src/helpers/hooks/use-reactive-value';
4
- export * from './src/helpers/icons';
5
- export * from './src/models/environment';
6
- export * from './src/models/generated';
7
- export * from './src/models/properties';
8
- export * from './src/models/renderer';
9
- export { Renderer, batchedUpdates, flushSync, render, batchedUpdates as unstable_batchedUpdates, } from './src/renderer/renderer';
10
- import { batchedUpdates, flushSync, render } from './src/renderer/renderer';
11
- var ReactUnityRenderer = {
12
- batchedUpdates: batchedUpdates,
13
- flushSync: flushSync,
14
- render: render,
15
- unstable_batchedUpdates: batchedUpdates,
16
- };
17
- export default ReactUnityRenderer;
1
+ import { n as _defineProperty, t as _objectSpread2 } from "./objectSpread2-CDDvZyE7.js";
2
+ import * as React from "react";
3
+ import { createContext, createElement, useContext, useMemo, useRef, useState } from "react";
4
+ import { useSyncExternalStore } from "use-sync-external-store/shim";
5
+ import { useSyncExternalStoreWithSelector } from "use-sync-external-store/with-selector";
6
+ import { ConcurrentRoot, ContinuousEventPriority, DefaultEventPriority, DiscreteEventPriority, IdleEventPriority, LegacyRoot } from "react-reconciler/constants.js";
7
+ import { Fragment, jsx, jsxs } from "react/jsx-runtime";
8
+ import Reconciler from "react-reconciler";
9
+ //#region src/helpers/dictionary-watcher.ts
10
+ /**
11
+ * Creates a context that updates its value when the values in the dictionary change
12
+ * @param dictionary The dictionary to be watched. Must implement the EventDictionary type in the C#
13
+ * @param displayName A displayName to identify this context easier in case of problems
14
+ */
15
+ function createDictionaryWatcher(dictionary, displayName) {
16
+ const ctx = createContext(void 0);
17
+ if (displayName) ctx.displayName = displayName;
18
+ const createSubscriber = (fields, isEqual) => {
19
+ let snapshot = _objectSpread2({}, dictionary);
20
+ return {
21
+ subscribe: (onStoreChange) => {
22
+ snapshot = _objectSpread2({}, dictionary);
23
+ const remove = dictionary === null || dictionary === void 0 ? void 0 : dictionary.AddListener(() => {
24
+ const prev = snapshot;
25
+ snapshot = _objectSpread2({}, dictionary);
26
+ if (!fields) onStoreChange();
27
+ else {
28
+ const it = fields.values();
29
+ for (let field = it.next().value; field; field = it.next().value) if (isEqual ? !isEqual(prev[field], snapshot[field]) : prev[field] !== snapshot[field]) {
30
+ onStoreChange();
31
+ break;
32
+ }
33
+ }
34
+ });
35
+ if (!remove) if (displayName) console.warn(`${displayName} dictionary does not provide a change listener`);
36
+ else console.warn("The dictionary does not provide a change listener");
37
+ return () => remove === null || remove === void 0 ? void 0 : remove();
38
+ },
39
+ getSnapshot: () => snapshot
40
+ };
41
+ };
42
+ const defaultSubscriber = createSubscriber();
43
+ const Provider = function GlobalsProvider({ children }) {
44
+ const value = useSyncExternalStore(defaultSubscriber.subscribe, defaultSubscriber.getSnapshot, defaultSubscriber.getSnapshot);
45
+ return createElement(ctx.Provider, { value }, children);
46
+ };
47
+ function useDictionaryContext() {
48
+ const context = useContext(ctx);
49
+ if (context === void 0) {
50
+ if (displayName) throw new Error(`${displayName}.useContext must be used within a ${displayName}.Provider`);
51
+ throw new Error("useContext must be used within a provider");
52
+ }
53
+ return context;
54
+ }
55
+ function useValue(subscribeToAllFields = false, fieldEqual) {
56
+ const fields = useMemo(() => /* @__PURE__ */ new Set(), []);
57
+ const fieldsRef = useRef(fields);
58
+ const [allFieldsSubscribed, setAllFieldsSubscribed] = useState(false);
59
+ subscribeToAllFields || (subscribeToAllFields = allFieldsSubscribed);
60
+ const subscriber = useMemo(() => subscribeToAllFields ? defaultSubscriber : createSubscriber(fieldsRef.current, fieldEqual), [subscribeToAllFields, fieldEqual]);
61
+ const value = useSyncExternalStore(subscriber.subscribe, subscriber.getSnapshot, subscriber.getSnapshot);
62
+ return new Proxy(value, {
63
+ get(target, p, receiver) {
64
+ fields.add(p);
65
+ return value[p];
66
+ },
67
+ ownKeys(target) {
68
+ if (!allFieldsSubscribed) setAllFieldsSubscribed(true);
69
+ return Reflect.ownKeys(target);
70
+ },
71
+ getOwnPropertyDescriptor(target, p) {
72
+ fields.add(p);
73
+ return _objectSpread2(_objectSpread2({}, Reflect.getOwnPropertyDescriptor(target, p)), {}, { value: value[p] });
74
+ }
75
+ });
76
+ }
77
+ function useSelector(selector, isEqual) {
78
+ return useSyncExternalStoreWithSelector(defaultSubscriber.subscribe, defaultSubscriber.getSnapshot, defaultSubscriber.getSnapshot, selector, isEqual);
79
+ }
80
+ return {
81
+ context: ctx,
82
+ Provider,
83
+ useValue,
84
+ useContext: useDictionaryContext,
85
+ useSelector
86
+ };
87
+ }
88
+ //#endregion
89
+ //#region src/helpers/hooks/use-globals.ts
90
+ const globalsWatcher = createDictionaryWatcher(Globals, "globalsContext");
91
+ const useGlobals = globalsWatcher.useValue;
92
+ const useGlobalsContext = globalsWatcher.useContext;
93
+ const useGlobalsSelector = globalsWatcher.useSelector;
94
+ const GlobalsProvider = globalsWatcher.Provider;
95
+ //#endregion
96
+ //#region src/helpers/hooks/use-reactive-value.ts
97
+ function createSubscriber(obj, isEqual) {
98
+ const isReactive = obj && typeof obj === "object" && "Value" in obj;
99
+ let snapshot = isReactive ? obj.Value : void 0;
100
+ return {
101
+ subscribe: (onStoreChange) => {
102
+ snapshot = isReactive ? obj.Value : void 0;
103
+ const remove = isReactive && typeof obj.AddListener === "function" && (obj === null || obj === void 0 ? void 0 : obj.AddListener(() => {
104
+ const prev = snapshot;
105
+ snapshot = isReactive ? obj.Value : void 0;
106
+ if (typeof isEqual !== "function" || !isEqual(prev, snapshot)) onStoreChange();
107
+ }));
108
+ if (isReactive && typeof remove !== "function") console.warn("The reactive value does not provide a change listener");
109
+ return () => remove === null || remove === void 0 ? void 0 : remove();
110
+ },
111
+ getSnapshot: () => snapshot
112
+ };
113
+ }
114
+ function useReactiveValue(obj, isEqual) {
115
+ const sb = useMemo(() => createSubscriber(obj, isEqual), [obj, isEqual]);
116
+ return useSyncExternalStore(sb.subscribe, sb.getSnapshot, sb.getSnapshot);
117
+ }
118
+ //#endregion
119
+ //#region src/helpers/icons.ts
120
+ const componentCache = {};
121
+ const icon = new Proxy({}, { get: (target, key) => {
122
+ if (typeof key === "symbol") return target[key];
123
+ const icon = key.replace(/^_/, "");
124
+ let cmp = componentCache[icon];
125
+ if (cmp) return cmp;
126
+ cmp = function NamedIcon(props, ref) {
127
+ return React.createElement("icon", _objectSpread2(_objectSpread2({ name: `<icon ${icon}>` }, props), {}, { ref }), icon);
128
+ };
129
+ cmp = React.forwardRef(cmp);
130
+ componentCache[icon] = cmp;
131
+ return cmp;
132
+ } });
133
+ //#endregion
134
+ //#region src/version.ts
135
+ const version = "0.21.0";
136
+ //#endregion
137
+ //#region src/views/error-boundary.tsx
138
+ var ErrorBoundary = class extends React.Component {
139
+ constructor(props) {
140
+ super(props);
141
+ this.state = {
142
+ hasError: false,
143
+ error: null
144
+ };
145
+ }
146
+ static getDerivedStateFromError(error) {
147
+ return {
148
+ hasError: true,
149
+ error
150
+ };
151
+ }
152
+ componentDidCatch(error, errorInfo) {}
153
+ render() {
154
+ if (this.state.hasError) {
155
+ var _this$state$error, _this$state$error2;
156
+ return /* @__PURE__ */ jsxs("view", {
157
+ id: "__react-unity-error-boundary",
158
+ style: {
159
+ color: "crimson",
160
+ padding: 20,
161
+ fontSize: 16
162
+ },
163
+ children: [/* @__PURE__ */ jsx("view", {
164
+ style: { marginBottom: "12px" },
165
+ children: ((_this$state$error = this.state.error) === null || _this$state$error === void 0 ? void 0 : _this$state$error.message) || ""
166
+ }), /* @__PURE__ */ jsx("view", { children: ((_this$state$error2 = this.state.error) === null || _this$state$error2 === void 0 ? void 0 : _this$state$error2.stack) || "" })]
167
+ });
168
+ }
169
+ return this.props.children;
170
+ }
171
+ };
172
+ //#endregion
173
+ //#region src/views/default-view.tsx
174
+ function DefaultView({ children, withHelpers, renderCount }) {
175
+ return /* @__PURE__ */ jsx(Fragment, { children: !withHelpers ? children : /* @__PURE__ */ jsx(ErrorBoundary, { children }, renderCount) });
176
+ }
177
+ //#endregion
178
+ //#region src/renderer/async/objects.ts
179
+ var ObjectsRepo = class {
180
+ constructor() {
181
+ _defineProperty(this, "indices", [{}]);
182
+ _defineProperty(this, "objects", /* @__PURE__ */ new WeakMap());
183
+ _defineProperty(this, "setObject", (index, item) => {
184
+ let it = this.indices[index];
185
+ if (!it) it = this.indices[index] = {};
186
+ this.objects.set(it, item);
187
+ });
188
+ _defineProperty(this, "addObject", (item) => {
189
+ if (!item) return -1;
190
+ const it = {};
191
+ const ind = this.indices.length;
192
+ this.indices.push(it);
193
+ this.objects.set(it, item);
194
+ return ind;
195
+ });
196
+ _defineProperty(this, "getObject", (index) => {
197
+ if (index < 0) return void 0;
198
+ const it = this.indices[index];
199
+ return this.objects.get(it);
200
+ });
201
+ }
202
+ };
203
+ //#endregion
204
+ //#region src/renderer/diffing.ts
205
+ const styleStringSymbol = "__style_as_string__";
206
+ const propDepths = {
207
+ style: 1,
208
+ data: 1,
209
+ custom: 1
210
+ };
211
+ function diffProperties(lastProps, nextProps, deepDiffing = 0) {
212
+ if (lastProps === nextProps) return null;
213
+ let updatePayload = null;
214
+ let propKey;
215
+ for (propKey in lastProps) {
216
+ if (Object.hasOwn(nextProps, propKey) || !Object.hasOwn(lastProps, propKey) || lastProps[propKey] == null) continue;
217
+ let prop = null;
218
+ if (propKey === "style" && typeof lastProps.style === "string") (updatePayload = updatePayload || {})[styleStringSymbol] = null;
219
+ else {
220
+ const depth = deepDiffing > 0 ? deepDiffing : propDepths[propKey] || 0;
221
+ if (depth > 0) {
222
+ prop = diffProperties(lastProps[propKey], {}, depth - 1);
223
+ if (!prop) continue;
224
+ }
225
+ (updatePayload = updatePayload || {})[propKey] = prop;
226
+ }
227
+ }
228
+ for (propKey in nextProps) {
229
+ const nextProp = nextProps[propKey];
230
+ const lastProp = lastProps != null ? lastProps[propKey] : void 0;
231
+ if (!Object.hasOwn(nextProps, propKey) || nextProp === lastProp || nextProp == null && lastProp == null) continue;
232
+ let prop = nextProp;
233
+ if (propKey === "style") {
234
+ const prevWasString = typeof lastProp === "string";
235
+ const curIsString = typeof prop === "string";
236
+ if (prevWasString !== curIsString) {
237
+ (updatePayload = updatePayload || {})[styleStringSymbol] = typeof prop === "string" ? prop : null;
238
+ if (curIsString) {
239
+ prop = diffProperties(lastProp, {}, 0);
240
+ if (!prop) continue;
241
+ }
242
+ } else {
243
+ if (curIsString) continue;
244
+ prop = diffProperties(lastProp, nextProp, 0);
245
+ if (!prop) continue;
246
+ }
247
+ } else {
248
+ const depth = deepDiffing > 0 ? deepDiffing : propDepths[propKey] || 0;
249
+ if (depth > 0) {
250
+ prop = diffProperties(lastProp, nextProp, depth - 1);
251
+ if (!prop) continue;
252
+ }
253
+ }
254
+ (updatePayload = updatePayload || {})[propKey] = prop;
255
+ }
256
+ return updatePayload;
257
+ }
258
+ //#endregion
259
+ //#region \0@oxc-project+runtime@0.140.0/helpers/esm/objectWithoutPropertiesLoose.js
260
+ function _objectWithoutPropertiesLoose(r, e) {
261
+ if (null == r) return {};
262
+ var t = {};
263
+ for (var n in r) if ({}.hasOwnProperty.call(r, n)) {
264
+ if (e.includes(n)) continue;
265
+ t[n] = r[n];
266
+ }
267
+ return t;
268
+ }
269
+ //#endregion
270
+ //#region \0@oxc-project+runtime@0.140.0/helpers/esm/objectWithoutProperties.js
271
+ function _objectWithoutProperties(e, t) {
272
+ if (null == e) return {};
273
+ var o, r, i = _objectWithoutPropertiesLoose(e, t);
274
+ if (Object.getOwnPropertySymbols) {
275
+ var s = Object.getOwnPropertySymbols(e);
276
+ for (r = 0; r < s.length; r++) o = s[r], t.includes(o) || {}.propertyIsEnumerable.call(e, o) && (i[o] = e[o]);
277
+ }
278
+ return i;
279
+ }
280
+ //#endregion
281
+ //#region src/renderer/constants.ts
282
+ const _excluded = [
283
+ "children",
284
+ "tag",
285
+ "pool",
286
+ "ref"
287
+ ];
288
+ const hideClass = "react-unity__renderer__hidden";
289
+ const eventPriorities = {
290
+ discrete: DiscreteEventPriority,
291
+ continuous: ContinuousEventPriority,
292
+ default: DefaultEventPriority,
293
+ idle: IdleEventPriority
294
+ };
295
+ const textTypes = {
296
+ text: true,
297
+ icon: true,
298
+ style: true,
299
+ script: true
300
+ };
301
+ function stringizePoolKey(key) {
302
+ switch (typeof key) {
303
+ case "string": return key;
304
+ case "boolean": return key ? "default" : "";
305
+ case "number": return key.toString();
306
+ case "undefined": return null;
307
+ default: return "";
308
+ }
309
+ }
310
+ function getAllowedProps(props, type) {
311
+ const { children, tag, pool, ref } = props, rest = _objectWithoutProperties(props, _excluded);
312
+ if (textTypes[type] && "children" in props) rest.children = !children || typeof children === "boolean" ? null : Array.isArray(children) ? children.join("") : String(children);
313
+ if (typeof props.style === "string") rest[styleStringSymbol] = props.style;
314
+ return rest;
315
+ }
316
+ const HostTransitionContext = createContext(null);
317
+ let currentUpdatePriority = 0;
318
+ const commonReconciler = _objectSpread2({
319
+ noTimeout: -1,
320
+ scheduleTimeout: (callback, delay) => setTimeout(callback, delay),
321
+ scheduleMicrotask: typeof queueMicrotask === "function" ? queueMicrotask : (callback) => Promise.resolve(null).then(callback).catch((error) => setTimeout(() => {
322
+ throw error;
323
+ }, 0)),
324
+ cancelTimeout: (handle) => clearTimeout(handle),
325
+ beforeActiveInstanceBlur() {},
326
+ afterActiveInstanceBlur() {},
327
+ prepareScopeUpdate: () => {},
328
+ getInstanceFromScope: () => void 0,
329
+ getInstanceFromNode: () => void 0,
330
+ setCurrentUpdatePriority: (newPriority) => currentUpdatePriority = newPriority,
331
+ getCurrentUpdatePriority: () => currentUpdatePriority,
332
+ resolveUpdatePriority: () => currentUpdatePriority || UnityBridge.CurrentEventPriority || eventPriorities.default,
333
+ maySuspendCommit: () => false,
334
+ requestPostPaintCallback: () => {},
335
+ preloadInstance: () => true,
336
+ resetFormInstance: () => {},
337
+ resolveEventTimeStamp: () => -1.1,
338
+ resolveEventType: () => null,
339
+ shouldAttemptEagerTransition: () => false,
340
+ startSuspendingCommit: () => {},
341
+ suspendInstance: () => {},
342
+ trackSchedulerEvent: () => {},
343
+ waitForCommitToBeReady: () => null,
344
+ NotPendingTransition: null,
345
+ HostTransitionContext
346
+ }, {
347
+ now: typeof performance !== "undefined" && typeof performance.now === "function" ? () => performance.now() : typeof Date !== "undefined" && typeof Date.now === "function" ? () => Date.now() : () => 0,
348
+ getCurrentEventPriority: () => UnityBridge.CurrentEventPriority || eventPriorities.default
349
+ });
350
+ const isDevelopment = process.env.NODE_ENV === "development";
351
+ //#endregion
352
+ //#region src/renderer/subcontexts/richtext.ts
353
+ function parametrizeValue(value) {
354
+ if (typeof value === "number") return String(value);
355
+ value = String(value);
356
+ if (value.includes(" ") || value.includes("-")) return `"${value}"`;
357
+ return value;
358
+ }
359
+ function stringifyRichText(node) {
360
+ var _node$children;
361
+ if (node.hidden) return "";
362
+ if ("text" in node) return node.text;
363
+ const acc = [];
364
+ const tag = node.tag;
365
+ if (tag) {
366
+ var _node$attributes;
367
+ acc.push("<");
368
+ acc.push(tag);
369
+ if (((_node$attributes = node.attributes) === null || _node$attributes === void 0 ? void 0 : _node$attributes.value) != null) {
370
+ var _node$attributes2;
371
+ const value = (_node$attributes2 = node.attributes) === null || _node$attributes2 === void 0 ? void 0 : _node$attributes2.value;
372
+ acc.push("=");
373
+ acc.push(parametrizeValue(value));
374
+ }
375
+ for (const key in node.attributes) {
376
+ if (key === "value") continue;
377
+ if (Object.hasOwn(node.attributes, key)) {
378
+ const value = node.attributes[key];
379
+ if (value != null) {
380
+ acc.push(" ");
381
+ acc.push(key);
382
+ acc.push("=");
383
+ acc.push(parametrizeValue(value));
384
+ }
385
+ }
386
+ }
387
+ acc.push(">");
388
+ }
389
+ if (((_node$children = node.children) === null || _node$children === void 0 ? void 0 : _node$children.length) > 0) {
390
+ for (const child of node.children) acc.push(stringifyRichText(child));
391
+ if (tag) {
392
+ acc.push("</");
393
+ acc.push(tag);
394
+ acc.push(">");
395
+ }
396
+ }
397
+ return acc.join("");
398
+ }
399
+ //#endregion
400
+ //#region src/renderer/subcontexts/svg.ts
401
+ function kebabize(str) {
402
+ return str.split("").map((letter, idx) => {
403
+ return letter.toUpperCase() === letter ? `${idx !== 0 ? "-" : ""}${letter.toLowerCase()}` : letter;
404
+ }).join("");
405
+ }
406
+ function stringifyStyle(style) {
407
+ if (typeof style === "string") return style;
408
+ const acc = [];
409
+ for (const key in style) if (Object.hasOwn(style, key)) {
410
+ const element = style[key];
411
+ if (element != null) {
412
+ acc.push(kebabize(key));
413
+ acc.push(":");
414
+ acc.push(element);
415
+ acc.push(";");
416
+ }
417
+ }
418
+ return acc.join("");
419
+ }
420
+ function stringifySVG(node) {
421
+ var _node$children;
422
+ if (node.hidden) return "";
423
+ if ("text" in node) return node.text;
424
+ const acc = [];
425
+ const tag = node.tag;
426
+ if (tag) {
427
+ acc.push("<");
428
+ acc.push(tag);
429
+ for (const key in node.attributes) if (Object.hasOwn(node.attributes, key)) {
430
+ let element = node.attributes[key];
431
+ if (key === "style") element = stringifyStyle(element);
432
+ if (element != null) {
433
+ acc.push(" ");
434
+ acc.push(kebabize(key));
435
+ acc.push("=\"");
436
+ acc.push(element);
437
+ acc.push("\"");
438
+ }
439
+ }
440
+ }
441
+ if (((_node$children = node.children) === null || _node$children === void 0 ? void 0 : _node$children.length) > 0) {
442
+ if (tag) acc.push(">");
443
+ for (const child of node.children) acc.push(stringifySVG(child));
444
+ if (tag) {
445
+ acc.push("</");
446
+ acc.push(tag);
447
+ acc.push(">");
448
+ }
449
+ } else if (tag) acc.push(" />");
450
+ return acc.join("");
451
+ }
452
+ //#endregion
453
+ //#region src/renderer/subcontexts/index.ts
454
+ const subContextRenderers = {
455
+ richtext: stringifyRichText,
456
+ svg: stringifySVG
457
+ };
458
+ //#endregion
459
+ //#region src/renderer/async/callbacks.ts
460
+ var CallbacksRepo = class extends ObjectsRepo {
461
+ constructor(..._args) {
462
+ super(..._args);
463
+ _defineProperty(this, "call", (ind, args) => {
464
+ const cb = this.getObject(ind);
465
+ const argsAsList = args;
466
+ const argsAsArray = args;
467
+ if (typeof argsAsArray.Length === "number") {
468
+ args = [];
469
+ const length = argsAsArray.Length;
470
+ for (let index = 0; index < length; index++) args.push(argsAsArray.GetValue(index));
471
+ } else if (typeof argsAsList.Count === "number") {
472
+ args = [];
473
+ const length = argsAsList.Count;
474
+ for (let index = 0; index < length; index++) args.push(argsAsList[index]);
475
+ } else if (typeof argsAsList.Count === "function") {
476
+ args = [];
477
+ const length = argsAsList.Count();
478
+ for (let index = 0; index < length; index++) args.push(argsAsArray.GetValue(index));
479
+ }
480
+ return cb.apply(null, args);
481
+ });
482
+ }
483
+ };
484
+ //#endregion
485
+ //#region src/renderer/async/serializer.ts
486
+ const callbacksRepo = new CallbacksRepo();
487
+ const objectsRepo = new ObjectsRepo();
488
+ function convertPropsToSerializable(props) {
489
+ const res = {};
490
+ for (const key in props) if (Object.hasOwn(props, key)) {
491
+ const value = props[key];
492
+ if (value == null) (res.p || (res.p = {}))[key] = null;
493
+ else if (key === "style") (res.p || (res.p = {}))[key] = convertPropsToSerializable(value);
494
+ else if (key[0] === "o" && key[1] === "n" && typeof value === "function") {
495
+ const ind = callbacksRepo.addObject(value);
496
+ (res.e || (res.e = {}))[key] = ind;
497
+ } else if (typeof value === "object" || typeof value === "function") {
498
+ const ind = objectsRepo.addObject(value);
499
+ (res.o || (res.o = {}))[key] = ind;
500
+ } else (res.p || (res.p = {}))[key] = value;
501
+ }
502
+ return res;
503
+ }
504
+ //#endregion
505
+ //#region src/renderer/async/reconciler.ts
506
+ let refId = 0;
507
+ const ctxMap = /* @__PURE__ */ new Map();
508
+ const updateSubContext = (instance) => {
509
+ const rend = subContextRenderers[instance.type];
510
+ let root = instance === null || instance === void 0 ? void 0 : instance.root;
511
+ let cur = instance;
512
+ while (cur && !root) {
513
+ root = cur.root;
514
+ cur = cur.parent;
515
+ }
516
+ if (!root) return;
517
+ const content = rend(root.subContext.node);
518
+ if (instance.type === "richtext") instance.hostContext.commands.push([
519
+ 6,
520
+ root.refId,
521
+ content
522
+ ]);
523
+ else if (instance.type === "svg") instance.hostContext.commands.push([
524
+ 5,
525
+ root.refId,
526
+ "svg",
527
+ convertPropsToSerializable({ innerContent: content })
528
+ ]);
529
+ };
530
+ const hostConfig$1 = _objectSpread2(_objectSpread2({}, commonReconciler), {}, {
531
+ getRootHostContext: (rootContainer) => {
532
+ const context = rootContainer.context;
533
+ if (rootContainer.refId < 0) {
534
+ refId++;
535
+ rootContainer.context.SetRef(refId, rootContainer.component);
536
+ rootContainer.refId = refId;
537
+ }
538
+ const existing = ctxMap.get(context);
539
+ if (existing) return existing;
540
+ const commands = rootContainer.commands;
541
+ const flushCommands = () => {
542
+ const serialized = JSON.stringify(commands);
543
+ commands.length = 0;
544
+ return serialized;
545
+ };
546
+ const fireEventByRef = (ind, args) => {
547
+ return callbacksRepo.call(ind, args);
548
+ };
549
+ const getObjectRef = (ind) => {
550
+ return objectsRepo.getObject(ind);
551
+ };
552
+ const getEventAsObjectRef = (ind) => {
553
+ return callbacksRepo.getObject(ind);
554
+ };
555
+ context.BindCommands(flushCommands, fireEventByRef, getObjectRef, getEventAsObjectRef);
556
+ const ctx = {
557
+ context,
558
+ commands,
559
+ refId: rootContainer.refId,
560
+ type: "native"
561
+ };
562
+ ctxMap.set(context, ctx);
563
+ return ctx;
564
+ },
565
+ getChildHostContext: (parentCtx, type) => {
566
+ if (type === "richtext" && parentCtx.type === "native") return {
567
+ type: "richtext",
568
+ hostContext: parentCtx,
569
+ node: null,
570
+ parent: null,
571
+ root: null
572
+ };
573
+ if (type === "svg" && parentCtx.type === "native") return {
574
+ type: "svg",
575
+ hostContext: parentCtx,
576
+ node: null,
577
+ parent: null,
578
+ root: null
579
+ };
580
+ return parentCtx;
581
+ },
582
+ getPublicInstance: (instance) => {
583
+ if (instance.type === "native") return instance.context.GetRef(instance.refId, instance.commands.length > 0);
584
+ return null;
585
+ },
586
+ supportsMutation: true,
587
+ supportsHydration: false,
588
+ supportsPersistence: false,
589
+ supportsMicrotasks: true,
590
+ isPrimaryRenderer: true,
591
+ warnsIfNotActing: true,
592
+ prepareForCommit: () => null,
593
+ resetAfterCommit: () => {},
594
+ clearContainer(container) {
595
+ UnityBridge.clearContainer(container);
596
+ },
597
+ createInstance(type, props, rootContainer, ctx, internalHandle) {
598
+ const aProps = getAllowedProps(props, type);
599
+ if (ctx.type === "native") {
600
+ refId++;
601
+ ctx.commands.push([
602
+ 0,
603
+ refId,
604
+ type,
605
+ convertPropsToSerializable(aProps),
606
+ stringizePoolKey(props.pool)
607
+ ]);
608
+ if (rootContainer.fiberCache) rootContainer.fiberCache.setObject(refId, internalHandle);
609
+ const res = _objectSpread2(_objectSpread2({}, ctx), {}, { refId });
610
+ if (type === "richtext") res.subContext = {
611
+ type: "richtext",
612
+ node: {
613
+ tag: "",
614
+ children: [],
615
+ attributes: aProps
616
+ },
617
+ root: res,
618
+ hostContext: res,
619
+ parent: null
620
+ };
621
+ if (type === "svg") res.subContext = {
622
+ type: "svg",
623
+ node: {
624
+ tag: "",
625
+ children: [],
626
+ attributes: aProps
627
+ },
628
+ root: res,
629
+ hostContext: res,
630
+ parent: null
631
+ };
632
+ return res;
633
+ }
634
+ if (ctx.type === "richtext" || ctx.type === "svg") return _objectSpread2(_objectSpread2({}, ctx), {}, { node: {
635
+ tag: type,
636
+ children: [],
637
+ attributes: aProps
638
+ } });
639
+ },
640
+ createTextInstance(text, rootContainer, ctx, internalHandle) {
641
+ if (ctx.type === "native") {
642
+ refId++;
643
+ ctx.commands.push([
644
+ 1,
645
+ refId,
646
+ text
647
+ ]);
648
+ if (rootContainer.fiberCache) rootContainer.fiberCache.setObject(refId, internalHandle);
649
+ return _objectSpread2(_objectSpread2({}, ctx), {}, { refId });
650
+ }
651
+ if (ctx.type === "richtext" || ctx.type === "svg") return _objectSpread2(_objectSpread2({}, ctx), {}, { node: { text } });
652
+ },
653
+ appendInitialChild(parent, child) {
654
+ if (!child) return;
655
+ if (parent.type === "native" && parent.subContext) parent = parent.subContext;
656
+ if (parent.type === "native" && child.type === "native") parent.commands.push([
657
+ 2,
658
+ parent.refId,
659
+ child.refId
660
+ ]);
661
+ else if (parent.type === "richtext" && child.type === "richtext" || parent.type === "svg" && child.type === "svg") {
662
+ if ("children" in parent.node) parent.node.children.push(child.node);
663
+ child.root = parent.root;
664
+ child.parent = parent;
665
+ updateSubContext(child);
666
+ }
667
+ },
668
+ finalizeInitialChildren: () => false,
669
+ commitMount: (instance) => {},
670
+ shouldSetTextContent(type) {
671
+ return textTypes[type];
672
+ },
673
+ commitUpdate(instance, type, prevProps, nextProps) {
674
+ let updatePayload = null;
675
+ if (typeof prevProps === "string") {
676
+ updatePayload = type;
677
+ type = prevProps;
678
+ } else {
679
+ updatePayload = diffProperties(prevProps, nextProps);
680
+ if (!updatePayload) return;
681
+ }
682
+ const props = getAllowedProps(updatePayload, type);
683
+ if (instance.type === "native") instance.commands.push([
684
+ 5,
685
+ instance.refId,
686
+ type,
687
+ convertPropsToSerializable(props)
688
+ ]);
689
+ else if (instance.type === "richtext" || instance.type === "svg") {
690
+ if ("attributes" in instance.node) instance.node.attributes = _objectSpread2(_objectSpread2({}, instance.node.attributes), props);
691
+ updateSubContext(instance);
692
+ }
693
+ },
694
+ commitTextUpdate(instance, oldText, newText) {
695
+ if (instance.type === "native") instance.commands.push([
696
+ 6,
697
+ instance.refId,
698
+ newText
699
+ ]);
700
+ else if (instance.type === "richtext" || instance.type === "svg") {
701
+ instance.node.text = newText;
702
+ updateSubContext(instance);
703
+ }
704
+ },
705
+ appendChild(parent, child) {
706
+ if (!child) return;
707
+ if (parent.type === "native" && parent.subContext) parent = parent.subContext;
708
+ if (parent.type === "native" && child.type === "native") child.commands.push([
709
+ 2,
710
+ parent.refId,
711
+ child.refId
712
+ ]);
713
+ else if (parent.type === "richtext" && child.type === "richtext" || parent.type === "svg" && child.type === "svg") {
714
+ if ("children" in parent.node) parent.node.children.push(child.node);
715
+ child.root = parent.root;
716
+ child.parent = parent;
717
+ updateSubContext(child);
718
+ }
719
+ },
720
+ appendChildToContainer(parent, child) {
721
+ if (child.type === "native") child.commands.push([
722
+ 2,
723
+ parent.refId,
724
+ child.refId
725
+ ]);
726
+ },
727
+ insertBefore(parent, child, beforeChild) {
728
+ if (!child) return;
729
+ if (parent.type === "native" && parent.subContext) parent = parent.subContext;
730
+ if (parent.type === "native" && child.type === "native" && beforeChild.type === "native") child.commands.push([
731
+ 4,
732
+ parent.refId,
733
+ child.refId,
734
+ beforeChild.refId
735
+ ]);
736
+ else if (parent.type === "richtext" && child.type === "richtext" && beforeChild.type === "richtext" || parent.type === "svg" && child.type === "svg" && beforeChild.type === "svg") {
737
+ if ("children" in parent.node) {
738
+ const index = parent.node.children.indexOf(beforeChild.node);
739
+ if (index >= 0) parent.node.children.splice(index, 0, child.node);
740
+ else parent.node.children.push(child.node);
741
+ }
742
+ child.root = parent.root;
743
+ child.parent = parent;
744
+ updateSubContext(child);
745
+ }
746
+ },
747
+ insertInContainerBefore(parent, child, beforeChild) {
748
+ if (child.type === "native" && beforeChild.type === "native") child.commands.push([
749
+ 4,
750
+ parent.refId,
751
+ child.refId,
752
+ beforeChild.refId
753
+ ]);
754
+ },
755
+ removeChild(parent, child) {
756
+ if (!child) return;
757
+ if (parent.type === "native" && parent.subContext) parent = parent.subContext;
758
+ if (parent.type === "native" && child.type === "native") child.commands.push([
759
+ 3,
760
+ parent.refId,
761
+ child.refId
762
+ ]);
763
+ else if (parent.type === "richtext" && child.type === "richtext" || parent.type === "svg" && child.type === "svg") {
764
+ if ("children" in parent.node) {
765
+ const index = parent.node.children.indexOf(child.node);
766
+ if (index >= 0) parent.node.children.splice(index, 1);
767
+ }
768
+ updateSubContext(parent);
769
+ }
770
+ },
771
+ removeChildFromContainer(parent, child) {
772
+ if (child.type === "native") child.commands.push([
773
+ 3,
774
+ parent.refId,
775
+ child.refId
776
+ ]);
777
+ },
778
+ resetTextContent: () => {},
779
+ preparePortalMount: () => {},
780
+ detachDeletedInstance: () => {},
781
+ hideInstance: (instance) => {
782
+ if (instance.type === "native") instance.commands.push([
783
+ 7,
784
+ instance.refId,
785
+ true
786
+ ]);
787
+ else if (instance.type === "richtext" || instance.type === "svg") {
788
+ instance.node.hidden = true;
789
+ updateSubContext(instance);
790
+ }
791
+ },
792
+ hideTextInstance: (instance) => {
793
+ if (instance.type === "native") instance.commands.push([
794
+ 7,
795
+ instance.refId,
796
+ true
797
+ ]);
798
+ else if (instance.type === "richtext" || instance.type === "svg") {
799
+ instance.node.hidden = true;
800
+ updateSubContext(instance);
801
+ }
802
+ },
803
+ unhideInstance: (instance) => {
804
+ if (instance.type === "native") instance.commands.push([
805
+ 7,
806
+ instance.refId,
807
+ false
808
+ ]);
809
+ else if (instance.type === "richtext" || instance.type === "svg") {
810
+ instance.node.hidden = false;
811
+ updateSubContext(instance);
812
+ }
813
+ },
814
+ unhideTextInstance: (instance) => {
815
+ if (instance.type === "native") instance.commands.push([
816
+ 7,
817
+ instance.refId,
818
+ false
819
+ ]);
820
+ else if (instance.type === "richtext" || instance.type === "svg") {
821
+ instance.node.hidden = false;
822
+ updateSubContext(instance);
823
+ }
824
+ }
825
+ }, {
826
+ supportsTestSelectors: false,
827
+ shouldDeprioritizeSubtree: () => false,
828
+ prepareUpdate(instance, type, oldProps, newProps) {
829
+ return diffProperties(oldProps, newProps);
830
+ }
831
+ });
832
+ let asyncReconciler = null;
833
+ const getAsyncReconciler = () => {
834
+ var _asyncReconciler;
835
+ return (_asyncReconciler = asyncReconciler) !== null && _asyncReconciler !== void 0 ? _asyncReconciler : asyncReconciler = Reconciler(hostConfig$1);
836
+ };
837
+ //#endregion
838
+ //#region src/renderer/sync/reconciler.ts
839
+ const hostContext = {};
840
+ const childContext = {};
841
+ const hostConfig = _objectSpread2(_objectSpread2({}, commonReconciler), {}, {
842
+ getRootHostContext: () => hostContext,
843
+ getChildHostContext: () => childContext,
844
+ getPublicInstance: (instance) => instance,
845
+ supportsMutation: true,
846
+ supportsHydration: false,
847
+ supportsPersistence: false,
848
+ supportsMicrotasks: true,
849
+ isPrimaryRenderer: true,
850
+ warnsIfNotActing: true,
851
+ prepareForCommit: () => null,
852
+ resetAfterCommit: () => {},
853
+ clearContainer: (container) => UnityBridge.clearContainer(container),
854
+ createInstance(type, props, rootContainerInstance) {
855
+ const aProps = getAllowedProps(props, type);
856
+ const children = aProps.children || null;
857
+ delete aProps.children;
858
+ return UnityBridge.createElement(props.tag || type, children, rootContainerInstance, aProps, stringizePoolKey(props.pool));
859
+ },
860
+ createTextInstance(text, rootContainerInstance) {
861
+ return UnityBridge.createText(text, rootContainerInstance);
862
+ },
863
+ appendInitialChild(parent, child) {
864
+ UnityBridge.appendChild(parent, child);
865
+ },
866
+ finalizeInitialChildren: () => false,
867
+ commitMount: () => {},
868
+ shouldSetTextContent(type) {
869
+ return textTypes[type];
870
+ },
871
+ commitUpdate(instance, type, prevProps, nextProps) {
872
+ let updatePayload = null;
873
+ if (typeof prevProps === "string") {
874
+ updatePayload = type;
875
+ type = prevProps;
876
+ } else {
877
+ updatePayload = diffProperties(prevProps, nextProps);
878
+ if (!updatePayload) return;
879
+ }
880
+ UnityBridge.applyUpdate(instance, getAllowedProps(updatePayload, type), type);
881
+ },
882
+ commitTextUpdate(textInstance, oldText, newText) {
883
+ UnityBridge.setText(textInstance, newText);
884
+ },
885
+ appendChild(parent, child) {
886
+ return UnityBridge.appendChild(parent, child);
887
+ },
888
+ appendChildToContainer(parent, child) {
889
+ return UnityBridge.appendChildToContainer(parent, child);
890
+ },
891
+ insertBefore(parent, child, beforeChild) {
892
+ return UnityBridge.insertBefore(parent, child, beforeChild);
893
+ },
894
+ insertInContainerBefore(parent, child, beforeChild) {
895
+ return UnityBridge.insertBefore(parent, child, beforeChild);
896
+ },
897
+ removeChild(parent, child) {
898
+ return UnityBridge.removeChild(parent, child);
899
+ },
900
+ removeChildFromContainer(parent, child) {
901
+ return UnityBridge.removeChild(parent, child);
902
+ },
903
+ resetTextContent: () => {},
904
+ preparePortalMount: () => {},
905
+ detachDeletedInstance: () => {},
906
+ hideInstance: (instance) => {
907
+ instance.ClassList.Add(hideClass);
908
+ },
909
+ hideTextInstance: (instance) => {
910
+ instance.ClassList.Add(hideClass);
911
+ },
912
+ unhideInstance: (instance) => {
913
+ instance.ClassList.Remove(hideClass);
914
+ },
915
+ unhideTextInstance: (instance) => {
916
+ instance.ClassList.Remove(hideClass);
917
+ }
918
+ }, {
919
+ supportsTestSelectors: false,
920
+ shouldDeprioritizeSubtree: () => false,
921
+ prepareUpdate(instance, type, oldProps, newProps) {
922
+ return diffProperties(oldProps, newProps);
923
+ }
924
+ });
925
+ let syncReconciler = null;
926
+ const getSyncReconciler = () => {
927
+ var _syncReconciler;
928
+ return (_syncReconciler = syncReconciler) !== null && _syncReconciler !== void 0 ? _syncReconciler : syncReconciler = Reconciler(hostConfig);
929
+ };
930
+ //#endregion
931
+ //#region src/renderer/renderer.ts
932
+ const containerMap = /* @__PURE__ */ new Map();
933
+ let renderCount = 0;
934
+ function render(element, options = {}) {
935
+ renderCount++;
936
+ const hostContainer = (options === null || options === void 0 ? void 0 : options.hostContainer) || HostContainer;
937
+ const cacheKey = hostContainer.InstanceId >= 0 ? hostContainer.InstanceId : hostContainer;
938
+ const isAsync = !(options === null || options === void 0 ? void 0 : options.disableBatchRendering);
939
+ let { hostRoot, asyncJobCallback } = containerMap.get(cacheKey) || {};
940
+ let findFiberByHostInstance = () => null;
941
+ if (!hostRoot) {
942
+ const mode = (options === null || options === void 0 ? void 0 : options.mode) === "legacy" ? LegacyRoot : ConcurrentRoot;
943
+ if (isAsync) {
944
+ const asyncReconciler = getAsyncReconciler();
945
+ const fiberCache = isDevelopment ? new ObjectsRepo() : null;
946
+ if (isDevelopment) findFiberByHostInstance = (instance) => !instance ? null : fiberCache.getObject(instance.refId);
947
+ let scheduled = false;
948
+ const commands = [];
949
+ commands.push = (...args) => {
950
+ if (!scheduled) {
951
+ scheduled = true;
952
+ Promise.resolve().then(() => {
953
+ asyncJobCallback();
954
+ scheduled = false;
955
+ });
956
+ }
957
+ return Array.prototype.push.apply(commands, args);
958
+ };
959
+ const hostContainerInstance = {
960
+ type: "native",
961
+ commands,
962
+ component: hostContainer,
963
+ context: hostContainer.Context,
964
+ refId: hostContainer.RefId,
965
+ fiberCache
966
+ };
967
+ asyncJobCallback = () => {
968
+ if (!commands.length) return;
969
+ const serialized = JSON.stringify(commands);
970
+ commands.length = 0;
971
+ hostContainerInstance.context.FlushCommands(serialized);
972
+ };
973
+ hostRoot = asyncReconciler.createContainer(hostContainerInstance, mode, null, false, void 0, "", (error) => console.error(error), () => {}, () => {}, () => {});
974
+ } else hostRoot = getSyncReconciler().createContainer(hostContainer, mode, null, false, void 0, "", (error) => console.error(error), () => {}, () => {}, () => {});
975
+ containerMap.set(cacheKey, {
976
+ hostRoot,
977
+ asyncJobCallback
978
+ });
979
+ }
980
+ if (!(options === null || options === void 0 ? void 0 : options.disableHelpers)) element = createElement(DefaultView, {
981
+ withHelpers: !(options === null || options === void 0 ? void 0 : options.disableHelpers),
982
+ renderCount
983
+ }, element);
984
+ const rc = isAsync ? getAsyncReconciler() : getSyncReconciler();
985
+ if (!injectedReconcilers.has(rc)) {
986
+ injectedReconcilers.add(rc);
987
+ rc.injectIntoDevTools({
988
+ bundleType: isDevelopment ? 1 : 0,
989
+ version,
990
+ rendererPackageName: "@reactunity/renderer",
991
+ rendererConfig: { isAsync },
992
+ findFiberByHostInstance
993
+ });
994
+ }
995
+ if ("updateContainerSync" in rc && typeof rc.updateContainerSync === "function" && "flushSyncWork" in rc && typeof rc.flushSyncWork === "function") {
996
+ rc.updateContainerSync(element, hostRoot, null, () => {});
997
+ rc.flushSyncWork();
998
+ } else rc.updateContainer(element, hostRoot, null, () => {});
999
+ return rc;
1000
+ }
1001
+ const injectedReconcilers = /* @__PURE__ */ new WeakSet();
1002
+ /**
1003
+ * @deprecated Instead, import `render` directly from `@reactunity/renderer`
1004
+ */
1005
+ const Renderer = { render(element, options = {}) {
1006
+ return render(element, options);
1007
+ } };
1008
+ const batchedUpdates = (...args) => getAsyncReconciler().batchedUpdates(...args);
1009
+ const flushSync = (...args) => getAsyncReconciler().flushSync(...args);
1010
+ //#endregion
1011
+ //#region index.ts
1012
+ const ReactUnityRenderer = {
1013
+ batchedUpdates,
1014
+ flushSync,
1015
+ render,
1016
+ unstable_batchedUpdates: batchedUpdates
1017
+ };
1018
+ //#endregion
1019
+ export { GlobalsProvider, Renderer, batchedUpdates, batchedUpdates as unstable_batchedUpdates, createDictionaryWatcher, ReactUnityRenderer as default, flushSync, icon, render, useGlobals, useGlobalsContext, useGlobalsSelector, useReactiveValue };
1020
+
18
1021
  //# sourceMappingURL=index.js.map