{"version":3,"file":"delta-remove.mjs","sources":["../../../../src/projection/geometry/delta-remove.ts"],"sourcesContent":["import { Axis, Box } from \"motion-utils\"\nimport { mixNumber } from \"../../utils/mix/number\"\nimport { percent } from \"../../value/types/numbers/units\"\nimport { ResolvedValues } from \"../../render/types\"\nimport { scalePoint } from \"./delta-apply\"\n\n/**\n * Remove a delta from a point. This is essentially the steps of applyPointDelta in reverse\n */\nexport function removePointDelta(\n    point: number,\n    translate: number,\n    scale: number,\n    originPoint: number,\n    boxScale?: number\n): number {\n    point -= translate\n    point = scalePoint(point, 1 / scale, originPoint)\n\n    if (boxScale !== undefined) {\n        point = scalePoint(point, 1 / boxScale, originPoint)\n    }\n\n    return point\n}\n\n/**\n * Remove a delta from an axis. This is essentially the steps of applyAxisDelta in reverse\n */\nexport function removeAxisDelta(\n    axis: Axis,\n    translate: number | string = 0,\n    scale: number = 1,\n    origin: number = 0.5,\n    boxScale?: number,\n    originAxis: Axis = axis,\n    sourceAxis: Axis = axis\n): void {\n    if (percent.test(translate)) {\n        translate = parseFloat(translate as string)\n        const relativeProgress = mixNumber(\n            sourceAxis.min,\n            sourceAxis.max,\n            translate / 100\n        )\n        translate = relativeProgress - sourceAxis.min\n    }\n\n    if (typeof translate !== \"number\") return\n\n    let originPoint = mixNumber(originAxis.min, originAxis.max, origin)\n    if (axis === originAxis) originPoint -= translate\n\n    axis.min = removePointDelta(\n        axis.min,\n        translate,\n        scale,\n        originPoint,\n        boxScale\n    )\n\n    axis.max = removePointDelta(\n        axis.max,\n        translate,\n        scale,\n        originPoint,\n        boxScale\n    )\n}\n\n/**\n * Remove a transforms from an axis. This is essentially the steps of applyAxisTransforms in reverse\n * and acts as a bridge between motion values and removeAxisDelta\n */\nexport function removeAxisTransforms(\n    axis: Axis,\n    transforms: ResolvedValues,\n    [key, scaleKey, originKey]: string[],\n    origin?: Axis,\n    sourceAxis?: Axis\n) {\n    removeAxisDelta(\n        axis,\n        transforms[key] as number,\n        transforms[scaleKey] as number,\n        transforms[originKey] as number,\n        transforms.scale as number,\n        origin,\n        sourceAxis\n    )\n}\n\n/**\n * The names of the motion values we want to apply as translation, scale and origin.\n */\nconst xKeys = [\"x\", \"scaleX\", \"originX\"]\nconst yKeys = [\"y\", \"scaleY\", \"originY\"]\n\n/**\n * Remove a transforms from an box. This is essentially the steps of applyAxisBox in reverse\n * and acts as a bridge between motion values and removeAxisDelta\n */\nexport function removeBoxTransforms(\n    box: Box,\n    transforms: ResolvedValues,\n    originBox?: Box,\n    sourceBox?: Box\n): void {\n    removeAxisTransforms(\n        box.x,\n        transforms,\n        xKeys,\n        originBox ? originBox.x : undefined,\n        sourceBox ? sourceBox.x : undefined\n    )\n    removeAxisTransforms(\n        box.y,\n        transforms,\n        yKeys,\n        originBox ? originBox.y : undefined,\n        sourceBox ? sourceBox.y : undefined\n    )\n}\n"],"names":[],"mappings":";;;;AAMA;;AAEG;AACG,SAAU,gBAAgB,CAC5B,KAAa,EACb,SAAiB,EACjB,KAAa,EACb,WAAmB,EACnB,QAAiB,EAAA;IAEjB,KAAK,IAAI,SAAS;IAClB,KAAK,GAAG,UAAU,CAAC,KAAK,EAAE,CAAC,GAAG,KAAK,EAAE,WAAW,CAAC;AAEjD,IAAA,IAAI,QAAQ,KAAK,SAAS,EAAE;QACxB,KAAK,GAAG,UAAU,CAAC,KAAK,EAAE,CAAC,GAAG,QAAQ,EAAE,WAAW,CAAC;IACxD;AAEA,IAAA,OAAO,KAAK;AAChB;AAEA;;AAEG;AACG,SAAU,eAAe,CAC3B,IAAU,EACV,SAAA,GAA6B,CAAC,EAC9B,KAAA,GAAgB,CAAC,EACjB,MAAA,GAAiB,GAAG,EACpB,QAAiB,EACjB,aAAmB,IAAI,EACvB,aAAmB,IAAI,EAAA;AAEvB,IAAA,IAAI,OAAO,CAAC,IAAI,CAAC,SAAS,CAAC,EAAE;AACzB,QAAA,SAAS,GAAG,UAAU,CAAC,SAAmB,CAAC;AAC3C,QAAA,MAAM,gBAAgB,GAAG,SAAS,C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