@logic-pad/core 0.12.1 → 0.12.3

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.
@@ -1489,7 +1489,21 @@ declare global {
1489
1489
  * Get the types of a puzzle based on its grid properties. The returned types are ordered by their priority.
1490
1490
  * The first type is the most important one.
1491
1491
  */
1492
- export declare function getPuzzleTypes(puzzle: Puzzle): PuzzleType[];
1492
+ export declare function getPuzzleTypes(grid: GridData): PuzzleType[];
1493
+ export interface PuzzleChecklistItem {
1494
+ id: string;
1495
+ success: boolean;
1496
+ mandatory: boolean;
1497
+ }
1498
+ export interface PuzzleChecklist {
1499
+ items: PuzzleChecklistItem[];
1500
+ isValid: boolean;
1501
+ }
1502
+ export declare function validatePuzzleChecklist(
1503
+ metadata: PuzzleMetadata,
1504
+ gridWithSolution: GridData,
1505
+ state: GridState
1506
+ ): PuzzleChecklist;
1493
1507
  export interface ShapeElement {
1494
1508
  x: number;
1495
1509
  y: number;
@@ -1,6 +1,6 @@
1
1
  import { z } from 'zod';
2
2
  import GridData from './grid.js';
3
- import { PuzzleType } from './primitives.js';
3
+ import { GridState, PuzzleType } from './primitives.js';
4
4
  export type PuzzleMetadata = {
5
5
  /**
6
6
  * The title of the puzzle. (required)
@@ -80,4 +80,14 @@ export type Puzzle = PuzzleMetadata & PuzzleData;
80
80
  * Get the types of a puzzle based on its grid properties. The returned types are ordered by their priority.
81
81
  * The first type is the most important one.
82
82
  */
83
- export declare function getPuzzleTypes(puzzle: Puzzle): PuzzleType[];
83
+ export declare function getPuzzleTypes(grid: GridData): PuzzleType[];
84
+ export interface PuzzleChecklistItem {
85
+ id: string;
86
+ success: boolean;
87
+ mandatory: boolean;
88
+ }
89
+ export interface PuzzleChecklist {
90
+ items: PuzzleChecklistItem[];
91
+ isValid: boolean;
92
+ }
93
+ export declare function validatePuzzleChecklist(metadata: PuzzleMetadata, gridWithSolution: GridData, state: GridState): PuzzleChecklist;
@@ -1,6 +1,6 @@
1
1
  import { z } from 'zod';
2
2
  import GridData from './grid.js';
3
- import { PuzzleType } from './primitives.js';
3
+ import { Color, PuzzleType, State } from './primitives.js';
4
4
  export const MetadataSchema = z
5
5
  .object({
6
6
  title: z.string().min(1),
@@ -23,18 +23,18 @@ export const PuzzleSchema = z
23
23
  * Get the types of a puzzle based on its grid properties. The returned types are ordered by their priority.
24
24
  * The first type is the most important one.
25
25
  */
26
- export function getPuzzleTypes(puzzle) {
26
+ export function getPuzzleTypes(grid) {
27
27
  const types = [];
28
28
  let logic = true;
29
- if (puzzle.grid.musicGrid.value) {
29
+ if (grid.musicGrid.value) {
30
30
  types.push(PuzzleType.Music);
31
31
  logic = false;
32
32
  }
33
- if (puzzle.grid.completePattern.value) {
33
+ if (grid.completePattern.value) {
34
34
  types.push(PuzzleType.Pattern);
35
35
  logic = false;
36
36
  }
37
- if (puzzle.grid.underclued.value) {
37
+ if (grid.underclued.value) {
38
38
  types.push(PuzzleType.Underclued);
39
39
  }
40
40
  if (logic) {
@@ -42,3 +42,45 @@ export function getPuzzleTypes(puzzle) {
42
42
  }
43
43
  return types;
44
44
  }
45
+ export function validatePuzzleChecklist(metadata, gridWithSolution, state) {
46
+ const checklist = {
47
+ items: [],
48
+ isValid: true,
49
+ };
50
+ checklist.items.push({
51
+ id: 'metadataValid',
52
+ success: MetadataSchema.safeParse(metadata).success,
53
+ mandatory: true,
54
+ });
55
+ if (gridWithSolution.requireSolution()) {
56
+ checklist.items.push({
57
+ id: 'autoValidation',
58
+ success: false,
59
+ mandatory: false,
60
+ });
61
+ checklist.items.push({
62
+ id: 'solutionIsNotEmpty',
63
+ success: gridWithSolution.tiles.some(row => row.some(tile => !tile.fixed && tile.color !== Color.Gray)),
64
+ mandatory: true,
65
+ });
66
+ }
67
+ else {
68
+ checklist.items.push({
69
+ id: 'autoValidation',
70
+ success: true,
71
+ mandatory: false,
72
+ });
73
+ checklist.items.push({
74
+ id: 'solutionIsComplete',
75
+ success: gridWithSolution.isComplete(),
76
+ mandatory: true,
77
+ });
78
+ checklist.items.push({
79
+ id: 'solutionIsValid',
80
+ success: state.final !== State.Error,
81
+ mandatory: true,
82
+ });
83
+ }
84
+ checklist.isValid = !checklist.items.some(x => !x.success && x.mandatory);
85
+ return checklist;
86
+ }
package/dist/index.d.ts CHANGED
@@ -14,7 +14,7 @@ import GridConnections from './data/gridConnections.js';
14
14
  import GridZones from './data/gridZones.js';
15
15
  import Instruction from './data/instruction.js';
16
16
  import { COMPARISONS, Color, Comparison, DIRECTIONS, Direction, MajorRule, Mode, ORIENTATIONS, Orientation, PuzzleType, State, WRAPPINGS, Wrapping, directionToggle, orientationToggle } from './data/primitives.js';
17
- import { MetadataSchema, PuzzleSchema, getPuzzleTypes } from './data/puzzle.js';
17
+ import { MetadataSchema, PuzzleSchema, getPuzzleTypes, validatePuzzleChecklist } from './data/puzzle.js';
18
18
  import BanPatternRule from './data/rules/banPatternRule.js';
19
19
  import CellCountPerZoneRule from './data/rules/cellCountPerZoneRule.js';
20
20
  import CellCountRule from './data/rules/cellCountRule.js';
@@ -108,4 +108,4 @@ import ViewpointSymbol from './data/symbols/viewpointSymbol.js';
108
108
  import TileData from './data/tile.js';
109
109
  import TileConnections from './data/tileConnections.js';
110
110
  import validateGrid, { aggregateState, applyFinalOverrides } from './data/validate.js';
111
- export { ConfigType, configEquals, Configurable, CachedAccess, allEqual, array, directionToRotation, escape, isSameEdge, maxBy, minBy, move, orientationToRotation, resize, unescape, isEventHandler, handlesFinalValidation, handlesGetTile, handlesGridChange, handlesGridResize, handlesSetGrid, invokeSetGrid, handlesSymbolDisplay, handlesSymbolValidation, GridData, NEIGHBOR_OFFSETS, GridConnections, GridZones, Instruction, COMPARISONS, Color, Comparison, DIRECTIONS, Direction, MajorRule, Mode, ORIENTATIONS, Orientation, PuzzleType, State, WRAPPINGS, Wrapping, directionToggle, orientationToggle, MetadataSchema, PuzzleSchema, getPuzzleTypes, BanPatternRule, CellCountPerZoneRule, CellCountRule, CompletePatternRule, ConnectAllRule, ContainsShapeRule, CustomRule, ForesightRule, allRules, LyingSymbolRule, ControlLine, Row, MusicGridRule, MysteryRule, OffByXRule, PerfectionRule, RegionAreaRule, RegionShapeRule, Rule, SameShapeRule, SymbolsPerRegionRule, UndercluedRule, UniqueShapeRule, WrapAroundRule, Serializer, Compressor, CompressorBase, DeflateCompressor, GzipCompressor, StreamCompressor, SerializerBase, SerializerV0, getShapeVariants, normalizeShape, positionsToShape, sanitizePatternGrid, shapeEquals, tilesToShape, allSolvers, AutoSolver, BacktrackSolver, BTModule, BTGridData, BTTile, IntArray2D, colorToBTTile, createOneTileResult, getOppositeColor, BanPatternBTModule, CellCountBTModule, ConnectAllBTModule, RegionAreaBTModule, RegionShapeBTModule, SameShapeBTModule, SymbolsPerRegionBTModule, UniqueShapeBTModule, AreaNumberBTModule, DartBTModule, DirectionLinkerBTModule, FocusBTModule, GalaxyBTModule, LetterBTModule, LotusBTModule, MinesweeperBTModule, MyopiaBTModule, ViewpointBTModule, CspuzSolver, gridToJson, EventIteratingSolver, Solver, UniversalSolver, AreaNumberModule, CellCountModule, ConnectAllModule, DartModule, allZ3Modules, LetterModule, MyopiaModule, RegionAreaModule, ViewpointModule, Z3Module, convertDirection, Z3Solver, Z3SolverContext, AreaNumberSymbol, CustomIconSymbol, CustomSymbol, CustomTextSymbol, DartSymbol, DirectionLinkerSymbol, FocusSymbol, GalaxySymbol, HiddenSymbol, allSymbols, LetterSymbol, LotusSymbol, MinesweeperSymbol, MultiEntrySymbol, MyopiaSymbol, NumberSymbol, Symbol, ViewpointSymbol, TileData, TileConnections, validateGrid, aggregateState, applyFinalOverrides, };
111
+ export { ConfigType, configEquals, Configurable, CachedAccess, allEqual, array, directionToRotation, escape, isSameEdge, maxBy, minBy, move, orientationToRotation, resize, unescape, isEventHandler, handlesFinalValidation, handlesGetTile, handlesGridChange, handlesGridResize, handlesSetGrid, invokeSetGrid, handlesSymbolDisplay, handlesSymbolValidation, GridData, NEIGHBOR_OFFSETS, GridConnections, GridZones, Instruction, COMPARISONS, Color, Comparison, DIRECTIONS, Direction, MajorRule, Mode, ORIENTATIONS, Orientation, PuzzleType, State, WRAPPINGS, Wrapping, directionToggle, orientationToggle, MetadataSchema, PuzzleSchema, getPuzzleTypes, validatePuzzleChecklist, BanPatternRule, CellCountPerZoneRule, CellCountRule, CompletePatternRule, ConnectAllRule, ContainsShapeRule, CustomRule, ForesightRule, allRules, LyingSymbolRule, ControlLine, Row, MusicGridRule, MysteryRule, OffByXRule, PerfectionRule, RegionAreaRule, RegionShapeRule, Rule, SameShapeRule, SymbolsPerRegionRule, UndercluedRule, UniqueShapeRule, WrapAroundRule, Serializer, Compressor, CompressorBase, DeflateCompressor, GzipCompressor, StreamCompressor, SerializerBase, SerializerV0, getShapeVariants, normalizeShape, positionsToShape, sanitizePatternGrid, shapeEquals, tilesToShape, allSolvers, AutoSolver, BacktrackSolver, BTModule, BTGridData, BTTile, IntArray2D, colorToBTTile, createOneTileResult, getOppositeColor, BanPatternBTModule, CellCountBTModule, ConnectAllBTModule, RegionAreaBTModule, RegionShapeBTModule, SameShapeBTModule, SymbolsPerRegionBTModule, UniqueShapeBTModule, AreaNumberBTModule, DartBTModule, DirectionLinkerBTModule, FocusBTModule, GalaxyBTModule, LetterBTModule, LotusBTModule, MinesweeperBTModule, MyopiaBTModule, ViewpointBTModule, CspuzSolver, gridToJson, EventIteratingSolver, Solver, UniversalSolver, AreaNumberModule, CellCountModule, ConnectAllModule, DartModule, allZ3Modules, LetterModule, MyopiaModule, RegionAreaModule, ViewpointModule, Z3Module, convertDirection, Z3Solver, Z3SolverContext, AreaNumberSymbol, CustomIconSymbol, CustomSymbol, CustomTextSymbol, DartSymbol, DirectionLinkerSymbol, FocusSymbol, GalaxySymbol, HiddenSymbol, allSymbols, LetterSymbol, LotusSymbol, MinesweeperSymbol, MultiEntrySymbol, MyopiaSymbol, NumberSymbol, Symbol, ViewpointSymbol, TileData, TileConnections, validateGrid, aggregateState, applyFinalOverrides, };
package/dist/index.js CHANGED
@@ -17,7 +17,7 @@ import GridConnections from './data/gridConnections.js';
17
17
  import GridZones from './data/gridZones.js';
18
18
  import Instruction from './data/instruction.js';
19
19
  import { COMPARISONS, Color, Comparison, DIRECTIONS, Direction, MajorRule, Mode, ORIENTATIONS, Orientation, PuzzleType, State, WRAPPINGS, Wrapping, directionToggle, orientationToggle } from './data/primitives.js';
20
- import { MetadataSchema, PuzzleSchema, getPuzzleTypes } from './data/puzzle.js';
20
+ import { MetadataSchema, PuzzleSchema, getPuzzleTypes, validatePuzzleChecklist } from './data/puzzle.js';
21
21
  import BanPatternRule from './data/rules/banPatternRule.js';
22
22
  import CellCountPerZoneRule from './data/rules/cellCountPerZoneRule.js';
23
23
  import CellCountRule from './data/rules/cellCountRule.js';
@@ -111,4 +111,4 @@ import ViewpointSymbol from './data/symbols/viewpointSymbol.js';
111
111
  import TileData from './data/tile.js';
112
112
  import TileConnections from './data/tileConnections.js';
113
113
  import validateGrid, { aggregateState, applyFinalOverrides } from './data/validate.js';
114
- export { ConfigType, configEquals, Configurable, CachedAccess, allEqual, array, directionToRotation, escape, isSameEdge, maxBy, minBy, move, orientationToRotation, resize, unescape, isEventHandler, handlesFinalValidation, handlesGetTile, handlesGridChange, handlesGridResize, handlesSetGrid, invokeSetGrid, handlesSymbolDisplay, handlesSymbolValidation, GridData, NEIGHBOR_OFFSETS, GridConnections, GridZones, Instruction, COMPARISONS, Color, Comparison, DIRECTIONS, Direction, MajorRule, Mode, ORIENTATIONS, Orientation, PuzzleType, State, WRAPPINGS, Wrapping, directionToggle, orientationToggle, MetadataSchema, PuzzleSchema, getPuzzleTypes, BanPatternRule, CellCountPerZoneRule, CellCountRule, CompletePatternRule, ConnectAllRule, ContainsShapeRule, CustomRule, ForesightRule, allRules, LyingSymbolRule, ControlLine, Row, MusicGridRule, MysteryRule, OffByXRule, PerfectionRule, RegionAreaRule, RegionShapeRule, Rule, SameShapeRule, SymbolsPerRegionRule, UndercluedRule, UniqueShapeRule, WrapAroundRule, Serializer, Compressor, CompressorBase, DeflateCompressor, GzipCompressor, StreamCompressor, SerializerBase, SerializerV0, getShapeVariants, normalizeShape, positionsToShape, sanitizePatternGrid, shapeEquals, tilesToShape, allSolvers, AutoSolver, BacktrackSolver, BTModule, BTGridData, BTTile, IntArray2D, colorToBTTile, createOneTileResult, getOppositeColor, BanPatternBTModule, CellCountBTModule, ConnectAllBTModule, RegionAreaBTModule, RegionShapeBTModule, SameShapeBTModule, SymbolsPerRegionBTModule, UniqueShapeBTModule, AreaNumberBTModule, DartBTModule, DirectionLinkerBTModule, FocusBTModule, GalaxyBTModule, LetterBTModule, LotusBTModule, MinesweeperBTModule, MyopiaBTModule, ViewpointBTModule, CspuzSolver, gridToJson, EventIteratingSolver, Solver, UniversalSolver, AreaNumberModule, CellCountModule, ConnectAllModule, DartModule, allZ3Modules, LetterModule, MyopiaModule, RegionAreaModule, ViewpointModule, Z3Module, convertDirection, Z3Solver, Z3SolverContext, AreaNumberSymbol, CustomIconSymbol, CustomSymbol, CustomTextSymbol, DartSymbol, DirectionLinkerSymbol, FocusSymbol, GalaxySymbol, HiddenSymbol, allSymbols, LetterSymbol, LotusSymbol, MinesweeperSymbol, MultiEntrySymbol, MyopiaSymbol, NumberSymbol, Symbol, ViewpointSymbol, TileData, TileConnections, validateGrid, aggregateState, applyFinalOverrides, };
114
+ export { ConfigType, configEquals, Configurable, CachedAccess, allEqual, array, directionToRotation, escape, isSameEdge, maxBy, minBy, move, orientationToRotation, resize, unescape, isEventHandler, handlesFinalValidation, handlesGetTile, handlesGridChange, handlesGridResize, handlesSetGrid, invokeSetGrid, handlesSymbolDisplay, handlesSymbolValidation, GridData, NEIGHBOR_OFFSETS, GridConnections, GridZones, Instruction, COMPARISONS, Color, Comparison, DIRECTIONS, Direction, MajorRule, Mode, ORIENTATIONS, Orientation, PuzzleType, State, WRAPPINGS, Wrapping, directionToggle, orientationToggle, MetadataSchema, PuzzleSchema, getPuzzleTypes, validatePuzzleChecklist, BanPatternRule, CellCountPerZoneRule, CellCountRule, CompletePatternRule, ConnectAllRule, ContainsShapeRule, CustomRule, ForesightRule, allRules, LyingSymbolRule, ControlLine, Row, MusicGridRule, MysteryRule, OffByXRule, PerfectionRule, RegionAreaRule, RegionShapeRule, Rule, SameShapeRule, SymbolsPerRegionRule, UndercluedRule, UniqueShapeRule, WrapAroundRule, Serializer, Compressor, CompressorBase, DeflateCompressor, GzipCompressor, StreamCompressor, SerializerBase, SerializerV0, getShapeVariants, normalizeShape, positionsToShape, sanitizePatternGrid, shapeEquals, tilesToShape, allSolvers, AutoSolver, BacktrackSolver, BTModule, BTGridData, BTTile, IntArray2D, colorToBTTile, createOneTileResult, getOppositeColor, BanPatternBTModule, CellCountBTModule, ConnectAllBTModule, RegionAreaBTModule, RegionShapeBTModule, SameShapeBTModule, SymbolsPerRegionBTModule, UniqueShapeBTModule, AreaNumberBTModule, DartBTModule, DirectionLinkerBTModule, FocusBTModule, GalaxyBTModule, LetterBTModule, LotusBTModule, MinesweeperBTModule, MyopiaBTModule, ViewpointBTModule, CspuzSolver, gridToJson, EventIteratingSolver, Solver, UniversalSolver, AreaNumberModule, CellCountModule, ConnectAllModule, DartModule, allZ3Modules, LetterModule, MyopiaModule, RegionAreaModule, ViewpointModule, Z3Module, convertDirection, Z3Solver, Z3SolverContext, AreaNumberSymbol, CustomIconSymbol, CustomSymbol, CustomTextSymbol, DartSymbol, DirectionLinkerSymbol, FocusSymbol, GalaxySymbol, HiddenSymbol, allSymbols, LetterSymbol, LotusSymbol, MinesweeperSymbol, MultiEntrySymbol, MyopiaSymbol, NumberSymbol, Symbol, ViewpointSymbol, TileData, TileConnections, validateGrid, aggregateState, applyFinalOverrides, };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@logic-pad/core",
3
- "version": "0.12.1",
3
+ "version": "0.12.3",
4
4
  "type": "module",
5
5
  "files": [
6
6
  "dist",