@xsynaptic/share-kit 0.2.0 → 0.3.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,
@@ -54,15 +84,35 @@ Every action in the dialog fires a `share-kit:action` event. Listen in the same
54
84
 
55
85
  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
86
 
57
- `strings` in the payload overrides the dialog's wording by key (`ShareKitStringKey`).
87
+ `strings` in the payload overrides the dialog's wording by key, including `destination.<id>` and `hint.<id>`.
88
+
89
+ ## Destinations
90
+
91
+ The built-ins are `shareKitAnywhere`, `shareKitBluesky`, `shareKitFacebook`, `shareKitInstagram`, `shareKitInstagramStory`, `shareKitLinkedin`, `shareKitMastodon`, `shareKitMessages`, `shareKitPinterest`, `shareKitReddit`, `shareKitThreads` and `shareKitX`. Adjust one by spreading it (`{ ...shareKitMastodon, limit: 1000 }`), or write your own with `defineShareKitDestination`:
92
+
93
+ ```ts
94
+ export const line = defineShareKitDestination({
95
+ actions: { desktop: ['open-composer'], mobile: ['open-composer'] },
96
+ composer: ({ text }) => `https://line.me/R/share?text=${encodeURIComponent(text)}`,
97
+ count: shareKitCountLength,
98
+ id: 'line',
99
+ images: [shareKitLandscapeFormat],
100
+ label: 'LINE',
101
+ shape: 'full',
102
+ });
103
+ ```
104
+
105
+ `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.
106
+
107
+ ## Images
108
+
109
+ 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
110
 
59
111
  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
112
 
61
113
  ## Icons
62
114
 
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.
115
+ 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
116
 
67
117
  ## Styles
68
118
 
@@ -76,7 +126,7 @@ To change colours and spacing, set custom properties on `share-kit` or a parent.
76
126
 
77
127
  ## Testing
78
128
 
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.
129
+ 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
130
 
81
131
  ## Browser support
82
132
 
