@konoui/mjimage 0.0.16 → 0.0.18

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.
@@ -13,6 +13,7 @@ var __assign = (this && this.__assign) || function () {
13
13
  Object.defineProperty(exports, "__esModule", { value: true });
14
14
  exports.mjimage = void 0;
15
15
  var core_1 = require("./core");
16
+ var image_1 = require("./image");
16
17
  var measure_text_1 = require("./measure-text");
17
18
  var table_1 = require("./table");
18
19
  var svg_js_1 = require("@svgdotjs/svg.js");
@@ -65,7 +66,7 @@ var mjimage = (function () {
65
66
  else {
66
67
  var scale = calculateScale(handScale, textHeight);
67
68
  var blocks = new core_1.Parser(input).parse();
68
- (0, core_1.drawBlocks)(svg, blocks, __assign(__assign({}, props), { svgSprite: svgSprite, scale: scale }), { responsive: responsive });
69
+ (0, image_1.drawBlocks)(svg, blocks, __assign(__assign({}, props), { svgSprite: svgSprite, scale: scale }), { responsive: responsive });
69
70
  }
70
71
  svg.addTo(target);
71
72
  }
@@ -1,152 +1,57 @@
1
- import { z } from "zod";
1
+ import { InferOutput } from "valibot";
2
2
  import { Tile, Block } from "../core/parser";
3
3
  import { WIND_MAP, ROUND_MAP } from "../core/constants";
4
- declare const tableInputSchema: z.ZodObject<{
5
- "1w": z.ZodDefault<z.ZodOptional<z.ZodObject<{
6
- discard: z.ZodDefault<z.ZodOptional<z.ZodString>>;
7
- hand: z.ZodDefault<z.ZodOptional<z.ZodString>>;
8
- score: z.ZodDefault<z.ZodOptional<z.ZodNumber>>;
9
- }, "strict", z.ZodTypeAny, {
10
- discard: string;
11
- hand: string;
12
- score: number;
13
- }, {
14
- discard?: string | undefined;
15
- hand?: string | undefined;
16
- score?: number | undefined;
17
- }>>>;
18
- "2w": z.ZodDefault<z.ZodOptional<z.ZodObject<{
19
- discard: z.ZodDefault<z.ZodOptional<z.ZodString>>;
20
- hand: z.ZodDefault<z.ZodOptional<z.ZodString>>;
21
- score: z.ZodDefault<z.ZodOptional<z.ZodNumber>>;
22
- }, "strict", z.ZodTypeAny, {
23
- discard: string;
24
- hand: string;
25
- score: number;
26
- }, {
27
- discard?: string | undefined;
28
- hand?: string | undefined;
29
- score?: number | undefined;
30
- }>>>;
31
- "3w": z.ZodDefault<z.ZodOptional<z.ZodObject<{
32
- discard: z.ZodDefault<z.ZodOptional<z.ZodString>>;
33
- hand: z.ZodDefault<z.ZodOptional<z.ZodString>>;
34
- score: z.ZodDefault<z.ZodOptional<z.ZodNumber>>;
35
- }, "strict", z.ZodTypeAny, {
36
- discard: string;
37
- hand: string;
38
- score: number;
39
- }, {
40
- discard?: string | undefined;
41
- hand?: string | undefined;
42
- score?: number | undefined;
43
- }>>>;
44
- "4w": z.ZodDefault<z.ZodOptional<z.ZodObject<{
45
- discard: z.ZodDefault<z.ZodOptional<z.ZodString>>;
46
- hand: z.ZodDefault<z.ZodOptional<z.ZodString>>;
47
- score: z.ZodDefault<z.ZodOptional<z.ZodNumber>>;
48
- }, "strict", z.ZodTypeAny, {
49
- discard: string;
50
- hand: string;
51
- score: number;
52
- }, {
53
- discard?: string | undefined;
54
- hand?: string | undefined;
55
- score?: number | undefined;
56
- }>>>;
57
- board: z.ZodObject<{
58
- round: z.ZodDefault<z.ZodOptional<z.ZodUnion<readonly [z.ZodLiteral<"1w1" | "1w2" | "1w3" | "1w4" | "2w1" | "2w2" | "2w3" | "2w4" | "3w1" | "3w2" | "3w3" | "3w4" | "4w1" | "4w2" | "4w3" | "4w4">, z.ZodLiteral<"1w1" | "1w2" | "1w3" | "1w4" | "2w1" | "2w2" | "2w3" | "2w4" | "3w1" | "3w2" | "3w3" | "3w4" | "4w1" | "4w2" | "4w3" | "4w4">, ...z.ZodLiteral<"1w1" | "1w2" | "1w3" | "1w4" | "2w1" | "2w2" | "2w3" | "2w4" | "3w1" | "3w2" | "3w3" | "3w4" | "4w1" | "4w2" | "4w3" | "4w4">[]]>>>;
59
- sticks: z.ZodDefault<z.ZodOptional<z.ZodObject<{
60
- reach: z.ZodDefault<z.ZodOptional<z.ZodNumber>>;
61
- dead: z.ZodDefault<z.ZodOptional<z.ZodNumber>>;
62
- }, "strip", z.ZodTypeAny, {
63
- reach: number;
64
- dead: number;
65
- }, {
66
- reach?: number | undefined;
67
- dead?: number | undefined;
68
- }>>>;
69
- doras: z.ZodDefault<z.ZodOptional<z.ZodArray<z.ZodString, "many">>>;
70
- front: z.ZodDefault<z.ZodOptional<z.ZodUnion<readonly [z.ZodLiteral<"1w" | "2w" | "3w" | "4w">, z.ZodLiteral<"1w" | "2w" | "3w" | "4w">, ...z.ZodLiteral<"1w" | "2w" | "3w" | "4w">[]]>>>;
71
- }, "strict", z.ZodTypeAny, {
72
- round: "1w1" | "1w2" | "1w3" | "1w4" | "2w1" | "2w2" | "2w3" | "2w4" | "3w1" | "3w2" | "3w3" | "3w4" | "4w1" | "4w2" | "4w3" | "4w4";
73
- front: "1w" | "2w" | "3w" | "4w";
74
- sticks: {
75
- reach: number;
76
- dead: number;
77
- };
78
- doras: string[];
79
- }, {
80
- round?: "1w1" | "1w2" | "1w3" | "1w4" | "2w1" | "2w2" | "2w3" | "2w4" | "3w1" | "3w2" | "3w3" | "3w4" | "4w1" | "4w2" | "4w3" | "4w4" | undefined;
81
- sticks?: {
82
- reach?: number | undefined;
83
- dead?: number | undefined;
84
- } | undefined;
85
- doras?: string[] | undefined;
86
- front?: "1w" | "2w" | "3w" | "4w" | undefined;
4
+ declare const tableInputSchema: import("valibot").StrictObjectSchema<{
5
+ readonly board: import("valibot").StrictObjectSchema<{
6
+ readonly round: import("valibot").OptionalSchema<import("valibot").PicklistSchema<("1w1" | "1w2" | "1w3" | "1w4" | "2w1" | "2w2" | "2w3" | "2w4" | "3w1" | "3w2" | "3w3" | "3w4" | "4w1" | "4w2" | "4w3" | "4w4")[], undefined>, "1w1">;
7
+ readonly sticks: import("valibot").OptionalSchema<import("valibot").StrictObjectSchema<{
8
+ readonly reach: import("valibot").OptionalSchema<import("valibot").SchemaWithPipe<[import("valibot").NumberSchema<undefined>, import("valibot").MinValueAction<number, 0, "">, import("valibot").MaxValueAction<number, 9, "">]>, 0>;
9
+ readonly dead: import("valibot").OptionalSchema<import("valibot").SchemaWithPipe<[import("valibot").NumberSchema<undefined>, import("valibot").MinValueAction<number, 0, "">, import("valibot").MaxValueAction<number, 9, "">]>, 0>;
10
+ }, undefined>, {
11
+ readonly reach: 0;
12
+ readonly dead: 0;
13
+ }>;
14
+ readonly doras: import("valibot").OptionalSchema<import("valibot").ArraySchema<import("valibot").StringSchema<undefined>, undefined>, readonly ["3w"]>;
15
+ readonly front: import("valibot").OptionalSchema<import("valibot").PicklistSchema<("1w" | "2w" | "3w" | "4w")[], undefined>, "1w">;
16
+ }, undefined>;
17
+ readonly "1w": import("valibot").OptionalSchema<import("valibot").StrictObjectSchema<{
18
+ readonly discard: import("valibot").OptionalSchema<import("valibot").StringSchema<undefined>, "">;
19
+ readonly hand: import("valibot").OptionalSchema<import("valibot").StringSchema<undefined>, "">;
20
+ readonly score: import("valibot").OptionalSchema<import("valibot").NumberSchema<undefined>, 25000>;
21
+ }, undefined>, {
22
+ readonly discard: "";
23
+ readonly hand: "";
24
+ readonly score: 25000;
87
25
  }>;
88
- }, "strict", z.ZodTypeAny, {
89
- "1w": {
90
- discard: string;
91
- hand: string;
92
- score: number;
93
- };
94
- "2w": {
95
- discard: string;
96
- hand: string;
97
- score: number;
98
- };
99
- "3w": {
100
- discard: string;
101
- hand: string;
102
- score: number;
103
- };
104
- "4w": {
105
- discard: string;
106
- hand: string;
107
- score: number;
108
- };
109
- board: {
110
- round: "1w1" | "1w2" | "1w3" | "1w4" | "2w1" | "2w2" | "2w3" | "2w4" | "3w1" | "3w2" | "3w3" | "3w4" | "4w1" | "4w2" | "4w3" | "4w4";
111
- front: "1w" | "2w" | "3w" | "4w";
112
- sticks: {
113
- reach: number;
114
- dead: number;
115
- };
116
- doras: string[];
117
- };
118
- }, {
119
- board: {
120
- round?: "1w1" | "1w2" | "1w3" | "1w4" | "2w1" | "2w2" | "2w3" | "2w4" | "3w1" | "3w2" | "3w3" | "3w4" | "4w1" | "4w2" | "4w3" | "4w4" | undefined;
121
- sticks?: {
122
- reach?: number | undefined;
123
- dead?: number | undefined;
124
- } | undefined;
125
- doras?: string[] | undefined;
126
- front?: "1w" | "2w" | "3w" | "4w" | undefined;
127
- };
128
- "1w"?: {
129
- discard?: string | undefined;
130
- hand?: string | undefined;
131
- score?: number | undefined;
132
- } | undefined;
133
- "2w"?: {
134
- discard?: string | undefined;
135
- hand?: string | undefined;
136
- score?: number | undefined;
137
- } | undefined;
138
- "3w"?: {
139
- discard?: string | undefined;
140
- hand?: string | undefined;
141
- score?: number | undefined;
142
- } | undefined;
143
- "4w"?: {
144
- discard?: string | undefined;
145
- hand?: string | undefined;
146
- score?: number | undefined;
147
- } | undefined;
148
- }>;
149
- export type TableInput = z.infer<typeof tableInputSchema>;
26
+ readonly "2w": import("valibot").OptionalSchema<import("valibot").StrictObjectSchema<{
27
+ readonly discard: import("valibot").OptionalSchema<import("valibot").StringSchema<undefined>, "">;
28
+ readonly hand: import("valibot").OptionalSchema<import("valibot").StringSchema<undefined>, "">;
29
+ readonly score: import("valibot").OptionalSchema<import("valibot").NumberSchema<undefined>, 25000>;
30
+ }, undefined>, {
31
+ readonly discard: "";
32
+ readonly hand: "";
33
+ readonly score: 25000;
34
+ }>;
35
+ readonly "3w": import("valibot").OptionalSchema<import("valibot").StrictObjectSchema<{
36
+ readonly discard: import("valibot").OptionalSchema<import("valibot").StringSchema<undefined>, "">;
37
+ readonly hand: import("valibot").OptionalSchema<import("valibot").StringSchema<undefined>, "">;
38
+ readonly score: import("valibot").OptionalSchema<import("valibot").NumberSchema<undefined>, 25000>;
39
+ }, undefined>, {
40
+ readonly discard: "";
41
+ readonly hand: "";
42
+ readonly score: 25000;
43
+ }>;
44
+ readonly "4w": import("valibot").OptionalSchema<import("valibot").StrictObjectSchema<{
45
+ readonly discard: import("valibot").OptionalSchema<import("valibot").StringSchema<undefined>, "">;
46
+ readonly hand: import("valibot").OptionalSchema<import("valibot").StringSchema<undefined>, "">;
47
+ readonly score: import("valibot").OptionalSchema<import("valibot").NumberSchema<undefined>, 25000>;
48
+ }, undefined>, {
49
+ readonly discard: "";
50
+ readonly hand: "";
51
+ readonly score: 25000;
52
+ }>;
53
+ }, undefined>;
54
+ export type TableInput = InferOutput<typeof tableInputSchema>;
150
55
  export interface DiscardsInput {
151
56
  front: Tile[];
152
57
  right: Tile[];
@@ -1,53 +1,43 @@
1
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
+ };
2
13
  var _a;
3
14
  Object.defineProperty(exports, "__esModule", { value: true });
4
15
  exports.convertInput = exports.parseTableInput = exports.parse = void 0;
5
16
  var js_yaml_1 = require("js-yaml");
6
- var zod_1 = require("zod");
17
+ var valibot_1 = require("valibot");
7
18
  var parser_1 = require("../core/parser");
8
19
  var constants_1 = require("../core/constants");
9
- var windInputSchema = zod_1.z
10
- .object({
11
- discard: zod_1.z.string().max(50).optional().default(""),
12
- hand: zod_1.z.string().max(25).optional().default(""),
13
- score: zod_1.z.number().optional().default(25000),
14
- })
15
- .strict()
16
- .optional()
17
- .default({ discard: "", hand: "", score: 25000 });
18
- var windInputsSchema = zod_1.z
19
- .object((_a = {},
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 = {},
20
26
  _a[constants_1.WIND.EAST] = windInputSchema,
21
27
  _a[constants_1.WIND.SOUTH] = windInputSchema,
22
28
  _a[constants_1.WIND.WEST] = windInputSchema,
23
29
  _a[constants_1.WIND.NORTH] = windInputSchema,
24
- _a))
25
- .strict();
26
- function unionOfLiterals(constants) {
27
- var literals = constants.map(function (x) { return zod_1.z.literal(x); });
28
- return zod_1.z.union(literals);
29
- }
30
- var boardInputSchema = zod_1.z
31
- .object({
32
- round: unionOfLiterals(Object.keys(constants_1.ROUND_MAP))
33
- .optional()
34
- .default("1w1"),
35
- sticks: zod_1.z
36
- .object({
37
- reach: zod_1.z.number().max(9).gte(0).optional().default(0),
38
- dead: zod_1.z.number().max(9).gte(0).optional().default(0),
39
- })
40
- .optional()
41
- .default({ reach: 0, dead: 0 }),
42
- doras: zod_1.z.array(zod_1.z.string()).max(4).optional().default(["3w"]),
43
- front: unionOfLiterals(Object.keys(constants_1.WIND_MAP))
44
- .optional()
45
- .default("1w"),
46
- })
47
- .strict();
48
- var tableInputSchema = windInputsSchema.extend({
49
- board: boardInputSchema,
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"),
50
39
  });
40
+ var tableInputSchema = (0, valibot_1.strictObject)(__assign(__assign({}, windInputsSchema.entries), { board: boardInputSchema }));
51
41
  var parse = function (s) {
52
42
  var d = (0, exports.parseTableInput)(s);
53
43
  return (0, exports.convertInput)(d);
@@ -55,11 +45,11 @@ var parse = function (s) {
55
45
  exports.parse = parse;
56
46
  var parseTableInput = function (s) {
57
47
  var rawInput = (0, js_yaml_1.load)(s);
58
- var ret = tableInputSchema.safeParse(rawInput.table);
48
+ var ret = (0, valibot_1.safeParse)(tableInputSchema, rawInput.table);
59
49
  if (!ret.success) {
60
- throw ret.error;
50
+ throw ret.issues;
61
51
  }
62
- return ret.data;
52
+ return ret.output;
63
53
  };
64
54
  exports.parseTableInput = parseTableInput;
65
55
  var convertInput = function (i) {
@@ -1,7 +1,7 @@
1
- import { ImageHelper, ImageHelperConfig } from "../core/image";
1
+ import { ImageHelper, ImageHelperConfig } from "../image/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");
5
- var image_1 = require("../core/image");
4
+ var core_1 = require("../core/");
5
+ var image_1 = require("../image/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.16",
3
+ "version": "0.0.18",
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
  ],
@@ -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",
@@ -63,20 +65,20 @@
63
65
  "assert": "^2.1.0",
64
66
  "buffer": "^6.0.3",
65
67
  "jest": "^29.7.0",
66
- "parcel": "^2.9.3",
68
+ "parcel": "^2.12.0",
67
69
  "parcel-reporter-static-files-copy": "^1.5.2",
68
70
  "process": "^0.11.10",
69
71
  "svg-sprite": "^2.0.2",
70
72
  "svgdom": "0.1.14",
71
73
  "svgo": "^3.0.2",
72
74
  "ts-jest": "^29.1.1",
73
- "typescript": "^5.2.2"
75
+ "typescript": "^5.5.4"
74
76
  },
75
77
  "dependencies": {
76
78
  "@svgdotjs/svg.js": "^3.2.4",
77
79
  "eventmit": "^2.0.4",
78
80
  "js-yaml": "^4.1.0",
79
- "xstate": "^5.7.0",
80
- "zod": "^3.22.4"
81
+ "valibot": "^0.40.0",
82
+ "xstate": "^5.7.0"
81
83
  }
82
84
  }