@logic-pad/core 0.26.2 → 0.26.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.
Files changed (240) hide show
  1. package/assets/logic-core.global.d.ts +3264 -3264
  2. package/dist/benchmark/helper.d.ts +21 -0
  3. package/dist/benchmark/helper.js +34 -0
  4. package/dist/benchmark/prepareBench.d.ts +1 -0
  5. package/dist/benchmark/prepareBench.js +140 -0
  6. package/dist/benchmark/runBench.d.ts +1 -0
  7. package/dist/benchmark/runBench.js +206 -0
  8. package/dist/src/data/config.d.ts +119 -0
  9. package/dist/src/data/config.js +72 -0
  10. package/dist/src/data/configurable.d.ts +14 -0
  11. package/dist/src/data/configurable.js +26 -0
  12. package/dist/src/data/dataHelper.d.ts +92 -0
  13. package/dist/src/data/dataHelper.js +217 -0
  14. package/dist/src/data/events/eventHelper.d.ts +1 -0
  15. package/dist/src/data/events/eventHelper.js +6 -0
  16. package/dist/src/data/events/onFinalValidation.d.ts +14 -0
  17. package/dist/src/data/events/onFinalValidation.js +4 -0
  18. package/dist/src/data/events/onGetTile.d.ts +7 -0
  19. package/dist/src/data/events/onGetTile.js +4 -0
  20. package/dist/src/data/events/onGridChange.d.ts +6 -0
  21. package/dist/src/data/events/onGridChange.js +4 -0
  22. package/dist/src/data/events/onGridResize.d.ts +9 -0
  23. package/dist/src/data/events/onGridResize.js +4 -0
  24. package/dist/src/data/events/onSetGrid.d.ts +7 -0
  25. package/dist/src/data/events/onSetGrid.js +19 -0
  26. package/dist/src/data/events/onSymbolDisplay.d.ts +16 -0
  27. package/dist/src/data/events/onSymbolDisplay.js +4 -0
  28. package/dist/src/data/events/onSymbolMerge.d.ts +10 -0
  29. package/dist/src/data/events/onSymbolMerge.js +4 -0
  30. package/dist/src/data/events/onSymbolValidation.d.ts +18 -0
  31. package/dist/src/data/events/onSymbolValidation.js +4 -0
  32. package/dist/src/data/grid.d.ts +410 -0
  33. package/dist/src/data/grid.js +1106 -0
  34. package/dist/src/data/gridConnections.d.ts +25 -0
  35. package/dist/src/data/gridConnections.js +309 -0
  36. package/dist/src/data/gridZones.d.ts +26 -0
  37. package/dist/src/data/gridZones.js +117 -0
  38. package/dist/src/data/instruction.d.ts +26 -0
  39. package/dist/src/data/instruction.js +29 -0
  40. package/dist/src/data/primitives.d.ts +138 -0
  41. package/dist/src/data/primitives.js +177 -0
  42. package/dist/src/data/puzzle.d.ts +73 -0
  43. package/dist/src/data/puzzle.js +105 -0
  44. package/dist/src/data/rules/banPatternRule.d.ts +30 -0
  45. package/dist/src/data/rules/banPatternRule.js +125 -0
  46. package/dist/src/data/rules/cellCountPerZoneRule.d.ts +23 -0
  47. package/dist/src/data/rules/cellCountPerZoneRule.js +39 -0
  48. package/dist/src/data/rules/cellCountRule.d.ts +33 -0
  49. package/dist/src/data/rules/cellCountRule.js +138 -0
  50. package/dist/src/data/rules/completePatternRule.d.ts +24 -0
  51. package/dist/src/data/rules/completePatternRule.js +46 -0
  52. package/dist/src/data/rules/connectAllRule.d.ts +29 -0
  53. package/dist/src/data/rules/connectAllRule.js +88 -0
  54. package/dist/src/data/rules/connectZonesRule.d.ts +29 -0
  55. package/dist/src/data/rules/connectZonesRule.js +111 -0
  56. package/dist/src/data/rules/containsShapeRule.d.ts +34 -0
  57. package/dist/src/data/rules/containsShapeRule.js +125 -0
  58. package/dist/src/data/rules/customRule.d.ts +34 -0
  59. package/dist/src/data/rules/customRule.js +74 -0
  60. package/dist/src/data/rules/differentCountPerZoneRule.d.ts +30 -0
  61. package/dist/src/data/rules/differentCountPerZoneRule.js +96 -0
  62. package/dist/src/data/rules/exactCountPerZoneRule.d.ts +33 -0
  63. package/dist/src/data/rules/exactCountPerZoneRule.js +99 -0
  64. package/dist/src/data/rules/foresightRule.d.ts +36 -0
  65. package/dist/src/data/rules/foresightRule.js +107 -0
  66. package/dist/src/data/rules/index.d.ts +3 -0
  67. package/dist/src/data/rules/index.js +10 -0
  68. package/dist/src/data/rules/lyingSymbolRule.d.ts +31 -0
  69. package/dist/src/data/rules/lyingSymbolRule.js +207 -0
  70. package/dist/src/data/rules/musicControlLine.d.ts +82 -0
  71. package/dist/src/data/rules/musicControlLine.js +167 -0
  72. package/dist/src/data/rules/musicGridRule.d.ts +51 -0
  73. package/dist/src/data/rules/musicGridRule.js +212 -0
  74. package/dist/src/data/rules/mysteryRule.d.ts +39 -0
  75. package/dist/src/data/rules/mysteryRule.js +146 -0
  76. package/dist/src/data/rules/noLoopsRule.d.ts +29 -0
  77. package/dist/src/data/rules/noLoopsRule.js +218 -0
  78. package/dist/src/data/rules/offByXRule.d.ts +32 -0
  79. package/dist/src/data/rules/offByXRule.js +124 -0
  80. package/dist/src/data/rules/perfectionRule.d.ts +45 -0
  81. package/dist/src/data/rules/perfectionRule.js +158 -0
  82. package/dist/src/data/rules/regionAreaRule.d.ts +34 -0
  83. package/dist/src/data/rules/regionAreaRule.js +149 -0
  84. package/dist/src/data/rules/regionShapeRule.d.ts +22 -0
  85. package/dist/src/data/rules/regionShapeRule.js +58 -0
  86. package/dist/src/data/rules/rule.d.ts +18 -0
  87. package/dist/src/data/rules/rule.js +19 -0
  88. package/dist/src/data/rules/rules.gen.d.ts +23 -0
  89. package/dist/src/data/rules/rules.gen.js +27 -0
  90. package/dist/src/data/rules/sameCountPerZoneRule.d.ts +30 -0
  91. package/dist/src/data/rules/sameCountPerZoneRule.js +95 -0
  92. package/dist/src/data/rules/sameShapeRule.d.ts +28 -0
  93. package/dist/src/data/rules/sameShapeRule.js +68 -0
  94. package/dist/src/data/rules/symbolsPerRegionRule.d.ts +38 -0
  95. package/dist/src/data/rules/symbolsPerRegionRule.js +181 -0
  96. package/dist/src/data/rules/undercluedRule.d.ts +24 -0
  97. package/dist/src/data/rules/undercluedRule.js +53 -0
  98. package/dist/src/data/rules/uniqueShapeRule.d.ts +28 -0
  99. package/dist/src/data/rules/uniqueShapeRule.js +65 -0
  100. package/dist/src/data/rules/wrapAroundRule.d.ts +36 -0
  101. package/dist/src/data/rules/wrapAroundRule.js +241 -0
  102. package/dist/src/data/serializer/allSerializers.d.ts +35 -0
  103. package/dist/src/data/serializer/allSerializers.js +78 -0
  104. package/dist/src/data/serializer/compressor/allCompressors.d.ts +14 -0
  105. package/dist/src/data/serializer/compressor/allCompressors.js +43 -0
  106. package/dist/src/data/serializer/compressor/checksumCompressor.d.ts +6 -0
  107. package/dist/src/data/serializer/compressor/checksumCompressor.js +21 -0
  108. package/dist/src/data/serializer/compressor/compressorBase.d.ts +16 -0
  109. package/dist/src/data/serializer/compressor/compressorBase.js +2 -0
  110. package/dist/src/data/serializer/compressor/deflateCompressor.d.ts +7 -0
  111. package/dist/src/data/serializer/compressor/deflateCompressor.js +17 -0
  112. package/dist/src/data/serializer/compressor/gzipCompressor.d.ts +5 -0
  113. package/dist/src/data/serializer/compressor/gzipCompressor.js +9 -0
  114. package/dist/src/data/serializer/compressor/streamCompressor.d.ts +6 -0
  115. package/dist/src/data/serializer/compressor/streamCompressor.js +41 -0
  116. package/dist/src/data/serializer/serializerBase.d.ts +32 -0
  117. package/dist/src/data/serializer/serializerBase.js +2 -0
  118. package/dist/src/data/serializer/serializer_checksum.d.ts +35 -0
  119. package/dist/src/data/serializer/serializer_checksum.js +179 -0
  120. package/dist/src/data/serializer/serializer_v0.d.ts +55 -0
  121. package/dist/src/data/serializer/serializer_v0.js +484 -0
  122. package/dist/src/data/shapes.d.ts +19 -0
  123. package/dist/src/data/shapes.js +137 -0
  124. package/dist/src/data/solver/allSolvers.d.ts +3 -0
  125. package/dist/src/data/solver/allSolvers.js +13 -0
  126. package/dist/src/data/solver/auto/autoSolver.d.ts +18 -0
  127. package/dist/src/data/solver/auto/autoSolver.js +156 -0
  128. package/dist/src/data/solver/backtrack/backtrackSolver.d.ts +11 -0
  129. package/dist/src/data/solver/backtrack/backtrackSolver.js +54 -0
  130. package/dist/src/data/solver/backtrack/backtrackWorker.d.ts +1 -0
  131. package/dist/src/data/solver/backtrack/backtrackWorker.js +312 -0
  132. package/dist/src/data/solver/backtrack/data.d.ts +47 -0
  133. package/dist/src/data/solver/backtrack/data.js +151 -0
  134. package/dist/src/data/solver/backtrack/rules/banPattern.d.ts +9 -0
  135. package/dist/src/data/solver/backtrack/rules/banPattern.js +77 -0
  136. package/dist/src/data/solver/backtrack/rules/cellCount.d.ts +7 -0
  137. package/dist/src/data/solver/backtrack/rules/cellCount.js +25 -0
  138. package/dist/src/data/solver/backtrack/rules/connectAll.d.ts +7 -0
  139. package/dist/src/data/solver/backtrack/rules/connectAll.js +44 -0
  140. package/dist/src/data/solver/backtrack/rules/regionArea.d.ts +8 -0
  141. package/dist/src/data/solver/backtrack/rules/regionArea.js +71 -0
  142. package/dist/src/data/solver/backtrack/rules/regionShape.d.ts +8 -0
  143. package/dist/src/data/solver/backtrack/rules/regionShape.js +57 -0
  144. package/dist/src/data/solver/backtrack/rules/sameShape.d.ts +8 -0
  145. package/dist/src/data/solver/backtrack/rules/sameShape.js +14 -0
  146. package/dist/src/data/solver/backtrack/rules/symbolsPerRegion.d.ts +10 -0
  147. package/dist/src/data/solver/backtrack/rules/symbolsPerRegion.js +82 -0
  148. package/dist/src/data/solver/backtrack/rules/uniqueShape.d.ts +8 -0
  149. package/dist/src/data/solver/backtrack/rules/uniqueShape.js +14 -0
  150. package/dist/src/data/solver/backtrack/symbols/areaNumber.d.ts +9 -0
  151. package/dist/src/data/solver/backtrack/symbols/areaNumber.js +75 -0
  152. package/dist/src/data/solver/backtrack/symbols/dart.d.ts +8 -0
  153. package/dist/src/data/solver/backtrack/symbols/dart.js +45 -0
  154. package/dist/src/data/solver/backtrack/symbols/directionLinker.d.ts +11 -0
  155. package/dist/src/data/solver/backtrack/symbols/directionLinker.js +121 -0
  156. package/dist/src/data/solver/backtrack/symbols/focus.d.ts +9 -0
  157. package/dist/src/data/solver/backtrack/symbols/focus.js +48 -0
  158. package/dist/src/data/solver/backtrack/symbols/galaxy.d.ts +9 -0
  159. package/dist/src/data/solver/backtrack/symbols/galaxy.js +14 -0
  160. package/dist/src/data/solver/backtrack/symbols/letter.d.ts +9 -0
  161. package/dist/src/data/solver/backtrack/symbols/letter.js +95 -0
  162. package/dist/src/data/solver/backtrack/symbols/lotus.d.ts +11 -0
  163. package/dist/src/data/solver/backtrack/symbols/lotus.js +55 -0
  164. package/dist/src/data/solver/backtrack/symbols/minesweeper.d.ts +9 -0
  165. package/dist/src/data/solver/backtrack/symbols/minesweeper.js +44 -0
  166. package/dist/src/data/solver/backtrack/symbols/myopia.d.ts +7 -0
  167. package/dist/src/data/solver/backtrack/symbols/myopia.js +73 -0
  168. package/dist/src/data/solver/backtrack/symbols/viewpoint.d.ts +7 -0
  169. package/dist/src/data/solver/backtrack/symbols/viewpoint.js +51 -0
  170. package/dist/src/data/solver/cspuz/cspuzSolver.d.ts +13 -0
  171. package/dist/src/data/solver/cspuz/cspuzSolver.js +124 -0
  172. package/dist/src/data/solver/cspuz/cspuzWorker.d.ts +1 -0
  173. package/dist/src/data/solver/cspuz/cspuzWorker.js +82 -0
  174. package/dist/src/data/solver/cspuz/jsonify.d.ts +3 -0
  175. package/dist/src/data/solver/cspuz/jsonify.js +215 -0
  176. package/dist/src/data/solver/eventIteratingSolver.d.ts +8 -0
  177. package/dist/src/data/solver/eventIteratingSolver.js +54 -0
  178. package/dist/src/data/solver/solver.d.ts +77 -0
  179. package/dist/src/data/solver/solver.js +59 -0
  180. package/dist/src/data/solver/universal/universalSolver.d.ts +7 -0
  181. package/dist/src/data/solver/universal/universalSolver.js +13 -0
  182. package/dist/src/data/solver/universal/universalWorker.d.ts +1 -0
  183. package/dist/src/data/solver/universal/universalWorker.js +128 -0
  184. package/dist/src/data/symbols/areaNumberSymbol.d.ts +31 -0
  185. package/dist/src/data/symbols/areaNumberSymbol.js +80 -0
  186. package/dist/src/data/symbols/customIconSymbol.d.ts +35 -0
  187. package/dist/src/data/symbols/customIconSymbol.js +94 -0
  188. package/dist/src/data/symbols/customSymbol.d.ts +25 -0
  189. package/dist/src/data/symbols/customSymbol.js +45 -0
  190. package/dist/src/data/symbols/customTextSymbol.d.ts +35 -0
  191. package/dist/src/data/symbols/customTextSymbol.js +95 -0
  192. package/dist/src/data/symbols/dartSymbol.d.ts +36 -0
  193. package/dist/src/data/symbols/dartSymbol.js +96 -0
  194. package/dist/src/data/symbols/directionLinkerSymbol.d.ts +29 -0
  195. package/dist/src/data/symbols/directionLinkerSymbol.js +232 -0
  196. package/dist/src/data/symbols/everyLetterSymbol.d.ts +32 -0
  197. package/dist/src/data/symbols/everyLetterSymbol.js +119 -0
  198. package/dist/src/data/symbols/focusSymbol.d.ts +40 -0
  199. package/dist/src/data/symbols/focusSymbol.js +159 -0
  200. package/dist/src/data/symbols/galaxySymbol.d.ts +27 -0
  201. package/dist/src/data/symbols/galaxySymbol.js +61 -0
  202. package/dist/src/data/symbols/hiddenSymbol.d.ts +38 -0
  203. package/dist/src/data/symbols/hiddenSymbol.js +113 -0
  204. package/dist/src/data/symbols/houseSymbol.d.ts +33 -0
  205. package/dist/src/data/symbols/houseSymbol.js +104 -0
  206. package/dist/src/data/symbols/index.d.ts +3 -0
  207. package/dist/src/data/symbols/index.js +10 -0
  208. package/dist/src/data/symbols/letterSymbol.d.ts +32 -0
  209. package/dist/src/data/symbols/letterSymbol.js +118 -0
  210. package/dist/src/data/symbols/lotusSymbol.d.ts +30 -0
  211. package/dist/src/data/symbols/lotusSymbol.js +132 -0
  212. package/dist/src/data/symbols/minesweeperSymbol.d.ts +33 -0
  213. package/dist/src/data/symbols/minesweeperSymbol.js +106 -0
  214. package/dist/src/data/symbols/myopiaSymbol.d.ts +37 -0
  215. package/dist/src/data/symbols/myopiaSymbol.js +182 -0
  216. package/dist/src/data/symbols/numberSymbol.d.ts +19 -0
  217. package/dist/src/data/symbols/numberSymbol.js +32 -0
  218. package/dist/src/data/symbols/symbol.d.ts +29 -0
  219. package/dist/src/data/symbols/symbol.js +87 -0
  220. package/dist/src/data/symbols/symbols.gen.d.ts +15 -0
  221. package/dist/src/data/symbols/symbols.gen.js +19 -0
  222. package/dist/src/data/symbols/unsupportedSymbol.d.ts +23 -0
  223. package/dist/src/data/symbols/unsupportedSymbol.js +47 -0
  224. package/dist/src/data/symbols/viewpointSymbol.d.ts +32 -0
  225. package/dist/src/data/symbols/viewpointSymbol.js +95 -0
  226. package/dist/src/data/tile.d.ts +26 -0
  227. package/dist/src/data/tile.js +56 -0
  228. package/dist/src/data/tileConnections.d.ts +25 -0
  229. package/dist/src/data/tileConnections.js +74 -0
  230. package/dist/src/data/validate.d.ts +5 -0
  231. package/dist/src/data/validate.js +131 -0
  232. package/dist/src/data/validateAsync.d.ts +15 -0
  233. package/dist/src/data/validateAsync.js +71 -0
  234. package/dist/src/data/validateAsyncWorker.d.ts +1 -0
  235. package/dist/src/data/validateAsyncWorker.js +9 -0
  236. package/dist/src/index.d.ts +109 -0
  237. package/dist/src/index.js +112 -0
  238. package/dist/src/polyfill/streamPolyfill.d.ts +2 -0
  239. package/dist/src/polyfill/streamPolyfill.js +1 -0
  240. package/package.json +1 -1
