@antv/g-lite 1.0.6 → 1.0.7
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/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 +704 -613
- package/dist/index.js +703 -611
- package/dist/index.umd.js +703 -611
- 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.js
CHANGED
|
@@ -3246,717 +3246,747 @@ var TOUCH_TO_POINTER = {
|
|
|
3246
3246
|
touchcancel: 'pointercancel'
|
|
3247
3247
|
};
|
|
3248
3248
|
|
|
3249
|
-
|
|
3250
|
-
|
|
3251
|
-
|
|
3252
|
-
|
|
3253
|
-
|
|
3254
|
-
var type = colorStop.type,
|
|
3255
|
-
value = colorStop.value;
|
|
3256
|
-
|
|
3257
|
-
if (type === 'hex') {
|
|
3258
|
-
return "#" + value;
|
|
3259
|
-
} else if (type === 'literal') {
|
|
3260
|
-
return value;
|
|
3261
|
-
} else if (type === 'rgb') {
|
|
3262
|
-
return "rgb(" + value.join(',') + ")";
|
|
3263
|
-
} else {
|
|
3264
|
-
return "rgba(" + value.join(',') + ")";
|
|
3249
|
+
function getAngle(angle) {
|
|
3250
|
+
if (angle === undefined) {
|
|
3251
|
+
return 0;
|
|
3252
|
+
} else if (angle > 360 || angle < -360) {
|
|
3253
|
+
return angle % 360;
|
|
3265
3254
|
}
|
|
3266
|
-
}
|
|
3267
|
-
var parseGradient = function () {
|
|
3268
|
-
var tokens = {
|
|
3269
|
-
linearGradient: /^(linear\-gradient)/i,
|
|
3270
|
-
repeatingLinearGradient: /^(repeating\-linear\-gradient)/i,
|
|
3271
|
-
radialGradient: /^(radial\-gradient)/i,
|
|
3272
|
-
repeatingRadialGradient: /^(repeating\-radial\-gradient)/i,
|
|
3273
|
-
|
|
3274
|
-
/**
|
|
3275
|
-
* @see https://projects.verou.me/conic-gradient/
|
|
3276
|
-
*/
|
|
3277
|
-
conicGradient: /^(conic\-gradient)/i,
|
|
3278
|
-
sideOrCorner: /^to (left (top|bottom)|right (top|bottom)|top (left|right)|bottom (left|right)|left|right|top|bottom)/i,
|
|
3279
|
-
extentKeywords: /^(closest\-side|closest\-corner|farthest\-side|farthest\-corner|contain|cover)/,
|
|
3280
|
-
positionKeywords: /^(left|center|right|top|bottom)/i,
|
|
3281
|
-
pixelValue: /^(-?(([0-9]*\.[0-9]+)|([0-9]+\.?)))px/,
|
|
3282
|
-
percentageValue: /^(-?(([0-9]*\.[0-9]+)|([0-9]+\.?)))\%/,
|
|
3283
|
-
emValue: /^(-?(([0-9]*\.[0-9]+)|([0-9]+\.?)))em/,
|
|
3284
|
-
angleValue: /^(-?(([0-9]*\.[0-9]+)|([0-9]+\.?)))deg/,
|
|
3285
|
-
startCall: /^\(/,
|
|
3286
|
-
endCall: /^\)/,
|
|
3287
|
-
comma: /^,/,
|
|
3288
|
-
hexColor: /^\#([0-9a-fA-F]+)/,
|
|
3289
|
-
literalColor: /^([a-zA-Z]+)/,
|
|
3290
|
-
rgbColor: /^rgb/i,
|
|
3291
|
-
rgbaColor: /^rgba/i,
|
|
3292
|
-
number: /^(([0-9]*\.[0-9]+)|([0-9]+\.?))/
|
|
3293
|
-
};
|
|
3294
|
-
var input = '';
|
|
3295
3255
|
|
|
3296
|
-
|
|
3297
|
-
|
|
3256
|
+
return angle;
|
|
3257
|
+
}
|
|
3258
|
+
function createVec3(x, y, z) {
|
|
3259
|
+
if (y === void 0) {
|
|
3260
|
+
y = 0;
|
|
3298
3261
|
}
|
|
3299
3262
|
|
|
3300
|
-
|
|
3301
|
-
|
|
3302
|
-
|
|
3303
|
-
if (input.length > 0) {
|
|
3304
|
-
error('Invalid input not EOF');
|
|
3305
|
-
}
|
|
3263
|
+
if (z === void 0) {
|
|
3264
|
+
z = 0;
|
|
3265
|
+
}
|
|
3306
3266
|
|
|
3307
|
-
|
|
3267
|
+
if (util.isNumber(x)) {
|
|
3268
|
+
return glMatrix.vec3.fromValues(x, y, z);
|
|
3308
3269
|
}
|
|
3309
3270
|
|
|
3310
|
-
|
|
3311
|
-
return
|
|
3271
|
+
if (Array.isArray(x) && x.length === 3) {
|
|
3272
|
+
return glMatrix.vec3.clone(x);
|
|
3312
3273
|
}
|
|
3313
3274
|
|
|
3314
|
-
|
|
3315
|
-
|
|
3275
|
+
return glMatrix.vec3.fromValues(x[0], x[1] || y, x[2] || z);
|
|
3276
|
+
}
|
|
3277
|
+
function deg2rad(deg) {
|
|
3278
|
+
return deg * (Math.PI / 180);
|
|
3279
|
+
}
|
|
3280
|
+
function rad2deg(rad) {
|
|
3281
|
+
return rad * (180 / Math.PI);
|
|
3282
|
+
}
|
|
3283
|
+
function grad2deg(grads) {
|
|
3284
|
+
grads = grads % 400;
|
|
3285
|
+
|
|
3286
|
+
if (grads < 0) {
|
|
3287
|
+
grads += 400;
|
|
3316
3288
|
}
|
|
3317
3289
|
|
|
3318
|
-
|
|
3319
|
-
|
|
3320
|
-
|
|
3290
|
+
return grads / 400 * 360;
|
|
3291
|
+
}
|
|
3292
|
+
function deg2turn(deg) {
|
|
3293
|
+
return deg / 360;
|
|
3294
|
+
}
|
|
3295
|
+
function turn2deg(turn) {
|
|
3296
|
+
return 360 * turn;
|
|
3297
|
+
}
|
|
3321
3298
|
|
|
3322
|
-
|
|
3323
|
-
|
|
3324
|
-
|
|
3325
|
-
|
|
3326
|
-
|
|
3299
|
+
function getEulerFromQuat(out, quat) {
|
|
3300
|
+
var x = quat[0];
|
|
3301
|
+
var y = quat[1];
|
|
3302
|
+
var z = quat[2];
|
|
3303
|
+
var w = quat[3];
|
|
3304
|
+
var x2 = x * x;
|
|
3305
|
+
var y2 = y * y;
|
|
3306
|
+
var z2 = z * z;
|
|
3307
|
+
var w2 = w * w;
|
|
3308
|
+
var unit = x2 + y2 + z2 + w2;
|
|
3309
|
+
var test = x * w - y * z;
|
|
3327
3310
|
|
|
3328
|
-
|
|
3329
|
-
|
|
3330
|
-
|
|
3331
|
-
|
|
3332
|
-
|
|
3333
|
-
|
|
3334
|
-
}
|
|
3311
|
+
if (test > 0.499995 * unit) {
|
|
3312
|
+
// TODO: Use glmatrix.EPSILON
|
|
3313
|
+
// singularity at the north pole
|
|
3314
|
+
out[0] = Math.PI / 2;
|
|
3315
|
+
out[1] = 2 * Math.atan2(y, x);
|
|
3316
|
+
out[2] = 0;
|
|
3317
|
+
} else if (test < -0.499995 * unit) {
|
|
3318
|
+
//TODO: Use glmatrix.EPSILON
|
|
3319
|
+
// singularity at the south pole
|
|
3320
|
+
out[0] = -Math.PI / 2;
|
|
3321
|
+
out[1] = 2 * Math.atan2(y, x);
|
|
3322
|
+
out[2] = 0;
|
|
3323
|
+
} else {
|
|
3324
|
+
out[0] = Math.asin(2 * (x * z - w * y));
|
|
3325
|
+
out[1] = Math.atan2(2 * (x * w + y * z), 1 - 2 * (z2 + w2));
|
|
3326
|
+
out[2] = Math.atan2(2 * (x * y + z * w), 1 - 2 * (y2 + z2));
|
|
3327
|
+
} // TODO: Return them as degrees and not as radians
|
|
3335
3328
|
|
|
3336
|
-
function matchCall(pattern, callback) {
|
|
3337
|
-
var captures = scan(pattern);
|
|
3338
3329
|
|
|
3339
|
-
|
|
3340
|
-
|
|
3341
|
-
error('Missing (');
|
|
3342
|
-
}
|
|
3330
|
+
return out;
|
|
3331
|
+
}
|
|
3343
3332
|
|
|
3344
|
-
|
|
3333
|
+
function getEulerFromMat4(out, m) {
|
|
3334
|
+
var x;
|
|
3335
|
+
var z;
|
|
3336
|
+
var halfPi = Math.PI * 0.5;
|
|
3345
3337
|
|
|
3346
|
-
|
|
3347
|
-
|
|
3348
|
-
|
|
3338
|
+
var _mat4$getScaling = glMatrix.mat4.getScaling(glMatrix.vec3.create(), m),
|
|
3339
|
+
sx = _mat4$getScaling[0],
|
|
3340
|
+
sy = _mat4$getScaling[1],
|
|
3341
|
+
sz = _mat4$getScaling[2];
|
|
3349
3342
|
|
|
3350
|
-
|
|
3343
|
+
var y = Math.asin(-m[2] / sx);
|
|
3344
|
+
|
|
3345
|
+
if (y < halfPi) {
|
|
3346
|
+
if (y > -halfPi) {
|
|
3347
|
+
x = Math.atan2(m[6] / sy, m[10] / sz);
|
|
3348
|
+
z = Math.atan2(m[1] / sx, m[0] / sx);
|
|
3349
|
+
} else {
|
|
3350
|
+
// Not a unique solution
|
|
3351
|
+
z = 0;
|
|
3352
|
+
x = -Math.atan2(m[4] / sy, m[5] / sy);
|
|
3351
3353
|
}
|
|
3354
|
+
} else {
|
|
3355
|
+
// Not a unique solution
|
|
3356
|
+
z = 0;
|
|
3357
|
+
x = Math.atan2(m[4] / sy, m[5] / sy);
|
|
3352
3358
|
}
|
|
3353
3359
|
|
|
3354
|
-
|
|
3355
|
-
|
|
3356
|
-
|
|
3360
|
+
out[0] = x;
|
|
3361
|
+
out[1] = y;
|
|
3362
|
+
out[2] = z;
|
|
3363
|
+
return out;
|
|
3364
|
+
}
|
|
3365
|
+
/**
|
|
3366
|
+
* @see https://github.com/toji/gl-matrix/issues/329
|
|
3367
|
+
* @see https://doc.babylonjs.com/divingDeeper/mesh/transforms/center_origin/rotation_conventions
|
|
3368
|
+
*/
|
|
3357
3369
|
|
|
3358
|
-
function matchSideOrCorner() {
|
|
3359
|
-
return match('directional', tokens.sideOrCorner, 1);
|
|
3360
|
-
}
|
|
3361
3370
|
|
|
3362
|
-
|
|
3363
|
-
|
|
3371
|
+
function getEuler(out, quat) {
|
|
3372
|
+
if (quat.length === 16) {
|
|
3373
|
+
return getEulerFromMat4(out, quat);
|
|
3374
|
+
} else {
|
|
3375
|
+
return getEulerFromQuat(out, quat);
|
|
3364
3376
|
}
|
|
3377
|
+
}
|
|
3378
|
+
function fromRotationTranslationScale(rotation, x, y, scaleX, scaleY) {
|
|
3379
|
+
var cos = Math.cos(rotation);
|
|
3380
|
+
var sin = Math.sin(rotation);
|
|
3381
|
+
return glMatrix.mat3.fromValues(scaleX * cos, scaleY * sin, 0, -scaleX * sin, scaleY * cos, 0, x, y, 1);
|
|
3382
|
+
}
|
|
3383
|
+
function makePerspective(out, left, right, top, bottom, near, far) {
|
|
3384
|
+
var x = 2 * near / (right - left);
|
|
3385
|
+
var y = 2 * near / (top - bottom);
|
|
3386
|
+
var a = (right + left) / (right - left);
|
|
3387
|
+
var b = (top + bottom) / (top - bottom);
|
|
3388
|
+
var c = -(far + near) / (far - near);
|
|
3389
|
+
var d = -2 * far * near / (far - near);
|
|
3390
|
+
out[0] = x;
|
|
3391
|
+
out[1] = 0;
|
|
3392
|
+
out[2] = 0;
|
|
3393
|
+
out[3] = 0;
|
|
3394
|
+
out[4] = 0;
|
|
3395
|
+
out[5] = y;
|
|
3396
|
+
out[6] = 0;
|
|
3397
|
+
out[7] = 0;
|
|
3398
|
+
out[8] = a;
|
|
3399
|
+
out[9] = b;
|
|
3400
|
+
out[10] = c;
|
|
3401
|
+
out[11] = -1;
|
|
3402
|
+
out[12] = 0;
|
|
3403
|
+
out[13] = 0;
|
|
3404
|
+
out[14] = d;
|
|
3405
|
+
out[15] = 0;
|
|
3406
|
+
return out;
|
|
3407
|
+
}
|
|
3408
|
+
function decompose(mat) {
|
|
3409
|
+
var row0x = mat[0];
|
|
3410
|
+
var row0y = mat[1];
|
|
3411
|
+
var row1x = mat[3];
|
|
3412
|
+
var row1y = mat[4]; // decompose 3x3 matrix
|
|
3413
|
+
// @see https://www.w3.org/TR/css-transforms-1/#decomposing-a-2d-matrix
|
|
3365
3414
|
|
|
3366
|
-
|
|
3367
|
-
|
|
3368
|
-
radialOrientation = matchRadialOrientation(),
|
|
3369
|
-
lookaheadCache;
|
|
3370
|
-
|
|
3371
|
-
if (radialOrientation) {
|
|
3372
|
-
radialOrientations = [];
|
|
3373
|
-
radialOrientations.push(radialOrientation);
|
|
3374
|
-
lookaheadCache = input;
|
|
3415
|
+
var scalingX = Math.sqrt(row0x * row0x + row0y * row0y);
|
|
3416
|
+
var scalingY = Math.sqrt(row1x * row1x + row1y * row1y); // If determinant is negative, one axis was flipped.
|
|
3375
3417
|
|
|
3376
|
-
|
|
3377
|
-
radialOrientation = matchRadialOrientation();
|
|
3418
|
+
var determinant = row0x * row1y - row0y * row1x;
|
|
3378
3419
|
|
|
3379
|
-
|
|
3380
|
-
|
|
3381
|
-
|
|
3382
|
-
|
|
3383
|
-
|
|
3384
|
-
|
|
3420
|
+
if (determinant < 0) {
|
|
3421
|
+
// Flip axis with minimum unit vector dot product.
|
|
3422
|
+
if (row0x < row1y) {
|
|
3423
|
+
scalingX = -scalingX;
|
|
3424
|
+
} else {
|
|
3425
|
+
scalingY = -scalingY;
|
|
3385
3426
|
}
|
|
3427
|
+
} // Renormalize matrix to remove scale.
|
|
3386
3428
|
|
|
3387
|
-
|
|
3429
|
+
|
|
3430
|
+
if (scalingX) {
|
|
3431
|
+
row0x *= 1 / scalingX;
|
|
3432
|
+
row0y *= 1 / scalingX;
|
|
3388
3433
|
}
|
|
3389
3434
|
|
|
3390
|
-
|
|
3391
|
-
|
|
3435
|
+
if (scalingY) {
|
|
3436
|
+
row1x *= 1 / scalingY;
|
|
3437
|
+
row1y *= 1 / scalingY;
|
|
3438
|
+
} // Compute rotation and renormalize matrix.
|
|
3392
3439
|
|
|
3393
|
-
if (radialType) {
|
|
3394
|
-
// @ts-ignore
|
|
3395
|
-
radialType.at = matchAtPosition();
|
|
3396
|
-
} else {
|
|
3397
|
-
var extent = matchExtentKeyword();
|
|
3398
3440
|
|
|
3399
|
-
|
|
3400
|
-
|
|
3401
|
-
|
|
3441
|
+
var rotation = Math.atan2(row0y, row0x);
|
|
3442
|
+
var angle = rad2deg(rotation);
|
|
3443
|
+
return [mat[6], mat[7], scalingX, scalingY, angle];
|
|
3444
|
+
}
|
|
3445
|
+
var tmp = glMatrix.mat4.create();
|
|
3446
|
+
var perspectiveMatrix = glMatrix.mat4.create();
|
|
3447
|
+
var tmpVec4 = glMatrix.vec4.create();
|
|
3448
|
+
var row = [glMatrix.vec3.create(), glMatrix.vec3.create(), glMatrix.vec3.create()];
|
|
3449
|
+
var pdum3 = glMatrix.vec3.create();
|
|
3450
|
+
/*
|
|
3451
|
+
Input: matrix ; a 4x4 matrix
|
|
3452
|
+
Output: translation ; a 3 component vector
|
|
3453
|
+
scale ; a 3 component vector
|
|
3454
|
+
skew ; skew factors XY,XZ,YZ represented as a 3 component vector
|
|
3455
|
+
perspective ; a 4 component vector
|
|
3456
|
+
quaternion ; a 4 component vector
|
|
3457
|
+
Returns false if the matrix cannot be decomposed, true if it can
|
|
3402
3458
|
|
|
3403
|
-
if (positionAt) {
|
|
3404
|
-
// @ts-ignore
|
|
3405
|
-
radialType.at = positionAt;
|
|
3406
|
-
}
|
|
3407
|
-
} else {
|
|
3408
|
-
var defaultPosition = matchPositioning();
|
|
3409
3459
|
|
|
3410
|
-
|
|
3411
|
-
|
|
3412
|
-
|
|
3413
|
-
|
|
3414
|
-
|
|
3415
|
-
};
|
|
3416
|
-
}
|
|
3417
|
-
}
|
|
3418
|
-
}
|
|
3460
|
+
References:
|
|
3461
|
+
https://github.com/kamicane/matrix3d/blob/master/lib/Matrix3d.js
|
|
3462
|
+
https://github.com/ChromiumWebApps/chromium/blob/master/ui/gfx/transform_util.cc
|
|
3463
|
+
http://www.w3.org/TR/css3-transforms/#decomposing-a-3d-matrix
|
|
3464
|
+
*/
|
|
3419
3465
|
|
|
3420
|
-
|
|
3421
|
-
|
|
3466
|
+
function decomposeMat4(matrix, translation, scale, skew, perspective, quaternion) {
|
|
3467
|
+
//normalize, if not possible then bail out early
|
|
3468
|
+
if (!normalize(tmp, matrix)) return false; // perspectiveMatrix is used to solve for perspective, but it also provides
|
|
3469
|
+
// an easy way to test for singularity of the upper 3x3 component.
|
|
3422
3470
|
|
|
3423
|
-
|
|
3424
|
-
|
|
3471
|
+
glMatrix.mat4.copy(perspectiveMatrix, tmp);
|
|
3472
|
+
perspectiveMatrix[3] = 0;
|
|
3473
|
+
perspectiveMatrix[7] = 0;
|
|
3474
|
+
perspectiveMatrix[11] = 0;
|
|
3475
|
+
perspectiveMatrix[15] = 1; // If the perspectiveMatrix is not invertible, we are also unable to
|
|
3476
|
+
// decompose, so we'll bail early. Constant taken from SkMatrix44::invert.
|
|
3425
3477
|
|
|
3426
|
-
|
|
3427
|
-
|
|
3428
|
-
|
|
3429
|
-
|
|
3478
|
+
if (Math.abs(glMatrix.mat4.determinant(perspectiveMatrix)) < 1e-8) return false;
|
|
3479
|
+
var a03 = tmp[3],
|
|
3480
|
+
a13 = tmp[7],
|
|
3481
|
+
a23 = tmp[11],
|
|
3482
|
+
a30 = tmp[12],
|
|
3483
|
+
a31 = tmp[13],
|
|
3484
|
+
a32 = tmp[14],
|
|
3485
|
+
a33 = tmp[15]; // First, isolate perspective.
|
|
3430
3486
|
|
|
3431
|
-
|
|
3432
|
-
|
|
3487
|
+
if (a03 !== 0 || a13 !== 0 || a23 !== 0) {
|
|
3488
|
+
tmpVec4[0] = a03;
|
|
3489
|
+
tmpVec4[1] = a13;
|
|
3490
|
+
tmpVec4[2] = a23;
|
|
3491
|
+
tmpVec4[3] = a33; // Solve the equation by inverting perspectiveMatrix and multiplying
|
|
3492
|
+
// rightHandSide by the inverse.
|
|
3493
|
+
// resuing the perspectiveMatrix here since it's no longer needed
|
|
3494
|
+
|
|
3495
|
+
var ret = glMatrix.mat4.invert(perspectiveMatrix, perspectiveMatrix);
|
|
3496
|
+
if (!ret) return false;
|
|
3497
|
+
glMatrix.mat4.transpose(perspectiveMatrix, perspectiveMatrix); //multiply by transposed inverse perspective matrix, into perspective vec4
|
|
3498
|
+
|
|
3499
|
+
glMatrix.vec4.transformMat4(perspective, tmpVec4, perspectiveMatrix);
|
|
3500
|
+
} else {
|
|
3501
|
+
//no perspective
|
|
3502
|
+
perspective[0] = perspective[1] = perspective[2] = 0;
|
|
3503
|
+
perspective[3] = 1;
|
|
3504
|
+
} // Next take care of translation
|
|
3505
|
+
|
|
3506
|
+
|
|
3507
|
+
translation[0] = a30;
|
|
3508
|
+
translation[1] = a31;
|
|
3509
|
+
translation[2] = a32; // Now get scale and shear. 'row' is a 3 element array of 3 component vectors
|
|
3510
|
+
|
|
3511
|
+
mat3from4(row, tmp); // Compute X scale factor and normalize first row.
|
|
3512
|
+
|
|
3513
|
+
scale[0] = glMatrix.vec3.length(row[0]);
|
|
3514
|
+
glMatrix.vec3.normalize(row[0], row[0]); // Compute XY shear factor and make 2nd row orthogonal to 1st.
|
|
3515
|
+
|
|
3516
|
+
skew[0] = glMatrix.vec3.dot(row[0], row[1]);
|
|
3517
|
+
combine(row[1], row[1], row[0], 1.0, -skew[0]); // Now, compute Y scale and normalize 2nd row.
|
|
3518
|
+
|
|
3519
|
+
scale[1] = glMatrix.vec3.length(row[1]);
|
|
3520
|
+
glMatrix.vec3.normalize(row[1], row[1]);
|
|
3521
|
+
skew[0] /= scale[1]; // Compute XZ and YZ shears, orthogonalize 3rd row
|
|
3522
|
+
|
|
3523
|
+
skew[1] = glMatrix.vec3.dot(row[0], row[2]);
|
|
3524
|
+
combine(row[2], row[2], row[0], 1.0, -skew[1]);
|
|
3525
|
+
skew[2] = glMatrix.vec3.dot(row[1], row[2]);
|
|
3526
|
+
combine(row[2], row[2], row[1], 1.0, -skew[2]); // Next, get Z scale and normalize 3rd row.
|
|
3527
|
+
|
|
3528
|
+
scale[2] = glMatrix.vec3.length(row[2]);
|
|
3529
|
+
glMatrix.vec3.normalize(row[2], row[2]);
|
|
3530
|
+
skew[1] /= scale[2];
|
|
3531
|
+
skew[2] /= scale[2]; // At this point, the matrix (in rows) is orthonormal.
|
|
3532
|
+
// Check for a coordinate system flip. If the determinant
|
|
3533
|
+
// is -1, then negate the matrix and the scaling factors.
|
|
3433
3534
|
|
|
3434
|
-
|
|
3435
|
-
var ellipse = match('shape', /^(ellipse)/i, 0);
|
|
3535
|
+
glMatrix.vec3.cross(pdum3, row[1], row[2]);
|
|
3436
3536
|
|
|
3437
|
-
|
|
3438
|
-
|
|
3439
|
-
|
|
3537
|
+
if (glMatrix.vec3.dot(row[0], pdum3) < 0) {
|
|
3538
|
+
for (var i = 0; i < 3; i++) {
|
|
3539
|
+
scale[i] *= -1;
|
|
3540
|
+
row[i][0] *= -1;
|
|
3541
|
+
row[i][1] *= -1;
|
|
3542
|
+
row[i][2] *= -1;
|
|
3440
3543
|
}
|
|
3544
|
+
} // Now, get the rotations out
|
|
3441
3545
|
|
|
3442
|
-
return ellipse;
|
|
3443
|
-
}
|
|
3444
3546
|
|
|
3445
|
-
|
|
3446
|
-
|
|
3447
|
-
|
|
3547
|
+
quaternion[0] = 0.5 * Math.sqrt(Math.max(1 + row[0][0] - row[1][1] - row[2][2], 0));
|
|
3548
|
+
quaternion[1] = 0.5 * Math.sqrt(Math.max(1 - row[0][0] + row[1][1] - row[2][2], 0));
|
|
3549
|
+
quaternion[2] = 0.5 * Math.sqrt(Math.max(1 - row[0][0] - row[1][1] + row[2][2], 0));
|
|
3550
|
+
quaternion[3] = 0.5 * Math.sqrt(Math.max(1 + row[0][0] + row[1][1] + row[2][2], 0));
|
|
3551
|
+
if (row[2][1] > row[1][2]) quaternion[0] = -quaternion[0];
|
|
3552
|
+
if (row[0][2] > row[2][0]) quaternion[1] = -quaternion[1];
|
|
3553
|
+
if (row[1][0] > row[0][1]) quaternion[2] = -quaternion[2];
|
|
3554
|
+
return true;
|
|
3555
|
+
}
|
|
3448
3556
|
|
|
3449
|
-
|
|
3450
|
-
|
|
3451
|
-
var positioning = matchPositioning();
|
|
3557
|
+
function normalize(out, mat) {
|
|
3558
|
+
var m44 = mat[15]; // Cannot normalize.
|
|
3452
3559
|
|
|
3453
|
-
|
|
3454
|
-
|
|
3455
|
-
}
|
|
3560
|
+
if (m44 === 0) return false;
|
|
3561
|
+
var scale = 1 / m44;
|
|
3456
3562
|
|
|
3457
|
-
|
|
3458
|
-
|
|
3563
|
+
for (var i = 0; i < 16; i++) {
|
|
3564
|
+
out[i] = mat[i] * scale;
|
|
3459
3565
|
}
|
|
3460
3566
|
|
|
3461
|
-
|
|
3462
|
-
|
|
3567
|
+
return true;
|
|
3568
|
+
} //gets upper-left of a 4x4 matrix into a 3x3 of vectors
|
|
3463
3569
|
|
|
3464
|
-
if (location.x || location.y) {
|
|
3465
|
-
return {
|
|
3466
|
-
type: 'position',
|
|
3467
|
-
value: location
|
|
3468
|
-
};
|
|
3469
|
-
}
|
|
3470
|
-
}
|
|
3471
3570
|
|
|
3472
|
-
|
|
3473
|
-
|
|
3474
|
-
|
|
3475
|
-
|
|
3476
|
-
|
|
3477
|
-
|
|
3571
|
+
function mat3from4(out, mat4x4) {
|
|
3572
|
+
out[0][0] = mat4x4[0];
|
|
3573
|
+
out[0][1] = mat4x4[1];
|
|
3574
|
+
out[0][2] = mat4x4[2];
|
|
3575
|
+
out[1][0] = mat4x4[4];
|
|
3576
|
+
out[1][1] = mat4x4[5];
|
|
3577
|
+
out[1][2] = mat4x4[6];
|
|
3578
|
+
out[2][0] = mat4x4[8];
|
|
3579
|
+
out[2][1] = mat4x4[9];
|
|
3580
|
+
out[2][2] = mat4x4[10];
|
|
3581
|
+
}
|
|
3478
3582
|
|
|
3479
|
-
|
|
3480
|
-
|
|
3481
|
-
|
|
3583
|
+
function combine(out, a, b, scale1, scale2) {
|
|
3584
|
+
out[0] = a[0] * scale1 + b[0] * scale2;
|
|
3585
|
+
out[1] = a[1] * scale1 + b[1] * scale2;
|
|
3586
|
+
out[2] = a[2] * scale1 + b[2] * scale2;
|
|
3587
|
+
}
|
|
3482
3588
|
|
|
3483
|
-
|
|
3484
|
-
|
|
3589
|
+
/**
|
|
3590
|
+
* borrow from gradient-parser, but we delete some browser compatible prefix such as `-webkit-`
|
|
3591
|
+
* @see https://github.com/rafaelcaricio/gradient-parser
|
|
3592
|
+
*/
|
|
3593
|
+
function colorStopToString(colorStop) {
|
|
3594
|
+
var type = colorStop.type,
|
|
3595
|
+
value = colorStop.value;
|
|
3485
3596
|
|
|
3486
|
-
|
|
3487
|
-
|
|
3597
|
+
if (type === 'hex') {
|
|
3598
|
+
return "#" + value;
|
|
3599
|
+
} else if (type === 'literal') {
|
|
3600
|
+
return value;
|
|
3601
|
+
} else if (type === 'rgb') {
|
|
3602
|
+
return "rgb(" + value.join(',') + ")";
|
|
3603
|
+
} else {
|
|
3604
|
+
return "rgba(" + value.join(',') + ")";
|
|
3605
|
+
}
|
|
3606
|
+
}
|
|
3607
|
+
var parseGradient = function () {
|
|
3608
|
+
var tokens = {
|
|
3609
|
+
linearGradient: /^(linear\-gradient)/i,
|
|
3610
|
+
repeatingLinearGradient: /^(repeating\-linear\-gradient)/i,
|
|
3611
|
+
radialGradient: /^(radial\-gradient)/i,
|
|
3612
|
+
repeatingRadialGradient: /^(repeating\-radial\-gradient)/i,
|
|
3488
3613
|
|
|
3489
|
-
|
|
3490
|
-
|
|
3491
|
-
|
|
3492
|
-
|
|
3493
|
-
|
|
3494
|
-
|
|
3495
|
-
|
|
3614
|
+
/**
|
|
3615
|
+
* @see https://projects.verou.me/conic-gradient/
|
|
3616
|
+
*/
|
|
3617
|
+
conicGradient: /^(conic\-gradient)/i,
|
|
3618
|
+
sideOrCorner: /^to (left (top|bottom)|right (top|bottom)|top (left|right)|bottom (left|right)|left|right|top|bottom)/i,
|
|
3619
|
+
extentKeywords: /^(closest\-side|closest\-corner|farthest\-side|farthest\-corner|contain|cover)/,
|
|
3620
|
+
positionKeywords: /^(left|center|right|top|bottom)/i,
|
|
3621
|
+
pixelValue: /^(-?(([0-9]*\.[0-9]+)|([0-9]+\.?)))px/,
|
|
3622
|
+
percentageValue: /^(-?(([0-9]*\.[0-9]+)|([0-9]+\.?)))\%/,
|
|
3623
|
+
emValue: /^(-?(([0-9]*\.[0-9]+)|([0-9]+\.?)))em/,
|
|
3624
|
+
angleValue: /^(-?(([0-9]*\.[0-9]+)|([0-9]+\.?)))deg/,
|
|
3625
|
+
startCall: /^\(/,
|
|
3626
|
+
endCall: /^\)/,
|
|
3627
|
+
comma: /^,/,
|
|
3628
|
+
hexColor: /^\#([0-9a-fA-F]+)/,
|
|
3629
|
+
literalColor: /^([a-zA-Z]+)/,
|
|
3630
|
+
rgbColor: /^rgb/i,
|
|
3631
|
+
rgbaColor: /^rgba/i,
|
|
3632
|
+
number: /^(([0-9]*\.[0-9]+)|([0-9]+\.?))/
|
|
3633
|
+
};
|
|
3634
|
+
var input = '';
|
|
3496
3635
|
|
|
3497
|
-
|
|
3636
|
+
function error(msg) {
|
|
3637
|
+
throw new Error(input + ': ' + msg);
|
|
3498
3638
|
}
|
|
3499
3639
|
|
|
3500
|
-
function
|
|
3501
|
-
var
|
|
3640
|
+
function getAST() {
|
|
3641
|
+
var ast = matchListDefinitions();
|
|
3502
3642
|
|
|
3503
|
-
if (
|
|
3504
|
-
error('
|
|
3643
|
+
if (input.length > 0) {
|
|
3644
|
+
error('Invalid input not EOF');
|
|
3505
3645
|
}
|
|
3506
3646
|
|
|
3507
|
-
|
|
3508
|
-
return color;
|
|
3647
|
+
return ast;
|
|
3509
3648
|
}
|
|
3510
3649
|
|
|
3511
|
-
function
|
|
3512
|
-
return
|
|
3650
|
+
function matchListDefinitions() {
|
|
3651
|
+
return matchListing(matchDefinition);
|
|
3513
3652
|
}
|
|
3514
3653
|
|
|
3515
|
-
function
|
|
3516
|
-
return
|
|
3654
|
+
function matchDefinition() {
|
|
3655
|
+
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);
|
|
3517
3656
|
}
|
|
3518
3657
|
|
|
3519
|
-
function
|
|
3520
|
-
return
|
|
3521
|
-
|
|
3658
|
+
function matchGradient(gradientType, pattern, orientationMatcher) {
|
|
3659
|
+
return matchCall(pattern, function (captures) {
|
|
3660
|
+
var orientation = orientationMatcher();
|
|
3522
3661
|
|
|
3523
|
-
|
|
3524
|
-
|
|
3525
|
-
|
|
3526
|
-
|
|
3527
|
-
|
|
3528
|
-
};
|
|
3529
|
-
});
|
|
3530
|
-
}
|
|
3662
|
+
if (orientation) {
|
|
3663
|
+
if (!scan(tokens.comma)) {
|
|
3664
|
+
error('Missing comma before color stops');
|
|
3665
|
+
}
|
|
3666
|
+
}
|
|
3531
3667
|
|
|
3532
|
-
function matchRGBAColor() {
|
|
3533
|
-
return matchCall(tokens.rgbaColor, function () {
|
|
3534
3668
|
return {
|
|
3535
|
-
type:
|
|
3536
|
-
|
|
3669
|
+
type: gradientType,
|
|
3670
|
+
orientation: orientation,
|
|
3671
|
+
colorStops: matchListing(matchColorStop)
|
|
3537
3672
|
};
|
|
3538
3673
|
});
|
|
3539
3674
|
}
|
|
3540
3675
|
|
|
3541
|
-
function
|
|
3542
|
-
return scan(tokens.number)[1];
|
|
3543
|
-
}
|
|
3544
|
-
|
|
3545
|
-
function matchDistance() {
|
|
3546
|
-
return match('%', tokens.percentageValue, 1) || matchPositionKeyword() || matchLength();
|
|
3547
|
-
}
|
|
3548
|
-
|
|
3549
|
-
function matchPositionKeyword() {
|
|
3550
|
-
return match('position-keyword', tokens.positionKeywords, 1);
|
|
3551
|
-
}
|
|
3552
|
-
|
|
3553
|
-
function matchLength() {
|
|
3554
|
-
return match('px', tokens.pixelValue, 1) || match('em', tokens.emValue, 1);
|
|
3555
|
-
}
|
|
3556
|
-
|
|
3557
|
-
function match(type, pattern, captureIndex) {
|
|
3676
|
+
function matchCall(pattern, callback) {
|
|
3558
3677
|
var captures = scan(pattern);
|
|
3559
3678
|
|
|
3560
3679
|
if (captures) {
|
|
3561
|
-
|
|
3562
|
-
|
|
3563
|
-
|
|
3564
|
-
};
|
|
3565
|
-
}
|
|
3566
|
-
}
|
|
3567
|
-
|
|
3568
|
-
function scan(regexp) {
|
|
3569
|
-
var blankCaptures = /^[\n\r\t\s]+/.exec(input);
|
|
3570
|
-
|
|
3571
|
-
if (blankCaptures) {
|
|
3572
|
-
consume(blankCaptures[0].length);
|
|
3573
|
-
}
|
|
3574
|
-
|
|
3575
|
-
var captures = regexp.exec(input);
|
|
3576
|
-
|
|
3577
|
-
if (captures) {
|
|
3578
|
-
consume(captures[0].length);
|
|
3579
|
-
}
|
|
3580
|
-
|
|
3581
|
-
return captures;
|
|
3582
|
-
}
|
|
3583
|
-
|
|
3584
|
-
function consume(size) {
|
|
3585
|
-
input = input.substring(size);
|
|
3586
|
-
}
|
|
3587
|
-
|
|
3588
|
-
return function (code) {
|
|
3589
|
-
input = code;
|
|
3590
|
-
return getAST();
|
|
3591
|
-
};
|
|
3592
|
-
}();
|
|
3593
|
-
function computeLinearGradient(width, height, angle) {
|
|
3594
|
-
var rad = angle * Math.PI / 180;
|
|
3595
|
-
var rx = 0;
|
|
3596
|
-
var ry = 0;
|
|
3597
|
-
var rcx = rx + width / 2;
|
|
3598
|
-
var rcy = ry + height / 2; // get the length of gradient line
|
|
3599
|
-
// @see https://observablehq.com/@danburzo/css-gradient-line
|
|
3680
|
+
if (!scan(tokens.startCall)) {
|
|
3681
|
+
error('Missing (');
|
|
3682
|
+
}
|
|
3600
3683
|
|
|
3601
|
-
|
|
3602
|
-
var x1 = rcx - Math.cos(rad) * length / 2;
|
|
3603
|
-
var y1 = rcy - Math.sin(rad) * length / 2;
|
|
3604
|
-
var x2 = rcx + Math.cos(rad) * length / 2;
|
|
3605
|
-
var y2 = rcy + Math.sin(rad) * length / 2;
|
|
3606
|
-
return {
|
|
3607
|
-
x1: x1,
|
|
3608
|
-
y1: y1,
|
|
3609
|
-
x2: x2,
|
|
3610
|
-
y2: y2
|
|
3611
|
-
};
|
|
3612
|
-
}
|
|
3613
|
-
function computeRadialGradient(width, height, cx, cy) {
|
|
3614
|
-
var r = Math.sqrt(width * width + height * height) / 2;
|
|
3615
|
-
return {
|
|
3616
|
-
x: cx * width,
|
|
3617
|
-
y: cy * height,
|
|
3618
|
-
r: r
|
|
3619
|
-
};
|
|
3620
|
-
}
|
|
3684
|
+
var result = callback(captures);
|
|
3621
3685
|
|
|
3622
|
-
|
|
3623
|
-
|
|
3624
|
-
|
|
3625
|
-
} else if (angle > 360 || angle < -360) {
|
|
3626
|
-
return angle % 360;
|
|
3627
|
-
}
|
|
3686
|
+
if (!scan(tokens.endCall)) {
|
|
3687
|
+
error('Missing )');
|
|
3688
|
+
}
|
|
3628
3689
|
|
|
3629
|
-
|
|
3630
|
-
}
|
|
3631
|
-
function createVec3(x, y, z) {
|
|
3632
|
-
if (y === void 0) {
|
|
3633
|
-
y = 0;
|
|
3690
|
+
return result;
|
|
3691
|
+
}
|
|
3634
3692
|
}
|
|
3635
3693
|
|
|
3636
|
-
|
|
3637
|
-
|
|
3694
|
+
function matchLinearOrientation() {
|
|
3695
|
+
return matchSideOrCorner() || matchAngle();
|
|
3638
3696
|
}
|
|
3639
3697
|
|
|
3640
|
-
|
|
3641
|
-
return
|
|
3698
|
+
function matchSideOrCorner() {
|
|
3699
|
+
return match('directional', tokens.sideOrCorner, 1);
|
|
3642
3700
|
}
|
|
3643
3701
|
|
|
3644
|
-
|
|
3645
|
-
return
|
|
3702
|
+
function matchAngle() {
|
|
3703
|
+
return match('angular', tokens.angleValue, 1);
|
|
3646
3704
|
}
|
|
3647
3705
|
|
|
3648
|
-
|
|
3649
|
-
|
|
3650
|
-
|
|
3651
|
-
|
|
3652
|
-
}
|
|
3653
|
-
function rad2deg(rad) {
|
|
3654
|
-
return rad * (180 / Math.PI);
|
|
3655
|
-
}
|
|
3656
|
-
function grad2deg(grads) {
|
|
3657
|
-
grads = grads % 400;
|
|
3706
|
+
function matchListRadialOrientations() {
|
|
3707
|
+
var radialOrientations,
|
|
3708
|
+
radialOrientation = matchRadialOrientation(),
|
|
3709
|
+
lookaheadCache;
|
|
3658
3710
|
|
|
3659
|
-
|
|
3660
|
-
|
|
3661
|
-
|
|
3711
|
+
if (radialOrientation) {
|
|
3712
|
+
radialOrientations = [];
|
|
3713
|
+
radialOrientations.push(radialOrientation);
|
|
3714
|
+
lookaheadCache = input;
|
|
3662
3715
|
|
|
3663
|
-
|
|
3664
|
-
|
|
3665
|
-
function deg2turn(deg) {
|
|
3666
|
-
return deg / 360;
|
|
3667
|
-
}
|
|
3668
|
-
function turn2deg(turn) {
|
|
3669
|
-
return 360 * turn;
|
|
3670
|
-
}
|
|
3716
|
+
if (scan(tokens.comma)) {
|
|
3717
|
+
radialOrientation = matchRadialOrientation();
|
|
3671
3718
|
|
|
3672
|
-
|
|
3673
|
-
|
|
3674
|
-
|
|
3675
|
-
|
|
3676
|
-
|
|
3677
|
-
|
|
3678
|
-
|
|
3679
|
-
var z2 = z * z;
|
|
3680
|
-
var w2 = w * w;
|
|
3681
|
-
var unit = x2 + y2 + z2 + w2;
|
|
3682
|
-
var test = x * w - y * z;
|
|
3719
|
+
if (radialOrientation) {
|
|
3720
|
+
radialOrientations.push(radialOrientation);
|
|
3721
|
+
} else {
|
|
3722
|
+
input = lookaheadCache;
|
|
3723
|
+
}
|
|
3724
|
+
}
|
|
3725
|
+
}
|
|
3683
3726
|
|
|
3684
|
-
|
|
3685
|
-
|
|
3686
|
-
// singularity at the north pole
|
|
3687
|
-
out[0] = Math.PI / 2;
|
|
3688
|
-
out[1] = 2 * Math.atan2(y, x);
|
|
3689
|
-
out[2] = 0;
|
|
3690
|
-
} else if (test < -0.499995 * unit) {
|
|
3691
|
-
//TODO: Use glmatrix.EPSILON
|
|
3692
|
-
// singularity at the south pole
|
|
3693
|
-
out[0] = -Math.PI / 2;
|
|
3694
|
-
out[1] = 2 * Math.atan2(y, x);
|
|
3695
|
-
out[2] = 0;
|
|
3696
|
-
} else {
|
|
3697
|
-
out[0] = Math.asin(2 * (x * z - w * y));
|
|
3698
|
-
out[1] = Math.atan2(2 * (x * w + y * z), 1 - 2 * (z2 + w2));
|
|
3699
|
-
out[2] = Math.atan2(2 * (x * y + z * w), 1 - 2 * (y2 + z2));
|
|
3700
|
-
} // TODO: Return them as degrees and not as radians
|
|
3727
|
+
return radialOrientations;
|
|
3728
|
+
}
|
|
3701
3729
|
|
|
3730
|
+
function matchRadialOrientation() {
|
|
3731
|
+
var radialType = matchCircle() || matchEllipse();
|
|
3702
3732
|
|
|
3703
|
-
|
|
3704
|
-
|
|
3733
|
+
if (radialType) {
|
|
3734
|
+
// @ts-ignore
|
|
3735
|
+
radialType.at = matchAtPosition();
|
|
3736
|
+
} else {
|
|
3737
|
+
var extent = matchExtentKeyword();
|
|
3705
3738
|
|
|
3706
|
-
|
|
3707
|
-
|
|
3708
|
-
|
|
3709
|
-
var halfPi = Math.PI * 0.5;
|
|
3739
|
+
if (extent) {
|
|
3740
|
+
radialType = extent;
|
|
3741
|
+
var positionAt = matchAtPosition();
|
|
3710
3742
|
|
|
3711
|
-
|
|
3712
|
-
|
|
3713
|
-
|
|
3714
|
-
|
|
3743
|
+
if (positionAt) {
|
|
3744
|
+
// @ts-ignore
|
|
3745
|
+
radialType.at = positionAt;
|
|
3746
|
+
}
|
|
3747
|
+
} else {
|
|
3748
|
+
var defaultPosition = matchPositioning();
|
|
3715
3749
|
|
|
3716
|
-
|
|
3750
|
+
if (defaultPosition) {
|
|
3751
|
+
radialType = {
|
|
3752
|
+
type: 'default-radial',
|
|
3753
|
+
// @ts-ignore
|
|
3754
|
+
at: defaultPosition
|
|
3755
|
+
};
|
|
3756
|
+
}
|
|
3757
|
+
}
|
|
3758
|
+
}
|
|
3717
3759
|
|
|
3718
|
-
|
|
3719
|
-
|
|
3720
|
-
|
|
3721
|
-
|
|
3722
|
-
|
|
3723
|
-
|
|
3724
|
-
|
|
3725
|
-
|
|
3760
|
+
return radialType;
|
|
3761
|
+
}
|
|
3762
|
+
|
|
3763
|
+
function matchCircle() {
|
|
3764
|
+
var circle = match('shape', /^(circle)/i, 0);
|
|
3765
|
+
|
|
3766
|
+
if (circle) {
|
|
3767
|
+
// @ts-ignore
|
|
3768
|
+
circle.style = matchLength() || matchExtentKeyword();
|
|
3726
3769
|
}
|
|
3727
|
-
|
|
3728
|
-
|
|
3729
|
-
z = 0;
|
|
3730
|
-
x = Math.atan2(m[4] / sy, m[5] / sy);
|
|
3770
|
+
|
|
3771
|
+
return circle;
|
|
3731
3772
|
}
|
|
3732
3773
|
|
|
3733
|
-
|
|
3734
|
-
|
|
3735
|
-
out[2] = z;
|
|
3736
|
-
return out;
|
|
3737
|
-
}
|
|
3738
|
-
/**
|
|
3739
|
-
* @see https://github.com/toji/gl-matrix/issues/329
|
|
3740
|
-
* @see https://doc.babylonjs.com/divingDeeper/mesh/transforms/center_origin/rotation_conventions
|
|
3741
|
-
*/
|
|
3774
|
+
function matchEllipse() {
|
|
3775
|
+
var ellipse = match('shape', /^(ellipse)/i, 0);
|
|
3742
3776
|
|
|
3777
|
+
if (ellipse) {
|
|
3778
|
+
// @ts-ignore
|
|
3779
|
+
ellipse.style = matchDistance() || matchExtentKeyword();
|
|
3780
|
+
}
|
|
3743
3781
|
|
|
3744
|
-
|
|
3745
|
-
if (quat.length === 16) {
|
|
3746
|
-
return getEulerFromMat4(out, quat);
|
|
3747
|
-
} else {
|
|
3748
|
-
return getEulerFromQuat(out, quat);
|
|
3782
|
+
return ellipse;
|
|
3749
3783
|
}
|
|
3750
|
-
}
|
|
3751
|
-
function fromRotationTranslationScale(rotation, x, y, scaleX, scaleY) {
|
|
3752
|
-
var cos = Math.cos(rotation);
|
|
3753
|
-
var sin = Math.sin(rotation);
|
|
3754
|
-
return glMatrix.mat3.fromValues(scaleX * cos, scaleY * sin, 0, -scaleX * sin, scaleY * cos, 0, x, y, 1);
|
|
3755
|
-
}
|
|
3756
|
-
function makePerspective(out, left, right, top, bottom, near, far) {
|
|
3757
|
-
var x = 2 * near / (right - left);
|
|
3758
|
-
var y = 2 * near / (top - bottom);
|
|
3759
|
-
var a = (right + left) / (right - left);
|
|
3760
|
-
var b = (top + bottom) / (top - bottom);
|
|
3761
|
-
var c = -(far + near) / (far - near);
|
|
3762
|
-
var d = -2 * far * near / (far - near);
|
|
3763
|
-
out[0] = x;
|
|
3764
|
-
out[1] = 0;
|
|
3765
|
-
out[2] = 0;
|
|
3766
|
-
out[3] = 0;
|
|
3767
|
-
out[4] = 0;
|
|
3768
|
-
out[5] = y;
|
|
3769
|
-
out[6] = 0;
|
|
3770
|
-
out[7] = 0;
|
|
3771
|
-
out[8] = a;
|
|
3772
|
-
out[9] = b;
|
|
3773
|
-
out[10] = c;
|
|
3774
|
-
out[11] = -1;
|
|
3775
|
-
out[12] = 0;
|
|
3776
|
-
out[13] = 0;
|
|
3777
|
-
out[14] = d;
|
|
3778
|
-
out[15] = 0;
|
|
3779
|
-
return out;
|
|
3780
|
-
}
|
|
3781
|
-
function decompose(mat) {
|
|
3782
|
-
var row0x = mat[0];
|
|
3783
|
-
var row0y = mat[1];
|
|
3784
|
-
var row1x = mat[3];
|
|
3785
|
-
var row1y = mat[4]; // decompose 3x3 matrix
|
|
3786
|
-
// @see https://www.w3.org/TR/css-transforms-1/#decomposing-a-2d-matrix
|
|
3787
3784
|
|
|
3788
|
-
|
|
3789
|
-
|
|
3785
|
+
function matchExtentKeyword() {
|
|
3786
|
+
return match('extent-keyword', tokens.extentKeywords, 1);
|
|
3787
|
+
}
|
|
3790
3788
|
|
|
3791
|
-
|
|
3789
|
+
function matchAtPosition() {
|
|
3790
|
+
if (match('position', /^at/, 0)) {
|
|
3791
|
+
var positioning = matchPositioning();
|
|
3792
3792
|
|
|
3793
|
-
|
|
3794
|
-
|
|
3795
|
-
|
|
3796
|
-
|
|
3797
|
-
|
|
3798
|
-
scalingY = -scalingY;
|
|
3793
|
+
if (!positioning) {
|
|
3794
|
+
error('Missing positioning value');
|
|
3795
|
+
}
|
|
3796
|
+
|
|
3797
|
+
return positioning;
|
|
3799
3798
|
}
|
|
3800
|
-
}
|
|
3799
|
+
}
|
|
3801
3800
|
|
|
3801
|
+
function matchPositioning() {
|
|
3802
|
+
var location = matchCoordinates();
|
|
3802
3803
|
|
|
3803
|
-
|
|
3804
|
-
|
|
3805
|
-
|
|
3804
|
+
if (location.x || location.y) {
|
|
3805
|
+
return {
|
|
3806
|
+
type: 'position',
|
|
3807
|
+
value: location
|
|
3808
|
+
};
|
|
3809
|
+
}
|
|
3806
3810
|
}
|
|
3807
3811
|
|
|
3808
|
-
|
|
3809
|
-
|
|
3810
|
-
|
|
3811
|
-
|
|
3812
|
-
|
|
3812
|
+
function matchCoordinates() {
|
|
3813
|
+
return {
|
|
3814
|
+
x: matchDistance(),
|
|
3815
|
+
y: matchDistance()
|
|
3816
|
+
};
|
|
3817
|
+
}
|
|
3813
3818
|
|
|
3814
|
-
|
|
3815
|
-
|
|
3816
|
-
|
|
3817
|
-
}
|
|
3818
|
-
var tmp = glMatrix.mat4.create();
|
|
3819
|
-
var perspectiveMatrix = glMatrix.mat4.create();
|
|
3820
|
-
var tmpVec4 = glMatrix.vec4.create();
|
|
3821
|
-
var row = [glMatrix.vec3.create(), glMatrix.vec3.create(), glMatrix.vec3.create()];
|
|
3822
|
-
var pdum3 = glMatrix.vec3.create();
|
|
3823
|
-
/*
|
|
3824
|
-
Input: matrix ; a 4x4 matrix
|
|
3825
|
-
Output: translation ; a 3 component vector
|
|
3826
|
-
scale ; a 3 component vector
|
|
3827
|
-
skew ; skew factors XY,XZ,YZ represented as a 3 component vector
|
|
3828
|
-
perspective ; a 4 component vector
|
|
3829
|
-
quaternion ; a 4 component vector
|
|
3830
|
-
Returns false if the matrix cannot be decomposed, true if it can
|
|
3819
|
+
function matchListing(matcher) {
|
|
3820
|
+
var captures = matcher();
|
|
3821
|
+
var result = [];
|
|
3831
3822
|
|
|
3823
|
+
if (captures) {
|
|
3824
|
+
result.push(captures);
|
|
3832
3825
|
|
|
3833
|
-
|
|
3834
|
-
|
|
3835
|
-
https://github.com/ChromiumWebApps/chromium/blob/master/ui/gfx/transform_util.cc
|
|
3836
|
-
http://www.w3.org/TR/css3-transforms/#decomposing-a-3d-matrix
|
|
3837
|
-
*/
|
|
3826
|
+
while (scan(tokens.comma)) {
|
|
3827
|
+
captures = matcher();
|
|
3838
3828
|
|
|
3839
|
-
|
|
3840
|
-
|
|
3841
|
-
|
|
3842
|
-
|
|
3829
|
+
if (captures) {
|
|
3830
|
+
result.push(captures);
|
|
3831
|
+
} else {
|
|
3832
|
+
error('One extra comma');
|
|
3833
|
+
}
|
|
3834
|
+
}
|
|
3835
|
+
}
|
|
3843
3836
|
|
|
3844
|
-
|
|
3845
|
-
|
|
3846
|
-
perspectiveMatrix[7] = 0;
|
|
3847
|
-
perspectiveMatrix[11] = 0;
|
|
3848
|
-
perspectiveMatrix[15] = 1; // If the perspectiveMatrix is not invertible, we are also unable to
|
|
3849
|
-
// decompose, so we'll bail early. Constant taken from SkMatrix44::invert.
|
|
3837
|
+
return result;
|
|
3838
|
+
}
|
|
3850
3839
|
|
|
3851
|
-
|
|
3852
|
-
|
|
3853
|
-
a13 = tmp[7],
|
|
3854
|
-
a23 = tmp[11],
|
|
3855
|
-
a30 = tmp[12],
|
|
3856
|
-
a31 = tmp[13],
|
|
3857
|
-
a32 = tmp[14],
|
|
3858
|
-
a33 = tmp[15]; // First, isolate perspective.
|
|
3840
|
+
function matchColorStop() {
|
|
3841
|
+
var color = matchColor();
|
|
3859
3842
|
|
|
3860
|
-
|
|
3861
|
-
|
|
3862
|
-
|
|
3863
|
-
tmpVec4[2] = a23;
|
|
3864
|
-
tmpVec4[3] = a33; // Solve the equation by inverting perspectiveMatrix and multiplying
|
|
3865
|
-
// rightHandSide by the inverse.
|
|
3866
|
-
// resuing the perspectiveMatrix here since it's no longer needed
|
|
3843
|
+
if (!color) {
|
|
3844
|
+
error('Expected color definition');
|
|
3845
|
+
}
|
|
3867
3846
|
|
|
3868
|
-
|
|
3869
|
-
|
|
3870
|
-
|
|
3847
|
+
color.length = matchDistance();
|
|
3848
|
+
return color;
|
|
3849
|
+
}
|
|
3871
3850
|
|
|
3872
|
-
|
|
3873
|
-
|
|
3874
|
-
|
|
3875
|
-
perspective[0] = perspective[1] = perspective[2] = 0;
|
|
3876
|
-
perspective[3] = 1;
|
|
3877
|
-
} // Next take care of translation
|
|
3851
|
+
function matchColor() {
|
|
3852
|
+
return matchHexColor() || matchRGBAColor() || matchRGBColor() || matchLiteralColor();
|
|
3853
|
+
}
|
|
3878
3854
|
|
|
3855
|
+
function matchLiteralColor() {
|
|
3856
|
+
return match('literal', tokens.literalColor, 0);
|
|
3857
|
+
}
|
|
3879
3858
|
|
|
3880
|
-
|
|
3881
|
-
|
|
3882
|
-
|
|
3859
|
+
function matchHexColor() {
|
|
3860
|
+
return match('hex', tokens.hexColor, 1);
|
|
3861
|
+
}
|
|
3883
3862
|
|
|
3884
|
-
|
|
3863
|
+
function matchRGBColor() {
|
|
3864
|
+
return matchCall(tokens.rgbColor, function () {
|
|
3865
|
+
return {
|
|
3866
|
+
type: 'rgb',
|
|
3867
|
+
value: matchListing(matchNumber)
|
|
3868
|
+
};
|
|
3869
|
+
});
|
|
3870
|
+
}
|
|
3885
3871
|
|
|
3886
|
-
|
|
3887
|
-
|
|
3872
|
+
function matchRGBAColor() {
|
|
3873
|
+
return matchCall(tokens.rgbaColor, function () {
|
|
3874
|
+
return {
|
|
3875
|
+
type: 'rgba',
|
|
3876
|
+
value: matchListing(matchNumber)
|
|
3877
|
+
};
|
|
3878
|
+
});
|
|
3879
|
+
}
|
|
3888
3880
|
|
|
3889
|
-
|
|
3890
|
-
|
|
3881
|
+
function matchNumber() {
|
|
3882
|
+
return scan(tokens.number)[1];
|
|
3883
|
+
}
|
|
3891
3884
|
|
|
3892
|
-
|
|
3893
|
-
|
|
3894
|
-
|
|
3885
|
+
function matchDistance() {
|
|
3886
|
+
return match('%', tokens.percentageValue, 1) || matchPositionKeyword() || matchLength();
|
|
3887
|
+
}
|
|
3895
3888
|
|
|
3896
|
-
|
|
3897
|
-
|
|
3898
|
-
|
|
3899
|
-
combine(row[2], row[2], row[1], 1.0, -skew[2]); // Next, get Z scale and normalize 3rd row.
|
|
3889
|
+
function matchPositionKeyword() {
|
|
3890
|
+
return match('position-keyword', tokens.positionKeywords, 1);
|
|
3891
|
+
}
|
|
3900
3892
|
|
|
3901
|
-
|
|
3902
|
-
|
|
3903
|
-
|
|
3904
|
-
skew[2] /= scale[2]; // At this point, the matrix (in rows) is orthonormal.
|
|
3905
|
-
// Check for a coordinate system flip. If the determinant
|
|
3906
|
-
// is -1, then negate the matrix and the scaling factors.
|
|
3893
|
+
function matchLength() {
|
|
3894
|
+
return match('px', tokens.pixelValue, 1) || match('em', tokens.emValue, 1);
|
|
3895
|
+
}
|
|
3907
3896
|
|
|
3908
|
-
|
|
3897
|
+
function match(type, pattern, captureIndex) {
|
|
3898
|
+
var captures = scan(pattern);
|
|
3909
3899
|
|
|
3910
|
-
|
|
3911
|
-
|
|
3912
|
-
|
|
3913
|
-
|
|
3914
|
-
|
|
3915
|
-
row[i][2] *= -1;
|
|
3900
|
+
if (captures) {
|
|
3901
|
+
return {
|
|
3902
|
+
type: type,
|
|
3903
|
+
value: captures[captureIndex]
|
|
3904
|
+
};
|
|
3916
3905
|
}
|
|
3917
|
-
}
|
|
3906
|
+
}
|
|
3918
3907
|
|
|
3908
|
+
function scan(regexp) {
|
|
3909
|
+
var blankCaptures = /^[\n\r\t\s]+/.exec(input);
|
|
3919
3910
|
|
|
3920
|
-
|
|
3921
|
-
|
|
3922
|
-
|
|
3923
|
-
quaternion[3] = 0.5 * Math.sqrt(Math.max(1 + row[0][0] + row[1][1] + row[2][2], 0));
|
|
3924
|
-
if (row[2][1] > row[1][2]) quaternion[0] = -quaternion[0];
|
|
3925
|
-
if (row[0][2] > row[2][0]) quaternion[1] = -quaternion[1];
|
|
3926
|
-
if (row[1][0] > row[0][1]) quaternion[2] = -quaternion[2];
|
|
3927
|
-
return true;
|
|
3928
|
-
}
|
|
3911
|
+
if (blankCaptures) {
|
|
3912
|
+
consume(blankCaptures[0].length);
|
|
3913
|
+
}
|
|
3929
3914
|
|
|
3930
|
-
|
|
3931
|
-
var m44 = mat[15]; // Cannot normalize.
|
|
3915
|
+
var captures = regexp.exec(input);
|
|
3932
3916
|
|
|
3933
|
-
|
|
3934
|
-
|
|
3917
|
+
if (captures) {
|
|
3918
|
+
consume(captures[0].length);
|
|
3919
|
+
}
|
|
3935
3920
|
|
|
3936
|
-
|
|
3937
|
-
out[i] = mat[i] * scale;
|
|
3921
|
+
return captures;
|
|
3938
3922
|
}
|
|
3939
3923
|
|
|
3940
|
-
|
|
3941
|
-
|
|
3924
|
+
function consume(size) {
|
|
3925
|
+
input = input.substring(size);
|
|
3926
|
+
}
|
|
3942
3927
|
|
|
3928
|
+
return function (code) {
|
|
3929
|
+
input = code;
|
|
3930
|
+
return getAST();
|
|
3931
|
+
};
|
|
3932
|
+
}();
|
|
3933
|
+
function computeLinearGradient(width, height, angle) {
|
|
3934
|
+
var rad = deg2rad(angle.value);
|
|
3935
|
+
var rx = 0;
|
|
3936
|
+
var ry = 0;
|
|
3937
|
+
var rcx = rx + width / 2;
|
|
3938
|
+
var rcy = ry + height / 2; // get the length of gradient line
|
|
3939
|
+
// @see https://observablehq.com/@danburzo/css-gradient-line
|
|
3943
3940
|
|
|
3944
|
-
|
|
3945
|
-
|
|
3946
|
-
|
|
3947
|
-
|
|
3948
|
-
|
|
3949
|
-
|
|
3950
|
-
|
|
3951
|
-
|
|
3952
|
-
|
|
3953
|
-
|
|
3941
|
+
var length = Math.abs(width * Math.cos(rad)) + Math.abs(height * Math.sin(rad));
|
|
3942
|
+
var x1 = rcx - Math.cos(rad) * length / 2;
|
|
3943
|
+
var y1 = rcy - Math.sin(rad) * length / 2;
|
|
3944
|
+
var x2 = rcx + Math.cos(rad) * length / 2;
|
|
3945
|
+
var y2 = rcy + Math.sin(rad) * length / 2;
|
|
3946
|
+
return {
|
|
3947
|
+
x1: x1,
|
|
3948
|
+
y1: y1,
|
|
3949
|
+
x2: x2,
|
|
3950
|
+
y2: y2
|
|
3951
|
+
};
|
|
3954
3952
|
}
|
|
3953
|
+
function computeRadialGradient(width, height, cx, cy, size) {
|
|
3954
|
+
// 'px'
|
|
3955
|
+
var x = cx.value;
|
|
3956
|
+
var y = cy.value; // TODO: 'em'
|
|
3957
|
+
// '%'
|
|
3958
|
+
|
|
3959
|
+
if (cx.unit === exports.UnitType.kPercentage) {
|
|
3960
|
+
x = cx.value / 100 * width;
|
|
3961
|
+
}
|
|
3962
|
+
|
|
3963
|
+
if (cy.unit === exports.UnitType.kPercentage) {
|
|
3964
|
+
y = cy.value / 100 * height;
|
|
3965
|
+
} // default to farthest-side
|
|
3966
|
+
|
|
3967
|
+
|
|
3968
|
+
var r = Math.max(util.distanceSquareRoot([0, 0], [x, y]), util.distanceSquareRoot([0, height], [x, y]), util.distanceSquareRoot([width, height], [x, y]), util.distanceSquareRoot([width, 0], [x, y]));
|
|
3969
|
+
|
|
3970
|
+
if (size) {
|
|
3971
|
+
if (size instanceof CSSUnitValue) {
|
|
3972
|
+
r = size.value;
|
|
3973
|
+
} else if (size instanceof CSSKeywordValue) {
|
|
3974
|
+
// @see https://developer.mozilla.org/zh-CN/docs/Web/CSS/CSS_Images/Using_CSS_gradients#example_closest-side_for_circles
|
|
3975
|
+
if (size.value === 'closest-side') {
|
|
3976
|
+
r = Math.min(x, width - x, y, height - y);
|
|
3977
|
+
} else if (size.value === 'farthest-side') {
|
|
3978
|
+
r = Math.max(x, width - x, y, height - y);
|
|
3979
|
+
} else if (size.value === 'closest-corner') {
|
|
3980
|
+
r = Math.min(util.distanceSquareRoot([0, 0], [x, y]), util.distanceSquareRoot([0, height], [x, y]), util.distanceSquareRoot([width, height], [x, y]), util.distanceSquareRoot([width, 0], [x, y]));
|
|
3981
|
+
}
|
|
3982
|
+
}
|
|
3983
|
+
}
|
|
3955
3984
|
|
|
3956
|
-
|
|
3957
|
-
|
|
3958
|
-
|
|
3959
|
-
|
|
3985
|
+
return {
|
|
3986
|
+
x: x,
|
|
3987
|
+
y: y,
|
|
3988
|
+
r: r
|
|
3989
|
+
};
|
|
3960
3990
|
}
|
|
3961
3991
|
|
|
3962
3992
|
(function (Shape) {
|
|
@@ -5524,6 +5554,7 @@ function spaceColorStops(colorStops) {
|
|
|
5524
5554
|
for (var i = 1; i < length; i++) {
|
|
5525
5555
|
var _colorStops$i$length;
|
|
5526
5556
|
|
|
5557
|
+
// support '%' & 'px'
|
|
5527
5558
|
var offset = (_colorStops$i$length = colorStops[i].length) === null || _colorStops$i$length === void 0 ? void 0 : _colorStops$i$length.value;
|
|
5528
5559
|
|
|
5529
5560
|
if (!util.isNil(offset) && !util.isNil(previousOffset)) {
|
|
@@ -5565,11 +5596,13 @@ var angleToDeg = util.memoize(function (orientation) {
|
|
|
5565
5596
|
angle = SideOrCornerToDegMap[orientation.value] || 0;
|
|
5566
5597
|
}
|
|
5567
5598
|
|
|
5568
|
-
return angle;
|
|
5599
|
+
return getOrCreateUnitValue(angle, 'deg');
|
|
5569
5600
|
});
|
|
5570
|
-
var
|
|
5571
|
-
var cx =
|
|
5572
|
-
var cy =
|
|
5601
|
+
var positonToCSSUnitValue = util.memoize(function (position) {
|
|
5602
|
+
var cx = 50;
|
|
5603
|
+
var cy = 50;
|
|
5604
|
+
var unitX = '%';
|
|
5605
|
+
var unitY = '%';
|
|
5573
5606
|
|
|
5574
5607
|
if ((position === null || position === void 0 ? void 0 : position.type) === 'position') {
|
|
5575
5608
|
var _position$value = position.value,
|
|
@@ -5580,13 +5613,13 @@ var positonToPercentage = util.memoize(function (position) {
|
|
|
5580
5613
|
if (x.value === 'left') {
|
|
5581
5614
|
cx = 0;
|
|
5582
5615
|
} else if (x.value === 'center') {
|
|
5583
|
-
cx =
|
|
5616
|
+
cx = 50;
|
|
5584
5617
|
} else if (x.value === 'right') {
|
|
5585
|
-
cx =
|
|
5618
|
+
cx = 100;
|
|
5586
5619
|
} else if (x.value === 'top') {
|
|
5587
5620
|
cy = 0;
|
|
5588
5621
|
} else if (x.value === 'bottom') {
|
|
5589
|
-
cy =
|
|
5622
|
+
cy = 100;
|
|
5590
5623
|
}
|
|
5591
5624
|
}
|
|
5592
5625
|
|
|
@@ -5594,28 +5627,30 @@ var positonToPercentage = util.memoize(function (position) {
|
|
|
5594
5627
|
if (y.value === 'left') {
|
|
5595
5628
|
cx = 0;
|
|
5596
5629
|
} else if (y.value === 'center') {
|
|
5597
|
-
cy =
|
|
5630
|
+
cy = 50;
|
|
5598
5631
|
} else if (y.value === 'right') {
|
|
5599
|
-
cx =
|
|
5632
|
+
cx = 100;
|
|
5600
5633
|
} else if (y.value === 'top') {
|
|
5601
5634
|
cy = 0;
|
|
5602
5635
|
} else if (y.value === 'bottom') {
|
|
5603
|
-
cy =
|
|
5636
|
+
cy = 100;
|
|
5604
5637
|
}
|
|
5605
5638
|
}
|
|
5606
5639
|
|
|
5607
|
-
if ((x === null || x === void 0 ? void 0 : x.type) === '%') {
|
|
5608
|
-
|
|
5640
|
+
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') {
|
|
5641
|
+
unitX = x === null || x === void 0 ? void 0 : x.type;
|
|
5642
|
+
cx = Number(x.value);
|
|
5609
5643
|
}
|
|
5610
5644
|
|
|
5611
|
-
if ((y === null || y === void 0 ? void 0 : y.type) === '%') {
|
|
5612
|
-
|
|
5645
|
+
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') {
|
|
5646
|
+
unitY = y === null || y === void 0 ? void 0 : y.type;
|
|
5647
|
+
cy = Number(y.value);
|
|
5613
5648
|
}
|
|
5614
5649
|
}
|
|
5615
5650
|
|
|
5616
5651
|
return {
|
|
5617
|
-
cx: cx,
|
|
5618
|
-
cy: cy
|
|
5652
|
+
cx: getOrCreateUnitValue(cx, unitX),
|
|
5653
|
+
cy: getOrCreateUnitValue(cy, unitY)
|
|
5619
5654
|
};
|
|
5620
5655
|
});
|
|
5621
5656
|
var parseGradient$1 = util.memoize(function (colorStr) {
|
|
@@ -5628,14 +5663,16 @@ var parseGradient$1 = util.memoize(function (colorStr) {
|
|
|
5628
5663
|
spaceColorStops(colorStops);
|
|
5629
5664
|
var steps = colorStops.map(function (colorStop) {
|
|
5630
5665
|
// TODO: only support % for now, should calc percentage of axis length when using px/em
|
|
5631
|
-
return
|
|
5666
|
+
return {
|
|
5667
|
+
offset: getOrCreateUnitValue(colorStop.length.value, '%'),
|
|
5668
|
+
color: colorStopToString(colorStop)
|
|
5669
|
+
};
|
|
5632
5670
|
});
|
|
5633
5671
|
|
|
5634
5672
|
if (type === 'linear-gradient') {
|
|
5635
5673
|
return new CSSGradientValue(exports.GradientType.LinearGradient, {
|
|
5636
|
-
angle: orientation ? angleToDeg(orientation) :
|
|
5637
|
-
steps: steps
|
|
5638
|
-
hash: colorStr
|
|
5674
|
+
angle: orientation ? angleToDeg(orientation) : Odeg,
|
|
5675
|
+
steps: steps
|
|
5639
5676
|
});
|
|
5640
5677
|
} else if (type === 'radial-gradient') {
|
|
5641
5678
|
if (!orientation) {
|
|
@@ -5646,17 +5683,33 @@ var parseGradient$1 = util.memoize(function (colorStr) {
|
|
|
5646
5683
|
}
|
|
5647
5684
|
|
|
5648
5685
|
if (orientation[0].type === 'shape' && orientation[0].value === 'circle') {
|
|
5649
|
-
var
|
|
5650
|
-
cx =
|
|
5651
|
-
cy =
|
|
5686
|
+
var _positonToCSSUnitValu = positonToCSSUnitValue(orientation[0].at),
|
|
5687
|
+
cx = _positonToCSSUnitValu.cx,
|
|
5688
|
+
cy = _positonToCSSUnitValu.cy;
|
|
5689
|
+
|
|
5690
|
+
var size;
|
|
5691
|
+
|
|
5692
|
+
if (orientation[0].style) {
|
|
5693
|
+
var _orientation$0$style = orientation[0].style,
|
|
5694
|
+
_type = _orientation$0$style.type,
|
|
5695
|
+
value = _orientation$0$style.value;
|
|
5696
|
+
|
|
5697
|
+
if (_type === 'extent-keyword') {
|
|
5698
|
+
size = getOrCreateKeyword(value);
|
|
5699
|
+
} else {
|
|
5700
|
+
size = getOrCreateUnitValue(value, _type);
|
|
5701
|
+
}
|
|
5702
|
+
}
|
|
5652
5703
|
|
|
5653
5704
|
return new CSSGradientValue(exports.GradientType.RadialGradient, {
|
|
5654
5705
|
cx: cx,
|
|
5655
5706
|
cy: cy,
|
|
5656
|
-
|
|
5657
|
-
|
|
5707
|
+
size: size,
|
|
5708
|
+
steps: steps
|
|
5658
5709
|
});
|
|
5659
|
-
} //
|
|
5710
|
+
} // TODO: support ellipse shape
|
|
5711
|
+
// TODO: repeating-linear-gradient & repeating-radial-gradient
|
|
5712
|
+
// } else if (type === 'repeating-linear-gradient') {
|
|
5660
5713
|
// } else if (type === 'repeating-radial-gradient') {
|
|
5661
5714
|
|
|
5662
5715
|
}
|
|
@@ -5677,13 +5730,15 @@ var parseGradient$1 = util.memoize(function (colorStr) {
|
|
|
5677
5730
|
return stop.split(':');
|
|
5678
5731
|
})) || [];
|
|
5679
5732
|
return [new CSSGradientValue(exports.GradientType.LinearGradient, {
|
|
5680
|
-
angle: parseFloat(arr[1]),
|
|
5733
|
+
angle: getOrCreateUnitValue(parseFloat(arr[1]), 'deg'),
|
|
5681
5734
|
steps: steps.map(function (_ref2) {
|
|
5682
5735
|
var offset = _ref2[0],
|
|
5683
5736
|
color = _ref2[1];
|
|
5684
|
-
return
|
|
5685
|
-
|
|
5686
|
-
|
|
5737
|
+
return {
|
|
5738
|
+
offset: getOrCreateUnitValue(Number(offset) * 100, '%'),
|
|
5739
|
+
color: color
|
|
5740
|
+
};
|
|
5741
|
+
})
|
|
5687
5742
|
})];
|
|
5688
5743
|
}
|
|
5689
5744
|
} else if (type === 'r') {
|
|
@@ -5712,14 +5767,16 @@ function parseRadialGradient(gradientStr) {
|
|
|
5712
5767
|
return stop.split(':');
|
|
5713
5768
|
})) || [];
|
|
5714
5769
|
return {
|
|
5715
|
-
cx:
|
|
5716
|
-
cy:
|
|
5770
|
+
cx: getOrCreateUnitValue(50, '%'),
|
|
5771
|
+
cy: getOrCreateUnitValue(50, '%'),
|
|
5717
5772
|
steps: steps.map(function (_ref3) {
|
|
5718
5773
|
var offset = _ref3[0],
|
|
5719
5774
|
color = _ref3[1];
|
|
5720
|
-
return
|
|
5721
|
-
|
|
5722
|
-
|
|
5775
|
+
return {
|
|
5776
|
+
offset: getOrCreateUnitValue(Number(offset) * 100, '%'),
|
|
5777
|
+
color: color
|
|
5778
|
+
};
|
|
5779
|
+
})
|
|
5723
5780
|
};
|
|
5724
5781
|
}
|
|
5725
5782
|
|
|
@@ -9357,7 +9414,10 @@ MutationEvent.ADDITION = 2;
|
|
|
9357
9414
|
MutationEvent.MODIFICATION = 1;
|
|
9358
9415
|
MutationEvent.REMOVAL = 3;
|
|
9359
9416
|
|
|
9360
|
-
var entityCounter = 0;
|
|
9417
|
+
var entityCounter = 0;
|
|
9418
|
+
function resetEntityCounter() {
|
|
9419
|
+
entityCounter = 0;
|
|
9420
|
+
} // let this.sceneGraphService: SceneGraphService;
|
|
9361
9421
|
|
|
9362
9422
|
var childInsertedEvent = new CustomEvent(exports.ElementEvent.CHILD_INSERTED, {
|
|
9363
9423
|
child: null
|
|
@@ -17737,6 +17797,35 @@ var EventPlugin = EventPlugin_1 = (_class$2 = /*#__PURE__*/function () {
|
|
|
17737
17797
|
renderingService.hooks.pointerOut.tap(EventPlugin_1.tag, this.onPointerMove);
|
|
17738
17798
|
};
|
|
17739
17799
|
|
|
17800
|
+
_proto.getViewportXY = function getViewportXY(nativeEvent) {
|
|
17801
|
+
var x;
|
|
17802
|
+
var y;
|
|
17803
|
+
/**
|
|
17804
|
+
* Should account for CSS Transform applied on container.
|
|
17805
|
+
* @see https://github.com/antvis/G/issues/1161
|
|
17806
|
+
* @see https://developer.mozilla.org/zh-CN/docs/Web/API/MouseEvent/offsetX
|
|
17807
|
+
*/
|
|
17808
|
+
|
|
17809
|
+
var offsetX = nativeEvent.offsetX,
|
|
17810
|
+
offsetY = nativeEvent.offsetY,
|
|
17811
|
+
clientX = nativeEvent.clientX,
|
|
17812
|
+
clientY = nativeEvent.clientY;
|
|
17813
|
+
|
|
17814
|
+
if (this.canvasConfig.supportsCSSTransform && !util.isNil(offsetX) && !util.isNil(offsetY)) {
|
|
17815
|
+
x = offsetX;
|
|
17816
|
+
y = offsetY;
|
|
17817
|
+
} else {
|
|
17818
|
+
var point = this.eventService.client2Viewport(new Point(clientX, clientY));
|
|
17819
|
+
x = point.x;
|
|
17820
|
+
y = point.y;
|
|
17821
|
+
}
|
|
17822
|
+
|
|
17823
|
+
return {
|
|
17824
|
+
x: x,
|
|
17825
|
+
y: y
|
|
17826
|
+
};
|
|
17827
|
+
};
|
|
17828
|
+
|
|
17740
17829
|
_proto.bootstrapEvent = function bootstrapEvent(event, nativeEvent, view) {
|
|
17741
17830
|
event.view = view;
|
|
17742
17831
|
event.originalEvent = null;
|
|
@@ -17753,9 +17842,9 @@ var EventPlugin = EventPlugin_1 = (_class$2 = /*#__PURE__*/function () {
|
|
|
17753
17842
|
event.twist = nativeEvent.twist;
|
|
17754
17843
|
this.transferMouseData(event, nativeEvent);
|
|
17755
17844
|
|
|
17756
|
-
var _this$
|
|
17757
|
-
x = _this$
|
|
17758
|
-
y = _this$
|
|
17845
|
+
var _this$getViewportXY = this.getViewportXY(nativeEvent),
|
|
17846
|
+
x = _this$getViewportXY.x,
|
|
17847
|
+
y = _this$getViewportXY.y;
|
|
17759
17848
|
|
|
17760
17849
|
event.viewport.x = x;
|
|
17761
17850
|
event.viewport.y = y;
|
|
@@ -17793,9 +17882,9 @@ var EventPlugin = EventPlugin_1 = (_class$2 = /*#__PURE__*/function () {
|
|
|
17793
17882
|
event.deltaY = nativeEvent.deltaY;
|
|
17794
17883
|
event.deltaZ = nativeEvent.deltaZ;
|
|
17795
17884
|
|
|
17796
|
-
var _this$
|
|
17797
|
-
x = _this$
|
|
17798
|
-
y = _this$
|
|
17885
|
+
var _this$getViewportXY2 = this.getViewportXY(nativeEvent),
|
|
17886
|
+
x = _this$getViewportXY2.x,
|
|
17887
|
+
y = _this$getViewportXY2.y;
|
|
17799
17888
|
|
|
17800
17889
|
event.viewport.x = x;
|
|
17801
17890
|
event.viewport.y = y;
|
|
@@ -18335,6 +18424,7 @@ var Canvas = /*#__PURE__*/function (_EventTarget) {
|
|
|
18335
18424
|
createImage = config.createImage,
|
|
18336
18425
|
supportsPointerEvents = config.supportsPointerEvents,
|
|
18337
18426
|
supportsTouchEvents = config.supportsTouchEvents,
|
|
18427
|
+
supportsCSSTransform = config.supportsCSSTransform,
|
|
18338
18428
|
isTouchEvent = config.isTouchEvent,
|
|
18339
18429
|
isMouseEvent = config.isMouseEvent;
|
|
18340
18430
|
cleanExistedCanvas(container, _assertThisInitialized(_this));
|
|
@@ -18383,7 +18473,8 @@ var Canvas = /*#__PURE__*/function (_EventTarget) {
|
|
|
18383
18473
|
cursor: cursor || 'default',
|
|
18384
18474
|
background: background || 'transparent',
|
|
18385
18475
|
createImage: createImage,
|
|
18386
|
-
document: document
|
|
18476
|
+
document: document,
|
|
18477
|
+
supportsCSSTransform: supportsCSSTransform
|
|
18387
18478
|
});
|
|
18388
18479
|
|
|
18389
18480
|
_this.initDefaultCamera(canvasWidth, canvasHeight);
|
|
@@ -19006,6 +19097,7 @@ exports.parseLength = parseLength;
|
|
|
19006
19097
|
exports.parsePath = parsePath;
|
|
19007
19098
|
exports.propertyMetadataCache = propertyMetadataCache;
|
|
19008
19099
|
exports.rad2deg = rad2deg;
|
|
19100
|
+
exports.resetEntityCounter = resetEntityCounter;
|
|
19009
19101
|
exports.setDOMSize = setDOMSize;
|
|
19010
19102
|
exports.styleValueRegistry = styleValueRegistry;
|
|
19011
19103
|
exports.translatePathToString = translatePathToString;
|