Skip to content

Commit

Permalink
v0.2.2
Browse files Browse the repository at this point in the history
  • Loading branch information
daengdaengLee committed Jun 8, 2020
2 parents 9382b89 + 4e6ebeb commit 06decf0
Show file tree
Hide file tree
Showing 7 changed files with 369 additions and 37 deletions.
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "fxsvg",
"version": "0.2.1",
"version": "0.2.2",
"description": "Functional SVG Handling Library",
"type": "module",
"main": "./src/index.js",
Expand Down
4 changes: 4 additions & 0 deletions src/mergeScaleTransform/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,7 @@

- [source](./mergeScaleTransform.index.js)
- [test](./mergeScaleTransform.spec.js)

`$$initScaleTransform` 으로 적용된 3개의 `SVGTransform` 객체를 하나의 `SVGTransform` 으로 병합합니다.
병합된 `SVGTransform``SVGTransform.SVG_TRANSFORM_MATRIX` 타입입니다.
따라서 한 번 병합한 `SVGTransform``$$updateScaleTransform` 이나 `$$appendScaleTransform` 으로 변경할 수 없습니다.
64 changes: 29 additions & 35 deletions src/mergeScaleTransform2/mergeScaleTransform2.index.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,17 @@
import { each, go, mapL, rangeL } from "fxjs2";
import { each, go, go1, mapL, rangeL, some } from "fxjs2";
import { $$getBaseTransformList } from "../getBaseTransformList/getBaseTransformList.index.js";
import { $$isValidFxScaleSVGTransformList } from "../isValidFxScaleSVGTransformList/isValidFxScaleSVGTransformList.index.js";

export const $$mergeScaleTransform2 = (
$el,
{ index, x_name, y_name, width_name, height_name, direction }
{
index = 0,
x_name = "x",
y_name = "y",
width_name = "width",
height_name = "height",
direction = "se",
} = {}
) => {
const transform_list = $$getBaseTransformList($el);

Expand All @@ -18,45 +25,32 @@ export const $$mergeScaleTransform2 = (
mapL((i) => transform_list.getItem(i)),
mapL(({ matrix: m }) => m)
);
const [x, y, width, height] = mapL(
(name) => parseFloat($el.getAttributeNS(null, name)),
[x_name, y_name, width_name, height_name]
const [x, y, width, height] = go(
[x_name, y_name, width_name, height_name],
mapL((name) => $el.getAttributeNS(null, name)),
mapL(parseFloat)
);

const [scaled_width, scaled_height] = mapL(([len, s]) => len * Math.abs(s), [
[width, sx],
[height, sy],
]);
let scaled_x = x;
let scaled_y = y;
if (direction === "n") {
scaled_y = sy >= 0 ? (scaled_y + cy1) * sy + cy2 : scaled_y + height;
} else if (direction === "ne") {
scaled_x = sx >= 0 ? (scaled_x + cx1) * sx + cx2 : scaled_x - scaled_width;
scaled_y = sy >= 0 ? (scaled_y + cy1) * sy + cy2 : scaled_y + height;
} else if (direction === "e") {
scaled_x = sx >= 0 ? (scaled_x + cx1) * sx + cx2 : scaled_x - scaled_width;
} else if (direction === "se") {
scaled_x = sx >= 0 ? (scaled_x + cx1) * sx + cx2 : scaled_x - scaled_width;
scaled_y = sy >= 0 ? (scaled_y + cy1) * sy + cy2 : scaled_y - scaled_height;
} else if (direction === "s") {
scaled_y = sy >= 0 ? (scaled_y + cy1) * sy + cy2 : scaled_y - scaled_height;
} else if (direction === "sw") {
scaled_x = sx >= 0 ? (scaled_x + cx1) * sx + cx2 : scaled_x + width;
scaled_y = sy >= 0 ? (scaled_y + cy1) * sy + cy2 : scaled_y - scaled_height;
} else if (direction === "w") {
scaled_x = sx >= 0 ? (scaled_x + cx1) * sx + cx2 : scaled_x + width;
} else if (direction === "nw") {
scaled_x = sx >= 0 ? (scaled_x + cx1) * sx + cx2 : scaled_x + width;
scaled_y = sy >= 0 ? (scaled_y + cy1) * sy + cy2 : scaled_y + height;
}

go(
[
[x, sx, cx1, cx2, width, ["e", "w"]],
[y, sy, cy1, cy2, height, ["n", "s"]],
],
mapL(([v, s, c1, c2, l, conditions]) =>
go(
conditions,
some((condition) => direction.includes(condition)),
(is_changed) =>
is_changed
? go1((v + c1) * s + c2, (v) => (s < 0 ? v + l * s : v))
: v
)
),
([scaled_x, scaled_y]) => [
[x_name, scaled_x],
[y_name, scaled_y],
[width_name, scaled_width],
[height_name, scaled_height],
[width_name, width * Math.abs(sx)],
[height_name, height * Math.abs(sy)],
],
mapL(([k, v]) => [k, `${v}`]),
each(([k, v]) => $el.setAttributeNS(null, k, v))
Expand Down
Loading

0 comments on commit 06decf0

Please sign in to comment.