@logic-pad/core 0.1.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.
Files changed (211) hide show
  1. package/LICENSE +661 -0
  2. package/README.md +19 -0
  3. package/assets/logic-core.global.d.ts +5865 -0
  4. package/assets/z3-built.js +14723 -0
  5. package/assets/z3-built.wasm +0 -0
  6. package/assets/z3-built.worker.js +206 -0
  7. package/dist/data/config.d.ts +101 -0
  8. package/dist/data/config.js +55 -0
  9. package/dist/data/configurable.d.ts +12 -0
  10. package/dist/data/configurable.js +26 -0
  11. package/dist/data/dataHelper.d.ts +77 -0
  12. package/dist/data/dataHelper.js +190 -0
  13. package/dist/data/events/eventHelper.d.ts +1 -0
  14. package/dist/data/events/eventHelper.js +6 -0
  15. package/dist/data/events/onFinalValidation.d.ts +14 -0
  16. package/dist/data/events/onFinalValidation.js +4 -0
  17. package/dist/data/events/onGridChange.d.ts +6 -0
  18. package/dist/data/events/onGridChange.js +4 -0
  19. package/dist/data/events/onGridResize.d.ts +9 -0
  20. package/dist/data/events/onGridResize.js +4 -0
  21. package/dist/data/events/onSetGrid.d.ts +6 -0
  22. package/dist/data/events/onSetGrid.js +4 -0
  23. package/dist/data/events/onSymbolValidation.d.ts +18 -0
  24. package/dist/data/events/onSymbolValidation.js +4 -0
  25. package/dist/data/grid.d.ts +362 -0
  26. package/dist/data/grid.js +886 -0
  27. package/dist/data/gridConnections.d.ts +38 -0
  28. package/dist/data/gridConnections.js +328 -0
  29. package/dist/data/instruction.d.ts +19 -0
  30. package/dist/data/instruction.js +23 -0
  31. package/dist/data/primitives.d.ts +85 -0
  32. package/dist/data/primitives.js +90 -0
  33. package/dist/data/puzzle.d.ts +86 -0
  34. package/dist/data/puzzle.js +22 -0
  35. package/dist/data/rules/banPatternRule.d.ts +29 -0
  36. package/dist/data/rules/banPatternRule.js +133 -0
  37. package/dist/data/rules/cellCountRule.d.ts +32 -0
  38. package/dist/data/rules/cellCountRule.js +166 -0
  39. package/dist/data/rules/completePatternRule.d.ts +22 -0
  40. package/dist/data/rules/completePatternRule.js +53 -0
  41. package/dist/data/rules/connectAllRule.d.ts +28 -0
  42. package/dist/data/rules/connectAllRule.js +113 -0
  43. package/dist/data/rules/customRule.d.ts +32 -0
  44. package/dist/data/rules/customRule.js +92 -0
  45. package/dist/data/rules/foresightRule.d.ts +30 -0
  46. package/dist/data/rules/foresightRule.js +107 -0
  47. package/dist/data/rules/index.d.ts +3 -0
  48. package/dist/data/rules/index.js +10 -0
  49. package/dist/data/rules/musicControlLine.d.ts +64 -0
  50. package/dist/data/rules/musicControlLine.js +178 -0
  51. package/dist/data/rules/musicGridRule.d.ts +46 -0
  52. package/dist/data/rules/musicGridRule.js +211 -0
  53. package/dist/data/rules/mysteryRule.d.ts +37 -0
  54. package/dist/data/rules/mysteryRule.js +164 -0
  55. package/dist/data/rules/offByXRule.d.ts +30 -0
  56. package/dist/data/rules/offByXRule.js +134 -0
  57. package/dist/data/rules/regionAreaRule.d.ts +33 -0
  58. package/dist/data/rules/regionAreaRule.js +182 -0
  59. package/dist/data/rules/regionShapeRule.d.ts +22 -0
  60. package/dist/data/rules/regionShapeRule.js +58 -0
  61. package/dist/data/rules/rule.d.ts +18 -0
  62. package/dist/data/rules/rule.js +19 -0
  63. package/dist/data/rules/rules.gen.d.ts +14 -0
  64. package/dist/data/rules/rules.gen.js +18 -0
  65. package/dist/data/rules/sameShapeRule.d.ts +27 -0
  66. package/dist/data/rules/sameShapeRule.js +88 -0
  67. package/dist/data/rules/symbolsPerRegionRule.d.ts +37 -0
  68. package/dist/data/rules/symbolsPerRegionRule.js +211 -0
  69. package/dist/data/rules/undercluedRule.d.ts +22 -0
  70. package/dist/data/rules/undercluedRule.js +60 -0
  71. package/dist/data/rules/uniqueShapeRule.d.ts +27 -0
  72. package/dist/data/rules/uniqueShapeRule.js +85 -0
  73. package/dist/data/serializer/allSerializers.d.ts +30 -0
  74. package/dist/data/serializer/allSerializers.js +64 -0
  75. package/dist/data/serializer/compressor/allCompressors.d.ts +14 -0
  76. package/dist/data/serializer/compressor/allCompressors.js +43 -0
  77. package/dist/data/serializer/compressor/compressorBase.d.ts +16 -0
  78. package/dist/data/serializer/compressor/compressorBase.js +2 -0
  79. package/dist/data/serializer/compressor/deflateCompressor.d.ts +7 -0
  80. package/dist/data/serializer/compressor/deflateCompressor.js +17 -0
  81. package/dist/data/serializer/compressor/gzipCompressor.d.ts +5 -0
  82. package/dist/data/serializer/compressor/gzipCompressor.js +9 -0
  83. package/dist/data/serializer/compressor/streamCompressor.d.ts +6 -0
  84. package/dist/data/serializer/compressor/streamCompressor.js +36 -0
  85. package/dist/data/serializer/serializerBase.d.ts +27 -0
  86. package/dist/data/serializer/serializerBase.js +2 -0
  87. package/dist/data/serializer/serializer_v0.d.ts +36 -0
  88. package/dist/data/serializer/serializer_v0.js +426 -0
  89. package/dist/data/shapes.d.ts +17 -0
  90. package/dist/data/shapes.js +117 -0
  91. package/dist/data/solver/allSolvers.d.ts +3 -0
  92. package/dist/data/solver/allSolvers.js +11 -0
  93. package/dist/data/solver/backtrack/backtrackSolver.d.ts +9 -0
  94. package/dist/data/solver/backtrack/backtrackSolver.js +92 -0
  95. package/dist/data/solver/backtrack/backtrackWorker.d.ts +2 -0
  96. package/dist/data/solver/backtrack/backtrackWorker.js +295 -0
  97. package/dist/data/solver/backtrack/data.d.ts +46 -0
  98. package/dist/data/solver/backtrack/data.js +140 -0
  99. package/dist/data/solver/backtrack/rules/banPattern.d.ts +9 -0
  100. package/dist/data/solver/backtrack/rules/banPattern.js +66 -0
  101. package/dist/data/solver/backtrack/rules/cellCount.d.ts +7 -0
  102. package/dist/data/solver/backtrack/rules/cellCount.js +30 -0
  103. package/dist/data/solver/backtrack/rules/connectAll.d.ts +7 -0
  104. package/dist/data/solver/backtrack/rules/connectAll.js +49 -0
  105. package/dist/data/solver/backtrack/rules/regionArea.d.ts +8 -0
  106. package/dist/data/solver/backtrack/rules/regionArea.js +76 -0
  107. package/dist/data/solver/backtrack/rules/regionShape.d.ts +8 -0
  108. package/dist/data/solver/backtrack/rules/regionShape.js +62 -0
  109. package/dist/data/solver/backtrack/rules/sameShape.d.ts +8 -0
  110. package/dist/data/solver/backtrack/rules/sameShape.js +19 -0
  111. package/dist/data/solver/backtrack/rules/symbolsPerRegion.d.ts +10 -0
  112. package/dist/data/solver/backtrack/rules/symbolsPerRegion.js +92 -0
  113. package/dist/data/solver/backtrack/rules/uniqueShape.d.ts +8 -0
  114. package/dist/data/solver/backtrack/rules/uniqueShape.js +19 -0
  115. package/dist/data/solver/backtrack/symbols/areaNumber.d.ts +9 -0
  116. package/dist/data/solver/backtrack/symbols/areaNumber.js +77 -0
  117. package/dist/data/solver/backtrack/symbols/dart.d.ts +9 -0
  118. package/dist/data/solver/backtrack/symbols/dart.js +58 -0
  119. package/dist/data/solver/backtrack/symbols/directionLinker.d.ts +9 -0
  120. package/dist/data/solver/backtrack/symbols/directionLinker.js +50 -0
  121. package/dist/data/solver/backtrack/symbols/galaxy.d.ts +9 -0
  122. package/dist/data/solver/backtrack/symbols/galaxy.js +19 -0
  123. package/dist/data/solver/backtrack/symbols/letter.d.ts +9 -0
  124. package/dist/data/solver/backtrack/symbols/letter.js +100 -0
  125. package/dist/data/solver/backtrack/symbols/lotus.d.ts +9 -0
  126. package/dist/data/solver/backtrack/symbols/lotus.js +36 -0
  127. package/dist/data/solver/backtrack/symbols/minesweeper.d.ts +9 -0
  128. package/dist/data/solver/backtrack/symbols/minesweeper.js +55 -0
  129. package/dist/data/solver/backtrack/symbols/myopia.d.ts +7 -0
  130. package/dist/data/solver/backtrack/symbols/myopia.js +79 -0
  131. package/dist/data/solver/backtrack/symbols/viewpoint.d.ts +7 -0
  132. package/dist/data/solver/backtrack/symbols/viewpoint.js +56 -0
  133. package/dist/data/solver/solver.d.ts +61 -0
  134. package/dist/data/solver/solver.js +55 -0
  135. package/dist/data/solver/underclued/undercluedSolver.d.ts +8 -0
  136. package/dist/data/solver/underclued/undercluedSolver.js +55 -0
  137. package/dist/data/solver/underclued/undercluedWorker.d.ts +2 -0
  138. package/dist/data/solver/underclued/undercluedWorker.js +131 -0
  139. package/dist/data/solver/z3/modules/areaNumberModule.d.ts +9 -0
  140. package/dist/data/solver/z3/modules/areaNumberModule.js +35 -0
  141. package/dist/data/solver/z3/modules/cellCountModule.d.ts +9 -0
  142. package/dist/data/solver/z3/modules/cellCountModule.js +59 -0
  143. package/dist/data/solver/z3/modules/connectAllModule.d.ts +9 -0
  144. package/dist/data/solver/z3/modules/connectAllModule.js +32 -0
  145. package/dist/data/solver/z3/modules/dartModule.d.ts +9 -0
  146. package/dist/data/solver/z3/modules/dartModule.js +69 -0
  147. package/dist/data/solver/z3/modules/index.d.ts +3 -0
  148. package/dist/data/solver/z3/modules/index.js +10 -0
  149. package/dist/data/solver/z3/modules/letterModule.d.ts +9 -0
  150. package/dist/data/solver/z3/modules/letterModule.js +41 -0
  151. package/dist/data/solver/z3/modules/modules.gen.d.ts +8 -0
  152. package/dist/data/solver/z3/modules/modules.gen.js +12 -0
  153. package/dist/data/solver/z3/modules/myopiaModule.d.ts +9 -0
  154. package/dist/data/solver/z3/modules/myopiaModule.js +64 -0
  155. package/dist/data/solver/z3/modules/regionAreaModule.d.ts +9 -0
  156. package/dist/data/solver/z3/modules/regionAreaModule.js +48 -0
  157. package/dist/data/solver/z3/modules/viewpointModule.d.ts +9 -0
  158. package/dist/data/solver/z3/modules/viewpointModule.js +37 -0
  159. package/dist/data/solver/z3/modules/z3Module.d.ts +7 -0
  160. package/dist/data/solver/z3/modules/z3Module.js +3 -0
  161. package/dist/data/solver/z3/utils.d.ts +2 -0
  162. package/dist/data/solver/z3/utils.js +26 -0
  163. package/dist/data/solver/z3/z3Solver.d.ts +10 -0
  164. package/dist/data/solver/z3/z3Solver.js +134 -0
  165. package/dist/data/solver/z3/z3SolverContext.d.ts +808 -0
  166. package/dist/data/solver/z3/z3SolverContext.js +49 -0
  167. package/dist/data/symbols/areaNumberSymbol.d.ts +30 -0
  168. package/dist/data/symbols/areaNumberSymbol.js +88 -0
  169. package/dist/data/symbols/customIconSymbol.d.ts +35 -0
  170. package/dist/data/symbols/customIconSymbol.js +105 -0
  171. package/dist/data/symbols/customSymbol.d.ts +23 -0
  172. package/dist/data/symbols/customSymbol.js +48 -0
  173. package/dist/data/symbols/customTextSymbol.d.ts +33 -0
  174. package/dist/data/symbols/customTextSymbol.js +106 -0
  175. package/dist/data/symbols/dartSymbol.d.ts +35 -0
  176. package/dist/data/symbols/dartSymbol.js +110 -0
  177. package/dist/data/symbols/directionLinkerSymbol.d.ts +36 -0
  178. package/dist/data/symbols/directionLinkerSymbol.js +259 -0
  179. package/dist/data/symbols/galaxySymbol.d.ts +26 -0
  180. package/dist/data/symbols/galaxySymbol.js +74 -0
  181. package/dist/data/symbols/index.d.ts +3 -0
  182. package/dist/data/symbols/index.js +10 -0
  183. package/dist/data/symbols/letterSymbol.d.ts +31 -0
  184. package/dist/data/symbols/letterSymbol.js +137 -0
  185. package/dist/data/symbols/lotusSymbol.d.ts +29 -0
  186. package/dist/data/symbols/lotusSymbol.js +132 -0
  187. package/dist/data/symbols/minesweeperSymbol.d.ts +31 -0
  188. package/dist/data/symbols/minesweeperSymbol.js +100 -0
  189. package/dist/data/symbols/multiEntrySymbol.d.ts +11 -0
  190. package/dist/data/symbols/multiEntrySymbol.js +14 -0
  191. package/dist/data/symbols/myopiaSymbol.d.ts +34 -0
  192. package/dist/data/symbols/myopiaSymbol.js +187 -0
  193. package/dist/data/symbols/numberSymbol.d.ts +19 -0
  194. package/dist/data/symbols/numberSymbol.js +41 -0
  195. package/dist/data/symbols/symbol.d.ts +16 -0
  196. package/dist/data/symbols/symbol.js +51 -0
  197. package/dist/data/symbols/symbols.gen.d.ts +10 -0
  198. package/dist/data/symbols/symbols.gen.js +14 -0
  199. package/dist/data/symbols/viewpointSymbol.d.ts +31 -0
  200. package/dist/data/symbols/viewpointSymbol.js +106 -0
  201. package/dist/data/tile.d.ts +26 -0
  202. package/dist/data/tile.js +68 -0
  203. package/dist/data/tileConnections.d.ts +25 -0
  204. package/dist/data/tileConnections.js +74 -0
  205. package/dist/data/validate.d.ts +5 -0
  206. package/dist/data/validate.js +131 -0
  207. package/dist/index.d.ts +96 -0
  208. package/dist/index.js +100 -0
  209. package/dist/polyfill/streamPolyfill.d.ts +2 -0
  210. package/dist/polyfill/streamPolyfill.js +1 -0
  211. package/package.json +75 -0
