@konoui/mjimage 0.0.30 → 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 (59) 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 -18
  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 -1399
  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 -900
  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 -197
  28. package/dist/mjs/lib/controller/player-efficiency.d.ts +0 -24
  29. package/dist/mjs/lib/controller/player-efficiency.js +0 -156
  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 -34
  34. package/dist/mjs/lib/controller/river.d.ts +0 -19
  35. package/dist/mjs/lib/controller/river.js +0 -55
  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/table/index.d.ts +0 -2
  55. package/dist/mjs/lib/table/index.js +0 -18
  56. package/dist/mjs/lib/table/table-parser.d.ts +0 -127
  57. package/dist/mjs/lib/table/table-parser.js +0 -105
  58. package/dist/mjs/lib/table/table.d.ts +0 -12
  59. package/dist/mjs/lib/table/table.js +0 -248
@@ -1,105 +0,0 @@
1
- "use strict";
2
- var __assign = (this && this.__assign) || function () {
3
- __assign = Object.assign || function(t) {
4
- for (var s, i = 1, n = arguments.length; i < n; i++) {
5
- s = arguments[i];
6
- for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
7
- t[p] = s[p];
8
- }
9
- return t;
10
- };
11
- return __assign.apply(this, arguments);
12
- };
13
- var _a;
14
- Object.defineProperty(exports, "__esModule", { value: true });
15
- exports.convertInput = exports.parseTableInput = exports.parse = void 0;
16
- var js_yaml_1 = require("js-yaml");
17
- var valibot_1 = require("valibot");
18
- var parser_1 = require("../core/parser");
19
- var constants_1 = require("../core/constants");
20
- var windInputSchema = (0, valibot_1.optional)((0, valibot_1.strictObject)({
21
- discard: (0, valibot_1.optional)((0, valibot_1.string)(), ""),
22
- hand: (0, valibot_1.optional)((0, valibot_1.string)(), ""),
23
- score: (0, valibot_1.optional)((0, valibot_1.number)(), 25000),
24
- }), { discard: "", hand: "", score: 25000 });
25
- var windInputsSchema = (0, valibot_1.strictObject)((_a = {},
26
- _a[constants_1.WIND.EAST] = windInputSchema,
27
- _a[constants_1.WIND.SOUTH] = windInputSchema,
28
- _a[constants_1.WIND.WEST] = windInputSchema,
29
- _a[constants_1.WIND.NORTH] = windInputSchema,
30
- _a));
31
- var boardInputSchema = (0, valibot_1.strictObject)({
32
- round: (0, valibot_1.optional)((0, valibot_1.picklist)(Object.keys(constants_1.ROUND_MAP)), "1w1"),
33
- sticks: (0, valibot_1.optional)((0, valibot_1.strictObject)({
34
- reach: (0, valibot_1.optional)((0, valibot_1.pipe)((0, valibot_1.number)(), (0, valibot_1.minValue)(0, ""), (0, valibot_1.maxValue)(9, "")), 0),
35
- dead: (0, valibot_1.optional)((0, valibot_1.pipe)((0, valibot_1.number)(), (0, valibot_1.minValue)(0, ""), (0, valibot_1.maxValue)(9, "")), 0),
36
- }), { reach: 0, dead: 0 }),
37
- doras: (0, valibot_1.optional)((0, valibot_1.array)((0, valibot_1.string)()), ["3w"]),
38
- front: (0, valibot_1.optional)((0, valibot_1.picklist)(Object.keys(constants_1.WIND_MAP)), "1w"),
39
- });
40
- var tableInputSchema = (0, valibot_1.strictObject)(__assign(__assign({}, windInputsSchema.entries), { board: boardInputSchema }));
41
- var parse = function (s) {
42
- var d = (0, exports.parseTableInput)(s);
43
- return (0, exports.convertInput)(d);
44
- };
45
- exports.parse = parse;
46
- var parseTableInput = function (s) {
47
- var rawInput = (0, js_yaml_1.load)(s);
48
- var ret = (0, valibot_1.safeParse)(tableInputSchema, rawInput.table);
49
- if (!ret.success) {
50
- throw ret.issues;
51
- }
52
- return ret.output;
53
- };
54
- exports.parseTableInput = parseTableInput;
55
- var convertInput = function (i) {
56
- var frontPlace = i.board.front;
57
- var m = createPlaceMap(frontPlace);
58
- var f = function (w) {
59
- return i[w].discard.replace(/\r?\n/g, "");
60
- };
61
- var discards = {
62
- front: new parser_1.Parser(f(m.front)).tiles(),
63
- right: new parser_1.Parser(f(m.right)).tiles(),
64
- opposite: new parser_1.Parser(f(m.opposite)).tiles(),
65
- left: new parser_1.Parser(f(m.left)).tiles(),
66
- };
67
- var hands = {
68
- front: new parser_1.Parser(i[m.front].hand).parse(),
69
- right: new parser_1.Parser(i[m.right].hand).parse(),
70
- opposite: new parser_1.Parser(i[m.opposite].hand).parse(),
71
- left: new parser_1.Parser(i[m.left].hand).parse(),
72
- };
73
- var scoreBoard = {
74
- round: constants_1.ROUND_MAP[i.board.round],
75
- frontPlace: constants_1.WIND_MAP[frontPlace],
76
- sticks: i.board.sticks,
77
- doras: i.board.doras.map(function (v) {
78
- return parser_1.Tile.from(v);
79
- }),
80
- scores: {
81
- front: i[m.front].score,
82
- right: i[m.right].score,
83
- opposite: i[m.opposite].score,
84
- left: i[m.left].score,
85
- },
86
- };
87
- return { discards: discards, hands: hands, scoreBoard: scoreBoard };
88
- };
89
- exports.convertInput = convertInput;
90
- var createPlaceMap = function (front) {
91
- var f = function (start, v) {
92
- var ret = "".concat(v, "w");
93
- if (v > 4)
94
- ret = "".concat(v - start, "w");
95
- return ret;
96
- };
97
- var start = Number(front[0]);
98
- var m = {
99
- front: front,
100
- right: f(start, start + 1),
101
- opposite: f(start, start + 2),
102
- left: f(start, start + 3),
103
- };
104
- return m;
105
- };
@@ -1,12 +0,0 @@
1
- import { ImageHelper, ImageHelperConfig } from "../image/image";
2
- import { Svg, G } from "@svgdotjs/svg.js";
3
- import { FontContext } from "../measure-text/";
4
- import { ScoreBoardInput, DiscardsInput, HandsInput } from "./";
5
- export declare const createTable: (helper: ImageHelper, fontCtx: FontContext, handsProps: HandsInput, discardsProps: DiscardsInput, scoreBoardProps: ScoreBoardInput) => {
6
- e: G;
7
- width: number;
8
- height: number;
9
- };
10
- export declare const drawTable: (svg: Svg, tableInput: string, config: ImageHelperConfig | undefined, fontCtx: FontContext, params?: {
11
- responsive: boolean;
12
- }) => void;
@@ -1,248 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.drawTable = exports.createTable = void 0;
4
- var core_1 = require("../core/");
5
- var image_1 = require("../image/image");
6
- var svg_js_1 = require("@svgdotjs/svg.js");
7
- var _1 = require("./");
8
- var splitTiles = function (input) {
9
- var chunkSize = 6;
10
- var result = [];
11
- for (var i = 0; i < input.length; i += chunkSize) {
12
- var chunk = input.slice(i, i + chunkSize);
13
- result.push(chunk);
14
- }
15
- return result;
16
- };
17
- var simpleRotate = function (e, width, height, degree, x, y) {
18
- if (x === void 0) { x = 0; }
19
- if (y === void 0) { y = 0; }
20
- var g = new svg_js_1.G().add(e);
21
- if (degree == 90) {
22
- var translatedX = x;
23
- var translatedY = y - height;
24
- g.rotate(degree, 0, height).translate(translatedX, translatedY);
25
- return g;
26
- }
27
- if (degree == 180) {
28
- var translatedX = x + width;
29
- var translatedY = y - height;
30
- g.rotate(degree, 0, height).translate(translatedX, translatedY);
31
- return g;
32
- }
33
- if (degree == 270) {
34
- var translatedX = x + height;
35
- var translatedY = y + (width - height);
36
- g.rotate(degree, 0, height).translate(translatedX, translatedY);
37
- return g;
38
- }
39
- return g;
40
- };
41
- var handleDiscard = function (tiles, helper) {
42
- var g = new svg_js_1.G();
43
- var chunks = splitTiles(tiles);
44
- for (var i = 0; i < chunks.length; i++) {
45
- var tiles_1 = chunks[i];
46
- var posY = i * helper.tileHeight;
47
- var e = helper
48
- .createBlockHandDiscard(new core_1.BlockOther(tiles_1, core_1.BLOCK.IMAGE_DISCARD))
49
- .translate(0, posY);
50
- g.add(e);
51
- }
52
- return {
53
- e: g,
54
- width: helper.tileWidth * 5 + helper.tileHeight * 1,
55
- height: helper.tileHeight * chunks.length,
56
- };
57
- };
58
- var createStickAndDora = function (helper, fontCtx, scoreBoard) {
59
- var font = fontCtx.font;
60
- var textWidth = fontCtx.textWidth;
61
- var textHeight = fontCtx.textHeight;
62
- var g = new svg_js_1.G();
63
- var num100 = scoreBoard.sticks.dead;
64
- var num1000 = scoreBoard.sticks.reach;
65
- var stickWidth = 125 * helper.scale;
66
- var stickHeight = 27.5 * helper.scale;
67
- var roundWidth = textWidth * 3;
68
- var roundHeight = textHeight;
69
- var roundX = (stickWidth + helper.tileWidth + textWidth - roundWidth) / 2;
70
- var roundText = new svg_js_1.Text()
71
- .plain(scoreBoard.round)
72
- .font(font)
73
- .move(roundX, 0);
74
- g.add(roundText);
75
- roundHeight += 25 * helper.scale;
76
- var stickGroupHeight = helper.tileHeight;
77
- var stickGroup = new svg_js_1.G()
78
- .size(stickWidth, stickGroupHeight)
79
- .translate(0, roundHeight);
80
- var stickFont = { family: font.family, size: font.size * 0.7 };
81
- var stick1000 = helper
82
- .createStick(1000)
83
- .size(stickWidth, stickHeight)
84
- .move(0, 0);
85
- var text1000 = new svg_js_1.Text()
86
- .plain(num1000.toString())
87
- .font(stickFont)
88
- .attr({ x: stickWidth, y: stickHeight });
89
- stickGroup.add(stick1000);
90
- stickGroup.add(text1000);
91
- var stick100 = helper
92
- .createStick(100)
93
- .size(stickWidth, stickHeight)
94
- .move(0, stickHeight + stickHeight);
95
- var text100 = new svg_js_1.Text()
96
- .plain(num100.toString())
97
- .font(stickFont)
98
- .attr({ x: stickWidth, y: stickHeight * 3 });
99
- stickGroup.add(stick100);
100
- stickGroup.add(text100);
101
- var doraImg = helper
102
- .createImage(scoreBoard.doras[0], 0, 0)
103
- .move(stickWidth + textWidth, 0);
104
- stickGroup.add(doraImg);
105
- g.add(roundText);
106
- g.add(stickGroup);
107
- return {
108
- e: g,
109
- width: stickWidth + helper.tileWidth + textWidth,
110
- height: roundHeight + helper.tileHeight,
111
- };
112
- };
113
- var createHands = function (helper, hands, minWidth) {
114
- if (minWidth === void 0) { minWidth = 0; }
115
- var fe = (0, image_1.createHand)(helper, hands.front);
116
- var re = (0, image_1.createHand)(helper, hands.right);
117
- var oe = (0, image_1.createHand)(helper, hands.opposite);
118
- var le = (0, image_1.createHand)(helper, hands.left);
119
- var maxWidth = [fe.width, re.width, oe.width, le.width].reduce(function (a, b) {
120
- return Math.max(a, b);
121
- });
122
- var sizeWidth = Math.max(minWidth + helper.tileHeight * 2 + helper.blockMargin * 2, maxWidth + helper.tileWidth * 2 + helper.blockMargin);
123
- var sizeHeight = sizeWidth;
124
- var g = new svg_js_1.G().size(sizeWidth, sizeHeight);
125
- var front = simpleRotate(fe.e, fe.width, fe.height, 0).translate((sizeWidth - fe.width) / 2, sizeHeight - fe.height);
126
- var right = simpleRotate(re.e, re.width, re.height, 270).translate(sizeWidth - re.height, (sizeWidth - re.width) / 2);
127
- var opposite = simpleRotate(oe.e, oe.width, oe.height, 180).translate((sizeWidth - oe.width) / 2, 0);
128
- var left = simpleRotate(le.e, le.width, le.height, 90).translate(0, (sizeWidth - le.width) / 2);
129
- g.add(front);
130
- g.add(right);
131
- g.add(opposite);
132
- g.add(left);
133
- return { e: g, width: sizeWidth, height: sizeHeight };
134
- };
135
- var getPlaces = function (front) {
136
- if (front == "東")
137
- return ["東", "南", "西", "北"];
138
- if (front == "南")
139
- return ["南", "西", "北", "東"];
140
- if (front == "西")
141
- return ["西", "北", "東", "南"];
142
- return ["北", "東", "南", "西"];
143
- };
144
- var createScoreBoard = function (helper, fontCtx, scoreBoard) {
145
- var sizeWidth = helper.tileWidth * 5 + helper.tileHeight * 1;
146
- var g = new svg_js_1.G();
147
- var rect = new svg_js_1.Rect()
148
- .size(sizeWidth, sizeWidth)
149
- .move(0, 0)
150
- .fill("none")
151
- .stroke("#000000");
152
- g.add(rect);
153
- var font = fontCtx.font;
154
- var textWidth = fontCtx.textWidth;
155
- var textHeight = fontCtx.textHeight;
156
- var numWidth = fontCtx.numWidth;
157
- var boardRect = createStickAndDora(helper, fontCtx, scoreBoard);
158
- boardRect.e.translate(sizeWidth / 2 - boardRect.width / 2, sizeWidth / 2 - boardRect.height / 2);
159
- var createScore = function (place, score, attr) {
160
- var s = "".concat(place, " ").concat(score);
161
- var t = new svg_js_1.Text().plain(s).font(font).attr(attr);
162
- var g = new svg_js_1.G().add(t);
163
- return {
164
- e: g,
165
- width: textWidth + numWidth * score.toString().length,
166
- height: textHeight,
167
- };
168
- };
169
- var _a = getPlaces(scoreBoard.frontPlace), frontPlace = _a[0], rightPlace = _a[1], oppositePlace = _a[2], leftPlace = _a[3];
170
- var scores = scoreBoard.scores;
171
- var ft = createScore(frontPlace, scores.front, {
172
- x: sizeWidth / 2,
173
- y: sizeWidth,
174
- "dominant-baseline": "text-after-edge",
175
- "text-anchor": "middle",
176
- });
177
- var frontText = ft.e;
178
- var rt = createScore(rightPlace, scores.right, {
179
- "dominant-baseline": "text-after-edge",
180
- "text-anchor": "middle",
181
- });
182
- var rightText = simpleRotate(rt.e, rt.width, rt.height, 270).translate(sizeWidth, sizeWidth / 2 - rt.width);
183
- var ot = createScore(oppositePlace, scores.opposite, {
184
- "text-anchor": "middle",
185
- "dominant-baseline": "text-after-edge",
186
- });
187
- var oppositeText = simpleRotate(ot.e, ot.width, ot.height, 180).translate(sizeWidth / 2 - ot.width, -ot.height);
188
- var lt = createScore(leftPlace, scores.left, {
189
- "dominant-baseline": "ideographic",
190
- "text-anchor": "middle",
191
- });
192
- var leftText = simpleRotate(lt.e, lt.width, lt.height, 90).translate(-lt.height, sizeWidth / 2);
193
- g.add(boardRect.e);
194
- g.add(frontText);
195
- g.add(rightText);
196
- g.add(oppositeText);
197
- g.add(leftText);
198
- return { e: g, width: sizeWidth, height: sizeWidth };
199
- };
200
- var createDiscards = function (helper, discards) {
201
- var fe = handleDiscard(discards.front, helper);
202
- var re = handleDiscard(discards.right, helper);
203
- var oe = handleDiscard(discards.opposite, helper);
204
- var le = handleDiscard(discards.left, helper);
205
- var maxDiscardHeight = [fe.height, re.height, oe.height, le.height].reduce(function (a, b) { return Math.max(a, b); });
206
- var discardWidth = helper.tileWidth * 5 + helper.tileHeight * 1;
207
- var discardHeight = maxDiscardHeight;
208
- var sizeWidth = discardWidth + maxDiscardHeight * 2 + helper.blockMargin;
209
- var sizeHeight = sizeWidth;
210
- var g = new svg_js_1.G().size(sizeWidth, sizeHeight);
211
- var centerX = sizeWidth / 2 - discardWidth / 2;
212
- var centerY = sizeHeight / 2 - discardWidth / 2;
213
- var front = simpleRotate(fe.e, discardWidth, discardHeight, 0).translate(centerX, sizeHeight - discardHeight);
214
- var right = simpleRotate(re.e, discardWidth, discardHeight, 270).translate(sizeWidth - discardHeight, centerY);
215
- var opposite = simpleRotate(oe.e, discardWidth, discardHeight, 180).translate(centerX, 0);
216
- var left = simpleRotate(le.e, discardWidth, discardHeight, 90).translate(0, centerY);
217
- g.add(front);
218
- g.add(right);
219
- g.add(opposite);
220
- g.add(left);
221
- return { e: g, width: sizeWidth, height: sizeHeight };
222
- };
223
- var createTable = function (helper, fontCtx, handsProps, discardsProps, scoreBoardProps) {
224
- var g = new svg_js_1.G();
225
- var discards = createDiscards(helper, discardsProps);
226
- var hands = createHands(helper, handsProps, discards.height);
227
- var scoreBoard = createScoreBoard(helper, fontCtx, scoreBoardProps);
228
- discards.e.translate((hands.width - discards.width) / 2, (hands.height - discards.height) / 2);
229
- scoreBoard.e.translate((hands.width - scoreBoard.width) / 2, (hands.height - scoreBoard.height) / 2);
230
- g.add(hands.e);
231
- g.add(discards.e);
232
- g.add(scoreBoard.e);
233
- return { e: g, width: hands.width, height: hands.height };
234
- };
235
- exports.createTable = createTable;
236
- var drawTable = function (svg, tableInput, config, fontCtx, params) {
237
- if (config === void 0) { config = {}; }
238
- if (params === void 0) { params = { responsive: false }; }
239
- var helper = new image_1.ImageHelper(config);
240
- var ctx = fontCtx;
241
- var _a = (0, _1.parse)(tableInput), discards = _a.discards, hands = _a.hands, scoreBoard = _a.scoreBoard;
242
- var table = (0, exports.createTable)(helper, ctx, hands, discards, scoreBoard);
243
- if (!params.responsive)
244
- svg.size(table.width, table.height);
245
- svg.viewbox(0, 0, table.width, table.height);
246
- svg.add(table.e);
247
- };
248
- exports.drawTable = drawTable;