diff --git a/doc/API.md b/doc/API.md
index c100d1e..588a4fc 100644
--- a/doc/API.md
+++ b/doc/API.md
@@ -4,11 +4,21 @@
---
+## \$\$append
+
+- [source](../src/append/append.index.js)
+- [detail](../src/append/README.md)
+
## \$\$appendRotateTransform
- [source](../src/appendRotateTransform/appendRotateTransform.index.js)
- [detail](../src/appendRotateTransform/README.md)
+## \$\$appendTo
+
+- [source](../src/appendTo/appendTo.index.js)
+- [detail](../src/appendTo/README.md)
+
## \$\$appendTranslateTransform
- [source](../src/appendTranslateTransform/appendTranslateTransform.index.js)
@@ -209,6 +219,16 @@
- [source](../src/mergeTranslateTransform/mergeTranslateTransform.index.js)
- [detail](../src/mergeTranslateTransform/README.md)
+## \$\$qs
+
+- [source](../src/qs/qs.index.js)
+- [detail](../src/qs/README.md)
+
+## \$\$qsa
+
+- [source](../src/qsa/qsa.index.js)
+- [detail](../src/qsa/README.md)
+
## \$\$removeAttrNS
- [source](../src/removeAttrNS/removeAttrNS.index.js)
diff --git a/doc/API_KR.md b/doc/API_KR.md
index 12fcbef..5207a7f 100644
--- a/doc/API_KR.md
+++ b/doc/API_KR.md
@@ -6,6 +6,14 @@
---
+## \$\$append
+
+- [source](../src/append/append.index.js)
+- [detail](../src/append/README.md)
+
+첫 번째로 받은 엘리먼트를 두 번째로 받은 엘리먼트의 자식 엘리먼트로 추가합니다.
+`appendChild` 와 동일한 함수입니다.
+
## \$\$appendRotateTransform
- [source](../src/appendRotateTransform/appendRotateTransform.index.js)
@@ -13,6 +21,14 @@
`SVGTransform.SVG_TRANSFORM_ROTATE` 타입의 `SVGTransform` 의 `angle` 값에 입력받은 `angle`을 더합니다.
+## \$\$appendTo
+
+- [source](../src/appendTo/appendTo.index.js)
+- [detail](../src/appendTo/README.md)
+
+첫 번째로 받은 엘리먼트에 두 번째로 받은 엘리먼트를 자식 엘리먼트로 추가합니다.
+`appendChild` 와 동일한 함수입니다.
+
## \$\$appendTranslateTransform
- [source](../src/appendTranslateTransform/appendTranslateTransform.index.js)
@@ -311,6 +327,20 @@ svg 엘리먼트에 가장 마지막으로 적용된 `SVGTransform` 이 `SVGTran
해당 `SVGTransform` 을 svg 엘리먼트의 `x`, `y` 속성 (혹은 그에 준하는 속성) 에 반영합니다.
svg 엘리먼트에 다른 `SVGTransform` 이 있는 경우 각 `SVGTransform` 을 업데이트합니다.
+## \$\$qs
+
+- [source](../src/qs/qs.index.js)
+- [detail](../src/qs/README.md)
+
+부모 엘리먼트에서 가장 먼저 셀렉터에 해당하는 자손 엘리먼트를 찾아 반환합니다. `querySelector` 와 동일한 함수입니다.
+
+## \$\$qsa
+
+- [source](../src/qsa/qsa.index.js)
+- [detail](../src/qsa/README.md)
+
+부모 엘리먼트에서 셀렉터에 해당하는 자손 엘리먼트 목록을 찾아 반환합니다. `querySelectorAll` 과 동일한 함수입니다.
+
## \$\$removeAttrNS
- [source](../src/removeAttrNS/removeAttrNS.index.js)
diff --git a/package-lock.json b/package-lock.json
index 99e89ab..b2bfb87 100644
--- a/package-lock.json
+++ b/package-lock.json
@@ -1,6 +1,6 @@
{
"name": "fxsvg",
- "version": "0.4.4",
+ "version": "0.4.5",
"lockfileVersion": 1,
"requires": true,
"dependencies": {
diff --git a/package.json b/package.json
index 1345c8b..552a787 100644
--- a/package.json
+++ b/package.json
@@ -1,6 +1,6 @@
{
"name": "fxsvg",
- "version": "0.4.4",
+ "version": "0.4.5",
"description": "Functional SVG Handling Library",
"type": "module",
"main": "./src/index.js",
diff --git a/src/LiveScaleTransform2/LiveScaleTransform2.spec.js b/src/LiveScaleTransform2/LiveScaleTransform2.spec.js
index c9c9c2c..f18a125 100644
--- a/src/LiveScaleTransform2/LiveScaleTransform2.spec.js
+++ b/src/LiveScaleTransform2/LiveScaleTransform2.spec.js
@@ -6,6 +6,7 @@ import { makeRandomNumber } from "../../test/utils/makeRandomNumber.js";
import { makeRandomNumberExcept } from "../../test/utils/makeRandomNumberExcept.js";
import { makeRandomTransformAttributeValue } from "../../test/utils/makeRandomTransformAttributeValue.js";
import { $$createSVGTransformScale } from "../createSVGTransformScale/createSVGTransformScale.index.js";
+import { $$getAttrNS } from "../getAttrNS/getAttrNS.index.js";
import { $$getBaseTransformList } from "../getBaseTransformList/getBaseTransformList.index.js";
import { $$isScaleSVGTransform } from "../isScaleSVGTransform/isScaleSVGTransform.index.js";
import { $$LiveScaleTransform2 } from "./LiveScaleTransform2.index.js";
@@ -186,7 +187,7 @@ export default ({ describe, it }) => [
live_scale_transform.$$merge();
const [x2, y2, width2, height2] = mapL(
- (k) => parseFloat($el.getAttributeNS(null, k)),
+ (k) => parseFloat($$getAttrNS(k)($el)),
[x_name, y_name, width_name, height_name]
);
let expect_x;
diff --git a/src/LiveTranslateTransform/LiveTranslateTransform.spec.js b/src/LiveTranslateTransform/LiveTranslateTransform.spec.js
index 21fc67d..7797353 100644
--- a/src/LiveTranslateTransform/LiveTranslateTransform.spec.js
+++ b/src/LiveTranslateTransform/LiveTranslateTransform.spec.js
@@ -5,6 +5,7 @@ import { makeRandomInt } from "../../test/utils/makeRandomInt.js";
import { makeRandomNumber } from "../../test/utils/makeRandomNumber.js";
import { makeRandomTransformAttributeValue } from "../../test/utils/makeRandomTransformAttributeValue.js";
import { $$createSVGTransformTranslate } from "../createSVGTransformTranslate/createSVGTransformTranslate.index.js";
+import { $$getAttrNS } from "../getAttrNS/getAttrNS.index.js";
import { $$getBaseTransformList } from "../getBaseTransformList/getBaseTransformList.index.js";
import { $$isTranslateSVGTransform } from "../isTranslateSVGTransform/isTranslateSVGTransform.index.js";
import { $$LiveTranslateTransform } from "./LiveTranslateTransform.index.js";
@@ -121,7 +122,7 @@ export default ({ describe, it }) => [
live_translate_transform.$$merge();
const { numberOfItems: l2 } = $$getBaseTransformList($el);
- const [x2, y2] = mapL((k) => parseFloat($el.getAttributeNS(null, k)), [
+ const [x2, y2] = mapL((k) => parseFloat($$getAttrNS(k)($el)), [
x_name,
y_name,
]);
diff --git a/src/append/README.md b/src/append/README.md
new file mode 100644
index 0000000..fbb2db0
--- /dev/null
+++ b/src/append/README.md
@@ -0,0 +1,19 @@
+# \$\$append
+
+- [source](./append.index.js)
+- [test](./append.spec.js)
+
+첫 번째로 받은 엘리먼트를 두 번째로 받은 엘리먼트의 자식 엘리먼트로 추가합니다.
+`appendChild` 와 동일한 함수입니다.
+
+```javascript
+const parent_el = $$el(``)();
+const child_el = $$el(``)();
+
+$$append(child_el)(parent_el);
+
+console.log(parent_el);
+//
+//
+//
+```
diff --git a/src/append/append.index.js b/src/append/append.index.js
new file mode 100644
index 0000000..bd4a946
--- /dev/null
+++ b/src/append/append.index.js
@@ -0,0 +1 @@
+export const $$append = (child) => (parent) => parent.appendChild(child);
diff --git a/src/append/append.spec.js b/src/append/append.spec.js
new file mode 100644
index 0000000..433f9f6
--- /dev/null
+++ b/src/append/append.spec.js
@@ -0,0 +1,19 @@
+import { expect } from "chai";
+import { $$el } from "../el/el.index.js";
+import { $$append } from "./append.index.js";
+
+export default ({ describe, it }) => [
+ describe(`$$append`, function () {
+ it(`The function append the element to the parent element as a child element.`, function () {
+ // given
+ const parent_el = $$el(``)();
+ const child_el = $$el(``)();
+
+ // when
+ $$append(child_el)(parent_el);
+
+ // then
+ expect(parent_el.contains(child_el)).true;
+ });
+ }),
+];
diff --git a/src/appendTo/README.md b/src/appendTo/README.md
new file mode 100644
index 0000000..8fd9b54
--- /dev/null
+++ b/src/appendTo/README.md
@@ -0,0 +1,19 @@
+# \$\$appendTo
+
+- [source](./appendTo.index.js)
+- [test](./appendTo.spec.js)
+
+첫 번째로 받은 엘리먼트에 두 번째로 받은 엘리먼트를 자식 엘리먼트로 추가합니다.
+`appendChild` 와 동일한 함수입니다.
+
+```javascript
+const parent_el = $$el(``)();
+const child_el = $$el(``)();
+
+$$appendTo(parent_el)(child_el);
+
+console.log(parent_el);
+//
+//
+//
+```
diff --git a/src/appendTo/appendTo.index.js b/src/appendTo/appendTo.index.js
new file mode 100644
index 0000000..b9c5e79
--- /dev/null
+++ b/src/appendTo/appendTo.index.js
@@ -0,0 +1,3 @@
+export const $$appendTo = (parent) => (child) => (
+ parent.appendChild(child), parent
+);
diff --git a/src/appendTo/appendTo.spec.js b/src/appendTo/appendTo.spec.js
new file mode 100644
index 0000000..7a5272c
--- /dev/null
+++ b/src/appendTo/appendTo.spec.js
@@ -0,0 +1,19 @@
+import { expect } from "chai";
+import { $$el } from "../el/el.index.js";
+import { $$appendTo } from "./appendTo.index.js";
+
+export default ({ describe, it }) => [
+ describe(`$$appendTo`, function () {
+ it(`The function append the element to the parent element as a child element.`, function () {
+ // given
+ const parent_el = $$el(``)();
+ const child_el = $$el(``)();
+
+ // when
+ $$appendTo(parent_el)(child_el);
+
+ // then
+ expect(parent_el.contains(child_el)).true;
+ });
+ }),
+];
diff --git a/src/el/el.spec.js b/src/el/el.spec.js
index 85f6d00..062bf00 100644
--- a/src/el/el.spec.js
+++ b/src/el/el.spec.js
@@ -1,5 +1,6 @@
import { expect } from "chai";
import { flatMapL, mapL } from "fxjs2";
+import { $$getAttrNS } from "../getAttrNS/getAttrNS.index.js";
import { $$el } from "./el.index.js";
const MOCK_STR = ``;
@@ -12,9 +13,9 @@ const setupSVGList = () => [
const expectElFromMockStr = ($el) => {
expect($el).instanceof(SVGElement);
expect($el.nodeName.toLowerCase()).equal("circle");
- expect($el.getAttributeNS(null, "cx")).equal("10");
- expect($el.getAttributeNS(null, "cy")).equal("20");
- expect($el.getAttributeNS(null, "r")).equal("30");
+ expect($$getAttrNS("cx")($el)).equal("10");
+ expect($$getAttrNS("cy")($el)).equal("20");
+ expect($$getAttrNS("r")($el)).equal("30");
};
export default ({ describe, it }) => [
diff --git a/src/els/els.spec.js b/src/els/els.spec.js
index 9521f56..73d39db 100644
--- a/src/els/els.spec.js
+++ b/src/els/els.spec.js
@@ -11,6 +11,7 @@ import {
zip,
} from "fxjs2";
import { makeRandomInt } from "../../test/utils/makeRandomInt.js";
+import { $$getAttrNS } from "../getAttrNS/getAttrNS.index.js";
import { $$els } from "./els.index.js";
const setupSVGList = () => [
@@ -79,7 +80,7 @@ export default ({ describe, it }) => [
expect($el).instanceof(SVGElement);
expect($el.nodeName.toLowerCase()).equal(name);
for (const [key, expect_value] of entriesL(attrs)) {
- const receive_value = $el.getAttributeNS(null, key);
+ const receive_value = $$getAttrNS(key)($el);
expect(receive_value).equal(expect_value);
}
}
diff --git a/src/fxsvg.js b/src/fxsvg.js
index 3fe65a4..951ccff 100644
--- a/src/fxsvg.js
+++ b/src/fxsvg.js
@@ -1,4 +1,6 @@
+import { $$append } from "./append/append.index.js";
import { $$appendRotateTransform } from "./appendRotateTransform/appendRotateTransform.index.js";
+import { $$appendTo } from "./appendTo/appendTo.index.js";
import { $$appendTranslateTransform } from "./appendTranslateTransform/appendTranslateTransform.index.js";
import { $$consolidateTransformList } from "./consolidateTransformList/consolidateTransformList.index.js";
import { $$createSVGMatrix } from "./createSVGMatrix/createSVGMatrix.index.js";
@@ -38,6 +40,8 @@ import { $$mergeRotateTransform } from "./mergeRotateTransform/mergeRotateTransf
import { $$mergeScaleTransform } from "./mergeScaleTransform/mergeScaleTransform.index.js";
import { $$mergeScaleTransform2 } from "./mergeScaleTransform2/mergeScaleTransform2.index.js";
import { $$mergeTranslateTransform } from "./mergeTranslateTransform/mergeTranslateTransform.index.js";
+import { $$qs } from "./qs/qs.index.js";
+import { $$qsa } from "./qsa/qsa.index.js";
import { $$removeAttrNS } from "./removeAttrNS/removeAttrNS.index.js";
import { $$setAttrNS } from "./setAttrNS/setAttrNS.index.js";
import { $$updateMatrixTransform } from "./updateMatrixTransform/updateMatrixTransform.index.js";
@@ -46,7 +50,9 @@ import { $$updateScaleTransform } from "./updateScaleTransform/updateScaleTransf
import { $$updateTranslateTransform } from "./updateTranslateTransform/updateTranslateTransform.index.js";
export const FxSVG = {
+ append: $$append,
appendRotateTransform: $$appendRotateTransform,
+ appendTo: $$appendTo,
appendTranslateTransform: $$appendTranslateTransform,
consolidateTransformList: $$consolidateTransformList,
createSVGMatrix: $$createSVGMatrix,
@@ -87,6 +93,8 @@ export const FxSVG = {
mergeScaleTransform: $$mergeScaleTransform,
mergeScaleTransform2: $$mergeScaleTransform2,
mergeTranslateTransform: $$mergeTranslateTransform,
+ qs: $$qs,
+ qsa: $$qsa,
removeAttrNS: $$removeAttrNS,
setAttrNS: $$setAttrNS,
updateMatrixTransform: $$updateMatrixTransform,
diff --git a/src/getBoxPoints/README.md b/src/getBoxPoints/README.md
index ffc4c3f..03408d8 100644
--- a/src/getBoxPoints/README.md
+++ b/src/getBoxPoints/README.md
@@ -21,7 +21,7 @@ const str = `
`;
const $el = $$el(str)();
-$svg.appendChild($el);
+$$append($el)($svg);
console.log($$getBoxPoints($el));
// {original: {...}, transformed: {...}, bounding: {...}}
// original:
diff --git a/src/getBoxPoints/getBoxPoints.spec.js b/src/getBoxPoints/getBoxPoints.spec.js
index 5535673..0093985 100644
--- a/src/getBoxPoints/getBoxPoints.spec.js
+++ b/src/getBoxPoints/getBoxPoints.spec.js
@@ -4,6 +4,7 @@ import { makeMockRect } from "../../test/utils/makeMockRect.js";
import { makeRandomInt } from "../../test/utils/makeRandomInt.js";
import { makeRandomNumber } from "../../test/utils/makeRandomNumber.js";
import { makeRandomTransformAttributeValue } from "../../test/utils/makeRandomTransformAttributeValue.js";
+import { $$append } from "../append/append.index.js";
import { $$createSVGMatrix } from "../createSVGMatrix/createSVGMatrix.index.js";
import { $$getBaseTransformList } from "../getBaseTransformList/getBaseTransformList.index.js";
import { $$getBoxPoints } from "./getBoxPoints.index.js";
@@ -25,7 +26,7 @@ const setupMock = ({ transform } = {}) => {
});
document.body.appendChild($svg);
- $svg.appendChild($el);
+ $$append($el)($svg);
return { x, y, width, height, $el, $svg };
};
diff --git a/src/getCenterPoint/README.md b/src/getCenterPoint/README.md
index 306ae9e..73ec3ef 100644
--- a/src/getCenterPoint/README.md
+++ b/src/getCenterPoint/README.md
@@ -23,7 +23,7 @@ const str = `
`;
const $el = $$el(str)();
-$svg.appendChild($el);
+$$append($el)($svg);
console.log($$getCenterPoint($el));
// {original: SVGPoint, transformed: SVGPoint}
diff --git a/src/getCenterPoint/getCenterPoint.spec.js b/src/getCenterPoint/getCenterPoint.spec.js
index 4eec7be..1afc2d9 100644
--- a/src/getCenterPoint/getCenterPoint.spec.js
+++ b/src/getCenterPoint/getCenterPoint.spec.js
@@ -4,6 +4,7 @@ import { makeMockRect } from "../../test/utils/makeMockRect.js";
import { makeRandomInt } from "../../test/utils/makeRandomInt.js";
import { makeRandomNumber } from "../../test/utils/makeRandomNumber.js";
import { makeRandomTransformAttributeValue } from "../../test/utils/makeRandomTransformAttributeValue.js";
+import { $$append } from "../append/append.index.js";
import { $$createSVGPoint } from "../createSVGPoint/createSVGPoint.index.js";
import { $$getBoxPoints } from "../getBoxPoints/getBoxPoints.index.js";
import { $$getCenterPoint } from "./getCenterPoint.index.js";
@@ -20,7 +21,7 @@ const setupMock = ({ transform } = {}) => {
});
document.body.appendChild($svg);
- $svg.appendChild($el);
+ $$append($el)($svg);
return { $el, $svg };
};
diff --git a/src/index.js b/src/index.js
index ada44e0..a539ca9 100644
--- a/src/index.js
+++ b/src/index.js
@@ -1,4 +1,6 @@
+export { $$append } from "./append/append.index.js";
export { $$appendRotateTransform } from "./appendRotateTransform/appendRotateTransform.index.js";
+export { $$appendTo } from "./appendTo/appendTo.index.js";
export { $$appendTranslateTransform } from "./appendTranslateTransform/appendTranslateTransform.index.js";
export { $$consolidateTransformList } from "./consolidateTransformList/consolidateTransformList.index.js";
export { $$createSVGMatrix } from "./createSVGMatrix/createSVGMatrix.index.js";
@@ -38,6 +40,8 @@ export { $$mergeRotateTransform } from "./mergeRotateTransform/mergeRotateTransf
export { $$mergeScaleTransform } from "./mergeScaleTransform/mergeScaleTransform.index.js";
export { $$mergeScaleTransform2 } from "./mergeScaleTransform2/mergeScaleTransform2.index.js";
export { $$mergeTranslateTransform } from "./mergeTranslateTransform/mergeTranslateTransform.index.js";
+export { $$qs } from "./qs/qs.index.js";
+export { $$qsa } from "./qsa/qsa.index.js";
export { $$removeAttrNS } from "./removeAttrNS/removeAttrNS.index.js";
export { $$setAttrNS } from "./setAttrNS/setAttrNS.index.js";
export { $$updateMatrixTransform } from "./updateMatrixTransform/updateMatrixTransform.index.js";
diff --git a/src/mergeScaleTransform2/mergeScaleTransform2.index.js b/src/mergeScaleTransform2/mergeScaleTransform2.index.js
index 8458720..c0596d5 100644
--- a/src/mergeScaleTransform2/mergeScaleTransform2.index.js
+++ b/src/mergeScaleTransform2/mergeScaleTransform2.index.js
@@ -1,6 +1,8 @@
import { each, go, go1, mapL, rangeL, some } from "fxjs2";
+import { $$getAttrNS } from "../getAttrNS/getAttrNS.index.js";
import { $$getBaseTransformList } from "../getBaseTransformList/getBaseTransformList.index.js";
import { $$isValidFxScaleSVGTransformList } from "../isValidFxScaleSVGTransformList/isValidFxScaleSVGTransformList.index.js";
+import { $$setAttrNS } from "../setAttrNS/setAttrNS.index.js";
const VALID_DIRECTION = new Set(["n", "ne", "e", "se", "s", "sw", "w", "nw"]);
@@ -29,7 +31,7 @@ export const $$mergeScaleTransform2 = ({
);
const [x, y, width, height] = go(
[x_name, y_name, width_name, height_name],
- mapL((name) => $el.getAttributeNS(null, name)),
+ mapL((name) => $$getAttrNS(name)($el)),
mapL(parseFloat)
);
@@ -57,7 +59,7 @@ export const $$mergeScaleTransform2 = ({
[height_name, height * Math.abs(sy)],
],
mapL(([k, v]) => [k, `${v}`]),
- each(([k, v]) => $el.setAttributeNS(null, k, v))
+ each((kv) => $$setAttrNS(kv)($el))
);
each(() => transform_list.removeItem(index - 1), rangeL(3));
diff --git a/src/mergeScaleTransform2/mergeScaleTransform2.spec.js b/src/mergeScaleTransform2/mergeScaleTransform2.spec.js
index 17bc1ec..5bd2504 100644
--- a/src/mergeScaleTransform2/mergeScaleTransform2.spec.js
+++ b/src/mergeScaleTransform2/mergeScaleTransform2.spec.js
@@ -22,6 +22,7 @@ import {
makeRandomTransformAttributeValue,
makeMockRectInitiatedScaleTransform,
} from "../../test/utils/index.js";
+import { $$getAttrNS } from "../getAttrNS/getAttrNS.index.js";
import { $$getBaseTransformList } from "../getBaseTransformList/getBaseTransformList.index.js";
import { makeInvalidCases as makeInvalidIsValidFxSVGTransformListCases } from "../isValidFxScaleSVGTransformList/isValidFxScaleSVGTransformList.spec.js";
import { $$mergeScaleTransform2 } from "./mergeScaleTransform2.index.js";
@@ -121,7 +122,7 @@ export default ({ describe, it }) => [
const [after_x, after_y, after_width, after_height] = go(
["x", "y", "width", "height"],
- mapL((k) => $output.getAttributeNS(null, k)),
+ mapL((k) => $$getAttrNS(k)($output)),
mapL(parseFloat)
);
const after_transform_list = deepCopyTransformList(
@@ -223,7 +224,7 @@ export default ({ describe, it }) => [
);
const [after_x, after_y, after_width, after_height] = go(
["x", "y", "width", "height"],
- mapL((k) => $output.getAttributeNS(null, k)),
+ mapL((k) => $$getAttrNS(k)($output)),
mapL(parseFloat)
);
expectNotChange(
@@ -340,7 +341,7 @@ export default ({ describe, it }) => [
const [after_width, after_height] = go(
["width", "height"],
- mapL((k) => $el.getAttributeNS(null, k)),
+ mapL((k) => $$getAttrNS(k)($el)),
mapL(parseFloat)
);
expect(after_width).equal(before_width * Math.abs(sx));
@@ -381,7 +382,7 @@ export default ({ describe, it }) => [
height_name: "height",
})($el);
- const after_x = parseFloat($el.getAttributeNS(null, "x"));
+ const after_x = parseFloat($$getAttrNS("x")($el));
expect(after_x).equal(before_x);
}
});
@@ -419,7 +420,7 @@ export default ({ describe, it }) => [
height_name: "height",
})($el);
- const after_y = parseFloat($el.getAttributeNS(null, "y"));
+ const after_y = parseFloat($$getAttrNS("y")($el));
expect(after_y).equal(before_y);
}
});
@@ -478,7 +479,7 @@ export default ({ describe, it }) => [
height_name: "height",
})($el);
- const after_x = parseFloat($el.getAttributeNS(null, "x"));
+ const after_x = parseFloat($$getAttrNS("x")($el));
expect(after_x).equal((before_x - cx) * sx + cx);
}
});
@@ -537,7 +538,7 @@ export default ({ describe, it }) => [
height_name: "height",
})($el);
- const after_y = parseFloat($el.getAttributeNS(null, "y"));
+ const after_y = parseFloat($$getAttrNS("y")($el));
expect(after_y).equal((before_y - cy) * sy + cy);
}
});
@@ -578,7 +579,7 @@ export default ({ describe, it }) => [
height_name: "height",
})($el);
- const after_x = parseFloat($el.getAttributeNS(null, "x"));
+ const after_x = parseFloat($$getAttrNS("x")($el));
expect(after_x).equal((before_x - cx) * sx + cx + width * sx);
}
});
@@ -619,7 +620,7 @@ export default ({ describe, it }) => [
height_name: "height",
})($el);
- const after_y = parseFloat($el.getAttributeNS(null, "y"));
+ const after_y = parseFloat($$getAttrNS("y")($el));
expect(after_y).equal((before_y - cy) * sy + cy + height * sy);
}
});
diff --git a/src/mergeTranslateTransform/mergeTranslateTransform.index.js b/src/mergeTranslateTransform/mergeTranslateTransform.index.js
index c401861..08e97e0 100644
--- a/src/mergeTranslateTransform/mergeTranslateTransform.index.js
+++ b/src/mergeTranslateTransform/mergeTranslateTransform.index.js
@@ -1,8 +1,10 @@
import { each, go, mapL, rangeL } from "fxjs2";
import { $$createSVGTransformTranslate } from "../createSVGTransformTranslate/createSVGTransformTranslate.index.js";
+import { $$getAttrNS } from "../getAttrNS/getAttrNS.index.js";
import { $$getBaseTransformList } from "../getBaseTransformList/getBaseTransformList.index.js";
import { $$getSVG } from "../getSetSVG/getSetSVG.index.js";
import { $$isTranslateSVGTransform } from "../isTranslateSVGTransform/isTranslateSVGTransform.index.js";
+import { $$setAttrNS } from "../setAttrNS/setAttrNS.index.js";
export const $$mergeTranslateTransform = ({
index = 0,
@@ -26,11 +28,11 @@ export const $$mergeTranslateTransform = ({
{ name: x_name, value: tx },
{ name: y_name, value: ty },
],
- mapL(({ name, value }) => ({
+ mapL(({ name, value }) => [
name,
- value: `${parseFloat($el.getAttributeNS(null, name)) + value}`,
- })),
- each(({ name, value }) => $el.setAttributeNS(null, name, value))
+ `${parseFloat($$getAttrNS(name)($el)) + value}`,
+ ]),
+ each((kv) => $$setAttrNS(kv)($el))
);
base_transform_list.removeItem(index);
diff --git a/src/mergeTranslateTransform/mergeTranslateTransform.spec.js b/src/mergeTranslateTransform/mergeTranslateTransform.spec.js
index 862d910..a7c997a 100644
--- a/src/mergeTranslateTransform/mergeTranslateTransform.spec.js
+++ b/src/mergeTranslateTransform/mergeTranslateTransform.spec.js
@@ -14,6 +14,7 @@ import { $$createSVGTransformMatrix } from "../createSVGTransformMatrix/createSV
import { $$createSVGTransformRotate } from "../createSVGTransformRotate/createSVGTransformRotate.index.js";
import { $$createSVGTransformScale } from "../createSVGTransformScale/createSVGTransformScale.index.js";
import { $$createSVGTransformTranslate } from "../createSVGTransformTranslate/createSVGTransformTranslate.index.js";
+import { $$getAttrNS } from "../getAttrNS/getAttrNS.index.js";
import { $$getBaseTransformList } from "../getBaseTransformList/getBaseTransformList.index.js";
import { $$mergeTranslateTransform } from "./mergeTranslateTransform.index.js";
@@ -46,10 +47,10 @@ export default ({ describe, it }) => [
const { numberOfItems: transform_list_length } = $$getBaseTransformList(
$input
);
- const [before_x, before_y] = mapL(
- (k) => $input.getAttributeNS(null, k),
- ["x", "y"]
- );
+ const [before_x, before_y] = mapL((k) => $$getAttrNS(k)($input), [
+ "x",
+ "y",
+ ]);
const before_transform_list = deepCopyTransformList(
$$getBaseTransformList($input)
);
@@ -63,10 +64,10 @@ export default ({ describe, it }) => [
y_name: "y",
})($input, $svg);
- const [after_x, after_y] = mapL(
- (k) => $output.getAttributeNS(null, k),
- ["x", "y"]
- );
+ const [after_x, after_y] = mapL((k) => $$getAttrNS(k)($output), [
+ "x",
+ "y",
+ ]);
const after_transform_list = deepCopyTransformList(
$$getBaseTransformList($output)
);
@@ -99,10 +100,10 @@ export default ({ describe, it }) => [
})(),
index
);
- const [before_x, before_y] = mapL(
- (k) => $input.getAttributeNS(null, k),
- ["x", "y"]
- );
+ const [before_x, before_y] = mapL((k) => $$getAttrNS(k)($input), [
+ "x",
+ "y",
+ ]);
const before_transform_list = deepCopyTransformList(
$$getBaseTransformList($input)
);
@@ -113,10 +114,10 @@ export default ({ describe, it }) => [
y_name: "y",
})($input, $svg);
- const [after_x, after_y] = mapL(
- (k) => $output.getAttributeNS(null, k),
- ["x", "y"]
- );
+ const [after_x, after_y] = mapL((k) => $$getAttrNS(k)($output), [
+ "x",
+ "y",
+ ]);
const after_transform_list = deepCopyTransformList(
$$getBaseTransformList($output)
);
@@ -149,10 +150,10 @@ export default ({ describe, it }) => [
})(),
index
);
- const [before_x, before_y] = mapL(
- (k) => $input.getAttributeNS(null, k),
- ["x", "y"]
- );
+ const [before_x, before_y] = mapL((k) => $$getAttrNS(k)($input), [
+ "x",
+ "y",
+ ]);
const before_transform_list = deepCopyTransformList(
$$getBaseTransformList($input)
);
@@ -163,10 +164,10 @@ export default ({ describe, it }) => [
y_name: "y",
})($input, $svg);
- const [after_x, after_y] = mapL(
- (k) => $output.getAttributeNS(null, k),
- ["x", "y"]
- );
+ const [after_x, after_y] = mapL((k) => $$getAttrNS(k)($output), [
+ "x",
+ "y",
+ ]);
const after_transform_list = deepCopyTransformList(
$$getBaseTransformList($output)
);
@@ -198,10 +199,10 @@ export default ({ describe, it }) => [
})(),
index
);
- const [before_x, before_y] = mapL(
- (k) => $input.getAttributeNS(null, k),
- ["x", "y"]
- );
+ const [before_x, before_y] = mapL((k) => $$getAttrNS(k)($input), [
+ "x",
+ "y",
+ ]);
const before_transform_list = deepCopyTransformList(
$$getBaseTransformList($input)
);
@@ -212,10 +213,10 @@ export default ({ describe, it }) => [
y_name: "y",
})($input, $svg);
- const [after_x, after_y] = mapL(
- (k) => $output.getAttributeNS(null, k),
- ["x", "y"]
- );
+ const [after_x, after_y] = mapL((k) => $$getAttrNS(k)($output), [
+ "x",
+ "y",
+ ]);
const after_transform_list = deepCopyTransformList(
$$getBaseTransformList($output)
);
@@ -292,8 +293,8 @@ export default ({ describe, it }) => [
y_name: "y",
})($input, $svg);
- expect($output.getAttributeNS(null, "x")).equal(`${x + tx}`);
- expect($output.getAttributeNS(null, "y")).equal(`${y + ty}`);
+ expect($$getAttrNS("x")($output)).equal(`${x + tx}`);
+ expect($$getAttrNS("y")($output)).equal(`${y + ty}`);
}
});
}),
diff --git a/src/qs/README.md b/src/qs/README.md
new file mode 100644
index 0000000..ce901b3
--- /dev/null
+++ b/src/qs/README.md
@@ -0,0 +1,19 @@
+# \$\$qs
+
+- [source](./qs.index.js)
+- [test](./qs.spec.js)
+
+부모 엘리먼트에서 가장 먼저 셀렉터에 해당하는 자손 엘리먼트를 찾아 반환합니다. `querySelector` 와 동일한 함수입니다.
+
+```javascript
+const el = $$el(`
+
+
+
+
+`)();
+const child = $$qs("*", el);
+
+console.log(child);
+//
+```
diff --git a/src/qs/qs.index.js b/src/qs/qs.index.js
new file mode 100644
index 0000000..9d71a3b
--- /dev/null
+++ b/src/qs/qs.index.js
@@ -0,0 +1 @@
+export const $$qs = (sel, base = document) => base.querySelector(sel);
diff --git a/src/qs/qs.spec.js b/src/qs/qs.spec.js
new file mode 100644
index 0000000..5ba34ad
--- /dev/null
+++ b/src/qs/qs.spec.js
@@ -0,0 +1,34 @@
+import { expect } from "chai";
+import { $$append } from "../append/append.index.js";
+import { $$el } from "../el/el.index.js";
+import { $$qs } from "./qs.index.js";
+
+export default ({ describe, it }) => [
+ describe(`$$qs`, function () {
+ it(`The function returns the element matched with the selector.`, function () {
+ // given
+ const g_el = $$el(``)();
+ const a_el = $$el(``)();
+ $$append(a_el)(g_el);
+
+ // when
+ const received = $$qs("circle", g_el);
+
+ // then
+ expect(received).equal(a_el);
+ });
+
+ it(`The function returns "null" when there is no matched element.`, function () {
+ // given
+ const g_el = $$el(``)();
+ const a_el = $$el(``)();
+ $$append(a_el)(g_el);
+
+ // when
+ const received = $$qs("rect", g_el);
+
+ // then
+ expect(received).null;
+ });
+ }),
+];
diff --git a/src/qsa/README.md b/src/qsa/README.md
new file mode 100644
index 0000000..e5e9723
--- /dev/null
+++ b/src/qsa/README.md
@@ -0,0 +1,19 @@
+# \$\$qsa
+
+- [source](./qsa.index.js)
+- [test](./qsa.spec.js)
+
+부모 엘리먼트에서 셀렉터에 해당하는 자손 엘리먼트 목록을 찾아 반환합니다. `querySelectorAll` 과 동일한 함수입니다.
+
+```javascript
+const el = $$el(`
+
+
+
+
+`)();
+const list = $$qsa("*", el);
+
+console.log(list);
+// NodeList(2) [circle, rect]
+```
diff --git a/src/qsa/qsa.index.js b/src/qsa/qsa.index.js
new file mode 100644
index 0000000..6aac3d4
--- /dev/null
+++ b/src/qsa/qsa.index.js
@@ -0,0 +1 @@
+export const $$qsa = (sel, base = document) => base.querySelectorAll(sel);
diff --git a/src/qsa/qsa.spec.js b/src/qsa/qsa.spec.js
new file mode 100644
index 0000000..426927c
--- /dev/null
+++ b/src/qsa/qsa.spec.js
@@ -0,0 +1,47 @@
+import { expect } from "chai";
+import { $$append } from "../append/append.index.js";
+import { $$el } from "../el/el.index.js";
+import { $$qsa } from "./qsa.index.js";
+
+export default ({ describe, it }) => [
+ describe(`$$qsa`, function () {
+ it(`The function returns a NodeList that contains elements matched with the selector.`, function () {
+ // given
+ const g_el = $$el(``)();
+ const class_name = "test";
+ const a_el = $$el(
+ ``
+ )();
+ $$append(a_el)(g_el);
+ const b_el = $$el(
+ ``
+ )();
+ $$append(b_el)(g_el);
+
+ // when
+ const received = $$qsa(`.${class_name}`, g_el);
+
+ // then
+ expect(received).instanceof(NodeList);
+ expect(received.length).equal(2);
+ expect(received).include(a_el);
+ expect(received).include(b_el);
+ });
+
+ it(`The function returns an empty NodeList when there is no matched elements with the selector.`, function () {
+ // given
+ const g_el = $$el(``)();
+ $$append($$el(``)())(g_el);
+ $$append($$el(``)())(
+ g_el
+ );
+
+ // when
+ const received = $$qsa(`#test`, g_el);
+
+ // then
+ expect(received).instanceof(NodeList);
+ expect(received.length).equal(0);
+ });
+ }),
+];
diff --git a/test/playground.html b/test/playground.html
index b549215..79f5315 100644
--- a/test/playground.html
+++ b/test/playground.html
@@ -26,9 +26,9 @@
(() => {
const { width, height } = document.body.getBoundingClientRect();
- $svg.setAttributeNS(null, "width", `${width}`);
- $svg.setAttributeNS(null, "height", `${height}`);
- $svg.setAttributeNS(null, "viewBox", "-1000 -1000 2000 2000");
+ FxSVG.setAttrNS(["width", `${width}`])($svg);
+ FxSVG.setAttrNS(["height", `${height}`])($svg);
+ FxSVG.setAttrNS(["viewBox", "-1000 -1000 2000 2000"])($svg);
})();