@reactunity/renderer 0.7.0 → 0.9.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.
@@ -1,6 +1,6 @@
1
1
  //
2
2
  // Types in assemblies: ReactUnity, ReactUnity.Editor, ReactUnity.UGUI, ReactUnity.UIToolkit
3
- // Generated 17/10/2021 03:18:39
3
+ // Generated 15/01/2022 01:23:51
4
4
  //
5
5
  /* eslint-disable */
6
6
  export {};
@@ -1,5 +1,6 @@
1
1
  export declare type FontWeight = 'thin' | 100 | 'extra-light' | 200 | 'light' | 300 | 'regular' | 400 | 'medium' | 500 | 'semi-bold' | 600 | 'bold' | 700 | 'heavy' | 800 | 'black' | 900;
2
2
  export declare type FontStyles = 'normal' | 'bold' | 'italic' | 'underline' | 'lowercase' | 'uppercase' | 'smallcaps' | 'strikethrough' | 'superscript' | 'subscript' | 'highlight';
3
+ export declare type TextTransform = 'none' | 'lowercase' | 'uppercase' | 'smallcaps' | 'capitalize';
3
4
  export declare type TextOverflowModes = 'overflow' | 'ellipsis' | 'masking' | 'truncate' | 'scroll-rect' | 'page' | 'linked';
4
5
  export declare type PointerEvents = 'auto' | 'visible' | 'all' | 'none';
5
6
  export declare type Visibility = 'visible' | 'hidden';
@@ -14,3 +15,4 @@ export declare type TimingFunctionType = 'ease' | 'linear' | 'ease-in' | 'ease-o
14
15
  export declare type AnimationFillMode = 'none' | 'both' | 'forwards' | 'backwards';
15
16
  export declare type AnimationDirection = 'normal' | 'reverse' | 'alternate' | 'alternate-reverse';
16
17
  export declare type AnimationPlayState = 'running' | 'paused';
18
+ export declare type BackgroundSize = 'cover' | 'contain';
@@ -1,11 +1,11 @@
1
- import { AnimationDirection, AnimationFillMode, AnimationPlayState, Appearance, BackgroundBlendMode, CursorType, FontStyles, FontWeight, NavigationMode, ObjectFit, PointerEvents, TextAlign, TextOverflowModes, TimingFunctionType, Visibility, WhiteSpace } from './styles-enums';
1
+ import { AnimationDirection, AnimationFillMode, AnimationPlayState, Appearance, BackgroundBlendMode, BackgroundSize, CursorType, FontStyles, FontWeight, NavigationMode, ObjectFit, PointerEvents, TextAlign, TextOverflowModes, TextTransform, TimingFunctionType, Visibility, WhiteSpace } from './styles-enums';
2
2
  import { AssetReference, ColorAux, NumberAux, Vector2Aux, Vector3Aux } from './values';
3
3
  import { YogaValue2Aux, YogaValueAux } from './yoga';
