Comparing version 0.0.2 to 0.0.3
{ | ||
"name": "fxsvg", | ||
"version": "0.0.2", | ||
"version": "0.0.3", | ||
"description": "Functional SVG Handling Library", | ||
"type": "module", | ||
"main": "./src/index.js", | ||
@@ -6,0 +7,0 @@ "scripts": { |
317
README.md
@@ -7,11 +7,33 @@ # FxSVG | ||
### els | ||
### \$\$getSVG | ||
๋ด๋ถ์ ์ผ๋ก ์ฌ์ฉํ๋ svg ๊ฐ์ฒด๋ฅผ ๋ฐํํฉ๋๋ค. | ||
`$$setSVG` ํจ์๋ก ์ค์ ํ์ง ์์ ๊ฒฝ์ฐ `document.createElementNS` ๋ฅผ ์คํํฉ๋๋ค. | ||
ํด๋น ํจ์๋ฅผ ์คํํ์ง ๋ชปํ๋ ํ๊ฒฝ์ธ ๊ฒฝ์ฐ `$$setSVG` ํจ์๋ก ์ฌ์ฉํ svg ๊ฐ์ฒด๋ฅผ ์ค์ ํฉ๋๋ค. | ||
```javascript | ||
console.log($$getSVG()); | ||
// <svg></svg> | ||
``` | ||
### \$\$setSVG | ||
๋ด๋ถ์ ์ผ๋ก ์ฌ์ฉํ๋ svg ๊ฐ์ฒด๋ฅผ ์ค์ ํ ํ ์ค์ ํ svg ๊ฐ์ฒด๋ฅผ ๋ฐํํฉ๋๋ค. | ||
```javascript | ||
console.log( | ||
$$setSVG(document.createElementNS("http://www.w3.org/2000/svg", "svg")) | ||
); | ||
// <svg></svg> | ||
``` | ||
### \$\$els | ||
svg ๋ฌธ์์ด์ ๋ฐ์ svg ๊ฐ์ฒด๋ฅผ ๋ด์ ๋ฐฐ์ด์ ์์ฑํฉ๋๋ค. | ||
```javascript | ||
console.log(els('<rect x="0" y="0" width="10" height="10"></rect>')); | ||
console.log($$els('<rect x="0" y="0" width="10" height="10"></rect>')); | ||
// [rect] | ||
console.log( | ||
els( | ||
$$els( | ||
'<rect x="0" y="0" width="10" height="10"></rect><circle cx="1" cy="1" r="5"></circle>' | ||
@@ -23,3 +45,3 @@ ) | ||
### el | ||
### \$\$el | ||
@@ -29,6 +51,6 @@ svg ๋ฌธ์์ด์ ๋ฐ์ svg ๊ฐ์ฒด๋ฅผ ์์ฑํฉ๋๋ค. | ||
```javascript | ||
console.log(els('<rect x="0" y="0" width="10" height="10"></rect>')); | ||
console.log($$el('<rect x="0" y="0" width="10" height="10"></rect>')); | ||
// rect | ||
console.log( | ||
els( | ||
$$el( | ||
'<rect x="0" y="0" width="10" height="10"></rect><circle cx="1" cy="1" r="5"></circle>' | ||
@@ -39,1 +61,284 @@ ) | ||
``` | ||
### \$\$createSVGPoint | ||
`SVGPoint` ๊ฐ์ฒด๋ฅผ ์์ฑํฉ๋๋ค. | ||
```javascript | ||
console.log($$createSVGPoint()); | ||
// SVGPoint {x: 0, y: 0} | ||
console.log($$createSVGPoint({ x: 10 })); | ||
// SVGPoint {x: 10, y: 0} | ||
console.log($$createSVGPoint({ y: 10 })); | ||
// SVGPoint {x: 0, y: 10} | ||
console.log($$createSVGPoint({ x: 10, y: 10 })); | ||
// SVGPoint {x: 10, y: 10} | ||
``` | ||
### \$\$createSVGRect | ||
`SVGRect` ๊ฐ์ฒด๋ฅผ ์์ฑํฉ๋๋ค. | ||
```javascript | ||
console.log($$createSVGRect()); | ||
// SVGRect {x: 0, y: 0, width: 0, height: 0} | ||
console.log($$createSVGRect({ x: 10 })); | ||
// SVGRect {x: 10, y: 0, width: 0, height: 0} | ||
console.log($$createSVGRect({ width: 100 })); | ||
// SVGRect {x: 0, y: 0, width: 100, height: 0} | ||
console.log($$createSVGRect({ x: 10, y: 10, width: 100, height: 100 })); | ||
// SVGRect {x: 10, y: 10, width: 100, height: 100} | ||
``` | ||
### \$\$createSVGMatrix | ||
`SVGMatrix` ๊ฐ์ฒด๋ฅผ ์์ฑํฉ๋๋ค. | ||
```javascript | ||
console.log($$createSVGMatrix()); | ||
// SVGMatrix {a: 1, b: 0, c: 0, d: 1, e: 0, f: 0} | ||
console.log($$createSVGMatrix({ e: 10, f: 20 })); | ||
// SVGMatrix {a: 1, b: 0, c: 0, d: 1, e: 10, f: 20} | ||
console.log($$createSVGMatrix({ a: 2, b: 0, c: 0, d: 4, e: 10, f: 20 })); | ||
// SVGMatrix {a: 2, b: 0, c: 0, d: 4, e: 10, f: 20} | ||
``` | ||
### \$\$createSVGTransform | ||
`SVGTransform` ๊ฐ์ฒด๋ฅผ ์์ฑํฉ๋๋ค. | ||
```javascript | ||
console.log($$createSVGTransform()); | ||
// SVGTransform {type: 1, matrix: SVGMatrix, angle: 0} | ||
``` | ||
### \$\$createSVGTransformTranslate | ||
`type`์ด `SVGTransform.SVG_TRANSFORM_TRANSLATE`์ธ `SVGTransform` ๊ฐ์ฒด๋ฅผ ์์ฑํฉ๋๋ค. | ||
`tx`๋ก x์ถ ๋ฐฉํฅ์ผ๋ก ์ด๋ํ ๊ฐ, `ty`๋ก y์ถ ๋ฐฉํฅ์ผ๋ก ์ด๋ํ ๊ฐ์ ์ค์ ํฉ๋๋ค. | ||
```javascript | ||
console.log($$createSVGTransformTranslate()); | ||
// SVGTransform {type: 2, matrix: SVGMatrix, angle: 0} | ||
console.log($$createSVGTransformTranslate({ tx: 10 })); | ||
// SVGTransform {type: 2, matrix: SVGMatrix, angle: 0} | ||
// SVGMatrix {a: 1, b: 0, c: 0, d: 1, e: 10, f: 0} | ||
console.log($$createSVGTransformTranslate({ tx: 10, ty: 20 })); | ||
// SVGTransform {type: 2, matrix: SVGMatrix, angle: 0} | ||
// SVGMatrix {a: 1, b: 0, c: 0, d: 1, e: 10, f: 20} | ||
``` | ||
### \$\$createSVGTransformRotate | ||
`type`์ด `SVGTransform.SVG_TRANSFORM_ROTATE`์ธ `SVGTransform` ๊ฐ์ฒด๋ฅผ ์์ฑํฉ๋๋ค. | ||
`cx`, `cy`๋ก ํ์ ํ ์ค์ฌ์ ์ขํฌ๋ฅผ ์ค์ ํ๊ณ `angle`๋ก ํ์ ํ ๊ฐ๋(`deg` ๋จ์)๋ฅผ ์ค์ ํฉ๋๋ค. | ||
`cx`, `cy`๋ฅผ ์ค์ ํ์ง ์์ผ๋ฉด `(0, 0)`์ผ๋ก ์ค์ ํฉ๋๋ค. | ||
```javascript | ||
console.log($$createSVGTransformRotate()); | ||
// SVGTransform {type: 4, matrix: SVGMatrix, angle: 0} | ||
console.log($$createSVGTransformRotate({ angle: 45 })); | ||
// SVGTransform {type: 4, matrix: SVGMatrix, angle: 45} | ||
console.log($$createSVGTransformRotate({ cx: 10, cy: 10, angle: 30 })); | ||
// SVGTransform {type: 4, matrix: SVGMatrix, angle: 30} | ||
``` | ||
### \$\$createSVGTransformScale | ||
`type`์ด `SVGTransform.SVG_TRANSFORM_SCALE`์ธ `SVGTransform` ๊ฐ์ฒด๋ฅผ ์์ฑํฉ๋๋ค. | ||
`sx`๋ก x์ถ ๋ฐฉํฅ์ผ๋ก ํ๋ํ ๋น์จ์, `sy`๋ก y์ถ ๋ฐฉํฅ์ผ๋ก ํ๋ํ ๋น์จ์ ์ค์ ํฉ๋๋ค. | ||
`sx`, `sy`๊ฐ ์์์ผ ๊ฒฝ์ฐ ํด๋น ์ถ์ ๊ธฐ์ค์ผ๋ก ๋์นญ์ด๋ํฉ๋๋ค. | ||
```javascript | ||
console.log($$createSVGTransformScale()); | ||
// SVGTransform {type: 3, matrix: SVGMatrix, angle: 0} | ||
// SVGMatrix {a: 1, b: 0, c: 0, d: 1, e: 0, f: 0} | ||
console.log($$createSVGTransformScale({ sx: 2 })); | ||
// SVGTransform {type: 3, matrix: SVGMatrix, angle: 0} | ||
// SVGMatrix {a: 2, b: 0, c: 0, d: 1, e: 0, f: 0} | ||
console.log($$createSVGTransformScale({ sx: 2, sy: 4 })); | ||
// SVGTransform {type: 3, matrix: SVGMatrix, angle: 0} | ||
// SVGMatrix {a: 2, b: 0, c: 0, d: 4, e: 0, f: 0} | ||
``` | ||
### \$\$createSVGTransformMatrix | ||
`type`์ด `SVGTransform.SVG_TRANSFORM_MATRIX`์ธ `SVGTransform` ๊ฐ์ฒด๋ฅผ ์์ฑํฉ๋๋ค. | ||
`SVGTransform`์ ์ธ์๋ก ๋ฐ์ `SVGMatrix`๋ฅผ ์ค์ ํฉ๋๋ค. | ||
```javascript | ||
console.log($$createSVGTransformMatrix($$createSVGMatrix())); | ||
// SVGTransform {type: 1, matrix: SVGMatrix, angle: 0} | ||
// SVGMatrix {a: 1, b: 0, c: 0, d: 1, e: 0, f: 0} | ||
console.log( | ||
$$createSVGTransformMatrix( | ||
$$createSVGMatrix({ a: 2, b: 3, c: 4, d: 5, e: 6, f: 7 }) | ||
) | ||
); | ||
// SVGTransform {type: 1, matrix: SVGMatrix, angle: 0} | ||
// SVGMatrix {a: 2, b: 3, c: 4, d: 5, e: 6, f: 7} | ||
``` | ||
### \$\$isTranslateSVGTransform | ||
ํด๋น `SVGTransform`์ `type`์ด `SVGTransform.SVG_TRANSFORM_TRANSLATE`์ธ์ง ์ฌ๋ถ๋ฅผ ํ๋จํฉ๋๋ค. | ||
```javascript | ||
console.log($$isTranslateSVGTransform($$createSVGTransformTranslate())); | ||
// true | ||
console.log($$isTranslateSVGTransform($$createSVGTransformRotate())); | ||
// false | ||
``` | ||
### \$\$isRotateSVGTransform | ||
ํด๋น `SVGTransform`์ `type`์ด `SVGTransform.SVG_TRANSFORM_ROTATE`์ธ์ง ์ฌ๋ถ๋ฅผ ํ๋จํฉ๋๋ค. | ||
```javascript | ||
console.log($$isRotateSVGTransform($$createSVGTransformRotate())); | ||
// true | ||
console.log($$isRotateSVGTransform($$createSVGTransformTranslate())); | ||
// false | ||
``` | ||
### \$\$isScaleSVGTransform | ||
ํด๋น `SVGTransform`์ `type`์ด `SVGTransform.SVG_TRANSFORM_SCALE`์ธ์ง ์ฌ๋ถ๋ฅผ ํ๋จํฉ๋๋ค. | ||
```javascript | ||
console.log($$isScaleSVGTransform($$createSVGTransformScale())); | ||
// true | ||
console.log($$isScaleSVGTransform($$createSVGTransformTranslate())); | ||
// false | ||
``` | ||
### \$\$getBaseTransformList | ||
์ ๋ ฅ๋ฐ์ svg ๊ฐ์ฒด์ `transform.baseVal` ๊ฐ์ ๋ฐํํฉ๋๋ค. | ||
`SVGGraphicsElement` ์ธํฐํ์ด์ค๋ `transform` ์์ฑ์ผ๋ก `SVGAnimatedTransformList` ๊ฐ์ฒด๋ฅผ ๊ฐ์ง๊ณ ์๊ณ | ||
ํด๋น ๊ฐ์ฒด๋ `baseVal` ์์ฑ์ผ๋ก `SVGTransformList` ๊ฐ์ฒด๋ฅผ ๊ฐ์ง๊ณ ์์ต๋๋ค. | ||
```javascript | ||
const $el = $$el(` | ||
<rect | ||
x="0" | ||
y="0" | ||
width="10" | ||
height="20" | ||
transform="translate(10, 20) rotate(45, 100, 200) scale(2, 3)" | ||
></rect> | ||
`); | ||
console.log($$getBaseTransformList($el)); | ||
// SVGTransformList {0: SVGTransform, 1: SVGTransform, 2: SVGTransform, length: 3, numberOfItem: 3} | ||
// 0: SVGTransform - type: SVG_TRANSFORM_TRANSLATE | ||
// 1: SVGTransform - type: SVG_TRANSFORM_ROTATE | ||
// 2: SVGTransform - type: SVG_TRANSFORM_SCALE | ||
``` | ||
### \$\$getAnimTransformList | ||
์ ๋ ฅ๋ฐ์ svg ๊ฐ์ฒด์ `transform.animVal` ๊ฐ์ ๋ฐํํฉ๋๋ค. | ||
`SVGGraphicsElement` ์ธํฐํ์ด์ค๋ `transform` ์์ฑ์ผ๋ก `SVGAnimatedTransformList` ๊ฐ์ฒด๋ฅผ ๊ฐ์ง๊ณ ์๊ณ | ||
ํด๋น ๊ฐ์ฒด๋ `animVal` ์์ฑ์ผ๋ก `SVGTransformList` ๊ฐ์ฒด๋ฅผ ๊ฐ์ง๊ณ ์์ต๋๋ค. | ||
`animVal`์ SMIL ์ ๋๋ฉ์ด์ ์ด ์ ์ฉ๋ ๊ฒฝ์ฐ์๋ง `baseVal`๊ณผ ๋ค๋ฆ ๋๋ค. ํน๋ณํ ์ํฉ์ด ์๋ ํ ๋์ผํ ๊ฐ์ ๊ฐ์ง๋๋ค. | ||
ํ์ง๋ง ๊ฐ์ ๋์ผํด๋ ๋ค๋ฅธ ๋ํผ๋ฐ์ค๋ฅผ ๊ฐ๋ฆฌํต๋๋ค. | ||
```javascript | ||
const $el = $$el(` | ||
<rect | ||
x="0" | ||
y="0" | ||
width="10" | ||
height="20" | ||
transform="translate(10, 20) rotate(45, 100, 200) scale(2, 3)" | ||
></rect> | ||
`); | ||
console.log($$getAnimTransformList($el)); | ||
// SVGTransformList {0: SVGTransform, 1: SVGTransform, 2: SVGTransform, length: 3, numberOfItem: 3} | ||
// 0: SVGTransform - type: SVG_TRANSFORM_TRANSLATE | ||
// 1: SVGTransform - type: SVG_TRANSFORM_ROTATE | ||
// 2: SVGTransform - type: SVG_TRANSFORM_SCALE | ||
``` | ||
### \$\$getBoxPoints | ||
svg ๊ฐ์ฒด์ ์์ญ์ ํด๋นํ๋ `SVGPoint`๋ค์ ๋ฐํํฉ๋๋ค. ํด๋น svg ๊ฐ์ฒด๋ DOM ํธ๋ฆฌ์ `<svg></svg>` ํ๊ทธ์ ์ํด ์์ด์ผ ํฉ๋๋ค. | ||
`original` ์์ฑ์ svg ๊ฐ์ฒด๊ฐ `transform` ํ๊ธฐ ์ ์์ญ์ ๋๋ค. | ||
`transformed` ์์ฑ์ svg ๊ฐ์ฒด๊ฐ `transform` ํ ํ ์์ญ์ ๋๋ค. | ||
`bounding` ์์ฑ์ svg ๊ฐ์ฒด๊ฐ `transform` ํ ํ ์์ญ์ ๋ฎ๋ ์ต์ ์ง์ฌ๊ฐํ ์์ญ์ ๋๋ค. | ||
```javascript | ||
const $el = $$el(` | ||
<rect | ||
x="10" | ||
y="20" | ||
width="100" | ||
height="200" | ||
transform="translate(400, 500)" | ||
> | ||
</rect> | ||
`); | ||
$svg.appendChild($el); | ||
console.log($$getBoxPoints($el)); | ||
// {original: {...}, transformed: {...}, bounding: {...}} | ||
// original: | ||
// top_left: SVGPoint {x: 10, y: 20} | ||
// top_right: SVGPoint {x: 110, y: 20} | ||
// bottom_left: SVGPoint {x: 10, y: 220} | ||
// bottom_right: SVGPoint {x: 110, y: 220} | ||
// transformed: | ||
// top_left: SVGPoint {x: 410, y: 520} | ||
// top_right: SVGPoint {x: 510, y: 520} | ||
// bottom_left: SVGPoint {x: 410, y: 720} | ||
// bottom_right: SVGPoint {x: 510, y: 720} | ||
// bounding: | ||
// min: SVGPoint {x: 410, y: 520} | ||
// max: SVGPoint {x: 510, y: 720} | ||
``` | ||
### \$\$getCenterPoint | ||
svg ๊ฐ์ฒด์ ์ค์ฌ์ ํด๋นํ๋ `SVGPoint`๋ฅผ ๋ฐํํฉ๋๋ค. ํด๋น svg ๊ฐ์ฒด๋ DOM ํธ๋ฆฌ์ `<svg></svg>` ํ๊ทธ์ ์ํด ์์ด์ผ ํฉ๋๋ค. | ||
`original` ์์ฑ์ svg ๊ฐ์ฒด๊ฐ `transform` ํ๊ธฐ ์ ์ค์ฌ์ ๋๋ค. | ||
`transformed` ์์ฑ์ svg ๊ฐ์ฒด๊ฐ `transform` ํ ํ ์ค์ฌ์ ๋๋ค. | ||
```javascript | ||
const $el = $$el(` | ||
<rect | ||
x="10" | ||
y="20" | ||
width="100" | ||
height="200" | ||
transform="translate(400, 500)" | ||
> | ||
</rect> | ||
`); | ||
$svg.appendChild($el); | ||
console.log($$getCenterPoint($el)); | ||
// {original: SVGPoint, transformed: SVGPoint} | ||
// original: SVGPoint {x: 60, y: 120} | ||
// transformed: SVGPoint {x: 460, y: 620} | ||
``` |
@@ -1,3 +0,3 @@ | ||
import { els } from "./els.js"; | ||
import { $$els } from "./els.js"; | ||
export const el = (svg) => els(svg)[0]; | ||
export const $$el = (svg) => $$els(svg)[0]; |
@@ -1,14 +0,10 @@ | ||
import { getSVG } from "./getSetSVG.js"; | ||
import { $$getSVG } from "./getSetSVG.js"; | ||
export const els = (svg) => { | ||
export const $$els = (svg) => { | ||
svg = svg.trim(); | ||
const $svg = getSVG(); | ||
const $svg = $$getSVG(); | ||
$svg.innerHTML = svg; | ||
const result = []; | ||
for (const $el of $svg.childNodes) { | ||
$svg.removeChild($el); | ||
result.push($el); | ||
} | ||
const result = [...$svg.childNodes]; | ||
$svg.innerHTML = ""; | ||
return result; | ||
}; |
let $svg; | ||
export const setSVG = ($new_svg) => { | ||
export const $$setSVG = ($new_svg) => { | ||
$svg = $new_svg; | ||
@@ -8,7 +8,7 @@ return $svg; | ||
export const getSVG = () => { | ||
export const $$getSVG = () => { | ||
if (!$svg) { | ||
setSVG(document.createElementNS("http://www.w3.org/2000/svg", "svg")); | ||
$$setSVG(document.createElementNS("http://www.w3.org/2000/svg", "svg")); | ||
} | ||
return $svg; | ||
}; |
@@ -1,3 +0,19 @@ | ||
export { getSVG, setSVG } from "./getSetSVG.js"; | ||
export { els } from "./els.js"; | ||
export { el } from "./el.js"; | ||
export { $$getSVG, $$setSVG } from "./getSetSVG.js"; | ||
export { $$els } from "./els.js"; | ||
export { $$el } from "./el.js"; | ||
export { $$createSVGPoint } from "./createSVGPoint.js"; | ||
export { $$createSVGRect } from "./createSVGRect.js"; | ||
export { $$createSVGMatrix } from "./createSVGMatrix.js"; | ||
export { $$createSVGTransform } from "./createSVGTransform.js"; | ||
export { $$createSVGTransformTranslate } from "./createSVGTransformTranslate.js"; | ||
export { $$createSVGTransformRotate } from "./createSVGTransformRotate.js"; | ||
export { $$createSVGTransformScale } from "./createSVGTransformScale.js"; | ||
export { $$createSVGTransformMatrix } from "./createSVGTransformMatrix.js"; | ||
export { $$isTranslateSVGTransform } from "./isTranslateSVGTransform.js"; | ||
export { $$isRotateSVGTransform } from "./isRotateSVGTransform.js"; | ||
export { $$isScaleSVGTransform } from "./isScaleSVGTransform.js"; | ||
export { $$getBaseTransformList } from "./getBaseTransformList.js"; | ||
export { $$getAnimTransformList } from "./getAnimTransformList.js"; | ||
export { $$getBoxPoints } from "./getBoxPoints.js"; | ||
export { $$getCenterPoint } from "./getCenterPoint.js"; | ||
export { default } from "./index_default.js"; |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
20528
23
238
341
Yes