@bitblit/ratchet-maze 5.1.609-alpha
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/lib/build/ratchet-maze-info.d.ts +5 -0
- package/lib/build/ratchet-maze-info.js +16 -0
- package/lib/build/ratchet-maze-info.js.map +1 -0
- package/lib/model/binary-generator.d.ts +4 -0
- package/lib/model/binary-generator.js +29 -0
- package/lib/model/binary-generator.js.map +1 -0
- package/lib/model/coordinate.d.ts +4 -0
- package/lib/model/coordinate.js +2 -0
- package/lib/model/coordinate.js.map +1 -0
- package/lib/model/direction.d.ts +6 -0
- package/lib/model/direction.js +8 -0
- package/lib/model/direction.js.map +1 -0
- package/lib/model/drawing-util.d.ts +12 -0
- package/lib/model/drawing-util.js +66 -0
- package/lib/model/drawing-util.js.map +1 -0
- package/lib/model/rectangular-maze.d.ts +24 -0
- package/lib/model/rectangular-maze.js +118 -0
- package/lib/model/rectangular-maze.js.map +1 -0
- package/package.json +48 -0
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
export class RatchetInfo {
|
|
2
|
+
constructor() {
|
|
3
|
+
}
|
|
4
|
+
static buildInformation() {
|
|
5
|
+
const val = {
|
|
6
|
+
version: 'LOCAL-SNAPSHOT',
|
|
7
|
+
hash: 'LOCAL-HASH',
|
|
8
|
+
branch: 'LOCAL-BRANCH',
|
|
9
|
+
tag: 'LOCAL-TAG',
|
|
10
|
+
timeBuiltISO: 'LOCAL-TIME-ISO',
|
|
11
|
+
notes: 'LOCAL-NOTES',
|
|
12
|
+
};
|
|
13
|
+
return val;
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
//# sourceMappingURL=ratchet-maze-info.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ratchet-maze-info.js","sourceRoot":"","sources":["../../src/build/ratchet-maze-info.ts"],"names":[],"mappings":"AAEA,MAAM,OAAO,WAAW;IAGtB;IACA,CAAC;IAEM,MAAM,CAAC,gBAAgB;QAC5B,MAAM,GAAG,GAAqB;YAC5B,OAAO,EAAE,gBAAgB;YACzB,IAAI,EAAE,YAAY;YAClB,MAAM,EAAE,cAAc;YACtB,GAAG,EAAE,WAAW;YAChB,YAAY,EAAE,gBAAgB;YAC9B,KAAK,EAAE,aAAa;SACrB,CAAC;QACF,OAAO,GAAG,CAAC;IACb,CAAC;CACF"}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { RectangularMaze } from "./rectangular-maze.js";
|
|
2
|
+
export class BinaryGenerator {
|
|
3
|
+
static generate(width, height) {
|
|
4
|
+
const rval = new RectangularMaze(width, height);
|
|
5
|
+
for (let y = 0; y < height; y++) {
|
|
6
|
+
for (let x = 0; x < width; x++) {
|
|
7
|
+
if (y === 0) {
|
|
8
|
+
if (x < width - 1) {
|
|
9
|
+
rval.addPassage({ x, y }, { x: x + 1, y: y });
|
|
10
|
+
}
|
|
11
|
+
}
|
|
12
|
+
else if (x === width - 1) {
|
|
13
|
+
rval.addPassage({ x, y }, { x: x, y: y - 1 });
|
|
14
|
+
}
|
|
15
|
+
else {
|
|
16
|
+
const flip = Math.random();
|
|
17
|
+
if (flip <= .5) {
|
|
18
|
+
rval.addPassage({ x, y }, { x: x + 1, y: y });
|
|
19
|
+
}
|
|
20
|
+
else {
|
|
21
|
+
rval.addPassage({ x, y }, { x: x, y: y - 1 });
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
return rval;
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
//# sourceMappingURL=binary-generator.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"binary-generator.js","sourceRoot":"","sources":["../../src/model/binary-generator.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,uBAAuB,CAAC;AAKxD,MAAM,OAAO,eAAe;IAEnB,MAAM,CAAC,QAAQ,CAAC,KAAa,EAAE,MAAc;QAClD,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d,CAAC;CACF"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"coordinate.js","sourceRoot":"","sources":["../../src/model/coordinate.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"direction.js","sourceRoot":"","sources":["../../src/model/direction.ts"],"names":[],"mappings":"AAAA,MAAM,CAAN,IAAY,SAEX;AAFD,WAAY,SAAS;IACnB,4BAAa,CAAA;IAAC,4BAAa,CAAA;IAAC,0BAAW,CAAA;IAAC,0BAAW,CAAA;AACrD,CAAC,EAFW,SAAS,KAAT,SAAS,QAEpB"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { RectangularMaze } from "./rectangular-maze.js";
|
|
2
|
+
export declare class DrawingUtil {
|
|
3
|
+
static formatBitmapToString(bmap: string[][], lineEnd?: string): string;
|
|
4
|
+
static rectangularMazeToBitmap(maze: RectangularMaze): string[][];
|
|
5
|
+
static rectangularMazeToSvg(maze: RectangularMaze, opts?: RectangularMazeDrawOptions): string;
|
|
6
|
+
}
|
|
7
|
+
export interface RectangularMazeDrawOptions {
|
|
8
|
+
backgroundColor: string;
|
|
9
|
+
wallColor: string;
|
|
10
|
+
disabledColor: string;
|
|
11
|
+
cellSize: number;
|
|
12
|
+
}
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
import { RequireRatchet } from "@bitblit/ratchet-common/lang/require-ratchet";
|
|
2
|
+
import { Direction } from "./direction.js";
|
|
3
|
+
import { StringRatchet } from "@bitblit/ratchet-common/lang/string-ratchet";
|
|
4
|
+
export class DrawingUtil {
|
|
5
|
+
static formatBitmapToString(bmap, lineEnd = '\n') {
|
|
6
|
+
const rval = bmap.map(s => s.join(' ')).join(lineEnd);
|
|
7
|
+
return rval;
|
|
8
|
+
}
|
|
9
|
+
static rectangularMazeToBitmap(maze) {
|
|
10
|
+
RequireRatchet.notNullOrUndefined(maze);
|
|
11
|
+
RequireRatchet.true(maze.width > 0);
|
|
12
|
+
RequireRatchet.true(maze.height > 0);
|
|
13
|
+
const rval = [];
|
|
14
|
+
for (let y = 0; y < maze.height; y++) {
|
|
15
|
+
const curRow = [];
|
|
16
|
+
for (let x = 0; x < maze.width; x++) {
|
|
17
|
+
if (maze.isDisabled({ x: x, y: y })) {
|
|
18
|
+
curRow.push('X');
|
|
19
|
+
}
|
|
20
|
+
else {
|
|
21
|
+
let num = 0;
|
|
22
|
+
num += maze.hasWall({ x, y }, Direction.North) ? 1 : 0;
|
|
23
|
+
num += maze.hasWall({ x, y }, Direction.East) ? 2 : 0;
|
|
24
|
+
num += maze.hasWall({ x, y }, Direction.South) ? 4 : 0;
|
|
25
|
+
num += maze.hasWall({ x, y }, Direction.West) ? 8 : 0;
|
|
26
|
+
curRow.push(StringRatchet.HEXITS[num]);
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
rval.push(curRow);
|
|
30
|
+
}
|
|
31
|
+
return rval;
|
|
32
|
+
}
|
|
33
|
+
static rectangularMazeToSvg(maze, opts) {
|
|
34
|
+
RequireRatchet.notNullOrUndefined(maze);
|
|
35
|
+
RequireRatchet.true(maze.width > 0);
|
|
36
|
+
RequireRatchet.true(maze.height > 0);
|
|
37
|
+
const widthPx = maze.width * opts.cellSize;
|
|
38
|
+
const heightPx = maze.height * opts.cellSize;
|
|
39
|
+
let rval = `<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 ${widthPx} ${heightPx}"><g> \n`;
|
|
40
|
+
for (let y = 0; y < maze.height; y++) {
|
|
41
|
+
for (let x = 0; x < maze.width; x++) {
|
|
42
|
+
const uX = x * opts.cellSize;
|
|
43
|
+
const uY = y * opts.cellSize;
|
|
44
|
+
if (maze.isDisabled({ x: x, y: y })) {
|
|
45
|
+
}
|
|
46
|
+
else {
|
|
47
|
+
if (maze.hasWall({ x, y }, Direction.North)) {
|
|
48
|
+
rval += `<polyline stroke="#000080" stroke-width="1" fill="none" points="${uX},${uY} ${uX + opts.cellSize} ${uY}" />\n`;
|
|
49
|
+
}
|
|
50
|
+
if (maze.hasWall({ x, y }, Direction.East)) {
|
|
51
|
+
rval += `<polyline stroke="#000080" stroke-width="1" fill="none" points="${uX + opts.cellSize},${uY} ${uX + opts.cellSize} ${uY + opts.cellSize}" />\n`;
|
|
52
|
+
}
|
|
53
|
+
if (maze.hasWall({ x, y }, Direction.South)) {
|
|
54
|
+
rval += `<polyline stroke="#000080" stroke-width="1" fill="none" points="${uX},${uY + opts.cellSize} ${uX + opts.cellSize} ${uY + opts.cellSize}" />\n`;
|
|
55
|
+
}
|
|
56
|
+
if (maze.hasWall({ x, y }, Direction.West)) {
|
|
57
|
+
rval += `<polyline stroke="#000080" stroke-width="1" fill="none" points="${uX},${uY + opts.cellSize} ${uX} ${uY}" />\n`;
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
rval += '</g></svg>';
|
|
63
|
+
return rval;
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
//# sourceMappingURL=drawing-util.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"drawing-util.js","sourceRoot":"","sources":["../../src/model/drawing-util.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,cAAc,EAAE,MAAM,8CAA8C,CAAC;AAG9E,OAAO,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC;AAC3C,OAAO,EAAE,aAAa,EAAE,MAAM,6CAA6C,CAAC;AAM5E,MAAM,OAAO,WAAW;IAEf,MAAM,CAAC,oBAAoB,CAAC,IAAgB,EAAE,UAAkB,IAAI;QACzE,MAAM,IAAI,GAAW,IAAI,CAAC,GAAG,CAAC,CAAC,CAAA,EAAE,CAAA,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;QAC5D,OAAO,IAAI,CAAC;IACd,CAAC;IAEM,MAAM,CAAC,uBAAuB,CAAC,IAAqB;QACzD,cAAc,CAAC,kB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private _width;
|
|
5
|
+
private _height;
|
|
6
|
+
private disabledIdx;
|
|
7
|
+
private passages;
|
|
8
|
+
constructor(_width: number, _height: number);
|
|
9
|
+
isDisabled(idx: number | Coordinate): boolean;
|
|
10
|
+
neighborCoordinate(idx: number | Coordinate, direction: Direction): Coordinate;
|
|
11
|
+
neighborIdx(idx: number, direction: Direction): number;
|
|
12
|
+
hasWall(idx: number | Coordinate, direction: Direction): boolean;
|
|
13
|
+
get width(): number;
|
|
14
|
+
get height(): number;
|
|
15
|
+
coordinateToIndex(coord: Coordinate): number;
|
|
16
|
+
indexToCoordinate(idx: number): Coordinate;
|
|
17
|
+
get maxIdx(): number;
|
|
18
|
+
validIdx(idx: number): boolean;
|
|
19
|
+
get allIdxWithPassages(): Set<number>;
|
|
20
|
+
disable(idx: number): void;
|
|
21
|
+
hasPassage(idx1: number, idx2: number): boolean;
|
|
22
|
+
addPassage(idxC1: number | Coordinate, idxC2: number | Coordinate): void;
|
|
23
|
+
removePassage(idx1: number, idx2: number): void;
|
|
24
|
+
}
|
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
import { RequireRatchet } from "@bitblit/ratchet-common/lang/require-ratchet";
|
|
2
|
+
import { Direction } from "./direction.js";
|
|
3
|
+
export class RectangularMaze {
|
|
4
|
+
_width;
|
|
5
|
+
_height;
|
|
6
|
+
disabledIdx = new Set();
|
|
7
|
+
passages = new Map();
|
|
8
|
+
constructor(_width, _height) {
|
|
9
|
+
this._width = _width;
|
|
10
|
+
this._height = _height;
|
|
11
|
+
}
|
|
12
|
+
isDisabled(idx) {
|
|
13
|
+
if (typeof idx === 'number') {
|
|
14
|
+
return this.disabledIdx.has(idx);
|
|
15
|
+
}
|
|
16
|
+
else {
|
|
17
|
+
return this.disabledIdx.has(this.coordinateToIndex(idx));
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
neighborCoordinate(idx, direction) {
|
|
21
|
+
let rval = structuredClone((typeof idx === 'number') ? this.indexToCoordinate(idx) : idx);
|
|
22
|
+
switch (direction) {
|
|
23
|
+
case Direction.North:
|
|
24
|
+
rval.y--;
|
|
25
|
+
break;
|
|
26
|
+
case Direction.South:
|
|
27
|
+
rval.y++;
|
|
28
|
+
break;
|
|
29
|
+
case Direction.East:
|
|
30
|
+
rval.x++;
|
|
31
|
+
break;
|
|
32
|
+
case Direction.West:
|
|
33
|
+
rval.x--;
|
|
34
|
+
break;
|
|
35
|
+
default: throw new Error('Cannot happen - invalid direction');
|
|
36
|
+
}
|
|
37
|
+
if (rval.x < 0 || rval.y < 0 || rval.x >= this.width || rval.y >= this.height) {
|
|
38
|
+
rval = null;
|
|
39
|
+
}
|
|
40
|
+
return rval;
|
|
41
|
+
}
|
|
42
|
+
neighborIdx(idx, direction) {
|
|
43
|
+
const n = this.neighborCoordinate(idx, direction);
|
|
44
|
+
return n === null ? null : this.coordinateToIndex(n);
|
|
45
|
+
}
|
|
46
|
+
hasWall(idx, direction) {
|
|
47
|
+
const idx1 = (typeof (idx) === 'number') ? idx : this.coordinateToIndex(idx);
|
|
48
|
+
const idx2 = this.neighborIdx(idx1, direction);
|
|
49
|
+
return !this.hasPassage(idx1, idx2);
|
|
50
|
+
}
|
|
51
|
+
get width() {
|
|
52
|
+
return this._width;
|
|
53
|
+
}
|
|
54
|
+
get height() {
|
|
55
|
+
return this._height;
|
|
56
|
+
}
|
|
57
|
+
coordinateToIndex(coord) {
|
|
58
|
+
RequireRatchet.true(coord.x < this.width);
|
|
59
|
+
RequireRatchet.true(coord.y < this.height);
|
|
60
|
+
return (coord.y * this.width) + coord.x;
|
|
61
|
+
}
|
|
62
|
+
indexToCoordinate(idx) {
|
|
63
|
+
const row = Math.floor(idx / this.width);
|
|
64
|
+
const rval = {
|
|
65
|
+
x: idx - (row * this.width),
|
|
66
|
+
y: row
|
|
67
|
+
};
|
|
68
|
+
return rval;
|
|
69
|
+
}
|
|
70
|
+
get maxIdx() {
|
|
71
|
+
return this.coordinateToIndex({ x: this.width - 1, y: this.height - 1 });
|
|
72
|
+
}
|
|
73
|
+
validIdx(idx) {
|
|
74
|
+
const crd = this.indexToCoordinate(idx);
|
|
75
|
+
return crd.x < this.width && crd.y < this.height;
|
|
76
|
+
}
|
|
77
|
+
get allIdxWithPassages() {
|
|
78
|
+
const rval = new Set();
|
|
79
|
+
Array.from(this.passages.values()).forEach(vals => {
|
|
80
|
+
Array.from(vals).forEach(s => rval.add(s));
|
|
81
|
+
});
|
|
82
|
+
return rval;
|
|
83
|
+
}
|
|
84
|
+
disable(idx) {
|
|
85
|
+
RequireRatchet.true(this.validIdx(idx));
|
|
86
|
+
RequireRatchet.true(!this.passages.has(idx));
|
|
87
|
+
RequireRatchet.true(!this.allIdxWithPassages.has(idx));
|
|
88
|
+
this.disabledIdx.add(idx);
|
|
89
|
+
}
|
|
90
|
+
hasPassage(idx1, idx2) {
|
|
91
|
+
let rval = false;
|
|
92
|
+
if (idx1 !== null && idx2 !== null) {
|
|
93
|
+
const vals = this.passages.get(Math.min(idx1, idx2));
|
|
94
|
+
rval = vals && vals.has(Math.max(idx1, idx2));
|
|
95
|
+
}
|
|
96
|
+
return rval;
|
|
97
|
+
}
|
|
98
|
+
addPassage(idxC1, idxC2) {
|
|
99
|
+
RequireRatchet.notNullOrUndefined(idxC1);
|
|
100
|
+
RequireRatchet.notNullOrUndefined(idxC2);
|
|
101
|
+
const idx1 = (typeof idxC1 === 'number') ? idxC1 : this.coordinateToIndex(idxC1);
|
|
102
|
+
const idx2 = (typeof idxC2 === 'number') ? idxC2 : this.coordinateToIndex(idxC2);
|
|
103
|
+
RequireRatchet.true(this.validIdx(idx1));
|
|
104
|
+
RequireRatchet.true(this.validIdx(idx2));
|
|
105
|
+
RequireRatchet.true(!this.disabledIdx.has(idx1));
|
|
106
|
+
RequireRatchet.true(!this.disabledIdx.has(idx2));
|
|
107
|
+
const cur = this.passages.get(Math.min(idx1, idx2)) ?? new Set;
|
|
108
|
+
cur.add(Math.max(idx1, idx2));
|
|
109
|
+
this.passages.set(Math.min(idx1, idx2), cur);
|
|
110
|
+
}
|
|
111
|
+
removePassage(idx1, idx2) {
|
|
112
|
+
RequireRatchet.true(this.validIdx(idx1));
|
|
113
|
+
RequireRatchet.true(this.validIdx(idx2));
|
|
114
|
+
const cur = this.passages.get(Math.min(idx1, idx2)) ?? new Set;
|
|
115
|
+
cur.delete(Math.max(idx1, idx2));
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
//# sourceMappingURL=rectangular-maze.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"rectangular-maze.js","sourceRoot":"","sources":["../../src/model/rectangular-maze.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,cAAc,EAAE,MAAM,8CAA8C,CAAC;AAC9E,OAAO,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC;AAK3C,MAAM,OAAO,eAAe;IAKN;IAAwB;IAHpC,WAAW,GAAgB,IAAI,GAAG,EAAU,CAAC;IAC7C,QAAQ,GAA6B,IAAI,GAAG,EAAuB,CAAC;IAE5E,YAAoB,MAAc,EAAU,OAAe;QAAvC,WAAM,GAAN,MAAM,CAAQ;QAAU,YAAO,GAAP,OAAO,CAAQ;IAC3D,CAAC;IAEM,UAAU,CAAC,GAAwB;QACxC,IAAI,OAAO,GAAG,KAAK,QAAQ,EAAE,CAAC;YAC5B,OAAO,IAAI,CAAC,WAAW,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC;QACnC,CAAC;aAAM,CAAC;YACN,OAAO,IAAI,CAAC,WAAW,CAAC,GAAG,CAAC,IAAI,CAAC,iBAAiB,CAAC,GAAG,CAAC,CAAC,CAAC;QAC3D,CAAC;IACH,CAAC;IAEM,kBAAkB,CAAC,GAAuB,EAAE,SAAoB;QACrE,IAAI,IAAI,GAAe,eAAe,CAAC,CAAC,OAAO,GAAG,KAAG,QAAQ,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,iBAAiB,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,CAA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C,CAAC;QAEzC,MAAM,GAAG,GAAgB,IAAI,CAAC,QAAQ,CAAC,GAAG,CAAC,IAAI,CAAC,GAAG,CAAC,IAAI,EAAE,IAAI,CAAC,CAAC,IAAI,IAAI,GAAW,CAAC;QACpF,GAAG,CAAC,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,IAAI,EAAE,IAAI,CAAC,CAAC,CAAC;IACnC,CAAC;CAEF"}
|
package/package.json
ADDED
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@bitblit/ratchet-maze",
|
|
3
|
+
"version": "5.1.609-alpha",
|
|
4
|
+
"description": "My silly tools for mazes",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"files": [
|
|
7
|
+
"lib/**",
|
|
8
|
+
"bin/**"
|
|
9
|
+
],
|
|
10
|
+
"exports": {
|
|
11
|
+
"./package.json": "./package.json",
|
|
12
|
+
"./*": {
|
|
13
|
+
"types": "./lib/*.d.ts",
|
|
14
|
+
"import": "./lib/*.js"
|
|
15
|
+
}
|
|
16
|
+
},
|
|
17
|
+
"contributors": [
|
|
18
|
+
"Christopher Weiss <bitblit@gmail.com>"
|
|
19
|
+
],
|
|
20
|
+
"husky": {
|
|
21
|
+
"hooks": {
|
|
22
|
+
"pre-commit": "pretty-quick --staged"
|
|
23
|
+
}
|
|
24
|
+
},
|
|
25
|
+
"config": {},
|
|
26
|
+
"repository": {
|
|
27
|
+
"type": "git",
|
|
28
|
+
"url": "git+https://github.com/bitblit/Ratchet.git"
|
|
29
|
+
},
|
|
30
|
+
"scripts": {
|
|
31
|
+
"t": "yarn mod:test"
|
|
32
|
+
},
|
|
33
|
+
"keywords": [
|
|
34
|
+
"wrench",
|
|
35
|
+
"utility"
|
|
36
|
+
],
|
|
37
|
+
"bugs": {
|
|
38
|
+
"url": "https://github.com/bitblit/Ratchet/issues"
|
|
39
|
+
},
|
|
40
|
+
"homepage": "https://github.com/bitblit/Ratchet#readme",
|
|
41
|
+
"engines": {
|
|
42
|
+
"node": ">=14.18"
|
|
43
|
+
},
|
|
44
|
+
"license": "Apache-2.0",
|
|
45
|
+
"dependencies": {
|
|
46
|
+
"@bitblit/ratchet-common": "5.1.609-alpha"
|
|
47
|
+
}
|
|
48
|
+
}
|