Skip to content

Commit 8db1b58

Browse files
authored
Transferring new bp docs (#353)
Co-authored-by: Yuri Iozzelli <y.iozzelli@gmail.com> Transferred all renewed BP docs from the temporary starlight repo to the labs repo making changes were necessary. # changelog ## general - adjusted frontmatter where needed - prefixed all files with numbers - removed index.md files and opted for generated TOC pages - fixed all links - moved external components to sites/browserpod/components and updated paths accordingly (using @/component) - moved images to /public/assets and adjusted paths ## reference section - Opted to keep the old structure of page per function for easier lookup and searching - Did use a custom index here for added context in binary file subsection ## Non transferred files - core-concepts/webessambly.md contained a general wasm definition. Seemed not fitting as core concept and has not been transferred. - Added mdn link to wasm entry in glossary instead - getting-started/setup.md found in files but not on website preview, not transferred - The following pages of the more/ section seemed to be empty placeholders and have hence not been transferred - change log - roadmap - support - about leaning tech - Links to non the non existent file /docs/core-concepts/runtime-model have been removed.
1 parent 319050d commit 8db1b58

29 files changed

+1200
-218
lines changed

packages/astro-theme/replace-variables.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { visit } from "unist-util-visit";
22

33
const replacements = {
44
CX_LATEST: "1.2.2",
5-
BP_LATEST: "0.9.7",
5+
BP_LATEST: "1.0",
66
};
77

88
export function remarkReplaceVars() {

sites/browserpod/public/browserpod/tutorials/bp-quickstart.png renamed to sites/browserpod/public/assets/bp-quickstart.png

File renamed without changes.
File renamed without changes.
-87.1 KB
Binary file not shown.
Lines changed: 260 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,260 @@
1+
---
2+
const {
3+
label = "Cube",
4+
type = "geojson",
5+
data = "",
6+
width = 320,
7+
height = 220,
8+
frameless = false,
9+
showLabel = true,
10+
showSource = false,
11+
} = Astro.props;
12+
const id = `cube-${Math.random().toString(36).slice(2)}`;
13+
---
14+
15+
<div
16+
class={`cube-preview ${frameless ? "is-frameless" : ""}`}
17+
{id}
18+
data-type={type}
19+
>
20+
{showLabel && <div class="cube-preview-header">{label}</div>}
21+
<canvas {width} {height} aria-label={`${label} preview`}></canvas>
22+
<script type="application/json" data-cube set:html={data} />
23+
{
24+
showSource && (
25+
<details class="cube-preview-source">
26+
<summary>Show source</summary>
27+
<pre>
28+
<code>{data}</code>
29+
</pre>
30+
</details>
31+
)
32+
}
33+
</div>
34+
35+
<style>
36+
.cube-preview {
37+
border: 1px solid var(--sl-color-hairline);
38+
border-radius: 12px;
39+
background: color-mix(in srgb, var(--bp-bg) 92%, transparent);
40+
padding: 10px;
41+
max-width: 520px;
42+
}
43+
.cube-preview.is-frameless {
44+
border: none;
45+
background: transparent;
46+
padding: 0;
47+
}
48+
.cube-preview-header {
49+
font-size: 0.85rem;
50+
font-weight: 600;
51+
margin: 0 0 8px;
52+
color: var(--bp-text);
53+
letter-spacing: 0.01em;
54+
}
55+
.cube-preview.is-frameless .cube-preview-header {
56+
margin-bottom: 6px;
57+
}
58+
.cube-preview canvas {
59+
width: 100%;
60+
height: auto;
61+
display: block;
62+
background: transparent;
63+
border-radius: 8px;
64+
}
65+
.cube-preview.is-frameless canvas {
66+
border-radius: 0;
67+
}
68+
.cube-preview-source {
69+
margin-top: 10px;
70+
}
71+
.cube-preview-source summary {
72+
cursor: pointer;
73+
color: var(--sl-color-text-accent);
74+
font-weight: 600;
75+
}
76+
</style>
77+
78+
<script>
79+
(() => {
80+
const rotate = (p, rx, ry) => {
81+
const [x, y, z] = p;
82+
const cosy = Math.cos(ry);
83+
const siny = Math.sin(ry);
84+
const cosx = Math.cos(rx);
85+
const sinx = Math.sin(rx);
86+
const x1 = x * cosy + z * siny;
87+
const z1 = -x * siny + z * cosy;
88+
const y1 = y * cosx - z1 * sinx;
89+
const z2 = y * sinx + z1 * cosx;
90+
return [x1, y1, z2];
91+
};
92+
93+
const parseGeoJSON = (raw) => {
94+
const data = JSON.parse(raw);
95+
const edges = [];
96+
const points = [];
97+
const addEdge = (a, b) => edges.push([a, b]);
98+
const addPoint = (p) => {
99+
points.push(p);
100+
return points.length - 1;
101+
};
102+
for (const f of data.features || []) {
103+
const rings = f.geometry?.coordinates || [];
104+
for (const ring of rings) {
105+
let prev = null;
106+
for (const coord of ring) {
107+
const idx = addPoint(coord);
108+
if (prev !== null) addEdge(prev, idx);
109+
prev = idx;
110+
}
111+
}
112+
}
113+
return { points, edges };
114+
};
115+
116+
const parseTopoJSON = (raw) => {
117+
const data = JSON.parse(raw);
118+
const arcs = data.arcs || [];
119+
const points = [];
120+
const edges = [];
121+
const addPoint = (p) => {
122+
points.push(p);
123+
return points.length - 1;
124+
};
125+
const addEdge = (a, b) => edges.push([a, b]);
126+
const resolveArc = (arcIndex) => {
127+
const reversed = arcIndex < 0;
128+
const arc = arcs[Math.abs(arcIndex)];
129+
const coords = reversed ? [...arc].reverse() : arc;
130+
return coords;
131+
};
132+
const geoms = data.objects?.cube?.geometries || [];
133+
for (const g of geoms) {
134+
for (const ring of g.arcs || []) {
135+
const arc = resolveArc(ring[0]);
136+
let prev = null;
137+
for (const coord of arc) {
138+
const idx = addPoint(coord);
139+
if (prev !== null) addEdge(prev, idx);
140+
prev = idx;
141+
}
142+
}
143+
}
144+
return { points, edges };
145+
};
146+
147+
const parseSTL = (raw) => {
148+
const points = [];
149+
const edges = [];
150+
const addPoint = (p) => {
151+
points.push(p);
152+
return points.length - 1;
153+
};
154+
const addEdge = (a, b) => edges.push([a, b]);
155+
const vertices = [];
156+
raw.split("\n").forEach((line) => {
157+
const m = line
158+
.trim()
159+
.match(/^vertex\\s+([-\\d.eE]+)\\s+([-\\d.eE]+)\\s+([-\\d.eE]+)$/);
160+
if (m) vertices.push([Number(m[1]), Number(m[2]), Number(m[3])]);
161+
});
162+
for (let i = 0; i + 2 < vertices.length; i += 3) {
163+
const a = addPoint(vertices[i]);
164+
const b = addPoint(vertices[i + 1]);
165+
const c = addPoint(vertices[i + 2]);
166+
addEdge(a, b);
167+
addEdge(b, c);
168+
addEdge(c, a);
169+
}
170+
if (!edges.length) return parseMermaid();
171+
return { points, edges };
172+
};
173+
174+
const parseMermaid = () => {
175+
const points = [
176+
[0, 0, 0],
177+
[1, 0, 0],
178+
[1, 1, 0],
179+
[0, 1, 0],
180+
[0, 0, 1],
181+
[1, 0, 1],
182+
[1, 1, 1],
183+
[0, 1, 1],
184+
];
185+
const edges = [
186+
[0, 1],
187+
[1, 2],
188+
[2, 3],
189+
[3, 0],
190+
[4, 5],
191+
[5, 6],
192+
[6, 7],
193+
[7, 4],
194+
[0, 4],
195+
[1, 5],
196+
[2, 6],
197+
[3, 7],
198+
];
199+
return { points, edges };
200+
};
201+
202+
const render = (el) => {
203+
const canvas = el.querySelector("canvas");
204+
const ctx = canvas.getContext("2d");
205+
const raw = el.querySelector("[data-cube]")?.textContent?.trim() || "";
206+
const type = el.dataset.type || "geojson";
207+
let model;
208+
if (type === "geojson") model = parseGeoJSON(raw);
209+
else if (type === "topojson") model = parseTopoJSON(raw);
210+
else if (type === "stl") model = parseSTL(raw);
211+
else model = parseMermaid();
212+
213+
const rotated = model.points.map((p) => rotate(p, 0.6, -0.7));
214+
const xs = rotated.map((p) => p[0]);
215+
const ys = rotated.map((p) => p[1]);
216+
const minX = Math.min(...xs);
217+
const maxX = Math.max(...xs);
218+
const minY = Math.min(...ys);
219+
const maxY = Math.max(...ys);
220+
const pad = 18;
221+
const scale = Math.min(
222+
(canvas.width - pad * 2) / (maxX - minX || 1),
223+
(canvas.height - pad * 2) / (maxY - minY || 1)
224+
);
225+
226+
const project = (p) => {
227+
const x = (p[0] - minX) * scale + pad;
228+
const y = (p[1] - minY) * scale + pad;
229+
return [x, canvas.height - y];
230+
};
231+
232+
ctx.clearRect(0, 0, canvas.width, canvas.height);
233+
const colorMap = {
234+
mermaid: "rgba(64, 255, 200, 0.95)",
235+
geojson: "rgba(59, 130, 246, 0.95)",
236+
topojson: "rgba(16, 185, 129, 0.95)",
237+
stl: "rgba(249, 115, 22, 0.95)",
238+
};
239+
ctx.lineWidth = 2;
240+
ctx.strokeStyle = colorMap[type] || "rgba(64, 255, 200, 0.95)";
241+
for (const [a, b] of model.edges) {
242+
const [x1, y1] = project(rotated[a]);
243+
const [x2, y2] = project(rotated[b]);
244+
ctx.beginPath();
245+
ctx.moveTo(x1, y1);
246+
ctx.lineTo(x2, y2);
247+
ctx.stroke();
248+
}
249+
};
250+
251+
const init = () =>
252+
document.querySelectorAll(".cube-preview").forEach(render);
253+
254+
if (document.readyState === "loading") {
255+
document.addEventListener("DOMContentLoaded", init, { once: true });
256+
} else {
257+
init();
258+
}
259+
})();
260+
</script>

0 commit comments

Comments
 (0)