@amos.com/amos-js 0.9.13 → 0.9.15
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 +67 -74
- package/dist/apple-pay.d.ts +14 -9
- package/dist/google-pay.d.ts +16 -10
- package/dist/index.d.ts +2 -2
- package/dist/index.js +2 -2
- package/dist/index.mjs +214 -237
- package/dist/messaging.d.ts +4 -2
- package/dist/mount.d.ts +14 -0
- package/dist/types.d.ts +25 -81
- package/package.json +1 -1
- package/src/apple-pay.ts +25 -23
- package/src/google-pay.ts +27 -27
- package/src/index.ts +1 -9
- package/src/messaging.ts +8 -4
- package/src/mount.ts +29 -4
- package/src/types.ts +43 -179
package/src/types.ts
CHANGED
|
@@ -219,6 +219,13 @@ export type ThemeVariable =
|
|
|
219
219
|
* Default: 0.75rem
|
|
220
220
|
*/
|
|
221
221
|
| "--floating-label-font-size"
|
|
222
|
+
/*
|
|
223
|
+
* Font size of floating labels in the empty / unfocused position
|
|
224
|
+
* (e.g. `0.9375rem`, `15px`). Falls back to `--input-font-size` when unset.
|
|
225
|
+
*
|
|
226
|
+
* Default: var(--input-font-size)
|
|
227
|
+
*/
|
|
228
|
+
| "--floating-label-empty-font-size"
|
|
222
229
|
/*
|
|
223
230
|
* Font weight of floating labels (e.g. `400`, `500`, `normal`, `bold`).
|
|
224
231
|
*
|
|
@@ -226,11 +233,19 @@ export type ThemeVariable =
|
|
|
226
233
|
*/
|
|
227
234
|
| "--floating-label-font-weight"
|
|
228
235
|
/*
|
|
229
|
-
* Color of floating labels
|
|
236
|
+
* Color of floating labels in the empty / unfocused position.
|
|
230
237
|
*
|
|
231
238
|
* Default: var(--muted-foreground)
|
|
232
239
|
*/
|
|
233
240
|
| "--floating-label-color"
|
|
241
|
+
/*
|
|
242
|
+
* Color of floating labels when focused or filled. Falls back to
|
|
243
|
+
* `--floating-label-color` when unset, so overriding only
|
|
244
|
+
* `--floating-label-color` still recolors both states.
|
|
245
|
+
*
|
|
246
|
+
* Default: var(--floating-label-color)
|
|
247
|
+
*/
|
|
248
|
+
| "--floating-label-floated-color"
|
|
234
249
|
/*
|
|
235
250
|
* Top offset of the shrunk floating label inside the control (e.g. `0.625rem`).
|
|
236
251
|
*
|
|
@@ -315,71 +330,28 @@ export type Appearance = {
|
|
|
315
330
|
};
|
|
316
331
|
|
|
317
332
|
/**
|
|
318
|
-
*
|
|
319
|
-
*
|
|
320
|
-
*
|
|
321
|
-
* `CSSProperties` object (string or number values). Custom properties such
|
|
322
|
-
* as `--apple-pay-button-height` are allowed.
|
|
323
|
-
*/
|
|
324
|
-
export type WalletButtonStyle = {
|
|
325
|
-
[property: string]: string | number | undefined;
|
|
326
|
-
};
|
|
327
|
-
|
|
328
|
-
/**
|
|
329
|
-
* `buttonstyle` attribute on Apple's `<apple-pay-button>`.
|
|
330
|
-
*
|
|
331
|
-
* @see https://developer.apple.com/documentation/apple_pay_on_the_web/apple-pay-button
|
|
332
|
-
*/
|
|
333
|
-
export type ApplePayButtonStyle = "black" | "white" | "white-outline";
|
|
334
|
-
|
|
335
|
-
/**
|
|
336
|
-
* `type` attribute on Apple's `<apple-pay-button>`.
|
|
333
|
+
* Apple's `<apple-pay-button>` attributes. `@types/applepayjs` only
|
|
334
|
+
* covers `ApplePaySession`, so this bag is the custom element's HTML
|
|
335
|
+
* attributes plus inner `style`. Posted as-is on `buttonProps`.
|
|
337
336
|
*
|
|
338
|
-
*
|
|
339
|
-
|
|
340
|
-
export type ApplePayButtonType =
|
|
341
|
-
| "plain"
|
|
342
|
-
| "buy"
|
|
343
|
-
| "set-up"
|
|
344
|
-
| "donate"
|
|
345
|
-
| "check-out"
|
|
346
|
-
| "book"
|
|
347
|
-
| "subscribe"
|
|
348
|
-
| "reload"
|
|
349
|
-
| "add-money"
|
|
350
|
-
| "top-up"
|
|
351
|
-
| "order"
|
|
352
|
-
| "rent"
|
|
353
|
-
| "support"
|
|
354
|
-
| "contribute"
|
|
355
|
-
| "tip";
|
|
356
|
-
|
|
357
|
-
/**
|
|
358
|
-
* Visual props for Apple's `<apple-pay-button>`, using Apple's attribute
|
|
359
|
-
* names. Applied inside the Amos embed iframe.
|
|
337
|
+
* Omitted fields keep the painted button's defaults. Height belongs on
|
|
338
|
+
* the mount `height` option.
|
|
360
339
|
*
|
|
361
340
|
* @see https://developer.apple.com/documentation/apple_pay_on_the_web/apple-pay-button
|
|
362
341
|
*/
|
|
363
342
|
export type ApplePayButtonElementProps = {
|
|
364
|
-
/**
|
|
365
|
-
* Stretch the button to the iframe width while preserving its default
|
|
366
|
-
* compact size when omitted.
|
|
367
|
-
*
|
|
368
|
-
* @default false
|
|
369
|
-
*/
|
|
370
|
-
fullWidth?: boolean;
|
|
371
343
|
/**
|
|
372
344
|
* Apple Pay button color.
|
|
373
345
|
*
|
|
374
346
|
* @default "black"
|
|
375
347
|
*/
|
|
376
|
-
buttonstyle?:
|
|
348
|
+
buttonstyle?: string;
|
|
377
349
|
/**
|
|
378
350
|
* Apple Pay button label / verb.
|
|
379
351
|
*
|
|
380
352
|
* @default "plain"
|
|
381
353
|
*/
|
|
382
|
-
type?:
|
|
354
|
+
type?: string;
|
|
383
355
|
/**
|
|
384
356
|
* BCP 47 locale for the button label (e.g. `"en-US"`).
|
|
385
357
|
*
|
|
@@ -387,140 +359,34 @@ export type ApplePayButtonElementProps = {
|
|
|
387
359
|
*/
|
|
388
360
|
locale?: string;
|
|
389
361
|
/**
|
|
390
|
-
* Inline style for the `<apple-pay-button>`.
|
|
391
|
-
* `--apple-pay-button-
|
|
392
|
-
* `--apple-pay-button-width` or CSS `width`.
|
|
362
|
+
* Inline style for the `<apple-pay-button>`. Omitted keys keep fill
|
|
363
|
+
* (`width: 100%` and `--apple-pay-button-width`).
|
|
393
364
|
*/
|
|
394
|
-
style?:
|
|
365
|
+
style?: Record<string, string | number | undefined>;
|
|
395
366
|
};
|
|
396
367
|
|
|
397
368
|
/**
|
|
398
|
-
*
|
|
399
|
-
*
|
|
369
|
+
* Google Pay button visuals: {@link google.payments.api.ButtonOptions}
|
|
370
|
+
* without the fields that cannot go through `postMessage`, plus inner
|
|
371
|
+
* `style`. Posted as-is on `buttonProps`.
|
|
372
|
+
*
|
|
373
|
+
* Omitted fields keep the painted button's defaults (`buttonType:
|
|
374
|
+
* "plain"`, `buttonSizeMode: "fill"`). Height belongs on the mount
|
|
375
|
+
* `height` option.
|
|
400
376
|
*
|
|
401
377
|
* @see https://developers.google.com/pay/api/web/guides/resources/customize
|
|
402
378
|
*/
|
|
403
|
-
export type GooglePayButtonElementProps =
|
|
379
|
+
export type GooglePayButtonElementProps = Omit<
|
|
380
|
+
google.payments.api.ButtonOptions,
|
|
381
|
+
"onClick" | "buttonRootNode" | "allowedPaymentMethods"
|
|
382
|
+
> & {
|
|
404
383
|
/**
|
|
405
|
-
*
|
|
406
|
-
*
|
|
407
|
-
*
|
|
408
|
-
* @default false
|
|
409
|
-
*/
|
|
410
|
-
fullWidth?: boolean;
|
|
411
|
-
/**
|
|
412
|
-
* Button label / verb.
|
|
413
|
-
*
|
|
414
|
-
* @default "short"
|
|
415
|
-
*/
|
|
416
|
-
buttonType?: google.payments.api.ButtonType;
|
|
417
|
-
/** Button color. */
|
|
418
|
-
buttonColor?: google.payments.api.ButtonColor;
|
|
419
|
-
/** Corner radius in pixels (0–20). */
|
|
420
|
-
buttonRadius?: number;
|
|
421
|
-
/**
|
|
422
|
-
* `"fill"` stretches the button to the container width; `"static"`
|
|
423
|
-
* uses Google's default size.
|
|
424
|
-
*/
|
|
425
|
-
buttonSizeMode?: google.payments.api.ButtonSizeMode;
|
|
426
|
-
/** BCP 47 locale for the button label (e.g. `"en"`). */
|
|
427
|
-
buttonLocale?: string;
|
|
428
|
-
/** Whether the button draws a border. */
|
|
429
|
-
buttonBorderType?: google.payments.api.ButtonBorderType;
|
|
430
|
-
/**
|
|
431
|
-
* Inline style for the Google Pay button wrapper. Use `height` /
|
|
432
|
-
* `width` here (unlike Apple Pay, Google honors CSS `height`).
|
|
384
|
+
* Inline style for the Google Pay button wrapper. Omitted keys keep
|
|
385
|
+
* fill (`width: 100%`).
|
|
433
386
|
*/
|
|
434
|
-
style?:
|
|
387
|
+
style?: Record<string, string | number | undefined>;
|
|
435
388
|
};
|
|
436
389
|
|
|
437
|
-
/**
|
|
438
|
-
* Keep only JSON-cloneable string/number declarations from a style object
|
|
439
|
-
* before sending it through `postMessage`.
|
|
440
|
-
*/
|
|
441
|
-
export function serializeWalletButtonStyle(
|
|
442
|
-
style: WalletButtonStyle | undefined,
|
|
443
|
-
): Record<string, string | number> | undefined {
|
|
444
|
-
if (!style || typeof style !== "object") {
|
|
445
|
-
return undefined;
|
|
446
|
-
}
|
|
447
|
-
|
|
448
|
-
const result: Record<string, string | number> = {};
|
|
449
|
-
for (const [key, value] of Object.entries(style)) {
|
|
450
|
-
if (typeof value === "string") {
|
|
451
|
-
if (value.length === 0) {
|
|
452
|
-
continue;
|
|
453
|
-
}
|
|
454
|
-
result[key] = value;
|
|
455
|
-
continue;
|
|
456
|
-
}
|
|
457
|
-
if (typeof value === "number" && Number.isFinite(value)) {
|
|
458
|
-
result[key] = value;
|
|
459
|
-
}
|
|
460
|
-
}
|
|
461
|
-
|
|
462
|
-
return Object.keys(result).length > 0 ? result : undefined;
|
|
463
|
-
}
|
|
464
|
-
|
|
465
|
-
export function pickApplePayButtonElementProps(
|
|
466
|
-
options: ApplePayButtonElementProps,
|
|
467
|
-
): ApplePayButtonElementProps {
|
|
468
|
-
const props: ApplePayButtonElementProps = {};
|
|
469
|
-
if (options.fullWidth !== undefined) {
|
|
470
|
-
props.fullWidth = options.fullWidth;
|
|
471
|
-
}
|
|
472
|
-
if (options.buttonstyle !== undefined) {
|
|
473
|
-
props.buttonstyle = options.buttonstyle;
|
|
474
|
-
}
|
|
475
|
-
if (options.type !== undefined) {
|
|
476
|
-
props.type = options.type;
|
|
477
|
-
}
|
|
478
|
-
if (options.locale !== undefined) {
|
|
479
|
-
props.locale = options.locale;
|
|
480
|
-
}
|
|
481
|
-
if (options.style !== undefined) {
|
|
482
|
-
const style = serializeWalletButtonStyle(options.style);
|
|
483
|
-
if (style) {
|
|
484
|
-
props.style = style;
|
|
485
|
-
}
|
|
486
|
-
}
|
|
487
|
-
return props;
|
|
488
|
-
}
|
|
489
|
-
|
|
490
|
-
export function pickGooglePayButtonElementProps(
|
|
491
|
-
options: GooglePayButtonElementProps,
|
|
492
|
-
): GooglePayButtonElementProps {
|
|
493
|
-
const props: GooglePayButtonElementProps = {};
|
|
494
|
-
if (options.fullWidth !== undefined) {
|
|
495
|
-
props.fullWidth = options.fullWidth;
|
|
496
|
-
}
|
|
497
|
-
if (options.buttonType !== undefined) {
|
|
498
|
-
props.buttonType = options.buttonType;
|
|
499
|
-
}
|
|
500
|
-
if (options.buttonColor !== undefined) {
|
|
501
|
-
props.buttonColor = options.buttonColor;
|
|
502
|
-
}
|
|
503
|
-
if (options.buttonRadius !== undefined) {
|
|
504
|
-
props.buttonRadius = options.buttonRadius;
|
|
505
|
-
}
|
|
506
|
-
if (options.buttonSizeMode !== undefined) {
|
|
507
|
-
props.buttonSizeMode = options.buttonSizeMode;
|
|
508
|
-
}
|
|
509
|
-
if (options.buttonLocale !== undefined) {
|
|
510
|
-
props.buttonLocale = options.buttonLocale;
|
|
511
|
-
}
|
|
512
|
-
if (options.buttonBorderType !== undefined) {
|
|
513
|
-
props.buttonBorderType = options.buttonBorderType;
|
|
514
|
-
}
|
|
515
|
-
if (options.style !== undefined) {
|
|
516
|
-
const style = serializeWalletButtonStyle(options.style);
|
|
517
|
-
if (style) {
|
|
518
|
-
props.style = style;
|
|
519
|
-
}
|
|
520
|
-
}
|
|
521
|
-
return props;
|
|
522
|
-
}
|
|
523
|
-
|
|
524
390
|
/**
|
|
525
391
|
* Typed `postMessage` payloads exchanged between the host page and the
|
|
526
392
|
* embedded Amos iframe.
|
|
@@ -555,17 +421,15 @@ export type Message =
|
|
|
555
421
|
appearance: Appearance;
|
|
556
422
|
}
|
|
557
423
|
| {
|
|
558
|
-
/**
|
|
559
|
-
* Parent → embed: visual options for the Apple Pay button. Nested
|
|
560
|
-
* under `props` so Apple's `type` attribute does not collide with
|
|
561
|
-
* this message discriminant.
|
|
562
|
-
*/
|
|
424
|
+
/** Parent → embed: visual options for the Apple Pay button. */
|
|
563
425
|
type: "UPDATE_APPLE_PAY_BUTTON";
|
|
426
|
+
height?: string;
|
|
564
427
|
props: ApplePayButtonElementProps;
|
|
565
428
|
}
|
|
566
429
|
| {
|
|
567
430
|
/** Parent → embed: visual options for the Google Pay button. */
|
|
568
431
|
type: "UPDATE_GOOGLE_PAY_BUTTON";
|
|
432
|
+
height?: string;
|
|
569
433
|
props: GooglePayButtonElementProps;
|
|
570
434
|
}
|
|
571
435
|
| {
|