@openartifactsai/whiteboard-core 0.0.0-stage → 0.23.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 (160) hide show
  1. package/LICENSE +202 -0
  2. package/NOTICE +5 -0
  3. package/README.md +5 -2
  4. package/package.json +38 -4
  5. package/src/anchors.d.ts +78 -0
  6. package/src/anchors.js +215 -0
  7. package/src/arrows/bend-drag.d.ts +61 -0
  8. package/src/arrows/bend-drag.js +119 -0
  9. package/src/arrows/end-snap.d.ts +50 -0
  10. package/src/arrows/end-snap.js +81 -0
  11. package/src/arrows/labels.d.ts +149 -0
  12. package/src/arrows/labels.js +219 -0
  13. package/src/arrows/layout.d.ts +216 -0
  14. package/src/arrows/layout.js +524 -0
  15. package/src/arrows/routing.d.ts +163 -0
  16. package/src/arrows/routing.js +253 -0
  17. package/src/arrows/steer.d.ts +27 -0
  18. package/src/arrows/steer.js +93 -0
  19. package/src/attachments.d.ts +83 -0
  20. package/src/attachments.js +244 -0
  21. package/src/backdrop.d.ts +29 -0
  22. package/src/backdrop.js +72 -0
  23. package/src/board-file.d.ts +93 -0
  24. package/src/board-file.js +171 -0
  25. package/src/check.d.ts +79 -0
  26. package/src/check.js +448 -0
  27. package/src/claims.d.ts +196 -0
  28. package/src/claims.js +367 -0
  29. package/src/clipboard.d.ts +106 -0
  30. package/src/clipboard.js +228 -0
  31. package/src/codec.d.ts +115 -0
  32. package/src/codec.js +222 -0
  33. package/src/comment-anchors.d.ts +251 -0
  34. package/src/comment-anchors.js +515 -0
  35. package/src/derived.d.ts +16 -0
  36. package/src/derived.js +20 -0
  37. package/src/drawn-svg/contrast.d.ts +46 -0
  38. package/src/drawn-svg/contrast.js +192 -0
  39. package/src/drawn-svg/layer-edits.d.ts +22 -0
  40. package/src/drawn-svg/layer-edits.js +131 -0
  41. package/src/drawn-svg/layers.d.ts +126 -0
  42. package/src/drawn-svg/layers.js +385 -0
  43. package/src/drawn-svg/looks.d.ts +166 -0
  44. package/src/drawn-svg/looks.js +599 -0
  45. package/src/drawn-svg/restyle.d.ts +103 -0
  46. package/src/drawn-svg/restyle.js +480 -0
  47. package/src/drawn-svg/svg-geometry.d.ts +114 -0
  48. package/src/drawn-svg/svg-geometry.js +384 -0
  49. package/src/drawn-svg/vetting.d.ts +79 -0
  50. package/src/drawn-svg/vetting.js +219 -0
  51. package/src/drawn-svg/xml.d.ts +122 -0
  52. package/src/drawn-svg/xml.js +481 -0
  53. package/src/edits.d.ts +230 -0
  54. package/src/edits.js +618 -0
  55. package/src/geom-codec.d.ts +26 -0
  56. package/src/geom-codec.js +98 -0
  57. package/src/geometry.d.ts +261 -0
  58. package/src/geometry.js +479 -0
  59. package/src/groups.d.ts +143 -0
  60. package/src/groups.js +339 -0
  61. package/src/history/board-diff.d.ts +87 -0
  62. package/src/history/board-diff.js +326 -0
  63. package/src/history/board-steps.d.ts +61 -0
  64. package/src/history/board-steps.js +115 -0
  65. package/src/history/command-history.d.ts +81 -0
  66. package/src/history/command-history.js +151 -0
  67. package/src/history/content.d.ts +24 -0
  68. package/src/history/content.js +84 -0
  69. package/src/history/table-steps.d.ts +103 -0
  70. package/src/history/table-steps.js +251 -0
  71. package/src/history.d.ts +8 -0
  72. package/src/history.js +8 -0
  73. package/src/hit-test.d.ts +105 -0
  74. package/src/hit-test.js +369 -0
  75. package/src/ideas.d.ts +295 -0
  76. package/src/ideas.js +634 -0
  77. package/src/image-crop.d.ts +68 -0
  78. package/src/image-crop.js +140 -0
  79. package/src/image-source.d.ts +75 -0
  80. package/src/image-source.js +197 -0
  81. package/src/index.d.ts +72 -0
  82. package/src/index.js +78 -0
  83. package/src/ink.d.ts +164 -0
  84. package/src/ink.js +295 -0
  85. package/src/inks.d.ts +41 -0
  86. package/src/inks.js +60 -0
  87. package/src/json.d.ts +2 -0
  88. package/src/json.js +2 -0
  89. package/src/layout.d.ts +173 -0
  90. package/src/layout.js +365 -0
  91. package/src/links.d.ts +84 -0
  92. package/src/links.js +174 -0
  93. package/src/next-item.d.ts +87 -0
  94. package/src/next-item.js +179 -0
  95. package/src/normalize.d.ts +69 -0
  96. package/src/normalize.js +440 -0
  97. package/src/reading-order.d.ts +17 -0
  98. package/src/reading-order.js +178 -0
  99. package/src/schema.d.ts +500 -0
  100. package/src/schema.js +371 -0
  101. package/src/selection.d.ts +236 -0
  102. package/src/selection.js +504 -0
  103. package/src/shadows.d.ts +19 -0
  104. package/src/shadows.js +21 -0
  105. package/src/shape-paths.d.ts +120 -0
  106. package/src/shape-paths.js +197 -0
  107. package/src/snapping.d.ts +85 -0
  108. package/src/snapping.js +109 -0
  109. package/src/sticker-hosts.d.ts +43 -0
  110. package/src/sticker-hosts.js +157 -0
  111. package/src/stickers.d.ts +63 -0
  112. package/src/stickers.js +799 -0
  113. package/src/stroke-widths.d.ts +34 -0
  114. package/src/stroke-widths.js +52 -0
  115. package/src/sync/doc-hash.d.ts +1 -0
  116. package/src/sync/doc-hash.js +1 -0
  117. package/src/sync/engine.d.ts +1 -0
  118. package/src/sync/engine.js +1 -0
  119. package/src/sync/index.d.ts +9 -0
  120. package/src/sync/index.js +9 -0
  121. package/src/sync/live-board.d.ts +66 -0
  122. package/src/sync/live-board.js +157 -0
  123. package/src/sync/transport.d.ts +1 -0
  124. package/src/sync/transport.js +1 -0
  125. package/src/table-tints.d.ts +89 -0
  126. package/src/table-tints.js +234 -0
  127. package/src/table.d.ts +191 -0
  128. package/src/table.js +627 -0
  129. package/src/text/fit.d.ts +152 -0
  130. package/src/text/fit.js +299 -0
  131. package/src/text/grow-room.d.ts +20 -0
  132. package/src/text/grow-room.js +31 -0
  133. package/src/text/inline-markdown.d.ts +78 -0
  134. package/src/text/inline-markdown.js +186 -0
  135. package/src/text/links.d.ts +19 -0
  136. package/src/text/links.js +26 -0
  137. package/src/text/markup.d.ts +265 -0
  138. package/src/text/markup.js +339 -0
  139. package/src/text/measure.d.ts +74 -0
  140. package/src/text/measure.js +147 -0
  141. package/src/text/note-markdown.d.ts +59 -0
  142. package/src/text/note-markdown.js +71 -0
  143. package/src/text/placeholder.d.ts +17 -0
  144. package/src/text/placeholder.js +16 -0
  145. package/src/text/push-down.d.ts +29 -0
  146. package/src/text/push-down.js +72 -0
  147. package/src/text/text-arrows.d.ts +45 -0
  148. package/src/text/text-arrows.js +58 -0
  149. package/src/text/turned-anchor.d.ts +19 -0
  150. package/src/text/turned-anchor.js +32 -0
  151. package/src/text-limits.d.ts +14 -0
  152. package/src/text-limits.js +27 -0
  153. package/src/theme.d.ts +114 -0
  154. package/src/theme.js +281 -0
  155. package/src/timer.d.ts +64 -0
  156. package/src/timer.js +128 -0
  157. package/src/version-board.d.ts +28 -0
  158. package/src/version-board.js +74 -0
  159. package/src/view-context.d.ts +94 -0
  160. package/src/view-context.js +161 -0
