@segnavia/format 0.10.0 → 0.11.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.
@@ -27,6 +27,7 @@ export declare function boardBounds(board: Board, shapes: BoardShapes): Box;
27
27
  export declare function boardToScreen(view: BoardView, point: Point): Point;
28
28
  export declare function screenToBoard(view: BoardView, point: Point): Point;
29
29
  export declare function zoomToFit(bounds: Box, viewport: Size, padding: number): BoardView;
30
+ export declare function revealView(bounds: Box, viewport: Size, padding: number, options?: ZoomBounds): BoardView;
30
31
  export declare function zoomAt(view: BoardView, point: Point, factor: number, options?: ZoomBounds): BoardView;
31
32
  export declare function visibleItems(board: Board, shapes: BoardShapes, view: BoardView, margin: number): BoardItem[];
32
33
  export declare function itemAt(board: Board, shapes: BoardShapes, point: Point): BoardItem | undefined;
@@ -83,6 +83,21 @@ function zoomToFit(bounds, viewport, padding) {
83
83
  viewport
84
84
  };
85
85
  }
86
+ function revealView(bounds, viewport, padding, options = {}) {
87
+ const fitted = zoomToFit(bounds, viewport, padding);
88
+ const minZoom = options.minZoom ?? .05;
89
+ const maxZoom = options.maxZoom ?? 8;
90
+ if (!(minZoom > 0 && maxZoom >= minZoom)) throw new Error("zoom bounds are invalid; provide a positive minZoom no greater than maxZoom");
91
+ const zoom = Math.min(maxZoom, Math.max(minZoom, fitted.zoom));
92
+ return {
93
+ zoom,
94
+ pan: {
95
+ x: viewport.width / 2 - (bounds.x + bounds.width / 2) * zoom,
96
+ y: viewport.height / 2 - (bounds.y + bounds.height / 2) * zoom
97
+ },
98
+ viewport
99
+ };
100
+ }
86
101
  function zoomAt(view, point, factor, options = {}) {
87
102
  requireView(view);
88
103
  if (!(factor > 0)) throw new Error(`zoom factor is ${factor}; provide a factor greater than zero`);
@@ -181,4 +196,4 @@ function arrange(board, shapes, options) {
181
196
  };
182
197
  }
183
198
  //#endregion
184
- export { MAX_BOARD_ZOOM, MIN_BOARD_ZOOM, arrange, boardBounds, boardToScreen, itemAt, itemHeight, screenToBoard, visibleItems, zoomAt, zoomToFit };
199
+ export { MAX_BOARD_ZOOM, MIN_BOARD_ZOOM, arrange, boardBounds, boardToScreen, itemAt, itemHeight, revealView, screenToBoard, visibleItems, zoomAt, zoomToFit };
@@ -0,0 +1,15 @@
1
+ import { Board, BoardItem, BoardSection } from "./board.js";
2
+ //#region src/board-listing.d.ts
3
+ export type BoardListingGroup = {
4
+ kind: 'section';
5
+ section: BoardSection;
6
+ items: BoardItem[];
7
+ } | {
8
+ kind: 'loose';
9
+ items: BoardItem[];
10
+ };
11
+ export declare function foldForSearch(text: string): string;
12
+ export declare function nameMatches(name: string, query: string): boolean;
13
+ export declare function boardListingIsEmpty(query: string, groups: BoardListingGroup[]): boolean;
14
+ export declare function boardListing(board: Board, nameOf: (item: BoardItem) => string, query: string, contentMatches?: Iterable<string>): BoardListingGroup[];
15
+ //#endregion
@@ -0,0 +1,47 @@
1
+ //#region src/board-listing.ts
2
+ const FINAL_LETTERS = {
3
+ ך: "כ",
4
+ ם: "מ",
5
+ ן: "נ",
6
+ ף: "פ",
7
+ ץ: "צ"
8
+ };
9
+ function foldForSearch(text) {
10
+ return text.normalize("NFD").replace(/\p{M}/gu, "").replace(/[ךםןףץ]/g, (letter) => FINAL_LETTERS[letter] ?? letter).toLowerCase().trim().replace(/\s+/g, " ");
11
+ }
12
+ function nameMatches(name, query) {
13
+ return foldForSearch(name).includes(foldForSearch(query));
14
+ }
15
+ function boardListingIsEmpty(query, groups) {
16
+ return foldForSearch(query).length > 0 && groups.length === 0;
17
+ }
18
+ function boardListing(board, nameOf, query, contentMatches = []) {
19
+ const folded = foldForSearch(query);
20
+ const byId = new Map(board.items.map((item) => [item.id, item]));
21
+ const content = new Set(contentMatches);
22
+ const claimed = /* @__PURE__ */ new Set();
23
+ const groups = [];
24
+ for (const section of board.sections) {
25
+ const members = section.items.flatMap((id) => {
26
+ if (claimed.has(id)) return [];
27
+ claimed.add(id);
28
+ const item = byId.get(id);
29
+ return item ? [item] : [];
30
+ });
31
+ const items = !folded || nameMatches(section.title, folded) ? members : members.filter((item) => nameMatches(nameOf(item), folded) || content.has(item.id));
32
+ if (!folded || items.length > 0) groups.push({
33
+ kind: "section",
34
+ section,
35
+ items
36
+ });
37
+ }
38
+ const loose = board.items.filter((item) => !claimed.has(item.id));
39
+ const visibleLoose = folded ? loose.filter((item) => nameMatches(nameOf(item), folded) || content.has(item.id)) : loose;
40
+ if (visibleLoose.length > 0) groups.push({
41
+ kind: "loose",
42
+ items: visibleLoose
43
+ });
44
+ return groups;
45
+ }
46
+ //#endregion
47
+ export { boardListing, boardListingIsEmpty, foldForSearch, nameMatches };
package/dist/index.d.ts CHANGED
@@ -1,6 +1,7 @@
1
1
  import { Board, BoardInput, BoardItem, BoardLabel, BoardSection } from "./board.js";
