@xsynaptic/share-kit 0.2.1 → 0.4.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/README.md CHANGED
@@ -8,13 +8,40 @@ A `<share-kit>` custom element that opens a share dialog for the current page. P
8
8
  npm install @xsynaptic/share-kit
9
9
  ```
10
10
 
11
+ List your destinations in a module that server and client code both import:
12
+
13
+ ```ts
14
+ // src/lib/share-destinations.ts
15
+ import type { ShareKitDestinationIdOf } from '@xsynaptic/share-kit';
16
+
17
+ import {
18
+ shareKitAnywhere,
19
+ shareKitBluesky,
20
+ shareKitMastodon,
21
+ shareKitThreads,
22
+ shareKitX,
23
+ } from '@xsynaptic/share-kit';
24
+
25
+ export const destinations = [
26
+ shareKitAnywhere,
27
+ shareKitBluesky,
28
+ shareKitThreads,
29
+ shareKitX,
30
+ shareKitMastodon,
31
+ ] as const;
32
+
33
+ export type Destination = ShareKitDestinationIdOf<typeof destinations>;
34
+ ```
35
+
11
36
  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
37
 
13
38
  ```astro
14
39
  ---
15
40
  import { serializeShareKitPayload, type ShareKitPayload } from '@xsynaptic/share-kit';
16
41
 
