@widgetic/canvas 0.5.44 → 0.5.45

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 (160) hide show
  1. package/dist/canvas/DomCanvas.svelte +52 -3
  2. package/dist/canvas/DomCanvas.svelte.d.ts +59 -34
  3. package/dist/canvas/autosaveScheduler.js +89 -37
  4. package/dist/canvas/boardFrame.js +1 -1
  5. package/dist/canvas/boardSurface.js +1 -1
  6. package/dist/canvas/canvasLogger.js +19 -7
  7. package/dist/canvas/chromeLayout.js +21 -19
  8. package/dist/canvas/eventScope.js +14 -10
  9. package/dist/canvas/host/CanvasHost.d.ts +68 -1
  10. package/dist/canvas/host/CanvasHost.js +1901 -1407
  11. package/dist/canvas/host/CanvasHostApi.d.ts +2 -2
  12. package/dist/canvas/host/CanvasHostApi.js +28 -5
  13. package/dist/canvas/host/boardFiles.d.ts +90 -0
  14. package/dist/canvas/host/boardFiles.js +155 -0
  15. package/dist/canvas/host/browserServices.d.ts +17 -0
  16. package/dist/canvas/host/browserServices.js +211 -65
  17. package/dist/canvas/host/conversion.js +170 -82
  18. package/dist/canvas/host/hostObject.js +7 -7
  19. package/dist/canvas/host/nearCards.js +21 -18
  20. package/dist/canvas/host/pageEvents.js +5 -5
  21. package/dist/canvas/host/pictureSaves.js +11 -9
  22. package/dist/canvas/host/screenRects.js +31 -28
  23. package/dist/canvas/host/storedPictures.js +243 -149
  24. package/dist/canvas/host/strokeSnap.js +143 -88
  25. package/dist/canvas/index.d.ts +1 -0
  26. package/dist/canvas/openMarks.js +2 -2
  27. package/dist/canvas/outsideClickDeselect.js +7 -6
  28. package/dist/canvas/panZoomPosition.js +2 -2
  29. package/dist/canvas/preferredTextFont.js +25 -13
  30. package/dist/canvas/shapes/ShapeLibrary.js +148 -138
  31. package/dist/canvas/shapes/shapeImageStore.js +4 -4
  32. package/dist/canvas/shapes/strokeShapeSnap.js +233 -188
  33. package/dist/canvas/toolbarPosition.js +2 -2
  34. package/dist/canvas/ui/CanvasContextMenu.svelte +7 -0
  35. package/dist/canvas/ui/CanvasToolbar.svelte +4 -1
  36. package/dist/canvas/ui/CanvasToolbar.svelte.d.ts +2 -0
  37. package/dist/canvas/ui/SelectionPanel.svelte +78 -17
  38. package/dist/canvas/ui/ShapesMenu.svelte +65 -31
  39. package/dist/canvas/ui/ShapesMenu.svelte.d.ts +2 -0
  40. package/dist/canvas/ui/ShortcutTooltip.svelte +64 -0
  41. package/dist/canvas/ui/ShortcutTooltip.svelte.d.ts +24 -0
  42. package/dist/canvas/ui/ToolButton.svelte +34 -55
  43. package/dist/canvas/ui/ToolButton.svelte.d.ts +4 -1
  44. package/dist/canvas/ui/colorModel.js +32 -21
  45. package/dist/canvas/ui/colorPickerMessages.js +5 -5
  46. package/dist/canvas/ui/floatingCard.d.ts +26 -4
  47. package/dist/canvas/ui/floatingCard.js +43 -21
  48. package/dist/canvas/ui/floatingLayer.js +6 -5
  49. package/dist/canvas/ui/icons.d.ts +1 -1
  50. package/dist/canvas/ui/icons.js +1 -1
  51. package/dist/canvas/ui/keyHints.js +11 -9
  52. package/dist/canvas/ui/popoverSide.js +3 -2
  53. package/dist/canvas/ui/selectionTraits.d.ts +12 -0
  54. package/dist/canvas/ui/selectionTraits.js +66 -35
  55. package/dist/canvas/ui/sizeLabelVisibility.d.ts +4 -2
  56. package/dist/canvas/ui/sizeLabelVisibility.js +5 -5
  57. package/dist/canvas/view/CanvasStage.svelte +7 -2
  58. package/dist/canvas/view/CanvasStage.svelte.d.ts +2 -0
  59. package/dist/canvas/view/SelectionOverlay.svelte +17 -10
  60. package/dist/canvas/view/WidgetChromeLayer.svelte +15 -3
  61. package/dist/canvas/view/erasingMarks.js +7 -7
  62. package/dist/canvas/view/geometry.d.ts +1 -1
  63. package/dist/canvas/view/geometry.js +90 -71
  64. package/dist/canvas/view/liftedScene.js +36 -24
  65. package/dist/canvas/view/mountedScene.js +79 -76
  66. package/dist/components/CanvasBoardPoster.svelte +206 -0
  67. package/dist/components/CanvasBoardPoster.svelte.d.ts +17 -0
  68. package/dist/components/CanvasToolbarPlaceholder.svelte +115 -0
  69. package/dist/components/CanvasToolbarPlaceholder.svelte.d.ts +9 -0
  70. package/dist/components/index.d.ts +7 -0
  71. package/dist/components/index.js +8 -0
  72. package/dist/components/preferenceStorage.js +2 -2
  73. package/dist/engine/EngineCore.d.ts +37 -2
  74. package/dist/engine/EngineCore.js +946 -768
  75. package/dist/engine/codec/canvasDocument.d.ts +7 -0
  76. package/dist/engine/codec/canvasDocument.js +172 -186
  77. package/dist/engine/codec/hostReadableKeys.js +1 -1
  78. package/dist/engine/core/arrange.js +38 -26
  79. package/dist/engine/core/arrow.d.ts +18 -8
  80. package/dist/engine/core/arrow.js +109 -84
  81. package/dist/engine/core/arrowBinding.d.ts +1 -1
  82. package/dist/engine/core/arrowBinding.js +126 -101
  83. package/dist/engine/core/arrowBindingRecords.d.ts +9 -3
  84. package/dist/engine/core/arrowBindingRecords.js +48 -29
  85. package/dist/engine/core/brush.d.ts +8 -0
  86. package/dist/engine/core/brush.js +98 -78
  87. package/dist/engine/core/cameraMove.d.ts +6 -0
  88. package/dist/engine/core/cameraMove.js +56 -38
  89. package/dist/engine/core/defaults.js +51 -90
  90. package/dist/engine/core/freehand.js +163 -147
  91. package/dist/engine/core/geometry.js +54 -47
  92. package/dist/engine/core/history.js +55 -38
  93. package/dist/engine/core/hitTest.js +81 -68
  94. package/dist/engine/core/matrix.js +20 -18
  95. package/dist/engine/core/pathData.js +210 -183
  96. package/dist/engine/core/rotationReset.js +6 -5
  97. package/dist/engine/core/scene.d.ts +22 -0
  98. package/dist/engine/core/scene.js +288 -139
  99. package/dist/engine/core/scribble.js +84 -59
  100. package/dist/engine/core/shapePaths.js +15 -12
  101. package/dist/engine/core/shapeTools.js +63 -72
  102. package/dist/engine/core/snapping.js +117 -65
  103. package/dist/engine/core/style.d.ts +10 -0
  104. package/dist/engine/core/style.js +82 -33
  105. package/dist/engine/core/transform.d.ts +6 -0
  106. package/dist/engine/core/transform.js +103 -83
  107. package/dist/engine/core/types.d.ts +7 -0
  108. package/dist/engine/core/types.js +4 -4
  109. package/dist/engine/core/viewport.js +36 -23
  110. package/dist/engine/input/PointerController.d.ts +15 -1
  111. package/dist/engine/input/PointerController.js +547 -476
  112. package/dist/engine/input/arrowHandles.js +12 -12
  113. package/dist/engine/input/gestures.d.ts +3 -1
  114. package/dist/engine/input/gestures.js +340 -266
  115. package/dist/engine/input/hoverCursor.js +1 -1
  116. package/dist/engine/input/keyboard.d.ts +22 -3
  117. package/dist/engine/input/keyboard.js +131 -32
  118. package/dist/engine/input/selectionHandles.js +50 -45
  119. package/dist/engine/input/types.d.ts +7 -0
  120. package/dist/engine/input/types.js +1 -1
  121. package/dist/engine/render/rasterize.js +158 -86
  122. package/dist/engine/state.d.ts +18 -0
  123. package/dist/engine/state.js +25 -4
  124. package/dist/engine/text/layoutText.js +62 -43
  125. package/dist/engine/text/textMetrics.js +10 -8
  126. package/dist/engine/widgets.js +137 -101
  127. package/dist/fonts/interFont.js +83 -30
  128. package/dist/fonts/workspaceFonts.d.ts +6 -0
  129. package/dist/fonts/workspaceFonts.js +108 -34
  130. package/dist/i18n/labels.js +4 -4
  131. package/dist/i18n/language.d.ts +3 -3
  132. package/dist/i18n/language.js +4 -4
  133. package/dist/i18n/messages.d.ts +6 -0
  134. package/dist/i18n/messages.js +7 -1
  135. package/dist/i18n/shortcuts.d.ts +6 -4
  136. package/dist/i18n/shortcuts.js +30 -26
  137. package/dist/index.d.ts +1 -0
  138. package/dist/poster/boardPlacement.d.ts +80 -0
  139. package/dist/poster/boardPlacement.js +140 -0
  140. package/dist/poster/boardPoster.d.ts +80 -0
  141. package/dist/poster/boardPoster.js +251 -0
  142. package/dist/poster/paintBoardPoster.d.ts +49 -0
  143. package/dist/poster/paintBoardPoster.js +112 -0
  144. package/dist/poster/posterPictures.d.ts +32 -0
  145. package/dist/poster/posterPictures.js +138 -0
  146. package/dist/settings/workspaceToolSettings.d.ts +6 -0
  147. package/dist/settings/workspaceToolSettings.js +58 -34
  148. package/dist/tools/components/catalog.js +74 -64
  149. package/dist/tools/components/grouping.js +28 -6
  150. package/dist/tools/definitions.js +31 -9
  151. package/dist/tools/executors.js +214 -106
  152. package/dist/tools/hostAdapter.d.ts +5 -1
  153. package/dist/tools/hostAdapter.js +15 -11
  154. package/dist/tools/sceneSummary.js +57 -43
  155. package/dist/tools/sketchIntent.js +21 -13
  156. package/dist/tools/styleArguments.d.ts +35 -0
  157. package/dist/tools/styleArguments.js +93 -0
  158. package/dist/tools/types.d.ts +26 -1
  159. package/dist/tools/types.js +2 -1
  160. package/package.json +1 -1
