@gramps-connect/story 0.7.0 → 0.7.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.
Files changed (67) hide show
  1. package/dist/editor.js +41 -9
  2. package/dist/editor.js.map +2 -2
  3. package/dist/embed.js +41 -41
  4. package/dist/index.js.map +1 -1
  5. package/dist/map-edit.js.map +1 -1
  6. package/dist/player.js +39 -8
  7. package/dist/player.js.map +2 -2
  8. package/dist/types/editor/DateField.d.ts +3 -3
  9. package/dist/types/editor/MapEditor.d.ts +5 -4
  10. package/dist/types/editor/PhotosField.d.ts +2 -2
  11. package/dist/types/editor/PlaceField.d.ts +4 -4
  12. package/dist/types/editor/PlaceMap.d.ts +2 -2
  13. package/dist/types/editor/PlaceMapDialog.d.ts +4 -4
  14. package/dist/types/editor/StoryEditor.d.ts +7 -7
  15. package/dist/types/editor/index.d.ts +14 -14
  16. package/dist/types/editor/model.d.ts +1 -1
  17. package/dist/types/editor/placeShapes.d.ts +2 -2
  18. package/dist/types/editor/strings.d.ts +1 -1
  19. package/dist/types/editor/translations/de.d.ts +2 -2
  20. package/dist/types/editor/translations/es.d.ts +2 -2
  21. package/dist/types/editor/translations/fr.d.ts +2 -2
  22. package/dist/types/editor/translations/index.d.ts +2 -2
  23. package/dist/types/editor/translations/nl.d.ts +2 -2
  24. package/dist/types/index.d.ts +5 -5
  25. package/dist/types/mapEdit/index.d.ts +3 -3
  26. package/dist/types/mapEdit/mapFile.d.ts +1 -1
  27. package/dist/types/player/MapBackground.d.ts +3 -3
  28. package/dist/types/player/MapModeControl.d.ts +2 -2
  29. package/dist/types/player/StoryPlayer.d.ts +4 -4
  30. package/dist/types/player/TimelineStrip.d.ts +1 -1
  31. package/dist/types/player/dates.d.ts +1 -1
  32. package/dist/types/player/geo.d.ts +1 -1
  33. package/dist/types/player/index.d.ts +10 -10
  34. package/dist/types/version.d.ts +1 -1
  35. package/dist/types/zip.d.ts +3 -3
  36. package/package.json +2 -2
  37. package/src/editor/DateField.tsx +5 -5
  38. package/src/editor/MapEditor.tsx +10 -8
  39. package/src/editor/PhotosField.tsx +2 -2
  40. package/src/editor/PlaceField.tsx +6 -6
  41. package/src/editor/PlaceMap.tsx +5 -5
  42. package/src/editor/PlaceMapDialog.tsx +11 -11
  43. package/src/editor/StoryEditor.tsx +18 -18
  44. package/src/editor/index.ts +14 -14
  45. package/src/editor/mapEditorStrings.ts +1 -1
  46. package/src/editor/model.ts +2 -2
  47. package/src/editor/placeShapes.ts +3 -3
  48. package/src/editor/strings.ts +1 -1
  49. package/src/editor/translations/de.ts +2 -2
  50. package/src/editor/translations/es.ts +2 -2
  51. package/src/editor/translations/fr.ts +2 -2
  52. package/src/editor/translations/index.ts +6 -6
  53. package/src/editor/translations/nl.ts +2 -2
  54. package/src/embed/index.tsx +2 -2
  55. package/src/index.ts +5 -5
  56. package/src/mapEdit/index.ts +3 -3
  57. package/src/mapEdit/mapFile.ts +1 -1
  58. package/src/player/MapBackground.tsx +20 -10
  59. package/src/player/MapModeControl.tsx +2 -2
  60. package/src/player/StoryPlayer.tsx +50 -13
  61. package/src/player/TimelineStrip.tsx +2 -2
  62. package/src/player/dates.ts +1 -1
  63. package/src/player/geo.ts +1 -1
  64. package/src/player/index.ts +10 -10
  65. package/src/validate.ts +2 -2
  66. package/src/version.ts +1 -1
  67. package/src/zip.ts +3 -3
