@konoui/mjimage 0.0.31 → 0.0.32

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 (61) hide show
  1. package/dist/index.cjs +30 -0
  2. package/dist/index.d.cts +1386 -0
  3. package/dist/index.d.ts +1386 -0
  4. package/dist/index.js +10953 -0
  5. package/package.json +23 -14
  6. package/dist/mjs/cmd/index.d.ts +0 -1
  7. package/dist/mjs/cmd/index.js +0 -49
  8. package/dist/mjs/index.d.ts +0 -6
  9. package/dist/mjs/index.js +0 -22
  10. package/dist/mjs/lib/calculator/calc.d.ts +0 -275
  11. package/dist/mjs/lib/calculator/calc.js +0 -1397
  12. package/dist/mjs/lib/calculator/efficiency.d.ts +0 -24
  13. package/dist/mjs/lib/calculator/efficiency.js +0 -82
  14. package/dist/mjs/lib/calculator/helper.d.ts +0 -6
  15. package/dist/mjs/lib/calculator/helper.js +0 -21
  16. package/dist/mjs/lib/calculator/index.d.ts +0 -3
  17. package/dist/mjs/lib/calculator/index.js +0 -19
  18. package/dist/mjs/lib/controller/controller.d.ts +0 -168
  19. package/dist/mjs/lib/controller/controller.js +0 -897
  20. package/dist/mjs/lib/controller/events.d.ts +0 -171
  21. package/dist/mjs/lib/controller/events.js +0 -102
  22. package/dist/mjs/lib/controller/game.d.ts +0 -5
  23. package/dist/mjs/lib/controller/game.js +0 -29
  24. package/dist/mjs/lib/controller/index.d.ts +0 -10
  25. package/dist/mjs/lib/controller/index.js +0 -26
  26. package/dist/mjs/lib/controller/managers.d.ts +0 -83
  27. package/dist/mjs/lib/controller/managers.js +0 -194
  28. package/dist/mjs/lib/controller/player-efficiency.d.ts +0 -24
  29. package/dist/mjs/lib/controller/player-efficiency.js +0 -153
  30. package/dist/mjs/lib/controller/player.d.ts +0 -12
  31. package/dist/mjs/lib/controller/player.js +0 -85
  32. package/dist/mjs/lib/controller/replay.d.ts +0 -10
  33. package/dist/mjs/lib/controller/replay.js +0 -31
  34. package/dist/mjs/lib/controller/river.d.ts +0 -19
  35. package/dist/mjs/lib/controller/river.js +0 -52
  36. package/dist/mjs/lib/controller/state-machine.d.ts +0 -67
  37. package/dist/mjs/lib/controller/state-machine.js +0 -771
  38. package/dist/mjs/lib/controller/wall.d.ts +0 -24
  39. package/dist/mjs/lib/controller/wall.js +0 -117
  40. package/dist/mjs/lib/core/constants.d.ts +0 -73
  41. package/dist/mjs/lib/core/constants.js +0 -73
  42. package/dist/mjs/lib/core/index.d.ts +0 -2
  43. package/dist/mjs/lib/core/index.js +0 -18
  44. package/dist/mjs/lib/core/lexer.d.ts +0 -14
  45. package/dist/mjs/lib/core/lexer.js +0 -53
  46. package/dist/mjs/lib/core/parser.d.ts +0 -120
  47. package/dist/mjs/lib/core/parser.js +0 -612
  48. package/dist/mjs/lib/image/image.d.ts +0 -42
  49. package/dist/mjs/lib/image/image.js +0 -361
  50. package/dist/mjs/lib/image/index.d.ts +0 -1
  51. package/dist/mjs/lib/image/index.js +0 -17
  52. package/dist/mjs/lib/measure-text/index.d.ts +0 -19
  53. package/dist/mjs/lib/measure-text/index.js +0 -49
  54. package/dist/mjs/lib/myassert/index.d.ts +0 -1
  55. package/dist/mjs/lib/myassert/index.js +0 -8
  56. package/dist/mjs/lib/table/index.d.ts +0 -2
  57. package/dist/mjs/lib/table/index.js +0 -18
  58. package/dist/mjs/lib/table/table-parser.d.ts +0 -127
  59. package/dist/mjs/lib/table/table-parser.js +0 -105
  60. package/dist/mjs/lib/table/table.d.ts +0 -12
  61. package/dist/mjs/lib/table/table.js +0 -248
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@konoui/mjimage",
3
- "version": "0.0.31",
3
+ "version": "0.0.32",
4
4
  "description": "Generates Mahjong tiles in SVG format.",
5
5
  "author": "konoui",
6
6
  "license": "MIT",
@@ -13,34 +13,43 @@
13
13
  "access": "public"
14
14
  },
