arcadible 0.1.28 → 0.1.29

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/package.json CHANGED
@@ -61,5 +61,5 @@
61
61
  "license": "Apache-2.0",
62
62
  "main": "./src/cli/index.js",
63
63
  "name": "arcadible",
64
- "version": "0.1.28"
64
+ "version": "0.1.29"
65
65
  }
@@ -4,7 +4,7 @@
4
4
 
5
5
  module.exports = {
6
6
  allowed: {
7
- a: ["href", "alt", "title"],
7
+ a: ["href", "title"],
8
8
  blockquote: [],
9
9
  em: [],
10
10
  h3: [],
@@ -16,5 +16,6 @@ module.exports = {
16
16
  p: [],
17
17
  strong: [],
18
18
  ul: [],
19
+ video: ["src", "alt", "title"],
19
20
  },
20
21
  };
@@ -4,5 +4,4 @@
4
4
 
5
5
  module.exports = {
6
6
  ".png": "image/png",
7
- ".svg": "image/svg+xml",
8
7
  };
package/src/phrase.js CHANGED
@@ -41,7 +41,7 @@ const docAttrInvalid = function (tag, attr, value) {
41
41
  // [function]
42
42
 
43
43
  const docAttrUnallowed = function (tag, attr) {
44
- return `Attribute '${attr}' is not allowed on the '${tag}' tag.`;
44
+ return `Attribute '${attr}' is not permitted on the '${tag}' tag.`;
45
45
  };
46
46
 
47
47
  // [function]
@@ -52,6 +52,12 @@ const docSanitizeFailed = function () {
52
52
 
53
53
  // [function]
54
54
 
55
+ const docTagUnallowed = function (tag) {
56
+ return `Tag '${tag}' is not permitted.`;
57
+ };
58
+
59
+ // [function]
60
+
55
61
  const docUnsupported = function () {
56
62
  return "Document has an unsupported file type.";
57
63
  };
@@ -382,6 +388,7 @@ module.exports = {
382
388
  docAttrInvalid,
383
389
  docAttrUnallowed,
384
390
  docSanitizeFailed,
391
+ docTagUnallowed,
385
392
  docUnsupported,
386
393
  gameExists,
387
394
  gameVersionExists,
@@ -45,11 +45,16 @@ const videoCheck = check.video;
45
45
  // [declare]
46
46
 
47
47
  const HANDLE = cfgproduct.handle;
48
+
49
+ // [declare]
50
+
51
+ const GALLERY = `.${HANDLE}/gallery`;
48
52
  const MEDIA = `.${HANDLE}`;
49
53
 
50
54
  // [declare]
51
55
 
52
- const GALLERY = `${MEDIA}/gallery`;
56
+ const MAX_SIZE_MP4 = size.mb(15);
57
+ const MAX_SIZE_PNG = size.mb(2);
53
58
 
54
59
  // [function]
55
60
 
@@ -185,6 +190,33 @@ const zMp4 = function (field, root, opts) {
185
190
 
186
191
  // [function]
187
192
 
193
+ const zPngMp4 = function (field, root, optsPng, optsMp4) {
194
+ const pngSchema = zPng(field, root, optsPng);
195
+ const mp4Schema = zMp4(field, root, optsMp4);
196
+ return z.string().superRefine((file, ctx) => {
197
+ let schema = null;
198
+ if (file?.endsWith(".png")) {
199
+ schema = pngSchema;
200
+ }
201
+ if (file?.endsWith(".mp4")) {
202
+ schema = mp4Schema;
203
+ }
204
+ if (!schema) {
205
+ ctx.addIssue({
206
+ code: "custom",
207
+ ...message(field, ["Must be a PNG or MP4 file."]),
208
+ });
209
+ return;
210
+ }
211
+ const result = schema.safeParse(file);
212
+ if (!result.success) {
213
+ result.error.issues.forEach((issue) => ctx.addIssue(issue));
214
+ }
215
+ });
216
+ };
217
+
218
+ // [function]
219
+
188
220
  const zVimeo = function () {
189
221
  return z
190
222
  .string()
@@ -224,7 +256,7 @@ const zBanner = function (root) {
224
256
  return z.optional(
225
257
  zPng(field, root, {
226
258
  aspect: "2:1",
227
- maxSize: size.mb(2),
259
+ maxSize: MAX_SIZE_PNG,
228
260
  minHeight: 512,
229
261
  minWidth: 1024,
230
262
  }),
@@ -238,7 +270,7 @@ const zBannerVideo = function (root) {
238
270
  return z.optional(
239
271
  zMp4(field, root, {
240
272
  aspect: "2:1",
241
- maxSize: size.mb(15),
273
+ maxSize: MAX_SIZE_MP4,
242
274
  minHeight: 512,
243
275
  minWidth: 1024,
244
276
  }),
@@ -259,7 +291,7 @@ const zCover = function (root) {
259
291
  return z.optional(
260
292
  zPng(field, root, {
261
293
  aspect: "3:2",
262
- maxSize: size.mb(2),
294
+ maxSize: MAX_SIZE_PNG,
263
295
  minHeight: 512,
264
296
  minWidth: 768,
265
297
  }),
@@ -273,7 +305,7 @@ const zCoverVideo = function (root) {
273
305
  return z.optional(
274
306
  zMp4(field, root, {
275
307
  aspect: "3:2",
276
- maxSize: size.mb(15),
308
+ maxSize: MAX_SIZE_MP4,
277
309
  minHeight: 512,
278
310
  minWidth: 768,
279
311
  }),
@@ -308,44 +340,22 @@ const zGallery = function (root) {
308
340
  return z.optional(
309
341
  zSetBasefile(
310
342
  field,
311
- zMedia(field, root).superRefine((file, ctx) => {
312
- if (file.endsWith(".png")) {
313
- const issues = imageCheck(root, file, {
314
- maxSize: size.mb(2),
315
- type: cfgimage[".png"],
316
- });
317
- if (issues.length) {
318
- ctx.addIssue({
319
- code: "custom",
320
- ...message(field, [`Invalid PNG: ${file}`, ...issues]),
321
- });
322
- }
323
- } else if (file.endsWith(".svg")) {
324
- const issues = imageCheck(root, file, {
325
- maxSize: size.mb(1),
326
- type: cfgimage[".svg"],
327
- });
328
- if (issues.length) {
329
- ctx.addIssue({
330
- code: "custom",
331
- ...message(field, [`Invalid SVG: ${file}`, ...issues]),
332
- });
333
- }
334
- } else if (file.endsWith(".mp4")) {
335
- const issues = videoCheck(root, file, {
336
- maxDuration: 30,
337
- maxSize: size.mb(15),
338
- minDuration: 3,
339
- type: cfgvideo[".mp4"],
340
- });
341
- if (issues.length) {
342
- ctx.addIssue({
343
- code: "custom",
344
- ...message(field, [`Invalid MP4: ${file}`, ...issues]),
345
- });
346
- }
347
- }
348
- }),
343
+ zPngMp4(
344
+ field,
345
+ root,
346
+ // png
347
+ {
348
+ maxSize: MAX_SIZE_PNG,
349
+ minHeight: 512,
350
+ minWidth: 512,
351
+ },
352
+ // mp4
353
+ {
354
+ maxSize: MAX_SIZE_MP4,
355
+ minHeight: 512,
356
+ minWidth: 512,
357
+ },
358
+ ),
349
359
  { max: 8 * 3, min: 1 },
350
360
  ),
351
361
  );
@@ -379,7 +389,7 @@ const zIcon = function (root) {
379
389
  return z.optional(
380
390
  zPng(field, root, {
381
391
  aspect: "1:1",
382
- maxSize: size.mb(2),
392
+ maxSize: MAX_SIZE_PNG,
383
393
  minHeight: 512,
384
394
  minWidth: 512,
385
395
  }),
@@ -393,7 +403,7 @@ const zIconVideo = function (root) {
393
403
  return z.optional(
394
404
  zMp4(field, root, {
395
405
  aspect: "1:1",
396
- maxSize: size.mb(15),
406
+ maxSize: MAX_SIZE_MP4,
397
407
  minHeight: 512,
398
408
  minWidth: 512,
399
409
  }),
@@ -439,7 +449,7 @@ const zPoster = function (root) {
439
449
  return z.optional(
440
450
  zPng(field, root, {
441
451
  aspect: "2:3",
442
- maxSize: size.mb(2),
452
+ maxSize: MAX_SIZE_PNG,
443
453
  minHeight: 768,
444
454
  minWidth: 512,
445
455
  }),
@@ -453,7 +463,7 @@ const zPosterVideo = function (root) {
453
463
  return z.optional(
454
464
  zMp4(field, root, {
455
465
  aspect: "2:3",
456
- maxSize: size.mb(15),
466
+ maxSize: MAX_SIZE_MP4,
457
467
  minHeight: 768,
458
468
  minWidth: 512,
459
469
  }),
@@ -486,7 +496,7 @@ const zSplash = function (root) {
486
496
  return z.optional(
487
497
  zPng(field, root, {
488
498
  aspect: "16:9",
489
- maxSize: size.mb(2),
499
+ maxSize: MAX_SIZE_PNG,
490
500
  minHeight: 576,
491
501
  minWidth: 1024,
492
502
  }),
@@ -500,7 +510,7 @@ const zSplashVideo = function (root) {
500
510
  return z.optional(
501
511
  zMp4(field, root, {
502
512
  aspect: "16:9",
503
- maxSize: size.mb(15),
513
+ maxSize: MAX_SIZE_MP4,
504
514
  minHeight: 576,
505
515
  minWidth: 1024,
506
516
  }),
package/src/util/doc.js CHANGED
@@ -36,10 +36,15 @@ const checkHtml = function (str, { allowed, hooks }) {
36
36
  if (!checkAllowed(str, allowed, hooks, issues)) {
37
37
  if (issues) {
38
38
  return issues.map((issue) => {
39
- const { attrName, attrValue, isAllowed, nodeName } = issue;
40
- return isAllowed
41
- ? phrase.docAttrInvalid(nodeName, attrName, attrValue)
42
- : phrase.docAttrUnallowed(nodeName, attrName);
39
+ const { attrName, attrValue, isAllowed, isValid, nodeName } = issue;
40
+ if (!isAllowed) {
41
+ return Object.hasOwn(allowed, nodeName)
42
+ ? phrase.docAttrUnallowed(nodeName, attrName)
43
+ : phrase.docTagUnallowed(nodeName);
44
+ }
45
+ return isValid
46
+ ? phrase.docSanitizeFailed()
47
+ : phrase.docAttrInvalid(nodeName, attrName, attrValue);
43
48
  });
44
49
  }
45
50
  return [phrase.docSanitizeFailed()];
package/src/util/image.js CHANGED
@@ -71,19 +71,9 @@ const checkPng = function (file, { aspect, maxSize, minHeight, minWidth }) {
71
71
 
72
72
  // [function]
73
73
 
74
- const checkSvg = function (file, { maxSize }) {
75
- if (!checkSize(file, maxSize)) {
76
- return [phrase.imageSizeMax(formatBytes(maxSize))];
77
- }
78
- return [];
79
- };
80
-
81
- // [function]
82
-
83
74
  const check = function (file, { type, ...opts }) {
84
75
  const checks = {
85
76
  [cfgimage[".png"]]: checkPng,
86
- [cfgimage[".svg"]]: checkSvg,
87
77
  };
88
78
  const checkImage = checks[type];
89
79
  return checkImage && cfgimage[extname(file)] === type