2
2
  import { Annotation, Box, Cue, DECK_SIZE, Deck, DeckInput, DeckLimits, ImageFit, Manifest, Narration, Point, PublishedShot, SHOT_KEY, Shot, Size, Slide, SlideContent, Word, annotationCueIssues, exceedsLimits } from "./deck.js";
3
- import { ArrangeOptions, BoardShapes, BoardView, MAX_BOARD_ZOOM, MIN_BOARD_ZOOM, ZoomBounds, arrange, boardBounds, boardToScreen, itemAt, itemHeight, screenToBoard, visibleItems, zoomAt, zoomToFit } from "./board-geometry.js";
3
+ import { ArrangeOptions, BoardShapes, BoardView, MAX_BOARD_ZOOM, MIN_BOARD_ZOOM, ZoomBounds, arrange, boardBounds, boardToScreen, itemAt, itemHeight, revealView, screenToBoard, visibleItems, zoomAt, zoomToFit } from "./board-geometry.js";
4
+ import { BoardListingGroup, boardListing, boardListingIsEmpty, foldForSearch, nameMatches } from "./board-listing.js";
4
5
  import { Book, BookContents, BookFrontMatterEntry, BookInput, BookMode, BookPage, BookSection, BookView, BookViewInput, Chapter, isBookContents, isHebrew, noteMarkerIssues } from "./book.js";
5
6
  import { DeckFromSlidesOptions, SlideRow, deckFromSlides } from "./deck-from-slides.js";
6
7
  import { Direction, TextDirection, firstStrongDirection, languageDirection, resolveDirection } from "./direction.js";
@@ -719,4 +720,4 @@ export declare function jsonSchemas(): {
719
720
  }, z.core.$strip>>;
720
721
  };
721
722
  //#endregion