package/dist/index.d.mts CHANGED
@@ -1,3 +1,322 @@
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
+ export declare function shareKitWithLinkCost(count: ShareKitCounter, cost: ((link: string) => number) | number): ShareKitCounter;
9
+ interface ShareKitImageFormat {
10
+ height: number;
11
+ id: string;
12
+ width: number;
13
+ }
14
+ export declare const shareKitLandscapeFormat: {
15
+ readonly height: 630;
16
+ readonly id: "landscape";
17
+ readonly width: 1200;
18
+ };
19
+ export declare const shareKitPortraitFormat: {
20
+ readonly height: 1350;
21
+ readonly id: "portrait";
22
+ readonly width: 1080;
23
+ };
24
+ export declare const shareKitStoryFormat: {
25
+ readonly height: 1920;
26
+ readonly id: "story";
27
+ readonly width: 1080;
28
+ };
29
+ export declare const shareKitPinFormat: {
30
+ readonly height: 1500;
31
+ readonly id: "pin";
32
+ readonly width: 1000;
33
+ };
34
+ type ShareKitImageFormats = readonly [ShareKitImageFormat, ...Array<ShareKitImageFormat>];
35
+ export declare function getShareKitImageFormats(destinations: ReadonlyArray<{
36
+ images: ShareKitImageFormats;
37
+ }>): ShareKitImageFormat[];
38
+ type ShareKitActionKind = 'copy-caption' | 'open-composer' | 'share-image' | 'share-link' | 'share-text';
39
+ type ShareKitDevice = 'desktop' | 'mobile';
40
+ interface ShareKitComposerInput {
41
+ description?: string;
42
+ device: ShareKitDevice;
43
+ media?: string;
44
+ text: string;
45
+ title: string;
46
+ url: string;
47
+ }
48
+ interface ShareKitDestination<Id extends string> {
49
+ actions: Record<ShareKitDevice, ReadonlyArray<ShareKitActionKind>>;
50
+ composer?: (input: ShareKitComposerInput) => string | undefined;
51
+ count: ShareKitCounter;
52
+ hint?: string;
53
+ id: Id;
54
+ images: ShareKitImageFormats;
55
+ label: string;
56
+ limit?: number;
57
+ shape: 'full' | 'text' | 'title' | 'url';
58
+ utmSource?: false | string;
59
+ }
60
+ export declare function defineShareKitDestination<const Id extends string>(destination: ShareKitDestination<Id>): ShareKitDestination<Id>;
61
+ type ShareKitDestinationIdOf<Destinations extends ReadonlyArray<ShareKitDestination<string>>> = Destinations[number]['id'] extends (infer Id extends string) ? string extends Id ? never : Id : never;
62
+ export declare const shareKitAnywhere: {
63
+ readonly actions: {
64
+ readonly desktop: readonly [];
65
+ readonly mobile: readonly ["share-text"];
66
+ };
67
+ readonly count: typeof shareKitCountLength;
68
+ readonly id: "any";
69
+ readonly images: readonly [{
70
+ readonly height: 630;
71
+ readonly id: "landscape";
72
+ readonly width: 1200;
73
+ }];
74
+ readonly label: "Anywhere";
75
+ readonly shape: "full";
76
+ readonly utmSource: false;
77
+ };
78
+ export declare const shareKitBluesky: {
79
+ readonly actions: {
80
+ readonly desktop: readonly ["open-composer"];
81
+ readonly mobile: readonly ["share-image", "open-composer"];
82
+ };
83
+ readonly composer: ({ text }: ShareKitComposerInput) => string;
84
+ readonly count: ShareKitCounter;
85
+ readonly id: "bluesky";
86
+ readonly images: readonly [{
87
+ readonly height: 1350;
88
+ readonly id: "portrait";
89
+ readonly width: 1080;
90
+ }];
91
+ readonly label: "Bluesky";
92
+ readonly limit: 300;
93
+ readonly shape: "full";
94
+ };
95
+ export declare const shareKitFacebook: {
96
+ readonly actions: {
97
+ readonly desktop: readonly ["open-composer"];
98
+ readonly mobile: readonly ["share-link", "open-composer"];
99
+ };
100
+ readonly composer: ({ url }: ShareKitComposerInput) => string;
101
+ readonly count: typeof shareKitCountLength;
102
+ readonly hint: "Facebook only takes the link. Your caption is copied, so paste it into your post.";
103
+ readonly id: "facebook";
104
+ readonly images: readonly [{
105
+ readonly height: 630;
106
+ readonly id: "landscape";
107
+ readonly width: 1200;
108
+ }, {
109
+ readonly height: 1350;
110
+ readonly id: "portrait";
111
+ readonly width: 1080;
112
+ }];
113
+ readonly label: "Facebook";
114
+ readonly limit: 63206;
115
+ readonly shape: "full";
116
+ };
117
+ export declare const shareKitInstagram: {
118
+ readonly actions: {
119
+ readonly desktop: readonly [];
120
+ readonly mobile: readonly ["share-image"];
121
+ };
122
+ readonly count: typeof shareKitCountLength;
123
+ readonly hint: "Links in Instagram captions aren't clickable. Point people to the link in your bio.";
124
+ readonly id: "instagram";
125
+ readonly images: readonly [{
126
+ readonly height: 1350;
127
+ readonly id: "portrait";
128
+ readonly width: 1080;
129
+ }];
130
+ readonly label: "Instagram";
131
+ readonly limit: 2200;
132
+ readonly shape: "text";
133
+ };
134
+ export declare const shareKitInstagramStory: {
135
+ readonly actions: {
136
+ readonly desktop: readonly [];
137
+ readonly mobile: readonly ["share-image"];
138
+ };
139
+ readonly count: typeof shareKitCountLength;
140
+ readonly hint: "Add the link to your Story with a link sticker.";
141
+ readonly id: "instagram-story";
142
+ readonly images: readonly [{
143
+ readonly height: 1920;
144
+ readonly id: "story";
145
+ readonly width: 1080;
146
+ }, {
147
+ readonly height: 1350;
148
+ readonly id: "portrait";
149
+ readonly width: 1080;
150
+ }];
151
+ readonly label: "Story";
152
+ readonly shape: "url";
153
+ };
154
+ export declare const shareKitLinkedin: {
155
+ readonly actions: {
156
+ readonly desktop: readonly ["open-composer"];
157
+ readonly mobile: readonly ["share-link", "open-composer"];
158
+ };
159
+ readonly composer: ({ url }: ShareKitComposerInput) => string;
160
+ readonly count: typeof shareKitCountLength;
161
+ readonly hint: "LinkedIn only takes the link. Your caption is copied, so paste it into your post.";
162
+ readonly id: "linkedin";
163
+ readonly images: readonly [{
164
+ readonly height: 630;
165
+ readonly id: "landscape";
166
+ readonly width: 1200;
167
+ }];
168
+ readonly label: "LinkedIn";
169
+ readonly limit: 3000;
170
+ readonly shape: "full";
171
+ };
172
+ export declare const shareKitMastodon: {
173
+ readonly actions: {
174
+ readonly desktop: readonly [];
175
+ readonly mobile: readonly ["share-image"];
176
+ };
177
+ readonly count: ShareKitCounter;
178
+ readonly id: "mastodon";
179
+ readonly images: readonly [{
180
+ readonly height: 1350;
181
+ readonly id: "portrait";
182
+ readonly width: 1080;
183
+ }];
184
+ readonly label: "Mastodon";
185
+ readonly limit: 500;
186
+ readonly shape: "full";
187
+ };
188
+ export declare const shareKitMessages: {
189
+ readonly actions: {
190
+ readonly desktop: readonly ["share-text"];
191
+ readonly mobile: readonly ["share-text"];
192
+ };
193
+ readonly count: typeof shareKitCountLength;
194
+ readonly id: "messages";
195
+ readonly images: readonly [{
196
+ readonly height: 630;
197
+ readonly id: "landscape";
198
+ readonly width: 1200;
199
+ }];
200
+ readonly label: "Messages";
201
+ readonly shape: "full";
202
+ };
203
+ export declare const shareKitPinterest: {
204
+ readonly actions: {
205
+ readonly desktop: readonly ["open-composer"];
206
+ readonly mobile: readonly ["open-composer"];
207
+ };
208
+ readonly composer: ({ media, text, url }: ShareKitComposerInput) => string;
209
+ readonly count: typeof shareKitCountLength;
210
+ readonly id: "pinterest";
211
+ readonly images: readonly [{
212
+ readonly height: 1500;
213
+ readonly id: "pin";
214
+ readonly width: 1000;
215
+ }, {
216
+ readonly height: 1350;
217
+ readonly id: "portrait";
218
+ readonly width: 1080;
219
+ }];
220
+ readonly label: "Pinterest";
221
+ readonly limit: 800;
222
+ readonly shape: "text";
223
+ };
224
+ export declare const shareKitReddit: {
225
+ readonly actions: {
226
+ readonly desktop: readonly ["open-composer"];
227
+ readonly mobile: readonly ["open-composer"];
228
+ };
229
+ readonly composer: ({ text, url }: ShareKitComposerInput) => string;
230
+ readonly count: typeof shareKitCountLength;
231
+ readonly hint: "Reddit takes a title and the link.";
232
+ readonly id: "reddit";
233
+ readonly images: readonly [{
234
+ readonly height: 630;
235
+ readonly id: "landscape";
236
+ readonly width: 1200;
237
+ }];
238
+ readonly label: "Reddit";
239
+ readonly limit: 300;
240
+ readonly shape: "title";
241
+ };
242
+ export declare const shareKitThreads: {
243
+ readonly actions: {
244
+ readonly desktop: readonly ["open-composer"];
245
+ readonly mobile: readonly ["share-image", "open-composer"];
246
+ };
247
+ readonly composer: ({ text }: ShareKitComposerInput) => string;
248
+ readonly count: typeof shareKitCountUtf8;
249
+ readonly id: "threads";
250
+ readonly images: readonly [{
251
+ readonly height: 1350;
252
+ readonly id: "portrait";
253
+ readonly width: 1080;
254
+ }];
255
+ readonly label: "Threads";
256
+ readonly limit: 500;
257
+ readonly shape: "full";
258
+ };
259
+ export declare const shareKitX: {
260
+ readonly actions: {
261
+ readonly desktop: readonly ["open-composer"];
262
+ readonly mobile: readonly ["open-composer"];
263
+ };
264
+ readonly composer: ({ text }: ShareKitComposerInput) => string;
265
+ readonly count: ShareKitCounter;
266
+ readonly id: "x";
267
+ readonly images: readonly [{
268
+ readonly height: 630;
269
+ readonly id: "landscape";
270
+ readonly width: 1200;
271
+ }, {
272
+ readonly height: 1350;
273
+ readonly id: "portrait";
274
+ readonly width: 1080;
275
+ }];
276
+ readonly label: "X";
277
+ readonly limit: 280;
278
+ readonly shape: "full";
279
+ };
280
+ declare const shareKitInterfaceIconNames: readonly ["close", "more", "qr"];
281
+ type ShareKitIconName<Id extends string> = (typeof shareKitInterfaceIconNames)[number] | Id;
282
+ type ShareKitIcons<Id extends string> = Partial<Record<ShareKitIconName<Id>, string>>;
283
+ type ShareKitIconsOption<Id extends string> = (() => Promise<ShareKitIcons<Id>>) | ShareKitIcons<Id>;
284
+ export declare const shareKitInterfaceIcons: {
285
+ 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";
286
+ 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";
287
+ 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";
288
+ 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";
289
+ 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";
290
+ };
291
+ declare class ShareIconSource {
292
+ #private;
293
+ get icons(): Partial<Record<string, string>>;
294
+ get isLoading(): boolean;
295
+ constructor(option: ShareKitIconsOption<string>);
296
+ load(): Promise<Partial<Record<string, string>>>;
297
+ }
298
+ type ShareKitDestinationList = readonly [ShareKitDestination<string>, ...Array<ShareKitDestination<string>>];
299
+ interface ShareKitOptions<Destinations extends ShareKitDestinationList> {
300
+ destinations: Destinations;
301
+ icons?: ShareKitIconsOption<ShareKitDestinationIdOf<Destinations>>;
302
+ }
303
+ export declare function defineShareKit<const Destinations extends ShareKitDestinationList>({ destinations, icons }: ShareKitOptions<Destinations>): void;
304
+ declare const BaseElement: {
305
+ new (): HTMLElement;
306
+ prototype: HTMLElement;
307
+ };
308
+ declare class ShareKitElement extends BaseElement {
309
+ #private;
310
+ protected readonly catalogue: ReadonlyMap<string, ShareKitDestination<string>>;
311
+ protected readonly iconSource: ShareIconSource;
312
+ connectedCallback(): void;
313
+ disconnectedCallback(): void;
314
+ }
315
+ declare global {
316
+ interface HTMLElementTagNameMap {
317
+ 'share-kit': ShareKitElement;
318
+ }
319
+ }
1
320
  declare const shareKitStringDefaults: {
2
321
  readonly assetCopy: "Copy";
3
322
  readonly assetSave: "Save";
@@ -9,26 +328,9 @@ declare const shareKitStringDefaults: {
9
328
  readonly close: "Close";
10
329
  readonly copied: "Copied";
11
330
  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
331
  readonly destinationsMore: "More";
25
332
  readonly destinationsTitle: "Post to";
26
333
  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
334
  readonly imagesTitle: "Images";
33
335
  readonly linkCopy: "Copy link";
34
336
  readonly linkTitle: "Link";
@@ -47,33 +349,31 @@ declare const shareKitStringDefaults: {
47
349
  readonly title: "Share this page";
48
350
  };
49
351
  type ShareKitStringKey = keyof typeof shareKitStringDefaults;
50
- type ShareKitStrings = Record<ShareKitStringKey, string>;
51
- type ShareKitAssetRole = 'landscape' | 'photo' | 'portrait' | 'story';
52
- interface ShareKitAsset {
352
+ type ShareKitDestinationStringKey<Id extends string> = `destination.${Id}` | `hint.${Id}`;
353
+ type ShareKitStrings<Id extends string> = Partial<Record<ShareKitDestinationStringKey<Id>, string>> & Record<ShareKitStringKey, string>;
354
+ interface ShareKitAsset extends ShareKitImageFormat {
53
355
  alt: string;
54
356
  filename: string;
55
- height: number;
357
+ isSuggestable?: boolean;
56
358
  label: string;
57
359
  previewSrc: string;
58
- role: ShareKitAssetRole;
59
360
  src: string;
60
361
  type: string;
61
- width: number;
62
362
  }
63
363
  type ShareKitClassRole = 'action' | 'destination' | 'heading' | 'input' | 'primary';
64
- interface ShareKitSettings {
364
+ interface ShareKitSettings<Id extends string> {
65
365
  classNames?: Partial<Record<ShareKitClassRole, string>>;
66
- destinations: ReadonlyArray<ShareKitDestinationId>;
67
- destinationsMore?: ReadonlyArray<ShareKitDestinationId>;
366
+ destinations: ReadonlyArray<Id>;
367
+ destinationsMore?: ReadonlyArray<Id>;
68
368
  openHash?: string;
69
369
  utmMedium?: string;
70
370
  }
71
- interface ShareKitPayload {
371
+ interface ShareKitPayload<Id extends string> {
72
372
  assets: ReadonlyArray<ShareKitAsset>;
73
373
  description?: string;
74
374
  locale: string;
75
- settings: ShareKitSettings;
76
- strings?: Partial<Record<ShareKitStringKey, string>>;
375
+ settings: ShareKitSettings<Id>;
376
+ strings?: Partial<ShareKitStrings<Id>>;
77
377
  title: string;
78
378
  url: string;
79
379
  }
@@ -82,150 +382,12 @@ type ShareKitAction = 'copy' | 'copy-caption' | 'copy-link' | 'destination' | 'o
82
382
  interface ShareKitActionDetail {
83
383
  action: ShareKitAction;
84
384
  asset?: string;
85
- destination: ShareKitDestinationId;
385
+ destination: string;
86
386
  }
87
387
  declare global {
88
388
  interface GlobalEventHandlersEventMap {
89
389
  [shareKitActionEventName]: CustomEvent<ShareKitActionDetail>;
90
390
  }
91
391
  }
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 };
392
+ export declare function serializeShareKitPayload(payload: ShareKitPayload<string>): string;
393
+ export type { ShareKitAction, ShareKitActionDetail, ShareKitActionKind, ShareKitAsset, ShareKitClassRole, ShareKitComposerInput, ShareKitCounter, ShareKitDestination, ShareKitDestinationIdOf, ShareKitDestinationList, ShareKitDevice, ShareKitElement, ShareKitIconName, ShareKitIcons, ShareKitIconsOption, ShareKitImageFormat, ShareKitImageFormats, ShareKitOptions, ShareKitPayload, ShareKitSettings, ShareKitStringKey, ShareKitStrings };