@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,144 @@
|
|
|
1
|
+
/** Beats of every timed option, `part|property|from|to|start ms|length ms|easing`, from the card motion spec. */
|
|
2
|
+
export const BEAT_TABLE: Readonly<Record<string, readonly string[]>> = {
|
|
3
|
+
'mark-first': [
|
|
4
|
+
'photo|opacity|0|1|200|240|enter',
|
|
5
|
+
'photo|transform|scale(0.9)|scale(1)|200|420|enter',
|
|
6
|
+
'wordmark|opacity|0|1|260|240|enter',
|
|
7
|
+
'name1|opacity|0|1|280|240|enter',
|
|
8
|
+
'name1|transform|translateY(8px)|translateY(0px)|280|320|enter',
|
|
9
|
+
'name2|opacity|0|1|340|240|enter',
|
|
10
|
+
'name2|transform|translateY(8px)|translateY(0px)|340|320|enter',
|
|
11
|
+
'role|opacity|0|1|400|240|enter',
|
|
12
|
+
'role|transform|translateY(8px)|translateY(0px)|400|320|enter',
|
|
13
|
+
'rule1|opacity|0|1|480|240|enter',
|
|
14
|
+
'row1|opacity|0|1|500|240|enter',
|
|
15
|
+
'row1|transform|translateY(8px)|translateY(0px)|500|320|enter',
|
|
16
|
+
'rule2|opacity|0|1|540|240|enter',
|
|
17
|
+
'row2|opacity|0|1|560|240|enter',
|
|
18
|
+
'row2|transform|translateY(8px)|translateY(0px)|560|320|enter',
|
|
19
|
+
'rule3|opacity|0|1|600|240|enter',
|
|
20
|
+
'row3|opacity|0|1|620|240|enter',
|
|
21
|
+
'row3|transform|translateY(8px)|translateY(0px)|620|320|enter',
|
|
22
|
+
'rule4|opacity|0|1|660|240|enter',
|
|
23
|
+
'home|opacity|0|1|700|240|enter',
|
|
24
|
+
'qrBtn|opacity|0|1|740|240|enter',
|
|
25
|
+
],
|
|
26
|
+
'mark-lands': [
|
|
27
|
+
'rule1|transform|scaleX(0)|scaleX(1)|260|400|enter',
|
|
28
|
+
'row1|opacity|0|1|300|240|enter',
|
|
29
|
+
'row1|transform|translateY(8px)|translateY(0px)|300|320|enter',
|
|
30
|
+
'rule2|transform|scaleX(0)|scaleX(1)|320|400|enter',
|
|
31
|
+
'row2|opacity|0|1|360|240|enter',
|
|
32
|
+
'row2|transform|translateY(8px)|translateY(0px)|360|320|enter',
|
|
33
|
+
'rule3|transform|scaleX(0)|scaleX(1)|380|400|enter',
|
|
34
|
+
'row3|opacity|0|1|420|240|enter',
|
|
35
|
+
'row3|transform|translateY(8px)|translateY(0px)|420|320|enter',
|
|
36
|
+
'rule4|transform|scaleX(0)|scaleX(1)|440|400|enter',
|
|
37
|
+
'home|opacity|0|1|560|240|enter',
|
|
38
|
+
'qrBtn|opacity|0|1|600|240|enter',
|
|
39
|
+
'mark|transform|translate(var(--tmk-card-mark-x,148px),var(--tmk-card-mark-y,92px)) scale(5.5)|translate(0px,0px) scale(1)|620|420|glide',
|
|
40
|
+
'name1|opacity|0|1|900|240|enter',
|
|
41
|
+
'name1|transform|translateY(8px)|translateY(0px)|900|320|enter',
|
|
42
|
+
'photo|opacity|0|1|940|240|enter',
|
|
43
|
+
'photo|transform|scale(0.9)|scale(1)|940|400|enter',
|
|
44
|
+
'wordmark|opacity|0|1|960|240|enter',
|
|
45
|
+
'name2|opacity|0|1|960|240|enter',
|
|
46
|
+
'name2|transform|translateY(8px)|translateY(0px)|960|320|enter',
|
|
47
|
+
'role|opacity|0|1|1020|240|enter',
|
|
48
|
+
'role|transform|translateY(8px)|translateY(0px)|1020|320|enter',
|
|
49
|
+
],
|
|
50
|
+
'written-in': [
|
|
51
|
+
'name1|transform|translateY(105%)|translateY(0%)|60|520|enter',
|
|
52
|
+
'name2|transform|translateY(105%)|translateY(0%)|160|520|enter',
|
|
53
|
+
'wordmark|opacity|0|1|200|240|enter',
|
|
54
|
+
'photo|opacity|0|1|420|300|enter',
|
|
55
|
+
'role|opacity|0|1|420|300|enter',
|
|
56
|
+
'rule1|transform|scaleX(0)|scaleX(1)|480|520|enter',
|
|
57
|
+
'rule2|transform|scaleX(0)|scaleX(1)|590|520|enter',
|
|
58
|
+
'row1|opacity|0|1|600|260|enter',
|
|
59
|
+
'row1|transform|translateX(-12px)|translateX(0px)|600|360|enter',
|
|
60
|
+
'rule3|transform|scaleX(0)|scaleX(1)|700|520|enter',
|
|
61
|
+
'row2|opacity|0|1|710|260|enter',
|
|
62
|
+
'row2|transform|translateX(-12px)|translateX(0px)|710|360|enter',
|
|
63
|
+
'rule4|transform|scaleX(0)|scaleX(1)|810|520|enter',
|
|
64
|
+
'row3|opacity|0|1|820|260|enter',
|
|
65
|
+
'row3|transform|translateX(-12px)|translateX(0px)|820|360|enter',
|
|
66
|
+
'home|opacity|0|1|980|240|enter',
|
|
67
|
+
'qrBtn|opacity|0|1|1020|240|enter',
|
|
68
|
+
],
|
|
69
|
+
'turn-over': [
|
|
70
|
+
'card|transform|perspective(1100px) rotateY(0deg)|perspective(1100px) rotateY(90deg)|0|260|turnOut',
|
|
71
|
+
'card|opacity|1|0|260|0|swap',
|
|
72
|
+
'back|opacity|0|1|260|0|swap',
|
|
73
|
+
'back|transform|perspective(1100px) rotateY(-90deg)|perspective(1100px) rotateY(0deg)|260|260|turnIn',
|
|
74
|
+
'back|transform|perspective(1100px) rotateY(0deg)|perspective(1100px) rotateY(-90deg)|2200|260|turnOut',
|
|
75
|
+
'back|opacity|1|0|2460|0|swap',
|
|
76
|
+
'card|opacity|0|1|2460|0|swap',
|
|
77
|
+
'card|transform|perspective(1100px) rotateY(90deg)|perspective(1100px) rotateY(0deg)|2460|260|turnIn',
|
|
78
|
+
],
|
|
79
|
+
'cube-turn': [
|
|
80
|
+
'back|opacity|0|1|0|0|swap',
|
|
81
|
+
'card|transform|perspective(1100px) translateZ(-180px) rotateY(0deg) translateZ(180px)|perspective(1100px) translateZ(-180px) rotateY(-90deg) translateZ(180px)|0|560|glide',
|
|
82
|
+
'back|transform|perspective(1100px) translateZ(-180px) rotateY(90deg) translateZ(180px)|perspective(1100px) translateZ(-180px) rotateY(0deg) translateZ(180px)|0|560|glide',
|
|
83
|
+
'card|transform|perspective(1100px) translateZ(-180px) rotateY(-90deg) translateZ(180px)|perspective(1100px) translateZ(-180px) rotateY(0deg) translateZ(180px)|2200|560|glide',
|
|
84
|
+
'back|transform|perspective(1100px) translateZ(-180px) rotateY(0deg) translateZ(180px)|perspective(1100px) translateZ(-180px) rotateY(90deg) translateZ(180px)|2200|560|glide',
|
|
85
|
+
'back|opacity|1|0|2760|0|swap',
|
|
86
|
+
],
|
|
87
|
+
'list-turns': [
|
|
88
|
+
'qrBtn|transform|scale(1)|scale(0.97)|0|100|settle',
|
|
89
|
+
'listPanel|transform|perspective(900px) rotateX(0deg)|perspective(900px) rotateX(90deg)|60|220|turnOut',
|
|
90
|
+
'qrOpen|opacity|1|0|60|160|settle',
|
|
91
|
+
'qrClose|opacity|0|1|60|160|settle',
|
|
92
|
+
'qrBtn|transform|scale(0.97)|scale(1)|100|160|settle',
|
|
93
|
+
'listPanel|opacity|1|0|280|0|swap',
|
|
94
|
+
'qrPanel|opacity|0|1|280|0|swap',
|
|
95
|
+
'qrPanel|transform|perspective(900px) rotateX(-90deg)|perspective(900px) rotateX(0deg)|280|220|turnIn',
|
|
96
|
+
'qrBtn|transform|scale(1)|scale(0.97)|2200|100|settle',
|
|
97
|
+
'qrPanel|transform|perspective(900px) rotateX(0deg)|perspective(900px) rotateX(-90deg)|2260|220|turnOut',
|
|
98
|
+
'qrClose|opacity|1|0|2260|160|settle',
|
|
99
|
+
'qrOpen|opacity|0|1|2260|160|settle',
|
|
100
|
+
'qrBtn|transform|scale(0.97)|scale(1)|2300|160|settle',
|
|
101
|
+
'qrPanel|opacity|1|0|2480|0|swap',
|
|
102
|
+
'listPanel|opacity|0|1|2480|0|swap',
|
|
103
|
+
'listPanel|transform|perspective(900px) rotateX(90deg)|perspective(900px) rotateX(0deg)|2480|220|turnIn',
|
|
104
|
+
],
|
|
105
|
+
'tick': [
|
|
106
|
+
'save|transform|scale(1)|scale(0.97)|0|100|settle',
|
|
107
|
+
'saveText|opacity|1|0|60|120|settle',
|
|
108
|
+
'saveIcon|opacity|1|0|60|120|settle',
|
|
109
|
+
'save|transform|scale(0.97)|scale(1)|100|160|settle',
|
|
110
|
+
'readyText|opacity|0|1|160|200|settle',
|
|
111
|
+
'tick|opacity|0|1|180|0|swap',
|
|
112
|
+
'tickCover|transform|translateX(0px)|translateX(26px)|180|300|settle',
|
|
113
|
+
'readyText|opacity|1|0|2200|160|settle',
|
|
114
|
+
'tick|opacity|1|0|2200|160|settle',
|
|
115
|
+
'saveText|opacity|0|1|2240|200|settle',
|
|
116
|
+
'saveIcon|opacity|0|1|2240|200|settle',
|
|
117
|
+
],
|
|
118
|
+
'light-crosses': [
|
|
119
|
+
'save|transform|scale(1)|scale(0.97)|0|100|settle',
|
|
120
|
+
'wipe|transform|translateX(-100%)|translateX(0%)|80|420|settle',
|
|
121
|
+
'wipeIn|transform|translateX(100%)|translateX(0%)|80|420|settle',
|
|
122
|
+
'save|transform|scale(0.97)|scale(1)|100|160|settle',
|
|
123
|
+
'wipe|opacity|1|0|2200|240|settle',
|
|
124
|
+
],
|
|
125
|
+
'cube-closes': [
|
|
126
|
+
'save|transform|scale(1)|scale(0.97)|0|100|settle',
|
|
127
|
+
'saveText|opacity|1|0|60|120|settle',
|
|
128
|
+
'saveIcon|opacity|1|0|60|120|settle',
|
|
129
|
+
'save|transform|scale(0.97)|scale(1)|100|160|settle',
|
|
130
|
+
'readyText|opacity|0|1|160|200|settle',
|
|
131
|
+
'cubeTop|opacity|0|1|160|160|enter',
|
|
132
|
+
'cubeTop|transform|translate(0px,-9px)|translate(0px,0px)|160|340|enter',
|
|
133
|
+
'cubeLeft|opacity|0|1|220|160|enter',
|
|
134
|
+
'cubeLeft|transform|translate(-9px,6px)|translate(0px,0px)|220|340|enter',
|
|
135
|
+
'cubeRight|opacity|0|1|280|160|enter',
|
|
136
|
+
'cubeRight|transform|translate(9px,6px)|translate(0px,0px)|280|340|enter',
|
|
137
|
+
'readyText|opacity|1|0|2200|160|settle',
|
|
138
|
+
'cubeTop|opacity|1|0|2200|160|settle',
|
|
139
|
+
'cubeLeft|opacity|1|0|2200|160|settle',
|
|
140
|
+
'cubeRight|opacity|1|0|2200|160|settle',
|
|
141
|
+
'saveText|opacity|0|1|2240|200|settle',
|
|
142
|
+
'saveIcon|opacity|0|1|2240|200|settle',
|
|
143
|
+
],
|
|
144
|
+
};
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import { BEAT_TABLE } from './beatTable';
|
|
2
|
+
import { EASINGS } from './easings';
|
|
3
|
+
|
|
4
|
+
export interface Beat {
|
|
5
|
+
part: string;
|
|
6
|
+
property: string;
|
|
7
|
+
from: string;
|
|
8
|
+
to: string;
|
|
9
|
+
atMs: number;
|
|
10
|
+
lengthMs: number;
|
|
11
|
+
easing: string;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
export interface SplitBeats {
|
|
15
|
+
out: Beat[];
|
|
16
|
+
back: Beat[];
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
/** When a tap's change returns: the QR turns back and Save contact reads its label again. */
|
|
20
|
+
export const RETURN_AT_MS = 2200;
|
|
21
|
+
|
|
22
|
+
function parseBeat(line: string): Beat {
|
|
23
|
+
const [part = '', property = '', from = '', to = '', atMs = '0', lengthMs = '0', easing = ''] = line.split('|');
|
|
24
|
+
return { part, property, from, to, atMs: Number(atMs), lengthMs: Number(lengthMs), easing: EASINGS[easing] ?? easing };
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
/** The beats of one option (or of the given lines), or none for `none` and unknown keys. */
|
|
28
|
+
export function beatsFor(key: string, lines: readonly string[] = BEAT_TABLE[key] ?? []): Beat[] {
|
|
29
|
+
return lines.map(parseBeat);
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
/** The reduced-motion still: every change at once, the return at its time. */
|
|
33
|
+
export function stillBeats(beats: readonly Beat[]): Beat[] {
|
|
34
|
+
return beats.map((beat) => ({ ...beat, atMs: beat.atMs < RETURN_AT_MS ? 0 : RETURN_AT_MS, lengthMs: 0, easing: 'linear' }));
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
/** Splits a tap's beats into the way out and the way back, the way back starting at 0. */
|
|
38
|
+
export function splitBeats(beats: readonly Beat[], atMs = RETURN_AT_MS): SplitBeats {
|
|
39
|
+
return {
|
|
40
|
+
out: beats.filter((beat) => beat.atMs < atMs),
|
|
41
|
+
back: beats.filter((beat) => beat.atMs >= atMs).map((beat) => ({ ...beat, atMs: beat.atMs - atMs })),
|
|
42
|
+
};
|
|
43
|
+
}
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
import { FlipMotion } from './FlipMotion';
|
|
2
|
+
import { OpenLanding } from './OpenLanding';
|
|
3
|
+
import { OpenMotion } from './OpenMotion';
|
|
4
|
+
import { QrMotion } from './QrMotion';
|
|
5
|
+
import { SaveMotion } from './SaveMotion';
|
|
6
|
+
import { ShareMode } from './ShareMode';
|
|
7
|
+
import { TiltMotion } from './TiltMotion';
|
|
8
|
+
|
|
9
|
+
export interface ContactCardMotion {
|
|
10
|
+
openMotion: OpenMotion;
|
|
11
|
+
tiltMotion: TiltMotion;
|
|
12
|
+
qrMotion: QrMotion;
|
|
13
|
+
saveMotion: SaveMotion;
|
|
14
|
+
shareMode: ShareMode;
|
|
15
|
+
openLands: OpenLanding;
|
|
16
|
+
flipMotion: FlipMotion;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
export type ContactCardMotionInput = Partial<Record<keyof ContactCardMotion, string>>;
|
|
20
|
+
|
|
21
|
+
const CHOICES: Readonly<Record<keyof ContactCardMotion, readonly string[]>> = {
|
|
22
|
+
openMotion: [
|
|
23
|
+
OpenMotion.None, OpenMotion.MarkFirst, OpenMotion.MarkLands, OpenMotion.WrittenIn,
|
|
24
|
+
OpenMotion.TileGrows, OpenMotion.MoonOpens, OpenMotion.TurnsFaceUp, OpenMotion.PassRises,
|
|
25
|
+
],
|
|
26
|
+
tiltMotion: [
|
|
27
|
+
TiltMotion.None, TiltMotion.CardLeans, TiltMotion.PortraitLeans, TiltMotion.LayersDrift,
|
|
28
|
+
TiltMotion.LightSweeps, TiltMotion.GoldGloss, TiltMotion.DeepLayers,
|
|
29
|
+
],
|
|
30
|
+
qrMotion: [QrMotion.None, QrMotion.TurnOver, QrMotion.CubeTurn, QrMotion.ListTurns],
|
|
31
|
+
saveMotion: [SaveMotion.None, SaveMotion.Tick, SaveMotion.LightCrosses, SaveMotion.CubeCloses],
|
|
32
|
+
shareMode: [ShareMode.None, ShareMode.WhiteSheet, ShareMode.NightFrame, ShareMode.FaceAbove],
|
|
33
|
+
openLands: [OpenLanding.TurnToFront, OpenLanding.Front, OpenLanding.Back],
|
|
34
|
+
flipMotion: [FlipMotion.None, FlipMotion.TurnOver],
|
|
35
|
+
};
|
|
36
|
+
|
|
37
|
+
/** The recommended motion, used for every setting the host leaves out. */
|
|
38
|
+
export const DEFAULT_CARD_MOTION: Readonly<ContactCardMotion> = {
|
|
39
|
+
openMotion: OpenMotion.TileGrows,
|
|
40
|
+
tiltMotion: TiltMotion.LightSweeps,
|
|
41
|
+
qrMotion: QrMotion.ListTurns,
|
|
42
|
+
saveMotion: SaveMotion.Tick,
|
|
43
|
+
shareMode: ShareMode.FaceAbove,
|
|
44
|
+
openLands: OpenLanding.TurnToFront,
|
|
45
|
+
flipMotion: FlipMotion.TurnOver,
|
|
46
|
+
};
|
|
47
|
+
|
|
48
|
+
/** Fills the left-out settings with the defaults; throws on a value no option has. */
|
|
49
|
+
export function resolveCardMotion(input: ContactCardMotionInput = {}): ContactCardMotion {
|
|
50
|
+
const keys = Object.keys(CHOICES) as (keyof ContactCardMotion)[];
|
|
51
|
+
const entries = keys.map((key) => {
|
|
52
|
+
const value = input[key] ?? DEFAULT_CARD_MOTION[key];
|
|
53
|
+
if (!CHOICES[key].includes(value)) throw new Error(`Unknown ${key} "${value}"; use one of ${CHOICES[key].join(', ')}`);
|
|
54
|
+
return [key, value];
|
|
55
|
+
});
|
|
56
|
+
return Object.fromEntries(entries) as ContactCardMotion;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
/** The card's data attributes, one per setting, read by the motion script. */
|
|
60
|
+
export function motionAttributes(motion: ContactCardMotion): Record<string, string> {
|
|
61
|
+
return {
|
|
62
|
+
'data-open-motion': motion.openMotion,
|
|
63
|
+
'data-tilt-motion': motion.tiltMotion,
|
|
64
|
+
'data-qr-motion': motion.qrMotion,
|
|
65
|
+
'data-save-motion': motion.saveMotion,
|
|
66
|
+
'data-share-mode': motion.shareMode,
|
|
67
|
+
'data-open-lands': motion.openLands,
|
|
68
|
+
'data-flip-motion': motion.flipMotion,
|
|
69
|
+
};
|
|
70
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/** The card's named easings, from the motion spec. */
|
|
2
|
+
export const EASINGS: Readonly<Record<string, string>> = {
|
|
3
|
+
enter: 'cubic-bezier(0,0,0,1)',
|
|
4
|
+
settle: 'cubic-bezier(0.2,0,0,1)',
|
|
5
|
+
glide: 'cubic-bezier(0.4,0,0.2,1)',
|
|
6
|
+
turnOut: 'cubic-bezier(0.4,0,1,1)',
|
|
7
|
+
turnIn: 'cubic-bezier(0,0,0.2,1)',
|
|
8
|
+
swap: 'step-end',
|
|
9
|
+
};
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { partSelector } from './parts';
|
|
2
|
+
import { openingBeats } from './twoSidedBeats';
|
|
3
|
+
|
|
4
|
+
const HELD_PARTS = ['home', 'qrBtn', 'turn'];
|
|
5
|
+
const INERT = 'inert';
|
|
6
|
+
|
|
7
|
+
/** Keeps Add to home screen, Show my QR and the turn button untappable while the opening still hides them. */
|
|
8
|
+
export function holdDuringOpen(card: HTMLElement, openMotion: string, reduced: boolean, signal?: AbortSignal): void {
|
|
9
|
+
if (reduced) return;
|
|
10
|
+
const shownAtMs = openingBeats(openMotion)
|
|
11
|
+
.filter((beat) => HELD_PARTS.includes(beat.part))
|
|
12
|
+
.reduce((latest, beat) => Math.max(latest, beat.atMs + beat.lengthMs), 0);
|
|
13
|
+
if (shownAtMs === 0) return;
|
|
14
|
+
const buttons = HELD_PARTS.flatMap((part) => Array.from(card.querySelectorAll<HTMLElement>(partSelector(part))));
|
|
15
|
+
const release = (): void => buttons.forEach((button) => button.removeAttribute(INERT));
|
|
16
|
+
buttons.forEach((button) => button.setAttribute(INERT, ''));
|
|
17
|
+
const timer = setTimeout(release, shownAtMs);
|
|
18
|
+
signal?.addEventListener('abort', () => {
|
|
19
|
+
clearTimeout(timer);
|
|
20
|
+
release();
|
|
21
|
+
}, { once: true });
|
|
22
|
+
}
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
import { EASINGS } from './easings';
|
|
2
|
+
import { FlipMotion } from './FlipMotion';
|
|
3
|
+
|
|
4
|
+
const TURN_MS = 560;
|
|
5
|
+
const BACK_DEG = 180;
|
|
6
|
+
const HALF = 2;
|
|
7
|
+
const BACK = 'back';
|
|
8
|
+
const CONTROLS = 'a,button,input,select,textarea';
|
|
9
|
+
|
|
10
|
+
interface Faces {
|
|
11
|
+
flip: HTMLElement;
|
|
12
|
+
front: HTMLElement;
|
|
13
|
+
back: HTMLElement;
|
|
14
|
+
button: HTMLElement;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
function findFaces(card: HTMLElement): Faces | null {
|
|
18
|
+
const flip = card.querySelector<HTMLElement>('[data-part="flip"]');
|
|
19
|
+
const front = card.querySelector<HTMLElement>('[data-part="front"]');
|
|
20
|
+
const back = card.querySelector<HTMLElement>('[data-part="back"]');
|
|
21
|
+
const button = card.querySelector<HTMLElement>('[data-card-turn]');
|
|
22
|
+
return flip === null || front === null || back === null || button === null ? null : { flip, front, back, button };
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
function show(card: HTMLElement, faces: Faces, onBack: boolean): void {
|
|
26
|
+
faces.flip.dataset['face'] = onBack ? BACK : 'front';
|
|
27
|
+
faces.flip.style.transform = `rotateY(${onBack ? BACK_DEG : 0}deg)`;
|
|
28
|
+
faces.front.toggleAttribute('inert', onBack);
|
|
29
|
+
faces.back.toggleAttribute('inert', !onBack);
|
|
30
|
+
faces.button.setAttribute('aria-label', (onBack ? faces.button.dataset['labelFront'] : faces.button.dataset['labelBack']) ?? '');
|
|
31
|
+
const live = card.querySelector('[data-part="turn-live"]');
|
|
32
|
+
if (live !== null) live.textContent = (onBack ? faces.back : faces.front).getAttribute('aria-label') ?? '';
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
function turnKeyframes(onBack: boolean): Keyframe[] {
|
|
36
|
+
const [from, to] = onBack ? [0, BACK_DEG] : [BACK_DEG, 0];
|
|
37
|
+
return [
|
|
38
|
+
{ transform: `rotateY(${from}deg)`, easing: EASINGS['turnOut'] },
|
|
39
|
+
{ transform: `rotateY(${(from + to) / HALF}deg)`, easing: EASINGS['turnIn'] },
|
|
40
|
+
{ transform: `rotateY(${to}deg)` },
|
|
41
|
+
];
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
/** Turns the two-sided card on a tap outside its links, its turn button, Enter or Space; a tap mid-turn reverses it. */
|
|
45
|
+
export function mountFlip(card: HTMLElement, flipMotion: FlipMotion, reduced: boolean, signal?: AbortSignal): void {
|
|
46
|
+
const faces = findFaces(card);
|
|
47
|
+
if (faces === null) return;
|
|
48
|
+
let running: Animation | null = null;
|
|
49
|
+
const turn = (): void => {
|
|
50
|
+
const onBack = faces.flip.dataset['face'] !== BACK;
|
|
51
|
+
show(card, faces, onBack);
|
|
52
|
+
if (reduced || flipMotion === FlipMotion.None || typeof faces.flip.animate !== 'function') return;
|
|
53
|
+
if (running?.playState === 'running') {
|
|
54
|
+
running.reverse();
|
|
55
|
+
return;
|
|
56
|
+
}
|
|
57
|
+
running = faces.flip.animate(turnKeyframes(onBack), { duration: TURN_MS });
|
|
58
|
+
};
|
|
59
|
+
faces.button.addEventListener('click', turn, { signal });
|
|
60
|
+
card.querySelector('[data-part="stage"]')?.addEventListener('click', (event) => {
|
|
61
|
+
if (event.target instanceof Element && event.target.closest(CONTROLS) !== null) return;
|
|
62
|
+
turn();
|
|
63
|
+
}, { signal });
|
|
64
|
+
}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { holdDuringOpen } from './holdDuringOpen';
|
|
2
|
+
import { mountOpenMark } from './mountOpenMark';
|
|
3
|
+
import { mountQrTurn } from './mountQrTurn';
|
|
4
|
+
import { mountSave } from './mountSave';
|
|
5
|
+
import { mountTilt } from './mountTilt';
|
|
6
|
+
import { resolveCardMotion } from './cardMotion';
|
|
7
|
+
import { mountFlip } from './mountFlip';
|
|
8
|
+
import { mountShare } from './mountShare';
|
|
9
|
+
|
|
10
|
+
const REDUCED_QUERY = '(prefers-reduced-motion: reduce)';
|
|
11
|
+
|
|
12
|
+
/** Wires the motion, turn and share settings the card carries in its data attributes. */
|
|
13
|
+
export function mountCardMotion(card: HTMLElement, signal?: AbortSignal): void {
|
|
14
|
+
const reduced = window.matchMedia(REDUCED_QUERY).matches;
|
|
15
|
+
const settings = card.dataset;
|
|
16
|
+
const none = 'none';
|
|
17
|
+
const motion = resolveCardMotion({
|
|
18
|
+
openMotion: settings['openMotion'] ?? none,
|
|
19
|
+
tiltMotion: settings['tiltMotion'] ?? none,
|
|
20
|
+
qrMotion: settings['qrMotion'] ?? none,
|
|
21
|
+
saveMotion: settings['saveMotion'] ?? none,
|
|
22
|
+
shareMode: settings['shareMode'] ?? none,
|
|
23
|
+
openLands: settings['openLands'],
|
|
24
|
+
flipMotion: settings['flipMotion'] ?? none,
|
|
25
|
+
});
|
|
26
|
+
mountOpenMark(card, motion.openMotion, reduced);
|
|
27
|
+
holdDuringOpen(card, motion.openMotion, reduced, signal);
|
|
28
|
+
mountQrTurn(card, motion.qrMotion, reduced, signal);
|
|
29
|
+
mountSave(card, motion.saveMotion, reduced, signal);
|
|
30
|
+
mountTilt(card, motion.tiltMotion, signal);
|
|
31
|
+
mountShare(card, motion.shareMode, signal);
|
|
32
|
+
mountFlip(card, motion.flipMotion, reduced, signal);
|
|
33
|
+
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { OpenMotion } from './OpenMotion';
|
|
2
|
+
|
|
3
|
+
const LOGO_RATE: Readonly<Record<string, number>> = {
|
|
4
|
+
[OpenMotion.MarkFirst]: 1.8, [OpenMotion.MarkLands]: 2, [OpenMotion.WrittenIn]: 1.8, [OpenMotion.TileGrows]: 1.8,
|
|
5
|
+
[OpenMotion.MoonOpens]: 1.8, [OpenMotion.TurnsFaceUp]: 1.4, [OpenMotion.PassRises]: 1.8,
|
|
6
|
+
};
|
|
7
|
+
const FADE_MS = 300;
|
|
8
|
+
|
|
9
|
+
/** Speeds the logo-kit mark intro to the option's rate, or shows its still under reduced motion or without `d:path`. */
|
|
10
|
+
export function mountOpenMark(card: HTMLElement, openMotion: OpenMotion, reduced: boolean): void {
|
|
11
|
+
const mark = card.querySelector<HTMLElement>('[data-part="mark"][data-logo-intro]');
|
|
12
|
+
const still = card.querySelector<HTMLTemplateElement>('template[data-mark-still]');
|
|
13
|
+
if (mark === null || still === null) return;
|
|
14
|
+
const drawable = typeof CSS !== 'undefined' && CSS.supports('d', "path('M0 0')");
|
|
15
|
+
const moves = !reduced && openMotion !== OpenMotion.None;
|
|
16
|
+
if (moves && drawable) {
|
|
17
|
+
const rate = LOGO_RATE[openMotion] ?? 1;
|
|
18
|
+
mark.getAnimations({ subtree: true }).forEach((animation) => { animation.playbackRate = rate; });
|
|
19
|
+
return;
|
|
20
|
+
}
|
|
21
|
+
mark.replaceChildren(still.content.cloneNode(true));
|
|
22
|
+
if (moves) mark.animate?.([{ opacity: 0 }, { opacity: 1 }], { duration: FADE_MS, fill: 'backwards' });
|
|
23
|
+
}
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
import { beatsFor, splitBeats, stillBeats, type Beat } from './beats';
|
|
2
|
+
import { cancelAll, playBeats } from './playBeats';
|
|
3
|
+
import { partSelector } from './parts';
|
|
4
|
+
import { QrMotion } from './QrMotion';
|
|
5
|
+
import { cover, setSide, shareOrigin, sidesAround } from './sides';
|
|
6
|
+
|
|
7
|
+
const GAP_PX = 12;
|
|
8
|
+
|
|
9
|
+
interface Turn {
|
|
10
|
+
card: HTMLElement;
|
|
11
|
+
button: HTMLElement;
|
|
12
|
+
qrSide: HTMLElement;
|
|
13
|
+
fronts: HTMLElement[];
|
|
14
|
+
close: HTMLElement | null;
|
|
15
|
+
turnsCard: boolean;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
function findTurn(card: HTMLElement, qrMotion: QrMotion): Turn | null {
|
|
19
|
+
const button = card.querySelector<HTMLElement>('[data-card-qr]');
|
|
20
|
+
const save = card.querySelector<HTMLElement>('[data-part="save"]');
|
|
21
|
+
const turnsCard = qrMotion === QrMotion.TurnOver || qrMotion === QrMotion.CubeTurn;
|
|
22
|
+
const qrSide = card.querySelector<HTMLElement>(turnsCard ? '[data-part="qr-back"]' : '[data-part="qr-panel"]');
|
|
23
|
+
const list = card.querySelector<HTMLElement>('[data-part="contacts"]');
|
|
24
|
+
if (button === null || qrSide === null || save === null || list === null) return null;
|
|
25
|
+
const fronts = turnsCard ? sidesAround(card, save) : [list];
|
|
26
|
+
return { card, button, qrSide, fronts, close: card.querySelector<HTMLElement>('[data-card-qr-close]'), turnsCard };
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
function place(turn: Turn): void {
|
|
30
|
+
const save = turn.card.querySelector<HTMLElement>('[data-part="save"]')?.getBoundingClientRect();
|
|
31
|
+
if (!turn.turnsCard) {
|
|
32
|
+
const list = turn.fronts[0]?.getBoundingClientRect();
|
|
33
|
+
const comb = turn.card.querySelector('[data-part="comb"]')?.getBoundingClientRect();
|
|
34
|
+
const box = list !== undefined && list.height < 1 && comb !== undefined ? comb : list;
|
|
35
|
+
if (box !== undefined) cover(turn.card, turn.qrSide, box);
|
|
36
|
+
return;
|
|
37
|
+
}
|
|
38
|
+
shareOrigin(turn.card, turn.fronts);
|
|
39
|
+
const frame = turn.card.getBoundingClientRect();
|
|
40
|
+
if (save === undefined) return;
|
|
41
|
+
const top = save.bottom + GAP_PX;
|
|
42
|
+
cover(turn.card, turn.qrSide, new DOMRect(save.left, top, save.width, Math.max(frame.bottom - top - GAP_PX, 0)));
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
function finder(turn: Turn): (part: string) => Element[] {
|
|
46
|
+
return (part) => (part === 'card' ? turn.fronts : Array.from(turn.card.querySelectorAll(partSelector(part))));
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
function labelState(turn: Turn, open: boolean): void {
|
|
50
|
+
turn.button.setAttribute('aria-expanded', String(open));
|
|
51
|
+
turn.card.querySelector('[data-part="qr-open"]')?.toggleAttribute('aria-hidden', open);
|
|
52
|
+
turn.card.querySelector('[data-part="qr-close"]')?.toggleAttribute('aria-hidden', !open);
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
/** Wires Show my QR to turn the card or its list to the QR, reversing from where it is on a tap mid-turn. */
|
|
56
|
+
export function mountQrTurn(card: HTMLElement, qrMotion: QrMotion, reduced: boolean, signal?: AbortSignal): void {
|
|
57
|
+
const turn = findTurn(card, qrMotion);
|
|
58
|
+
if (turn === null) return;
|
|
59
|
+
const still = reduced || qrMotion === QrMotion.None;
|
|
60
|
+
const source = beatsFor(qrMotion === QrMotion.None ? QrMotion.ListTurns : qrMotion);
|
|
61
|
+
const { out, back } = splitBeats(still ? stillBeats(source) : source);
|
|
62
|
+
let open = false;
|
|
63
|
+
let playing: Animation[] = [];
|
|
64
|
+
const settle = (): void => {
|
|
65
|
+
setSide(turn.qrSide, !open);
|
|
66
|
+
turn.fronts.forEach((front) => setSide(front, open));
|
|
67
|
+
(open && turn.close !== null ? turn.close : turn.button).focus();
|
|
68
|
+
};
|
|
69
|
+
const toggle = (): void => {
|
|
70
|
+
open = !open;
|
|
71
|
+
labelState(turn, open);
|
|
72
|
+
if (playing.some((animation) => animation.playState === 'running')) {
|
|
73
|
+
playing.forEach((animation) => animation.reverse());
|
|
74
|
+
return;
|
|
75
|
+
}
|
|
76
|
+
cancelAll(playing);
|
|
77
|
+
place(turn);
|
|
78
|
+
[turn.qrSide, ...turn.fronts].forEach((side) => setSide(side, false));
|
|
79
|
+
const beats: Beat[] = open ? out : back;
|
|
80
|
+
playing = playBeats(beats, finder(turn));
|
|
81
|
+
Promise.all(playing.map((animation) => animation.finished)).then(settle, () => undefined);
|
|
82
|
+
};
|
|
83
|
+
turn.button.addEventListener('click', toggle, { signal });
|
|
84
|
+
turn.close?.addEventListener('click', () => { if (open) toggle(); }, { signal });
|
|
85
|
+
card.addEventListener('keydown', (event) => { if (event.key === 'Escape' && open) toggle(); }, { signal });
|
|
86
|
+
}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { RETURN_AT_MS, beatsFor, stillBeats } from './beats';
|
|
2
|
+
import { cancelAll, playBeats } from './playBeats';
|
|
3
|
+
import { partSelector } from './parts';
|
|
4
|
+
import { SaveMotion } from './SaveMotion';
|
|
5
|
+
|
|
6
|
+
/** Plays the Save contact confirmation on each tap and announces the ready words; never holds back the link. */
|
|
7
|
+
export function mountSave(card: HTMLElement, saveMotion: SaveMotion, reduced: boolean, signal?: AbortSignal): void {
|
|
8
|
+
const save = card.querySelector<HTMLElement>('[data-part="save"]');
|
|
9
|
+
const live = card.querySelector<HTMLElement>('[data-part="save-live"]');
|
|
10
|
+
if (save === null || live === null) return;
|
|
11
|
+
const still = reduced || saveMotion === SaveMotion.None;
|
|
12
|
+
const source = beatsFor(saveMotion === SaveMotion.None ? SaveMotion.Tick : saveMotion);
|
|
13
|
+
const beats = still ? stillBeats(source) : source;
|
|
14
|
+
const ready = card.querySelector('[data-part="ready-text"]')?.textContent ?? '';
|
|
15
|
+
const find = (part: string): Element[] => Array.from(card.querySelectorAll(partSelector(part)));
|
|
16
|
+
let playing: Animation[] = [];
|
|
17
|
+
let timer: ReturnType<typeof setTimeout> | undefined;
|
|
18
|
+
save.addEventListener('click', () => {
|
|
19
|
+
cancelAll(playing);
|
|
20
|
+
playing = playBeats(beats, find);
|
|
21
|
+
live.textContent = ready;
|
|
22
|
+
clearTimeout(timer);
|
|
23
|
+
timer = setTimeout(() => { live.textContent = ''; }, RETURN_AT_MS);
|
|
24
|
+
}, { signal });
|
|
25
|
+
signal?.addEventListener('abort', () => clearTimeout(timer), { once: true });
|
|
26
|
+
}
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import { ShareMode } from './ShareMode';
|
|
2
|
+
|
|
3
|
+
const SCREEN = 'screen';
|
|
4
|
+
const OPENED = 'tmk-share-open';
|
|
5
|
+
|
|
6
|
+
interface WakeLockHandle {
|
|
7
|
+
release: () => Promise<void>;
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
interface WakeLockNavigator {
|
|
11
|
+
wakeLock?: { request: (type: typeof SCREEN) => Promise<WakeLockHandle> };
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
const warn = (error: unknown): void => console.warn(error);
|
|
15
|
+
|
|
16
|
+
function keepAwake(share: HTMLDialogElement, signal?: AbortSignal): void {
|
|
17
|
+
const wakeLock = (navigator as WakeLockNavigator).wakeLock;
|
|
18
|
+
if (wakeLock === undefined) return;
|
|
19
|
+
let held: WakeLockHandle | null = null;
|
|
20
|
+
const take = (): void => {
|
|
21
|
+
if (!share.open || document.hidden || held !== null) return;
|
|
22
|
+
wakeLock.request(SCREEN).then((handle) => {
|
|
23
|
+
if (share.open) held = handle;
|
|
24
|
+
else handle.release().catch(warn);
|
|
25
|
+
}).catch(warn);
|
|
26
|
+
};
|
|
27
|
+
const letGo = (): void => {
|
|
28
|
+
held?.release().catch(warn);
|
|
29
|
+
held = null;
|
|
30
|
+
};
|
|
31
|
+
share.addEventListener(OPENED, take, { signal });
|
|
32
|
+
share.addEventListener('close', letGo, { signal });
|
|
33
|
+
document.addEventListener('visibilitychange', () => {
|
|
34
|
+
if (document.hidden) held = null;
|
|
35
|
+
else take();
|
|
36
|
+
}, { signal });
|
|
37
|
+
signal?.addEventListener('abort', letGo, { once: true });
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
/** Opens the full-screen, motionless share view from Show my QR and keeps the screen awake while it is open. */
|
|
41
|
+
export function mountShare(card: HTMLElement, shareMode: ShareMode, signal?: AbortSignal): void {
|
|
42
|
+
if (shareMode === ShareMode.None) return;
|
|
43
|
+
const share = card.querySelector<HTMLDialogElement>('[data-card-share]');
|
|
44
|
+
const button = card.querySelector<HTMLElement>('[data-card-qr]');
|
|
45
|
+
if (share === null || button === null) return;
|
|
46
|
+
keepAwake(share, signal);
|
|
47
|
+
button.addEventListener('click', () => {
|
|
48
|
+
share.showModal();
|
|
49
|
+
button.setAttribute('aria-expanded', 'true');
|
|
50
|
+
share.dispatchEvent(new Event(OPENED));
|
|
51
|
+
}, { signal });
|
|
52
|
+
share.addEventListener('close', () => {
|
|
53
|
+
button.setAttribute('aria-expanded', 'false');
|
|
54
|
+
button.focus();
|
|
55
|
+
}, { signal });
|
|
56
|
+
share.querySelector('[data-card-share-close]')?.addEventListener('click', () => share.close(), { signal });
|
|
57
|
+
}
|