UNPKG

@visactor/vgrammar-core

Version:

VGrammar is a visual grammar library

333 lines (307 loc) 14.2 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: !0 }), exports.growHeightOut = exports.growHeightIn = exports.growWidthOut = exports.growWidthIn = exports.growCenterOut = exports.growCenterIn = void 0; const vutils_1 = require("@visactor/vutils"), growCenterIn = (element, options, animationParameters) => { switch (null == options ? void 0 : options.direction) { case "x": { const x = element.getFinalAnimationAttribute("x"), x1 = element.getFinalAnimationAttribute("x1"), width = element.getFinalAnimationAttribute("width"); return { from: (0, vutils_1.isValid)(width) ? { x: x + width / 2, x1: void 0, width: 0 } : { x: (x + x1) / 2, x1: (x + x1) / 2, width: void 0 }, to: { x: x, x1: x1, width: width } }; } case "y": { const y = element.getFinalAnimationAttribute("y"), y1 = element.getFinalAnimationAttribute("y1"), height = element.getFinalAnimationAttribute("height"); return { from: (0, vutils_1.isValid)(height) ? { y: y + height / 2, y1: void 0, height: 0 } : { y: (y + y1) / 2, y1: (y + y1) / 2, height: void 0 }, to: { y: y, y1: y1, height: height } }; } default: { const x = element.getFinalAnimationAttribute("x"), x1 = element.getFinalAnimationAttribute("x1"), width = element.getFinalAnimationAttribute("width"), y = element.getFinalAnimationAttribute("y"), y1 = element.getFinalAnimationAttribute("y1"), height = element.getFinalAnimationAttribute("height"), from = {}; return (0, vutils_1.isValid)(width) ? (from.x = x + width / 2, from.width = 0, from.x1 = void 0) : (from.x = (x + x1) / 2, from.x1 = (x + x1) / 2, from.width = void 0), (0, vutils_1.isValid)(height) ? (from.y = y + height / 2, from.height = 0, from.y1 = void 0) : (from.y = (y + y1) / 2, from.y1 = (y + y1) / 2, from.height = void 0), { from: from, to: { x: x, y: y, x1: x1, y1: y1, width: width, height: height } }; } } }; exports.growCenterIn = growCenterIn; const growCenterOut = (element, options, animationParameters) => { switch (null == options ? void 0 : options.direction) { case "x": { const x = element.getFinalAnimationAttribute("x"), x1 = element.getFinalAnimationAttribute("x1"), width = element.getFinalAnimationAttribute("width"); return { to: (0, vutils_1.isValid)(width) ? { x: x + width / 2, x1: void 0, width: 0 } : { x: (x + x1) / 2, x1: (x + x1) / 2, width: void 0 } }; } case "y": { const y = element.getFinalAnimationAttribute("y"), y1 = element.getFinalAnimationAttribute("y1"), height = element.getFinalAnimationAttribute("height"); return { to: (0, vutils_1.isValid)(height) ? { y: y + height / 2, y1: void 0, height: 0 } : { y: (y + y1) / 2, y1: (y + y1) / 2, height: void 0 } }; } default: { const x = element.getFinalAnimationAttribute("x"), y = element.getFinalAnimationAttribute("y"), x1 = element.getFinalAnimationAttribute("x1"), y1 = element.getFinalAnimationAttribute("y1"), width = element.getFinalAnimationAttribute("width"), height = element.getFinalAnimationAttribute("height"), to = {}; return (0, vutils_1.isValid)(width) ? (to.x = x + width / 2, to.width = 0, to.x1 = void 0) : (to.x = (x + x1) / 2, to.x1 = (x + x1) / 2, to.width = void 0), (0, vutils_1.isValid)(height) ? (to.y = y + height / 2, to.height = 0, to.y1 = void 0) : (to.y = (y + y1) / 2, to.y1 = (y + y1) / 2, to.height = void 0), { to: to }; } } }; function growWidthInIndividual(element, options, animationParameters) { const x = element.getFinalAnimationAttribute("x"), x1 = element.getFinalAnimationAttribute("x1"), width = element.getFinalAnimationAttribute("width"); if (options && "negative" === options.orient) { const computedX1 = (0, vutils_1.isValid)(width) ? Math.max(x, x + width) : Math.max(x, x1); return { from: { x: computedX1, x1: (0, vutils_1.isNil)(x1) ? void 0 : computedX1, width: (0, vutils_1.isNil)(width) ? void 0 : 0 }, to: { x: x, x1: x1, width: width } }; } const computedX = (0, vutils_1.isValid)(width) ? Math.min(x, x + width) : Math.min(x, x1); return { from: { x: computedX, x1: (0, vutils_1.isNil)(x1) ? void 0 : computedX, width: (0, vutils_1.isNil)(width) ? void 0 : 0 }, to: { x: x, x1: x1, width: width } }; } function growWidthInOverall(element, options, animationParameters) { var _a; const x = element.getFinalAnimationAttribute("x"), x1 = element.getFinalAnimationAttribute("x1"), width = element.getFinalAnimationAttribute("width"); let overallValue; return options && "negative" === options.orient ? (0, vutils_1.isNumber)(options.overall) ? overallValue = options.overall : animationParameters.group ? (overallValue = null !== (_a = animationParameters.groupWidth) && void 0 !== _a ? _a : animationParameters.group.getBounds().width(), animationParameters.groupWidth = overallValue) : overallValue = animationParameters.width : overallValue = (0, vutils_1.isNumber)(null == options ? void 0 : options.overall) ? null == options ? void 0 : options.overall : 0, { from: { x: overallValue, x1: (0, vutils_1.isNil)(x1) ? void 0 : overallValue, width: (0, vutils_1.isNil)(width) ? void 0 : 0 }, to: { x: x, x1: x1, width: width } }; } exports.growCenterOut = growCenterOut; const growWidthIn = (element, options, animationParameters) => { var _a; return !1 !== (null !== (_a = null == options ? void 0 : options.overall) && void 0 !== _a && _a) ? growWidthInOverall(element, options, animationParameters) : growWidthInIndividual(element, options, animationParameters); }; function growWidthOutIndividual(element, options, animationParameters) { const x = element.getFinalAnimationAttribute("x"), x1 = element.getFinalAnimationAttribute("x1"), width = element.getFinalAnimationAttribute("width"); if (options && "negative" === options.orient) { const computedX1 = (0, vutils_1.isValid)(width) ? Math.max(x, x + width) : Math.max(x, x1); return { to: { x: computedX1, x1: (0, vutils_1.isNil)(x1) ? void 0 : computedX1, width: (0, vutils_1.isNil)(width) ? void 0 : 0 } }; } const computedX = (0, vutils_1.isValid)(width) ? Math.min(x, x + width) : Math.min(x, x1); return { to: { x: computedX, x1: (0, vutils_1.isNil)(x1) ? void 0 : computedX, width: (0, vutils_1.isNil)(width) ? void 0 : 0 } }; } function growWidthOutOverall(element, options, animationParameters) { var _a; const x1 = element.getFinalAnimationAttribute("x1"), width = element.getFinalAnimationAttribute("width"); let overallValue; return options && "negative" === options.orient ? (0, vutils_1.isNumber)(options.overall) ? overallValue = options.overall : animationParameters.group ? (overallValue = null !== (_a = animationParameters.groupWidth) && void 0 !== _a ? _a : animationParameters.group.getBounds().width(), animationParameters.groupWidth = overallValue) : overallValue = animationParameters.width : overallValue = (0, vutils_1.isNumber)(null == options ? void 0 : options.overall) ? options.overall : 0, { to: { x: overallValue, x1: (0, vutils_1.isNil)(x1) ? void 0 : overallValue, width: (0, vutils_1.isNil)(width) ? void 0 : 0 } }; } exports.growWidthIn = growWidthIn; const growWidthOut = (element, options, animationParameters) => { var _a; return !1 !== (null !== (_a = null == options ? void 0 : options.overall) && void 0 !== _a && _a) ? growWidthOutOverall(element, options, animationParameters) : growWidthOutIndividual(element, options, animationParameters); }; function growHeightInIndividual(element, options, animationParameters) { const y = element.getFinalAnimationAttribute("y"), y1 = element.getFinalAnimationAttribute("y1"), height = element.getFinalAnimationAttribute("height"); if (options && "negative" === options.orient) { const computedY1 = (0, vutils_1.isValid)(height) ? Math.max(y, y + height) : Math.max(y, y1); return { from: { y: computedY1, y1: (0, vutils_1.isNil)(y1) ? void 0 : computedY1, height: (0, vutils_1.isNil)(height) ? void 0 : 0 }, to: { y: y, y1: y1, height: height } }; } const computedY = (0, vutils_1.isValid)(height) ? Math.min(y, y + height) : Math.min(y, y1); return { from: { y: computedY, y1: (0, vutils_1.isNil)(y1) ? void 0 : computedY, height: (0, vutils_1.isNil)(height) ? void 0 : 0 }, to: { y: y, y1: y1, height: height } }; } function growHeightInOverall(element, options, animationParameters) { var _a; const y = element.getFinalAnimationAttribute("y"), y1 = element.getFinalAnimationAttribute("y1"), height = element.getFinalAnimationAttribute("height"); let overallValue; return options && "negative" === options.orient ? (0, vutils_1.isNumber)(options.overall) ? overallValue = options.overall : animationParameters.group ? (overallValue = null !== (_a = animationParameters.groupHeight) && void 0 !== _a ? _a : animationParameters.group.getBounds().height(), animationParameters.groupHeight = overallValue) : overallValue = animationParameters.height : overallValue = (0, vutils_1.isNumber)(null == options ? void 0 : options.overall) ? options.overall : 0, { from: { y: overallValue, y1: (0, vutils_1.isNil)(y1) ? void 0 : overallValue, height: (0, vutils_1.isNil)(height) ? void 0 : 0 }, to: { y: y, y1: y1, height: height } }; } exports.growWidthOut = growWidthOut; const growHeightIn = (element, options, animationParameters) => { var _a; return !1 !== (null !== (_a = null == options ? void 0 : options.overall) && void 0 !== _a && _a) ? growHeightInOverall(element, options, animationParameters) : growHeightInIndividual(element, options, animationParameters); }; function growHeightOutIndividual(element, options, animationParameters) { const y = element.getFinalAnimationAttribute("y"), y1 = element.getFinalAnimationAttribute("y1"), height = element.getFinalAnimationAttribute("height"); if (options && "negative" === options.orient) { const computedY1 = (0, vutils_1.isValid)(height) ? Math.max(y, y + height) : Math.max(y, y1); return { to: { y: computedY1, y1: (0, vutils_1.isNil)(y1) ? void 0 : computedY1, height: (0, vutils_1.isNil)(height) ? void 0 : 0 } }; } const computedY = (0, vutils_1.isValid)(height) ? Math.min(y, y + height) : Math.min(y, y1); return { to: { y: computedY, y1: (0, vutils_1.isNil)(y1) ? void 0 : computedY, height: (0, vutils_1.isNil)(height) ? void 0 : 0 } }; } function growHeightOutOverall(element, options, animationParameters) { var _a; const y1 = element.getFinalAnimationAttribute("y1"), height = element.getFinalAnimationAttribute("height"); let overallValue; return options && "negative" === options.orient ? (0, vutils_1.isNumber)(options.overall) ? overallValue = options.overall : animationParameters.group ? (overallValue = null !== (_a = animationParameters.groupHeight) && void 0 !== _a ? _a : animationParameters.group.getBounds().height(), animationParameters.groupHeight = overallValue) : overallValue = animationParameters.height : overallValue = (0, vutils_1.isNumber)(null == options ? void 0 : options.overall) ? options.overall : 0, { to: { y: overallValue, y1: (0, vutils_1.isNil)(y1) ? void 0 : overallValue, height: (0, vutils_1.isNil)(height) ? void 0 : 0 } }; } exports.growHeightIn = growHeightIn; const growHeightOut = (element, options, animationParameters) => { var _a; return !1 !== (null !== (_a = null == options ? void 0 : options.overall) && void 0 !== _a && _a) ? growHeightOutOverall(element, options, animationParameters) : growHeightOutIndividual(element, options, animationParameters); }; exports.growHeightOut = growHeightOut; //# sourceMappingURL=grow-cartesian.js.map