@molecule/app-annotation-pin-svelte 0.0.0-stage → 1.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.
- package/LICENSE +202 -0
- package/README.md +210 -2
- package/dist/AnnotationLayer.svelte +106 -0
- package/dist/AnnotationLayer.svelte.d.ts +5 -0
- package/dist/AnnotationLayer.svelte.d.ts.map +1 -0
- package/dist/AnnotationPin.svelte +162 -0
- package/dist/AnnotationPin.svelte.d.ts +5 -0
- package/dist/AnnotationPin.svelte.d.ts.map +1 -0
- package/dist/components.d.ts +9 -0
- package/dist/components.d.ts.map +1 -0
- package/dist/components.js +8 -0
- package/dist/css.d.ts +19 -0
- package/dist/css.d.ts.map +1 -0
- package/dist/css.js +72 -0
- package/dist/index.d.ts +52 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +51 -0
- package/dist/types.d.ts +107 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +7 -0
- package/package.json +74 -4
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/README.md
CHANGED
|
@@ -1,3 +1,211 @@
|
|
|
1
|
-
|
|
1
|
+
<!--
|
|
2
|
+
AUTO-GENERATED — DO NOT EDIT THIS FILE.
|
|
3
|
+
Generated by `mlcl sync-docs` from the package's src/index.ts JSDoc + mlcl/registry.json.
|
|
4
|
+
Edits here are overwritten on the next commit (molecule's pre-commit hook regenerates).
|
|
5
|
+
To change this document, edit the module-level JSDoc in src/index.ts.
|
|
6
|
+
Generated: 2026-11-16T18:56:21.388Z
|
|
7
|
+
-->
|
|
2
8
|
|
|
3
|
-
|
|
9
|
+
# @molecule/app-annotation-pin-svelte
|
|
10
|
+
|
|
11
|
+
Svelte annotation pin / hotspot overlay primitives — the Svelte counterpart
|
|
12
|
+
of `@molecule/app-annotation-pin-react`: same props (React names) and the
|
|
13
|
+
same DOM for the same input, so an app switches framework by changing only
|
|
14
|
+
the package name in its imports.
|
|
15
|
+
|
|
16
|
+
Exports `AnnotationPin` (single click-to-toggle marker) and
|
|
17
|
+
`AnnotationLayer` (parent wrapper that manages many pins on a surface).
|
|
18
|
+
Reusable for 3d-model viewers, image annotations, map pins, and hotspot
|
|
19
|
+
tours.
|
|
20
|
+
|
|
21
|
+
> **Auto-generated, AI-first package reference** for the [molecule.dev](https://molecule.dev) ecosystem.
|
|
22
|
+
> It is written to be read by coding agents as much as by people, and is generated from this
|
|
23
|
+
> package's source — edit `src/index.ts` JSDoc, not this file.
|
|
24
|
+
|
|
25
|
+
## Quick Start
|
|
26
|
+
|
|
27
|
+
```svelte
|
|
28
|
+
<script lang="ts">
|
|
29
|
+
import { AnnotationLayer, type Pin } from '@molecule/app-annotation-pin-svelte'
|
|
30
|
+
|
|
31
|
+
let pins = $state<Pin[]>([])
|
|
32
|
+
let activeId = $state<string | null>(null)
|
|
33
|
+
|
|
34
|
+
function addPin({ x, y }: { x: number; y: number }): void {
|
|
35
|
+
const id = crypto.randomUUID()
|
|
36
|
+
pins = [...pins, { id, position: { x, y }, label: pins.length + 1 }]
|
|
37
|
+
activeId = id
|
|
38
|
+
}
|
|
39
|
+
</script>
|
|
40
|
+
|
|
41
|
+
<AnnotationLayer
|
|
42
|
+
{pins}
|
|
43
|
+
activePinId={activeId}
|
|
44
|
+
onPinClick={(id) => (activeId = id === activeId ? null : id)}
|
|
45
|
+
onSurfaceClick={addPin}
|
|
46
|
+
>
|
|
47
|
+
<img src="/floorplan.png" alt="" style="width: 100%; display: block" />
|
|
48
|
+
</AnnotationLayer>
|
|
49
|
+
```
|
|
50
|
+
|
|
51
|
+
## Type
|
|
52
|
+
|
|
53
|
+
`feature`
|
|
54
|
+
|
|
55
|
+
## Installation
|
|
56
|
+
|
|
57
|
+
```bash
|
|
58
|
+
npm install @molecule/app-annotation-pin-svelte @molecule/app-svelte @molecule/app-ui @molecule/app-ui-svelte svelte
|
|
59
|
+
```
|
|
60
|
+
|
|
61
|
+
## API
|
|
62
|
+
|
|
63
|
+
### Interfaces
|
|
64
|
+
|
|
65
|
+
#### `Pin`
|
|
66
|
+
|
|
67
|
+
A single pin to display on a parent surface. `position` is in the
|
|
68
|
+
parent's coordinate space — for image / 2D-canvas overlays this is
|
|
69
|
+
normalised 0..1 (so the pin re-anchors as the surface resizes); for
|
|
70
|
+
pixel-positioned overlays callers can pass raw px values and provide
|
|
71
|
+
their own `style` overrides via `className`.
|
|
72
|
+
|
|
73
|
+
The label/note are pure data — components handle render only. Surfaces
|
|
74
|
+
supply pin objects via `<AnnotationLayer {pins}>` (or render a single pin
|
|
75
|
+
directly if there is only one).
|
|
76
|
+
|
|
77
|
+
```typescript
|
|
78
|
+
interface Pin {
|
|
79
|
+
/** Stable identifier (used as the list key). */
|
|
80
|
+
id: string
|
|
81
|
+
/** Position in the parent surface's coordinate space (typically normalised 0..1). */
|
|
82
|
+
position: { x: number; y: number }
|
|
83
|
+
/** Short label (e.g. an index or single-word tag) shown inside the pin marker. */
|
|
84
|
+
label?: Snippet | string | number | null | undefined
|
|
85
|
+
/** Longer note / description body, shown inside the popup when the pin is selected. */
|
|
86
|
+
note?: Snippet | string | number | null | undefined
|
|
87
|
+
}
|
|
88
|
+
```
|
|
89
|
+
|
|
90
|
+
#### `AnnotationPinProps`
|
|
91
|
+
|
|
92
|
+
`<AnnotationPin>` props.
|
|
93
|
+
|
|
94
|
+
```typescript
|
|
95
|
+
interface AnnotationPinProps {
|
|
96
|
+
/** Position in the parent surface's coordinate space (typically normalised 0..1). */
|
|
97
|
+
position: { x: number; y: number }
|
|
98
|
+
/** Short label (e.g. an index or single-word tag) shown inside the marker. */
|
|
99
|
+
label?: Snippet | string | number | null | undefined
|
|
100
|
+
/** Longer note shown inside the popup when the pin is selected. */
|
|
101
|
+
note?: Snippet | string | number | null | undefined
|
|
102
|
+
/**
|
|
103
|
+
* Whether the pin is currently selected. When `true` the popup is
|
|
104
|
+
* rendered. Selection is controlled — callers manage state in
|
|
105
|
+
* `<AnnotationLayer>` (or themselves) and update via `onClick`.
|
|
106
|
+
*/
|
|
107
|
+
selected?: boolean
|
|
108
|
+
/** Click handler — fires when the pin marker is clicked. */
|
|
109
|
+
onClick?: () => void
|
|
110
|
+
/**
|
|
111
|
+
* Side the popup renders on, relative to the marker. Defaults to `'right'`.
|
|
112
|
+
*/
|
|
113
|
+
popupSide?: 'top' | 'bottom' | 'left' | 'right'
|
|
114
|
+
/** Extra classes merged onto the root wrapper. */
|
|
115
|
+
className?: string
|
|
116
|
+
/**
|
|
117
|
+
* Whether `position` is normalised (0..1) — when `true` the wrapper
|
|
118
|
+
* positions itself with `%` units so pins re-anchor on resize. When
|
|
119
|
+
* `false` the wrapper uses raw `px` values. Defaults to `true`.
|
|
120
|
+
*/
|
|
121
|
+
normalised?: boolean
|
|
122
|
+
}
|
|
123
|
+
```
|
|
124
|
+
|
|
125
|
+
#### `AnnotationLayerProps`
|
|
126
|
+
|
|
127
|
+
`<AnnotationLayer>` props.
|
|
128
|
+
|
|
129
|
+
```typescript
|
|
130
|
+
interface AnnotationLayerProps {
|
|
131
|
+
/** Pins to render on the layer. */
|
|
132
|
+
pins: Pin[]
|
|
133
|
+
/** Optional layer content (the surface to annotate — image, canvas, map tile, etc.). */
|
|
134
|
+
children?: Snippet
|
|
135
|
+
/**
|
|
136
|
+
* The currently active (popup-open) pin id, or `null` for none. The
|
|
137
|
+
* layer is fully controlled — callers manage selection state.
|
|
138
|
+
*/
|
|
139
|
+
activePinId?: string | null
|
|
140
|
+
/** Called with the clicked pin id when a pin marker is clicked. */
|
|
141
|
+
onPinClick?: (pinId: string) => void
|
|
142
|
+
/**
|
|
143
|
+
* Called when the user clicks an empty area of the layer (i.e. not on
|
|
144
|
+
* a pin marker or a popup). Coordinates are in the same space as
|
|
145
|
+
* `Pin.position` — normalised 0..1 by default. Keyboard users get the
|
|
146
|
+
* same action: activating the layer's "add pin" button (Tab to it,
|
|
147
|
+
* then Enter / Space) places a pin at the surface centre.
|
|
148
|
+
*/
|
|
149
|
+
onSurfaceClick?: (position: { x: number; y: number }) => void
|
|
150
|
+
/**
|
|
151
|
+
* Whether positions are normalised (0..1) — when `true` the layer
|
|
152
|
+
* computes click coordinates as fractions of its bounding box; when
|
|
153
|
+
* `false` it returns raw pixel offsets. Defaults to `true`.
|
|
154
|
+
*/
|
|
155
|
+
normalised?: boolean
|
|
156
|
+
/**
|
|
157
|
+
* Side the popup renders on, relative to its marker. Defaults to `'right'`.
|
|
158
|
+
*/
|
|
159
|
+
popupSide?: 'top' | 'bottom' | 'left' | 'right'
|
|
160
|
+
/** Extra classes merged onto the layer root. */
|
|
161
|
+
className?: string
|
|
162
|
+
/** Inline style for the layer root, merged over the layer's own. */
|
|
163
|
+
style?: Record<string, string | number>
|
|
164
|
+
}
|
|
165
|
+
```
|
|
166
|
+
|
|
167
|
+
### Constants
|
|
168
|
+
|
|
169
|
+
#### `AnnotationLayer`
|
|
170
|
+
|
|
171
|
+
```typescript
|
|
172
|
+
const AnnotationLayer: LegacyComponentType
|
|
173
|
+
```
|
|
174
|
+
|
|
175
|
+
#### `AnnotationPin`
|
|
176
|
+
|
|
177
|
+
```typescript
|
|
178
|
+
const AnnotationPin: LegacyComponentType
|
|
179
|
+
```
|
|
180
|
+
|
|
181
|
+
## Injection Notes
|
|
182
|
+
|
|
183
|
+
### Requirements
|
|
184
|
+
|
|
185
|
+
Peer dependencies:
|
|
186
|
+
|
|
187
|
+
- `@molecule/app-svelte` ^3.5.0
|
|
188
|
+
- `@molecule/app-ui` ^1.0.1
|
|
189
|
+
- `@molecule/app-ui-svelte` ^1.1.0
|
|
190
|
+
- `svelte` ^5.0.0
|
|
191
|
+
|
|
192
|
+
### Runtime Dependencies
|
|
193
|
+
|
|
194
|
+
- `@molecule/app-svelte`
|
|
195
|
+
- `@molecule/app-ui`
|
|
196
|
+
- `@molecule/app-ui-svelte`
|
|
197
|
+
- `svelte`
|
|
198
|
+
|
|
199
|
+
Selection is fully controlled — the layer never stores the active pin;
|
|
200
|
+
manage `activePinId` yourself and toggle it in `onPinClick`. `position`
|
|
201
|
+
is normalised 0..1 by default (fractions of the layer box, so pins
|
|
202
|
+
re-anchor on resize); pass `normalised={false}` for raw pixel offsets — on
|
|
203
|
+
BOTH `<AnnotationLayer>` and any directly-rendered `<AnnotationPin>`, or
|
|
204
|
+
clicks and markers will disagree. The layer wraps the default content in a
|
|
205
|
+
`position: relative` box; a bare `<AnnotationPin>` needs its own positioned
|
|
206
|
+
ancestor. Node-valued props are snippets (or plain strings). Translations
|
|
207
|
+
come from the companion `@molecule/app-locales-annotation-pin` locale bond.
|
|
208
|
+
|
|
209
|
+
## Translations
|
|
210
|
+
|
|
211
|
+
Translation strings are provided by `@molecule/app-locales-annotation-pin`.
|
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
<!--
|
|
2
|
+
AnnotationLayer: the Svelte counterpart of
|
|
3
|
+
`@molecule/app-annotation-pin-react`'s `AnnotationLayer` — a wrapper that
|
|
4
|
+
renders its children (the annotated surface) and overlays each pin as a
|
|
5
|
+
clickable marker, plus the invisible full-surface "add pin" target when
|
|
6
|
+
`onSurfaceClick` is given. Same props, same DOM for the same input.
|
|
7
|
+
-->
|
|
8
|
+
<script lang="ts">
|
|
9
|
+
import { useTranslation } from '@molecule/app-svelte'
|
|
10
|
+
import { getClassMap } from '@molecule/app-ui'
|
|
11
|
+
|
|
12
|
+
import AnnotationPin from './AnnotationPin.svelte'
|
|
13
|
+
import { styleString } from './css.js'
|
|
14
|
+
import type { AnnotationLayerProps } from './types.js'
|
|
15
|
+
|
|
16
|
+
let {
|
|
17
|
+
pins,
|
|
18
|
+
children,
|
|
19
|
+
activePinId,
|
|
20
|
+
onPinClick,
|
|
21
|
+
onSurfaceClick,
|
|
22
|
+
normalised = true,
|
|
23
|
+
popupSide = 'right',
|
|
24
|
+
className,
|
|
25
|
+
style,
|
|
26
|
+
}: AnnotationLayerProps = $props()
|
|
27
|
+
|
|
28
|
+
const cm = $derived(getClassMap())
|
|
29
|
+
const { t } = useTranslation()
|
|
30
|
+
|
|
31
|
+
const regionLabel = $derived(
|
|
32
|
+
t('annotationPin.aria.layer', {}, { defaultValue: 'Annotation layer' }),
|
|
33
|
+
)
|
|
34
|
+
const addPinLabel = $derived(
|
|
35
|
+
t('annotationPin.aria.addPin', {}, { defaultValue: 'Add annotation pin' }),
|
|
36
|
+
)
|
|
37
|
+
|
|
38
|
+
/** The layer root's style (React's `rootStyle`: the caller's style wins). */
|
|
39
|
+
const rootStyle = $derived(
|
|
40
|
+
styleString({ position: 'relative', width: '100%', height: '100%', ...(style ?? {}) }),
|
|
41
|
+
)
|
|
42
|
+
|
|
43
|
+
// Reset the browser's default button chrome — the add-pin button is an
|
|
44
|
+
// invisible full-surface target, not a visible control.
|
|
45
|
+
const addPinStyle = $derived(
|
|
46
|
+
styleString({ border: 'none', padding: 0, background: 'transparent' }),
|
|
47
|
+
)
|
|
48
|
+
|
|
49
|
+
/**
|
|
50
|
+
* Computes the clicked position relative to the add-pin button's box (which
|
|
51
|
+
* covers the layer) and forwards to `onSurfaceClick`. If `normalised` is
|
|
52
|
+
* `true`, the returned coordinates are 0..1 fractions; otherwise they are
|
|
53
|
+
* raw pixel offsets.
|
|
54
|
+
*
|
|
55
|
+
* Clicks produced by keyboard activation (Enter / Space on the focused
|
|
56
|
+
* button) or assistive tech carry `detail === 0` and no pointer position —
|
|
57
|
+
* such clicks place the pin at the surface centre. Pin markers and popups
|
|
58
|
+
* never reach this handler: they stack above the button and are its
|
|
59
|
+
* siblings, so their clicks do not hit it.
|
|
60
|
+
*
|
|
61
|
+
* @param event - The originating mouse event.
|
|
62
|
+
*/
|
|
63
|
+
function handleSurfaceClick(event: MouseEvent): void {
|
|
64
|
+
if (!onSurfaceClick) return
|
|
65
|
+
const rect = (event.currentTarget as HTMLElement).getBoundingClientRect()
|
|
66
|
+
const keyboardActivated = event.detail === 0
|
|
67
|
+
const px = keyboardActivated ? rect.width / 2 : event.clientX - rect.left
|
|
68
|
+
const py = keyboardActivated ? rect.height / 2 : event.clientY - rect.top
|
|
69
|
+
const safeRectWidth = rect.width || 1
|
|
70
|
+
const safeRectHeight = rect.height || 1
|
|
71
|
+
const x = normalised ? px / safeRectWidth : px
|
|
72
|
+
const y = normalised ? py / safeRectHeight : py
|
|
73
|
+
onSurfaceClick({ x, y })
|
|
74
|
+
}
|
|
75
|
+
</script>
|
|
76
|
+
|
|
77
|
+
<div
|
|
78
|
+
role="region"
|
|
79
|
+
aria-label={regionLabel}
|
|
80
|
+
data-mol-id="annotation-layer"
|
|
81
|
+
class={cm.cn(className)}
|
|
82
|
+
style={rootStyle}
|
|
83
|
+
>
|
|
84
|
+
{#if children}{@render children()}{/if}
|
|
85
|
+
{#if onSurfaceClick}
|
|
86
|
+
<button
|
|
87
|
+
type="button"
|
|
88
|
+
aria-label={addPinLabel}
|
|
89
|
+
data-mol-id="annotation-layer-add-pin"
|
|
90
|
+
onclick={handleSurfaceClick}
|
|
91
|
+
class={cm.cn(cm.position('absolute'), cm.inset0, cm.cursorPointer)}
|
|
92
|
+
style={addPinStyle}
|
|
93
|
+
></button>
|
|
94
|
+
{/if}
|
|
95
|
+
{#each pins as pin (pin.id)}
|
|
96
|
+
<AnnotationPin
|
|
97
|
+
position={pin.position}
|
|
98
|
+
label={pin.label}
|
|
99
|
+
note={pin.note}
|
|
100
|
+
selected={activePinId === pin.id}
|
|
101
|
+
{popupSide}
|
|
102
|
+
{normalised}
|
|
103
|
+
onClick={() => onPinClick?.(pin.id)}
|
|
104
|
+
/>
|
|
105
|
+
{/each}
|
|
106
|
+
</div>
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import type { AnnotationLayerProps } from './types.js';
|
|
2
|
+
declare const AnnotationLayer: import("svelte").Component<AnnotationLayerProps, {}, "">;
|
|
3
|
+
type AnnotationLayer = ReturnType<typeof AnnotationLayer>;
|
|
4
|
+
export default AnnotationLayer;
|
|
5
|
+
//# sourceMappingURL=AnnotationLayer.svelte.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"AnnotationLayer.svelte.d.ts","sourceRoot":"","sources":["../src/AnnotationLayer.svelte"],"names":[],"mappings":"AAQA,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,YAAY,CAAC;AAoFvD,QAAA,MAAM,eAAe,0DAAwC,CAAC;AAC9D,KAAK,eAAe,GAAG,UAAU,CAAC,OAAO,eAAe,CAAC,CAAC;AAC1D,eAAe,eAAe,CAAC"}
|
|
@@ -0,0 +1,162 @@
|
|
|
1
|
+
<!--
|
|
2
|
+
AnnotationPin: the Svelte counterpart of
|
|
3
|
+
`@molecule/app-annotation-pin-react`'s `AnnotationPin` — a single pin marker
|
|
4
|
+
(small circle with optional label) rendered at an absolute position on its
|
|
5
|
+
parent, with a click-to-toggle popup showing the note. Same props, same DOM
|
|
6
|
+
for the same input; every visible string goes through `t()` so a locale
|
|
7
|
+
switch re-renders it.
|
|
8
|
+
-->
|
|
9
|
+
<script lang="ts">
|
|
10
|
+
import { useTranslation } from '@molecule/app-svelte'
|
|
11
|
+
import { getClassMap } from '@molecule/app-ui'
|
|
12
|
+
|
|
13
|
+
import { styleString } from './css.js'
|
|
14
|
+
import type { AnnotationPinProps } from './types.js'
|
|
15
|
+
|
|
16
|
+
let {
|
|
17
|
+
position,
|
|
18
|
+
label,
|
|
19
|
+
note,
|
|
20
|
+
selected = false,
|
|
21
|
+
onClick,
|
|
22
|
+
popupSide = 'right',
|
|
23
|
+
className,
|
|
24
|
+
normalised = true,
|
|
25
|
+
}: AnnotationPinProps = $props()
|
|
26
|
+
|
|
27
|
+
const cm = $derived(getClassMap())
|
|
28
|
+
const { t } = useTranslation()
|
|
29
|
+
|
|
30
|
+
// Every `t(…)` runs inside a `$derived`: it reads the i18n version under the
|
|
31
|
+
// hood, so this re-runs on a locale switch the way React's render-time `t`
|
|
32
|
+
// calls re-run on a re-render.
|
|
33
|
+
const markerLabel = $derived(
|
|
34
|
+
t('annotationPin.aria.marker', {}, { defaultValue: 'Annotation pin' }),
|
|
35
|
+
)
|
|
36
|
+
const popupLabel = $derived(
|
|
37
|
+
t('annotationPin.aria.popup', {}, { defaultValue: 'Annotation details' }),
|
|
38
|
+
)
|
|
39
|
+
const emptyNote = $derived(
|
|
40
|
+
t('annotationPin.empty', {}, { defaultValue: 'No notes for this pin.' }),
|
|
41
|
+
)
|
|
42
|
+
|
|
43
|
+
/** The wrapper's position (React's `wrapperStyle`). */
|
|
44
|
+
const wrapperStyle = $derived(
|
|
45
|
+
styleString({
|
|
46
|
+
position: 'absolute',
|
|
47
|
+
left: normalised ? `${position.x * 100}%` : `${position.x}px`,
|
|
48
|
+
top: normalised ? `${position.y * 100}%` : `${position.y}px`,
|
|
49
|
+
transform: 'translate(-50%, -50%)',
|
|
50
|
+
zIndex: selected ? 2 : 1,
|
|
51
|
+
}),
|
|
52
|
+
)
|
|
53
|
+
|
|
54
|
+
/** The marker button's reset style (React's `markerStyle`). */
|
|
55
|
+
const markerStyle = $derived(
|
|
56
|
+
styleString({
|
|
57
|
+
width: 24,
|
|
58
|
+
height: 24,
|
|
59
|
+
border: 'none',
|
|
60
|
+
padding: 0,
|
|
61
|
+
cursor: 'pointer',
|
|
62
|
+
display: 'inline-flex',
|
|
63
|
+
alignItems: 'center',
|
|
64
|
+
justifyContent: 'center',
|
|
65
|
+
boxShadow: '0 1px 3px rgba(0,0,0,0.25)',
|
|
66
|
+
}),
|
|
67
|
+
)
|
|
68
|
+
|
|
69
|
+
/** The marker label's style (React's inline `lineHeight` / `pointerEvents`). */
|
|
70
|
+
const labelStyle = $derived(styleString({ lineHeight: 1, pointerEvents: 'none' }))
|
|
71
|
+
|
|
72
|
+
/** The popup's side-specific style (React's `popupStyle`). */
|
|
73
|
+
const popupStyle = $derived.by(() => {
|
|
74
|
+
const base: Record<string, string | number> = {
|
|
75
|
+
position: 'absolute',
|
|
76
|
+
minWidth: 160,
|
|
77
|
+
maxWidth: 240,
|
|
78
|
+
padding: 8,
|
|
79
|
+
borderRadius: 4,
|
|
80
|
+
boxShadow: '0 4px 12px rgba(0,0,0,0.18)',
|
|
81
|
+
zIndex: 3,
|
|
82
|
+
}
|
|
83
|
+
switch (popupSide) {
|
|
84
|
+
case 'top':
|
|
85
|
+
base.bottom = '100%'
|
|
86
|
+
base.left = '50%'
|
|
87
|
+
base.transform = 'translate(-50%, -8px)'
|
|
88
|
+
break
|
|
89
|
+
case 'bottom':
|
|
90
|
+
base.top = '100%'
|
|
91
|
+
base.left = '50%'
|
|
92
|
+
base.transform = 'translate(-50%, 8px)'
|
|
93
|
+
break
|
|
94
|
+
case 'left':
|
|
95
|
+
base.right = '100%'
|
|
96
|
+
base.top = '50%'
|
|
97
|
+
base.transform = 'translate(-8px, -50%)'
|
|
98
|
+
break
|
|
99
|
+
case 'right':
|
|
100
|
+
default:
|
|
101
|
+
base.left = '100%'
|
|
102
|
+
base.top = '50%'
|
|
103
|
+
base.transform = 'translate(8px, -50%)'
|
|
104
|
+
break
|
|
105
|
+
}
|
|
106
|
+
return styleString(base)
|
|
107
|
+
})
|
|
108
|
+
|
|
109
|
+
/**
|
|
110
|
+
* Stops the marker click from bubbling to arbitrary ancestor click handlers
|
|
111
|
+
* and forwards it to `onClick`.
|
|
112
|
+
*
|
|
113
|
+
* @param event - The originating mouse event.
|
|
114
|
+
*/
|
|
115
|
+
function handleMarkerClick(event: MouseEvent): void {
|
|
116
|
+
event.stopPropagation()
|
|
117
|
+
onClick?.()
|
|
118
|
+
}
|
|
119
|
+
</script>
|
|
120
|
+
|
|
121
|
+
<div
|
|
122
|
+
class={cm.cn(className)}
|
|
123
|
+
data-mol-id="annotation-pin"
|
|
124
|
+
data-pin-selected={selected ? 'true' : 'false'}
|
|
125
|
+
style={wrapperStyle}
|
|
126
|
+
>
|
|
127
|
+
<button
|
|
128
|
+
type="button"
|
|
129
|
+
onclick={handleMarkerClick}
|
|
130
|
+
aria-label={markerLabel}
|
|
131
|
+
aria-expanded={selected ? 'true' : 'false'}
|
|
132
|
+
data-mol-id="annotation-pin-marker"
|
|
133
|
+
class={cm.cn(cm.roundedFull, cm.cursorPointer)}
|
|
134
|
+
style={markerStyle}
|
|
135
|
+
>
|
|
136
|
+
<span
|
|
137
|
+
class={cm.cn(cm.textSize('xs'), cm.fontWeight('bold'))}
|
|
138
|
+
data-mol-id="annotation-pin-label"
|
|
139
|
+
style={labelStyle}
|
|
140
|
+
>
|
|
141
|
+
{#if typeof label === 'function'}{@render label()}{:else if label !== undefined && label !== null}{label}{/if}
|
|
142
|
+
</span>
|
|
143
|
+
</button>
|
|
144
|
+
{#if selected}
|
|
145
|
+
<div
|
|
146
|
+
role="dialog"
|
|
147
|
+
aria-label={popupLabel}
|
|
148
|
+
data-mol-id="annotation-pin-popup"
|
|
149
|
+
data-popup-side={popupSide}
|
|
150
|
+
class={cm.cn(cm.surface, cm.borderAll, cm.textSize('sm'))}
|
|
151
|
+
style={popupStyle}
|
|
152
|
+
>
|
|
153
|
+
<div data-mol-id="annotation-pin-popup-body">
|
|
154
|
+
{#if note !== undefined && note !== null}
|
|
155
|
+
{#if typeof note === 'function'}{@render note()}{:else}{note}{/if}
|
|
156
|
+
{:else}
|
|
157
|
+
<span data-mol-id="annotation-pin-popup-empty">{emptyNote}</span>
|
|
158
|
+
{/if}
|
|
159
|
+
</div>
|
|
160
|
+
</div>
|
|
161
|
+
{/if}
|
|
162
|
+
</div>
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import type { AnnotationPinProps } from './types.js';
|
|
2
|
+
declare const AnnotationPin: import("svelte").Component<AnnotationPinProps, {}, "">;
|
|
3
|
+
type AnnotationPin = ReturnType<typeof AnnotationPin>;
|
|
4
|
+
export default AnnotationPin;
|
|
5
|
+
//# sourceMappingURL=AnnotationPin.svelte.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"AnnotationPin.svelte.d.ts","sourceRoot":"","sources":["../src/AnnotationPin.svelte"],"names":[],"mappings":"AAOA,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,YAAY,CAAC;AAwIrD,QAAA,MAAM,aAAa,wDAAwC,CAAC;AAC5D,KAAK,aAAa,GAAG,UAAU,CAAC,OAAO,aAAa,CAAC,CAAC;AACtD,eAAe,aAAa,CAAC"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The package's components: one Svelte 5 component per React component in
|
|
3
|
+
* `@molecule/app-annotation-pin-react`, under the same React name.
|
|
4
|
+
*
|
|
5
|
+
* @module
|
|
6
|
+
*/
|
|
7
|
+
export { default as AnnotationLayer } from './AnnotationLayer.svelte';
|
|
8
|
+
export { default as AnnotationPin } from './AnnotationPin.svelte';
|
|
9
|
+
//# sourceMappingURL=components.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"components.d.ts","sourceRoot":"","sources":["../src/components.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EAAE,OAAO,IAAI,eAAe,EAAE,MAAM,0BAA0B,CAAA;AACrE,OAAO,EAAE,OAAO,IAAI,aAAa,EAAE,MAAM,wBAAwB,CAAA"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The package's components: one Svelte 5 component per React component in
|
|
3
|
+
* `@molecule/app-annotation-pin-react`, under the same React name.
|
|
4
|
+
*
|
|
5
|
+
* @module
|
|
6
|
+
*/
|
|
7
|
+
export { default as AnnotationLayer } from './AnnotationLayer.svelte';
|
|
8
|
+
export { default as AnnotationPin } from './AnnotationPin.svelte';
|
package/dist/css.d.ts
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Inline-style serialisation for the annotation-pin components.
|
|
3
|
+
*
|
|
4
|
+
* React turns a style object into the element's `style` attribute, adding
|
|
5
|
+
* `px` to numeric values except the properties CSS keeps unitless. The other
|
|
6
|
+
* frameworks differ here (Solid passes values straight to the CSSOM), so the
|
|
7
|
+
* components serialise the style themselves: every framework then renders the
|
|
8
|
+
* same declarations and therefore the same pixels.
|
|
9
|
+
*
|
|
10
|
+
* @module
|
|
11
|
+
*/
|
|
12
|
+
/**
|
|
13
|
+
* Serialises a style object into the `style` attribute React would render.
|
|
14
|
+
*
|
|
15
|
+
* @param style - The style declarations.
|
|
16
|
+
* @returns The attribute value.
|
|
17
|
+
*/
|
|
18
|
+
export declare const styleString: (style: Record<string, string | number>) => string;
|
|
19
|
+
//# sourceMappingURL=css.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"css.d.ts","sourceRoot":"","sources":["../src/css.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAoDH;;;;;GAKG;AACH,eAAO,MAAM,WAAW,GAAI,OAAO,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,CAAC,KAAG,MAStD,CAAA"}
|
package/dist/css.js
ADDED
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Inline-style serialisation for the annotation-pin components.
|
|
3
|
+
*
|
|
4
|
+
* React turns a style object into the element's `style` attribute, adding
|
|
5
|
+
* `px` to numeric values except the properties CSS keeps unitless. The other
|
|
6
|
+
* frameworks differ here (Solid passes values straight to the CSSOM), so the
|
|
7
|
+
* components serialise the style themselves: every framework then renders the
|
|
8
|
+
* same declarations and therefore the same pixels.
|
|
9
|
+
*
|
|
10
|
+
* @module
|
|
11
|
+
*/
|
|
12
|
+
/** Properties React keeps unitless — a numeric value gets no `px`. */
|
|
13
|
+
const UNITLESS = new Set([
|
|
14
|
+
'animation-iteration-count',
|
|
15
|
+
'aspect-ratio',
|
|
16
|
+
'border-image-outset',
|
|
17
|
+
'border-image-slice',
|
|
18
|
+
'border-image-width',
|
|
19
|
+
'column-count',
|
|
20
|
+
'columns',
|
|
21
|
+
'fill-opacity',
|
|
22
|
+
'flex',
|
|
23
|
+
'flex-grow',
|
|
24
|
+
'flex-shrink',
|
|
25
|
+
'flood-opacity',
|
|
26
|
+
'font-weight',
|
|
27
|
+
'grid-area',
|
|
28
|
+
'grid-column',
|
|
29
|
+
'grid-column-end',
|
|
30
|
+
'grid-column-start',
|
|
31
|
+
'grid-row',
|
|
32
|
+
'grid-row-end',
|
|
33
|
+
'grid-row-start',
|
|
34
|
+
'line-clamp',
|
|
35
|
+
'line-height',
|
|
36
|
+
'opacity',
|
|
37
|
+
'order',
|
|
38
|
+
'orphans',
|
|
39
|
+
'scale',
|
|
40
|
+
'stop-opacity',
|
|
41
|
+
'stroke-dasharray',
|
|
42
|
+
'stroke-dashoffset',
|
|
43
|
+
'stroke-miterlimit',
|
|
44
|
+
'stroke-opacity',
|
|
45
|
+
'stroke-width',
|
|
46
|
+
'tab-size',
|
|
47
|
+
'widows',
|
|
48
|
+
'z-index',
|
|
49
|
+
'zoom',
|
|
50
|
+
]);
|
|
51
|
+
/**
|
|
52
|
+
* Hyphenates a camelCase CSS property name; an already-hyphenated name and a
|
|
53
|
+
* `--custom-property` are returned as they are.
|
|
54
|
+
*
|
|
55
|
+
* @param name - The property name.
|
|
56
|
+
* @returns The CSS property name.
|
|
57
|
+
*/
|
|
58
|
+
const hyphenate = (name) => name.startsWith('--') ? name : name.replace(/[A-Z]/g, (c) => `-${c.toLowerCase()}`);
|
|
59
|
+
/**
|
|
60
|
+
* Serialises a style object into the `style` attribute React would render.
|
|
61
|
+
*
|
|
62
|
+
* @param style - The style declarations.
|
|
63
|
+
* @returns The attribute value.
|
|
64
|
+
*/
|
|
65
|
+
export const styleString = (style) => Object.entries(style)
|
|
66
|
+
.filter(([, value]) => value !== undefined && value !== null && value !== '')
|
|
67
|
+
.map(([name, value]) => {
|
|
68
|
+
const property = hyphenate(name);
|
|
69
|
+
const rendered = typeof value === 'number' && !UNITLESS.has(property) ? `${value}px` : String(value);
|
|
70
|
+
return `${property}: ${rendered}`;
|
|
71
|
+
})
|
|
72
|
+
.join('; ');
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Svelte annotation pin / hotspot overlay primitives — the Svelte counterpart
|
|
3
|
+
* of `@molecule/app-annotation-pin-react`: same props (React names) and the
|
|
4
|
+
* same DOM for the same input, so an app switches framework by changing only
|
|
5
|
+
* the package name in its imports.
|
|
6
|
+
*
|
|
7
|
+
* Exports `AnnotationPin` (single click-to-toggle marker) and
|
|
8
|
+
* `AnnotationLayer` (parent wrapper that manages many pins on a surface).
|
|
9
|
+
* Reusable for 3d-model viewers, image annotations, map pins, and hotspot
|
|
10
|
+
* tours.
|
|
11
|
+
*
|
|
12
|
+
* @example
|
|
13
|
+
* ```svelte
|
|
14
|
+
* <script lang="ts">
|
|
15
|
+
* import { AnnotationLayer, type Pin } from '@molecule/app-annotation-pin-svelte'
|
|
16
|
+
*
|
|
17
|
+
* let pins = $state<Pin[]>([])
|
|
18
|
+
* let activeId = $state<string | null>(null)
|
|
19
|
+
*
|
|
20
|
+
* function addPin({ x, y }: { x: number; y: number }): void {
|
|
21
|
+
* const id = crypto.randomUUID()
|
|
22
|
+
* pins = [...pins, { id, position: { x, y }, label: pins.length + 1 }]
|
|
23
|
+
* activeId = id
|
|
24
|
+
* }
|
|
25
|
+
* </script>
|
|
26
|
+
*
|
|
27
|
+
* <AnnotationLayer
|
|
28
|
+
* {pins}
|
|
29
|
+
* activePinId={activeId}
|
|
30
|
+
* onPinClick={(id) => (activeId = id === activeId ? null : id)}
|
|
31
|
+
* onSurfaceClick={addPin}
|
|
32
|
+
* >
|
|
33
|
+
* <img src="/floorplan.png" alt="" style="width: 100%; display: block" />
|
|
34
|
+
* </AnnotationLayer>
|
|
35
|
+
* ```
|
|
36
|
+
*
|
|
37
|
+
* @remarks
|
|
38
|
+
* Selection is fully controlled — the layer never stores the active pin;
|
|
39
|
+
* manage `activePinId` yourself and toggle it in `onPinClick`. `position`
|
|
40
|
+
* is normalised 0..1 by default (fractions of the layer box, so pins
|
|
41
|
+
* re-anchor on resize); pass `normalised={false}` for raw pixel offsets — on
|
|
42
|
+
* BOTH `<AnnotationLayer>` and any directly-rendered `<AnnotationPin>`, or
|
|
43
|
+
* clicks and markers will disagree. The layer wraps the default content in a
|
|
44
|
+
* `position: relative` box; a bare `<AnnotationPin>` needs its own positioned
|
|
45
|
+
* ancestor. Node-valued props are snippets (or plain strings). Translations
|
|
46
|
+
* come from the companion `@molecule/app-locales-annotation-pin` locale bond.
|
|
47
|
+
*
|
|
48
|
+
* @module
|
|
49
|
+
*/
|
|
50
|
+
export * from './components.js';
|
|
51
|
+
export * from './types.js';
|
|
52
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAgDG;AAEH,cAAc,iBAAiB,CAAA;AAC/B,cAAc,YAAY,CAAA"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Svelte annotation pin / hotspot overlay primitives — the Svelte counterpart
|
|
3
|
+
* of `@molecule/app-annotation-pin-react`: same props (React names) and the
|
|
4
|
+
* same DOM for the same input, so an app switches framework by changing only
|
|
5
|
+
* the package name in its imports.
|
|
6
|
+
*
|
|
7
|
+
* Exports `AnnotationPin` (single click-to-toggle marker) and
|
|
8
|
+
* `AnnotationLayer` (parent wrapper that manages many pins on a surface).
|
|
9
|
+
* Reusable for 3d-model viewers, image annotations, map pins, and hotspot
|
|
10
|
+
* tours.
|
|
11
|
+
*
|
|
12
|
+
* @example
|
|
13
|
+
* ```svelte
|
|
14
|
+
* <script lang="ts">
|
|
15
|
+
* import { AnnotationLayer, type Pin } from '@molecule/app-annotation-pin-svelte'
|
|
16
|
+
*
|
|
17
|
+
* let pins = $state<Pin[]>([])
|
|
18
|
+
* let activeId = $state<string | null>(null)
|
|
19
|
+
*
|
|
20
|
+
* function addPin({ x, y }: { x: number; y: number }): void {
|
|
21
|
+
* const id = crypto.randomUUID()
|
|
22
|
+
* pins = [...pins, { id, position: { x, y }, label: pins.length + 1 }]
|
|
23
|
+
* activeId = id
|
|
24
|
+
* }
|
|
25
|
+
* </script>
|
|
26
|
+
*
|
|
27
|
+
* <AnnotationLayer
|
|
28
|
+
* {pins}
|
|
29
|
+
* activePinId={activeId}
|
|
30
|
+
* onPinClick={(id) => (activeId = id === activeId ? null : id)}
|
|
31
|
+
* onSurfaceClick={addPin}
|
|
32
|
+
* >
|
|
33
|
+
* <img src="/floorplan.png" alt="" style="width: 100%; display: block" />
|
|
34
|
+
* </AnnotationLayer>
|
|
35
|
+
* ```
|
|
36
|
+
*
|
|
37
|
+
* @remarks
|
|
38
|
+
* Selection is fully controlled — the layer never stores the active pin;
|
|
39
|
+
* manage `activePinId` yourself and toggle it in `onPinClick`. `position`
|
|
40
|
+
* is normalised 0..1 by default (fractions of the layer box, so pins
|
|
41
|
+
* re-anchor on resize); pass `normalised={false}` for raw pixel offsets — on
|
|
42
|
+
* BOTH `<AnnotationLayer>` and any directly-rendered `<AnnotationPin>`, or
|
|
43
|
+
* clicks and markers will disagree. The layer wraps the default content in a
|
|
44
|
+
* `position: relative` box; a bare `<AnnotationPin>` needs its own positioned
|
|
45
|
+
* ancestor. Node-valued props are snippets (or plain strings). Translations
|
|
46
|
+
* come from the companion `@molecule/app-locales-annotation-pin` locale bond.
|
|
47
|
+
*
|
|
48
|
+
* @module
|
|
49
|
+
*/
|
|
50
|
+
export * from './components.js';
|
|
51
|
+
export * from './types.js';
|
package/dist/types.d.ts
ADDED
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Types of `@molecule/app-annotation-pin-svelte` — the Svelte counterpart of
|
|
3
|
+
* `@molecule/app-annotation-pin-react`, same props and DOM.
|
|
4
|
+
*
|
|
5
|
+
* @module
|
|
6
|
+
*/
|
|
7
|
+
import type { Snippet } from 'svelte';
|
|
8
|
+
/**
|
|
9
|
+
* A single pin to display on a parent surface. `position` is in the
|
|
10
|
+
* parent's coordinate space — for image / 2D-canvas overlays this is
|
|
11
|
+
* normalised 0..1 (so the pin re-anchors as the surface resizes); for
|
|
12
|
+
* pixel-positioned overlays callers can pass raw px values and provide
|
|
13
|
+
* their own `style` overrides via `className`.
|
|
14
|
+
*
|
|
15
|
+
* The label/note are pure data — components handle render only. Surfaces
|
|
16
|
+
* supply pin objects via `<AnnotationLayer {pins}>` (or render a single pin
|
|
17
|
+
* directly if there is only one).
|
|
18
|
+
*/
|
|
19
|
+
export interface Pin {
|
|
20
|
+
/** Stable identifier (used as the list key). */
|
|
21
|
+
id: string;
|
|
22
|
+
/** Position in the parent surface's coordinate space (typically normalised 0..1). */
|
|
23
|
+
position: {
|
|
24
|
+
x: number;
|
|
25
|
+
y: number;
|
|
26
|
+
};
|
|
27
|
+
/** Short label (e.g. an index or single-word tag) shown inside the pin marker. */
|
|
28
|
+
label?: Snippet | string | number | null | undefined;
|
|
29
|
+
/** Longer note / description body, shown inside the popup when the pin is selected. */
|
|
30
|
+
note?: Snippet | string | number | null | undefined;
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* `<AnnotationPin>` props.
|
|
34
|
+
*/
|
|
35
|
+
export interface AnnotationPinProps {
|
|
36
|
+
/** Position in the parent surface's coordinate space (typically normalised 0..1). */
|
|
37
|
+
position: {
|
|
38
|
+
x: number;
|
|
39
|
+
y: number;
|
|
40
|
+
};
|
|
41
|
+
/** Short label (e.g. an index or single-word tag) shown inside the marker. */
|
|
42
|
+
label?: Snippet | string | number | null | undefined;
|
|
43
|
+
/** Longer note shown inside the popup when the pin is selected. */
|
|
44
|
+
note?: Snippet | string | number | null | undefined;
|
|
45
|
+
/**
|
|
46
|
+
* Whether the pin is currently selected. When `true` the popup is
|
|
47
|
+
* rendered. Selection is controlled — callers manage state in
|
|
48
|
+
* `<AnnotationLayer>` (or themselves) and update via `onClick`.
|
|
49
|
+
*/
|
|
50
|
+
selected?: boolean;
|
|
51
|
+
/** Click handler — fires when the pin marker is clicked. */
|
|
52
|
+
onClick?: () => void;
|
|
53
|
+
/**
|
|
54
|
+
* Side the popup renders on, relative to the marker. Defaults to `'right'`.
|
|
55
|
+
*/
|
|
56
|
+
popupSide?: 'top' | 'bottom' | 'left' | 'right';
|
|
57
|
+
/** Extra classes merged onto the root wrapper. */
|
|
58
|
+
className?: string;
|
|
59
|
+
/**
|
|
60
|
+
* Whether `position` is normalised (0..1) — when `true` the wrapper
|
|
61
|
+
* positions itself with `%` units so pins re-anchor on resize. When
|
|
62
|
+
* `false` the wrapper uses raw `px` values. Defaults to `true`.
|
|
63
|
+
*/
|
|
64
|
+
normalised?: boolean;
|
|
65
|
+
}
|
|
66
|
+
/**
|
|
67
|
+
* `<AnnotationLayer>` props.
|
|
68
|
+
*/
|
|
69
|
+
export interface AnnotationLayerProps {
|
|
70
|
+
/** Pins to render on the layer. */
|
|
71
|
+
pins: Pin[];
|
|
72
|
+
/** Optional layer content (the surface to annotate — image, canvas, map tile, etc.). */
|
|
73
|
+
children?: Snippet;
|
|
74
|
+
/**
|
|
75
|
+
* The currently active (popup-open) pin id, or `null` for none. The
|
|
76
|
+
* layer is fully controlled — callers manage selection state.
|
|
77
|
+
*/
|
|
78
|
+
activePinId?: string | null;
|
|
79
|
+
/** Called with the clicked pin id when a pin marker is clicked. */
|
|
80
|
+
onPinClick?: (pinId: string) => void;
|
|
81
|
+
/**
|
|
82
|
+
* Called when the user clicks an empty area of the layer (i.e. not on
|
|
83
|
+
* a pin marker or a popup). Coordinates are in the same space as
|
|
84
|
+
* `Pin.position` — normalised 0..1 by default. Keyboard users get the
|
|
85
|
+
* same action: activating the layer's "add pin" button (Tab to it,
|
|
86
|
+
* then Enter / Space) places a pin at the surface centre.
|
|
87
|
+
*/
|
|
88
|
+
onSurfaceClick?: (position: {
|
|
89
|
+
x: number;
|
|
90
|
+
y: number;
|
|
91
|
+
}) => void;
|
|
92
|
+
/**
|
|
93
|
+
* Whether positions are normalised (0..1) — when `true` the layer
|
|
94
|
+
* computes click coordinates as fractions of its bounding box; when
|
|
95
|
+
* `false` it returns raw pixel offsets. Defaults to `true`.
|
|
96
|
+
*/
|
|
97
|
+
normalised?: boolean;
|
|
98
|
+
/**
|
|
99
|
+
* Side the popup renders on, relative to its marker. Defaults to `'right'`.
|
|
100
|
+
*/
|
|
101
|
+
popupSide?: 'top' | 'bottom' | 'left' | 'right';
|
|
102
|
+
/** Extra classes merged onto the layer root. */
|
|
103
|
+
className?: string;
|
|
104
|
+
/** Inline style for the layer root, merged over the layer's own. */
|
|
105
|
+
style?: Record<string, string | number>;
|
|
106
|
+
}
|
|
107
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,QAAQ,CAAA;AAErC;;;;;;;;;;GAUG;AACH,MAAM,WAAW,GAAG;IAClB,gDAAgD;IAChD,EAAE,EAAE,MAAM,CAAA;IACV,qFAAqF;IACrF,QAAQ,EAAE;QAAE,CAAC,EAAE,MAAM,CAAC;QAAC,CAAC,EAAE,MAAM,CAAA;KAAE,CAAA;IAClC,kFAAkF;IAClF,KAAK,CAAC,EAAE,OAAO,GAAG,MAAM,GAAG,MAAM,GAAG,IAAI,GAAG,SAAS,CAAA;IACpD,uFAAuF;IACvF,IAAI,CAAC,EAAE,OAAO,GAAG,MAAM,GAAG,MAAM,GAAG,IAAI,GAAG,SAAS,CAAA;CACpD;AAED;;GAEG;AACH,MAAM,WAAW,kBAAkB;IACjC,qFAAqF;IACrF,QAAQ,EAAE;QAAE,CAAC,EAAE,MAAM,CAAC;QAAC,CAAC,EAAE,MAAM,CAAA;KAAE,CAAA;IAClC,8EAA8E;IAC9E,KAAK,CAAC,EAAE,OAAO,GAAG,MAAM,GAAG,MAAM,GAAG,IAAI,GAAG,SAAS,CAAA;IACpD,mEAAmE;IACnE,IAAI,CAAC,EAAE,OAAO,GAAG,MAAM,GAAG,MAAM,GAAG,IAAI,GAAG,SAAS,CAAA;IACnD;;;;OAIG;IACH,QAAQ,CAAC,EAAE,OAAO,CAAA;IAClB,4DAA4D;IAC5D,OAAO,CAAC,EAAE,MAAM,IAAI,CAAA;IACpB;;OAEG;IACH,SAAS,CAAC,EAAE,KAAK,GAAG,QAAQ,GAAG,MAAM,GAAG,OAAO,CAAA;IAC/C,kDAAkD;IAClD,SAAS,CAAC,EAAE,MAAM,CAAA;IAClB;;;;OAIG;IACH,UAAU,CAAC,EAAE,OAAO,CAAA;CACrB;AAED;;GAEG;AACH,MAAM,WAAW,oBAAoB;IACnC,mCAAmC;IACnC,IAAI,EAAE,GAAG,EAAE,CAAA;IACX,wFAAwF;IACxF,QAAQ,CAAC,EAAE,OAAO,CAAA;IAClB;;;OAGG;IACH,WAAW,CAAC,EAAE,MAAM,GAAG,IAAI,CAAA;IAC3B,mEAAmE;IACnE,UAAU,CAAC,EAAE,CAAC,KAAK,EAAE,MAAM,KAAK,IAAI,CAAA;IACpC;;;;;;OAMG;IACH,cAAc,CAAC,EAAE,CAAC,QAAQ,EAAE;QAAE,CAAC,EAAE,MAAM,CAAC;QAAC,CAAC,EAAE,MAAM,CAAA;KAAE,KAAK,IAAI,CAAA;IAC7D;;;;OAIG;IACH,UAAU,CAAC,EAAE,OAAO,CAAA;IACpB;;OAEG;IACH,SAAS,CAAC,EAAE,KAAK,GAAG,QAAQ,GAAG,MAAM,GAAG,OAAO,CAAA;IAC/C,gDAAgD;IAChD,SAAS,CAAC,EAAE,MAAM,CAAA;IAClB,oEAAoE;IACpE,KAAK,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,CAAC,CAAA;CACxC"}
|
package/dist/types.js
ADDED
package/package.json
CHANGED
|
@@ -1,6 +1,76 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@molecule/app-annotation-pin-svelte",
|
|
3
|
-
"version": "
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
|
|
3
|
+
"version": "1.1.0",
|
|
4
|
+
"description": "Pin/annotation marker overlay with click-to-place pins and label/note popups for 3d-model-viewer, image annotations, map pins, hotspot tours",
|
|
5
|
+
"homepage": "https://www.molecule.dev/packages/app-annotation-pin-svelte",
|
|
6
|
+
"type": "module",
|
|
7
|
+
"main": "dist/index.js",
|
|
8
|
+
"types": "dist/index.d.ts",
|
|
9
|
+
"exports": {
|
|
10
|
+
".": {
|
|
11
|
+
"types": "./dist/index.d.ts",
|
|
12
|
+
"svelte": "./dist/index.js",
|
|
13
|
+
"default": "./dist/index.js"
|
|
14
|
+
},
|
|
15
|
+
"./package.json": "./package.json"
|
|
16
|
+
},
|
|
17
|
+
"svelte": "./dist/index.js",
|
|
18
|
+
"files": [
|
|
19
|
+
"dist",
|
|
20
|
+
"!dist/**/__tests__",
|
|
21
|
+
"!dist/**/*.test.*",
|
|
22
|
+
"!dist/**/*.spec.*",
|
|
23
|
+
"README.md"
|
|
24
|
+
],
|
|
25
|
+
"scripts": {
|
|
26
|
+
"build": "svelte-check --tsconfig ./tsconfig.json --fail-on-warnings && svelte-package --input src --output dist --tsconfig ./tsconfig.json",
|
|
27
|
+
"dev": "svelte-package --input src --output dist --tsconfig ./tsconfig.json --watch",
|
|
28
|
+
"test": "vitest run",
|
|
29
|
+
"test:watch": "vitest"
|
|
30
|
+
},
|
|
31
|
+
"keywords": [
|
|
32
|
+
"molecule",
|
|
33
|
+
"annotation",
|
|
34
|
+
"pin",
|
|
35
|
+
"marker",
|
|
36
|
+
"hotspot",
|
|
37
|
+
"svelte"
|
|
38
|
+
],
|
|
39
|
+
"author": "Molecule Dev, Inc. (https://molecule.dev)",
|
|
40
|
+
"license": "Apache-2.0",
|
|
41
|
+
"repository": {
|
|
42
|
+
"type": "git",
|
|
43
|
+
"url": "https://github.com/molecule-dev/molecule.git",
|
|
44
|
+
"directory": "packages/app/features/annotation-pin-svelte"
|
|
45
|
+
},
|
|
46
|
+
"engines": {
|
|
47
|
+
"node": ">=20"
|
|
48
|
+
},
|
|
49
|
+
"bugs": "https://github.com/molecule-dev/molecule/issues",
|
|
50
|
+
"publishConfig": {
|
|
51
|
+
"access": "public"
|
|
52
|
+
},
|
|
53
|
+
"peerDependencies": {
|
|
54
|
+
"@molecule/app-svelte": "^3.5.0",
|
|
55
|
+
"@molecule/app-ui": "^1.0.1",
|
|
56
|
+
"@molecule/app-ui-svelte": "^1.1.0",
|
|
57
|
+
"svelte": "^5.0.0"
|
|
58
|
+
},
|
|
59
|
+
"devDependencies": {
|
|
60
|
+
"@molecule/app-framework-conformance": "0.0.0",
|
|
61
|
+
"@molecule/app-i18n": "1.2.2",
|
|
62
|
+
"@molecule/app-icons": "1.0.4",
|
|
63
|
+
"@molecule/app-svelte": "3.7.2",
|
|
64
|
+
"@molecule/app-ui": "1.4.0",
|
|
65
|
+
"@molecule/app-ui-svelte": "1.1.7",
|
|
66
|
+
"@sveltejs/package": "3.0.2",
|
|
67
|
+
"@sveltejs/vite-plugin-svelte": "7.1.2",
|
|
68
|
+
"@types/node": "26.6.5",
|
|
69
|
+
"jsdom": "30.1.3",
|
|
70
|
+
"svelte": "5.57.2",
|
|
71
|
+
"svelte-check": "4.7.7",
|
|
72
|
+
"typescript": "6.0.3",
|
|
73
|
+
"vite": "8.3.5",
|
|
74
|
+
"vitest": "4.1.12"
|
|
75
|
+
}
|
|
76
|
+
}
|