@antv/g-lite 1.0.6 → 1.0.8
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 +2 -2
- package/dist/Canvas.d.ts.map +1 -1
- package/dist/css/cssom/CSSGradientValue.d.ts +12 -7
- package/dist/css/cssom/CSSGradientValue.d.ts.map +1 -1
- package/dist/css/parser/gradient.d.ts.map +1 -1
- package/dist/dom/Element.d.ts +1 -0
- package/dist/dom/Element.d.ts.map +1 -1
- package/dist/index.esm.js +705 -614
- package/dist/index.js +704 -612
- package/dist/index.umd.js +704 -612
- package/dist/index.umd.min.js +2 -2
- package/dist/plugins/EventPlugin.d.ts +1 -0
- package/dist/plugins/EventPlugin.d.ts.map +1 -1
- package/dist/types.d.ts +4 -0
- package/dist/types.d.ts.map +1 -1
- package/dist/utils/gradient.d.ts +3 -2
- package/dist/utils/gradient.d.ts.map +1 -1
- package/package.json +3 -3
package/dist/index.esm.js
CHANGED
|
@@ -3,7 +3,7 @@ import { Syringe, GlobalContainer, singleton, inject, injectable, contrib, Modul
|
|
|
3
3
|
export { GlobalContainer, Module, Syringe, inject, injectable, singleton } from 'mana-syringe';
|
|
4
4
|
import RBush from 'rbush';
|
|
5
5
|
export { default as RBush } from 'rbush';
|
|
6
|
-
import { memoize, isString, isNumber, getTotalLength, clamp, isNil, isObject, normalizePath, path2Curve, getPathBBox, equalizeSegments, getDrawDirection, reverseCurve, clonePath, getRotatedCurve, isBoolean, isUndefined, getPointAtLength } from '@antv/util';
|
|
6
|
+
import { memoize, isString, isNumber, distanceSquareRoot, getTotalLength, clamp, isNil, isObject, normalizePath, path2Curve, getPathBBox, equalizeSegments, getDrawDirection, reverseCurve, clonePath, getRotatedCurve, isBoolean, isUndefined, getPointAtLength } from '@antv/util';
|
|
7
7
|
import { color } from 'd3-color';
|
|
8
8
|
import { vec3, mat4, vec4, mat3, quat as quat$1, vec2 } from 'gl-matrix';
|
|
9
9
|
import { Polyline as Polyline$1, Line as Line$1 } from '@antv/g-math';
|
|
@@ -3250,717 +3250,747 @@ var TOUCH_TO_POINTER = {
|
|
|
3250
3250
|
touchcancel: 'pointercancel'
|
|
3251
3251
|
};
|
|
3252
3252
|
|
|
3253
|
-
|
|
3254
|
-
|
|
3255
|
-
|
|
3256
|
-
|
|
3257
|
-
|
|
3258
|
-
var type = colorStop.type,
|
|
3259
|
-
value = colorStop.value;
|
|
3260
|
-
|
|
3261
|
-
if (type === 'hex') {
|
|
3262
|
-
return "#" + value;
|
|
3263
|
-
} else if (type === 'literal') {
|
|
3264
|
-
return value;
|
|
3265
|
-
} else if (type === 'rgb') {
|
|
3266
|
-
return "rgb(" + value.join(',') + ")";
|
|
3267
|
-
} else {
|
|
3268
|
-
return "rgba(" + value.join(',') + ")";
|
|
3253
|
+
function getAngle(angle) {
|
|
3254
|
+
if (angle === undefined) {
|
|
3255
|
+
return 0;
|
|
3256
|
+
} else if (angle > 360 || angle < -360) {
|
|
3257
|
+
return angle % 360;
|
|
3269
3258
|
}
|
|
3270
|
-
}
|
|
3271
|
-
var parseGradient = function () {
|
|
3272
|
-
var tokens = {
|
|
3273
|
-
linearGradient: /^(linear\-gradient)/i,
|
|
3274
|
-
repeatingLinearGradient: /^(repeating\-linear\-gradient)/i,
|
|
3275
|
-
radialGradient: /^(radial\-gradient)/i,
|
|
3276
|
-
repeatingRadialGradient: /^(repeating\-radial\-gradient)/i,
|
|
3277
|
-
|
|
3278
|
-
/**
|
|
3279
|
-
* @see https://projects.verou.me/conic-gradient/
|
|
3280
|
-
*/
|
|
3281
|
-
conicGradient: /^(conic\-gradient)/i,
|
|
3282
|
-
sideOrCorner: /^to (left (top|bottom)|right (top|bottom)|top (left|right)|bottom (left|right)|left|right|top|bottom)/i,
|
|
3283
|
-
extentKeywords: /^(closest\-side|closest\-corner|farthest\-side|farthest\-corner|contain|cover)/,
|
|
3284
|
-
positionKeywords: /^(left|center|right|top|bottom)/i,
|
|
3285
|
-
pixelValue: /^(-?(([0-9]*\.[0-9]+)|([0-9]+\.?)))px/,
|
|
3286
|
-
percentageValue: /^(-?(([0-9]*\.[0-9]+)|([0-9]+\.?)))\%/,
|
|
3287
|
-
emValue: /^(-?(([0-9]*\.[0-9]+)|([0-9]+\.?)))em/,
|
|
3288
|
-
angleValue: /^(-?(([0-9]*\.[0-9]+)|([0-9]+\.?)))deg/,
|
|
3289
|
-
startCall: /^\(/,
|
|
3290
|
-
endCall: /^\)/,
|
|
3291
|
-
comma: /^,/,
|
|
3292
|
-
hexColor: /^\#([0-9a-fA-F]+)/,
|
|
3293
|
-
literalColor: /^([a-zA-Z]+)/,
|
|
3294
|
-
rgbColor: /^rgb/i,
|
|
3295
|
-
rgbaColor: /^rgba/i,
|
|
3296
|
-
number: /^(([0-9]*\.[0-9]+)|([0-9]+\.?))/
|
|
3297
|
-
};
|
|
3298
|
-
var input = '';
|
|
3299
3259
|
|
|
3300
|
-
|
|
3301
|
-
|
|
3260
|
+
return angle;
|
|
3261
|
+
}
|
|
3262
|
+
function createVec3(x, y, z) {
|
|
3263
|
+
if (y === void 0) {
|
|
3264
|
+
y = 0;
|
|
3302
3265
|
}
|
|
3303
3266
|
|
|
3304
|
-
|
|
3305
|
-
|
|
3306
|
-
|
|
3307
|
-
if (input.length > 0) {
|
|
3308
|
-
error('Invalid input not EOF');
|
|
3309
|
-
}
|
|
3267
|
+
if (z === void 0) {
|
|
3268
|
+
z = 0;
|
|
3269
|
+
}
|
|
3310
3270
|
|
|
3311
|
-
|
|
3271
|
+
if (isNumber(x)) {
|
|
3272
|
+
return vec3.fromValues(x, y, z);
|
|
3312
3273
|
}
|
|
3313
3274
|
|
|
3314
|
-
|
|
3315
|
-
return
|
|
3275
|
+
if (Array.isArray(x) && x.length === 3) {
|
|
3276
|
+
return vec3.clone(x);
|
|
3316
3277
|
}
|
|
3317
3278
|
|
|
3318
|
-
|
|
3319
|
-
|
|
3279
|
+
return vec3.fromValues(x[0], x[1] || y, x[2] || z);
|
|
3280
|
+
}
|
|
3281
|
+
function deg2rad(deg) {
|
|
3282
|
+
return deg * (Math.PI / 180);
|
|
3283
|
+
}
|
|
3284
|
+
function rad2deg(rad) {
|
|
3285
|
+
return rad * (180 / Math.PI);
|
|
3286
|
+
}
|
|
3287
|
+
function grad2deg(grads) {
|
|
3288
|
+
grads = grads % 400;
|
|
3289
|
+
|
|
3290
|
+
if (grads < 0) {
|
|
3291
|
+
grads += 400;
|
|
3320
3292
|
}
|
|
3321
3293
|
|
|
3322
|
-
|
|
3323
|
-
|
|
3324
|
-
|
|
3294
|
+
return grads / 400 * 360;
|
|
3295
|
+
}
|
|
3296
|
+
function deg2turn(deg) {
|
|
3297
|
+
return deg / 360;
|
|
3298
|
+
}
|
|
3299
|
+
function turn2deg(turn) {
|
|
3300
|
+
return 360 * turn;
|
|
3301
|
+
}
|
|
3325
3302
|
|
|
3326
|
-
|
|
3327
|
-
|
|
3328
|
-
|
|
3329
|
-
|
|
3330
|
-
|
|
3303
|
+
function getEulerFromQuat(out, quat) {
|
|
3304
|
+
var x = quat[0];
|
|
3305
|
+
var y = quat[1];
|
|
3306
|
+
var z = quat[2];
|
|
3307
|
+
var w = quat[3];
|
|
3308
|
+
var x2 = x * x;
|
|
3309
|
+
var y2 = y * y;
|
|
3310
|
+
var z2 = z * z;
|
|
3311
|
+
var w2 = w * w;
|
|
3312
|
+
var unit = x2 + y2 + z2 + w2;
|
|
3313
|
+
var test = x * w - y * z;
|
|
3331
3314
|
|
|
3332
|
-
|
|
3333
|
-
|
|
3334
|
-
|
|
3335
|
-
|
|
3336
|
-
|
|
3337
|
-
|
|
3338
|
-
}
|
|
3315
|
+
if (test > 0.499995 * unit) {
|
|
3316
|
+
// TODO: Use glmatrix.EPSILON
|
|
3317
|
+
// singularity at the north pole
|
|
3318
|
+
out[0] = Math.PI / 2;
|
|
3319
|
+
out[1] = 2 * Math.atan2(y, x);
|
|
3320
|
+
out[2] = 0;
|
|
3321
|
+
} else if (test < -0.499995 * unit) {
|
|
3322
|
+
//TODO: Use glmatrix.EPSILON
|
|
3323
|
+
// singularity at the south pole
|
|
3324
|
+
out[0] = -Math.PI / 2;
|
|
3325
|
+
out[1] = 2 * Math.atan2(y, x);
|
|
3326
|
+
out[2] = 0;
|
|
3327
|
+
} else {
|
|
3328
|
+
out[0] = Math.asin(2 * (x * z - w * y));
|
|
3329
|
+
out[1] = Math.atan2(2 * (x * w + y * z), 1 - 2 * (z2 + w2));
|
|
3330
|
+
out[2] = Math.atan2(2 * (x * y + z * w), 1 - 2 * (y2 + z2));
|
|
3331
|
+
} // TODO: Return them as degrees and not as radians
|
|
3339
3332
|
|
|
3340
|
-
function matchCall(pattern, callback) {
|
|
3341
|
-
var captures = scan(pattern);
|
|
3342
3333
|
|
|
3343
|
-
|
|
3344
|
-
|
|
3345
|
-
error('Missing (');
|
|
3346
|
-
}
|
|
3334
|
+
return out;
|
|
3335
|
+
}
|
|
3347
3336
|
|
|
3348
|
-
|
|
3337
|
+
function getEulerFromMat4(out, m) {
|
|
3338
|
+
var x;
|
|
3339
|
+
var z;
|
|
3340
|
+
var halfPi = Math.PI * 0.5;
|
|
3349
3341
|
|
|
3350
|
-
|
|
3351
|
-
|
|
3352
|
-
|
|
3342
|
+
var _mat4$getScaling = mat4.getScaling(vec3.create(), m),
|
|
3343
|
+
sx = _mat4$getScaling[0],
|
|
3344
|
+
sy = _mat4$getScaling[1],
|
|
3345
|
+
sz = _mat4$getScaling[2];
|
|
3353
3346
|
|
|
3354
|
-
|
|
3347
|
+
var y = Math.asin(-m[2] / sx);
|
|
3348
|
+
|
|
3349
|
+
if (y < halfPi) {
|
|
3350
|
+
if (y > -halfPi) {
|
|
3351
|
+
x = Math.atan2(m[6] / sy, m[10] / sz);
|
|
3352
|
+
z = Math.atan2(m[1] / sx, m[0] / sx);
|
|
3353
|
+
} else {
|
|
3354
|
+
// Not a unique solution
|
|
3355
|
+
z = 0;
|
|
3356
|
+
x = -Math.atan2(m[4] / sy, m[5] / sy);
|
|
3355
3357
|
}
|
|
3358
|
+
} else {
|
|
3359
|
+
// Not a unique solution
|
|
3360
|
+
z = 0;
|
|
3361
|
+
x = Math.atan2(m[4] / sy, m[5] / sy);
|
|
3356
3362
|
}
|
|
3357
3363
|
|
|
3358
|
-
|
|
3359
|
-
|
|
3360
|
-
|
|
3364
|
+
out[0] = x;
|
|
3365
|
+
out[1] = y;
|
|
3366
|
+
out[2] = z;
|
|
3367
|
+
return out;
|
|
3368
|
+
}
|
|
3369
|
+
/**
|
|
3370
|
+
* @see https://github.com/toji/gl-matrix/issues/329
|
|
3371
|
+
* @see https://doc.babylonjs.com/divingDeeper/mesh/transforms/center_origin/rotation_conventions
|
|
3372
|
+
*/
|
|
3361
3373
|
|
|
3362
|
-
function matchSideOrCorner() {
|
|
3363
|
-
return match('directional', tokens.sideOrCorner, 1);
|
|
3364
|
-
}
|
|
3365
3374
|
|
|
3366
|
-
|
|
3367
|
-
|
|
3375
|
+
function getEuler(out, quat) {
|
|
3376
|
+
if (quat.length === 16) {
|
|
3377
|
+
return getEulerFromMat4(out, quat);
|
|
3378
|
+
} else {
|
|
3379
|
+
return getEulerFromQuat(out, quat);
|
|
3368
3380
|
}
|
|
3381
|
+
}
|
|
3382
|
+
function fromRotationTranslationScale(rotation, x, y, scaleX, scaleY) {
|
|
3383
|
+
var cos = Math.cos(rotation);
|
|
3384
|
+
var sin = Math.sin(rotation);
|
|
3385
|
+
return mat3.fromValues(scaleX * cos, scaleY * sin, 0, -scaleX * sin, scaleY * cos, 0, x, y, 1);
|
|
3386
|
+
}
|
|
3387
|
+
function makePerspective(out, left, right, top, bottom, near, far) {
|
|
3388
|
+
var x = 2 * near / (right - left);
|
|
3389
|
+
var y = 2 * near / (top - bottom);
|
|
3390
|
+
var a = (right + left) / (right - left);
|
|
3391
|
+
var b = (top + bottom) / (top - bottom);
|
|
3392
|
+
var c = -(far + near) / (far - near);
|
|
3393
|
+
var d = -2 * far * near / (far - near);
|
|
3394
|
+
out[0] = x;
|
|
3395
|
+
out[1] = 0;
|
|
3396
|
+
out[2] = 0;
|
|
3397
|
+
out[3] = 0;
|
|
3398
|
+
out[4] = 0;
|
|
3399
|
+
out[5] = y;
|
|
3400
|
+
out[6] = 0;
|
|
3401
|
+
out[7] = 0;
|
|
3402
|
+
out[8] = a;
|
|
3403
|
+
out[9] = b;
|
|
3404
|
+
out[10] = c;
|
|
3405
|
+
out[11] = -1;
|
|
3406
|
+
out[12] = 0;
|
|
3407
|
+
out[13] = 0;
|
|
3408
|
+
out[14] = d;
|
|
3409
|
+
out[15] = 0;
|
|
3410
|
+
return out;
|
|
3411
|
+
}
|
|
3412
|
+
function decompose(mat) {
|
|
3413
|
+
var row0x = mat[0];
|
|
3414
|
+
var row0y = mat[1];
|
|
3415
|
+
var row1x = mat[3];
|
|
3416
|
+
var row1y = mat[4]; // decompose 3x3 matrix
|
|
3417
|
+
// @see https://www.w3.org/TR/css-transforms-1/#decomposing-a-2d-matrix
|
|
3369
3418
|
|
|
3370
|
-
|
|
3371
|
-
|
|
3372
|
-
radialOrientation = matchRadialOrientation(),
|
|
3373
|
-
lookaheadCache;
|
|
3374
|
-
|
|
3375
|
-
if (radialOrientation) {
|
|
3376
|
-
radialOrientations = [];
|
|
3377
|
-
radialOrientations.push(radialOrientation);
|
|
3378
|
-
lookaheadCache = input;
|
|
3419
|
+
var scalingX = Math.sqrt(row0x * row0x + row0y * row0y);
|
|
3420
|
+
var scalingY = Math.sqrt(row1x * row1x + row1y * row1y); // If determinant is negative, one axis was flipped.
|
|
3379
3421
|
|
|
3380
|
-
|
|
3381
|
-
radialOrientation = matchRadialOrientation();
|
|
3422
|
+
var determinant = row0x * row1y - row0y * row1x;
|
|
3382
3423
|
|
|
3383
|
-
|
|
3384
|
-
|
|
3385
|
-
|
|
3386
|
-
|
|
3387
|
-
|
|
3388
|
-
|
|
3424
|
+
if (determinant < 0) {
|
|
3425
|
+
// Flip axis with minimum unit vector dot product.
|
|
3426
|
+
if (row0x < row1y) {
|
|
3427
|
+
scalingX = -scalingX;
|
|
3428
|
+
} else {
|
|
3429
|
+
scalingY = -scalingY;
|
|
3389
3430
|
}
|
|
3431
|
+
} // Renormalize matrix to remove scale.
|
|
3390
3432
|
|
|
3391
|
-
|
|
3433
|
+
|
|
3434
|
+
if (scalingX) {
|
|
3435
|
+
row0x *= 1 / scalingX;
|
|
3436
|
+
row0y *= 1 / scalingX;
|
|
3392
3437
|
}
|
|
3393
3438
|
|
|
3394
|
-
|
|
3395
|
-
|
|
3439
|
+
if (scalingY) {
|
|
3440
|
+
row1x *= 1 / scalingY;
|
|
3441
|
+
row1y *= 1 / scalingY;
|
|
3442
|
+
} // Compute rotation and renormalize matrix.
|
|
3396
3443
|
|
|
3397
|
-
if (radialType) {
|
|
3398
|
-
// @ts-ignore
|
|
3399
|
-
radialType.at = matchAtPosition();
|
|
3400
|
-
} else {
|
|
3401
|
-
var extent = matchExtentKeyword();
|
|
3402
3444
|
|
|
3403
|
-
|
|
3404
|
-
|
|
3405
|
-
|
|
3445
|
+
var rotation = Math.atan2(row0y, row0x);
|
|
3446
|
+
var angle = rad2deg(rotation);
|
|
3447
|
+
return [mat[6], mat[7], scalingX, scalingY, angle];
|
|
3448
|
+
}
|
|
3449
|
+
var tmp = mat4.create();
|
|
3450
|
+
var perspectiveMatrix = mat4.create();
|
|
3451
|
+
var tmpVec4 = vec4.create();
|
|
3452
|
+
var row = [vec3.create(), vec3.create(), vec3.create()];
|
|
3453
|
+
var pdum3 = vec3.create();
|
|
3454
|
+
/*
|
|
3455
|
+
Input: matrix ; a 4x4 matrix
|
|
3456
|
+
Output: translation ; a 3 component vector
|
|
3457
|
+
scale ; a 3 component vector
|
|
3458
|
+
skew ; skew factors XY,XZ,YZ represented as a 3 component vector
|
|
3459
|
+
perspective ; a 4 component vector
|
|
3460
|
+
quaternion ; a 4 component vector
|
|
3461
|
+
Returns false if the matrix cannot be decomposed, true if it can
|
|
3406
3462
|
|
|
3407
|
-
if (positionAt) {
|
|
3408
|
-
// @ts-ignore
|
|
3409
|
-
radialType.at = positionAt;
|
|
3410
|
-
}
|
|
3411
|
-
} else {
|
|
3412
|
-
var defaultPosition = matchPositioning();
|
|
3413
3463
|
|
|
3414
|
-
|
|
3415
|
-
|
|
3416
|
-
|
|
3417
|
-
|
|
3418
|
-
|
|
3419
|
-
};
|
|
3420
|
-
}
|
|
3421
|
-
}
|
|
3422
|
-
}
|
|
3464
|
+
References:
|
|
3465
|
+
https://github.com/kamicane/matrix3d/blob/master/lib/Matrix3d.js
|
|
3466
|
+
https://github.com/ChromiumWebApps/chromium/blob/master/ui/gfx/transform_util.cc
|
|
3467
|
+
http://www.w3.org/TR/css3-transforms/#decomposing-a-3d-matrix
|
|
3468
|
+
*/
|
|
3423
3469
|
|
|
3424
|
-
|
|
3425
|
-
|
|
3470
|
+
function decomposeMat4(matrix, translation, scale, skew, perspective, quaternion) {
|
|
3471
|
+
//normalize, if not possible then bail out early
|
|
3472
|
+
if (!normalize(tmp, matrix)) return false; // perspectiveMatrix is used to solve for perspective, but it also provides
|
|
3473
|
+
// an easy way to test for singularity of the upper 3x3 component.
|
|
3426
3474
|
|
|
3427
|
-
|
|
3428
|
-
|
|
3475
|
+
mat4.copy(perspectiveMatrix, tmp);
|
|
3476
|
+
perspectiveMatrix[3] = 0;
|
|
3477
|
+
perspectiveMatrix[7] = 0;
|
|
3478
|
+
perspectiveMatrix[11] = 0;
|
|
3479
|
+
perspectiveMatrix[15] = 1; // If the perspectiveMatrix is not invertible, we are also unable to
|
|
3480
|
+
// decompose, so we'll bail early. Constant taken from SkMatrix44::invert.
|
|
3429
3481
|
|
|
3430
|
-
|
|
3431
|
-
|
|
3432
|
-
|
|
3433
|
-
|
|
3482
|
+
if (Math.abs(mat4.determinant(perspectiveMatrix)) < 1e-8) return false;
|
|
3483
|
+
var a03 = tmp[3],
|
|
3484
|
+
a13 = tmp[7],
|
|
3485
|
+
a23 = tmp[11],
|
|
3486
|
+
a30 = tmp[12],
|
|
3487
|
+
a31 = tmp[13],
|
|
3488
|
+
a32 = tmp[14],
|
|
3489
|
+
a33 = tmp[15]; // First, isolate perspective.
|
|
3434
3490
|
|
|
3435
|
-
|
|
3436
|
-
|
|
3491
|
+
if (a03 !== 0 || a13 !== 0 || a23 !== 0) {
|
|
3492
|
+
tmpVec4[0] = a03;
|
|
3493
|
+
tmpVec4[1] = a13;
|
|
3494
|
+
tmpVec4[2] = a23;
|
|
3495
|
+
tmpVec4[3] = a33; // Solve the equation by inverting perspectiveMatrix and multiplying
|
|
3496
|
+
// rightHandSide by the inverse.
|
|
3497
|
+
// resuing the perspectiveMatrix here since it's no longer needed
|
|
3498
|
+
|
|
3499
|
+
var ret = mat4.invert(perspectiveMatrix, perspectiveMatrix);
|
|
3500
|
+
if (!ret) return false;
|
|
3501
|
+
mat4.transpose(perspectiveMatrix, perspectiveMatrix); //multiply by transposed inverse perspective matrix, into perspective vec4
|
|
3502
|
+
|
|
3503
|
+
vec4.transformMat4(perspective, tmpVec4, perspectiveMatrix);
|
|
3504
|
+
} else {
|
|
3505
|
+
//no perspective
|
|
3506
|
+
perspective[0] = perspective[1] = perspective[2] = 0;
|
|
3507
|
+
perspective[3] = 1;
|
|
3508
|
+
} // Next take care of translation
|
|
3509
|
+
|
|
3510
|
+
|
|
3511
|
+
translation[0] = a30;
|
|
3512
|
+
translation[1] = a31;
|
|
3513
|
+
translation[2] = a32; // Now get scale and shear. 'row' is a 3 element array of 3 component vectors
|
|
3514
|
+
|
|
3515
|
+
mat3from4(row, tmp); // Compute X scale factor and normalize first row.
|
|
3516
|
+
|
|
3517
|
+
scale[0] = vec3.length(row[0]);
|
|
3518
|
+
vec3.normalize(row[0], row[0]); // Compute XY shear factor and make 2nd row orthogonal to 1st.
|
|
3519
|
+
|
|
3520
|
+
skew[0] = vec3.dot(row[0], row[1]);
|
|
3521
|
+
combine(row[1], row[1], row[0], 1.0, -skew[0]); // Now, compute Y scale and normalize 2nd row.
|
|
3522
|
+
|
|
3523
|
+
scale[1] = vec3.length(row[1]);
|
|
3524
|
+
vec3.normalize(row[1], row[1]);
|
|
3525
|
+
skew[0] /= scale[1]; // Compute XZ and YZ shears, orthogonalize 3rd row
|
|
3526
|
+
|
|
3527
|
+
skew[1] = vec3.dot(row[0], row[2]);
|
|
3528
|
+
combine(row[2], row[2], row[0], 1.0, -skew[1]);
|
|
3529
|
+
skew[2] = vec3.dot(row[1], row[2]);
|
|
3530
|
+
combine(row[2], row[2], row[1], 1.0, -skew[2]); // Next, get Z scale and normalize 3rd row.
|
|
3531
|
+
|
|
3532
|
+
scale[2] = vec3.length(row[2]);
|
|
3533
|
+
vec3.normalize(row[2], row[2]);
|
|
3534
|
+
skew[1] /= scale[2];
|
|
3535
|
+
skew[2] /= scale[2]; // At this point, the matrix (in rows) is orthonormal.
|
|
3536
|
+
// Check for a coordinate system flip. If the determinant
|
|
3537
|
+
// is -1, then negate the matrix and the scaling factors.
|
|
3437
3538
|
|
|
3438
|
-
|
|
3439
|
-
var ellipse = match('shape', /^(ellipse)/i, 0);
|
|
3539
|
+
vec3.cross(pdum3, row[1], row[2]);
|
|
3440
3540
|
|
|
3441
|
-
|
|
3442
|
-
|
|
3443
|
-
|
|
3541
|
+
if (vec3.dot(row[0], pdum3) < 0) {
|
|
3542
|
+
for (var i = 0; i < 3; i++) {
|
|
3543
|
+
scale[i] *= -1;
|
|
3544
|
+
row[i][0] *= -1;
|
|
3545
|
+
row[i][1] *= -1;
|
|
3546
|
+
row[i][2] *= -1;
|
|
3444
3547
|
}
|
|
3548
|
+
} // Now, get the rotations out
|
|
3445
3549
|
|
|
3446
|
-
return ellipse;
|
|
3447
|
-
}
|
|
3448
3550
|
|
|
3449
|
-
|
|
3450
|
-
|
|
3451
|
-
|
|
3551
|
+
quaternion[0] = 0.5 * Math.sqrt(Math.max(1 + row[0][0] - row[1][1] - row[2][2], 0));
|
|
3552
|
+
quaternion[1] = 0.5 * Math.sqrt(Math.max(1 - row[0][0] + row[1][1] - row[2][2], 0));
|
|
3553
|
+
quaternion[2] = 0.5 * Math.sqrt(Math.max(1 - row[0][0] - row[1][1] + row[2][2], 0));
|
|
3554
|
+
quaternion[3] = 0.5 * Math.sqrt(Math.max(1 + row[0][0] + row[1][1] + row[2][2], 0));
|
|
3555
|
+
if (row[2][1] > row[1][2]) quaternion[0] = -quaternion[0];
|
|
3556
|
+
if (row[0][2] > row[2][0]) quaternion[1] = -quaternion[1];
|
|
3557
|
+
if (row[1][0] > row[0][1]) quaternion[2] = -quaternion[2];
|
|
3558
|
+
return true;
|
|
3559
|
+
}
|
|
3452
3560
|
|
|
3453
|
-
|
|
3454
|
-
|
|
3455
|
-
var positioning = matchPositioning();
|
|
3561
|
+
function normalize(out, mat) {
|
|
3562
|
+
var m44 = mat[15]; // Cannot normalize.
|
|
3456
3563
|
|
|
3457
|
-
|
|
3458
|
-
|
|
3459
|
-
}
|
|
3564
|
+
if (m44 === 0) return false;
|
|
3565
|
+
var scale = 1 / m44;
|
|
3460
3566
|
|
|
3461
|
-
|
|
3462
|
-
|
|
3567
|
+
for (var i = 0; i < 16; i++) {
|
|
3568
|
+
out[i] = mat[i] * scale;
|
|
3463
3569
|
}
|
|
3464
3570
|
|
|
3465
|
-
|
|
3466
|
-
|
|
3571
|
+
return true;
|
|
3572
|
+
} //gets upper-left of a 4x4 matrix into a 3x3 of vectors
|
|
3467
3573
|
|
|
3468
|
-
if (location.x || location.y) {
|
|
3469
|
-
return {
|
|
3470
|
-
type: 'position',
|
|
3471
|
-
value: location
|
|
3472
|
-
};
|
|
3473
|
-
}
|
|
3474
|
-
}
|
|
3475
3574
|
|
|
3476
|
-
|
|
3477
|
-
|
|
3478
|
-
|
|
3479
|
-
|
|
3480
|
-
|
|
3481
|
-
|
|
3575
|
+
function mat3from4(out, mat4x4) {
|
|
3576
|
+
out[0][0] = mat4x4[0];
|
|
3577
|
+
out[0][1] = mat4x4[1];
|
|
3578
|
+
out[0][2] = mat4x4[2];
|
|
3579
|
+
out[1][0] = mat4x4[4];
|
|
3580
|
+
out[1][1] = mat4x4[5];
|
|
3581
|
+
out[1][2] = mat4x4[6];
|
|
3582
|
+
out[2][0] = mat4x4[8];
|
|
3583
|
+
out[2][1] = mat4x4[9];
|
|
3584
|
+
out[2][2] = mat4x4[10];
|
|
3585
|
+
}
|
|
3482
3586
|
|
|
3483
|
-
|
|
3484
|
-
|
|
3485
|
-
|
|
3587
|
+
function combine(out, a, b, scale1, scale2) {
|
|
3588
|
+
out[0] = a[0] * scale1 + b[0] * scale2;
|
|
3589
|
+
out[1] = a[1] * scale1 + b[1] * scale2;
|
|
3590
|
+
out[2] = a[2] * scale1 + b[2] * scale2;
|
|
3591
|
+
}
|
|
3486
3592
|
|
|
3487
|
-
|
|
3488
|
-
|
|
3593
|
+
/**
|
|
3594
|
+
* borrow from gradient-parser, but we delete some browser compatible prefix such as `-webkit-`
|
|
3595
|
+
* @see https://github.com/rafaelcaricio/gradient-parser
|
|
3596
|
+
*/
|
|
3597
|
+
function colorStopToString(colorStop) {
|
|
3598
|
+
var type = colorStop.type,
|
|
3599
|
+
value = colorStop.value;
|
|
3489
3600
|
|
|
3490
|
-
|
|
3491
|
-
|
|
3601
|
+
if (type === 'hex') {
|
|
3602
|
+
return "#" + value;
|
|
3603
|
+
} else if (type === 'literal') {
|
|
3604
|
+
return value;
|
|
3605
|
+
} else if (type === 'rgb') {
|
|
3606
|
+
return "rgb(" + value.join(',') + ")";
|
|
3607
|
+
} else {
|
|
3608
|
+
return "rgba(" + value.join(',') + ")";
|
|
3609
|
+
}
|
|
3610
|
+
}
|
|
3611
|
+
var parseGradient = function () {
|
|
3612
|
+
var tokens = {
|
|
3613
|
+
linearGradient: /^(linear\-gradient)/i,
|
|
3614
|
+
repeatingLinearGradient: /^(repeating\-linear\-gradient)/i,
|
|
3615
|
+
radialGradient: /^(radial\-gradient)/i,
|
|
3616
|
+
repeatingRadialGradient: /^(repeating\-radial\-gradient)/i,
|
|
3492
3617
|
|
|
3493
|
-
|
|
3494
|
-
|
|
3495
|
-
|
|
3496
|
-
|
|
3497
|
-
|
|
3498
|
-
|
|
3499
|
-
|
|
3618
|
+
/**
|
|
3619
|
+
* @see https://projects.verou.me/conic-gradient/
|
|
3620
|
+
*/
|
|
3621
|
+
conicGradient: /^(conic\-gradient)/i,
|
|
3622
|
+
sideOrCorner: /^to (left (top|bottom)|right (top|bottom)|top (left|right)|bottom (left|right)|left|right|top|bottom)/i,
|
|
3623
|
+
extentKeywords: /^(closest\-side|closest\-corner|farthest\-side|farthest\-corner|contain|cover)/,
|
|
3624
|
+
positionKeywords: /^(left|center|right|top|bottom)/i,
|
|
3625
|
+
pixelValue: /^(-?(([0-9]*\.[0-9]+)|([0-9]+\.?)))px/,
|
|
3626
|
+
percentageValue: /^(-?(([0-9]*\.[0-9]+)|([0-9]+\.?)))\%/,
|
|
3627
|
+
emValue: /^(-?(([0-9]*\.[0-9]+)|([0-9]+\.?)))em/,
|
|
3628
|
+
angleValue: /^(-?(([0-9]*\.[0-9]+)|([0-9]+\.?)))deg/,
|
|
3629
|
+
startCall: /^\(/,
|
|
3630
|
+
endCall: /^\)/,
|
|
3631
|
+
comma: /^,/,
|
|
3632
|
+
hexColor: /^\#([0-9a-fA-F]+)/,
|
|
3633
|
+
literalColor: /^([a-zA-Z]+)/,
|
|
3634
|
+
rgbColor: /^rgb/i,
|
|
3635
|
+
rgbaColor: /^rgba/i,
|
|
3636
|
+
number: /^(([0-9]*\.[0-9]+)|([0-9]+\.?))/
|
|
3637
|
+
};
|
|
3638
|
+
var input = '';
|
|
3500
3639
|
|
|
3501
|
-
|
|
3640
|
+
function error(msg) {
|
|
3641
|
+
throw new Error(input + ': ' + msg);
|
|
3502
3642
|
}
|
|
3503
3643
|
|
|
3504
|
-
function
|
|
3505
|
-
var
|
|
3644
|
+
function getAST() {
|
|
3645
|
+
var ast = matchListDefinitions();
|
|
3506
3646
|
|
|
3507
|
-
if (
|
|
3508
|
-
error('
|
|
3647
|
+
if (input.length > 0) {
|
|
3648
|
+
error('Invalid input not EOF');
|
|
3509
3649
|
}
|
|
3510
3650
|
|
|
3511
|
-
|
|
3512
|
-
return color;
|
|
3651
|
+
return ast;
|
|
3513
3652
|
}
|
|
3514
3653
|
|
|
3515
|
-
function
|
|
3516
|
-
return
|
|
3654
|
+
function matchListDefinitions() {
|
|
3655
|
+
return matchListing(matchDefinition);
|
|
3517
3656
|
}
|
|
3518
3657
|
|
|
3519
|
-
function
|
|
3520
|
-
return
|
|
3658
|
+
function matchDefinition() {
|
|
3659
|
+
return matchGradient('linear-gradient', tokens.linearGradient, matchLinearOrientation) || matchGradient('repeating-linear-gradient', tokens.repeatingLinearGradient, matchLinearOrientation) || matchGradient('radial-gradient', tokens.radialGradient, matchListRadialOrientations) || matchGradient('repeating-radial-gradient', tokens.repeatingRadialGradient, matchListRadialOrientations) || matchGradient('conic-gradient', tokens.conicGradient, matchListRadialOrientations);
|
|
3521
3660
|
}
|
|
3522
3661
|
|
|
3523
|
-
function
|
|
3524
|
-
return
|
|
3525
|
-
|
|
3662
|
+
function matchGradient(gradientType, pattern, orientationMatcher) {
|
|
3663
|
+
return matchCall(pattern, function (captures) {
|
|
3664
|
+
var orientation = orientationMatcher();
|
|
3526
3665
|
|
|
3527
|
-
|
|
3528
|
-
|
|
3529
|
-
|
|
3530
|
-
|
|
3531
|
-
|
|
3532
|
-
};
|
|
3533
|
-
});
|
|
3534
|
-
}
|
|
3666
|
+
if (orientation) {
|
|
3667
|
+
if (!scan(tokens.comma)) {
|
|
3668
|
+
error('Missing comma before color stops');
|
|
3669
|
+
}
|
|
3670
|
+
}
|
|
3535
3671
|
|
|
3536
|
-
function matchRGBAColor() {
|
|
3537
|
-
return matchCall(tokens.rgbaColor, function () {
|
|
3538
3672
|
return {
|
|
3539
|
-
type:
|
|
3540
|
-
|
|
3673
|
+
type: gradientType,
|
|
3674
|
+
orientation: orientation,
|
|
3675
|
+
colorStops: matchListing(matchColorStop)
|
|
3541
3676
|
};
|
|
3542
3677
|
});
|
|
3543
3678
|
}
|
|
3544
3679
|
|
|
3545
|
-
function
|
|
3546
|
-
return scan(tokens.number)[1];
|
|
3547
|
-
}
|
|
3548
|
-
|
|
3549
|
-
function matchDistance() {
|
|
3550
|
-
return match('%', tokens.percentageValue, 1) || matchPositionKeyword() || matchLength();
|
|
3551
|
-
}
|
|
3552
|
-
|
|
3553
|
-
function matchPositionKeyword() {
|
|
3554
|
-
return match('position-keyword', tokens.positionKeywords, 1);
|
|
3555
|
-
}
|
|
3556
|
-
|
|
3557
|
-
function matchLength() {
|
|
3558
|
-
return match('px', tokens.pixelValue, 1) || match('em', tokens.emValue, 1);
|
|
3559
|
-
}
|
|
3560
|
-
|
|
3561
|
-
function match(type, pattern, captureIndex) {
|
|
3680
|
+
function matchCall(pattern, callback) {
|
|
3562
3681
|
var captures = scan(pattern);
|
|
3563
3682
|
|
|
3564
3683
|
if (captures) {
|
|
3565
|
-
|
|
3566
|
-
|
|
3567
|
-
|
|
3568
|
-
};
|
|
3569
|
-
}
|
|
3570
|
-
}
|
|
3571
|
-
|
|
3572
|
-
function scan(regexp) {
|
|
3573
|
-
var blankCaptures = /^[\n\r\t\s]+/.exec(input);
|
|
3574
|
-
|
|
3575
|
-
if (blankCaptures) {
|
|
3576
|
-
consume(blankCaptures[0].length);
|
|
3577
|
-
}
|
|
3578
|
-
|
|
3579
|
-
var captures = regexp.exec(input);
|
|
3580
|
-
|
|
3581
|
-
if (captures) {
|
|
3582
|
-
consume(captures[0].length);
|
|
3583
|
-
}
|
|
3584
|
-
|
|
3585
|
-
return captures;
|
|
3586
|
-
}
|
|
3587
|
-
|
|
3588
|
-
function consume(size) {
|
|
3589
|
-
input = input.substring(size);
|
|
3590
|
-
}
|
|
3591
|
-
|
|
3592
|
-
return function (code) {
|
|
3593
|
-
input = code;
|
|
3594
|
-
return getAST();
|
|
3595
|
-
};
|
|
3596
|
-
}();
|
|
3597
|
-
function computeLinearGradient(width, height, angle) {
|
|
3598
|
-
var rad = angle * Math.PI / 180;
|
|
3599
|
-
var rx = 0;
|
|
3600
|
-
var ry = 0;
|
|
3601
|
-
var rcx = rx + width / 2;
|
|
3602
|
-
var rcy = ry + height / 2; // get the length of gradient line
|
|
3603
|
-
// @see https://observablehq.com/@danburzo/css-gradient-line
|
|
3684
|
+
if (!scan(tokens.startCall)) {
|
|
3685
|
+
error('Missing (');
|
|
3686
|
+
}
|
|
3604
3687
|
|
|
3605
|
-
|
|
3606
|
-
var x1 = rcx - Math.cos(rad) * length / 2;
|
|
3607
|
-
var y1 = rcy - Math.sin(rad) * length / 2;
|
|
3608
|
-
var x2 = rcx + Math.cos(rad) * length / 2;
|
|
3609
|
-
var y2 = rcy + Math.sin(rad) * length / 2;
|
|
3610
|
-
return {
|
|
3611
|
-
x1: x1,
|
|
3612
|
-
y1: y1,
|
|
3613
|
-
x2: x2,
|
|
3614
|
-
y2: y2
|
|
3615
|
-
};
|
|
3616
|
-
}
|
|
3617
|
-
function computeRadialGradient(width, height, cx, cy) {
|
|
3618
|
-
var r = Math.sqrt(width * width + height * height) / 2;
|
|
3619
|
-
return {
|
|
3620
|
-
x: cx * width,
|
|
3621
|
-
y: cy * height,
|
|
3622
|
-
r: r
|
|
3623
|
-
};
|
|
3624
|
-
}
|
|
3688
|
+
var result = callback(captures);
|
|
3625
3689
|
|
|
3626
|
-
|
|
3627
|
-
|
|
3628
|
-
|
|
3629
|
-
} else if (angle > 360 || angle < -360) {
|
|
3630
|
-
return angle % 360;
|
|
3631
|
-
}
|
|
3690
|
+
if (!scan(tokens.endCall)) {
|
|
3691
|
+
error('Missing )');
|
|
3692
|
+
}
|
|
3632
3693
|
|
|
3633
|
-
|
|
3634
|
-
}
|
|
3635
|
-
function createVec3(x, y, z) {
|
|
3636
|
-
if (y === void 0) {
|
|
3637
|
-
y = 0;
|
|
3694
|
+
return result;
|
|
3695
|
+
}
|
|
3638
3696
|
}
|
|
3639
3697
|
|
|
3640
|
-
|
|
3641
|
-
|
|
3698
|
+
function matchLinearOrientation() {
|
|
3699
|
+
return matchSideOrCorner() || matchAngle();
|
|
3642
3700
|
}
|
|
3643
3701
|
|
|
3644
|
-
|
|
3645
|
-
return
|
|
3702
|
+
function matchSideOrCorner() {
|
|
3703
|
+
return match('directional', tokens.sideOrCorner, 1);
|
|
3646
3704
|
}
|
|
3647
3705
|
|
|
3648
|
-
|
|
3649
|
-
return
|
|
3706
|
+
function matchAngle() {
|
|
3707
|
+
return match('angular', tokens.angleValue, 1);
|
|
3650
3708
|
}
|
|
3651
3709
|
|
|
3652
|
-
|
|
3653
|
-
|
|
3654
|
-
|
|
3655
|
-
|
|
3656
|
-
}
|
|
3657
|
-
function rad2deg(rad) {
|
|
3658
|
-
return rad * (180 / Math.PI);
|
|
3659
|
-
}
|
|
3660
|
-
function grad2deg(grads) {
|
|
3661
|
-
grads = grads % 400;
|
|
3710
|
+
function matchListRadialOrientations() {
|
|
3711
|
+
var radialOrientations,
|
|
3712
|
+
radialOrientation = matchRadialOrientation(),
|
|
3713
|
+
lookaheadCache;
|
|
3662
3714
|
|
|
3663
|
-
|
|
3664
|
-
|
|
3665
|
-
|
|
3715
|
+
if (radialOrientation) {
|
|
3716
|
+
radialOrientations = [];
|
|
3717
|
+
radialOrientations.push(radialOrientation);
|
|
3718
|
+
lookaheadCache = input;
|
|
3666
3719
|
|
|
3667
|
-
|
|
3668
|
-
|
|
3669
|
-
function deg2turn(deg) {
|
|
3670
|
-
return deg / 360;
|
|
3671
|
-
}
|
|
3672
|
-
function turn2deg(turn) {
|
|
3673
|
-
return 360 * turn;
|
|
3674
|
-
}
|
|
3720
|
+
if (scan(tokens.comma)) {
|
|
3721
|
+
radialOrientation = matchRadialOrientation();
|
|
3675
3722
|
|
|
3676
|
-
|
|
3677
|
-
|
|
3678
|
-
|
|
3679
|
-
|
|
3680
|
-
|
|
3681
|
-
|
|
3682
|
-
|
|
3683
|
-
var z2 = z * z;
|
|
3684
|
-
var w2 = w * w;
|
|
3685
|
-
var unit = x2 + y2 + z2 + w2;
|
|
3686
|
-
var test = x * w - y * z;
|
|
3723
|
+
if (radialOrientation) {
|
|
3724
|
+
radialOrientations.push(radialOrientation);
|
|
3725
|
+
} else {
|
|
3726
|
+
input = lookaheadCache;
|
|
3727
|
+
}
|
|
3728
|
+
}
|
|
3729
|
+
}
|
|
3687
3730
|
|
|
3688
|
-
|
|
3689
|
-
|
|
3690
|
-
// singularity at the north pole
|
|
3691
|
-
out[0] = Math.PI / 2;
|
|
3692
|
-
out[1] = 2 * Math.atan2(y, x);
|
|
3693
|
-
out[2] = 0;
|
|
3694
|
-
} else if (test < -0.499995 * unit) {
|
|
3695
|
-
//TODO: Use glmatrix.EPSILON
|
|
3696
|
-
// singularity at the south pole
|
|
3697
|
-
out[0] = -Math.PI / 2;
|
|
3698
|
-
out[1] = 2 * Math.atan2(y, x);
|
|
3699
|
-
out[2] = 0;
|
|
3700
|
-
} else {
|
|
3701
|
-
out[0] = Math.asin(2 * (x * z - w * y));
|
|
3702
|
-
out[1] = Math.atan2(2 * (x * w + y * z), 1 - 2 * (z2 + w2));
|
|
3703
|
-
out[2] = Math.atan2(2 * (x * y + z * w), 1 - 2 * (y2 + z2));
|
|
3704
|
-
} // TODO: Return them as degrees and not as radians
|
|
3731
|
+
return radialOrientations;
|
|
3732
|
+
}
|
|
3705
3733
|
|
|
3734
|
+
function matchRadialOrientation() {
|
|
3735
|
+
var radialType = matchCircle() || matchEllipse();
|
|
3706
3736
|
|
|
3707
|
-
|
|
3708
|
-
|
|
3737
|
+
if (radialType) {
|
|
3738
|
+
// @ts-ignore
|
|
3739
|
+
radialType.at = matchAtPosition();
|
|
3740
|
+
} else {
|
|
3741
|
+
var extent = matchExtentKeyword();
|
|
3709
3742
|
|
|
3710
|
-
|
|
3711
|
-
|
|
3712
|
-
|
|
3713
|
-
var halfPi = Math.PI * 0.5;
|
|
3743
|
+
if (extent) {
|
|
3744
|
+
radialType = extent;
|
|
3745
|
+
var positionAt = matchAtPosition();
|
|
3714
3746
|
|
|
3715
|
-
|
|
3716
|
-
|
|
3717
|
-
|
|
3718
|
-
|
|
3747
|
+
if (positionAt) {
|
|
3748
|
+
// @ts-ignore
|
|
3749
|
+
radialType.at = positionAt;
|
|
3750
|
+
}
|
|
3751
|
+
} else {
|
|
3752
|
+
var defaultPosition = matchPositioning();
|
|
3719
3753
|
|
|
3720
|
-
|
|
3754
|
+
if (defaultPosition) {
|
|
3755
|
+
radialType = {
|
|
3756
|
+
type: 'default-radial',
|
|
3757
|
+
// @ts-ignore
|
|
3758
|
+
at: defaultPosition
|
|
3759
|
+
};
|
|
3760
|
+
}
|
|
3761
|
+
}
|
|
3762
|
+
}
|
|
3721
3763
|
|
|
3722
|
-
|
|
3723
|
-
|
|
3724
|
-
|
|
3725
|
-
|
|
3726
|
-
|
|
3727
|
-
|
|
3728
|
-
|
|
3729
|
-
|
|
3764
|
+
return radialType;
|
|
3765
|
+
}
|
|
3766
|
+
|
|
3767
|
+
function matchCircle() {
|
|
3768
|
+
var circle = match('shape', /^(circle)/i, 0);
|
|
3769
|
+
|
|
3770
|
+
if (circle) {
|
|
3771
|
+
// @ts-ignore
|
|
3772
|
+
circle.style = matchLength() || matchExtentKeyword();
|
|
3730
3773
|
}
|
|
3731
|
-
|
|
3732
|
-
|
|
3733
|
-
z = 0;
|
|
3734
|
-
x = Math.atan2(m[4] / sy, m[5] / sy);
|
|
3774
|
+
|
|
3775
|
+
return circle;
|
|
3735
3776
|
}
|
|
3736
3777
|
|
|
3737
|
-
|
|
3738
|
-
|
|
3739
|
-
out[2] = z;
|
|
3740
|
-
return out;
|
|
3741
|
-
}
|
|
3742
|
-
/**
|
|
3743
|
-
* @see https://github.com/toji/gl-matrix/issues/329
|
|
3744
|
-
* @see https://doc.babylonjs.com/divingDeeper/mesh/transforms/center_origin/rotation_conventions
|
|
3745
|
-
*/
|
|
3778
|
+
function matchEllipse() {
|
|
3779
|
+
var ellipse = match('shape', /^(ellipse)/i, 0);
|
|
3746
3780
|
|
|
3781
|
+
if (ellipse) {
|
|
3782
|
+
// @ts-ignore
|
|
3783
|
+
ellipse.style = matchDistance() || matchExtentKeyword();
|
|
3784
|
+
}
|
|
3747
3785
|
|
|
3748
|
-
|
|
3749
|
-
if (quat.length === 16) {
|
|
3750
|
-
return getEulerFromMat4(out, quat);
|
|
3751
|
-
} else {
|
|
3752
|
-
return getEulerFromQuat(out, quat);
|
|
3786
|
+
return ellipse;
|
|
3753
3787
|
}
|
|
3754
|
-
}
|
|
3755
|
-
function fromRotationTranslationScale(rotation, x, y, scaleX, scaleY) {
|
|
3756
|
-
var cos = Math.cos(rotation);
|
|
3757
|
-
var sin = Math.sin(rotation);
|
|
3758
|
-
return mat3.fromValues(scaleX * cos, scaleY * sin, 0, -scaleX * sin, scaleY * cos, 0, x, y, 1);
|
|
3759
|
-
}
|
|
3760
|
-
function makePerspective(out, left, right, top, bottom, near, far) {
|
|
3761
|
-
var x = 2 * near / (right - left);
|
|
3762
|
-
var y = 2 * near / (top - bottom);
|
|
3763
|
-
var a = (right + left) / (right - left);
|
|
3764
|
-
var b = (top + bottom) / (top - bottom);
|
|
3765
|
-
var c = -(far + near) / (far - near);
|
|
3766
|
-
var d = -2 * far * near / (far - near);
|
|
3767
|
-
out[0] = x;
|
|
3768
|
-
out[1] = 0;
|
|
3769
|
-
out[2] = 0;
|
|
3770
|
-
out[3] = 0;
|
|
3771
|
-
out[4] = 0;
|
|
3772
|
-
out[5] = y;
|
|
3773
|
-
out[6] = 0;
|
|
3774
|
-
out[7] = 0;
|
|
3775
|
-
out[8] = a;
|
|
3776
|
-
out[9] = b;
|
|
3777
|
-
out[10] = c;
|
|
3778
|
-
out[11] = -1;
|
|
3779
|
-
out[12] = 0;
|
|
3780
|
-
out[13] = 0;
|
|
3781
|
-
out[14] = d;
|
|
3782
|
-
out[15] = 0;
|
|
3783
|
-
return out;
|
|
3784
|
-
}
|
|
3785
|
-
function decompose(mat) {
|
|
3786
|
-
var row0x = mat[0];
|
|
3787
|
-
var row0y = mat[1];
|
|
3788
|
-
var row1x = mat[3];
|
|
3789
|
-
var row1y = mat[4]; // decompose 3x3 matrix
|
|
3790
|
-
// @see https://www.w3.org/TR/css-transforms-1/#decomposing-a-2d-matrix
|
|
3791
3788
|
|
|
3792
|
-
|
|
3793
|
-
|
|
3789
|
+
function matchExtentKeyword() {
|
|
3790
|
+
return match('extent-keyword', tokens.extentKeywords, 1);
|
|
3791
|
+
}
|
|
3794
3792
|
|
|
3795
|
-
|
|
3793
|
+
function matchAtPosition() {
|
|
3794
|
+
if (match('position', /^at/, 0)) {
|
|
3795
|
+
var positioning = matchPositioning();
|
|
3796
3796
|
|
|
3797
|
-
|
|
3798
|
-
|
|
3799
|
-
|
|
3800
|
-
|
|
3801
|
-
|
|
3802
|
-
scalingY = -scalingY;
|
|
3797
|
+
if (!positioning) {
|
|
3798
|
+
error('Missing positioning value');
|
|
3799
|
+
}
|
|
3800
|
+
|
|
3801
|
+
return positioning;
|
|
3803
3802
|
}
|
|
3804
|
-
}
|
|
3803
|
+
}
|
|
3805
3804
|
|
|
3805
|
+
function matchPositioning() {
|
|
3806
|
+
var location = matchCoordinates();
|
|
3806
3807
|
|
|
3807
|
-
|
|
3808
|
-
|
|
3809
|
-
|
|
3808
|
+
if (location.x || location.y) {
|
|
3809
|
+
return {
|
|
3810
|
+
type: 'position',
|
|
3811
|
+
value: location
|
|
3812
|
+
};
|
|
3813
|
+
}
|
|
3810
3814
|
}
|
|
3811
3815
|
|
|
3812
|
-
|
|
3813
|
-
|
|
3814
|
-
|
|
3815
|
-
|
|
3816
|
-
|
|
3816
|
+
function matchCoordinates() {
|
|
3817
|
+
return {
|
|
3818
|
+
x: matchDistance(),
|
|
3819
|
+
y: matchDistance()
|
|
3820
|
+
};
|
|
3821
|
+
}
|
|
3817
3822
|
|
|
3818
|
-
|
|
3819
|
-
|
|
3820
|
-
|
|
3821
|
-
}
|
|
3822
|
-
var tmp = mat4.create();
|
|
3823
|
-
var perspectiveMatrix = mat4.create();
|
|
3824
|
-
var tmpVec4 = vec4.create();
|
|
3825
|
-
var row = [vec3.create(), vec3.create(), vec3.create()];
|
|
3826
|
-
var pdum3 = vec3.create();
|
|
3827
|
-
/*
|
|
3828
|
-
Input: matrix ; a 4x4 matrix
|
|
3829
|
-
Output: translation ; a 3 component vector
|
|
3830
|
-
scale ; a 3 component vector
|
|
3831
|
-
skew ; skew factors XY,XZ,YZ represented as a 3 component vector
|
|
3832
|
-
perspective ; a 4 component vector
|
|
3833
|
-
quaternion ; a 4 component vector
|
|
3834
|
-
Returns false if the matrix cannot be decomposed, true if it can
|
|
3823
|
+
function matchListing(matcher) {
|
|
3824
|
+
var captures = matcher();
|
|
3825
|
+
var result = [];
|
|
3835
3826
|
|
|
3827
|
+
if (captures) {
|
|
3828
|
+
result.push(captures);
|
|
3836
3829
|
|
|
3837
|
-
|
|
3838
|
-
|
|
3839
|
-
https://github.com/ChromiumWebApps/chromium/blob/master/ui/gfx/transform_util.cc
|
|
3840
|
-
http://www.w3.org/TR/css3-transforms/#decomposing-a-3d-matrix
|
|
3841
|
-
*/
|
|
3830
|
+
while (scan(tokens.comma)) {
|
|
3831
|
+
captures = matcher();
|
|
3842
3832
|
|
|
3843
|
-
|
|
3844
|
-
|
|
3845
|
-
|
|
3846
|
-
|
|
3833
|
+
if (captures) {
|
|
3834
|
+
result.push(captures);
|
|
3835
|
+
} else {
|
|
3836
|
+
error('One extra comma');
|
|
3837
|
+
}
|
|
3838
|
+
}
|
|
3839
|
+
}
|
|
3847
3840
|
|
|
3848
|
-
|
|
3849
|
-
|
|
3850
|
-
perspectiveMatrix[7] = 0;
|
|
3851
|
-
perspectiveMatrix[11] = 0;
|
|
3852
|
-
perspectiveMatrix[15] = 1; // If the perspectiveMatrix is not invertible, we are also unable to
|
|
3853
|
-
// decompose, so we'll bail early. Constant taken from SkMatrix44::invert.
|
|
3841
|
+
return result;
|
|
3842
|
+
}
|
|
3854
3843
|
|
|
3855
|
-
|
|
3856
|
-
|
|
3857
|
-
a13 = tmp[7],
|
|
3858
|
-
a23 = tmp[11],
|
|
3859
|
-
a30 = tmp[12],
|
|
3860
|
-
a31 = tmp[13],
|
|
3861
|
-
a32 = tmp[14],
|
|
3862
|
-
a33 = tmp[15]; // First, isolate perspective.
|
|
3844
|
+
function matchColorStop() {
|
|
3845
|
+
var color = matchColor();
|
|
3863
3846
|
|
|
3864
|
-
|
|
3865
|
-
|
|
3866
|
-
|
|
3867
|
-
tmpVec4[2] = a23;
|
|
3868
|
-
tmpVec4[3] = a33; // Solve the equation by inverting perspectiveMatrix and multiplying
|
|
3869
|
-
// rightHandSide by the inverse.
|
|
3870
|
-
// resuing the perspectiveMatrix here since it's no longer needed
|
|
3847
|
+
if (!color) {
|
|
3848
|
+
error('Expected color definition');
|
|
3849
|
+
}
|
|
3871
3850
|
|
|
3872
|
-
|
|
3873
|
-
|
|
3874
|
-
|
|
3851
|
+
color.length = matchDistance();
|
|
3852
|
+
return color;
|
|
3853
|
+
}
|
|
3875
3854
|
|
|
3876
|
-
|
|
3877
|
-
|
|
3878
|
-
|
|
3879
|
-
perspective[0] = perspective[1] = perspective[2] = 0;
|
|
3880
|
-
perspective[3] = 1;
|
|
3881
|
-
} // Next take care of translation
|
|
3855
|
+
function matchColor() {
|
|
3856
|
+
return matchHexColor() || matchRGBAColor() || matchRGBColor() || matchLiteralColor();
|
|
3857
|
+
}
|
|
3882
3858
|
|
|
3859
|
+
function matchLiteralColor() {
|
|
3860
|
+
return match('literal', tokens.literalColor, 0);
|
|
3861
|
+
}
|
|
3883
3862
|
|
|
3884
|
-
|
|
3885
|
-
|
|
3886
|
-
|
|
3863
|
+
function matchHexColor() {
|
|
3864
|
+
return match('hex', tokens.hexColor, 1);
|
|
3865
|
+
}
|
|
3887
3866
|
|
|
3888
|
-
|
|
3867
|
+
function matchRGBColor() {
|
|
3868
|
+
return matchCall(tokens.rgbColor, function () {
|
|
3869
|
+
return {
|
|
3870
|
+
type: 'rgb',
|
|
3871
|
+
value: matchListing(matchNumber)
|
|
3872
|
+
};
|
|
3873
|
+
});
|
|
3874
|
+
}
|
|
3889
3875
|
|
|
3890
|
-
|
|
3891
|
-
|
|
3876
|
+
function matchRGBAColor() {
|
|
3877
|
+
return matchCall(tokens.rgbaColor, function () {
|
|
3878
|
+
return {
|
|
3879
|
+
type: 'rgba',
|
|
3880
|
+
value: matchListing(matchNumber)
|
|
3881
|
+
};
|
|
3882
|
+
});
|
|
3883
|
+
}
|
|
3892
3884
|
|
|
3893
|
-
|
|
3894
|
-
|
|
3885
|
+
function matchNumber() {
|
|
3886
|
+
return scan(tokens.number)[1];
|
|
3887
|
+
}
|
|
3895
3888
|
|
|
3896
|
-
|
|
3897
|
-
|
|
3898
|
-
|
|
3889
|
+
function matchDistance() {
|
|
3890
|
+
return match('%', tokens.percentageValue, 1) || matchPositionKeyword() || matchLength();
|
|
3891
|
+
}
|
|
3899
3892
|
|
|
3900
|
-
|
|
3901
|
-
|
|
3902
|
-
|
|
3903
|
-
combine(row[2], row[2], row[1], 1.0, -skew[2]); // Next, get Z scale and normalize 3rd row.
|
|
3893
|
+
function matchPositionKeyword() {
|
|
3894
|
+
return match('position-keyword', tokens.positionKeywords, 1);
|
|
3895
|
+
}
|
|
3904
3896
|
|
|
3905
|
-
|
|
3906
|
-
|
|
3907
|
-
|
|
3908
|
-
skew[2] /= scale[2]; // At this point, the matrix (in rows) is orthonormal.
|
|
3909
|
-
// Check for a coordinate system flip. If the determinant
|
|
3910
|
-
// is -1, then negate the matrix and the scaling factors.
|
|
3897
|
+
function matchLength() {
|
|
3898
|
+
return match('px', tokens.pixelValue, 1) || match('em', tokens.emValue, 1);
|
|
3899
|
+
}
|
|
3911
3900
|
|
|
3912
|
-
|
|
3901
|
+
function match(type, pattern, captureIndex) {
|
|
3902
|
+
var captures = scan(pattern);
|
|
3913
3903
|
|
|
3914
|
-
|
|
3915
|
-
|
|
3916
|
-
|
|
3917
|
-
|
|
3918
|
-
|
|
3919
|
-
row[i][2] *= -1;
|
|
3904
|
+
if (captures) {
|
|
3905
|
+
return {
|
|
3906
|
+
type: type,
|
|
3907
|
+
value: captures[captureIndex]
|
|
3908
|
+
};
|
|
3920
3909
|
}
|
|
3921
|
-
}
|
|
3910
|
+
}
|
|
3922
3911
|
|
|
3912
|
+
function scan(regexp) {
|
|
3913
|
+
var blankCaptures = /^[\n\r\t\s]+/.exec(input);
|
|
3923
3914
|
|
|
3924
|
-
|
|
3925
|
-
|
|
3926
|
-
|
|
3927
|
-
quaternion[3] = 0.5 * Math.sqrt(Math.max(1 + row[0][0] + row[1][1] + row[2][2], 0));
|
|
3928
|
-
if (row[2][1] > row[1][2]) quaternion[0] = -quaternion[0];
|
|
3929
|
-
if (row[0][2] > row[2][0]) quaternion[1] = -quaternion[1];
|
|
3930
|
-
if (row[1][0] > row[0][1]) quaternion[2] = -quaternion[2];
|
|
3931
|
-
return true;
|
|
3932
|
-
}
|
|
3915
|
+
if (blankCaptures) {
|
|
3916
|
+
consume(blankCaptures[0].length);
|
|
3917
|
+
}
|
|
3933
3918
|
|
|
3934
|
-
|
|
3935
|
-
var m44 = mat[15]; // Cannot normalize.
|
|
3919
|
+
var captures = regexp.exec(input);
|
|
3936
3920
|
|
|
3937
|
-
|
|
3938
|
-
|
|
3921
|
+
if (captures) {
|
|
3922
|
+
consume(captures[0].length);
|
|
3923
|
+
}
|
|
3939
3924
|
|
|
3940
|
-
|
|
3941
|
-
out[i] = mat[i] * scale;
|
|
3925
|
+
return captures;
|
|
3942
3926
|
}
|
|
3943
3927
|
|
|
3944
|
-
|
|
3945
|
-
|
|
3928
|
+
function consume(size) {
|
|
3929
|
+
input = input.substring(size);
|
|
3930
|
+
}
|
|
3946
3931
|
|
|
3932
|
+
return function (code) {
|
|
3933
|
+
input = code;
|
|
3934
|
+
return getAST();
|
|
3935
|
+
};
|
|
3936
|
+
}();
|
|
3937
|
+
function computeLinearGradient(width, height, angle) {
|
|
3938
|
+
var rad = deg2rad(angle.value);
|
|
3939
|
+
var rx = 0;
|
|
3940
|
+
var ry = 0;
|
|
3941
|
+
var rcx = rx + width / 2;
|
|
3942
|
+
var rcy = ry + height / 2; // get the length of gradient line
|
|
3943
|
+
// @see https://observablehq.com/@danburzo/css-gradient-line
|
|
3947
3944
|
|
|
3948
|
-
|
|
3949
|
-
|
|
3950
|
-
|
|
3951
|
-
|
|
3952
|
-
|
|
3953
|
-
|
|
3954
|
-
|
|
3955
|
-
|
|
3956
|
-
|
|
3957
|
-
|
|
3945
|
+
var length = Math.abs(width * Math.cos(rad)) + Math.abs(height * Math.sin(rad));
|
|
3946
|
+
var x1 = rcx - Math.cos(rad) * length / 2;
|
|
3947
|
+
var y1 = rcy - Math.sin(rad) * length / 2;
|
|
3948
|
+
var x2 = rcx + Math.cos(rad) * length / 2;
|
|
3949
|
+
var y2 = rcy + Math.sin(rad) * length / 2;
|
|
3950
|
+
return {
|
|
3951
|
+
x1: x1,
|
|
3952
|
+
y1: y1,
|
|
3953
|
+
x2: x2,
|
|
3954
|
+
y2: y2
|
|
3955
|
+
};
|
|
3958
3956
|
}
|
|
3957
|
+
function computeRadialGradient(width, height, cx, cy, size) {
|
|
3958
|
+
// 'px'
|
|
3959
|
+
var x = cx.value;
|
|
3960
|
+
var y = cy.value; // TODO: 'em'
|
|
3961
|
+
// '%'
|
|
3962
|
+
|
|
3963
|
+
if (cx.unit === UnitType.kPercentage) {
|
|
3964
|
+
x = cx.value / 100 * width;
|
|
3965
|
+
}
|
|
3966
|
+
|
|
3967
|
+
if (cy.unit === UnitType.kPercentage) {
|
|
3968
|
+
y = cy.value / 100 * height;
|
|
3969
|
+
} // default to farthest-side
|
|
3970
|
+
|
|
3971
|
+
|
|
3972
|
+
var r = Math.max(distanceSquareRoot([0, 0], [x, y]), distanceSquareRoot([0, height], [x, y]), distanceSquareRoot([width, height], [x, y]), distanceSquareRoot([width, 0], [x, y]));
|
|
3973
|
+
|
|
3974
|
+
if (size) {
|
|
3975
|
+
if (size instanceof CSSUnitValue) {
|
|
3976
|
+
r = size.value;
|
|
3977
|
+
} else if (size instanceof CSSKeywordValue) {
|
|
3978
|
+
// @see https://developer.mozilla.org/zh-CN/docs/Web/CSS/CSS_Images/Using_CSS_gradients#example_closest-side_for_circles
|
|
3979
|
+
if (size.value === 'closest-side') {
|
|
3980
|
+
r = Math.min(x, width - x, y, height - y);
|
|
3981
|
+
} else if (size.value === 'farthest-side') {
|
|
3982
|
+
r = Math.max(x, width - x, y, height - y);
|
|
3983
|
+
} else if (size.value === 'closest-corner') {
|
|
3984
|
+
r = Math.min(distanceSquareRoot([0, 0], [x, y]), distanceSquareRoot([0, height], [x, y]), distanceSquareRoot([width, height], [x, y]), distanceSquareRoot([width, 0], [x, y]));
|
|
3985
|
+
}
|
|
3986
|
+
}
|
|
3987
|
+
}
|
|
3959
3988
|
|
|
3960
|
-
|
|
3961
|
-
|
|
3962
|
-
|
|
3963
|
-
|
|
3989
|
+
return {
|
|
3990
|
+
x: x,
|
|
3991
|
+
y: y,
|
|
3992
|
+
r: r
|
|
3993
|
+
};
|
|
3964
3994
|
}
|
|
3965
3995
|
|
|
3966
3996
|
var Shape;
|
|
@@ -4298,7 +4328,7 @@ function convertToPath(object, applyLocalTransform) {
|
|
|
4298
4328
|
zCommandIndexes = _object$parsedStyle$p.zCommandIndexes;
|
|
4299
4329
|
commands = [].concat(curve);
|
|
4300
4330
|
zCommandIndexes.forEach(function (zIndex, index) {
|
|
4301
|
-
commands.splice(zIndex + index
|
|
4331
|
+
commands.splice(zIndex + index + 1, 0, ['Z']);
|
|
4302
4332
|
});
|
|
4303
4333
|
break;
|
|
4304
4334
|
}
|
|
@@ -5530,6 +5560,7 @@ function spaceColorStops(colorStops) {
|
|
|
5530
5560
|
for (var i = 1; i < length; i++) {
|
|
5531
5561
|
var _colorStops$i$length;
|
|
5532
5562
|
|
|
5563
|
+
// support '%' & 'px'
|
|
5533
5564
|
var offset = (_colorStops$i$length = colorStops[i].length) === null || _colorStops$i$length === void 0 ? void 0 : _colorStops$i$length.value;
|
|
5534
5565
|
|
|
5535
5566
|
if (!isNil(offset) && !isNil(previousOffset)) {
|
|
@@ -5571,11 +5602,13 @@ var angleToDeg = memoize(function (orientation) {
|
|
|
5571
5602
|
angle = SideOrCornerToDegMap[orientation.value] || 0;
|
|
5572
5603
|
}
|
|
5573
5604
|
|
|
5574
|
-
return angle;
|
|
5605
|
+
return getOrCreateUnitValue(angle, 'deg');
|
|
5575
5606
|
});
|
|
5576
|
-
var
|
|
5577
|
-
var cx =
|
|
5578
|
-
var cy =
|
|
5607
|
+
var positonToCSSUnitValue = memoize(function (position) {
|
|
5608
|
+
var cx = 50;
|
|
5609
|
+
var cy = 50;
|
|
5610
|
+
var unitX = '%';
|
|
5611
|
+
var unitY = '%';
|
|
5579
5612
|
|
|
5580
5613
|
if ((position === null || position === void 0 ? void 0 : position.type) === 'position') {
|
|
5581
5614
|
var _position$value = position.value,
|
|
@@ -5586,13 +5619,13 @@ var positonToPercentage = memoize(function (position) {
|
|
|
5586
5619
|
if (x.value === 'left') {
|
|
5587
5620
|
cx = 0;
|
|
5588
5621
|
} else if (x.value === 'center') {
|
|
5589
|
-
cx =
|
|
5622
|
+
cx = 50;
|
|
5590
5623
|
} else if (x.value === 'right') {
|
|
5591
|
-
cx =
|
|
5624
|
+
cx = 100;
|
|
5592
5625
|
} else if (x.value === 'top') {
|
|
5593
5626
|
cy = 0;
|
|
5594
5627
|
} else if (x.value === 'bottom') {
|
|
5595
|
-
cy =
|
|
5628
|
+
cy = 100;
|
|
5596
5629
|
}
|
|
5597
5630
|
}
|
|
5598
5631
|
|
|
@@ -5600,28 +5633,30 @@ var positonToPercentage = memoize(function (position) {
|
|
|
5600
5633
|
if (y.value === 'left') {
|
|
5601
5634
|
cx = 0;
|
|
5602
5635
|
} else if (y.value === 'center') {
|
|
5603
|
-
cy =
|
|
5636
|
+
cy = 50;
|
|
5604
5637
|
} else if (y.value === 'right') {
|
|
5605
|
-
cx =
|
|
5638
|
+
cx = 100;
|
|
5606
5639
|
} else if (y.value === 'top') {
|
|
5607
5640
|
cy = 0;
|
|
5608
5641
|
} else if (y.value === 'bottom') {
|
|
5609
|
-
cy =
|
|
5642
|
+
cy = 100;
|
|
5610
5643
|
}
|
|
5611
5644
|
}
|
|
5612
5645
|
|
|
5613
|
-
if ((x === null || x === void 0 ? void 0 : x.type) === '%') {
|
|
5614
|
-
|
|
5646
|
+
if ((x === null || x === void 0 ? void 0 : x.type) === 'px' || (x === null || x === void 0 ? void 0 : x.type) === '%' || (x === null || x === void 0 ? void 0 : x.type) === 'em') {
|
|
5647
|
+
unitX = x === null || x === void 0 ? void 0 : x.type;
|
|
5648
|
+
cx = Number(x.value);
|
|
5615
5649
|
}
|
|
5616
5650
|
|
|
5617
|
-
if ((y === null || y === void 0 ? void 0 : y.type) === '%') {
|
|
5618
|
-
|
|
5651
|
+
if ((y === null || y === void 0 ? void 0 : y.type) === 'px' || (y === null || y === void 0 ? void 0 : y.type) === '%' || (y === null || y === void 0 ? void 0 : y.type) === 'em') {
|
|
5652
|
+
unitY = y === null || y === void 0 ? void 0 : y.type;
|
|
5653
|
+
cy = Number(y.value);
|
|
5619
5654
|
}
|
|
5620
5655
|
}
|
|
5621
5656
|
|
|
5622
5657
|
return {
|
|
5623
|
-
cx: cx,
|
|
5624
|
-
cy: cy
|
|
5658
|
+
cx: getOrCreateUnitValue(cx, unitX),
|
|
5659
|
+
cy: getOrCreateUnitValue(cy, unitY)
|
|
5625
5660
|
};
|
|
5626
5661
|
});
|
|
5627
5662
|
var parseGradient$1 = memoize(function (colorStr) {
|
|
@@ -5634,14 +5669,16 @@ var parseGradient$1 = memoize(function (colorStr) {
|
|
|
5634
5669
|
spaceColorStops(colorStops);
|
|
5635
5670
|
var steps = colorStops.map(function (colorStop) {
|
|
5636
5671
|
// TODO: only support % for now, should calc percentage of axis length when using px/em
|
|
5637
|
-
return
|
|
5672
|
+
return {
|
|
5673
|
+
offset: getOrCreateUnitValue(colorStop.length.value, '%'),
|
|
5674
|
+
color: colorStopToString(colorStop)
|
|
5675
|
+
};
|
|
5638
5676
|
});
|
|
5639
5677
|
|
|
5640
5678
|
if (type === 'linear-gradient') {
|
|
5641
5679
|
return new CSSGradientValue(GradientType.LinearGradient, {
|
|
5642
|
-
angle: orientation ? angleToDeg(orientation) :
|
|
5643
|
-
steps: steps
|
|
5644
|
-
hash: colorStr
|
|
5680
|
+
angle: orientation ? angleToDeg(orientation) : Odeg,
|
|
5681
|
+
steps: steps
|
|
5645
5682
|
});
|
|
5646
5683
|
} else if (type === 'radial-gradient') {
|
|
5647
5684
|
if (!orientation) {
|
|
@@ -5652,17 +5689,33 @@ var parseGradient$1 = memoize(function (colorStr) {
|
|
|
5652
5689
|
}
|
|
5653
5690
|
|
|
5654
5691
|
if (orientation[0].type === 'shape' && orientation[0].value === 'circle') {
|
|
5655
|
-
var
|
|
5656
|
-
cx =
|
|
5657
|
-
cy =
|
|
5692
|
+
var _positonToCSSUnitValu = positonToCSSUnitValue(orientation[0].at),
|
|
5693
|
+
cx = _positonToCSSUnitValu.cx,
|
|
5694
|
+
cy = _positonToCSSUnitValu.cy;
|
|
5695
|
+
|
|
5696
|
+
var size;
|
|
5697
|
+
|
|
5698
|
+
if (orientation[0].style) {
|
|
5699
|
+
var _orientation$0$style = orientation[0].style,
|
|
5700
|
+
_type = _orientation$0$style.type,
|
|
5701
|
+
value = _orientation$0$style.value;
|
|
5702
|
+
|
|
5703
|
+
if (_type === 'extent-keyword') {
|
|
5704
|
+
size = getOrCreateKeyword(value);
|
|
5705
|
+
} else {
|
|
5706
|
+
size = getOrCreateUnitValue(value, _type);
|
|
5707
|
+
}
|
|
5708
|
+
}
|
|
5658
5709
|
|
|
5659
5710
|
return new CSSGradientValue(GradientType.RadialGradient, {
|
|
5660
5711
|
cx: cx,
|
|
5661
5712
|
cy: cy,
|
|
5662
|
-
|
|
5663
|
-
|
|
5713
|
+
size: size,
|
|
5714
|
+
steps: steps
|
|
5664
5715
|
});
|
|
5665
|
-
} //
|
|
5716
|
+
} // TODO: support ellipse shape
|
|
5717
|
+
// TODO: repeating-linear-gradient & repeating-radial-gradient
|
|
5718
|
+
// } else if (type === 'repeating-linear-gradient') {
|
|
5666
5719
|
// } else if (type === 'repeating-radial-gradient') {
|
|
5667
5720
|
|
|
5668
5721
|
}
|
|
@@ -5683,13 +5736,15 @@ var parseGradient$1 = memoize(function (colorStr) {
|
|
|
5683
5736
|
return stop.split(':');
|
|
5684
5737
|
})) || [];
|
|
5685
5738
|
return [new CSSGradientValue(GradientType.LinearGradient, {
|
|
5686
|
-
angle: parseFloat(arr[1]),
|
|
5739
|
+
angle: getOrCreateUnitValue(parseFloat(arr[1]), 'deg'),
|
|
5687
5740
|
steps: steps.map(function (_ref2) {
|
|
5688
5741
|
var offset = _ref2[0],
|
|
5689
5742
|
color = _ref2[1];
|
|
5690
|
-
return
|
|
5691
|
-
|
|
5692
|
-
|
|
5743
|
+
return {
|
|
5744
|
+
offset: getOrCreateUnitValue(Number(offset) * 100, '%'),
|
|
5745
|
+
color: color
|
|
5746
|
+
};
|
|
5747
|
+
})
|
|
5693
5748
|
})];
|
|
5694
5749
|
}
|
|
5695
5750
|
} else if (type === 'r') {
|
|
@@ -5718,14 +5773,16 @@ function parseRadialGradient(gradientStr) {
|
|
|
5718
5773
|
return stop.split(':');
|
|
5719
5774
|
})) || [];
|
|
5720
5775
|
return {
|
|
5721
|
-
cx:
|
|
5722
|
-
cy:
|
|
5776
|
+
cx: getOrCreateUnitValue(50, '%'),
|
|
5777
|
+
cy: getOrCreateUnitValue(50, '%'),
|
|
5723
5778
|
steps: steps.map(function (_ref3) {
|
|
5724
5779
|
var offset = _ref3[0],
|
|
5725
5780
|
color = _ref3[1];
|
|
5726
|
-
return
|
|
5727
|
-
|
|
5728
|
-
|
|
5781
|
+
return {
|
|
5782
|
+
offset: getOrCreateUnitValue(Number(offset) * 100, '%'),
|
|
5783
|
+
color: color
|
|
5784
|
+
};
|
|
5785
|
+
})
|
|
5729
5786
|
};
|
|
5730
5787
|
}
|
|
5731
5788
|
|
|
@@ -9367,7 +9424,10 @@ MutationEvent.ADDITION = 2;
|
|
|
9367
9424
|
MutationEvent.MODIFICATION = 1;
|
|
9368
9425
|
MutationEvent.REMOVAL = 3;
|
|
9369
9426
|
|
|
9370
|
-
var entityCounter = 0;
|
|
9427
|
+
var entityCounter = 0;
|
|
9428
|
+
function resetEntityCounter() {
|
|
9429
|
+
entityCounter = 0;
|
|
9430
|
+
} // let this.sceneGraphService: SceneGraphService;
|
|
9371
9431
|
|
|
9372
9432
|
var childInsertedEvent = new CustomEvent(ElementEvent.CHILD_INSERTED, {
|
|
9373
9433
|
child: null
|
|
@@ -17762,6 +17822,35 @@ var EventPlugin = EventPlugin_1 = (_class$2 = /*#__PURE__*/function () {
|
|
|
17762
17822
|
renderingService.hooks.pointerOut.tap(EventPlugin_1.tag, this.onPointerMove);
|
|
17763
17823
|
};
|
|
17764
17824
|
|
|
17825
|
+
_proto.getViewportXY = function getViewportXY(nativeEvent) {
|
|
17826
|
+
var x;
|
|
17827
|
+
var y;
|
|
17828
|
+
/**
|
|
17829
|
+
* Should account for CSS Transform applied on container.
|
|
17830
|
+
* @see https://github.com/antvis/G/issues/1161
|
|
17831
|
+
* @see https://developer.mozilla.org/zh-CN/docs/Web/API/MouseEvent/offsetX
|
|
17832
|
+
*/
|
|
17833
|
+
|
|
17834
|
+
var offsetX = nativeEvent.offsetX,
|
|
17835
|
+
offsetY = nativeEvent.offsetY,
|
|
17836
|
+
clientX = nativeEvent.clientX,
|
|
17837
|
+
clientY = nativeEvent.clientY;
|
|
17838
|
+
|
|
17839
|
+
if (this.canvasConfig.supportsCSSTransform && !isNil(offsetX) && !isNil(offsetY)) {
|
|
17840
|
+
x = offsetX;
|
|
17841
|
+
y = offsetY;
|
|
17842
|
+
} else {
|
|
17843
|
+
var point = this.eventService.client2Viewport(new Point(clientX, clientY));
|
|
17844
|
+
x = point.x;
|
|
17845
|
+
y = point.y;
|
|
17846
|
+
}
|
|
17847
|
+
|
|
17848
|
+
return {
|
|
17849
|
+
x: x,
|
|
17850
|
+
y: y
|
|
17851
|
+
};
|
|
17852
|
+
};
|
|
17853
|
+
|
|
17765
17854
|
_proto.bootstrapEvent = function bootstrapEvent(event, nativeEvent, view) {
|
|
17766
17855
|
event.view = view;
|
|
17767
17856
|
event.originalEvent = null;
|
|
@@ -17778,9 +17867,9 @@ var EventPlugin = EventPlugin_1 = (_class$2 = /*#__PURE__*/function () {
|
|
|
17778
17867
|
event.twist = nativeEvent.twist;
|
|
17779
17868
|
this.transferMouseData(event, nativeEvent);
|
|
17780
17869
|
|
|
17781
|
-
var _this$
|
|
17782
|
-
x = _this$
|
|
17783
|
-
y = _this$
|
|
17870
|
+
var _this$getViewportXY = this.getViewportXY(nativeEvent),
|
|
17871
|
+
x = _this$getViewportXY.x,
|
|
17872
|
+
y = _this$getViewportXY.y;
|
|
17784
17873
|
|
|
17785
17874
|
event.viewport.x = x;
|
|
17786
17875
|
event.viewport.y = y;
|
|
@@ -17818,9 +17907,9 @@ var EventPlugin = EventPlugin_1 = (_class$2 = /*#__PURE__*/function () {
|
|
|
17818
17907
|
event.deltaY = nativeEvent.deltaY;
|
|
17819
17908
|
event.deltaZ = nativeEvent.deltaZ;
|
|
17820
17909
|
|
|
17821
|
-
var _this$
|
|
17822
|
-
x = _this$
|
|
17823
|
-
y = _this$
|
|
17910
|
+
var _this$getViewportXY2 = this.getViewportXY(nativeEvent),
|
|
17911
|
+
x = _this$getViewportXY2.x,
|
|
17912
|
+
y = _this$getViewportXY2.y;
|
|
17824
17913
|
|
|
17825
17914
|
event.viewport.x = x;
|
|
17826
17915
|
event.viewport.y = y;
|
|
@@ -18362,6 +18451,7 @@ var Canvas = /*#__PURE__*/function (_EventTarget) {
|
|
|
18362
18451
|
createImage = config.createImage,
|
|
18363
18452
|
supportsPointerEvents = config.supportsPointerEvents,
|
|
18364
18453
|
supportsTouchEvents = config.supportsTouchEvents,
|
|
18454
|
+
supportsCSSTransform = config.supportsCSSTransform,
|
|
18365
18455
|
isTouchEvent = config.isTouchEvent,
|
|
18366
18456
|
isMouseEvent = config.isMouseEvent;
|
|
18367
18457
|
cleanExistedCanvas(container, _assertThisInitialized(_this));
|
|
@@ -18410,7 +18500,8 @@ var Canvas = /*#__PURE__*/function (_EventTarget) {
|
|
|
18410
18500
|
cursor: cursor || 'default',
|
|
18411
18501
|
background: background || 'transparent',
|
|
18412
18502
|
createImage: createImage,
|
|
18413
|
-
document: document
|
|
18503
|
+
document: document,
|
|
18504
|
+
supportsCSSTransform: supportsCSSTransform
|
|
18414
18505
|
});
|
|
18415
18506
|
|
|
18416
18507
|
_this.initDefaultCamera(canvasWidth, canvasHeight);
|
|
@@ -18912,4 +19003,4 @@ GlobalContainer.load(containerModule); // export const sceneGraphService = Globa
|
|
|
18912
19003
|
|
|
18913
19004
|
var styleValueRegistry = GlobalContainer.get(StyleValueRegistry); // export const displayObjectPool = GlobalContainer.get(DisplayObjectPool);
|
|
18914
19005
|
|
|
18915
|
-
export { AABB, AbstractRenderer, AbstractRendererPlugin, AnimationTimelineToken, BUILT_IN_PROPERTIES, CSS, CSSGradientValue, CSSKeywordValue, CSSRGB, CSSStyleValue, CSSUnitValue, Camera, CameraContribution, CameraEvent, CameraProjectionMode, CameraTrackingMode, CameraType, Canvas, CanvasConfig, CanvasEvent, Circle, CircleUpdater, ContextService, CustomElement, CustomElementRegistry, CustomEvent, DefaultCamera, DefaultSceneGraphSelector, DefaultSceneGraphService, DisplayObject, DisplayObjectPool, Document, ERROR_MSG_METHOD_NOT_IMPLEMENTED, Element, ElementEvent, Ellipse, EllipseUpdater, EventService, EventTarget, FederatedEvent, FederatedMouseEvent, FederatedPointerEvent, FederatedWheelEvent, Frustum, GeometryAABBUpdater, GeometryUpdaterFactory, GradientType, Group, HTML, Image, LayoutRegistry, Line, LineUpdater, Mask, MutationEvent, Node, OffscreenCanvasCreator, ParseEasingFunction, Path, PathUpdater, Plane, Point, Polygon, Polyline, PolylineUpdater, PropertySyntax, RBushRoot, Rect, RectUpdater, Rectangle, RenderReason, RenderingContext, RenderingPluginContribution, RenderingService, SceneGraphSelector, SceneGraphSelectorFactory, SceneGraphService, Shape, Strategy, StyleValueRegistry, Text, TextService, TextUpdater, UnitType, computeLinearGradient, computeRadialGradient, convertToPath, createVec3, decompose, definedProps, deg2rad, deg2turn, findClosestClipPathTarget, getAngle, getEuler, getOrCalculatePathTotalLength, grad2deg, isBrowser, isFillOrStrokeAffected, isPattern, mergeColors, parseColor, parseLength, parsePath, propertyMetadataCache, rad2deg, setDOMSize, styleValueRegistry, translatePathToString, turn2deg };
|
|
19006
|
+
export { AABB, AbstractRenderer, AbstractRendererPlugin, AnimationTimelineToken, BUILT_IN_PROPERTIES, CSS, CSSGradientValue, CSSKeywordValue, CSSRGB, CSSStyleValue, CSSUnitValue, Camera, CameraContribution, CameraEvent, CameraProjectionMode, CameraTrackingMode, CameraType, Canvas, CanvasConfig, CanvasEvent, Circle, CircleUpdater, ContextService, CustomElement, CustomElementRegistry, CustomEvent, DefaultCamera, DefaultSceneGraphSelector, DefaultSceneGraphService, DisplayObject, DisplayObjectPool, Document, ERROR_MSG_METHOD_NOT_IMPLEMENTED, Element, ElementEvent, Ellipse, EllipseUpdater, EventService, EventTarget, FederatedEvent, FederatedMouseEvent, FederatedPointerEvent, FederatedWheelEvent, Frustum, GeometryAABBUpdater, GeometryUpdaterFactory, GradientType, Group, HTML, Image, LayoutRegistry, Line, LineUpdater, Mask, MutationEvent, Node, OffscreenCanvasCreator, ParseEasingFunction, Path, PathUpdater, Plane, Point, Polygon, Polyline, PolylineUpdater, PropertySyntax, RBushRoot, Rect, RectUpdater, Rectangle, RenderReason, RenderingContext, RenderingPluginContribution, RenderingService, SceneGraphSelector, SceneGraphSelectorFactory, SceneGraphService, Shape, Strategy, StyleValueRegistry, Text, TextService, TextUpdater, UnitType, computeLinearGradient, computeRadialGradient, convertToPath, createVec3, decompose, definedProps, deg2rad, deg2turn, findClosestClipPathTarget, getAngle, getEuler, getOrCalculatePathTotalLength, grad2deg, isBrowser, isFillOrStrokeAffected, isPattern, mergeColors, parseColor, parseLength, parsePath, propertyMetadataCache, rad2deg, resetEntityCounter, setDOMSize, styleValueRegistry, translatePathToString, turn2deg };
|