@@ -17,9 +17,9 @@ export declare const CANVAS_CONTRACT_FUNCTION_NAMES: readonly ["shapeFillColor",
17
17
  * (feat/shopify-feedback-canvas) adds the same one, so it keeps the name and the answer (how many objects went): removes
18
18
  * the sketch objects around one widget card and keeps the card.
19
19
  */
20
- export declare const CANVAS_ADDED_FUNCTION_NAMES: readonly ["removeSketchObjectsKeepingWidget", "getSketchSceneSummary", "executeSketchTool", "beginSketchToolBatch", "endSketchToolBatch", "flyToObjects", "flyToPoint", "flyToContent"];
20
+ export declare const CANVAS_ADDED_FUNCTION_NAMES: readonly ["removeSketchObjectsKeepingWidget", "getSketchSceneSummary", "executeSketchTool", "beginSketchToolBatch", "endSketchToolBatch", "flyToObjects", "flyToPoint", "flyToContent", "openFileBrowser", "insertPickedFiles", "getBoardPictures", "getLoadedBoardPictures", "setPictureLibraryFile"];
21
21
  /** Every function the shell exports. */
22
- export declare const CANVAS_EXPORTED_FUNCTION_NAMES: readonly ["shapeFillColor", "captureCanvasSketch", "absorbCanvasSketchIntoWidget", "deselectAll", "duplicateSelectedObjects", "deleteSelectedObjects", "markSelectedAsDuplicating", "linkObjectToWidget", "linkFrameToWidget", "replaceObjectWithWidgetImage", "updateWidgetImage", "selectWidgetShape", "listWidgetShapeScreenRects", "getWidgetShapeScreenRect", "getObjectScreenRect", "getWidgetShapeDataUrl", "setWidgetShapeLivePreviewHiddenImage", "addWidgetShape", "getLinkedWidgetIds", "keepOnlyWidgetShape", "hydrateWidgetShapeMetadata", "markOrphanedWidgetShapes", "onSelectSelectTool", "onSelectLibraryShapeTool", "onSelectEraseTool", "onSelectDrawTool", "onSelectTextTool", "onSelectArrowTool", "onSelectShapeTool", "onSelectFrameTool", "setPrimaryWidgetShape", "getPrimaryWidgetId", "setWidgetShapeBodyDragAllowed", "translateWidgetShapeByScreen", "commitWidgetShapeTranslate", "setWidgetShapeOverlayDragActive", "selectWidgetShapeById", "getSelectedWidgetShapeId", "getSelectedObject", "getHoveredWidgetShapeId", "onSelectImageTool", "onSelectVideoTool", "onSelectPanTool", "zoomIn", "zoomOut", "zoomTo", "zoomReset", "zoomFit", "onGroupSelection", "onUngroupSelection", "onSelectAllObjects", "onDeselectAllObjects", "flushAutosave", "saveNow", "undo", "redo", "saveCanvas", "loadCanvas", "onClearAllObjects", "addText", "addTriangle", "addRect", "addCircle", "addFrame", "addImage", "removeSketchObjectsKeepingWidget", "getSketchSceneSummary", "executeSketchTool", "beginSketchToolBatch", "endSketchToolBatch", "flyToObjects", "flyToPoint", "flyToContent"];
22
+ export declare const CANVAS_EXPORTED_FUNCTION_NAMES: readonly ["shapeFillColor", "captureCanvasSketch", "absorbCanvasSketchIntoWidget", "deselectAll", "duplicateSelectedObjects", "deleteSelectedObjects", "markSelectedAsDuplicating", "linkObjectToWidget", "linkFrameToWidget", "replaceObjectWithWidgetImage", "updateWidgetImage", "selectWidgetShape", "listWidgetShapeScreenRects", "getWidgetShapeScreenRect", "getObjectScreenRect", "getWidgetShapeDataUrl", "setWidgetShapeLivePreviewHiddenImage", "addWidgetShape", "getLinkedWidgetIds", "keepOnlyWidgetShape", "hydrateWidgetShapeMetadata", "markOrphanedWidgetShapes", "onSelectSelectTool", "onSelectLibraryShapeTool", "onSelectEraseTool", "onSelectDrawTool", "onSelectTextTool", "onSelectArrowTool", "onSelectShapeTool", "onSelectFrameTool", "setPrimaryWidgetShape", "getPrimaryWidgetId", "setWidgetShapeBodyDragAllowed", "translateWidgetShapeByScreen", "commitWidgetShapeTranslate", "setWidgetShapeOverlayDragActive", "selectWidgetShapeById", "getSelectedWidgetShapeId", "getSelectedObject", "getHoveredWidgetShapeId", "onSelectImageTool", "onSelectVideoTool", "onSelectPanTool", "zoomIn", "zoomOut", "zoomTo", "zoomReset", "zoomFit", "onGroupSelection", "onUngroupSelection", "onSelectAllObjects", "onDeselectAllObjects", "flushAutosave", "saveNow", "undo", "redo", "saveCanvas", "loadCanvas", "onClearAllObjects", "addText", "addTriangle", "addRect", "addCircle", "addFrame", "addImage", "removeSketchObjectsKeepingWidget", "getSketchSceneSummary", "executeSketchTool", "beginSketchToolBatch", "endSketchToolBatch", "flyToObjects", "flyToPoint", "flyToContent", "openFileBrowser", "insertPickedFiles", "getBoardPictures", "getLoadedBoardPictures", "setPictureLibraryFile"];
23
23
  export type CanvasExportedFunctionName = (typeof CANVAS_EXPORTED_FUNCTION_NAMES)[number];
24
24
  /** What a page gets from `bind:this` besides the component's props: the host's own type of each function. */
25
25
  export type CanvasHostApi = Pick<CanvasHost, CanvasExportedFunctionName>;
@@ -9,8 +9,17 @@
9
9
  * Kept free of Svelte so that Node can test it: `tests/host/hostSurface.test.mjs` holds this list, the fixture and the
10
10
  * shell to each other.
11
11
  */
12
+ var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
13
+ if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
14
+ if (ar || !(i in from)) {
15
+ if (!ar) ar = Array.prototype.slice.call(from, 0, i);
16
+ ar[i] = from[i];
17
+ }
18
+ }
19
+ return to.concat(ar || Array.prototype.slice.call(from));
20
+ };
12
21
  /** Every function a page already calls, in the order the fixture lists them. */
