mirror of
https://github.com/ajayyy/SponsorBlock.git
synced 2026-01-27 04:40:49 +03:00
Add svgjs and testing with fake dom
This commit is contained in:
3319
package-lock.json
generated
3319
package-lock.json
generated
File diff suppressed because it is too large
Load Diff
@@ -4,6 +4,7 @@
|
|||||||
"description": "",
|
"description": "",
|
||||||
"main": "background.js",
|
"main": "background.js",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
|
"@svgdotjs/svg.js": "^3.1.1",
|
||||||
"@types/react": "^16.9.22",
|
"@types/react": "^16.9.22",
|
||||||
"@types/react-dom": "^16.9.5",
|
"@types/react-dom": "^16.9.5",
|
||||||
"@types/selenium-webdriver": "^4.0.15",
|
"@types/selenium-webdriver": "^4.0.15",
|
||||||
@@ -13,7 +14,8 @@
|
|||||||
"babel-preset-env": "^1.7.0",
|
"babel-preset-env": "^1.7.0",
|
||||||
"concurrently": "^5.1.0",
|
"concurrently": "^5.1.0",
|
||||||
"react": "^17.0.2",
|
"react": "^17.0.2",
|
||||||
"react-dom": "^17.0.2"
|
"react-dom": "^17.0.2",
|
||||||
|
"svgdom": "^0.1.8"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@types/chrome": "0.0.91",
|
"@types/chrome": "0.0.91",
|
||||||
|
|||||||
@@ -1,9 +1,29 @@
|
|||||||
import { VisualSegmentInfo } from "../types";
|
import { VisualSegmentInfo } from "../types";
|
||||||
|
import { Svg, SVG } from "@svgdotjs/svg.js";
|
||||||
|
|
||||||
export function toSVG(visuals: VisualSegmentInfo[]): string {
|
export function toSVG(visuals: VisualSegmentInfo[]): Svg {
|
||||||
throw new Error("Method not implemented.");
|
const svg = SVG().size(100, 100);
|
||||||
|
|
||||||
|
for (const visual of visuals) {
|
||||||
|
const path = svg.polygon();
|
||||||
|
path.fill(visual.color);
|
||||||
|
// path.stroke({
|
||||||
|
// width: 1,
|
||||||
|
// color: visual.color
|
||||||
|
// });
|
||||||
|
path.plot(visual.bounds);
|
||||||
|
}
|
||||||
|
|
||||||
|
console.log(svg.svg());
|
||||||
|
|
||||||
|
return svg;
|
||||||
}
|
}
|
||||||
|
|
||||||
export function toVisualSegmentInfo(svg: string): VisualSegmentInfo {
|
export function toVisualSegmentInfo(svgInput: string | Svg): VisualSegmentInfo {
|
||||||
|
let svg = svgInput as Svg;
|
||||||
|
if (typeof svgInput === "string") {
|
||||||
|
svg = SVG().svg(svgInput);
|
||||||
|
}
|
||||||
|
|
||||||
throw new Error("Method not implemented.");
|
throw new Error("Method not implemented.");
|
||||||
}
|
}
|
||||||
21
test/visualSegments.test.ts
Normal file
21
test/visualSegments.test.ts
Normal file
@@ -0,0 +1,21 @@
|
|||||||
|
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
||||||
|
//@ts-ignore
|
||||||
|
import { createSVGWindow } from "svgdom";
|
||||||
|
import { registerWindow } from "@svgdotjs/svg.js";
|
||||||
|
|
||||||
|
import { toSVG } from "../src/utils/visualUtils";
|
||||||
|
|
||||||
|
beforeAll(() => {
|
||||||
|
const window = createSVGWindow();
|
||||||
|
registerWindow(window, window.document)
|
||||||
|
})
|
||||||
|
|
||||||
|
test("Visual Segment SVG converter", async () => {
|
||||||
|
toSVG([{
|
||||||
|
time: 0,
|
||||||
|
bounds: [[0, 0], [25, 0], [25, 40], [0, 30]],
|
||||||
|
smooth: false,
|
||||||
|
curve: "linear",
|
||||||
|
color: "#000000",
|
||||||
|
}]);
|
||||||
|
});
|
||||||
Reference in New Issue
Block a user