15
15
  "scripts": {
16
- "test": "jest",
17
- "cmd": "ts-node ./src/cmd/index.ts",
18
- "tsc": "tsc --declaration --outDir ./dist/mjs",
19
- "prepublishOnly": "rm -rf ./dist && npm run tsc"
16
+ "build": "vite build",
17
+ "test": "vitest run",
18
+ "cmd": "tsx src/cmd/index.ts",
19
+ "prepublishOnly": "npm run build"
20
20
  },
21
- "types": "dist/mjs/index.d.ts",
21
+ "type": "module",
22
22
  "files": [
23
23
  "dist/",
24
24
  "!**/__tests__/"
25
25
  ],
26
26
  "exports": {
27
- ".": "./dist/mjs/index.js",
28
- "./core": "./dist/mjs/lib/core/index.js",
29
- "./image": "./dist/mjs/lib/image/index.js",
30
- "./table": "./dist/mjs/lib/table/index.js",
31
- "./calculator": "./dist/mjs/lib/calculator/index.js"
27
+ ".": {
28
+ "import": {
29
+ "types": "./dist/index.d.ts",
30
+ "default": "./dist/index.js"
31
+ },
32
+ "require": {
33
+ "types": "./dist/index.d.cts",
34
+ "default": "./dist/index.cjs"
35
+ }
36
+ }
32
37
  },
33
38
  "devDependencies": {
34
- "@types/jest": "^29.5.5",
35
39
  "@types/js-yaml": "^4.0.9",
40
+ "@types/node": "^22.6.1",
36
41
  "@types/svgdom": "^0.1.0",
37
42
  "buffer": "^6.0.3",
38
43
  "process": "^0.11.10",
39
44
  "svg-sprite": "^2.0.2",
40
45
  "svgdom": "0.1.14",
41
46
  "svgo": "^3.0.2",
42
- "ts-jest": "^29.1.1",
43
- "typescript": "^5.5.4"
47
+ "tsx": "^4.19.1",
48
+ "typescript": "^5.5.4",
49
+ "vite": "^5.4.7",
50
+ "vite-plugin-dts": "^4.2.2",
51
+ "vite-tsconfig-paths": "^5.0.1",
52
+ "vitest": "^2.1.1"
44
53
  },
