Skip to content

Commit c960405

Browse files
committed
update examples
1 parent 74521bc commit c960405

File tree

5 files changed

+724
-732
lines changed

5 files changed

+724
-732
lines changed

website/bun.lock

Lines changed: 29 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -5,48 +5,48 @@
55
"dependencies": {
66
"@b9g/crank": "^0.6.0",
77
"@b9g/revise": "^0.1.2",
8-
"@b9g/shovel": "^0.1.8",
9-
"@babel/core": "^7.21.0",
10-
"@babel/preset-react": "^7.18.6",
11-
"@babel/preset-typescript": "^7.21.0",
12-
"@emotion/css": "^11.10.6",
13-
"@emotion/server": "^11.10.0",
8+
"@b9g/shovel": "^0.1.9",
9+
"@babel/core": "^7.26.10",
10+
"@babel/preset-react": "^7.26.3",
11+
"@babel/preset-typescript": "^7.27.0",
12+
"@emotion/css": "^11.13.5",
13+
"@emotion/server": "^11.11.0",
1414
"@esbuild-plugins/node-globals-polyfill": "^0.2.3",
1515
"@esbuild-plugins/node-modules-polyfill": "^0.2.2",
16-
"@lezer/javascript": "^1.4.13",
17-
"@remix-run/web-fetch": "^4.3.2",
18-
"@tanstack/virtual-core": "^3.0.0-alpha.1",
19-
"@types/babel__core": "^7.20.0",
20-
"@types/lz-string": "^1.3.34",
21-
"@types/marked": "^4.0.8",
22-
"@types/mime-types": "^2.1.1",
23-
"@types/node": "^18.14.1",
16+
"@lezer/javascript": "^1.4.21",
17+
"@remix-run/web-fetch": "^4.4.2",
18+
"@tanstack/virtual-core": "^3.13.6",
19+
"@types/babel__core": "^7.20.5",
20+
"@types/lz-string": "^1.5.0",
21+
"@types/marked": "^4.3.2",
22+
"@types/mime-types": "^2.1.4",
23+
"@types/node": "^18.19.86",
2424
"@types/postcss-nested": "^4.2.3",
2525
"@types/postcss-preset-env": "^7.7.0",
26-
"@types/prismjs": "^1.26.0",
27-
"chokidar": "^3.5.3",
28-
"esbuild": "^0.20.0",
26+
"@types/prismjs": "^1.26.5",
27+
"chokidar": "^3.6.0",
28+
"esbuild": "^0.20.2",
2929
"front-matter": "^4.0.2",
3030
"gh-pages": "^5.0.0",
3131
"http-server": "^14.1.1",
32-
"lz-string": "^1.4.4",
33-
"marked": "^4.2.12",
32+
"lz-string": "^1.5.0",
33+
"marked": "^4.3.0",
3434
"mime-types": "^2.1.35",
35-
"nodemon": "^2.0.20",
35+
"nodemon": "^2.0.22",
3636
"normalize.css": "^8.0.1",
37-
"path-to-regexp": "^6.2.1",
38-
"postcss-nested": "^6.0.1",
39-
"postcss-preset-env": "^8.0.1",
37+
"path-to-regexp": "^6.3.0",
38+
"postcss-nested": "^6.2.0",
39+
"postcss-preset-env": "^8.5.1",
4040
"prism-themes": "^1.9.0",
41-
"prismjs": "^1.29.0",
42-
"serialize-javascript": "^6.0.1",
43-
"sucrase": "^3.29.0",
44-
"truncate-html": "^1.0.4",
45-
"ts-node": "^10.9.1",
41+
"prismjs": "^1.30.0",
42+
"serialize-javascript": "^6.0.2",
43+
"sucrase": "^3.35.0",
44+
"truncate-html": "^1.2.1",
45+
"ts-node": "^10.9.2",
4646
"typescript": "^4.9.5",
4747
},
4848
"devDependencies": {
49-
"@types/serialize-javascript": "^5.0.2",
49+
"@types/serialize-javascript": "^5.0.4",
5050
},
5151
},
5252
},

website/examples/minesweeper.ts

Lines changed: 63 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,17 @@
1-
import {jsx} from "@b9g/crank/standalone";
1+
emport {jsx} from "@b9g/crank/standalone";
22
import {renderer} from "@b9g/crank/dom";
33