4
4
  export interface RenderStyle {
5
5
  opacity?: NumberAux;
6
6
  zIndex?: number | string;
7
7
  order?: number | string;
8
- visibility?: Visibility | boolean | 'hidden' | 'visible';
8
+ visibility?: Visibility | boolean;
9
9
  cursor?: CursorType | string;
10
10
  pointerEvents?: PointerEvents;
11
11
  content?: string;
@@ -14,9 +14,17 @@ export interface RenderStyle {
14
14
  backgroundBlendMode?: BackgroundBlendMode;
15
15
  backgroundColor?: ColorAux;
16
16
  backgroundImage?: AssetReference;
17
- backgroundPosition?: YogaValue2Aux;
18
- backgroundSize?: YogaValue2Aux;
17
+ backgroundPositionX?: YogaValueAux;
18
+ backgroundPositionY?: YogaValueAux;
19
+ backgroundSize?: BackgroundSize | YogaValue2Aux;
20
+ backgroundRepeatX?: YogaValueAux;
21
+ backgroundRepeatY?: YogaValueAux;
19
22
  maskImage?: AssetReference;
23
+ maskPositionX?: YogaValueAux;
24
+ maskPositionY?: YogaValueAux;
25
+ maskSize?: BackgroundSize | YogaValue2Aux;
26
+ maskRepeatX?: YogaValueAux;
27
+ maskRepeatY?: YogaValueAux;
20
28
  borderRadius?: NumberAux;
21
29
  borderTopLeftRadius?: NumberAux;
22
30
  borderTopRightRadius?: NumberAux;
@@ -32,6 +40,7 @@ export interface RenderStyle {
32
40
  objectPosition?: YogaValue2Aux;
33
41
  transformOrigin?: Vector2Aux;
34
42
  translate?: YogaValue2Aux;
43
+ translateZ?: YogaValueAux;
35
44
  scale?: Vector2Aux;
36
45
  rotate?: Vector3Aux;
37
46
  stateDuration?: number | string;
@@ -39,6 +48,7 @@ export interface RenderStyle {
39
48
  fontFamily?: AssetReference;
40
49
  fontWeight?: FontWeight;
41
50
  fontStyle?: FontStyles;
51
+ textTransform?: TextTransform;
42
52
  fontSize?: YogaValueAux;
43
53
  textOverflow?: TextOverflowModes;
44
54
  textAlign?: TextAlign;
@@ -70,6 +80,8 @@ export interface RenderStyle {
70
80
  audioDelay?: number | string;
71
81
  all?: string;
72
82
  background?: string;
83
+ backgroundPosition?: string;
84
+ backgroundRepeat?: string;
73
85
  border?: string;
74
86
  borderTop?: string;
75
87
  borderRight?: string;
@@ -78,6 +90,8 @@ export interface RenderStyle {
78
90
  borderWidth?: string;
79
91
  margin?: string;
80
92
  mask?: string;
93
+ maskPosition?: string;
94
+ maskRepeat?: string;
81
95
  padding?: string;
82
96
  inset?: string;
83
97
  flex?: string;
@@ -1,3 +1,3 @@
1
- export declare type DiffResult = null | Array<string | any>;
1
+ export declare type DiffResult = null | Record<string, any>;
2
2
  export declare const styleStringSymbol = "__style_as_string__";
3
3
  export declare function diffProperties(lastProps: Record<string, any>, nextProps: Record<string, any>, deepDiffing?: number): DiffResult;
@@ -13,7 +13,7 @@ export function diffProperties(lastProps, nextProps, deepDiffing) {
13
13
  }
14
14
  var prop = null;
15
15
  if (propKey === 'style' && typeof lastProps.style === 'string') {
16
- (updatePayload = updatePayload || []).push(styleStringSymbol, null);
16
+ (updatePayload = updatePayload || {})[styleStringSymbol] = null;
17
17
  }
18
18
  var depth = deepDiffing > 0 ? deepDiffing : propKey === 'style' ? 1 : 0;
19
19
  if (depth > 0) {
@@ -23,7 +23,7 @@ export function diffProperties(lastProps, nextProps, deepDiffing) {
23
23
  }
24
24
  // For all other deleted properties we add it to the queue. We use
25
25
  // the whitelist in the commit phase instead.
26
- (updatePayload = updatePayload || []).push(propKey, prop);
26
+ (updatePayload = updatePayload || {})[propKey] = prop;
27
27
  }
28
28
  for (propKey in nextProps) {
29
29
  var nextProp = nextProps[propKey];
@@ -35,7 +35,7 @@ export function diffProperties(lastProps, nextProps, deepDiffing) {
35
35
  }
36
36
  var prop = nextProp;
37
37
  if (propKey === 'style' && (typeof prop === 'string') !== (typeof lastProp === 'string')) {
38
- (updatePayload = updatePayload || []).push(styleStringSymbol, typeof prop === 'string' ? prop : null);
38
+ (updatePayload = updatePayload || {})[styleStringSymbol] = typeof prop === 'string' ? prop : null;
39
39
  }
40
40
  var depth = deepDiffing > 0 ? deepDiffing : propKey === 'style' ? 1 : 0;
41
41
  if (depth > 0) {
@@ -43,7 +43,7 @@ export function diffProperties(lastProps, nextProps, deepDiffing) {
43
43
  if (!prop)
44
44
  continue;
45
45
  }
46
- (updatePayload = updatePayload || []).push(propKey, prop);
46
+ (updatePayload = updatePayload || {})[propKey] = prop;
47
47
  }
48
48
  return updatePayload;
49
49
  }
@@ -1,5 +1,7 @@
1
- import type * as React from 'react';
1
+ import * as React from 'react';
2
2
  import { NativeContainerInstance } from '../models/renderer';
3
3
  export declare const Renderer: {
4
- render(element: React.ReactNode, hostContainer?: NativeContainerInstance, renderWithoutHelpers?: boolean): number;
4
+ render(element: React.ReactNode, hostContainer?: NativeContainerInstance, renderWithoutHelpers?: boolean): void;
5
5
  };
6
+ export declare const batchedUpdates: <A, R>(fn: (a: A) => R, a: A) => R;
7
+ export declare const flushSync: <A, R>(fn: (a: A) => R, a: A) => R;
@@ -1,150 +1,84 @@
1
+ var __rest = (this && this.__rest) || function (s, e) {
2
+ var t = {};
3
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
4
+ t[p] = s[p];
5
+ if (s != null && typeof Object.getOwnPropertySymbols === "function")
6
+ for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
7
+ if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
8
+ t[p[i]] = s[p[i]];
9
+ }
10
+ return t;
11
+ };
1
12
  import { createElement } from 'react';
2
13
  import * as Reconciler from 'react-reconciler';
3
14
  import { DefaultView } from '../views/default-view';
4
15
  import { diffProperties, styleStringSymbol } from './diffing';
16
+ var LegacyRoot = 1;
17
+ var ConcurrentRoot = 1;
5
18
  var hostContext = {};
6
19
  var childContext = {};
20
+ var DiscreteEventPriority = 1;
21
+ var ContinuousEventPriority = 4;
22
+ var DefaultEventPriority = 16;
23
+ var eventPriorities = {
24
+ discrete: DiscreteEventPriority,
25
+ continuous: ContinuousEventPriority,
26
+ default: DefaultEventPriority,
27
+ };
7
28
  var textTypes = {
8
29
  text: true,
9
30
  icon: true,
10
31
  style: true,
11
32
  script: true,
12
- html: true,
13
33
  };
14
- function applyDiffedUpdate(writeTo, updatePayload, depth) {
15
- if (depth === void 0) { depth = 0; }
16
- if (!updatePayload)
17
- return false;
18
- if (Array.isArray(updatePayload)) {
19
- for (var index = 0; index < updatePayload.length; index += 2) {
20
- var attr = updatePayload[index];
21
- var value = updatePayload[index + 1];
22
- if (depth > 0)
23
- applyDiffedUpdate(writeTo[attr], value, depth - 1);
24
- else
25
- writeTo.SetWithoutNotify(attr, value);
26
- }
27
- return updatePayload.length > 0;
28
- }
29
- else {
30
- for (var attr in updatePayload) {
31
- if (updatePayload.hasOwnProperty(attr)) {
32
- var value = updatePayload[attr];
33
- writeTo.SetWithoutNotify(attr, value);
34
- }
35
- }
36
- return true;
34
+ function getAllowedProps(props, type) {
35
+ var children = props.children, tag = props.tag, rest = __rest(props, ["children", "tag"]);
36
+ if (textTypes[type]) {
37
+ rest.children = (!children || typeof children === 'boolean') ? null : Array.isArray(children) ? children.join('') : children + '';
37
38
  }
38
- }
39
- function applyUpdate(instance, updatePayload, isAfterMount, type, pre) {
40
- if (pre === void 0) { pre = true; }
41
- var updateAfterMount = false;
42
- for (var index = 0; index < updatePayload.length; index += 2) {
43
- var attr = updatePayload[index];
44
- var value = updatePayload[index + 1];
45
- var isEvent = attr.substring(0, 2) === 'on';
46
- // Register events before other properties
47
- if (pre !== isEvent)
48
- continue;
49
- if (isEvent) {
50
- UnityBridge.setEventListener(instance, attr, value);
51
- continue;
52
- }
53
- if (attr === 'children') {
54
- if (textTypes[type]) {
55
- UnityBridge.setText(instance, value ? ((Array.isArray(value) && value.join) ? value.join('') : value + '') : '');
56
- }
57
- continue;
58
- }
59
- if (attr === 'key')
60
- continue;
61
- if (attr === 'ref')
62
- continue;
63
- if (attr === 'tag')
64
- continue;
65
- if (!isAfterMount && (attr === 'style' || attr === styleStringSymbol)) {
66
- updateAfterMount = true;
67
- continue;
68
- }
69
- if (attr === 'style') {
70
- if (applyDiffedUpdate(instance.Style, value)) {
71
- instance.MarkForStyleResolving(false);
72
- }
73
- continue;
74
- }
75
- if (attr === styleStringSymbol) {
76
- UnityBridge.setProperty(instance, 'style', value);
77
- continue;
78
- }
79
- if (attr.substring(0, 5) === 'data-') {
80
- UnityBridge.setData(instance, attr.substring(5), value);
81
- }
82
- else {
83
- UnityBridge.setProperty(instance, attr, value);
84
- }
85
- }
86
- if (pre)
87
- return applyUpdate(instance, updatePayload, isAfterMount, type, false) || updateAfterMount;
88
- return updateAfterMount;
39
+ if (typeof props.style === 'string')
40
+ rest[styleStringSymbol] = props.style;
41
+ return rest;
89
42
  }
90
43
  var hostConfig = {
91
- getRootHostContext: function (rootContainerInstance) { return hostContext; },
92
- getChildHostContext: function (parentHostContext, type, rootContainerInstance) { return childContext; },
44
+ getRootHostContext: function () { return hostContext; },
45
+ getChildHostContext: function () { return childContext; },
93
46
  getPublicInstance: function (instance) { return instance; },
94
- prepareForCommit: function (containerInfo) { return null; },
95
- resetAfterCommit: function (containerInfo) { return null; },
96
- clearContainer: function () { return null; },
97
47
  now: Date.now,
48
+ supportsMutation: true,
98
49
  supportsHydration: false,
99
50
  supportsPersistence: false,
51
+ supportsMicrotasks: false,
52
+ supportsTestSelectors: false,
100
53
  isPrimaryRenderer: true,
101
- createInstance: function (type, props, rootContainerInstance, hostContext, internalInstanceHandle) {
102
- var _a;
103
- if (textTypes[type]) {
104
- var text = props.children === true ? '' :
105
- Array.isArray(props.children) ? props.children.join('') :
106
- ((_a = props.children) === null || _a === void 0 ? void 0 : _a.toString()) || '';
107
- return UnityBridge.createElement(type, text, rootContainerInstance);
108
- }
109
- return UnityBridge.createElement(props.tag || type, null, rootContainerInstance);
54
+ warnsIfNotActing: true,
55
+ prepareForCommit: function () { return null; },
56
+ resetAfterCommit: function () { },
57
+ clearContainer: function () { },
58
+ shouldDeprioritizeSubtree: function () { return false; },
59
+ createInstance: function (type, props, rootContainerInstance) {
60
+ var aProps = getAllowedProps(props, type);
61
+ var children = aProps.children || null;
62
+ delete aProps.children;
63
+ return UnityBridge.createElement(props.tag || type, children, rootContainerInstance, aProps);
110
64
  },
111
- createTextInstance: function (text, rootContainerInstance, hostContext, internalInstanceHandle) {
65
+ createTextInstance: function (text, rootContainerInstance) {
112
66
  return UnityBridge.createText(text, rootContainerInstance);
113
67
  },
114
68
  appendInitialChild: function (parent, child) { UnityBridge.appendChild(parent, child); },
115
- finalizeInitialChildren: function (instance, type, props, rootContainerInstance, hostContext) {
116
- var propsToUpdate = [];
117
- var keys = Object.keys(props);
118
- for (var index = 0; index < keys.length; index++) {
119
- var key = keys[index];
120
- var value = props[key];
121
- propsToUpdate.push(key, value);
122
- }
123
- return applyUpdate(instance, propsToUpdate, false);
124
- },
125
- // Some attributes like style need to be changed only after mount
126
- commitMount: function (instance, type, newProps, internalInstanceHandle) {
127
- var props = [];
128
- if ('style' in newProps) {
129
- props.push('style', newProps.style);
130
- if (typeof newProps.style === 'string')
131
- props.push(styleStringSymbol, newProps.style);
132
- }
133
- applyUpdate(instance, props, true);
134
- },
135
- shouldSetTextContent: function (type, props) { return textTypes[type]; },
136
- shouldDeprioritizeSubtree: function (type, props) { return false; },
69
+ finalizeInitialChildren: function () { return false; },
70
+ commitMount: function () { },
71
+ shouldSetTextContent: function (type) { return textTypes[type]; },
137
72
  // -------------------
138
73
  // Mutation
139
74
  // -------------------
140
- supportsMutation: true,
141
- prepareUpdate: function (instance, type, oldProps, newProps, rootContainerInstance, hostContext) {
75
+ prepareUpdate: function (instance, type, oldProps, newProps) {
142
76
  return diffProperties(oldProps, newProps);
143
77
  },
144
- commitUpdate: function (instance, updatePayload, type, oldProps, newProps, internalInstanceHandle) {
145
- applyUpdate(instance, updatePayload, true, type);
78
+ commitUpdate: function (instance, updatePayload, type) {
79
+ UnityBridge.applyUpdate(instance, getAllowedProps(updatePayload, type), type);
146
80
  },
147
- resetTextContent: function (instance) { console.log('resetTextContent'); },
81
+ resetTextContent: function () { return console.log('resetTextContent'); },
148
82
  commitTextUpdate: function (textInstance, oldText, newText) { UnityBridge.setText(textInstance, newText); },
149
83
  appendChild: function (parent, child) { return UnityBridge.appendChild(parent, child); },
150
84
  appendChildToContainer: function (parent, child) { return UnityBridge.appendChildToContainer(parent, child); },
@@ -155,32 +89,34 @@ var hostConfig = {
155
89
  // Required for Suspense
156
90
  // TODO: implement
157
91
  preparePortalMount: function () { },
158
- hideInstance: function (instance) {
159
- },
160
- hideTextInstance: function (textInstance) {
161
- },
162
- unhideInstance: function (instance, props) {
163
- },
164
- unhideTextInstance: function (textInstance, text) {
165
- },
92
+ hideInstance: function () { },
93
+ hideTextInstance: function () { },
94
+ unhideInstance: function () { },
95
+ unhideTextInstance: function () { },
96
+ detachDeletedInstance: function () { },
166
97
  // -------------------
167
98
  // Scheduling
168
99
  // -------------------
169
- scheduleDeferredCallback: function (callback, options) { return setTimeout(callback, (options === null || options === void 0 ? void 0 : options.timeout) || 0); },
170
- cancelDeferredCallback: function (callBackID) { clearTimeout(callBackID); },
100
+ getCurrentEventPriority: function () { return eventPriorities.default; },
171
101
  noTimeout: -1,
172
102
  scheduleTimeout: function (callback, timeout) { return setTimeout(callback, timeout); },
173
- cancelTimeout: function (handle) { clearTimeout(handle); },
174
- queueMicrotask: function (callback) { return setTimeout(callback, 0); },
103
+ cancelTimeout: function (handle) { return clearTimeout(handle); },
175
104
  };
176
- var ReactUnityReconciler = Reconciler(hostConfig);
105
+ var reconciler = Reconciler(hostConfig);
106
+ var containerMap = new Map();
177
107
  export var Renderer = {
178
108
  render: function (element, hostContainer, renderWithoutHelpers) {
179
109
  if (!hostContainer)
180
110
  hostContainer = HostContainer;
181
- var hostRoot = ReactUnityReconciler.createContainer(hostContainer, 0, false, {});
111
+ var hostRoot = containerMap.get(hostContainer);
112
+ if (!hostRoot) {
113
+ hostRoot = reconciler.createContainer(hostContainer, LegacyRoot, false, null);
114
+ containerMap.set(hostContainer, hostRoot);
115
+ }
182
116
  if (!renderWithoutHelpers)
183
117
  element = createElement(DefaultView, null, element);
184
- return ReactUnityReconciler.updateContainer(element, hostRoot, null);
118
+ reconciler.updateContainer(element, hostRoot, null);
185
119
  },
186
120
  };
121
+ export var batchedUpdates = reconciler.batchedUpdates;
122
+ export var flushSync = reconciler.flushSync;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@reactunity/renderer",
3
- "version": "0.7.0",
3
+ "version": "0.9.1",
4
4
  "description": "React renderer for Unity3D",
5
5
  "types": "dist/index.d.ts",
6
6
  "typings": "dist/index.d.ts",
@@ -30,7 +30,6 @@
30
30
  }
31
31
  },
32
32
  "scripts": {
33
- "preinstall": "npx only-allow@1.0.0 yarn",
34
33
  "build:clean": "rimraf dist",
35
34
  "build:base": "tsc",
36
35
  "build:editor": "tsc -p tsconfig.editor.json",
@@ -62,11 +61,9 @@
62
61
  "react": "^17.0.2"
63
62
  },
64
63
  "devDependencies": {
65
- "@reactunity/scripts": "^0.7.0",
66
- "@types/react": "^17.0.30",
64
+ "@reactunity/scripts": "^0.9.0",
67
65
  "@types/react-reconciler": "^0.26.4",
68
- "@types/webpack-env": "^1.16.3",
69
66
  "rimraf": "^3.0.2",
70
- "typescript": "^4.4.4"
67
+ "typescript": "^4.5.5"
71
68
  }
72
69
  }