@dloizides/marketing-astro-kit 1.12.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 +13 -0
- package/README.md +46 -0
- package/package.json +13 -6
- 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/motionController/createMotionController.ts +11 -9
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,18 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## 1.13.0
|
|
4
|
+
|
|
5
|
+
### Added
|
|
6
|
+
|
|
7
|
+
- `./contactCard`: the logic of a digital business card. `buildVCard(options)` returns a vCard 3.0 file (escaped, folded at 75 octets, CRLF, optional JPEG or PNG photo), `buildContactCardManifest(options)` a web manifest that installs one person's card as its own app, `buildQrSvg(options)` a QR code as standalone SVG, `toDialNumber(phone)` the number for a `tel:` link. A bad option throws, so it fails the build.
|
|
8
|
+
- `./ContactCard.astro`: the card itself, in four layouts (`portrait`, `name`, `framed`, `honeycomb`), with Save contact, call, email and website links, a QR dialog and Add to home screen.
|
|
9
|
+
- Dependencies `@dloizides/pwa-sw` (manifest builder) and `qrcode-generator`.
|
|
10
|
+
- `ContactCard.astro` motion: a `motion` prop with four settings (`openMotion`, `tiltMotion`, `qrMotion`, `saveMotion`), each with `none` and three options, recommended ones by default, stills under reduced motion. The settings are written to `data-open-motion`, `data-tilt-motion`, `data-qr-motion` and `data-save-motion`; `data-tilting` marks a lean.
|
|
11
|
+
- `ContactCard.astro` `brandMarkup` prop: a `@dloizides/logo-kit` mark drawn in on open.
|
|
12
|
+
- `ContactCardLabels` gains the required `hideQr` and `ready`.
|
|
13
|
+
- `--tmk-card-name-line-height` (default 1.2) and `--tmk-card-role-line-height` (default 1.3).
|
|
14
|
+
- `createMotionController` takes an optional `signal`; aborting it stops the frame loop and removes its listeners and observer. Without a signal it behaves as before.
|
|
15
|
+
|
|
3
16
|
## 1.12.0
|
|
4
17
|
|
|
5
18
|
### Added
|
package/README.md
CHANGED
|
@@ -304,3 +304,49 @@ The Astro build (Rollup) only needs the Vite alias — types are not required fo
|
|
|
304
304
|
`@dloizides/marketing-astro-kit/motionController` exports `createMotionController(options): { getState, sync }`. It runs `onFrame(deltaMs)` only while the page is visible and `target` is in view, and calls `onStill()` under `prefers-reduced-motion`. `forceStill` and `canRun` add host conditions; call `sync()` when they change. `watchReducedMotion: false` reads the preference once. The function references no module scope, so `HeroBackdrop` carries its source in an `is:inline` script.
|
|
305
305
|
|
|
306
306
|
`@dloizides/marketing-astro-kit/scrollFade` exports `createScrollFade({ belowLevel, switchShare }): { opacity, isBelow }` and `heroProgress(scrollY, heroHeight)`. `heroProgress` is 1 at the top of the page and 0 once the hero has scrolled away; `opacity(progress)` runs from 1 down to `belowLevel`; `isBelow(progress)` is true once less than `switchShare` of the hero is on screen.
|
|
307
|
+
|
|
308
|
+
## Contact card
|
|
309
|
+
|
|
310
|
+
`@dloizides/marketing-astro-kit/contactCard` builds the files behind a digital business card. Call it at build time, from a static endpoint or page frontmatter.
|
|
311
|
+
|
|
312
|
+
```ts
|
|
313
|
+
import { buildContactCardManifest, buildQrSvg, buildVCard } from '@dloizides/marketing-astro-kit/contactCard';
|
|
314
|
+
|
|
315
|
+
const vcf = buildVCard({ givenName, familyName, organisation, role, phone, email, website });
|
|
316
|
+
const manifest = buildContactCardManifest({ cardPath: '/card/sam/', name, shortName, description, themeColor, backgroundColor, icons });
|
|
317
|
+
const qr = buildQrSvg({ url: 'https://example.test/card/sam/', title: 'QR code of this card' });
|
|
318
|
+
```
|
|
319
|
+
|
|
320
|
+
- `phone` is international (`+44 20 7946 0958`); `website` and the QR `url` are https.
|
|
321
|
+
- `photo` is `{ type: ContactPhotoType.Jpeg, base64 }`, JPEG or PNG only.
|
|
322
|
+
- `cardPath` ends with `/` and is the app's id, start URL and scope, so serve the page at that exact path.
|
|
323
|
+
- Serve the files as `text/vcard` and `application/manifest+json`.
|
|
324
|
+
|
|
325
|
+
### The card (`ContactCard.astro`)
|
|
326
|
+
|
|
327
|
+
```astro
|
|
328
|
+
<ContactCard
|
|
329
|
+
layout="name"
|
|
330
|
+
person={{ givenName, familyName, role, phone, email, website }}
|
|
331
|
+
brand={{ src, width, height, href: '/', label: 'Example Works, home' }}
|
|
332
|
+
portrait={{ src, width, height, alt }}
|
|
333
|
+
labels={labels}
|
|
334
|
+
saveHref="/card/sam.vcf"
|
|
335
|
+
cardUrl="https://example.test/card/sam/"
|
|
336
|
+
motion={{ openMotion: 'mark-lands', tiltMotion: 'card-leans', qrMotion: 'list-turns', saveMotion: 'tick' }}
|
|
337
|
+
brandMarkup={{ intro, still, wordmark }}
|
|
338
|
+
/>
|
|
339
|
+
```
|
|
340
|
+
|
|
341
|
+
- `layout` is `portrait`, `name` (default), `framed` or `honeycomb`. All four show the same information.
|
|
342
|
+
- `labels` is `ContactCardLabels`: every visible text, including the iPhone steps and the browser menu hint. `hideQr` (the Show my QR button while the QR is open) and `ready` (said and shown after Save contact, e.g. "Contact ready") are required.
|
|
343
|
+
- The card fills the screen and renders the page's `h1`. Give it a page without a site header.
|
|
344
|
+
- Save contact, call, email and website work without JavaScript. The QR and install buttons are hidden without it.
|
|
345
|
+
- Add to home screen uses the browser's prompt when offered, else shows help. It is hidden inside the installed app and right after installing; a browser tab opened later cannot tell.
|
|
346
|
+
- Colours: `--tmk-card-bg`, `-raised`, `-fill`, `-text`, `-heading`, `-text-soft`, `-line`, `-edge`, `-accent`, `-on-accent`. Also `--tmk-card-font`, `--tmk-card-radius`, `--tmk-card-qr-dark` and `--tmk-card-qr-light`. Set them on `:root`.
|
|
347
|
+
- Portrait crop: `--tmk-card-portrait-scale`, `-origin` and `-mask`.
|
|
348
|
+
- Line heights: `--tmk-card-name-line-height` (default `1.2`) and `--tmk-card-role-line-height` (default `1.3`), in every layout and while motion runs. Raise them for fonts with tall ascenders or descenders.
|
|
349
|
+
- `motion` has four settings; each left out takes the recommended one shown above, and an unknown value throws at build time. `openMotion`: `none`, `mark-first`, `mark-lands`, `written-in`. `tiltMotion`: `none`, `card-leans`, `portrait-leans`, `layers-drift`. `qrMotion`: `none`, `turn-over`, `cube-turn`, `list-turns`. `saveMotion`: `none`, `tick`, `light-crosses`, `cube-closes`. Under `prefers-reduced-motion` each shows its still end state. Show my QR and Add to home screen cannot be tapped until the opening has shown them. A sideways drag tilts the card and never follows a link it started on.
|
|
350
|
+
- `brandMarkup` is a mark from `@dloizides/logo-kit` (`intro` and `still` markup, optional `wordmark` `{ html, css }`); the opening draws it in. Without it the `brand` image is used.
|
|
351
|
+
- Data attributes: the card carries `data-layout`, `data-open-motion`, `data-tilt-motion`, `data-qr-motion` and `data-save-motion`; `data-tilting` is set while it leans. `data-part` names each part the motion moves.
|
|
352
|
+
- `mountContactCards(root, signal)` wires the buttons and the motion; aborting the signal removes every listener, frame loop and timer.
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@dloizides/marketing-astro-kit",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.13.0",
|
|
4
4
|
"description": "Reusable, themeable Astro marketing sections for product sites — a Free-vs-Pro pricing comparison table, a trust / credibility section (security cards, customer-logo + testimonial placeholders, discreet built-by), a client-side \"try it\" demo shell, a meeting request form posting to a contact endpoint, and an SEO guides/content-hub card + frontmatter schema. Data-driven via a shared TypeScript schema; themed entirely through the host site's CSS custom properties.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"astro",
|
|
@@ -37,6 +37,7 @@
|
|
|
37
37
|
"files": [
|
|
38
38
|
"src",
|
|
39
39
|
"!src/**/*.test.ts",
|
|
40
|
+
"!src/**/*.test-util.ts",
|
|
40
41
|
"README.md",
|
|
41
42
|
"CHANGELOG.md"
|
|
42
43
|
],
|
|
@@ -64,15 +65,20 @@
|
|
|
64
65
|
"./dateField": "./src/dateField/index.ts",
|
|
65
66
|
"./motionController": "./src/motionController/index.ts",
|
|
66
67
|
"./scrollFade": "./src/scrollFade/index.ts",
|
|
67
|
-
"./logoIntro": "./src/logoIntro/index.ts"
|
|
68
|
+
"./logoIntro": "./src/logoIntro/index.ts",
|
|
69
|
+
"./ContactCard.astro": "./src/ContactCard.astro",
|
|
70
|
+
"./contactCard": "./src/contactCard/index.ts"
|
|
68
71
|
},
|
|
69
72
|
"scripts": {
|
|
70
73
|
"test": "vitest run",
|
|
71
|
-
"lint": "eslint src/bookingEmbed src/dateField src/meetingRequest src/motionController src/scrollFade src/logoIntro --ext .ts",
|
|
72
|
-
"typecheck": "tsc --noEmit -p ."
|
|
74
|
+
"lint": "eslint src/bookingEmbed src/dateField src/meetingRequest src/motionController src/scrollFade src/logoIntro src/contactCard --ext .ts",
|
|
75
|
+
"typecheck": "tsc --noEmit -p .",
|
|
76
|
+
"prepublishOnly": "npm run typecheck && npm run lint && npm test"
|
|
73
77
|
},
|
|
74
78
|
"dependencies": {
|
|
75
|
-
"@
|
|
79
|
+
"@dloizides/pwa-sw": "^1.11.0",
|
|
80
|
+
"@lucasmarkes/hairline": "0.3.0",
|
|
81
|
+
"qrcode-generator": "^2.0.4"
|
|
76
82
|
},
|
|
77
83
|
"devDependencies": {
|
|
78
84
|
"@typescript-eslint/eslint-plugin": "^7.18.0",
|
|
@@ -80,6 +86,7 @@
|
|
|
80
86
|
"eslint": "^8.57.1",
|
|
81
87
|
"eslint-plugin-sonarjs": "^3.0.7",
|
|
82
88
|
"jsdom": "^25.0.1",
|
|
89
|
+
"jsqr": "^1.4.0",
|
|
83
90
|
"typescript": "^5.9.3",
|
|
84
91
|
"vitest": "^2.1.9"
|
|
85
92
|
},
|
|
@@ -88,6 +95,6 @@
|
|
|
88
95
|
},
|
|
89
96
|
"sideEffects": false,
|
|
90
97
|
"engines": {
|
|
91
|
-
"node": ">=18.
|
|
98
|
+
"node": ">=18.17.0"
|
|
92
99
|
}
|
|
93
100
|
}
|
|
@@ -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
|
+
}
|