@nativescript/core 8.9.0-next-02-02-2025-13100070003 → 8.9.0-next-02-04-2025-13145148797
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/core-types/index.d.ts +3 -2
- package/core-types/index.js.map +1 -1
- package/package.json +1 -1
- package/ui/animation/animation-interfaces.d.ts +9 -4
- package/ui/animation/animation-interfaces.js.map +1 -1
- package/ui/animation/index.d.ts +1 -1
- package/ui/image/image-common.js +2 -0
- package/ui/image/image-common.js.map +1 -1
- package/ui/layouts/absolute-layout/absolute-layout-common.js +4 -2
- package/ui/layouts/absolute-layout/absolute-layout-common.js.map +1 -1
- package/ui/layouts/index.d.ts +1 -1
- package/ui/layouts/index.js +1 -1
- package/ui/layouts/index.js.map +1 -1
- package/ui/layouts/root-layout/index.android.d.ts +0 -1
- package/ui/layouts/root-layout/index.android.js +0 -3
- package/ui/layouts/root-layout/index.android.js.map +1 -1
- package/ui/layouts/root-layout/index.d.ts +1 -0
- package/ui/layouts/root-layout/index.ios.d.ts +2 -1
- package/ui/layouts/root-layout/index.ios.js +7 -2
- package/ui/layouts/root-layout/index.ios.js.map +1 -1
- package/ui/layouts/root-layout/root-layout-common.d.ts +12 -5
- package/ui/layouts/root-layout/root-layout-common.js +77 -52
- package/ui/layouts/root-layout/root-layout-common.js.map +1 -1
- package/ui/layouts/root-layout/root-layout-stack.d.ts +5 -0
- package/ui/layouts/root-layout/root-layout-stack.js +19 -0
- package/ui/layouts/root-layout/root-layout-stack.js.map +1 -0
- package/ui/layouts/wrap-layout/wrap-layout-common.js +4 -2
- package/ui/layouts/wrap-layout/wrap-layout-common.js.map +1 -1
- package/ui/list-view/index.ios.js +1 -1
- package/ui/list-view/index.ios.js.map +1 -1
- package/ui/list-view/list-view-common.js +2 -1
- package/ui/list-view/list-view-common.js.map +1 -1
- package/ui/styling/background-common.d.ts +3 -2
- package/ui/styling/background-common.js +13 -5
- package/ui/styling/background-common.js.map +1 -1
- package/ui/styling/background.android.js +2 -1
- package/ui/styling/background.android.js.map +1 -1
- package/ui/styling/background.d.ts +9 -8
- package/ui/styling/background.ios.js +22 -18
- package/ui/styling/background.ios.js.map +1 -1
- package/ui/styling/clip-path-function.d.ts +16 -0
- package/ui/styling/clip-path-function.js +25 -0
- package/ui/styling/clip-path-function.js.map +1 -0
- package/ui/styling/css-animation-parser.js +1 -1
- package/ui/styling/css-animation-parser.js.map +1 -1
- package/ui/styling/css-transform.d.ts +2 -0
- package/ui/styling/css-transform.js +110 -0
- package/ui/styling/css-transform.js.map +1 -0
- package/ui/styling/style/index.d.ts +2 -1
- package/ui/styling/style/index.js.map +1 -1
- package/ui/styling/style-properties.d.ts +17 -7
- package/ui/styling/style-properties.js +235 -368
- package/ui/styling/style-properties.js.map +1 -1
|
@@ -1,50 +1,42 @@
|
|
|
1
|
-
// Types
|
|
2
1
|
import { unsetValue, CssProperty, CssAnimationProperty, ShorthandProperty, InheritedCssProperty } from '../core/properties';
|
|
3
2
|
import { Style } from './style';
|
|
4
3
|
import { Color } from '../../color';
|
|
5
4
|
import { Font, parseFont, FontStyle, FontWeight, FontVariationSettings } from './font';
|
|
6
5
|
import { Background } from './background';
|
|
7
|
-
import { layout
|
|
8
|
-
import { radiansToDegrees } from '../../utils/number-utils';
|
|
9
|
-
import { decompose2DTransformMatrix, getTransformMatrix, matrixArrayToCssMatrix, multiplyAffine2d } from '../../matrix';
|
|
6
|
+
import { layout } from '../../utils';
|
|
10
7
|
import { Trace } from '../../trace';
|
|
11
8
|
import { CoreTypes } from '../../core-types';
|
|
12
9
|
import { parseBackground } from '../../css/parser';
|
|
13
10
|
import { LinearGradient } from './linear-gradient';
|
|
14
11
|
import { parseCSSShadow } from './css-shadow';
|
|
12
|
+
import { transformConverter } from './css-transform';
|
|
13
|
+
import { ClipPathFunction } from './clip-path-function';
|
|
15
14
|
function equalsCommon(a, b) {
|
|
16
15
|
if (a == 'auto') {
|
|
17
|
-
|
|
18
|
-
|
|
16
|
+
return b == 'auto';
|
|
17
|
+
}
|
|
18
|
+
if (b == 'auto') {
|
|
19
|
+
return false;
|
|
19
20
|
}
|
|
20
21
|
if (typeof a === 'number') {
|
|
21
|
-
if (b == 'auto') {
|
|
22
|
-
// tslint:disable-line
|
|
23
|
-
return false;
|
|
24
|
-
}
|
|
25
22
|
if (typeof b === 'number') {
|
|
26
|
-
return a == b;
|
|
23
|
+
return a == b;
|
|
27
24
|
}
|
|
28
25
|
if (!b) {
|
|
29
26
|
return false;
|
|
30
27
|
}
|
|
31
|
-
return b.unit == 'dip' && a == b.value;
|
|
32
|
-
}
|
|
33
|
-
if (b == 'auto') {
|
|
34
|
-
// tslint:disable-line
|
|
35
|
-
return false;
|
|
28
|
+
return b.unit == 'dip' && a == b.value;
|
|
36
29
|
}
|
|
37
30
|
if (typeof b === 'number') {
|
|
38
|
-
return a ? a.unit == 'dip' && a.value == b : false;
|
|
31
|
+
return a ? a.unit == 'dip' && a.value == b : false;
|
|
39
32
|
}
|
|
40
33
|
if (!a || !b) {
|
|
41
34
|
return false;
|
|
42
35
|
}
|
|
43
|
-
return a.value == b.value && a.unit == b.unit;
|
|
36
|
+
return a.value == b.value && a.unit == b.unit;
|
|
44
37
|
}
|
|
45
38
|
function convertToStringCommon(length) {
|
|
46
39
|
if (length == 'auto') {
|
|
47
|
-
// tslint:disable-line
|
|
48
40
|
return 'auto';
|
|
49
41
|
}
|
|
50
42
|
if (typeof length === 'number') {
|
|
@@ -58,7 +50,6 @@ function convertToStringCommon(length) {
|
|
|
58
50
|
}
|
|
59
51
|
function toDevicePixelsCommon(length, auto = Number.NaN, parentAvailableWidth = Number.NaN) {
|
|
60
52
|
if (length == 'auto') {
|
|
61
|
-
// tslint:disable-line
|
|
62
53
|
return auto;
|
|
63
54
|
}
|
|
64
55
|
if (typeof length === 'number') {
|
|
@@ -81,7 +72,6 @@ export var PercentLength;
|
|
|
81
72
|
(function (PercentLength) {
|
|
82
73
|
function parse(fromValue) {
|
|
83
74
|
if (fromValue == 'auto') {
|
|
84
|
-
// tslint:disable-line
|
|
85
75
|
return 'auto';
|
|
86
76
|
}
|
|
87
77
|
if (typeof fromValue === 'string') {
|
|
@@ -127,13 +117,9 @@ export var PercentLength;
|
|
|
127
117
|
PercentLength.toDevicePixels = toDevicePixelsCommon;
|
|
128
118
|
PercentLength.convertToString = convertToStringCommon;
|
|
129
119
|
})(PercentLength || (PercentLength = {}));
|
|
130
|
-
export var
|
|
131
|
-
(function (
|
|
120
|
+
export var FixedLength;
|
|
121
|
+
(function (FixedLength) {
|
|
132
122
|
function parse(fromValue) {
|
|
133
|
-
if (fromValue == 'auto') {
|
|
134
|
-
// tslint:disable-line
|
|
135
|
-
return 'auto';
|
|
136
|
-
}
|
|
137
123
|
if (typeof fromValue === 'string') {
|
|
138
124
|
let stringValue = fromValue.trim();
|
|
139
125
|
if (stringValue.indexOf('px') !== -1) {
|
|
@@ -156,11 +142,188 @@ export var Length;
|
|
|
156
142
|
return fromValue;
|
|
157
143
|
}
|
|
158
144
|
}
|
|
145
|
+
FixedLength.parse = parse;
|
|
146
|
+
FixedLength.equals = equalsCommon;
|
|
147
|
+
FixedLength.toDevicePixels = toDevicePixelsCommon;
|
|
148
|
+
FixedLength.convertToString = convertToStringCommon;
|
|
149
|
+
})(FixedLength || (FixedLength = {}));
|
|
150
|
+
export var Length;
|
|
151
|
+
(function (Length) {
|
|
152
|
+
function parse(fromValue) {
|
|
153
|
+
if (fromValue == 'auto') {
|
|
154
|
+
return 'auto';
|
|
155
|
+
}
|
|
156
|
+
return FixedLength.parse(fromValue);
|
|
157
|
+
}
|
|
159
158
|
Length.parse = parse;
|
|
160
159
|
Length.equals = equalsCommon;
|
|
161
160
|
Length.toDevicePixels = toDevicePixelsCommon;
|
|
162
161
|
Length.convertToString = convertToStringCommon;
|
|
163
162
|
})(Length || (Length = {}));
|
|
163
|
+
function isNonNegativeFiniteNumber(value) {
|
|
164
|
+
return isFinite(value) && !isNaN(value) && value >= 0;
|
|
165
|
+
}
|
|
166
|
+
function parseClipPath(value) {
|
|
167
|
+
const functionStartIndex = value.indexOf('(');
|
|
168
|
+
if (functionStartIndex > -1) {
|
|
169
|
+
const functionName = value.substring(0, functionStartIndex).trim();
|
|
170
|
+
switch (functionName) {
|
|
171
|
+
case 'rect':
|
|
172
|
+
case 'circle':
|
|
173
|
+
case 'ellipse':
|
|
174
|
+
case 'polygon':
|
|
175
|
+
case 'inset': {
|
|
176
|
+
const rule = value.replace(`${functionName}(`, '').replace(')', '');
|
|
177
|
+
return new ClipPathFunction(functionName, rule);
|
|
178
|
+
}
|
|
179
|
+
default:
|
|
180
|
+
throw new Error(`Clip-path function ${functionName} is not valid.`);
|
|
181
|
+
}
|
|
182
|
+
}
|
|
183
|
+
else {
|
|
184
|
+
if (value === 'none') {
|
|
185
|
+
return null;
|
|
186
|
+
}
|
|
187
|
+
// Only shape functions and none are supported for now
|
|
188
|
+
throw new Error(`Clip-path value ${value} is not valid.`);
|
|
189
|
+
}
|
|
190
|
+
}
|
|
191
|
+
function parseShorthandPositioning(value) {
|
|
192
|
+
const arr = value.split(/[ ,]+/);
|
|
193
|
+
let top;
|
|
194
|
+
let right;
|
|
195
|
+
let bottom;
|
|
196
|
+
let left;
|
|
197
|
+
if (arr.length === 1) {
|
|
198
|
+
top = arr[0];
|
|
199
|
+
right = arr[0];
|
|
200
|
+
bottom = arr[0];
|
|
201
|
+
left = arr[0];
|
|
202
|
+
}
|
|
203
|
+
else if (arr.length === 2) {
|
|
204
|
+
top = arr[0];
|
|
205
|
+
bottom = arr[0];
|
|
206
|
+
right = arr[1];
|
|
207
|
+
left = arr[1];
|
|
208
|
+
}
|
|
209
|
+
else if (arr.length === 3) {
|
|
210
|
+
top = arr[0];
|
|
211
|
+
right = arr[1];
|
|
212
|
+
left = arr[1];
|
|
213
|
+
bottom = arr[2];
|
|
214
|
+
}
|
|
215
|
+
else if (arr.length === 4) {
|
|
216
|
+
top = arr[0];
|
|
217
|
+
right = arr[1];
|
|
218
|
+
bottom = arr[2];
|
|
219
|
+
left = arr[3];
|
|
220
|
+
}
|
|
221
|
+
else {
|
|
222
|
+
throw new Error('Expected 1, 2, 3 or 4 parameters. Actual: ' + value);
|
|
223
|
+
}
|
|
224
|
+
return {
|
|
225
|
+
top: top,
|
|
226
|
+
right: right,
|
|
227
|
+
bottom: bottom,
|
|
228
|
+
left: left,
|
|
229
|
+
};
|
|
230
|
+
}
|
|
231
|
+
function parseBorderColorPositioning(value) {
|
|
232
|
+
if (value.indexOf('rgb') === 0 || value.indexOf('hsl') === 0) {
|
|
233
|
+
return {
|
|
234
|
+
top: value,
|
|
235
|
+
right: value,
|
|
236
|
+
bottom: value,
|
|
237
|
+
left: value,
|
|
238
|
+
};
|
|
239
|
+
}
|
|
240
|
+
return parseShorthandPositioning(value);
|
|
241
|
+
}
|
|
242
|
+
function convertToBackgrounds(value) {
|
|
243
|
+
if (typeof value === 'string') {
|
|
244
|
+
const backgrounds = parseBackground(value).value;
|
|
245
|
+
let backgroundColor = unsetValue;
|
|
246
|
+
if (backgrounds.color) {
|
|
247
|
+
backgroundColor = backgrounds.color instanceof Color ? backgrounds.color : new Color(backgrounds.color);
|
|
248
|
+
}
|
|
249
|
+
let backgroundImage;
|
|
250
|
+
if (typeof backgrounds.image === 'object' && backgrounds.image) {
|
|
251
|
+
backgroundImage = LinearGradient.parse(backgrounds.image);
|
|
252
|
+
}
|
|
253
|
+
else {
|
|
254
|
+
backgroundImage = backgrounds.image || unsetValue;
|
|
255
|
+
}
|
|
256
|
+
const backgroundRepeat = backgrounds.repeat || unsetValue;
|
|
257
|
+
const backgroundPosition = backgrounds.position ? backgrounds.position.text : unsetValue;
|
|
258
|
+
return [
|
|
259
|
+
[backgroundColorProperty, backgroundColor],
|
|
260
|
+
[backgroundImageProperty, backgroundImage],
|
|
261
|
+
[backgroundRepeatProperty, backgroundRepeat],
|
|
262
|
+
[backgroundPositionProperty, backgroundPosition],
|
|
263
|
+
];
|
|
264
|
+
}
|
|
265
|
+
else {
|
|
266
|
+
return [
|
|
267
|
+
[backgroundColorProperty, unsetValue],
|
|
268
|
+
[backgroundImageProperty, unsetValue],
|
|
269
|
+
[backgroundRepeatProperty, unsetValue],
|
|
270
|
+
[backgroundPositionProperty, unsetValue],
|
|
271
|
+
];
|
|
272
|
+
}
|
|
273
|
+
}
|
|
274
|
+
function convertToMargins(value) {
|
|
275
|
+
if (typeof value === 'string' && value !== 'auto') {
|
|
276
|
+
const thickness = parseShorthandPositioning(value);
|
|
277
|
+
return [
|
|
278
|
+
[marginTopProperty, PercentLength.parse(thickness.top)],
|
|
279
|
+
[marginRightProperty, PercentLength.parse(thickness.right)],
|
|
280
|
+
[marginBottomProperty, PercentLength.parse(thickness.bottom)],
|
|
281
|
+
[marginLeftProperty, PercentLength.parse(thickness.left)],
|
|
282
|
+
];
|
|
283
|
+
}
|
|
284
|
+
else {
|
|
285
|
+
return [
|
|
286
|
+
[marginTopProperty, value],
|
|
287
|
+
[marginRightProperty, value],
|
|
288
|
+
[marginBottomProperty, value],
|
|
289
|
+
[marginLeftProperty, value],
|
|
290
|
+
];
|
|
291
|
+
}
|
|
292
|
+
}
|
|
293
|
+
function convertToPaddings(value) {
|
|
294
|
+
if (typeof value === 'string' && value !== 'auto') {
|
|
295
|
+
const thickness = parseShorthandPositioning(value);
|
|
296
|
+
return [
|
|
297
|
+
[paddingTopProperty, Length.parse(thickness.top)],
|
|
298
|
+
[paddingRightProperty, Length.parse(thickness.right)],
|
|
299
|
+
[paddingBottomProperty, Length.parse(thickness.bottom)],
|
|
300
|
+
[paddingLeftProperty, Length.parse(thickness.left)],
|
|
301
|
+
];
|
|
302
|
+
}
|
|
303
|
+
else {
|
|
304
|
+
return [
|
|
305
|
+
[paddingTopProperty, value],
|
|
306
|
+
[paddingRightProperty, value],
|
|
307
|
+
[paddingBottomProperty, value],
|
|
308
|
+
[paddingLeftProperty, value],
|
|
309
|
+
];
|
|
310
|
+
}
|
|
311
|
+
}
|
|
312
|
+
function convertToTransform(value) {
|
|
313
|
+
if (value === unsetValue) {
|
|
314
|
+
value = 'none';
|
|
315
|
+
}
|
|
316
|
+
const { translate, rotate, scale } = transformConverter(value);
|
|
317
|
+
return [
|
|
318
|
+
[translateXProperty, translate.x],
|
|
319
|
+
[translateYProperty, translate.y],
|
|
320
|
+
[scaleXProperty, scale.x],
|
|
321
|
+
[scaleYProperty, scale.y],
|
|
322
|
+
[rotateProperty, rotate.z],
|
|
323
|
+
[rotateXProperty, rotate.x],
|
|
324
|
+
[rotateYProperty, rotate.y],
|
|
325
|
+
];
|
|
326
|
+
}
|
|
164
327
|
export const minWidthProperty = new CssProperty({
|
|
165
328
|
name: 'minWidth',
|
|
166
329
|
cssName: 'min-width',
|
|
@@ -381,89 +544,6 @@ export const verticalAlignmentProperty = new CssProperty({
|
|
|
381
544
|
valueConverter: CoreTypes.VerticalAlignmentText.parse,
|
|
382
545
|
});
|
|
383
546
|
verticalAlignmentProperty.register(Style);
|
|
384
|
-
function parseThickness(value) {
|
|
385
|
-
if (typeof value === 'string') {
|
|
386
|
-
const arr = value.split(/[ ,]+/);
|
|
387
|
-
let top;
|
|
388
|
-
let right;
|
|
389
|
-
let bottom;
|
|
390
|
-
let left;
|
|
391
|
-
if (arr.length === 1) {
|
|
392
|
-
top = arr[0];
|
|
393
|
-
right = arr[0];
|
|
394
|
-
bottom = arr[0];
|
|
395
|
-
left = arr[0];
|
|
396
|
-
}
|
|
397
|
-
else if (arr.length === 2) {
|
|
398
|
-
top = arr[0];
|
|
399
|
-
bottom = arr[0];
|
|
400
|
-
right = arr[1];
|
|
401
|
-
left = arr[1];
|
|
402
|
-
}
|
|
403
|
-
else if (arr.length === 3) {
|
|
404
|
-
top = arr[0];
|
|
405
|
-
right = arr[1];
|
|
406
|
-
left = arr[1];
|
|
407
|
-
bottom = arr[2];
|
|
408
|
-
}
|
|
409
|
-
else if (arr.length === 4) {
|
|
410
|
-
top = arr[0];
|
|
411
|
-
right = arr[1];
|
|
412
|
-
bottom = arr[2];
|
|
413
|
-
left = arr[3];
|
|
414
|
-
}
|
|
415
|
-
else {
|
|
416
|
-
throw new Error('Expected 1, 2, 3 or 4 parameters. Actual: ' + value);
|
|
417
|
-
}
|
|
418
|
-
return {
|
|
419
|
-
top: top,
|
|
420
|
-
right: right,
|
|
421
|
-
bottom: bottom,
|
|
422
|
-
left: left,
|
|
423
|
-
};
|
|
424
|
-
}
|
|
425
|
-
else {
|
|
426
|
-
return value;
|
|
427
|
-
}
|
|
428
|
-
}
|
|
429
|
-
function convertToMargins(value) {
|
|
430
|
-
if (typeof value === 'string' && value !== 'auto') {
|
|
431
|
-
const thickness = parseThickness(value);
|
|
432
|
-
return [
|
|
433
|
-
[marginTopProperty, PercentLength.parse(thickness.top)],
|
|
434
|
-
[marginRightProperty, PercentLength.parse(thickness.right)],
|
|
435
|
-
[marginBottomProperty, PercentLength.parse(thickness.bottom)],
|
|
436
|
-
[marginLeftProperty, PercentLength.parse(thickness.left)],
|
|
437
|
-
];
|
|
438
|
-
}
|
|
439
|
-
else {
|
|
440
|
-
return [
|
|
441
|
-
[marginTopProperty, value],
|
|
442
|
-
[marginRightProperty, value],
|
|
443
|
-
[marginBottomProperty, value],
|
|
444
|
-
[marginLeftProperty, value],
|
|
445
|
-
];
|
|
446
|
-
}
|
|
447
|
-
}
|
|
448
|
-
function convertToPaddings(value) {
|
|
449
|
-
if (typeof value === 'string' && value !== 'auto') {
|
|
450
|
-
const thickness = parseThickness(value);
|
|
451
|
-
return [
|
|
452
|
-
[paddingTopProperty, Length.parse(thickness.top)],
|
|
453
|
-
[paddingRightProperty, Length.parse(thickness.right)],
|
|
454
|
-
[paddingBottomProperty, Length.parse(thickness.bottom)],
|
|
455
|
-
[paddingLeftProperty, Length.parse(thickness.left)],
|
|
456
|
-
];
|
|
457
|
-
}
|
|
458
|
-
else {
|
|
459
|
-
return [
|
|
460
|
-
[paddingTopProperty, value],
|
|
461
|
-
[paddingRightProperty, value],
|
|
462
|
-
[paddingBottomProperty, value],
|
|
463
|
-
[paddingLeftProperty, value],
|
|
464
|
-
];
|
|
465
|
-
}
|
|
466
|
-
}
|
|
467
547
|
export const rotateProperty = new CssAnimationProperty({
|
|
468
548
|
name: 'rotate',
|
|
469
549
|
cssName: 'rotate',
|
|
@@ -506,26 +586,20 @@ export const scaleYProperty = new CssAnimationProperty({
|
|
|
506
586
|
valueConverter: parseFloat,
|
|
507
587
|
});
|
|
508
588
|
scaleYProperty.register(Style);
|
|
509
|
-
function parseDIPs(value) {
|
|
510
|
-
if (value.indexOf('px') !== -1) {
|
|
511
|
-
return layout.toDeviceIndependentPixels(parseFloat(value.replace('px', '').trim()));
|
|
512
|
-
}
|
|
513
|
-
else {
|
|
514
|
-
return parseFloat(value.replace('dip', '').trim());
|
|
515
|
-
}
|
|
516
|
-
}
|
|
517
589
|
export const translateXProperty = new CssAnimationProperty({
|
|
518
590
|
name: 'translateX',
|
|
519
591
|
cssName: 'translateX',
|
|
520
592
|
defaultValue: 0,
|
|
521
|
-
|
|
593
|
+
equalityComparer: FixedLength.equals,
|
|
594
|
+
valueConverter: FixedLength.parse,
|
|
522
595
|
});
|
|
523
596
|
translateXProperty.register(Style);
|
|
524
597
|
export const translateYProperty = new CssAnimationProperty({
|
|
525
598
|
name: 'translateY',
|
|
526
599
|
cssName: 'translateY',
|
|
527
600
|
defaultValue: 0,
|
|
528
|
-
|
|
601
|
+
equalityComparer: FixedLength.equals,
|
|
602
|
+
valueConverter: FixedLength.parse,
|
|
529
603
|
});
|
|
530
604
|
translateYProperty.register(Style);
|
|
531
605
|
const transformProperty = new ShorthandProperty({
|
|
@@ -555,125 +629,6 @@ const transformProperty = new ShorthandProperty({
|
|
|
555
629
|
converter: convertToTransform,
|
|
556
630
|
});
|
|
557
631
|
transformProperty.register(Style);
|
|
558
|
-
const IDENTITY_TRANSFORMATION = {
|
|
559
|
-
translate: { x: 0, y: 0 },
|
|
560
|
-
rotate: { x: 0, y: 0, z: 0 },
|
|
561
|
-
scale: { x: 1, y: 1 },
|
|
562
|
-
};
|
|
563
|
-
const TRANSFORM_SPLITTER = new RegExp(/\s*(.+?)\((.*?)\)/g);
|
|
564
|
-
const TRANSFORMATIONS = Object.freeze(['rotate', 'rotateX', 'rotateY', 'rotate3d', 'translate', 'translate3d', 'translateX', 'translateY', 'scale', 'scale3d', 'scaleX', 'scaleY']);
|
|
565
|
-
const STYLE_TRANSFORMATION_MAP = Object.freeze({
|
|
566
|
-
scale: (value) => ({ property: 'scale', value }),
|
|
567
|
-
scale3d: (value) => ({ property: 'scale', value }),
|
|
568
|
-
scaleX: ({ x }) => ({
|
|
569
|
-
property: 'scale',
|
|
570
|
-
value: { x, y: IDENTITY_TRANSFORMATION.scale.y },
|
|
571
|
-
}),
|
|
572
|
-
scaleY: ({ y }) => ({
|
|
573
|
-
property: 'scale',
|
|
574
|
-
value: { y, x: IDENTITY_TRANSFORMATION.scale.x },
|
|
575
|
-
}),
|
|
576
|
-
translate: (value) => ({ property: 'translate', value }),
|
|
577
|
-
translate3d: (value) => ({ property: 'translate', value }),
|
|
578
|
-
translateX: ({ x }) => ({
|
|
579
|
-
property: 'translate',
|
|
580
|
-
value: { x, y: IDENTITY_TRANSFORMATION.translate.y },
|
|
581
|
-
}),
|
|
582
|
-
translateY: ({ y }) => ({
|
|
583
|
-
property: 'translate',
|
|
584
|
-
value: { y, x: IDENTITY_TRANSFORMATION.translate.x },
|
|
585
|
-
}),
|
|
586
|
-
rotate3d: (value) => ({ property: 'rotate', value }),
|
|
587
|
-
rotateX: (x) => ({
|
|
588
|
-
property: 'rotate',
|
|
589
|
-
value: {
|
|
590
|
-
x,
|
|
591
|
-
y: IDENTITY_TRANSFORMATION.rotate.y,
|
|
592
|
-
z: IDENTITY_TRANSFORMATION.rotate.z,
|
|
593
|
-
},
|
|
594
|
-
}),
|
|
595
|
-
rotateY: (y) => ({
|
|
596
|
-
property: 'rotate',
|
|
597
|
-
value: {
|
|
598
|
-
x: IDENTITY_TRANSFORMATION.rotate.x,
|
|
599
|
-
y,
|
|
600
|
-
z: IDENTITY_TRANSFORMATION.rotate.z,
|
|
601
|
-
},
|
|
602
|
-
}),
|
|
603
|
-
rotate: (z) => ({
|
|
604
|
-
property: 'rotate',
|
|
605
|
-
value: {
|
|
606
|
-
x: IDENTITY_TRANSFORMATION.rotate.x,
|
|
607
|
-
y: IDENTITY_TRANSFORMATION.rotate.y,
|
|
608
|
-
z,
|
|
609
|
-
},
|
|
610
|
-
}),
|
|
611
|
-
});
|
|
612
|
-
function convertToTransform(value) {
|
|
613
|
-
if (value === unsetValue) {
|
|
614
|
-
value = 'none';
|
|
615
|
-
}
|
|
616
|
-
const { translate, rotate, scale } = transformConverter(value);
|
|
617
|
-
return [
|
|
618
|
-
[translateXProperty, translate.x],
|
|
619
|
-
[translateYProperty, translate.y],
|
|
620
|
-
[scaleXProperty, scale.x],
|
|
621
|
-
[scaleYProperty, scale.y],
|
|
622
|
-
[rotateProperty, rotate.z],
|
|
623
|
-
[rotateXProperty, rotate.x],
|
|
624
|
-
[rotateYProperty, rotate.y],
|
|
625
|
-
];
|
|
626
|
-
}
|
|
627
|
-
export function transformConverter(text) {
|
|
628
|
-
const transformations = parseTransformString(text);
|
|
629
|
-
if (text === 'none' || text === '' || !transformations.length) {
|
|
630
|
-
return IDENTITY_TRANSFORMATION;
|
|
631
|
-
}
|
|
632
|
-
const usedTransforms = transformations.map((t) => t.property);
|
|
633
|
-
if (!hasDuplicates(usedTransforms)) {
|
|
634
|
-
const fullTransformations = { ...IDENTITY_TRANSFORMATION };
|
|
635
|
-
transformations.forEach((transform) => {
|
|
636
|
-
fullTransformations[transform.property] = transform.value;
|
|
637
|
-
});
|
|
638
|
-
return fullTransformations;
|
|
639
|
-
}
|
|
640
|
-
const affineMatrix = transformations.map(getTransformMatrix).reduce(multiplyAffine2d);
|
|
641
|
-
const cssMatrix = matrixArrayToCssMatrix(affineMatrix);
|
|
642
|
-
return decompose2DTransformMatrix(cssMatrix);
|
|
643
|
-
}
|
|
644
|
-
// using general regex and manually checking the matched
|
|
645
|
-
// properties is faster than using more specific regex
|
|
646
|
-
// https://jsperf.com/cssparse
|
|
647
|
-
function parseTransformString(text) {
|
|
648
|
-
const matches = [];
|
|
649
|
-
let match;
|
|
650
|
-
while ((match = TRANSFORM_SPLITTER.exec(text)) !== null) {
|
|
651
|
-
const property = match[1];
|
|
652
|
-
const value = convertTransformValue(property, match[2]);
|
|
653
|
-
if (TRANSFORMATIONS.indexOf(property) !== -1) {
|
|
654
|
-
matches.push(normalizeTransformation({ property, value }));
|
|
655
|
-
}
|
|
656
|
-
}
|
|
657
|
-
return matches;
|
|
658
|
-
}
|
|
659
|
-
function normalizeTransformation({ property, value }) {
|
|
660
|
-
return STYLE_TRANSFORMATION_MAP[property](value);
|
|
661
|
-
}
|
|
662
|
-
function convertTransformValue(property, stringValue) {
|
|
663
|
-
// eslint-disable-next-line prefer-const
|
|
664
|
-
let [x, y, z] = stringValue.split(',').map(parseFloat);
|
|
665
|
-
if (property === 'translate') {
|
|
666
|
-
y ?? (y = IDENTITY_TRANSFORMATION.translate.y);
|
|
667
|
-
}
|
|
668
|
-
else {
|
|
669
|
-
y ?? (y = x);
|
|
670
|
-
z ?? (z = y);
|
|
671
|
-
}
|
|
672
|
-
if (property === 'rotate' || property === 'rotateX' || property === 'rotateY') {
|
|
673
|
-
return stringValue.slice(-3) === 'rad' ? radiansToDegrees(x) : x;
|
|
674
|
-
}
|
|
675
|
-
return { x, y, z };
|
|
676
|
-
}
|
|
677
632
|
// Background properties.
|
|
678
633
|
const backgroundProperty = new ShorthandProperty({
|
|
679
634
|
name: 'background',
|
|
@@ -690,7 +645,6 @@ export const backgroundInternalProperty = new CssProperty({
|
|
|
690
645
|
defaultValue: Background.default,
|
|
691
646
|
});
|
|
692
647
|
backgroundInternalProperty.register(Style);
|
|
693
|
-
// const pattern: RegExp = /url\(('|")(.*?)\1\)/;
|
|
694
648
|
export const backgroundImageProperty = new CssProperty({
|
|
695
649
|
name: 'backgroundImage',
|
|
696
650
|
cssName: 'background-image',
|
|
@@ -751,89 +705,6 @@ export const backgroundPositionProperty = new CssProperty({
|
|
|
751
705
|
},
|
|
752
706
|
});
|
|
753
707
|
backgroundPositionProperty.register(Style);
|
|
754
|
-
function convertToBackgrounds(value) {
|
|
755
|
-
if (typeof value === 'string') {
|
|
756
|
-
const backgrounds = parseBackground(value).value;
|
|
757
|
-
let backgroundColor = unsetValue;
|
|
758
|
-
if (backgrounds.color) {
|
|
759
|
-
backgroundColor = backgrounds.color instanceof Color ? backgrounds.color : new Color(backgrounds.color);
|
|
760
|
-
}
|
|
761
|
-
let backgroundImage;
|
|
762
|
-
if (typeof backgrounds.image === 'object' && backgrounds.image) {
|
|
763
|
-
backgroundImage = LinearGradient.parse(backgrounds.image);
|
|
764
|
-
}
|
|
765
|
-
else {
|
|
766
|
-
backgroundImage = backgrounds.image || unsetValue;
|
|
767
|
-
}
|
|
768
|
-
const backgroundRepeat = backgrounds.repeat || unsetValue;
|
|
769
|
-
const backgroundPosition = backgrounds.position ? backgrounds.position.text : unsetValue;
|
|
770
|
-
return [
|
|
771
|
-
[backgroundColorProperty, backgroundColor],
|
|
772
|
-
[backgroundImageProperty, backgroundImage],
|
|
773
|
-
[backgroundRepeatProperty, backgroundRepeat],
|
|
774
|
-
[backgroundPositionProperty, backgroundPosition],
|
|
775
|
-
];
|
|
776
|
-
}
|
|
777
|
-
else {
|
|
778
|
-
return [
|
|
779
|
-
[backgroundColorProperty, unsetValue],
|
|
780
|
-
[backgroundImageProperty, unsetValue],
|
|
781
|
-
[backgroundRepeatProperty, unsetValue],
|
|
782
|
-
[backgroundPositionProperty, unsetValue],
|
|
783
|
-
];
|
|
784
|
-
}
|
|
785
|
-
}
|
|
786
|
-
function parseBorderColor(value) {
|
|
787
|
-
const result = {
|
|
788
|
-
top: undefined,
|
|
789
|
-
right: undefined,
|
|
790
|
-
bottom: undefined,
|
|
791
|
-
left: undefined,
|
|
792
|
-
};
|
|
793
|
-
if (value.indexOf('rgb') === 0 || value.indexOf('hsl') === 0) {
|
|
794
|
-
result.top = result.right = result.bottom = result.left = new Color(value);
|
|
795
|
-
return result;
|
|
796
|
-
}
|
|
797
|
-
const arr = value.split(/[ ,]+/);
|
|
798
|
-
if (arr.length === 1) {
|
|
799
|
-
const arr0 = new Color(arr[0]);
|
|
800
|
-
result.top = arr0;
|
|
801
|
-
result.right = arr0;
|
|
802
|
-
result.bottom = arr0;
|
|
803
|
-
result.left = arr0;
|
|
804
|
-
}
|
|
805
|
-
else if (arr.length === 2) {
|
|
806
|
-
const arr0 = new Color(arr[0]);
|
|
807
|
-
const arr1 = new Color(arr[1]);
|
|
808
|
-
result.top = arr0;
|
|
809
|
-
result.right = arr1;
|
|
810
|
-
result.bottom = arr0;
|
|
811
|
-
result.left = arr1;
|
|
812
|
-
}
|
|
813
|
-
else if (arr.length === 3) {
|
|
814
|
-
const arr0 = new Color(arr[0]);
|
|
815
|
-
const arr1 = new Color(arr[1]);
|
|
816
|
-
const arr2 = new Color(arr[2]);
|
|
817
|
-
result.top = arr0;
|
|
818
|
-
result.right = arr1;
|
|
819
|
-
result.bottom = arr2;
|
|
820
|
-
result.left = arr1;
|
|
821
|
-
}
|
|
822
|
-
else if (arr.length === 4) {
|
|
823
|
-
const arr0 = new Color(arr[0]);
|
|
824
|
-
const arr1 = new Color(arr[1]);
|
|
825
|
-
const arr2 = new Color(arr[2]);
|
|
826
|
-
const arr3 = new Color(arr[3]);
|
|
827
|
-
result.top = arr0;
|
|
828
|
-
result.right = arr1;
|
|
829
|
-
result.bottom = arr2;
|
|
830
|
-
result.left = arr3;
|
|
831
|
-
}
|
|
832
|
-
else {
|
|
833
|
-
throw new Error(`Expected 1, 2, 3 or 4 parameters. Actual: ${value}`);
|
|
834
|
-
}
|
|
835
|
-
return result;
|
|
836
|
-
}
|
|
837
708
|
// Border Color properties.
|
|
838
709
|
const borderColorProperty = new ShorthandProperty({
|
|
839
710
|
name: 'borderColor',
|
|
@@ -848,12 +719,12 @@ const borderColorProperty = new ShorthandProperty({
|
|
|
848
719
|
},
|
|
849
720
|
converter: function (value) {
|
|
850
721
|
if (typeof value === 'string') {
|
|
851
|
-
const
|
|
722
|
+
const colors = parseBorderColorPositioning(value);
|
|
852
723
|
return [
|
|
853
|
-
[borderTopColorProperty,
|
|
854
|
-
[borderRightColorProperty,
|
|
855
|
-
[borderBottomColorProperty,
|
|
856
|
-
[borderLeftColorProperty,
|
|
724
|
+
[borderTopColorProperty, new Color(colors.top)],
|
|
725
|
+
[borderRightColorProperty, new Color(colors.right)],
|
|
726
|
+
[borderBottomColorProperty, new Color(colors.bottom)],
|
|
727
|
+
[borderLeftColorProperty, new Color(colors.left)],
|
|
857
728
|
];
|
|
858
729
|
}
|
|
859
730
|
else {
|
|
@@ -921,12 +792,12 @@ const borderWidthProperty = new ShorthandProperty({
|
|
|
921
792
|
},
|
|
922
793
|
converter: function (value) {
|
|
923
794
|
if (typeof value === 'string' && value !== 'auto') {
|
|
924
|
-
const borderWidths =
|
|
795
|
+
const borderWidths = parseShorthandPositioning(value);
|
|
925
796
|
return [
|
|
926
|
-
[borderTopWidthProperty, borderWidths.top],
|
|
927
|
-
[borderRightWidthProperty, borderWidths.right],
|
|
928
|
-
[borderBottomWidthProperty, borderWidths.bottom],
|
|
929
|
-
[borderLeftWidthProperty, borderWidths.left],
|
|
797
|
+
[borderTopWidthProperty, Length.parse(borderWidths.top)],
|
|
798
|
+
[borderRightWidthProperty, Length.parse(borderWidths.right)],
|
|
799
|
+
[borderBottomWidthProperty, Length.parse(borderWidths.bottom)],
|
|
800
|
+
[borderLeftWidthProperty, Length.parse(borderWidths.left)],
|
|
930
801
|
];
|
|
931
802
|
}
|
|
932
803
|
else {
|
|
@@ -1044,12 +915,12 @@ const borderRadiusProperty = new ShorthandProperty({
|
|
|
1044
915
|
},
|
|
1045
916
|
converter: function (value) {
|
|
1046
917
|
if (typeof value === 'string') {
|
|
1047
|
-
const borderRadius =
|
|
918
|
+
const borderRadius = parseShorthandPositioning(value);
|
|
1048
919
|
return [
|
|
1049
|
-
[borderTopLeftRadiusProperty, borderRadius.top],
|
|
1050
|
-
[borderTopRightRadiusProperty, borderRadius.right],
|
|
1051
|
-
[borderBottomRightRadiusProperty, borderRadius.bottom],
|
|
1052
|
-
[borderBottomLeftRadiusProperty, borderRadius.left],
|
|
920
|
+
[borderTopLeftRadiusProperty, Length.parse(borderRadius.top)],
|
|
921
|
+
[borderTopRightRadiusProperty, Length.parse(borderRadius.right)],
|
|
922
|
+
[borderBottomRightRadiusProperty, Length.parse(borderRadius.bottom)],
|
|
923
|
+
[borderBottomLeftRadiusProperty, Length.parse(borderRadius.left)],
|
|
1053
924
|
];
|
|
1054
925
|
}
|
|
1055
926
|
else {
|
|
@@ -1147,53 +1018,49 @@ const boxShadowProperty = new CssProperty({
|
|
|
1147
1018
|
},
|
|
1148
1019
|
});
|
|
1149
1020
|
boxShadowProperty.register(Style);
|
|
1150
|
-
function isNonNegativeFiniteNumber(value) {
|
|
1151
|
-
return isFinite(value) && !isNaN(value) && value >= 0;
|
|
1152
|
-
}
|
|
1153
|
-
const supportedPaths = ['rect', 'circle', 'ellipse', 'polygon', 'inset'];
|
|
1154
|
-
function isClipPathValid(value) {
|
|
1155
|
-
if (!value) {
|
|
1156
|
-
return true;
|
|
1157
|
-
}
|
|
1158
|
-
const functionName = value.substring(0, value.indexOf('(')).trim();
|
|
1159
|
-
return supportedPaths.indexOf(functionName) !== -1;
|
|
1160
|
-
}
|
|
1161
1021
|
export const clipPathProperty = new CssProperty({
|
|
1162
1022
|
name: 'clipPath',
|
|
1163
1023
|
cssName: 'clip-path',
|
|
1164
1024
|
valueChanged: (target, oldValue, newValue) => {
|
|
1165
|
-
if (!isClipPathValid(newValue)) {
|
|
1166
|
-
throw new Error('clip-path is not valid.');
|
|
1167
|
-
}
|
|
1168
1025
|
target.backgroundInternal = target.backgroundInternal.withClipPath(newValue);
|
|
1169
1026
|
},
|
|
1027
|
+
equalityComparer: (value1, value2) => {
|
|
1028
|
+
if (value1 instanceof ClipPathFunction && value2 instanceof ClipPathFunction) {
|
|
1029
|
+
return ClipPathFunction.equals(value1, value2);
|
|
1030
|
+
}
|
|
1031
|
+
return value1 === value2;
|
|
1032
|
+
},
|
|
1033
|
+
valueConverter(value) {
|
|
1034
|
+
if (typeof value === 'string') {
|
|
1035
|
+
return parseClipPath(value);
|
|
1036
|
+
}
|
|
1037
|
+
return value;
|
|
1038
|
+
},
|
|
1170
1039
|
});
|
|
1171
1040
|
clipPathProperty.register(Style);
|
|
1172
|
-
function isFloatValueConverter(value) {
|
|
1173
|
-
const newValue = parseFloat(value);
|
|
1174
|
-
if (isNaN(newValue)) {
|
|
1175
|
-
throw new Error(`Invalid value: ${newValue}`);
|
|
1176
|
-
}
|
|
1177
|
-
return newValue;
|
|
1178
|
-
}
|
|
1179
1041
|
export const zIndexProperty = new CssProperty({
|
|
1180
1042
|
name: 'zIndex',
|
|
1181
1043
|
cssName: 'z-index',
|
|
1182
|
-
valueConverter:
|
|
1044
|
+
valueConverter: (value) => {
|
|
1045
|
+
const newValue = parseFloat(value);
|
|
1046
|
+
if (isNaN(newValue)) {
|
|
1047
|
+
throw new Error(`Invalid value: ${newValue}`);
|
|
1048
|
+
}
|
|
1049
|
+
return newValue;
|
|
1050
|
+
},
|
|
1183
1051
|
});
|
|
1184
1052
|
zIndexProperty.register(Style);
|
|
1185
|
-
function opacityConverter(value) {
|
|
1186
|
-
const newValue = parseFloat(value);
|
|
1187
|
-
if (!isNaN(newValue) && 0 <= newValue && newValue <= 1) {
|
|
1188
|
-
return newValue;
|
|
1189
|
-
}
|
|
1190
|
-
throw new Error(`Opacity should be between [0, 1]. Value: ${newValue}`);
|
|
1191
|
-
}
|
|
1192
1053
|
export const opacityProperty = new CssAnimationProperty({
|
|
1193
1054
|
name: 'opacity',
|
|
1194
1055
|
cssName: 'opacity',
|
|
1195
1056
|
defaultValue: 1,
|
|
1196
|
-
valueConverter:
|
|
1057
|
+
valueConverter: (value) => {
|
|
1058
|
+
const newValue = parseFloat(value);
|
|
1059
|
+
if (!isNonNegativeFiniteNumber(newValue) || newValue > 1) {
|
|
1060
|
+
throw new Error(`Opacity should be between [0, 1]. Value: ${newValue}`);
|
|
1061
|
+
}
|
|
1062
|
+
return newValue;
|
|
1063
|
+
},
|
|
1197
1064
|
});
|
|
1198
1065
|
opacityProperty.register(Style);
|
|
1199
1066
|
export const colorProperty = new InheritedCssProperty({
|