13
- export const CANVAS_CONTRACT_FUNCTION_NAMES = [
22
+ export var CANVAS_CONTRACT_FUNCTION_NAMES = [
14
23
  'shapeFillColor',
15
24
  'captureCanvasSketch',
16
25
  'absorbCanvasSketchIntoWidget',
@@ -82,7 +91,7 @@ export const CANVAS_CONTRACT_FUNCTION_NAMES = [
82
91
  * (feat/shopify-feedback-canvas) adds the same one, so it keeps the name and the answer (how many objects went): removes
83
92
  * the sketch objects around one widget card and keeps the card.
84
93
  */
85
- export const CANVAS_ADDED_FUNCTION_NAMES = [
94
+ export var CANVAS_ADDED_FUNCTION_NAMES = [
86
95
  'removeSketchObjectsKeepingWidget',
87
96
  'getSketchSceneSummary',
88
97
  'executeSketchTool',
@@ -91,15 +100,29 @@ export const CANVAS_ADDED_FUNCTION_NAMES = [
91
100
  // The camera: the view eases to a place (position and zoom together). A page jumps from one object to another, or to a point.
92
101
  'flyToObjects',
93
102
  'flyToPoint',
94
- 'flyToContent'
103
+ 'flyToContent',
104
+ // The person's file library on the board: the Files entry of the Shapes menu, and the calls a page uses to put the pictures that
105
+ // are only on the board into its library (`getLoadedBoardPictures` is the same list as `getBoardPictures`, without waiting: for the
106
+ // moment the board is about to change).
107
+ 'openFileBrowser',
108
+ 'insertPickedFiles',
109
+ 'getBoardPictures',
110
+ 'getLoadedBoardPictures',
111
+ 'setPictureLibraryFile'
95
112
  ];
96
113
  /** Every function the shell exports. */
97
- export const CANVAS_EXPORTED_FUNCTION_NAMES = [...CANVAS_CONTRACT_FUNCTION_NAMES, ...CANVAS_ADDED_FUNCTION_NAMES];
114
+ export var CANVAS_EXPORTED_FUNCTION_NAMES = __spreadArray(__spreadArray([], CANVAS_CONTRACT_FUNCTION_NAMES, true), CANVAS_ADDED_FUNCTION_NAMES, true);
98
115
  /**
99
116
  * One exported function of the shell: it calls the host's method of that name, with the host as `this`, and has the
100
117
  * method's own type. A page that holds the shell's reference calls it exactly as it calls the host's method.
101
118
  */
102
119
  export function forwardToHost(host, name) {
103
- const forwarded = (...values) => host[name].apply(host, values);
120
+ var forwarded = function () {
121
+ var values = [];
122
+ for (var _i = 0; _i < arguments.length; _i++) {
123
+ values[_i] = arguments[_i];
124
+ }
125
+ return host[name].apply(host, values);
126
+ };
104
127
  return forwarded;
105
128
  }
@@ -0,0 +1,90 @@
1
+ /**
2
+ * The files of the person's library (the File Browser of their workspace) as the board sees them.
3
+ *
4
+ * The board never shows a File Browser itself: the page that embeds it owns the browser, the workspace and the partner's media
5
+ * library, and gives the board a picker (`pickFiles`). This module is what is said at that door in both directions:
6
+ *
7
+ * - what the board asks for (`BoardFilePickRequest`: pictures and vector files, one or several), and what comes back (`BoardLibraryFile`s,
8
+ * which are checked here because they come from the page, and a partner's page is not ours);
9
+ * - what the board says about the pictures it holds (`BoardPicture`), so the page can put the ones the library does not have yet into it.
10
+ *
11
+ * Deleting something from the board never reaches the library: no function here deletes anything, and the board has no callback
12
+ * that does.
13
+ *
14
+ * Plain TypeScript: runs in Node.
15
+ */
16
+ import type { Scene } from '../../engine/core/scene.js';
17
+ import type { ObjectId } from '../../engine/core/types.js';
18
+ /** The kinds of file the board can put down: pictures (png, jpg, gif, webp, avif…) and vector files (svg). */
19
+ export type BoardFileKind = 'image' | 'svg';
20
+ /** The kinds the board asks the picker for, in the order the File Browser lists them. */
21
+ export declare const BOARD_FILE_KINDS: readonly BoardFileKind[];
22
+ /** What the board asks the page's picker for. */
23
+ export interface BoardFilePickRequest {
24
+ /** The kinds of file the board can use (the picker should list nothing else). */
25
+ kinds: readonly BoardFileKind[];
26
+ /** Whether the person may choose several files at once. */
27
+ multiple: boolean;
28
+ }
29
+ /** A file of the library, as the page's picker reports it (and as a sketch assistant is told about it). */
30
+ export interface BoardLibraryFile {
31
+ /** The library's own id for the file. Null when the library has none (a partner's list without ids). */
32
+ id: string | null;
33
+ name: string;
34
+ /** Where the browser can load it: an http(s) address or a path of the page. */
35
+ url: string;
36
+ /** `image/png`, `image/svg+xml`… when the library knows it. */
37
+ mimeType: string | null;
38
+ }
39
+ /**
40
+ * The page's File Browser. It opens the browser in a dialog (in select state, filtered to `request.kinds`) and answers with the files the
41
+ * person chose, or with nothing when they closed it. It may be asynchronous. The answer is never trusted: see `normalizeLibraryFiles`.
42
+ */
43
+ export type BoardFilePicker = (request: BoardFilePickRequest) => Promise<readonly BoardLibraryFile[] | null | undefined> | readonly BoardLibraryFile[] | null | undefined;
44
+ /** A picture that is on the board, as it is told to the page (to be put in the library when it is not there yet). */
45
+ export interface BoardPicture {
46
+ objectId: string;
47
+ fileName: string | null;
48
+ /** What the board draws: a `data:` address, a `blob:` address of the page's picture store, or an http(s) address. Null if it never arrived. */
49
+ src: string | null;
50
+ /** The library's id for the picture, when it is in the library. */
51
+ libraryFileId: string | null;
52
+ libraryFileUrl: string | null;
53
+ naturalWidth: number;
54
+ naturalHeight: number;
55
+ }
56
+ /** Where a library file ended up, once the page put a board picture in the library. */
57
+ export interface BoardPictureLibraryFile {
58
+ id: string;
59
+ url: string;
60
+ }
61
+ /** A picked list longer than this is cut: one dialog is not for a hundred files, and each is fetched. */
62
+ export declare const MAX_PICKED_FILES = 40;
63
+ /** The extension of a file name or an address, lower-cased, without the query or the hash. Empty when there is none. */
64
+ export declare function fileExtensionOf(nameOrUrl: string): string;
65
+ /** The kind of a file by what the library says it is, else by its name; null when it is not a picture the board can draw. */
66
+ export declare function boardFileKindOf(file: {
67
+ name: string;
68
+ url?: string;
69
+ mimeType?: string | null;
70
+ }): BoardFileKind | null;
71
+ /** The media type the browser needs to draw the file: the library's own when it is a picture's, else the one its extension says. */
72
+ export declare function pictureMimeTypeOf(file: {
73
+ name: string;
74
+ url?: string;
75
+ mimeType?: string | null;
76
+ }): string;
77
+ /**
78
+ * Keeps what can be drawn of what a picker answered. The answer comes from the page, so it is checked like any input: not a list is
79
+ * nothing; an entry that is not an object, has no loadable address, or is not a picture is dropped; the list is cut at
80
+ * `MAX_PICKED_FILES`; the same file twice (same id, or the same address) is kept once.
81
+ */
82
+ export declare function normalizeLibraryFiles(answer: unknown): BoardLibraryFile[];
83
+ /** Whether a picture of the board is in the library already (the page put it there, or the person picked it from there). */
84
+ export declare function isInLibrary(picture: Pick<BoardPicture, 'libraryFileId' | 'libraryFileUrl'>): boolean;
85
+ /**
86
+ * The scene with the library's answer written into one picture: the very same list when no picture has that object id, or when it
87
+ * already says the same. An answer the page gave badly (no id, an address that is not http(s) or a path of the page) changes nothing,
88
+ * so a partner's bug cannot put an address of its choosing on the board.
89
+ */
90
+ export declare function applyLibraryFile(scene: Scene, objectId: ObjectId, file: BoardPictureLibraryFile): Scene;
@@ -0,0 +1,155 @@
1
+ /**
2
+ * The files of the person's library (the File Browser of their workspace) as the board sees them.
3
+ *
4
+ * The board never shows a File Browser itself: the page that embeds it owns the browser, the workspace and the partner's media
5
+ * library, and gives the board a picker (`pickFiles`). This module is what is said at that door in both directions:
6
+ *
7
+ * - what the board asks for (`BoardFilePickRequest`: pictures and vector files, one or several), and what comes back (`BoardLibraryFile`s,
8
+ * which are checked here because they come from the page, and a partner's page is not ours);
9
+ * - what the board says about the pictures it holds (`BoardPicture`), so the page can put the ones the library does not have yet into it.
10
+ *
11
+ * Deleting something from the board never reaches the library: no function here deletes anything, and the board has no callback
12
+ * that does.
13
+ *
14
+ * Plain TypeScript: runs in Node.
15
+ */
16
+ var __assign = (this && this.__assign) || function () {
17
+ __assign = Object.assign || function(t) {
18
+ for (var s, i = 1, n = arguments.length; i < n; i++) {
19
+ s = arguments[i];
20
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
21
+ t[p] = s[p];
22
+ }
23
+ return t;
24
+ };
25
+ return __assign.apply(this, arguments);
26
+ };
27
+ import { readLibraryFileAddress } from '../../engine/codec/canvasDocument.js';
28
+ /** The kinds the board asks the picker for, in the order the File Browser lists them. */
29
+ export var BOARD_FILE_KINDS = ['image', 'svg'];
30
+ var PICTURE_EXTENSIONS = {
31
+ svg: 'svg',
32
+ png: 'image',
33
+ jpg: 'image',
34
+ jpeg: 'image',
35
+ gif: 'image',
36
+ webp: 'image',
37
+ avif: 'image',
38
+ bmp: 'image'
39
+ };
40
+ /** What a library address is allowed to be: an http(s) address, or a path of the page (never `data:`, `javascript:`, `//host`). */
41
+ var LIBRARY_URL_PATTERN = /^(?:https?:\/\/|\/(?!\/))/i;
42
+ var MAX_URL_LENGTH = 2000;
43
+ var MAX_NAME_LENGTH = 300;
44
+ var MAX_ID_LENGTH = 200;
45
+ /** A picked list longer than this is cut: one dialog is not for a hundred files, and each is fetched. */
46
+ export var MAX_PICKED_FILES = 40;
47
+ /** The extension of a file name or an address, lower-cased, without the query or the hash. Empty when there is none. */
48
+ export function fileExtensionOf(nameOrUrl) {
49
+ var _a;
50
+ var withoutQuery = (_a = nameOrUrl.split(/[?#]/, 1)[0]) !== null && _a !== void 0 ? _a : '';
51
+ var lastSegment = withoutQuery.slice(withoutQuery.lastIndexOf('/') + 1);
52
+ var dot = lastSegment.lastIndexOf('.');
53
+ return dot > 0 ? lastSegment.slice(dot + 1).toLowerCase() : '';
54
+ }
55
+ /** The kind of a file by what the library says it is, else by its name; null when it is not a picture the board can draw. */
56
+ export function boardFileKindOf(file) {
57
+ var _a, _b, _c, _d;
58
+ var mimeType = ((_a = file.mimeType) !== null && _a !== void 0 ? _a : '').toLowerCase();
59
+ if (mimeType === 'image/svg+xml')
60
+ return 'svg';
61
+ if (mimeType.startsWith('image/'))
62
+ return 'image';
63
+ return (_d = (_b = PICTURE_EXTENSIONS[fileExtensionOf(file.name)]) !== null && _b !== void 0 ? _b : PICTURE_EXTENSIONS[fileExtensionOf((_c = file.url) !== null && _c !== void 0 ? _c : '')]) !== null && _d !== void 0 ? _d : null;
64
+ }
65
+ /** The media type the browser needs to draw the file: the library's own when it is a picture's, else the one its extension says. */
66
+ export function pictureMimeTypeOf(file) {
67
+ var _a, _b;
68
+ var mimeType = ((_a = file.mimeType) !== null && _a !== void 0 ? _a : '').toLowerCase();
69
+ if (mimeType.startsWith('image/'))
70
+ return mimeType;
71
+ var kind = boardFileKindOf(file);
72
+ if (kind === 'svg')
73
+ return 'image/svg+xml';
74
+ var extension = fileExtensionOf(file.name) || fileExtensionOf((_b = file.url) !== null && _b !== void 0 ? _b : '');
75
+ if (extension === 'jpg' || extension === 'jpeg')
76
+ return 'image/jpeg';
77
+ return extension ? "image/".concat(extension) : 'image/png';
78
+ }
79
+ /** A readable name for a file whose picker did not give one: the last part of its address. */
80
+ function nameFromUrl(url) {
81
+ var _a;
82
+ var withoutQuery = (_a = url.split(/[?#]/, 1)[0]) !== null && _a !== void 0 ? _a : '';
83
+ var last = withoutQuery.slice(withoutQuery.lastIndexOf('/') + 1);
84
+ try {
85
+ return decodeURIComponent(last).slice(0, MAX_NAME_LENGTH) || 'picture';
86
+ }
87
+ catch (_b) {
88
+ return last.slice(0, MAX_NAME_LENGTH) || 'picture';
89
+ }
90
+ }
91
+ function readId(value) {
92
+ if (typeof value === 'number' && Number.isFinite(value))
93
+ return String(value);
94
+ if (typeof value === 'string' && value !== '' && value.length <= MAX_ID_LENGTH)
95
+ return value;
96
+ return null;
97
+ }
98
+ /**
99
+ * Keeps what can be drawn of what a picker answered. The answer comes from the page, so it is checked like any input: not a list is
100
+ * nothing; an entry that is not an object, has no loadable address, or is not a picture is dropped; the list is cut at
101
+ * `MAX_PICKED_FILES`; the same file twice (same id, or the same address) is kept once.
102
+ */
103
+ export function normalizeLibraryFiles(answer) {
104
+ if (!Array.isArray(answer))
105
+ return [];
106
+ var files = [];
107
+ var seen = new Set();
108
+ for (var _i = 0, answer_1 = answer; _i < answer_1.length; _i++) {
109
+ var entry = answer_1[_i];
110
+ if (files.length >= MAX_PICKED_FILES)
111
+ break;
112
+ if (typeof entry !== 'object' || entry === null)
113
+ continue;
114
+ var raw = entry;
115
+ var url = typeof raw.url === 'string' ? raw.url.trim() : '';
116
+ if (url === '' || url.length > MAX_URL_LENGTH || !LIBRARY_URL_PATTERN.test(url))
117
+ continue;
118
+ var name = (typeof raw.name === 'string' && raw.name.trim() !== '' ? raw.name.trim() : nameFromUrl(url)).slice(0, MAX_NAME_LENGTH);
119
+ var mimeType = typeof raw.mimeType === 'string' && raw.mimeType !== '' ? raw.mimeType.slice(0, 100) : null;
120
+ if (!boardFileKindOf({ name: name, url: url, mimeType: mimeType }))
121
+ continue;
122
+ var id = readId(raw.id);
123
+ var identity = id ? "id:".concat(id) : "url:".concat(url);
124
+ if (seen.has(identity))
125
+ continue;
126
+ seen.add(identity);
127
+ files.push({ id: id, name: name, url: url, mimeType: mimeType });
128
+ }
129
+ return files;
130
+ }
131
+ /** Whether a picture of the board is in the library already (the page put it there, or the person picked it from there). */
132
+ export function isInLibrary(picture) {
133
+ return Boolean(picture.libraryFileId || picture.libraryFileUrl);
134
+ }
135
+ /**
136
+ * The scene with the library's answer written into one picture: the very same list when no picture has that object id, or when it
137
+ * already says the same. An answer the page gave badly (no id, an address that is not http(s) or a path of the page) changes nothing,
138
+ * so a partner's bug cannot put an address of its choosing on the board.
139
+ */
140
+ export function applyLibraryFile(scene, objectId, file) {
141
+ var id = readId(file === null || file === void 0 ? void 0 : file.id);
142
+ var url = readLibraryFileAddress(file === null || file === void 0 ? void 0 : file.url);
143
+ if (!id || !url)
144
+ return scene;
145
+ var changed = false;
146
+ var next = scene.map(function (object) {
147
+ if (object.id !== objectId || object.type !== 'image')
148
+ return object;
149
+ if (object.libraryFileId === id && object.libraryFileUrl === url)
150
+ return object;
151
+ changed = true;
152
+ return __assign(__assign({}, object), { libraryFileId: id, libraryFileUrl: url });
153
+ });
154
+ return changed ? next : scene;
155
+ }
@@ -8,6 +8,7 @@
8
8
  */
9
9
  import type { MeasureText } from '../../engine/text/layoutText.js';
10
10
  import type { RasterServices } from '../../engine/render/rasterize.js';
11
+ import type { BoardLibraryFile } from './boardFiles.js';
11
12
  /** A text measurer that uses the browser's canvas, or a fixed advance where there is none (the server, a test). */
12
13
  export declare function createBrowserMeasureText(): MeasureText;
13
14
  /** The picture behind an address, decoded. Null when it cannot be loaded. */
@@ -22,6 +23,9 @@ export interface LoadedImageFile {
22
23
  width: number;
23
24
  height: number;
24
25
  fileName: string;
26
+ /** Set when the picture came from the person's file library: the library's id for it, and where it keeps the file. */
27
+ libraryFileId?: string | null;
28
+ libraryFileUrl?: string | null;
25
29
  }
26
30
  /** The longest side a picture keeps when it is large; a bigger one is scaled down before it is stored in the board. */
27
31
  export declare const IMAGE_MAX_SIDE = 2048;
@@ -35,6 +39,19 @@ export declare const IMAGE_FALLBACK_SIDE = 300;
35
39
  * Rejects when the file is not a picture the browser can show.
36
40
  */
37
41
  export declare function readImageFile(file: File | Blob, fileName?: string): Promise<LoadedImageFile>;
42
+ /** How long the library gets to hand over a picture's bytes before the board settles for its address. */
43
+ export declare const LIBRARY_PICTURE_TIMEOUT_MS = 10000;
44
+ /** A library picture bigger than this is not read into the board: the board holds its address (a photo of 40 MB is not board material). */
45
+ export declare const LIBRARY_PICTURE_MAX_BYTES: number;
46
+ /**
47
+ * Reads a file of the person's library into a picture for the board, remembering where the library keeps it.
48
+ *
49
+ * The bytes are fetched when the library lets the page (CORS), so the board and the screenshots of it do not depend on the library
50
+ * being reachable, and a large photo is scaled down like any picture the person drops. When the bytes cannot be had (no CORS, an
51
+ * error, too slow, too big) the board holds the file's address instead: it still shows the picture, and the library stays the owner.
52
+ * Null when the browser cannot show the file at all.
53
+ */
54
+ export declare function readLibraryPicture(file: BoardLibraryFile): Promise<LoadedImageFile | null>;
38
55
  /**
39
56
  * Opens the browser's file chooser for pictures and answers with what was chosen (an empty list when the person
40
57
  * cancels). Must be called while a click or a key press is being handled, or the browser refuses to open the chooser.