visual-comments 0.0.0-stage → 0.1.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 (62) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +60 -2
  3. package/dist/core/aim.d.ts +21 -0
  4. package/dist/core/aim.js +21 -0
  5. package/dist/core/api.d.ts +5 -0
  6. package/dist/core/api.js +11 -0
  7. package/dist/core/metaball.d.ts +15 -0
  8. package/dist/core/metaball.js +42 -0
  9. package/dist/core/surfaces.d.ts +95 -0
  10. package/dist/core/surfaces.js +197 -0
  11. package/dist/core/target.d.ts +59 -0
  12. package/dist/core/target.js +382 -0
  13. package/dist/core/threads.svelte.d.ts +46 -0
  14. package/dist/core/threads.svelte.js +219 -0
  15. package/dist/core/time.d.ts +3 -0
  16. package/dist/core/time.js +25 -0
  17. package/dist/index.d.ts +5 -0
  18. package/dist/index.js +6 -0
  19. package/dist/server/index.d.ts +33 -0
  20. package/dist/server/index.js +67 -0
  21. package/dist/shared/limits.d.ts +9 -0
  22. package/dist/shared/limits.js +10 -0
  23. package/dist/shared/protocol.d.ts +2 -0
  24. package/dist/shared/protocol.js +3 -0
  25. package/dist/shared/types.d.ts +93 -0
  26. package/dist/shared/types.js +2 -0
  27. package/dist/ui/Account.svelte +68 -0
  28. package/dist/ui/Account.svelte.d.ts +8 -0
  29. package/dist/ui/App.svelte +68 -0
  30. package/dist/ui/App.svelte.d.ts +7 -0
  31. package/dist/ui/Avatar.svelte +42 -0
  32. package/dist/ui/Avatar.svelte.d.ts +12 -0
  33. package/dist/ui/Composer.svelte +267 -0
  34. package/dist/ui/Composer.svelte.d.ts +20 -0
  35. package/dist/ui/Icon.svelte +44 -0
  36. package/dist/ui/Icon.svelte.d.ts +29 -0
  37. package/dist/ui/Menu.svelte +65 -0
  38. package/dist/ui/Menu.svelte.d.ts +13 -0
  39. package/dist/ui/MenuItem.svelte +38 -0
  40. package/dist/ui/MenuItem.svelte.d.ts +12 -0
  41. package/dist/ui/Overlay.svelte +488 -0
  42. package/dist/ui/Overlay.svelte.d.ts +3 -0
  43. package/dist/ui/Panel.svelte +206 -0
  44. package/dist/ui/Panel.svelte.d.ts +10 -0
  45. package/dist/ui/Pin.svelte +136 -0
  46. package/dist/ui/Pin.svelte.d.ts +13 -0
  47. package/dist/ui/ThreadCard.svelte +177 -0
  48. package/dist/ui/ThreadCard.svelte.d.ts +13 -0
  49. package/dist/ui/Toolbar.svelte +35 -0
  50. package/dist/ui/Toolbar.svelte.d.ts +18 -0
  51. package/dist/ui/context.d.ts +3 -0
  52. package/dist/ui/context.js +8 -0
  53. package/dist/ui/generated/styles.css +2 -0
  54. package/dist/ui/generated/styles.d.ts +2 -0
  55. package/dist/ui/generated/styles.js +3 -0
  56. package/dist/ui/styles.css +92 -0
  57. package/dist/ui/text.d.ts +3 -0
  58. package/dist/ui/text.js +7 -0
  59. package/dist/visual-comments.svelte.d.ts +181 -0
  60. package/dist/visual-comments.svelte.js +568 -0
  61. package/dist-widget/visual-comments.js +51 -0
  62. package/package.json +66 -5
