@reactunity/renderer 0.11.0 → 0.13.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 (59) hide show
  1. package/dist/index.d.ts +1 -1
  2. package/dist/index.js +1 -1
  3. package/dist/src/helpers/icons.d.ts +7 -0
  4. package/dist/src/helpers/icons.js +29 -0
  5. package/dist/src/models/base.d.ts +6 -4
  6. package/dist/src/models/editor/jsx.d.ts +10 -1
  7. package/dist/src/models/environment/dom/common.d.ts +85 -0
  8. package/dist/src/models/environment/dom/common.js +1 -0
  9. package/dist/src/models/environment/dom/fetch.d.ts +111 -0
  10. package/dist/src/models/environment/dom/fetch.js +1 -0
  11. package/dist/src/models/environment/dom/global.d.ts +9 -0
  12. package/dist/src/models/environment/dom/global.js +1 -0
  13. package/dist/src/models/environment/dom/xhr.d.ts +161 -0
  14. package/dist/src/models/environment/dom/xhr.js +1 -0
  15. package/dist/src/models/environment/index.d.ts +4 -0
  16. package/dist/src/models/environment/index.js +1 -0
  17. package/dist/src/models/generated/editor.d.ts +698 -262
  18. package/dist/src/models/generated/editor.js +1 -1
  19. package/dist/src/models/generated/react.d.ts +1823 -491
  20. package/dist/src/models/generated/react.js +1 -1
  21. package/dist/src/models/generated/system.d.ts +148 -148
  22. package/dist/src/models/generated/system.js +1 -1
  23. package/dist/src/models/generated/tests.js +1 -1
  24. package/dist/src/models/generated/unity.d.ts +12737 -7216
  25. package/dist/src/models/generated/unity.js +2 -2
  26. package/dist/src/models/generated/yoga.d.ts +22 -12
  27. package/dist/src/models/generated/yoga.js +1 -1
  28. package/dist/src/models/properties/styles.d.ts +1 -0
  29. package/dist/src/models/properties/yoga-enums.d.ts +1 -1
  30. package/dist/src/models/properties/yoga.d.ts +12 -10
  31. package/dist/src/models/richtext.d.ts +65 -0
  32. package/dist/src/models/richtext.js +2 -0
  33. package/dist/src/models/svg.d.ts +68 -0
  34. package/dist/src/models/svg.js +1 -0
  35. package/dist/src/models/ugui/components.d.ts +11 -6
  36. package/dist/src/models/ugui/events.d.ts +1 -0
  37. package/dist/src/models/ugui/jsx.d.ts +10 -1
  38. package/dist/src/models/uitoolkit/components.d.ts +3 -1
  39. package/dist/src/models/uitoolkit/jsx.d.ts +9 -0
  40. package/dist/src/renderer/async/callbacks.js +22 -8
  41. package/dist/src/renderer/async/reconciler.d.ts +1 -7
  42. package/dist/src/renderer/async/reconciler.js +204 -26
  43. package/dist/src/renderer/async/types.d.ts +31 -5
  44. package/dist/src/renderer/constants.d.ts +5 -0
  45. package/dist/src/renderer/constants.js +12 -0
  46. package/dist/src/renderer/diffing.js +1 -1
  47. package/dist/src/renderer/renderer.d.ts +11 -10
  48. package/dist/src/renderer/renderer.js +6 -9
  49. package/dist/src/renderer/subcontexts/index.d.ts +6 -0
  50. package/dist/src/renderer/subcontexts/index.js +6 -0
  51. package/dist/src/renderer/subcontexts/richtext.d.ts +3 -0
  52. package/dist/src/renderer/subcontexts/richtext.js +52 -0
  53. package/dist/src/renderer/subcontexts/svg.d.ts +3 -0
  54. package/dist/src/renderer/subcontexts/svg.js +70 -0
  55. package/dist/src/version.d.ts +1 -1
  56. package/dist/src/version.js +1 -1
  57. package/package.json +6 -6
  58. package/dist/src/helpers/styled-components-helper.d.ts +0 -7
  59. package/dist/src/helpers/styled-components-helper.js +0 -16
