@alulore/kumiko 0.19.1 → 0.20.0

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.
Files changed (136) hide show
  1. package/dist/board/board-api.d.ts +2 -1
  2. package/dist/board/board-api.js +1 -1
  3. package/dist/board/board-motion.js +29 -1
  4. package/dist/board/board-slots.d.ts +14 -7
  5. package/dist/board/board-slots.js +5 -3
  6. package/dist/board/board.d.ts +20 -5
  7. package/dist/board/board.js +28 -5
  8. package/dist/board/keep-capture.d.ts +10 -5
  9. package/dist/board/keep-capture.js +48 -13
  10. package/dist/cooldown/cooldown-button.d.ts +30 -0
  11. package/dist/cooldown/cooldown-button.js +75 -0
  12. package/dist/cooldown/cooldown-labels.d.ts +8 -0
  13. package/dist/cooldown/cooldown-labels.js +4 -0
  14. package/dist/cooldown/cooldown-time.d.ts +8 -0
  15. package/dist/cooldown/cooldown-time.js +20 -0
  16. package/dist/cooldown/cooldown.css +21 -0
  17. package/dist/cooldown/index.d.ts +4 -0
  18. package/dist/cooldown/index.js +4 -0
  19. package/dist/cooldown/use-cooldown.d.ts +30 -0
  20. package/dist/cooldown/use-cooldown.js +63 -0
  21. package/dist/dialog/dialog-content.d.ts +5 -0
  22. package/dist/dialog/dialog-content.js +7 -0
  23. package/dist/empty-state/empty-state-labels.d.ts +14 -0
  24. package/dist/empty-state/empty-state-labels.js +10 -0
  25. package/dist/empty-state/empty-state.css +134 -0
  26. package/dist/empty-state/empty-state.d.ts +34 -0
  27. package/dist/empty-state/empty-state.js +61 -0
  28. package/dist/empty-state/index.d.ts +2 -0
  29. package/dist/empty-state/index.js +2 -0
  30. package/dist/form/choice-fields.d.ts +34 -0
  31. package/dist/form/choice-fields.js +41 -0
  32. package/dist/form/error-line.d.ts +8 -0
  33. package/dist/form/error-line.js +47 -0
  34. package/dist/form/field-props.d.ts +12 -0
  35. package/dist/form/field-props.js +8 -0
  36. package/dist/form/field-shell.d.ts +18 -0
  37. package/dist/form/field-shell.js +51 -0
  38. package/dist/form/focus-invalid.d.ts +5 -0
  39. package/dist/form/focus-invalid.js +17 -0
  40. package/dist/form/form-context.d.ts +2 -0
  41. package/dist/form/form-context.js +3 -0
  42. package/dist/form/form-parts.d.ts +20 -0
  43. package/dist/form/form-parts.js +73 -0
  44. package/dist/form/form.css +128 -0
  45. package/dist/form/index.d.ts +10 -0
  46. package/dist/form/index.js +9 -0
  47. package/dist/form/shown-error.d.ts +12 -0
  48. package/dist/form/shown-error.js +27 -0
  49. package/dist/form/submit-errors.d.ts +36 -0
  50. package/dist/form/submit-errors.js +46 -0
  51. package/dist/form/text-fields.d.ts +18 -0
  52. package/dist/form/text-fields.js +21 -0
  53. package/dist/form/use-app-form.d.ts +1655 -0
  54. package/dist/form/use-app-form.js +94 -0
  55. package/dist/form/use-dialog-link.d.ts +5 -0
  56. package/dist/form/use-dialog-link.js +30 -0
  57. package/dist/form/value-fields.d.ts +16 -0
  58. package/dist/form/value-fields.js +15 -0
  59. package/dist/map/geo.d.ts +20 -0
  60. package/dist/map/geo.js +41 -0
  61. package/dist/map/index.d.ts +5 -0
  62. package/dist/map/index.js +4 -0
  63. package/dist/map/label-overlap.d.ts +13 -0
  64. package/dist/map/label-overlap.js +23 -0
  65. package/dist/map/load-map.d.ts +12 -0
  66. package/dist/map/load-map.js +22 -0
  67. package/dist/map/location-map.d.ts +39 -0
  68. package/dist/map/location-map.js +171 -0
  69. package/dist/map/map-frame.d.ts +18 -0
  70. package/dist/map/map-frame.js +6 -0
  71. package/dist/map/map-pin.d.ts +4 -0
  72. package/dist/map/map-pin.js +38 -0
  73. package/dist/map/map-popup.d.ts +17 -0
  74. package/dist/map/map-popup.js +101 -0
  75. package/dist/map/map-source.d.ts +52 -0
  76. package/dist/map/map-source.js +59 -0
  77. package/dist/map/map.css +311 -0
  78. package/dist/map/marker-pins.d.ts +29 -0
  79. package/dist/map/marker-pins.js +144 -0
  80. package/dist/map/markers-map.d.ts +57 -0
  81. package/dist/map/markers-map.js +154 -0
  82. package/dist/map/use-label-overlap.d.ts +9 -0
  83. package/dist/map/use-label-overlap.js +55 -0
  84. package/dist/map/use-map.d.ts +49 -0
  85. package/dist/map/use-map.js +201 -0
  86. package/dist/media/encoding.d.ts +32 -0
  87. package/dist/media/encoding.js +59 -0
  88. package/dist/media/errors.d.ts +33 -0
  89. package/dist/media/errors.js +26 -0
  90. package/dist/media/image.d.ts +9 -0
  91. package/dist/media/image.js +35 -0
  92. package/dist/media/index.d.ts +10 -0
  93. package/dist/media/index.js +10 -0
  94. package/dist/media/load-mediabunny.d.ts +7 -0
  95. package/dist/media/load-mediabunny.js +13 -0
  96. package/dist/media/media-upload.d.ts +40 -0
  97. package/dist/media/media-upload.js +132 -0
  98. package/dist/media/media.css +101 -0
  99. package/dist/media/probe.d.ts +19 -0
  100. package/dist/media/probe.js +49 -0
  101. package/dist/media/sizes.d.ts +28 -0
  102. package/dist/media/sizes.js +51 -0
  103. package/dist/media/slideshow.d.ts +43 -0
  104. package/dist/media/slideshow.js +174 -0
  105. package/dist/media/timeline.d.ts +59 -0
  106. package/dist/media/timeline.js +105 -0
  107. package/dist/media/transcode.d.ts +35 -0
  108. package/dist/media/transcode.js +132 -0
  109. package/dist/media/upload.d.ts +21 -0
  110. package/dist/media/upload.js +54 -0
  111. package/dist/media/use-media-job.d.ts +79 -0
  112. package/dist/media/use-media-job.js +143 -0
  113. package/dist/server-render.test.js +93 -0
  114. package/dist/smooth-caret/caret-controller.js +16 -3
  115. package/dist/table/table-labels.d.ts +2 -0
  116. package/dist/table/table-labels.js +1 -0
  117. package/dist/table/table-sections.js +10 -2
  118. package/dist/table/table.css +1 -0
  119. package/dist/theme/define-theme.d.ts +38 -0
  120. package/dist/theme/define-theme.js +56 -0
  121. package/dist/theme/index.d.ts +3 -0
  122. package/dist/theme/index.js +3 -0
  123. package/dist/theme/theme-style.d.ts +6 -0
  124. package/dist/theme/theme-style.js +11 -0
  125. package/dist/theme/theme-types.d.ts +1 -0
  126. package/dist/theme/theme-types.js +26 -0
  127. package/dist/theme/tokens-1.generated.d.ts +1 -0
  128. package/dist/theme/tokens-1.generated.js +404 -0
  129. package/dist/theme/tokens-2.generated.d.ts +1 -0
  130. package/dist/theme/tokens-2.generated.js +404 -0
  131. package/dist/theme/tokens-3.generated.d.ts +1 -0
  132. package/dist/theme/tokens-3.generated.js +158 -0
  133. package/dist/theme/tokens.generated.d.ts +2 -0
  134. package/dist/theme/tokens.generated.js +6 -0
  135. package/dist/undo/undo-provider.js +24 -9
  136. package/package.json +78 -1
