@logic-pad/core 0.20.0 → 0.21.0
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/assets/logic-core.global.d.ts +15 -0
- package/dist/data/rules/musicGridRule.js +5 -5
- package/dist/data/validateAsync.d.ts +15 -0
- package/dist/data/validateAsync.js +128 -0
- package/dist/data/validateAsyncWorker.d.ts +1 -0
- package/dist/data/validateAsyncWorker.js +9 -0
- package/dist/index.d.ts +2 -1
- package/dist/index.js +2 -1
- package/package.json +4 -2
|
@@ -3153,6 +3153,21 @@ declare global {
|
|
|
3153
3153
|
grid: GridData,
|
|
3154
3154
|
solution: GridData | null
|
|
3155
3155
|
): GridState;
|
|
3156
|
+
export declare class GridValidator {
|
|
3157
|
+
private worker;
|
|
3158
|
+
private stateListeners;
|
|
3159
|
+
private loadListeners;
|
|
3160
|
+
private readonly validateGridDebounced;
|
|
3161
|
+
readonly validateGrid: (grid: GridData, solution: GridData | null) => void;
|
|
3162
|
+
private readonly notifyState;
|
|
3163
|
+
readonly subscribeToState: (
|
|
3164
|
+
listener: (state: GridState) => void
|
|
3165
|
+
) => () => void;
|
|
3166
|
+
private readonly notifyLoad;
|
|
3167
|
+
readonly subscribeToLoad: (listener: () => void) => () => void;
|
|
3168
|
+
readonly isLoading: () => boolean;
|
|
3169
|
+
readonly delete: () => void;
|
|
3170
|
+
}
|
|
3156
3171
|
|
|
3157
3172
|
export { Symbol$1 as Symbol, escape$1 as escape, unescape$1 as unescape };
|
|
3158
3173
|
|
|
@@ -5,7 +5,7 @@ import { Color, Instrument, MajorRule, State, } from '../primitives.js';
|
|
|
5
5
|
import CustomIconSymbol from '../symbols/customIconSymbol.js';
|
|
6
6
|
import { ControlLine, Row } from './musicControlLine.js';
|
|
7
7
|
import Rule from './rule.js';
|
|
8
|
-
const
|
|
8
|
+
const DEFAULT_SCALE = [
|
|
9
9
|
new Row('C5', Instrument.Piano, null),
|
|
10
10
|
new Row('B4', Instrument.Piano, null),
|
|
11
11
|
new Row('A4', Instrument.Piano, null),
|
|
@@ -204,7 +204,7 @@ Object.defineProperty(MusicGridRule, "CONFIGS", {
|
|
|
204
204
|
value: Object.freeze([
|
|
205
205
|
{
|
|
206
206
|
type: ConfigType.ControlLines,
|
|
207
|
-
default: [new ControlLine(0, 120, false, false,
|
|
207
|
+
default: [new ControlLine(0, 120, false, false, DEFAULT_SCALE)],
|
|
208
208
|
field: 'controlLines',
|
|
209
209
|
description: 'Control Lines',
|
|
210
210
|
configurable: false,
|
|
@@ -217,7 +217,7 @@ Object.defineProperty(MusicGridRule, "CONFIGS", {
|
|
|
217
217
|
'wwwww',
|
|
218
218
|
'wwwww',
|
|
219
219
|
'wwwww',
|
|
220
|
-
]).addRule(new MusicGridRule([new ControlLine(0, 120, false, false,
|
|
220
|
+
]).addRule(new MusicGridRule([new ControlLine(0, 120, false, false, DEFAULT_SCALE)], null)),
|
|
221
221
|
field: 'track',
|
|
222
222
|
description: 'Track',
|
|
223
223
|
explanation: 'If set, this grid will be played instead of the solution.',
|
|
@@ -238,8 +238,8 @@ Object.defineProperty(MusicGridRule, "SEARCH_VARIANTS", {
|
|
|
238
238
|
configurable: true,
|
|
239
239
|
writable: true,
|
|
240
240
|
value: [
|
|
241
|
-
new MusicGridRule([new ControlLine(0, 120, false, false,
|
|
241
|
+
new MusicGridRule([new ControlLine(0, 120, false, false, DEFAULT_SCALE)], null).searchVariant(),
|
|
242
242
|
]
|
|
243
243
|
});
|
|
244
244
|
export default MusicGridRule;
|
|
245
|
-
export const instance = new MusicGridRule([new ControlLine(0, 120, false, false,
|
|
245
|
+
export const instance = new MusicGridRule([new ControlLine(0, 120, false, false, DEFAULT_SCALE)], null);
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import GridData from './grid.js';
|
|
2
|
+
import { GridState } from './primitives.js';
|
|
3
|
+
export declare class GridValidator {
|
|
4
|
+
private worker;
|
|
5
|
+
private stateListeners;
|
|
6
|
+
private loadListeners;
|
|
7
|
+
private readonly validateGridDebounced;
|
|
8
|
+
readonly validateGrid: (grid: GridData, solution: GridData | null) => void;
|
|
9
|
+
private readonly notifyState;
|
|
10
|
+
readonly subscribeToState: (listener: (state: GridState) => void) => () => void;
|
|
11
|
+
private readonly notifyLoad;
|
|
12
|
+
readonly subscribeToLoad: (listener: () => void) => () => void;
|
|
13
|
+
readonly isLoading: () => boolean;
|
|
14
|
+
readonly delete: () => void;
|
|
15
|
+
}
|
|
@@ -0,0 +1,128 @@
|
|
|
1
|
+
import debounce from 'lodash/debounce.js';
|
|
2
|
+
import { Serializer } from './serializer/allSerializers.js';
|
|
3
|
+
import validateGrid from './validate.js';
|
|
4
|
+
const SYNC_VALIDATION_THRESHOLD = 10000;
|
|
5
|
+
export class GridValidator {
|
|
6
|
+
constructor() {
|
|
7
|
+
Object.defineProperty(this, "worker", {
|
|
8
|
+
enumerable: true,
|
|
9
|
+
configurable: true,
|
|
10
|
+
writable: true,
|
|
11
|
+
value: null
|
|
12
|
+
});
|
|
13
|
+
Object.defineProperty(this, "stateListeners", {
|
|
14
|
+
enumerable: true,
|
|
15
|
+
configurable: true,
|
|
16
|
+
writable: true,
|
|
17
|
+
value: new Set()
|
|
18
|
+
});
|
|
19
|
+
Object.defineProperty(this, "loadListeners", {
|
|
20
|
+
enumerable: true,
|
|
21
|
+
configurable: true,
|
|
22
|
+
writable: true,
|
|
23
|
+
value: new Set()
|
|
24
|
+
});
|
|
25
|
+
Object.defineProperty(this, "validateGridDebounced", {
|
|
26
|
+
enumerable: true,
|
|
27
|
+
configurable: true,
|
|
28
|
+
writable: true,
|
|
29
|
+
value: debounce((grid, solution) => {
|
|
30
|
+
this.worker?.terminate();
|
|
31
|
+
this.worker = new Worker(new URL('./validateAsyncWorker.js', import.meta.url), { type: 'module' });
|
|
32
|
+
this.worker.onmessage = (event) => {
|
|
33
|
+
if (event.data) {
|
|
34
|
+
this.notifyState(event.data);
|
|
35
|
+
}
|
|
36
|
+
this.worker?.terminate();
|
|
37
|
+
this.worker = null;
|
|
38
|
+
this.notifyLoad();
|
|
39
|
+
};
|
|
40
|
+
this.worker.onmessageerror = (error) => {
|
|
41
|
+
console.error('Validation worker error:', error);
|
|
42
|
+
this.worker?.terminate();
|
|
43
|
+
this.worker = null;
|
|
44
|
+
this.notifyLoad();
|
|
45
|
+
};
|
|
46
|
+
this.worker.postMessage({
|
|
47
|
+
grid: Serializer.stringifyGrid(grid),
|
|
48
|
+
solution: solution ? Serializer.stringifyGrid(solution) : null,
|
|
49
|
+
});
|
|
50
|
+
this.notifyLoad();
|
|
51
|
+
}, 300, { leading: true, trailing: true })
|
|
52
|
+
});
|
|
53
|
+
Object.defineProperty(this, "validateGrid", {
|
|
54
|
+
enumerable: true,
|
|
55
|
+
configurable: true,
|
|
56
|
+
writable: true,
|
|
57
|
+
value: (grid, solution) => {
|
|
58
|
+
if (grid.width * grid.height <= SYNC_VALIDATION_THRESHOLD) {
|
|
59
|
+
// Synchronous validation for small grids
|
|
60
|
+
// to avoid the overhead of worker communication.
|
|
61
|
+
const state = validateGrid(grid, solution);
|
|
62
|
+
this.notifyState(state);
|
|
63
|
+
}
|
|
64
|
+
else {
|
|
65
|
+
this.validateGridDebounced(grid, solution);
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
});
|
|
69
|
+
Object.defineProperty(this, "notifyState", {
|
|
70
|
+
enumerable: true,
|
|
71
|
+
configurable: true,
|
|
72
|
+
writable: true,
|
|
73
|
+
value: (state) => {
|
|
74
|
+
this.stateListeners.forEach(listener => listener(state));
|
|
75
|
+
}
|
|
76
|
+
});
|
|
77
|
+
Object.defineProperty(this, "subscribeToState", {
|
|
78
|
+
enumerable: true,
|
|
79
|
+
configurable: true,
|
|
80
|
+
writable: true,
|
|
81
|
+
value: (listener) => {
|
|
82
|
+
this.stateListeners.add(listener);
|
|
83
|
+
return () => {
|
|
84
|
+
this.stateListeners.delete(listener);
|
|
85
|
+
};
|
|
86
|
+
}
|
|
87
|
+
});
|
|
88
|
+
Object.defineProperty(this, "notifyLoad", {
|
|
89
|
+
enumerable: true,
|
|
90
|
+
configurable: true,
|
|
91
|
+
writable: true,
|
|
92
|
+
value: () => {
|
|
93
|
+
this.loadListeners.forEach(listener => listener());
|
|
94
|
+
}
|
|
95
|
+
});
|
|
96
|
+
Object.defineProperty(this, "subscribeToLoad", {
|
|
97
|
+
enumerable: true,
|
|
98
|
+
configurable: true,
|
|
99
|
+
writable: true,
|
|
100
|
+
value: (listener) => {
|
|
101
|
+
this.loadListeners.add(listener);
|
|
102
|
+
return () => {
|
|
103
|
+
this.loadListeners.delete(listener);
|
|
104
|
+
};
|
|
105
|
+
}
|
|
106
|
+
});
|
|
107
|
+
Object.defineProperty(this, "isLoading", {
|
|
108
|
+
enumerable: true,
|
|
109
|
+
configurable: true,
|
|
110
|
+
writable: true,
|
|
111
|
+
value: () => {
|
|
112
|
+
return this.worker !== null;
|
|
113
|
+
}
|
|
114
|
+
});
|
|
115
|
+
Object.defineProperty(this, "delete", {
|
|
116
|
+
enumerable: true,
|
|
117
|
+
configurable: true,
|
|
118
|
+
writable: true,
|
|
119
|
+
value: () => {
|
|
120
|
+
if (this.worker) {
|
|
121
|
+
this.worker.terminate();
|
|
122
|
+
this.worker = null;
|
|
123
|
+
}
|
|
124
|
+
this.stateListeners.clear();
|
|
125
|
+
}
|
|
126
|
+
});
|
|
127
|
+
}
|
|
128
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { Serializer } from './serializer/allSerializers.js';
|
|
2
|
+
import validateGrid from './validate.js';
|
|
3
|
+
onmessage = e => {
|
|
4
|
+
const data = e.data;
|
|
5
|
+
const grid = Serializer.parseGrid(data.grid);
|
|
6
|
+
const solution = data.solution ? Serializer.parseGrid(data.solution) : null;
|
|
7
|
+
const state = validateGrid(grid, solution);
|
|
8
|
+
postMessage(state);
|
|
9
|
+
};
|
package/dist/index.d.ts
CHANGED
|
@@ -113,4 +113,5 @@ import ViewpointSymbol from './data/symbols/viewpointSymbol.js';
|
|
|
113
113
|
import TileData from './data/tile.js';
|
|
114
114
|
import TileConnections from './data/tileConnections.js';
|
|
115
115
|
import validateGrid, { aggregateState, applyFinalOverrides } from './data/validate.js';
|
|
116
|
-
|
|
116
|
+
import { GridValidator } from './data/validateAsync.js';
|
|
117
|
+
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, DRUM_SAMPLES, Direction, INSTRUMENTS, Instrument, MajorRule, Mode, ORIENTATIONS, Orientation, PuzzleType, State, WRAPPINGS, Wrapping, directionToggle, isDrumSample, orientationToggle, MetadataSchema, PuzzleSchema, getPuzzleTypes, puzzleEquals, validatePuzzleChecklist, BanPatternRule, CellCountPerZoneRule, CellCountRule, CompletePatternRule, ConnectAllRule, ContainsShapeRule, CustomRule, DifferentCountPerZoneRule, ForesightRule, allRules, LyingSymbolRule, ControlLine, Row, MusicGridRule, MysteryRule, OffByXRule, PerfectionRule, RegionAreaRule, RegionShapeRule, Rule, SameCountPerZoneRule, SameShapeRule, SymbolsPerRegionRule, UndercluedRule, UniqueShapeRule, WrapAroundRule, Serializer, Compressor, ChecksumCompressor, CompressorBase, DeflateCompressor, GzipCompressor, StreamCompressor, SerializerBase, SerializerChecksum, SerializerV0, OFFSETS, orientationChars, 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, HouseSymbol, allSymbols, LetterSymbol, LotusSymbol, MinesweeperSymbol, MultiEntrySymbol, MyopiaSymbol, NumberSymbol, Symbol, ViewpointSymbol, TileData, TileConnections, validateGrid, aggregateState, applyFinalOverrides, GridValidator, };
|
package/dist/index.js
CHANGED
|
@@ -116,4 +116,5 @@ import ViewpointSymbol from './data/symbols/viewpointSymbol.js';
|
|
|
116
116
|
import TileData from './data/tile.js';
|
|
117
117
|
import TileConnections from './data/tileConnections.js';
|
|
118
118
|
import validateGrid, { aggregateState, applyFinalOverrides } from './data/validate.js';
|
|
119
|
-
|
|
119
|
+
import { GridValidator } from './data/validateAsync.js';
|
|
120
|
+
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, DRUM_SAMPLES, Direction, INSTRUMENTS, Instrument, MajorRule, Mode, ORIENTATIONS, Orientation, PuzzleType, State, WRAPPINGS, Wrapping, directionToggle, isDrumSample, orientationToggle, MetadataSchema, PuzzleSchema, getPuzzleTypes, puzzleEquals, validatePuzzleChecklist, BanPatternRule, CellCountPerZoneRule, CellCountRule, CompletePatternRule, ConnectAllRule, ContainsShapeRule, CustomRule, DifferentCountPerZoneRule, ForesightRule, allRules, LyingSymbolRule, ControlLine, Row, MusicGridRule, MysteryRule, OffByXRule, PerfectionRule, RegionAreaRule, RegionShapeRule, Rule, SameCountPerZoneRule, SameShapeRule, SymbolsPerRegionRule, UndercluedRule, UniqueShapeRule, WrapAroundRule, Serializer, Compressor, ChecksumCompressor, CompressorBase, DeflateCompressor, GzipCompressor, StreamCompressor, SerializerBase, SerializerChecksum, SerializerV0, OFFSETS, orientationChars, 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, HouseSymbol, allSymbols, LetterSymbol, LotusSymbol, MinesweeperSymbol, MultiEntrySymbol, MyopiaSymbol, NumberSymbol, Symbol, ViewpointSymbol, TileData, TileConnections, validateGrid, aggregateState, applyFinalOverrides, GridValidator, };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@logic-pad/core",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.21.0",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"files": [
|
|
6
6
|
"dist",
|
|
@@ -54,6 +54,7 @@
|
|
|
54
54
|
"compression-streams-polyfill": "^0.1.7",
|
|
55
55
|
"event-iterator": "^2.0.0",
|
|
56
56
|
"grilops": "^0.1.2",
|
|
57
|
+
"lodash": "^4.17.21",
|
|
57
58
|
"logic-pad-solver-core": "^0.1.2",
|
|
58
59
|
"z3-solver": "^4.13.0",
|
|
59
60
|
"zod": "^4.0.17"
|
|
@@ -61,6 +62,7 @@
|
|
|
61
62
|
"devDependencies": {
|
|
62
63
|
"@types/bun": "^1.2.20",
|
|
63
64
|
"@types/glob": "^9.0.0",
|
|
65
|
+
"@types/lodash": "^4.17.20",
|
|
64
66
|
"dts-bundle-generator": "^9.5.1",
|
|
65
67
|
"fast-glob": "^3.3.3",
|
|
66
68
|
"prettier": "^3.6.2",
|
|
@@ -70,4 +72,4 @@
|
|
|
70
72
|
"trustedDependencies": [
|
|
71
73
|
"esbuild"
|
|
72
74
|
]
|
|
73
|
-
}
|
|
75
|
+
}
|