@copilotkit/shared 2.0.0-rc.37 → 2.0.0-rc.39
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/dist/generative-ui/clone-value.cjs +364 -0
- package/dist/generative-ui/clone-value.cjs.map +1 -0
- package/dist/generative-ui/clone-value.d.cts +51 -0
- package/dist/generative-ui/clone-value.d.cts.map +1 -0
- package/dist/generative-ui/clone-value.d.mts +51 -0
- package/dist/generative-ui/clone-value.d.mts.map +1 -0
- package/dist/generative-ui/clone-value.mjs +363 -0
- package/dist/generative-ui/clone-value.mjs.map +1 -0
- package/dist/generative-ui/index.cjs +39 -0
- package/dist/generative-ui/index.d.cts +8 -2
- package/dist/generative-ui/index.d.mts +8 -2
- package/dist/generative-ui/index.mjs +8 -2
- package/dist/generative-ui/is-record.d.cts +3 -1
- package/dist/generative-ui/is-record.d.cts.map +1 -1
- package/dist/generative-ui/is-record.d.mts +3 -1
- package/dist/generative-ui/is-record.d.mts.map +1 -1
- package/dist/generative-ui/schema-render.cjs +2 -1
- package/dist/generative-ui/schema-render.cjs.map +1 -1
- package/dist/generative-ui/schema-render.d.cts.map +1 -1
- package/dist/generative-ui/schema-render.d.mts.map +1 -1
- package/dist/generative-ui/schema-render.mjs +2 -1
- package/dist/generative-ui/schema-render.mjs.map +1 -1
- package/dist/generative-ui/standard/chart-config.cjs +347 -0
- package/dist/generative-ui/standard/chart-config.cjs.map +1 -0
- package/dist/generative-ui/standard/chart-config.d.cts +97 -0
- package/dist/generative-ui/standard/chart-config.d.cts.map +1 -0
- package/dist/generative-ui/standard/chart-config.d.mts +97 -0
- package/dist/generative-ui/standard/chart-config.d.mts.map +1 -0
- package/dist/generative-ui/standard/chart-config.mjs +342 -0
- package/dist/generative-ui/standard/chart-config.mjs.map +1 -0
- package/dist/generative-ui/standard/composites.d.cts +2 -2
- package/dist/generative-ui/standard/composites.d.mts +2 -2
- package/dist/generative-ui/standard/declarations.d.cts +68 -68
- package/dist/generative-ui/standard/declarations.d.mts +68 -68
- package/dist/generative-ui/standard/index.d.mts +5 -1
- package/dist/generative-ui/standard/inputs.d.cts +22 -22
- package/dist/generative-ui/standard/inputs.d.mts +22 -22
- package/dist/generative-ui/standard/layout.d.cts +90 -90
- package/dist/generative-ui/standard/layout.d.mts +90 -90
- package/dist/generative-ui/standard/map-helpers.cjs +104 -0
- package/dist/generative-ui/standard/map-helpers.cjs.map +1 -0
- package/dist/generative-ui/standard/map-helpers.d.cts +88 -0
- package/dist/generative-ui/standard/map-helpers.d.cts.map +1 -0
- package/dist/generative-ui/standard/map-helpers.d.mts +88 -0
- package/dist/generative-ui/standard/map-helpers.d.mts.map +1 -0
- package/dist/generative-ui/standard/map-helpers.mjs +95 -0
- package/dist/generative-ui/standard/map-helpers.mjs.map +1 -0
- package/dist/generative-ui/standard/media.d.cts +6 -6
- package/dist/generative-ui/standard/media.d.mts +6 -6
- package/dist/generative-ui/standard/style-helpers.cjs +151 -0
- package/dist/generative-ui/standard/style-helpers.cjs.map +1 -0
- package/dist/generative-ui/standard/style-helpers.d.cts +56 -0
- package/dist/generative-ui/standard/style-helpers.d.cts.map +1 -0
- package/dist/generative-ui/standard/style-helpers.d.mts +56 -0
- package/dist/generative-ui/standard/style-helpers.d.mts.map +1 -0
- package/dist/generative-ui/standard/style-helpers.mjs +142 -0
- package/dist/generative-ui/standard/style-helpers.mjs.map +1 -0
- package/dist/generative-ui/standard/text.d.cts +14 -14
- package/dist/generative-ui/standard/text.d.mts +14 -14
- package/dist/generative-ui/standard/url.cjs +54 -0
- package/dist/generative-ui/standard/url.cjs.map +1 -0
- package/dist/generative-ui/standard/url.d.cts +32 -0
- package/dist/generative-ui/standard/url.d.cts.map +1 -0
- package/dist/generative-ui/standard/url.d.mts +32 -0
- package/dist/generative-ui/standard/url.d.mts.map +1 -0
- package/dist/generative-ui/standard/url.mjs +50 -0
- package/dist/generative-ui/standard/url.mjs.map +1 -0
- package/dist/generative-ui/thrown.cjs +69 -0
- package/dist/generative-ui/thrown.cjs.map +1 -0
- package/dist/generative-ui/thrown.d.cts +21 -0
- package/dist/generative-ui/thrown.d.cts.map +1 -0
- package/dist/generative-ui/thrown.d.mts +21 -0
- package/dist/generative-ui/thrown.d.mts.map +1 -0
- package/dist/generative-ui/thrown.mjs +67 -0
- package/dist/generative-ui/thrown.mjs.map +1 -0
- package/dist/index.cjs +2 -0
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +2 -1
- package/dist/index.d.cts.map +1 -1
- package/dist/index.d.mts +2 -1
- package/dist/index.d.mts.map +1 -1
- package/dist/index.mjs +2 -1
- package/dist/index.mjs.map +1 -1
- package/dist/index.umd.js +368 -2
- package/dist/index.umd.js.map +1 -1
- package/dist/package.cjs +1 -1
- package/dist/package.mjs +1 -1
- package/package.json +1 -1
- package/src/__tests__/schema-render.test.ts +78 -0
- package/src/generative-ui/__tests__/clone-value-differential.test.ts +480 -0
- package/src/generative-ui/__tests__/clone-value.test.ts +226 -0
- package/src/generative-ui/clone-value.ts +511 -0
- package/src/generative-ui/index.ts +6 -2
- package/src/generative-ui/schema-render.ts +2 -1
- package/src/generative-ui/standard/__tests__/standard-helpers.test.ts +407 -0
- package/src/generative-ui/standard/chart-config.ts +434 -0
- package/src/generative-ui/standard/index.ts +36 -0
- package/src/generative-ui/standard/map-helpers.ts +155 -0
- package/src/generative-ui/standard/style-helpers.ts +170 -0
- package/src/generative-ui/standard/url.ts +51 -0
- package/src/generative-ui/thrown.ts +90 -0
- package/src/index.ts +5 -0
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
|
|
2
|
+
//#region src/generative-ui/standard/map-helpers.ts
|
|
3
|
+
/**
|
|
4
|
+
* The default basemap: the Positron style of OpenFreeMap. It is a keyless
|
|
5
|
+
* OpenStreetMap vector style with streets and labels at city zoom. A host
|
|
6
|
+
* sets another style with `theme: { mapStyle: "<style url>" }`, and a
|
|
7
|
+
* dark one with `theme: { dark: { mapStyle: "<style url>" } }`.
|
|
8
|
+
*/
|
|
9
|
+
const DEFAULT_MAP_STYLE = "https://tiles.openfreemap.org/styles/positron";
|
|
10
|
+
/** The default basemap in dark mode: the Dark style of OpenFreeMap. */
|
|
11
|
+
const DEFAULT_DARK_MAP_STYLE = "https://tiles.openfreemap.org/styles/dark";
|
|
12
|
+
const ORDERING_OPS = new Set([
|
|
13
|
+
"<",
|
|
14
|
+
"<=",
|
|
15
|
+
">",
|
|
16
|
+
">="
|
|
17
|
+
]);
|
|
18
|
+
/**
|
|
19
|
+
* A filter expression with every numeric comparison of a feature property
|
|
20
|
+
* guarded by `["has", property]`.
|
|
21
|
+
*
|
|
22
|
+
* MapLibre adds a number assertion to `["get", key]` in a comparison with a
|
|
23
|
+
* number. The assertion logs a warning for each feature without the
|
|
24
|
+
* property. OpenFreeMap styles compare `ref_length` on roads that mostly do
|
|
25
|
+
* not have it. The comparison is false for a missing property in both
|
|
26
|
+
* cases, so the guard changes no result.
|
|
27
|
+
*
|
|
28
|
+
* @param filter - A MapLibre filter expression, at any depth.
|
|
29
|
+
*/
|
|
30
|
+
function guardNumericFilter(filter) {
|
|
31
|
+
if (!Array.isArray(filter)) return filter;
|
|
32
|
+
const [op, left, right] = filter;
|
|
33
|
+
if (typeof op === "string" && ORDERING_OPS.has(op) && Array.isArray(left) && left[0] === "get" && typeof left[1] === "string" && typeof right === "number") return [
|
|
34
|
+
"all",
|
|
35
|
+
["has", left[1]],
|
|
36
|
+
filter
|
|
37
|
+
];
|
|
38
|
+
return filter.map((part) => guardNumericFilter(part));
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* The style with `guardNumericFilter` applied to the filter of each layer.
|
|
42
|
+
* Pass it as the `transformStyle` of MapLibre's `setStyle`.
|
|
43
|
+
*
|
|
44
|
+
* @param style - A MapLibre style object.
|
|
45
|
+
*/
|
|
46
|
+
function guardStyleFilters(style) {
|
|
47
|
+
const layers = style.layers;
|
|
48
|
+
if (layers === void 0) return style;
|
|
49
|
+
const guarded = layers.map((layer) => "filter" in layer ? {
|
|
50
|
+
...layer,
|
|
51
|
+
filter: guardNumericFilter(layer.filter)
|
|
52
|
+
} : layer);
|
|
53
|
+
return {
|
|
54
|
+
...style,
|
|
55
|
+
layers: guarded
|
|
56
|
+
};
|
|
57
|
+
}
|
|
58
|
+
/** The id of the map stylesheet (`MAP_CSS`) in the document. */
|
|
59
|
+
const MAP_STYLE_ID = "a2ui-standard-map";
|
|
60
|
+
/** The source and layer id of the route line between the markers. */
|
|
61
|
+
const ROUTE_SOURCE = "a2ui-route";
|
|
62
|
+
/**
|
|
63
|
+
* The few maplibre-gl rules that markers and popups need, so a host does not
|
|
64
|
+
* have to import maplibre-gl.css. The list of places is hidden while the map
|
|
65
|
+
* shows. It shows when a keyboard user moves focus into it.
|
|
66
|
+
*/
|
|
67
|
+
const MAP_CSS = [
|
|
68
|
+
".maplibregl-map{position:relative;overflow:hidden}",
|
|
69
|
+
".maplibregl-canvas{position:absolute;left:0;top:0}",
|
|
70
|
+
".maplibregl-canvas-container{width:100%;height:100%}",
|
|
71
|
+
".maplibregl-marker{position:absolute;top:0;left:0;will-change:transform;cursor:pointer}",
|
|
72
|
+
".maplibregl-popup{position:absolute;top:0;left:0;display:flex;will-change:transform;pointer-events:none}",
|
|
73
|
+
".maplibregl-popup-content{position:relative;background:var(--a2ui-color-surface-elevated, #fff);color:var(--a2ui-color-text-default, #0d0d0d);border-radius:6px;padding:6px 10px;font:12px/1.4 system-ui,sans-serif;box-shadow:var(--a2ui-shadow-sm, 0 1px 4px rgba(0,0,0,.2));pointer-events:auto}",
|
|
74
|
+
".maplibregl-popup-tip{display:none}",
|
|
75
|
+
".maplibregl-popup-close-button{display:none}",
|
|
76
|
+
".maplibregl-ctrl-attrib{font:10px system-ui,sans-serif;position:absolute;right:0;bottom:0;background:color-mix(in srgb, var(--a2ui-color-surface, #fff) 70%, transparent);color:var(--a2ui-color-text-secondary, #5d5d5d);padding:0 4px}",
|
|
77
|
+
".maplibregl-ctrl-attrib a{color:inherit}",
|
|
78
|
+
".maplibregl-cooperative-gesture-screen{align-items:center;background:rgba(0,0,0,.4);color:#fff;display:flex;font:14px/1.3 system-ui,sans-serif;inset:0;justify-content:center;opacity:0;padding:1rem;pointer-events:none;position:absolute;text-align:center;transition:opacity 1s ease 1s;z-index:2}",
|
|
79
|
+
".maplibregl-cooperative-gesture-screen.maplibregl-show{opacity:1;transition:opacity .05s}",
|
|
80
|
+
".maplibregl-cooperative-gesture-screen .maplibregl-mobile-message{display:none}",
|
|
81
|
+
"@media (hover:none){.maplibregl-cooperative-gesture-screen .maplibregl-desktop-message{display:none}.maplibregl-cooperative-gesture-screen .maplibregl-mobile-message{display:block}}",
|
|
82
|
+
".a2ui-std-map-places[data-collapsed]:not(:focus-within){position:absolute;width:1px;height:1px;padding:0;margin:-1px;overflow:hidden;clip:rect(0 0 0 0);white-space:nowrap;border:0}"
|
|
83
|
+
].join("\n");
|
|
84
|
+
/**
|
|
85
|
+
* True when `value` looks like the maplibre-gl module: it has a `Map`
|
|
86
|
+
* constructor. Use it on the module that a map loader resolves.
|
|
87
|
+
*/
|
|
88
|
+
function isMapLibre(value) {
|
|
89
|
+
return typeof value === "object" && value !== null && "Map" in value && typeof value.Map === "function";
|
|
90
|
+
}
|
|
91
|
+
/** True when the marker has finite coordinates, so the map can place it. */
|
|
92
|
+
const isValidMarker = (marker) => Number.isFinite(marker.lat) && Number.isFinite(marker.lng);
|
|
93
|
+
|
|
94
|
+
//#endregion
|
|
95
|
+
exports.DEFAULT_DARK_MAP_STYLE = DEFAULT_DARK_MAP_STYLE;
|
|
96
|
+
exports.DEFAULT_MAP_STYLE = DEFAULT_MAP_STYLE;
|
|
97
|
+
exports.MAP_CSS = MAP_CSS;
|
|
98
|
+
exports.MAP_STYLE_ID = MAP_STYLE_ID;
|
|
99
|
+
exports.ROUTE_SOURCE = ROUTE_SOURCE;
|
|
100
|
+
exports.guardNumericFilter = guardNumericFilter;
|
|
101
|
+
exports.guardStyleFilters = guardStyleFilters;
|
|
102
|
+
exports.isMapLibre = isMapLibre;
|
|
103
|
+
exports.isValidMarker = isValidMarker;
|
|
104
|
+
//# sourceMappingURL=map-helpers.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"map-helpers.cjs","names":[],"sources":["../../../src/generative-ui/standard/map-helpers.ts"],"sourcesContent":["// Framework-free map helpers of the standard Map component. The maplibre-gl\n// parts are typed structurally, so maplibre-gl stays an optional peer of\n// each framework package.\nimport type { MapMarker } from \"./map\";\n\n/**\n * The default basemap: the Positron style of OpenFreeMap. It is a keyless\n * OpenStreetMap vector style with streets and labels at city zoom. A host\n * sets another style with `theme: { mapStyle: \"<style url>\" }`, and a\n * dark one with `theme: { dark: { mapStyle: \"<style url>\" } }`.\n */\nexport const DEFAULT_MAP_STYLE =\n \"https://tiles.openfreemap.org/styles/positron\";\n\n/** The default basemap in dark mode: the Dark style of OpenFreeMap. */\nexport const DEFAULT_DARK_MAP_STYLE =\n \"https://tiles.openfreemap.org/styles/dark\";\n\nconst ORDERING_OPS = new Set([\"<\", \"<=\", \">\", \">=\"]);\n\n// guardNumericFilter keeps its return type: the function calls itself, so\n// TypeScript cannot infer it.\n/**\n * A filter expression with every numeric comparison of a feature property\n * guarded by `[\"has\", property]`.\n *\n * MapLibre adds a number assertion to `[\"get\", key]` in a comparison with a\n * number. The assertion logs a warning for each feature without the\n * property. OpenFreeMap styles compare `ref_length` on roads that mostly do\n * not have it. The comparison is false for a missing property in both\n * cases, so the guard changes no result.\n *\n * @param filter - A MapLibre filter expression, at any depth.\n */\nexport function guardNumericFilter(filter: unknown): unknown {\n if (!Array.isArray(filter)) return filter;\n const [op, left, right] = filter;\n const isPropertyComparison =\n typeof op === \"string\" &&\n ORDERING_OPS.has(op) &&\n Array.isArray(left) &&\n left[0] === \"get\" &&\n typeof left[1] === \"string\" &&\n typeof right === \"number\";\n if (isPropertyComparison) return [\"all\", [\"has\", left[1]], filter];\n return filter.map((part) => guardNumericFilter(part));\n}\n\n/**\n * The style with `guardNumericFilter` applied to the filter of each layer.\n * Pass it as the `transformStyle` of MapLibre's `setStyle`.\n *\n * @param style - A MapLibre style object.\n */\nexport function guardStyleFilters<Style extends { layers?: readonly object[] }>(\n style: Style,\n) {\n const layers = style.layers;\n if (layers === undefined) return style;\n const guarded = layers.map((layer) =>\n \"filter\" in layer\n ? { ...layer, filter: guardNumericFilter(layer.filter) }\n : layer,\n );\n // The guard only wraps a comparison in [\"all\", [\"has\", key], comparison],\n // which is a valid filter, so each layer keeps its type.\n return { ...style, layers: guarded } as Style;\n}\n\n/** The id of the map stylesheet (`MAP_CSS`) in the document. */\nexport const MAP_STYLE_ID = \"a2ui-standard-map\";\n\n/** The source and layer id of the route line between the markers. */\nexport const ROUTE_SOURCE = \"a2ui-route\";\n\n/**\n * The few maplibre-gl rules that markers and popups need, so a host does not\n * have to import maplibre-gl.css. The list of places is hidden while the map\n * shows. It shows when a keyboard user moves focus into it.\n */\nexport const MAP_CSS = [\n \".maplibregl-map{position:relative;overflow:hidden}\",\n \".maplibregl-canvas{position:absolute;left:0;top:0}\",\n \".maplibregl-canvas-container{width:100%;height:100%}\",\n \".maplibregl-marker{position:absolute;top:0;left:0;will-change:transform;cursor:pointer}\",\n \".maplibregl-popup{position:absolute;top:0;left:0;display:flex;will-change:transform;pointer-events:none}\",\n \".maplibregl-popup-content{position:relative;background:var(--a2ui-color-surface-elevated, #fff);color:var(--a2ui-color-text-default, #0d0d0d);border-radius:6px;padding:6px 10px;font:12px/1.4 system-ui,sans-serif;box-shadow:var(--a2ui-shadow-sm, 0 1px 4px rgba(0,0,0,.2));pointer-events:auto}\",\n \".maplibregl-popup-tip{display:none}\",\n \".maplibregl-popup-close-button{display:none}\",\n \".maplibregl-ctrl-attrib{font:10px system-ui,sans-serif;position:absolute;right:0;bottom:0;background:color-mix(in srgb, var(--a2ui-color-surface, #fff) 70%, transparent);color:var(--a2ui-color-text-secondary, #5d5d5d);padding:0 4px}\",\n \".maplibregl-ctrl-attrib a{color:inherit}\",\n // The cooperative-gesture hint is hidden until MapLibre adds `maplibregl-show`.\n \".maplibregl-cooperative-gesture-screen{align-items:center;background:rgba(0,0,0,.4);color:#fff;display:flex;font:14px/1.3 system-ui,sans-serif;inset:0;justify-content:center;opacity:0;padding:1rem;pointer-events:none;position:absolute;text-align:center;transition:opacity 1s ease 1s;z-index:2}\",\n \".maplibregl-cooperative-gesture-screen.maplibregl-show{opacity:1;transition:opacity .05s}\",\n \".maplibregl-cooperative-gesture-screen .maplibregl-mobile-message{display:none}\",\n \"@media (hover:none){.maplibregl-cooperative-gesture-screen .maplibregl-desktop-message{display:none}.maplibregl-cooperative-gesture-screen .maplibregl-mobile-message{display:block}}\",\n \".a2ui-std-map-places[data-collapsed]:not(:focus-within){position:absolute;width:1px;height:1px;padding:0;margin:-1px;overflow:hidden;clip:rect(0 0 0 0);white-space:nowrap;border:0}\",\n].join(\"\\n\");\n\n/** The part of a maplibre-gl `Map` that the standard Map component uses. */\nexport interface MapLibreMap {\n setStyle(\n style: string,\n options: {\n transformStyle: (\n previous: unknown,\n next: { layers?: readonly object[] },\n ) => unknown;\n },\n ): void;\n on(\n event: string,\n handler: (event: { originalEvent?: unknown }) => void,\n ): void;\n fitBounds(bounds: unknown, options: Record<string, unknown>): void;\n getSource(id: string): unknown;\n addSource(id: string, source: Record<string, unknown>): void;\n addLayer(layer: Record<string, unknown>): void;\n remove(): void;\n}\n\n/** The part of a maplibre-gl `Marker` that the standard Map component uses. */\nexport interface MapLibreMarker {\n setLngLat(position: [number, number]): MapLibreMarker;\n setPopup(popup: unknown): MapLibreMarker;\n addTo(map: MapLibreMap): MapLibreMarker;\n getElement(): HTMLElement;\n}\n\n/** The part of the maplibre-gl module that the standard Map component uses. */\nexport interface MapLibre {\n Map: new (options: Record<string, unknown>) => MapLibreMap;\n Marker: new () => MapLibreMarker;\n Popup: new (options: Record<string, unknown>) => {\n setText(text: string): unknown;\n };\n LngLatBounds: new () => { extend(position: [number, number]): void };\n}\n\n/**\n * True when `value` looks like the maplibre-gl module: it has a `Map`\n * constructor. Use it on the module that a map loader resolves.\n */\nexport function isMapLibre(value: unknown): value is MapLibre {\n return (\n typeof value === \"object\" &&\n value !== null &&\n \"Map\" in value &&\n typeof value.Map === \"function\"\n );\n}\n\n/** True when the marker has finite coordinates, so the map can place it. */\nexport const isValidMarker = (marker: MapMarker) =>\n Number.isFinite(marker.lat) && Number.isFinite(marker.lng);\n"],"mappings":";;;;;;;;AAWA,MAAa,oBACX;;AAGF,MAAa,yBACX;AAEF,MAAM,eAAe,IAAI,IAAI;CAAC;CAAK;CAAM;CAAK;CAAK,CAAC;;;;;;;;;;;;;AAgBpD,SAAgB,mBAAmB,QAA0B;AAC3D,KAAI,CAAC,MAAM,QAAQ,OAAO,CAAE,QAAO;CACnC,MAAM,CAAC,IAAI,MAAM,SAAS;AAQ1B,KANE,OAAO,OAAO,YACd,aAAa,IAAI,GAAG,IACpB,MAAM,QAAQ,KAAK,IACnB,KAAK,OAAO,SACZ,OAAO,KAAK,OAAO,YACnB,OAAO,UAAU,SACO,QAAO;EAAC;EAAO,CAAC,OAAO,KAAK,GAAG;EAAE;EAAO;AAClE,QAAO,OAAO,KAAK,SAAS,mBAAmB,KAAK,CAAC;;;;;;;;AASvD,SAAgB,kBACd,OACA;CACA,MAAM,SAAS,MAAM;AACrB,KAAI,WAAW,OAAW,QAAO;CACjC,MAAM,UAAU,OAAO,KAAK,UAC1B,YAAY,QACR;EAAE,GAAG;EAAO,QAAQ,mBAAmB,MAAM,OAAO;EAAE,GACtD,MACL;AAGD,QAAO;EAAE,GAAG;EAAO,QAAQ;EAAS;;;AAItC,MAAa,eAAe;;AAG5B,MAAa,eAAe;;;;;;AAO5B,MAAa,UAAU;CACrB;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CAEA;CACA;CACA;CACA;CACA;CACD,CAAC,KAAK,KAAK;;;;;AA8CZ,SAAgB,WAAW,OAAmC;AAC5D,QACE,OAAO,UAAU,YACjB,UAAU,QACV,SAAS,SACT,OAAO,MAAM,QAAQ;;;AAKzB,MAAa,iBAAiB,WAC5B,OAAO,SAAS,OAAO,IAAI,IAAI,OAAO,SAAS,OAAO,IAAI"}
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
import { MapMarker } from "./map.cjs";
|
|
2
|
+
|
|
3
|
+
//#region src/generative-ui/standard/map-helpers.d.ts
|
|
4
|
+
/**
|
|
5
|
+
* The default basemap: the Positron style of OpenFreeMap. It is a keyless
|
|
6
|
+
* OpenStreetMap vector style with streets and labels at city zoom. A host
|
|
7
|
+
* sets another style with `theme: { mapStyle: "<style url>" }`, and a
|
|
8
|
+
* dark one with `theme: { dark: { mapStyle: "<style url>" } }`.
|
|
9
|
+
*/
|
|
10
|
+
declare const DEFAULT_MAP_STYLE = "https://tiles.openfreemap.org/styles/positron";
|
|
11
|
+
/** The default basemap in dark mode: the Dark style of OpenFreeMap. */
|
|
12
|
+
declare const DEFAULT_DARK_MAP_STYLE = "https://tiles.openfreemap.org/styles/dark";
|
|
13
|
+
/**
|
|
14
|
+
* A filter expression with every numeric comparison of a feature property
|
|
15
|
+
* guarded by `["has", property]`.
|
|
16
|
+
*
|
|
17
|
+
* MapLibre adds a number assertion to `["get", key]` in a comparison with a
|
|
18
|
+
* number. The assertion logs a warning for each feature without the
|
|
19
|
+
* property. OpenFreeMap styles compare `ref_length` on roads that mostly do
|
|
20
|
+
* not have it. The comparison is false for a missing property in both
|
|
21
|
+
* cases, so the guard changes no result.
|
|
22
|
+
*
|
|
23
|
+
* @param filter - A MapLibre filter expression, at any depth.
|
|
24
|
+
*/
|
|
25
|
+
declare function guardNumericFilter(filter: unknown): unknown;
|
|
26
|
+
/**
|
|
27
|
+
* The style with `guardNumericFilter` applied to the filter of each layer.
|
|
28
|
+
* Pass it as the `transformStyle` of MapLibre's `setStyle`.
|
|
29
|
+
*
|
|
30
|
+
* @param style - A MapLibre style object.
|
|
31
|
+
*/
|
|
32
|
+
declare function guardStyleFilters<Style extends {
|
|
33
|
+
layers?: readonly object[];
|
|
34
|
+
}>(style: Style): Style;
|
|
35
|
+
/** The id of the map stylesheet (`MAP_CSS`) in the document. */
|
|
36
|
+
declare const MAP_STYLE_ID = "a2ui-standard-map";
|
|
37
|
+
/** The source and layer id of the route line between the markers. */
|
|
38
|
+
declare const ROUTE_SOURCE = "a2ui-route";
|
|
39
|
+
/**
|
|
40
|
+
* The few maplibre-gl rules that markers and popups need, so a host does not
|
|
41
|
+
* have to import maplibre-gl.css. The list of places is hidden while the map
|
|
42
|
+
* shows. It shows when a keyboard user moves focus into it.
|
|
43
|
+
*/
|
|
44
|
+
declare const MAP_CSS: string;
|
|
45
|
+
/** The part of a maplibre-gl `Map` that the standard Map component uses. */
|
|
46
|
+
interface MapLibreMap {
|
|
47
|
+
setStyle(style: string, options: {
|
|
48
|
+
transformStyle: (previous: unknown, next: {
|
|
49
|
+
layers?: readonly object[];
|
|
50
|
+
}) => unknown;
|
|
51
|
+
}): void;
|
|
52
|
+
on(event: string, handler: (event: {
|
|
53
|
+
originalEvent?: unknown;
|
|
54
|
+
}) => void): void;
|
|
55
|
+
fitBounds(bounds: unknown, options: Record<string, unknown>): void;
|
|
56
|
+
getSource(id: string): unknown;
|
|
57
|
+
addSource(id: string, source: Record<string, unknown>): void;
|
|
58
|
+
addLayer(layer: Record<string, unknown>): void;
|
|
59
|
+
remove(): void;
|
|
60
|
+
}
|
|
61
|
+
/** The part of a maplibre-gl `Marker` that the standard Map component uses. */
|
|
62
|
+
interface MapLibreMarker {
|
|
63
|
+
setLngLat(position: [number, number]): MapLibreMarker;
|
|
64
|
+
setPopup(popup: unknown): MapLibreMarker;
|
|
65
|
+
addTo(map: MapLibreMap): MapLibreMarker;
|
|
66
|
+
getElement(): HTMLElement;
|
|
67
|
+
}
|
|
68
|
+
/** The part of the maplibre-gl module that the standard Map component uses. */
|
|
69
|
+
interface MapLibre {
|
|
70
|
+
Map: new (options: Record<string, unknown>) => MapLibreMap;
|
|
71
|
+
Marker: new () => MapLibreMarker;
|
|
72
|
+
Popup: new (options: Record<string, unknown>) => {
|
|
73
|
+
setText(text: string): unknown;
|
|
74
|
+
};
|
|
75
|
+
LngLatBounds: new () => {
|
|
76
|
+
extend(position: [number, number]): void;
|
|
77
|
+
};
|
|
78
|
+
}
|
|
79
|
+
/**
|
|
80
|
+
* True when `value` looks like the maplibre-gl module: it has a `Map`
|
|
81
|
+
* constructor. Use it on the module that a map loader resolves.
|
|
82
|
+
*/
|
|
83
|
+
declare function isMapLibre(value: unknown): value is MapLibre;
|
|
84
|
+
/** True when the marker has finite coordinates, so the map can place it. */
|
|
85
|
+
declare const isValidMarker: (marker: MapMarker) => boolean;
|
|
86
|
+
//#endregion
|
|
87
|
+
export { DEFAULT_DARK_MAP_STYLE, DEFAULT_MAP_STYLE, MAP_CSS, MAP_STYLE_ID, MapLibre, MapLibreMap, MapLibreMarker, ROUTE_SOURCE, guardNumericFilter, guardStyleFilters, isMapLibre, isValidMarker };
|
|
88
|
+
//# sourceMappingURL=map-helpers.d.cts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"map-helpers.d.cts","names":[],"sources":["../../../src/generative-ui/standard/map-helpers.ts"],"mappings":";;;;;AAWA;;;;cAAa,iBAAA;AAIb;AAAA,cAAa,sBAAA;;;;AAmBb;;;;;AAoBA;;;;iBApBgB,kBAAA,CAAmB,MAAA;;;;;;;iBAoBnB,iBAAA;EAAkC,MAAA;AAAA,EAAA,CAChD,KAAA,EAAO,KAAA,GAAK,KAAA;;cAeD,YAAA;AAGb;AAAA,cAAa,YAAA;;;;AAOb;;cAAa,OAAA;;UAoBI,WAAA;EACf,QAAA,CACE,KAAA,UACA,OAAA;IACE,cAAA,GACE,QAAA,WACA,IAAA;MAAQ,MAAA;IAAA;EAAA;EAId,EAAA,CACE,KAAA,UACA,OAAA,GAAU,KAAA;IAAS,aAAA;EAAA;EAErB,SAAA,CAAU,MAAA,WAAiB,OAAA,EAAS,MAAA;EACpC,SAAA,CAAU,EAAA;EACV,SAAA,CAAU,EAAA,UAAY,MAAA,EAAQ,MAAA;EAC9B,QAAA,CAAS,KAAA,EAAO,MAAA;EAChB,MAAA;AAAA;;UAIe,cAAA;EACf,SAAA,CAAU,QAAA,qBAA6B,cAAA;EACvC,QAAA,CAAS,KAAA,YAAiB,cAAA;EAC1B,KAAA,CAAM,GAAA,EAAK,WAAA,GAAc,cAAA;EACzB,UAAA,IAAc,WAAA;AAAA;;UAIC,QAAA;EACf,GAAA,OAAU,OAAA,EAAS,MAAA,sBAA4B,WAAA;EAC/C,MAAA,YAAkB,cAAA;EAClB,KAAA,OAAY,OAAA,EAAS,MAAA;IACnB,OAAA,CAAQ,IAAA;EAAA;EAEV,YAAA;IAA0B,MAAA,CAAO,QAAA;EAAA;AAAA;;;;;iBAOnB,UAAA,CAAW,KAAA,YAAiB,KAAA,IAAS,QAAA;;cAUxC,aAAA,GAAiB,MAAA,EAAQ,SAAA"}
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
import { MapMarker } from "./map.mjs";
|
|
2
|
+
|
|
3
|
+
//#region src/generative-ui/standard/map-helpers.d.ts
|
|
4
|
+
/**
|
|
5
|
+
* The default basemap: the Positron style of OpenFreeMap. It is a keyless
|
|
6
|
+
* OpenStreetMap vector style with streets and labels at city zoom. A host
|
|
7
|
+
* sets another style with `theme: { mapStyle: "<style url>" }`, and a
|
|
8
|
+
* dark one with `theme: { dark: { mapStyle: "<style url>" } }`.
|
|
9
|
+
*/
|
|
10
|
+
declare const DEFAULT_MAP_STYLE = "https://tiles.openfreemap.org/styles/positron";
|
|
11
|
+
/** The default basemap in dark mode: the Dark style of OpenFreeMap. */
|
|
12
|
+
declare const DEFAULT_DARK_MAP_STYLE = "https://tiles.openfreemap.org/styles/dark";
|
|
13
|
+
/**
|
|
14
|
+
* A filter expression with every numeric comparison of a feature property
|
|
15
|
+
* guarded by `["has", property]`.
|
|
16
|
+
*
|
|
17
|
+
* MapLibre adds a number assertion to `["get", key]` in a comparison with a
|
|
18
|
+
* number. The assertion logs a warning for each feature without the
|
|
19
|
+
* property. OpenFreeMap styles compare `ref_length` on roads that mostly do
|
|
20
|
+
* not have it. The comparison is false for a missing property in both
|
|
21
|
+
* cases, so the guard changes no result.
|
|
22
|
+
*
|
|
23
|
+
* @param filter - A MapLibre filter expression, at any depth.
|
|
24
|
+
*/
|
|
25
|
+
declare function guardNumericFilter(filter: unknown): unknown;
|
|
26
|
+
/**
|
|
27
|
+
* The style with `guardNumericFilter` applied to the filter of each layer.
|
|
28
|
+
* Pass it as the `transformStyle` of MapLibre's `setStyle`.
|
|
29
|
+
*
|
|
30
|
+
* @param style - A MapLibre style object.
|
|
31
|
+
*/
|
|
32
|
+
declare function guardStyleFilters<Style extends {
|
|
33
|
+
layers?: readonly object[];
|
|
34
|
+
}>(style: Style): Style;
|
|
35
|
+
/** The id of the map stylesheet (`MAP_CSS`) in the document. */
|
|
36
|
+
declare const MAP_STYLE_ID = "a2ui-standard-map";
|
|
37
|
+
/** The source and layer id of the route line between the markers. */
|
|
38
|
+
declare const ROUTE_SOURCE = "a2ui-route";
|
|
39
|
+
/**
|
|
40
|
+
* The few maplibre-gl rules that markers and popups need, so a host does not
|
|
41
|
+
* have to import maplibre-gl.css. The list of places is hidden while the map
|
|
42
|
+
* shows. It shows when a keyboard user moves focus into it.
|
|
43
|
+
*/
|
|
44
|
+
declare const MAP_CSS: string;
|
|
45
|
+
/** The part of a maplibre-gl `Map` that the standard Map component uses. */
|
|
46
|
+
interface MapLibreMap {
|
|
47
|
+
setStyle(style: string, options: {
|
|
48
|
+
transformStyle: (previous: unknown, next: {
|
|
49
|
+
layers?: readonly object[];
|
|
50
|
+
}) => unknown;
|
|
51
|
+
}): void;
|
|
52
|
+
on(event: string, handler: (event: {
|
|
53
|
+
originalEvent?: unknown;
|
|
54
|
+
}) => void): void;
|
|
55
|
+
fitBounds(bounds: unknown, options: Record<string, unknown>): void;
|
|
56
|
+
getSource(id: string): unknown;
|
|
57
|
+
addSource(id: string, source: Record<string, unknown>): void;
|
|
58
|
+
addLayer(layer: Record<string, unknown>): void;
|
|
59
|
+
remove(): void;
|
|
60
|
+
}
|
|
61
|
+
/** The part of a maplibre-gl `Marker` that the standard Map component uses. */
|
|
62
|
+
interface MapLibreMarker {
|
|
63
|
+
setLngLat(position: [number, number]): MapLibreMarker;
|
|
64
|
+
setPopup(popup: unknown): MapLibreMarker;
|
|
65
|
+
addTo(map: MapLibreMap): MapLibreMarker;
|
|
66
|
+
getElement(): HTMLElement;
|
|
67
|
+
}
|
|
68
|
+
/** The part of the maplibre-gl module that the standard Map component uses. */
|
|
69
|
+
interface MapLibre {
|
|
70
|
+
Map: new (options: Record<string, unknown>) => MapLibreMap;
|
|
71
|
+
Marker: new () => MapLibreMarker;
|
|
72
|
+
Popup: new (options: Record<string, unknown>) => {
|
|
73
|
+
setText(text: string): unknown;
|
|
74
|
+
};
|
|
75
|
+
LngLatBounds: new () => {
|
|
76
|
+
extend(position: [number, number]): void;
|
|
77
|
+
};
|
|
78
|
+
}
|
|
79
|
+
/**
|
|
80
|
+
* True when `value` looks like the maplibre-gl module: it has a `Map`
|
|
81
|
+
* constructor. Use it on the module that a map loader resolves.
|
|
82
|
+
*/
|
|
83
|
+
declare function isMapLibre(value: unknown): value is MapLibre;
|
|
84
|
+
/** True when the marker has finite coordinates, so the map can place it. */
|
|
85
|
+
declare const isValidMarker: (marker: MapMarker) => boolean;
|
|
86
|
+
//#endregion
|
|
87
|
+
export { DEFAULT_DARK_MAP_STYLE, DEFAULT_MAP_STYLE, MAP_CSS, MAP_STYLE_ID, MapLibre, MapLibreMap, MapLibreMarker, ROUTE_SOURCE, guardNumericFilter, guardStyleFilters, isMapLibre, isValidMarker };
|
|
88
|
+
//# sourceMappingURL=map-helpers.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"map-helpers.d.mts","names":[],"sources":["../../../src/generative-ui/standard/map-helpers.ts"],"mappings":";;;;;AAWA;;;;cAAa,iBAAA;AAIb;AAAA,cAAa,sBAAA;;;;AAmBb;;;;;AAoBA;;;;iBApBgB,kBAAA,CAAmB,MAAA;;;;;;;iBAoBnB,iBAAA;EAAkC,MAAA;AAAA,EAAA,CAChD,KAAA,EAAO,KAAA,GAAK,KAAA;;cAeD,YAAA;AAGb;AAAA,cAAa,YAAA;;;;AAOb;;cAAa,OAAA;;UAoBI,WAAA;EACf,QAAA,CACE,KAAA,UACA,OAAA;IACE,cAAA,GACE,QAAA,WACA,IAAA;MAAQ,MAAA;IAAA;EAAA;EAId,EAAA,CACE,KAAA,UACA,OAAA,GAAU,KAAA;IAAS,aAAA;EAAA;EAErB,SAAA,CAAU,MAAA,WAAiB,OAAA,EAAS,MAAA;EACpC,SAAA,CAAU,EAAA;EACV,SAAA,CAAU,EAAA,UAAY,MAAA,EAAQ,MAAA;EAC9B,QAAA,CAAS,KAAA,EAAO,MAAA;EAChB,MAAA;AAAA;;UAIe,cAAA;EACf,SAAA,CAAU,QAAA,qBAA6B,cAAA;EACvC,QAAA,CAAS,KAAA,YAAiB,cAAA;EAC1B,KAAA,CAAM,GAAA,EAAK,WAAA,GAAc,cAAA;EACzB,UAAA,IAAc,WAAA;AAAA;;UAIC,QAAA;EACf,GAAA,OAAU,OAAA,EAAS,MAAA,sBAA4B,WAAA;EAC/C,MAAA,YAAkB,cAAA;EAClB,KAAA,OAAY,OAAA,EAAS,MAAA;IACnB,OAAA,CAAQ,IAAA;EAAA;EAEV,YAAA;IAA0B,MAAA,CAAO,QAAA;EAAA;AAAA;;;;;iBAOnB,UAAA,CAAW,KAAA,YAAiB,KAAA,IAAS,QAAA;;cAUxC,aAAA,GAAiB,MAAA,EAAQ,SAAA"}
|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
//#region src/generative-ui/standard/map-helpers.ts
|
|
2
|
+
/**
|
|
3
|
+
* The default basemap: the Positron style of OpenFreeMap. It is a keyless
|
|
4
|
+
* OpenStreetMap vector style with streets and labels at city zoom. A host
|
|
5
|
+
* sets another style with `theme: { mapStyle: "<style url>" }`, and a
|
|
6
|
+
* dark one with `theme: { dark: { mapStyle: "<style url>" } }`.
|
|
7
|
+
*/
|
|
8
|
+
const DEFAULT_MAP_STYLE = "https://tiles.openfreemap.org/styles/positron";
|
|
9
|
+
/** The default basemap in dark mode: the Dark style of OpenFreeMap. */
|
|
10
|
+
const DEFAULT_DARK_MAP_STYLE = "https://tiles.openfreemap.org/styles/dark";
|
|
11
|
+
const ORDERING_OPS = new Set([
|
|
12
|
+
"<",
|
|
13
|
+
"<=",
|
|
14
|
+
">",
|
|
15
|
+
">="
|
|
16
|
+
]);
|
|
17
|
+
/**
|
|
18
|
+
* A filter expression with every numeric comparison of a feature property
|
|
19
|
+
* guarded by `["has", property]`.
|
|
20
|
+
*
|
|
21
|
+
* MapLibre adds a number assertion to `["get", key]` in a comparison with a
|
|
22
|
+
* number. The assertion logs a warning for each feature without the
|
|
23
|
+
* property. OpenFreeMap styles compare `ref_length` on roads that mostly do
|
|
24
|
+
* not have it. The comparison is false for a missing property in both
|
|
25
|
+
* cases, so the guard changes no result.
|
|
26
|
+
*
|
|
27
|
+
* @param filter - A MapLibre filter expression, at any depth.
|
|
28
|
+
*/
|
|
29
|
+
function guardNumericFilter(filter) {
|
|
30
|
+
if (!Array.isArray(filter)) return filter;
|
|
31
|
+
const [op, left, right] = filter;
|
|
32
|
+
if (typeof op === "string" && ORDERING_OPS.has(op) && Array.isArray(left) && left[0] === "get" && typeof left[1] === "string" && typeof right === "number") return [
|
|
33
|
+
"all",
|
|
34
|
+
["has", left[1]],
|
|
35
|
+
filter
|
|
36
|
+
];
|
|
37
|
+
return filter.map((part) => guardNumericFilter(part));
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* The style with `guardNumericFilter` applied to the filter of each layer.
|
|
41
|
+
* Pass it as the `transformStyle` of MapLibre's `setStyle`.
|
|
42
|
+
*
|
|
43
|
+
* @param style - A MapLibre style object.
|
|
44
|
+
*/
|
|
45
|
+
function guardStyleFilters(style) {
|
|
46
|
+
const layers = style.layers;
|
|
47
|
+
if (layers === void 0) return style;
|
|
48
|
+
const guarded = layers.map((layer) => "filter" in layer ? {
|
|
49
|
+
...layer,
|
|
50
|
+
filter: guardNumericFilter(layer.filter)
|
|
51
|
+
} : layer);
|
|
52
|
+
return {
|
|
53
|
+
...style,
|
|
54
|
+
layers: guarded
|
|
55
|
+
};
|
|
56
|
+
}
|
|
57
|
+
/** The id of the map stylesheet (`MAP_CSS`) in the document. */
|
|
58
|
+
const MAP_STYLE_ID = "a2ui-standard-map";
|
|
59
|
+
/** The source and layer id of the route line between the markers. */
|
|
60
|
+
const ROUTE_SOURCE = "a2ui-route";
|
|
61
|
+
/**
|
|
62
|
+
* The few maplibre-gl rules that markers and popups need, so a host does not
|
|
63
|
+
* have to import maplibre-gl.css. The list of places is hidden while the map
|
|
64
|
+
* shows. It shows when a keyboard user moves focus into it.
|
|
65
|
+
*/
|
|
66
|
+
const MAP_CSS = [
|
|
67
|
+
".maplibregl-map{position:relative;overflow:hidden}",
|
|
68
|
+
".maplibregl-canvas{position:absolute;left:0;top:0}",
|
|
69
|
+
".maplibregl-canvas-container{width:100%;height:100%}",
|
|
70
|
+
".maplibregl-marker{position:absolute;top:0;left:0;will-change:transform;cursor:pointer}",
|
|
71
|
+
".maplibregl-popup{position:absolute;top:0;left:0;display:flex;will-change:transform;pointer-events:none}",
|
|
72
|
+
".maplibregl-popup-content{position:relative;background:var(--a2ui-color-surface-elevated, #fff);color:var(--a2ui-color-text-default, #0d0d0d);border-radius:6px;padding:6px 10px;font:12px/1.4 system-ui,sans-serif;box-shadow:var(--a2ui-shadow-sm, 0 1px 4px rgba(0,0,0,.2));pointer-events:auto}",
|
|
73
|
+
".maplibregl-popup-tip{display:none}",
|
|
74
|
+
".maplibregl-popup-close-button{display:none}",
|
|
75
|
+
".maplibregl-ctrl-attrib{font:10px system-ui,sans-serif;position:absolute;right:0;bottom:0;background:color-mix(in srgb, var(--a2ui-color-surface, #fff) 70%, transparent);color:var(--a2ui-color-text-secondary, #5d5d5d);padding:0 4px}",
|
|
76
|
+
".maplibregl-ctrl-attrib a{color:inherit}",
|
|
77
|
+
".maplibregl-cooperative-gesture-screen{align-items:center;background:rgba(0,0,0,.4);color:#fff;display:flex;font:14px/1.3 system-ui,sans-serif;inset:0;justify-content:center;opacity:0;padding:1rem;pointer-events:none;position:absolute;text-align:center;transition:opacity 1s ease 1s;z-index:2}",
|
|
78
|
+
".maplibregl-cooperative-gesture-screen.maplibregl-show{opacity:1;transition:opacity .05s}",
|
|
79
|
+
".maplibregl-cooperative-gesture-screen .maplibregl-mobile-message{display:none}",
|
|
80
|
+
"@media (hover:none){.maplibregl-cooperative-gesture-screen .maplibregl-desktop-message{display:none}.maplibregl-cooperative-gesture-screen .maplibregl-mobile-message{display:block}}",
|
|
81
|
+
".a2ui-std-map-places[data-collapsed]:not(:focus-within){position:absolute;width:1px;height:1px;padding:0;margin:-1px;overflow:hidden;clip:rect(0 0 0 0);white-space:nowrap;border:0}"
|
|
82
|
+
].join("\n");
|
|
83
|
+
/**
|
|
84
|
+
* True when `value` looks like the maplibre-gl module: it has a `Map`
|
|
85
|
+
* constructor. Use it on the module that a map loader resolves.
|
|
86
|
+
*/
|
|
87
|
+
function isMapLibre(value) {
|
|
88
|
+
return typeof value === "object" && value !== null && "Map" in value && typeof value.Map === "function";
|
|
89
|
+
}
|
|
90
|
+
/** True when the marker has finite coordinates, so the map can place it. */
|
|
91
|
+
const isValidMarker = (marker) => Number.isFinite(marker.lat) && Number.isFinite(marker.lng);
|
|
92
|
+
|
|
93
|
+
//#endregion
|
|
94
|
+
export { DEFAULT_DARK_MAP_STYLE, DEFAULT_MAP_STYLE, MAP_CSS, MAP_STYLE_ID, ROUTE_SOURCE, guardNumericFilter, guardStyleFilters, isMapLibre, isValidMarker };
|
|
95
|
+
//# sourceMappingURL=map-helpers.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"map-helpers.mjs","names":[],"sources":["../../../src/generative-ui/standard/map-helpers.ts"],"sourcesContent":["// Framework-free map helpers of the standard Map component. The maplibre-gl\n// parts are typed structurally, so maplibre-gl stays an optional peer of\n// each framework package.\nimport type { MapMarker } from \"./map\";\n\n/**\n * The default basemap: the Positron style of OpenFreeMap. It is a keyless\n * OpenStreetMap vector style with streets and labels at city zoom. A host\n * sets another style with `theme: { mapStyle: \"<style url>\" }`, and a\n * dark one with `theme: { dark: { mapStyle: \"<style url>\" } }`.\n */\nexport const DEFAULT_MAP_STYLE =\n \"https://tiles.openfreemap.org/styles/positron\";\n\n/** The default basemap in dark mode: the Dark style of OpenFreeMap. */\nexport const DEFAULT_DARK_MAP_STYLE =\n \"https://tiles.openfreemap.org/styles/dark\";\n\nconst ORDERING_OPS = new Set([\"<\", \"<=\", \">\", \">=\"]);\n\n// guardNumericFilter keeps its return type: the function calls itself, so\n// TypeScript cannot infer it.\n/**\n * A filter expression with every numeric comparison of a feature property\n * guarded by `[\"has\", property]`.\n *\n * MapLibre adds a number assertion to `[\"get\", key]` in a comparison with a\n * number. The assertion logs a warning for each feature without the\n * property. OpenFreeMap styles compare `ref_length` on roads that mostly do\n * not have it. The comparison is false for a missing property in both\n * cases, so the guard changes no result.\n *\n * @param filter - A MapLibre filter expression, at any depth.\n */\nexport function guardNumericFilter(filter: unknown): unknown {\n if (!Array.isArray(filter)) return filter;\n const [op, left, right] = filter;\n const isPropertyComparison =\n typeof op === \"string\" &&\n ORDERING_OPS.has(op) &&\n Array.isArray(left) &&\n left[0] === \"get\" &&\n typeof left[1] === \"string\" &&\n typeof right === \"number\";\n if (isPropertyComparison) return [\"all\", [\"has\", left[1]], filter];\n return filter.map((part) => guardNumericFilter(part));\n}\n\n/**\n * The style with `guardNumericFilter` applied to the filter of each layer.\n * Pass it as the `transformStyle` of MapLibre's `setStyle`.\n *\n * @param style - A MapLibre style object.\n */\nexport function guardStyleFilters<Style extends { layers?: readonly object[] }>(\n style: Style,\n) {\n const layers = style.layers;\n if (layers === undefined) return style;\n const guarded = layers.map((layer) =>\n \"filter\" in layer\n ? { ...layer, filter: guardNumericFilter(layer.filter) }\n : layer,\n );\n // The guard only wraps a comparison in [\"all\", [\"has\", key], comparison],\n // which is a valid filter, so each layer keeps its type.\n return { ...style, layers: guarded } as Style;\n}\n\n/** The id of the map stylesheet (`MAP_CSS`) in the document. */\nexport const MAP_STYLE_ID = \"a2ui-standard-map\";\n\n/** The source and layer id of the route line between the markers. */\nexport const ROUTE_SOURCE = \"a2ui-route\";\n\n/**\n * The few maplibre-gl rules that markers and popups need, so a host does not\n * have to import maplibre-gl.css. The list of places is hidden while the map\n * shows. It shows when a keyboard user moves focus into it.\n */\nexport const MAP_CSS = [\n \".maplibregl-map{position:relative;overflow:hidden}\",\n \".maplibregl-canvas{position:absolute;left:0;top:0}\",\n \".maplibregl-canvas-container{width:100%;height:100%}\",\n \".maplibregl-marker{position:absolute;top:0;left:0;will-change:transform;cursor:pointer}\",\n \".maplibregl-popup{position:absolute;top:0;left:0;display:flex;will-change:transform;pointer-events:none}\",\n \".maplibregl-popup-content{position:relative;background:var(--a2ui-color-surface-elevated, #fff);color:var(--a2ui-color-text-default, #0d0d0d);border-radius:6px;padding:6px 10px;font:12px/1.4 system-ui,sans-serif;box-shadow:var(--a2ui-shadow-sm, 0 1px 4px rgba(0,0,0,.2));pointer-events:auto}\",\n \".maplibregl-popup-tip{display:none}\",\n \".maplibregl-popup-close-button{display:none}\",\n \".maplibregl-ctrl-attrib{font:10px system-ui,sans-serif;position:absolute;right:0;bottom:0;background:color-mix(in srgb, var(--a2ui-color-surface, #fff) 70%, transparent);color:var(--a2ui-color-text-secondary, #5d5d5d);padding:0 4px}\",\n \".maplibregl-ctrl-attrib a{color:inherit}\",\n // The cooperative-gesture hint is hidden until MapLibre adds `maplibregl-show`.\n \".maplibregl-cooperative-gesture-screen{align-items:center;background:rgba(0,0,0,.4);color:#fff;display:flex;font:14px/1.3 system-ui,sans-serif;inset:0;justify-content:center;opacity:0;padding:1rem;pointer-events:none;position:absolute;text-align:center;transition:opacity 1s ease 1s;z-index:2}\",\n \".maplibregl-cooperative-gesture-screen.maplibregl-show{opacity:1;transition:opacity .05s}\",\n \".maplibregl-cooperative-gesture-screen .maplibregl-mobile-message{display:none}\",\n \"@media (hover:none){.maplibregl-cooperative-gesture-screen .maplibregl-desktop-message{display:none}.maplibregl-cooperative-gesture-screen .maplibregl-mobile-message{display:block}}\",\n \".a2ui-std-map-places[data-collapsed]:not(:focus-within){position:absolute;width:1px;height:1px;padding:0;margin:-1px;overflow:hidden;clip:rect(0 0 0 0);white-space:nowrap;border:0}\",\n].join(\"\\n\");\n\n/** The part of a maplibre-gl `Map` that the standard Map component uses. */\nexport interface MapLibreMap {\n setStyle(\n style: string,\n options: {\n transformStyle: (\n previous: unknown,\n next: { layers?: readonly object[] },\n ) => unknown;\n },\n ): void;\n on(\n event: string,\n handler: (event: { originalEvent?: unknown }) => void,\n ): void;\n fitBounds(bounds: unknown, options: Record<string, unknown>): void;\n getSource(id: string): unknown;\n addSource(id: string, source: Record<string, unknown>): void;\n addLayer(layer: Record<string, unknown>): void;\n remove(): void;\n}\n\n/** The part of a maplibre-gl `Marker` that the standard Map component uses. */\nexport interface MapLibreMarker {\n setLngLat(position: [number, number]): MapLibreMarker;\n setPopup(popup: unknown): MapLibreMarker;\n addTo(map: MapLibreMap): MapLibreMarker;\n getElement(): HTMLElement;\n}\n\n/** The part of the maplibre-gl module that the standard Map component uses. */\nexport interface MapLibre {\n Map: new (options: Record<string, unknown>) => MapLibreMap;\n Marker: new () => MapLibreMarker;\n Popup: new (options: Record<string, unknown>) => {\n setText(text: string): unknown;\n };\n LngLatBounds: new () => { extend(position: [number, number]): void };\n}\n\n/**\n * True when `value` looks like the maplibre-gl module: it has a `Map`\n * constructor. Use it on the module that a map loader resolves.\n */\nexport function isMapLibre(value: unknown): value is MapLibre {\n return (\n typeof value === \"object\" &&\n value !== null &&\n \"Map\" in value &&\n typeof value.Map === \"function\"\n );\n}\n\n/** True when the marker has finite coordinates, so the map can place it. */\nexport const isValidMarker = (marker: MapMarker) =>\n Number.isFinite(marker.lat) && Number.isFinite(marker.lng);\n"],"mappings":";;;;;;;AAWA,MAAa,oBACX;;AAGF,MAAa,yBACX;AAEF,MAAM,eAAe,IAAI,IAAI;CAAC;CAAK;CAAM;CAAK;CAAK,CAAC;;;;;;;;;;;;;AAgBpD,SAAgB,mBAAmB,QAA0B;AAC3D,KAAI,CAAC,MAAM,QAAQ,OAAO,CAAE,QAAO;CACnC,MAAM,CAAC,IAAI,MAAM,SAAS;AAQ1B,KANE,OAAO,OAAO,YACd,aAAa,IAAI,GAAG,IACpB,MAAM,QAAQ,KAAK,IACnB,KAAK,OAAO,SACZ,OAAO,KAAK,OAAO,YACnB,OAAO,UAAU,SACO,QAAO;EAAC;EAAO,CAAC,OAAO,KAAK,GAAG;EAAE;EAAO;AAClE,QAAO,OAAO,KAAK,SAAS,mBAAmB,KAAK,CAAC;;;;;;;;AASvD,SAAgB,kBACd,OACA;CACA,MAAM,SAAS,MAAM;AACrB,KAAI,WAAW,OAAW,QAAO;CACjC,MAAM,UAAU,OAAO,KAAK,UAC1B,YAAY,QACR;EAAE,GAAG;EAAO,QAAQ,mBAAmB,MAAM,OAAO;EAAE,GACtD,MACL;AAGD,QAAO;EAAE,GAAG;EAAO,QAAQ;EAAS;;;AAItC,MAAa,eAAe;;AAG5B,MAAa,eAAe;;;;;;AAO5B,MAAa,UAAU;CACrB;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CAEA;CACA;CACA;CACA;CACA;CACD,CAAC,KAAK,KAAK;;;;;AA8CZ,SAAgB,WAAW,OAAmC;AAC5D,QACE,OAAO,UAAU,YACjB,UAAU,QACV,SAAS,SACT,OAAO,MAAM,QAAQ;;;AAKzB,MAAa,iBAAiB,WAC5B,OAAO,SAAS,OAAO,IAAI,IAAI,OAAO,SAAS,OAAO,IAAI"}
|
|
@@ -25,8 +25,6 @@ declare const imageSchema: z.ZodObject<{
|
|
|
25
25
|
scaleDown: "scaleDown";
|
|
26
26
|
}>>;
|
|
27
27
|
radius: z.ZodOptional<z.ZodUnion<readonly [z.ZodEnum<{
|
|
28
|
-
"2xs": "2xs";
|
|
29
|
-
xs: "xs";
|
|
30
28
|
sm: "sm";
|
|
31
29
|
md: "md";
|
|
32
30
|
lg: "lg";
|
|
@@ -34,6 +32,8 @@ declare const imageSchema: z.ZodObject<{
|
|
|
34
32
|
"2xl": "2xl";
|
|
35
33
|
"3xl": "3xl";
|
|
36
34
|
"4xl": "4xl";
|
|
35
|
+
"2xs": "2xs";
|
|
36
|
+
xs: "xs";
|
|
37
37
|
full: "full";
|
|
38
38
|
}>, z.ZodNumber, z.ZodString, z.ZodObject<{
|
|
39
39
|
topLeft: z.ZodOptional<z.ZodString>;
|
|
@@ -160,8 +160,8 @@ declare const videoSchema: z.ZodObject<{
|
|
|
160
160
|
language: z.ZodOptional<z.ZodString>;
|
|
161
161
|
label: z.ZodOptional<z.ZodString>;
|
|
162
162
|
kind: z.ZodOptional<z.ZodEnum<{
|
|
163
|
-
subtitles: "subtitles";
|
|
164
163
|
captions: "captions";
|
|
164
|
+
subtitles: "subtitles";
|
|
165
165
|
descriptions: "descriptions";
|
|
166
166
|
}>>;
|
|
167
167
|
}, z.core.$strip>>>;
|
|
@@ -209,8 +209,6 @@ declare const mediaDeclarations: {
|
|
|
209
209
|
scaleDown: "scaleDown";
|
|
210
210
|
}>>;
|
|
211
211
|
radius: z.ZodOptional<z.ZodUnion<readonly [z.ZodEnum<{
|
|
212
|
-
"2xs": "2xs";
|
|
213
|
-
xs: "xs";
|
|
214
212
|
sm: "sm";
|
|
215
213
|
md: "md";
|
|
216
214
|
lg: "lg";
|
|
@@ -218,6 +216,8 @@ declare const mediaDeclarations: {
|
|
|
218
216
|
"2xl": "2xl";
|
|
219
217
|
"3xl": "3xl";
|
|
220
218
|
"4xl": "4xl";
|
|
219
|
+
"2xs": "2xs";
|
|
220
|
+
xs: "xs";
|
|
221
221
|
full: "full";
|
|
222
222
|
}>, z.ZodNumber, z.ZodString, z.ZodObject<{
|
|
223
223
|
topLeft: z.ZodOptional<z.ZodString>;
|
|
@@ -362,8 +362,8 @@ declare const mediaDeclarations: {
|
|
|
362
362
|
language: z.ZodOptional<z.ZodString>;
|
|
363
363
|
label: z.ZodOptional<z.ZodString>;
|
|
364
364
|
kind: z.ZodOptional<z.ZodEnum<{
|
|
365
|
-
subtitles: "subtitles";
|
|
366
365
|
captions: "captions";
|
|
366
|
+
subtitles: "subtitles";
|
|
367
367
|
descriptions: "descriptions";
|
|
368
368
|
}>>;
|
|
369
369
|
}, z.core.$strip>>>;
|
|
@@ -25,8 +25,6 @@ declare const imageSchema: z.ZodObject<{
|
|
|
25
25
|
scaleDown: "scaleDown";
|
|
26
26
|
}>>;
|
|
27
27
|
radius: z.ZodOptional<z.ZodUnion<readonly [z.ZodEnum<{
|
|
28
|
-
"2xs": "2xs";
|
|
29
|
-
xs: "xs";
|
|
30
28
|
sm: "sm";
|
|
31
29
|
md: "md";
|
|
32
30
|
lg: "lg";
|
|
@@ -34,6 +32,8 @@ declare const imageSchema: z.ZodObject<{
|
|
|
34
32
|
"2xl": "2xl";
|
|
35
33
|
"3xl": "3xl";
|
|
36
34
|
"4xl": "4xl";
|
|
35
|
+
"2xs": "2xs";
|
|
36
|
+
xs: "xs";
|
|
37
37
|
full: "full";
|
|
38
38
|
}>, z.ZodNumber, z.ZodString, z.ZodObject<{
|
|
39
39
|
topLeft: z.ZodOptional<z.ZodString>;
|
|
@@ -160,8 +160,8 @@ declare const videoSchema: z.ZodObject<{
|
|
|
160
160
|
language: z.ZodOptional<z.ZodString>;
|
|
161
161
|
label: z.ZodOptional<z.ZodString>;
|
|
162
162
|
kind: z.ZodOptional<z.ZodEnum<{
|
|
163
|
-
subtitles: "subtitles";
|
|
164
163
|
captions: "captions";
|
|
164
|
+
subtitles: "subtitles";
|
|
165
165
|
descriptions: "descriptions";
|
|
166
166
|
}>>;
|
|
167
167
|
}, z.core.$strip>>>;
|
|
@@ -209,8 +209,6 @@ declare const mediaDeclarations: {
|
|
|
209
209
|
scaleDown: "scaleDown";
|
|
210
210
|
}>>;
|
|
211
211
|
radius: z.ZodOptional<z.ZodUnion<readonly [z.ZodEnum<{
|
|
212
|
-
"2xs": "2xs";
|
|
213
|
-
xs: "xs";
|
|
214
212
|
sm: "sm";
|
|
215
213
|
md: "md";
|
|
216
214
|
lg: "lg";
|
|
@@ -218,6 +216,8 @@ declare const mediaDeclarations: {
|
|
|
218
216
|
"2xl": "2xl";
|
|
219
217
|
"3xl": "3xl";
|
|
220
218
|
"4xl": "4xl";
|
|
219
|
+
"2xs": "2xs";
|
|
220
|
+
xs: "xs";
|
|
221
221
|
full: "full";
|
|
222
222
|
}>, z.ZodNumber, z.ZodString, z.ZodObject<{
|
|
223
223
|
topLeft: z.ZodOptional<z.ZodString>;
|
|
@@ -362,8 +362,8 @@ declare const mediaDeclarations: {
|
|
|
362
362
|
language: z.ZodOptional<z.ZodString>;
|
|
363
363
|
label: z.ZodOptional<z.ZodString>;
|
|
364
364
|
kind: z.ZodOptional<z.ZodEnum<{
|
|
365
|
-
subtitles: "subtitles";
|
|
366
365
|
captions: "captions";
|
|
366
|
+
subtitles: "subtitles";
|
|
367
367
|
descriptions: "descriptions";
|
|
368
368
|
}>>;
|
|
369
369
|
}, z.core.$strip>>>;
|