{"version":3,"file":"scale-box-shadow.mjs","sources":["../../../../src/projection/styles/scale-box-shadow.ts"],"sourcesContent":["import { complex } from \"../../value/types/complex\"\nimport { mixNumber } from \"../../utils/mix/number\"\nimport type { ScaleCorrectorDefinition } from \"./types\"\n\nexport const correctBoxShadow: ScaleCorrectorDefinition = {\n    correct: (latest: string, { treeScale, projectionDelta }) => {\n        const original = latest\n        const shadow = complex.parse(latest)\n\n        // TODO: Doesn't support multiple shadows\n        if (shadow.length > 5) return original\n\n        const template = complex.createTransformer(latest)\n        const offset = typeof shadow[0] !== \"number\" ? 1 : 0\n\n        // Calculate the overall context scale\n        const xScale = projectionDelta!.x.scale * treeScale!.x\n        const yScale = projectionDelta!.y.scale * treeScale!.y\n\n        // Scale x/y\n        ;(shadow[0 + offset] as number) /= xScale\n        ;(shadow[1 + offset] as number) /= yScale\n\n        /**\n         * Ideally we'd correct x and y scales individually, but because blur and\n         * spread apply to both we have to take a scale average and apply that instead.\n         * We could potentially improve the outcome of this by incorporating the ratio between\n         * the two scales.\n         */\n        const averageScale = mixNumber(xScale, yScale, 0.5)\n\n        // Blur\n        if (typeof shadow[2 + offset] === \"number\")\n            (shadow[2 + offset] as number) /= averageScale\n\n        // Spread\n        if (typeof shadow[3 + offset] === \"number\")\n            (shadow[3 + offset] as number) /= averageScale\n\n        return template(shadow)\n    },\n}\n"],"names":[],"mappings":";;;AAIO,MAAM,gBAAgB,GAA6B;IACtD,OAAO,EAAE,CAAC,MAAc,EAAE,EAAE,SAAS,EAAE,eAAe,EAAE,KAAI;QACxD,MAAM,QAAQ,GAAG,MAAM;QACvB,MAAM,MAAM,GAAG,OAAO,CAAC,KAAK,CAAC,MAAM,CAAC;;AAGpC,QAAA,IAAI,MAAM,CAAC,MAAM,GAAG,CAAC;AAAE,YAAA,OAAO,QAAQ;QAEtC,MAAM,QAAQ,GAAG,OAAO,CAAC,iBAAiB,CAAC,MAAM,CAAC;AAClD,QAAA,MAAM,MAAM,GAAG,OAAO,MAAM,CAAC,CAAC,CAAC,KAAK,QAAQ,GAAG,CAAC,GAAG,CAAC;;QAGpD,MAAM,MAAM,GAAG,eAAgB,CAAC,CAAC,CAAC,KAAK,GAAG,SAAU,CAAC,CAAC;QACtD,MAAM,MAAM,GAAG,eAAgB,CAAC,CAAC,CAAC,KAAK,GAAG,SAAU,CAAC,CAAC;AAGpD,QAAA,MAAM,CAAC,CAAC,GAAG,MAAM,CAAY,IAAI,MAAM;AACvC,QAAA,MAAM,CAAC,CAAC,GAAG,MAAM,CAAY,IAAI,MAAM;AAEzC;;;;;AAKG;QACH,MAAM,YAAY,GAAG,SAAS,CAAC,MAAM,EAAE,MAAM,EAAE,GAAG,CAAC;;QAGnD,IAAI,OAAO,MAAM,CAAC,CAAC,GAAG,MAAM,CAAC,KAAK,QAAQ;AACrC,YAAA,MAAM,CAAC,CAAC,GAAG,MAAM,CAAY,IAAI,YAAY;;QAGlD,IAAI,OAAO,MAAM,CAAC,CAAC,GAAG,MAAM,CAAC,KAAK,QAAQ;AACrC,YAAA,MAAM,CAAC,CAAC,GAAG,MAAM,CAAY,IAAI,YAAY;AAElD,QAAA,OAAO,QAAQ,CAAC,MAAM,CAAC;IAC3B,CAAC;;;;;"}