@@ -0,0 +1,3 @@
1
+ import type { Comment } from '../shared/types.js';
2
+ /** A comment's text for previews, or what it holds when it is only images. */
3
+ export declare function commentText(comment: Comment): string;
@@ -0,0 +1,7 @@
1
+ /** A comment's text for previews, or what it holds when it is only images. */
2
+ export function commentText(comment) {
3
+ if (comment.body)
4
+ return comment.body;
5
+ const count = comment.images?.length ?? 0;
6
+ return count === 1 ? 'Image' : `${count} images`;
7
+ }
@@ -0,0 +1,181 @@
1
+ import { type Aim } from './core/aim.js';
2
+ import { Api } from './core/api.js';
3
+ import { type Rect, type Surface } from './core/surfaces.js';
4
+ import { type CommentTarget } from './core/target.js';
5
+ import { Threads } from './core/threads.svelte.js';
6
+ import type { CommentImage, CommentThread } from './shared/types.js';
7
+ export interface VisualCommentsOptions {
8
+ /** Where the site's server passes comment requests on to the comment server. Default `/_comments`. */
9
+ endpoint?: string;
10
+ /**
11
+ * The site's sign-in: the path of its routes, as in `@convex-works/sign-in`
12
+ * (default `/auth`), or functions that sign in and out.
13
+ */
14
+ auth?: string | {
15
+ signIn(): void;
16
+ signOut(): void;
17
+ };
18
+ /**
19
+ * The page threads belong to. Default: the address's origin and path, so
20
+ * the query and fragment do not matter. A fixed string makes every page share threads.
21
+ */
22
+ page?: string | ((url: URL) => string);
23
+ /** What to store about where a thread is placed, besides the viewport size and `data-vc-context`. */
24
+ context?: (surface: SurfaceInfo) => Record<string, string | number | undefined> | undefined;
25
+ /**
26
+ * Brings a thread's surface into view when it is opened from the list or a
27
+ * link, e.g. by zooming a canvas to it or navigating to it. Return true when
28
+ * handled; otherwise threads on other pages are opened by navigating to them.
29
+ */
30
+ show?: (thread: CommentThread) => boolean | void;
31
+ /** The address that opens a thread. Default: where it was placed, with `#vc=<id>`. */
32
+ link?: (thread: CommentThread) => string;
33
+ /** A surface's title and place in the list, for surfaces not on screen. */
34
+ describe?: (surface: string) => {
35
+ title?: string;
36
+ order?: number;
37
+ } | undefined;
38
+ /** A frame surface's document, when the default (any same-origin frame once loaded) is not right. */
39
+ documentOf?: (surface: Element, frame: HTMLIFrameElement) => Document | undefined;
40
+ /** The key that turns comment mode on and off. Default: `c`. */
41
+ shortcut?: string | false;
42
+ /** Show the floating toolbar. Default: unless the page has a `[data-vc-toggle]` button. */
43
+ toolbar?: boolean;
44
+ }
45
+ export interface SurfaceInfo {
46
+ id: string;
47
+ title: string;
48
+ element: Element | null;
49
+ }
50
+ export interface CommentFilters {
51
+ query: string;
52
+ sort: 'date' | 'place';
53
+ showResolved: boolean;
54
+ onlyMine: boolean;
55
+ /** Threads on every page, not only this one. */
56
+ allPages: boolean;
57
+ }
58
+ /** A new comment being written. */
59
+ export interface Draft extends Aim {
60
+ text: string;
61
+ /** Narrower targets the pin was widened from, innermost first. */
62
+ inner?: CommentTarget[];
63
+ /** Images added so far, so a click elsewhere keeps them like text. */
64
+ images?: number;
65
+ }
66
+ interface Pointer {
67
+ x: number;
68
+ y: number;
69
+ alt: boolean;
70
+ }
71
+ /**
72
+ * Comments on a page: pins, the comment mode, the list of threads and the
73
+ * sign-in, drawn in a shadow root over the page. One per page.
74
+ */
75
+ export declare class VisualComments {
76
+ readonly api: Api;
77
+ readonly store: Threads;
78
+ options: VisualCommentsOptions;
79
+ /** Comment mode: the list is shown, and clicking a surface starts a thread. Pins always show. */
80
+ active: boolean;
81
+ /** The thread whose conversation is open. */
82
+ openId: number | undefined;
83
+ draft: Draft | undefined;
84
+ filters: CommentFilters;
85
+ /** Measured on every change of the page. */
86
+ surfaces: Surface[];
87
+ /** Bumped whenever anything on the page may have moved. */
88
+ layout: number;
89
+ page: string;
90
+ /** Where the host asked for the list to go. */
91
+ panelRect: Rect | undefined;
92
+ hostToggles: boolean;
93
+ /** Where a click would start a thread, while it would. */
94
+ aim: Aim | undefined;
95
+ /** The pointer while it is over a surface in comment mode: the comment cursor is drawn there. */
96
+ cursor: {
97
+ x: number;
98
+ y: number;
99
+ } | undefined;
100
+ /** Opening a thread scrolls its element into view once it is found. */
101
+ revealing: number | undefined;
102
+ readonly doc: Document;
103
+ readonly host: HTMLElement;
104
+ private app?;
105
+ private slots;
106
+ private frames;
107
+ private cleanup;
108
+ private pointer?;
109
+ private pressed?;
110
+ private measuring;
111
+ private aiming;
112
+ private animating;
113
+ private cursorSheet;
114
+ private focusDraftHandler?;
115
+ private linked?;
116
+ constructor(options: VisualCommentsOptions, doc?: Document);
117
+ get viewer(): import("./index.js").Viewer | null;
118
+ get threads(): CommentThread[];
119
+ get unreadCount(): number;
120
+ get loading(): boolean;
121
+ get open(): CommentThread | undefined;
122
+ /** Threads shown as pins: on this page, unresolved unless resolved ones are shown or it is open. */
123
+ get pinned(): CommentThread[];
124
+ get showToolbar(): boolean;
125
+ surface(id: string): Surface | undefined;
126
+ /** A surface's title for the list, whether or not it is on screen. */
127
+ titleOf(thread: CommentThread): string;
128
+ orderOf(thread: CommentThread): number;
129
+ linkOf(thread: CommentThread): string;
130
+ imageUrl(image: CommentImage): string;
131
+ /** Whether an element belongs to the comment UI. */
132
+ readonly ours: (element: Element) => boolean;
133
+ /** Changes options after creation, e.g. when a host's view mounts and can show threads. */
134
+ configure(options: Partial<VisualCommentsOptions>): void;
135
+ toggle(on?: boolean): void;
136
+ openThread(id: number | undefined): void;
137
+ /** Opens a thread from the list or a link, bringing it into view. */
138
+ focus(thread: CommentThread): void;
139
+ /** The thread's element, once found, scrolled into view inside its document. */
140
+ revealElement(element: Element): void;
141
+ /** Leaves for the site's sign-in, and comes back to this address. */
142
+ signIn(): void;
143
+ signOut(): void;
144
+ /** Measures the page again, e.g. after the host moved surfaces in a way it cannot see. */
145
+ relayout(): void;
146
+ /** For hosts that are not built with Svelte: called after any change of state. */
147
+ subscribe(listener: (comments: VisualComments) => void): () => void;
148
+ destroy(): void;
149
+ /** Called by the UI so a click elsewhere can bring the unsent comment back to attention. */
150
+ onFocusDraft(handler: (() => void) | undefined): void;
151
+ private get draftHasContent();
152
+ private start;
153
+ /** Watches a frame's own document: its scrolling, its changes and its keys. */
154
+ private watchFrame;
155
+ private schedule;
156
+ private measure;
157
+ /** Puts the account button in every `[data-vc-account]` element of the host's own toolbar. */
158
+ private mountSlots;
159
+ private fromUs;
160
+ private surfaceAt;
161
+ /** The pointer moved, or left (undefined). Also called by the layers over frames. */
162
+ move(pointer: Pointer | undefined): void;
163
+ private onPointerMove;
164
+ /** Aims again, at most once per frame: the pointer moved, or the page moved under it. */
165
+ private updateAim;
166
+ /** Over a surface in comment mode the page's cursor is hidden; the comment cursor is drawn instead. */
167
+ private updateCursorStyle;
168
+ /** Pressing on a surface in comment mode does not reach the page, unless the host keeps its gestures there. */
169
+ private onPress;
170
+ private onRelease;
171
+ private onOtherClick;
172
+ private onClick;
173
+ /** A click on a surface in comment mode starts a thread. A click away from an open thread closes it first. */
174
+ place(surface: Surface, x: number, y: number, free: boolean): void;
175
+ /** A layer over a frame passes wheel turns to whatever scrolls under the pointer. */
176
+ wheel(surface: Surface, event: WheelEvent): void;
177
+ private onKey;
178
+ }
179
+ /** The page key: the address's origin and path, without a trailing slash. */
180
+ export declare function pageOf(option: VisualCommentsOptions['page']): string;
181
+ export {};