@dloizides/marketing-astro-kit 1.11.0 → 1.13.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/CHANGELOG.md +173 -154
- package/README.md +72 -26
- package/package.json +16 -7
- package/src/ContactCard.astro +107 -0
- package/src/contactCard/CardActions.astro +20 -0
- package/src/contactCard/CardBrand.astro +25 -0
- package/src/contactCard/CardContacts.astro +22 -0
- package/src/contactCard/CardContactsVariant.ts +5 -0
- package/src/contactCard/CardDialog.astro +16 -0
- package/src/contactCard/CardIcon.astro +12 -0
- package/src/contactCard/CardIconName.ts +6 -0
- package/src/contactCard/CardIdentity.astro +14 -0
- package/src/contactCard/CardLinkKind.ts +6 -0
- package/src/contactCard/CardPortrait.astro +14 -0
- package/src/contactCard/CardQr.astro +24 -0
- package/src/contactCard/CardSave.astro +43 -0
- package/src/contactCard/CardValues.astro +12 -0
- package/src/contactCard/ContactCardLayout.ts +7 -0
- package/src/contactCard/ContactPhotoType.ts +5 -0
- package/src/contactCard/InstallRoute.ts +6 -0
- package/src/contactCard/cardIcons.ts +11 -0
- package/src/contactCard/cardLinks.ts +43 -0
- package/src/contactCard/checks.ts +28 -0
- package/src/contactCard/chooseInstall.ts +21 -0
- package/src/contactCard/contactCard.css +69 -0
- package/src/contactCard/index.ts +16 -0
- package/src/contactCard/layouts.css +106 -0
- package/src/contactCard/manifest.ts +37 -0
- package/src/contactCard/motion/OpenMotion.ts +7 -0
- package/src/contactCard/motion/QrMotion.ts +7 -0
- package/src/contactCard/motion/SaveMotion.ts +7 -0
- package/src/contactCard/motion/TiltMotion.ts +7 -0
- package/src/contactCard/motion/beatTable.ts +144 -0
- package/src/contactCard/motion/beats.ts +43 -0
- package/src/contactCard/motion/cardMotion.ts +49 -0
- package/src/contactCard/motion/easings.ts +9 -0
- package/src/contactCard/motion/holdDuringOpen.ts +22 -0
- package/src/contactCard/motion/mountMotion.ts +26 -0
- package/src/contactCard/motion/mountOpenMark.ts +20 -0
- package/src/contactCard/motion/mountQrTurn.ts +86 -0
- package/src/contactCard/motion/mountSave.ts +26 -0
- package/src/contactCard/motion/mountTilt.ts +92 -0
- package/src/contactCard/motion/openCss.ts +18 -0
- package/src/contactCard/motion/parts.ts +25 -0
- package/src/contactCard/motion/playBeats.ts +21 -0
- package/src/contactCard/motion/sides.ts +33 -0
- package/src/contactCard/motion/tiltPose.ts +38 -0
- package/src/contactCard/motion.css +39 -0
- package/src/contactCard/mount.ts +76 -0
- package/src/contactCard/phone.ts +11 -0
- package/src/contactCard/qrSvg.ts +54 -0
- package/src/contactCard/types.ts +47 -0
- package/src/contactCard/vCard.ts +48 -0
- package/src/contactCard/vCardLines.ts +33 -0
- package/src/logoIntro/LogoIntroState.ts +8 -0
- package/src/logoIntro/geometry.ts +53 -0
- package/src/logoIntro/index.ts +6 -0
- package/src/logoIntro/runLogoIntro.ts +75 -0
- package/src/logoIntro/settleReveal.ts +146 -0
- package/src/logoIntro/strokes.ts +61 -0
- package/src/logoIntro/timeline.ts +30 -0
- package/src/motionController/createMotionController.ts +11 -9
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
---
|
|
2
|
+
import './contactCard/contactCard.css';
|
|
3
|
+
import './contactCard/layouts.css';
|
|
4
|
+
import './contactCard/motion.css';
|
|
5
|
+
import CardActions from './contactCard/CardActions.astro';
|
|
6
|
+
import CardBrand from './contactCard/CardBrand.astro';
|
|
7
|
+
import CardContacts from './contactCard/CardContacts.astro';
|
|
8
|
+
import { CardContactsVariant } from './contactCard/CardContactsVariant';
|
|
9
|
+
import CardDialog from './contactCard/CardDialog.astro';
|
|
10
|
+
import CardIdentity from './contactCard/CardIdentity.astro';
|
|
11
|
+
import { buildCardLinks, requireCardLayout, requireSaveHref } from './contactCard/cardLinks';
|
|
12
|
+
import CardPortrait from './contactCard/CardPortrait.astro';
|
|
13
|
+
import CardQr from './contactCard/CardQr.astro';
|
|
14
|
+
import CardSave from './contactCard/CardSave.astro';
|
|
15
|
+
import CardValues from './contactCard/CardValues.astro';
|
|
16
|
+
import { requireHttpsUrl } from './contactCard/checks';
|
|
17
|
+
import { ContactCardLayout } from './contactCard/ContactCardLayout';
|
|
18
|
+
import { InstallRoute } from './contactCard/InstallRoute';
|
|
19
|
+
import { motionAttributes, resolveCardMotion, type ContactCardMotionInput } from './contactCard/motion/cardMotion';
|
|
20
|
+
import { buildOpenCss } from './contactCard/motion/openCss';
|
|
21
|
+
import { OpenMotion } from './contactCard/motion/OpenMotion';
|
|
22
|
+
import { TiltMotion } from './contactCard/motion/TiltMotion';
|
|
23
|
+
import { buildQrSvg } from './contactCard/qrSvg';
|
|
24
|
+
import type { ContactCardBrand, ContactCardBrandMarkup, ContactCardLabels, ContactCardPerson, ContactCardPortrait } from './contactCard/types';
|
|
25
|
+
|
|
26
|
+
interface Props {
|
|
27
|
+
layout?: `${ContactCardLayout}`;
|
|
28
|
+
person: ContactCardPerson;
|
|
29
|
+
brand: ContactCardBrand;
|
|
30
|
+
portrait: ContactCardPortrait;
|
|
31
|
+
labels: ContactCardLabels;
|
|
32
|
+
/** Address of the person's `.vcf` file. */
|
|
33
|
+
saveHref: string;
|
|
34
|
+
/** Full https address of this card, carried by the QR. */
|
|
35
|
+
cardUrl: string;
|
|
36
|
+
/** The four motion settings; each left out takes its recommended option. */
|
|
37
|
+
motion?: ContactCardMotionInput;
|
|
38
|
+
/** The mark from @dloizides/logo-kit, drawn in on open; the brand image is used without it. */
|
|
39
|
+
brandMarkup?: ContactCardBrandMarkup;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
const { person, brand, portrait, labels } = Astro.props;
|
|
43
|
+
const layout = requireCardLayout(Astro.props.layout ?? ContactCardLayout.Name);
|
|
44
|
+
const saveHref = requireSaveHref(Astro.props.saveHref);
|
|
45
|
+
const cardUrl = requireHttpsUrl(Astro.props.cardUrl, 'cardUrl');
|
|
46
|
+
const links = buildCardLinks(person, labels);
|
|
47
|
+
const qrSvg = buildQrSvg({ url: cardUrl, title: labels.qrTitle });
|
|
48
|
+
const motion = resolveCardMotion(Astro.props.motion);
|
|
49
|
+
const openCss = buildOpenCss(motion.openMotion);
|
|
50
|
+
const brandProps = { brand, markup: Astro.props.brandMarkup, animated: motion.openMotion !== OpenMotion.None };
|
|
51
|
+
const portraitProps = { portrait, light: motion.tiltMotion === TiltMotion.PortraitLeans || motion.tiltMotion === TiltMotion.LayersDrift };
|
|
52
|
+
const saveProps = { href: saveHref, label: labels.save, readyLabel: labels.ready, saveMotion: motion.saveMotion };
|
|
53
|
+
---
|
|
54
|
+
<div class="tmk-card" data-contact-card data-layout={layout} {...motionAttributes(motion)} data-testid="card">
|
|
55
|
+
{openCss !== '' && <style is:inline set:html={openCss} />}
|
|
56
|
+
{layout === ContactCardLayout.Portrait && (
|
|
57
|
+
<CardBrand {...brandProps} />
|
|
58
|
+
<div class="tmk-card-disc"><CardPortrait {...portraitProps} /></div>
|
|
59
|
+
<div class="tmk-card-main">
|
|
60
|
+
<CardIdentity person={person} />
|
|
61
|
+
<CardSave {...saveProps} />
|
|
62
|
+
<CardContacts links={links} label={labels.contacts} variant={CardContactsVariant.Tiles} />
|
|
63
|
+
<CardValues links={links} />
|
|
64
|
+
<CardActions labels={labels} />
|
|
65
|
+
</div>
|
|
66
|
+
)}
|
|
67
|
+
{layout === ContactCardLayout.Name && (
|
|
68
|
+
<CardBrand {...brandProps} />
|
|
69
|
+
<CardIdentity person={person}><CardPortrait {...portraitProps} /></CardIdentity>
|
|
70
|
+
<CardSave {...saveProps} />
|
|
71
|
+
<CardContacts links={links} label={labels.contacts} variant={CardContactsVariant.Rows} />
|
|
72
|
+
<CardActions labels={labels} />
|
|
73
|
+
)}
|
|
74
|
+
{layout === ContactCardLayout.Framed && (
|
|
75
|
+
<div class="tmk-card-frame" data-part="frame">
|
|
76
|
+
<CardBrand {...brandProps} />
|
|
77
|
+
<CardIdentity person={person}><CardPortrait {...portraitProps} /></CardIdentity>
|
|
78
|
+
<CardContacts links={links} label={labels.contacts} variant={CardContactsVariant.Rows} />
|
|
79
|
+
</div>
|
|
80
|
+
<CardActions labels={labels}><CardSave {...saveProps} /></CardActions>
|
|
81
|
+
)}
|
|
82
|
+
{layout === ContactCardLayout.Honeycomb && (
|
|
83
|
+
<CardBrand {...brandProps} />
|
|
84
|
+
<CardIdentity person={person} />
|
|
85
|
+
<div class="tmk-card-comb" data-part="comb">
|
|
86
|
+
<CardPortrait {...portraitProps} />
|
|
87
|
+
<CardSave {...saveProps} />
|
|
88
|
+
<CardContacts links={links} label={labels.contacts} variant={CardContactsVariant.Tiles} />
|
|
89
|
+
</div>
|
|
90
|
+
<CardValues links={links} />
|
|
91
|
+
<CardActions labels={labels} />
|
|
92
|
+
)}
|
|
93
|
+
<CardQr qrSvg={qrSvg} cardUrl={cardUrl} title={labels.qrTitle} hideLabel={labels.hideQr} qrMotion={motion.qrMotion} />
|
|
94
|
+
{motion.tiltMotion === TiltMotion.CardLeans && <span class="tmk-card-edge" aria-hidden="true" data-part="edge"><span data-part="edge-light"></span></span>}
|
|
95
|
+
<CardDialog name="install" title={labels.installTitle} closeLabel={labels.close}>
|
|
96
|
+
<ol data-install-route={InstallRoute.AppleSteps} data-testid="card-install-steps" hidden>
|
|
97
|
+
{labels.appleSteps.map((step) => <li>{step}</li>)}
|
|
98
|
+
</ol>
|
|
99
|
+
<p data-install-route={InstallRoute.MenuHint} data-testid="card-install-hint" hidden>{labels.menuHint}</p>
|
|
100
|
+
</CardDialog>
|
|
101
|
+
</div>
|
|
102
|
+
|
|
103
|
+
<script>
|
|
104
|
+
import { mountContactCards } from './contactCard/mount';
|
|
105
|
+
|
|
106
|
+
mountContactCards();
|
|
107
|
+
</script>
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
---
|
|
2
|
+
import CardIcon from './CardIcon.astro';
|
|
3
|
+
import { CardIconName } from './CardIconName';
|
|
4
|
+
import type { ContactCardLabels } from './types';
|
|
5
|
+
|
|
6
|
+
interface Props {
|
|
7
|
+
labels: ContactCardLabels;
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
const { labels } = Astro.props;
|
|
11
|
+
---
|
|
12
|
+
<div class="tmk-card-actions" data-part="actions">
|
|
13
|
+
<slot />
|
|
14
|
+
<button class="tmk-card-button tmk-card-install" type="button" aria-haspopup="dialog" hidden data-card-install data-part="install" data-testid="card-install">
|
|
15
|
+
<CardIcon name={CardIconName.Install} /><span>{labels.install}</span>
|
|
16
|
+
</button>
|
|
17
|
+
<button class="tmk-card-button" type="button" aria-expanded="false" hidden data-card-qr data-part="show-qr" data-testid="card-show-qr">
|
|
18
|
+
<CardIcon name={CardIconName.Qr} /><span class="tmk-card-qr-words"><span data-part="qr-open">{labels.showQr}</span><span data-part="qr-close" aria-hidden="true">{labels.hideQr}</span></span>
|
|
19
|
+
</button>
|
|
20
|
+
</div>
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
---
|
|
2
|
+
import type { ContactCardBrand, ContactCardBrandMarkup } from './types';
|
|
3
|
+
|
|
4
|
+
interface Props {
|
|
5
|
+
brand: ContactCardBrand;
|
|
6
|
+
markup?: ContactCardBrandMarkup | undefined;
|
|
7
|
+
animated: boolean;
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
const { brand, markup, animated } = Astro.props;
|
|
11
|
+
const wordmark = markup?.wordmark ?? null;
|
|
12
|
+
const wordmarkCss = animated && wordmark !== null ? `@media (prefers-reduced-motion:no-preference){${wordmark.css}}` : '';
|
|
13
|
+
---
|
|
14
|
+
<a class="tmk-card-brand" href={brand.href} aria-label={brand.label} data-part="brand" data-testid="card-brand">
|
|
15
|
+
{markup === undefined ? (
|
|
16
|
+
<img src={brand.src} width={brand.width} height={brand.height} alt="" data-part="mark" />
|
|
17
|
+
) : (
|
|
18
|
+
<>
|
|
19
|
+
<span class="tmk-card-mark" aria-hidden="true" data-part="mark" data-logo-intro={animated ? '' : undefined} set:html={animated ? markup.intro : markup.still} />
|
|
20
|
+
{animated && <template data-mark-still set:html={markup.still} />}
|
|
21
|
+
{wordmark !== null && <span class="tmk-card-wordmark" aria-hidden="true" data-part="wordmark" set:html={wordmark.html} />}
|
|
22
|
+
{wordmarkCss !== '' && <style is:inline set:html={wordmarkCss} />}
|
|
23
|
+
</>
|
|
24
|
+
)}
|
|
25
|
+
</a>
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
---
|
|
2
|
+
import CardIcon from './CardIcon.astro';
|
|
3
|
+
import { CardContactsVariant } from './CardContactsVariant';
|
|
4
|
+
import type { CardLink } from './cardLinks';
|
|
5
|
+
|
|
6
|
+
interface Props {
|
|
7
|
+
links: CardLink[];
|
|
8
|
+
label: string;
|
|
9
|
+
variant: CardContactsVariant;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
const { links, label, variant } = Astro.props;
|
|
13
|
+
---
|
|
14
|
+
<nav class={`tmk-card-${variant}`} aria-label={label} data-part="contacts">
|
|
15
|
+
{links.map((link) => (
|
|
16
|
+
<a href={link.href} data-part={link.kind} data-testid={`card-${link.kind}`}>
|
|
17
|
+
<CardIcon name={link.kind} />
|
|
18
|
+
<span class="tmk-card-label">{link.label}</span>
|
|
19
|
+
{variant === CardContactsVariant.Rows && <span class="tmk-card-value">{link.value}</span>}
|
|
20
|
+
</a>
|
|
21
|
+
))}
|
|
22
|
+
</nav>
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
---
|
|
2
|
+
interface Props {
|
|
3
|
+
name: string;
|
|
4
|
+
title: string;
|
|
5
|
+
closeLabel: string;
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
const { name, title, closeLabel } = Astro.props;
|
|
9
|
+
---
|
|
10
|
+
<dialog class="tmk-card-dialog" aria-label={title} data-card-dialog={name} data-part={`${name}-dialog`} data-testid={`card-${name}-dialog`}>
|
|
11
|
+
<h2>{title}</h2>
|
|
12
|
+
<slot />
|
|
13
|
+
<form method="dialog">
|
|
14
|
+
<button class="tmk-card-button" type="submit" autofocus data-testid={`card-${name}-close`}>{closeLabel}</button>
|
|
15
|
+
</form>
|
|
16
|
+
</dialog>
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
---
|
|
2
|
+
import { CARD_ICONS } from './cardIcons';
|
|
3
|
+
import type { CardIconName } from './CardIconName';
|
|
4
|
+
import type { CardLinkKind } from './CardLinkKind';
|
|
5
|
+
|
|
6
|
+
interface Props {
|
|
7
|
+
name: CardIconName | CardLinkKind;
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
const { name } = Astro.props;
|
|
11
|
+
---
|
|
12
|
+
<svg class="tmk-card-icon" viewBox="0 0 24 24" aria-hidden="true" set:html={CARD_ICONS[name]} />
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
---
|
|
2
|
+
import type { ContactCardPerson } from './types';
|
|
3
|
+
|
|
4
|
+
interface Props {
|
|
5
|
+
person: ContactCardPerson;
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
const { person } = Astro.props;
|
|
9
|
+
---
|
|
10
|
+
<div class="tmk-card-identity">
|
|
11
|
+
<h1 class="tmk-card-name" data-part="name" data-testid="card-name"><span>{person.givenName}</span>{' '}<span>{person.familyName}</span></h1>
|
|
12
|
+
<slot />
|
|
13
|
+
<p class="tmk-card-role" data-part="role" data-testid="card-role">{person.role}</p>
|
|
14
|
+
</div>
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
---
|
|
2
|
+
import type { ContactCardPortrait } from './types';
|
|
3
|
+
|
|
4
|
+
interface Props {
|
|
5
|
+
portrait: ContactCardPortrait;
|
|
6
|
+
light: boolean;
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
const { portrait, light } = Astro.props;
|
|
10
|
+
---
|
|
11
|
+
<div class="tmk-card-portrait" data-part="portrait" data-testid="card-portrait">
|
|
12
|
+
<div><img src={portrait.src} width={portrait.width} height={portrait.height} alt={portrait.alt} /></div>
|
|
13
|
+
{light && <span class="tmk-card-hex-light" aria-hidden="true" data-part="hex-light"><span data-part="hex-band"></span></span>}
|
|
14
|
+
</div>
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
---
|
|
2
|
+
import { QrMotion } from './motion/QrMotion';
|
|
3
|
+
|
|
4
|
+
interface Props {
|
|
5
|
+
qrSvg: string;
|
|
6
|
+
cardUrl: string;
|
|
7
|
+
title: string;
|
|
8
|
+
hideLabel: string;
|
|
9
|
+
qrMotion: QrMotion;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
const { qrSvg, cardUrl, title, hideLabel, qrMotion } = Astro.props;
|
|
13
|
+
const onBack = qrMotion === QrMotion.TurnOver || qrMotion === QrMotion.CubeTurn;
|
|
14
|
+
---
|
|
15
|
+
{onBack ? (
|
|
16
|
+
<div class="tmk-card-qr-side tmk-card-qr-back" role="group" aria-label={title} data-part="qr-back" data-side-hidden inert>
|
|
17
|
+
<div class="tmk-card-qr" data-qr-value={cardUrl} data-testid="card-qr" set:html={qrSvg} />
|
|
18
|
+
<button class="tmk-card-button" type="button" data-card-qr-close data-testid="card-qr-close">{hideLabel}</button>
|
|
19
|
+
</div>
|
|
20
|
+
) : (
|
|
21
|
+
<div class="tmk-card-qr-side" role="group" aria-label={title} data-part="qr-panel" data-side-hidden inert>
|
|
22
|
+
<div class="tmk-card-qr" data-qr-value={cardUrl} data-testid="card-qr" set:html={qrSvg} />
|
|
23
|
+
</div>
|
|
24
|
+
)}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
---
|
|
2
|
+
import CardIcon from './CardIcon.astro';
|
|
3
|
+
import { CardIconName } from './CardIconName';
|
|
4
|
+
import { SaveMotion } from './motion/SaveMotion';
|
|
5
|
+
|
|
6
|
+
interface Props {
|
|
7
|
+
href: string;
|
|
8
|
+
label: string;
|
|
9
|
+
readyLabel: string;
|
|
10
|
+
saveMotion: SaveMotion;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
const { href, label, readyLabel, saveMotion } = Astro.props;
|
|
14
|
+
const TICK = 'M5 12.5l4.5 4.5L19 7.5';
|
|
15
|
+
---
|
|
16
|
+
<a class="tmk-card-save" href={href} data-part="save" data-testid="card-save">
|
|
17
|
+
<span class="tmk-card-save-icon">
|
|
18
|
+
<span data-part="save-icon"><CardIcon name={CardIconName.Save} /></span>
|
|
19
|
+
{saveMotion === SaveMotion.Tick && (
|
|
20
|
+
<svg class="tmk-card-mini tmk-card-tick" viewBox="0 0 24 24" aria-hidden="true" data-part="tick"><path d={TICK} /></svg>
|
|
21
|
+
<span class="tmk-card-tick-cover" data-part="tick-cover"></span>
|
|
22
|
+
)}
|
|
23
|
+
{saveMotion === SaveMotion.CubeCloses && (
|
|
24
|
+
<svg class="tmk-card-mini tmk-card-cube" viewBox="0 0 24 24" aria-hidden="true">
|
|
25
|
+
<path data-part="cube-top" d="M12 3.5l7.5 4.2-7.5 4.2-7.5-4.2z" />
|
|
26
|
+
<path data-part="cube-left" d="M4.5 9.3l6.8 3.9v7.6l-6.8-3.9z" />
|
|
27
|
+
<path data-part="cube-right" d="M19.5 9.3l-6.8 3.9v7.6l6.8-3.9z" />
|
|
28
|
+
</svg>
|
|
29
|
+
)}
|
|
30
|
+
</span>
|
|
31
|
+
<span class="tmk-card-save-words">
|
|
32
|
+
<span data-part="save-text">{label}</span>
|
|
33
|
+
<span data-part="ready-text" aria-hidden="true">{readyLabel}</span>
|
|
34
|
+
</span>
|
|
35
|
+
{saveMotion === SaveMotion.LightCrosses && (
|
|
36
|
+
<span class="tmk-card-wipe" data-part="wipe" aria-hidden="true">
|
|
37
|
+
<span class="tmk-card-wipe-in" data-part="wipe-in">
|
|
38
|
+
<svg class="tmk-card-mini" viewBox="0 0 24 24"><path d={TICK} /></svg><span>{readyLabel}</span>
|
|
39
|
+
</span>
|
|
40
|
+
</span>
|
|
41
|
+
)}
|
|
42
|
+
</a>
|
|
43
|
+
<span class="tmk-card-live" aria-live="polite" data-part="save-live"></span>
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
---
|
|
2
|
+
import type { CardLink } from './cardLinks';
|
|
3
|
+
|
|
4
|
+
interface Props {
|
|
5
|
+
links: CardLink[];
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
const { links } = Astro.props;
|
|
9
|
+
---
|
|
10
|
+
<ul class="tmk-card-values" data-part="values" data-testid="card-values">
|
|
11
|
+
{links.map((link) => <li>{link.value}</li>)}
|
|
12
|
+
</ul>
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { CardIconName } from './CardIconName';
|
|
2
|
+
import { CardLinkKind } from './CardLinkKind';
|
|
3
|
+
|
|
4
|
+
export const CARD_ICONS: Readonly<Record<CardIconName | CardLinkKind, string>> = {
|
|
5
|
+
[CardIconName.Save]: '<circle cx="9.5" cy="8" r="4"/><path d="M2.5 20.5c0-4 3-6.5 7-6.5 1.6 0 3 .4 4.2 1.1M18 14v7M14.5 17.5h7"/>',
|
|
6
|
+
[CardLinkKind.Call]: '<path d="M5 3h4l1.8 4.8-2.3 1.7a12 12 0 0 0 6 6l1.7-2.3L21 15v4a2 2 0 0 1-2.2 2A17 17 0 0 1 3 5.2 2 2 0 0 1 5 3Z"/>',
|
|
7
|
+
[CardLinkKind.Email]: '<rect x="3" y="5" width="18" height="14" rx="1.5"/><path d="m3.5 6.5 8.5 6.5 8.5-6.5"/>',
|
|
8
|
+
[CardLinkKind.Website]: '<circle cx="12" cy="12" r="9"/><path d="M3 12h18M12 3c2.6 2.6 3.8 5.6 3.8 9S14.6 18.4 12 21c-2.6-2.6-3.8-5.6-3.8-9S9.4 5.6 12 3Z"/>',
|
|
9
|
+
[CardIconName.Install]: '<rect x="6" y="2.5" width="12" height="19" rx="2"/><path d="M12 8v7M8.8 11.8 12 15l3.2-3.2"/>',
|
|
10
|
+
[CardIconName.Qr]: '<rect x="3.5" y="3.5" width="6.5" height="6.5"/><rect x="14" y="3.5" width="6.5" height="6.5"/><rect x="3.5" y="14" width="6.5" height="6.5"/><path d="M14 14h2.5v2.5M20.5 14v2.5M14 20.5h2.5M20.5 20.5h-1.5"/>',
|
|
11
|
+
};
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import { CardLinkKind } from './CardLinkKind';
|
|
2
|
+
import { optionError, requireEmail, requireHttpsUrl } from './checks';
|
|
3
|
+
import { ContactCardLayout } from './ContactCardLayout';
|
|
4
|
+
import { toDialNumber } from './phone';
|
|
5
|
+
import type { ContactCardLabels, ContactCardPerson } from './types';
|
|
6
|
+
|
|
7
|
+
const LAYOUTS = [ContactCardLayout.Portrait, ContactCardLayout.Name, ContactCardLayout.Framed, ContactCardLayout.Honeycomb];
|
|
8
|
+
const SAVE_HREF_PATTERN = /^(?:https:\/\/|\/(?![/\\]))\S+$/;
|
|
9
|
+
|
|
10
|
+
export interface CardLink {
|
|
11
|
+
kind: CardLinkKind;
|
|
12
|
+
label: string;
|
|
13
|
+
value: string;
|
|
14
|
+
href: string;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
function websiteText(href: string): string {
|
|
18
|
+
const { host, pathname } = new URL(href);
|
|
19
|
+
return `${host}${pathname}`.replace(/\/$/, '');
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
/** Returns the call, email and website links in card order; throws naming the first bad field. */
|
|
23
|
+
export function buildCardLinks(person: ContactCardPerson, labels: Pick<ContactCardLabels, CardLinkKind>): CardLink[] {
|
|
24
|
+
const website = requireHttpsUrl(person.website, 'website');
|
|
25
|
+
return [
|
|
26
|
+
{ kind: CardLinkKind.Call, label: labels.call, value: person.phone, href: `tel:${toDialNumber(person.phone)}` },
|
|
27
|
+
{ kind: CardLinkKind.Email, label: labels.email, value: person.email, href: `mailto:${requireEmail(person.email)}` },
|
|
28
|
+
{ kind: CardLinkKind.Website, label: labels.website, value: websiteText(website), href: website },
|
|
29
|
+
];
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
/** Returns the layout; throws listing the allowed ones, because a typo would render an unstyled card. */
|
|
33
|
+
export function requireCardLayout(layout: string): ContactCardLayout {
|
|
34
|
+
const known = LAYOUTS.find((item) => String(item) === layout);
|
|
35
|
+
if (known === undefined) throw optionError('layout', `must be one of ${LAYOUTS.join(', ')}`);
|
|
36
|
+
return known;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
/** Returns the address of the contact file; throws unless it is an https URL or a path on this site. */
|
|
40
|
+
export function requireSaveHref(href: string): string {
|
|
41
|
+
if (!SAVE_HREF_PATTERN.test(href)) throw optionError('saveHref', 'must be an https URL or a path starting with /');
|
|
42
|
+
return href;
|
|
43
|
+
}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
const ERROR_PREFIX = 'contactCard:';
|
|
2
|
+
const HTTPS_PROTOCOL = 'https:';
|
|
3
|
+
const EMAIL_PATTERN = /^[\w.+-]+@[\w-]+(?:\.[\w-]+)+$/;
|
|
4
|
+
|
|
5
|
+
/** Returns the error every contact card builder throws for a bad option. */
|
|
6
|
+
export function optionError(field: string, problem: string): Error {
|
|
7
|
+
return new Error(`${ERROR_PREFIX} ${field} ${problem}`);
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
/** Returns the trimmed text; throws naming the field when it is blank. */
|
|
11
|
+
export function requireText(value: string, field: string): string {
|
|
12
|
+
const trimmed = value.trim();
|
|
13
|
+
if (trimmed === '') throw optionError(field, 'must not be blank');
|
|
14
|
+
return trimmed;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
/** Returns the URL in its normalised, percent-encoded form; throws naming the field unless it is https. */
|
|
18
|
+
export function requireHttpsUrl(value: string, field: string): string {
|
|
19
|
+
const url = URL.canParse(value) ? new URL(value) : null;
|
|
20
|
+
if (url?.protocol !== HTTPS_PROTOCOL) throw optionError(field, 'must be an https URL');
|
|
21
|
+
return url.href;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
/** Returns the address unchanged; throws unless it is one email address. */
|
|
25
|
+
export function requireEmail(email: string): string {
|
|
26
|
+
if (!EMAIL_PATTERN.test(email)) throw optionError('email', 'must be one email address');
|
|
27
|
+
return email;
|
|
28
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { InstallRoute } from './InstallRoute';
|
|
2
|
+
|
|
3
|
+
const APPLE_MOBILE_PATTERN = /iPhone|iPad|iPod/;
|
|
4
|
+
const MAC_PATTERN = /Macintosh/;
|
|
5
|
+
|
|
6
|
+
export interface InstallState {
|
|
7
|
+
hasPrompt: boolean;
|
|
8
|
+
isApple: boolean;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
/** Returns true on an iPhone or iPad; an iPad reports itself as a Mac, but only the iPad has touch points. */
|
|
12
|
+
export function isAppleMobile(device: Pick<Navigator, 'userAgent' | 'maxTouchPoints'>): boolean {
|
|
13
|
+
if (APPLE_MOBILE_PATTERN.test(device.userAgent)) return true;
|
|
14
|
+
return MAC_PATTERN.test(device.userAgent) && device.maxTouchPoints > 1;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
/** Returns the browser's own prompt when it offered one, else the help that fits the device. */
|
|
18
|
+
export function chooseInstallRoute(state: InstallState): InstallRoute {
|
|
19
|
+
if (state.hasPrompt) return InstallRoute.Prompt;
|
|
20
|
+
return state.isApple ? InstallRoute.AppleSteps : InstallRoute.MenuHint;
|
|
21
|
+
}
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
.tmk-card{
|
|
2
|
+
--tmk-card-hex:polygon(50% 0,100% 25%,100% 75%,50% 100%,0 75%,0 25%);
|
|
3
|
+
--card-bg:var(--tmk-card-bg,var(--paper,Canvas));
|
|
4
|
+
--card-raised:var(--tmk-card-raised,var(--bg-tint,var(--card-bg)));
|
|
5
|
+
--card-fill:var(--tmk-card-fill,var(--tmk-card-raised,var(--bg-tint,color-mix(in srgb,var(--card-text) 8%,var(--card-bg)))));
|
|
6
|
+
--card-text:var(--tmk-card-text,var(--ink,CanvasText));
|
|
7
|
+
--card-heading:var(--tmk-card-heading,var(--card-text));
|
|
8
|
+
--card-soft:var(--tmk-card-text-soft,var(--muted,var(--card-text)));
|
|
9
|
+
--card-line:var(--tmk-card-line,var(--hairline,currentColor));
|
|
10
|
+
--card-edge:var(--tmk-card-edge,var(--card-soft));
|
|
11
|
+
--card-accent:var(--tmk-card-accent,var(--accent,LinkText));
|
|
12
|
+
--card-on-accent:var(--tmk-card-on-accent,var(--card-bg));
|
|
13
|
+
--card-radius:var(--tmk-card-radius,6px);
|
|
14
|
+
position:relative;
|
|
15
|
+
display:flex;
|
|
16
|
+
flex-direction:column;
|
|
17
|
+
min-height:100vh;
|
|
18
|
+
min-height:100svh;
|
|
19
|
+
padding:12px max(16px,(100% - 480px)/2) 16px;
|
|
20
|
+
background:var(--card-bg);
|
|
21
|
+
color:var(--card-text);
|
|
22
|
+
font-family:var(--tmk-card-font,inherit);
|
|
23
|
+
font-size:16px;
|
|
24
|
+
font-weight:400;
|
|
25
|
+
line-height:1.4;
|
|
26
|
+
}
|
|
27
|
+
.tmk-card,.tmk-card *,.tmk-card *::before,.tmk-card *::after{box-sizing:border-box}
|
|
28
|
+
.tmk-card :where(h1,h2,p,ul,ol,button){margin:0;font:inherit;letter-spacing:normal}
|
|
29
|
+
.tmk-card :where(a,button){color:inherit;text-decoration:none}
|
|
30
|
+
.tmk-card :where(button){cursor:pointer}
|
|
31
|
+
.tmk-card [hidden]{display:none!important}
|
|
32
|
+
.tmk-card :focus-visible{outline:2px solid var(--card-accent);outline-offset:2px}
|
|
33
|
+
|
|
34
|
+
.tmk-card-brand{display:flex;align-items:center;min-height:44px}
|
|
35
|
+
.tmk-card-brand img{display:block;width:auto;height:32px}
|
|
36
|
+
.tmk-card .tmk-card-name{color:var(--card-heading);font-weight:500;letter-spacing:-.01em;overflow-wrap:break-word;hyphens:auto}
|
|
37
|
+
.tmk-card .tmk-card-role{color:var(--card-soft);font-weight:500;line-height:var(--tmk-card-role-line-height,1.3);text-wrap:balance}
|
|
38
|
+
.tmk-card-icon{flex:none;width:22px;height:22px;fill:none;stroke:currentColor;stroke-width:1.75;stroke-linecap:square;stroke-linejoin:miter}
|
|
39
|
+
|
|
40
|
+
.tmk-card-portrait{flex:none;width:112px;aspect-ratio:112/128;padding:2px;background:var(--card-accent);clip-path:var(--tmk-card-hex)}
|
|
41
|
+
.tmk-card-portrait div{height:100%;overflow:hidden;background:var(--card-fill);clip-path:var(--tmk-card-hex)}
|
|
42
|
+
.tmk-card-portrait img{display:block;width:100%;height:100%;object-fit:cover;transform:scale(var(--tmk-card-portrait-scale,1));transform-origin:var(--tmk-card-portrait-origin,50% 50%);-webkit-mask-image:var(--tmk-card-portrait-mask,none);mask-image:var(--tmk-card-portrait-mask,none)}
|
|
43
|
+
|
|
44
|
+
.tmk-card-save{display:flex;align-items:center;justify-content:center;gap:10px;min-height:56px;border-radius:var(--card-radius);background:var(--card-accent);color:var(--card-on-accent);font-size:20px;font-weight:600}
|
|
45
|
+
.tmk-card-actions{display:flex;flex-wrap:wrap;gap:8px}
|
|
46
|
+
.tmk-card .tmk-card-button{display:flex;align-items:center;justify-content:center;gap:6px;min-height:48px;padding:0 6px;border:1px solid var(--card-edge);border-radius:var(--card-radius);background:none;font-weight:500;white-space:nowrap}
|
|
47
|
+
.tmk-card-button .tmk-card-icon{width:20px;height:20px}
|
|
48
|
+
.tmk-card-install{flex:1}
|
|
49
|
+
|
|
50
|
+
.tmk-card .tmk-card-values{padding:0;list-style:none;font-size:17px;line-height:1.45}
|
|
51
|
+
.tmk-card-values li{overflow-wrap:anywhere}
|
|
52
|
+
.tmk-card-rows a{display:flex;align-items:center;min-height:48px}
|
|
53
|
+
.tmk-card-rows .tmk-card-label{color:var(--card-soft)}
|
|
54
|
+
.tmk-card-value{min-width:0;font-size:17px;font-weight:500;overflow-wrap:anywhere}
|
|
55
|
+
.tmk-card-value,.tmk-card-values{font-variant-numeric:tabular-nums}
|
|
56
|
+
|
|
57
|
+
.tmk-card-dialog{width:min(400px,100vw - 32px);max-width:none;max-height:calc(100dvh - 32px);margin:auto;padding:20px;overflow:auto;border:1px solid var(--card-accent);border-radius:var(--card-radius);background:var(--card-raised);color:var(--card-text)}
|
|
58
|
+
.tmk-card-dialog::backdrop{background:rgb(0 0 0/.7)}
|
|
59
|
+
.tmk-card .tmk-card-dialog h2{margin-bottom:16px;color:var(--card-heading);font-size:22px;font-weight:500;line-height:1.25}
|
|
60
|
+
.tmk-card .tmk-card-dialog ol{padding-left:1.25em}
|
|
61
|
+
.tmk-card-dialog li+li{margin-top:8px}
|
|
62
|
+
.tmk-card-dialog .tmk-card-button{width:100%;margin-top:20px}
|
|
63
|
+
.tmk-card-qr svg{display:block;width:min(100%,100dvh - 190px);min-width:160px;margin:0 auto}
|
|
64
|
+
.tmk-card-qr rect{fill:var(--tmk-card-qr-light,#fff)}
|
|
65
|
+
.tmk-card-qr path{fill:var(--tmk-card-qr-dark,#000)}
|
|
66
|
+
|
|
67
|
+
@media (display-mode:standalone){
|
|
68
|
+
.tmk-card .tmk-card-install{display:none}
|
|
69
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
export { ContactCardLayout } from './ContactCardLayout';
|
|
2
|
+
export { ContactPhotoType } from './ContactPhotoType';
|
|
3
|
+
export { buildContactCardManifest } from './manifest';
|
|
4
|
+
export type { ContactCardManifestOptions } from './manifest';
|
|
5
|
+
export { toDialNumber } from './phone';
|
|
6
|
+
export { buildQrSvg } from './qrSvg';
|
|
7
|
+
export type { QrSvgOptions } from './qrSvg';
|
|
8
|
+
export type { ContactCardBrand, ContactCardBrandMarkup, ContactCardLabels, ContactCardPerson, ContactCardPortrait } from './types';
|
|
9
|
+
export { DEFAULT_CARD_MOTION, resolveCardMotion } from './motion/cardMotion';
|
|
10
|
+
export type { ContactCardMotion, ContactCardMotionInput } from './motion/cardMotion';
|
|
11
|
+
export { OpenMotion } from './motion/OpenMotion';
|
|
12
|
+
export { QrMotion } from './motion/QrMotion';
|
|
13
|
+
export { SaveMotion } from './motion/SaveMotion';
|
|
14
|
+
export { TiltMotion } from './motion/TiltMotion';
|
|
15
|
+
export { buildVCard } from './vCard';
|
|
16
|
+
export type { ContactPhoto, VCardOptions } from './vCard';
|