@@ -0,0 +1,101 @@
1
+ import { useEffect, useRef, useState } from "react";
2
+ const GAP = 6;
3
+ /**
4
+ * Where the popup sits for each side MapLibre may put it on: clear of the pin's drawing, at its selected size
5
+ * when it is selected. Above is first choice; near the top edge it flips below the tip.
6
+ */
7
+ function offsetsFor(pin) {
8
+ const style = getComputedStyle(pin.element);
9
+ const scale = Object.hasOwn(pin.element.dataset, "selected")
10
+ ? Number(style.getPropertyValue("--kumiko-map-pin-selected-scale")) || 1
11
+ : 1;
12
+ const high = pin.element.offsetHeight * scale;
13
+ const half = (pin.element.offsetWidth * scale) / 2;
14
+ const middle = -high / 2;
15
+ return {
16
+ center: [0, middle],
17
+ top: [0, GAP],
18
+ "top-left": [GAP, GAP],
19
+ "top-right": [-GAP, GAP],
20
+ bottom: [0, -high - GAP],
21
+ "bottom-left": [GAP, -high - GAP],
22
+ "bottom-right": [-GAP, -high - GAP],
23
+ left: [half + GAP, middle],
24
+ right: [-half - GAP, middle]
25
+ };
26
+ }
27
+ function createPopup(loaded, handle, kind, onClose, quiet) {
28
+ const content = document.createElement("div");
29
+ content.dataset.slot = `map-${kind}`;
30
+ const made = new loaded.maplibre.Popup({
31
+ closeButton: false,
32
+ closeOnClick: false,
33
+ closeOnMove: false,
34
+ focusAfterOpen: false,
35
+ maxWidth: "none",
36
+ className: `kumiko-map-${kind}`
37
+ }).setDOMContent(content);
38
+ made.on("close", () => {
39
+ if (!quiet.current) {
40
+ onClose.current();
41
+ }
42
+ });
43
+ const map = handle.map.current;
44
+ const onMapClick = (event) => {
45
+ const target = event.originalEvent.target;
46
+ const onPin = target instanceof Element && target.closest("[data-slot=map-pin]");
47
+ if (kind === "card" && made.isOpen() && !onPin) {
48
+ made.remove();
49
+ }
50
+ };
51
+ map?.on("click", onMapClick);
52
+ return { content, made, stop: () => map?.off("click", onMapClick) };
53
+ }
54
+ /**
55
+ * One MapLibre popup whose content the component renders. A card closes on a click on the map, which is
56
+ * reported through `onClose`: MapLibre's own close-on-click is off, because a press on a pin is a click on the
57
+ * map too and would close the card it just opened. A preview never takes the pointer.
58
+ */
59
+ export function useMapPopup(handle, kind, onClose) {
60
+ const [element, setElement] = useState(null);
61
+ const popup = useRef(null);
62
+ const quiet = useRef(false);
63
+ const ready = handle.state.phase === "ready";
64
+ useEffect(() => {
65
+ const loaded = handle.modules.current;
66
+ if (!ready || !loaded) {
67
+ return undefined;
68
+ }
69
+ const { content, made, stop } = createPopup(loaded, handle, kind, onClose, quiet);
70
+ popup.current = made;
71
+ setElement(content);
72
+ return () => {
73
+ stop();
74
+ quiet.current = true;
75
+ made.remove();
76
+ quiet.current = false;
77
+ popup.current = null;
78
+ setElement(null);
79
+ };
80
+ }, [ready, handle, kind, onClose]);
81
+ const map = handle.map;
82
+ return {
83
+ element,
84
+ open: (pin) => {
85
+ const made = popup.current;
86
+ const live = map.current;
87
+ if (!made || !live) {
88
+ return;
89
+ }
90
+ made.setOffset(offsetsFor(pin)).setLngLat(pin.marker.getLngLat());
91
+ if (!made.isOpen()) {
92
+ made.addTo(live);
93
+ }
94
+ },
95
+ close: () => {
96
+ quiet.current = true;
97
+ popup.current?.remove();
98
+ quiet.current = false;
99
+ }
100
+ };
101
+ }
@@ -0,0 +1,52 @@
1
+ import type * as BasemapsModule from "@protomaps/basemaps";
2
+ import type { StyleSpecification } from "maplibre-gl";
3
+ /** A MapLibre style, its URL, or one per flavour. */
4
+ export type MapStyle = StyleSpecification | string | ((flavor: MapFlavor) => StyleSpecification | string);
5
+ /** A Protomaps basemap flavour. */
6
+ export type MapFlavor = "light" | "dark" | "white" | "grayscale" | "black";
7
+ export interface MapSourceInput {
8
+ /**
9
+ * The vector tiles: a `.pmtiles` archive URL (read through the PMTiles protocol) or a TileJSON URL. There is
10
+ * no default tile server, so an app always names its own.
11
+ */
12
+ readonly tiles: string;
13
+ /** The glyph URL template, with `{fontstack}` and `{range}`. */
14
+ readonly glyphs: string;
15
+ /** The sprite base URL. The flavour is added as the last part: `<sprite>/light`. */
16
+ readonly sprite: string;
17
+ /** The language labels are shown in, such as `pt`. @defaultValue `"en"` */
18
+ readonly language?: string;
19
+ /** The credit the tiles need. It is always shown on the map. */
20
+ readonly attribution: string;
21
+ /**
22
+ * MapLibre's worker file, served by the app. In Vite:
23
+ * `import workerUrl from "maplibre-gl/dist/maplibre-gl-worker.mjs?worker&url"`.
24
+ */
25
+ readonly workerUrl: string;
26
+ /** A fixed flavour. Without it the map follows the page's light or dark scheme. */
27
+ readonly flavor?: MapFlavor;
28
+ /**
29
+ * A whole MapLibre style that replaces the basemap, so `tiles`, `glyphs` and `sprite` are unused. A function
30
+ * is given the flavour and is called again when the page turns light or dark.
31
+ */
32
+ readonly style?: MapStyle;
33
+ }
34
+ /** A checked map source, shared by every map on the page. */
35
+ export interface MapSource extends Required<Omit<MapSourceInput, "flavor" | "style">> {
36
+ readonly flavor: MapFlavor | undefined;
37
+ readonly style: MapStyle | undefined;
38
+ }
39
+ /** Checks a map source once, so a missing URL fails where the app defines it rather than in a blank map. */
40
+ export declare function defineMapSource(input: MapSourceInput): MapSource;
41
+ /** The vector source's URL: a `.pmtiles` archive goes through the PMTiles protocol. */
42
+ export declare function tilesUrl(tiles: string): string;
43
+ /** The flavour a map shows: the fixed one, or light or dark from the scheme it sits in. */
44
+ export declare function flavorFor(source: MapSource, dark: boolean): MapFlavor;
45
+ /** Whether the map draws a new style when the page turns light or dark. */
46
+ export declare function followsScheme(source: MapSource): boolean;
47
+ /** The style a source draws in a flavour. */
48
+ export declare function styleFor(source: MapSource, flavor: MapFlavor, basemaps: Basemaps): StyleSpecification | string;
49
+ /** What `@protomaps/basemaps` gives the style builder. */
50
+ export type Basemaps = Pick<typeof BasemapsModule, "layers" | "namedFlavor">;
51
+ /** The MapLibre style for a source and flavour. The attribution is shown by the map's own control. */
52
+ export declare function basemapStyle(source: MapSource, flavor: MapFlavor, basemaps: Basemaps): StyleSpecification;
@@ -0,0 +1,59 @@
1
+ const required = ["tiles", "glyphs", "sprite", "attribution", "workerUrl"];
2
+ /** Checks a map source once, so a missing URL fails where the app defines it rather than in a blank map. */
3
+ export function defineMapSource(input) {
4
+ for (const key of input.style === undefined
5
+ ? required
6
+ : ["attribution", "workerUrl"]) {
7
+ if (typeof input[key] !== "string" || input[key].trim() === "") {
8
+ throw new Error(`The map source needs "${key}"`);
9
+ }
10
+ }
11
+ return {
12
+ tiles: input.tiles,
13
+ glyphs: input.glyphs,
14
+ sprite: input.sprite,
15
+ language: input.language ?? "en",
16
+ attribution: input.attribution,
17
+ workerUrl: input.workerUrl,
18
+ flavor: input.flavor,
19
+ style: input.style
20
+ };
21
+ }
22
+ /** The vector source's URL: a `.pmtiles` archive goes through the PMTiles protocol. */
23
+ export function tilesUrl(tiles) {
24
+ if (tiles.startsWith("pmtiles://")) {
25
+ return tiles;
26
+ }
27
+ const path = tiles.split(/[?#]/u)[0] ?? tiles;
28
+ return path.toLowerCase().endsWith(".pmtiles") ? `pmtiles://${tiles}` : tiles;
29
+ }
30
+ /** The flavour a map shows: the fixed one, or light or dark from the scheme it sits in. */
31
+ export function flavorFor(source, dark) {
32
+ return source.flavor ?? (dark ? "dark" : "light");
33
+ }
34
+ /** Whether the map draws a new style when the page turns light or dark. */
35
+ export function followsScheme(source) {
36
+ return (source.flavor === undefined &&
37
+ (source.style === undefined || typeof source.style === "function"));
38
+ }
39
+ /** The style a source draws in a flavour. */
40
+ export function styleFor(source, flavor, basemaps) {
41
+ if (typeof source.style === "function") {
42
+ return source.style(flavor);
43
+ }
44
+ return source.style ?? basemapStyle(source, flavor, basemaps);
45
+ }
46
+ /** The MapLibre style for a source and flavour. The attribution is shown by the map's own control. */
47
+ export function basemapStyle(source, flavor, basemaps) {
48
+ return {
49
+ version: 8,
50
+ glyphs: source.glyphs,
51
+ sprite: `${source.sprite.replace(/\/+$/u, "")}/${flavor}`,
52
+ sources: {
53
+ protomaps: { type: "vector", url: tilesUrl(source.tiles) }
54
+ },
55
+ layers: basemaps.layers("protomaps", basemaps.namedFlavor(flavor), {
56
+ lang: source.language
57
+ })
58
+ };
59
+ }
@@ -0,0 +1,311 @@
1
+ @import "../motion/motion.css";
2
+ /* MapLibre's own rules sit in a layer under Kumiko's, so every rule below wins without raising specificity. */
3
+ @import "maplibre-gl/dist/maplibre-gl.css" layer(kumiko.maplibre);
4
+
5
+ @layer kumiko {
6
+ :where(:root) {
7
+ --kumiko-map-min-height: 18rem;
8
+ --kumiko-map-radius: 0.75rem;
9
+ --kumiko-map-border: 1px solid color-mix(in oklab, currentColor 16%, transparent);
10
+ --kumiko-map-surface: color-mix(in oklab, currentColor 6%, Canvas);
11
+ --kumiko-map-note-color: color-mix(in oklab, currentColor 70%, transparent);
12
+ --kumiko-map-control-bg: color-mix(in oklab, Canvas 88%, transparent);
13
+ --kumiko-map-control-color: CanvasText;
14
+ --kumiko-map-pin-size: 2.25rem;
15
+ --kumiko-map-pin-selected-scale: 1.3;
16
+ --kumiko-map-pin: Highlight;
17
+ --kumiko-map-pin-selected: var(--kumiko-map-pin);
18
+ --kumiko-map-pin-edge: Canvas;
19
+ --kumiko-map-pin-dot: Canvas;
20
+ --kumiko-map-focus-ring: Highlight;
21
+ --kumiko-map-focus-ring-width: 2px;
22
+ --kumiko-map-label-size: 0.75rem;
23
+ --kumiko-map-label-weight: 600;
24
+ --kumiko-map-label-color: CanvasText;
25
+ --kumiko-map-label-halo: Canvas;
26
+ --kumiko-map-card-bg: Canvas;
27
+ --kumiko-map-card-color: CanvasText;
28
+ --kumiko-map-card-radius: 0.625rem;
29
+ --kumiko-map-card-padding: 0.75rem;
30
+ --kumiko-map-card-max-width: 18rem;
31
+ --kumiko-map-card-shadow: 0 8px 24px -6px color-mix(in oklab, CanvasText 28%, transparent);
32
+ --kumiko-map-preview-bg: CanvasText;
33
+ --kumiko-map-preview-color: Canvas;
34
+ --kumiko-map-preview-radius: 0.375rem;
35
+ --kumiko-map-preview-padding: 0.25rem 0.5rem;
36
+ }
37
+
38
+ :where([data-slot="map"]) {
39
+ position: relative;
40
+ isolation: isolate;
41
+ display: grid;
42
+ /* Fills a box the app sizes; under a box of auto height, the minimum decides. */
43
+ box-sizing: border-box;
44
+ block-size: 100%;
45
+ min-block-size: var(--kumiko-map-min-height);
46
+ overflow: hidden;
47
+ border: var(--kumiko-map-border);
48
+ border-radius: var(--kumiko-map-radius);
49
+ background: var(--kumiko-map-surface);
50
+ }
51
+
52
+ :where([data-slot="map-canvas"]) {
53
+ grid-area: 1 / 1;
54
+ min-block-size: 0;
55
+ }
56
+
57
+ /* Resolves light-dark() to white in a dark scheme, which is how the map knows which basemap to draw. */
58
+ :where([data-slot="map-scheme"]) {
59
+ position: absolute;
60
+ inline-size: 0;
61
+ block-size: 0;
62
+ overflow: hidden;
63
+ color: rgb(0 0 0);
64
+ color: light-dark(rgb(0 0 0), rgb(255 255 255));
65
+ }
66
+
67
+ :where([data-slot="map-loading"], [data-slot="map-fallback"]) {
68
+ z-index: 1;
69
+ display: grid;
70
+ grid-area: 1 / 1;
71
+ place-items: center;
72
+ padding: 1rem;
73
+ color: var(--kumiko-map-note-color);
74
+ text-align: center;
75
+ background: var(--kumiko-map-surface);
76
+ transition: opacity var(--kumiko-fade-duration) var(--kumiko-fade-ease);
77
+ }
78
+
79
+ @starting-style {
80
+ :where([data-slot="map-fallback"]) {
81
+ opacity: 0;
82
+ }
83
+ }
84
+
85
+ :where([data-slot="map"]) .maplibregl-canvas:focus-visible {
86
+ outline: var(--kumiko-map-focus-ring-width) solid var(--kumiko-map-focus-ring);
87
+ outline-offset: calc(var(--kumiko-map-focus-ring-width) * -1);
88
+ }
89
+
90
+ /* The pin: a button with no box of its own, so only the drawing shows and takes the press. */
91
+ :where([data-slot="map-pin"]) {
92
+ display: block;
93
+ inline-size: var(--kumiko-map-pin-size);
94
+ aspect-ratio: 36 / 44;
95
+ padding: 0;
96
+ border: 0;
97
+ background: none;
98
+ color: var(--kumiko-map-pin);
99
+ cursor: var(--kumiko-press-cursor, pointer);
100
+ touch-action: none;
101
+ }
102
+
103
+ :where([data-slot="map-pin"][data-read-only]) {
104
+ cursor: default;
105
+ }
106
+
107
+ :where([data-slot="map-pin"][data-selected]) {
108
+ z-index: 1;
109
+ color: var(--kumiko-map-pin-selected);
110
+ }
111
+
112
+ :where([data-slot="map-pin-art"]) {
113
+ display: block;
114
+ inline-size: 100%;
115
+ block-size: 100%;
116
+ overflow: visible;
117
+ transform-origin: 50% 100%;
118
+ transition: scale var(--kumiko-move-duration) var(--kumiko-move-ease);
119
+ }
120
+
121
+ :where([data-slot="map-pin-art"] [data-part="body"]) {
122
+ fill: currentColor;
123
+ stroke: var(--kumiko-map-pin-edge);
124
+ stroke-width: 2.5;
125
+ stroke-linejoin: round;
126
+ }
127
+
128
+ :where([data-slot="map-pin-art"] [data-part="dot"]) {
129
+ fill: var(--kumiko-map-pin-dot);
130
+ }
131
+
132
+ :where([data-slot="map-pin"][data-selected] [data-slot="map-pin-art"]) {
133
+ scale: var(--kumiko-map-pin-selected-scale);
134
+ }
135
+
136
+ @media (hover: hover) and (pointer: fine) {
137
+ :where(button[data-slot="map-pin"]:hover [data-slot="map-pin-art"]) {
138
+ scale: var(--kumiko-hover-scale, 1.06);
139
+ }
140
+
141
+ :where(button[data-slot="map-pin"][data-selected]:hover [data-slot="map-pin-art"]) {
142
+ scale: var(--kumiko-map-pin-selected-scale);
143
+ }
144
+ }
145
+
146
+ :where([data-slot="map-pin"]:focus-visible) {
147
+ outline: none;
148
+ }
149
+
150
+ :where([data-slot="map-pin"]:focus-visible [data-part="body"]) {
151
+ stroke: var(--kumiko-map-focus-ring);
152
+ stroke-width: 4;
153
+ }
154
+
155
+ /* A finger gets a target of the touch size, centred on the drawing. */
156
+ @media (pointer: coarse) {
157
+ :where(button[data-slot="map-pin"])::after {
158
+ position: absolute;
159
+ inset: 50% auto auto 50%;
160
+ inline-size: max(100%, var(--kumiko-touch-target, 2.75rem));
161
+ block-size: max(100%, var(--kumiko-touch-target, 2.75rem));
162
+ translate: -50% -50%;
163
+ content: "";
164
+ }
165
+ }
166
+
167
+ /* MapLibre's controls, on the page's colours rather than fixed white. */
168
+ :where([data-slot="map"]) .maplibregl-ctrl-group,
169
+ :where([data-slot="map"]) .maplibregl-ctrl-attrib {
170
+ color: var(--kumiko-map-control-color);
171
+ background: var(--kumiko-map-control-bg);
172
+ }
173
+
174
+ :where([data-slot="map"]) .maplibregl-ctrl-attrib a {
175
+ color: inherit;
176
+ }
177
+
178
+ :where([data-slot="map"]) .maplibregl-ctrl-group button + button {
179
+ border-block-start-color: color-mix(in oklab, currentColor 18%, transparent);
180
+ }
181
+
182
+ /*
183
+ * The name beside a pin. It sits level with the pin's head and clears the drawing at its selected size too.
184
+ * Hidden by default; the map's labels option shows it.
185
+ */
186
+ :where([data-slot="map-pin-label"]) {
187
+ --_scale: 1;
188
+ position: absolute;
189
+ inset-block-start: calc(100% - 100% * 0.58 * var(--_scale));
190
+ inset-inline-start: calc(50% + 50% * 0.8 * var(--_scale) + 0.25rem);
191
+ display: none;
192
+ translate: 0 -50%;
193
+ color: var(--kumiko-map-label-color);
194
+ font-size: var(--kumiko-map-label-size);
195
+ font-weight: var(--kumiko-map-label-weight);
196
+ line-height: 1.2;
197
+ white-space: nowrap;
198
+ pointer-events: none;
199
+ text-shadow:
200
+ 0 0 2px var(--kumiko-map-label-halo),
201
+ 0 0 2px var(--kumiko-map-label-halo),
202
+ 0 0 3px var(--kumiko-map-label-halo);
203
+ }
204
+
205
+ :where([data-slot="map-pin"][data-selected] [data-slot="map-pin-label"]) {
206
+ --_scale: var(--kumiko-map-pin-selected-scale);
207
+ }
208
+
209
+ :where([data-slot="map"][data-labels="always"] [data-slot="map-pin-label"]),
210
+ :where([data-slot="map"][data-labels="selected"] [data-selected] [data-slot="map-pin-label"]) {
211
+ display: block;
212
+ }
213
+
214
+ :where([data-slot="map-pin-label"][data-hidden]) {
215
+ visibility: hidden;
216
+ }
217
+
218
+ /* The card and the preview are MapLibre popups: Kumiko draws their box and tip. */
219
+ :where([data-slot="map"]) .maplibregl-popup {
220
+ z-index: 3;
221
+ transition: opacity var(--kumiko-fade-duration) var(--kumiko-fade-ease);
222
+ }
223
+
224
+ @starting-style {
225
+ :where([data-slot="map"]) .maplibregl-popup {
226
+ opacity: 0;
227
+ }
228
+ }
229
+
230
+ :where([data-slot="map"]) .kumiko-map-card .maplibregl-popup-content {
231
+ max-inline-size: var(--kumiko-map-card-max-width);
232
+ padding: var(--kumiko-map-card-padding);
233
+ border-radius: var(--kumiko-map-card-radius);
234
+ color: var(--kumiko-map-card-color);
235
+ background: var(--kumiko-map-card-bg);
236
+ box-shadow: var(--kumiko-map-card-shadow);
237
+ }
238
+
239
+ :where([data-slot="map"]) .kumiko-map-card {
240
+ --_tip: var(--kumiko-map-card-bg);
241
+ }
242
+
243
+ :where([data-slot="map-card-body"]:focus-visible) {
244
+ outline: var(--kumiko-map-focus-ring-width) solid var(--kumiko-map-focus-ring);
245
+ outline-offset: calc(var(--kumiko-map-card-padding) / 2);
246
+ border-radius: 0.25rem;
247
+ }
248
+
249
+ :where([data-slot="map"]) .kumiko-map-preview {
250
+ pointer-events: none;
251
+ }
252
+
253
+ :where([data-slot="map"]) .kumiko-map-preview .maplibregl-popup-content {
254
+ padding: var(--kumiko-map-preview-padding);
255
+ border-radius: var(--kumiko-map-preview-radius);
256
+ color: var(--kumiko-map-preview-color);
257
+ background: var(--kumiko-map-preview-bg);
258
+ font-size: var(--kumiko-map-label-size);
259
+ font-weight: var(--kumiko-map-label-weight);
260
+ white-space: nowrap;
261
+ box-shadow: none;
262
+ }
263
+
264
+ :where([data-slot="map"]) .kumiko-map-preview {
265
+ --_tip: var(--kumiko-map-preview-bg);
266
+ }
267
+
268
+ /* The tip takes the popup's colour on whichever side MapLibre put the popup. */
269
+ :where([data-slot="map"])
270
+ :is(
271
+ .maplibregl-popup-anchor-bottom,
272
+ .maplibregl-popup-anchor-bottom-left,
273
+ .maplibregl-popup-anchor-bottom-right
274
+ )
275
+ .maplibregl-popup-tip {
276
+ border-top-color: var(--_tip);
277
+ }
278
+
279
+ :where([data-slot="map"])
280
+ :is(
281
+ .maplibregl-popup-anchor-top,
282
+ .maplibregl-popup-anchor-top-left,
283
+ .maplibregl-popup-anchor-top-right
284
+ )
285
+ .maplibregl-popup-tip {
286
+ border-bottom-color: var(--_tip);
287
+ }
288
+
289
+ :where([data-slot="map"]) .maplibregl-popup-anchor-left .maplibregl-popup-tip {
290
+ border-right-color: var(--_tip);
291
+ }
292
+
293
+ :where([data-slot="map"]) .maplibregl-popup-anchor-right .maplibregl-popup-tip {
294
+ border-left-color: var(--_tip);
295
+ }
296
+
297
+ @media (forced-colors: active) {
298
+ :where([data-slot="map-pin-art"] [data-part="body"]) {
299
+ fill: Highlight;
300
+ stroke: Canvas;
301
+ }
302
+
303
+ :where([data-slot="map-pin"][data-selected] [data-part="body"]) {
304
+ fill: SelectedItem;
305
+ }
306
+
307
+ :where([data-slot="map-pin"]:focus-visible [data-part="body"]) {
308
+ stroke: CanvasText;
309
+ }
310
+ }
311
+ }
@@ -0,0 +1,29 @@
1
+ import type { Marker } from "maplibre-gl";
2
+ import { type RefObject } from "react";
3
+ import type { LatLng } from "./geo";
4
+ import type { MapHandle } from "./use-map";
5
+ export interface MapMarker extends LatLng {
6
+ /** A stable id, given back by `onSelect` and `onHover`. */
7
+ readonly id: string;
8
+ /** The pin's accessible name: the place's name. It is also the text of its label and default preview. */
9
+ readonly label: string;
10
+ }
11
+ export interface Pin {
12
+ readonly marker: Marker;
13
+ readonly element: HTMLButtonElement;
14
+ readonly label: HTMLSpanElement;
15
+ }
16
+ /** What a pin does when it is pressed, hovered or focused. `keyboard` is true for a press without a pointer. */
17
+ export interface PinEvents {
18
+ readonly select: (id: string, keyboard: boolean) => void;
19
+ readonly hover: (id: string | null, from: "pointer" | "focus") => void;
20
+ readonly escape: (id: string) => void;
21
+ }
22
+ export type Pins = RefObject<Map<string, Pin>>;
23
+ /** The pins, kept in step with `markers` once the map is ready, and removed with the map. */
24
+ export declare function usePins(handle: MapHandle, events: RefObject<PinEvents>, markers: readonly MapMarker[]): Pins;
25
+ /** Marks the selected pin, and says on each pin whether pressing it opens a card. */
26
+ export declare function useSelected(pins: Pins, handle: MapHandle, markers: readonly MapMarker[], selectedId: string | null, card: {
27
+ readonly id: string;
28
+ readonly open: boolean;
29
+ } | undefined): void;