17
- const payload: ShareKitPayload = {
42
+ import type { Destination } from '../lib/share-destinations';
43
+
44
+ const payload: ShareKitPayload<Destination> = {
18
45
  assets: [],
19
46
  description: 'On foggy nights the cat follows the keeper up the tower.',
20
47
  locale: 'en',
@@ -39,8 +66,11 @@ const payload: ShareKitPayload = {
39
66
  } from '@xsynaptic/share-kit';
40
67
  import { siBluesky, siThreads } from 'simple-icons';
41
68
 
69
+ import { destinations } from '../lib/share-destinations';
70
+
42
71
  document.addEventListener(shareKitActionEventName, ({ detail }) => console.log(detail));
43
72
  defineShareKit({
73
+ destinations,
44
74
  icons: {
45
75
  ...shareKitInterfaceIcons,
46
76
  bluesky: siBluesky.path,
@@ -50,19 +80,48 @@ const payload: ShareKitPayload = {
50
80
  </script>
51
81
  ```
52
82
 
53
- Every action in the dialog fires a `share-kit:action` event. Listen in the same script as `defineShareKit()`, before or after the call.
83
+ Every action in the dialog fires a `share-kit:action` event whose `detail` holds the `action`, the selected `destination` and, for an image, its `asset` id. Listen in the same script as `defineShareKit()`, before or after the call.
84
+
85
+ Sharing and saving fire once they finish, with an `outcome`:
86
+
87
+ - `share`: `shared`, `dismissed`, `retry` (a slow download used up the tap), `saved` (the browser refused the file, so it downloaded instead) or `error`
88
+ - `share-link`, `share-text`: `shared`, `dismissed` or `error`
89
+ - `save`: `saved` or `error`
90
+
91
+ `shared` means the share sheet took it, not that it was posted.
54
92
 
55
93
  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
94
 
57
- `strings` in the payload overrides the dialog's wording by key (`ShareKitStringKey`).
95
+ `strings` in the payload overrides the dialog's wording by key, including `destination.<id>` and `hint.<id>`.
96
+
97
+ ## Destinations
98
+
99
+ The built-ins are `shareKitAnywhere`, `shareKitBluesky`, `shareKitFacebook`, `shareKitInstagram`, `shareKitInstagramStory`, `shareKitLine`, `shareKitLinkedin`, `shareKitMastodon`, `shareKitMessages`, `shareKitPinterest`, `shareKitReddit`, `shareKitThreads` and `shareKitX`. Adjust one by spreading it (`{ ...shareKitMastodon, limit: 1000 }`), or write your own with `defineShareKitDestination`:
100
+
101
+ ```ts
102
+ export const email = defineShareKitDestination({
103
+ actions: { desktop: ['open-composer'], mobile: ['open-composer'] },
104
+ composer: ({ text, title }) =>
105
+ `mailto:?subject=${encodeURIComponent(title)}&body=${encodeURIComponent(text)}`,
106
+ count: shareKitCountLength,
107
+ id: 'email',
108
+ images: [shareKitLandscapeFormat],
109
+ label: 'Email',
110
+ shape: 'full',
111
+ });
112
+ ```
113
+
114
+ `actions` is what the main button tries on each device, in order, before falling back to copying the caption. `images` lists the formats the destination takes, best first.
115
+
116
+ ## Images
117
+
118
+ Each entry in `assets` has an `id`, `width` and `height`; spread a preset such as `shareKitPortraitFormat` into a card to get all three. Photos set `isSuggestable: false`. `getShareKitImageFormats(destinations)` lists the card formats worth rendering.
58
119
 
59
120
  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
121
 
61
122
  ## Icons
62
123
 
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.
124
+ 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`, or pass a function that returns a promise of that map to load them lazily. `shareKitInterfaceIcons` holds the five drawn for this package. For brand marks, [Simple Icons](https://simpleicons.org) has every built-in but LinkedIn.
66
125
 
67
126
  ## Styles
68
127
 
@@ -76,7 +135,7 @@ To change colours and spacing, set custom properties on `share-kit` or a parent.
76
135
 
77
136
  ## Testing
78
137
 
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.
138
+ The element checks what the browser supports: sharing files (`files`), sharing links (`link`), copying images (`copy-image`) and whether it is a phone or tablet, whose share sheet reaches installed apps (`mobile`, from touch input). To preview another device, list the features you want in `data-can`, for example `<share-kit data-can="files link mobile">` for a phone.
80
139
 
81
140
  ## Browser support
82
141
 
package/dist/index.d.mts CHANGED
@@ -1,3 +1,339 @@
1
+ export declare function shareKitCountWeighted(text: string): number;
2
+ export declare function shareKitCountStringz(text: string): number;
3
+ export declare function shareKitShortenedLinkCost(url: string): number;
4
+ export declare function shareKitCountLength(text: string): number;
5
+ export declare function shareKitCountGraphemes(text: string): number;
6
+ export declare function shareKitCountUtf8(text: string): number;
7
+ type ShareKitCounter = (text: string) => number;
8
+ type LinkCost = ((link: string) => number) | number;
9
+ export declare function shareKitWithLinkCost(count: ShareKitCounter, cost: LinkCost): ShareKitCounter;
10
+ interface ShareKitImageFormat {
11
+ height: number;
12
+ id: string;
13
+ width: number;
14
+ }
15
+ export declare const shareKitLandscapeFormat: {
16
+ readonly height: 630;
17
+ readonly id: "landscape";
18
+ readonly width: 1200;
19
+ };
20
+ export declare const shareKitPortraitFormat: {
21
+ readonly height: 1350;
22
+ readonly id: "portrait";
23
+ readonly width: 1080;
24
+ };
25
+ export declare const shareKitStoryFormat: {
26
+ readonly height: 1920;
27
+ readonly id: "story";
28
+ readonly width: 1080;
29
+ };
30
+ export declare const shareKitPinFormat: {
31
+ readonly height: 1500;
32
+ readonly id: "pin";
33
+ readonly width: 1000;
34
+ };
35
+ type ShareKitImageFormats = readonly [ShareKitImageFormat, ...Array<ShareKitImageFormat>];
36
+ export declare function getShareKitImageFormats(destinations: ReadonlyArray<{
37
+ images: ShareKitImageFormats;
38
+ }>): ShareKitImageFormat[];
39
+ type ShareKitActionKind = 'copy-caption' | 'open-composer' | 'share-image' | 'share-link' | 'share-text';
40
+ type ShareKitDevice = 'desktop' | 'mobile';
41
+ interface ShareKitComposerInput {
42
+ description?: string;
43
+ device: ShareKitDevice;
44
+ media?: string;
45
+ text: string;
46
+ title: string;
47
+ url: string;
48
+ }
49
+ interface ShareKitDestination<Id extends string> {
50
+ actions: Record<ShareKitDevice, ReadonlyArray<ShareKitActionKind>>;
51
+ composer?: (input: ShareKitComposerInput) => string | undefined;
52
+ count: ShareKitCounter;
53
+ hint?: string;
54
+ id: Id;
55
+ images: ShareKitImageFormats;
56
+ label: string;
57
+ limit?: number;
58
+ shape: 'full' | 'text' | 'title' | 'url';
59
+ utmSource?: false | string;
60
+ }
61
+ export declare function defineShareKitDestination<const Id extends string>(destination: ShareKitDestination<Id>): ShareKitDestination<Id>;
62
+ type ShareKitDestinationIdOf<Destinations extends ReadonlyArray<ShareKitDestination<string>>> = Destinations[number]['id'] extends (infer Id extends string) ? string extends Id ? never : Id : never;
63
+ export declare const shareKitAnywhere: {
64
+ readonly actions: {
65
+ readonly desktop: readonly [];
66
+ readonly mobile: readonly ["share-text"];
67
+ };
68
+ readonly count: typeof shareKitCountLength;
69
+ readonly id: "any";
70
+ readonly images: readonly [{
71
+ readonly height: 630;
72
+ readonly id: "landscape";
73
+ readonly width: 1200;
74
+ }];
75
+ readonly label: "Anywhere";
76
+ readonly shape: "full";
77
+ readonly utmSource: false;
78
+ };
79
+ export declare const shareKitBluesky: {
80
+ readonly actions: {
81
+ readonly desktop: readonly ["open-composer"];
82
+ readonly mobile: readonly ["share-image", "open-composer"];
83
+ };
84
+ readonly composer: ({ text }: ShareKitComposerInput) => string;
85
+ readonly count: ShareKitCounter;
86
+ readonly id: "bluesky";
87
+ readonly images: readonly [{
88
+ readonly height: 1350;
89
+ readonly id: "portrait";
90
+ readonly width: 1080;
91
+ }];
92
+ readonly label: "Bluesky";
93
+ readonly limit: 300;
94
+ readonly shape: "full";
95
+ };
96
+ export declare const shareKitFacebook: {
97
+ readonly actions: {
98
+ readonly desktop: readonly ["open-composer"];
99
+ readonly mobile: readonly ["share-link", "open-composer"];
100
+ };
101
+ readonly composer: ({ url }: ShareKitComposerInput) => string;
102
+ readonly count: typeof shareKitCountLength;
103
+ readonly hint: "Facebook only takes the link. Your caption is copied, so paste it into your post.";
104
+ readonly id: "facebook";
105
+ readonly images: readonly [{
106
+ readonly height: 630;
107
+ readonly id: "landscape";
108
+ readonly width: 1200;
109
+ }, {
110
+ readonly height: 1350;
111
+ readonly id: "portrait";
112
+ readonly width: 1080;
113
+ }];
114
+ readonly label: "Facebook";
115
+ readonly limit: 63206;
116
+ readonly shape: "full";
117
+ };
118
+ export declare const shareKitInstagram: {
119
+ readonly actions: {
120
+ readonly desktop: readonly [];
121
+ readonly mobile: readonly ["share-image"];
122
+ };
123
+ readonly count: typeof shareKitCountLength;
124
+ readonly hint: "Links in Instagram captions aren't clickable. Point people to the link in your bio.";
125
+ readonly id: "instagram";
126
+ readonly images: readonly [{
127
+ readonly height: 1350;
128
+ readonly id: "portrait";
129
+ readonly width: 1080;
130
+ }];
131
+ readonly label: "Instagram";
132
+ readonly limit: 2200;
133
+ readonly shape: "text";
134
+ };
135
+ export declare const shareKitInstagramStory: {
136
+ readonly actions: {
137
+ readonly desktop: readonly [];
138
+ readonly mobile: readonly ["share-image"];
139
+ };
140
+ readonly count: typeof shareKitCountLength;
141
+ readonly hint: "Add the link to your Story with a link sticker.";
142
+ readonly id: "instagram-story";
143
+ readonly images: readonly [{
144
+ readonly height: 1920;
145
+ readonly id: "story";
146
+ readonly width: 1080;
147
+ }, {
148
+ readonly height: 1350;
149
+ readonly id: "portrait";
150
+ readonly width: 1080;
151
+ }];
152
+ readonly label: "Story";
153
+ readonly shape: "url";
154
+ };
155
+ export declare const shareKitLinkedin: {
156
+ readonly actions: {
157
+ readonly desktop: readonly ["open-composer"];
158
+ readonly mobile: readonly ["share-link", "open-composer"];
159
+ };
160
+ readonly composer: ({ url }: ShareKitComposerInput) => string;
161
+ readonly count: typeof shareKitCountLength;
162
+ readonly hint: "LinkedIn only takes the link. Your caption is copied, so paste it into your post.";
163
+ readonly id: "linkedin";
164
+ readonly images: readonly [{
165
+ readonly height: 630;
166
+ readonly id: "landscape";
167
+ readonly width: 1200;
168
+ }];
169
+ readonly label: "LinkedIn";
170
+ readonly limit: 3000;
171
+ readonly shape: "full";
172
+ };
173
+ export declare const shareKitLine: {
174
+ readonly actions: {
175
+ readonly desktop: readonly ["open-composer"];
176
+ readonly mobile: readonly ["open-composer"];
177
+ };
178
+ readonly composer: ({ device, text, url }: ShareKitComposerInput) => string;
179
+ readonly count: typeof shareKitCountLength;
180
+ readonly id: "line";
181
+ readonly images: readonly [{
182
+ readonly height: 630;
183
+ readonly id: "landscape";
184
+ readonly width: 1200;
185
+ }];
186
+ readonly label: "LINE";
187
+ readonly shape: "full";
188
+ };
189
+ export declare const shareKitMastodon: {
190
+ readonly actions: {
191
+ readonly desktop: readonly [];
192
+ readonly mobile: readonly ["share-image"];
193
+ };
194
+ readonly count: ShareKitCounter;
195
+ readonly id: "mastodon";
196
+ readonly images: readonly [{
197
+ readonly height: 1350;
198
+ readonly id: "portrait";
199
+ readonly width: 1080;
200
+ }];
201
+ readonly label: "Mastodon";
202
+ readonly limit: 500;
203
+ readonly shape: "full";
204
+ };
205
+ export declare const shareKitMessages: {
206
+ readonly actions: {
207
+ readonly desktop: readonly ["share-text"];
208
+ readonly mobile: readonly ["share-text"];
209
+ };
210
+ readonly count: typeof shareKitCountLength;
211
+ readonly id: "messages";
212
+ readonly images: readonly [{
213
+ readonly height: 630;
214
+ readonly id: "landscape";
215
+ readonly width: 1200;
216
+ }];
217
+ readonly label: "Messages";
218
+ readonly shape: "full";
219
+ };
220
+ export declare const shareKitPinterest: {
221
+ readonly actions: {
222
+ readonly desktop: readonly ["open-composer"];
223
+ readonly mobile: readonly ["open-composer"];
224
+ };
225
+ readonly composer: ({ media, text, url }: ShareKitComposerInput) => string;
226
+ readonly count: typeof shareKitCountLength;
227
+ readonly id: "pinterest";
228
+ readonly images: readonly [{
229
+ readonly height: 1500;
230
+ readonly id: "pin";
231
+ readonly width: 1000;
232
+ }, {
233
+ readonly height: 1350;
234
+ readonly id: "portrait";
235
+ readonly width: 1080;
236
+ }];
237
+ readonly label: "Pinterest";
238
+ readonly limit: 800;
239
+ readonly shape: "text";
240
+ };
241
+ export declare const shareKitReddit: {
242
+ readonly actions: {
243
+ readonly desktop: readonly ["open-composer"];
244
+ readonly mobile: readonly ["open-composer"];
245
+ };
246
+ readonly composer: ({ text, url }: ShareKitComposerInput) => string;
247
+ readonly count: typeof shareKitCountLength;
248
+ readonly hint: "Reddit takes a title and the link.";
249
+ readonly id: "reddit";
250
+ readonly images: readonly [{
251
+ readonly height: 630;
252
+ readonly id: "landscape";
253
+ readonly width: 1200;
254
+ }];
255
+ readonly label: "Reddit";
256
+ readonly limit: 300;
257
+ readonly shape: "title";
258
+ };
259
+ export declare const shareKitThreads: {
260
+ readonly actions: {
261
+ readonly desktop: readonly ["open-composer"];
262
+ readonly mobile: readonly ["share-image", "open-composer"];
263
+ };
264
+ readonly composer: ({ text }: ShareKitComposerInput) => string;
265
+ readonly count: typeof shareKitCountUtf8;
266
+ readonly id: "threads";
267
+ readonly images: readonly [{
268
+ readonly height: 1350;
269
+ readonly id: "portrait";
270
+ readonly width: 1080;
271
+ }];
272
+ readonly label: "Threads";
273
+ readonly limit: 500;
274
+ readonly shape: "full";
275
+ };
276
+ export declare const shareKitX: {
277
+ readonly actions: {
278
+ readonly desktop: readonly ["open-composer"];
279
+ readonly mobile: readonly ["open-composer"];
280
+ };
281
+ readonly composer: ({ text }: ShareKitComposerInput) => string;
282
+ readonly count: ShareKitCounter;
283
+ readonly id: "x";
284
+ readonly images: readonly [{
285
+ readonly height: 630;
286
+ readonly id: "landscape";
287
+ readonly width: 1200;
288
+ }, {
289
+ readonly height: 1350;
290
+ readonly id: "portrait";
291
+ readonly width: 1080;
292
+ }];
293
+ readonly label: "X";
294
+ readonly limit: 280;
295
+ readonly shape: "full";
296
+ };
297
+ declare const shareKitInterfaceIconNames: readonly ["close", "more", "qr"];
298
+ type ShareKitIconName<Id extends string> = (typeof shareKitInterfaceIconNames)[number] | Id;
299
+ type ShareKitIcons<Id extends string> = Partial<Record<ShareKitIconName<Id>, string>>;
300
+ type ShareKitIconsOption<Id extends string> = (() => Promise<ShareKitIcons<Id>>) | ShareKitIcons<Id>;
301
+ export declare const shareKitInterfaceIcons: {
302
+ 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";
303
+ 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";
304
+ 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";
305
+ 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";
306
+ 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";
307
+ };
308
+ declare class ShareIconSource {
309
+ #private;
310
+ get icons(): Partial<Record<string, string>>;
311
+ get isLoading(): boolean;
312
+ constructor(option: ShareKitIconsOption<string>);
313
+ load(): Promise<Partial<Record<string, string>>>;
314
+ }
315
+ type ShareKitDestinationList = readonly [ShareKitDestination<string>, ...Array<ShareKitDestination<string>>];
316
+ interface ShareKitOptions<Destinations extends ShareKitDestinationList> {
317
+ destinations: Destinations;
318
+ icons?: ShareKitIconsOption<ShareKitDestinationIdOf<Destinations>>;
319
+ }
320
+ export declare function defineShareKit<const Destinations extends ShareKitDestinationList>({ destinations, icons }: ShareKitOptions<Destinations>): void;
321
+ declare const BaseElement: {
322
+ new (): HTMLElement;
323
+ prototype: HTMLElement;
324
+ };
325
+ declare class ShareKitElement extends BaseElement {
326
+ #private;
327
+ protected readonly catalogue: ReadonlyMap<string, ShareKitDestination<string>>;
328
+ protected readonly iconSource: ShareIconSource;
329
+ connectedCallback(): void;
330
+ disconnectedCallback(): void;
331
+ }
332
+ declare global {
333
+ interface HTMLElementTagNameMap {
334
+ 'share-kit': ShareKitElement;
335
+ }
336
+ }
1
337
  declare const shareKitStringDefaults: {
2
338
  readonly assetCopy: "Copy";
3
339
  readonly assetSave: "Save";
@@ -9,26 +345,9 @@ declare const shareKitStringDefaults: {
9
345
  readonly close: "Close";
10
346
  readonly copied: "Copied";
11
347
  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
348
  readonly destinationsMore: "More";
25
349
  readonly destinationsTitle: "Post to";
26
350
  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
351
  readonly imagesTitle: "Images";
33
352
  readonly linkCopy: "Copy link";
34
353
  readonly linkTitle: "Link";
@@ -47,185 +366,47 @@ declare const shareKitStringDefaults: {
47
366
  readonly title: "Share this page";
48
367
  };
49
368
  type ShareKitStringKey = keyof typeof shareKitStringDefaults;
50
- type ShareKitStrings = Record<ShareKitStringKey, string>;
51
- type ShareKitAssetRole = 'landscape' | 'photo' | 'portrait' | 'story';
52
- interface ShareKitAsset {
369
+ type ShareKitDestinationStringKey<Id extends string> = `destination.${Id}` | `hint.${Id}`;
370
+ type ShareKitStrings<Id extends string> = Partial<Record<ShareKitDestinationStringKey<Id>, string>> & Record<ShareKitStringKey, string>;
371
+ interface ShareKitAsset extends ShareKitImageFormat {
53
372
  alt: string;
54
373
  filename: string;
55
- height: number;
374
+ isSuggestable?: boolean;
56
375
  label: string;
57
376
  previewSrc: string;
58
- role: ShareKitAssetRole;
59
377
  src: string;
60
378
  type: string;
61
- width: number;
62
379
  }
63
380
  type ShareKitClassRole = 'action' | 'destination' | 'heading' | 'input' | 'primary';
64
- interface ShareKitSettings {
381
+ interface ShareKitSettings<Id extends string> {
65
382
  classNames?: Partial<Record<ShareKitClassRole, string>>;
66
- destinations: ReadonlyArray<ShareKitDestinationId>;
67
- destinationsMore?: ReadonlyArray<ShareKitDestinationId>;
383
+ destinations: ReadonlyArray<Id>;
384
+ destinationsMore?: ReadonlyArray<Id>;
68
385
  openHash?: string;
69
386
  utmMedium?: string;
70
387
  }
71
- interface ShareKitPayload {
388
+ interface ShareKitPayload<Id extends string> {
72
389
  assets: ReadonlyArray<ShareKitAsset>;
73
390
  description?: string;
74
391
  locale: string;
75
- settings: ShareKitSettings;
76
- strings?: Partial<Record<ShareKitStringKey, string>>;
392
+ settings: ShareKitSettings<Id>;
393
+ strings?: Partial<ShareKitStrings<Id>>;
77
394
  title: string;
78
395
  url: string;
79
396
  }
80
397
  export declare const shareKitActionEventName = "share-kit:action";
81
398
  type ShareKitAction = 'copy' | 'copy-caption' | 'copy-link' | 'destination' | 'open' | 'open-composer' | 'qr' | 'save' | 'share' | 'share-link' | 'share-text';
399
+ type ShareKitActionOutcome = 'dismissed' | 'error' | 'retry' | 'saved' | 'shared';
82
400
  interface ShareKitActionDetail {
83
401
  action: ShareKitAction;
84
402
  asset?: string;
85
- destination: ShareKitDestinationId;
403
+ destination: string;
404
+ outcome?: ShareKitActionOutcome;
86
405
  }
87
406
  declare global {
88
407
  interface GlobalEventHandlersEventMap {
89
408
  [shareKitActionEventName]: CustomEvent<ShareKitActionDetail>;
90
409
  }
91
410
  }
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 };
411
+ export declare function serializeShareKitPayload(payload: ShareKitPayload<string>): string;
412
+ export type { ShareKitAction, ShareKitActionDetail, ShareKitActionKind, ShareKitActionOutcome, ShareKitAsset, ShareKitClassRole, ShareKitComposerInput, ShareKitCounter, ShareKitDestination, ShareKitDestinationIdOf, ShareKitDestinationList, ShareKitDevice, ShareKitElement, ShareKitIconName, ShareKitIcons, ShareKitIconsOption, ShareKitImageFormat, ShareKitImageFormats, ShareKitOptions, ShareKitPayload, ShareKitSettings, ShareKitStringKey, ShareKitStrings };