@konoui/mjimage 0.0.27 → 0.0.28
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.
|
@@ -2,12 +2,12 @@ import { Tile } from "../core";
|
|
|
2
2
|
import { Hand } from "./calc";
|
|
3
3
|
export interface SerializedCandidate {
|
|
4
4
|
tile: string;
|
|
5
|
-
candidates: string[];
|
|
5
|
+
candidates: readonly string[];
|
|
6
6
|
shanten: number;
|
|
7
7
|
}
|
|
8
8
|
export interface Candidate {
|
|
9
9
|
tile: Tile;
|
|
10
|
-
candidates: Tile[];
|
|
10
|
+
candidates: readonly Tile[];
|
|
11
11
|
shanten: number;
|
|
12
12
|
}
|
|
13
13
|
export declare class Efficiency {
|
|
@@ -47,7 +47,7 @@ export declare abstract class Block {
|
|
|
47
47
|
};
|
|
48
48
|
get type(): "unknown" | "pon" | "chi" | "shokan" | "daikan" | "ankan" | "tsumo" | "three" | "pair" | "isolated" | "run" | "hand" | "dora" | "simple-discard";
|
|
49
49
|
get tiles(): readonly Tile[];
|
|
50
|
-
toString(): string;
|
|
50
|
+
abstract toString(): string;
|
|
51
51
|
is(type: BLOCK): boolean;
|
|
52
52
|
isCalled(): boolean;
|
|
53
53
|
clone(override?: {
|
|
@@ -63,9 +63,11 @@ export declare abstract class Block {
|
|
|
63
63
|
}
|
|
64
64
|
export declare class BlockChi extends Block {
|
|
65
65
|
constructor(tiles: readonly [Tile, Tile, Tile]);
|
|
66
|
+
toString(): string;
|
|
66
67
|
}
|
|
67
68
|
export declare class BlockPon extends Block {
|
|
68
69
|
constructor(tiles: readonly [Tile, Tile, Tile]);
|
|
70
|
+
toString(): string;
|
|
69
71
|
}
|
|
70
72
|
export declare class BlockAnKan extends Block {
|
|
71
73
|
constructor(tiles: readonly Tile[]);
|
|
@@ -75,27 +77,35 @@ export declare class BlockAnKan extends Block {
|
|
|
75
77
|
}
|
|
76
78
|
export declare class BlockDaiKan extends Block {
|
|
77
79
|
constructor(tiles: readonly Tile[]);
|
|
80
|
+
toString(): string;
|
|
78
81
|
}
|
|
79
82
|
export declare class BlockShoKan extends Block {
|
|
80
83
|
constructor(tiles: readonly Tile[]);
|
|
84
|
+
toString(): string;
|
|
81
85
|
}
|
|
82
86
|
export declare class BlockPair extends Block {
|
|
83
87
|
constructor(tile1: Tile, tile2: Tile);
|
|
88
|
+
toString(): string;
|
|
84
89
|
}
|
|
85
90
|
export declare class BlockThree extends Block {
|
|
86
91
|
constructor(tiles: readonly [Tile, Tile, Tile]);
|
|
92
|
+
toString(): string;
|
|
87
93
|
}
|
|
88
94
|
export declare class BlockRun extends Block {
|
|
89
95
|
constructor(tiles: readonly [Tile, Tile, Tile]);
|
|
96
|
+
toString(): string;
|
|
90
97
|
}
|
|
91
98
|
export declare class BlockIsolated extends Block {
|
|
92
99
|
constructor(tile: Tile);
|
|
100
|
+
toString(): string;
|
|
93
101
|
}
|
|
94
102
|
export declare class BlockHand extends Block {
|
|
95
103
|
constructor(tiles: readonly Tile[]);
|
|
104
|
+
toString(): string;
|
|
96
105
|
}
|
|
97
106
|
export declare class BlockOther extends Block {
|
|
98
107
|
constructor(tiles: readonly Tile[], type: BLOCK);
|
|
108
|
+
toString(): string;
|
|
99
109
|
}
|
|
100
110
|
export declare class Parser {
|
|
101
111
|
readonly input: string;
|
|
@@ -172,25 +172,6 @@ var Block = (function () {
|
|
|
172
172
|
enumerable: false,
|
|
173
173
|
configurable: true
|
|
174
174
|
});
|
|
175
|
-
Block.prototype.toString = function () {
|
|
176
|
-
var _this = this;
|
|
177
|
-
var sameType = this.tiles.every(function (v) { return v.t == _this.tiles[0].t; });
|
|
178
|
-
var ret = "";
|
|
179
|
-
if (sameType) {
|
|
180
|
-
if (this.tiles[0].t == _1.TYPE.BACK)
|
|
181
|
-
return this.tiles.join("");
|
|
182
|
-
for (var _i = 0, _a = this.tiles; _i < _a.length; _i++) {
|
|
183
|
-
var v = _a[_i];
|
|
184
|
-
ret += v.toString().slice(0, -1);
|
|
185
|
-
}
|
|
186
|
-
return "".concat(ret).concat(this.tiles[0].t);
|
|
187
|
-
}
|
|
188
|
-
for (var _b = 0, _c = this.tiles; _b < _c.length; _b++) {
|
|
189
|
-
var t = _c[_b];
|
|
190
|
-
ret += t.toString();
|
|
191
|
-
}
|
|
192
|
-
return ret;
|
|
193
|
-
};
|
|
194
175
|
Block.prototype.is = function (type) {
|
|
195
176
|
return this._type == type;
|
|
196
177
|
};
|
|
@@ -227,11 +208,42 @@ var Block = (function () {
|
|
|
227
208
|
return Block;
|
|
228
209
|
}());
|
|
229
210
|
exports.Block = Block;
|
|
211
|
+
var toStringForSame = function (tiles) {
|
|
212
|
+
var ret = "";
|
|
213
|
+
for (var _i = 0, tiles_1 = tiles; _i < tiles_1.length; _i++) {
|
|
214
|
+
var v = tiles_1[_i];
|
|
215
|
+
if (v.t == _1.TYPE.BACK)
|
|
216
|
+
return tiles.join("");
|
|
217
|
+
ret += v.toString().slice(0, -1);
|
|
218
|
+
}
|
|
219
|
+
return "".concat(ret).concat(tiles[0].t);
|
|
220
|
+
};
|
|
221
|
+
var toStringForHand = function (tiles) {
|
|
222
|
+
var preType = tiles[0].t;
|
|
223
|
+
var ret = "";
|
|
224
|
+
for (var i = 0; i < tiles.length; i++) {
|
|
225
|
+
var tile = tiles[i];
|
|
226
|
+
var type = tile.t;
|
|
227
|
+
var nop = type == _1.TYPE.BACK ? tile.toString() : tile.toString().slice(0, -1);
|
|
228
|
+
if (type != preType)
|
|
229
|
+
if (preType != _1.TYPE.BACK)
|
|
230
|
+
ret += preType;
|
|
231
|
+
preType = type;
|
|
232
|
+
ret += nop;
|
|
233
|
+
}
|
|
234
|
+
var last = tiles.at(-1);
|
|
235
|
+
if (last.t != _1.TYPE.BACK)
|
|
236
|
+
ret += last.t;
|
|
237
|
+
return ret;
|
|
238
|
+
};
|
|
230
239
|
var BlockChi = (function (_super) {
|
|
231
240
|
__extends(BlockChi, _super);
|
|
232
241
|
function BlockChi(tiles) {
|
|
233
242
|
return _super.call(this, tiles, _1.BLOCK.CHI) || this;
|
|
234
243
|
}
|
|
244
|
+
BlockChi.prototype.toString = function () {
|
|
245
|
+
return toStringForSame(this.tiles);
|
|
246
|
+
};
|
|
235
247
|
return BlockChi;
|
|
236
248
|
}(Block));
|
|
237
249
|
exports.BlockChi = BlockChi;
|
|
@@ -240,6 +252,9 @@ var BlockPon = (function (_super) {
|
|
|
240
252
|
function BlockPon(tiles) {
|
|
241
253
|
return _super.call(this, tiles, _1.BLOCK.PON) || this;
|
|
242
254
|
}
|
|
255
|
+
BlockPon.prototype.toString = function () {
|
|
256
|
+
return toStringForSame(this.tiles);
|
|
257
|
+
};
|
|
243
258
|
return BlockPon;
|
|
244
259
|
}(Block));
|
|
245
260
|
exports.BlockPon = BlockPon;
|
|
@@ -281,10 +296,7 @@ var BlockAnKan = (function (_super) {
|
|
|
281
296
|
return _super.from.call(this, v);
|
|
282
297
|
};
|
|
283
298
|
BlockAnKan.prototype.toString = function () {
|
|
284
|
-
|
|
285
|
-
return tiles.reduce(function (s, t) {
|
|
286
|
-
return "".concat(s).concat(t.toString());
|
|
287
|
-
}, "");
|
|
299
|
+
return toStringForHand(this.tilesWithBack);
|
|
288
300
|
};
|
|
289
301
|
return BlockAnKan;
|
|
290
302
|
}(Block));
|
|
@@ -294,6 +306,9 @@ var BlockDaiKan = (function (_super) {
|
|
|
294
306
|
function BlockDaiKan(tiles) {
|
|
295
307
|
return _super.call(this, tiles, _1.BLOCK.DAI_KAN) || this;
|
|
296
308
|
}
|
|
309
|
+
BlockDaiKan.prototype.toString = function () {
|
|
310
|
+
return toStringForSame(this.tiles);
|
|
311
|
+
};
|
|
297
312
|
return BlockDaiKan;
|
|
298
313
|
}(Block));
|
|
299
314
|
exports.BlockDaiKan = BlockDaiKan;
|
|
@@ -302,6 +317,9 @@ var BlockShoKan = (function (_super) {
|
|
|
302
317
|
function BlockShoKan(tiles) {
|
|
303
318
|
return _super.call(this, tiles, _1.BLOCK.SHO_KAN) || this;
|
|
304
319
|
}
|
|
320
|
+
BlockShoKan.prototype.toString = function () {
|
|
321
|
+
return toStringForSame(this.tiles);
|
|
322
|
+
};
|
|
305
323
|
return BlockShoKan;
|
|
306
324
|
}(Block));
|
|
307
325
|
exports.BlockShoKan = BlockShoKan;
|
|
@@ -310,6 +328,9 @@ var BlockPair = (function (_super) {
|
|
|
310
328
|
function BlockPair(tile1, tile2) {
|
|
311
329
|
return _super.call(this, [tile1, tile2], _1.BLOCK.PAIR) || this;
|
|
312
330
|
}
|
|
331
|
+
BlockPair.prototype.toString = function () {
|
|
332
|
+
return toStringForSame(this.tiles);
|
|
333
|
+
};
|
|
313
334
|
return BlockPair;
|
|
314
335
|
}(Block));
|
|
315
336
|
exports.BlockPair = BlockPair;
|
|
@@ -318,6 +339,9 @@ var BlockThree = (function (_super) {
|
|
|
318
339
|
function BlockThree(tiles) {
|
|
319
340
|
return _super.call(this, tiles, _1.BLOCK.THREE) || this;
|
|
320
341
|
}
|
|
342
|
+
BlockThree.prototype.toString = function () {
|
|
343
|
+
return toStringForSame(this.tiles);
|
|
344
|
+
};
|
|
321
345
|
return BlockThree;
|
|
322
346
|
}(Block));
|
|
323
347
|
exports.BlockThree = BlockThree;
|
|
@@ -326,6 +350,9 @@ var BlockRun = (function (_super) {
|
|
|
326
350
|
function BlockRun(tiles) {
|
|
327
351
|
return _super.call(this, tiles, _1.BLOCK.RUN) || this;
|
|
328
352
|
}
|
|
353
|
+
BlockRun.prototype.toString = function () {
|
|
354
|
+
return toStringForSame(this.tiles);
|
|
355
|
+
};
|
|
329
356
|
return BlockRun;
|
|
330
357
|
}(Block));
|
|
331
358
|
exports.BlockRun = BlockRun;
|
|
@@ -334,6 +361,9 @@ var BlockIsolated = (function (_super) {
|
|
|
334
361
|
function BlockIsolated(tile) {
|
|
335
362
|
return _super.call(this, [tile], _1.BLOCK.ISOLATED) || this;
|
|
336
363
|
}
|
|
364
|
+
BlockIsolated.prototype.toString = function () {
|
|
365
|
+
return this.tiles[0].toString();
|
|
366
|
+
};
|
|
337
367
|
return BlockIsolated;
|
|
338
368
|
}(Block));
|
|
339
369
|
exports.BlockIsolated = BlockIsolated;
|
|
@@ -342,6 +372,9 @@ var BlockHand = (function (_super) {
|
|
|
342
372
|
function BlockHand(tiles) {
|
|
343
373
|
return _super.call(this, tiles, _1.BLOCK.HAND) || this;
|
|
344
374
|
}
|
|
375
|
+
BlockHand.prototype.toString = function () {
|
|
376
|
+
return toStringForHand(this.tiles);
|
|
377
|
+
};
|
|
345
378
|
return BlockHand;
|
|
346
379
|
}(Block));
|
|
347
380
|
exports.BlockHand = BlockHand;
|
|
@@ -350,6 +383,11 @@ var BlockOther = (function (_super) {
|
|
|
350
383
|
function BlockOther(tiles, type) {
|
|
351
384
|
return _super.call(this, tiles, type) || this;
|
|
352
385
|
}
|
|
386
|
+
BlockOther.prototype.toString = function () {
|
|
387
|
+
if (this.is(_1.BLOCK.IMAGE_DISCARD))
|
|
388
|
+
return this.tiles.join("");
|
|
389
|
+
return toStringForHand(this.tiles);
|
|
390
|
+
};
|
|
353
391
|
return BlockOther;
|
|
354
392
|
}(Block));
|
|
355
393
|
exports.BlockOther = BlockOther;
|
|
@@ -442,8 +480,8 @@ var Parser = (function () {
|
|
|
442
480
|
var res = [];
|
|
443
481
|
if (tiles.length == 0)
|
|
444
482
|
return res;
|
|
445
|
-
for (var _i = 0,
|
|
446
|
-
var t =
|
|
483
|
+
for (var _i = 0, tiles_2 = tiles; _i < tiles_2.length; _i++) {
|
|
484
|
+
var t = tiles_2[_i];
|
|
447
485
|
if (t == _1.INPUT_SEPARATOR) {
|
|
448
486
|
var type_1 = detectBlockType(cluster);
|
|
449
487
|
var b_1 = blockWrapper(cluster, type_1);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@konoui/mjimage",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.28",
|
|
4
4
|
"description": "Generates Mahjong tiles in SVG format.",
|
|
5
5
|
"author": "konoui",
|
|
6
6
|
"license": "MIT",
|
|
@@ -23,7 +23,8 @@
|
|
|
23
23
|
"svg-sprite": "svg-sprite -C svg-sprite.config.json -shape-transform-svgo svg-sprite.config.json static/svg/*.svg",
|
|
24
24
|
"tsc": "tsc --declaration --outDir ./dist/mjs",
|
|
25
25
|
"prepublishOnly": "rm -rf ./dist && npm run tsc && cp -rf ./static/svg ./dist/mjs/svg/",
|
|
26
|
-
"deploy": "./scripts/sync.sh personal"
|
|
26
|
+
"deploy": "./scripts/sync.sh personal",
|
|
27
|
+
"analyze": "parcel build --reporter @parcel/reporter-bundle-analyzer"
|
|
27
28
|
},
|
|
28
29
|
"types": "dist/mjs/index.d.ts",
|
|
29
30
|
"files": [
|