722
- export { Annotation, type ArrangeOptions, Board, type BoardInput, BoardItem, BoardLabel, BoardSection, type BoardShapes, type BoardView, Book, BookContents, BookFrontMatterEntry, type BookInput, BookMode, BookPage, BookSection, BookView, type BookViewInput, Box, Chapter, Cue, DECK_SIZE, DEFAULT_TRANSITION_DURATION_MS, Deck, type DeckFromSlidesOptions, type DeckInput, type DeckLimits, Direction, ImageFit, type Imposed, Lexicon, MARK_GAP_MM, MARK_LENGTH_MM, MAX_BOARD_ZOOM, MAX_SLIDE_TIMING_MS, MAX_TRANSITION_DURATION_MS, MIN_BOARD_ZOOM, MIN_TRANSITION_DURATION_MS, MM_PER_PT, Manifest, type MillimeterEdges, NAMED_PAPERS, Narration, NoteMarker, NumberSystem, PAPER_MM, PX_PER_MM, type PageFit, type PagePlacementKind, type PagePlacementLayout, Paper, type PaperBox, type Placement, Point, PronunciationEntry, PublishedShot, SHOT_KEY, Scripts, Shot, type ShotUse, Size, Slide, SlideContent, type SlideRow, TextDirection, Transition, TransitionInput, Word, type ZoomBounds, annotationCueIssues, arrange, boardBounds, boardToScreen, deckFromSlides, exceedsLimits, firstStrongDirection, fitPage, formatNumber, impose, isBookContents, isHebrew, itemAt, itemHeight, languageDirection, lexiconVersion, mirrorPlacement, noteMarker, noteMarkerIssues, pagePlacementLayout, printBoxes, printPadding, printProperties, resolveDirection, roundMillimeters, screenToBoard, sheetMm, shotsUsed, toMillimeters, visibleItems, zoomAt, zoomToFit };
723
+ export { Annotation, type ArrangeOptions, Board, type BoardInput, BoardItem, BoardLabel, type BoardListingGroup, BoardSection, type BoardShapes, type BoardView, Book, BookContents, BookFrontMatterEntry, type BookInput, BookMode, BookPage, BookSection, BookView, type BookViewInput, Box, Chapter, Cue, DECK_SIZE, DEFAULT_TRANSITION_DURATION_MS, Deck, type DeckFromSlidesOptions, type DeckInput, type DeckLimits, Direction, ImageFit, type Imposed, Lexicon, MARK_GAP_MM, MARK_LENGTH_MM, MAX_BOARD_ZOOM, MAX_SLIDE_TIMING_MS, MAX_TRANSITION_DURATION_MS, MIN_BOARD_ZOOM, MIN_TRANSITION_DURATION_MS, MM_PER_PT, Manifest, type MillimeterEdges, NAMED_PAPERS, Narration, NoteMarker, NumberSystem, PAPER_MM, PX_PER_MM, type PageFit, type PagePlacementKind, type PagePlacementLayout, Paper, type PaperBox, type Placement, Point, PronunciationEntry, PublishedShot, SHOT_KEY, Scripts, Shot, type ShotUse, Size, Slide, SlideContent, type SlideRow, TextDirection, Transition, TransitionInput, Word, type ZoomBounds, annotationCueIssues, arrange, boardBounds, boardListing, boardListingIsEmpty, boardToScreen, deckFromSlides, exceedsLimits, firstStrongDirection, fitPage, foldForSearch, formatNumber, impose, isBookContents, isHebrew, itemAt, itemHeight, languageDirection, lexiconVersion, mirrorPlacement, nameMatches, noteMarker, noteMarkerIssues, pagePlacementLayout, printBoxes, printPadding, printProperties, resolveDirection, revealView, roundMillimeters, screenToBoard, sheetMm, shotsUsed, toMillimeters, visibleItems, zoomAt, zoomToFit };
package/dist/index.js CHANGED
@@ -8,7 +8,8 @@ import { NoteMarker, NumberSystem, formatNumber, noteMarker } from "./numbering.
8
8
  import { MARK_GAP_MM, MARK_LENGTH_MM, MM_PER_PT, NAMED_PAPERS, PAPER_MM, PX_PER_MM, Paper, printBoxes, printPadding, printProperties, roundMillimeters, sheetMm, toMillimeters } from "./paper.js";
9
9
  import { Book, BookContents, BookFrontMatterEntry, BookMode, BookPage, BookSection, BookShape, BookView, Chapter, isBookContents, isHebrew, noteMarkerIssues } from "./book.js";
10
10
  import { Lexicon, PronunciationEntry, lexiconVersion } from "./lexicon.js";
