@akashic/headless-driver 2.13.2 → 2.13.4
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/lib/runner/v3/platform/graphics/canvas/AffineTransformer.d.ts +9 -0
- package/lib/runner/v3/platform/graphics/canvas/AffineTransformer.js +57 -0
- package/lib/runner/v3/platform/graphics/canvas/NodeCanvasContext.d.ts +42 -0
- package/lib/runner/v3/platform/graphics/canvas/NodeCanvasContext.js +140 -0
- package/lib/runner/v3/platform/graphics/canvas/NodeCanvasRenderer.d.ts +3 -2
- package/lib/runner/v3/platform/graphics/canvas/NodeCanvasRenderer.js +2 -2
- package/lib/runner/v3/platform/graphics/canvas/NodeCanvasSurface.js +3 -1
- package/lib/runner/v3/platform/graphics/canvas/RenderingState.d.ts +8 -0
- package/lib/runner/v3/platform/graphics/canvas/RenderingState.js +21 -0
- package/package.json +3 -3
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
export declare class AffineTransformer {
|
|
2
|
+
matrix: Float32Array;
|
|
3
|
+
constructor(rhs?: AffineTransformer);
|
|
4
|
+
scale(x: number, y: number): AffineTransformer;
|
|
5
|
+
translate(x: number, y: number): AffineTransformer;
|
|
6
|
+
transform(matrix: number[]): AffineTransformer;
|
|
7
|
+
setTransform(matrix: number[]): void;
|
|
8
|
+
copyFrom(rhs: AffineTransformer): AffineTransformer;
|
|
9
|
+
}
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.AffineTransformer = void 0;
|
|
4
|
+
class AffineTransformer {
|
|
5
|
+
constructor(rhs) {
|
|
6
|
+
if (rhs) {
|
|
7
|
+
this.matrix = new Float32Array(rhs.matrix);
|
|
8
|
+
}
|
|
9
|
+
else {
|
|
10
|
+
this.matrix = new Float32Array([1, 0, 0, 1, 0, 0]);
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
scale(x, y) {
|
|
14
|
+
const m = this.matrix;
|
|
15
|
+
m[0] *= x;
|
|
16
|
+
m[1] *= x;
|
|
17
|
+
m[2] *= y;
|
|
18
|
+
m[3] *= y;
|
|
19
|
+
return this;
|
|
20
|
+
}
|
|
21
|
+
translate(x, y) {
|
|
22
|
+
const m = this.matrix;
|
|
23
|
+
m[4] += m[0] * x + m[2] * y;
|
|
24
|
+
m[5] += m[1] * x + m[3] * y;
|
|
25
|
+
return this;
|
|
26
|
+
}
|
|
27
|
+
transform(matrix) {
|
|
28
|
+
const m = this.matrix;
|
|
29
|
+
const a = matrix[0] * m[0] + matrix[1] * m[2];
|
|
30
|
+
const b = matrix[0] * m[1] + matrix[1] * m[3];
|
|
31
|
+
const c = matrix[2] * m[0] + matrix[3] * m[2];
|
|
32
|
+
const d = matrix[2] * m[1] + matrix[3] * m[3];
|
|
33
|
+
const e = matrix[4] * m[0] + matrix[5] * m[2] + m[4];
|
|
34
|
+
const f = matrix[4] * m[1] + matrix[5] * m[3] + m[5];
|
|
35
|
+
m[0] = a;
|
|
36
|
+
m[1] = b;
|
|
37
|
+
m[2] = c;
|
|
38
|
+
m[3] = d;
|
|
39
|
+
m[4] = e;
|
|
40
|
+
m[5] = f;
|
|
41
|
+
return this;
|
|
42
|
+
}
|
|
43
|
+
setTransform(matrix) {
|
|
44
|
+
const m = this.matrix;
|
|
45
|
+
m[0] = matrix[0];
|
|
46
|
+
m[1] = matrix[1];
|
|
47
|
+
m[2] = matrix[2];
|
|
48
|
+
m[3] = matrix[3];
|
|
49
|
+
m[4] = matrix[4];
|
|
50
|
+
m[5] = matrix[5];
|
|
51
|
+
}
|
|
52
|
+
copyFrom(rhs) {
|
|
53
|
+
this.matrix.set(rhs.matrix);
|
|
54
|
+
return this;
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
exports.AffineTransformer = AffineTransformer;
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
/** @ts-ignore */
|
|
2
|
+
import type { CanvasRenderingContext2D, ImageData } from "canvas";
|
|
3
|
+
import type { akashicEngine as g } from "../../../engineFiles";
|
|
4
|
+
import { RenderingState } from "./RenderingState";
|
|
5
|
+
export declare class NodeCanvasContext {
|
|
6
|
+
protected _context: CanvasRenderingContext2D;
|
|
7
|
+
protected _stateStack: RenderingState[];
|
|
8
|
+
protected _contextFillStyle: string;
|
|
9
|
+
protected _contextGlobalAlpha: number;
|
|
10
|
+
protected _contextGlobalCompositeOperation: string;
|
|
11
|
+
private _modifiedTransform;
|
|
12
|
+
constructor(context: CanvasRenderingContext2D);
|
|
13
|
+
set fillStyle(fillStyle: string);
|
|
14
|
+
get fillStyle(): string;
|
|
15
|
+
set globalAlpha(globalAlpha: number);
|
|
16
|
+
get globalAlpha(): number;
|
|
17
|
+
set globalCompositeOperation(operation: string);
|
|
18
|
+
get globalCompositeOperation(): string;
|
|
19
|
+
getCanvasRenderingContext2D(): CanvasRenderingContext2D;
|
|
20
|
+
clearRect(x: number, y: number, width: number, height: number): void;
|
|
21
|
+
save(): void;
|
|
22
|
+
restore(): void;
|
|
23
|
+
scale(x: number, y: number): void;
|
|
24
|
+
drawImage(surface: g.Surface, srcX: number, srcY: number, srcW: number, srcH: number, dstX: number, dstY: number, dstW: number, dstH: number): void;
|
|
25
|
+
fillRect(x: number, y: number, width: number, height: number): void;
|
|
26
|
+
fillText(text: string, x: number, y: number, maxWidth: number): void;
|
|
27
|
+
strokeText(text: string, x: number, y: number, maxWidth?: number): void;
|
|
28
|
+
translate(x: number, y: number): void;
|
|
29
|
+
transform(m11: number, m12: number, m21: number, m22: number, dx: number, dy: number): void;
|
|
30
|
+
setTransform(m11: number, m12: number, m21: number, m22: number, dx: number, dy: number): void;
|
|
31
|
+
setGlobalAlpha(globalAlpha: number): void;
|
|
32
|
+
getImageData(sx: number, sy: number, sw: number, sh: number): ImageData;
|
|
33
|
+
putImageData(imagedata: ImageData, dx: number, dy: number, dirtyX?: number, dirtyY?: number, dirtyWidth?: number, dirtyHeight?: number): void;
|
|
34
|
+
/**
|
|
35
|
+
* 描画の前処理。
|
|
36
|
+
* 描画を省略すべきであれば false を返す。
|
|
37
|
+
*/
|
|
38
|
+
prerender(): boolean;
|
|
39
|
+
private pushState;
|
|
40
|
+
private popState;
|
|
41
|
+
private currentState;
|
|
42
|
+
}
|
|
@@ -0,0 +1,140 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.NodeCanvasContext = void 0;
|
|
4
|
+
const RenderingState_1 = require("./RenderingState");
|
|
5
|
+
class NodeCanvasContext {
|
|
6
|
+
constructor(context) {
|
|
7
|
+
this._stateStack = [];
|
|
8
|
+
this._modifiedTransform = false;
|
|
9
|
+
this._context = context;
|
|
10
|
+
const state = new RenderingState_1.RenderingState();
|
|
11
|
+
this._contextFillStyle = state.fillStyle;
|
|
12
|
+
this._contextGlobalAlpha = state.globalAlpha;
|
|
13
|
+
this._contextGlobalCompositeOperation = state.globalCompositeOperation;
|
|
14
|
+
this.pushState(state);
|
|
15
|
+
}
|
|
16
|
+
set fillStyle(fillStyle) {
|
|
17
|
+
this.currentState().fillStyle = fillStyle;
|
|
18
|
+
}
|
|
19
|
+
get fillStyle() {
|
|
20
|
+
return this.currentState().fillStyle;
|
|
21
|
+
}
|
|
22
|
+
set globalAlpha(globalAlpha) {
|
|
23
|
+
this.currentState().globalAlpha = globalAlpha;
|
|
24
|
+
}
|
|
25
|
+
get globalAlpha() {
|
|
26
|
+
return this.currentState().globalAlpha;
|
|
27
|
+
}
|
|
28
|
+
set globalCompositeOperation(operation) {
|
|
29
|
+
this.currentState().globalCompositeOperation = operation;
|
|
30
|
+
}
|
|
31
|
+
get globalCompositeOperation() {
|
|
32
|
+
return this.currentState().globalCompositeOperation;
|
|
33
|
+
}
|
|
34
|
+
getCanvasRenderingContext2D() {
|
|
35
|
+
return this._context;
|
|
36
|
+
}
|
|
37
|
+
clearRect(x, y, width, height) {
|
|
38
|
+
this.prerender();
|
|
39
|
+
this._context.clearRect(x, y, width, height);
|
|
40
|
+
}
|
|
41
|
+
save() {
|
|
42
|
+
const state = new RenderingState_1.RenderingState(this.currentState());
|
|
43
|
+
this.pushState(state);
|
|
44
|
+
}
|
|
45
|
+
restore() {
|
|
46
|
+
this.popState();
|
|
47
|
+
}
|
|
48
|
+
scale(x, y) {
|
|
49
|
+
this.currentState().transformer.scale(x, y);
|
|
50
|
+
this._modifiedTransform = true;
|
|
51
|
+
}
|
|
52
|
+
drawImage(surface, srcX, srcY, srcW, srcH, dstX, dstY, dstW, dstH) {
|
|
53
|
+
if (this.prerender()) {
|
|
54
|
+
this._context.drawImage(surface._drawable, srcX, srcY, srcW, srcH, dstX, dstY, dstW, dstH);
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
fillRect(x, y, width, height) {
|
|
58
|
+
if (this.prerender()) {
|
|
59
|
+
this._context.fillRect(x, y, width, height);
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
fillText(text, x, y, maxWidth) {
|
|
63
|
+
if (this.prerender()) {
|
|
64
|
+
this._context.fillText(text, x, y, maxWidth);
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
strokeText(text, x, y, maxWidth) {
|
|
68
|
+
if (this.prerender()) {
|
|
69
|
+
this._context.strokeText(text, x, y, maxWidth);
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
translate(x, y) {
|
|
73
|
+
this.currentState().transformer.translate(x, y);
|
|
74
|
+
this._modifiedTransform = true;
|
|
75
|
+
}
|
|
76
|
+
transform(m11, m12, m21, m22, dx, dy) {
|
|
77
|
+
this.currentState().transformer.transform([m11, m12, m21, m22, dx, dy]);
|
|
78
|
+
this._modifiedTransform = true;
|
|
79
|
+
}
|
|
80
|
+
setTransform(m11, m12, m21, m22, dx, dy) {
|
|
81
|
+
this.currentState().transformer.setTransform([m11, m12, m21, m22, dx, dy]);
|
|
82
|
+
this._modifiedTransform = true;
|
|
83
|
+
}
|
|
84
|
+
setGlobalAlpha(globalAlpha) {
|
|
85
|
+
this.currentState().globalAlpha = globalAlpha;
|
|
86
|
+
}
|
|
87
|
+
getImageData(sx, sy, sw, sh) {
|
|
88
|
+
return this._context.getImageData(sx, sy, sw, sh);
|
|
89
|
+
}
|
|
90
|
+
putImageData(imagedata, dx, dy, dirtyX, dirtyY, dirtyWidth, dirtyHeight) {
|
|
91
|
+
this._context.putImageData(imagedata, dx, dy, dirtyX, dirtyY, dirtyWidth, dirtyHeight);
|
|
92
|
+
}
|
|
93
|
+
/**
|
|
94
|
+
* 描画の前処理。
|
|
95
|
+
* 描画を省略すべきであれば false を返す。
|
|
96
|
+
*/
|
|
97
|
+
prerender() {
|
|
98
|
+
const currentState = this.currentState();
|
|
99
|
+
if (currentState.fillStyle !== this._contextFillStyle) {
|
|
100
|
+
this._context.fillStyle = currentState.fillStyle;
|
|
101
|
+
this._contextFillStyle = currentState.fillStyle;
|
|
102
|
+
}
|
|
103
|
+
if (currentState.globalAlpha !== this._contextGlobalAlpha) {
|
|
104
|
+
this._context.globalAlpha = currentState.globalAlpha;
|
|
105
|
+
this._contextGlobalAlpha = currentState.globalAlpha;
|
|
106
|
+
}
|
|
107
|
+
if (currentState.globalCompositeOperation !== this._contextGlobalCompositeOperation) {
|
|
108
|
+
this._context.globalCompositeOperation = currentState.globalCompositeOperation;
|
|
109
|
+
this._contextGlobalCompositeOperation = currentState.globalCompositeOperation;
|
|
110
|
+
}
|
|
111
|
+
if (this._modifiedTransform) {
|
|
112
|
+
this._modifiedTransform = false;
|
|
113
|
+
const transformer = currentState.transformer;
|
|
114
|
+
if (transformer.matrix[0] === 0 || transformer.matrix[3] === 0) {
|
|
115
|
+
// node-canvas 側の不具合? アフィン変換行列における拡大縮小の x, y の係数のいずれかが 0 の場合それ以降描画がされなくなる。
|
|
116
|
+
// そのためこれらの要素が 0 の際は context に対して変換行列を適用せず、描画をスキップする。
|
|
117
|
+
// @see https://github.com/Automattic/node-canvas/issues/702
|
|
118
|
+
return false;
|
|
119
|
+
}
|
|
120
|
+
// FIXME: canvas@2.11.2 時点で setTransform() の TypeScript の型定義が不足しているため暫定でコンパイルできるように修正
|
|
121
|
+
// @see https://github.com/Automattic/node-canvas/pull/2322
|
|
122
|
+
this._context.setTransform(transformer.matrix[0], transformer.matrix[1], transformer.matrix[2], transformer.matrix[3], transformer.matrix[4], transformer.matrix[5]);
|
|
123
|
+
}
|
|
124
|
+
return true;
|
|
125
|
+
}
|
|
126
|
+
pushState(state) {
|
|
127
|
+
this._stateStack.push(state);
|
|
128
|
+
}
|
|
129
|
+
popState() {
|
|
130
|
+
if (this._stateStack.length <= 1) {
|
|
131
|
+
return;
|
|
132
|
+
}
|
|
133
|
+
this._stateStack.pop();
|
|
134
|
+
this._modifiedTransform = true;
|
|
135
|
+
}
|
|
136
|
+
currentState() {
|
|
137
|
+
return this._stateStack[this._stateStack.length - 1];
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
exports.NodeCanvasContext = NodeCanvasContext;
|
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
/** @ts-ignore */
|
|
2
|
-
import type {
|
|
2
|
+
import type { ImageData } from "canvas";
|
|
3
3
|
import type { akashicEngine as g } from "../../../engineFiles";
|
|
4
|
+
import type { NodeCanvasContext } from "./NodeCanvasContext";
|
|
4
5
|
export declare class NodeCanvasRenderer implements g.Renderer {
|
|
5
6
|
private context;
|
|
6
7
|
private width;
|
|
7
8
|
private height;
|
|
8
|
-
constructor(context:
|
|
9
|
+
constructor(context: NodeCanvasContext, width: number, height: number);
|
|
9
10
|
begin(): void;
|
|
10
11
|
drawSprites(): void;
|
|
11
12
|
clear(): void;
|
|
@@ -18,10 +18,10 @@ class NodeCanvasRenderer {
|
|
|
18
18
|
this.context.clearRect(0, 0, this.width, this.height);
|
|
19
19
|
}
|
|
20
20
|
end() {
|
|
21
|
-
// do
|
|
21
|
+
// do nothing
|
|
22
22
|
}
|
|
23
23
|
drawImage(surface, offsetX, offsetY, width, height, canvasOffsetX, canvasOffsetY) {
|
|
24
|
-
this.context.drawImage(surface
|
|
24
|
+
this.context.drawImage(surface, offsetX, offsetY, width, height, canvasOffsetX, canvasOffsetY, width, height);
|
|
25
25
|
}
|
|
26
26
|
translate(x, y) {
|
|
27
27
|
this.context.translate(x, y);
|
|
@@ -1,13 +1,15 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.NodeCanvasSurface = void 0;
|
|
4
|
+
const NodeCanvasContext_1 = require("./NodeCanvasContext");
|
|
4
5
|
const NodeCanvasRenderer_1 = require("./NodeCanvasRenderer");
|
|
5
6
|
class NodeCanvasSurface {
|
|
6
7
|
constructor(canvas) {
|
|
7
8
|
this.width = canvas.width;
|
|
8
9
|
this.height = canvas.height;
|
|
9
10
|
this._drawable = canvas;
|
|
10
|
-
|
|
11
|
+
const context = new NodeCanvasContext_1.NodeCanvasContext(canvas.getContext("2d"));
|
|
12
|
+
this._renderer = new NodeCanvasRenderer_1.NodeCanvasRenderer(context, canvas.width, canvas.height);
|
|
11
13
|
}
|
|
12
14
|
renderer() {
|
|
13
15
|
return this._renderer;
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.RenderingState = void 0;
|
|
4
|
+
const AffineTransformer_1 = require("./AffineTransformer");
|
|
5
|
+
class RenderingState {
|
|
6
|
+
constructor(crs) {
|
|
7
|
+
if (crs) {
|
|
8
|
+
this.fillStyle = crs.fillStyle;
|
|
9
|
+
this.globalAlpha = crs.globalAlpha;
|
|
10
|
+
this.globalCompositeOperation = crs.globalCompositeOperation;
|
|
11
|
+
this.transformer = new AffineTransformer_1.AffineTransformer(crs.transformer);
|
|
12
|
+
}
|
|
13
|
+
else {
|
|
14
|
+
this.fillStyle = "#000000";
|
|
15
|
+
this.globalAlpha = 1.0;
|
|
16
|
+
this.globalCompositeOperation = "source-over";
|
|
17
|
+
this.transformer = new AffineTransformer_1.AffineTransformer();
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
exports.RenderingState = RenderingState;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@akashic/headless-driver",
|
|
3
|
-
"version": "2.13.
|
|
3
|
+
"version": "2.13.4",
|
|
4
4
|
"description": "A library to execute contents using Akashic Engine headlessly",
|
|
5
5
|
"main": "lib/index.js",
|
|
6
6
|
"author": "DWANGO Co., Ltd.",
|
|
@@ -29,7 +29,7 @@
|
|
|
29
29
|
"@akashic/trigger": "^2.0.0",
|
|
30
30
|
"engine-files-v1": "npm:@akashic/engine-files@1.4.0",
|
|
31
31
|
"engine-files-v2": "npm:@akashic/engine-files@2.4.0",
|
|
32
|
-
"engine-files-v3": "npm:@akashic/engine-files@3.7.
|
|
32
|
+
"engine-files-v3": "npm:@akashic/engine-files@3.7.13",
|
|
33
33
|
"js-sha256": "^0.10.0",
|
|
34
34
|
"lodash.clonedeep": "^4.5.0",
|
|
35
35
|
"node-fetch": "^2.6.7"
|
|
@@ -44,7 +44,7 @@
|
|
|
44
44
|
"@types/pixelmatch": "^5.2.4",
|
|
45
45
|
"@types/pngjs": "^6.0.1",
|
|
46
46
|
"@typescript-eslint/eslint-plugin": "^6.12.0",
|
|
47
|
-
"canvas": "^2.
|
|
47
|
+
"canvas": "^2.11.2",
|
|
48
48
|
"eslint": "^8.54.0",
|
|
49
49
|
"eslint-config-prettier": "^9.0.0",
|
|
50
50
|
"eslint-plugin-import": "^2.29.0",
|