@jbrowse/svgcanvas 6.4.2 → 7.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/context.test.js +67 -0
- package/dist/context.test.js.map +1 -0
- package/dist/index.d.ts +15 -56
- package/dist/index.js +154 -525
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
- package/src/context.test.ts +71 -0
- package/src/index.ts +167 -652
- package/dist/drawImage.test.js +0 -76
- package/dist/drawImage.test.js.map +0 -1
- package/src/drawImage.test.ts +0 -81
- /package/dist/{drawImage.test.d.ts → context.test.d.ts} +0 -0
package/dist/drawImage.test.js
DELETED
|
@@ -1,76 +0,0 @@
|
|
|
1
|
-
// @vitest-environment jsdom
|
|
2
|
-
import { beforeAll, expect, test } from 'vitest';
|
|
3
|
-
import { Context } from './index.js';
|
|
4
|
-
class Matrix {
|
|
5
|
-
m;
|
|
6
|
-
constructor(m = [1, 0, 0, 1, 0, 0]) {
|
|
7
|
-
this.m = m;
|
|
8
|
-
}
|
|
9
|
-
get a() {
|
|
10
|
-
return this.m[0];
|
|
11
|
-
}
|
|
12
|
-
get b() {
|
|
13
|
-
return this.m[1];
|
|
14
|
-
}
|
|
15
|
-
get c() {
|
|
16
|
-
return this.m[2];
|
|
17
|
-
}
|
|
18
|
-
get d() {
|
|
19
|
-
return this.m[3];
|
|
20
|
-
}
|
|
21
|
-
get e() {
|
|
22
|
-
return this.m[4];
|
|
23
|
-
}
|
|
24
|
-
get f() {
|
|
25
|
-
return this.m[5];
|
|
26
|
-
}
|
|
27
|
-
multiply(o) {
|
|
28
|
-
return new Matrix([
|
|
29
|
-
this.a * o.a + this.c * o.b,
|
|
30
|
-
this.b * o.a + this.d * o.b,
|
|
31
|
-
this.a * o.c + this.c * o.d,
|
|
32
|
-
this.b * o.c + this.d * o.d,
|
|
33
|
-
this.a * o.e + this.c * o.f + this.e,
|
|
34
|
-
this.b * o.e + this.d * o.f + this.f,
|
|
35
|
-
]);
|
|
36
|
-
}
|
|
37
|
-
translate(x, y = 0) {
|
|
38
|
-
return this.multiply(new Matrix([1, 0, 0, 1, x, y]));
|
|
39
|
-
}
|
|
40
|
-
scale(x, y = x) {
|
|
41
|
-
return this.multiply(new Matrix([x, 0, 0, y, 0, 0]));
|
|
42
|
-
}
|
|
43
|
-
}
|
|
44
|
-
beforeAll(() => {
|
|
45
|
-
globalThis.DOMMatrix = Matrix;
|
|
46
|
-
});
|
|
47
|
-
const source = {
|
|
48
|
-
width: 40,
|
|
49
|
-
height: 30,
|
|
50
|
-
toDataURL: () => 'data:image/png;base64,STUB',
|
|
51
|
-
};
|
|
52
|
-
test('a full-image draw is one image scaled onto the destination', () => {
|
|
53
|
-
const ctx = new Context(200, 100);
|
|
54
|
-
ctx.translate(5, 0);
|
|
55
|
-
ctx.drawImage(source, 10, 20, 80, 60);
|
|
56
|
-
const svg = ctx.getSerializedSvg();
|
|
57
|
-
expect(svg).toContain('href="data:image/png;base64,STUB"');
|
|
58
|
-
expect(svg).toContain('viewBox="0 0 40 30"');
|
|
59
|
-
expect(svg).toContain('x="10" y="20" width="80" height="60"');
|
|
60
|
-
expect(svg).toContain('transform="matrix(1 0 0 1 5 0)"');
|
|
61
|
-
});
|
|
62
|
-
test('a source rectangle crops through the viewBox', () => {
|
|
63
|
-
const ctx = new Context(200, 100);
|
|
64
|
-
ctx.imageSmoothingEnabled = false;
|
|
65
|
-
ctx.drawImage(source, 8, 4, 16, 8, 0, 0, 32, 16);
|
|
66
|
-
const svg = ctx.getSerializedSvg();
|
|
67
|
-
expect(svg).toContain('viewBox="8 4 16 8"');
|
|
68
|
-
expect(svg).toContain('image-rendering="pixelated"');
|
|
69
|
-
});
|
|
70
|
-
test('an unreadable source is an error, not a silent gap', () => {
|
|
71
|
-
const ctx = new Context(10, 10);
|
|
72
|
-
expect(() => {
|
|
73
|
-
ctx.drawImage({ width: 1, height: 1 }, 0, 0);
|
|
74
|
-
}).toThrow(/toDataURL/);
|
|
75
|
-
});
|
|
76
|
-
//# sourceMappingURL=drawImage.test.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"drawImage.test.js","sourceRoot":"","sources":["../src/drawImage.test.ts"],"names":[],"mappings":"AAAA,4BAA4B;AAC5B,OAAO,EAAE,SAAS,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,QAAQ,CAAA;AAEhD,OAAO,EAAE,OAAO,EAAE,MAAM,YAAY,CAAA;AAEpC,MAAM,MAAM;IACS,CAAC;IAApB,YAAmB,CAAC,GAAG,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC;iBAAtB,CAAC;IAAwB,CAAC;IAC7C,IAAI,CAAC;QACH,OAAO,IAAI,CAAC,CAAC,CAAC,CAAC,CAAE,CAAA;IACnB,CAAC;IACD,IAAI,CAAC;QACH,OAAO,IAAI,CAAC,CAAC,CAAC,CAAC,CAAE,CAAA;IACnB,CAAC;IACD,IAAI,CAAC;QACH,OAAO,IAAI,CAAC,CAAC,CAAC,CAAC,CAAE,CAAA;IACnB,CAAC;IACD,IAAI,CAAC;QACH,OAAO,IAAI,CAAC,CAAC,CAAC,CAAC,CAAE,CAAA;IACnB,CAAC;IACD,IAAI,CAAC;QACH,OAAO,IAAI,CAAC,CAAC,CAAC,CAAC,CAAE,CAAA;IACnB,CAAC;IACD,IAAI,CAAC;QACH,OAAO,IAAI,CAAC,CAAC,CAAC,CAAC,CAAE,CAAA;IACnB,CAAC;IACD,QAAQ,CAAC,CAAS;QAChB,OAAO,IAAI,MAAM,CAAC;YAChB,IAAI,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,GAAG,IAAI,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC;YAC3B,IAAI,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,GAAG,IAAI,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC;YAC3B,IAAI,CAAC,CAAC,GAAG,CAAC,CAAC,CAA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AAC,EAAE,CAAC,CAAC,CAAA;IAC9C,CAAC,CAAC,CAAC,OAAO,CAAC,WAAW,CAAC,CAAA;AACzB,CAAC,CAAC,CAAA"}
|
package/src/drawImage.test.ts
DELETED
|
@@ -1,81 +0,0 @@
|
|
|
1
|
-
// @vitest-environment jsdom
|
|
2
|
-
import { beforeAll, expect, test } from 'vitest'
|
|
3
|
-
|
|
4
|
-
import { Context } from './index.ts'
|
|
5
|
-
|
|
6
|
-
class Matrix {
|
|
7
|
-
constructor(public m = [1, 0, 0, 1, 0, 0]) {}
|
|
8
|
-
get a() {
|
|
9
|
-
return this.m[0]!
|
|
10
|
-
}
|
|
11
|
-
get b() {
|
|
12
|
-
return this.m[1]!
|
|
13
|
-
}
|
|
14
|
-
get c() {
|
|
15
|
-
return this.m[2]!
|
|
16
|
-
}
|
|
17
|
-
get d() {
|
|
18
|
-
return this.m[3]!
|
|
19
|
-
}
|
|
20
|
-
get e() {
|
|
21
|
-
return this.m[4]!
|
|
22
|
-
}
|
|
23
|
-
get f() {
|
|
24
|
-
return this.m[5]!
|
|
25
|
-
}
|
|
26
|
-
multiply(o: Matrix) {
|
|
27
|
-
return new Matrix([
|
|
28
|
-
this.a * o.a + this.c * o.b,
|
|
29
|
-
this.b * o.a + this.d * o.b,
|
|
30
|
-
this.a * o.c + this.c * o.d,
|
|
31
|
-
this.b * o.c + this.d * o.d,
|
|
32
|
-
this.a * o.e + this.c * o.f + this.e,
|
|
33
|
-
this.b * o.e + this.d * o.f + this.f,
|
|
34
|
-
])
|
|
35
|
-
}
|
|
36
|
-
translate(x: number, y = 0) {
|
|
37
|
-
return this.multiply(new Matrix([1, 0, 0, 1, x, y]))
|
|
38
|
-
}
|
|
39
|
-
scale(x: number, y = x) {
|
|
40
|
-
return this.multiply(new Matrix([x, 0, 0, y, 0, 0]))
|
|
41
|
-
}
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
beforeAll(() => {
|
|
45
|
-
globalThis.DOMMatrix = Matrix as unknown as typeof DOMMatrix
|
|
46
|
-
})
|
|
47
|
-
|
|
48
|
-
const source = {
|
|
49
|
-
width: 40,
|
|
50
|
-
height: 30,
|
|
51
|
-
toDataURL: () => 'data:image/png;base64,STUB',
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
test('a full-image draw is one image scaled onto the destination', () => {
|
|
55
|
-
const ctx = new Context(200, 100)
|
|
56
|
-
ctx.translate(5, 0)
|
|
57
|
-
ctx.drawImage(source, 10, 20, 80, 60)
|
|
58
|
-
const svg = ctx.getSerializedSvg()
|
|
59
|
-
|
|
60
|
-
expect(svg).toContain('href="data:image/png;base64,STUB"')
|
|
61
|
-
expect(svg).toContain('viewBox="0 0 40 30"')
|
|
62
|
-
expect(svg).toContain('x="10" y="20" width="80" height="60"')
|
|
63
|
-
expect(svg).toContain('transform="matrix(1 0 0 1 5 0)"')
|
|
64
|
-
})
|
|
65
|
-
|
|
66
|
-
test('a source rectangle crops through the viewBox', () => {
|
|
67
|
-
const ctx = new Context(200, 100)
|
|
68
|
-
ctx.imageSmoothingEnabled = false
|
|
69
|
-
ctx.drawImage(source, 8, 4, 16, 8, 0, 0, 32, 16)
|
|
70
|
-
const svg = ctx.getSerializedSvg()
|
|
71
|
-
|
|
72
|
-
expect(svg).toContain('viewBox="8 4 16 8"')
|
|
73
|
-
expect(svg).toContain('image-rendering="pixelated"')
|
|
74
|
-
})
|
|
75
|
-
|
|
76
|
-
test('an unreadable source is an error, not a silent gap', () => {
|
|
77
|
-
const ctx = new Context(10, 10)
|
|
78
|
-
expect(() => {
|
|
79
|
-
ctx.drawImage({ width: 1, height: 1 }, 0, 0)
|
|
80
|
-
}).toThrow(/toDataURL/)
|
|
81
|
-
})
|
|
File without changes
|