@a2f0/skyline 0.1.7 → 0.2.2
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/README.md +3 -3
- package/docs/package.md +163 -25
- package/lib/skyline-package.d.ts +26 -18
- package/lib/skyline-package.js +10 -26
- package/lib/skyline-shell.d.ts +69 -0
- package/lib/skyline-shell.js +115 -0
- package/lib/skyline-three.d.ts +2 -0
- package/lib/skyline-three.js +10 -0
- package/lib/three-engine.d.ts +18 -0
- package/lib/three-engine.js +12 -0
- package/package.json +15 -4
- package/site/building-detail-page.js +16 -0
- package/site/building-detail.html +45 -38
- package/site/building-detail.js +25 -19
- package/site/index.html +21 -373
- package/site/markup.js +36 -0
- package/site/skyline-3d-page.js +12 -0
- package/site/skyline-3d.html +7 -11
- package/site/skyline-3d.js +396 -310
- package/site/skyline-shell.js +115 -0
- package/site/skyline-viewer.js +321 -0
- package/site/stars.svg +8 -6
- package/site/study-loader.js +0 -2
- package/site/study-viewer.js +97 -37
- package/site/study.css +57 -30
- package/site/three-engine.js +12 -0
- package/site/vendor/three-r186.bundle.js +4228 -0
- package/site/vendor/three-r186.js +11 -4228
- package/site/viewer-page.js +15 -0
- package/site/viewer.css +147 -0
package/site/markup.js
ADDED
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
// Loads the markup and styles the viewer renders in its shadow roots. The scene and the
|
|
2
|
+
// building detail keep their markup in their own pages, skyline-3d.html and
|
|
3
|
+
// building-detail.html, which also work on their own; the viewer takes it from there, so one
|
|
4
|
+
// copy serves both.
|
|
5
|
+
/**
|
|
6
|
+
* Fetches a page and parses it, leaving out its scripts and `noscript` fallbacks, with its
|
|
7
|
+
* links and sources resolved against the page's own address, so its elements can render in
|
|
8
|
+
* another document. Fragment links, such as an SVG `use` of a path beside it, stay as they are.
|
|
9
|
+
*/
|
|
10
|
+
export async function loadMarkup(url, signal) {
|
|
11
|
+
const response = await fetch(url, { signal });
|
|
12
|
+
if (!response.ok)
|
|
13
|
+
throw new Error(`Couldn't load ${url.href} (${response.status}).`);
|
|
14
|
+
const page = new DOMParser().parseFromString(await response.text(), "text/html");
|
|
15
|
+
page.querySelectorAll("script, noscript").forEach((element) => element.remove());
|
|
16
|
+
for (const element of page.querySelectorAll("[href], [src]")) {
|
|
17
|
+
for (const name of ["href", "src"]) {
|
|
18
|
+
const value = element.getAttribute(name);
|
|
19
|
+
if (value !== null && !value.startsWith("#"))
|
|
20
|
+
element.setAttribute(name, new URL(value, url).href);
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
return page;
|
|
24
|
+
}
|
|
25
|
+
/** Adds a stylesheet to a shadow root, and resolves once it has loaded. */
|
|
26
|
+
export function loadStylesheet(root, url) {
|
|
27
|
+
const link = root.ownerDocument.createElement("link");
|
|
28
|
+
link.rel = "stylesheet";
|
|
29
|
+
link.href = url.href;
|
|
30
|
+
const loaded = new Promise((resolve, reject) => {
|
|
31
|
+
link.addEventListener("load", () => resolve(), { once: true });
|
|
32
|
+
link.addEventListener("error", () => reject(new Error(`Couldn't load ${url.href}.`)), { once: true });
|
|
33
|
+
});
|
|
34
|
+
root.prepend(link);
|
|
35
|
+
return loaded;
|
|
36
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { startSkyline3d } from "./skyline-3d.js";
|
|
2
|
+
// skyline-3d.html: the full-screen 3D skyline on a page of its own, which has no drawing to
|
|
3
|
+
// switch to. Its address's settings were applied before the scene's code arrived.
|
|
4
|
+
const life = new AbortController();
|
|
5
|
+
try {
|
|
6
|
+
startSkyline3d({ root: document, frame: document.body, assets: new URL("./", location.href), signal: life.signal });
|
|
7
|
+
}
|
|
8
|
+
catch (error) {
|
|
9
|
+
// A scene that fails part way releases what it started; study-loader.js says why.
|
|
10
|
+
life.abort(error);
|
|
11
|
+
throw error;
|
|
12
|
+
}
|
package/site/skyline-3d.html
CHANGED
|
@@ -31,9 +31,9 @@
|
|
|
31
31
|
<p class="visually-hidden" id="motion-status" role="status">Camera moves only when you interact or start the turntable.</p>
|
|
32
32
|
<p class="visually-hidden" id="celebration-announcement" role="status"></p>
|
|
33
33
|
<noscript><style>#loading { display: none; }</style><p class="loading">Enable JavaScript to explore the 3D skyline.</p></noscript>
|
|
34
|
-
<
|
|
34
|
+
<section class="detail-panel" id="building-detail" role="dialog" aria-label="Building detail" hidden>
|
|
35
35
|
<button type="button" class="detail-close" id="detail-close" aria-label="Close building detail" title="Close (Esc)">×</button>
|
|
36
|
-
</
|
|
36
|
+
</section>
|
|
37
37
|
</main>
|
|
38
38
|
<footer class="control-bar" aria-label="3D skyline controls">
|
|
39
39
|
<!-- Chicago's six-pointed star, after devopsrockstars' white-star-only.svg, drawn in
|
|
@@ -79,16 +79,12 @@
|
|
|
79
79
|
</div>
|
|
80
80
|
</footer>
|
|
81
81
|
<script>
|
|
82
|
-
// Settings from this page's address,
|
|
83
|
-
//
|
|
84
|
-
//
|
|
82
|
+
// Settings from this page's address, applied before the bar's first frame.
|
|
83
|
+
// ?controls=open starts the bar open, with no fold; skyline-3d.ts folds it from there.
|
|
84
|
+
// ?attribution=hidden leaves out the OpenStreetMap credit. The viewer, which renders this
|
|
85
|
+
// markup in its shadow root, applies its own options the same way (skyline-viewer.ts).
|
|
85
86
|
(() => {
|
|
86
87
|
const settings = new URLSearchParams(location.search);
|
|
87
|
-
try {
|
|
88
|
-
if (parent !== window && parent.document.querySelector("#skyline-3d-scene")?.contentWindow === window) {
|
|
89
|
-
for (const [key, value] of new URLSearchParams(parent.location.search)) if (!settings.has(key)) settings.set(key, value);
|
|
90
|
-
}
|
|
91
|
-
} catch { /* A scene embedded on another origin reads only its own address. */ }
|
|
92
88
|
if (settings.get("controls") === "open") {
|
|
93
89
|
const toggle = document.querySelector("#menu-toggle");
|
|
94
90
|
toggle.setAttribute("aria-expanded", "true");
|
|
@@ -107,6 +103,6 @@
|
|
|
107
103
|
</div>
|
|
108
104
|
</div>
|
|
109
105
|
<!-- The loader is compiled into dist/; opened from the sources, say how to build it. -->
|
|
110
|
-
<script src="study-loader.js" data-study="./skyline-3d.js" onerror="document.querySelector('#loading').textContent = 'Build the site with bun run build:site, then serve dist/ with python3 -m http.server -d dist to explore the 3D skyline.'"></script>
|
|
106
|
+
<script src="study-loader.js" data-study="./skyline-3d-page.js" onerror="document.querySelector('#loading').textContent = 'Build the site with bun run build:site, then serve dist/ with python3 -m http.server -d dist to explore the 3D skyline.'"></script>
|
|
111
107
|
</body>
|
|
112
108
|
</html>
|