@@ -0,0 +1,92 @@
1
+ import { Direction, Edge, Orientation, Position } from './primitives.js';
2
+ /**
3
+ * Offset the given position by a given step in the given direction.
4
+ * @param position The position to offset.
5
+ * @param direction The direction to offset in.
6
+ * @param step The distance to offset by.
7
+ * @returns The offset position.
8
+ */
9
+ export declare function move(position: Position, direction: Direction | Orientation, step?: number): {
10
+ x: number;
11
+ y: number;
12
+ };
13
+ /**
14
+ * Check if two edges are the same, regardless of direction.
15
+ * @param a The first edge.
16
+ * @param b The second edge.
17
+ * @returns Whether the edges are the same.
18
+ */
19
+ export declare function isSameEdge(a: Edge, b: Edge): boolean;
20
+ /**
21
+ * Convert the given direction to a rotation in degrees.
22
+ * @param direction The direction to convert.
23
+ * @returns The rotation in degrees.
24
+ */
25
+ export declare function directionToRotation(direction: Direction): 0 | 270 | 90 | 180;
26
+ /**
27
+ * Convert the given orientation to a rotation in degrees.
28
+ * @param orientation The orientation to convert.
29
+ * @returns The rotation in degrees.
30
+ */
31
+ export declare function orientationToRotation(orientation: Orientation): 0 | 270 | 90 | 180 | 225 | 125 | 315 | 45;
32
+ /**
33
+ * Create a new 2D array with the given dimensions and values.
34
+ * @param width The width of the array.
35
+ * @param height The height of the array.
36
+ * @param value A function that returns the value for each x,y coordinate.
37
+ * @returns The 2D array.
38
+ */
39
+ export declare function array<T>(width: number, height: number, value: (x: number, y: number) => T): T[][];
40
+ /**
41
+ * Resize the given array to the new size, cutting off or padding with the default value.
42
+ * @param array The array to resize.
43
+ * @param newSize The new size of the array.
44
+ * @param defaultValue A function that returns the default value for each new element.
45
+ * @returns The resized array.
46
+ */
47
+ export declare function resize<T>(array: T[], newSize: number, defaultValue: () => T): T[];
48
+ export declare function resize<T>(array: readonly T[], newSize: number, defaultValue: () => T): readonly T[];
49
+ /**
50
+ * Check if all the given values are equal.
51
+ * @param values The values to compare.
52
+ * @returns Whether all the values are equal.
53
+ */
54
+ export declare function allEqual<T>(...values: T[]): boolean;
55
+ /**
56
+ * Return the first element of the array which has the minimum mapped value.
57
+ *
58
+ * @param values The array of values.
59
+ * @param mapper The function to map each value to a number.
60
+ * @returns The first element with the minimum mapped value.
61
+ */
62
+ export declare function minBy<T>(values: readonly T[], mapper: (element: T) => number): T | undefined;
63
+ /**
64
+ * Return the first element of the array which has the maximum mapped value.
65
+ *
66
+ * @param values The array of values.
67
+ * @param mapper The function to map each value to a number.
68
+ * @returns The first element with the maximum mapped value.
69
+ */
70
+ export declare function maxBy<T>(values: readonly T[], mapper: (element: T) => number): T | undefined;
71
+ /**
72
+ * Escape the given text by replacing the specified characters with HTML escape sequences.
73
+ * @param text The text to escape.
74
+ * @param escapeCharacters The characters to escape.
75
+ * @returns The escaped text.
76
+ */
77
+ export declare function escape(text: string, escapeCharacters?: string): string;
78
+ /**
79
+ * Unescape the given text by replacing HTML escape sequences with the corresponding characters.
80
+ * @param text The text to unescape.
81
+ * @param escapeCharacters The characters to unescape. This should match the characters escaped by the `escape` function.
82
+ * @returns The unescaped text.
83
+ */
84
+ export declare function unescape(text: string, escapeCharacters?: string): string;
85
+ export declare class CachedAccess<T> {
86
+ private readonly getter;
87
+ private static readonly UNCACHED;
88
+ private cache;
89
+ private constructor();
90
+ static of<T>(getter: () => T): CachedAccess<T>;
91
+ get value(): T;
92
+ }
@@ -0,0 +1,217 @@
1
+ import { Direction, Orientation } from './primitives.js';
2
+ /**
3
+ * Offset the given position by a given step in the given direction.
4
+ * @param position The position to offset.
5
+ * @param direction The direction to offset in.
6
+ * @param step The distance to offset by.
7
+ * @returns The offset position.
8
+ */
9
+ export function move(position, direction, step = 1) {
10
+ switch (direction) {
11
+ case Direction.Up:
12
+ case Orientation.Up:
13
+ return { x: position.x, y: position.y - step };
14
+ case Direction.Down:
15
+ case Orientation.Down:
16
+ return { x: position.x, y: position.y + step };
17
+ case Direction.Left:
18
+ case Orientation.Left:
19
+ return { x: position.x - step, y: position.y };
20
+ case Direction.Right:
21
+ case Orientation.Right:
22
+ return { x: position.x + step, y: position.y };
23
+ case Orientation.UpLeft:
24
+ return { x: position.x - step, y: position.y - step };
25
+ case Orientation.UpRight:
26
+ return { x: position.x + step, y: position.y - step };
27
+ case Orientation.DownLeft:
28
+ return { x: position.x - step, y: position.y + step };
29
+ case Orientation.DownRight:
30
+ return { x: position.x + step, y: position.y + step };
31
+ }
32
+ }
33
+ /**
34
+ * Check if two edges are the same, regardless of direction.
35
+ * @param a The first edge.
36
+ * @param b The second edge.
37
+ * @returns Whether the edges are the same.
38
+ */
39
+ export function isSameEdge(a, b) {
40
+ return ((a.x1 === b.x1 && a.y1 === b.y1 && a.x2 === b.x2 && a.y2 === b.y2) ||
41
+ (a.x1 === b.x2 && a.y1 === b.y2 && a.x2 === b.x1 && a.y2 === b.y1));
42
+ }
43
+ /**
44
+ * Convert the given direction to a rotation in degrees.
45
+ * @param direction The direction to convert.
46
+ * @returns The rotation in degrees.
47
+ */
48
+ export function directionToRotation(direction) {
49
+ switch (direction) {
50
+ case Direction.Up:
51
+ return 0;
52
+ case Direction.Left:
53
+ return 270;
54
+ case Direction.Right:
55
+ return 90;
56
+ case Direction.Down:
57
+ return 180;
58
+ }
59
+ }
60
+ /**
61
+ * Convert the given orientation to a rotation in degrees.
62
+ * @param orientation The orientation to convert.
63
+ * @returns The rotation in degrees.
64
+ */
65
+ export function orientationToRotation(orientation) {
66
+ switch (orientation) {
67
+ case Orientation.Up:
68
+ return 0;
69
+ case Orientation.Left:
70
+ return 270;
71
+ case Orientation.Right:
72
+ return 90;
73
+ case Orientation.Down:
74
+ return 180;
75
+ case Orientation.DownLeft:
76
+ return 225;
77
+ case Orientation.DownRight:
78
+ return 125;
79
+ case Orientation.UpLeft:
80
+ return 315;
81
+ case Orientation.UpRight:
82
+ return 45;
83
+ }
84
+ }
85
+ /**
86
+ * Create a new 2D array with the given dimensions and values.
87
+ * @param width The width of the array.
88
+ * @param height The height of the array.
89
+ * @param value A function that returns the value for each x,y coordinate.
90
+ * @returns The 2D array.
91
+ */
92
+ export function array(width, height, value) {
93
+ const result = [];
94
+ for (let y = 0; y < height; y++) {
95
+ result[y] = [];
96
+ for (let x = 0; x < width; x++) {
97
+ result[y][x] = value(x, y);
98
+ }
99
+ }
100
+ return result;
101
+ }
102
+ export function resize(array, newSize, defaultValue) {
103
+ if (array.length < newSize) {
104
+ return [
105
+ ...array,
106
+ ...Array.from({ length: newSize - array.length }, defaultValue),
107
+ ];
108
+ }
109
+ else if (array.length > newSize) {
110
+ return array.slice(0, newSize);
111
+ }
112
+ return array;
113
+ }
114
+ /**
115
+ * Check if all the given values are equal.
116
+ * @param values The values to compare.
117
+ * @returns Whether all the values are equal.
118
+ */
119
+ export function allEqual(...values) {
120
+ return values.every(value => value === values[0]);
121
+ }
122
+ /**
123
+ * Return the first element of the array which has the minimum mapped value.
124
+ *
125
+ * @param values The array of values.
126
+ * @param mapper The function to map each value to a number.
127
+ * @returns The first element with the minimum mapped value.
128
+ */
129
+ export function minBy(values, mapper) {
130
+ let min = Number.POSITIVE_INFINITY;
131
+ let result;
132
+ for (const value of values) {
133
+ const mapped = mapper(value);
134
+ if (mapped < min) {
135
+ min = mapped;
136
+ result = value;
137
+ }
138
+ }
139
+ return result;
140
+ }
141
+ /**
142
+ * Return the first element of the array which has the maximum mapped value.
143
+ *
144
+ * @param values The array of values.
145
+ * @param mapper The function to map each value to a number.
146
+ * @returns The first element with the maximum mapped value.
147
+ */
148
+ export function maxBy(values, mapper) {
149
+ let max = Number.NEGATIVE_INFINITY;
150
+ let result;
151
+ for (const value of values) {
152
+ const mapped = mapper(value);
153
+ if (mapped > max) {
154
+ max = mapped;
155
+ result = value;
156
+ }
157
+ }
158
+ return result;
159
+ }
160
+ /**
161
+ * Escape the given text by replacing the specified characters with HTML escape sequences.
162
+ * @param text The text to escape.
163
+ * @param escapeCharacters The characters to escape.
164
+ * @returns The escaped text.
165
+ */
166
+ export function escape(text, escapeCharacters = '=,:|') {
167
+ let result = '';
168
+ for (const char of text) {
169
+ if (escapeCharacters.includes(char) || char === '&') {
170
+ result += `&#${char.charCodeAt(0)};`;
171
+ }
172
+ else {
173
+ result += char;
174
+ }
175
+ }
176
+ return result;
177
+ }
178
+ /**
179
+ * Unescape the given text by replacing HTML escape sequences with the corresponding characters.
180
+ * @param text The text to unescape.
181
+ * @param escapeCharacters The characters to unescape. This should match the characters escaped by the `escape` function.
182
+ * @returns The unescaped text.
183
+ */
184
+ export function unescape(text, escapeCharacters = '=,:|') {
185
+ let result = '';
186
+ const matches = text.matchAll(/&#([0-9]+);/g);
187
+ let index = 0;
188
+ for (const match of matches) {
189
+ result += text.substring(index, match.index);
190
+ const char = String.fromCharCode(parseInt(match[1], 10));
191
+ if (escapeCharacters.includes(char) || char === '&') {
192
+ result += char;
193
+ }
194
+ else {
195
+ result += match[0];
196
+ }
197
+ index = match.index + match[0].length;
198
+ }
199
+ return result + text.substring(index);
200
+ }
201
+ export class CachedAccess {
202
+ getter;
203
+ static UNCACHED = Symbol('uncached');
204
+ cache = CachedAccess.UNCACHED;
205
+ constructor(getter) {
206
+ this.getter = getter;
207
+ }
208
+ static of(getter) {
209
+ return new CachedAccess(getter);
210
+ }
211
+ get value() {
212
+ if (this.cache === CachedAccess.UNCACHED) {
213
+ this.cache = this.getter();
214
+ }
215
+ return this.cache;
216
+ }
217
+ }
@@ -0,0 +1 @@
1
+ export declare function isEventHandler<T>(val: unknown, event: string): val is T;
@@ -0,0 +1,6 @@
1
+ export function isEventHandler(val, event) {
2
+ if (typeof val !== 'object' || val === null || val === undefined)
3
+ return false;
4
+ return (event in val &&
5
+ typeof val[event] === 'function');
6
+ }
@@ -0,0 +1,14 @@
1
+ import GridData from '../grid.js';
2
+ import Instruction from '../instruction.js';
3
+ import { GridState } from '../primitives.js';
4
+ export interface FinalValidationHandler {
5
+ /**
6
+ * Edits the final grid state after all rules and symbols have been validated.
7
+ *
8
+ * @param grid The grid that is being validated.
9
+ * @param solution The solution grid, or null if the solution is not available.
10
+ * @param state The current state of the grid.
11
+ */
12
+ onFinalValidation(grid: GridData, solution: GridData | null, state: GridState): GridState;
13
+ }
14
+ export declare function handlesFinalValidation<T extends Instruction>(val: T): val is T & FinalValidationHandler;
@@ -0,0 +1,4 @@
1
+ import { isEventHandler } from './eventHelper.js';
2
+ export function handlesFinalValidation(val) {
3
+ return isEventHandler(val, 'onFinalValidation');
4
+ }
@@ -0,0 +1,7 @@
1
+ import Instruction from '../instruction.js';
2
+ import { Position } from '../primitives.js';
3
+ import GridData from '../grid.js';
4
+ export interface GetTileHandler {
5
+ onGetTile(x: number, y: number, grid: GridData): Position;
6
+ }
7
+ export declare function handlesGetTile<T extends Instruction>(val: T): val is T & GetTileHandler;
@@ -0,0 +1,4 @@
1
+ import { isEventHandler } from './eventHelper.js';
2
+ export function handlesGetTile(val) {
3
+ return isEventHandler(val, 'onGetTile');
4
+ }
@@ -0,0 +1,6 @@
1
+ import GridData from '../grid.js';
2
+ import Instruction from '../instruction.js';
3
+ export interface GridChangeHandler {
4
+ onGridChange(newGrid: GridData): this;
5
+ }
6
+ export declare function handlesGridChange<T extends Instruction>(val: T): val is T & GridChangeHandler;
@@ -0,0 +1,4 @@
1
+ import { isEventHandler } from './eventHelper.js';
2
+ export function handlesGridChange(val) {
3
+ return isEventHandler(val, 'onGridChange');
4
+ }
@@ -0,0 +1,9 @@
1
+ import GridData from '../grid.js';
2
+ import Instruction from '../instruction.js';
3
+ export interface GridResizeHandler {
4
+ /**
5
+ * Update itself when the grid is resized.
6
+ */
7
+ onGridResize(grid: GridData, mode: 'insert' | 'remove', direction: 'row' | 'column', index: number): this | null;
8
+ }
9
+ export declare function handlesGridResize<T extends Instruction>(val: T): val is T & GridResizeHandler;
@@ -0,0 +1,4 @@
1
+ import { isEventHandler } from './eventHelper.js';
2
+ export function handlesGridResize(val) {
3
+ return isEventHandler(val, 'onGridResize');
4
+ }
@@ -0,0 +1,7 @@
1
+ import GridData from '../grid.js';
2
+ import Instruction from '../instruction.js';
3
+ export interface SetGridHandler {
4
+ onSetGrid(oldGrid: GridData, newGrid: GridData, solution: GridData | null): GridData;
5
+ }
6
+ export declare function handlesSetGrid<T extends Instruction>(val: T): val is T & SetGridHandler;
7
+ export declare function invokeSetGrid(oldGrid: GridData, newGrid: GridData, solution: GridData | null): GridData;
@@ -0,0 +1,19 @@
1
+ import { isEventHandler } from './eventHelper.js';
2
+ export function handlesSetGrid(val) {
3
+ return isEventHandler(val, 'onSetGrid');
4
+ }
5
+ export function invokeSetGrid(oldGrid, newGrid, solution) {
6
+ newGrid.symbols.forEach(list => {
7
+ list.forEach(symbol => {
8
+ if (handlesSetGrid(symbol)) {
9
+ newGrid = symbol.onSetGrid(oldGrid, newGrid, solution);
10
+ }
11
+ });
12
+ });
13
+ newGrid.rules.forEach(rule => {
14
+ if (handlesSetGrid(rule)) {
15
+ newGrid = rule.onSetGrid(oldGrid, newGrid, solution);
16
+ }
17
+ });
18
+ return newGrid;
19
+ }
@@ -0,0 +1,16 @@
1
+ import GridData from '../grid.js';
2
+ import Instruction from '../instruction.js';
3
+ import Symbol from '../symbols/symbol.js';
4
+ export interface SymbolDisplayHandler {
5
+ /**
6
+ * Controls whether a symbol should be visible in the grid.
7
+ *
8
+ * @param grid The grid that is being displayed.
9
+ * @param solution The solution grid, if it is available.
10
+ * @param symbol The symbol that is being displayed.
11
+ * @param editing Whether the grid is being edited.
12
+ * @returns True if the symbol should be displayed, false otherwise. The symbol will not be displayed if any handler returns false.
13
+ */
14
+ onSymbolDisplay(grid: GridData, solution: GridData | null, symbol: Symbol, editing: boolean): boolean;
15
+ }
16
+ export declare function handlesSymbolDisplay<T extends Instruction>(val: T): val is T & SymbolDisplayHandler;
@@ -0,0 +1,4 @@
1
+ import { isEventHandler } from './eventHelper.js';
2
+ export function handlesSymbolDisplay(val) {
3
+ return isEventHandler(val, 'onSymbolDisplay');
4
+ }
@@ -0,0 +1,10 @@
1
+ import Instruction from '../instruction.js';
2
+ import Symbol from '../symbols/symbol.js';
3
+ export interface SymbolMergeHandler {
4
+ /**
5
+ * Determines if the description of two symbols can be merged when displayed in the UI.
6
+ * @param other The other symbol to compare against.
7
+ */
8
+ descriptionEquals(other: Symbol): boolean;
9
+ }
10
+ export declare function handlesSymbolMerge<T extends Instruction>(val: T): val is T & SymbolMergeHandler;
@@ -0,0 +1,4 @@
1
+ import { isEventHandler } from './eventHelper.js';
2
+ export function handlesSymbolMerge(val) {
3
+ return isEventHandler(val, 'descriptionEquals');
4
+ }
@@ -0,0 +1,18 @@
1
+ import GridData from '../grid.js';
2
+ import { State } from '../primitives.js';
3
+ import Rule from '../rules/rule.js';
4
+ import Symbol from '../symbols/symbol.js';
5
+ export interface SymbolValidationHandler {
6
+ /**
7
+ * Overrides the validation of symbols.
8
+ *
9
+ * You can return a different validation result, or call the original validation logic with a modified grid.
10
+ *
11
+ * @param grid - The grid to validate.
12
+ * @param _symbol - The symbol to validate.
13
+ * @param validator - The original validation logic for the symbol.
14
+ * @returns The state of the symbol after validation.
15
+ */
16
+ onSymbolValidation(grid: GridData, symbol: Symbol, validator: (grid: GridData) => State): State | undefined;
17
+ }
18
+ export declare function handlesSymbolValidation<T extends Rule>(val: T): val is T & SymbolValidationHandler;
@@ -0,0 +1,4 @@
1
+ import { isEventHandler } from './eventHelper.js';
2
+ export function handlesSymbolValidation(val) {
3
+ return isEventHandler(val, 'onSymbolValidation');
4
+ }