@akashic/headless-driver 1.11.36 → 2.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.
Files changed (139) hide show
  1. package/CHANGELOG.md +1725 -0
  2. package/README.md +30 -0
  3. package/lib/ExecuteVmScriptV1.d.ts +2 -2
  4. package/lib/ExecuteVmScriptV1.js +2 -2
  5. package/lib/ExecuteVmScriptV2.d.ts +2 -2
  6. package/lib/ExecuteVmScriptV2.js +2 -2
  7. package/lib/ExecuteVmScriptV3.d.ts +2 -2
  8. package/lib/ExecuteVmScriptV3.js +2 -2
  9. package/lib/Looper.d.ts +24 -0
  10. package/lib/Looper.js +79 -0
  11. package/lib/index.d.ts +3 -11
  12. package/lib/index.js +3 -11
  13. package/lib/play/AMFlowClientManager.d.ts +1 -1
  14. package/lib/play/Play.d.ts +1 -1
  15. package/lib/play/PlayManager.d.ts +5 -5
  16. package/lib/play/amflow/AMFlowClient.d.ts +4 -4
  17. package/lib/play/amflow/AMFlowStore.d.ts +3 -3
  18. package/lib/play/amflow/index.d.ts +4 -0
  19. package/lib/play/amflow/index.js +16 -0
  20. package/lib/play/amflow/types.d.ts +2 -2
  21. package/lib/play/index.d.ts +5 -0
  22. package/lib/play/index.js +17 -0
  23. package/lib/runner/Platform.d.ts +25 -0
  24. package/lib/runner/Platform.js +34 -0
  25. package/lib/runner/Runner.d.ts +110 -0
  26. package/lib/runner/Runner.js +101 -0
  27. package/lib/runner/RunnerManager.d.ts +6 -6
  28. package/lib/runner/RunnerManager.js +2 -2
  29. package/lib/runner/index.d.ts +7 -0
  30. package/lib/runner/index.js +19 -0
  31. package/lib/runner/types.d.ts +15 -0
  32. package/lib/runner/types.js +2 -0
  33. package/lib/runner/v1/RunnerV1.d.ts +26 -0
  34. package/lib/runner/v1/RunnerV1.js +230 -0
  35. package/lib/runner/v1/index.d.ts +3 -0
  36. package/lib/runner/v1/index.js +19 -0
  37. package/lib/runner/v1/platform/NullAudioPlayer.d.ts +3 -0
  38. package/lib/runner/v1/platform/NullAudioPlayer.js +7 -0
  39. package/lib/runner/v1/platform/NullGlyphFactory.d.ts +6 -0
  40. package/lib/runner/v1/platform/NullGlyphFactory.js +18 -0
  41. package/lib/runner/v1/platform/NullRenderer.d.ts +16 -0
  42. package/lib/runner/v1/platform/NullRenderer.js +46 -0
  43. package/lib/runner/v1/platform/NullSurface.d.ts +7 -0
  44. package/lib/runner/v1/platform/NullSurface.js +18 -0
  45. package/lib/runner/v1/platform/NullVideoPlayer.d.ts +4 -0
  46. package/lib/runner/v1/platform/NullVideoPlayer.js +10 -0
  47. package/lib/runner/v1/platform/PlatformV1.d.ts +22 -0
  48. package/lib/runner/v1/platform/PlatformV1.js +67 -0
  49. package/lib/runner/v1/platform/ResourceFactory.d.ts +18 -0
  50. package/lib/runner/v1/platform/ResourceFactory.js +53 -0
  51. package/lib/runner/v1/platform/assets/NodeScriptAsset.d.ts +16 -0
  52. package/lib/runner/v1/platform/assets/NodeScriptAsset.js +36 -0
  53. package/lib/runner/v1/platform/assets/NodeTextAsset.d.ts +11 -0
  54. package/lib/runner/v1/platform/assets/NodeTextAsset.js +23 -0
  55. package/lib/runner/v1/platform/assets/NullAudioAsset.d.ts +4 -0
  56. package/lib/runner/v1/platform/assets/NullAudioAsset.js +10 -0
  57. package/lib/runner/v1/platform/assets/NullImageAsset.d.ts +6 -0
  58. package/lib/runner/v1/platform/assets/NullImageAsset.js +18 -0
  59. package/lib/runner/v1/platform/assets/NullVideoAsset.d.ts +10 -0
  60. package/lib/runner/v1/platform/assets/NullVideoAsset.js +25 -0
  61. package/lib/runner/v2/RunnerV2.d.ts +26 -0
  62. package/lib/runner/v2/RunnerV2.js +229 -0
  63. package/lib/runner/v2/index.d.ts +3 -0
  64. package/lib/runner/v2/index.js +19 -0
  65. package/lib/runner/v2/platform/NullAudioPlayer.d.ts +3 -0
  66. package/lib/runner/v2/platform/NullAudioPlayer.js +7 -0
  67. package/lib/runner/v2/platform/NullGlyphFactory.d.ts +6 -0
  68. package/lib/runner/v2/platform/NullGlyphFactory.js +18 -0
  69. package/lib/runner/v2/platform/NullRenderer.d.ts +20 -0
  70. package/lib/runner/v2/platform/NullRenderer.js +58 -0
  71. package/lib/runner/v2/platform/NullSurface.d.ts +7 -0
  72. package/lib/runner/v2/platform/NullSurface.js +18 -0
  73. package/lib/runner/v2/platform/NullVideoPlayer.d.ts +4 -0
  74. package/lib/runner/v2/platform/NullVideoPlayer.js +10 -0
  75. package/lib/runner/v2/platform/PlatformV2.d.ts +23 -0
  76. package/lib/runner/v2/platform/PlatformV2.js +70 -0
  77. package/lib/runner/v2/platform/ResourceFactory.d.ts +18 -0
  78. package/lib/runner/v2/platform/ResourceFactory.js +53 -0
  79. package/lib/runner/v2/platform/assets/NodeScriptAsset.d.ts +16 -0
  80. package/lib/runner/v2/platform/assets/NodeScriptAsset.js +36 -0
  81. package/lib/runner/v2/platform/assets/NodeTextAsset.d.ts +11 -0
  82. package/lib/runner/v2/platform/assets/NodeTextAsset.js +23 -0
  83. package/lib/runner/v2/platform/assets/NullAudioAsset.d.ts +4 -0
  84. package/lib/runner/v2/platform/assets/NullAudioAsset.js +10 -0
  85. package/lib/runner/v2/platform/assets/NullImageAsset.d.ts +6 -0
  86. package/lib/runner/v2/platform/assets/NullImageAsset.js +18 -0
  87. package/lib/runner/v2/platform/assets/NullVideoAsset.d.ts +10 -0
  88. package/lib/runner/v2/platform/assets/NullVideoAsset.js +25 -0
  89. package/lib/runner/v3/RunnerV3.d.ts +38 -0
  90. package/lib/runner/v3/RunnerV3.js +245 -0
  91. package/lib/runner/v3/engineFiles.d.ts +2 -0
  92. package/lib/runner/v3/engineFiles.js +31 -0
  93. package/lib/runner/v3/index.d.ts +5 -0
  94. package/lib/runner/v3/index.js +21 -0
  95. package/lib/runner/v3/platform/NodeCanvasResourceFactory.d.ts +22 -0
  96. package/lib/runner/v3/platform/NodeCanvasResourceFactory.js +57 -0
  97. package/lib/runner/v3/platform/NullResourceFactory.d.ts +21 -0
  98. package/lib/runner/v3/platform/NullResourceFactory.js +54 -0
  99. package/lib/runner/v3/platform/PlatformV3.d.ts +23 -0
  100. package/lib/runner/v3/platform/PlatformV3.js +94 -0
  101. package/lib/runner/v3/platform/assets/Asset.d.ts +14 -0
  102. package/lib/runner/v3/platform/assets/Asset.js +30 -0
  103. package/lib/runner/v3/platform/assets/NodeScriptAsset.d.ts +19 -0
  104. package/lib/runner/v3/platform/assets/NodeScriptAsset.js +48 -0
  105. package/lib/runner/v3/platform/assets/NodeTextAsset.d.ts +14 -0
  106. package/lib/runner/v3/platform/assets/NodeTextAsset.js +35 -0
  107. package/lib/runner/v3/platform/audios/NullAudioAsset.d.ts +15 -0
  108. package/lib/runner/v3/platform/audios/NullAudioAsset.js +28 -0
  109. package/lib/runner/v3/platform/audios/NullAudioPlayer.d.ts +17 -0
  110. package/lib/runner/v3/platform/audios/NullAudioPlayer.js +34 -0
  111. package/lib/runner/v3/platform/graphics/canvas/CompositeOperationConverter.d.ts +6 -0
  112. package/lib/runner/v3/platform/graphics/canvas/CompositeOperationConverter.js +78 -0
  113. package/lib/runner/v3/platform/graphics/canvas/NodeCanvasGlyph.d.ts +16 -0
  114. package/lib/runner/v3/platform/graphics/canvas/NodeCanvasGlyph.js +25 -0
  115. package/lib/runner/v3/platform/graphics/canvas/NodeCanvasGlyphFactory.d.ts +24 -0
  116. package/lib/runner/v3/platform/graphics/canvas/NodeCanvasGlyphFactory.js +204 -0
  117. package/lib/runner/v3/platform/graphics/canvas/NodeCanvasImageAsset.d.ts +16 -0
  118. package/lib/runner/v3/platform/graphics/canvas/NodeCanvasImageAsset.js +78 -0
  119. package/lib/runner/v3/platform/graphics/canvas/NodeCanvasRenderer.d.ts +26 -0
  120. package/lib/runner/v3/platform/graphics/canvas/NodeCanvasRenderer.js +72 -0
  121. package/lib/runner/v3/platform/graphics/canvas/NodeCanvasSurface.d.ts +14 -0
  122. package/lib/runner/v3/platform/graphics/canvas/NodeCanvasSurface.js +25 -0
  123. package/lib/runner/v3/platform/graphics/null/NullGlyph.d.ts +16 -0
  124. package/lib/runner/v3/platform/graphics/null/NullGlyph.js +25 -0
  125. package/lib/runner/v3/platform/graphics/null/NullGlyphFactory.d.ts +14 -0
  126. package/lib/runner/v3/platform/graphics/null/NullGlyphFactory.js +22 -0
  127. package/lib/runner/v3/platform/graphics/null/NullImageAsset.d.ts +13 -0
  128. package/lib/runner/v3/platform/graphics/null/NullImageAsset.js +24 -0
  129. package/lib/runner/v3/platform/graphics/null/NullRenderer.d.ts +21 -0
  130. package/lib/runner/v3/platform/graphics/null/NullRenderer.js +60 -0
  131. package/lib/runner/v3/platform/graphics/null/NullSurface.d.ts +14 -0
  132. package/lib/runner/v3/platform/graphics/null/NullSurface.js +26 -0
  133. package/lib/runner/v3/platform/videos/NullVideoAsset.d.ts +20 -0
  134. package/lib/runner/v3/platform/videos/NullVideoAsset.js +37 -0
  135. package/lib/runner/v3/platform/videos/NullVideoPlayer.d.ts +14 -0
  136. package/lib/runner/v3/platform/videos/NullVideoPlayer.js +25 -0
  137. package/lib/runner/v3/requireEngineFiles.d.ts +5 -0
  138. package/lib/runner/v3/requireEngineFiles.js +21 -0
  139. package/package.json +26 -18
