@dloizides/marketing-astro-kit 1.12.0 → 1.14.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 +47 -0
- package/package.json +13 -6
- package/src/ContactCard.astro +124 -0
- package/src/contactCard/CardActions.astro +20 -0
- package/src/contactCard/CardBack.astro +31 -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/CardForm.ts +5 -0
- package/src/contactCard/CardFront.astro +27 -0
- package/src/contactCard/CardIcon.astro +12 -0
- package/src/contactCard/CardIconName.ts +7 -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 +45 -0
- package/src/contactCard/CardShare.astro +32 -0
- package/src/contactCard/CardTurn.astro +15 -0
- package/src/contactCard/CardTwoSided.astro +48 -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 +12 -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/cssRaw.d.ts +4 -0
- package/src/contactCard/index.ts +20 -0
- package/src/contactCard/layouts.css +106 -0
- package/src/contactCard/manifest.ts +37 -0
- package/src/contactCard/motion/FlipMotion.ts +5 -0
- package/src/contactCard/motion/OpenLanding.ts +6 -0
- package/src/contactCard/motion/OpenMotion.ts +11 -0
- package/src/contactCard/motion/QrMotion.ts +7 -0
- package/src/contactCard/motion/SaveMotion.ts +7 -0
- package/src/contactCard/motion/ShareMode.ts +7 -0
- package/src/contactCard/motion/TiltMotion.ts +10 -0
- package/src/contactCard/motion/beatTable.ts +144 -0
- package/src/contactCard/motion/beats.ts +43 -0
- package/src/contactCard/motion/cardMotion.ts +70 -0
- package/src/contactCard/motion/easings.ts +9 -0
- package/src/contactCard/motion/holdDuringOpen.ts +22 -0
- package/src/contactCard/motion/mountFlip.ts +64 -0
- package/src/contactCard/motion/mountMotion.ts +33 -0
- package/src/contactCard/motion/mountOpenMark.ts +23 -0
- package/src/contactCard/motion/mountQrTurn.ts +86 -0
- package/src/contactCard/motion/mountSave.ts +26 -0
- package/src/contactCard/motion/mountShare.ts +57 -0
- package/src/contactCard/motion/mountTilt.ts +84 -0
- package/src/contactCard/motion/openCss.ts +18 -0
- package/src/contactCard/motion/orientationAccess.ts +36 -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/tiltLights.ts +14 -0
- package/src/contactCard/motion/tiltPose.ts +59 -0
- package/src/contactCard/motion/twoSidedBeats.ts +37 -0
- package/src/contactCard/motion.css +44 -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/share.css +16 -0
- package/src/contactCard/twoSided.css +43 -0
- package/src/contactCard/types.ts +52 -0
- package/src/contactCard/vCard.ts +48 -0
- package/src/contactCard/vCardLines.ts +33 -0
- package/src/motionController/createMotionController.ts +11 -9
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import { optionError, requireEmail, requireHttpsUrl, requireText } from './checks';
|
|
2
|
+
import type { ContactPhotoType } from './ContactPhotoType';
|
|
3
|
+
import { toDialNumber } from './phone';
|
|
4
|
+
import { escapeText, joinLines } from './vCardLines';
|
|
5
|
+
|
|
6
|
+
const BASE64_PATTERN = /^[A-Za-z0-9+/]+={0,2}$/;
|
|
7
|
+
const BASE64_GROUP_LENGTH = 4;
|
|
8
|
+
|
|
9
|
+
export interface ContactPhoto {
|
|
10
|
+
type: ContactPhotoType;
|
|
11
|
+
base64: string;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
export interface VCardOptions {
|
|
15
|
+
givenName: string;
|
|
16
|
+
familyName: string;
|
|
17
|
+
organisation: string;
|
|
18
|
+
role: string;
|
|
19
|
+
phone: string;
|
|
20
|
+
email: string;
|
|
21
|
+
website: string;
|
|
22
|
+
photo?: ContactPhoto;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
function photoLine(photo: ContactPhoto): string {
|
|
26
|
+
const isBase64 = BASE64_PATTERN.test(photo.base64) && photo.base64.length % BASE64_GROUP_LENGTH === 0;
|
|
27
|
+
if (!isBase64) throw optionError('photo', 'must be plain base64 with no data: prefix or line breaks');
|
|
28
|
+
return `PHOTO;ENCODING=b;TYPE=${photo.type}:${photo.base64}`;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
/** Returns the text of a vCard 3.0 `.vcf` file for one person; throws naming the first bad option. */
|
|
32
|
+
export function buildVCard(options: VCardOptions): string {
|
|
33
|
+
const givenName = escapeText(requireText(options.givenName, 'givenName'));
|
|
34
|
+
const familyName = escapeText(requireText(options.familyName, 'familyName'));
|
|
35
|
+
return joinLines([
|
|
36
|
+
'BEGIN:VCARD',
|
|
37
|
+
'VERSION:3.0',
|
|
38
|
+
`N:${familyName};${givenName};;;`,
|
|
39
|
+
`FN:${givenName} ${familyName}`,
|
|
40
|
+
`ORG:${escapeText(requireText(options.organisation, 'organisation'))}`,
|
|
41
|
+
`TITLE:${escapeText(requireText(options.role, 'role'))}`,
|
|
42
|
+
`TEL;TYPE=CELL,VOICE:${toDialNumber(options.phone)}`,
|
|
43
|
+
`EMAIL;TYPE=INTERNET:${requireEmail(options.email)}`,
|
|
44
|
+
`URL:${requireHttpsUrl(options.website, 'website')}`,
|
|
45
|
+
...(options.photo === undefined ? [] : [photoLine(options.photo)]),
|
|
46
|
+
'END:VCARD',
|
|
47
|
+
]);
|
|
48
|
+
}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
const LINE_BREAK = '\r\n';
|
|
2
|
+
const CONTINUATION = ' ';
|
|
3
|
+
const MAX_LINE_OCTETS = 75;
|
|
4
|
+
const SPECIAL_CHARACTERS = /[\\;,]/g;
|
|
5
|
+
const ANY_LINE_BREAK = /\r\n|\r|\n/g;
|
|
6
|
+
|
|
7
|
+
/** Escapes a vCard text value, so it can neither split a field nor start a new property. */
|
|
8
|
+
export function escapeText(value: string): string {
|
|
9
|
+
return value.replace(SPECIAL_CHARACTERS, '\\$&').replace(ANY_LINE_BREAK, '\\n');
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
function foldLine(line: string, encoder: TextEncoder): string {
|
|
13
|
+
const parts: string[] = [];
|
|
14
|
+
let part = '';
|
|
15
|
+
let octets = 0;
|
|
16
|
+
for (const character of line) {
|
|
17
|
+
const size = encoder.encode(character).length;
|
|
18
|
+
if (octets + size > MAX_LINE_OCTETS) {
|
|
19
|
+
parts.push(part);
|
|
20
|
+
part = CONTINUATION;
|
|
21
|
+
octets = CONTINUATION.length;
|
|
22
|
+
}
|
|
23
|
+
part += character;
|
|
24
|
+
octets += size;
|
|
25
|
+
}
|
|
26
|
+
return [...parts, part].join(LINE_BREAK);
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
/** Joins property lines with CRLF, folding each at 75 octets without splitting a character. */
|
|
30
|
+
export function joinLines(lines: readonly string[]): string {
|
|
31
|
+
const encoder = new TextEncoder();
|
|
32
|
+
return lines.map((line) => `${foldLine(line, encoder)}${LINE_BREAK}`).join('');
|
|
33
|
+
}
|
|
@@ -13,6 +13,7 @@ export interface MotionControllerOptions {
|
|
|
13
13
|
watchReducedMotion?: boolean;
|
|
14
14
|
forceStill?: () => boolean;
|
|
15
15
|
canRun?: () => boolean;
|
|
16
|
+
signal?: AbortSignal;
|
|
16
17
|
}
|
|
17
18
|
|
|
18
19
|
export interface MotionController {
|
|
@@ -27,7 +28,7 @@ export function createMotionController(options: MotionControllerOptions): Motion
|
|
|
27
28
|
const PAUSED = 'paused' as string as MotionState;
|
|
28
29
|
const FIRST_FRAME_MS = 16;
|
|
29
30
|
const MAX_FRAME_MS = 100;
|
|
30
|
-
const { target, onFrame, onStill, onState, threshold = 0, watchReducedMotion = true, forceStill, canRun } = options;
|
|
31
|
+
const { target, onFrame, onStill, onState, threshold = 0, watchReducedMotion = true, forceStill, canRun, signal } = options;
|
|
31
32
|
const reducedQuery = window.matchMedia('(prefers-reduced-motion: reduce)');
|
|
32
33
|
const reducedAtStart = reducedQuery.matches;
|
|
33
34
|
let inView = true;
|
|
@@ -53,20 +54,21 @@ export function createMotionController(options: MotionControllerOptions): Motion
|
|
|
53
54
|
const sync = (): void => {
|
|
54
55
|
const state = getState();
|
|
55
56
|
onState?.(state);
|
|
56
|
-
if (state === RUNNING && canRun?.() !== false) {
|
|
57
|
+
if (state === RUNNING && canRun?.() !== false && signal?.aborted !== true) {
|
|
57
58
|
if (!running) { running = true; frame = window.requestAnimationFrame(tick); }
|
|
58
59
|
return;
|
|
59
60
|
}
|
|
60
61
|
stop();
|
|
61
62
|
if (state === STILL) onStill?.();
|
|
62
63
|
};
|
|
63
|
-
if (watchReducedMotion) reducedQuery.addEventListener('change', sync);
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
64
|
+
if (watchReducedMotion) reducedQuery.addEventListener('change', sync, { signal });
|
|
65
|
+
const watchesPage = watchReducedMotion || !reducedAtStart;
|
|
66
|
+
if (watchesPage) document.addEventListener('visibilitychange', sync, { signal });
|
|
67
|
+
const observer = watchesPage && 'IntersectionObserver' in window
|
|
68
|
+
? new IntersectionObserver((entries) => { entries.forEach((entry) => { inView = entry.isIntersecting; }); sync(); }, { threshold })
|
|
69
|
+
: undefined;
|
|
70
|
+
observer?.observe(target);
|
|
71
|
+
signal?.addEventListener('abort', () => { observer?.disconnect(); sync(); }, { once: true });
|
|
70
72
|
sync();
|
|
71
73
|
return { getState, sync };
|
|
72
74
|
}
|