Binary file
@@ -0,0 +1,206 @@
1
+ /**
2
+ * @license
3
+ * Copyright 2015 The Emscripten Authors
4
+ * SPDX-License-Identifier: MIT
5
+ */
6
+
7
+ // Pthread Web Worker startup routine:
8
+ // This is the entry point file that is loaded first by each Web Worker
9
+ // that executes pthreads on the Emscripten application.
10
+
11
+ 'use strict';
12
+
13
+ var Module = {};
14
+
15
+ // Node.js support
16
+ var ENVIRONMENT_IS_NODE = typeof process == 'object' && typeof process.versions == 'object' && typeof process.versions.node == 'string';
17
+ if (ENVIRONMENT_IS_NODE) {
18
+ // Create as web-worker-like an environment as we can.
19
+
20
+ var nodeWorkerThreads = require('worker_threads');
21
+
22
+ var parentPort = nodeWorkerThreads.parentPort;
23
+
24
+ parentPort.on('message', function(data) {
25
+ onmessage({ data: data });
26
+ });
27
+
28
+ var fs = require('fs');
29
+
30
+ Object.assign(global, {
31
+ self: global,
32
+ require: require,
33
+ Module: Module,
34
+ location: {
35
+ href: __filename
36
+ },
37
+ Worker: nodeWorkerThreads.Worker,
38
+ importScripts: function(f) {
39
+ (0, eval)(fs.readFileSync(f, 'utf8'));
40
+ },
41
+ postMessage: function(msg) {
42
+ parentPort.postMessage(msg);
43
+ },
44
+ performance: global.performance || {
45
+ now: function() {
46
+ return Date.now();
47
+ }
48
+ },
49
+ });
50
+ }
51
+
52
+ // Thread-local guard variable for one-time init of the JS state
53
+ var initializedJS = false;
54
+
55
+ // Proxying queues that were notified before the thread started and need to be
56
+ // executed as part of startup.
57
+ var pendingNotifiedProxyingQueues = [];
58
+
59
+ function assert(condition, text) {
60
+ if (!condition) abort('Assertion failed: ' + text);
61
+ }
62
+
63
+ function threadPrintErr() {
64
+ var text = Array.prototype.slice.call(arguments).join(' ');
65
+ // See https://github.com/emscripten-core/emscripten/issues/14804
66
+ if (ENVIRONMENT_IS_NODE) {
67
+ fs.writeSync(2, text + '\n');
68
+ return;
69
+ }
70
+ console.error(text);
71
+ }
72
+ function threadAlert() {
73
+ var text = Array.prototype.slice.call(arguments).join(' ');
74
+ postMessage({cmd: 'alert', text: text, threadId: Module['_pthread_self']()});
75
+ }
76
+ // We don't need out() for now, but may need to add it if we want to use it
77
+ // here. Or, if this code all moves into the main JS, that problem will go
78
+ // away. (For now, adding it here increases code size for no benefit.)
79
+ var out = () => { throw 'out() is not defined in worker.js.'; }
80
+ var err = threadPrintErr;
81
+ self.alert = threadAlert;
82
+
83
+ Module['instantiateWasm'] = (info, receiveInstance) => {
84
+ // Instantiate from the module posted from the main thread.
85
+ // We can just use sync instantiation in the worker.
86
+ var instance = new WebAssembly.Instance(Module['wasmModule'], info);
87
+ // TODO: Due to Closure regression https://github.com/google/closure-compiler/issues/3193,
88
+ // the above line no longer optimizes out down to the following line.
89
+ // When the regression is fixed, we can remove this if/else.
90
+ receiveInstance(instance);
91
+ // We don't need the module anymore; new threads will be spawned from the main thread.
92
+ Module['wasmModule'] = null;
93
+ return instance.exports;
94
+ }
95
+
96
+ self.onmessage = (e) => {
97
+ try {
98
+ if (e.data.cmd === 'load') { // Preload command that is called once per worker to parse and load the Emscripten code.
99
+
100
+ // Module and memory were sent from main thread
101
+ Module['wasmModule'] = e.data.wasmModule;
102
+
103
+ Module['wasmMemory'] = e.data.wasmMemory;
104
+
105
+ Module['buffer'] = Module['wasmMemory'].buffer;
106
+
107
+ Module['ENVIRONMENT_IS_PTHREAD'] = true;
108
+
109
+ if (typeof e.data.urlOrBlob == 'string') {
110
+ importScripts(e.data.urlOrBlob);
111
+ } else {
112
+ var objectUrl = URL.createObjectURL(e.data.urlOrBlob);
113
+ importScripts(objectUrl);
114
+ URL.revokeObjectURL(objectUrl);
115
+ }
116
+ initZ3(Module).then(function (instance) {
117
+ Module = instance;
118
+ });
119
+ } else if (e.data.cmd === 'run') {
120
+ // This worker was idle, and now should start executing its pthread entry
121
+ // point.
122
+ // performance.now() is specced to return a wallclock time in msecs since
123
+ // that Web Worker/main thread launched. However for pthreads this can
124
+ // cause subtle problems in emscripten_get_now() as this essentially
125
+ // would measure time from pthread_create(), meaning that the clocks
126
+ // between each threads would be wildly out of sync. Therefore sync all
127
+ // pthreads to the clock on the main browser thread, so that different
128
+ // threads see a somewhat coherent clock across each of them
129
+ // (+/- 0.1msecs in testing).
130
+ Module['__performance_now_clock_drift'] = performance.now() - e.data.time;
131
+
132
+ // Pass the thread address inside the asm.js scope to store it for fast access that avoids the need for a FFI out.
133
+ Module['__emscripten_thread_init'](e.data.threadInfoStruct, /*isMainBrowserThread=*/0, /*isMainRuntimeThread=*/0, /*canBlock=*/1);
134
+
135
+ assert(e.data.threadInfoStruct);
136
+ // Also call inside JS module to set up the stack frame for this pthread in JS module scope
137
+ Module['establishStackSpace']();
138
+ Module['PThread'].receiveObjectTransfer(e.data);
139
+ Module['PThread'].threadInitTLS();
140
+
141
+ if (!initializedJS) {
142
+
143
+ // Execute any proxied work that came in before the thread was
144
+ // initialized. Only do this once because it is only possible for
145
+ // proxying notifications to arrive before thread initialization on
146
+ // fresh workers.
147
+ pendingNotifiedProxyingQueues.forEach(queue => {
148
+ Module['executeNotifiedProxyingQueue'](queue);
149
+ });
150
+ pendingNotifiedProxyingQueues = [];
151
+ initializedJS = true;
152
+ }
153
+
154
+ try {
155
+ Module['invokeEntryPoint'](e.data.start_routine, e.data.arg);
156
+ } catch(ex) {
157
+ if (ex != 'unwind') {
158
+ // ExitStatus not present in MINIMAL_RUNTIME
159
+ if (ex instanceof Module['ExitStatus']) {
160
+ if (Module['keepRuntimeAlive']()) {
161
+ err('Pthread 0x' + Module['_pthread_self']().toString(16) + ' called exit(), staying alive due to noExitRuntime.');
162
+ } else {
163
+ err('Pthread 0x' + Module['_pthread_self']().toString(16) + ' called exit(), calling _emscripten_thread_exit.');
164
+ Module['__emscripten_thread_exit'](ex.status);
165
+ }
166
+ }
167
+ else
168
+ {
169
+ // The pthread "crashed". Do not call `_emscripten_thread_exit` (which
170
+ // would make this thread joinable. Instead, re-throw the exception
171
+ // and let the top level handler propagate it back to the main thread.
172
+ throw ex;
173
+ }
174
+ } else {
175
+ // else e == 'unwind', and we should fall through here and keep the pthread alive for asynchronous events.
176
+ err('Pthread 0x' + Module['_pthread_self']().toString(16) + ' completed its main entry point with an `unwind`, keeping the worker alive for asynchronous operation.');
177
+ }
178
+ }
179
+ } else if (e.data.cmd === 'cancel') { // Main thread is asking for a pthread_cancel() on this thread.
180
+ if (Module['_pthread_self']()) {
181
+ Module['__emscripten_thread_exit'](-1/*PTHREAD_CANCELED*/);
182
+ }
183
+ } else if (e.data.target === 'setimmediate') {
184
+ // no-op
185
+ } else if (e.data.cmd === 'processProxyingQueue') {
186
+ if (initializedJS) {
187
+ Module['executeNotifiedProxyingQueue'](e.data.queue);
188
+ } else {
189
+ // Defer executing this queue until the runtime is initialized.
190
+ pendingNotifiedProxyingQueues.push(e.data.queue);
191
+ }
192
+ } else {
193
+ err('worker.js received unknown command ' + e.data.cmd);
194
+ err(e.data);
195
+ }
196
+ } catch(ex) {
197
+ err('worker.js onmessage() captured an uncaught exception: ' + ex);
198
+ if (ex && ex.stack) err(ex.stack);
199
+ if (Module['__emscripten_thread_crashed']) {
200
+ Module['__emscripten_thread_crashed']();
201
+ }
202
+ throw ex;
203
+ }
204
+ };
205
+
206
+
@@ -0,0 +1,101 @@
1
+ import GridData from './grid';
2
+ import { Color, Comparison, Direction, DirectionToggle, Orientation, OrientationToggle } from './primitives';
3
+ import { ControlLine } from './rules/musicControlLine';
4
+ export declare enum ConfigType {
5
+ Boolean = "boolean",
6
+ NullableBoolean = "nullableBoolean",
7
+ Number = "number",
8
+ NullableNumber = "nullableNumber",
9
+ String = "string",
10
+ Color = "color",
11
+ Comparison = "comparison",
12
+ Direction = "direction",
13
+ DirectionToggle = "directionToggle",
14
+ Orientation = "orientation",
15
+ OrientationToggle = "orientationToggle",
16
+ Tile = "tile",
17
+ Grid = "grid",
18
+ NullableGrid = "nullableGrid",
19
+ Icon = "icon",
20
+ ControlLines = "controlLines",
21
+ NullableNote = "nullableNote"
22
+ }
23
+ export interface Config<T> {
24
+ readonly type: ConfigType;
25
+ readonly field: string;
26
+ readonly description: string;
27
+ readonly default: T;
28
+ readonly configurable: boolean;
29
+ }
30
+ export interface BooleanConfig extends Config<boolean> {
31
+ readonly type: ConfigType.Boolean;
32
+ }
33
+ export interface NullableBooleanConfig extends Config<boolean | null> {
34
+ readonly type: ConfigType.NullableBoolean;
35
+ }
36
+ export interface NumberConfig extends Config<number> {
37
+ readonly type: ConfigType.Number;
38
+ readonly min?: number;
39
+ readonly max?: number;
40
+ readonly step?: number;
41
+ }
42
+ export interface NullableNumberConfig extends Config<number | null> {
43
+ readonly type: ConfigType.NullableNumber;
44
+ readonly min?: number;
45
+ readonly max?: number;
46
+ readonly step?: number;
47
+ }
48
+ export interface StringConfig extends Config<string> {
49
+ readonly type: ConfigType.String;
50
+ readonly maxLength?: number;
51
+ readonly placeholder?: string;
52
+ }
53
+ export interface ColorConfig extends Config<Color> {
54
+ readonly type: ConfigType.Color;
55
+ readonly allowGray: boolean;
56
+ }
57
+ export interface ComparisonConfig extends Config<Comparison> {
58
+ readonly type: ConfigType.Comparison;
59
+ }
60
+ export interface DirectionConfig extends Config<Direction> {
61
+ readonly type: ConfigType.Direction;
62
+ }
63
+ export interface DirectionToggleConfig extends Config<DirectionToggle> {
64
+ readonly type: ConfigType.DirectionToggle;
65
+ }
66
+ export interface OrientationConfig extends Config<Orientation> {
67
+ readonly type: ConfigType.Orientation;
68
+ }
69
+ export interface OrientationToggleConfig extends Config<OrientationToggle> {
70
+ readonly type: ConfigType.OrientationToggle;
71
+ }
72
+ export interface TileConfig extends Config<GridData> {
73
+ readonly type: ConfigType.Tile;
74
+ readonly resizable: boolean;
75
+ }
76
+ export interface GridConfig extends Config<GridData> {
77
+ readonly type: ConfigType.Grid;
78
+ }
79
+ export interface NullableGridConfig extends Config<GridData | null> {
80
+ readonly type: ConfigType.NullableGrid;
81
+ readonly nonNullDefault: GridData;
82
+ }
83
+ export interface IconConfig extends Config<string> {
84
+ readonly type: ConfigType.Icon;
85
+ }
86
+ export interface ControlLinesConfig extends Config<ControlLine[]> {
87
+ readonly type: ConfigType.ControlLines;
88
+ }
89
+ export interface NullableNoteConfig extends Config<string | null> {
90
+ readonly type: ConfigType.NullableNote;
91
+ }
92
+ export type AnyConfig = BooleanConfig | NullableBooleanConfig | NumberConfig | NullableNumberConfig | StringConfig | ColorConfig | ComparisonConfig | DirectionConfig | DirectionToggleConfig | OrientationConfig | OrientationToggleConfig | TileConfig | GridConfig | NullableGridConfig | IconConfig | ControlLinesConfig | NullableNoteConfig;
93
+ /**
94
+ * Compare two config values for equality, using an appropriate method for the config type.
95
+ *
96
+ * @param type The type of the config.
97
+ * @param a The first value to compare.
98
+ * @param b The second value to compare.
99
+ * @returns Whether the two values are equal.
100
+ */
101
+ export declare function configEquals<C extends AnyConfig>(type: C['type'], a: C['default'], b: C['default']): boolean;
@@ -0,0 +1,55 @@
1
+ import { DIRECTIONS, ORIENTATIONS, } from './primitives';
2
+ export var ConfigType;
3
+ (function (ConfigType) {
4
+ ConfigType["Boolean"] = "boolean";
5
+ ConfigType["NullableBoolean"] = "nullableBoolean";
6
+ ConfigType["Number"] = "number";
7
+ ConfigType["NullableNumber"] = "nullableNumber";
8
+ ConfigType["String"] = "string";
9
+ ConfigType["Color"] = "color";
10
+ ConfigType["Comparison"] = "comparison";
11
+ ConfigType["Direction"] = "direction";
12
+ ConfigType["DirectionToggle"] = "directionToggle";
13
+ ConfigType["Orientation"] = "orientation";
14
+ ConfigType["OrientationToggle"] = "orientationToggle";
15
+ ConfigType["Tile"] = "tile";
16
+ ConfigType["Grid"] = "grid";
17
+ ConfigType["NullableGrid"] = "nullableGrid";
18
+ ConfigType["Icon"] = "icon";
19
+ ConfigType["ControlLines"] = "controlLines";
20
+ ConfigType["NullableNote"] = "nullableNote";
21
+ })(ConfigType || (ConfigType = {}));
22
+ /**
23
+ * Compare two config values for equality, using an appropriate method for the config type.
24
+ *
25
+ * @param type The type of the config.
26
+ * @param a The first value to compare.
27
+ * @param b The second value to compare.
28
+ * @returns Whether the two values are equal.
29
+ */
30
+ export function configEquals(type, a, b) {
31
+ if (type === ConfigType.ControlLines) {
32
+ const aLines = a;
33
+ const bLines = b;
34
+ if (aLines.length !== bLines.length)
35
+ return false;
36
+ return aLines.every((line, i) => line.equals(bLines[i]));
37
+ }
38
+ if (type === ConfigType.Tile || type === ConfigType.Grid) {
39
+ return a.equals(b);
40
+ }
41
+ if (type === ConfigType.NullableGrid) {
42
+ if (a === null && b === null)
43
+ return true;
44
+ if (a === null || b === null)
45
+ return false;
46
+ return a.equals(b);
47
+ }
48
+ if (type === ConfigType.DirectionToggle) {
49
+ return DIRECTIONS.every(dir => a[dir] === b[dir]);
50
+ }
51
+ if (type === ConfigType.OrientationToggle) {
52
+ return ORIENTATIONS.every(dir => a[dir] === b[dir]);
53
+ }
54
+ return a === b;
55
+ }
@@ -0,0 +1,12 @@
1
+ import { AnyConfig } from './config';
2
+ export default abstract class Configurable {
3
+ get configs(): readonly AnyConfig[] | null;
4
+ abstract copyWith(props: Record<string, unknown>): this;
5
+ /**
6
+ * Check if this instruction is equal to another instruction by comparing their IDs and configs.
7
+ *
8
+ * @param other The other instruction to compare to.
9
+ * @returns Whether the two instructions are equal.
10
+ */
11
+ equals(other: Configurable): boolean;
12
+ }
@@ -0,0 +1,26 @@
1
+ import { configEquals } from './config';
2
+ export default class Configurable {
3
+ get configs() {
4
+ return null;
5
+ }
6
+ /**
7
+ * Check if this instruction is equal to another instruction by comparing their IDs and configs.
8
+ *
9
+ * @param other The other instruction to compare to.
10
+ * @returns Whether the two instructions are equal.
11
+ */
12
+ equals(other) {
13
+ const configs = this.configs;
14
+ if (configs === null)
15
+ return true;
16
+ // this is only possible when an instruction is instantiated before the class itself is completely defined
17
+ // in this case, we can only compare the instances themselves
18
+ if (configs === undefined)
19
+ return this === other;
20
+ for (const config of this.configs) {
21
+ if (!configEquals(config.type, this[config.field], other[config.field]))
22
+ return false;
23
+ }
24
+ return true;
25
+ }
26
+ }
@@ -0,0 +1,77 @@
1
+ import { Direction, Orientation, Position } from './primitives';
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
+ * Convert the given direction to a rotation in degrees.
15
+ * @param direction The direction to convert.
16
+ * @returns The rotation in degrees.
17
+ */
18
+ export declare function directionToRotation(direction: Direction): 0 | 270 | 90 | 180;
19
+ /**
20
+ * Convert the given orientation to a rotation in degrees.
21
+ * @param orientation The orientation to convert.
22
+ * @returns The rotation in degrees.
23
+ */
24
+ export declare function orientationToRotation(orientation: Orientation): 0 | 270 | 90 | 180 | 225 | 125 | 315 | 45;
25
+ /**
26
+ * Create a new 2D array with the given dimensions and values.
27
+ * @param width The width of the array.
28
+ * @param height The height of the array.
29
+ * @param value A function that returns the value for each x,y coordinate.
30
+ * @returns The 2D array.
31
+ */
32
+ export declare function array<T>(width: number, height: number, value: (x: number, y: number) => T): T[][];
33
+ /**
34
+ * Resize the given array to the new size, cutting off or padding with the default value.
35
+ * @param array The array to resize.
36
+ * @param newSize The new size of the array.
37
+ * @param defaultValue A function that returns the default value for each new element.
38
+ * @returns The resized array.
39
+ */
40
+ export declare function resize<T>(array: T[], newSize: number, defaultValue: () => T): T[];
41
+ export declare function resize<T>(array: readonly T[], newSize: number, defaultValue: () => T): readonly T[];
42
+ /**
43
+ * Check if all the given values are equal.
44
+ * @param values The values to compare.
45
+ * @returns Whether all the values are equal.
46
+ */
47
+ export declare function allEqual<T>(...values: T[]): boolean;
48
+ /**
49
+ * Return the first element of the array which has the minimum mapped value.
50
+ *
51
+ * @param values The array of values.
52
+ * @param mapper The function to map each value to a number.
53
+ * @returns The first element with the minimum mapped value.
54
+ */
55
+ export declare function minBy<T>(values: readonly T[], mapper: (element: T) => number): T | undefined;
56
+ /**
57
+ * Return the first element of the array which has the maximum mapped value.
58
+ *
59
+ * @param values The array of values.
60
+ * @param mapper The function to map each value to a number.
61
+ * @returns The first element with the maximum mapped value.
62
+ */
63
+ export declare function maxBy<T>(values: readonly T[], mapper: (element: T) => number): T | undefined;
64
+ /**
65
+ * Escape the given text by replacing the specified characters with HTML escape sequences.
66
+ * @param text The text to escape.
67
+ * @param escapeCharacters The characters to escape.
68
+ * @returns The escaped text.
69
+ */
70
+ export declare function escape(text: string, escapeCharacters?: string): string;
71
+ /**
72
+ * Unescape the given text by replacing HTML escape sequences with the corresponding characters.
73
+ * @param text The text to unescape.
74
+ * @param escapeCharacters The characters to unescape. This should match the characters escaped by the `escape` function.
75
+ * @returns The unescaped text.
76
+ */
77
+ export declare function unescape(text: string, escapeCharacters?: string): string;
@@ -0,0 +1,190 @@
1
+ import { Direction, Orientation } from './primitives';
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
+ * Convert the given direction to a rotation in degrees.
35
+ * @param direction The direction to convert.
36
+ * @returns The rotation in degrees.
37
+ */
38
+ export function directionToRotation(direction) {
39
+ switch (direction) {
40
+ case Direction.Up:
41
+ return 0;
42
+ case Direction.Left:
43
+ return 270;
44
+ case Direction.Right:
45
+ return 90;
46
+ case Direction.Down:
47
+ return 180;
48
+ }
49
+ }
50
+ /**
51
+ * Convert the given orientation to a rotation in degrees.
52
+ * @param orientation The orientation to convert.
53
+ * @returns The rotation in degrees.
54
+ */
55
+ export function orientationToRotation(orientation) {
56
+ switch (orientation) {
57
+ case Orientation.Up:
58
+ return 0;
59
+ case Orientation.Left:
60
+ return 270;
61
+ case Orientation.Right:
62
+ return 90;
63
+ case Orientation.Down:
64
+ return 180;
65
+ case Orientation.DownLeft:
66
+ return 225;
67
+ case Orientation.DownRight:
68
+ return 125;
69
+ case Orientation.UpLeft:
70
+ return 315;
71
+ case Orientation.UpRight:
72
+ return 45;
73
+ }
74
+ }
75
+ /**
76
+ * Create a new 2D array with the given dimensions and values.
77
+ * @param width The width of the array.
78
+ * @param height The height of the array.
79
+ * @param value A function that returns the value for each x,y coordinate.
80
+ * @returns The 2D array.
81
+ */
82
+ export function array(width, height, value) {
83
+ const result = [];
84
+ for (let y = 0; y < height; y++) {
85
+ result[y] = [];
86
+ for (let x = 0; x < width; x++) {
87
+ result[y][x] = value(x, y);
88
+ }
89
+ }
90
+ return result;
91
+ }
92
+ export function resize(array, newSize, defaultValue) {
93
+ if (array.length < newSize) {
94
+ return [
95
+ ...array,
96
+ ...Array.from({ length: newSize - array.length }, defaultValue),
97
+ ];
98
+ }
99
+ else if (array.length > newSize) {
100
+ return array.slice(0, newSize);
101
+ }
102
+ return array;
103
+ }
104
+ /**
105
+ * Check if all the given values are equal.
106
+ * @param values The values to compare.
107
+ * @returns Whether all the values are equal.
108
+ */
109
+ export function allEqual(...values) {
110
+ return values.every(value => value === values[0]);
111
+ }
112
+ /**
113
+ * Return the first element of the array which has the minimum mapped value.
114
+ *
115
+ * @param values The array of values.
116
+ * @param mapper The function to map each value to a number.
117
+ * @returns The first element with the minimum mapped value.
118
+ */
119
+ export function minBy(values, mapper) {
120
+ let min = Number.POSITIVE_INFINITY;
121
+ let result;
122
+ for (const value of values) {
123
+ const mapped = mapper(value);
124
+ if (mapped < min) {
125
+ min = mapped;
126
+ result = value;
127
+ }
128
+ }
129
+ return result;
130
+ }
131
+ /**
132
+ * Return the first element of the array which has the maximum mapped value.
133
+ *
134
+ * @param values The array of values.
135
+ * @param mapper The function to map each value to a number.
136
+ * @returns The first element with the maximum mapped value.
137
+ */
138
+ export function maxBy(values, mapper) {
139
+ let max = Number.NEGATIVE_INFINITY;
140
+ let result;
141
+ for (const value of values) {
142
+ const mapped = mapper(value);
143
+ if (mapped > max) {
144
+ max = mapped;
145
+ result = value;
146
+ }
147
+ }
148
+ return result;
149
+ }
150
+ /**
151
+ * Escape the given text by replacing the specified characters with HTML escape sequences.
152
+ * @param text The text to escape.
153
+ * @param escapeCharacters The characters to escape.
154
+ * @returns The escaped text.
155
+ */
156
+ export function escape(text, escapeCharacters = '=,:|') {
157
+ let result = '';
158
+ for (const char of text) {
159
+ if (escapeCharacters.includes(char) || char === '&') {
160
+ result += `&#${char.charCodeAt(0)};`;
161
+ }
162
+ else {
163
+ result += char;
164
+ }
165
+ }
166
+ return result;
167
+ }
168
+ /**
169
+ * Unescape the given text by replacing HTML escape sequences with the corresponding characters.
170
+ * @param text The text to unescape.
171
+ * @param escapeCharacters The characters to unescape. This should match the characters escaped by the `escape` function.
172
+ * @returns The unescaped text.
173
+ */
174
+ export function unescape(text, escapeCharacters = '=,:|') {
175
+ let result = '';
176
+ const matches = text.matchAll(/&#([0-9]+);/g);
177
+ let index = 0;
178
+ for (const match of matches) {
179
+ result += text.substring(index, match.index);
180
+ const char = String.fromCharCode(parseInt(match[1], 10));
181
+ if (escapeCharacters.includes(char) || char === '&') {
182
+ result += char;
183
+ }
184
+ else {
185
+ result += match[0];
186
+ }
187
+ index = match.index + match[0].length;
188
+ }
189
+ return result + text.substring(index);
190
+ }
@@ -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
+ }