11
- import { MAX_BOARD_ZOOM, MIN_BOARD_ZOOM, arrange, boardBounds, boardToScreen, itemAt, itemHeight, screenToBoard, visibleItems, zoomAt, zoomToFit } from "./board-geometry.js";
11
+ import { MAX_BOARD_ZOOM, MIN_BOARD_ZOOM, arrange, boardBounds, boardToScreen, itemAt, itemHeight, revealView, screenToBoard, visibleItems, zoomAt, zoomToFit } from "./board-geometry.js";
12
+ import { boardListing, boardListingIsEmpty, foldForSearch, nameMatches } from "./board-listing.js";
12
13
  import { deckFromSlides } from "./deck-from-slides.js";
13
14
  import { fitPage, impose, mirrorPlacement, pagePlacementLayout } from "./imposition.js";
14
15
  import { shotsUsed } from "./shots-used.js";
@@ -154,4 +155,4 @@ function jsonSchemas() {
154
155
  };
155
156
  }
156
157
  //#endregion
157
- export { Annotation, Board, BoardItem, BoardLabel, BoardSection, Book, BookContents, BookFrontMatterEntry, BookMode, BookPage, BookSection, BookView, Box, Chapter, Cue, DECK_SIZE, DEFAULT_TRANSITION_DURATION_MS, Deck, Direction, ImageFit, Imposition, Lexicon, MARK_GAP_MM, MARK_LENGTH_MM, MAX_BOARD_ZOOM, MAX_IMPOSITION_CELLS, MAX_SLIDE_TIMING_MS, MAX_TRANSITION_DURATION_MS, MIN_BOARD_ZOOM, MIN_TRANSITION_DURATION_MS, MM_PER_PT, Manifest, Margin, NAMED_PAPERS, Narration, NoteMarker, NumberSystem, PAPER_MM, PX_PER_MM, Page, PageSize, Paper, Point, Print, PronunciationEntry, PublishedShot, SHOT_KEY, Scripts, Shot, Size, Slide, SlideContent, TextDirection, Transition, Word, annotationCueIssues, arrange, boardBounds, boardToScreen, deckFromSlides, exceedsLimits, firstStrongDirection, fitPage, formatNumber, impose, isBookContents, isHebrew, itemAt, itemHeight, jsonSchemas, languageDirection, lexiconVersion, mirrorPlacement, noteMarker, noteMarkerIssues, pagePlacementLayout, printBoxes, printPadding, printProperties, resolveDirection, roundMillimeters, screenToBoard, sheetMm, shotsUsed, toMillimeters, visibleItems, zoomAt, zoomToFit };
158
+ export { Annotation, Board, BoardItem, BoardLabel, BoardSection, Book, BookContents, BookFrontMatterEntry, BookMode, BookPage, BookSection, BookView, Box, Chapter, Cue, DECK_SIZE, DEFAULT_TRANSITION_DURATION_MS, Deck, Direction, ImageFit, Imposition, Lexicon, MARK_GAP_MM, MARK_LENGTH_MM, MAX_BOARD_ZOOM, MAX_IMPOSITION_CELLS, MAX_SLIDE_TIMING_MS, MAX_TRANSITION_DURATION_MS, MIN_BOARD_ZOOM, MIN_TRANSITION_DURATION_MS, MM_PER_PT, Manifest, Margin, NAMED_PAPERS, Narration, NoteMarker, NumberSystem, PAPER_MM, PX_PER_MM, Page, PageSize, Paper, Point, Print, PronunciationEntry, PublishedShot, SHOT_KEY, Scripts, Shot, Size, Slide, SlideContent, TextDirection, Transition, Word, annotationCueIssues, arrange, boardBounds, boardListing, boardListingIsEmpty, boardToScreen, deckFromSlides, exceedsLimits, firstStrongDirection, fitPage, foldForSearch, formatNumber, impose, isBookContents, isHebrew, itemAt, itemHeight, jsonSchemas, languageDirection, lexiconVersion, mirrorPlacement, nameMatches, noteMarker, noteMarkerIssues, pagePlacementLayout, printBoxes, printPadding, printProperties, resolveDirection, revealView, roundMillimeters, screenToBoard, sheetMm, shotsUsed, toMillimeters, visibleItems, zoomAt, zoomToFit };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@segnavia/format",
3
- "version": "0.10.0",
3
+ "version": "0.11.0",
4
4
  "type": "module",
5
5
  "license": "MIT",
6
6
  "repository": {