revas 1.0.2 → 2.0.0
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.
- package/README.md +61 -1
- package/dist/chunk-JPUKLNW3.js +1710 -0
- package/dist/chunk-JPUKLNW3.js.map +1 -0
- package/dist/revas-common.cjs +1768 -0
- package/dist/revas-common.cjs.map +1 -0
- package/dist/revas-common.d.cts +363 -0
- package/dist/revas-common.d.ts +363 -0
- package/dist/revas-common.js +3 -0
- package/dist/revas-common.js.map +1 -0
- package/dist/revas.cjs +1881 -0
- package/dist/revas.cjs.map +1 -0
- package/dist/revas.d.cts +13 -0
- package/dist/revas.d.ts +13 -0
- package/dist/revas.js +108 -1967
- package/dist/revas.js.map +1 -1
- package/package.json +58 -45
- package/.eslintcache +0 -1
- package/common.d.ts +0 -1
- package/common.js +0 -1
- package/dist/revas.common.js +0 -1861
- package/dist/revas.common.js.map +0 -1
- package/dist/revas.es.js +0 -1932
- package/dist/revas.es.js.map +0 -1
- package/dist/types/develop/App.d.ts +0 -8
- package/dist/types/develop/Intro/About.d.ts +0 -2
- package/dist/types/develop/Intro/Animation.d.ts +0 -2
- package/dist/types/develop/Intro/Component.d.ts +0 -2
- package/dist/types/develop/Intro/Entry.d.ts +0 -6
- package/dist/types/develop/Intro/Gesture.d.ts +0 -2
- package/dist/types/develop/Intro/Interactable.d.ts +0 -10
- package/dist/types/develop/Intro/Navbar.d.ts +0 -6
- package/dist/types/develop/Intro/Panel.d.ts +0 -14
- package/dist/types/develop/Intro/Style.d.ts +0 -2
- package/dist/types/develop/Intro/index.d.ts +0 -2
- package/dist/types/develop/Music/Player.d.ts +0 -79
- package/dist/types/develop/Music/data.d.ts +0 -8
- package/dist/types/develop/Music/index.d.ts +0 -23
- package/dist/types/develop/Music/styles.d.ts +0 -19
- package/dist/types/develop/Timeline/data.d.ts +0 -5
- package/dist/types/develop/Timeline/index.d.ts +0 -11
- package/dist/types/develop/common/back.d.ts +0 -2
- package/dist/types/develop/common/simple-router.d.ts +0 -44
- package/dist/types/develop/serviceWorker.d.ts +0 -7
- package/dist/types/index.d.ts +0 -1
- package/dist/types/revas/common.d.ts +0 -24
- package/dist/types/revas/components/Context.d.ts +0 -12
- package/dist/types/revas/components/Image.d.ts +0 -20
- package/dist/types/revas/components/LinearGradient.d.ts +0 -38
- package/dist/types/revas/components/ListView.d.ts +0 -22
- package/dist/types/revas/components/ScrollView.d.ts +0 -43
- package/dist/types/revas/components/Text.d.ts +0 -16
- package/dist/types/revas/components/Touchable.d.ts +0 -34
- package/dist/types/revas/components/View.d.ts +0 -3
- package/dist/types/revas/components/common/Scroller.d.ts +0 -35
- package/dist/types/revas/components/common/drawImage.d.ts +0 -3
- package/dist/types/revas/components/common/drawText.d.ts +0 -17
- package/dist/types/revas/components/common/imageLoader.d.ts +0 -2
- package/dist/types/revas/core/Animated.d.ts +0 -59
- package/dist/types/revas/core/Canvas.d.ts +0 -17
- package/dist/types/revas/core/Container.d.ts +0 -18
- package/dist/types/revas/core/Node.d.ts +0 -46
- package/dist/types/revas/core/css-layout/index.d.ts +0 -9
- package/dist/types/revas/core/draw.d.ts +0 -4
- package/dist/types/revas/core/offscreen.d.ts +0 -11
- package/dist/types/revas/core/reconciler.d.ts +0 -5
- package/dist/types/revas/core/touch.d.ts +0 -3
- package/dist/types/revas/core/utils.d.ts +0 -22
- package/dist/types/revas/core/yoga-layout/index.d.ts +0 -3
- package/dist/types/revas/core/yoga-layout/init.d.ts +0 -3
- package/dist/types/revas/core/yoga-layout/style.d.ts +0 -3
- package/dist/types/revas/index.d.ts +0 -2
- package/dist/types/revas/web/index.d.ts +0 -1
- package/dist/types/revas/web/render.d.ts +0 -7
- package/doc/API.md +0 -241
- package/doc/README-zh.md +0 -266
- package/public/favicon.ico +0 -0
- package/public/index.html +0 -64
- package/public/logo192.png +0 -0
- package/public/logo512.png +0 -0
- package/public/manifest.json +0 -25
- package/public/robots.txt +0 -2
- package/public/stats.min.js +0 -5
- package/public/touch-emulator.js +0 -363
- package/rollup.config.ts +0 -44
- package/tsconfig.json +0 -30
package/dist/revas.js
CHANGED
|
@@ -1,1975 +1,116 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
function
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
return React.createElement('View', props);
|
|
1
|
+
import { noop, RevasCanvas, Container, reconciler_default, clearCache, Root } from './chunk-JPUKLNW3.js';
|
|
2
|
+
export { AnimatedInterpolate, AnimatedNode, AnimatedTiming, AnimatedValue, AppContext, Container, EMPTY_ARRAY, EMPTY_OBJECT, Easing, Frame, ImageView as Image, LinearGradient, ListView, Node, RevasCanvas, Root, ScrollView, Text, Touchable, Transform, View, adapter, applyAnimated, clamp, flatten, getChars, getFrameFromNode, getMergedStyleFromNode, getWords, noop, now, pushOpacity, reconciler_default as renderer, setShadow, sortByZIndexAscending, timing, withContext } from './chunk-JPUKLNW3.js';
|
|
3
|
+
import { createElement } from 'react';
|
|
4
|
+
|
|
5
|
+
function getNodePosition(node) {
|
|
6
|
+
let top = 0;
|
|
7
|
+
let left = 0;
|
|
8
|
+
while (node) {
|
|
9
|
+
top += node.offsetTop;
|
|
10
|
+
left += node.offsetLeft;
|
|
11
|
+
node = node.offsetParent;
|
|
12
|
+
}
|
|
13
|
+
return [top, left];
|
|
15
14
|
}
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
}
|
|
34
|
-
var now = typeof performance === 'object' && typeof performance.now === 'function' ? function () { return performance.now(); } : function () { return Date.now(); };
|
|
35
|
-
function observeAnimatedValue(value, observer, defaultValue) {
|
|
36
|
-
if (value === undefined) {
|
|
37
|
-
return defaultValue;
|
|
38
|
-
}
|
|
39
|
-
if (value && value.getValue) {
|
|
40
|
-
return value.getValue(observer);
|
|
41
|
-
}
|
|
42
|
-
return value;
|
|
43
|
-
}
|
|
44
|
-
function applyAnimated(style, callback) {
|
|
45
|
-
if (style.animated) {
|
|
46
|
-
// Animated Styles
|
|
47
|
-
for (var key in style) {
|
|
48
|
-
style[key] = observeAnimatedValue(style[key], callback);
|
|
49
|
-
}
|
|
50
|
-
}
|
|
51
|
-
return style;
|
|
52
|
-
}
|
|
53
|
-
function getMergedStyleFromNode(node, callback) {
|
|
54
|
-
var _a = node.props.style, style = _a === void 0 ? EMPTY_ARRAY : _a;
|
|
55
|
-
return applyAnimated(Object.assign.apply(Object, tslib.__spreadArrays([{}], flatten([style]))), callback);
|
|
56
|
-
}
|
|
57
|
-
function getFrameFromNode(node) {
|
|
58
|
-
var frame = node.frame;
|
|
59
|
-
return frame;
|
|
60
|
-
}
|
|
61
|
-
function sortByZIndexAscending(a, b) {
|
|
62
|
-
var styleA = getMergedStyleFromNode(a);
|
|
63
|
-
var styleB = getMergedStyleFromNode(b);
|
|
64
|
-
return (styleA.zIndex || 0) - (styleB.zIndex || 0);
|
|
65
|
-
}
|
|
66
|
-
function clamp(n, min, max) {
|
|
67
|
-
return Math.min(Math.max(n, min), max);
|
|
68
|
-
}
|
|
69
|
-
var ASTRAL_RANGE = /\ud83c[\udffb-\udfff](?=\ud83c[\udffb-\udfff])|(?:[^\ud800-\udfff][\u0300-\u036f\ufe20-\ufe23\u20d0-\u20f0]?|[\u0300-\u036f\ufe20-\ufe23\u20d0-\u20f0]|(?:\ud83c[\udde6-\uddff]){2}|[\ud800-\udbff][\udc00-\udfff]|[\ud800-\udfff])[\ufe0e\ufe0f]?(?:[\u0300-\u036f\ufe20-\ufe23\u20d0-\u20f0]|\ud83c[\udffb-\udfff])?(?:\u200d(?:[^\ud800-\udfff]|(?:\ud83c[\udde6-\uddff]){2}|[\ud800-\udbff][\udc00-\udfff])[\ufe0e\ufe0f]?(?:[\u0300-\u036f\ufe20-\ufe23\u20d0-\u20f0]|\ud83c[\udffb-\udfff])?)*/g;
|
|
70
|
-
var WORD_RANGE = /\w+|\ud83c[\udffb-\udfff](?=\ud83c[\udffb-\udfff])|(?:[^\ud800-\udfff][\u0300-\u036f\ufe20-\ufe23\u20d0-\u20f0]?|[\u0300-\u036f\ufe20-\ufe23\u20d0-\u20f0]|(?:\ud83c[\udde6-\uddff]){2}|[\ud800-\udbff][\udc00-\udfff]|[\ud800-\udfff])[\ufe0e\ufe0f]?(?:[\u0300-\u036f\ufe20-\ufe23\u20d0-\u20f0]|\ud83c[\udffb-\udfff])?(?:\u200d(?:[^\ud800-\udfff]|(?:\ud83c[\udde6-\uddff]){2}|[\ud800-\udbff][\udc00-\udfff])[\ufe0e\ufe0f]?(?:[\u0300-\u036f\ufe20-\ufe23\u20d0-\u20f0]|\ud83c[\udffb-\udfff])?)*/g;
|
|
71
|
-
function getChars(str) {
|
|
72
|
-
return str.match(ASTRAL_RANGE) || EMPTY_ARRAY;
|
|
73
|
-
}
|
|
74
|
-
function getWords(str) {
|
|
75
|
-
return str.match(WORD_RANGE) || EMPTY_ARRAY;
|
|
76
|
-
}
|
|
77
|
-
function setShadow(canvas, color, x, y, blur) {
|
|
78
|
-
if (x === void 0) { x = 0; }
|
|
79
|
-
if (y === void 0) { y = 0; }
|
|
80
|
-
if (blur === void 0) { blur = 0; }
|
|
81
|
-
if (color && (x || y || blur)) {
|
|
82
|
-
var ctx_1 = canvas.context;
|
|
83
|
-
var shadowBlur_1 = ctx_1.shadowBlur, shadowColor_1 = ctx_1.shadowColor, shadowOffsetX_1 = ctx_1.shadowOffsetX, shadowOffsetY_1 = ctx_1.shadowOffsetY;
|
|
84
|
-
ctx_1.shadowBlur = blur;
|
|
85
|
-
ctx_1.shadowColor = color;
|
|
86
|
-
ctx_1.shadowOffsetX = x;
|
|
87
|
-
ctx_1.shadowOffsetY = y;
|
|
88
|
-
return function resetShadow() {
|
|
89
|
-
ctx_1.shadowBlur = shadowBlur_1;
|
|
90
|
-
ctx_1.shadowColor = shadowColor_1;
|
|
91
|
-
ctx_1.shadowOffsetX = shadowOffsetX_1;
|
|
92
|
-
ctx_1.shadowOffsetY = shadowOffsetY_1;
|
|
93
|
-
};
|
|
94
|
-
}
|
|
95
|
-
return noop;
|
|
96
|
-
}
|
|
97
|
-
function pushOpacity(canvas, opacity) {
|
|
98
|
-
if (opacity !== null && opacity < 1 && opacity >= 0) {
|
|
99
|
-
var cachedOpacity_1 = canvas.context.globalAlpha || 1;
|
|
100
|
-
canvas.context.globalAlpha = cachedOpacity_1 * opacity;
|
|
101
|
-
return function popOpacity() {
|
|
102
|
-
canvas.context.globalAlpha = cachedOpacity_1;
|
|
103
|
-
};
|
|
104
|
-
}
|
|
105
|
-
return noop;
|
|
106
|
-
}
|
|
107
|
-
var adapter = {
|
|
108
|
-
createImage: function () { return new Image(); },
|
|
109
|
-
};
|
|
110
|
-
|
|
111
|
-
var DEFAULT_MEASURE = [[], 0];
|
|
112
|
-
function measureLines(canvas, chars, boxWidth, numberOfLines) {
|
|
113
|
-
var lines = [];
|
|
114
|
-
var width = 0;
|
|
115
|
-
var text = '';
|
|
116
|
-
var cursor = -1;
|
|
117
|
-
function pushLine(charWidth, char, force) {
|
|
118
|
-
if (charWidth === void 0) { charWidth = 0; }
|
|
119
|
-
if (char === void 0) { char = ''; }
|
|
120
|
-
if (force === void 0) { force = false; }
|
|
121
|
-
if (force || text) {
|
|
122
|
-
lines.push({ width: width, text: text });
|
|
123
|
-
}
|
|
124
|
-
if (cursor < chars.length && numberOfLines > 0 && lines.length >= numberOfLines) {
|
|
125
|
-
var lastLine = lines[lines.length - 1];
|
|
126
|
-
lastLine.text = lastLine.text.slice(0, -2) + "...";
|
|
127
|
-
lastLine.width = canvas.context.measureText(lastLine.text).width;
|
|
128
|
-
cursor = chars.length + 1;
|
|
129
|
-
}
|
|
130
|
-
else {
|
|
131
|
-
width = charWidth;
|
|
132
|
-
text = char.trim();
|
|
133
|
-
}
|
|
134
|
-
}
|
|
135
|
-
while (cursor++ <= chars.length) {
|
|
136
|
-
if (chars.length > cursor) {
|
|
137
|
-
var char = chars[cursor];
|
|
138
|
-
if (char === '\n') {
|
|
139
|
-
pushLine(0, '', true);
|
|
140
|
-
}
|
|
141
|
-
else {
|
|
142
|
-
var charWidth = canvas.context.measureText(char).width;
|
|
143
|
-
if (charWidth + width > boxWidth) {
|
|
144
|
-
pushLine(charWidth, char);
|
|
145
|
-
}
|
|
146
|
-
else {
|
|
147
|
-
width += charWidth;
|
|
148
|
-
text += char;
|
|
149
|
-
}
|
|
150
|
-
}
|
|
151
|
-
}
|
|
152
|
-
else {
|
|
153
|
-
pushLine();
|
|
154
|
-
}
|
|
155
|
-
}
|
|
156
|
-
return lines;
|
|
157
|
-
}
|
|
158
|
-
function splitContent(content, wordBreak) {
|
|
159
|
-
switch (wordBreak) {
|
|
160
|
-
case 'break-all':
|
|
161
|
-
return getChars(content);
|
|
162
|
-
case 'keep-all':
|
|
163
|
-
return [content];
|
|
164
|
-
default:
|
|
165
|
-
return getWords(content);
|
|
166
|
-
}
|
|
167
|
-
}
|
|
168
|
-
function applyTextStyle(canvas, options) {
|
|
169
|
-
var _a = options.textStyle, fontStyle = _a.fontStyle, fontWeight = _a.fontWeight, fontSize = _a.fontSize, fontFamily = _a.fontFamily, textBaseline = _a.textBaseline, color = _a.color;
|
|
170
|
-
// Apply Styles
|
|
171
|
-
canvas.context.font = fontStyle + " " + fontWeight + " " + fontSize + "px " + fontFamily;
|
|
172
|
-
canvas.context.fillStyle = color;
|
|
173
|
-
canvas.context.textBaseline = textBaseline;
|
|
174
|
-
}
|
|
175
|
-
function measureText(canvas, options) {
|
|
176
|
-
var lines = measureLines(canvas, splitContent(options.content, options.textStyle.wordBreak), options.frame.width, options.numberOfLines);
|
|
177
|
-
return [lines, options.textStyle.lineHeight * lines.length];
|
|
178
|
-
}
|
|
179
|
-
function drawText(canvas, options, lines) {
|
|
180
|
-
var style = options.textStyle, frame = options.frame;
|
|
181
|
-
// Shadow:
|
|
182
|
-
var resetShadow = setShadow(canvas, style.textShadowColor, style.textShadowOffsetX, style.textShadowOffsetY, style.textShadowBlur);
|
|
183
|
-
for (var i = 0; i < lines.length; i++) {
|
|
184
|
-
var line = lines[i];
|
|
185
|
-
var x = frame.x;
|
|
186
|
-
switch (style.textAlign) {
|
|
187
|
-
case 'center':
|
|
188
|
-
x = x + frame.width / 2 - line.width / 2;
|
|
189
|
-
break;
|
|
190
|
-
case 'right':
|
|
191
|
-
x = x + frame.width - line.width;
|
|
192
|
-
break;
|
|
193
|
-
}
|
|
194
|
-
canvas.context.fillText(line.text, x, style.lineHeight * (i + 0.5) + frame.y);
|
|
195
|
-
}
|
|
196
|
-
resetShadow();
|
|
15
|
+
function createRevasTouchEvent(e) {
|
|
16
|
+
e.preventDefault();
|
|
17
|
+
e.stopPropagation();
|
|
18
|
+
const touches = {};
|
|
19
|
+
const type = e.type === "touchcancel" ? "touchend" : e.type;
|
|
20
|
+
Object.keys(e.changedTouches).forEach((key) => {
|
|
21
|
+
const touch = e.changedTouches[key];
|
|
22
|
+
if (touch && touch.target) {
|
|
23
|
+
const [offsetTop, offsetLeft] = getNodePosition(touch.target);
|
|
24
|
+
touches[touch.identifier] = {
|
|
25
|
+
identifier: touch.identifier,
|
|
26
|
+
x: touch.clientX - offsetLeft,
|
|
27
|
+
y: touch.clientY - offsetTop
|
|
28
|
+
};
|
|
29
|
+
}
|
|
30
|
+
});
|
|
31
|
+
return { type, touches, timestamp: e.timeStamp || Date.now() };
|
|
197
32
|
}
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
_this.drawText = function (canvas, node) {
|
|
206
|
-
var content = getTextFromNode(node);
|
|
207
|
-
if (content) {
|
|
208
|
-
var options = {
|
|
209
|
-
numberOfLines: node.props.numberOfLines || 0,
|
|
210
|
-
textStyle: getTextStyleFromNode(node),
|
|
211
|
-
frame: getFrameFromNode(node),
|
|
212
|
-
content: content,
|
|
213
|
-
};
|
|
214
|
-
applyTextStyle(canvas, options);
|
|
215
|
-
if (textPropsChanged(options, _this._drawed)) {
|
|
216
|
-
_this._measured = measureText(canvas, options);
|
|
217
|
-
_this._drawed = options;
|
|
218
|
-
}
|
|
219
|
-
var _a = _this._measured, lines = _a[0], height = _a[1];
|
|
220
|
-
if (height !== _this.state.height) {
|
|
221
|
-
_this.setState({ height: height });
|
|
222
|
-
}
|
|
223
|
-
else {
|
|
224
|
-
drawText(canvas, options, lines);
|
|
225
|
-
}
|
|
226
|
-
}
|
|
227
|
-
};
|
|
228
|
-
return _this;
|
|
229
|
-
}
|
|
230
|
-
Text.prototype.render = function () {
|
|
231
|
-
var _a = this.props, children = _a.children, numberOfLines = _a.numberOfLines, others = tslib.__rest(_a, ["children", "numberOfLines"]);
|
|
232
|
-
return React.createElement('View', others, React.createElement('Text', {
|
|
233
|
-
content: children,
|
|
234
|
-
customDrawer: this.drawText,
|
|
235
|
-
textStyle: others.style,
|
|
236
|
-
style: this.state,
|
|
237
|
-
numberOfLines: numberOfLines,
|
|
238
|
-
$ready: Boolean(this._drawed),
|
|
239
|
-
}));
|
|
240
|
-
};
|
|
241
|
-
return Text;
|
|
242
|
-
}(React.Component));
|
|
243
|
-
var TEXT_STYLES_LIST = [
|
|
244
|
-
'fontStyle',
|
|
245
|
-
'fontWeight',
|
|
246
|
-
'fontSize',
|
|
247
|
-
'fontFamily',
|
|
248
|
-
'textBaseline',
|
|
249
|
-
'wordBreak',
|
|
250
|
-
'lineHeight',
|
|
251
|
-
];
|
|
252
|
-
var DEFAULT_TEXTSTYLE = {
|
|
253
|
-
fontFamily: "-apple-system, BlinkMacSystemFont, 'Segoe UI', 'Roboto', 'Oxygen', 'Ubuntu', 'Cantarell', 'Fira Sans', 'Droid Sans', 'Helvetica Neue'",
|
|
254
|
-
fontWeight: 'normal',
|
|
255
|
-
fontSize: 14,
|
|
256
|
-
color: '#000',
|
|
257
|
-
fontStyle: 'normal',
|
|
258
|
-
textBaseline: 'middle',
|
|
259
|
-
};
|
|
260
|
-
function textStyleChanged(left, right) {
|
|
261
|
-
for (var i = 0; i < TEXT_STYLES_LIST.length; i++) {
|
|
262
|
-
var item = TEXT_STYLES_LIST[i];
|
|
263
|
-
if (left[item] !== right[item]) {
|
|
264
|
-
return true;
|
|
265
|
-
}
|
|
266
|
-
}
|
|
267
|
-
return false;
|
|
268
|
-
}
|
|
269
|
-
function textPropsChanged(left, right) {
|
|
270
|
-
if (!right) {
|
|
271
|
-
return true;
|
|
272
|
-
}
|
|
273
|
-
if (left.content !== right.content) {
|
|
274
|
-
return true;
|
|
275
|
-
}
|
|
276
|
-
if (left.numberOfLines !== right.numberOfLines) {
|
|
277
|
-
return true;
|
|
278
|
-
}
|
|
279
|
-
if (left.frame.width !== right.frame.width) {
|
|
280
|
-
return true;
|
|
281
|
-
}
|
|
282
|
-
return textStyleChanged(left.textStyle, right.textStyle);
|
|
283
|
-
}
|
|
284
|
-
function getTextFromNode(node) {
|
|
285
|
-
var frame = getFrameFromNode(node);
|
|
286
|
-
if (frame.width > 0) {
|
|
287
|
-
var content = node.props.content;
|
|
288
|
-
if (typeof content === 'string') {
|
|
289
|
-
return content;
|
|
290
|
-
}
|
|
291
|
-
else if (Array.isArray(content)) {
|
|
292
|
-
return content.join('');
|
|
293
|
-
}
|
|
294
|
-
}
|
|
295
|
-
return '';
|
|
296
|
-
}
|
|
297
|
-
function getTextStyleFromNode(node) {
|
|
298
|
-
var style = Object.assign.apply(Object, tslib.__spreadArrays([{}, DEFAULT_TEXTSTYLE], flatten([node.props.textStyle])));
|
|
299
|
-
style.lineHeight = style.lineHeight || style.fontSize * 1.1;
|
|
300
|
-
return applyAnimated(style);
|
|
301
|
-
}
|
|
302
|
-
// TODO: nested text support
|
|
303
|
-
|
|
304
|
-
var Frame = /** @class */ (function () {
|
|
305
|
-
function Frame(x, y, width, height) {
|
|
306
|
-
if (x === void 0) { x = 0; }
|
|
307
|
-
if (y === void 0) { y = 0; }
|
|
308
|
-
if (width === void 0) { width = 0; }
|
|
309
|
-
if (height === void 0) { height = 0; }
|
|
310
|
-
this.x = x;
|
|
311
|
-
this.y = y;
|
|
312
|
-
this.width = width;
|
|
313
|
-
this.height = height;
|
|
314
|
-
}
|
|
315
|
-
return Frame;
|
|
316
|
-
}());
|
|
317
|
-
var Node = /** @class */ (function () {
|
|
318
|
-
function Node(type, props) {
|
|
319
|
-
this.type = type;
|
|
320
|
-
this.props = props;
|
|
321
|
-
this.children = [];
|
|
322
|
-
this.frame = new Frame();
|
|
323
|
-
}
|
|
324
|
-
Object.defineProperty(Node.prototype, "$ready", {
|
|
325
|
-
get: function () {
|
|
326
|
-
if (this.props.$ready === false) {
|
|
327
|
-
return false;
|
|
328
|
-
}
|
|
329
|
-
for (var i = 0; i < this.children.length; i++) {
|
|
330
|
-
var child = this.children[i];
|
|
331
|
-
if (child.$ready === false) {
|
|
332
|
-
return false;
|
|
333
|
-
}
|
|
334
|
-
}
|
|
335
|
-
return true;
|
|
336
|
-
},
|
|
337
|
-
enumerable: false,
|
|
338
|
-
configurable: true
|
|
339
|
-
});
|
|
340
|
-
return Node;
|
|
341
|
-
}());
|
|
342
|
-
|
|
343
|
-
function checkAndRemove(parent, child) {
|
|
344
|
-
var index = parent.children.indexOf(child);
|
|
345
|
-
if (index >= 0) {
|
|
346
|
-
parent.children.splice(index, 1);
|
|
347
|
-
}
|
|
348
|
-
}
|
|
349
|
-
function appendChild(parent, child) {
|
|
350
|
-
checkAndRemove(parent, child);
|
|
351
|
-
parent.children.push(child);
|
|
352
|
-
child.parent = parent;
|
|
353
|
-
}
|
|
354
|
-
var unused = {
|
|
355
|
-
unhideTextInstance: function () {
|
|
356
|
-
// noop
|
|
357
|
-
},
|
|
358
|
-
mountEventComponent: function () {
|
|
359
|
-
// noop
|
|
360
|
-
},
|
|
361
|
-
getFundamentalComponentInstance: function () {
|
|
362
|
-
throw new Error('Not yet implemented.');
|
|
363
|
-
},
|
|
364
|
-
mountFundamentalComponent: function () {
|
|
365
|
-
throw new Error('Not yet implemented.');
|
|
366
|
-
},
|
|
367
|
-
shouldUpdateFundamentalComponent: function () {
|
|
368
|
-
throw new Error('Not yet implemented.');
|
|
369
|
-
},
|
|
370
|
-
unmountFundamentalComponent: function () {
|
|
371
|
-
throw new Error('Not yet implemented.');
|
|
372
|
-
},
|
|
373
|
-
getInstanceFromNode: function () {
|
|
374
|
-
throw new Error('Not yet implemented.');
|
|
375
|
-
},
|
|
376
|
-
isOpaqueHydratingObject: function () {
|
|
377
|
-
throw new Error('Not yet implemented');
|
|
378
|
-
},
|
|
379
|
-
makeOpaqueHydratingObject: function () {
|
|
380
|
-
throw new Error('Not yet implemented.');
|
|
381
|
-
},
|
|
382
|
-
makeClientIdInDEV: function () {
|
|
383
|
-
throw new Error('Not yet implemented');
|
|
384
|
-
},
|
|
385
|
-
beforeActiveInstanceBlur: function () {
|
|
386
|
-
// noop
|
|
387
|
-
},
|
|
388
|
-
afterActiveInstanceBlur: function () {
|
|
389
|
-
// noop
|
|
390
|
-
},
|
|
391
|
-
preparePortalMount: function () {
|
|
392
|
-
// noop
|
|
393
|
-
},
|
|
394
|
-
};
|
|
395
|
-
var renderer = ReactReconciler(tslib.__assign(tslib.__assign({ supportsHydration: false, supportsPersistence: false, supportsMutation: true, isPrimaryRenderer: false }, unused), { createInstance: function (type, props) {
|
|
396
|
-
return new Node(type, props);
|
|
397
|
-
},
|
|
398
|
-
createTextInstance: function () {
|
|
399
|
-
throw new Error('Revas: string cannot be child out of <Text/>');
|
|
400
|
-
},
|
|
401
|
-
appendChild: appendChild, appendInitialChild: appendChild, appendChildToContainer: function (container, instance) {
|
|
402
|
-
if (instance.type !== 'Root') {
|
|
403
|
-
throw new Error("wrong root instance type: " + instance.type);
|
|
404
|
-
}
|
|
405
|
-
container.setRoot(instance);
|
|
406
|
-
},
|
|
407
|
-
removeChild: function (parent, child) {
|
|
408
|
-
checkAndRemove(parent, child);
|
|
409
|
-
child.parent = void 0;
|
|
410
|
-
},
|
|
411
|
-
removeChildFromContainer: function (container) {
|
|
412
|
-
container.setRoot();
|
|
413
|
-
},
|
|
414
|
-
insertBefore: function (parent, child, before) {
|
|
415
|
-
checkAndRemove(parent, child);
|
|
416
|
-
var beforeIndex = parent.children.indexOf(before);
|
|
417
|
-
parent.children.splice(beforeIndex, 0, child);
|
|
418
|
-
child.parent = parent;
|
|
419
|
-
},
|
|
420
|
-
insertInContainerBefore: function () {
|
|
421
|
-
throw new Error("shouldn't be here: insertInContainerBefore");
|
|
422
|
-
},
|
|
423
|
-
clearContainer: function () {
|
|
424
|
-
// TODO implement this
|
|
425
|
-
},
|
|
426
|
-
finalizeInitialChildren: function () {
|
|
427
|
-
return false;
|
|
428
|
-
},
|
|
429
|
-
getPublicInstance: function (instance) {
|
|
430
|
-
return instance;
|
|
431
|
-
},
|
|
432
|
-
prepareUpdate: function () {
|
|
433
|
-
return true;
|
|
434
|
-
},
|
|
435
|
-
commitUpdate: function (instance, updatePayload, type, oldProps, newProps) {
|
|
436
|
-
instance.props = newProps;
|
|
437
|
-
},
|
|
438
|
-
prepareForCommit: function () {
|
|
439
|
-
return null;
|
|
440
|
-
},
|
|
441
|
-
resetAfterCommit: function (container) {
|
|
442
|
-
container.draw(true);
|
|
443
|
-
}, resetTextContent: noop, getRootHostContext: function () {
|
|
444
|
-
return {};
|
|
445
|
-
},
|
|
446
|
-
getChildHostContext: function (parentHostContext) {
|
|
447
|
-
return parentHostContext;
|
|
448
|
-
},
|
|
449
|
-
shouldSetTextContent: function () {
|
|
450
|
-
return false;
|
|
451
|
-
}, shouldDeprioritizeSubtree: function () { return false; }, scheduleDeferredCallback: noop, cancelDeferredCallback: noop, setTimeout: setTimeout,
|
|
452
|
-
clearTimeout: clearTimeout, noTimeout: -1, now: now }));
|
|
453
|
-
|
|
454
|
-
var CachedImage = /** @class */ (function () {
|
|
455
|
-
function CachedImage(src) {
|
|
456
|
-
var _this = this;
|
|
457
|
-
this.src = src;
|
|
458
|
-
this.image = adapter.createImage();
|
|
459
|
-
this.targets = [];
|
|
460
|
-
this._ready = false;
|
|
461
|
-
this.onload = function () {
|
|
462
|
-
_this._ready = true;
|
|
463
|
-
renderer.batchedUpdates(function () {
|
|
464
|
-
_this.targets.forEach(function (target) { return target(_this.image); });
|
|
465
|
-
});
|
|
466
|
-
};
|
|
467
|
-
this.onerror = function () { };
|
|
468
|
-
if (!this.image) {
|
|
469
|
-
throw new Error('Revas: createImage must be initialized');
|
|
470
|
-
}
|
|
471
|
-
this.image.onload = this.onload;
|
|
472
|
-
this.image.onerror = this.onerror;
|
|
473
|
-
this.image.src = src;
|
|
474
|
-
}
|
|
475
|
-
Object.defineProperty(CachedImage.prototype, "empty", {
|
|
476
|
-
get: function () {
|
|
477
|
-
return this.targets.length === 0;
|
|
478
|
-
},
|
|
479
|
-
enumerable: false,
|
|
480
|
-
configurable: true
|
|
481
|
-
});
|
|
482
|
-
CachedImage.prototype.add = function (target) {
|
|
483
|
-
if (this.targets.indexOf(target) < 0) {
|
|
484
|
-
this.targets.push(target);
|
|
485
|
-
if (this._ready) {
|
|
486
|
-
target(this.image);
|
|
487
|
-
}
|
|
488
|
-
}
|
|
489
|
-
};
|
|
490
|
-
CachedImage.prototype.remove = function (target) {
|
|
491
|
-
var index = this.targets.indexOf(target);
|
|
492
|
-
this.targets.splice(index, 1);
|
|
493
|
-
};
|
|
494
|
-
return CachedImage;
|
|
495
|
-
}());
|
|
496
|
-
var cache = new Map();
|
|
497
|
-
function get(src, target) {
|
|
498
|
-
if (!cache.has(src)) {
|
|
499
|
-
cache.set(src, new CachedImage(src));
|
|
500
|
-
}
|
|
501
|
-
var cached = cache.get(src);
|
|
502
|
-
target && cached.add(target);
|
|
503
|
-
return cached.image;
|
|
504
|
-
}
|
|
505
|
-
function remove(src, target) {
|
|
506
|
-
if (cache.has(src)) {
|
|
507
|
-
var cached = cache.get(src);
|
|
508
|
-
cached.remove(target);
|
|
509
|
-
if (cached.empty) {
|
|
510
|
-
cache.delete(src);
|
|
511
|
-
}
|
|
512
|
-
}
|
|
33
|
+
function createCanvas(parent, scale) {
|
|
34
|
+
const canvas = document.createElement("canvas");
|
|
35
|
+
canvas.setAttribute("style", "width: 100%; height: 100%;");
|
|
36
|
+
parent.appendChild(canvas);
|
|
37
|
+
canvas.width = canvas.clientWidth * scale;
|
|
38
|
+
canvas.height = canvas.clientHeight * scale;
|
|
39
|
+
return canvas;
|
|
513
40
|
}
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
var style = getMergedStyleFromNode(node);
|
|
526
|
-
var actualSize = {
|
|
527
|
-
width: image.width,
|
|
528
|
-
height: image.height,
|
|
529
|
-
};
|
|
530
|
-
var focusPoint = style.focusPoint || {
|
|
531
|
-
x: actualSize.width * 0.5,
|
|
532
|
-
y: actualSize.height * 0.5,
|
|
533
|
-
};
|
|
534
|
-
var hasClip = flags.hasRadius && !flags.hasClip;
|
|
535
|
-
if (hasClip) {
|
|
536
|
-
canvas.context.save();
|
|
537
|
-
canvas.context.clip();
|
|
538
|
-
}
|
|
539
|
-
if (style.resizeMode === 'contain') {
|
|
540
|
-
var scale = Math.min(width / actualSize.width, height / actualSize.height) || 1;
|
|
541
|
-
var scaledSize = {
|
|
542
|
-
width: actualSize.width * scale,
|
|
543
|
-
height: actualSize.height * scale,
|
|
544
|
-
};
|
|
545
|
-
// Clip the image to rectangle (sx, sy, sw, sh).
|
|
546
|
-
var sw = Math.round(actualSize.width);
|
|
547
|
-
var sh = Math.round(actualSize.height);
|
|
548
|
-
// Scale the image to dimensions (dw, dh).
|
|
549
|
-
var dw = Math.round(scaledSize.width);
|
|
550
|
-
var dh = Math.round(scaledSize.height);
|
|
551
|
-
// Draw the image on the canvas at coordinates (dx, dy).
|
|
552
|
-
var dx = Math.round((width - scaledSize.width) / 2 + x);
|
|
553
|
-
var dy = Math.round((height - scaledSize.height) / 2 + y);
|
|
554
|
-
canvas.context.drawImage(image, 0, 0, sw, sh, dx, dy, dw, dh);
|
|
555
|
-
}
|
|
556
|
-
else {
|
|
557
|
-
var scale = Math.max(width / actualSize.width, height / actualSize.height) || 1;
|
|
558
|
-
var scaledSize = {
|
|
559
|
-
width: actualSize.width * scale,
|
|
560
|
-
height: actualSize.height * scale,
|
|
561
|
-
};
|
|
562
|
-
// Clip the image to rectangle (sx, sy, sw, sh).
|
|
563
|
-
var sx = Math.round(clamp(width * 0.5 - focusPoint.x * scale, width - scaledSize.width, 0)) * (-1 / scale);
|
|
564
|
-
var sy = Math.round(clamp(height * 0.5 - focusPoint.y * scale, height - scaledSize.height, 0)) * (-1 / scale);
|
|
565
|
-
var sw = Math.round(actualSize.width - sx * 2);
|
|
566
|
-
var sh = Math.round(actualSize.height - sy * 2);
|
|
567
|
-
// Scale the image to dimensions (dw, dh).
|
|
568
|
-
var dw = Math.round(width);
|
|
569
|
-
var dh = Math.round(height);
|
|
570
|
-
// Draw the image on the canvas at coordinates (dx, dy).
|
|
571
|
-
var dx = Math.round(x);
|
|
572
|
-
var dy = Math.round(y);
|
|
573
|
-
canvas.context.drawImage(image, sx, sy, sw, sh, dx, dy, dw, dh);
|
|
574
|
-
}
|
|
575
|
-
if (hasClip) {
|
|
576
|
-
canvas.context.restore();
|
|
577
|
-
}
|
|
41
|
+
function createRoot(app, dom, canvas) {
|
|
42
|
+
return createElement(
|
|
43
|
+
Root,
|
|
44
|
+
{
|
|
45
|
+
clientWidth: dom.clientWidth,
|
|
46
|
+
clientHeight: dom.clientHeight,
|
|
47
|
+
deviceRatio: window.devicePixelRatio,
|
|
48
|
+
canvas
|
|
49
|
+
},
|
|
50
|
+
app
|
|
51
|
+
);
|
|
578
52
|
}
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
}, [src]);
|
|
591
|
-
return React.createElement('Image', tslib.__assign(tslib.__assign({ customDrawer: ready ? drawImage : void 0 }, props), { style: [DEFAULT_STYLE, style], $ready: ready }));
|
|
53
|
+
function initTouch(dom, handler) {
|
|
54
|
+
dom.addEventListener("touchstart", handler, false);
|
|
55
|
+
dom.addEventListener("touchmove", handler, false);
|
|
56
|
+
dom.addEventListener("touchend", handler, false);
|
|
57
|
+
dom.addEventListener("touchcancel", handler, false);
|
|
58
|
+
return () => {
|
|
59
|
+
dom.removeEventListener("touchstart", handler, false);
|
|
60
|
+
dom.removeEventListener("touchmove", handler, false);
|
|
61
|
+
dom.removeEventListener("touchend", handler, false);
|
|
62
|
+
dom.removeEventListener("touchcancel", handler, false);
|
|
63
|
+
};
|
|
592
64
|
}
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
|
|
612
|
-
|
|
613
|
-
|
|
614
|
-
|
|
615
|
-
|
|
616
|
-
|
|
617
|
-
|
|
618
|
-
|
|
619
|
-
|
|
620
|
-
|
|
621
|
-
|
|
622
|
-
|
|
623
|
-
|
|
624
|
-
|
|
625
|
-
}
|
|
626
|
-
|
|
627
|
-
|
|
628
|
-
|
|
629
|
-
|
|
630
|
-
|
|
631
|
-
|
|
632
|
-
|
|
633
|
-
|
|
634
|
-
|
|
635
|
-
|
|
636
|
-
|
|
637
|
-
|
|
638
|
-
|
|
639
|
-
|
|
640
|
-
var i = 1;
|
|
641
|
-
for (; i < len; i++) {
|
|
642
|
-
var x1 = this.inRange[i];
|
|
643
|
-
if (value < x1 || i === len - 1) {
|
|
644
|
-
var x0 = this.inRange[i - 1];
|
|
645
|
-
var y0 = this.outRange[i - 1];
|
|
646
|
-
var y1 = this.outRange[i];
|
|
647
|
-
var percent = (value - x0) / (x1 - x0);
|
|
648
|
-
var result = (y1 - y0) * this.ease(percent) + y0;
|
|
649
|
-
return result;
|
|
650
|
-
}
|
|
651
|
-
}
|
|
652
|
-
return 0;
|
|
653
|
-
};
|
|
654
|
-
return AnimatedInterpolate;
|
|
655
|
-
}(AnimatedNode));
|
|
656
|
-
var AnimatedTiming = /** @class */ (function () {
|
|
657
|
-
function AnimatedTiming(value, config) {
|
|
658
|
-
var _this = this;
|
|
659
|
-
this.value = value;
|
|
660
|
-
this.config = config;
|
|
661
|
-
this._startTime = 0;
|
|
662
|
-
this._startValue = 0;
|
|
663
|
-
this._next = 0;
|
|
664
|
-
this._loop = function () {
|
|
665
|
-
var duration = Date.now() - _this._startTime;
|
|
666
|
-
if (duration < _this.config.duration) {
|
|
667
|
-
var percent = duration / _this.config.duration;
|
|
668
|
-
var inc = _this._ease(percent) * (_this.config.to - _this._startValue);
|
|
669
|
-
_this.value.setValue(_this._startValue + inc);
|
|
670
|
-
_this._next = requestAnimationFrame(_this._loop);
|
|
671
|
-
}
|
|
672
|
-
else {
|
|
673
|
-
_this.value.setValue(_this.config.to);
|
|
674
|
-
_this._onEnd && requestAnimationFrame(_this._onEnd);
|
|
675
|
-
}
|
|
676
|
-
};
|
|
677
|
-
}
|
|
678
|
-
Object.defineProperty(AnimatedTiming.prototype, "_ease", {
|
|
679
|
-
get: function () {
|
|
680
|
-
return this.config.ease || Easing.linear;
|
|
681
|
-
},
|
|
682
|
-
enumerable: false,
|
|
683
|
-
configurable: true
|
|
684
|
-
});
|
|
685
|
-
AnimatedTiming.prototype.start = function (onEnd) {
|
|
686
|
-
this._startTime = Date.now();
|
|
687
|
-
this._startValue = this.value.getValue();
|
|
688
|
-
this._onEnd = onEnd;
|
|
689
|
-
this._next = requestAnimationFrame(this._loop);
|
|
690
|
-
return this;
|
|
691
|
-
};
|
|
692
|
-
AnimatedTiming.prototype.stop = function () {
|
|
693
|
-
cancelAnimationFrame(this._next);
|
|
694
|
-
return this;
|
|
695
|
-
};
|
|
696
|
-
AnimatedTiming.prototype.promise = function () {
|
|
697
|
-
var _this = this;
|
|
698
|
-
return new Promise(function (resolve) { return (_this._onEnd = resolve); });
|
|
699
|
-
};
|
|
700
|
-
return AnimatedTiming;
|
|
701
|
-
}());
|
|
702
|
-
function timing(value, config) {
|
|
703
|
-
return new AnimatedTiming(value, config);
|
|
704
|
-
}
|
|
705
|
-
var ease;
|
|
706
|
-
function getEase() {
|
|
707
|
-
if (!ease) {
|
|
708
|
-
ease = bezier(0.42, 0, 1, 1);
|
|
709
|
-
}
|
|
710
|
-
return ease;
|
|
711
|
-
}
|
|
712
|
-
var Easing = {
|
|
713
|
-
linear: function (t) {
|
|
714
|
-
return t;
|
|
715
|
-
},
|
|
716
|
-
ease: function (t) {
|
|
717
|
-
return getEase()(t);
|
|
718
|
-
},
|
|
719
|
-
/**
|
|
720
|
-
* Runs an easing function forwards.
|
|
721
|
-
*/
|
|
722
|
-
in: function (easing) {
|
|
723
|
-
if (easing === void 0) { easing = getEase(); }
|
|
724
|
-
return easing;
|
|
725
|
-
},
|
|
726
|
-
/**
|
|
727
|
-
* Runs an easing function backwards.
|
|
728
|
-
*/
|
|
729
|
-
out: function (easing) {
|
|
730
|
-
if (easing === void 0) { easing = getEase(); }
|
|
731
|
-
return function (t) { return 1 - easing(1 - t); };
|
|
732
|
-
},
|
|
733
|
-
/**
|
|
734
|
-
* Makes any easing function symmetrical. The easing function will run
|
|
735
|
-
* forwards for half of the duration, then backwards for the rest of the
|
|
736
|
-
* duration.
|
|
737
|
-
*/
|
|
738
|
-
inOut: function (easing) {
|
|
739
|
-
if (easing === void 0) { easing = getEase(); }
|
|
740
|
-
return function (t) {
|
|
741
|
-
if (t < 0.5) {
|
|
742
|
-
return easing(t * 2) / 2;
|
|
743
|
-
}
|
|
744
|
-
return 1 - easing((1 - t) * 2) / 2;
|
|
745
|
-
};
|
|
746
|
-
},
|
|
747
|
-
bounce: function (t) {
|
|
748
|
-
if (t < 1 / 2.75) {
|
|
749
|
-
return 7.5625 * t * t;
|
|
750
|
-
}
|
|
751
|
-
if (t < 2 / 2.75) {
|
|
752
|
-
var t2_1 = t - 1.5 / 2.75;
|
|
753
|
-
return 7.5625 * t2_1 * t2_1 + 0.75;
|
|
754
|
-
}
|
|
755
|
-
if (t < 2.5 / 2.75) {
|
|
756
|
-
var t2_2 = t - 2.25 / 2.75;
|
|
757
|
-
return 7.5625 * t2_2 * t2_2 + 0.9375;
|
|
758
|
-
}
|
|
759
|
-
var t2 = t - 2.625 / 2.75;
|
|
760
|
-
return 7.5625 * t2 * t2 + 0.984375;
|
|
761
|
-
},
|
|
762
|
-
elastic: function (bounciness) {
|
|
763
|
-
if (bounciness === void 0) { bounciness = 1; }
|
|
764
|
-
var p = bounciness * Math.PI;
|
|
765
|
-
return function (t) { return 1 - Math.pow(Math.cos((t * Math.PI) / 2), 3) * Math.cos(t * p); };
|
|
766
|
-
},
|
|
767
|
-
};
|
|
768
|
-
|
|
769
|
-
var Touchable = /** @class */ (function (_super) {
|
|
770
|
-
tslib.__extends(Touchable, _super);
|
|
771
|
-
function Touchable() {
|
|
772
|
-
var _this = _super !== null && _super.apply(this, arguments) || this;
|
|
773
|
-
_this._style = {
|
|
774
|
-
opacity: new AnimatedValue(1),
|
|
775
|
-
animated: true
|
|
776
|
-
};
|
|
777
|
-
_this._tid = '';
|
|
778
|
-
_this._onTouchStart = function (e) {
|
|
779
|
-
_this._tid = Object.keys(e.touches)[0];
|
|
780
|
-
_this._start = e.touches[_this._tid];
|
|
781
|
-
_this._style.opacity.setValue(_this.props.activeOpacity);
|
|
782
|
-
_this.props.onPressIn && _this.props.onPressIn();
|
|
783
|
-
};
|
|
784
|
-
_this._onTouchEnd = function (e) {
|
|
785
|
-
if (_this._start && e.touches[_this._tid]) {
|
|
786
|
-
if (Math.abs(_this._start.x - e.touches[_this._tid].x) < 3 &&
|
|
787
|
-
Math.abs(_this._start.y - e.touches[_this._tid].y) < 3) {
|
|
788
|
-
_this.props.onPress && _this.props.onPress();
|
|
789
|
-
}
|
|
790
|
-
}
|
|
791
|
-
_this._style.opacity.setValue(1);
|
|
792
|
-
_this.props.onPressOut && _this.props.onPressOut();
|
|
793
|
-
};
|
|
794
|
-
return _this;
|
|
795
|
-
}
|
|
796
|
-
Touchable.prototype.render = function () {
|
|
797
|
-
return React.createElement('Touchable', tslib.__assign(tslib.__assign({ onTouchStart: this._onTouchStart, onTouchEnd: this._onTouchEnd }, this.props), { style: [
|
|
798
|
-
this.props.style,
|
|
799
|
-
this._style
|
|
800
|
-
] }));
|
|
801
|
-
};
|
|
802
|
-
Touchable.defaultProps = {
|
|
803
|
-
activeOpacity: 0.7
|
|
804
|
-
};
|
|
805
|
-
return Touchable;
|
|
806
|
-
}(React.Component));
|
|
807
|
-
|
|
808
|
-
var Handler = /** @class */ (function () {
|
|
809
|
-
function Handler() {
|
|
810
|
-
this.offset = 0;
|
|
811
|
-
this.velocity = 0;
|
|
812
|
-
this.max = -1;
|
|
813
|
-
this.paging = 0;
|
|
814
|
-
this._last = -1;
|
|
815
|
-
}
|
|
816
|
-
Handler.prototype.capture = function (value) {
|
|
817
|
-
if (this._last < 0) {
|
|
818
|
-
this._last = value;
|
|
819
|
-
}
|
|
820
|
-
};
|
|
821
|
-
Handler.prototype.onMove = function (value, duration) {
|
|
822
|
-
if (this._last >= 0 && duration > 0) {
|
|
823
|
-
var move = this._last - value;
|
|
824
|
-
this.velocity = move / duration;
|
|
825
|
-
this._last = value;
|
|
826
|
-
this.change(move);
|
|
827
|
-
}
|
|
828
|
-
};
|
|
829
|
-
Handler.prototype.onEnd = function () {
|
|
830
|
-
if (this._last >= 0) {
|
|
831
|
-
this._last = -1;
|
|
832
|
-
}
|
|
833
|
-
};
|
|
834
|
-
Handler.prototype.afterEnd = function (duration) {
|
|
835
|
-
if (this._last < 0) {
|
|
836
|
-
var absv = Math.abs(this.velocity);
|
|
837
|
-
if (this.paging > 0 && absv <= 0.5 && this.offset < this.max) {
|
|
838
|
-
// start reset to paging
|
|
839
|
-
var distance = Math.round(this.offset / this.paging + this.velocity) * this.paging - this.offset;
|
|
840
|
-
this.velocity = clamp(distance / 2000 + friction(this.velocity, duration, 0.01), -0.5, 0.5);
|
|
841
|
-
if (Math.abs(distance) > 0.5 || absv > 0.05) {
|
|
842
|
-
var move = this.velocity * duration;
|
|
843
|
-
this.change(move);
|
|
844
|
-
return true;
|
|
845
|
-
}
|
|
846
|
-
else {
|
|
847
|
-
// end to paging
|
|
848
|
-
this.change(distance);
|
|
849
|
-
}
|
|
850
|
-
}
|
|
851
|
-
else if (absv > 0.05) {
|
|
852
|
-
// scroll for free
|
|
853
|
-
this.velocity = friction(this.velocity, duration, 0.002);
|
|
854
|
-
var move = this.velocity * duration;
|
|
855
|
-
this.change(move);
|
|
856
|
-
return true;
|
|
857
|
-
}
|
|
858
|
-
else {
|
|
859
|
-
this.velocity = 0;
|
|
860
|
-
}
|
|
861
|
-
}
|
|
862
|
-
return false;
|
|
863
|
-
};
|
|
864
|
-
Handler.prototype.change = function (move) {
|
|
865
|
-
var _offset = clamp(this.offset + move, 0, this.max > 0 ? this.max : 0);
|
|
866
|
-
// check validate
|
|
867
|
-
if (_offset !== this.offset) {
|
|
868
|
-
this.offset = _offset;
|
|
869
|
-
}
|
|
870
|
-
else if (this._last < 0) {
|
|
871
|
-
this.velocity = 0;
|
|
872
|
-
}
|
|
873
|
-
};
|
|
874
|
-
return Handler;
|
|
875
|
-
}());
|
|
876
|
-
var Scroller = /** @class */ (function () {
|
|
877
|
-
function Scroller(listener) {
|
|
878
|
-
var _this = this;
|
|
879
|
-
this.listener = listener;
|
|
880
|
-
this._timestamp = 0;
|
|
881
|
-
this._x = new Handler();
|
|
882
|
-
this._y = new Handler();
|
|
883
|
-
this._tid = '';
|
|
884
|
-
this.horizontal = false;
|
|
885
|
-
this.touchStart = function (e) {
|
|
886
|
-
if (!_this._tid) {
|
|
887
|
-
_this._tid = Object.keys(e.touches)[0];
|
|
888
|
-
_this._timestamp = e.timestamp;
|
|
889
|
-
var _a = e.touches[_this._tid], x = _a.x, y = _a.y;
|
|
890
|
-
_this.horizontal ? _this._x.capture(x) : _this._y.capture(y);
|
|
891
|
-
_this.emit('start');
|
|
892
|
-
}
|
|
893
|
-
};
|
|
894
|
-
this.touchMove = function (e) {
|
|
895
|
-
if (_this._tid && e.touches[_this._tid] && _this._check(e)) {
|
|
896
|
-
var _a = e.touches[_this._tid], x = _a.x, y = _a.y;
|
|
897
|
-
var duration = e.timestamp - _this._timestamp;
|
|
898
|
-
_this._timestamp = e.timestamp;
|
|
899
|
-
_this.horizontal ? _this._x.onMove(x, duration) : _this._y.onMove(y, duration);
|
|
900
|
-
_this.emit('scroll');
|
|
901
|
-
_this._sign(e);
|
|
902
|
-
}
|
|
903
|
-
};
|
|
904
|
-
this.touchEnd = function () {
|
|
905
|
-
if (_this._tid) {
|
|
906
|
-
_this._tid = '';
|
|
907
|
-
_this._timestamp = Date.now();
|
|
908
|
-
_this._x.onEnd();
|
|
909
|
-
_this._y.onEnd();
|
|
910
|
-
_this._timer = requestAnimationFrame(_this.afterEnd);
|
|
911
|
-
}
|
|
912
|
-
};
|
|
913
|
-
this.afterEnd = function () {
|
|
914
|
-
var timestamp = Date.now();
|
|
915
|
-
var duration = timestamp - _this._timestamp;
|
|
916
|
-
_this._timestamp = timestamp;
|
|
917
|
-
if (_this.horizontal ? _this._x.afterEnd(duration) : _this._y.afterEnd(duration)) {
|
|
918
|
-
_this.emit('scroll');
|
|
919
|
-
_this._timer = requestAnimationFrame(_this.afterEnd);
|
|
920
|
-
}
|
|
921
|
-
else {
|
|
922
|
-
_this.emit('end');
|
|
923
|
-
}
|
|
924
|
-
};
|
|
925
|
-
}
|
|
926
|
-
Object.defineProperty(Scroller.prototype, "maxX", {
|
|
927
|
-
get: function () {
|
|
928
|
-
return this._x.max;
|
|
929
|
-
},
|
|
930
|
-
set: function (value) {
|
|
931
|
-
this._x.max = value;
|
|
932
|
-
},
|
|
933
|
-
enumerable: false,
|
|
934
|
-
configurable: true
|
|
935
|
-
});
|
|
936
|
-
Object.defineProperty(Scroller.prototype, "maxY", {
|
|
937
|
-
get: function () {
|
|
938
|
-
return this._y.max;
|
|
939
|
-
},
|
|
940
|
-
set: function (value) {
|
|
941
|
-
this._y.max = value;
|
|
942
|
-
},
|
|
943
|
-
enumerable: false,
|
|
944
|
-
configurable: true
|
|
945
|
-
});
|
|
946
|
-
Object.defineProperty(Scroller.prototype, "pagingX", {
|
|
947
|
-
set: function (value) {
|
|
948
|
-
this._x.paging = value;
|
|
949
|
-
},
|
|
950
|
-
enumerable: false,
|
|
951
|
-
configurable: true
|
|
952
|
-
});
|
|
953
|
-
Object.defineProperty(Scroller.prototype, "pagingY", {
|
|
954
|
-
set: function (value) {
|
|
955
|
-
this._y.paging = value;
|
|
956
|
-
},
|
|
957
|
-
enumerable: false,
|
|
958
|
-
configurable: true
|
|
959
|
-
});
|
|
960
|
-
Scroller.prototype._sign = function (e) {
|
|
961
|
-
var _this = this;
|
|
962
|
-
e.scroll = tslib.__assign(tslib.__assign({}, e.scroll), { x: true, y: true });
|
|
963
|
-
var stopPropagation = e.scroll.stopPropagation || noop;
|
|
964
|
-
if (this.horizontal) {
|
|
965
|
-
if (this._x.velocity > 0) {
|
|
966
|
-
e.scroll.y = false;
|
|
967
|
-
stopPropagation();
|
|
968
|
-
}
|
|
969
|
-
if (this._x.offset > 0 && this._x.offset < this._x.max) {
|
|
970
|
-
e.scroll.x = false;
|
|
971
|
-
}
|
|
972
|
-
}
|
|
973
|
-
else {
|
|
974
|
-
if (this._y.velocity > 0) {
|
|
975
|
-
e.scroll.x = false;
|
|
976
|
-
stopPropagation();
|
|
977
|
-
}
|
|
978
|
-
if (this._y.offset > 0 && this._y.offset < this._y.max) {
|
|
979
|
-
e.scroll.y = false;
|
|
980
|
-
}
|
|
981
|
-
}
|
|
982
|
-
e.stopPropagation = function () {
|
|
983
|
-
_this.touchEnd();
|
|
984
|
-
stopPropagation();
|
|
985
|
-
};
|
|
986
|
-
};
|
|
987
|
-
Scroller.prototype._check = function (e) {
|
|
988
|
-
if (this.horizontal && e.scroll && e.scroll.x === false) {
|
|
989
|
-
return this.touchEnd();
|
|
990
|
-
}
|
|
991
|
-
if (!this.horizontal && e.scroll && e.scroll.y === false) {
|
|
992
|
-
return this.touchEnd();
|
|
993
|
-
}
|
|
994
|
-
return true;
|
|
995
|
-
};
|
|
996
|
-
Scroller.prototype.emit = function (type) {
|
|
997
|
-
this.listener({
|
|
998
|
-
type: type,
|
|
999
|
-
x: this._x.offset,
|
|
1000
|
-
vx: this._x.velocity,
|
|
1001
|
-
y: this._y.offset,
|
|
1002
|
-
vy: this._y.velocity,
|
|
1003
|
-
timestamp: this._timestamp,
|
|
1004
|
-
tid: this._tid,
|
|
1005
|
-
});
|
|
1006
|
-
};
|
|
1007
|
-
Scroller.prototype.cancel = function () {
|
|
1008
|
-
cancelAnimationFrame(this._timer);
|
|
1009
|
-
this._tid = '';
|
|
1010
|
-
this._timestamp = Date.now();
|
|
1011
|
-
this._x.onEnd();
|
|
1012
|
-
this._y.onEnd();
|
|
1013
|
-
};
|
|
1014
|
-
return Scroller;
|
|
1015
|
-
}());
|
|
1016
|
-
function friction(v, duration, factor) {
|
|
1017
|
-
return v - Math.min(duration * factor, 1) * v;
|
|
1018
|
-
}
|
|
1019
|
-
|
|
1020
|
-
var ScrollView = /** @class */ (function (_super) {
|
|
1021
|
-
tslib.__extends(ScrollView, _super);
|
|
1022
|
-
function ScrollView() {
|
|
1023
|
-
var _this = _super !== null && _super.apply(this, arguments) || this;
|
|
1024
|
-
_this._height = -1;
|
|
1025
|
-
_this._contentHeight = -1;
|
|
1026
|
-
_this._width = -1;
|
|
1027
|
-
_this._contentWidth = -1;
|
|
1028
|
-
_this._innerStyle = {
|
|
1029
|
-
translateX: new AnimatedValue(0),
|
|
1030
|
-
translateY: new AnimatedValue(0),
|
|
1031
|
-
position: 'absolute',
|
|
1032
|
-
animated: true,
|
|
1033
|
-
};
|
|
1034
|
-
_this._offset = { x: 0, y: 0 };
|
|
1035
|
-
_this._scroller = new Scroller(function (e) {
|
|
1036
|
-
var _a = _this._offset, _b = _a.x, x = _b === void 0 ? 0 : _b, _c = _a.y, y = _c === void 0 ? 0 : _c;
|
|
1037
|
-
_this.props.horizontal ?
|
|
1038
|
-
_this._innerStyle.translateX.setValue(x - e.x) :
|
|
1039
|
-
_this._innerStyle.translateY.setValue(y - e.y);
|
|
1040
|
-
switch (e.type) {
|
|
1041
|
-
case 'scroll':
|
|
1042
|
-
return _this.props.onScroll && _this.props.onScroll(e);
|
|
1043
|
-
case 'start':
|
|
1044
|
-
return _this.props.onScrollStart && _this.props.onScrollStart(e);
|
|
1045
|
-
case 'end':
|
|
1046
|
-
return _this.props.onScrollEnd && _this.props.onScrollEnd(e);
|
|
1047
|
-
}
|
|
1048
|
-
});
|
|
1049
|
-
_this._onLayout = function (frame) {
|
|
1050
|
-
if (_this._width !== frame.width || _this._height !== frame.height) {
|
|
1051
|
-
_this._height = frame.height;
|
|
1052
|
-
_this._width = frame.width;
|
|
1053
|
-
_this._checkLayout();
|
|
1054
|
-
if (_this.props.paging) {
|
|
1055
|
-
if (_this.props.horizontal) {
|
|
1056
|
-
_this._scroller.pagingX = _this.props.paging === true ? frame.width : _this.props.paging;
|
|
1057
|
-
}
|
|
1058
|
-
else {
|
|
1059
|
-
_this._scroller.pagingY = _this.props.paging === true ? frame.height : _this.props.paging;
|
|
1060
|
-
}
|
|
1061
|
-
}
|
|
1062
|
-
}
|
|
1063
|
-
_this.props.onLayout && _this.props.onLayout(frame);
|
|
1064
|
-
};
|
|
1065
|
-
_this._onContentLayout = function (frame) {
|
|
1066
|
-
var _a = _this._offset, _b = _a.x, x = _b === void 0 ? 0 : _b, _c = _a.y, y = _c === void 0 ? 0 : _c;
|
|
1067
|
-
var width = frame.width + x;
|
|
1068
|
-
var height = frame.height + y;
|
|
1069
|
-
if (_this._contentWidth !== width || _this._contentHeight !== height) {
|
|
1070
|
-
_this._contentHeight = height;
|
|
1071
|
-
_this._contentWidth = width;
|
|
1072
|
-
_this._checkLayout();
|
|
1073
|
-
}
|
|
1074
|
-
};
|
|
1075
|
-
_this._checkLayout = function () {
|
|
1076
|
-
var maxX = _this._contentWidth - _this._width;
|
|
1077
|
-
var maxY = _this._contentHeight - _this._height;
|
|
1078
|
-
if ((maxX > 0 && maxX !== _this._scroller.maxX) || (maxY > 0 && maxY !== _this._scroller.maxY)) {
|
|
1079
|
-
_this._scroller.maxX = maxX;
|
|
1080
|
-
_this._scroller.maxY = maxY;
|
|
1081
|
-
_this._scroller.emit('none');
|
|
1082
|
-
}
|
|
1083
|
-
};
|
|
1084
|
-
return _this;
|
|
1085
|
-
}
|
|
1086
|
-
ScrollView.prototype.componentWillUnmount = function () {
|
|
1087
|
-
this._scroller.cancel();
|
|
1088
|
-
};
|
|
1089
|
-
ScrollView.prototype.render = function () {
|
|
1090
|
-
var _a;
|
|
1091
|
-
var _b = this.props, children = _b.children, horizontal = _b.horizontal, offset = _b.offset, others = tslib.__rest(_b, ["children", "horizontal", "offset"]);
|
|
1092
|
-
this._scroller.horizontal = horizontal;
|
|
1093
|
-
if (offset) {
|
|
1094
|
-
this._offset = offset;
|
|
1095
|
-
this._scroller.emit('none');
|
|
1096
|
-
}
|
|
1097
|
-
return React.createElement('Scrollable', tslib.__assign(tslib.__assign({}, others), { onLayout: this._onLayout }), React.createElement('ScrollContent', {
|
|
1098
|
-
onTouchStart: this._scroller.touchStart,
|
|
1099
|
-
onTouchMove: this._scroller.touchMove,
|
|
1100
|
-
onTouchEnd: this._scroller.touchEnd,
|
|
1101
|
-
onLayout: this._onContentLayout,
|
|
1102
|
-
style: [
|
|
1103
|
-
this._innerStyle,
|
|
1104
|
-
(_a = {
|
|
1105
|
-
flexDirection: horizontal ? 'row' : 'column'
|
|
1106
|
-
},
|
|
1107
|
-
_a[horizontal ? 'height' : 'width'] = '100%',
|
|
1108
|
-
_a),
|
|
1109
|
-
],
|
|
1110
|
-
children: children,
|
|
1111
|
-
}));
|
|
1112
|
-
};
|
|
1113
|
-
return ScrollView;
|
|
1114
|
-
}(React.Component));
|
|
1115
|
-
|
|
1116
|
-
var ListView = /** @class */ (function (_super) {
|
|
1117
|
-
tslib.__extends(ListView, _super);
|
|
1118
|
-
function ListView() {
|
|
1119
|
-
var _this = _super !== null && _super.apply(this, arguments) || this;
|
|
1120
|
-
_this.state = {
|
|
1121
|
-
start: 0,
|
|
1122
|
-
end: 1,
|
|
1123
|
-
};
|
|
1124
|
-
_this._height = 0;
|
|
1125
|
-
_this.checkVisible = function (y) {
|
|
1126
|
-
if (_this._height > 0) {
|
|
1127
|
-
var itemHeight = _this.props.itemHeight;
|
|
1128
|
-
var _a = _this.state, _start = _a.start, _end = _a.end;
|
|
1129
|
-
var start = Math.max(0, Math.floor((y - 10) / itemHeight));
|
|
1130
|
-
var end = Math.floor((y + _this._height + 10) / itemHeight);
|
|
1131
|
-
if (start !== _start || end !== _end) {
|
|
1132
|
-
_this.setState({ start: start, end: end });
|
|
1133
|
-
}
|
|
1134
|
-
}
|
|
1135
|
-
};
|
|
1136
|
-
_this._onScroll = function (e) {
|
|
1137
|
-
_this.checkVisible(e.y);
|
|
1138
|
-
_this.props.onScroll && _this.props.onScroll(e);
|
|
1139
|
-
};
|
|
1140
|
-
_this._onLayout = function (frame) {
|
|
1141
|
-
if (_this._height !== frame.height) {
|
|
1142
|
-
_this._height = frame.height;
|
|
1143
|
-
}
|
|
1144
|
-
// this._width = frame.width
|
|
1145
|
-
};
|
|
1146
|
-
_this.renderItem = function (item, i) {
|
|
1147
|
-
var _a = _this.props, data = _a.data, renderItem = _a.renderItem;
|
|
1148
|
-
var index = i + _this.state.start;
|
|
1149
|
-
return React.createElement(React.Fragment, { key: index }, renderItem(item, index, data));
|
|
1150
|
-
};
|
|
1151
|
-
return _this;
|
|
1152
|
-
}
|
|
1153
|
-
ListView.prototype.componentDidMount = function () {
|
|
1154
|
-
this.checkVisible(0);
|
|
1155
|
-
};
|
|
1156
|
-
ListView.prototype.render = function () {
|
|
1157
|
-
var _a = this.props, data = _a.data, itemHeight = _a.itemHeight;
|
|
1158
|
-
var _b = this.state, start = _b.start, end = _b.end;
|
|
1159
|
-
// console.log(start, end, this._height);
|
|
1160
|
-
return React.createElement(ScrollView, tslib.__assign(tslib.__assign({}, this.props), { onScroll: this._onScroll, onLayout: this._onLayout, offset: { y: start * itemHeight } }), data.slice(start, end + 1).map(this.renderItem));
|
|
1161
|
-
};
|
|
1162
|
-
return ListView;
|
|
1163
|
-
}(React.Component));
|
|
1164
|
-
|
|
1165
|
-
var DEFAULT_STYLE$1 = { path: true };
|
|
1166
|
-
function LinearGradient(props) {
|
|
1167
|
-
return React.createElement('LinearGradient', tslib.__assign(tslib.__assign({}, props), { style: [DEFAULT_STYLE$1, props.style], customDrawer: drawGradient }));
|
|
1168
|
-
}
|
|
1169
|
-
function drawGradient(canvas, node) {
|
|
1170
|
-
var colors = node.props.colors;
|
|
1171
|
-
if (colors && colors.length > 0) {
|
|
1172
|
-
var _a = node.props, _b = _a.start, start = _b === void 0 ? { x: 0, y: 0 } : _b, _c = _a.end, end = _c === void 0 ? { x: 1, y: 0 } : _c;
|
|
1173
|
-
var frame = getFrameFromNode(node);
|
|
1174
|
-
var grad = canvas.context.createLinearGradient(start.x * frame.width + frame.x, start.y * frame.height + frame.y, end.x * frame.width + frame.x, end.y * frame.height + frame.y);
|
|
1175
|
-
for (var i = 0; i < colors.length; i++) {
|
|
1176
|
-
grad.addColorStop(i / (colors.length - 1), colors[i]);
|
|
1177
|
-
}
|
|
1178
|
-
canvas.context.fillStyle = grad;
|
|
1179
|
-
canvas.context.fill();
|
|
1180
|
-
}
|
|
65
|
+
function render(app, parent, parentComponent, callback = noop) {
|
|
66
|
+
const scale = window.devicePixelRatio;
|
|
67
|
+
const dom = createCanvas(parent, scale);
|
|
68
|
+
const canvas = new RevasCanvas(dom.getContext("2d"));
|
|
69
|
+
const container = new Container();
|
|
70
|
+
const destroyTouch = initTouch(dom, (e) => container.handleTouch(createRevasTouchEvent(e)));
|
|
71
|
+
const fiber = reconciler_default.createContainer(
|
|
72
|
+
container,
|
|
73
|
+
0,
|
|
74
|
+
// tag: LegacyRoot = 0, ConcurrentRoot = 1
|
|
75
|
+
null,
|
|
76
|
+
// hydrationCallbacks
|
|
77
|
+
false,
|
|
78
|
+
// isStrictMode
|
|
79
|
+
null,
|
|
80
|
+
// concurrentUpdatesByDefaultOverride
|
|
81
|
+
"",
|
|
82
|
+
// identifierPrefix
|
|
83
|
+
console.error,
|
|
84
|
+
// onUncaughtError
|
|
85
|
+
console.error,
|
|
86
|
+
// onCaughtError
|
|
87
|
+
console.error,
|
|
88
|
+
// onRecoverableError
|
|
89
|
+
null
|
|
90
|
+
// transitionCallbacks
|
|
91
|
+
);
|
|
92
|
+
canvas.transform.scale(scale, scale);
|
|
93
|
+
reconciler_default.updateContainer(createRoot(app, dom, canvas), fiber, parentComponent, callback);
|
|
94
|
+
return {
|
|
95
|
+
get $() {
|
|
96
|
+
return dom;
|
|
97
|
+
},
|
|
98
|
+
update(next = app, callback2 = noop) {
|
|
99
|
+
dom.width = dom.clientWidth * scale;
|
|
100
|
+
dom.height = dom.clientHeight * scale;
|
|
101
|
+
clearCache();
|
|
102
|
+
canvas.transform.scale(scale, scale);
|
|
103
|
+
reconciler_default.updateContainer(createRoot(next, dom, canvas), fiber, parentComponent, callback2);
|
|
104
|
+
},
|
|
105
|
+
unmount(callback2 = noop) {
|
|
106
|
+
reconciler_default.updateContainer(null, fiber, null, callback2);
|
|
107
|
+
destroyTouch();
|
|
108
|
+
clearCache();
|
|
109
|
+
dom.remove();
|
|
110
|
+
}
|
|
111
|
+
};
|
|
1181
112
|
}
|
|
1182
113
|
|
|
1183
|
-
|
|
1184
|
-
clientWidth: 0,
|
|
1185
|
-
clientHeight: 0,
|
|
1186
|
-
deviceRatio: 1,
|
|
1187
|
-
});
|
|
1188
|
-
function withContext(comp) {
|
|
1189
|
-
comp.contextType = AppContext;
|
|
1190
|
-
return comp;
|
|
1191
|
-
}
|
|
1192
|
-
function Root(props) {
|
|
1193
|
-
return React.createElement(AppContext.Provider, { value: props }, React.createElement('Root', props));
|
|
1194
|
-
}
|
|
1195
|
-
|
|
1196
|
-
var yoga = {};
|
|
1197
|
-
var promise = Yoga.init().then(function (y) {
|
|
1198
|
-
Object.assign(yoga, y);
|
|
1199
|
-
});
|
|
1200
|
-
|
|
1201
|
-
function funcName(key) {
|
|
1202
|
-
return "set" + key[0].toUpperCase() + key.substr(1);
|
|
1203
|
-
}
|
|
1204
|
-
function checkAndRun(yoga, key) {
|
|
1205
|
-
var values = [];
|
|
1206
|
-
for (var _i = 2; _i < arguments.length; _i++) {
|
|
1207
|
-
values[_i - 2] = arguments[_i];
|
|
1208
|
-
}
|
|
1209
|
-
if (yoga[key]) {
|
|
1210
|
-
yoga[key].apply(yoga, values);
|
|
1211
|
-
}
|
|
1212
|
-
else {
|
|
1213
|
-
throw new Error("ReCanvas: No Such Style Func - " + key);
|
|
1214
|
-
}
|
|
1215
|
-
}
|
|
1216
|
-
function parseValue(func, value) {
|
|
1217
|
-
if (typeof value === 'number') {
|
|
1218
|
-
return [func, value];
|
|
1219
|
-
}
|
|
1220
|
-
else if (value === 'auto') {
|
|
1221
|
-
return [func + "Auto"];
|
|
1222
|
-
}
|
|
1223
|
-
else if (value.endsWith('%')) {
|
|
1224
|
-
return [func + "Percent", Number(value.slice(0, -1))];
|
|
1225
|
-
}
|
|
1226
|
-
else {
|
|
1227
|
-
throw new Error("ReCanvas: No Such Style Value - " + value);
|
|
1228
|
-
}
|
|
1229
|
-
}
|
|
1230
|
-
function parseEnum(func, enums, value) {
|
|
1231
|
-
if (enums[value] !== undefined) {
|
|
1232
|
-
return [func, enums[value]];
|
|
1233
|
-
}
|
|
1234
|
-
else {
|
|
1235
|
-
throw new Error("ReCanvas: No Such Style Value - " + value);
|
|
1236
|
-
}
|
|
1237
|
-
}
|
|
1238
|
-
function parseEdge(func, edge, value) {
|
|
1239
|
-
if (typeof value === 'number') {
|
|
1240
|
-
return [func, edge, value];
|
|
1241
|
-
}
|
|
1242
|
-
else if (value === 'auto') {
|
|
1243
|
-
return [func + "Auto", edge];
|
|
1244
|
-
}
|
|
1245
|
-
else if (value.endsWith('%')) {
|
|
1246
|
-
return [func + "Percent", edge, Number(value.slice(0, -1))];
|
|
1247
|
-
}
|
|
1248
|
-
else {
|
|
1249
|
-
throw new Error("ReCanvas: No Such Style Value - " + value);
|
|
1250
|
-
}
|
|
1251
|
-
}
|
|
1252
|
-
var STYLE_MAP = {};
|
|
1253
|
-
function init() {
|
|
1254
|
-
var ALIGN_ENUM = {
|
|
1255
|
-
auto: yoga.ALIGN_AUTO,
|
|
1256
|
-
baseline: yoga.ALIGN_BASELINE,
|
|
1257
|
-
center: yoga.ALIGN_CENTER,
|
|
1258
|
-
'flex-end': yoga.ALIGN_FLEX_END,
|
|
1259
|
-
'flex-start': yoga.ALIGN_FLEX_START,
|
|
1260
|
-
'space-around': yoga.ALIGN_SPACE_AROUND,
|
|
1261
|
-
'space-between': yoga.ALIGN_SPACE_BETWEEN,
|
|
1262
|
-
stretch: yoga.ALIGN_STRETCH,
|
|
1263
|
-
};
|
|
1264
|
-
var AVAILABLE = {
|
|
1265
|
-
VALUE: [
|
|
1266
|
-
'flex',
|
|
1267
|
-
'width',
|
|
1268
|
-
'height',
|
|
1269
|
-
'minWidth',
|
|
1270
|
-
'maxWidth',
|
|
1271
|
-
'minHeight',
|
|
1272
|
-
'maxHeight',
|
|
1273
|
-
'flexGrow',
|
|
1274
|
-
'flexShrink',
|
|
1275
|
-
'aspectRatio',
|
|
1276
|
-
],
|
|
1277
|
-
ENUM: [
|
|
1278
|
-
{
|
|
1279
|
-
key: 'justifyContent',
|
|
1280
|
-
enum: {
|
|
1281
|
-
center: yoga.JUSTIFY_CENTER,
|
|
1282
|
-
'flex-end': yoga.JUSTIFY_FLEX_END,
|
|
1283
|
-
'flex-start': yoga.JUSTIFY_FLEX_START,
|
|
1284
|
-
'space-around': yoga.JUSTIFY_SPACE_AROUND,
|
|
1285
|
-
'space-between': yoga.JUSTIFY_SPACE_BETWEEN,
|
|
1286
|
-
'space-evenly': yoga.JUSTIFY_SPACE_EVENLY,
|
|
1287
|
-
},
|
|
1288
|
-
},
|
|
1289
|
-
{ key: 'alignItems', enum: ALIGN_ENUM },
|
|
1290
|
-
{ key: 'alignSelf', enum: ALIGN_ENUM },
|
|
1291
|
-
{ key: 'alignContent', enum: ALIGN_ENUM },
|
|
1292
|
-
{
|
|
1293
|
-
key: 'flexWrap',
|
|
1294
|
-
enum: {
|
|
1295
|
-
'no-wrap': yoga.WRAP_NO_WRAP,
|
|
1296
|
-
wrap: yoga.WRAP_WRAP,
|
|
1297
|
-
'wrap-reverse': yoga.WRAP_WRAP_REVERSE,
|
|
1298
|
-
},
|
|
1299
|
-
},
|
|
1300
|
-
{
|
|
1301
|
-
key: 'flexDirection',
|
|
1302
|
-
enum: {
|
|
1303
|
-
column: yoga.FLEX_DIRECTION_COLUMN,
|
|
1304
|
-
'column-reverse': yoga.FLEX_DIRECTION_COLUMN_REVERSE,
|
|
1305
|
-
count: yoga.FLEX_DIRECTION_COUNT,
|
|
1306
|
-
row: yoga.FLEX_DIRECTION_ROW,
|
|
1307
|
-
'row-reverse': yoga.FLEX_DIRECTION_ROW_REVERSE,
|
|
1308
|
-
},
|
|
1309
|
-
},
|
|
1310
|
-
{
|
|
1311
|
-
key: 'position',
|
|
1312
|
-
remap: 'positionType',
|
|
1313
|
-
enum: {
|
|
1314
|
-
relative: yoga.POSITION_TYPE_RELATIVE,
|
|
1315
|
-
absolute: yoga.POSITION_TYPE_ABSOLUTE,
|
|
1316
|
-
count: yoga.POSITION_TYPE_COUNT,
|
|
1317
|
-
},
|
|
1318
|
-
},
|
|
1319
|
-
],
|
|
1320
|
-
EDGE: [
|
|
1321
|
-
{ key: 'padding', remap: 'padding', edge: yoga.EDGE_ALL },
|
|
1322
|
-
{ key: 'paddingLeft', remap: 'padding', edge: yoga.EDGE_LEFT },
|
|
1323
|
-
{ key: 'paddingRight', remap: 'padding', edge: yoga.EDGE_RIGHT },
|
|
1324
|
-
{ key: 'paddingTop', remap: 'padding', edge: yoga.EDGE_TOP },
|
|
1325
|
-
{ key: 'paddingBottom', remap: 'padding', edge: yoga.EDGE_BOTTOM },
|
|
1326
|
-
{ key: 'left', remap: 'position', edge: yoga.EDGE_LEFT },
|
|
1327
|
-
{ key: 'right', remap: 'position', edge: yoga.EDGE_RIGHT },
|
|
1328
|
-
{ key: 'top', remap: 'position', edge: yoga.EDGE_TOP },
|
|
1329
|
-
{ key: 'bottom', remap: 'position', edge: yoga.EDGE_BOTTOM },
|
|
1330
|
-
{ key: 'margin', remap: 'margin', edge: yoga.EDGE_ALL },
|
|
1331
|
-
{ key: 'marginLeft', remap: 'margin', edge: yoga.EDGE_LEFT },
|
|
1332
|
-
{ key: 'marginRight', remap: 'margin', edge: yoga.EDGE_RIGHT },
|
|
1333
|
-
{ key: 'marginTop', remap: 'margin', edge: yoga.EDGE_TOP },
|
|
1334
|
-
{ key: 'marginBottom', remap: 'margin', edge: yoga.EDGE_BOTTOM },
|
|
1335
|
-
{ key: 'borderWidth', remap: 'border', edge: yoga.EDGE_ALL },
|
|
1336
|
-
{ key: 'borderLeftWidth', remap: 'border', edge: yoga.EDGE_LEFT },
|
|
1337
|
-
{ key: 'borderRightWidth', remap: 'border', edge: yoga.EDGE_RIGHT },
|
|
1338
|
-
{ key: 'borderTopWidth', remap: 'border', edge: yoga.EDGE_TOP },
|
|
1339
|
-
{ key: 'borderBottomWidth', remap: 'border', edge: yoga.EDGE_BOTTOM },
|
|
1340
|
-
],
|
|
1341
|
-
};
|
|
1342
|
-
AVAILABLE.VALUE.forEach(function (key) {
|
|
1343
|
-
var func = funcName(key);
|
|
1344
|
-
STYLE_MAP[key] = function (value) { return parseValue(func, value); };
|
|
1345
|
-
});
|
|
1346
|
-
AVAILABLE.ENUM.forEach(function (item) {
|
|
1347
|
-
var func = funcName(item.remap || item.key);
|
|
1348
|
-
var enums = item.enum;
|
|
1349
|
-
STYLE_MAP[item.key] = function (value) { return parseEnum(func, enums, value); };
|
|
1350
|
-
});
|
|
1351
|
-
AVAILABLE.EDGE.forEach(function (item) {
|
|
1352
|
-
var func = funcName(item.remap);
|
|
1353
|
-
var edge = item.edge;
|
|
1354
|
-
STYLE_MAP[item.key] = function (value) { return parseEdge(func, edge, value); };
|
|
1355
|
-
});
|
|
1356
|
-
}
|
|
1357
|
-
promise.then(init);
|
|
1358
|
-
// function _apply(yoga: Yoga.YogaNode, style: any) {
|
|
1359
|
-
// for (const key in style) {
|
|
1360
|
-
// const func = STYLE_MAP[key]
|
|
1361
|
-
// func && checkAndRun(yoga, ...func(style[key]))
|
|
1362
|
-
// }
|
|
1363
|
-
// }
|
|
1364
|
-
var cache$1 = new WeakMap();
|
|
1365
|
-
function _apply(yoga, style) {
|
|
1366
|
-
if (style) {
|
|
1367
|
-
if (!cache$1.has(style)) {
|
|
1368
|
-
var _styles = [];
|
|
1369
|
-
for (var key in style) {
|
|
1370
|
-
var func = STYLE_MAP[key];
|
|
1371
|
-
func && _styles.push(func(style[key]));
|
|
1372
|
-
}
|
|
1373
|
-
cache$1.set(style, _styles);
|
|
1374
|
-
}
|
|
1375
|
-
var styles = cache$1.get(style);
|
|
1376
|
-
for (var i = 0; i < styles.length; i++) {
|
|
1377
|
-
checkAndRun.apply(void 0, tslib.__spreadArrays([yoga], styles[i]));
|
|
1378
|
-
}
|
|
1379
|
-
}
|
|
1380
|
-
}
|
|
1381
|
-
function apply(yoga, style) {
|
|
1382
|
-
if (style) {
|
|
1383
|
-
flatten([style]).forEach(function (s) { return _apply(yoga, s); });
|
|
1384
|
-
}
|
|
1385
|
-
}
|
|
1386
|
-
|
|
1387
|
-
function _updateLayout(node) {
|
|
1388
|
-
var yoga$1 = yoga.Node.create();
|
|
1389
|
-
var children = [];
|
|
1390
|
-
apply(yoga$1, node.props.style);
|
|
1391
|
-
for (var i = 0; i < node.children.length; i++) {
|
|
1392
|
-
var child = node.children[i];
|
|
1393
|
-
var _a = _updateLayout(child), f = _a[0], y = _a[1];
|
|
1394
|
-
var index = children.push(f);
|
|
1395
|
-
yoga$1.insertChild(y, index - 1);
|
|
1396
|
-
}
|
|
1397
|
-
function process(x, y) {
|
|
1398
|
-
if (x === void 0) { x = 0; }
|
|
1399
|
-
if (y === void 0) { y = 0; }
|
|
1400
|
-
var _a = yoga$1.getComputedLayout(), left = _a.left, top = _a.top, width = _a.width, height = _a.height;
|
|
1401
|
-
node.frame = new Frame(x + left, y + top, width, height);
|
|
1402
|
-
node.props.onLayout && node.props.onLayout(node.frame);
|
|
1403
|
-
for (var i = 0; i < children.length; i++) {
|
|
1404
|
-
children[i](node.frame.x, node.frame.y);
|
|
1405
|
-
}
|
|
1406
|
-
yoga$1.free();
|
|
1407
|
-
}
|
|
1408
|
-
return [process, yoga$1];
|
|
1409
|
-
}
|
|
1410
|
-
function updateLayout(root) {
|
|
1411
|
-
var _a = _updateLayout(root), process = _a[0], yoga$1 = _a[1];
|
|
1412
|
-
var _b = root.props, clientWidth = _b.clientWidth, clientHeight = _b.clientHeight, RTL = _b.RTL;
|
|
1413
|
-
yoga$1.calculateLayout(clientWidth, clientHeight, RTL ? yoga.DIRECTION_RTL : yoga.DIRECTION_LTR);
|
|
1414
|
-
return process;
|
|
1415
|
-
}
|
|
1416
|
-
|
|
1417
|
-
var MAX_SIZE = 30;
|
|
1418
|
-
var cache$2 = new Map();
|
|
1419
|
-
var ids = [];
|
|
1420
|
-
function getCache(id) {
|
|
1421
|
-
return cache$2.get(id);
|
|
1422
|
-
}
|
|
1423
|
-
function createCache(style, w, h, id) {
|
|
1424
|
-
if (ids.length >= MAX_SIZE) {
|
|
1425
|
-
var expiredId = ids.shift();
|
|
1426
|
-
var canvas = cache$2.get(expiredId).canvas;
|
|
1427
|
-
var cached = {
|
|
1428
|
-
canvas: adapter.resetOffscreenCanvas(canvas, w, h),
|
|
1429
|
-
id: id,
|
|
1430
|
-
style: style,
|
|
1431
|
-
};
|
|
1432
|
-
cache$2.delete(expiredId);
|
|
1433
|
-
cache$2.set(cached.id, cached);
|
|
1434
|
-
ids.push(cached.id);
|
|
1435
|
-
return cached;
|
|
1436
|
-
}
|
|
1437
|
-
else {
|
|
1438
|
-
var cached = {
|
|
1439
|
-
canvas: adapter.createOffscreenCanvas(w, h),
|
|
1440
|
-
id: id,
|
|
1441
|
-
style: style,
|
|
1442
|
-
};
|
|
1443
|
-
cache$2.set(cached.id, cached);
|
|
1444
|
-
ids.push(cached.id);
|
|
1445
|
-
return cached;
|
|
1446
|
-
}
|
|
1447
|
-
}
|
|
1448
|
-
var idCache = new WeakMap();
|
|
1449
|
-
var __ID = 0;
|
|
1450
|
-
function autoCacheId(node) {
|
|
1451
|
-
if (idCache.has(node)) {
|
|
1452
|
-
return idCache.get(node);
|
|
1453
|
-
}
|
|
1454
|
-
else {
|
|
1455
|
-
var id = "$$auto_id-" + __ID++;
|
|
1456
|
-
idCache.set(node, id);
|
|
1457
|
-
return id;
|
|
1458
|
-
}
|
|
1459
|
-
}
|
|
1460
|
-
function clearCache() {
|
|
1461
|
-
cache$2.clear();
|
|
1462
|
-
ids.length = 0;
|
|
1463
|
-
}
|
|
1464
|
-
|
|
1465
|
-
function getRadius(style) {
|
|
1466
|
-
return {
|
|
1467
|
-
tl: style.borderTopLeftRadius || style.borderRadius || 0,
|
|
1468
|
-
tr: style.borderTopRightRadius || style.borderRadius || 0,
|
|
1469
|
-
bl: style.borderBottomLeftRadius || style.borderRadius || 0,
|
|
1470
|
-
br: style.borderBottomRightRadius || style.borderRadius || 0,
|
|
1471
|
-
};
|
|
1472
|
-
}
|
|
1473
|
-
function drawNode(canvas, node, container) {
|
|
1474
|
-
var style = getMergedStyleFromNode(node, container.draw);
|
|
1475
|
-
var frame = getFrameFromNode(node);
|
|
1476
|
-
if (style.opacity <= 0) {
|
|
1477
|
-
return;
|
|
1478
|
-
}
|
|
1479
|
-
// flags
|
|
1480
|
-
var hasTransform = style.translateX || style.translateY || style.rotate || style.scaleX || style.scaleY || style.scale;
|
|
1481
|
-
var hasClip = style.overflow === 'hidden';
|
|
1482
|
-
if (hasClip) {
|
|
1483
|
-
canvas.context.save();
|
|
1484
|
-
}
|
|
1485
|
-
else if (hasTransform) {
|
|
1486
|
-
canvas.transform.save();
|
|
1487
|
-
}
|
|
1488
|
-
// Area Range
|
|
1489
|
-
// Opacity:
|
|
1490
|
-
var popOpacity = pushOpacity(canvas, style.opacity);
|
|
1491
|
-
// Translation:
|
|
1492
|
-
if (style.translateX || style.translateY) {
|
|
1493
|
-
canvas.transform.translate(style.translateX || 0, style.translateY || 0);
|
|
1494
|
-
}
|
|
1495
|
-
// Rotate && Scale
|
|
1496
|
-
if (style.rotate || style.scaleX || style.scaleY || style.scale) {
|
|
1497
|
-
// Origin Center
|
|
1498
|
-
var originX = frame.x + frame.width / 2;
|
|
1499
|
-
var originY = frame.y + frame.height / 2;
|
|
1500
|
-
canvas.transform.translate(originX, originY);
|
|
1501
|
-
if (style.rotate) {
|
|
1502
|
-
canvas.transform.rotate(style.rotate);
|
|
1503
|
-
}
|
|
1504
|
-
if (style.scaleX || style.scaleY || style.scale) {
|
|
1505
|
-
canvas.transform.scale(style.scaleX || style.scale, style.scaleY || style.scale);
|
|
1506
|
-
}
|
|
1507
|
-
canvas.transform.translate(-originX, -originY);
|
|
1508
|
-
}
|
|
1509
|
-
if (node.props.cache && adapter.createOffscreenCanvas && frame.height > 0 && frame.width > 0) {
|
|
1510
|
-
drawCache(canvas, node, container, style, frame, hasClip);
|
|
1511
|
-
}
|
|
1512
|
-
else {
|
|
1513
|
-
drawContent(canvas, node, container, style, frame, hasClip);
|
|
1514
|
-
}
|
|
1515
|
-
popOpacity();
|
|
1516
|
-
if (hasClip) {
|
|
1517
|
-
canvas.context.restore();
|
|
1518
|
-
}
|
|
1519
|
-
else if (hasTransform) {
|
|
1520
|
-
canvas.transform.restore();
|
|
1521
|
-
}
|
|
1522
|
-
}
|
|
1523
|
-
function drawCache(canvas, node, container, style, frame, hasClip) {
|
|
1524
|
-
var cachedId = node.props.cache === true ? autoCacheId(node) : node.props.cache;
|
|
1525
|
-
var cached = getCache(cachedId);
|
|
1526
|
-
var _a = cached ? cached.style : style, _b = _a.shadowBlur, shadowBlur = _b === void 0 ? 0 : _b, _c = _a.shadowOffsetX, shadowOffsetX = _c === void 0 ? 0 : _c, _d = _a.shadowOffsetY, shadowOffsetY = _d === void 0 ? 0 : _d;
|
|
1527
|
-
var spread = shadowBlur * 2;
|
|
1528
|
-
var x = frame.x + shadowOffsetX - shadowBlur;
|
|
1529
|
-
var y = frame.y + shadowOffsetY - shadowBlur;
|
|
1530
|
-
var w = frame.width + spread;
|
|
1531
|
-
var h = frame.height + spread;
|
|
1532
|
-
if (!cached) {
|
|
1533
|
-
if (!node.$ready && !node.props.forceCache) {
|
|
1534
|
-
return drawContent(canvas, node, container, style, frame, hasClip);
|
|
1535
|
-
}
|
|
1536
|
-
cached = createCache(style, w, h, cachedId);
|
|
1537
|
-
cached.canvas.transform.translate(-x, -y);
|
|
1538
|
-
drawContent(cached.canvas, node, container, style, frame, hasClip);
|
|
1539
|
-
cached.canvas.transform.translate(x, y);
|
|
1540
|
-
}
|
|
1541
|
-
canvas.context.drawImage(cached.canvas.element, x, y, w, h);
|
|
1542
|
-
}
|
|
1543
|
-
function drawContent(canvas, node, container, style, frame, hasClip) {
|
|
1544
|
-
var hasBG = style.backgroundColor && style.backgroundColor !== 'transparent';
|
|
1545
|
-
var hasBorder = style.borderColor && style.borderWidth > 0;
|
|
1546
|
-
var hasRadius = style.borderRadius ||
|
|
1547
|
-
style.borderTopLeftRadius ||
|
|
1548
|
-
style.borderTopRightRadius ||
|
|
1549
|
-
style.borderBottomLeftRadius ||
|
|
1550
|
-
style.borderBottomRightRadius;
|
|
1551
|
-
// consts
|
|
1552
|
-
var useFrame = hasBG || hasBorder || hasClip || style.path;
|
|
1553
|
-
var usePath = hasRadius || hasClip || style.path;
|
|
1554
|
-
if (useFrame) {
|
|
1555
|
-
var ctx = canvas.context;
|
|
1556
|
-
if (usePath) {
|
|
1557
|
-
// Draw Path
|
|
1558
|
-
ctx.beginPath();
|
|
1559
|
-
if (hasRadius) {
|
|
1560
|
-
var radius = getRadius(style);
|
|
1561
|
-
ctx.moveTo(frame.x + radius.tl, frame.y);
|
|
1562
|
-
ctx.arcTo(frame.x + frame.width, frame.y, frame.x + frame.width, frame.y + frame.height, radius.tr);
|
|
1563
|
-
ctx.arcTo(frame.x + frame.width, frame.y + frame.height, frame.x, frame.y + frame.height, radius.br);
|
|
1564
|
-
ctx.arcTo(frame.x, frame.y + frame.height, frame.x, frame.y, radius.bl);
|
|
1565
|
-
ctx.arcTo(frame.x, frame.y, frame.x + frame.width, frame.y, radius.tl);
|
|
1566
|
-
}
|
|
1567
|
-
else {
|
|
1568
|
-
ctx.rect(frame.x, frame.y, frame.width, frame.height);
|
|
1569
|
-
}
|
|
1570
|
-
ctx.closePath();
|
|
1571
|
-
if (hasClip) {
|
|
1572
|
-
ctx.clip();
|
|
1573
|
-
}
|
|
1574
|
-
}
|
|
1575
|
-
if (hasBG || hasBorder) {
|
|
1576
|
-
// Shadow:
|
|
1577
|
-
var resetShadow = setShadow(canvas, style.shadowColor, style.shadowOffsetX, style.shadowOffsetY, style.shadowBlur);
|
|
1578
|
-
// Background color & Shadow
|
|
1579
|
-
if (hasBG) {
|
|
1580
|
-
ctx.fillStyle = style.backgroundColor;
|
|
1581
|
-
if (usePath) {
|
|
1582
|
-
ctx.fill();
|
|
1583
|
-
}
|
|
1584
|
-
else {
|
|
1585
|
-
ctx.fillRect(frame.x, frame.y, frame.width, frame.height);
|
|
1586
|
-
}
|
|
1587
|
-
}
|
|
1588
|
-
// Border with border radius:
|
|
1589
|
-
if (hasBorder) {
|
|
1590
|
-
ctx.lineWidth = style.borderWidth;
|
|
1591
|
-
ctx.strokeStyle = style.borderColor;
|
|
1592
|
-
if (usePath) {
|
|
1593
|
-
ctx.stroke();
|
|
1594
|
-
}
|
|
1595
|
-
else {
|
|
1596
|
-
ctx.strokeRect(frame.x, frame.y, frame.width, frame.height);
|
|
1597
|
-
}
|
|
1598
|
-
}
|
|
1599
|
-
resetShadow();
|
|
1600
|
-
}
|
|
1601
|
-
}
|
|
1602
|
-
if (node.props.customDrawer) {
|
|
1603
|
-
node.props.customDrawer(canvas, node, { hasRadius: hasRadius, hasClip: hasClip });
|
|
1604
|
-
}
|
|
1605
|
-
// Draw child layers, sorted by their z-index.
|
|
1606
|
-
node.children
|
|
1607
|
-
.slice()
|
|
1608
|
-
.sort(sortByZIndexAscending)
|
|
1609
|
-
.forEach(function drawChild(child) {
|
|
1610
|
-
drawNode(canvas, child, container);
|
|
1611
|
-
});
|
|
1612
|
-
}
|
|
1613
|
-
|
|
1614
|
-
function scaled(x, c, s) {
|
|
1615
|
-
if (s === void 0) { s = 1; }
|
|
1616
|
-
if (!s && s === 1)
|
|
1617
|
-
return x;
|
|
1618
|
-
return ((s - 1) * c + x) / s;
|
|
1619
|
-
}
|
|
1620
|
-
function findNodeByPoint(node, x, y) {
|
|
1621
|
-
if (node.props.pointerEvents === 'none')
|
|
1622
|
-
return;
|
|
1623
|
-
var children = node.children.slice().sort(sortByZIndexAscending).reverse();
|
|
1624
|
-
var style = getMergedStyleFromNode(node);
|
|
1625
|
-
var frame = getFrameFromNode(node);
|
|
1626
|
-
// tranlate
|
|
1627
|
-
var scaleX = style.scaleX || style.scale;
|
|
1628
|
-
var scaleY = style.scaleY || style.scale;
|
|
1629
|
-
var originX = frame.width / 2 + frame.x;
|
|
1630
|
-
var originY = frame.height / 2 + frame.y;
|
|
1631
|
-
x -= style.translateX || 0;
|
|
1632
|
-
y -= style.translateY || 0;
|
|
1633
|
-
x = scaled(x, originX, scaleX);
|
|
1634
|
-
y = scaled(y, originY, scaleY);
|
|
1635
|
-
if (frame.x < x && frame.y < y
|
|
1636
|
-
&& x <= frame.x + frame.width
|
|
1637
|
-
&& y <= frame.y + frame.height) {
|
|
1638
|
-
for (var i = 0; i < children.length; i++) {
|
|
1639
|
-
var target = findNodeByPoint(children[i], x, y);
|
|
1640
|
-
if (target)
|
|
1641
|
-
return target;
|
|
1642
|
-
}
|
|
1643
|
-
if (node.props.pointerEvents === 'box-none')
|
|
1644
|
-
return;
|
|
1645
|
-
return node;
|
|
1646
|
-
}
|
|
1647
|
-
}
|
|
1648
|
-
var eventNodeHolder = {};
|
|
1649
|
-
function getNodeByTouch(root, type, touch) {
|
|
1650
|
-
if (type === 'touchstart') {
|
|
1651
|
-
var target = findNodeByPoint(root, touch.x, touch.y);
|
|
1652
|
-
eventNodeHolder[touch.identifier] = target || root;
|
|
1653
|
-
return eventNodeHolder[touch.identifier];
|
|
1654
|
-
}
|
|
1655
|
-
else if (type === 'touchmove') {
|
|
1656
|
-
return eventNodeHolder[touch.identifier] || root;
|
|
1657
|
-
}
|
|
1658
|
-
else if (type === 'touchend') {
|
|
1659
|
-
var target = eventNodeHolder[touch.identifier];
|
|
1660
|
-
delete eventNodeHolder[touch.identifier];
|
|
1661
|
-
return target || root;
|
|
1662
|
-
}
|
|
1663
|
-
return root;
|
|
1664
|
-
}
|
|
1665
|
-
var LISTENER_MAP = {
|
|
1666
|
-
touchstart: 'onTouchStart',
|
|
1667
|
-
touchmove: 'onTouchMove',
|
|
1668
|
-
touchend: 'onTouchEnd'
|
|
1669
|
-
};
|
|
1670
|
-
function emitTouch(node, e) {
|
|
1671
|
-
var funcName = LISTENER_MAP[e.type];
|
|
1672
|
-
if (funcName) {
|
|
1673
|
-
while (node) {
|
|
1674
|
-
if (node.props[funcName]
|
|
1675
|
-
&& node.props.pointerEvents !== 'box-none'
|
|
1676
|
-
&& node.props[funcName](e) === false)
|
|
1677
|
-
return;
|
|
1678
|
-
node = node.parent;
|
|
1679
|
-
}
|
|
1680
|
-
}
|
|
1681
|
-
}
|
|
1682
|
-
|
|
1683
|
-
// import { updateLayout } from './css-layout'
|
|
1684
|
-
var Container = /** @class */ (function () {
|
|
1685
|
-
function Container() {
|
|
1686
|
-
var _this = this;
|
|
1687
|
-
this._ready = false;
|
|
1688
|
-
this._next = false;
|
|
1689
|
-
this._reflow = false;
|
|
1690
|
-
this.handleTouch = function (evt) {
|
|
1691
|
-
var _root = _this._root;
|
|
1692
|
-
if (_root) {
|
|
1693
|
-
var emitted_1 = new WeakSet();
|
|
1694
|
-
Object.values(evt.touches).forEach(function (touch) {
|
|
1695
|
-
var node = getNodeByTouch(_root, evt.type, touch);
|
|
1696
|
-
// check if node is unmounted
|
|
1697
|
-
if (node.parent && !emitted_1.has(node)) {
|
|
1698
|
-
emitted_1.add(node);
|
|
1699
|
-
emitTouch(node, evt);
|
|
1700
|
-
}
|
|
1701
|
-
});
|
|
1702
|
-
}
|
|
1703
|
-
};
|
|
1704
|
-
this.draw = function (reflow) {
|
|
1705
|
-
if (reflow === void 0) { reflow = false; }
|
|
1706
|
-
_this._reflow = _this._reflow || reflow;
|
|
1707
|
-
if (!_this._ready) {
|
|
1708
|
-
_this._next = true;
|
|
1709
|
-
return;
|
|
1710
|
-
}
|
|
1711
|
-
_this._ready = false;
|
|
1712
|
-
var _a = _this, _root = _a._root, canvas = _a.canvas;
|
|
1713
|
-
if (canvas) {
|
|
1714
|
-
// if not unmounted
|
|
1715
|
-
if (_this._reflow) {
|
|
1716
|
-
updateLayout(_root)();
|
|
1717
|
-
_this._reflow = false;
|
|
1718
|
-
}
|
|
1719
|
-
canvas.context.clearRect(0, 0, _this.width, _this.height);
|
|
1720
|
-
drawNode(canvas, _root, _this);
|
|
1721
|
-
requestAnimationFrame(_this.ready);
|
|
1722
|
-
}
|
|
1723
|
-
};
|
|
1724
|
-
this.ready = function () {
|
|
1725
|
-
_this._ready = true;
|
|
1726
|
-
if (_this._next) {
|
|
1727
|
-
_this._next = false;
|
|
1728
|
-
_this.draw();
|
|
1729
|
-
}
|
|
1730
|
-
};
|
|
1731
|
-
promise.then(this.ready);
|
|
1732
|
-
}
|
|
1733
|
-
Object.defineProperty(Container.prototype, "canvas", {
|
|
1734
|
-
get: function () {
|
|
1735
|
-
var _a;
|
|
1736
|
-
return (_a = this._root) === null || _a === void 0 ? void 0 : _a.props.canvas;
|
|
1737
|
-
},
|
|
1738
|
-
enumerable: false,
|
|
1739
|
-
configurable: true
|
|
1740
|
-
});
|
|
1741
|
-
Object.defineProperty(Container.prototype, "width", {
|
|
1742
|
-
get: function () {
|
|
1743
|
-
var _a;
|
|
1744
|
-
return ((_a = this._root) === null || _a === void 0 ? void 0 : _a.props.clientWidth) || 0;
|
|
1745
|
-
},
|
|
1746
|
-
enumerable: false,
|
|
1747
|
-
configurable: true
|
|
1748
|
-
});
|
|
1749
|
-
Object.defineProperty(Container.prototype, "height", {
|
|
1750
|
-
get: function () {
|
|
1751
|
-
var _a;
|
|
1752
|
-
return ((_a = this._root) === null || _a === void 0 ? void 0 : _a.props.clientHeight) || 0;
|
|
1753
|
-
},
|
|
1754
|
-
enumerable: false,
|
|
1755
|
-
configurable: true
|
|
1756
|
-
});
|
|
1757
|
-
Object.defineProperty(Container.prototype, "scale", {
|
|
1758
|
-
get: function () {
|
|
1759
|
-
var _a;
|
|
1760
|
-
return ((_a = this._root) === null || _a === void 0 ? void 0 : _a.props.deviceRatio) || 1;
|
|
1761
|
-
},
|
|
1762
|
-
enumerable: false,
|
|
1763
|
-
configurable: true
|
|
1764
|
-
});
|
|
1765
|
-
Container.prototype.setRoot = function (root) {
|
|
1766
|
-
this._root = root;
|
|
1767
|
-
};
|
|
1768
|
-
return Container;
|
|
1769
|
-
}());
|
|
1770
|
-
|
|
1771
|
-
var RevasCanvas = /** @class */ (function () {
|
|
1772
|
-
function RevasCanvas(context) {
|
|
1773
|
-
this.transform = new Transform(context);
|
|
1774
|
-
}
|
|
1775
|
-
Object.defineProperty(RevasCanvas.prototype, "context", {
|
|
1776
|
-
get: function () {
|
|
1777
|
-
return this.transform.context;
|
|
1778
|
-
},
|
|
1779
|
-
enumerable: false,
|
|
1780
|
-
configurable: true
|
|
1781
|
-
});
|
|
1782
|
-
Object.defineProperty(RevasCanvas.prototype, "element", {
|
|
1783
|
-
get: function () {
|
|
1784
|
-
return this.context.canvas;
|
|
1785
|
-
},
|
|
1786
|
-
enumerable: false,
|
|
1787
|
-
configurable: true
|
|
1788
|
-
});
|
|
1789
|
-
return RevasCanvas;
|
|
1790
|
-
}());
|
|
1791
|
-
var Transform = /** @class */ (function () {
|
|
1792
|
-
function Transform(context) {
|
|
1793
|
-
this.context = context;
|
|
1794
|
-
this._stack = [];
|
|
1795
|
-
this._canGetTransform = false;
|
|
1796
|
-
this._canGetTransform = Boolean(context.getTransform);
|
|
1797
|
-
}
|
|
1798
|
-
Transform.prototype.save = function () {
|
|
1799
|
-
if (this._canGetTransform) {
|
|
1800
|
-
this._stack.push(this.context.getTransform());
|
|
1801
|
-
}
|
|
1802
|
-
else {
|
|
1803
|
-
this.context.save();
|
|
1804
|
-
}
|
|
1805
|
-
};
|
|
1806
|
-
Transform.prototype.restore = function () {
|
|
1807
|
-
if (this._canGetTransform) {
|
|
1808
|
-
if (this._stack.length > 0) {
|
|
1809
|
-
this.context.setTransform(this._stack.pop());
|
|
1810
|
-
}
|
|
1811
|
-
}
|
|
1812
|
-
else {
|
|
1813
|
-
this.context.restore();
|
|
1814
|
-
}
|
|
1815
|
-
};
|
|
1816
|
-
Transform.prototype.translate = function (x, y) {
|
|
1817
|
-
this.context.translate(x, y);
|
|
1818
|
-
};
|
|
1819
|
-
Transform.prototype.rotate = function (rad) {
|
|
1820
|
-
this.context.rotate(rad);
|
|
1821
|
-
};
|
|
1822
|
-
Transform.prototype.scale = function (sx, sy) {
|
|
1823
|
-
this.context.scale(sx, sy);
|
|
1824
|
-
};
|
|
1825
|
-
return Transform;
|
|
1826
|
-
}());
|
|
1827
|
-
|
|
1828
|
-
function getNodePosition(node) {
|
|
1829
|
-
var top = 0;
|
|
1830
|
-
var left = 0;
|
|
1831
|
-
while (node) {
|
|
1832
|
-
top += node.offsetTop;
|
|
1833
|
-
left += node.offsetLeft;
|
|
1834
|
-
node = node.offsetParent;
|
|
1835
|
-
}
|
|
1836
|
-
return [top, left];
|
|
1837
|
-
}
|
|
1838
|
-
function createRevasTouchEvent(e) {
|
|
1839
|
-
e.preventDefault();
|
|
1840
|
-
e.stopPropagation();
|
|
1841
|
-
var touches = {};
|
|
1842
|
-
var type = e.type === 'touchcancel' ? 'touchend' : e.type;
|
|
1843
|
-
Object.keys(e.changedTouches).forEach(function (key) {
|
|
1844
|
-
var touch = e.changedTouches[key];
|
|
1845
|
-
if (touch && touch.target) {
|
|
1846
|
-
var _a = getNodePosition(touch.target), offsetTop = _a[0], offsetLeft = _a[1];
|
|
1847
|
-
touches[touch.identifier] = {
|
|
1848
|
-
identifier: touch.identifier,
|
|
1849
|
-
x: touch.clientX - offsetLeft,
|
|
1850
|
-
y: touch.clientY - offsetTop,
|
|
1851
|
-
};
|
|
1852
|
-
}
|
|
1853
|
-
});
|
|
1854
|
-
return { type: type, touches: touches, timestamp: e.timeStamp || Date.now() };
|
|
1855
|
-
}
|
|
1856
|
-
function createCanvas(parent, scale) {
|
|
1857
|
-
var canvas = document.createElement('canvas');
|
|
1858
|
-
canvas.setAttribute('style', 'width: 100%; height: 100%;');
|
|
1859
|
-
parent.appendChild(canvas);
|
|
1860
|
-
canvas.width = canvas.clientWidth * scale;
|
|
1861
|
-
canvas.height = canvas.clientHeight * scale;
|
|
1862
|
-
return canvas;
|
|
1863
|
-
}
|
|
1864
|
-
function createRoot(app, dom, canvas) {
|
|
1865
|
-
return React.createElement(Root, {
|
|
1866
|
-
clientWidth: dom.clientWidth,
|
|
1867
|
-
clientHeight: dom.clientHeight,
|
|
1868
|
-
deviceRatio: window.devicePixelRatio,
|
|
1869
|
-
canvas: canvas,
|
|
1870
|
-
}, app);
|
|
1871
|
-
}
|
|
1872
|
-
function initTouch(dom, handler) {
|
|
1873
|
-
dom.addEventListener('touchstart', handler, false);
|
|
1874
|
-
dom.addEventListener('touchmove', handler, false);
|
|
1875
|
-
dom.addEventListener('touchend', handler, false);
|
|
1876
|
-
dom.addEventListener('touchcancel', handler, false);
|
|
1877
|
-
return function () {
|
|
1878
|
-
dom.removeEventListener('touchstart', handler, false);
|
|
1879
|
-
dom.removeEventListener('touchmove', handler, false);
|
|
1880
|
-
dom.removeEventListener('touchend', handler, false);
|
|
1881
|
-
dom.removeEventListener('touchcancel', handler, false);
|
|
1882
|
-
};
|
|
1883
|
-
}
|
|
1884
|
-
function render(app, parent, parentComponent, callback) {
|
|
1885
|
-
if (callback === void 0) { callback = noop; }
|
|
1886
|
-
var scale = window.devicePixelRatio;
|
|
1887
|
-
var dom = createCanvas(parent, scale);
|
|
1888
|
-
var canvas = new RevasCanvas(dom.getContext('2d'));
|
|
1889
|
-
var container = new Container();
|
|
1890
|
-
var destroyTouch = initTouch(dom, function (e) { return container.handleTouch(createRevasTouchEvent(e)); });
|
|
1891
|
-
var fiber = renderer.createContainer(container, false, false);
|
|
1892
|
-
canvas.transform.scale(scale, scale);
|
|
1893
|
-
renderer.updateContainer(createRoot(app, dom, canvas), fiber, parentComponent, callback);
|
|
1894
|
-
return {
|
|
1895
|
-
get $() {
|
|
1896
|
-
return dom;
|
|
1897
|
-
},
|
|
1898
|
-
update: function (next, callback) {
|
|
1899
|
-
if (next === void 0) { next = app; }
|
|
1900
|
-
if (callback === void 0) { callback = noop; }
|
|
1901
|
-
dom.width = dom.clientWidth * scale;
|
|
1902
|
-
dom.height = dom.clientHeight * scale;
|
|
1903
|
-
clearCache();
|
|
1904
|
-
canvas.transform.scale(scale, scale);
|
|
1905
|
-
renderer.updateContainer(createRoot(next, dom, canvas), fiber, parentComponent, callback);
|
|
1906
|
-
},
|
|
1907
|
-
unmount: function (callback) {
|
|
1908
|
-
if (callback === void 0) { callback = noop; }
|
|
1909
|
-
renderer.updateContainer(null, fiber, null, callback);
|
|
1910
|
-
destroyTouch();
|
|
1911
|
-
clearCache();
|
|
1912
|
-
dom.remove();
|
|
1913
|
-
},
|
|
1914
|
-
};
|
|
1915
|
-
}
|
|
1916
|
-
|
|
1917
|
-
adapter.createOffscreenCanvas = function (width, height) {
|
|
1918
|
-
var dom = document.createElement('canvas');
|
|
1919
|
-
var scale = window.devicePixelRatio;
|
|
1920
|
-
dom.width = width * scale;
|
|
1921
|
-
dom.height = height * scale;
|
|
1922
|
-
var context = dom.getContext('2d');
|
|
1923
|
-
var canvas = new RevasCanvas(context);
|
|
1924
|
-
canvas.transform.scale(scale, scale);
|
|
1925
|
-
return canvas;
|
|
1926
|
-
};
|
|
1927
|
-
adapter.resetOffscreenCanvas = function (prev, width, height) {
|
|
1928
|
-
var context = prev.context, element = prev.element;
|
|
1929
|
-
var scale = window.devicePixelRatio;
|
|
1930
|
-
element.width = width * scale;
|
|
1931
|
-
element.height = height * scale;
|
|
1932
|
-
var canvas = new RevasCanvas(context);
|
|
1933
|
-
canvas.transform.scale(scale, scale);
|
|
1934
|
-
return canvas;
|
|
1935
|
-
};
|
|
1936
|
-
|
|
1937
|
-
exports.AnimatedInterpolate = AnimatedInterpolate;
|
|
1938
|
-
exports.AnimatedNode = AnimatedNode;
|
|
1939
|
-
exports.AnimatedTiming = AnimatedTiming;
|
|
1940
|
-
exports.AnimatedValue = AnimatedValue;
|
|
1941
|
-
exports.AppContext = AppContext;
|
|
1942
|
-
exports.Container = Container;
|
|
1943
|
-
exports.EMPTY_ARRAY = EMPTY_ARRAY;
|
|
1944
|
-
exports.EMPTY_OBJECT = EMPTY_OBJECT;
|
|
1945
|
-
exports.Easing = Easing;
|
|
1946
|
-
exports.Frame = Frame;
|
|
1947
|
-
exports.Image = ImageView;
|
|
1948
|
-
exports.LinearGradient = LinearGradient;
|
|
1949
|
-
exports.ListView = ListView;
|
|
1950
|
-
exports.Node = Node;
|
|
1951
|
-
exports.RevasCanvas = RevasCanvas;
|
|
1952
|
-
exports.Root = Root;
|
|
1953
|
-
exports.ScrollView = ScrollView;
|
|
1954
|
-
exports.Text = Text;
|
|
1955
|
-
exports.Touchable = Touchable;
|
|
1956
|
-
exports.Transform = Transform;
|
|
1957
|
-
exports.View = View;
|
|
1958
|
-
exports.adapter = adapter;
|
|
1959
|
-
exports.applyAnimated = applyAnimated;
|
|
1960
|
-
exports.clamp = clamp;
|
|
1961
|
-
exports.flatten = flatten;
|
|
1962
|
-
exports.getChars = getChars;
|
|
1963
|
-
exports.getFrameFromNode = getFrameFromNode;
|
|
1964
|
-
exports.getMergedStyleFromNode = getMergedStyleFromNode;
|
|
1965
|
-
exports.getWords = getWords;
|
|
1966
|
-
exports.noop = noop;
|
|
1967
|
-
exports.now = now;
|
|
1968
|
-
exports.pushOpacity = pushOpacity;
|
|
1969
|
-
exports.render = render;
|
|
1970
|
-
exports.renderer = renderer;
|
|
1971
|
-
exports.setShadow = setShadow;
|
|
1972
|
-
exports.sortByZIndexAscending = sortByZIndexAscending;
|
|
1973
|
-
exports.timing = timing;
|
|
1974
|
-
exports.withContext = withContext;
|
|
114
|
+
export { render };
|
|
1975
115
|
//# sourceMappingURL=revas.js.map
|
|
116
|
+
//# sourceMappingURL=revas.js.map
|