@xsynaptic/share-kit 0.0.0-stage → 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +69 -2
- package/dist/index.d.mts +224 -0
- package/dist/index.mjs +1392 -0
- package/dist/index.mjs.map +1 -0
- package/dist/styles.css +371 -0
- package/package.json +52 -3
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Alexander Synaptic
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,3 +1,70 @@
|
|
|
1
|
-
#
|
|
1
|
+
# @xsynaptic/share-kit
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
A `<share-kit>` custom element that opens a share dialog for the current page. Pick a destination like Bluesky, Threads or Instagram, and the dialog trims your caption to that platform's length limit, suggests an image in the right shape, and opens the platform's composer or your device's share sheet. It works without a framework.
|
|
4
|
+
|
|
5
|
+
This is an early release, and the API will change.
|
|
6
|
+
|
|
7
|
+
## Usage
|
|
8
|
+
|
|
9
|
+
```sh
|
|
10
|
+
npm install @xsynaptic/share-kit
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
Put a trigger button and a JSON payload inside the element. The button starts out `disabled`, and the element enables it once its script loads. Write the payload with `serializeShareKitPayload`, which escapes `<` so a title can't break out of the script tag.
|
|
14
|
+
|
|
15
|
+
```astro
|
|
16
|
+
---
|
|
17
|
+
import { serializeShareKitPayload, type ShareKitPayload } from '@xsynaptic/share-kit';
|
|
18
|
+
|
|
19
|
+
const payload: ShareKitPayload = {
|
|
20
|
+
assets: [],
|
|
21
|
+
description: 'On foggy nights the cat follows the keeper up the tower.',
|
|
22
|
+
locale: 'en',
|
|
23
|
+
settings: { destinations: ['any', 'bluesky', 'threads'], destinationsMore: ['x', 'mastodon'] },
|
|
24
|
+
title: "The Lighthouse Keeper's Cat",
|
|
25
|
+
url: 'https://example.com/lighthouse-keepers-cat/',
|
|
26
|
+
};
|
|
27
|
+
---
|
|
28
|
+
|
|
29
|
+
<share-kit>
|
|
30
|
+
<button data-share-kit-trigger disabled={true} type="button">
|
|
31
|
+
Share
|
|
32
|
+
</button>
|
|
33
|
+
<script is:inline set:html={serializeShareKitPayload(payload)} type="application/json" />
|
|
34
|
+
</share-kit>
|
|
35
|
+
|
|
36
|
+
<script>
|
|
37
|
+
import { defineShareKit, shareKitActionEventName } from '@xsynaptic/share-kit';
|
|
38
|
+
|
|
39
|
+
document.addEventListener(shareKitActionEventName, ({ detail }) => console.log(detail));
|
|
40
|
+
defineShareKit();
|
|
41
|
+
</script>
|
|
42
|
+
```
|
|
43
|
+
|
|
44
|
+
Every action in the dialog fires a `share-kit:action` event. Add your listeners before calling `defineShareKit()`. If `settings.openHash` matches the URL hash, the dialog opens straight away and you would miss that first event.
|
|
45
|
+
|
|
46
|
+
`defineShareKit({ icons })` swaps in your own icons as 24×24 SVG path data. Only the first call counts.
|
|
47
|
+
|
|
48
|
+
The dialog downloads the images in `assets` to save, copy or share them, so serve them from the same origin or with CORS headers.
|
|
49
|
+
|
|
50
|
+
## Styles
|
|
51
|
+
|
|
52
|
+
```css
|
|
53
|
+
@import '@xsynaptic/share-kit/styles.css';
|
|
54
|
+
```
|
|
55
|
+
|
|
56
|
+
The dialog doesn't use a shadow root, so your CSS can reach it. If your stylesheets use cascade layers, import this one into an early layer, for example `layer(components)`, so classes you pass in `settings.classNames` take priority. If they don't, import it without a layer. A layered import would lose to every plain rule on your page. Also keep the element out of containers like `.prose` that style every `p` or `button` inside them.
|
|
57
|
+
|
|
58
|
+
To change colours and spacing, set custom properties on `share-kit` or a parent. Each name starts with `--share-kit-` and ends with one of `surface`, `text`, `muted`, `border`, `field`, `accent`, `accent-text`, `hover`, `hover-border`, `danger`, `radius`, `gap`, `shadow` or `font-mono`.
|
|
59
|
+
|
|
60
|
+
## Testing
|
|
61
|
+
|
|
62
|
+
The element checks what the browser supports: sharing files (`files`), sharing links (`link`), copying images (`copy-image`) and touch input (`handheld`). To preview another device, list the features you want in `data-can`, for example `<share-kit data-can="files link handheld">` for a phone.
|
|
63
|
+
|
|
64
|
+
## Browser support
|
|
65
|
+
|
|
66
|
+
Chrome 120, Safari 17.2 and Firefox 125 or later.
|
|
67
|
+
|
|
68
|
+
## License
|
|
69
|
+
|
|
70
|
+
MIT. The brand icons come from [Simple Icons](https://simpleicons.org) and are in the public domain (CC0). The LinkedIn and Threads icons are from Simple Icons 13.0.0, since newer releases removed LinkedIn and redrew Threads.
|
package/dist/index.d.mts
ADDED
|
@@ -0,0 +1,224 @@
|
|
|
1
|
+
export declare const shareKitStringDefaults: {
|
|
2
|
+
readonly assetCopy: "Copy";
|
|
3
|
+
readonly assetSave: "Save";
|
|
4
|
+
readonly assetShare: "Share";
|
|
5
|
+
readonly captionCopy: "Copy caption";
|
|
6
|
+
readonly captionOver: "{count} over the limit for {destination}";
|
|
7
|
+
readonly captionReset: "Reset";
|
|
8
|
+
readonly captionTitle: "Caption";
|
|
9
|
+
readonly close: "Close";
|
|
10
|
+
readonly copied: "Copied";
|
|
11
|
+
readonly copyManual: "Couldn't copy. The caption is selected, so you can copy it yourself.";
|
|
12
|
+
readonly 'destination.any': "Anywhere";
|
|
13
|
+
readonly 'destination.bluesky': "Bluesky";
|
|
14
|
+
readonly 'destination.facebook': "Facebook";
|
|
15
|
+
readonly 'destination.instagram': "Instagram";
|
|
16
|
+
readonly 'destination.instagram-story': "Story";
|
|
17
|
+
readonly 'destination.linkedin': "LinkedIn";
|
|
18
|
+
readonly 'destination.mastodon': "Mastodon";
|
|
19
|
+
readonly 'destination.messages': "Messages";
|
|
20
|
+
readonly 'destination.pinterest': "Pinterest";
|
|
21
|
+
readonly 'destination.reddit': "Reddit";
|
|
22
|
+
readonly 'destination.threads': "Threads";
|
|
23
|
+
readonly 'destination.x': "X";
|
|
24
|
+
readonly destinationsMore: "More";
|
|
25
|
+
readonly destinationsTitle: "Post to";
|
|
26
|
+
readonly error: "Something went wrong. Try saving instead.";
|
|
27
|
+
readonly 'hint.facebook': "Facebook only takes the link. Your caption is copied, so paste it into your post.";
|
|
28
|
+
readonly 'hint.instagram': "Links in Instagram captions aren't clickable. Point people to the link in your bio.";
|
|
29
|
+
readonly 'hint.instagram-story': "Add the link to your Story with a link sticker.";
|
|
30
|
+
readonly 'hint.linkedin': "LinkedIn only takes the link. Your caption is copied, so paste it into your post.";
|
|
31
|
+
readonly 'hint.reddit': "Reddit takes a title and the link.";
|
|
32
|
+
readonly imagesTitle: "Images";
|
|
33
|
+
readonly linkCopy: "Copy link";
|
|
34
|
+
readonly linkTitle: "Link";
|
|
35
|
+
readonly primaryCopy: "Copy caption";
|
|
36
|
+
readonly primaryOpen: "Open {destination}";
|
|
37
|
+
readonly primaryShareImage: "Share image";
|
|
38
|
+
readonly primaryShareLink: "Share link";
|
|
39
|
+
readonly primaryShareText: "Share";
|
|
40
|
+
readonly qrAlt: "QR code for this page";
|
|
41
|
+
readonly qrTitle: "Scan to continue on your phone";
|
|
42
|
+
readonly qrToggle: "Continue on your phone";
|
|
43
|
+
readonly retry: "Ready. Tap again to share.";
|
|
44
|
+
readonly saved: "Saved";
|
|
45
|
+
readonly saveError: "Couldn't save. Try again.";
|
|
46
|
+
readonly suggested: "Suggested";
|
|
47
|
+
readonly title: "Share this page";
|
|
48
|
+
};
|
|
49
|
+
type ShareKitStringKey = keyof typeof shareKitStringDefaults;
|
|
50
|
+
type ShareKitStrings = Record<ShareKitStringKey, string>;
|
|
51
|
+
type ShareKitAssetRole = 'landscape' | 'photo' | 'portrait' | 'story';
|
|
52
|
+
interface ShareKitAsset {
|
|
53
|
+
alt: string;
|
|
54
|
+
filename: string;
|
|
55
|
+
height: number;
|
|
56
|
+
label: string;
|
|
57
|
+
previewSrc: string;
|
|
58
|
+
role: ShareKitAssetRole;
|
|
59
|
+
src: string;
|
|
60
|
+
type: string;
|
|
61
|
+
width: number;
|
|
62
|
+
}
|
|
63
|
+
type ShareKitClassRole = 'action' | 'destination' | 'heading' | 'input' | 'primary';
|
|
64
|
+
interface ShareKitSettings {
|
|
65
|
+
classNames?: Partial<Record<ShareKitClassRole, string>>;
|
|
66
|
+
destinations: ReadonlyArray<ShareKitDestinationId>;
|
|
67
|
+
destinationsMore?: ReadonlyArray<ShareKitDestinationId>;
|
|
68
|
+
openHash?: string;
|
|
69
|
+
utmMedium?: string;
|
|
70
|
+
}
|
|
71
|
+
interface ShareKitPayload {
|
|
72
|
+
assets: ReadonlyArray<ShareKitAsset>;
|
|
73
|
+
description?: string;
|
|
74
|
+
locale: string;
|
|
75
|
+
settings: ShareKitSettings;
|
|
76
|
+
strings?: Partial<Record<ShareKitStringKey, string>>;
|
|
77
|
+
title: string;
|
|
78
|
+
url: string;
|
|
79
|
+
}
|
|
80
|
+
export declare const shareKitActionEventName = "share-kit:action";
|
|
81
|
+
type ShareKitAction = 'copy' | 'copy-caption' | 'copy-link' | 'destination' | 'open' | 'open-composer' | 'qr' | 'save' | 'share' | 'share-link' | 'share-text';
|
|
82
|
+
interface ShareKitActionDetail {
|
|
83
|
+
action: ShareKitAction;
|
|
84
|
+
asset?: string;
|
|
85
|
+
destination: ShareKitDestinationId;
|
|
86
|
+
}
|
|
87
|
+
declare global {
|
|
88
|
+
interface GlobalEventHandlersEventMap {
|
|
89
|
+
[shareKitActionEventName]: CustomEvent<ShareKitActionDetail>;
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
interface ShareComposerInput {
|
|
93
|
+
media: string | undefined;
|
|
94
|
+
text: string;
|
|
95
|
+
url: string;
|
|
96
|
+
}
|
|
97
|
+
declare const shareDestinations: {
|
|
98
|
+
readonly bluesky: {
|
|
99
|
+
readonly assetRole: "portrait";
|
|
100
|
+
readonly counter: "graphemes";
|
|
101
|
+
readonly getComposerUrl: ({ text }: ShareComposerInput) => string;
|
|
102
|
+
readonly isImagePost: true;
|
|
103
|
+
readonly limit: 300;
|
|
104
|
+
readonly shape: "full";
|
|
105
|
+
readonly urlCost: "shortened";
|
|
106
|
+
};
|
|
107
|
+
readonly facebook: {
|
|
108
|
+
readonly assetRole: "landscape";
|
|
109
|
+
readonly counter: "length";
|
|
110
|
+
readonly getComposerUrl: ({ url }: ShareComposerInput) => string;
|
|
111
|
+
readonly isImagePost: false;
|
|
112
|
+
readonly isLinkOnly: true;
|
|
113
|
+
readonly limit: 63206;
|
|
114
|
+
readonly shape: "full";
|
|
115
|
+
readonly urlCost: "actual";
|
|
116
|
+
};
|
|
117
|
+
readonly instagram: {
|
|
118
|
+
readonly assetRole: "portrait";
|
|
119
|
+
readonly counter: "length";
|
|
120
|
+
readonly isImagePost: true;
|
|
121
|
+
readonly limit: 2200;
|
|
122
|
+
readonly shape: "text";
|
|
123
|
+
readonly urlCost: "actual";
|
|
124
|
+
};
|
|
125
|
+
readonly 'instagram-story': {
|
|
126
|
+
readonly assetRole: "story";
|
|
127
|
+
readonly counter: "length";
|
|
128
|
+
readonly isImagePost: true;
|
|
129
|
+
readonly shape: "url";
|
|
130
|
+
readonly urlCost: "actual";
|
|
131
|
+
};
|
|
132
|
+
readonly linkedin: {
|
|
133
|
+
readonly assetRole: "landscape";
|
|
134
|
+
readonly counter: "length";
|
|
135
|
+
readonly getComposerUrl: ({ url }: ShareComposerInput) => string;
|
|
136
|
+
readonly isImagePost: false;
|
|
137
|
+
readonly isLinkOnly: true;
|
|
138
|
+
readonly limit: 3000;
|
|
139
|
+
readonly shape: "full";
|
|
140
|
+
readonly urlCost: "actual";
|
|
141
|
+
};
|
|
142
|
+
readonly mastodon: {
|
|
143
|
+
readonly assetRole: "portrait";
|
|
144
|
+
readonly counter: "stringz";
|
|
145
|
+
readonly isImagePost: true;
|
|
146
|
+
readonly limit: 500;
|
|
147
|
+
readonly shape: "full";
|
|
148
|
+
readonly urlCost: "fixed";
|
|
149
|
+
};
|
|
150
|
+
readonly messages: {
|
|
151
|
+
readonly assetRole: "landscape";
|
|
152
|
+
readonly counter: "length";
|
|
153
|
+
readonly isImagePost: false;
|
|
154
|
+
readonly shape: "full";
|
|
155
|
+
readonly urlCost: "actual";
|
|
156
|
+
};
|
|
157
|
+
readonly pinterest: {
|
|
158
|
+
readonly assetRole: "portrait";
|
|
159
|
+
readonly counter: "length";
|
|
160
|
+
readonly getComposerUrl: ({ media, text, url }: ShareComposerInput) => string;
|
|
161
|
+
readonly isImagePost: false;
|
|
162
|
+
readonly limit: 800;
|
|
163
|
+
readonly shape: "text";
|
|
164
|
+
readonly urlCost: "actual";
|
|
165
|
+
};
|
|
166
|
+
readonly reddit: {
|
|
167
|
+
readonly assetRole: "landscape";
|
|
168
|
+
readonly counter: "length";
|
|
169
|
+
readonly getComposerUrl: ({ text, url }: ShareComposerInput) => string;
|
|
170
|
+
readonly isImagePost: false;
|
|
171
|
+
readonly limit: 300;
|
|
172
|
+
readonly shape: "title";
|
|
173
|
+
readonly urlCost: "actual";
|
|
174
|
+
};
|
|
175
|
+
readonly any: {
|
|
176
|
+
readonly assetRole: "landscape";
|
|
177
|
+
readonly counter: "length";
|
|
178
|
+
readonly isImagePost: false;
|
|
179
|
+
readonly shape: "full";
|
|
180
|
+
readonly urlCost: "actual";
|
|
181
|
+
};
|
|
182
|
+
readonly threads: {
|
|
183
|
+
readonly assetRole: "portrait";
|
|
184
|
+
readonly counter: "utf8";
|
|
185
|
+
readonly getComposerUrl: ({ text }: ShareComposerInput) => string;
|
|
186
|
+
readonly isImagePost: true;
|
|
187
|
+
readonly limit: 500;
|
|
188
|
+
readonly shape: "full";
|
|
189
|
+
readonly urlCost: "actual";
|
|
190
|
+
};
|
|
191
|
+
readonly x: {
|
|
192
|
+
readonly assetRole: "landscape";
|
|
193
|
+
readonly counter: "weighted";
|
|
194
|
+
readonly getComposerUrl: ({ text }: ShareComposerInput) => string;
|
|
195
|
+
readonly isImagePost: false;
|
|
196
|
+
readonly limit: 280;
|
|
197
|
+
readonly shape: "full";
|
|
198
|
+
readonly urlCost: "fixed";
|
|
199
|
+
};
|
|
200
|
+
};
|
|
201
|
+
type ShareKitDestinationId = keyof typeof shareDestinations;
|
|
202
|
+
type ShareKitIconName = 'close' | 'more' | 'qr' | ShareKitDestinationId;
|
|
203
|
+
type ShareKitIcons = Partial<Record<ShareKitIconName, string>>;
|
|
204
|
+
interface ShareKitOptions {
|
|
205
|
+
icons?: ShareKitIcons;
|
|
206
|
+
}
|
|
207
|
+
export declare function defineShareKit({ icons }?: ShareKitOptions): void;
|
|
208
|
+
declare const BaseElement: {
|
|
209
|
+
new (): HTMLElement;
|
|
210
|
+
prototype: HTMLElement;
|
|
211
|
+
};
|
|
212
|
+
declare class ShareKitElement extends BaseElement {
|
|
213
|
+
#private;
|
|
214
|
+
protected readonly icons: ShareKitIcons;
|
|
215
|
+
connectedCallback(): void;
|
|
216
|
+
disconnectedCallback(): void;
|
|
217
|
+
}
|
|
218
|
+
declare global {
|
|
219
|
+
interface HTMLElementTagNameMap {
|
|
220
|
+
'share-kit': ShareKitElement;
|
|
221
|
+
}
|
|
222
|
+
}
|
|
223
|
+
export declare function serializeShareKitPayload(payload: ShareKitPayload): string;
|
|
224
|
+
export type { ShareKitAction, ShareKitActionDetail, ShareKitAsset, ShareKitAssetRole, ShareKitClassRole, ShareKitDestinationId, ShareKitElement, ShareKitIconName, ShareKitIcons, ShareKitOptions, ShareKitPayload, ShareKitSettings, ShareKitStringKey, ShareKitStrings };
|