package/LICENSE ADDED
@@ -0,0 +1,202 @@
1
+
2
+ Apache License
3
+ Version 2.0, January 2004
4
+ http://www.apache.org/licenses/
5
+
6
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
7
+
8
+ 1. Definitions.
9
+
10
+ "License" shall mean the terms and conditions for use, reproduction,
11
+ and distribution as defined by Sections 1 through 9 of this document.
12
+
13
+ "Licensor" shall mean the copyright owner or entity authorized by
14
+ the copyright owner that is granting the License.
15
+
16
+ "Legal Entity" shall mean the union of the acting entity and all
17
+ other entities that control, are controlled by, or are under common
18
+ control with that entity. For the purposes of this definition,
19
+ "control" means (i) the power, direct or indirect, to cause the
20
+ direction or management of such entity, whether by contract or
21
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
22
+ outstanding shares, or (iii) beneficial ownership of such entity.
23
+
24
+ "You" (or "Your") shall mean an individual or Legal Entity
25
+ exercising permissions granted by this License.
26
+
27
+ "Source" form shall mean the preferred form for making modifications,
28
+ including but not limited to software source code, documentation
29
+ source, and configuration files.
30
+
31
+ "Object" form shall mean any form resulting from mechanical
32
+ transformation or translation of a Source form, including but
33
+ not limited to compiled object code, generated documentation,
34
+ and conversions to other media types.
35
+
36
+ "Work" shall mean the work of authorship, whether in Source or
37
+ Object form, made available under the License, as indicated by a
38
+ copyright notice that is included in or attached to the work
39
+ (an example is provided in the Appendix below).
40
+
41
+ "Derivative Works" shall mean any work, whether in Source or Object
42
+ form, that is based on (or derived from) the Work and for which the
43
+ editorial revisions, annotations, elaborations, or other modifications
44
+ represent, as a whole, an original work of authorship. For the purposes
45
+ of this License, Derivative Works shall not include works that remain
46
+ separable from, or merely link (or bind by name) to the interfaces of,
47
+ the Work and Derivative Works thereof.
48
+
49
+ "Contribution" shall mean any work of authorship, including
50
+ the original version of the Work and any modifications or additions
51
+ to that Work or Derivative Works thereof, that is intentionally
52
+ submitted to Licensor for inclusion in the Work by the copyright owner
53
+ or by an individual or Legal Entity authorized to submit on behalf of
54
+ the copyright owner. For the purposes of this definition, "submitted"
55
+ means any form of electronic, verbal, or written communication sent
56
+ to the Licensor or its representatives, including but not limited to
57
+ communication on electronic mailing lists, source code control systems,
58
+ and issue tracking systems that are managed by, or on behalf of, the
59
+ Licensor for the purpose of discussing and improving the Work, but
60
+ excluding communication that is conspicuously marked or otherwise
61
+ designated in writing by the copyright owner as "Not a Contribution."
62
+
63
+ "Contributor" shall mean Licensor and any individual or Legal Entity
64
+ on behalf of whom a Contribution has been received by Licensor and
65
+ subsequently incorporated within the Work.
66
+
67
+ 2. Grant of Copyright License. Subject to the terms and conditions of
68
+ this License, each Contributor hereby grants to You a perpetual,
69
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
70
+ copyright license to reproduce, prepare Derivative Works of,
71
+ publicly display, publicly perform, sublicense, and distribute the
72
+ Work and such Derivative Works in Source or Object form.
73
+
74
+ 3. Grant of Patent License. Subject to the terms and conditions of
75
+ this License, each Contributor hereby grants to You a perpetual,
76
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
77
+ (except as stated in this section) patent license to make, have made,
78
+ use, offer to sell, sell, import, and otherwise transfer the Work,
79
+ where such license applies only to those patent claims licensable
80
+ by such Contributor that are necessarily infringed by their
81
+ Contribution(s) alone or by combination of their Contribution(s)
82
+ with the Work to which such Contribution(s) was submitted. If You
83
+ institute patent litigation against any entity (including a
84
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
85
+ or a Contribution incorporated within the Work constitutes direct
86
+ or contributory patent infringement, then any patent licenses
87
+ granted to You under this License for that Work shall terminate
88
+ as of the date such litigation is filed.
89
+
90
+ 4. Redistribution. You may reproduce and distribute copies of the
91
+ Work or Derivative Works thereof in any medium, with or without
92
+ modifications, and in Source or Object form, provided that You
93
+ meet the following conditions:
94
+
95
+ (a) You must give any other recipients of the Work or
96
+ Derivative Works a copy of this License; and
97
+
98
+ (b) You must cause any modified files to carry prominent notices
99
+ stating that You changed the files; and
100
+
101
+ (c) You must retain, in the Source form of any Derivative Works
102
+ that You distribute, all copyright, patent, trademark, and
103
+ attribution notices from the Source form of the Work,
104
+ excluding those notices that do not pertain to any part of
105
+ the Derivative Works; and
106
+
107
+ (d) If the Work includes a "NOTICE" text file as part of its
108
+ distribution, then any Derivative Works that You distribute must
109
+ include a readable copy of the attribution notices contained
110
+ within such NOTICE file, excluding those notices that do not
111
+ pertain to any part of the Derivative Works, in at least one
112
+ of the following places: within a NOTICE text file distributed
113
+ as part of the Derivative Works; within the Source form or
114
+ documentation, if provided along with the Derivative Works; or,
115
+ within a display generated by the Derivative Works, if and
116
+ wherever such third-party notices normally appear. The contents
117
+ of the NOTICE file are for informational purposes only and
118
+ do not modify the License. You may add Your own attribution
119
+ notices within Derivative Works that You distribute, alongside
120
+ or as an addendum to the NOTICE text from the Work, provided
121
+ that such additional attribution notices cannot be construed
122
+ as modifying the License.
123
+
124
+ You may add Your own copyright statement to Your modifications and
125
+ may provide additional or different license terms and conditions
126
+ for use, reproduction, or distribution of Your modifications, or
127
+ for any such Derivative Works as a whole, provided Your use,
128
+ reproduction, and distribution of the Work otherwise complies with
129
+ the conditions stated in this License.
130
+
131
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
132
+ any Contribution intentionally submitted for inclusion in the Work
133
+ by You to the Licensor shall be under the terms and conditions of
134
+ this License, without any additional terms or conditions.
135
+ Notwithstanding the above, nothing herein shall supersede or modify
136
+ the terms of any separate license agreement you may have executed
137
+ with Licensor regarding such Contributions.
138
+
139
+ 6. Trademarks. This License does not grant permission to use the trade
140
+ names, trademarks, service marks, or product names of the Licensor,
141
+ except as required for reasonable and customary use in describing the
142
+ origin of the Work and reproducing the content of the NOTICE file.
143
+
144
+ 7. Disclaimer of Warranty. Unless required by applicable law or
145
+ agreed to in writing, Licensor provides the Work (and each
146
+ Contributor provides its Contributions) on an "AS IS" BASIS,
147
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
148
+ implied, including, without limitation, any warranties or conditions
149
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
150
+ PARTICULAR PURPOSE. You are solely responsible for determining the
151
+ appropriateness of using or redistributing the Work and assume any
152
+ risks associated with Your exercise of permissions under this License.
153
+
154
+ 8. Limitation of Liability. In no event and under no legal theory,
155
+ whether in tort (including negligence), contract, or otherwise,
156
+ unless required by applicable law (such as deliberate and grossly
157
+ negligent acts) or agreed to in writing, shall any Contributor be
158
+ liable to You for damages, including any direct, indirect, special,
159
+ incidental, or consequential damages of any character arising as a
160
+ result of this License or out of the use or inability to use the
161
+ Work (including but not limited to damages for loss of goodwill,
162
+ work stoppage, computer failure or malfunction, or any and all
163
+ other commercial damages or losses), even if such Contributor
164
+ has been advised of the possibility of such damages.
165
+
166
+ 9. Accepting Warranty or Additional Liability. While redistributing
167
+ the Work or Derivative Works thereof, You may choose to offer,
168
+ and charge a fee for, acceptance of support, warranty, indemnity,
169
+ or other liability obligations and/or rights consistent with this
170
+ License. However, in accepting such obligations, You may act only
171
+ on Your own behalf and on Your sole responsibility, not on behalf
172
+ of any other Contributor, and only if You agree to indemnify,
173
+ defend, and hold each Contributor harmless for any liability
174
+ incurred by, or claims asserted against, such Contributor by reason
175
+ of your accepting any such warranty or additional liability.
176
+
177
+ END OF TERMS AND CONDITIONS
178
+
179
+ APPENDIX: How to apply the Apache License to your work.
180
+
181
+ To apply the Apache License to your work, attach the following
182
+ boilerplate notice, with the fields enclosed by brackets "[]"
183
+ replaced with your own identifying information. (Don't include
184
+ the brackets!) The text should be enclosed in the appropriate
185
+ comment syntax for the file format. We also recommend that a
186
+ file or class name and description of purpose be included on the
187
+ same "printed page" as the copyright notice for easier
188
+ identification within third-party archives.
189
+
190
+ Copyright [yyyy] [name of copyright owner]
191
+
192
+ Licensed under the Apache License, Version 2.0 (the "License");
193
+ you may not use this file except in compliance with the License.
194
+ You may obtain a copy of the License at
195
+
196
+ http://www.apache.org/licenses/LICENSE-2.0
197
+
198
+ Unless required by applicable law or agreed to in writing, software
199
+ distributed under the License is distributed on an "AS IS" BASIS,
200
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
201
+ See the License for the specific language governing permissions and
202
+ limitations under the License.
package/NOTICE ADDED
@@ -0,0 +1,5 @@
1
+ Open Artifacts
2
+ Copyright 2026 Jim Liu 宝玉
3
+
4
+ This product is licensed under the Apache License, Version 2.0 (see LICENSE).
5
+ It was formerly published as baoyu-design.
package/README.md CHANGED
@@ -1,3 +1,6 @@
1
- # Temporary Holding Version
1
+ # @openartifactsai/whiteboard-core
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ The Whiteboard artifact model: element schema and normalization, the document codec, geometry, arrows, hand-drawn ink, history, view context and the live sync engine.
4
+
5
+ Part of [Open Artifacts](https://github.com/openartifactsai/open-artifacts): slide decks, design canvases and whiteboards an agent makes
6
+ and you view, edit and comment on in one local page. Source: [`packages/whiteboard-core`](https://github.com/openartifactsai/open-artifacts/tree/main/packages/whiteboard-core).
package/package.json CHANGED
@@ -1,6 +1,40 @@
1
1
  {
2
2
  "name": "@openartifactsai/whiteboard-core",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
6
- }
3
+ "version": "0.23.0",
4
+ "description": "The Whiteboard artifact model: element schema and normalization, the document codec, geometry, arrows, hand-drawn ink, history, view context and the live sync engine.",
5
+ "type": "module",
6
+ "exports": {
7
+ ".": {
8
+ "types": "./src/index.d.ts",
9
+ "default": "./src/index.js"
10
+ },
11
+ "./package.json": "./package.json"
12
+ },
13
+ "files": [
14
+ "src",
15
+ "LICENSE",
16
+ "NOTICE"
17
+ ],
18
+ "dependencies": {
19
+ "@openartifactsai/live-store": "0.23.0",
20
+ "@openartifactsai/protocol": "0.23.0",
21
+ "@openartifactsai/wasm-wb-geom": "0.23.0"
22
+ },
23
+ "license": "Apache-2.0",
24
+ "author": {
25
+ "name": "Jim Liu 宝玉",
26
+ "url": "https://github.com/JimLiu"
27
+ },
28
+ "homepage": "https://github.com/openartifactsai/open-artifacts#readme",
29
+ "repository": {
30
+ "type": "git",
31
+ "url": "git+https://github.com/openartifactsai/open-artifacts.git",
32
+ "directory": "packages/whiteboard-core"
33
+ },
34
+ "bugs": {
35
+ "url": "https://github.com/openartifactsai/open-artifacts/issues"
36
+ },
37
+ "publishConfig": {
38
+ "access": "public"
39
+ }
40
+ }
@@ -0,0 +1,78 @@
1
+ /**
2
+ * Links between the elements of a board: a link card, a linked picture or a
3
+ * link in text that points at `#element=<id>` (see `links.ts`). Which element
4
+ * a link points at, what a card to it is titled, and how copies keep their
5
+ * links pointing where they should.
6
+ *
7
+ * DOM-free; the editor follows the links and draws the cards.
8
+ */
9
+ import { type BoardElement, type ElementId, type ElementType, type LinkElement } from './schema.js';
10
+ /** What a card to an element of the same board calls the element's kind. */
11
+ export declare const ANCHOR_KIND_LABELS: Readonly<Record<ElementType, string>>;
12
+ /** The line under the title of a card to an element of the same board. */
13
+ export declare const ON_THIS_BOARD = "On this board";
14
+ /** The line under the title of a card whose element is gone. */
15
+ export declare const NOT_ON_THIS_BOARD = "Not on this board";
16
+ /** Every link an element holds, as stored: a card's or picture's address and the targets of the links in its text. */
17
+ export declare function elementLinkHrefs(element: BoardElement): string[];
18
+ /** The ids of the elements of the same board an element links to, without repeats. */
19
+ export declare function anchoredIds(element: BoardElement): ElementId[];
20
+ /**
21
+ * The element of this board a stored link points at: `#element=<id>`, or the
22
+ * address of this very board (`here`) at `#element=<id>`. `undefined` for
23
+ * links elsewhere.
24
+ */
25
+ export declare function linkedElementId(href: string, here?: string): ElementId | undefined;
26
+ /** The title a card to `target` shows: its words (a section's title, a note's first line), else its kind. */
27
+ export declare function anchorTitle(target: BoardElement): string;
28
+ /** The line under the title of a card to `target` (`undefined`: the element is gone). */
29
+ export declare function anchorSubtitle(target: BoardElement | undefined): string;
30
+ /** The title of a card to an element that is gone and had no title stored. */
31
+ export declare const MISSING_ANCHOR_TITLE = "Missing item";
32
+ /** What a link card shows. */
33
+ export interface LinkCardFace {
34
+ title: string;
35
+ subtitle: string;
36
+ /** The element of this board it points at, if it does. */
37
+ anchored?: ElementId;
38
+ /** It points at an element of this board that is not on it. */
39
+ gone: boolean;
40
+ }
41
+ /**
42
+ * What a link card shows: a card to an element of this board (`here` is
43
+ * this board's artifact id, when known) shows the element's title and kind
44
+ * as they are now, and its stored title once the element is gone; any
45
+ * other card its stored title and kind or address.
46
+ */
47
+ export declare function linkCardFace(link: LinkElement, byId: ReadonlyMap<ElementId, BoardElement>, here?: string): LinkCardFace;
48
+ /**
49
+ * The element with every link passed through `rewrite` (which returns the
50
+ * new target, or `undefined` to keep it). The element itself when nothing
51
+ * changes.
52
+ */
53
+ export declare function rewriteElementLinks<T extends BoardElement>(element: T, rewrite: (href: string) => string | undefined): T;
54
+ /** Where copied elements come from and go to: the artifact ids of both boards, when known. */
55
+ export interface CopiedLinkBoards {
56
+ /** The board the elements were copied from. */
57
+ from?: string;
58
+ /** The board they land on. */
59
+ here?: string;
60
+ }
61
+ /**
62
+ * Copies with their links kept pointing where they should (`idMap`: source
63
+ * id to copy id):
64
+ * - a link to an element copied with it points at that element's copy;
65
+ * - a link to an element left behind keeps pointing at it: on the same
66
+ * board as it is, on another board through the source board's address
67
+ * (`open-artifacts://artifact/<from>#element=<id>`);
68
+ * - a link to an element of the destination board through that board's
69
+ * address becomes a plain `#element=<id>`.
70
+ */
71
+ export declare function relinkCopies(copies: readonly BoardElement[], idMap: ReadonlyMap<ElementId, ElementId>, boards?: CopiedLinkBoards): BoardElement[];
72
+ /**
73
+ * The board's other elements with their links to cut elements (`idMap`:
74
+ * the id each had to the id of its pasted copy) moved to the copies, so
75
+ * cutting and pasting an element on the same board keeps the links to it.
76
+ * Only links to elements no longer on the board move.
77
+ */
78
+ export declare function followPastedLinks(elements: readonly BoardElement[], idMap: ReadonlyMap<ElementId, ElementId>): BoardElement[];
package/src/anchors.js ADDED
@@ -0,0 +1,215 @@
1
+ /**
2
+ * Links between the elements of a board: a link card, a linked picture or a
3
+ * link in text that points at `#element=<id>` (see `links.ts`). Which element
4
+ * a link points at, what a card to it is titled, and how copies keep their
5
+ * links pointing where they should.
6
+ *
7
+ * DOM-free; the editor follows the links and draws the cards.
8
+ */
9
+ import { artifactAddress, artifactAddressParts, ELEMENT_ANCHOR_PREFIX, elementAnchor, elementAnchorId, linkSubtitle, linkTitle, sanitizeShortLabel } from "./links.js";
10
+ import { MAX_LINK_TITLE_CHARS, elementPlainText } from "./schema.js";
11
+ import { stripInlineMarkers, stripMarkdownLinks, tableColumnIds, tableRowIds } from "./table.js";
12
+ import { MARKDOWN_LINK_PATTERN, TEXT_LINK_PATTERN } from "./text/inline-markdown.js";
13
+ /** What a card to an element of the same board calls the element's kind. */
14
+ export const ANCHOR_KIND_LABELS = {
15
+ note: 'Sticky note',
16
+ shape: 'Shape',
17
+ text: 'Text',
18
+ container: 'Section',
19
+ arrow: 'Arrow',
20
+ sticker: 'Sticker',
21
+ image: 'Image',
22
+ stroke: 'Sketch',
23
+ timer: 'Timer',
24
+ html: 'Web embed',
25
+ link: 'Link card',
26
+ table: 'Table',
27
+ };
28
+ /** The line under the title of a card to an element of the same board. */
29
+ export const ON_THIS_BOARD = 'On this board';
30
+ /** The line under the title of a card whose element is gone. */
31
+ export const NOT_ON_THIS_BOARD = 'Not on this board';
32
+ /* -------------------------------------------------------------------------- */
33
+ /* Reading links */
34
+ /* -------------------------------------------------------------------------- */
35
+ /** The texts of an element that may hold Markdown links. */
36
+ function linkableTexts(element) {
37
+ switch (element.type) {
38
+ case 'note':
39
+ case 'shape':
40
+ case 'text':
41
+ return [element.text];
42
+ case 'table':
43
+ return Object.values(element.rows).flatMap((row) => Object.entries(row).flatMap(([key, value]) => (key !== 'at' && typeof value === 'string' ? [value] : [])));
44
+ default:
45
+ return [];
46
+ }
47
+ }
48
+ /** Every link an element holds, as stored: a card's or picture's address and the targets of the links in its text. */
49
+ export function elementLinkHrefs(element) {
50
+ const hrefs = [];
51
+ if (element.type === 'link')
52
+ hrefs.push(element.href);
53
+ if (element.type === 'image' && element.href !== undefined)
54
+ hrefs.push(element.href);
55
+ for (const text of linkableTexts(element)) {
56
+ for (const match of text.matchAll(MARKDOWN_LINK_PATTERN))
57
+ if (match[1] !== undefined && TEXT_LINK_PATTERN.test(match[1]))
58
+ hrefs.push(match[1]);
59
+ }
60
+ return hrefs;
61
+ }
62
+ /** The ids of the elements of the same board an element links to, without repeats. */
63
+ export function anchoredIds(element) {
64
+ return [...new Set(elementLinkHrefs(element).flatMap((href) => elementAnchorId(href) ?? []))];
65
+ }
66
+ /**
67
+ * The element of this board a stored link points at: `#element=<id>`, or the
68
+ * address of this very board (`here`) at `#element=<id>`. `undefined` for
69
+ * links elsewhere.
70
+ */
71
+ export function linkedElementId(href, here) {
72
+ const anchored = elementAnchorId(href);
73
+ if (anchored !== undefined)
74
+ return anchored;
75
+ if (here === undefined)
76
+ return undefined;
77
+ const parts = artifactAddressParts(href);
78
+ return parts?.artifact === here ? elementAnchorId(parts.place) : undefined;
79
+ }
80
+ /* -------------------------------------------------------------------------- */
81
+ /* Titles */
82
+ /* -------------------------------------------------------------------------- */
83
+ /** The first line of some markup with something to show, without link targets, markers or a list bullet. */
84
+ function firstShownLine(text) {
85
+ for (const line of stripInlineMarkers(stripMarkdownLinks(text)).split('\n')) {
86
+ const shown = sanitizeShortLabel(line.replace(/^ *(?:[-•*]|\d{1,3}\.) /, ''), MAX_LINK_TITLE_CHARS);
87
+ if (shown !== '')
88
+ return shown;
89
+ }
90
+ return '';
91
+ }
92
+ /** The words of a table's first row, joined. */
93
+ function firstRowText(element) {
94
+ const row = tableRowIds(element)[0];
95
+ if (row === undefined)
96
+ return '';
97
+ const cells = tableColumnIds(element).map((column) => element.rows[row]?.[column]);
98
+ return firstShownLine(cells.filter((cell) => typeof cell === 'string' && cell.trim() !== '').join(', '));
99
+ }
100
+ /** The title a card to `target` shows: its words (a section's title, a note's first line), else its kind. */
101
+ export function anchorTitle(target) {
102
+ switch (target.type) {
103
+ case 'link':
104
+ return linkTitle(target);
105
+ case 'table':
106
+ return firstRowText(target) || ANCHOR_KIND_LABELS.table;
107
+ default:
108
+ return firstShownLine(elementPlainText(target)) || (target.type === 'container' ? 'Untitled section' : ANCHOR_KIND_LABELS[target.type]);
109
+ }
110
+ }
111
+ /** The line under the title of a card to `target` (`undefined`: the element is gone). */
112
+ export function anchorSubtitle(target) {
113
+ return target === undefined ? NOT_ON_THIS_BOARD : `${ANCHOR_KIND_LABELS[target.type]} · ${ON_THIS_BOARD}`;
114
+ }
115
+ /** The title of a card to an element that is gone and had no title stored. */
116
+ export const MISSING_ANCHOR_TITLE = 'Missing item';
117
+ /**
118
+ * What a link card shows: a card to an element of this board (`here` is
119
+ * this board's artifact id, when known) shows the element's title and kind
120
+ * as they are now, and its stored title once the element is gone; any
121
+ * other card its stored title and kind or address.
122
+ */
123
+ export function linkCardFace(link, byId, here) {
124
+ const anchored = linkedElementId(link.href, here);
125
+ if (anchored === undefined)
126
+ return { title: linkTitle(link), subtitle: linkSubtitle(link), gone: false };
127
+ const target = byId.get(anchored);
128
+ return { title: target === undefined ? (link.title ?? MISSING_ANCHOR_TITLE) : anchorTitle(target), subtitle: anchorSubtitle(target), anchored, gone: target === undefined };
129
+ }
130
+ /* -------------------------------------------------------------------------- */
131
+ /* Rewriting links */
132
+ /* -------------------------------------------------------------------------- */
133
+ /**
134
+ * The element with every link passed through `rewrite` (which returns the
135
+ * new target, or `undefined` to keep it). The element itself when nothing
136
+ * changes.
137
+ */
138
+ export function rewriteElementLinks(element, rewrite) {
139
+ const swap = (href) => rewrite(href) ?? href;
140
+ const inText = (text) => text.includes('](') ? text.replace(MARKDOWN_LINK_PATTERN, (whole, href) => (TEXT_LINK_PATTERN.test(href) ? whole.slice(0, whole.length - href.length - 1) + swap(href) + ')' : whole)) : text;
141
+ let next = element;
142
+ if (element.type === 'link') {
143
+ const href = swap(element.href);
144
+ if (href !== element.href)
145
+ next = { ...element, href };
146
+ }
147
+ else if (element.type === 'image' && element.href !== undefined) {
148
+ const href = swap(element.href);
149
+ if (href !== element.href)
150
+ next = { ...element, href };
151
+ }
152
+ else if (element.type === 'note' || element.type === 'shape' || element.type === 'text') {
153
+ const text = inText(element.text);
154
+ if (text !== element.text)
155
+ next = { ...element, text };
156
+ }
157
+ else if (element.type === 'table') {
158
+ let changed = false;
159
+ const rows = Object.fromEntries(Object.entries(element.rows).map(([rowId, row]) => [
160
+ rowId,
161
+ Object.fromEntries(Object.entries(row).map(([key, value]) => {
162
+ if (key === 'at' || typeof value !== 'string')
163
+ return [key, value];
164
+ const text = inText(value);
165
+ if (text !== value)
166
+ changed = true;
167
+ return [key, text];
168
+ })),
169
+ ]));
170
+ if (changed)
171
+ next = { ...element, rows };
172
+ }
173
+ return next;
174
+ }
175
+ /**
176
+ * Copies with their links kept pointing where they should (`idMap`: source
177
+ * id to copy id):
178
+ * - a link to an element copied with it points at that element's copy;
179
+ * - a link to an element left behind keeps pointing at it: on the same
180
+ * board as it is, on another board through the source board's address
181
+ * (`open-artifacts://artifact/<from>#element=<id>`);
182
+ * - a link to an element of the destination board through that board's
183
+ * address becomes a plain `#element=<id>`.
184
+ */
185
+ export function relinkCopies(copies, idMap, boards = {}) {
186
+ const elsewhere = boards.from !== undefined && boards.here !== undefined && boards.from !== boards.here;
187
+ return copies.map((copy) => rewriteElementLinks(copy, (href) => {
188
+ const anchored = elementAnchorId(href);
189
+ if (anchored !== undefined) {
190
+ const copied = idMap.get(anchored);
191
+ if (copied !== undefined)
192
+ return elementAnchor(copied);
193
+ return elsewhere ? artifactAddress(boards.from, ELEMENT_ANCHOR_PREFIX + anchored) : undefined;
194
+ }
195
+ const parts = artifactAddressParts(href);
196
+ if (parts === undefined || boards.here === undefined || parts.artifact !== boards.here)
197
+ return undefined;
198
+ const target = elementAnchorId(parts.place);
199
+ return target === undefined ? undefined : elementAnchor(target);
200
+ }));
201
+ }
202
+ /**
203
+ * The board's other elements with their links to cut elements (`idMap`:
204
+ * the id each had to the id of its pasted copy) moved to the copies, so
205
+ * cutting and pasting an element on the same board keeps the links to it.
206
+ * Only links to elements no longer on the board move.
207
+ */
208
+ export function followPastedLinks(elements, idMap) {
209
+ const present = new Set(elements.map((element) => element.id));
210
+ return elements.map((element) => rewriteElementLinks(element, (href) => {
211
+ const anchored = elementAnchorId(href);
212
+ const copied = anchored !== undefined && !present.has(anchored) ? idMap.get(anchored) : undefined;
213
+ return copied === undefined ? undefined : elementAnchor(copied);
214
+ }));
215
+ }
@@ -0,0 +1,61 @@
1
+ /**
2
+ * Dragging one leg of an elbow arrow sideways to bend its route.
3
+ *
4
+ * A selected elbow arrow shows a handle on each leg that can move. Dragging
5
+ * it slides the leg across its own direction (neighboring legs stretch) and
6
+ * stores the new route as manual `bends`. A drag that lands back on the
7
+ * automatic route, or on the straight line between the ends, clears the
8
+ * bends instead, so an arrow straightens by being dragged back into line.
9
+ *
10
+ * The leg handle and clearance math runs in WebAssembly
11
+ * (`crates/open-artifacts-wb-geom/src/bend_drag.rs`). The drag itself stays here: it
12
+ * combines board lookups and arrow layouts that already run there.
13
+ */
14
+ import { type ArrowBends, type ArrowElement } from '../schema.js';
15
+ import type { ArrowLabelBox } from './labels.js';
16
+ import { type ArrowGeometry, type BoardIndex, type ElementLayoutBoxResolver } from './layout.js';
17
+ import { type RoutePoint } from './routing.js';
18
+ /** How close (screen pixels) a dragged leg counts as back on the automatic route. */
19
+ export declare const ARROW_LEG_GRAB_PX = 4;
20
+ /** Extra room a fitted manual route must keep from the end boxes to count as routable. */
21
+ export declare const BEND_FIT_TOLERANCE = 4;
22
+ /** Handle reach from an arrow end, screen pixels: a leg handle this close to an end moves along the leg. */
23
+ export declare const ARROW_LEG_HANDLE_REACH: {
24
+ readonly fine: 24;
25
+ readonly coarse: 40;
26
+ };
27
+ /**
28
+ * The shortest end leg each end of `route` must keep: room for the arrow
29
+ * head (bounded by how long the end leg already is, on this route or the
30
+ * automatic one), or the plain minimum for an end without a head.
31
+ */
32
+ export declare function arrowEndClearances(arrow: ArrowElement, route: readonly RoutePoint[], board: BoardIndex, layoutBox: ElementLayoutBoxResolver): [number, number];
33
+ /**
34
+ * What dragging leg `leg` of `route` to the point `x, y` does to the
35
+ * arrow's manual route:
36
+ * - `'same'`: the leg cannot move there (nothing changes);
37
+ * - bends: the new manual route;
38
+ * - `null`: the drag lands on the automatic or straight route (clear the bends);
39
+ * - `undefined`: no valid route (keep the last one).
40
+ *
41
+ * `tolerance` is how close (board units) counts as landing on a route.
42
+ */
43
+ export declare function bendsForDraggedSegment(arrow: ArrowElement, route: readonly RoutePoint[], leg: number, x: number, y: number, tolerance: number, board: BoardIndex, layoutBox: ElementLayoutBoxResolver): ArrowBends | null | undefined | 'same';
44
+ /** A handle that drags one leg of an arrow. */
45
+ export interface ArrowLegHandle {
46
+ /** Index of the leg (it runs from route point `leg` to `leg + 1`). */
47
+ leg: number;
48
+ /** Where the handle sits, board units. */
49
+ x: number;
50
+ y: number;
51
+ /** Whether the leg runs horizontally (the handle drags up and down). */
52
+ level: boolean;
53
+ }
54
+ /**
55
+ * The leg handles of a selected arrow drawn as `line`: one at the middle of
56
+ * each leg that can move, slid along the leg off the label and away from the
57
+ * end handles. A straight arrow gets no handle too close to its ends.
58
+ *
59
+ * `zoom` is the camera zoom; `coarse` is a touch pointer (wider reach).
60
+ */
61
+ export declare function arrowLegHandles(arrow: ArrowElement, line: ArrowGeometry, board: BoardIndex, layoutBox: ElementLayoutBoxResolver, label: ArrowLabelBox | undefined, zoom: number, coarse: boolean): ArrowLegHandle[];