@xsynaptic/share-kit 0.0.0-stage → 0.2.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 +86 -2
- package/dist/index.d.mts +231 -0
- package/dist/index.mjs +1379 -0
- package/dist/index.mjs.map +1 -0
- package/dist/styles.css +371 -0
- package/package.json +51 -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,87 @@
|
|
|
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
|
+
## Usage
|
|
6
|
+
|
|
7
|
+
```sh
|
|
8
|
+
npm install @xsynaptic/share-kit
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
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.
|
|
12
|
+
|
|
13
|
+
```astro
|
|
14
|
+
---
|
|
15
|
+
import { serializeShareKitPayload, type ShareKitPayload } from '@xsynaptic/share-kit';
|
|
16
|
+
|
|
17
|
+
const payload: ShareKitPayload = {
|
|
18
|
+
assets: [],
|
|
19
|
+
description: 'On foggy nights the cat follows the keeper up the tower.',
|
|
20
|
+
locale: 'en',
|
|
21
|
+
settings: { destinations: ['any', 'bluesky', 'threads'], destinationsMore: ['x', 'mastodon'] },
|
|
22
|
+
title: "The Lighthouse Keeper's Cat",
|
|
23
|
+
url: 'https://example.com/lighthouse-keepers-cat/',
|
|
24
|
+
};
|
|
25
|
+
---
|
|
26
|
+
|
|
27
|
+
<share-kit>
|
|
28
|
+
<button data-share-kit-trigger disabled={true} type="button">
|
|
29
|
+
Share
|
|
30
|
+
</button>
|
|
31
|
+
<script is:inline set:html={serializeShareKitPayload(payload)} type="application/json" />
|
|
32
|
+
</share-kit>
|
|
33
|
+
|
|
34
|
+
<script>
|
|
35
|
+
import {
|
|
36
|
+
defineShareKit,
|
|
37
|
+
shareKitActionEventName,
|
|
38
|
+
shareKitInterfaceIcons,
|
|
39
|
+
} from '@xsynaptic/share-kit';
|
|
40
|
+
import { siBluesky, siThreads } from 'simple-icons';
|
|
41
|
+
|
|
42
|
+
document.addEventListener(shareKitActionEventName, ({ detail }) => console.log(detail));
|
|
43
|
+
defineShareKit({
|
|
44
|
+
icons: {
|
|
45
|
+
...shareKitInterfaceIcons,
|
|
46
|
+
bluesky: siBluesky.path,
|
|
47
|
+
threads: siThreads.path,
|
|
48
|
+
},
|
|
49
|
+
});
|
|
50
|
+
</script>
|
|
51
|
+
```
|
|
52
|
+
|
|
53
|
+
Every action in the dialog fires a `share-kit:action` event. Listen in the same script as `defineShareKit()`, before or after the call.
|
|
54
|
+
|
|
55
|
+
If `settings.openHash` matches the URL hash, the dialog opens on load. Pick a fragment that no element id on the page uses, or the page also scrolls there.
|
|
56
|
+
|
|
57
|
+
`strings` in the payload overrides the dialog's wording by key (`ShareKitStringKey`).
|
|
58
|
+
|
|
59
|
+
The dialog downloads the images in `assets` to save, copy or share them, so serve them from the same origin or with CORS headers.
|
|
60
|
+
|
|
61
|
+
## Icons
|
|
62
|
+
|
|
63
|
+
The package ships no brand icons. Pass the ones you show to `defineShareKit({ icons })` as 24×24 SVG path data, keyed by destination id or by `close`, `more` and `qr`. A missing icon falls back to text. Only the first call counts.
|
|
64
|
+
|
|
65
|
+
`shareKitInterfaceIcons` holds the five drawn for this package: `any`, `close`, `messages`, `more` and `qr`. For brand marks, [Simple Icons](https://simpleicons.org) exports each one as `si<Name>` with its path on `.path`, and its current release has every destination but LinkedIn.
|
|
66
|
+
|
|
67
|
+
## Styles
|
|
68
|
+
|
|
69
|
+
```css
|
|
70
|
+
@import '@xsynaptic/share-kit/styles.css';
|
|
71
|
+
```
|
|
72
|
+
|
|
73
|
+
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.
|
|
74
|
+
|
|
75
|
+
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`.
|
|
76
|
+
|
|
77
|
+
## Testing
|
|
78
|
+
|
|
79
|
+
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.
|
|
80
|
+
|
|
81
|
+
## Browser support
|
|
82
|
+
|
|
83
|
+
Chrome 120, Safari 17.2 and Firefox 125 or later.
|
|
84
|
+
|
|
85
|
+
## License
|
|
86
|
+
|
|
87
|
+
MIT.
|
package/dist/index.d.mts
ADDED
|
@@ -0,0 +1,231 @@
|
|
|
1
|
+
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
|
+
export declare const shareKitInterfaceIcons: {
|
|
205
|
+
readonly any: "M3.16 14.47L5.99 11.65A4.5 4.5 0 0 1 12.35 18.01L9.53 20.84A4.5 4.5 0 0 1 3.16 14.47ZM4.58 15.89A2.5 2.5 0 0 0 8.11 19.42L10.94 16.6A2.5 2.5 0 0 0 7.4 13.06ZM11.65 5.99L14.47 3.16A4.5 4.5 0 0 1 20.84 9.53L18.01 12.35A4.5 4.5 0 0 1 11.65 5.99ZM13.06 7.4A2.5 2.5 0 0 0 16.6 10.94L19.42 8.11A2.5 2.5 0 0 0 15.89 4.58ZM8.46 14.12L14.12 8.46L15.54 9.88L9.88 15.54Z";
|
|
206
|
+
readonly close: "M6 7.41 7.41 6 12 10.59 16.59 6 18 7.41 13.41 12 18 16.59 16.59 18 12 13.41 7.41 18 6 16.59 10.59 12Z";
|
|
207
|
+
readonly messages: "M5 4h14a2 2 0 0 1 2 2v9a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2V6a2 2 0 0 1 2-2ZM5 6v9h14V6ZM7 17v4l4-4Z";
|
|
208
|
+
readonly more: "M4 12a2 2 0 1 0 4 0a2 2 0 1 0-4 0ZM10 12a2 2 0 1 0 4 0a2 2 0 1 0-4 0ZM16 12a2 2 0 1 0 4 0a2 2 0 1 0-4 0Z";
|
|
209
|
+
readonly qr: "M3 3h7v7H3ZM4.5 4.5v4h4v-4ZM5.5 5.5h2v2h-2ZM14 3h7v7h-7ZM15.5 4.5v4h4v-4ZM16.5 5.5h2v2h-2ZM3 14h7v7H3ZM4.5 15.5v4h4v-4ZM5.5 16.5h2v2h-2ZM14 14h2v2h-2ZM18 14h3v2h-3ZM16 16h2v2h-2ZM14 18h2v3h-2ZM18 18h3v3h-3Z";
|
|
210
|
+
};
|
|
211
|
+
interface ShareKitOptions {
|
|
212
|
+
icons?: ShareKitIcons;
|
|
213
|
+
}
|
|
214
|
+
export declare function defineShareKit({ icons }?: ShareKitOptions): void;
|
|
215
|
+
declare const BaseElement: {
|
|
216
|
+
new (): HTMLElement;
|
|
217
|
+
prototype: HTMLElement;
|
|
218
|
+
};
|
|
219
|
+
declare class ShareKitElement extends BaseElement {
|
|
220
|
+
#private;
|
|
221
|
+
protected readonly icons: ShareKitIcons;
|
|
222
|
+
connectedCallback(): void;
|
|
223
|
+
disconnectedCallback(): void;
|
|
224
|
+
}
|
|
225
|
+
declare global {
|
|
226
|
+
interface HTMLElementTagNameMap {
|
|
227
|
+
'share-kit': ShareKitElement;
|
|
228
|
+
}
|
|
229
|
+
}
|
|
230
|
+
export declare function serializeShareKitPayload(payload: ShareKitPayload): string;
|
|
231
|
+
export type { ShareKitAction, ShareKitActionDetail, ShareKitAsset, ShareKitAssetRole, ShareKitClassRole, ShareKitDestinationId, ShareKitElement, ShareKitIconName, ShareKitIcons, ShareKitOptions, ShareKitPayload, ShareKitSettings, ShareKitStringKey, ShareKitStrings };
|