@konoui/mjimage 0.0.13 → 0.0.14
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.
- package/dist/mjs/lib/constants.d.ts +2 -0
- package/dist/mjs/lib/constants.js +6 -1
- package/dist/mjs/lib/image.d.ts +5 -5
- package/dist/mjs/lib/image.js +109 -111
- package/dist/mjs/lib/mjimage.d.ts +1 -0
- package/dist/mjs/lib/mjimage.js +6 -4
- package/dist/mjs/lib/parser.d.ts +10 -1
- package/dist/mjs/lib/parser.js +28 -17
- package/dist/mjs/lib/table.d.ts +3 -1
- package/dist/mjs/lib/table.js +10 -3
- package/dist/mjs/svg/_0.svg +1 -1
- package/dist/mjs/svg/m0.svg +1 -1
- package/dist/mjs/svg/m1.svg +1 -1
- package/dist/mjs/svg/m2.svg +1 -1
- package/dist/mjs/svg/m3.svg +1 -1
- package/dist/mjs/svg/m4.svg +1 -1
- package/dist/mjs/svg/m5.svg +1 -1
- package/dist/mjs/svg/m6.svg +1 -1
- package/dist/mjs/svg/m7.svg +1 -1
- package/dist/mjs/svg/m8.svg +1 -1
- package/dist/mjs/svg/m9.svg +1 -1
- package/dist/mjs/svg/p0.svg +1 -1
- package/dist/mjs/svg/p1.svg +1 -1
- package/dist/mjs/svg/p2.svg +1 -1
- package/dist/mjs/svg/p3.svg +1 -1
- package/dist/mjs/svg/p4.svg +1 -1
- package/dist/mjs/svg/p5.svg +1 -1
- package/dist/mjs/svg/p6.svg +1 -1
- package/dist/mjs/svg/p7.svg +1 -1
- package/dist/mjs/svg/p8.svg +1 -1
- package/dist/mjs/svg/p9.svg +1 -1
- package/dist/mjs/svg/s0.svg +1 -1
- package/dist/mjs/svg/s1.svg +1 -1
- package/dist/mjs/svg/s2.svg +1 -1
- package/dist/mjs/svg/s3.svg +1 -1
- package/dist/mjs/svg/s4.svg +1 -1
- package/dist/mjs/svg/s5.svg +1 -1
- package/dist/mjs/svg/s6.svg +1 -1
- package/dist/mjs/svg/s7.svg +1 -1
- package/dist/mjs/svg/s8.svg +1 -1
- package/dist/mjs/svg/s9.svg +1 -1
- package/dist/mjs/svg/stick100.svg +1 -1
- package/dist/mjs/svg/stick1000.svg +1 -1
- package/dist/mjs/svg/z1.svg +1 -1
- package/dist/mjs/svg/z2.svg +1 -1
- package/dist/mjs/svg/z3.svg +1 -1
- package/dist/mjs/svg/z4.svg +1 -1
- package/dist/mjs/svg/z5.svg +1 -1
- package/dist/mjs/svg/z6.svg +1 -1
- package/dist/mjs/svg/z7.svg +1 -1
- package/package.json +2 -2
|
@@ -3,7 +3,12 @@ var _a;
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
4
|
exports.WIND_MAP = exports.ROUND_MAP = exports.WIND = exports.BLOCK = exports.OPERATOR = exports.TYPE = exports.INPUT_SEPARATOR = exports.TABLE_CONTEXT = exports.TILE_CONTEXT = exports.FONT_FAMILY = void 0;
|
|
5
5
|
exports.FONT_FAMILY = "MS Gothic, sans-serif";
|
|
6
|
-
exports.TILE_CONTEXT = {
|
|
6
|
+
exports.TILE_CONTEXT = {
|
|
7
|
+
WIDTH: 66,
|
|
8
|
+
HEIGHT: 90,
|
|
9
|
+
TEXT_SCALE: 0.8,
|
|
10
|
+
BLOCK_MARGIN_SCALE: 0.3,
|
|
11
|
+
};
|
|
7
12
|
exports.TABLE_CONTEXT = { BASE: 40 };
|
|
8
13
|
exports.INPUT_SEPARATOR = ",";
|
|
9
14
|
exports.TYPE = {
|
package/dist/mjs/lib/image.d.ts
CHANGED
|
@@ -9,17 +9,15 @@ export interface ImageHelperConfig {
|
|
|
9
9
|
declare class BaseHelper {
|
|
10
10
|
readonly tileWidth: number;
|
|
11
11
|
readonly tileHeight: number;
|
|
12
|
-
readonly diffTileHeightWidth: number;
|
|
13
|
-
readonly textWidth: number;
|
|
14
12
|
readonly image_host_path: string;
|
|
15
13
|
readonly image_host_url: string;
|
|
16
14
|
readonly scale: number;
|
|
17
15
|
readonly svgSprite: boolean;
|
|
18
16
|
constructor(props?: ImageHelperConfig);
|
|
17
|
+
protected getDiffTileHeightWidth(t: Tile): number;
|
|
19
18
|
private image;
|
|
20
19
|
createImage(tile: Tile, x: number, y: number): Image | Use;
|
|
21
20
|
createTextImage(tile: Tile, x: number, y: number, t: string): G;
|
|
22
|
-
createStackImage(baseTile: Tile, upTile: Tile, x: number, y: number): G;
|
|
23
21
|
createRotate90Image(tile: Tile, x: number, y: number, adjustY?: boolean): G;
|
|
24
22
|
createStick(v: 100 | 1000): Image | Use;
|
|
25
23
|
static buildID(tile: Tile | 100 | 1000): string;
|
|
@@ -27,7 +25,7 @@ declare class BaseHelper {
|
|
|
27
25
|
}
|
|
28
26
|
export declare class ImageHelper extends BaseHelper {
|
|
29
27
|
readonly blockMargin: number;
|
|
30
|
-
createBlockHandDiscard(
|
|
28
|
+
createBlockHandDiscard(block: Block): G;
|
|
31
29
|
createBlockPonChiKan(block: Block): G;
|
|
32
30
|
}
|
|
33
31
|
export declare const createHand: (helper: ImageHelper, blocks: Block[]) => {
|
|
@@ -35,6 +33,8 @@ export declare const createHand: (helper: ImageHelper, blocks: Block[]) => {
|
|
|
35
33
|
width: number;
|
|
36
34
|
height: number;
|
|
37
35
|
};
|
|
38
|
-
export declare const drawBlocks: (svg: Svg, blocks: Block[], config?: ImageHelperConfig
|
|
36
|
+
export declare const drawBlocks: (svg: Svg, blocks: Block[], config?: ImageHelperConfig, params?: {
|
|
37
|
+
responsive: boolean;
|
|
38
|
+
}) => void;
|
|
39
39
|
export declare const optimizeSVG: (draw: Svg) => void;
|
|
40
40
|
export {};
|
package/dist/mjs/lib/image.js
CHANGED
|
@@ -14,6 +14,17 @@ var __extends = (this && this.__extends) || (function () {
|
|
|
14
14
|
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
|
15
15
|
};
|
|
16
16
|
})();
|
|
17
|
+
var __assign = (this && this.__assign) || function () {
|
|
18
|
+
__assign = Object.assign || function(t) {
|
|
19
|
+
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
20
|
+
s = arguments[i];
|
|
21
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
|
22
|
+
t[p] = s[p];
|
|
23
|
+
}
|
|
24
|
+
return t;
|
|
25
|
+
};
|
|
26
|
+
return __assign.apply(this, arguments);
|
|
27
|
+
};
|
|
17
28
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
18
29
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
19
30
|
};
|
|
@@ -32,10 +43,12 @@ var BaseHelper = (function () {
|
|
|
32
43
|
this.image_host_url = (_c = props.imageHostUrl) !== null && _c !== void 0 ? _c : "";
|
|
33
44
|
this.tileWidth = constants_1.TILE_CONTEXT.WIDTH * this.scale;
|
|
34
45
|
this.tileHeight = constants_1.TILE_CONTEXT.HEIGHT * this.scale;
|
|
35
|
-
this.textWidth = this.tileWidth * 0.8;
|
|
36
|
-
this.diffTileHeightWidth = (this.tileHeight - this.tileWidth) / 2;
|
|
37
46
|
this.svgSprite = (_d = props.svgSprite) !== null && _d !== void 0 ? _d : false;
|
|
38
47
|
}
|
|
48
|
+
BaseHelper.prototype.getDiffTileHeightWidth = function (t) {
|
|
49
|
+
var size = t.imageSize(this.scale);
|
|
50
|
+
return (size.baseHeight - size.baseWidth) / 2;
|
|
51
|
+
};
|
|
39
52
|
BaseHelper.prototype.image = function (tile) {
|
|
40
53
|
var img = new svg_js_1.Image().load(this.buildURL(tile));
|
|
41
54
|
if (this.svgSprite) {
|
|
@@ -47,21 +60,22 @@ var BaseHelper = (function () {
|
|
|
47
60
|
return img;
|
|
48
61
|
};
|
|
49
62
|
BaseHelper.prototype.createImage = function (tile, x, y) {
|
|
63
|
+
var size = tile.imageSize(this.scale);
|
|
50
64
|
var image = this.image(tile)
|
|
51
65
|
.dx(x)
|
|
52
66
|
.dy(y)
|
|
53
|
-
.size(
|
|
67
|
+
.size(size.baseWidth, size.baseHeight);
|
|
54
68
|
return image;
|
|
55
69
|
};
|
|
56
70
|
BaseHelper.prototype.createTextImage = function (tile, x, y, t) {
|
|
57
71
|
var image = this.createImage(tile, x, y);
|
|
58
|
-
var
|
|
59
|
-
var
|
|
60
|
-
var
|
|
72
|
+
var size = tile.imageSize(this.scale);
|
|
73
|
+
var fontSize = size.baseHeight * 0.2;
|
|
74
|
+
var textX = size.baseWidth;
|
|
75
|
+
var textY = size.baseHeight;
|
|
61
76
|
var text = new svg_js_1.Text().text(t);
|
|
62
77
|
text
|
|
63
|
-
.
|
|
64
|
-
.height(this.tileHeight)
|
|
78
|
+
.size(size.baseWidth, size.baseHeight)
|
|
65
79
|
.font({
|
|
66
80
|
family: constants_1.FONT_FAMILY,
|
|
67
81
|
size: fontSize,
|
|
@@ -72,19 +86,14 @@ var BaseHelper = (function () {
|
|
|
72
86
|
g.add(image).add(text).translate(x, y);
|
|
73
87
|
return g;
|
|
74
88
|
};
|
|
75
|
-
BaseHelper.prototype.createStackImage = function (baseTile, upTile, x, y) {
|
|
76
|
-
var base = this.createRotate90Image(baseTile, 0, 0, true);
|
|
77
|
-
var up = this.createRotate90Image(upTile, 0, this.tileWidth, true);
|
|
78
|
-
var g = new svg_js_1.G().translate(x, y).add(base).add(up);
|
|
79
|
-
return g;
|
|
80
|
-
};
|
|
81
89
|
BaseHelper.prototype.createRotate90Image = function (tile, x, y, adjustY) {
|
|
82
90
|
if (adjustY === void 0) { adjustY = false; }
|
|
83
91
|
var image = this.createImage(tile, 0, 0);
|
|
84
|
-
var
|
|
85
|
-
var
|
|
86
|
-
var
|
|
87
|
-
var
|
|
92
|
+
var size = tile.imageSize(this.scale);
|
|
93
|
+
var centerX = size.baseWidth / 2;
|
|
94
|
+
var centerY = size.baseHeight / 2;
|
|
95
|
+
var translatedX = x + this.getDiffTileHeightWidth(tile);
|
|
96
|
+
var translatedY = adjustY ? y - this.getDiffTileHeightWidth(tile) : y;
|
|
88
97
|
var g = new svg_js_1.G();
|
|
89
98
|
g.add(image)
|
|
90
99
|
.translate(translatedX, translatedY)
|
|
@@ -114,23 +123,22 @@ var ImageHelper = (function (_super) {
|
|
|
114
123
|
__extends(ImageHelper, _super);
|
|
115
124
|
function ImageHelper() {
|
|
116
125
|
var _this = _super !== null && _super.apply(this, arguments) || this;
|
|
117
|
-
_this.blockMargin =
|
|
126
|
+
_this.blockMargin = constants_1.TILE_CONTEXT.WIDTH * constants_1.TILE_CONTEXT.BLOCK_MARGIN_SCALE * _this.scale;
|
|
118
127
|
return _this;
|
|
119
128
|
}
|
|
120
|
-
ImageHelper.prototype.createBlockHandDiscard = function (
|
|
129
|
+
ImageHelper.prototype.createBlockHandDiscard = function (block) {
|
|
121
130
|
var g = new svg_js_1.G();
|
|
122
131
|
var pos = 0;
|
|
123
|
-
for (var _i = 0,
|
|
124
|
-
var t =
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
var img = this.createImage(t, pos, 0);
|
|
132
|
+
for (var _i = 0, _a = block.tiles; _i < _a.length; _i++) {
|
|
133
|
+
var t = _a[_i];
|
|
134
|
+
var size = t.imageSize(this.scale);
|
|
135
|
+
var f = t.has(constants_1.OPERATOR.HORIZONTAL)
|
|
136
|
+
? this.createRotate90Image.bind(this)
|
|
137
|
+
: this.createImage.bind(this);
|
|
138
|
+
var y = t.has(constants_1.OPERATOR.HORIZONTAL) ? this.getDiffTileHeightWidth(t) : 0;
|
|
139
|
+
var img = f(t, pos, y);
|
|
132
140
|
g.add(img);
|
|
133
|
-
pos +=
|
|
141
|
+
pos += size.width;
|
|
134
142
|
}
|
|
135
143
|
return g;
|
|
136
144
|
};
|
|
@@ -139,52 +147,53 @@ var ImageHelper = (function (_super) {
|
|
|
139
147
|
var pos = 0;
|
|
140
148
|
var g = new svg_js_1.G();
|
|
141
149
|
if (block.type == constants_1.BLOCK.SHO_KAN) {
|
|
142
|
-
var diff = this.tileWidth * 2 - this.tileHeight;
|
|
143
150
|
var lastIdx = idx;
|
|
144
|
-
var i = 0;
|
|
145
|
-
|
|
146
|
-
var t = _a[_i];
|
|
147
|
-
if (t.has(constants_1.OPERATOR.HORIZONTAL))
|
|
151
|
+
for (var i = 0; i < block.tiles.length; i++)
|
|
152
|
+
if (block.tiles[i].has(constants_1.OPERATOR.HORIZONTAL))
|
|
148
153
|
lastIdx = i;
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
if (i_1 == lastIdx)
|
|
154
|
+
for (var i = 0; i < block.tiles.length; i++) {
|
|
155
|
+
var size = block.tiles[i].imageSize(this.scale);
|
|
156
|
+
if (i == lastIdx)
|
|
153
157
|
continue;
|
|
154
|
-
if (
|
|
155
|
-
var
|
|
156
|
-
|
|
157
|
-
|
|
158
|
+
if (i == idx) {
|
|
159
|
+
var baseTile = block.tiles[idx];
|
|
160
|
+
var upperTile = block.tiles[lastIdx];
|
|
161
|
+
var size_1 = baseTile.imageSize(this.scale);
|
|
162
|
+
var baseImg = this.createRotate90Image(baseTile, 0, 0, true);
|
|
163
|
+
var upImg = this.createRotate90Image(upperTile, 0, size_1.height, true);
|
|
164
|
+
g.add(new svg_js_1.G().translate(pos, 0).add(baseImg).add(upImg));
|
|
165
|
+
pos += size_1.width;
|
|
158
166
|
continue;
|
|
159
167
|
}
|
|
160
|
-
var
|
|
161
|
-
|
|
168
|
+
var diff = size.width * 2 - size.height;
|
|
169
|
+
var img = this.createImage(block.tiles[i], pos, diff);
|
|
170
|
+
pos += size.width;
|
|
162
171
|
g.add(img);
|
|
163
172
|
}
|
|
164
173
|
return g;
|
|
165
174
|
}
|
|
166
175
|
if (block.type == constants_1.BLOCK.CHI) {
|
|
167
|
-
var img = this.createRotate90Image(block.tiles[idx], pos, this.
|
|
168
|
-
pos += this.
|
|
176
|
+
var img = this.createRotate90Image(block.tiles[idx], pos, this.getDiffTileHeightWidth(block.tiles[idx]));
|
|
177
|
+
pos += block.tiles[idx].imageSize(this.scale).width;
|
|
169
178
|
g.add(img);
|
|
170
179
|
for (var i = 0; i < block.tiles.length; i++) {
|
|
171
180
|
if (i == idx)
|
|
172
181
|
continue;
|
|
173
|
-
var
|
|
174
|
-
|
|
175
|
-
|
|
182
|
+
var size = block.tiles[i].imageSize(this.scale);
|
|
183
|
+
var img_1 = this.createImage(block.tiles[i], pos, 0);
|
|
184
|
+
pos += size.width;
|
|
185
|
+
g.add(img_1);
|
|
176
186
|
}
|
|
177
187
|
return g;
|
|
178
188
|
}
|
|
179
189
|
for (var i = 0; i < block.tiles.length; i++) {
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
pos += this.tileWidth;
|
|
190
|
+
var f = i == idx
|
|
191
|
+
? this.createRotate90Image.bind(this)
|
|
192
|
+
: this.createImage.bind(this);
|
|
193
|
+
var y = i == idx ? this.getDiffTileHeightWidth(block.tiles[i]) : 0;
|
|
194
|
+
var size = block.tiles[i].imageSize(this.scale);
|
|
195
|
+
var img = f(block.tiles[i], pos, y);
|
|
196
|
+
pos += size.width;
|
|
188
197
|
g.add(img);
|
|
189
198
|
}
|
|
190
199
|
return g;
|
|
@@ -194,80 +203,62 @@ var ImageHelper = (function (_super) {
|
|
|
194
203
|
exports.ImageHelper = ImageHelper;
|
|
195
204
|
var getBlockCreators = function (h) {
|
|
196
205
|
var _a;
|
|
206
|
+
var scale = h.scale;
|
|
197
207
|
var lookup = (_a = {},
|
|
198
208
|
_a[constants_1.BLOCK.CHI] = function (block) {
|
|
199
|
-
var
|
|
200
|
-
var height = h.tileHeight;
|
|
209
|
+
var size = block.imageSize(scale);
|
|
201
210
|
var g = h.createBlockPonChiKan(block);
|
|
202
|
-
return {
|
|
211
|
+
return __assign(__assign({}, size), { e: g });
|
|
203
212
|
},
|
|
204
213
|
_a[constants_1.BLOCK.PON] = function (block) {
|
|
205
|
-
var
|
|
206
|
-
var height = h.tileHeight;
|
|
214
|
+
var size = block.imageSize(scale);
|
|
207
215
|
var g = h.createBlockPonChiKan(block);
|
|
208
|
-
return {
|
|
216
|
+
return __assign(__assign({}, size), { e: g });
|
|
209
217
|
},
|
|
210
218
|
_a[constants_1.BLOCK.DAI_KAN] = function (block) {
|
|
211
|
-
var
|
|
212
|
-
var height = h.tileHeight;
|
|
219
|
+
var size = block.imageSize(scale);
|
|
213
220
|
var g = h.createBlockPonChiKan(block);
|
|
214
|
-
return {
|
|
221
|
+
return __assign(__assign({}, size), { e: g });
|
|
215
222
|
},
|
|
216
223
|
_a[constants_1.BLOCK.SHO_KAN] = function (block) {
|
|
217
|
-
var
|
|
218
|
-
var height = h.tileWidth * 2;
|
|
224
|
+
var size = block.imageSize(scale);
|
|
219
225
|
var g = h.createBlockPonChiKan(block);
|
|
220
|
-
return {
|
|
226
|
+
return __assign(__assign({}, size), { e: g });
|
|
221
227
|
},
|
|
222
228
|
_a[constants_1.BLOCK.AN_KAN] = function (block) {
|
|
223
|
-
var
|
|
224
|
-
var height = h.tileHeight;
|
|
229
|
+
var size = block.imageSize(scale);
|
|
225
230
|
var zp = block.tiles.filter(function (v) {
|
|
226
231
|
return v.t !== constants_1.TYPE.BACK;
|
|
227
232
|
});
|
|
228
233
|
(0, assert_1.default)(zp != null && zp.length == 2);
|
|
229
|
-
var g = h.createBlockHandDiscard([
|
|
230
|
-
|
|
231
|
-
zp[0],
|
|
232
|
-
zp[1],
|
|
233
|
-
new parser_1.Tile(constants_1.TYPE.BACK, 0),
|
|
234
|
-
]);
|
|
235
|
-
return { width: width, height: height, e: g };
|
|
234
|
+
var g = h.createBlockHandDiscard(new parser_1.BlockAnKan([zp[0], zp[1], zp[0], zp[1]]));
|
|
235
|
+
return __assign(__assign({}, size), { e: g });
|
|
236
236
|
},
|
|
237
237
|
_a[constants_1.BLOCK.DORA] = function (block) {
|
|
238
|
-
var
|
|
239
|
-
var height = h.tileHeight;
|
|
238
|
+
var size = block.imageSize(scale);
|
|
240
239
|
var g = new svg_js_1.G();
|
|
241
240
|
var img = h.createTextImage(block.tiles[0], 0, 0, "(ドラ)");
|
|
242
241
|
g.add(img);
|
|
243
|
-
return {
|
|
242
|
+
return __assign(__assign({}, size), { e: g });
|
|
244
243
|
},
|
|
245
244
|
_a[constants_1.BLOCK.TSUMO] = function (block) {
|
|
246
|
-
var
|
|
247
|
-
var height = h.tileHeight;
|
|
245
|
+
var size = block.imageSize(scale);
|
|
248
246
|
var g = new svg_js_1.G();
|
|
249
247
|
var img = h.createTextImage(block.tiles[0], 0, 0, "(ツモ)");
|
|
250
248
|
g.add(img);
|
|
251
|
-
return {
|
|
249
|
+
return __assign(__assign({}, size), { e: g });
|
|
252
250
|
},
|
|
253
251
|
_a[constants_1.BLOCK.HAND] = function (block) {
|
|
254
|
-
var
|
|
255
|
-
var
|
|
256
|
-
|
|
257
|
-
return { width: width, height: height, e: g };
|
|
252
|
+
var size = block.imageSize(scale);
|
|
253
|
+
var g = h.createBlockHandDiscard(block);
|
|
254
|
+
return __assign(__assign({}, size), { e: g });
|
|
258
255
|
},
|
|
259
256
|
_a[constants_1.BLOCK.DISCARD] = function (block) {
|
|
260
|
-
var
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
var height = h.tileHeight;
|
|
264
|
-
var g = h.createBlockHandDiscard(block.tiles);
|
|
265
|
-
return { width: width, height: height, e: g };
|
|
257
|
+
var size = block.imageSize(scale);
|
|
258
|
+
var g = h.createBlockHandDiscard(block);
|
|
259
|
+
return __assign(__assign({}, size), { e: g });
|
|
266
260
|
},
|
|
267
261
|
_a[constants_1.BLOCK.UNKNOWN] = function (block) {
|
|
268
|
-
var width = 0;
|
|
269
|
-
var height = 0;
|
|
270
|
-
var g = new svg_js_1.G();
|
|
271
262
|
throw new Error("found unknown block");
|
|
272
263
|
},
|
|
273
264
|
_a[constants_1.BLOCK.PAIR] = function (block) {
|
|
@@ -283,39 +274,46 @@ var getBlockCreators = function (h) {
|
|
|
283
274
|
return lookup;
|
|
284
275
|
};
|
|
285
276
|
var createHand = function (helper, blocks) {
|
|
277
|
+
var _a = blocks.reduce(function (acc, b) {
|
|
278
|
+
var size = b.imageSize(helper.scale);
|
|
279
|
+
var v = size.height > acc.maxHeight ? size.height : acc.maxHeight;
|
|
280
|
+
return { maxHeight: v, sumWidth: acc.sumWidth + size.width };
|
|
281
|
+
}, { maxHeight: 0, sumWidth: 0 }), maxHeight = _a.maxHeight, sumWidth = _a.sumWidth;
|
|
282
|
+
var viewBoxHeight = maxHeight;
|
|
283
|
+
var viewBoxWidth = sumWidth + (blocks.length - 1) * helper.blockMargin;
|
|
284
|
+
var params = {
|
|
285
|
+
viewBoxWidth: viewBoxWidth,
|
|
286
|
+
viewBoxHeight: viewBoxHeight,
|
|
287
|
+
};
|
|
286
288
|
var creators = getBlockCreators(helper);
|
|
287
|
-
var baseHeight = helper.tileWidth;
|
|
288
|
-
var sumOfWidth = 0;
|
|
289
289
|
var elms = [];
|
|
290
290
|
for (var _i = 0, blocks_1 = blocks; _i < blocks_1.length; _i++) {
|
|
291
291
|
var block = blocks_1[_i];
|
|
292
292
|
var fn = creators[block.type];
|
|
293
293
|
var elm = fn(block);
|
|
294
294
|
elms.push(elm);
|
|
295
|
-
sumOfWidth += elm.width;
|
|
296
|
-
if (elm.height > baseHeight)
|
|
297
|
-
baseHeight = elm.height;
|
|
298
295
|
}
|
|
299
|
-
var sizeHeight = baseHeight;
|
|
300
|
-
var sizeWidth = sumOfWidth + (blocks.length - 1) * helper.blockMargin;
|
|
301
296
|
var hand = new svg_js_1.G();
|
|
302
297
|
var pos = 0;
|
|
303
|
-
for (var
|
|
304
|
-
var elm = elms_1[
|
|
305
|
-
var diff =
|
|
298
|
+
for (var _b = 0, elms_1 = elms; _b < elms_1.length; _b++) {
|
|
299
|
+
var elm = elms_1[_b];
|
|
300
|
+
var diff = viewBoxHeight - elm.height;
|
|
306
301
|
var g = new svg_js_1.G().translate(pos, diff);
|
|
307
302
|
g.add(elm.e);
|
|
308
303
|
hand.add(g);
|
|
309
304
|
pos += elm.width + helper.blockMargin;
|
|
310
305
|
}
|
|
311
|
-
return { e: hand, width:
|
|
306
|
+
return { e: hand, width: viewBoxWidth, height: viewBoxHeight };
|
|
312
307
|
};
|
|
313
308
|
exports.createHand = createHand;
|
|
314
|
-
var drawBlocks = function (svg, blocks, config) {
|
|
309
|
+
var drawBlocks = function (svg, blocks, config, params) {
|
|
315
310
|
if (config === void 0) { config = {}; }
|
|
311
|
+
if (params === void 0) { params = { responsive: false }; }
|
|
316
312
|
var helper = new ImageHelper(config);
|
|
317
313
|
var hand = (0, exports.createHand)(helper, blocks);
|
|
318
|
-
|
|
314
|
+
if (!params.responsive)
|
|
315
|
+
svg.size(hand.width, hand.height);
|
|
316
|
+
svg.viewbox(0, 0, hand.width, hand.height);
|
|
319
317
|
svg.add(hand.e);
|
|
320
318
|
};
|
|
321
319
|
exports.drawBlocks = drawBlocks;
|
package/dist/mjs/lib/mjimage.js
CHANGED
|
@@ -20,6 +20,7 @@ var constants_1 = require("./constants");
|
|
|
20
20
|
var svg_js_1 = require("@svgdotjs/svg.js");
|
|
21
21
|
var defaultQuerySelector = ".mjimage";
|
|
22
22
|
var defaultScale = 1.6;
|
|
23
|
+
var defaultResponsive = false;
|
|
23
24
|
var defaultSvgSprite = false;
|
|
24
25
|
var tableRegex = /^\s*table/;
|
|
25
26
|
var minPaiHeight = Math.min(constants_1.TILE_CONTEXT.WIDTH, constants_1.TILE_CONTEXT.HEIGHT);
|
|
@@ -30,13 +31,14 @@ var mjimage = (function () {
|
|
|
30
31
|
function mjimage() {
|
|
31
32
|
}
|
|
32
33
|
mjimage.initialize = function (props) {
|
|
33
|
-
var _a, _b, _c, _d;
|
|
34
|
+
var _a, _b, _c, _d, _e;
|
|
34
35
|
if (props === void 0) { props = {}; }
|
|
35
36
|
console.debug("initializing....");
|
|
36
37
|
var querySelector = (_a = props.querySelector) !== null && _a !== void 0 ? _a : defaultQuerySelector;
|
|
37
38
|
var handScale = (_b = props.scale) !== null && _b !== void 0 ? _b : defaultScale;
|
|
38
39
|
var tableScale = (_c = props.tableScale) !== null && _c !== void 0 ? _c : handScale;
|
|
39
|
-
var
|
|
40
|
+
var responsive = (_d = props.responsive) !== null && _d !== void 0 ? _d : defaultResponsive;
|
|
41
|
+
var svgSprite = (_e = props.svgSprite) !== null && _e !== void 0 ? _e : defaultSvgSprite;
|
|
40
42
|
if (typeof querySelector === "string")
|
|
41
43
|
querySelector = [querySelector];
|
|
42
44
|
var mtext = new measure_text_1.MeasureText();
|
|
@@ -60,12 +62,12 @@ var mjimage = (function () {
|
|
|
60
62
|
if (tableRegex.test(input)) {
|
|
61
63
|
var scale = calculateScale(tableScale, textHeight);
|
|
62
64
|
var fontCtx = mtext.measureTableFontContext(scale);
|
|
63
|
-
(0, table_1.drawTable)(svg, input, __assign(__assign({}, props), { svgSprite: svgSprite, scale: scale }), fontCtx);
|
|
65
|
+
(0, table_1.drawTable)(svg, input, __assign(__assign({}, props), { svgSprite: svgSprite, scale: scale }), fontCtx, { responsive: responsive });
|
|
64
66
|
}
|
|
65
67
|
else {
|
|
66
68
|
var scale = calculateScale(handScale, textHeight);
|
|
67
69
|
var blocks = new parser_1.Parser(input).parse();
|
|
68
|
-
(0, image_1.drawBlocks)(svg, blocks, __assign(__assign({}, props), { svgSprite: svgSprite, scale: scale }));
|
|
70
|
+
(0, image_1.drawBlocks)(svg, blocks, __assign(__assign({}, props), { svgSprite: svgSprite, scale: scale }), { responsive: responsive });
|
|
69
71
|
}
|
|
70
72
|
svg.addTo(target);
|
|
71
73
|
}
|
package/dist/mjs/lib/parser.d.ts
CHANGED
|
@@ -16,6 +16,12 @@ export declare class Tile {
|
|
|
16
16
|
remove(op: Operator): Tile;
|
|
17
17
|
isNum(): boolean;
|
|
18
18
|
equals(t: Tile, ignoreRed?: boolean): boolean;
|
|
19
|
+
imageSize(scale: number): {
|
|
20
|
+
width: number;
|
|
21
|
+
height: number;
|
|
22
|
+
baseWidth: number;
|
|
23
|
+
baseHeight: number;
|
|
24
|
+
};
|
|
19
25
|
}
|
|
20
26
|
type BLOCK = (typeof BLOCK)[keyof typeof BLOCK];
|
|
21
27
|
export declare class Block {
|
|
@@ -25,9 +31,12 @@ export declare class Block {
|
|
|
25
31
|
toString(): string;
|
|
26
32
|
is(type: BLOCK): boolean;
|
|
27
33
|
isCalled(): boolean;
|
|
28
|
-
equals(b: Block): boolean;
|
|
29
34
|
minTile(): Tile;
|
|
30
35
|
clone(): Block | BlockChi | BlockPon | BlockAnKan | BlockDaiKan | BlockShoKan | BlockPair | BlockSet | BlockIsolated;
|
|
36
|
+
imageSize(scale: number): {
|
|
37
|
+
width: number;
|
|
38
|
+
height: number;
|
|
39
|
+
};
|
|
31
40
|
}
|
|
32
41
|
export declare class BlockChi extends Block {
|
|
33
42
|
constructor(tiles: [Tile, Tile, Tile]);
|
package/dist/mjs/lib/parser.js
CHANGED
|
@@ -97,6 +97,16 @@ var Tile = (function () {
|
|
|
97
97
|
ok || (ok = (this.n == 5 && t.n == 0) || (this.n == 0 && t.n == 5));
|
|
98
98
|
return this.t == t.t && ok;
|
|
99
99
|
};
|
|
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)
|
|
104
|
+
? { width: h, height: w, baseWidth: w, baseHeight: h }
|
|
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;
|
|
108
|
+
return size;
|
|
109
|
+
};
|
|
100
110
|
return Tile;
|
|
101
111
|
}());
|
|
102
112
|
exports.Tile = Tile;
|
|
@@ -152,21 +162,6 @@ var Block = (function () {
|
|
|
152
162
|
constants_1.BLOCK.SHO_KAN.toString(),
|
|
153
163
|
].includes(this.type.toString());
|
|
154
164
|
};
|
|
155
|
-
Block.prototype.equals = function (b) {
|
|
156
|
-
if (this.tiles.length != b.tiles.length)
|
|
157
|
-
return false;
|
|
158
|
-
var ab = this.tiles;
|
|
159
|
-
var bb = b.tiles;
|
|
160
|
-
if (this.is(constants_1.BLOCK.CHI) || b.is(constants_1.BLOCK.CHI)) {
|
|
161
|
-
ab = b.clone().tiles.sort(exports.tileSortFunc);
|
|
162
|
-
bb = this.clone().tiles.sort(exports.tileSortFunc);
|
|
163
|
-
}
|
|
164
|
-
for (var i = 0; i < b.tiles.length; i++) {
|
|
165
|
-
if (!ab[i].equals(bb[i], true))
|
|
166
|
-
return false;
|
|
167
|
-
}
|
|
168
|
-
return true;
|
|
169
|
-
};
|
|
170
165
|
Block.prototype.minTile = function () {
|
|
171
166
|
if (this.is(constants_1.BLOCK.CHI))
|
|
172
167
|
return this.clone().tiles.sort(exports.tileSortFunc)[0];
|
|
@@ -177,6 +172,20 @@ var Block = (function () {
|
|
|
177
172
|
var tiles = this.tiles.map(function (t) { return new Tile(t.t, t.n, __spreadArray([], t.ops, true)); });
|
|
178
173
|
return (0, exports.blockWrapper)(tiles, this.type);
|
|
179
174
|
};
|
|
175
|
+
Block.prototype.imageSize = function (scale) {
|
|
176
|
+
var bh = this.tiles[0].imageSize(scale).baseHeight;
|
|
177
|
+
var bw = this.tiles[0].imageSize(scale).baseWidth;
|
|
178
|
+
if (this.is(constants_1.BLOCK.SHO_KAN))
|
|
179
|
+
return { width: bw * 2 + bh, height: Math.max(bw * 2, bh) };
|
|
180
|
+
var maxHeight = this.tiles.reduce(function (max, t) {
|
|
181
|
+
var h = t.imageSize(scale).height;
|
|
182
|
+
return h > max ? h : max;
|
|
183
|
+
}, 0);
|
|
184
|
+
var sumWidth = this.tiles.reduce(function (sum, t) {
|
|
185
|
+
return sum + t.imageSize(scale).width;
|
|
186
|
+
}, 0);
|
|
187
|
+
return { width: sumWidth, height: maxHeight };
|
|
188
|
+
};
|
|
180
189
|
return Block;
|
|
181
190
|
}());
|
|
182
191
|
exports.Block = Block;
|
|
@@ -203,8 +212,10 @@ var BlockAnKan = (function (_super) {
|
|
|
203
212
|
}
|
|
204
213
|
BlockAnKan.prototype.toString = function () {
|
|
205
214
|
var tiles = this.tiles.map(function (t) { return t.clone(); });
|
|
206
|
-
tiles
|
|
207
|
-
|
|
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);
|
|
218
|
+
}
|
|
208
219
|
return tiles.reduce(function (s, t) {
|
|
209
220
|
return "".concat(s).concat(t.toString());
|
|
210
221
|
}, "");
|
package/dist/mjs/lib/table.d.ts
CHANGED
|
@@ -7,4 +7,6 @@ export declare const createTable: (helper: ImageHelper, fontCtx: FontContext, ha
|
|
|
7
7
|
width: number;
|
|
8
8
|
height: number;
|
|
9
9
|
};
|
|
10
|
-
export declare const drawTable: (svg: Svg, tableInput: string, config: ImageHelperConfig | undefined, fontCtx: FontContext
|
|
10
|
+
export declare const drawTable: (svg: Svg, tableInput: string, config: ImageHelperConfig | undefined, fontCtx: FontContext, params?: {
|
|
11
|
+
responsive: boolean;
|
|
12
|
+
}) => void;
|
package/dist/mjs/lib/table.js
CHANGED
|
@@ -1,9 +1,11 @@
|
|
|
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("./parser");
|
|
4
5
|
var image_1 = require("./image");
|
|
5
6
|
var svg_js_1 = require("@svgdotjs/svg.js");
|
|
6
7
|
var table_parser_1 = require("./table-parser");
|
|
8
|
+
var constants_1 = require("./constants");
|
|
7
9
|
var splitTiles = function (input) {
|
|
8
10
|
var chunkSize = 6;
|
|
9
11
|
var result = [];
|
|
@@ -43,7 +45,9 @@ var handleDiscard = function (tiles, helper) {
|
|
|
43
45
|
for (var i = 0; i < chunks.length; i++) {
|
|
44
46
|
var tiles_1 = chunks[i];
|
|
45
47
|
var posY = i * helper.tileHeight;
|
|
46
|
-
var e = helper
|
|
48
|
+
var e = helper
|
|
49
|
+
.createBlockHandDiscard(new parser_1.Block(tiles_1, constants_1.BLOCK.DISCARD))
|
|
50
|
+
.translate(0, posY);
|
|
47
51
|
g.add(e);
|
|
48
52
|
}
|
|
49
53
|
return {
|
|
@@ -230,13 +234,16 @@ var createTable = function (helper, fontCtx, handsProps, discardsProps, scoreBoa
|
|
|
230
234
|
return { e: g, width: hands.width, height: hands.height };
|
|
231
235
|
};
|
|
232
236
|
exports.createTable = createTable;
|
|
233
|
-
var drawTable = function (svg, tableInput, config, fontCtx) {
|
|
237
|
+
var drawTable = function (svg, tableInput, config, fontCtx, params) {
|
|
234
238
|
if (config === void 0) { config = {}; }
|
|
239
|
+
if (params === void 0) { params = { responsive: false }; }
|
|
235
240
|
var helper = new image_1.ImageHelper(config);
|
|
236
241
|
var ctx = fontCtx;
|
|
237
242
|
var _a = (0, table_parser_1.parse)(tableInput), discards = _a.discards, hands = _a.hands, scoreBoard = _a.scoreBoard;
|
|
238
243
|
var table = (0, exports.createTable)(helper, ctx, hands, discards, scoreBoard);
|
|
239
|
-
|
|
244
|
+
if (!params.responsive)
|
|
245
|
+
svg.size(table.width, table.height);
|
|
246
|
+
svg.viewbox(0, 0, table.width, table.height);
|
|
240
247
|
svg.add(table.e);
|
|
241
248
|
};
|
|
242
249
|
exports.drawTable = drawTable;
|
package/dist/mjs/svg/_0.svg
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
<svg xmlns="http://www.w3.org/2000/svg"
|
|
1
|
+
<svg xmlns="http://www.w3.org/2000/svg" baseProfile="tiny" version="1.2" viewBox="0 0 66 90"><path fill="#c73" d="M0 0h66v90H0z"/></svg>
|