@konoui/mjimage 0.0.19 → 0.0.20

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.
@@ -8,12 +8,8 @@ var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
8
8
  }
9
9
  return to.concat(ar || Array.prototype.slice.call(from));
10
10
  };
11
- var __importDefault = (this && this.__importDefault) || function (mod) {
12
- return (mod && mod.__esModule) ? mod : { "default": mod };
13
- };
14
11
  Object.defineProperty(exports, "__esModule", { value: true });
15
12
  exports.DoubleCalculator = exports.BlockCalculator = exports.ShantenCalculator = exports.Hand = void 0;
16
- var assert_1 = __importDefault(require("assert"));
17
13
  var constants_1 = require("../core/constants");
18
14
  var parser_1 = require("../core/parser");
19
15
  var Hand = (function () {
@@ -79,10 +75,12 @@ var Hand = (function () {
79
75
  }
80
76
  if (this.drawn != null) {
81
77
  var idx = tiles.findIndex(function (t) { return t.equals(t); });
82
- (0, assert_1.default)(idx >= 0, "hand has drawn: ".concat(this.drawn, " but no tile in hands"));
78
+ if (idx < 0)
79
+ throw new Error("[debug] hand has drawn: ".concat(this.drawn, " but no tile in hands"));
83
80
  tiles[idx].add(constants_1.OPERATOR.TSUMO);
84
81
  }
85
- (0, assert_1.default)(tiles.length > 0, "no tiles in hand ".concat(tiles.length, ", called: ").concat(this.called, ", data: ").concat(JSON.stringify(this.data, null, 2)));
82
+ if (tiles.length < 1)
83
+ throw new Error("[debug] no tiles in hand ".concat(tiles.length, ", called: ").concat(this.called, ", data: ").concat(JSON.stringify(this.data, null, 2)));
86
84
  return tiles;
87
85
  },
88
86
  enumerable: false,
@@ -1,5 +1,5 @@
1
1
  import { Tile } from "../core";
2
- import { Hand } from "../calculator";
2
+ import { Hand } from "./calc";
3
3
  export interface Candidate {
4
4
  tile: Tile;
5
5
  candidates: Tile[];
@@ -1,17 +1,14 @@
1
1
  "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
2
  Object.defineProperty(exports, "__esModule", { value: true });
6
3
  exports.Efficiency = void 0;
7
- var assert_1 = __importDefault(require("assert"));
8
4
  var core_1 = require("../core");
9
- var calculator_1 = require("../calculator");
5
+ var calc_1 = require("./calc");
10
6
  var Efficiency = (function () {
11
7
  function Efficiency() {
12
8
  }
13
9
  Efficiency.calcCandidates = function (hand, choices) {
14
- (0, assert_1.default)(choices.length > 0, "choices to discard is zero");
10
+ if (choices.length == 0)
11
+ throw new Error("[debug] choices to discard is zero");
15
12
  var ret = [];
16
13
  for (var _i = 0, choices_1 = choices; _i < choices_1.length; _i++) {
17
14
  var t = choices_1[_i];
@@ -40,7 +37,7 @@ var Efficiency = (function () {
40
37
  Efficiency.candidateTiles = function (hand) {
41
38
  var r = Number.POSITIVE_INFINITY;
42
39
  var candidates = [];
43
- var sc = new calculator_1.ShantenCalculator(hand);
40
+ var sc = new calc_1.ShantenCalculator(hand);
44
41
  for (var _i = 0, _a = Object.values(core_1.TYPE); _i < _a.length; _i++) {
45
42
  var t = _a[_i];
46
43
  if (t == core_1.TYPE.BACK)
@@ -66,18 +63,18 @@ var Efficiency = (function () {
66
63
  };
67
64
  };
68
65
  Efficiency.partialCandidateTiles = function (input) {
69
- var h = new calculator_1.Hand(input, true);
66
+ var h = new calc_1.Hand(input, true);
70
67
  Array(13 - h.hands.length)
71
68
  .fill(undefined)
72
69
  .map(function () { return h.inc([new core_1.Tile(core_1.TYPE.BACK, 0)]); });
73
70
  return Efficiency.candidateTiles(h);
74
71
  };
75
72
  Efficiency.partialShanten = function (input) {
76
- var h = new calculator_1.Hand(input, true);
73
+ var h = new calc_1.Hand(input, true);
77
74
  Array(13 - h.hands.length)
78
75
  .fill(undefined)
79
76
  .map(function () { return h.inc([new core_1.Tile(core_1.TYPE.BACK, 0)]); });
80
- var sc = new calculator_1.ShantenCalculator(h);
77
+ var sc = new calc_1.ShantenCalculator(h);
81
78
  return sc.calc();
82
79
  };
83
80
  return Efficiency;
@@ -25,12 +25,8 @@ var __assign = (this && this.__assign) || function () {
25
25
  };
26
26
  return __assign.apply(this, arguments);
27
27
  };
28
- var __importDefault = (this && this.__importDefault) || function (mod) {
29
- return (mod && mod.__esModule) ? mod : { "default": mod };
30
- };
31
28
  Object.defineProperty(exports, "__esModule", { value: true });
32
29
  exports.optimizeSVG = exports.drawBlocks = exports.createHand = exports.ImageHelper = void 0;
33
- var assert_1 = __importDefault(require("assert"));
34
30
  var core_1 = require("../core");
35
31
  var svg_js_1 = require("@svgdotjs/svg.js");
36
32
  var core_2 = require("../core");
@@ -230,7 +226,8 @@ var getBlockCreators = function (h) {
230
226
  var zp = block.tiles.filter(function (v) {
231
227
  return v.t !== core_2.TYPE.BACK;
232
228
  });
233
- (0, assert_1.default)(zp != null && zp.length == 2);
229
+ if (!(zp != null && zp.length == 2))
230
+ throw new Error("[debug] back tile must be two but ".concat(block));
234
231
  var g = h.createBlockHandDiscard(new core_1.BlockAnKan([zp[0], zp[1], zp[0], zp[1]]));
235
232
  return __assign(__assign({}, size), { e: g });
236
233
  },
@@ -1,10 +1,6 @@
1
1
  "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
2
  Object.defineProperty(exports, "__esModule", { value: true });
6
3
  exports.MeasureText = void 0;
7
- var assert_1 = __importDefault(require("assert"));
8
4
  var constants_1 = require("../core/constants");
9
5
  var MeasureText = (function () {
10
6
  function MeasureText(strText, numText) {
@@ -15,7 +11,8 @@ var MeasureText = (function () {
15
11
  this.measure = function (str, fontStr) {
16
12
  if (_this.ctx == null) {
17
13
  _this.ctx = document.createElement("canvas").getContext("2d");
18
- (0, assert_1.default)(_this.ctx != null);
14
+ if (_this.ctx == null)
15
+ throw new Error("[debug] context is null");
19
16
  }
20
17
  var ctx = _this.ctx;
21
18
  ctx.font = fontStr;
package/package.json CHANGED
@@ -1,11 +1,13 @@
1
1
  {
2
2
  "name": "@konoui/mjimage",
3
- "version": "0.0.19",
3
+ "version": "0.0.20",
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
+ "sideEffects": [
9
+ "./src/global.ts"
10
+ ],
9
11
  "keywords": [
10
12
  "mahjong"
11
13
  ],
@@ -63,9 +65,7 @@
63
65
  "@types/jest": "^29.5.5",
64
66
  "@types/js-yaml": "^4.0.9",
65
67
  "@types/svgdom": "^0.1.0",
66
- "assert": "^2.1.0",
67
68
  "buffer": "^6.0.3",
68
- "jest": "^29.7.0",
69
69
  "parcel": "^2.12.0",
70
70
  "parcel-reporter-static-files-copy": "^1.5.2",
71
71
  "process": "^0.11.10",