package/src/index.ts CHANGED
@@ -8,7 +8,7 @@ export type {
8
8
  SlideMedia,
9
9
  StoryDate,
10
10
  StoryDoc,
11
- } from "./types";
11
+ } from "./types.js";
12
12
  export {
13
13
  CURRENT_MAJOR,
14
14
  FORMAT_ID,
@@ -19,8 +19,8 @@ export {
19
19
  upgradeStory,
20
20
  type ParsedVersion,
21
21
  type StoryErrorCode,
22
- } from "./version";
23
- export { validate, type StoryIssue, type ValidationResult } from "./validate";
22
+ } from "./version.js";
23
+ export { validate, type StoryIssue, type ValidationResult } from "./validate.js";
24
24
  export {
25
25
  mediaBlob,
26
26
  readStoryZip,
@@ -28,7 +28,7 @@ export {
28
28
  writeStoryZip,
29
29
  type ReadLimits,
30
30
  type StoryPackage,
31
- } from "./zip";
31
+ } from "./zip.js";
32
32
  export {
33
33
  DEFAULT_MAX_EDGE,
34
34
  encodingCandidates,
@@ -37,4 +37,4 @@ export {
37
37
  type ImagePurpose,
38
38
  type OptimizedImage,
39
39
  type OptimizeOptions,
40
- } from "./image";
40
+ } from "./image.js";
@@ -4,12 +4,12 @@
4
4
  export {
5
5
  addToSession, assembleForSaving, lockPart, prepareForEditing,
6
6
  type EditableGeometry, type EditablePart, type EditMode, type EditSession, type SavedPart,
7
- } from "./model";
7
+ } from "./model.js";
8
8
  export {
9
9
  IMAGE_OVERLAY_PROPERTY, isKmlLine, isKmlRegion, lineCoordsOf, mapItemToGeoJson, MEDIA_HANDLE_PREFIX, overlaySourceOfText,
10
10
  parseMapFile, polygonRingsOf, SOURCE_PROPERTY, type ImageOverlay,
11
- } from "./mapFile";
11
+ } from "./mapFile.js";
12
12
  export {
13
13
  cornersFromBox, kmlBounds, kmlCenter, kmlOverlayBounds, kmlOverlayCenter, mercatorBearing, mercatorDistance, rotatePoint,
14
14
  scalePoint, unionBounds, type OverlayCorners,
15
- } from "./geometry";
15
+ } from "./geometry.js";
@@ -13,7 +13,7 @@
13
13
  // @tmcw/togeojson's GPX/KML readers put them.
14
14
  import type { Feature, FeatureCollection, GeoJsonObject, Geometry, Position } from "geojson";
15
15
  import { gpx, kml } from "@tmcw/togeojson";
16
- import type { OverlayCorners } from "./geometry";
16
+ import type { OverlayCorners } from "./geometry.js";
17
17
 
