mirror of
https://github.com/ajayyy/SponsorBlock.git
synced 2024-09-19 20:51:28 +02:00
Add svgjs and testing with fake dom
This commit is contained in:
parent
51d9edbbb4
commit
21f54eef67
4 changed files with 3102 additions and 268 deletions
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": "",
|
||||
"main": "background.js",
|
||||
"dependencies": {
|
||||
"@svgdotjs/svg.js": "^3.1.1",
|
||||
"@types/react": "^16.9.22",
|
||||
"@types/react-dom": "^16.9.5",
|
||||
"@types/selenium-webdriver": "^4.0.15",
|
||||
|
@ -13,7 +14,8 @@
|
|||
"babel-preset-env": "^1.7.0",
|
||||
"concurrently": "^5.1.0",
|
||||
"react": "^17.0.2",
|
||||
"react-dom": "^17.0.2"
|
||||
"react-dom": "^17.0.2",
|
||||
"svgdom": "^0.1.8"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@types/chrome": "0.0.91",
|
||||
|
|
|
@ -1,9 +1,29 @@
|
|||
import { VisualSegmentInfo } from "../types";
|
||||
import { Svg, SVG } from "@svgdotjs/svg.js";
|
||||
|
||||
export function toSVG(visuals: VisualSegmentInfo[]): string {
|
||||
throw new Error("Method not implemented.");
|
||||
export function toSVG(visuals: VisualSegmentInfo[]): Svg {
|
||||
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.");
|
||||
}
|
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",
|
||||
}]);
|
||||
});
|
Loading…
Reference in a new issue