@tileflow/dev 0.1.0-alpha.4 → 0.1.0-alpha.41
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/LICENSE +201 -0
- package/README.md +264 -5
- package/THIRD_PARTY_NOTICES.md +309 -0
- package/dist/artifacts.d.ts +269 -0
- package/dist/artifacts.js +98 -0
- package/dist/chunk-AQUGMUZW.js +324 -0
- package/dist/chunk-C4VPHZ3F.js +4062 -0
- package/dist/chunk-D4OE4ITL.js +13 -0
- package/dist/chunk-FOMTSCOP.js +671 -0
- package/dist/chunk-GXLY73PD.js +3199 -0
- package/dist/chunk-KDFTE4Q5.js +156 -0
- package/dist/chunk-ONYQNLNA.js +1108 -0
- package/dist/chunk-RTU7TD4M.js +172 -0
- package/dist/chunk-XHJBCVBB.js +241 -0
- package/dist/config.d.ts +33 -0
- package/dist/config.js +27 -0
- package/dist/fonts.d.ts +47 -0
- package/dist/fonts.js +16 -0
- package/dist/icons-BIHpw5Zy.d.ts +417 -0
- package/dist/icons.d.ts +3 -0
- package/dist/icons.js +41 -0
- package/dist/inspect.d.ts +149 -0
- package/dist/inspect.js +805 -0
- package/dist/inspector-browser.js +16955 -0
- package/dist/inspector-observer.js +95 -0
- package/dist/preview-assets-ATLLYY72.js +103 -0
- package/dist/preview.d.ts +31 -0
- package/dist/preview.js +1974 -0
- package/dist/server.d.ts +89 -0
- package/dist/server.js +3662 -0
- package/dist/tilesets.d.ts +89 -0
- package/dist/tilesets.js +6 -0
- package/dist/validation.d.ts +65 -0
- package/dist/validation.js +24 -0
- package/package.json +77 -13
- package/ui-fonts/hubot-sans-OFL.txt +93 -0
- package/ui-fonts/hubot-sans.woff2 +0 -0
- package/ui-fonts/inter-OFL.txt +92 -0
- package/ui-fonts/inter.woff2 +0 -0
- package/ui-fonts/jetbrains-mono-OFL.txt +93 -0
- package/ui-fonts/jetbrains-mono.woff2 +0 -0
- package/ui-fonts/mona-sans-OFL.txt +93 -0
- package/ui-fonts/mona-sans.woff2 +0 -0
- package/dist/index.d.ts +0 -54
- package/dist/index.js +0 -314
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
// src/inspector/observer.ts
|
|
2
|
+
function resourceAddress(input, base = "http://localhost") {
|
|
3
|
+
try {
|
|
4
|
+
const url = new URL(input.replace(/^(?:tileflow-pmtiles|pmtiles):\/\//u, ""), base);
|
|
5
|
+
if (!["http:", "https:"].includes(url.protocol)) return url.protocol;
|
|
6
|
+
return `${url.origin}${url.pathname}`.slice(0, 2048);
|
|
7
|
+
} catch {
|
|
8
|
+
return "(unavailable URL)";
|
|
9
|
+
}
|
|
10
|
+
}
|
|
11
|
+
function resourceKind(url, initiator = "") {
|
|
12
|
+
if (/\.(?:pbf|mvt|mlt)(?:$|\?)/iu.test(url)) return /glyph|font/iu.test(url) ? "Font" : "Tile";
|
|
13
|
+
if (/\.pmtiles(?:$|\?)/iu.test(url)) return "Archive";
|
|
14
|
+
if (/\/(?:\d+)\/(?:\d+)\/(?:\d+)(?:\.[a-z]+)?(?:$|\?)/iu.test(url)) return "Tile";
|
|
15
|
+
if (/sprite/iu.test(url)) return "Sprite";
|
|
16
|
+
if (/\.(?:woff2?|ttf|otf)(?:$|\?)/iu.test(url)) return "Font";
|
|
17
|
+
if (/\.(?:glb|gltf)(?:$|\?)/iu.test(url)) return "Model";
|
|
18
|
+
if (/\.json(?:$|\?)/iu.test(url)) return "JSON";
|
|
19
|
+
return initiator === "script" || /\.m?js(?:$|\?)/iu.test(url) ? "Script" : "Other";
|
|
20
|
+
}
|
|
21
|
+
function createPreviewObserver() {
|
|
22
|
+
let nextId = 0;
|
|
23
|
+
const seen = /* @__PURE__ */ new Set();
|
|
24
|
+
const limit = 2e3;
|
|
25
|
+
let map;
|
|
26
|
+
const observer = {
|
|
27
|
+
records: [],
|
|
28
|
+
revision: 0,
|
|
29
|
+
dropped: 0,
|
|
30
|
+
recording: true,
|
|
31
|
+
attach(value) {
|
|
32
|
+
map = value;
|
|
33
|
+
map.on("data", onData);
|
|
34
|
+
if (!map.loaded()) map.once("load", onLoad);
|
|
35
|
+
},
|
|
36
|
+
clear() {
|
|
37
|
+
observer.records.length = 0;
|
|
38
|
+
observer.dropped = 0;
|
|
39
|
+
observer.revision++;
|
|
40
|
+
},
|
|
41
|
+
dispose() {
|
|
42
|
+
performanceObserver?.disconnect();
|
|
43
|
+
map?.off("data", onData);
|
|
44
|
+
map?.off("load", onLoad);
|
|
45
|
+
seen.clear();
|
|
46
|
+
}
|
|
47
|
+
};
|
|
48
|
+
function onLoad() {
|
|
49
|
+
observer.mapReadyMs = performance.now();
|
|
50
|
+
}
|
|
51
|
+
function record(entry) {
|
|
52
|
+
if (!observer.recording) return;
|
|
53
|
+
const key = `${entry.name}|${entry.startTime}|${entry.duration}`;
|
|
54
|
+
if (seen.has(key)) return;
|
|
55
|
+
seen.add(key);
|
|
56
|
+
if (seen.size > limit * 2) seen.delete(seen.values().next().value);
|
|
57
|
+
const url = resourceAddress(entry.name, location.href);
|
|
58
|
+
if (/\/__(?:status|events|workbench|inspection)/u.test(url)) return;
|
|
59
|
+
const sizesAvailable = entry.decodedBodySize > 0 || entry.encodedBodySize > 0;
|
|
60
|
+
const status = entry.responseStatus;
|
|
61
|
+
const item = {
|
|
62
|
+
id: ++nextId,
|
|
63
|
+
url,
|
|
64
|
+
name: /\/\d+\/\d+\/\d+(?:\.[a-z]+)?$/iu.exec(url)?.[0].slice(1) || url.split("/").pop() || url,
|
|
65
|
+
kind: resourceKind(url, entry.initiatorType),
|
|
66
|
+
transport: "resource",
|
|
67
|
+
start: Number.isFinite(entry.startTime) ? Math.max(0, entry.startTime) : 0,
|
|
68
|
+
duration: Number.isFinite(entry.duration) && entry.duration >= 0 ? entry.duration : void 0,
|
|
69
|
+
status: status ? String(status) : "\u2014",
|
|
70
|
+
...sizesAvailable ? { bytes: entry.encodedBodySize, transferred: entry.transferSize } : {}
|
|
71
|
+
};
|
|
72
|
+
if (entry.transferSize === 0 && sizesAvailable) item.status = "Cached";
|
|
73
|
+
observer.records.push(item);
|
|
74
|
+
if (observer.records.length > limit) {
|
|
75
|
+
observer.records.shift();
|
|
76
|
+
observer.dropped++;
|
|
77
|
+
}
|
|
78
|
+
observer.revision++;
|
|
79
|
+
}
|
|
80
|
+
function onData(event) {
|
|
81
|
+
const timings = event.resourceTiming;
|
|
82
|
+
for (const timing of timings || []) record(timing);
|
|
83
|
+
}
|
|
84
|
+
const performanceObserver = typeof PerformanceObserver === "undefined" ? void 0 : new PerformanceObserver((list) => {
|
|
85
|
+
for (const entry of list.getEntries()) record(entry);
|
|
86
|
+
});
|
|
87
|
+
performanceObserver?.observe({ type: "resource", buffered: true });
|
|
88
|
+
addEventListener("pagehide", observer.dispose, { once: true });
|
|
89
|
+
return observer;
|
|
90
|
+
}
|
|
91
|
+
export {
|
|
92
|
+
createPreviewObserver,
|
|
93
|
+
resourceAddress,
|
|
94
|
+
resourceKind
|
|
95
|
+
};
|
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
import {
|
|
2
|
+
isPathWithin
|
|
3
|
+
} from "./chunk-D4OE4ITL.js";
|
|
4
|
+
|
|
5
|
+
// src/preview-assets.ts
|
|
6
|
+
import { readFileSync } from "fs";
|
|
7
|
+
import { createRequire } from "module";
|
|
8
|
+
import { dirname, join } from "path";
|
|
9
|
+
var localRequire = createRequire(import.meta.url);
|
|
10
|
+
var localMapLibreAssets = /* @__PURE__ */ new Map();
|
|
11
|
+
var localTileflowBrowserJavaScript;
|
|
12
|
+
var localThreeCoreJavaScript;
|
|
13
|
+
var localThreeModuleJavaScript;
|
|
14
|
+
function getTileflowPreviewRuntimeResponse(path) {
|
|
15
|
+
if (path === "/__runtime/inspector-observer.js") {
|
|
16
|
+
return textAssetResponse(
|
|
17
|
+
readFileSync(new URL("../dist/inspector-observer.js", import.meta.url), "utf8"),
|
|
18
|
+
"text/javascript; charset=utf-8"
|
|
19
|
+
);
|
|
20
|
+
}
|
|
21
|
+
if (path === "/__runtime/maplibre-gl.mjs") {
|
|
22
|
+
return textAssetResponse(
|
|
23
|
+
getLocalMapLibreAsset("maplibre-gl.mjs"),
|
|
24
|
+
"text/javascript; charset=utf-8"
|
|
25
|
+
);
|
|
26
|
+
}
|
|
27
|
+
if (path === "/__runtime/maplibre-gl-worker.mjs") {
|
|
28
|
+
return textAssetResponse(
|
|
29
|
+
getLocalMapLibreAsset("maplibre-gl-worker.mjs"),
|
|
30
|
+
"text/javascript; charset=utf-8"
|
|
31
|
+
);
|
|
32
|
+
}
|
|
33
|
+
if (path === "/__runtime/maplibre-gl.css") {
|
|
34
|
+
return textAssetResponse(getLocalMapLibreAsset("maplibre-gl.css"), "text/css; charset=utf-8");
|
|
35
|
+
}
|
|
36
|
+
if (path === "/__runtime/tileflow-browser.js") {
|
|
37
|
+
return textAssetResponse(getLocalTileflowBrowserAsset(), "text/javascript; charset=utf-8");
|
|
38
|
+
}
|
|
39
|
+
if (path === "/__runtime/three.module.js") {
|
|
40
|
+
return textAssetResponse(getLocalThreeAsset("module"), "text/javascript; charset=utf-8");
|
|
41
|
+
}
|
|
42
|
+
if (path === "/__runtime/three.core.min.js") {
|
|
43
|
+
return textAssetResponse(getLocalThreeAsset("core"), "text/javascript; charset=utf-8");
|
|
44
|
+
}
|
|
45
|
+
if (path.startsWith("/__runtime/three-addons/")) {
|
|
46
|
+
return textAssetResponse(
|
|
47
|
+
getLocalThreeAddonAsset(path.slice("/__runtime/three-addons/".length)),
|
|
48
|
+
"text/javascript; charset=utf-8"
|
|
49
|
+
);
|
|
50
|
+
}
|
|
51
|
+
return void 0;
|
|
52
|
+
}
|
|
53
|
+
function getLocalMapLibreAsset(fileName) {
|
|
54
|
+
const cached = localMapLibreAssets.get(fileName);
|
|
55
|
+
if (cached !== void 0) return cached;
|
|
56
|
+
const source = readFileSync(localRequire.resolve(`maplibre-gl/dist/${fileName}`), "utf8");
|
|
57
|
+
localMapLibreAssets.set(fileName, source);
|
|
58
|
+
return source;
|
|
59
|
+
}
|
|
60
|
+
function getLocalTileflowBrowserAsset() {
|
|
61
|
+
if (localTileflowBrowserJavaScript !== void 0) return localTileflowBrowserJavaScript;
|
|
62
|
+
const packagePath = localRequire.resolve("@tileflow/core/package.json");
|
|
63
|
+
localTileflowBrowserJavaScript = readFileSync(
|
|
64
|
+
join(dirname(packagePath), "dist", "browser.js"),
|
|
65
|
+
"utf8"
|
|
66
|
+
);
|
|
67
|
+
return localTileflowBrowserJavaScript;
|
|
68
|
+
}
|
|
69
|
+
function getLocalThreeAsset(kind) {
|
|
70
|
+
if (kind === "core" && localThreeCoreJavaScript !== void 0) return localThreeCoreJavaScript;
|
|
71
|
+
if (kind === "module" && localThreeModuleJavaScript !== void 0)
|
|
72
|
+
return localThreeModuleJavaScript;
|
|
73
|
+
const commonJsPath = localRequire.resolve("three");
|
|
74
|
+
const source = readFileSync(
|
|
75
|
+
join(dirname(commonJsPath), kind === "core" ? "three.core.min.js" : "three.module.min.js"),
|
|
76
|
+
"utf8"
|
|
77
|
+
);
|
|
78
|
+
if (kind === "core") localThreeCoreJavaScript = source;
|
|
79
|
+
else localThreeModuleJavaScript = source;
|
|
80
|
+
return source;
|
|
81
|
+
}
|
|
82
|
+
function getLocalThreeAddonAsset(relativePath) {
|
|
83
|
+
if (!/^[A-Za-z0-9_./-]+\.js$/.test(relativePath) || relativePath.includes("..")) {
|
|
84
|
+
throw new Error("Invalid Three.js addon path.");
|
|
85
|
+
}
|
|
86
|
+
const commonJsPath = localRequire.resolve("three");
|
|
87
|
+
const addonRoot = join(dirname(dirname(commonJsPath)), "examples", "jsm");
|
|
88
|
+
const assetPath = join(addonRoot, relativePath);
|
|
89
|
+
if (!isPathWithin(addonRoot, assetPath)) throw new Error("Invalid Three.js addon path.");
|
|
90
|
+
return readFileSync(assetPath, "utf8");
|
|
91
|
+
}
|
|
92
|
+
function textAssetResponse(body, contentType) {
|
|
93
|
+
return new Response(body, {
|
|
94
|
+
headers: {
|
|
95
|
+
"Access-Control-Allow-Origin": "*",
|
|
96
|
+
"Cache-Control": "no-store",
|
|
97
|
+
"Content-Type": contentType
|
|
98
|
+
}
|
|
99
|
+
});
|
|
100
|
+
}
|
|
101
|
+
export {
|
|
102
|
+
getTileflowPreviewRuntimeResponse
|
|
103
|
+
};
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { TileflowStyleFontFace, NormalizedTileflowCaptureScene } from '@tileflow/core';
|
|
2
|
+
import { TileflowBuildCatalog } from '@tileflow/core/build';
|
|
3
|
+
|
|
4
|
+
declare function renderTileflowPreviewHtml(preview: ResolvedTileflowPreview | undefined, basePath: string, initialStatus: unknown, isSemanticPreview: boolean, fontFaces?: readonly TileflowStyleFontFace[], fitViewport?: boolean, controls?: string): string;
|
|
5
|
+
|
|
6
|
+
/** Reads a response without ever buffering more than the declared bound. */
|
|
7
|
+
declare function readBoundedTileflowResponse(response: Response, maximumBytes: number): Promise<Uint8Array>;
|
|
8
|
+
/** Reads and strictly decodes a bounded UTF-8 JSON response. */
|
|
9
|
+
declare function readBoundedTileflowJsonResponse(response: Response, maximumBytes: number): Promise<unknown>;
|
|
10
|
+
|
|
11
|
+
type TileflowPreviewSelection = {
|
|
12
|
+
map?: string;
|
|
13
|
+
scene?: string;
|
|
14
|
+
theme?: string;
|
|
15
|
+
};
|
|
16
|
+
type ResolvedTileflowPreview = {
|
|
17
|
+
camera: NormalizedTileflowCaptureScene['camera'];
|
|
18
|
+
label: string;
|
|
19
|
+
mapName: string;
|
|
20
|
+
themeName: string;
|
|
21
|
+
/** Every theme of a map preview, in declaration order. A scene owns its theme and omits this. */
|
|
22
|
+
themeNames?: readonly string[];
|
|
23
|
+
viewport?: NormalizedTileflowCaptureScene['viewport'];
|
|
24
|
+
};
|
|
25
|
+
declare class TileflowPreviewSelectionError extends Error {
|
|
26
|
+
readonly code: "PREVIEW_SELECTION_INVALID";
|
|
27
|
+
constructor(message: string);
|
|
28
|
+
}
|
|
29
|
+
declare function resolveTileflowPreview(project: TileflowBuildCatalog, selection?: TileflowPreviewSelection): ResolvedTileflowPreview;
|
|
30
|
+
|
|
31
|
+
export { type ResolvedTileflowPreview, type TileflowPreviewSelection, TileflowPreviewSelectionError, readBoundedTileflowJsonResponse, readBoundedTileflowResponse, renderTileflowPreviewHtml, resolveTileflowPreview };
|