@markuplint/types 4.0.0-alpha.6 → 4.0.0-alpha.7

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 (3) hide show
  1. package/LICENSE +1 -1
  2. package/lib/defs.js +72 -42
  3. package/package.json +8 -4
package/LICENSE CHANGED
@@ -1,6 +1,6 @@
1
1
  MIT License
2
2
 
3
- Copyright (c) 2017-2023 Yusuke Hirao
3
+ Copyright (c) 2017-2024 Yusuke Hirao
4
4
 
5
5
  Permission is hereby granted, free of charge, to any person obtaining a copy
6
6
  of this software and associated documentation files (the "Software"), to deal
package/lib/defs.js CHANGED
@@ -405,51 +405,81 @@ export const types = {
405
405
  },
406
406
  Srcset: {
407
407
  ref: 'https://html.spec.whatwg.org/multipage/images.html#srcset-attributes',
408
- syntax: {
409
- apply: '<srcset>',
410
- def: {
411
- srcset: '<image-candidate-strings> [, <image-candidate-strings>]*',
412
- 'image-candidate-strings': '<valid-non-empty-url> [ <width-descriptor> | <pixel-density-descriptor> ]?',
413
- 'valid-non-empty-url'(token, getNextToken) {
414
- if (!token) {
415
- return 0;
416
- }
417
- let willAdoptTokenLength = 0;
418
- do {
419
- if (token.type === 13) {
408
+ is(value) {
409
+ const images = value.split(',');
410
+ for (const image of images) {
411
+ // image candidate string
412
+ const [url, , descriptor, ...tail] = new TokenCollection(image.trim(), {
413
+ disallowToSurroundBySpaces: true,
414
+ separator: 'space',
415
+ });
416
+ if (!url) {
417
+ return unmatched(value, 'unexpected-token', {
418
+ expects: [
419
+ {
420
+ type: 'format',
421
+ value: 'valid non-empty URL',
422
+ },
423
+ ],
424
+ });
425
+ }
426
+ if (descriptor) {
427
+ const { num, unit } = splitUnit(descriptor.value);
428
+ switch (unit) {
429
+ case 'w': {
430
+ if (!isUint(num)) {
431
+ return unmatched(value, 'unexpected-token', {
432
+ expects: [
433
+ {
434
+ type: 'format',
435
+ value: 'width descriptor',
436
+ },
437
+ ],
438
+ });
439
+ }
420
440
  break;
421
441
  }
422
- willAdoptTokenLength++;
423
- } while ((token = getNextToken(willAdoptTokenLength)));
424
- return willAdoptTokenLength;
425
- },
426
- 'width-descriptor'(token) {
427
- if (!token) {
428
- return 0;
429
- }
430
- const { num, unit } = splitUnit(token.value);
431
- if (unit !== 'w') {
432
- return 0;
433
- }
434
- if (!isUint(num)) {
435
- return 0;
436
- }
437
- return 1;
438
- },
439
- 'pixel-density-descriptor'(token) {
440
- if (!token) {
441
- return 0;
442
- }
443
- const { num, unit } = splitUnit(token.value);
444
- if (unit !== 'x') {
445
- return 0;
446
- }
447
- if (!isFloat(num)) {
448
- return 0;
442
+ case 'x': {
443
+ if (!isFloat(num)) {
444
+ return unmatched(value, 'unexpected-token', {
445
+ expects: [
446
+ {
447
+ type: 'format',
448
+ value: 'pixel density descriptor',
449
+ },
450
+ ],
451
+ });
452
+ }
453
+ break;
454
+ }
455
+ default: {
456
+ return unmatched(value, 'unexpected-token', {
457
+ expects: [
458
+ {
459
+ type: 'format',
460
+ value: 'width descriptor',
461
+ },
462
+ {
463
+ type: 'format',
464
+ value: 'pixel density descriptor',
465
+ },
466
+ ],
467
+ });
468
+ }
449
469
  }
450
- return 1;
451
- },
452
- },
470
+ }
471
+ if (tail[0]) {
472
+ return unmatched(value, 'unexpected-token', {
473
+ expects: [
474
+ {
475
+ type: 'syntax',
476
+ value: 'image candidate string',
477
+ },
478
+ ],
479
+ });
480
+ }
481
+ }
482
+ return matched();
453
483
  },
454
484
  },
455
485
  SourceSizeList: {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@markuplint/types",
3
- "version": "4.0.0-alpha.6",
3
+ "version": "4.0.0-alpha.7",
4
4
  "description": "Type declaration and value checker",
5
5
  "repository": "git@github.com:markuplint/markuplint.git",
6
6
  "author": "Yusuke Hirao <yusukehirao@me.com>",
@@ -22,7 +22,11 @@
22
22
  "scripts": {
23
23
  "build": "tsc",
24
24
  "clean": "tsc --build --clean",
25
- "schema": "ts-node './gen/types.ts'; json2ts './types.schema.json' > './src/types.schema.ts'; prettier './src/types.schema.ts' './types.schema.json' --write; eslint './src/types.schema.ts' --fix; tsc;"
25
+ "schema": "run-s schema:types schema:schema build schema:prettier schema:eslint schema:prettier",
26
+ "schema:types": "node --loader ts-node/esm \"./gen/types.ts\"",
27
+ "schema:schema": "json2ts \"./types.schema.json\" > \"./src/types.schema.ts\"",
28
+ "schema:eslint": "eslint --fix \"./src/types.schema.ts\"",
29
+ "schema:prettier": "prettier --write \"./src/types.schema.ts\" \"./types.schema.json\" --log-level warn"
26
30
  },
27
31
  "dependencies": {
28
32
  "@types/css-tree": "^2.3.4",
@@ -32,8 +36,8 @@
32
36
  "css-tree": "^2.3.1",
33
37
  "debug": "^4.3.4",
34
38
  "leven": "^4.0.0",
35
- "type-fest": "^4.8.2",
39
+ "type-fest": "^4.9.0",
36
40
  "whatwg-mimetype": "^4.0.0"
37
41
  },
38
- "gitHead": "06e1242d274c72cf08a10a572b06ac35d1b924a4"
42
+ "gitHead": "571129bf6498541125e1e7c3907d5ed9af53459a"
39
43
  }