@@ -12,9 +12,28 @@ var __assign = (this && this.__assign) || function () {
12
12
  import * as Reconciler from 'react-reconciler';
13
13
  import { commonReconciler, getAllowedProps, textTypes } from '../constants';
14
14
  import { diffProperties } from '../diffing';
15
+ import { subContextRenderers } from '../subcontexts';
15
16
  import { callbacksRepo, convertPropsToSerializable, objectsRepo } from './serializer';
16
17
  var refId = 0;
17
18
  var ctxMap = new Map();
19
+ var updateSubContext = function (instance) {
20
+ var rend = subContextRenderers[instance.type];
21
+ var root = instance === null || instance === void 0 ? void 0 : instance.root;
22
+ var cur = instance;
23
+ while (cur && !root) {
24
+ root = cur.root;
25
+ cur = cur.parent;
26
+ }
27
+ if (!root)
28
+ return;
29
+ var content = rend(root.subContext.node);
30
+ if (instance.type === 'richtext') {
31
+ instance.hostContext.commands.push(['x', { r: root.refId, c: content }]);
32
+ }
33
+ else if (instance.type === 'svg') {
34
+ instance.hostContext.commands.push(['u', __assign({ r: root.refId, t: 'svg' }, convertPropsToSerializable({ innerContent: content }))]);
35
+ }
36
+ };
18
37
  var hostConfig = __assign(__assign({}, commonReconciler), { getRootHostContext: function (rootContainer) {
19
38
  var context = rootContainer.context;
20
39
  if (rootContainer.refId < 0) {
@@ -44,30 +63,105 @@ var hostConfig = __assign(__assign({}, commonReconciler), { getRootHostContext:
44
63
  var ctx = {
45
64
  context: context,
46
65
  commands: commands,
66
+ refId: rootContainer.refId,
67
+ type: 'native',
47
68
  };
48
69
  ctxMap.set(context, ctx);
49
70
  return ctx;
50
- }, getChildHostContext: function (parentCtx) {
71
+ }, getChildHostContext: function (parentCtx, type) {
72
+ if (type === 'richtext' && parentCtx.type === 'native')
73
+ return {
74
+ type: 'richtext',
75
+ hostContext: parentCtx,
76
+ node: null,
77
+ parent: null,
78
+ root: null,
79
+ };
80
+ if (type === 'svg' && parentCtx.type === 'native')
81
+ return {
82
+ type: 'svg',
83
+ hostContext: parentCtx,
84
+ node: null,
85
+ parent: null,
86
+ root: null,
87
+ };
51
88
  return parentCtx;
52
89
  }, getPublicInstance: function (instance) {
53
- return instance.context.GetRef(instance.refId, instance.commands.length > 0);
90
+ if (instance.type === 'native')
91
+ return instance.context.GetRef(instance.refId, instance.commands.length > 0);
92
+ return null;
54
93
  }, supportsMutation: true, supportsHydration: false, supportsPersistence: false, supportsMicrotasks: true, supportsTestSelectors: false, isPrimaryRenderer: true, warnsIfNotActing: true, prepareForCommit: function () { return null; }, resetAfterCommit: function () { }, shouldDeprioritizeSubtree: function () { return false; }, clearContainer: function (container) {
55
94
  UnityBridge.clearContainer(container);
56
95
  }, createInstance: function (type, props, rootContainer, ctx, internalHandle) {
57
- refId++;
58
96
  var aProps = getAllowedProps(props, type);
59
- ctx.commands.push(['c', __assign({ t: type, r: refId }, convertPropsToSerializable(aProps))]);
60
- if (rootContainer.fiberCache)
61
- rootContainer.fiberCache.setObject(refId, internalHandle);
62
- return __assign(__assign({}, ctx), { refId: refId });
97
+ if (ctx.type === 'native') {
98
+ refId++;
99
+ ctx.commands.push(['c', __assign({ t: type, r: refId }, convertPropsToSerializable(aProps))]);
100
+ if (rootContainer.fiberCache)
101
+ rootContainer.fiberCache.setObject(refId, internalHandle);
102
+ var res = __assign(__assign({}, ctx), { refId: refId });
103
+ if (type === 'richtext') {
104
+ res.subContext = {
105
+ type: 'richtext',
106
+ node: {
107
+ tag: '',
108
+ children: [],
109
+ attributes: aProps,
110
+ },
111
+ root: res,
112
+ hostContext: res,
113
+ parent: null,
114
+ };
115
+ }
116
+ if (type === 'svg') {
117
+ res.subContext = {
118
+ type: 'svg',
119
+ node: {
120
+ tag: '',
121
+ children: [],
122
+ attributes: aProps,
123
+ },
124
+ root: res,
125
+ hostContext: res,
126
+ parent: null,
127
+ };
128
+ }
129
+ return res;
130
+ }
131
+ else if (ctx.type === 'richtext' || ctx.type === 'svg') {
132
+ return __assign(__assign({}, ctx), { node: {
133
+ tag: type,
134
+ children: [],
135
+ attributes: aProps,
136
+ } });
137
+ }
63
138
  }, createTextInstance: function (text, rootContainer, ctx, internalHandle) {
64
- refId++;
65
- ctx.commands.push(['t', { r: refId, c: text }]);
66
- if (rootContainer.fiberCache)
67
- rootContainer.fiberCache.setObject(refId, internalHandle);
68
- return __assign(__assign({}, ctx), { refId: refId });
139
+ if (ctx.type === 'native') {
140
+ refId++;
141
+ ctx.commands.push(['t', { r: refId, c: text }]);
142
+ if (rootContainer.fiberCache)
143
+ rootContainer.fiberCache.setObject(refId, internalHandle);
144
+ return __assign(__assign({}, ctx), { refId: refId });
145
+ }
146
+ else if (ctx.type === 'richtext' || ctx.type === 'svg') {
147
+ return __assign(__assign({}, ctx), { node: { text: text } });
148
+ }
69
149
  }, appendInitialChild: function (parent, child) {
70
- parent.commands.push(['a', { p: parent.refId, c: child.refId }]);
150
+ if (!child)
151
+ return;
152
+ if (parent.type === 'native' && parent.subContext)
153
+ parent = parent.subContext;
154
+ if (parent.type === 'native' && child.type === 'native') {
155
+ parent.commands.push(['a', { p: parent.refId, c: child.refId }]);
156
+ }
157
+ else if ((parent.type === 'richtext' && child.type === 'richtext') ||
158
+ (parent.type === 'svg' && child.type === 'svg')) {
159
+ if ('children' in parent.node)
160
+ parent.node.children.push(child.node);
161
+ child.root = parent.root;
162
+ child.parent = parent;
163
+ updateSubContext(child);
164
+ }
71
165
  }, finalizeInitialChildren: function () { return false; }, commitMount: function (instance) { }, shouldSetTextContent: function (type) { return textTypes[type]; },
72
166
  // -------------------
73
167
  // Mutation
@@ -76,30 +170,114 @@ var hostConfig = __assign(__assign({}, commonReconciler), { getRootHostContext:
76
170
  return diffProperties(oldProps, newProps);
77
171
  }, commitUpdate: function (instance, updatePayload, type) {
78
172
  var props = getAllowedProps(updatePayload, type);
79
- instance.commands.push(['u', __assign({ r: instance.refId, t: type }, convertPropsToSerializable(props))]);
80
- }, commitTextUpdate: function (textInstance, oldText, newText) {
81
- textInstance.commands.push(['x', { r: textInstance.refId, c: newText }]);
173
+ if (instance.type === 'native') {
174
+ instance.commands.push(['u', __assign({ r: instance.refId, t: type }, convertPropsToSerializable(props))]);
175
+ }
176
+ else if (instance.type === 'richtext' || instance.type === 'svg') {
177
+ if ('attributes' in instance.node)
178
+ instance.node.attributes = __assign(__assign({}, instance.node.attributes), props);
179
+ updateSubContext(instance);
180
+ }
181
+ }, commitTextUpdate: function (instance, oldText, newText) {
182
+ if (instance.type === 'native') {
183
+ instance.commands.push(['x', { r: instance.refId, c: newText }]);
184
+ }
185
+ else if (instance.type === 'richtext' || instance.type === 'svg') {
186
+ instance.node = { text: newText };
187
+ updateSubContext(instance);
188
+ }
82
189
  }, appendChild: function (parent, child) {
83
- child.commands.push(['a', { p: parent.refId, c: child.refId }]);
190
+ if (!child)
191
+ return;
192
+ if (parent.type === 'native' && parent.subContext)
193
+ parent = parent.subContext;
194
+ if (parent.type === 'native' && child.type === 'native') {
195
+ child.commands.push(['a', { p: parent.refId, c: child.refId }]);
196
+ }
197
+ else if ((parent.type === 'richtext' && child.type === 'richtext') ||
198
+ (parent.type === 'svg' && child.type === 'svg')) {
199
+ if ('children' in parent.node)
200
+ parent.node.children.push(child.node);
201
+ child.root = parent.root;
202
+ child.parent = parent;
203
+ updateSubContext(child);
204
+ }
84
205
  }, appendChildToContainer: function (parent, child) {
85
- child.commands.push(['a', { p: parent.refId, c: child.refId }]);
206
+ if (child.type === 'native')
207
+ child.commands.push(['a', { p: parent.refId, c: child.refId }]);
86
208
  }, insertBefore: function (parent, child, beforeChild) {
87
- child.commands.push(['i', { p: parent.refId, c: child.refId, i: beforeChild.refId }]);
209
+ if (!child)
210
+ return;
211
+ if (parent.type === 'native' && parent.subContext)
212
+ parent = parent.subContext;
213
+ if (parent.type === 'native' && child.type === 'native' && beforeChild.type === 'native') {
214
+ child.commands.push(['i', { p: parent.refId, c: child.refId, i: beforeChild.refId }]);
215
+ }
216
+ else if ((parent.type === 'richtext' && child.type === 'richtext' && beforeChild.type === 'richtext') ||
217
+ (parent.type === 'svg' && child.type === 'svg' && beforeChild.type === 'svg')) {
218
+ if ('children' in parent.node) {
219
+ var index = parent.node.children.indexOf(beforeChild.node);
220
+ if (index >= 0)
221
+ parent.node.children.splice(index, 0, child.node);
222
+ else
223
+ parent.node.children.push(child.node);
224
+ }
225
+ child.root = parent.root;
226
+ child.parent = parent;
227
+ updateSubContext(child);
228
+ }
88
229
  }, insertInContainerBefore: function (parent, child, beforeChild) {
89
- child.commands.push(['i', { p: parent.refId, c: child.refId, i: beforeChild.refId }]);
230
+ if (child.type === 'native' && beforeChild.type === 'native')
231
+ child.commands.push(['i', { p: parent.refId, c: child.refId, i: beforeChild.refId }]);
90
232
  }, removeChild: function (parent, child) {
91
- child.commands.push(['r', { p: parent.refId, c: child.refId }]);
233
+ if (!child)
234
+ return;
235
+ if (parent.type === 'native' && parent.subContext)
236
+ parent = parent.subContext;
237
+ if (parent.type === 'native' && child.type === 'native') {
238
+ child.commands.push(['r', { p: parent.refId, c: child.refId }]);
239
+ }
240
+ else if ((parent.type === 'richtext' && child.type === 'richtext') ||
241
+ (parent.type === 'svg' && child.type === 'svg')) {
242
+ if ('children' in parent.node) {
243
+ var index = parent.node.children.indexOf(child.node);
244
+ if (index >= 0)
245
+ parent.node.children.splice(index, 1);
246
+ }
247
+ updateSubContext(parent);
248
+ }
92
249
  }, removeChildFromContainer: function (parent, child) {
93
- child.commands.push(['r', { p: parent.refId, c: child.refId }]);
250
+ if (child.type === 'native')
251
+ child.commands.push(['r', { p: parent.refId, c: child.refId }]);
94
252
  }, resetTextContent: function () { }, preparePortalMount: function () { }, detachDeletedInstance: function () { },
95
253
  // Required for Suspense
96
254
  hideInstance: function (instance) {
97
- instance.commands.push(['h', { r: instance.refId, h: true }]);
255
+ if (instance.type === 'native')
256
+ instance.commands.push(['h', { r: instance.refId, h: true }]);
257
+ else if (instance.type === 'richtext' || instance.type === 'svg') {
258
+ instance.node.hidden = true;
259
+ updateSubContext(instance);
260
+ }
98
261
  }, hideTextInstance: function (instance) {
99
- instance.commands.push(['h', { r: instance.refId, h: true }]);
262
+ if (instance.type === 'native')
263
+ instance.commands.push(['h', { r: instance.refId, h: true }]);
264
+ else if (instance.type === 'richtext' || instance.type === 'svg') {
265
+ instance.node.hidden = true;
266
+ updateSubContext(instance);
267
+ }
100
268
  }, unhideInstance: function (instance) {
101
- instance.commands.push(['h', { r: instance.refId, h: false }]);
269
+ if (instance.type === 'native')
270
+ instance.commands.push(['h', { r: instance.refId, h: false }]);
271
+ else if (instance.type === 'richtext' || instance.type === 'svg') {
272
+ instance.node.hidden = false;
273
+ updateSubContext(instance);
274
+ }
102
275
  }, unhideTextInstance: function (instance) {
103
- instance.commands.push(['h', { r: instance.refId, h: false }]);
276
+ if (instance.type === 'native')
277
+ instance.commands.push(['h', { r: instance.refId, h: false }]);
278
+ else if (instance.type === 'richtext' || instance.type === 'svg') {
279
+ instance.node.hidden = false;
280
+ updateSubContext(instance);
281
+ }
104
282
  } });
105
283
  export var asyncReconciler = Reconciler(hostConfig);
@@ -3,17 +3,43 @@ import { ReactUnity } from '../../models/generated';
3
3
  import { ChildSet, HydratableInstance, InstanceTag, NoTimeout, Props, TimeoutHandle, UpdatePayload } from '../../models/renderer';
4
4
  import { BatchCommand } from './commands';
5
5
  import { ObjectsRepo } from './objects';
6
- export declare type AsyncHostContext = {
6
+ export declare type AsyncHostContext = AsyncNativeInstance | AsyncSubContext;
7
+ export declare type AsyncInstance = AsyncNativeInstance | AsyncSubContext;
8
+ export declare type AsyncNativeInstance = {
7
9
  context: ReactUnity.ReactContext;
8
10
  commands: BatchCommand[];
9
- };
10
- export declare type AsyncNativeInstance = AsyncHostContext & {
11
11
  refId: number;
12
+ type: 'native';
13
+ subContext?: AsyncSubContext;
14
+ };
15
+ export declare type AsyncSubContext = RichTextContext | SvgContext;
16
+ export declare type RichTextContext = {
17
+ hostContext: AsyncNativeInstance;
18
+ type: 'richtext';
19
+ node: RichTextNode;
20
+ root: AsyncNativeInstance;
21
+ parent: RichTextContext;
22
+ };
23
+ export declare type SvgContext = {
24
+ hostContext: AsyncNativeInstance;
25
+ type: 'svg';
26
+ node: RichTextNode;
27
+ root: AsyncNativeInstance;
28
+ parent: SvgContext;
12
29
  };
13
- declare type AsyncContainerInstance = AsyncNativeInstance & {
30
+ export declare type RichTextNode = ({
31
+ tag: string;
32
+ attributes: Record<string, any>;
33
+ children: RichTextNode[];
34
+ hidden?: boolean;
35
+ } | {
36
+ text: string;
37
+ hidden?: boolean;
38
+ });
39
+ export declare type AsyncContainerInstance = AsyncNativeInstance & {
14
40
  component: ReactUnity.IReactComponent;
15
41
  fiberCache: ObjectsRepo | null;
16
42
  };
17
43
  declare type AsyncPublicInstance = ReactUnity.IReactComponent;
18
- export declare type AsyncReconcilerConfig = Reconciler.HostConfig<InstanceTag, Props, AsyncContainerInstance, AsyncNativeInstance, AsyncNativeInstance, AsyncNativeInstance, HydratableInstance, AsyncPublicInstance, AsyncHostContext, UpdatePayload, ChildSet, TimeoutHandle, NoTimeout>;
44
+ export declare type AsyncReconcilerConfig = Reconciler.HostConfig<InstanceTag, Props, AsyncContainerInstance, AsyncInstance, AsyncInstance, AsyncNativeInstance, HydratableInstance, AsyncPublicInstance, AsyncHostContext, UpdatePayload, ChildSet, TimeoutHandle, NoTimeout>;
19
45
  export {};
@@ -19,5 +19,10 @@ export declare const commonReconciler: {
19
19
  scheduleTimeout: (callback: any, delay: any) => number;
20
20
  scheduleMicrotask: (callback: (...args: any[]) => any) => void;
21
21
  cancelTimeout: (handle: any) => void;
22
+ beforeActiveInstanceBlur(): void;
23
+ afterActiveInstanceBlur(): void;
24
+ getInstanceFromNode(node: any): any;
25
+ getInstanceFromScope(scopeInstance: any): any;
26
+ prepareScopeUpdate(scopeInstance: any, instance: any): void;
22
27
  };
23
28
  export declare const isDevelopment: boolean;
@@ -45,5 +45,17 @@ export var commonReconciler = {
45
45
  function (callback) { return Promise.resolve(null).then(callback)
46
46
  .catch(function (error) { return setTimeout(function () { throw error; }, 0); }); },
47
47
  cancelTimeout: function (handle) { return clearTimeout(handle); },
48
+ beforeActiveInstanceBlur: function () {
49
+ },
50
+ afterActiveInstanceBlur: function () {
51
+ },
52
+ getInstanceFromNode: function (node) {
53
+ return undefined;
54
+ },
55
+ getInstanceFromScope: function (scopeInstance) {
56
+ return undefined;
57
+ },
58
+ prepareScopeUpdate: function (scopeInstance, instance) {
59
+ },
48
60
  };
49
61
  export var isDevelopment = process.env.NODE_ENV === 'development';
@@ -20,7 +20,7 @@ export function diffProperties(lastProps, nextProps, deepDiffing) {
20
20
  else {
21
21
  var depth = deepDiffing > 0 ? deepDiffing : propKey === 'style' ? 1 : 0;
22
22
  if (depth > 0) {
23
- prop = diffProperties(lastProps[propKey], null, depth - 1);
23
+ prop = diffProperties(lastProps[propKey], {}, depth - 1);
24
24
  if (!prop)
25
25
  continue;
26
26
  }
@@ -1,21 +1,22 @@
1
1
  import * as React from 'react';
2
2
  import { NativeContainerInstance } from '../models/renderer';
3
- import { ObjectsRepo } from './async/objects';
4
- import { AsyncNativeInstance } from './async/types';
3
+ import { AsyncContainerInstance, AsyncNativeInstance } from './async/types';
5
4
  interface RenderOptions {
6
5
  hostContainer?: NativeContainerInstance;
7
6
  disableHelpers?: boolean;
8
7
  mode?: 'legacy' | 'concurrent';
9
- sync?: boolean;
8
+ /**
9
+ Render using the sync reconciler instead of the batch rendering. It is not recommended to change this value.
10
+ Changing this will disable some features like inline rich-text and svg rendering, although it may improve performance for Jint.
11
+ */
12
+ disableBatchRendering?: boolean;
10
13
  }
11
14
  export declare const Renderer: {
12
- render(element: React.ReactNode, options?: RenderOptions): import("react-reconciler").Reconciler<import("./async/types").AsyncHostContext & {
13
- refId: number;
14
- } & {
15
- component: import("../..").ReactUnity.IReactComponent;
16
- fiberCache: ObjectsRepo<any>;
17
- }, AsyncNativeInstance, AsyncNativeInstance, AsyncNativeInstance, import("../..").ReactUnity.IReactComponent> | import("react-reconciler").Reconciler<import("../..").ReactUnity.IReactComponent, import("../..").ReactUnity.IReactComponent, import("../..").ReactUnity.ITextComponent, import("../..").ReactUnity.IReactComponent, any>;
15
+ render(element: React.ReactNode, options?: RenderOptions): import("react-reconciler").Reconciler<AsyncContainerInstance, import("./async/types").AsyncInstance, import("./async/types").AsyncInstance, AsyncNativeInstance, import("../..").ReactUnity.IReactComponent> | import("react-reconciler").Reconciler<import("../..").ReactUnity.IReactComponent, import("../..").ReactUnity.IReactComponent, import("../..").ReactUnity.ITextComponent, import("../..").ReactUnity.IReactComponent, any>;
18
16
  };
19
17
  export declare const batchedUpdates: <A, R>(fn: (a: A) => R, a: A) => R;
20
- export declare const flushSync: <A, R>(fn: (a: A) => R, a: A) => R;
18
+ export declare const flushSync: {
19
+ (): void;
20
+ <R>(fn: () => R): R;
21
+ };
21
22
  export {};
@@ -11,9 +11,7 @@ export var Renderer = {
11
11
  render: function (element, options) {
12
12
  if (options === void 0) { options = {}; }
13
13
  var hostContainer = (options === null || options === void 0 ? void 0 : options.hostContainer) || HostContainer;
14
- // For Jint engine, sync is default
15
- // For other engines (ClearScript), async is default
16
- var isAsync = hostContainer.Context.Script.Engine.Key === 'jint' ? (options === null || options === void 0 ? void 0 : options.sync) === false : !(options === null || options === void 0 ? void 0 : options.sync);
14
+ var isAsync = !(options === null || options === void 0 ? void 0 : options.disableBatchRendering);
17
15
  var _a = containerMap.get(hostContainer) || {}, hostRoot = _a.hostRoot, asyncJobCallback = _a.asyncJobCallback;
18
16
  var findFiberByHostInstance = function () { return null; };
19
17
  if (!hostRoot) {
@@ -40,6 +38,7 @@ export var Renderer = {
40
38
  return Array.prototype.push.apply(commands_1, args);
41
39
  };
42
40
  var hostContainerInstance = {
41
+ type: 'native',
43
42
  commands: commands_1,
44
43
  component: hostContainer,
45
44
  context: hostContainer.Context,
@@ -53,10 +52,10 @@ export var Renderer = {
53
52
  commands_1.length = 0;
54
53
  hostContainer.Context.FlushCommands(serialized);
55
54
  };
56
- hostRoot = asyncReconciler.createContainer(hostContainerInstance, mode, false, null);
55
+ hostRoot = asyncReconciler.createContainer(hostContainerInstance, mode, null, false, undefined, '', function (error) { return console.error(error); }, null);
57
56
  }
58
57
  else {
59
- hostRoot = syncReconciler.createContainer(hostContainer, mode, false, null);
58
+ hostRoot = syncReconciler.createContainer(hostContainer, mode, null, false, undefined, '', function (error) { return console.error(error); }, null);
60
59
  }
61
60
  containerMap.set(hostContainer, { hostRoot: hostRoot, asyncJobCallback: asyncJobCallback });
62
61
  }
@@ -79,7 +78,5 @@ export var Renderer = {
79
78
  return rc;
80
79
  },
81
80
  };
82
- var isSyncByDefault = HostContainer.Context.Script.Engine.Key === 'jint';
83
- var defaultReconciler = isSyncByDefault ? syncReconciler : asyncReconciler;
84
- export var batchedUpdates = defaultReconciler.batchedUpdates;
85
- export var flushSync = defaultReconciler.flushSync;
81
+ export var batchedUpdates = asyncReconciler.batchedUpdates;
82
+ export var flushSync = asyncReconciler.flushSync;
@@ -0,0 +1,6 @@
1
+ import { stringifyRichText } from './richtext';
2
+ import { stringifySVG } from './svg';
3
+ export declare const subContextRenderers: {
4
+ richtext: typeof stringifyRichText;
5
+ svg: typeof stringifySVG;
6
+ };
@@ -0,0 +1,6 @@
1
+ import { stringifyRichText } from './richtext';
2
+ import { stringifySVG } from './svg';
3
+ export var subContextRenderers = {
4
+ 'richtext': stringifyRichText,
5
+ 'svg': stringifySVG,
6
+ };
@@ -0,0 +1,3 @@
1
+ import { RichTextNode } from '../async/types';
2
+ export declare function parametrizeValue(value: string | number): string;
3
+ export declare function stringifyRichText(node: RichTextNode): string;
@@ -0,0 +1,52 @@
1
+ export function parametrizeValue(value) {
2
+ if (typeof value === 'number')
3
+ return value + '';
4
+ value = value + '';
5
+ if (value.includes(' ') || value.includes('-'))
6
+ return '"' + value + '"';
7
+ return value;
8
+ }
9
+ export function stringifyRichText(node) {
10
+ var _a, _b, _c;
11
+ if (node.hidden)
12
+ return '';
13
+ if ('text' in node)
14
+ return node.text;
15
+ var acc = [];
16
+ var tag = node.tag;
17
+ if (tag) {
18
+ acc.push('<');
19
+ acc.push(tag);
20
+ if (((_a = node.attributes) === null || _a === void 0 ? void 0 : _a.value) != null) {
21
+ var value = (_b = node.attributes) === null || _b === void 0 ? void 0 : _b.value;
22
+ acc.push('=');
23
+ acc.push(parametrizeValue(value));
24
+ }
25
+ for (var key in node.attributes) {
26
+ if (key === 'value')
27
+ continue;
28
+ if (Object.prototype.hasOwnProperty.call(node.attributes, key)) {
29
+ var value = node.attributes[key];
30
+ if (value != null) {
31
+ acc.push(' ');
32
+ acc.push(key);
33
+ acc.push('=');
34
+ acc.push(parametrizeValue(value));
35
+ }
36
+ }
37
+ }
38
+ acc.push('>');
39
+ }
40
+ if (((_c = node.children) === null || _c === void 0 ? void 0 : _c.length) > 0) {
41
+ for (var _i = 0, _d = node.children; _i < _d.length; _i++) {
42
+ var child = _d[_i];
43
+ acc.push(stringifyRichText(child));
44
+ }
45
+ if (tag) {
46
+ acc.push('</');
47
+ acc.push(tag);
48
+ acc.push('>');
49
+ }
50
+ }
51
+ return acc.join('');
52
+ }
@@ -0,0 +1,3 @@
1
+ import { RichTextNode } from '../async/types';
2
+ export declare function stringifyStyle(style: any): string;
3
+ export declare function stringifySVG(node: RichTextNode): string;
@@ -0,0 +1,70 @@
1
+ function kebabize(str) {
2
+ return str.split('').map(function (letter, idx) {
3
+ return letter.toUpperCase() === letter
4
+ ? "".concat(idx !== 0 ? '-' : '').concat(letter.toLowerCase())
5
+ : letter;
6
+ }).join('');
7
+ }
8
+ ;
9
+ export function stringifyStyle(style) {
10
+ if (typeof style === 'string')
11
+ return style;
12
+ var acc = [];
13
+ for (var key in style) {
14
+ if (Object.prototype.hasOwnProperty.call(style, key)) {
15
+ var element = style[key];
16
+ if (element != null) {
17
+ acc.push(kebabize(key));
18
+ acc.push(':');
19
+ acc.push(element);
20
+ acc.push(';');
21
+ }
22
+ }
23
+ }
24
+ return acc.join('');
25
+ }
26
+ export function stringifySVG(node) {
27
+ var _a;
28
+ if (node.hidden)
29
+ return '';
30
+ if ('text' in node)
31
+ return node.text;
32
+ var acc = [];
33
+ var tag = node.tag;
34
+ if (tag) {
35
+ acc.push('<');
36
+ acc.push(tag);
37
+ for (var key in node.attributes) {
38
+ if (Object.prototype.hasOwnProperty.call(node.attributes, key)) {
39
+ var element = node.attributes[key];
40
+ if (key === 'style')
41
+ element = stringifyStyle(element);
42
+ if (element != null) {
43
+ acc.push(' ');
44
+ acc.push(kebabize(key));
45
+ acc.push('="');
46
+ acc.push(element);
47
+ acc.push('"');
48
+ }
49
+ }
50
+ }
51
+ }
52
+ if (((_a = node.children) === null || _a === void 0 ? void 0 : _a.length) > 0) {
53
+ if (tag)
54
+ acc.push('>');
55
+ for (var _i = 0, _b = node.children; _i < _b.length; _i++) {
56
+ var child = _b[_i];
57
+ acc.push(stringifySVG(child));
58
+ }
59
+ if (tag) {
60
+ acc.push('</');
61
+ acc.push(tag);
62
+ acc.push('>');
63
+ }
64
+ }
65
+ else {
66
+ if (tag)
67
+ acc.push(' />');
68
+ }
69
+ return acc.join('');
70
+ }
@@ -1 +1 @@
1
- export declare const version = "0.11.0";
1
+ export declare const version = "0.13.1";
@@ -1 +1 @@
1
- export var version = '0.11.0';
1
+ export var version = '0.13.1';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@reactunity/renderer",
3
- "version": "0.11.0",
3
+ "version": "0.13.1",
4
4
  "description": "React renderer for Unity3D",
5
5
  "types": "dist/index.d.ts",
6
6
  "typings": "dist/index.d.ts",
@@ -54,16 +54,16 @@
54
54
  "unity3d"
55
55
  ],
56
56
  "dependencies": {
57
- "react-reconciler": "^0.28.0",
58
- "use-sync-external-store": "^1.1.0"
57
+ "react-reconciler": "^0.29.0",
58
+ "use-sync-external-store": "^1.2.0"
59
59
  },
60
60
  "peerDependencies": {
61
61
  "react": "^18.0.0"
62
62
  },
63
63
  "devDependencies": {
64
- "@reactunity/scripts": "^0.11.0",
65
- "@types/react-reconciler": "^0.26.6",
64
+ "@reactunity/scripts": "^0.13.0",
65
+ "@types/react-reconciler": "^0.28.0",
66
66
  "rimraf": "^3.0.2",
67
- "typescript": "^4.6.4"
67
+ "typescript": "^4.7.4"
68
68
  }
69
69
  }
@@ -1,7 +0,0 @@
1
- import { ReactElement } from 'react';
2
- interface ServerStyleSheet {
3
- getStyleElement(): Array<ReactElement<{}>>;
4
- seal(): void;
5
- }
6
- export declare function insertStyledComponentsSheet(sheet: ServerStyleSheet): void;
7
- export {};
@@ -1,16 +0,0 @@
1
- export function insertStyledComponentsSheet(sheet) {
2
- try {
3
- var styleElements = sheet.getStyleElement();
4
- for (var _i = 0, styleElements_1 = styleElements; _i < styleElements_1.length; _i++) {
5
- var element = styleElements_1[_i];
6
- var styleContent = element.props.dangerouslySetInnerHTML.__html;
7
- Context.InsertStyle(styleContent);
8
- }
9
- }
10
- catch (error) {
11
- console.error(error);
12
- }
13
- finally {
14
- sheet.seal();
15
- }
16
- }