@konoui/mjimage 0.0.15 → 0.0.17

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.
@@ -17,7 +17,7 @@ export declare class Hand {
17
17
  private init;
18
18
  get hands(): Tile[];
19
19
  toString(): string;
20
- get called(): (BlockChi | BlockPon | BlockAnKan | BlockDaiKan | BlockShoKan)[];
20
+ get called(): (BlockAnKan | BlockChi | BlockPon | BlockDaiKan | BlockShoKan)[];
21
21
  get reached(): boolean;
22
22
  get drawn(): Tile | null;
23
23
  get menzen(): boolean;
@@ -1,4 +1,4 @@
1
- import { Tile } from "../core/parser";
1
+ import { Tile } from "../core";
2
2
  import { Hand } from "../calculator";
3
3
  export interface Candidate {
4
4
  tile: Tile;
@@ -5,8 +5,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
6
  exports.Efficiency = void 0;
7
7
  var assert_1 = __importDefault(require("assert"));
8
- var constants_1 = require("../core/constants");
9
- var parser_1 = require("../core/parser");
8
+ var core_1 = require("../core");
10
9
  var calculator_1 = require("../calculator");
11
10
  var Efficiency = (function () {
12
11
  function Efficiency() {
@@ -42,14 +41,14 @@ var Efficiency = (function () {
42
41
  var r = Number.POSITIVE_INFINITY;
43
42
  var candidates = [];
44
43
  var sc = new calculator_1.ShantenCalculator(hand);
45
- for (var _i = 0, _a = Object.values(constants_1.TYPE); _i < _a.length; _i++) {
44
+ for (var _i = 0, _a = Object.values(core_1.TYPE); _i < _a.length; _i++) {
46
45
  var t = _a[_i];
47
- if (t == constants_1.TYPE.BACK)
46
+ if (t == core_1.TYPE.BACK)
48
47
  continue;
49
48
  for (var n = 1; n < hand.getArrayLen(t); n++) {
50
49
  if (hand.get(t, n) >= 4)
51
50
  continue;
52
- var tile = new parser_1.Tile(t, n);
51
+ var tile = new core_1.Tile(t, n);
53
52
  var tiles = hand.inc([tile]);
54
53
  var s = sc.calc();
55
54
  hand.dec(tiles);
@@ -70,14 +69,14 @@ var Efficiency = (function () {
70
69
  var h = new calculator_1.Hand(input, true);
71
70
  Array(13 - h.hands.length)
72
71
  .fill(undefined)
73
- .map(function () { return h.inc([new parser_1.Tile(constants_1.TYPE.BACK, 0)]); });
72
+ .map(function () { return h.inc([new core_1.Tile(core_1.TYPE.BACK, 0)]); });
74
73
  return Efficiency.candidateTiles(h);
75
74
  };
76
75
  Efficiency.partialShanten = function (input) {
77
76
  var h = new calculator_1.Hand(input, true);
78
77
  Array(13 - h.hands.length)
79
78
  .fill(undefined)
80
- .map(function () { return h.inc([new parser_1.Tile(constants_1.TYPE.BACK, 0)]); });
79
+ .map(function () { return h.inc([new core_1.Tile(core_1.TYPE.BACK, 0)]); });
81
80
  var sc = new calculator_1.ShantenCalculator(h);
82
81
  return sc.calc();
83
82
  };
@@ -1,4 +1,4 @@
1
- import { Tile, Block } from "./parser";
1
+ import { Tile, Block } from "./";
2
2
  import { Svg, G, Image, Use } from "@svgdotjs/svg.js";
3
3
  export interface ImageHelperConfig {
4
4
  scale?: number;
@@ -31,9 +31,9 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
31
31
  Object.defineProperty(exports, "__esModule", { value: true });
32
32
  exports.optimizeSVG = exports.drawBlocks = exports.createHand = exports.ImageHelper = void 0;
33
33
  var assert_1 = __importDefault(require("assert"));
34
- var parser_1 = require("./parser");
34
+ var _1 = require("./");
35
35
  var svg_js_1 = require("@svgdotjs/svg.js");
36
- var constants_1 = require("./constants");
36
+ var _2 = require("./");
37
37
  var BaseHelper = (function () {
38
38
  function BaseHelper(props) {
39
39
  if (props === void 0) { props = {}; }
@@ -41,8 +41,8 @@ var BaseHelper = (function () {
41
41
  this.scale = (_a = props.scale) !== null && _a !== void 0 ? _a : 1;
42
42
  this.image_host_path = (_b = props.imageHostPath) !== null && _b !== void 0 ? _b : "";
43
43
  this.image_host_url = (_c = props.imageHostUrl) !== null && _c !== void 0 ? _c : "";
44
- this.tileWidth = constants_1.TILE_CONTEXT.WIDTH * this.scale;
45
- this.tileHeight = constants_1.TILE_CONTEXT.HEIGHT * this.scale;
44
+ this.tileWidth = _2.TILE_CONTEXT.WIDTH * this.scale;
45
+ this.tileHeight = _2.TILE_CONTEXT.HEIGHT * this.scale;
46
46
  this.svgSprite = (_d = props.svgSprite) !== null && _d !== void 0 ? _d : false;
47
47
  }
48
48
  BaseHelper.prototype.getDiffTileHeightWidth = function (t) {
@@ -54,7 +54,7 @@ var BaseHelper = (function () {
54
54
  if (this.svgSprite) {
55
55
  img = new svg_js_1.Use().use(BaseHelper.buildID(tile));
56
56
  }
57
- if (tile instanceof parser_1.Tile && tile.has(constants_1.OPERATOR.COLOR_GRAYSCALE)) {
57
+ if (tile instanceof _1.Tile && tile.has(_2.OPERATOR.COLOR_GRAYSCALE)) {
58
58
  img.css({ filter: "contrast(65%)" });
59
59
  }
60
60
  return img;
@@ -77,7 +77,7 @@ var BaseHelper = (function () {
77
77
  text
78
78
  .size(size.baseWidth, size.baseHeight)
79
79
  .font({
80
- family: constants_1.FONT_FAMILY,
80
+ family: _2.FONT_FAMILY,
81
81
  size: fontSize,
82
82
  })
83
83
  .dx(textX)
@@ -107,7 +107,7 @@ var BaseHelper = (function () {
107
107
  if (tile == 100 || tile == 1000) {
108
108
  return tile == 100 ? "stick100" : "stick1000";
109
109
  }
110
- var n = tile.t == constants_1.TYPE.BACK ? 0 : tile.n;
110
+ var n = tile.t == _2.TYPE.BACK ? 0 : tile.n;
111
111
  return "".concat(tile.t).concat(n);
112
112
  };
113
113
  BaseHelper.prototype.buildURL = function (tile) {
@@ -123,7 +123,7 @@ var ImageHelper = (function (_super) {
123
123
  __extends(ImageHelper, _super);
124
124
  function ImageHelper() {
125
125
  var _this = _super !== null && _super.apply(this, arguments) || this;
126
- _this.blockMargin = constants_1.TILE_CONTEXT.WIDTH * constants_1.TILE_CONTEXT.BLOCK_MARGIN_SCALE * _this.scale;
126
+ _this.blockMargin = _2.TILE_CONTEXT.WIDTH * _2.TILE_CONTEXT.BLOCK_MARGIN_SCALE * _this.scale;
127
127
  return _this;
128
128
  }
129
129
  ImageHelper.prototype.createBlockHandDiscard = function (block) {
@@ -132,10 +132,10 @@ var ImageHelper = (function (_super) {
132
132
  for (var _i = 0, _a = block.tiles; _i < _a.length; _i++) {
133
133
  var t = _a[_i];
134
134
  var size = t.imageSize(this.scale);
135
- var f = t.has(constants_1.OPERATOR.HORIZONTAL)
135
+ var f = t.has(_2.OPERATOR.HORIZONTAL)
136
136
  ? this.createRotate90Image.bind(this)
137
137
  : this.createImage.bind(this);
138
- var y = t.has(constants_1.OPERATOR.HORIZONTAL) ? this.getDiffTileHeightWidth(t) : 0;
138
+ var y = t.has(_2.OPERATOR.HORIZONTAL) ? this.getDiffTileHeightWidth(t) : 0;
139
139
  var img = f(t, pos, y);
140
140
  g.add(img);
141
141
  pos += size.width;
@@ -143,13 +143,13 @@ var ImageHelper = (function (_super) {
143
143
  return g;
144
144
  };
145
145
  ImageHelper.prototype.createBlockPonChiKan = function (block) {
146
- var idx = block.tiles.findIndex(function (d) { return d.has(constants_1.OPERATOR.HORIZONTAL); });
146
+ var idx = block.tiles.findIndex(function (d) { return d.has(_2.OPERATOR.HORIZONTAL); });
147
147
  var pos = 0;
148
148
  var g = new svg_js_1.G();
149
- if (block.type == constants_1.BLOCK.SHO_KAN) {
149
+ if (block.type == _2.BLOCK.SHO_KAN) {
150
150
  var lastIdx = idx;
151
151
  for (var i = 0; i < block.tiles.length; i++)
152
- if (block.tiles[i].has(constants_1.OPERATOR.HORIZONTAL))
152
+ if (block.tiles[i].has(_2.OPERATOR.HORIZONTAL))
153
153
  lastIdx = i;
154
154
  for (var i = 0; i < block.tiles.length; i++) {
155
155
  var size = block.tiles[i].imageSize(this.scale);
@@ -172,7 +172,7 @@ var ImageHelper = (function (_super) {
172
172
  }
173
173
  return g;
174
174
  }
175
- if (block.type == constants_1.BLOCK.CHI) {
175
+ if (block.type == _2.BLOCK.CHI) {
176
176
  var img = this.createRotate90Image(block.tiles[idx], pos, this.getDiffTileHeightWidth(block.tiles[idx]));
177
177
  pos += block.tiles[idx].imageSize(this.scale).width;
178
178
  g.add(img);
@@ -205,69 +205,69 @@ var getBlockCreators = function (h) {
205
205
  var _a;
206
206
  var scale = h.scale;
207
207
  var lookup = (_a = {},
208
- _a[constants_1.BLOCK.CHI] = function (block) {
208
+ _a[_2.BLOCK.CHI] = function (block) {
209
209
  var size = block.imageSize(scale);
210
210
  var g = h.createBlockPonChiKan(block);
211
211
  return __assign(__assign({}, size), { e: g });
212
212
  },
213
- _a[constants_1.BLOCK.PON] = function (block) {
213
+ _a[_2.BLOCK.PON] = function (block) {
214
214
  var size = block.imageSize(scale);
215
215
  var g = h.createBlockPonChiKan(block);
216
216
  return __assign(__assign({}, size), { e: g });
217
217
  },
218
- _a[constants_1.BLOCK.DAI_KAN] = function (block) {
218
+ _a[_2.BLOCK.DAI_KAN] = function (block) {
219
219
  var size = block.imageSize(scale);
220
220
  var g = h.createBlockPonChiKan(block);
221
221
  return __assign(__assign({}, size), { e: g });
222
222
  },
223
- _a[constants_1.BLOCK.SHO_KAN] = function (block) {
223
+ _a[_2.BLOCK.SHO_KAN] = function (block) {
224
224
  var size = block.imageSize(scale);
225
225
  var g = h.createBlockPonChiKan(block);
226
226
  return __assign(__assign({}, size), { e: g });
227
227
  },
228
- _a[constants_1.BLOCK.AN_KAN] = function (block) {
228
+ _a[_2.BLOCK.AN_KAN] = function (block) {
229
229
  var size = block.imageSize(scale);
230
230
  var zp = block.tiles.filter(function (v) {
231
- return v.t !== constants_1.TYPE.BACK;
231
+ return v.t !== _2.TYPE.BACK;
232
232
  });
233
233
  (0, assert_1.default)(zp != null && zp.length == 2);
234
- var g = h.createBlockHandDiscard(new parser_1.BlockAnKan([zp[0], zp[1], zp[0], zp[1]]));
234
+ var g = h.createBlockHandDiscard(new _1.BlockAnKan([zp[0], zp[1], zp[0], zp[1]]));
235
235
  return __assign(__assign({}, size), { e: g });
236
236
  },
237
- _a[constants_1.BLOCK.DORA] = function (block) {
237
+ _a[_2.BLOCK.DORA] = function (block) {
238
238
  var size = block.imageSize(scale);
239
239
  var g = new svg_js_1.G();
240
240
  var img = h.createTextImage(block.tiles[0], 0, 0, "(ドラ)");
241
241
  g.add(img);
242
242
  return __assign(__assign({}, size), { e: g });
243
243
  },
244
- _a[constants_1.BLOCK.TSUMO] = function (block) {
244
+ _a[_2.BLOCK.TSUMO] = function (block) {
245
245
  var size = block.imageSize(scale);
246
246
  var g = new svg_js_1.G();
247
247
  var img = h.createTextImage(block.tiles[0], 0, 0, "(ツモ)");
248
248
  g.add(img);
249
249
  return __assign(__assign({}, size), { e: g });
250
250
  },
251
- _a[constants_1.BLOCK.HAND] = function (block) {
251
+ _a[_2.BLOCK.HAND] = function (block) {
252
252
  var size = block.imageSize(scale);
253
253
  var g = h.createBlockHandDiscard(block);
254
254
  return __assign(__assign({}, size), { e: g });
255
255
  },
256
- _a[constants_1.BLOCK.DISCARD] = function (block) {
256
+ _a[_2.BLOCK.DISCARD] = function (block) {
257
257
  var size = block.imageSize(scale);
258
258
  var g = h.createBlockHandDiscard(block);
259
259
  return __assign(__assign({}, size), { e: g });
260
260
  },
261
- _a[constants_1.BLOCK.UNKNOWN] = function (block) {
261
+ _a[_2.BLOCK.UNKNOWN] = function (block) {
262
262
  throw new Error("found unknown block");
263
263
  },
264
- _a[constants_1.BLOCK.PAIR] = function (block) {
264
+ _a[_2.BLOCK.PAIR] = function (block) {
265
265
  throw new Error("unsupported");
266
266
  },
267
- _a[constants_1.BLOCK.SET] = function (block) {
267
+ _a[_2.BLOCK.SET] = function (block) {
268
268
  throw new Error("unsupported");
269
269
  },
270
- _a[constants_1.BLOCK.ISOLATED] = function (block) {
270
+ _a[_2.BLOCK.ISOLATED] = function (block) {
271
271
  throw new Error("unsupported");
272
272
  },
273
273
  _a);
@@ -321,13 +321,13 @@ var getValidIDs = function () {
321
321
  var values = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9];
322
322
  var ids = [];
323
323
  var _loop_1 = function (kind) {
324
- if (kind == constants_1.TYPE.BACK) {
325
- ids.push(BaseHelper.buildID(new parser_1.Tile(kind, 0)));
324
+ if (kind == _2.TYPE.BACK) {
325
+ ids.push(BaseHelper.buildID(new _1.Tile(kind, 0)));
326
326
  return "continue";
327
327
  }
328
- ids.push.apply(ids, values.map(function (v) { return BaseHelper.buildID(new parser_1.Tile(kind, v)); }).flat());
328
+ ids.push.apply(ids, values.map(function (v) { return BaseHelper.buildID(new _1.Tile(kind, v)); }).flat());
329
329
  };
330
- for (var _i = 0, _a = Object.values(constants_1.TYPE); _i < _a.length; _i++) {
330
+ for (var _i = 0, _a = Object.values(_2.TYPE); _i < _a.length; _i++) {
331
331
  var kind = _a[_i];
332
332
  _loop_1(kind);
333
333
  }
@@ -1,4 +1,4 @@
1
- import { BLOCK, OPERATOR, TYPE, INPUT_SEPARATOR } from "./constants";
1
+ 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];
@@ -32,7 +32,7 @@ export declare class Block {
32
32
  is(type: BLOCK): boolean;
33
33
  isCalled(): boolean;
34
34
  minTile(): Tile;
35
- clone(): Block | BlockChi | BlockPon | BlockAnKan | BlockDaiKan | BlockShoKan | BlockPair | BlockSet | BlockIsolated;
35
+ clone(): Block | BlockAnKan | BlockChi | BlockPon | BlockDaiKan | BlockShoKan | BlockPair | BlockSet | BlockIsolated;
36
36
  imageSize(scale: number): {
37
37
  width: number;
38
38
  height: number;
@@ -74,7 +74,7 @@ export declare class Parser {
74
74
  readonly input: string;
75
75
  readonly maxInputLength = 600;
76
76
  constructor(input: string);
77
- parse(): (Block | BlockChi | BlockPon | BlockAnKan | BlockDaiKan | BlockShoKan)[];
77
+ parse(): (Block | BlockAnKan | BlockChi | BlockPon | BlockDaiKan | BlockShoKan)[];
78
78
  tiles(): Tile[];
79
79
  tileSeparators(): (Tile | Separator)[];
80
80
  private makeBlocks;
@@ -29,7 +29,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
29
29
  Object.defineProperty(exports, "__esModule", { value: true });
30
30
  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.isType = exports.tileSortFunc = void 0;
31
31
  var lexer_1 = require("./lexer");
32
- var constants_1 = require("./constants");
32
+ var _1 = require("./");
33
33
  var assert_1 = __importDefault(require("assert"));
34
34
  var tileSortFunc = function (i, j) {
35
35
  var _a;
@@ -41,23 +41,23 @@ var tileSortFunc = function (i, j) {
41
41
  return i.n - j.n;
42
42
  }
43
43
  var lookup = (_a = {},
44
- _a[constants_1.TYPE.M] = 1,
45
- _a[constants_1.TYPE.P] = 2,
46
- _a[constants_1.TYPE.S] = 3,
47
- _a[constants_1.TYPE.Z] = 4,
48
- _a[constants_1.TYPE.BACK] = 5,
44
+ _a[_1.TYPE.M] = 1,
45
+ _a[_1.TYPE.P] = 2,
46
+ _a[_1.TYPE.S] = 3,
47
+ _a[_1.TYPE.Z] = 4,
48
+ _a[_1.TYPE.BACK] = 5,
49
49
  _a);
50
50
  return lookup[i.t] - lookup[j.t];
51
51
  };
52
52
  exports.tileSortFunc = tileSortFunc;
53
53
  function isType(v) {
54
- for (var _i = 0, _a = Object.values(constants_1.TYPE); _i < _a.length; _i++) {
54
+ for (var _i = 0, _a = Object.values(_1.TYPE); _i < _a.length; _i++) {
55
55
  var t = _a[_i];
56
56
  if (t == v) {
57
57
  return [t, true];
58
58
  }
59
59
  }
60
- return [constants_1.TYPE.BACK, false];
60
+ return [_1.TYPE.BACK, false];
61
61
  }
62
62
  exports.isType = isType;
63
63
  var Tile = (function () {
@@ -68,7 +68,7 @@ var Tile = (function () {
68
68
  this.ops = ops;
69
69
  }
70
70
  Tile.prototype.toString = function () {
71
- if (this.t === constants_1.TYPE.BACK)
71
+ if (this.t === _1.TYPE.BACK)
72
72
  return this.t;
73
73
  return "".concat(this.ops.join("")).concat(this.n).concat(this.t);
74
74
  };
@@ -88,7 +88,7 @@ var Tile = (function () {
88
88
  return this;
89
89
  };
90
90
  Tile.prototype.isNum = function () {
91
- return this.t == constants_1.TYPE.M || this.t == constants_1.TYPE.P || this.t == constants_1.TYPE.S;
91
+ return this.t == _1.TYPE.M || this.t == _1.TYPE.P || this.t == _1.TYPE.S;
92
92
  };
93
93
  Tile.prototype.equals = function (t, ignoreRed) {
94
94
  if (ignoreRed === void 0) { ignoreRed = false; }
@@ -98,13 +98,13 @@ var Tile = (function () {
98
98
  return this.t == t.t && ok;
99
99
  };
100
100
  Tile.prototype.imageSize = function (scale) {
101
- var h = parseFloat((constants_1.TILE_CONTEXT.HEIGHT * scale).toPrecision(5));
102
- var w = parseFloat((constants_1.TILE_CONTEXT.WIDTH * scale).toPrecision(5));
103
- var size = this.has(constants_1.OPERATOR.HORIZONTAL)
101
+ var h = parseFloat((_1.TILE_CONTEXT.HEIGHT * scale).toPrecision(5));
102
+ var w = parseFloat((_1.TILE_CONTEXT.WIDTH * scale).toPrecision(5));
103
+ var size = this.has(_1.OPERATOR.HORIZONTAL)
104
104
  ? { width: h, height: w, baseWidth: w, baseHeight: h }
105
105
  : { width: w, height: h, w: w, baseWidth: w, baseHeight: h };
106
- if (this.has(constants_1.OPERATOR.TSUMO) || this.has(constants_1.OPERATOR.DORA))
107
- size.width += w * constants_1.TILE_CONTEXT.TEXT_SCALE;
106
+ if (this.has(_1.OPERATOR.TSUMO) || this.has(_1.OPERATOR.DORA))
107
+ size.width += w * _1.TILE_CONTEXT.TEXT_SCALE;
108
108
  return size;
109
109
  };
110
110
  return Tile;
@@ -114,20 +114,20 @@ var Block = (function () {
114
114
  function Block(tiles, type) {
115
115
  this.tiles = tiles;
116
116
  this.type = type;
117
- if (type == constants_1.BLOCK.CHI) {
117
+ if (type == _1.BLOCK.CHI) {
118
118
  tiles.sort(function (a, b) {
119
- if (a.has(constants_1.OPERATOR.HORIZONTAL))
119
+ if (a.has(_1.OPERATOR.HORIZONTAL))
120
120
  return -1;
121
- if (b.has(constants_1.OPERATOR.HORIZONTAL))
121
+ if (b.has(_1.OPERATOR.HORIZONTAL))
122
122
  return 1;
123
123
  return (0, exports.tileSortFunc)(a, b);
124
124
  });
125
125
  return;
126
126
  }
127
- if (type == constants_1.BLOCK.SHO_KAN) {
127
+ if (type == _1.BLOCK.SHO_KAN) {
128
128
  return;
129
129
  }
130
- if (type != constants_1.BLOCK.DISCARD) {
130
+ if (type != _1.BLOCK.DISCARD) {
131
131
  tiles.sort(exports.tileSortFunc);
132
132
  }
133
133
  }
@@ -136,7 +136,7 @@ var Block = (function () {
136
136
  var sameType = this.tiles.every(function (v) { return v.t == _this.tiles[0].t; });
137
137
  var ret = "";
138
138
  if (sameType) {
139
- if (this.tiles[0].t == constants_1.TYPE.BACK)
139
+ if (this.tiles[0].t == _1.TYPE.BACK)
140
140
  return this.tiles.join("");
141
141
  for (var _i = 0, _a = this.tiles; _i < _a.length; _i++) {
142
142
  var v = _a[_i];
@@ -155,17 +155,17 @@ var Block = (function () {
155
155
  };
156
156
  Block.prototype.isCalled = function () {
157
157
  return [
158
- constants_1.BLOCK.PON.toString(),
159
- constants_1.BLOCK.CHI.toString(),
160
- constants_1.BLOCK.AN_KAN.toString(),
161
- constants_1.BLOCK.DAI_KAN.toString(),
162
- constants_1.BLOCK.SHO_KAN.toString(),
158
+ _1.BLOCK.PON.toString(),
159
+ _1.BLOCK.CHI.toString(),
160
+ _1.BLOCK.AN_KAN.toString(),
161
+ _1.BLOCK.DAI_KAN.toString(),
162
+ _1.BLOCK.SHO_KAN.toString(),
163
163
  ].includes(this.type.toString());
164
164
  };
165
165
  Block.prototype.minTile = function () {
166
- if (this.is(constants_1.BLOCK.CHI))
166
+ if (this.is(_1.BLOCK.CHI))
167
167
  return this.clone().tiles.sort(exports.tileSortFunc)[0];
168
- (0, assert_1.default)(!this.is(constants_1.BLOCK.HAND), "mintile() is called with ".concat(this.toString()));
168
+ (0, assert_1.default)(!this.is(_1.BLOCK.HAND), "mintile() is called with ".concat(this.toString()));
169
169
  return this.tiles[0];
170
170
  };
171
171
  Block.prototype.clone = function () {
@@ -175,7 +175,7 @@ var Block = (function () {
175
175
  Block.prototype.imageSize = function (scale) {
176
176
  var bh = this.tiles[0].imageSize(scale).baseHeight;
177
177
  var bw = this.tiles[0].imageSize(scale).baseWidth;
178
- if (this.is(constants_1.BLOCK.SHO_KAN))
178
+ if (this.is(_1.BLOCK.SHO_KAN))
179
179
  return { width: bw * 2 + bh, height: Math.max(bw * 2, bh) };
180
180
  var maxHeight = this.tiles.reduce(function (max, t) {
181
181
  var h = t.imageSize(scale).height;
@@ -192,7 +192,7 @@ exports.Block = Block;
192
192
  var BlockChi = (function (_super) {
193
193
  __extends(BlockChi, _super);
194
194
  function BlockChi(tiles) {
195
- return _super.call(this, tiles, constants_1.BLOCK.CHI) || this;
195
+ return _super.call(this, tiles, _1.BLOCK.CHI) || this;
196
196
  }
197
197
  return BlockChi;
198
198
  }(Block));
@@ -200,7 +200,7 @@ exports.BlockChi = BlockChi;
200
200
  var BlockPon = (function (_super) {
201
201
  __extends(BlockPon, _super);
202
202
  function BlockPon(tiles) {
203
- return _super.call(this, tiles, constants_1.BLOCK.PON) || this;
203
+ return _super.call(this, tiles, _1.BLOCK.PON) || this;
204
204
  }
205
205
  return BlockPon;
206
206
  }(Block));
@@ -208,13 +208,13 @@ exports.BlockPon = BlockPon;
208
208
  var BlockAnKan = (function (_super) {
209
209
  __extends(BlockAnKan, _super);
210
210
  function BlockAnKan(tiles) {
211
- return _super.call(this, tiles, constants_1.BLOCK.AN_KAN) || this;
211
+ return _super.call(this, tiles, _1.BLOCK.AN_KAN) || this;
212
212
  }
213
213
  BlockAnKan.prototype.toString = function () {
214
214
  var tiles = this.tiles.map(function (t) { return t.clone(); });
215
- if (!tiles.some(function (v) { return v.t == constants_1.TYPE.BACK; })) {
216
- tiles[0] = new Tile(constants_1.TYPE.BACK, 0);
217
- tiles[3] = new Tile(constants_1.TYPE.BACK, 0);
215
+ if (!tiles.some(function (v) { return v.t == _1.TYPE.BACK; })) {
216
+ tiles[0] = new Tile(_1.TYPE.BACK, 0);
217
+ tiles[3] = new Tile(_1.TYPE.BACK, 0);
218
218
  }
219
219
  return tiles.reduce(function (s, t) {
220
220
  return "".concat(s).concat(t.toString());
@@ -226,7 +226,7 @@ exports.BlockAnKan = BlockAnKan;
226
226
  var BlockDaiKan = (function (_super) {
227
227
  __extends(BlockDaiKan, _super);
228
228
  function BlockDaiKan(tiles) {
229
- return _super.call(this, tiles, constants_1.BLOCK.DAI_KAN) || this;
229
+ return _super.call(this, tiles, _1.BLOCK.DAI_KAN) || this;
230
230
  }
231
231
  return BlockDaiKan;
232
232
  }(Block));
@@ -234,7 +234,7 @@ exports.BlockDaiKan = BlockDaiKan;
234
234
  var BlockShoKan = (function (_super) {
235
235
  __extends(BlockShoKan, _super);
236
236
  function BlockShoKan(tiles) {
237
- return _super.call(this, tiles, constants_1.BLOCK.SHO_KAN) || this;
237
+ return _super.call(this, tiles, _1.BLOCK.SHO_KAN) || this;
238
238
  }
239
239
  return BlockShoKan;
240
240
  }(Block));
@@ -242,7 +242,7 @@ exports.BlockShoKan = BlockShoKan;
242
242
  var BlockPair = (function (_super) {
243
243
  __extends(BlockPair, _super);
244
244
  function BlockPair(tile1, tile2) {
245
- return _super.call(this, [tile1, tile2], constants_1.BLOCK.PAIR) || this;
245
+ return _super.call(this, [tile1, tile2], _1.BLOCK.PAIR) || this;
246
246
  }
247
247
  return BlockPair;
248
248
  }(Block));
@@ -250,7 +250,7 @@ exports.BlockPair = BlockPair;
250
250
  var BlockSet = (function (_super) {
251
251
  __extends(BlockSet, _super);
252
252
  function BlockSet(tiles) {
253
- return _super.call(this, tiles, constants_1.BLOCK.SET) || this;
253
+ return _super.call(this, tiles, _1.BLOCK.SET) || this;
254
254
  }
255
255
  return BlockSet;
256
256
  }(Block));
@@ -273,30 +273,30 @@ exports.BlockRun = BlockRun;
273
273
  var BlockIsolated = (function (_super) {
274
274
  __extends(BlockIsolated, _super);
275
275
  function BlockIsolated(tile) {
276
- return _super.call(this, [tile], constants_1.BLOCK.ISOLATED) || this;
276
+ return _super.call(this, [tile], _1.BLOCK.ISOLATED) || this;
277
277
  }
278
278
  return BlockIsolated;
279
279
  }(Block));
280
280
  exports.BlockIsolated = BlockIsolated;
281
281
  var blockWrapper = function (tiles, type) {
282
282
  switch (type) {
283
- case constants_1.BLOCK.CHI:
283
+ case _1.BLOCK.CHI:
284
284
  return new BlockChi([tiles[0], tiles[1], tiles[2]]);
285
- case constants_1.BLOCK.PON:
285
+ case _1.BLOCK.PON:
286
286
  return new BlockPon([tiles[0], tiles[1], tiles[2]]);
287
- case constants_1.BLOCK.AN_KAN:
287
+ case _1.BLOCK.AN_KAN:
288
288
  return new BlockAnKan(tiles);
289
- case constants_1.BLOCK.DAI_KAN:
289
+ case _1.BLOCK.DAI_KAN:
290
290
  return new BlockDaiKan(tiles);
291
- case constants_1.BLOCK.SHO_KAN:
291
+ case _1.BLOCK.SHO_KAN:
292
292
  return new BlockShoKan(tiles);
293
- case constants_1.BLOCK.SET:
293
+ case _1.BLOCK.SET:
294
294
  if (tiles[0].equals(tiles[1], true))
295
295
  return new BlockThree(tiles);
296
296
  return new BlockRun(tiles);
297
- case constants_1.BLOCK.PAIR:
297
+ case _1.BLOCK.PAIR:
298
298
  return new BlockPair(tiles[0], tiles[1]);
299
- case constants_1.BLOCK.ISOLATED:
299
+ case _1.BLOCK.ISOLATED:
300
300
  return new BlockIsolated(tiles[0]);
301
301
  default:
302
302
  return new Block(tiles, type);
@@ -314,7 +314,7 @@ var Parser = (function () {
314
314
  return this.makeBlocks(parsed);
315
315
  };
316
316
  Parser.prototype.tiles = function () {
317
- return this.tileSeparators().filter(function (v) { return v != constants_1.INPUT_SEPARATOR; });
317
+ return this.tileSeparators().filter(function (v) { return v != _1.INPUT_SEPARATOR; });
318
318
  };
319
319
  Parser.prototype.tileSeparators = function () {
320
320
  var l = new lexer_1.Lexer(this.input);
@@ -326,14 +326,14 @@ var Parser = (function () {
326
326
  var char = l.char;
327
327
  if (char === l.eof)
328
328
  break;
329
- if (char == constants_1.INPUT_SEPARATOR) {
330
- res.push(constants_1.INPUT_SEPARATOR);
329
+ if (char == _1.INPUT_SEPARATOR) {
330
+ res.push(_1.INPUT_SEPARATOR);
331
331
  l.readChar();
332
332
  continue;
333
333
  }
334
334
  var _a = isTypeAlias(char, cluster), type = _a[0], isType_1 = _a[1];
335
335
  if (isType_1) {
336
- if (type == constants_1.TYPE.BACK) {
336
+ if (type == _1.TYPE.BACK) {
337
337
  res.push(new Tile(type, 0));
338
338
  l.readChar();
339
339
  continue;
@@ -353,7 +353,7 @@ var Parser = (function () {
353
353
  var _c = isNumber(char), n = _c[0], isNum = _c[1];
354
354
  if (!isNum)
355
355
  throw new Error("encounter unexpected number. n: ".concat(n, ", current: ").concat(char, ", input: ").concat(l.input));
356
- cluster.push(new Tile(constants_1.TYPE.BACK, n));
356
+ cluster.push(new Tile(_1.TYPE.BACK, n));
357
357
  }
358
358
  l.readChar();
359
359
  }
@@ -368,7 +368,7 @@ var Parser = (function () {
368
368
  return res;
369
369
  for (var _i = 0, tiles_1 = tiles; _i < tiles_1.length; _i++) {
370
370
  var t = tiles_1[_i];
371
- if (t == constants_1.INPUT_SEPARATOR) {
371
+ if (t == _1.INPUT_SEPARATOR) {
372
372
  var type_1 = detectBlockType(cluster);
373
373
  var b_1 = (0, exports.blockWrapper)(cluster, type_1);
374
374
  res.push(b_1);
@@ -389,7 +389,7 @@ var Parser = (function () {
389
389
  if (input.length > this.maxInputLength)
390
390
  throw new Error("exceeded maximum input length(".concat(input.length, ")"));
391
391
  var lastChar = input.charAt(input.length - 1);
392
- var _a = isTypeAlias(lastChar, [new Tile(constants_1.TYPE.BACK, 1)]), _ = _a[0], isKind = _a[1];
392
+ var _a = isTypeAlias(lastChar, [new Tile(_1.TYPE.BACK, 1)]), _ = _a[0], isKind = _a[1];
393
393
  if (!isKind)
394
394
  throw new Error("last character(".concat(lastChar, ") is not type value"));
395
395
  };
@@ -398,42 +398,42 @@ var Parser = (function () {
398
398
  exports.Parser = Parser;
399
399
  function detectBlockType(tiles) {
400
400
  if (tiles.length === 0)
401
- return constants_1.BLOCK.UNKNOWN;
401
+ return _1.BLOCK.UNKNOWN;
402
402
  if (tiles.length === 1) {
403
- if (tiles[0].has(constants_1.OPERATOR.DORA))
404
- return constants_1.BLOCK.DORA;
405
- if (tiles[0].has(constants_1.OPERATOR.TSUMO))
406
- return constants_1.BLOCK.TSUMO;
407
- return constants_1.BLOCK.HAND;
403
+ if (tiles[0].has(_1.OPERATOR.DORA))
404
+ return _1.BLOCK.DORA;
405
+ if (tiles[0].has(_1.OPERATOR.TSUMO))
406
+ return _1.BLOCK.TSUMO;
407
+ return _1.BLOCK.HAND;
408
408
  }
409
409
  var sameAll = tiles.every(function (v) { return v.equals(tiles[0], true); });
410
410
  var numOfHorizontals = tiles.filter(function (v) {
411
- return v.has(constants_1.OPERATOR.HORIZONTAL);
411
+ return v.has(_1.OPERATOR.HORIZONTAL);
412
412
  }).length;
413
- var numOfTsumoDoraTiles = tiles.filter(function (v) { return v.has(constants_1.OPERATOR.TSUMO) || v.has(constants_1.OPERATOR.DORA); }).length;
414
- var numOfBackTiles = tiles.filter(function (v) { return v.t == constants_1.TYPE.BACK; }).length;
413
+ var numOfTsumoDoraTiles = tiles.filter(function (v) { return v.has(_1.OPERATOR.TSUMO) || v.has(_1.OPERATOR.DORA); }).length;
414
+ var numOfBackTiles = tiles.filter(function (v) { return v.t == _1.TYPE.BACK; }).length;
415
415
  if (numOfTsumoDoraTiles > 0)
416
- return constants_1.BLOCK.UNKNOWN;
416
+ return _1.BLOCK.UNKNOWN;
417
417
  if (numOfHorizontals == 0 && numOfBackTiles == 0)
418
- return constants_1.BLOCK.HAND;
418
+ return _1.BLOCK.HAND;
419
419
  if (tiles.length === 3 && numOfBackTiles === 0) {
420
420
  if (sameAll)
421
- return constants_1.BLOCK.PON;
421
+ return _1.BLOCK.PON;
422
422
  if (numOfHorizontals == 1 && areConsecutiveTiles(tiles))
423
- return constants_1.BLOCK.CHI;
424
- return constants_1.BLOCK.DISCARD;
423
+ return _1.BLOCK.CHI;
424
+ return _1.BLOCK.DISCARD;
425
425
  }
426
426
  if (tiles.length == 4 && numOfBackTiles == 2)
427
- return constants_1.BLOCK.AN_KAN;
427
+ return _1.BLOCK.AN_KAN;
428
428
  if (tiles.length == 4 && sameAll) {
429
429
  if (numOfHorizontals == 1)
430
- return constants_1.BLOCK.DAI_KAN;
430
+ return _1.BLOCK.DAI_KAN;
431
431
  if (numOfHorizontals == 2)
432
- return constants_1.BLOCK.SHO_KAN;
432
+ return _1.BLOCK.SHO_KAN;
433
433
  }
434
434
  if (numOfHorizontals == 1)
435
- return constants_1.BLOCK.DISCARD;
436
- return constants_1.BLOCK.UNKNOWN;
435
+ return _1.BLOCK.DISCARD;
436
+ return _1.BLOCK.UNKNOWN;
437
437
  }
438
438
  function areConsecutiveTiles(tiles) {
439
439
  tiles = tiles.map(function (t) { return t.clone(); }).sort(exports.tileSortFunc);
@@ -466,18 +466,18 @@ function isTypeAlias(s, cluster) {
466
466
  if (s === "d")
467
467
  cluster[i].n += 4;
468
468
  }
469
- return [constants_1.TYPE.Z, true];
469
+ return [_1.TYPE.Z, true];
470
470
  }
471
- return [constants_1.TYPE.BACK, false];
471
+ return [_1.TYPE.BACK, false];
472
472
  }
473
473
  function isNumber(v) {
474
474
  var valid = ["0", "1", "2", "3", "4", "5", "6", "7", "8", "9"];
475
475
  return [Number(v), valid.includes(v)];
476
476
  }
477
477
  function isOperator(l) {
478
- var ops = Object.values(constants_1.OPERATOR);
478
+ var ops = Object.values(_1.OPERATOR);
479
479
  if (!ops.includes(l.char))
480
- return [new Tile(constants_1.TYPE.BACK, 0), false];
480
+ return [new Tile(_1.TYPE.BACK, 0), false];
481
481
  var found = [];
482
482
  for (var i = 0; i < 4; i++) {
483
483
  var c = l.peekCharN(i);
@@ -489,8 +489,8 @@ function isOperator(l) {
489
489
  break;
490
490
  for (var i_1 = 0; i_1 < found.length; i_1++)
491
491
  l.readChar();
492
- return [new Tile(constants_1.TYPE.BACK, n, found), true];
492
+ return [new Tile(_1.TYPE.BACK, n, found), true];
493
493
  }
494
494
  }
495
- return [new Tile(constants_1.TYPE.BACK, 0), false];
495
+ return [new Tile(_1.TYPE.BACK, 0), false];
496
496
  }
@@ -1,7 +1,7 @@
1
1
  import { ImageHelper, ImageHelperConfig } from "../core/image";
2
2
  import { Svg, G } from "@svgdotjs/svg.js";
3
3
  import { FontContext } from "../measure-text/";
4
- import { ScoreBoardInput, DiscardsInput, HandsInput } from "./table-parser";
4
+ import { ScoreBoardInput, DiscardsInput, HandsInput } from "./";
5
5
  export declare const createTable: (helper: ImageHelper, fontCtx: FontContext, handsProps: HandsInput, discardsProps: DiscardsInput, scoreBoardProps: ScoreBoardInput) => {
6
6
  e: G;
7
7
  width: number;
@@ -1,11 +1,10 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.drawTable = exports.createTable = void 0;
4
- var parser_1 = require("../core/parser");
4
+ var core_1 = require("../core/");
5
5
  var image_1 = require("../core/image");
6
6
  var svg_js_1 = require("@svgdotjs/svg.js");
7
- var table_parser_1 = require("./table-parser");
8
- var constants_1 = require("../core/constants");
7
+ var _1 = require("./");
9
8
  var splitTiles = function (input) {
10
9
  var chunkSize = 6;
11
10
  var result = [];
@@ -46,7 +45,7 @@ var handleDiscard = function (tiles, helper) {
46
45
  var tiles_1 = chunks[i];
47
46
  var posY = i * helper.tileHeight;
48
47
  var e = helper
49
- .createBlockHandDiscard(new parser_1.Block(tiles_1, constants_1.BLOCK.DISCARD))
48
+ .createBlockHandDiscard(new core_1.Block(tiles_1, core_1.BLOCK.DISCARD))
50
49
  .translate(0, posY);
51
50
  g.add(e);
52
51
  }
@@ -239,7 +238,7 @@ var drawTable = function (svg, tableInput, config, fontCtx, params) {
239
238
  if (params === void 0) { params = { responsive: false }; }
240
239
  var helper = new image_1.ImageHelper(config);
241
240
  var ctx = fontCtx;
242
- var _a = (0, table_parser_1.parse)(tableInput), discards = _a.discards, hands = _a.hands, scoreBoard = _a.scoreBoard;
241
+ var _a = (0, _1.parse)(tableInput), discards = _a.discards, hands = _a.hands, scoreBoard = _a.scoreBoard;
243
242
  var table = (0, exports.createTable)(helper, ctx, hands, discards, scoreBoard);
244
243
  if (!params.responsive)
245
244
  svg.size(table.width, table.height);
package/package.json CHANGED
@@ -1,10 +1,11 @@
1
1
  {
2
2
  "name": "@konoui/mjimage",
3
- "version": "0.0.15",
3
+ "version": "0.0.17",
4
4
  "description": "Generates Mahjong tiles in SVG format.",
5
5
  "author": "konoui",
6
6
  "license": "MIT",
7
7
  "repository": "github.com/konoui/mjimage",
8
+ "sideEffects": false,
8
9
  "keywords": [
9
10
  "mahjong"
10
11
  ],
@@ -30,9 +31,9 @@
30
31
  ],
31
32
  "exports": {
32
33
  ".": "./dist/mjs/index.js",
33
- "./core": "./dist/mjs/core/index.js",
34
- "./table": "./dist/mjs/table/index.js",
35
- "./calculator": "./dist/mjs/calculator/index.js"
34
+ "./core": "./dist/mjs/lib/core/index.js",
35
+ "./table": "./dist/mjs/lib/table/index.js",
36
+ "./calculator": "./dist/mjs/lib/calculator/index.js"
36
37
  },
37
38
  "targets": {
38
39
  "global": {
@@ -54,6 +55,7 @@
54
55
  "staticOutPath": "svg"
55
56
  },
56
57
  "devDependencies": {
58
+ "@parcel/reporter-bundle-analyzer": "^2.12.0",
57
59
  "@parcel/transformer-inline-string": "^2.9.3",
58
60
  "@parcel/transformer-typescript-tsc": "^2.9.3",
59
61
  "@parcel/validator-typescript": "^2.9.3",