45
54
  "dependencies": {
46
55
  "@svgdotjs/svg.js": "^3.2.4",
@@ -1 +0,0 @@
1
- export {};
@@ -1,49 +0,0 @@
1
- "use strict";
2
- var _a;
3
- Object.defineProperty(exports, "__esModule", { value: true });
4
- var controller_1 = require("./../lib/controller");
5
- var replay_1 = require("../lib/controller/replay");
6
- var helper_1 = require("./../lib/__tests__/utils/helper");
7
- var type = process.argv[2];
8
- if (!["test", "single", "game"].includes(type))
9
- throw new Error("unexpected type");
10
- var count = (_a = Number(process.argv[3])) !== null && _a !== void 0 ? _a : 1;
11
- var filename = "games.json";
12
- if (type == "test") {
13
- var games = (0, helper_1.loadArrayData)(filename);
14
- for (var _i = 0, games_1 = games; _i < games_1.length; _i++) {
15
- var game = games_1[_i];
16
- var r = new replay_1.Replayer(game);
17
- r.auto();
18
- }
19
- }
20
- if (type == "game" || type == "single") {
21
- for (var i = 0; i < count; i++) {
22
- console.debug("".concat(type, "(").concat(i, ")==="));
23
- var c = (0, controller_1.createLocalGame)();
24
- var starter = factory(c, type);
25
- subscribeError(c);
26
- try {
27
- starter();
28
- }
29
- catch (e) {
30
- console.error("Error", e);
31
- (0, helper_1.storeArrayData)(filename, c.export());
32
- }
33
- }
34
- }
35
- function factory(c, type) {
36
- if (type == "single")
37
- return function () { return c.start(); };
38
- else
39
- return function () { return c.startGame(); };
40
- }
41
- function subscribeError(c) {
42
- c.actor.subscribe({
43
- error: function (err) {
44
- console.error("Error", err);
45
- (0, helper_1.storeArrayData)(filename, c.export());
46
- process.exit(1);
47
- },
48
- });
49
- }
@@ -1,6 +0,0 @@
1
- export * from "./lib/measure-text/";
2
- export * from "./lib/core/";
3
- export * from "./lib/table/";
4
- export * from "./lib/image/";
5
- export * from "./lib/calculator/";
6
- export * from "./lib/controller/";
package/dist/mjs/index.js DELETED
@@ -1,22 +0,0 @@
1
- "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- var desc = Object.getOwnPropertyDescriptor(m, k);
5
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
- desc = { enumerable: true, get: function() { return m[k]; } };
7
- }
8
- Object.defineProperty(o, k2, desc);
9
- }) : (function(o, m, k, k2) {
10
- if (k2 === undefined) k2 = k;
11
- o[k2] = m[k];
12
- }));
13
- var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
- for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
- };
16
- Object.defineProperty(exports, "__esModule", { value: true });
17
- __exportStar(require("./lib/measure-text/"), exports);
18
- __exportStar(require("./lib/core/"), exports);
19
- __exportStar(require("./lib/table/"), exports);
20
- __exportStar(require("./lib/image/"), exports);
21
- __exportStar(require("./lib/calculator/"), exports);
22
- __exportStar(require("./lib/controller/"), exports);
@@ -1,275 +0,0 @@
1
- import { TYPE, Round, Wind } from "../core/constants";
2
- import { Tile, BlockPon, BlockChi, BlockShoKan, BlockAnKan, BlockDaiKan, Type, Block, SerializedBlock } from "../core/parser";
3
- export type TupleOfSize<T, N extends number, R extends unknown[] = []> = R["length"] extends N ? R : TupleOfSize<T, N, [T, ...R]>;
4
- export interface HandData {
5
- [TYPE.M]: TupleOfSize<number, 10>;
6
- [TYPE.S]: TupleOfSize<number, 10>;
7
- [TYPE.P]: TupleOfSize<number, 10>;
8
- [TYPE.Z]: TupleOfSize<number, 8>;
9
- [TYPE.BACK]: [string, number];
10
- called: readonly (BlockChi | BlockPon | BlockAnKan | BlockDaiKan | BlockShoKan)[];
11
- tsumo: Tile | null;
12
- reached: boolean;
13
- }
14
- export declare class Hand {
15
- protected data: HandData;
16
- constructor(input: string, allowBackBlock?: boolean);
17
- private init;
18
- get hands(): Tile[];
19
- toString(): string;
20
- get called(): readonly (BlockChi | BlockPon | BlockAnKan | BlockDaiKan | BlockShoKan)[];
21
- get reached(): boolean;
22
- get drawn(): Tile | null;
23
- get menzen(): boolean;
24
- getArrayLen(t: Type): 2 | 8 | 10;
25
- sum(t: Type): number;
26
- get(t: Type, n: number): number;
27
- inc(tiles: readonly Tile[]): Tile[];
28
- dec(tiles: readonly Tile[]): Tile[];
29
- draw(t: Tile): void;
30
- discard(t: Tile): void;
31
- reach(): void;
32
- call(b: BlockPon | BlockChi | BlockDaiKan): void;
33
- kan(b: BlockAnKan | BlockShoKan): void;
34
- clone(): Hand;
35
- }
36
- export declare class ShantenCalculator {
37
- hand: Hand;
38
- constructor(hand: Hand);
39
- calc(): number;
40
- sevenPairs(): number;
41
- thirteenOrphans(): number;
42
- fourSetsOnePair(): number;
43
- private commonByType;
44
- private groupRemainingTiles;
45
- private calcCommon;
46
- }
47
- export declare class BlockCalculator {
48
- hand: Hand;
49
- constructor(hand: Hand);
50
- calc(lastTile: Tile): Block[][];
51
- markDrawn(hands: Block[][], lastTile: Tile): Block[][];
52
- sevenPairs(): Block[][];
53
- thirteenOrphans(): Block[][];
54
- nineGates(): Block[][];
55
- fourSetsOnePair(): Block[][];
56
- private commonAll;
57
- private commonByType;
58
- }
59
- export declare const NZ: readonly number[];
60
- export declare const N19: readonly number[];
61
- export declare const deserializeWinResult: (ret: SerializedWinResult) => WinResult;
62
- type SerializedBoardContext = Omit<BoardContext, "doraMarkers" | "blindDoraMarkers"> & {
63
- doraMarkers: string[];
64
- blindDoraMarkers?: string[];
65
- };
66
- export type SerializedWinResult = Omit<WinResult, "hand" | "boardContext"> & {
67
- hand: SerializedBlock[];
68
- boardContext: SerializedBoardContext;
69
- };
70
- export interface BoardContext {
71
- doraMarkers: Tile[];
72
- blindDoraMarkers?: Tile[];
73
- round: Round;
74
- myWind: Wind;
75
- ronWind?: Wind;
76
- sticks?: {
77
- reach: number;
78
- dead: number;
79
- };
80
- reached?: 1 | 2;
81
- replacementWin?: boolean;
82
- quadWin?: boolean;
83
- finalWallWin?: boolean;
84
- finalDiscardWin?: boolean;
85
- oneShotWin?: boolean;
86
- }
87
- export interface WinResult {
88
- deltas: {
89
- [w in Wind]: number;
90
- };
91
- sum: number;
92
- fu: number;
93
- points: {
94
- name: string;
95
- double: number;
96
- }[];
97
- point: number;
98
- hand: Block[];
99
- boardContext: BoardContext;
100
- }
101
- export declare class DoubleCalculator {
102
- hand: Hand;
103
- cfg: {
104
- doras: Tile[];
105
- blindDoras: Tile[];
106
- roundWind: Tile;
107
- myWind: Tile;
108
- reached: 0 | 1 | 2;
109
- sticks: {
110
- reach: number;
111
- dead: number;
112
- };
113
- replacementWin: boolean;
114
- quadWin: boolean;
115
- finalWallWin: boolean;
116
- finalDiscardWin: boolean;
117
- oneShotWin: boolean;
118
- orig: BoardContext;
119
- };
120
- constructor(hand: Hand, params: BoardContext);
121
- calc(hands: Block[][]): WinResult | false;
122
- calcPatterns(hands: Block[][]): {
123
- points: {
124
- name: string;
125
- double: number;
126
- }[];
127
- fu: number;
128
- hand: Block[];
129
- }[];
130
- private minus;
131
- dA1(h: Block[]): {
132
- name: string;
133
- double: number;
134
- }[];
135
- dB1(h: Block[]): {
136
- name: string;
137
- double: number;
138
- }[];
139
- dC1(h: Block[]): {
140
- name: string;
141
- double: number;
142
- }[];
143
- dD1(h: Block[]): {
144
- name: string;
145
- double: number;
146
- }[];
147
- dE1(h: Block[]): {
148
- name: string;
149
- double: number;
150
- }[];
151
- dF1(h: Block[]): {
152
- name: string;
153
- double: number;
154
- }[];
155
- dG1(h: Block[]): {
156
- name: string;
157
- double: number;
158
- }[];
159
- dH1(h: Block[]): {
160
- name: string;
161
- double: number;
162
- }[];
163
- dI1(h: Block[]): {
164
- name: string;
165
- double: number;
166
- }[];
167
- dJ1(h: Block[]): {
168
- name: string;
169
- double: number;
170
- }[];
171
- dK1(h: Block[]): {
172
- name: string;
173
- double: number;
174
- }[];
175
- dX1(h: Block[]): {
176
- name: string;
177
- double: number;
178
- }[];
179
- dA2(h: Block[]): {
180
- name: string;
181
- double: number;
182
- }[];
183
- dB2(h: Block[]): {
184
- name: string;
185
- double: number;
186
- }[];
187
- dC2(h: Block[]): {
188
- name: string;
189
- double: number;
190
- }[];
191
- dD2(h: Block[]): {
192
- name: string;
193
- double: number;
194
- }[];
195
- dE2(h: Block[]): {
196
- name: string;
197
- double: number;
198
- }[];
199
- dF2(h: Block[]): {
200
- name: string;
201
- double: number;
202
- }[];
203
- dG2(h: Block[]): {
204
- name: string;
205
- double: number;
206
- }[];
207
- dH2(h: Block[]): {
208
- name: string;
209
- double: number;
210
- }[];
211
- dI2(h: Block[]): {
212
- name: string;
213
- double: number;
214
- }[];
215
- dJ2(h: Block[]): {
216
- name: string;
217
- double: number;
218
- }[];
219
- dA3(h: Block[]): {
220
- name: string;
221
- double: number;
222
- }[];
223
- dB3(h: Block[]): {
224
- name: string;
225
- double: number;
226
- }[];
227
- dC3(h: Block[]): {
228
- name: string;
229
- double: number;
230
- }[];
231
- dA6(h: Block[]): {
232
- name: string;
233
- double: number;
234
- }[];
235
- dA13(h: Block[]): {
236
- name: string;
237
- double: number;
238
- }[];
239
- dB13(h: Block[]): {
240
- name: string;
241
- double: number;
242
- }[];
243
- dC13(h: Block[]): {
244
- name: string;
245
- double: number;
246
- }[];
247
- dD13(h: Block[]): {
248
- name: string;
249
- double: number;
250
- }[];
251
- dE13(h: Block[]): {
252
- name: string;
253
- double: number;
254
- }[];
255
- dF13(h: Block[]): {
256
- name: string;
257
- double: number;
258
- }[];
259
- dG13(h: Block[]): {
260
- name: string;
261
- double: number;
262
- }[];
263
- dH13(h: Block[]): {
264
- name: string;
265
- double: number;
266
- }[];
267
- dI13(h: Block[]): {
268
- name: string;
269
- double: number;
270
- }[];
271
- dJ13(h: Block[]): never[];
272
- dK13(h: Block[]): never[];
273
- calcFu(h: Block[]): number;
274
- }
275
- export {};