18
18
  /** An image overlay's picture, as a Media handle behind this marker (not a
19
19
  * real URL: an app-internal reference, since a resolvable link would need
@@ -10,11 +10,11 @@ import * as maplibregl from "maplibre-gl";
10
10
  import "maplibre-gl/dist/maplibre-gl.css";
11
11
  import type { GeoJSONSource, Map as MapLibreMap, Marker as MapLibreMarker } from "maplibre-gl";
12
12
  import type { FeatureCollection, GeoJSON } from "geojson";
13
- import type { Overlay, Place } from "../types";
14
- import { dateCoversYear } from "./dates";
15
- import { placeBounds, placeCenter, type StoryPlaces } from "./geo";
16
- import { applyOhmYear, crossfadeStyleSwap, mapStyleKey, mapStyleUrl } from "./mapStyles";
17
- import { PIN_PATH_D, type PlayerColors } from "./theme";
13
+ import type { Overlay, Place } from "../types.js";
14
+ import { dateCoversYear } from "./dates.js";
15
+ import { placeBounds, placeCenter, type StoryPlaces } from "./geo.js";
16
+ import { applyOhmYear, crossfadeStyleSwap, mapStyleKey, mapStyleUrl } from "./mapStyles.js";
17
+ import { PIN_PATH_D, type PlayerColors } from "./theme.js";
18
18
 
19
19
  const SHAPE_SOURCE = "story-shape";
20
20
  const FILL_LAYER = "story-shape-fill";
@@ -27,6 +27,16 @@ const PLACES_LAYER = "story-places-dots";
27
27
  // Room around the outermost dots of the opening view, inside the part of
28
28
  // the map the slide panel leaves free.
29
29
  const OVERVIEW_PADDING = 60;
30
+ // A place with only a point: far enough out to see where it is in its
31
+ // country (Le Havre with Paris and London in view), not just the town.
32
+ const POINT_ZOOM = 6;
33
+ // A shape or old map is framed, but never closer than a town and its
34
+ // surroundings, so readers can still tell where it is.
35
+ const SHAPE_MAX_ZOOM = 13;
36
+ const SHAPE_PADDING = 40;
37
+ // A "shape" with no size (a single point) is shown as a point; anything
38
+ // bigger, even a building, at the town zoom, where it can still be seen.
39
+ const MIN_SHAPE_DEGREES = 1e-5;
30
40
  const EMPTY: FeatureCollection = { type: "FeatureCollection", features: [] };
31
41
 
32
42
  /** The current slide, as far as the map cares. `key` is the slide id:
@@ -40,8 +50,8 @@ export interface MapSlide {
40
50
  }
41
51
 
42
52
  /** Frame the story's places for an overview; else the place's shape or
43
- * overlays (usually a field, a route or an old map, far tighter than a
44
- * town-level zoom); else fly to its point. */
53
+ * overlays (a parish, a route or an old map), no closer than a town;
54
+ * else fly to its point, at a regional zoom. */
45
55
  function moveCamera(map: MapLibreMap, slide: MapSlide, duration: number) {
46
56
  if (slide.overview) {
47
57
  const [west, south, east, north] = slide.overview.bounds;
@@ -50,12 +60,12 @@ function moveCamera(map: MapLibreMap, slide: MapSlide, duration: number) {
50
60
  }
51
61
  const place = slide.place;
52
62
  const bounds = placeBounds(place);
53
- if (bounds) {
54
- map.fitBounds([[bounds[0], bounds[1]], [bounds[2], bounds[3]]], { maxZoom: 17, duration });
63
+ if (bounds && Math.max(bounds[2] - bounds[0], bounds[3] - bounds[1]) >= MIN_SHAPE_DEGREES) {
64
+ map.fitBounds([[bounds[0], bounds[1]], [bounds[2], bounds[3]]], { maxZoom: SHAPE_MAX_ZOOM, padding: SHAPE_PADDING, duration });
55
65
  return;
56
66
  }
57
67
  const center = placeCenter(place);
58
- if (center) map.flyTo({ center, zoom: 9, essential: true, duration });
68
+ if (center) map.flyTo({ center, zoom: POINT_ZOOM, essential: true, duration });
59
69
  }
60
70
 
61
71
  /** The pin on the place; hidden for an overview (the dots stand in for
@@ -1,8 +1,8 @@
1
1
  // The Auto / Standard / Historical map picker, in plain HTML. A host app
2
2
  // with its own UI kit can supply its own control instead (StoryPlayer's
3
3
  // renderMapModeControl), taking the same props.
4
- import type { PlayerStrings } from "./strings";
5
- import type { PlayerColors } from "./theme";
4
+ import type { PlayerStrings } from "./strings.js";
5
+ import type { PlayerColors } from "./theme.js";
6
6
 
7
7
  /** "standard" is today's map; "historical" a map of the year the viewer
8
8
  * picks; "auto" a map of each slide's own year as the story moves. */
@@ -4,20 +4,24 @@
4
4
  // when two or more slides are dated. Fills its container; the host decides
5
5
  // whether that's a fullscreen modal, a page, or a box on a blog.
6
6
  import { useEffect, useMemo, useRef, useState, type CSSProperties, type ReactNode, type TouchEvent } from "react";
7
- import type { MediaItem, Slide, StoryDoc } from "../types";
8
- import { timelineYear } from "./dates";
9
- import { placeCenter, storyPlaces } from "./geo";
10
- import { MapBackground, type MapSlide } from "./MapBackground";
11
- import { MapModeControl, type MapMode, type MapModeControlProps } from "./MapModeControl";
12
- import { parseStoryText } from "./text";
13
- import { stringsFor, type PlayerStrings } from "./strings";
14
- import { defaultColors, type PlayerColors } from "./theme";
15
- import { TIMELINE_HEIGHT, TimelineStrip, type TimelinePoint } from "./TimelineStrip";
7
+ import type { MediaItem, Slide, StoryDoc } from "../types.js";
8
+ import { timelineYear } from "./dates.js";
9
+ import { placeCenter, storyPlaces } from "./geo.js";
10
+ import { MapBackground, type MapSlide } from "./MapBackground.js";
11
+ import { MapModeControl, type MapMode, type MapModeControlProps } from "./MapModeControl.js";
12
+ import { parseStoryText } from "./text.js";
13
+ import { stringsFor, type PlayerStrings } from "./strings.js";
14
+ import { defaultColors, type PlayerColors } from "./theme.js";
15
+ import { TIMELINE_HEIGHT, TimelineStrip, type TimelinePoint } from "./TimelineStrip.js";
16
16
 
17
17
  /** How much of the width the slide panel takes over a map; the map
18
18
  * centers each point in what's left. */
19
19
  const PANEL_FRACTION = 0.62;
20
20
  const BAR_HEIGHT = 56;
21
+ /** Space kept between the map-mode switch and the title or buttons beside it. */
22
+ const BAR_GAP = 8;
23
+ /** The map-mode switch's own row under the bar, when the bar has no room for it. */
24
+ const MODE_ROW_HEIGHT = 40;
21
25
 
22
26
  export interface StoryPlayerProps {
23
27
  story: StoryDoc;
@@ -107,7 +111,10 @@ function SlidePhoto({ mediaKey, item, caption, credit, resolveMedia, colors }: {
107
111
  />
108
112
  {(caption || credit) && (
109
113
  <figcaption style={{ fontSize: 13, color: colors.muted }}>
110
- {[caption, credit && `© ${credit}`].filter(Boolean).join(" · ")}
114
+ {/* The credit as written: a "©" would be wrong for public-domain
115
+ and freely licensed images, which need their licence named
116
+ instead. */}
117
+ {[caption, credit].filter(Boolean).join(" · ")}
111
118
  </figcaption>
112
119
  )}
113
120
  </figure>
@@ -265,6 +272,33 @@ export function StoryPlayer({
265
272
  [story.language, stringOverrides],
266
273
  );
267
274
  const rootRef = useRef<HTMLDivElement>(null);
275
+ const titleRef = useRef<HTMLDivElement>(null);
276
+ const modeRef = useRef<HTMLDivElement>(null);
277
+ const actionsRef = useRef<HTMLDivElement>(null);
278
+ // The map-mode switch is centered on the title bar; when it would run
279
+ // into the title or the buttons on the right (a phone, or a host with
280
+ // several actions), it gets a row of its own just under the bar.
281
+ const [modeBelowBar, setModeBelowBar] = useState(false);
282
+ useEffect(() => {
283
+ const root = rootRef.current;
284
+ if (!root || typeof ResizeObserver === "undefined") return;
285
+ const check = () => {
286
+ const mode = modeRef.current;
287
+ if (!mode) return;
288
+ const rootBox = root.getBoundingClientRect();
289
+ const half = mode.offsetWidth / 2;
290
+ const center = rootBox.width / 2;
291
+ // Edges measured from the bar's own left; none of them depends on
292
+ // where the switch is, so moving it can't change the answer.
293
+ const titleRight = titleRef.current ? titleRef.current.getBoundingClientRect().right - rootBox.left : 0;
294
+ const actionsLeft = actionsRef.current ? actionsRef.current.getBoundingClientRect().left - rootBox.left : rootBox.width - 60;
295
+ setModeBelowBar(center - half < titleRight + BAR_GAP || center + half > actionsLeft - BAR_GAP);
296
+ };
297
+ const observer = new ResizeObserver(check);
298
+ for (const el of [root, titleRef.current, modeRef.current, actionsRef.current]) if (el) observer.observe(el);
299
+ check();
300
+ return () => observer.disconnect();
301
+ }, [story, Boolean(actions), Boolean(onClose)]);
268
302
  const slides = story.slides;
269
303
  const [index, setIndex] = useState(initialSlide);
270
304
  const slide = slides[index];
@@ -401,6 +435,7 @@ export function StoryPlayer({
401
435
  }}
402
436
  />
403
437
  <div
438
+ ref={titleRef}
404
439
  dir="auto"
405
440
  style={{
406
441
  position: "absolute", top: 0, left: 20, height: BAR_HEIGHT, maxWidth: "26%", zIndex: 3,
@@ -415,11 +450,11 @@ export function StoryPlayer({
415
450
  {firstCenter && (
416
451
  <div
417
452
  style={{
418
- position: "absolute", top: 0, left: 0, right: 0, height: BAR_HEIGHT, zIndex: 3,
453
+ position: "absolute", top: modeBelowBar ? BAR_HEIGHT : 0, left: 0, right: 0, height: modeBelowBar ? MODE_ROW_HEIGHT : BAR_HEIGHT, zIndex: 3,
419
454
  display: "flex", alignItems: "center", justifyContent: "center", pointerEvents: "none",
420
455
  }}
421
456
  >
422
- <div style={{ pointerEvents: "auto" }}>
457
+ <div ref={modeRef} style={{ pointerEvents: "auto" }}>
423
458
  {renderMapModeControl
424
459
  ? renderMapModeControl(modeControlProps)
425
460
  : <MapModeControl {...modeControlProps} strings={strings} colors={colors} />}
@@ -428,6 +463,7 @@ export function StoryPlayer({
428
463
  )}
429
464
  {actions && (
430
465
  <div
466
+ ref={actionsRef}
431
467
  style={{
432
468
  position: "absolute", top: 0, right: onClose ? 60 : 12, height: BAR_HEIGHT, zIndex: 3,
433
469
  display: "flex", alignItems: "center", gap: 8,
@@ -459,7 +495,8 @@ export function StoryPlayer({
459
495
  <div
460
496
  style={{
461
497
  position: "absolute", top: 0, bottom: 0, right: 0, width: `${PANEL_FRACTION * 100}%`, zIndex: 1,
462
- padding: `${BAR_HEIGHT}px 32px ${showTimeline ? TIMELINE_HEIGHT : 32}px`, boxSizing: "border-box",
498
+ // Below the map-mode switch too, when it has a row of its own.
499
+ padding: `${BAR_HEIGHT + (modeBelowBar ? MODE_ROW_HEIGHT : 0)}px 32px ${showTimeline ? TIMELINE_HEIGHT : 32}px`, boxSizing: "border-box",
463
500
  display: "flex", flexDirection: "column", justifyContent: "center", alignItems: "center", gap: 16,
464
501
  overflowY: "auto",
465
502
  // Transparent where the panel starts, mid-screen, and solid
@@ -2,8 +2,8 @@
2
2
  // the story's dated slides, with click-to-jump per dot. SVG, since a story
3
3
  // has at most a few dozen dated slides and SVG rescales for free.
4
4
  import { useEffect, useRef, useState } from "react";
5
- import { axisTicks, storyDomain, tickLabel, xForYear } from "./timelineLayout";
6
- import { PIN_PATH_D, type PlayerColors } from "./theme";
5
+ import { axisTicks, storyDomain, tickLabel, xForYear } from "./timelineLayout.js";
6
+ import { PIN_PATH_D, type PlayerColors } from "./theme.js";
7
7
 
8
8
  export const TIMELINE_HEIGHT = 70;
9
9
  const MARGIN = 28;
@@ -1,7 +1,7 @@
1
1
  // What the player needs from a story's dates: which years an EDTF value
2
2
  // covers (to show a historical map overlay only in its own era), and a
3
3
  // position on the timeline finer than a whole year when the date allows.
4
- import type { StoryDate } from "../types";
4
+ import type { StoryDate } from "../types.js";
5
5
 
6
6
  export interface YearRange {
7
7
  /** Undefined for an open start ("../1850"). */
package/src/player/geo.ts CHANGED
@@ -1,6 +1,6 @@
1
1
  // Where a slide is on the map: its point, or the box around its shape and
2
2
  // overlays -- pure geometry, no map library.
3
- import type { LonLat, Place } from "../types";
3
+ import type { LonLat, Place } from "../types.js";
4
4
 
5
5
  export type Bounds = [west: number, south: number, east: number, north: number];
6
6
 
@@ -1,12 +1,12 @@
1
- export { StoryPlayer, type StoryPlayerProps } from "./StoryPlayer";
2
- export { VIEWER_NAME, VIEWER_URL, ViewerBrand, ViewerIcon, type ViewerBrandProps } from "./brand";
3
- export { MapModeControl, type MapMode, type MapModeControlProps } from "./MapModeControl";
4
- export { defaultColors, PIN_PATH_D, type PlayerColors } from "./theme";
5
- export { ENGLISH, PLAYER_LANGUAGES, stringsFor, type PlayerStrings } from "./strings";
6
- export { parseStoryText, type ParsedText, type TextSpan } from "./text";
7
- export { dateCoversYear, edtfYearRange, timelineYear, type YearRange } from "./dates";
8
- export { placeBounds, placeCenter, type Bounds } from "./geo";
9
- export { axisTicks, storyDomain, tickLabel, xForYear, type AxisTick } from "./timelineLayout";
1
+ export { StoryPlayer, type StoryPlayerProps } from "./StoryPlayer.js";
2
+ export { VIEWER_NAME, VIEWER_URL, ViewerBrand, ViewerIcon, type ViewerBrandProps } from "./brand.js";
3
+ export { MapModeControl, type MapMode, type MapModeControlProps } from "./MapModeControl.js";
4
+ export { defaultColors, PIN_PATH_D, type PlayerColors } from "./theme.js";
5
+ export { ENGLISH, PLAYER_LANGUAGES, stringsFor, type PlayerStrings } from "./strings.js";
6
+ export { parseStoryText, type ParsedText, type TextSpan } from "./text.js";
7
+ export { dateCoversYear, edtfYearRange, timelineYear, type YearRange } from "./dates.js";
8
+ export { placeBounds, placeCenter, type Bounds } from "./geo.js";
9
+ export { axisTicks, storyDomain, tickLabel, xForYear, type AxisTick } from "./timelineLayout.js";
10
10
  export {
11
11
  applyOhmYear, crossfadeStyleSwap, mapStyleKey, mapStyleUrl, OHM_STYLE, STYLE_DARK, STYLE_LIGHT,
12
- } from "./mapStyles";
12
+ } from "./mapStyles.js";
package/src/validate.ts CHANGED
@@ -4,8 +4,8 @@
4
4
  // schema can't express (spec/1.0/README.md section 8).
5
5
  import schema from "../spec/1.0/story.schema.json" with { type: "json" };
6
6
  import { validate as schemaValidate } from "./generated/schemaValidator.js";
7
- import { CURRENT_MAJOR, parseVersion } from "./version";
8
- import type { StoryDoc } from "./types";
7
+ import { CURRENT_MAJOR, parseVersion } from "./version.js";
8
+ import type { StoryDoc } from "./types.js";
9
9
 
10
10
  /** Minor version of the schema bundled here: unknown fields in a file of
11
11
  * this minor version or older are probably typos, not newer features. */
package/src/version.ts CHANGED
@@ -1,7 +1,7 @@
1
1
  // Format identity and versioning (spec/1.0/README.md section 2), and the
2
2
  // chain of upgraders that lets this package keep opening every older major
3
3
  // version of the format.
4
- import type { StoryDoc } from "./types";
4
+ import type { StoryDoc } from "./types.js";
5
5
 
6
6
  export const FORMAT_ID = "gramps-connect-story";
7
7
 
package/src/zip.ts CHANGED
@@ -2,9 +2,9 @@
2
2
  // sections 1 and 5). A zip handed to readStoryZip() may come from anyone,
3
3
  // so reading caps how much it will inflate before looking at any of it.
4
4
  import { unzip, zip, type AsyncZippable, type UnzipFileInfo } from "fflate";
5
- import { FORMAT_ID, FORMAT_VERSION, StoryFormatError, upgradeStory } from "./version";
6
- import { validate, type StoryIssue } from "./validate";
7
- import type { MediaItem, StoryDoc } from "./types";
5
+ import { FORMAT_ID, FORMAT_VERSION, StoryFormatError, upgradeStory } from "./version.js";
6
+ import { validate, type StoryIssue } from "./validate.js";
7
+ import type { MediaItem, StoryDoc } from "./types.js";
8
8
 
9
9
  export interface StoryPackage {
10
10
  doc: StoryDoc;