Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More โ†’
Socket
Sign inDemoInstall
Socket

fxsvg

Package Overview
Dependencies
Maintainers
3
Versions
41
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

fxsvg - npm Package Compare versions

Comparing version 0.0.2 to 0.0.3

src/createSVGMatrix.js

3

package.json
{
"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": {

@@ -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";
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with โšก๏ธ by Socket Inc