@@ -0,0 +1,25 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.NodeCanvasGlyph = void 0;
4
+ class NodeCanvasGlyph {
5
+ constructor(code, x, y, width, height, offsetX = 0, offsetY = 0, advanceWidth = width, surface, isSurfaceValid) {
6
+ this.code = code;
7
+ this.x = x;
8
+ this.y = y;
9
+ this.width = width;
10
+ this.height = height;
11
+ this.offsetX = offsetX;
12
+ this.offsetY = offsetY;
13
+ this.advanceWidth = advanceWidth;
14
+ this.surface = surface;
15
+ this.isSurfaceValid = isSurfaceValid;
16
+ this._atlas = null;
17
+ }
18
+ renderingWidth(fontSize) {
19
+ if (!this.width || !this.height) {
20
+ return 0;
21
+ }
22
+ return (fontSize / this.height) * this.width;
23
+ }
24
+ }
25
+ exports.NodeCanvasGlyph = NodeCanvasGlyph;
@@ -0,0 +1,24 @@
1
+ import type { akashicEngine as g } from "../../../engineFiles";
2
+ export declare class NodeCanvasGlyphFactory implements g.GlyphFactory {
3
+ /**
4
+ * 実行環境が描画可能な最小フォントサイズ
5
+ */
6
+ static _environmentMinimumFontSize: number;
7
+ fontFamily: string | string[];
8
+ fontSize: number;
9
+ baselineHeight: number;
10
+ fontColor: string;
11
+ fontWeight: g.FontWeightString;
12
+ strokeWidth: number;
13
+ strokeColor: string;
14
+ strokeOnly: boolean;
15
+ _glyphAreas: {
16
+ [key: number]: g.GlyphArea;
17
+ };
18
+ _marginW: number;
19
+ _marginH: number;
20
+ _cssFontFamily: string;
21
+ constructor(fontFamily: string | string[], fontSize: number, baselineHeight?: number, fontColor?: string, strokeWidth?: number, strokeColor?: string, strokeOnly?: boolean, fontWeight?: g.FontWeightString);
22
+ create(code: number): g.Glyph;
23
+ measureMinimumFontSize(): number;
24
+ }
@@ -0,0 +1,204 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.NodeCanvasGlyphFactory = void 0;
4
+ const canvas_1 = require("canvas");
5
+ const NodeCanvasGlyph_1 = require("./NodeCanvasGlyph");
6
+ const NodeCanvasSurface_1 = require("./NodeCanvasSurface");
7
+ function createGlyphRenderedSurface(code, fontSize, cssFontFamily, baselineHeight, marginW, marginH, needImageData, fontColor, strokeWidth, strokeColor, strokeOnly, fontWeight) {
8
+ // 要求されたフォントサイズが描画可能な最小フォントサイズ以下だった場合、必要なスケーリング係数
9
+ const scale = fontSize < NodeCanvasGlyphFactory._environmentMinimumFontSize ? fontSize / NodeCanvasGlyphFactory._environmentMinimumFontSize : 1;
10
+ const surfaceWidth = Math.ceil((fontSize + marginW * 2) * scale);
11
+ const surfaceHeight = Math.ceil((fontSize + marginH * 2) * scale);
12
+ // NOTE: canvasを直接操作する
13
+ // 理由:
14
+ // * Renderer#drawSystemText()を廃止または非推奨にしたいのでそれを用いず文字列を描画する
15
+ // * RenderingHelperがcontextの状態を復帰するためTextMetricsを取れない
16
+ const canvas = new canvas_1.Canvas(surfaceWidth, surfaceHeight);
17
+ const context = canvas.getContext("2d");
18
+ const str = code & 0xffff0000 ? String.fromCharCode((code & 0xffff0000) >>> 16, code & 0xffff) : String.fromCharCode(code);
19
+ const fontWeightValue = fontWeight === "bold" ? "bold " : "";
20
+ context.save();
21
+ // CanvasRenderingContext2D.font
22
+ // see: https://developer.mozilla.org/en-US/docs/Web/API/CanvasRenderingContext2D/font
23
+ // > This string uses the same syntax as the CSS font specifier. The default font is 10px sans-serif.
24
+ context.font = fontWeightValue + fontSize + "px " + cssFontFamily;
25
+ context.textAlign = "left";
26
+ context.textBaseline = "alphabetic";
27
+ context.lineJoin = "bevel";
28
+ // 描画可能な最小フォントサイズ以下のフォントサイズはスケーリングで実現する
29
+ if (scale !== 1)
30
+ context.scale(scale, scale);
31
+ if (strokeWidth > 0) {
32
+ context.lineWidth = strokeWidth;
33
+ context.strokeStyle = strokeColor;
34
+ context.strokeText(str, marginW, marginH + baselineHeight);
35
+ }
36
+ if (!strokeOnly) {
37
+ context.fillStyle = fontColor;
38
+ context.fillText(str, marginW, marginH + baselineHeight);
39
+ }
40
+ const advanceWidth = context.measureText(str).width;
41
+ context.restore();
42
+ const result = {
43
+ surface: new NodeCanvasSurface_1.NodeCanvasSurface(canvas),
44
+ advanceWidth: advanceWidth,
45
+ imageData: needImageData ? context.getImageData(0, 0, canvas.width, canvas.height) : null
46
+ };
47
+ return result;
48
+ }
49
+ function calcGlyphArea(imageData) {
50
+ let sx = imageData.width;
51
+ let sy = imageData.height;
52
+ let ex = 0;
53
+ let ey = 0;
54
+ let currentPos = 0;
55
+ for (let y = 0, height = imageData.height; y < height; y = (y + 1) | 0) {
56
+ for (let x = 0, width = imageData.width; x < width; x = (x + 1) | 0) {
57
+ const a = imageData.data[currentPos + 3]; // get alpha value
58
+ if (a !== 0) {
59
+ if (x < sx) {
60
+ sx = x;
61
+ }
62
+ if (x > ex) {
63
+ ex = x;
64
+ }
65
+ if (y < sy) {
66
+ sy = y;
67
+ }
68
+ if (y > ey) {
69
+ ey = y;
70
+ }
71
+ }
72
+ currentPos += 4; // go to next pixel
73
+ }
74
+ }
75
+ let glyphArea;
76
+ if (sx === imageData.width) {
77
+ // 空白文字
78
+ glyphArea = { x: 0, y: 0, width: 0, height: 0 }; // 空の領域に設定
79
+ }
80
+ else {
81
+ // sx, sy, ex, eyは座標ではなく画素のメモリ上の位置を指す添字。
82
+ // 故にwidth, heightを算出する時 1 加算する。
83
+ glyphArea = { x: sx, y: sy, width: ex - sx + 1, height: ey - sy + 1 };
84
+ }
85
+ return glyphArea;
86
+ }
87
+ function isGlyphAreaEmpty(glyphArea) {
88
+ return glyphArea.width === 0 || glyphArea.height === 0;
89
+ }
90
+ // ジェネリックフォントファミリとして定義されているキーワードのリスト
91
+ // see: https://developer.mozilla.org/en-US/docs/Web/CSS/font-family
92
+ const genericFontFamilyNames = ["serif", "sans-serif", "monospace", "cursive", "fantasy", "system-ui"];
93
+ // ジェネリックフォントファミリでない時クォートする。
94
+ // > Font family names must either be given quoted as strings, or unquoted as a sequence of one or more identifiers.
95
+ // > Generic family names are keywords and must not be quoted.
96
+ // see: https://developer.mozilla.org/en-US/docs/Web/CSS/font-family
97
+ function quoteIfNotGeneric(name) {
98
+ if (genericFontFamilyNames.indexOf(name) !== -1) {
99
+ return name;
100
+ }
101
+ else {
102
+ return `"${name}"`;
103
+ }
104
+ }
105
+ function fontFamily2CSSFontFamily(fontFamily) {
106
+ if (typeof fontFamily === "string") {
107
+ return quoteIfNotGeneric(fontFamily);
108
+ }
109
+ else {
110
+ return fontFamily
111
+ .map((font) => {
112
+ if (typeof font === "string") {
113
+ return quoteIfNotGeneric(font);
114
+ }
115
+ else {
116
+ return font;
117
+ }
118
+ })
119
+ .join(",");
120
+ }
121
+ }
122
+ class NodeCanvasGlyphFactory {
123
+ constructor(fontFamily, fontSize, baselineHeight = fontSize, fontColor = "black", strokeWidth = 0, strokeColor = "black", strokeOnly = false, fontWeight = "normal") {
124
+ this.fontFamily = fontFamily;
125
+ this.fontSize = fontSize;
126
+ this.fontWeight = fontWeight;
127
+ this.baselineHeight = baselineHeight;
128
+ this.fontColor = fontColor;
129
+ this.strokeWidth = strokeWidth;
130
+ this.strokeColor = strokeColor;
131
+ this.strokeOnly = strokeOnly;
132
+ this._glyphAreas = {};
133
+ this._cssFontFamily = fontFamily2CSSFontFamily(fontFamily);
134
+ // Akashicエンジンは指定されたフォントに利用可能なものが見つからない時
135
+ // `g.FontFamily.SansSerif` を利用する、と仕様して定められている。
136
+ const fallbackFontFamilyName = "sans-serif";
137
+ if (this._cssFontFamily.indexOf(fallbackFontFamilyName) === -1) {
138
+ this._cssFontFamily += "," + fallbackFontFamilyName;
139
+ }
140
+ // `this.fontSize`の大きさの文字を描画するためのサーフェスを生成する。
141
+ // 一部の文字は縦横が`this.fontSize`幅の矩形に収まらない。
142
+ // そこで上下左右にマージンを設ける。マージン幅は`this.fontSize`に
143
+ // 0.3 を乗じたものにする。0.3に確たる根拠はないが、検証した範囲では
144
+ // これで十分であることを確認している。
145
+ //
146
+ // strokeWidthサポートに伴い、輪郭線の厚みを加味している。
147
+ this._marginW = Math.ceil(this.fontSize * 0.3 + this.strokeWidth / 2);
148
+ this._marginH = Math.ceil(this.fontSize * 0.3 + this.strokeWidth / 2);
149
+ if (NodeCanvasGlyphFactory._environmentMinimumFontSize === undefined) {
150
+ NodeCanvasGlyphFactory._environmentMinimumFontSize = this.measureMinimumFontSize();
151
+ }
152
+ }
153
+ create(code) {
154
+ var _a, _b;
155
+ let result = null;
156
+ let glyphArea = this._glyphAreas[code];
157
+ if (!glyphArea) {
158
+ result = createGlyphRenderedSurface(code, this.fontSize, this._cssFontFamily, this.baselineHeight, this._marginW, this._marginH, true, this.fontColor, this.strokeWidth, this.strokeColor, this.strokeOnly, this.fontWeight);
159
+ glyphArea = calcGlyphArea(result.imageData); // NOTE: `needImageData` が true のため必ず真
160
+ glyphArea.advanceWidth = result.advanceWidth;
161
+ this._glyphAreas[code] = glyphArea;
162
+ }
163
+ if (isGlyphAreaEmpty(glyphArea)) {
164
+ if (result) {
165
+ result.surface.destroy();
166
+ }
167
+ return new NodeCanvasGlyph_1.NodeCanvasGlyph(code, 0, 0, 0, 0, 0, 0, glyphArea.advanceWidth, undefined, true);
168
+ }
169
+ else {
170
+ // g.Glyphに格納するサーフェスを生成する。
171
+ // glyphAreaはサーフェスをキャッシュしないため、描画する内容を持つグリフに対しては
172
+ // サーフェスを生成する。もし前段でcalcGlyphArea()のためのサーフェスを生成して
173
+ // いればここでは生成せずにそれを利用する。
174
+ if (!result) {
175
+ result = createGlyphRenderedSurface(code, this.fontSize, this._cssFontFamily, this.baselineHeight, this._marginW, this._marginH, false, this.fontColor, this.strokeWidth, this.strokeColor, this.strokeOnly, this.fontWeight);
176
+ }
177
+ return new NodeCanvasGlyph_1.NodeCanvasGlyph(code, glyphArea.x, glyphArea.y, (_a = glyphArea.width) !== null && _a !== void 0 ? _a : 0, (_b = glyphArea.height) !== null && _b !== void 0 ? _b : 0, glyphArea.x - this._marginW, glyphArea.y - this._marginH, glyphArea.advanceWidth, result.surface, true);
178
+ }
179
+ }
180
+ // 実行環境の描画可能なフォントサイズの最小値を返す
181
+ measureMinimumFontSize() {
182
+ let fontSize = 1;
183
+ const str = "M";
184
+ const canvas = new canvas_1.Canvas(50, 50);
185
+ const context = canvas.getContext("2d");
186
+ if (context == null) {
187
+ throw new Error("cannot get canvas context");
188
+ }
189
+ context.textAlign = "left";
190
+ context.textBaseline = "alphabetic";
191
+ context.lineJoin = "bevel";
192
+ let preWidth;
193
+ context.font = fontSize + "px sans-serif";
194
+ let width = context.measureText(str).width;
195
+ do {
196
+ preWidth = width;
197
+ fontSize += 1;
198
+ context.font = fontSize + "px sans-serif";
199
+ width = context.measureText(str).width;
200
+ } while (preWidth === width || fontSize > 50); // フォントサイズに対応しない動作環境の場合を考慮して上限値を設ける
201
+ return fontSize;
202
+ }
203
+ }
204
+ exports.NodeCanvasGlyphFactory = NodeCanvasGlyphFactory;
@@ -0,0 +1,16 @@
1
+ import type { akashicEngine as g } from "../../../engineFiles";
2
+ import { Asset } from "../../assets/Asset";
3
+ export declare class NodeCanvasImageAsset extends Asset implements g.ImageAsset {
4
+ type: "image";
5
+ width: number;
6
+ height: number;
7
+ hint: g.ImageAssetHint | undefined;
8
+ _surface: g.Surface | null;
9
+ private data;
10
+ private dataCache;
11
+ constructor(id: string, path: string, width: number, height: number);
12
+ destroy(): void;
13
+ _load(loader: g.AssetLoadHandler): void;
14
+ asSurface(): g.Surface;
15
+ initialize(hint: g.ImageAssetHint): void;
16
+ }
@@ -0,0 +1,78 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.NodeCanvasImageAsset = void 0;
4
+ const canvas_1 = require("canvas");
5
+ const Asset_1 = require("../../assets/Asset");
6
+ const NodeCanvasSurface_1 = require("./NodeCanvasSurface");
7
+ class NodeCanvasImageAsset extends Asset_1.Asset {
8
+ constructor(id, path, width, height) {
9
+ super(id, path);
10
+ this.type = "image";
11
+ this._surface = null;
12
+ this.data = null;
13
+ this.dataCache = null;
14
+ this.width = width;
15
+ this.height = height;
16
+ }
17
+ destroy() {
18
+ if (this._surface && !this._surface.destroyed()) {
19
+ this._surface.destroy();
20
+ }
21
+ this.data = null;
22
+ this._surface = null;
23
+ super.destroy();
24
+ }
25
+ _load(loader) {
26
+ if (this.dataCache != null) {
27
+ // restore image asset data and metadata destroyed in this.destroy()
28
+ this.data = this.dataCache.data;
29
+ this.id = this.dataCache.id;
30
+ this.onDestroyed = this.dataCache.onDestroyed;
31
+ this.originalPath = this.dataCache.originalPath;
32
+ this.path = this.dataCache.path;
33
+ this.width = this.dataCache.width;
34
+ this.height = this.dataCache.height;
35
+ loader._onAssetLoad(this);
36
+ }
37
+ else {
38
+ const image = new canvas_1.Image();
39
+ image.onerror = () => {
40
+ loader._onAssetError(this, {
41
+ name: "AssetLoadError",
42
+ message: "HTMLImageAsset unknown loading error",
43
+ retriable: false
44
+ });
45
+ };
46
+ image.onload = () => {
47
+ this.data = image;
48
+ this.dataCache = {
49
+ data: image,
50
+ id: this.id,
51
+ onDestroyed: this.onDestroyed,
52
+ originalPath: this.originalPath,
53
+ path: this.path,
54
+ width: this.width,
55
+ height: this.height
56
+ };
57
+ loader._onAssetLoad(this);
58
+ };
59
+ image.src = this.path;
60
+ }
61
+ }
62
+ asSurface() {
63
+ if (this.data == null) {
64
+ throw new Error("NodeCanvasImageAsset#asSurface(): not yet loaded.");
65
+ }
66
+ if (this._surface == null) {
67
+ const canvas = new canvas_1.Canvas(this.width, this.height);
68
+ const context = canvas.getContext("2d");
69
+ context.drawImage(this.data, 0, 0, this.width, this.height);
70
+ this._surface = new NodeCanvasSurface_1.NodeCanvasSurface(canvas);
71
+ }
72
+ return this._surface;
73
+ }
74
+ initialize(hint) {
75
+ this.hint = hint;
76
+ }
77
+ }
78
+ exports.NodeCanvasImageAsset = NodeCanvasImageAsset;
@@ -0,0 +1,26 @@
1
+ import type { CanvasRenderingContext2D } from "canvas";
2
+ import type { akashicEngine as g } from "../../../engineFiles";
3
+ export declare class NodeCanvasRenderer implements g.Renderer {
4
+ private context;
5
+ private width;
6
+ private height;
7
+ constructor(context: CanvasRenderingContext2D, width: number, height: number);
8
+ begin(): void;
9
+ drawSprites(): void;
10
+ clear(): void;
11
+ end(): void;
12
+ drawImage(surface: g.Surface, offsetX: number, offsetY: number, width: number, height: number, canvasOffsetX: number, canvasOffsetY: number): void;
13
+ translate(x: number, y: number): void;
14
+ transform(matrix: number[]): void;
15
+ opacity(opacity: number): void;
16
+ save(): void;
17
+ restore(): void;
18
+ fillRect(x: number, y: number, width: number, height: number, cssColor: string): void;
19
+ setCompositeOperation(operation: g.CompositeOperationString): void;
20
+ setOpacity(opacity: number): void;
21
+ setTransform(matrix: number[]): void;
22
+ setShaderProgram(_shaderProgram: g.ShaderProgram | null): void;
23
+ isSupportedShaderProgram(): boolean;
24
+ _getImageData(sx: number, sy: number, sw: number, sh: number): g.ImageData | null;
25
+ _putImageData(imageData: ImageData, dx: number, dy: number, dirtyX?: number, dirtyY?: number, dirtyWidth?: number, dirtyHeight?: number): void;
26
+ }
@@ -0,0 +1,72 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.NodeCanvasRenderer = void 0;
4
+ const CompositeOperationConverter_1 = require("./CompositeOperationConverter");
5
+ class NodeCanvasRenderer {
6
+ constructor(context, width, height) {
7
+ this.context = context;
8
+ this.width = width;
9
+ this.height = height;
10
+ }
11
+ begin() {
12
+ // do nothing
13
+ }
14
+ drawSprites() {
15
+ // do nothing
16
+ }
17
+ clear() {
18
+ this.context.clearRect(0, 0, this.width, this.height);
19
+ }
20
+ end() {
21
+ // do notiong
22
+ }
23
+ drawImage(surface, offsetX, offsetY, width, height, canvasOffsetX, canvasOffsetY) {
24
+ this.context.drawImage(surface._drawable, offsetX, offsetY, width, height, canvasOffsetX, canvasOffsetY, width, height);
25
+ }
26
+ translate(x, y) {
27
+ this.context.translate(x, y);
28
+ }
29
+ transform(matrix) {
30
+ // @ts-ignore 高速化のため型チェックを無効
31
+ this.context.transform.apply(this.context, matrix);
32
+ }
33
+ opacity(opacity) {
34
+ // NOTE: globalAlphaの初期値が1であることは仕様上保証されているため、常に掛け合わせる
35
+ this.context.globalAlpha *= opacity;
36
+ }
37
+ save() {
38
+ this.context.save();
39
+ }
40
+ restore() {
41
+ this.context.restore();
42
+ }
43
+ fillRect(x, y, width, height, cssColor) {
44
+ const _fillStyle = this.context.fillStyle;
45
+ this.context.fillStyle = cssColor;
46
+ this.context.fillRect(x, y, width, height);
47
+ this.context.fillStyle = _fillStyle;
48
+ }
49
+ setCompositeOperation(operation) {
50
+ this.context.globalCompositeOperation = CompositeOperationConverter_1.CompositeOperationConverter.toContext2D(operation);
51
+ }
52
+ setOpacity(opacity) {
53
+ this.context.globalAlpha = opacity;
54
+ }
55
+ setTransform(matrix) {
56
+ // @ts-ignore 高速化のため型チェックを無効
57
+ this.context.setTransform.apply(this.context, matrix);
58
+ }
59
+ setShaderProgram(_shaderProgram) {
60
+ // do nothing
61
+ }
62
+ isSupportedShaderProgram() {
63
+ return false;
64
+ }
65
+ _getImageData(sx, sy, sw, sh) {
66
+ return this.context.getImageData(sx, sy, sw, sh);
67
+ }
68
+ _putImageData(imageData, dx, dy, dirtyX = 0, dirtyY = 0, dirtyWidth = imageData.width, dirtyHeight = imageData.height) {
69
+ this.context.putImageData(imageData, dx, dy, dirtyX, dirtyY, dirtyWidth, dirtyHeight);
70
+ }
71
+ }
72
+ exports.NodeCanvasRenderer = NodeCanvasRenderer;
@@ -0,0 +1,14 @@
1
+ import type { Canvas } from "canvas";
2
+ import type { akashicEngine as g } from "../../../engineFiles";
3
+ import { NodeCanvasRenderer } from "./NodeCanvasRenderer";
4
+ export declare class NodeCanvasSurface implements g.Surface {
5
+ width: number;
6
+ height: number;
7
+ _drawable: Canvas;
8
+ _renderer: NodeCanvasRenderer;
9
+ constructor(canvas: Canvas);
10
+ renderer(): NodeCanvasRenderer;
11
+ isPlaying(): boolean;
12
+ destroy(): void;
13
+ destroyed(): boolean;
14
+ }
@@ -0,0 +1,25 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.NodeCanvasSurface = void 0;
4
+ const NodeCanvasRenderer_1 = require("./NodeCanvasRenderer");
5
+ class NodeCanvasSurface {
6
+ constructor(canvas) {
7
+ this.width = canvas.width;
8
+ this.height = canvas.height;
9
+ this._drawable = canvas;
10
+ this._renderer = new NodeCanvasRenderer_1.NodeCanvasRenderer(canvas.getContext("2d"), canvas.width, canvas.height);
11
+ }
12
+ renderer() {
13
+ return this._renderer;
14
+ }
15
+ isPlaying() {
16
+ return false;
17
+ }
18
+ destroy() {
19
+ // do nothing
20
+ }
21
+ destroyed() {
22
+ return this._renderer == null;
23
+ }
24
+ }
25
+ exports.NodeCanvasSurface = NodeCanvasSurface;
@@ -0,0 +1,16 @@
1
+ import type { akashicEngine as g } from "../../../engineFiles";
2
+ export declare class NullGlyph implements g.Glyph {
3
+ code: number;
4
+ x: number;
5
+ y: number;
6
+ width: number;
7
+ height: number;
8
+ surface: g.Surface;
9
+ offsetX: number;
10
+ offsetY: number;
11
+ advanceWidth: number;
12
+ isSurfaceValid: boolean;
13
+ _atlas: g.SurfaceAtlas | null;
14
+ constructor(code: number, x: number, y: number, width: number, height: number, offsetX: number | undefined, offsetY: number | undefined, advanceWidth: number | undefined, surface: g.Surface, isSurfaceValid: boolean);
15
+ renderingWidth(fontSize: number): number;
16
+ }
@@ -0,0 +1,25 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.NullGlyph = void 0;
4
+ class NullGlyph {
5
+ constructor(code, x, y, width, height, offsetX = 0, offsetY = 0, advanceWidth = width, surface, isSurfaceValid) {
6
+ this.code = code;
7
+ this.x = x;
8
+ this.y = y;
9
+ this.width = width;
10
+ this.height = height;
11
+ this.offsetX = offsetX;
12
+ this.offsetY = offsetY;
13
+ this.advanceWidth = advanceWidth;
14
+ this.surface = surface;
15
+ this.isSurfaceValid = isSurfaceValid;
16
+ this._atlas = null;
17
+ }
18
+ renderingWidth(fontSize) {
19
+ if (!this.width || !this.height) {
20
+ return 0;
21
+ }
22
+ return (fontSize / this.height) * this.width;
23
+ }
24
+ }
25
+ exports.NullGlyph = NullGlyph;
@@ -0,0 +1,14 @@
1
+ import type { akashicEngine as g } from "../../../engineFiles";
2
+ export declare class NullGlyphFactory implements g.GlyphFactory {
3
+ fontFamily: string | string[];
4
+ fontSize: number;
5
+ baselineHeight: number;
6
+ fontColor: string;
7
+ fontWeight: g.FontWeightString;
8
+ strokeWidth: number;
9
+ strokeColor: string;
10
+ strokeOnly: boolean;
11
+ private dummySurface;
12
+ constructor(fontFamily: string | string[], fontSize: number, baselineHeight?: number, fontColor?: string, strokeWidth?: number, strokeColor?: string, strokeOnly?: boolean, fontWeight?: g.FontWeightString);
13
+ create(code: number): g.Glyph;
14
+ }
@@ -0,0 +1,22 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.NullGlyphFactory = void 0;
4
+ const NullGlyph_1 = require("./NullGlyph");
5
+ const NullSurface_1 = require("./NullSurface");
6
+ class NullGlyphFactory {
7
+ constructor(fontFamily, fontSize, baselineHeight = fontSize, fontColor = "black", strokeWidth = 0, strokeColor = "black", strokeOnly = false, fontWeight = "normal") {
8
+ this.dummySurface = new NullSurface_1.NullSurface(0, 0);
9
+ this.fontFamily = fontFamily;
10
+ this.fontSize = fontSize;
11
+ this.fontWeight = fontWeight;
12
+ this.baselineHeight = baselineHeight;
13
+ this.fontColor = fontColor;
14
+ this.strokeWidth = strokeWidth;
15
+ this.strokeColor = strokeColor;
16
+ this.strokeOnly = strokeOnly;
17
+ }
18
+ create(code) {
19
+ return new NullGlyph_1.NullGlyph(code, 0, 0, 0, 0, 0, 0, this.fontSize, this.dummySurface, true);
20
+ }
21
+ }
22
+ exports.NullGlyphFactory = NullGlyphFactory;
@@ -0,0 +1,13 @@
1
+ import type { akashicEngine as g } from "../../../engineFiles";
2
+ import { Asset } from "../../assets/Asset";
3
+ export declare class NullImageAsset extends Asset implements g.ImageAsset {
4
+ type: "image";
5
+ width: number;
6
+ height: number;
7
+ hint: g.ImageAssetHint | undefined;
8
+ _surface: g.Surface | null;
9
+ constructor(id: string, assetPath: string, width: number, height: number);
10
+ _load(loader: g.AssetLoadHandler): void;
11
+ asSurface(): g.Surface;
12
+ initialize(hint: g.ImageAssetHint): void;
13
+ }
@@ -0,0 +1,24 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.NullImageAsset = void 0;
4
+ const Asset_1 = require("../../assets/Asset");
5
+ const NullSurface_1 = require("./NullSurface");
6
+ class NullImageAsset extends Asset_1.Asset {
7
+ constructor(id, assetPath, width, height) {
8
+ super(id, assetPath);
9
+ this.type = "image";
10
+ this._surface = null;
11
+ this.width = width;
12
+ this.height = height;
13
+ }
14
+ _load(loader) {
15
+ loader._onAssetLoad(this);
16
+ }
17
+ asSurface() {
18
+ return this._surface || (this._surface = new NullSurface_1.NullSurface(this.width, this.height));
19
+ }
20
+ initialize(hint) {
21
+ this.hint = hint;
22
+ }
23
+ }
24
+ exports.NullImageAsset = NullImageAsset;
@@ -0,0 +1,21 @@
1
+ import type { akashicEngine as g } from "../../../engineFiles";
2
+ export declare class NullRenderer implements g.Renderer {
3
+ begin(): void;
4
+ end(): void;
5
+ clear(): void;
6
+ drawImage(_surface: g.Surface, _offsetX: number, _offsetY: number, _width: number, _height: number, _destOffsetX: number, _destOffsetY: number): void;
7
+ drawSprites(_surface: g.Surface, _offsetX: number[], _offsetY: number[], _width: number[], _height: number[], _canvasOffsetX: number[], _canvasOffsetY: number[], _count: number): void;
8
+ translate(_x: number, _y: number): void;
9
+ transform(_matrix: number[]): void;
10
+ opacity(_opacity: number): void;
11
+ save(): void;
12
+ restore(): void;
13
+ fillRect(_x: number, _y: number, _width: number, _height: number, _cssColor: string): void;
14
+ setCompositeOperation(_operation: g.CompositeOperationString): void;
15
+ setTransform(_matrix: number[]): void;
16
+ setOpacity(_opacity: number): void;
17
+ isSupportedShaderProgram(): boolean;
18
+ setShaderProgram(_shaderProgram: g.ShaderProgram | null): void;
19
+ _getImageData(_sx: number, _sy: number, _sw: number, _sh: number): g.ImageData | null;
20
+ _putImageData(_imageData: g.ImageData, _dx: number, _dy: number, _dirtyX?: number, _dirtyY?: number, _dirtyWidth?: number, _dirtyHeight?: number): void;
21
+ }