44
function Hexagon({cx = 0, cy = 0, r, ...props}) {
5-
if (!r) {
6-
return null;
7-
}
5+
if (!r) {
6+
return null;
7+
}
88

9-
const points = [];
10-
for (let i = 0, a = 0; i < 6; i++, a += Math.PI / 3) {
11-
points.push([cx + Math.cos(a) * r, cy + Math.sin(a) * r]);
12-
}
9+
const points = [];
10+
for (let i = 0, a = 0; i < 6; i++, a += Math.PI / 3) {
11+
points.push([cx + Math.cos(a) * r, cy + Math.sin(a) * r]);
12+
}
1313

14-
return jsx`
14+
return jsx`
1515
<path
1616
...${props}
1717
d="M ${points.map(([x, y], i) => `${i > 0 ? "L" : ""} ${x} ${y}`)} Z"
@@ -20,26 +20,26 @@ function Hexagon({cx = 0, cy = 0, r, ...props}) {
2020
}
2121

2222
function centerCoordsFor(cell, size) {
23-
const colSpacing = (size * 3) / 2;
24-
const rowSpacing = Math.sqrt(3) * size;
25-
return {
26-
cx: cell.col * colSpacing,
27-
cy: cell.row * rowSpacing + (cell.col % 2 === 0 ? 0 : rowSpacing / 2),
28-
};
23+
const colSpacing = (size * 3) / 2;
24+
const rowSpacing = Math.sqrt(3) * size;
25+
return {
26+
cx: cell.col * colSpacing,
27+
cy: cell.row * rowSpacing + (cell.col % 2 === 0 ? 0 : rowSpacing / 2),
28+
};
2929
}
3030

3131
function axialCoordsFor(cell) {
32-
return {q: cell.col, r: cell.row - Math.floor(cell.col / 2)};
32+
return {q: cell.col, r: cell.row - Math.floor(cell.col / 2)};
3333
}
3434

3535
function HexagonalGrid({radius = 20, cells /*, testCell*/}) {
36-
return cells.map((cell /*, i*/) => {
37-
const onclick = () => {
38-
//console.log(neighborsOf(cell, cells));
39-
};
40-
const {cx, cy} = centerCoordsFor(cell, radius);
41-
const {q, r} = axialCoordsFor(cell);
42-
return jsx`
36+
return cells.map((cell /*, i*/) => {
37+
const onclick = () => {
38+
//console.log(neighborsOf(cell, cells));
39+
};
40+
const {cx, cy} = centerCoordsFor(cell, radius);
41+
const {q, r} = axialCoordsFor(cell);
42+
return jsx`
4343
<${Hexagon}
4444
r=${radius}
4545
cx=${cx} cy=${cy}
@@ -67,58 +67,58 @@ function HexagonalGrid({radius = 20, cells /*, testCell*/}) {
6767
>${q},${r}</text>
6868
-->
6969
`;
70-
});
70+
});
7171
}
7272

7373
function shuffle(arr) {
74-
for (let i = arr.length - 1; i > 0; i--) {
75-
const j = Math.floor(Math.random() * (i + 1));
76-
[arr[i], arr[j]] = [arr[j], arr[i]];
77-
}
74+
for (let i = arr.length - 1; i > 0; i--) {
75+
const j = Math.floor(Math.random() * (i + 1));
76+
[arr[i], arr[j]] = [arr[j], arr[i]];
77+
}
7878

79-
return arr;
79+
return arr;
8080
}
8181

8282
function neighborsOf(cell, cells) {
83-
const {q, r} = axialCoordsFor(cell);
84-
const vectors = [
85-
[1, 0],
86-
[0, 1],
87-
[-1, 1],
88-
[-1, 0],
89-
[0, -1],
90-
[1, -1],
91-
];
92-
const axialSet = new Set(vectors.map(([q1, r1]) => `${q + q1},${r + r1}`));
93-
return cells.filter((cell1) => {
94-
const {q, r} = axialCoordsFor(cell1);
95-
return axialSet.has(`${q},${r}`);
96-
});
83+
const {q, r} = axialCoordsFor(cell);
84+
const vectors = [
85+
[1, 0],
86+
[0, 1],
87+
[-1, 1],
88+
[-1, 0],
89+
[0, -1],
90+
[1, -1],
91+
];
92+
const axialSet = new Set(vectors.map(([q1, r1]) => `${q + q1},${r + r1}`));
93+
return cells.filter((cell1) => {
94+
const {q, r} = axialCoordsFor(cell1);
95+
return axialSet.has(`${q},${r}`);
96+
});
9797
}
9898

9999
function* Minesweeper() {
100-
const rows = 12,
101-
cols = 15;
102-
const cells = [];
103-
for (let row = 0; row < rows; row++) {
104-
for (let col = 0; col < cols; col++) {
105-
cells.push({row, col, bomb: false, bombCount: 0});
106-
}
107-
}
100+
const rows = 12,
101+
cols = 15;
102+
const cells = [];
103+
for (let row = 0; row < rows; row++) {
104+
for (let col = 0; col < cols; col++) {
105+
cells.push({row, col, bomb: false, bombCount: 0});
106+
}
107+
}
108108

109-
for (const cell of shuffle(cells.slice()).slice(0, 30)) {
110-
cell.bomb = true;
111-
}
109+
for (const cell of shuffle(cells.slice()).slice(0, 30)) {
110+
cell.bomb = true;
111+
}
112112

113-
for (const cell of cells) {
114-
cell.bombCount = neighborsOf(cell, cells).reduce(
115-
(a, c) => a + (c.bomb ? 1 : 0),
116-
0,
117-
);
118-
}
113+
for (const cell of cells) {
114+
cell.bombCount = neighborsOf(cell, cells).reduce(
115+
(a, c) => a + (c.bomb ? 1 : 0),
116+
0,
117+
);
118+
}
119119

120-
for ({} of this) {
121-
yield jsx`
120+
for ({} of this) {
121+
yield jsx`
122122
<svg
123123
width="500px"
124124
height="500px"
@@ -131,7 +131,7 @@ function* Minesweeper() {
131131
<${HexagonalGrid} cells=${cells} radius=${15} />
132132
</svg>
133133
`;
134-
}
134+
}
135135
}
136136

137137
renderer.render(jsx`<${Minesweeper} />`, document.body);

0 commit comments

Comments
 (0)