@konoui/mjimage 0.0.21 → 0.0.23

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.
@@ -63,9 +63,6 @@ var Player = (function (_super) {
63
63
  Player.prototype.handleEvent = function (e) {
64
64
  switch (e.type) {
65
65
  case "CHOICE_AFTER_DISCARDED":
66
- e.choices.CHI = false;
67
- e.choices.DAI_KAN = false;
68
- e.choices.PON = false;
69
66
  this.eventHandler.emit(e);
70
67
  break;
71
68
  case "CHOICE_AFTER_CALLED":
@@ -337,7 +337,7 @@ var createControllerMachine = function (c) {
337
337
  var context = _a.context, event = _a.event;
338
338
  var id = context.genEventID();
339
339
  var discarded = context.controller.river.lastTile;
340
- var ltile = discarded.t.clone().add(constants_1.OPERATOR.HORIZONTAL);
340
+ var ltile = discarded.t.clone({ add: constants_1.OPERATOR.HORIZONTAL });
341
341
  for (var _i = 0, _b = Object.values(constants_1.WIND); _i < _b.length; _i++) {
342
342
  var w = _b[_i];
343
343
  var e = {
@@ -388,10 +388,10 @@ var createControllerMachine = function (c) {
388
388
  if (event.type != "SHO_KAN" && event.type != "AN_KAN")
389
389
  throw new Error("unexpected event ".concat(event.type));
390
390
  var id = context.genEventID();
391
- var t = event.block.tiles[0].clone().remove(constants_1.OPERATOR.HORIZONTAL);
391
+ var t = event.block.tiles[0].clone({ remove: constants_1.OPERATOR.HORIZONTAL });
392
392
  for (var _i = 0, _b = Object.values(constants_1.WIND); _i < _b.length; _i++) {
393
393
  var w = _b[_i];
394
- var ron = context.controller.doWin(w, event.block.tiles[0].clone().remove(constants_1.OPERATOR.HORIZONTAL), {
394
+ var ron = context.controller.doWin(w, event.block.tiles[0].clone({ remove: constants_1.OPERATOR.HORIZONTAL }), {
395
395
  whoDiscarded: event.iam,
396
396
  quadWin: true,
397
397
  oneShot: context.oneShotMap[w],
@@ -533,7 +533,7 @@ var createControllerMachine = function (c) {
533
533
  throw new Error("unexpected event ".concat(event.type));
534
534
  var id = context.genEventID();
535
535
  var iam = event.iam;
536
- var t = event.tile.clone().add(constants_1.OPERATOR.HORIZONTAL);
536
+ var t = event.tile.clone({ add: constants_1.OPERATOR.HORIZONTAL });
537
537
  context.oneShotMap[iam] = true;
538
538
  for (var _i = 0, _b = Object.values(constants_1.WIND); _i < _b.length; _i++) {
539
539
  var w = _b[_i];
@@ -31,11 +31,12 @@ export declare const BLOCK: {
31
31
  readonly AN_KAN: "ankan";
32
32
  readonly DORA: "dora";
33
33
  readonly TSUMO: "tsumo";
34
+ readonly THREE: "three";
35
+ readonly RUN: "run";
34
36
  readonly HAND: "hand";
35
37
  readonly DISCARD: "simple-discard";
36
38
  readonly UNKNOWN: "unknown";
37
39
  readonly PAIR: "pair";
38
- readonly SET: "set";
39
40
  readonly ISOLATED: "isolated";
40
41
  };
41
42
  export declare const WIND: {
@@ -33,11 +33,12 @@ exports.BLOCK = {
33
33
  AN_KAN: "ankan",
34
34
  DORA: "dora",
35
35
  TSUMO: "tsumo",
36
+ THREE: "three",
37
+ RUN: "run",
36
38
  HAND: "hand",
37
39
  DISCARD: "simple-discard",
38
40
  UNKNOWN: "unknown",
39
41
  PAIR: "pair",
40
- SET: "set",
41
42
  ISOLATED: "isolated",
42
43
  };
43
44
  exports.WIND = {
@@ -2,18 +2,21 @@ import { BLOCK, OPERATOR, TYPE, INPUT_SEPARATOR } from "./";
2
2
  type Separator = typeof INPUT_SEPARATOR;
3
3
  export declare const tileSortFunc: (i: Tile, j: Tile) => number;
4
4
  export type Type = (typeof TYPE)[keyof typeof TYPE];
5
- export declare function isType(v: string): [Type, boolean];
6
5
  type Operator = (typeof OPERATOR)[keyof typeof OPERATOR];
7
6
  export declare class Tile {
8
- t: Type;
9
- n: number;
10
- ops: Operator[];
7
+ readonly t: Type;
8
+ readonly n: number;
9
+ readonly ops: Operator[];
11
10
  constructor(t: Type, n: number, ops?: Operator[]);
11
+ static from(s: string): Tile;
12
12
  toString(): string;
13
- clone(): Tile;
13
+ clone(override?: {
14
+ t?: Type;
15
+ n?: number;
16
+ remove?: Operator;
17
+ add?: Operator;
18
+ }): Tile;
14
19
  has(op: Operator): boolean;
15
- add(op: Operator): Tile;
16
- remove(op: Operator): Tile;
17
20
  isNum(): boolean;
18
21
  equals(t: Tile, ignoreRed?: boolean): boolean;
19
22
  imageSize(scale: number): {
@@ -23,58 +26,72 @@ export declare class Tile {
23
26
  baseHeight: number;
24
27
  };
25
28
  }
29
+ export declare function isNum5or0(t: Tile): boolean;
30
+ export declare function isNum5(t: Tile): boolean;
31
+ export declare function isNum0(t: Tile): boolean;
26
32
  type BLOCK = (typeof BLOCK)[keyof typeof BLOCK];
27
- export declare class Block {
28
- tiles: Tile[];
29
- type: BLOCK;
30
- constructor(tiles: Tile[], type: BLOCK);
33
+ export declare abstract class Block {
34
+ private readonly _tiles;
35
+ private readonly _type;
36
+ constructor(tiles: readonly Tile[], type: BLOCK);
37
+ static from(s: string): BlockHand | BlockOther | BlockChi | BlockPon | BlockAnKan | BlockDaiKan | BlockShoKan | BlockThree | BlockRun | BlockIsolated | BlockPair;
38
+ get type(): "unknown" | "pon" | "chi" | "shokan" | "daikan" | "ankan" | "dora" | "tsumo" | "three" | "run" | "hand" | "simple-discard" | "pair" | "isolated";
39
+ get tiles(): readonly Tile[];
31
40
  toString(): string;
32
41
  is(type: BLOCK): boolean;
33
42
  isCalled(): boolean;
34
- minTile(): Tile;
35
- clone(): Block | BlockChi | BlockPon | BlockAnKan | BlockDaiKan | BlockShoKan | BlockPair | BlockSet | BlockIsolated;
43
+ clone(override?: {
44
+ replace?: {
45
+ idx: number;
46
+ tile: Tile;
47
+ };
48
+ }): Block | BlockHand | BlockOther | BlockChi | BlockPon | BlockAnKan | BlockDaiKan | BlockShoKan | BlockThree | BlockRun | BlockIsolated | BlockPair;
36
49
  imageSize(scale: number): {
37
50
  width: number;
38
51
  height: number;
39
52
  };
40
53
  }
41
54
  export declare class BlockChi extends Block {
42
- constructor(tiles: [Tile, Tile, Tile]);
55
+ constructor(tiles: readonly [Tile, Tile, Tile]);
43
56
  }
44
57
  export declare class BlockPon extends Block {
45
- constructor(tiles: [Tile, Tile, Tile]);
58
+ constructor(tiles: readonly [Tile, Tile, Tile]);
46
59
  }
47
60
  export declare class BlockAnKan extends Block {
48
- constructor(tiles: Tile[]);
61
+ constructor(tiles: readonly Tile[]);
62
+ get tilesWithBack(): Tile[];
49
63
  toString(): string;
50
64
  }
51
65
  export declare class BlockDaiKan extends Block {
52
- constructor(tiles: Tile[]);
66
+ constructor(tiles: readonly Tile[]);
53
67
  }
54
68
  export declare class BlockShoKan extends Block {
55
- constructor(tiles: Tile[]);
69
+ constructor(tiles: readonly Tile[]);
56
70
  }
57
71
  export declare class BlockPair extends Block {
58
72
  constructor(tile1: Tile, tile2: Tile);
59
73
  }
60
- declare class BlockSet extends Block {
61
- constructor(tiles: [Tile, Tile, Tile]);
74
+ export declare class BlockThree extends Block {
75
+ constructor(tiles: readonly [Tile, Tile, Tile]);
62
76
  }
63
- export declare class BlockThree extends BlockSet {
64
- constructor(tiles: [Tile, Tile, Tile]);
65
- }
66
- export declare class BlockRun extends BlockSet {
67
- constructor(tiles: [Tile, Tile, Tile]);
77
+ export declare class BlockRun extends Block {
78
+ constructor(tiles: readonly [Tile, Tile, Tile]);
68
79
  }
69
80
  export declare class BlockIsolated extends Block {
70
81
  constructor(tile: Tile);
71
82
  }
72
- export declare const blockWrapper: (tiles: Tile[], type: BLOCK) => Block | BlockChi | BlockPon | BlockAnKan | BlockDaiKan | BlockShoKan | BlockPair | BlockSet | BlockIsolated;
83
+ export declare class BlockHand extends Block {
84
+ constructor(tiles: readonly Tile[]);
85
+ }
86
+ export declare class BlockOther extends Block {
87
+ constructor(tiles: readonly Tile[], type: BLOCK);
88
+ }
89
+ export declare const blockWrapper: (tiles: Tile[], type: BLOCK) => Block | BlockChi | BlockPon | BlockAnKan | BlockDaiKan | BlockShoKan | BlockPair | BlockRun | BlockThree | BlockHand | BlockIsolated | BlockOther;
73
90
  export declare class Parser {
74
91
  readonly input: string;
75
92
  readonly maxInputLength = 600;
76
93
  constructor(input: string);
77
- parse(): (Block | BlockChi | BlockPon | BlockAnKan | BlockDaiKan | BlockShoKan)[];
94
+ parse(): (BlockHand | BlockOther | BlockChi | BlockPon | BlockAnKan | BlockDaiKan | BlockShoKan | BlockThree | BlockRun | BlockIsolated | BlockPair)[];
78
95
  tiles(): Tile[];
79
96
  tileSeparators(): (Tile | Separator)[];
80
97
  private makeBlocks;
@@ -24,8 +24,10 @@ var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
24
24
  return to.concat(ar || Array.prototype.slice.call(from));
25
25
  };
26
26
  Object.defineProperty(exports, "__esModule", { value: true });
27
- exports.Parser = exports.blockWrapper = exports.BlockIsolated = exports.BlockRun = exports.BlockThree = exports.BlockPair = exports.BlockShoKan = exports.BlockDaiKan = exports.BlockAnKan = exports.BlockPon = exports.BlockChi = exports.Block = exports.Tile = exports.tileSortFunc = void 0;
28
- exports.isType = isType;
27
+ exports.Parser = exports.blockWrapper = exports.BlockOther = exports.BlockHand = exports.BlockIsolated = exports.BlockRun = exports.BlockThree = exports.BlockPair = exports.BlockShoKan = exports.BlockDaiKan = exports.BlockAnKan = exports.BlockPon = exports.BlockChi = exports.Block = exports.Tile = exports.tileSortFunc = void 0;
28
+ exports.isNum5or0 = isNum5or0;
29
+ exports.isNum5 = isNum5;
30
+ exports.isNum0 = isNum0;
29
31
  var lexer_1 = require("./lexer");
30
32
  var _1 = require("./");
31
33
  var tileSortFunc = function (i, j) {
@@ -63,26 +65,30 @@ var Tile = (function () {
63
65
  this.n = n;
64
66
  this.ops = ops;
65
67
  }
68
+ Tile.from = function (s) {
69
+ var tiles = new Parser(s).tiles();
70
+ if (tiles.length != 1)
71
+ throw new Error("input is not a single tile ".concat(s));
72
+ return tiles[0];
73
+ };
66
74
  Tile.prototype.toString = function () {
67
75
  if (this.t === _1.TYPE.BACK)
68
76
  return this.t;
69
77
  return "".concat(this.ops.join("")).concat(this.n).concat(this.t);
70
78
  };
71
- Tile.prototype.clone = function () {
72
- return new Tile(this.t, this.n, __spreadArray([], this.ops, true));
79
+ Tile.prototype.clone = function (override) {
80
+ var _a, _b;
81
+ var t = (_a = override === null || override === void 0 ? void 0 : override.t) !== null && _a !== void 0 ? _a : this.t;
82
+ var n = (_b = override === null || override === void 0 ? void 0 : override.n) !== null && _b !== void 0 ? _b : this.n;
83
+ var ops = this.ops.filter(function (v) { return (override === null || override === void 0 ? void 0 : override.remove) != v; });
84
+ var s = new Set(__spreadArray([], ops, true));
85
+ if (override === null || override === void 0 ? void 0 : override.add)
86
+ s.add(override.add);
87
+ return new Tile(t, n, Array.from(s));
73
88
  };
74
89
  Tile.prototype.has = function (op) {
75
90
  return this.ops.includes(op);
76
91
  };
77
- Tile.prototype.add = function (op) {
78
- this.ops.push(op);
79
- this.ops = Array.from(new Set(this.ops));
80
- return this;
81
- };
82
- Tile.prototype.remove = function (op) {
83
- this.ops = this.ops.filter(function (v) { return v != op; });
84
- return this;
85
- };
86
92
  Tile.prototype.isNum = function () {
87
93
  return this.t == _1.TYPE.M || this.t == _1.TYPE.P || this.t == _1.TYPE.S;
88
94
  };
@@ -90,7 +96,7 @@ var Tile = (function () {
90
96
  if (ignoreRed === void 0) { ignoreRed = false; }
91
97
  var ok = this.n == t.n;
92
98
  if (ignoreRed)
93
- ok || (ok = (this.n == 5 && t.n == 0) || (this.n == 0 && t.n == 5));
99
+ ok || (ok = isNum5or0(this) && isNum5or0(t));
94
100
  return this.t == t.t && ok;
95
101
  };
96
102
  Tile.prototype.imageSize = function (scale) {
@@ -106,12 +112,21 @@ var Tile = (function () {
106
112
  return Tile;
107
113
  }());
108
114
  exports.Tile = Tile;
115
+ function isNum5or0(t) {
116
+ return isNum0(t) || isNum5(t);
117
+ }
118
+ function isNum5(t) {
119
+ return t.isNum() && t.n == 5;
120
+ }
121
+ function isNum0(t) {
122
+ return t.isNum() && t.n == 0;
123
+ }
109
124
  var Block = (function () {
110
125
  function Block(tiles, type) {
111
- this.tiles = tiles;
112
- this.type = type;
113
- if (type == _1.BLOCK.CHI) {
114
- tiles.sort(function (a, b) {
126
+ this._tiles = tiles;
127
+ this._type = type;
128
+ if (this._type == _1.BLOCK.CHI) {
129
+ this._tiles = __spreadArray([], this._tiles, true).sort(function (a, b) {
115
130
  if (a.has(_1.OPERATOR.HORIZONTAL))
116
131
  return -1;
117
132
  if (b.has(_1.OPERATOR.HORIZONTAL))
@@ -120,13 +135,33 @@ var Block = (function () {
120
135
  });
121
136
  return;
122
137
  }
123
- if (type == _1.BLOCK.SHO_KAN) {
138
+ if (this._type == _1.BLOCK.SHO_KAN) {
124
139
  return;
125
140
  }
126
- if (type != _1.BLOCK.DISCARD) {
127
- tiles.sort(exports.tileSortFunc);
141
+ if (this._type != _1.BLOCK.DISCARD) {
142
+ this._tiles = __spreadArray([], this._tiles, true).sort(exports.tileSortFunc);
128
143
  }
129
144
  }
145
+ Block.from = function (s) {
146
+ var b = new Parser(s).parse();
147
+ if (b.length != 1)
148
+ throw new Error("input is not a single block ".concat(s));
149
+ return b[0];
150
+ };
151
+ Object.defineProperty(Block.prototype, "type", {
152
+ get: function () {
153
+ return this._type;
154
+ },
155
+ enumerable: false,
156
+ configurable: true
157
+ });
158
+ Object.defineProperty(Block.prototype, "tiles", {
159
+ get: function () {
160
+ return this._tiles;
161
+ },
162
+ enumerable: false,
163
+ configurable: true
164
+ });
130
165
  Block.prototype.toString = function () {
131
166
  var _this = this;
132
167
  var sameType = this.tiles.every(function (v) { return v.t == _this.tiles[0].t; });
@@ -147,27 +182,23 @@ var Block = (function () {
147
182
  return ret;
148
183
  };
149
184
  Block.prototype.is = function (type) {
150
- return this.type == type;
185
+ return this._type == type;
151
186
  };
152
187
  Block.prototype.isCalled = function () {
153
188
  return [
154
189
  _1.BLOCK.PON.toString(),
155
190
  _1.BLOCK.CHI.toString(),
156
- _1.BLOCK.AN_KAN.toString(),
157
191
  _1.BLOCK.DAI_KAN.toString(),
158
192
  _1.BLOCK.SHO_KAN.toString(),
159
- ].includes(this.type.toString());
160
- };
161
- Block.prototype.minTile = function () {
162
- if (this.is(_1.BLOCK.CHI))
163
- return this.clone().tiles.sort(exports.tileSortFunc)[0];
164
- if (this.is(_1.BLOCK.HAND))
165
- throw new Error("[debug] mintile() is called with ".concat(this.toString()));
166
- return this.tiles[0];
193
+ _1.BLOCK.AN_KAN.toString(),
194
+ ].includes(this._type.toString());
167
195
  };
168
- Block.prototype.clone = function () {
169
- var tiles = this.tiles.map(function (t) { return new Tile(t.t, t.n, __spreadArray([], t.ops, true)); });
170
- return (0, exports.blockWrapper)(tiles, this.type);
196
+ Block.prototype.clone = function (override) {
197
+ var rp = override === null || override === void 0 ? void 0 : override.replace;
198
+ var tiles = __spreadArray([], this.tiles, true);
199
+ if (rp)
200
+ tiles[rp.idx] = rp.tile;
201
+ return (0, exports.blockWrapper)(tiles, this._type);
171
202
  };
172
203
  Block.prototype.imageSize = function (scale) {
173
204
  var bh = this.tiles[0].imageSize(scale).baseHeight;
@@ -205,14 +236,39 @@ exports.BlockPon = BlockPon;
205
236
  var BlockAnKan = (function (_super) {
206
237
  __extends(BlockAnKan, _super);
207
238
  function BlockAnKan(tiles) {
208
- return _super.call(this, tiles, _1.BLOCK.AN_KAN) || this;
239
+ var _this = this;
240
+ var ftiles = tiles.filter(function (v) { return v.t != _1.TYPE.BACK; });
241
+ var sample = ftiles[0];
242
+ if (ftiles.length < tiles.length) {
243
+ if (isNum5or0(sample)) {
244
+ var t = new Tile(sample.t, 5);
245
+ _this = _super.call(this, [new Tile(sample.t, 0), t, t, t], _1.BLOCK.AN_KAN) || this;
246
+ return _this;
247
+ }
248
+ _this = _super.call(this, [sample, sample, sample, sample], _1.BLOCK.AN_KAN) || this;
249
+ return _this;
250
+ }
251
+ _this = _super.call(this, tiles, _1.BLOCK.AN_KAN) || this;
252
+ return _this;
209
253
  }
254
+ Object.defineProperty(BlockAnKan.prototype, "tilesWithBack", {
255
+ get: function () {
256
+ var sample = this.tiles[0];
257
+ if (isNum5or0(sample)) {
258
+ return [
259
+ new Tile(_1.TYPE.BACK, 0),
260
+ new Tile(sample.t, 0),
261
+ new Tile(sample.t, 5),
262
+ new Tile(_1.TYPE.BACK, 0),
263
+ ];
264
+ }
265
+ return [new Tile(_1.TYPE.BACK, 0), sample, sample, new Tile(_1.TYPE.BACK, 0)];
266
+ },
267
+ enumerable: false,
268
+ configurable: true
269
+ });
210
270
  BlockAnKan.prototype.toString = function () {
211
- var tiles = this.tiles.map(function (t) { return t.clone(); });
212
- if (!tiles.some(function (v) { return v.t == _1.TYPE.BACK; })) {
213
- tiles[0] = new Tile(_1.TYPE.BACK, 0);
214
- tiles[3] = new Tile(_1.TYPE.BACK, 0);
215
- }
271
+ var tiles = this.tilesWithBack;
216
272
  return tiles.reduce(function (s, t) {
217
273
  return "".concat(s).concat(t.toString());
218
274
  }, "");
@@ -244,28 +300,21 @@ var BlockPair = (function (_super) {
244
300
  return BlockPair;
245
301
  }(Block));
246
302
  exports.BlockPair = BlockPair;
247
- var BlockSet = (function (_super) {
248
- __extends(BlockSet, _super);
249
- function BlockSet(tiles) {
250
- return _super.call(this, tiles, _1.BLOCK.SET) || this;
251
- }
252
- return BlockSet;
253
- }(Block));
254
303
  var BlockThree = (function (_super) {
255
304
  __extends(BlockThree, _super);
256
305
  function BlockThree(tiles) {
257
- return _super.call(this, tiles) || this;
306
+ return _super.call(this, tiles, _1.BLOCK.THREE) || this;
258
307
  }
259
308
  return BlockThree;
260
- }(BlockSet));
309
+ }(Block));
261
310
  exports.BlockThree = BlockThree;
262
311
  var BlockRun = (function (_super) {
263
312
  __extends(BlockRun, _super);
264
313
  function BlockRun(tiles) {
265
- return _super.call(this, tiles) || this;
314
+ return _super.call(this, tiles, _1.BLOCK.RUN) || this;
266
315
  }
267
316
  return BlockRun;
268
- }(BlockSet));
317
+ }(Block));
269
318
  exports.BlockRun = BlockRun;
270
319
  var BlockIsolated = (function (_super) {
271
320
  __extends(BlockIsolated, _super);
@@ -275,6 +324,22 @@ var BlockIsolated = (function (_super) {
275
324
  return BlockIsolated;
276
325
  }(Block));
277
326
  exports.BlockIsolated = BlockIsolated;
327
+ var BlockHand = (function (_super) {
328
+ __extends(BlockHand, _super);
329
+ function BlockHand(tiles) {
330
+ return _super.call(this, tiles, _1.BLOCK.HAND) || this;
331
+ }
332
+ return BlockHand;
333
+ }(Block));
334
+ exports.BlockHand = BlockHand;
335
+ var BlockOther = (function (_super) {
336
+ __extends(BlockOther, _super);
337
+ function BlockOther(tiles, type) {
338
+ return _super.call(this, tiles, type) || this;
339
+ }
340
+ return BlockOther;
341
+ }(Block));
342
+ exports.BlockOther = BlockOther;
278
343
  var blockWrapper = function (tiles, type) {
279
344
  switch (type) {
280
345
  case _1.BLOCK.CHI:
@@ -287,16 +352,18 @@ var blockWrapper = function (tiles, type) {
287
352
  return new BlockDaiKan(tiles);
288
353
  case _1.BLOCK.SHO_KAN:
289
354
  return new BlockShoKan(tiles);
290
- case _1.BLOCK.SET:
291
- if (tiles[0].equals(tiles[1], true))
292
- return new BlockThree(tiles);
355
+ case _1.BLOCK.THREE:
356
+ return new BlockThree(tiles);
357
+ case _1.BLOCK.RUN:
293
358
  return new BlockRun(tiles);
294
359
  case _1.BLOCK.PAIR:
295
360
  return new BlockPair(tiles[0], tiles[1]);
296
361
  case _1.BLOCK.ISOLATED:
297
362
  return new BlockIsolated(tiles[0]);
363
+ case _1.BLOCK.HAND:
364
+ return new BlockHand(tiles);
298
365
  default:
299
- return new Block(tiles, type);
366
+ return new BlockOther(tiles, type);
300
367
  }
301
368
  };
302
369
  exports.blockWrapper = blockWrapper;
@@ -433,7 +500,7 @@ function detectBlockType(tiles) {
433
500
  return _1.BLOCK.UNKNOWN;
434
501
  }
435
502
  function areConsecutiveTiles(tiles) {
436
- tiles = tiles.map(function (t) { return t.clone(); }).sort(exports.tileSortFunc);
503
+ tiles = __spreadArray([], tiles, true).sort(exports.tileSortFunc);
437
504
  for (var i = 0; i < tiles.length - 1; i++) {
438
505
  var n = tiles[i].n, np = tiles[i + 1].n;
439
506
  var type = tiles[i].t, kp = tiles[i + 1].t;
@@ -460,8 +527,10 @@ function isTypeAlias(s, cluster) {
460
527
  var isAlias = s === "w" || s === "d";
461
528
  if (isAlias && cluster.length > 0) {
462
529
  for (var i = 0; i < cluster.length; i++) {
463
- if (s === "d")
464
- cluster[i].n += 4;
530
+ var t = cluster[i];
531
+ if (s === "d") {
532
+ cluster[i] = t.clone({ n: t.n + 4 });
533
+ }
465
534
  }
466
535
  return [_1.TYPE.Z, true];
467
536
  }
@@ -4,13 +4,15 @@ export interface ImageHelperConfig {
4
4
  scale?: number;
5
5
  imageHostPath?: string;
6
6
  imageHostUrl?: string;
7
+ imageExt?: "svg" | "webp";
7
8
  svgSprite?: boolean;
8
9
  }
9
10
  declare class BaseHelper {
10
11
  readonly tileWidth: number;
11
12
  readonly tileHeight: number;
12
- readonly image_host_path: string;
13
- readonly image_host_url: string;
13
+ readonly imageHostPath: string;
14
+ readonly imageHostUrl: string;
15
+ readonly imageExt: string;
14
16
  readonly scale: number;
15
17
  readonly svgSprite: boolean;
16
18
  constructor(props?: ImageHelperConfig);
@@ -33,13 +33,14 @@ var core_2 = require("../core");
33
33
  var BaseHelper = (function () {
34
34
  function BaseHelper(props) {
35
35
  if (props === void 0) { props = {}; }
36
- var _a, _b, _c, _d;
36
+ var _a, _b, _c, _d, _e;
37
37
  this.scale = (_a = props.scale) !== null && _a !== void 0 ? _a : 1;
38
- this.image_host_path = (_b = props.imageHostPath) !== null && _b !== void 0 ? _b : "";
39
- this.image_host_url = (_c = props.imageHostUrl) !== null && _c !== void 0 ? _c : "";
38
+ this.imageHostPath = (_b = props.imageHostPath) !== null && _b !== void 0 ? _b : "";
39
+ this.imageHostUrl = (_c = props.imageHostUrl) !== null && _c !== void 0 ? _c : "";
40
+ this.imageExt = (_d = props.imageExt) !== null && _d !== void 0 ? _d : "svg";
40
41
  this.tileWidth = core_2.TILE_CONTEXT.WIDTH * this.scale;
41
42
  this.tileHeight = core_2.TILE_CONTEXT.HEIGHT * this.scale;
42
- this.svgSprite = (_d = props.svgSprite) !== null && _d !== void 0 ? _d : false;
43
+ this.svgSprite = (_e = props.svgSprite) !== null && _e !== void 0 ? _e : false;
43
44
  }
44
45
  BaseHelper.prototype.getDiffTileHeightWidth = function (t) {
45
46
  var size = t.imageSize(this.scale);
@@ -107,11 +108,11 @@ var BaseHelper = (function () {
107
108
  return "".concat(tile.t).concat(n);
108
109
  };
109
110
  BaseHelper.prototype.buildURL = function (tile) {
110
- var filename = "".concat(BaseHelper.buildID(tile), ".svg");
111
- if (this.image_host_url != "") {
112
- return "".concat(this.image_host_url).concat(filename);
111
+ var filename = "".concat(BaseHelper.buildID(tile), ".").concat(this.imageExt);
112
+ if (this.imageHostUrl != "") {
113
+ return "".concat(this.imageHostUrl).concat(filename);
113
114
  }
114
- return "".concat(this.image_host_path).concat(filename);
115
+ return "".concat(this.imageHostPath).concat(filename);
115
116
  };
116
117
  return BaseHelper;
117
118
  }());
@@ -222,8 +223,10 @@ var getBlockCreators = function (h) {
222
223
  return __assign(__assign({}, size), { e: g });
223
224
  },
224
225
  _a[core_2.BLOCK.AN_KAN] = function (block) {
226
+ if (!(block instanceof core_1.BlockAnKan))
227
+ throw new Error("block type is not ankan: ".concat(block.type));
225
228
  var size = block.imageSize(scale);
226
- var zp = block.tiles.filter(function (v) {
229
+ var zp = block.tilesWithBack.filter(function (v) {
227
230
  return v.t !== core_2.TYPE.BACK;
228
231
  });
229
232
  if (!(zp != null && zp.length == 2))
@@ -255,15 +258,18 @@ var getBlockCreators = function (h) {
255
258
  var g = h.createBlockHandDiscard(block);
256
259
  return __assign(__assign({}, size), { e: g });
257
260
  },
261
+ _a[core_2.BLOCK.THREE] = function (block) {
262
+ throw new Error("found unknown block");
263
+ },
264
+ _a[core_2.BLOCK.RUN] = function (block) {
265
+ throw new Error("found unknown block");
266
+ },
258
267
  _a[core_2.BLOCK.UNKNOWN] = function (block) {
259
268
  throw new Error("found unknown block");
260
269
  },
261
270
  _a[core_2.BLOCK.PAIR] = function (block) {
262
271
  throw new Error("unsupported");
263
272
  },
264
- _a[core_2.BLOCK.SET] = function (block) {
265
- throw new Error("unsupported");
266
- },
267
273
  _a[core_2.BLOCK.ISOLATED] = function (block) {
268
274
  throw new Error("unsupported");
269
275
  },
@@ -278,10 +284,6 @@ var createHand = function (helper, blocks) {
278
284
  }, { maxHeight: 0, sumWidth: 0 }), maxHeight = _a.maxHeight, sumWidth = _a.sumWidth;
279
285
  var viewBoxHeight = maxHeight;
280
286
  var viewBoxWidth = sumWidth + (blocks.length - 1) * helper.blockMargin;
281
- var params = {
282
- viewBoxWidth: viewBoxWidth,
283
- viewBoxHeight: viewBoxHeight,
284
- };
285
287
  var creators = getBlockCreators(helper);
286
288
  var elms = [];
287
289
  for (var _i = 0, blocks_1 = blocks; _i < blocks_1.length; _i++) {
@@ -75,7 +75,7 @@ var convertInput = function (i) {
75
75
  frontPlace: constants_1.WIND_MAP[frontPlace],
76
76
  sticks: i.board.sticks,
77
77
  doras: i.board.doras.map(function (v) {
78
- return new parser_1.Parser(v).tiles()[0];
78
+ return parser_1.Tile.from(v);
79
79
  }),
80
80
  scores: {
81
81
  front: i[m.front].score,
@@ -45,7 +45,7 @@ var handleDiscard = function (tiles, helper) {
45
45
  var tiles_1 = chunks[i];
46
46
  var posY = i * helper.tileHeight;
47
47
  var e = helper
48
- .createBlockHandDiscard(new core_1.Block(tiles_1, core_1.BLOCK.DISCARD))
48
+ .createBlockHandDiscard(new core_1.BlockOther(tiles_1, core_1.BLOCK.DISCARD))
49
49
  .translate(0, posY);
50
50
  g.add(e);
51
51
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@konoui/mjimage",
3
- "version": "0.0.21",
3
+ "version": "0.0.23",
4
4
  "description": "Generates Mahjong tiles in SVG format.",
5
5
  "author": "konoui",
6
6
  "license": "MIT",
@@ -53,10 +53,16 @@
53
53
  "module": {}
54
54
  },
55
55
  "alias": {},
56
- "staticFiles": {
57
- "staticPath": "static/svg",
58
- "staticOutPath": "svg"
59
- },
56
+ "staticFiles": [
57
+ {
58
+ "staticPath": "static/svg",
59
+ "staticOutPath": "svg"
60
+ },
61
+ {
62
+ "staticPath": "static/webp",
63
+ "staticOutPath": "webp"
64
+ }
65
+ ],
60
66
  "devDependencies": {
61
67
  "@parcel/reporter-bundle-analyzer": "^2.12.0",
62
68
  "@parcel/transformer-inline-string": "^2.9.3",