@dloizides/marketing-astro-kit 1.6.1 → 1.8.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 +121 -109
- package/README.md +28 -0
- package/package.json +24 -3
- package/src/BookingEmbed.astro +53 -0
- package/src/BottomSheet.astro +26 -0
- package/src/bookingEmbed/BookingState.ts +6 -0
- package/src/bookingEmbed/BookingTheme.ts +5 -0
- package/src/bookingEmbed/CalLayout.ts +6 -0
- package/src/bookingEmbed/contact.ts +22 -0
- package/src/bookingEmbed/fallbackWatch.ts +37 -0
- package/src/bookingEmbed/index.ts +6 -0
- package/src/bookingEmbed/mount.ts +140 -0
- package/src/bookingEmbed/options.ts +132 -0
- package/src/bottomSheet.css +15 -0
package/CHANGELOG.md
CHANGED
|
@@ -1,109 +1,121 @@
|
|
|
1
|
-
# Changelog
|
|
2
|
-
|
|
3
|
-
## 1.
|
|
4
|
-
|
|
5
|
-
###
|
|
6
|
-
|
|
7
|
-
- `
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
-
|
|
21
|
-
|
|
22
|
-
## 1.
|
|
23
|
-
|
|
24
|
-
### Added
|
|
25
|
-
|
|
26
|
-
- `<
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
(
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
- `
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
-
|
|
107
|
-
|
|
108
|
-
-
|
|
109
|
-
|
|
1
|
+
# Changelog
|
|
2
|
+
|
|
3
|
+
## 1.8.0
|
|
4
|
+
|
|
5
|
+
### Added
|
|
6
|
+
|
|
7
|
+
- `<BookingEmbed />` (`./BookingEmbed.astro`) + `./bookingEmbed` helpers: Cal.com inline embed set by options, contact fallback after 8 s or a load error, address assembled in the browser. Unit tests (vitest), lint and typecheck scripts. MOONCUBE-SITE-1 "Moon Cube Technologies site: read and book", AC-18.
|
|
8
|
+
|
|
9
|
+
## 1.7.0
|
|
10
|
+
|
|
11
|
+
### Added
|
|
12
|
+
|
|
13
|
+
- `<BottomSheet />` (`./BottomSheet.astro`): slot-based phone bottom sheet opened by `:target`, inline at 1024 px and up. Sits above `--dlz-consent-inset`. BEAD-ONE-2 "One-host follow-ups".
|
|
14
|
+
|
|
15
|
+
## 1.6.1
|
|
16
|
+
|
|
17
|
+
### Fixed
|
|
18
|
+
|
|
19
|
+
- `HairlineFigure` mount: a failed lazy-chunk load or figure mount no longer becomes an unhandled rejection. The host gets `data-hairline-failed="true"` and the page logs one `console.warn`. HAIRLINE-1 "Adopt hairline isometric line figures".
|
|
20
|
+
- README: a sub-path host (kefi-landings) needs `build.assetsPrefix` set to an ABSOLUTE origin serving `dist/_astro/`; a relative prefix fails silently.
|
|
21
|
+
|
|
22
|
+
## 1.6.0
|
|
23
|
+
|
|
24
|
+
### Added
|
|
25
|
+
|
|
26
|
+
- `<HairlineFigure />` (`./HairlineFigure.astro`) plus `HAIRLINE_FIGURES`, `TOUCH_SAFE_HAIRLINE_FIGURES` and `clampHairlineIntensity` (`./hairline`). Wraps `@lucasmarkes/hairline` 0.3.0 (exact pin): SSR 5:4 box, lazy mount near the viewport, destroy on page swap, `--hairline-*` mapped from the theming contract. HAIRLINE-1 "Adopt hairline isometric line figures".
|
|
27
|
+
|
|
28
|
+
## 1.5.2
|
|
29
|
+
|
|
30
|
+
### Fixed
|
|
31
|
+
|
|
32
|
+
- `.dmk-disclaimer` (DemoFrame) and `.pmk-footnote` (PricingComparison) cap their measure at 65ch; at 1280 px they ran 102-113 characters per line. Mobile is unaffected.
|
|
33
|
+
|
|
34
|
+
## 1.3.0
|
|
35
|
+
|
|
36
|
+
### Added
|
|
37
|
+
|
|
38
|
+
- `<HeroBackdrop />` plus the named hero-backdrop preset catalog (`./heroBackdrop`).
|
|
39
|
+
Nine animated hero treatments -- three canvas, one SVG-filter, five pure-CSS --
|
|
40
|
+
that until now existed ONLY in a disposable per-session scratchpad and had been
|
|
41
|
+
rebuilt from scratch more than once. `HERO_BACKDROP_PRESETS` is the permanent
|
|
42
|
+
record: preset name -> `{ variant, engine, palette, css, ember }`, using the
|
|
43
|
+
design studio's own parameter names verbatim so a studio export pastes in with
|
|
44
|
+
no translation step.
|
|
45
|
+
- `csdf-ember-sparse` -- CSDF's shipped configuration. 40 particles, an eighth of
|
|
46
|
+
the studio default, which is what makes a canvas backdrop affordable against a
|
|
47
|
+
hard Lighthouse >= 80 budget.
|
|
48
|
+
- Only the ember canvas engine ships as a RENDERER. The CSS/SVG entries are
|
|
49
|
+
recorded PARAMETER SETS painted by the host stylesheet; the component renders
|
|
50
|
+
nothing for those, leaving the host's own backdrop untouched.
|
|
51
|
+
|
|
52
|
+
### Notes
|
|
53
|
+
|
|
54
|
+
- The component's script is `is:inline` deliberately -- a bundled Astro script
|
|
55
|
+
emits a root-absolute `/_astro/*.js` reference, which 404s under kefi-landings'
|
|
56
|
+
host-based per-tenant nginx roots.
|
|
57
|
+
- Respects `prefers-reduced-motion` (one still frame, no loop) and stops the rAF
|
|
58
|
+
loop on `visibilitychange` and when the canvas leaves the viewport.
|
|
59
|
+
|
|
60
|
+
## 1.2.1
|
|
61
|
+
|
|
62
|
+
- **a11y fix (serious): the pricing comparison was SILENT to screen readers.**
|
|
63
|
+
`PricingComparison.astro` marked each cell with `aria-label` on a bare
|
|
64
|
+
`<span>`. `aria-label` is *prohibited* on a roleless generic element, so
|
|
65
|
+
assistive tech ignored it — and the inner `<svg>` is `aria-hidden`. Net
|
|
66
|
+
effect: a screen-reader user reached every included/not-included cell and
|
|
67
|
+
heard **nothing**, so they could not tell which plan carried which feature,
|
|
68
|
+
on a public pricing page. Fixed by giving the span `role="img"` alongside
|
|
69
|
+
the existing label. Found by the `a11y-public` E2E axe scan against the live
|
|
70
|
+
kefi landing: `aria-prohibited-attr`, 27 nodes. Swept the rest of the kit —
|
|
71
|
+
no other instances of this shape.
|
|
72
|
+
|
|
73
|
+
## 1.2.0
|
|
74
|
+
|
|
75
|
+
- New `DemoFrame.astro` — a themeable, **client-side "try it" demo** shell for
|
|
76
|
+
static marketing sites (no backend): an eyebrow/title/intro, a row of clickable
|
|
77
|
+
example chips, a per-example result panel (bespoke product body injected via a
|
|
78
|
+
named slot `result-<example.id>`), a clearly-visible "sample data" disclaimer,
|
|
79
|
+
and a primary CTA (reuses `PrimaryCta`). Tiny inline vanilla JS toggles which
|
|
80
|
+
result shows on chip click (+ arrow-key roving tablist); the first example is
|
|
81
|
+
visible without JS (progressive enhancement). New `DemoExample` / `DemoFrameData`
|
|
82
|
+
types in `schema.ts`.
|
|
83
|
+
- New `GuideCard.astro` — a themeable card for a **guides / SEO content-hub**
|
|
84
|
+
listing, rendering one guide's tags, title, description and date. New
|
|
85
|
+
`GuideCardData` type.
|
|
86
|
+
- New `guideFrontmatterSchema` (Zod, built on `astro/zod`) + `GuideFrontmatter`
|
|
87
|
+
type in `schema.ts` — plug straight into an Astro content collection
|
|
88
|
+
(`defineCollection({ loader: glob(...), schema: guideFrontmatterSchema })`) so
|
|
89
|
+
every product's guides validate the same shape (title, description, slug?,
|
|
90
|
+
publishDate, updatedDate?, tags, ogImage?, canonical?, draft?). The article
|
|
91
|
+
page + routes + JSON-LD stay product-owned.
|
|
92
|
+
- `schema.ts` now imports `z` from `astro/zod` (Astro is already a peer dep) —
|
|
93
|
+
the ONE runtime import; every other export stays plain types.
|
|
94
|
+
|
|
95
|
+
## 1.1.0
|
|
96
|
+
|
|
97
|
+
- New `PrimaryCta.astro` — a themeable primary call-to-action (link OR spam-safe
|
|
98
|
+
contact) with an optional secondary CTA and a `tone: 'light' | 'dark'` for
|
|
99
|
+
dark bands. Renders a `MarketingCta` so link-vs-lead-capture + analytics wiring
|
|
100
|
+
is no longer hand-coded per page.
|
|
101
|
+
- New `buildPrimaryCta(opts)` helper + `PrimaryCtaOptions` in `schema.ts`: drive
|
|
102
|
+
a primary CTA from ONE `SIGNUP_URL` constant — a real signup link when set,
|
|
103
|
+
spam-safe lead-capture when `null` (flip at GA with no template change).
|
|
104
|
+
- `ctaAttrs()` promoted from `PricingComparison.astro` into `schema.ts` and now
|
|
105
|
+
shared by every CTA-rendering component (no duplication).
|
|
106
|
+
- `TrustSection` gains three optional, guarded fields (existing sites
|
|
107
|
+
unaffected): `foundingPartner` ("first N free during beta" panel),
|
|
108
|
+
`founder` (honest one-line credibility) and `sampleDeliverable` (a "here's the
|
|
109
|
+
actual report you get" showcase — image, or a `slot="sample-deliverable"` for
|
|
110
|
+
bespoke mock markup while the section chrome stays shared).
|
|
111
|
+
|
|
112
|
+
## 1.0.0
|
|
113
|
+
|
|
114
|
+
- Initial release. `PricingComparison.astro` (Free-vs-Pro comparison table with
|
|
115
|
+
tier columns, grouped feature rows, optional footnote + one-time callout card)
|
|
116
|
+
and `TrustSection.astro` (security cards with inline icons, customer-logo row
|
|
117
|
+
with placeholders, testimonial placeholders, discreet built-by line).
|
|
118
|
+
- Framework-agnostic data schema (`schema.ts`) + inline icon set (`icons.ts`).
|
|
119
|
+
- Themed via host CSS custom properties with fallbacks; no image assets.
|
|
120
|
+
- Extracted from `kefi-marketing` as the 2nd genuine use of the pricing/trust
|
|
121
|
+
sections across the Astro marketing sites.
|
package/README.md
CHANGED
|
@@ -10,6 +10,7 @@ credibility + conversion markers an executive scans for before they trust a SaaS
|
|
|
10
10
|
| `PrimaryCta.astro` | A themeable **primary call-to-action** (link OR spam-safe contact) with an optional secondary CTA. Pair with `buildPrimaryCta` so ONE `SIGNUP_URL` constant drives whether it's a real signup link or lead-capture. |
|
|
11
11
|
| `DemoFrame.astro` | A themeable, **client-side "try it" demo** shell for static sites (no backend): eyebrow/title/intro, a row of clickable example chips, a per-example result panel (bespoke product body via a named `result-<id>` slot), a "sample data" disclaimer, and a primary CTA. Tiny inline vanilla JS toggles which result shows; first example visible without JS. |
|
|
12
12
|
| `GuideCard.astro` | A themeable **card for a guides / SEO content-hub** listing — one guide's tags, title, description and date. Pair with `guideFrontmatterSchema` on an Astro content collection. |
|
|
13
|
+
| `BookingEmbed.astro` | A **Cal.com inline booking embed** set by options (link, theme, brand colours), loaded on its page only, with a spam-safe contact fallback after a timeout or load error. |
|
|
13
14
|
| `HairlineFigure.astro` | A **Hairline isometric line figure** (`@lucasmarkes/hairline`, pinned 0.3.0) for heroes and empty states: an empty 5:4 box server-side, drawn on the client once it nears the viewport, coloured from the host's tokens. |
|
|
14
15
|
|
|
15
16
|
## Config-driven primary CTA (`PrimaryCta` + `buildPrimaryCta`)
|
|
@@ -185,6 +186,33 @@ import HairlineFigure from '@dloizides/marketing-astro-kit/HairlineFigure.astro'
|
|
|
185
186
|
- **Script bundling:** unlike `HeroBackdrop`, this script is a bundled Astro `<script>` (it imports an npm module), so it emits a root-absolute `/_astro/*.js` URL. On a host that serves a tenant from a sub-directory (kefi-landings: the nginx root is the tenant sub-directory), set Astro's `build.assetsPrefix` to an ABSOLUTE origin (`https://cdn.example.com`) that serves this build's `dist/_astro/`, both the entry script and the lazy Hairline chunk. A relative prefix fails silently: the chunk 404s and the box stays empty, marked `data-hairline-failed` with one `console.warn`.
|
|
186
187
|
- **Vite-alias consumers** (the kit aliased to source, not installed) must have `@lucasmarkes/hairline@0.3.0` resolvable from the site.
|
|
187
188
|
|
|
189
|
+
## Booking embed (`BookingEmbed`)
|
|
190
|
+
|
|
191
|
+
```astro
|
|
192
|
+
---
|
|
193
|
+
import BookingEmbed from "@dloizides/marketing-astro-kit/BookingEmbed.astro";
|
|
194
|
+
import { BookingTheme, CalLayout } from "@dloizides/marketing-astro-kit/bookingEmbed";
|
|
195
|
+
---
|
|
196
|
+
<BookingEmbed
|
|
197
|
+
id="book"
|
|
198
|
+
label="Book a call"
|
|
199
|
+
options={{ calLink: "mooncube/intro", theme: BookingTheme.Dark, layout: CalLayout.Month,
|
|
200
|
+
hideEventTypeDetails: true, cssVarsPerTheme: { dark: { "cal-bg": "#0F1B2D", "cal-brand": "#E8C36A" } } }}
|
|
201
|
+
contact={{ local: "hello", domain: "example.com" }}
|
|
202
|
+
>
|
|
203
|
+
<p slot="fallback">Calendar unavailable. Email <a data-booking-contact></a></p>
|
|
204
|
+
</BookingEmbed>
|
|
205
|
+
```
|
|
206
|
+
|
|
207
|
+
- Options: `calLink` (required, Cal.com path), `theme` (default dark), `layout` (default month view), `hideEventTypeDetails`, `cssVarsPerTheme` (`cal-*` names, hex only, checked at build), `timeoutMs` (default 8000), `namespace` (`^[\w-]+$`, default the host `id`), `origin` (https URL with no path, default `https://app.cal.com`; the embed script loads from `<origin>/embed/embed.js`).
|
|
208
|
+
- The Cal.com script is added by the component script only when a host is on the page.
|
|
209
|
+
- The fallback slot shows after `timeoutMs` with no `linkReady`, on `linkFailed`, or when the script fails, for hosts mounted by any later call too. Each `[data-booking-contact]` link gets its `mailto:` filled in the browser from `data-local` + `data-domain`; the served HTML holds no address.
|
|
210
|
+
- `data-booking-state` on the host is `loading`, `ready` or `fallback`. Set `--tmk-booking-min-height` (default 640px).
|
|
211
|
+
|
|
212
|
+
## Bottom sheet (`BottomSheet`)
|
|
213
|
+
|
|
214
|
+
Below 1024 px the default slot opens as a bottom sheet when the URL hash equals `id`; link to `#id` to open it. From 1024 px the slot renders inline and the head and foot are hidden. The `foot` slot holds the sticky action. Set `--tmk-sheet-bg` and `--tmk-sheet-edge` to theme it (fallbacks `--paper`, `--ink`). It stays above a consent card through `--dlz-consent-inset`. The close link carries `data-sheet-close`.
|
|
215
|
+
|
|
188
216
|
## Theming contract
|
|
189
217
|
|
|
190
218
|
The components read these CSS vars off the host `:root` (each has a sensible
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@dloizides/marketing-astro-kit",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.8.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, 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",
|
|
@@ -19,7 +19,9 @@
|
|
|
19
19
|
"canvas",
|
|
20
20
|
"animation",
|
|
21
21
|
"hairline",
|
|
22
|
-
"illustration"
|
|
22
|
+
"illustration",
|
|
23
|
+
"booking",
|
|
24
|
+
"cal.com"
|
|
23
25
|
],
|
|
24
26
|
"author": "dloizides",
|
|
25
27
|
"license": "MIT",
|
|
@@ -30,6 +32,7 @@
|
|
|
30
32
|
},
|
|
31
33
|
"files": [
|
|
32
34
|
"src",
|
|
35
|
+
"!src/**/*.test.ts",
|
|
33
36
|
"README.md",
|
|
34
37
|
"CHANGELOG.md"
|
|
35
38
|
],
|
|
@@ -46,11 +49,29 @@
|
|
|
46
49
|
"./heroBackdrop": "./src/heroBackdrop/presets.ts",
|
|
47
50
|
"./heroBackdrop/types": "./src/heroBackdrop/types.ts",
|
|
48
51
|
"./HairlineFigure.astro": "./src/HairlineFigure.astro",
|
|
49
|
-
"./hairline": "./src/hairline/figures.ts"
|
|
52
|
+
"./hairline": "./src/hairline/figures.ts",
|
|
53
|
+
"./BottomSheet.astro": "./src/BottomSheet.astro",
|
|
54
|
+
"./bottomSheet.css": "./src/bottomSheet.css",
|
|
55
|
+
"./BookingEmbed.astro": "./src/BookingEmbed.astro",
|
|
56
|
+
"./bookingEmbed": "./src/bookingEmbed/index.ts"
|
|
57
|
+
},
|
|
58
|
+
"scripts": {
|
|
59
|
+
"test": "vitest run",
|
|
60
|
+
"lint": "eslint src/bookingEmbed --ext .ts",
|
|
61
|
+
"typecheck": "tsc --noEmit -p ."
|
|
50
62
|
},
|
|
51
63
|
"dependencies": {
|
|
52
64
|
"@lucasmarkes/hairline": "0.3.0"
|
|
53
65
|
},
|
|
66
|
+
"devDependencies": {
|
|
67
|
+
"@typescript-eslint/eslint-plugin": "^7.18.0",
|
|
68
|
+
"@typescript-eslint/parser": "^7.18.0",
|
|
69
|
+
"eslint": "^8.57.1",
|
|
70
|
+
"eslint-plugin-sonarjs": "^3.0.7",
|
|
71
|
+
"jsdom": "^25.0.1",
|
|
72
|
+
"typescript": "^5.9.3",
|
|
73
|
+
"vitest": "^2.1.9"
|
|
74
|
+
},
|
|
54
75
|
"peerDependencies": {
|
|
55
76
|
"astro": ">=4"
|
|
56
77
|
},
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
---
|
|
2
|
+
import { contactDataAttributes, type BookingContact } from './bookingEmbed/contact';
|
|
3
|
+
import { serializeBookingOptions, type BookingEmbedOptions } from './bookingEmbed/options';
|
|
4
|
+
|
|
5
|
+
interface Props {
|
|
6
|
+
/** Unique id; the calendar mounts at `#<id>-calendar`. */
|
|
7
|
+
id: string;
|
|
8
|
+
options: BookingEmbedOptions;
|
|
9
|
+
/** Address parts, joined in the browser only when the fallback shows. */
|
|
10
|
+
contact: BookingContact;
|
|
11
|
+
label: string;
|
|
12
|
+
testId?: string;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
const { id, options, contact, label, testId } = Astro.props;
|
|
16
|
+
---
|
|
17
|
+
|
|
18
|
+
<section
|
|
19
|
+
class="tmk-booking"
|
|
20
|
+
id={id}
|
|
21
|
+
aria-label={label}
|
|
22
|
+
data-booking-embed
|
|
23
|
+
data-booking-options={serializeBookingOptions(options)}
|
|
24
|
+
{...contactDataAttributes(contact)}
|
|
25
|
+
data-testid={testId}
|
|
26
|
+
>
|
|
27
|
+
<div class="tmk-booking-calendar" id={`${id}-calendar`} data-booking-calendar tabindex="-1"></div>
|
|
28
|
+
<div class="tmk-booking-fallback" data-booking-fallback hidden>
|
|
29
|
+
<slot name="fallback" />
|
|
30
|
+
</div>
|
|
31
|
+
</section>
|
|
32
|
+
|
|
33
|
+
<style>
|
|
34
|
+
:where(.tmk-booking) {
|
|
35
|
+
display: block;
|
|
36
|
+
width: 100%;
|
|
37
|
+
min-height: var(--tmk-booking-min-height, 640px);
|
|
38
|
+
}
|
|
39
|
+
:where(.tmk-booking-calendar) {
|
|
40
|
+
width: 100%;
|
|
41
|
+
min-height: inherit;
|
|
42
|
+
overflow: auto;
|
|
43
|
+
}
|
|
44
|
+
:where(.tmk-booking[data-booking-state='fallback']) {
|
|
45
|
+
min-height: 0;
|
|
46
|
+
}
|
|
47
|
+
</style>
|
|
48
|
+
|
|
49
|
+
<script>
|
|
50
|
+
import { mountBookingEmbeds } from './bookingEmbed/mount';
|
|
51
|
+
|
|
52
|
+
mountBookingEmbeds();
|
|
53
|
+
</script>
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
---
|
|
2
|
+
import './bottomSheet.css';
|
|
3
|
+
|
|
4
|
+
interface Props {
|
|
5
|
+
id: string;
|
|
6
|
+
title: string;
|
|
7
|
+
closeLabel: string;
|
|
8
|
+
testId?: string;
|
|
9
|
+
closeTestId?: string;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
const { id, title, closeLabel, testId, closeTestId } = Astro.props;
|
|
13
|
+
const titleId = `${id}-title`;
|
|
14
|
+
---
|
|
15
|
+
<div class="tmk-sheet" id={id} role="group" aria-labelledby={titleId} data-testid={testId}>
|
|
16
|
+
<div class="tmk-sheet-head">
|
|
17
|
+
<div class="tmk-sheet-title" id={titleId}>{title}</div>
|
|
18
|
+
<a class="tmk-sheet-close" href="#" aria-label={closeLabel} data-sheet-close data-testid={closeTestId}>
|
|
19
|
+
<svg width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" aria-hidden="true"><path d="M6 6l12 12M18 6L6 18" /></svg>
|
|
20
|
+
</a>
|
|
21
|
+
</div>
|
|
22
|
+
<slot />
|
|
23
|
+
<div class="tmk-sheet-foot">
|
|
24
|
+
<slot name="foot" />
|
|
25
|
+
</div>
|
|
26
|
+
</div>
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
export interface BookingContact {
|
|
2
|
+
local: string;
|
|
3
|
+
domain: string;
|
|
4
|
+
}
|
|
5
|
+
|
|
6
|
+
/** Joins the two parts into an address at runtime, so the served HTML never holds it; throws on a bad part. */
|
|
7
|
+
export function assembleContactEmail(local: string, domain: string): string {
|
|
8
|
+
if (local === '' || local.includes('@')) throw new Error('BookingEmbed: contact local part must be non-empty with no @');
|
|
9
|
+
if (domain === '' || domain.includes('@')) throw new Error('BookingEmbed: contact domain must be non-empty with no @');
|
|
10
|
+
return `${local}@${domain}`;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
/** Returns the mailto link for the contact. */
|
|
14
|
+
export function contactMailtoHref(contact: BookingContact): string {
|
|
15
|
+
return `mailto:${assembleContactEmail(contact.local, contact.domain)}`;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
/** Returns the split data attributes the host renders instead of an address. */
|
|
19
|
+
export function contactDataAttributes(contact: BookingContact): Record<string, string> {
|
|
20
|
+
assembleContactEmail(contact.local, contact.domain);
|
|
21
|
+
return { 'data-local': contact.local, 'data-domain': contact.domain };
|
|
22
|
+
}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { BookingState } from './BookingState';
|
|
2
|
+
|
|
3
|
+
export interface FallbackWatchOptions {
|
|
4
|
+
timeoutMs: number;
|
|
5
|
+
onFallback: () => void;
|
|
6
|
+
onLoaded?: () => void;
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
export interface FallbackWatch {
|
|
10
|
+
markLoaded: () => void;
|
|
11
|
+
markFailed: () => void;
|
|
12
|
+
state: () => BookingState;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
/** Shows the fallback once when the embed errors or is not ready within `timeoutMs`; a ready embed cancels it. */
|
|
16
|
+
export function createFallbackWatch(options: FallbackWatchOptions): FallbackWatch {
|
|
17
|
+
let state = BookingState.Loading;
|
|
18
|
+
const fallBack = (): void => {
|
|
19
|
+
if (state !== BookingState.Loading) return;
|
|
20
|
+
state = BookingState.Fallback;
|
|
21
|
+
options.onFallback();
|
|
22
|
+
};
|
|
23
|
+
const timer = setTimeout(fallBack, options.timeoutMs);
|
|
24
|
+
return {
|
|
25
|
+
markLoaded: (): void => {
|
|
26
|
+
if (state !== BookingState.Loading) return;
|
|
27
|
+
state = BookingState.Ready;
|
|
28
|
+
clearTimeout(timer);
|
|
29
|
+
options.onLoaded?.();
|
|
30
|
+
},
|
|
31
|
+
markFailed: (): void => {
|
|
32
|
+
clearTimeout(timer);
|
|
33
|
+
fallBack();
|
|
34
|
+
},
|
|
35
|
+
state: (): BookingState => state,
|
|
36
|
+
};
|
|
37
|
+
}
|
|
@@ -0,0 +1,140 @@
|
|
|
1
|
+
import { BookingState } from './BookingState';
|
|
2
|
+
import { contactMailtoHref } from './contact';
|
|
3
|
+
import { createFallbackWatch, type FallbackWatch } from './fallbackWatch';
|
|
4
|
+
import {
|
|
5
|
+
buildCalCommands,
|
|
6
|
+
calEmbedScriptUrl,
|
|
7
|
+
parseBookingOptions,
|
|
8
|
+
resolveBookingTimeoutMs,
|
|
9
|
+
resolveCalNamespace,
|
|
10
|
+
} from './options';
|
|
11
|
+
|
|
12
|
+
const HOST_SELECTOR = '[data-booking-embed]';
|
|
13
|
+
const CALENDAR_SELECTOR = '[data-booking-calendar]';
|
|
14
|
+
const FALLBACK_SELECTOR = '[data-booking-fallback]';
|
|
15
|
+
const CONTACT_SELECTOR = '[data-booking-contact]';
|
|
16
|
+
const SCRIPT_SELECTOR = 'script[data-booking-cal-script]';
|
|
17
|
+
const SCRIPT_FAILED = 'failed';
|
|
18
|
+
const SELECTOR_UNSAFE_CHARS = /[^\w-]/g;
|
|
19
|
+
|
|
20
|
+
export interface CalQueue {
|
|
21
|
+
(...args: unknown[]): void;
|
|
22
|
+
q: unknown[][];
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
export interface CalApi extends CalQueue {
|
|
26
|
+
ns: Record<string, CalQueue | undefined>;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
export type CalWindow = Window & { Cal?: CalApi };
|
|
30
|
+
|
|
31
|
+
function createQueue(): CalQueue {
|
|
32
|
+
const queue = ((...args: unknown[]): void => {
|
|
33
|
+
queue.q.push(args);
|
|
34
|
+
}) as CalQueue;
|
|
35
|
+
queue.q = [];
|
|
36
|
+
return queue;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
function createCalStub(doc: Document, scriptUrl: string): CalApi {
|
|
40
|
+
const cal = ((...args: unknown[]): void => {
|
|
41
|
+
const namespace = args[1];
|
|
42
|
+
if (args[0] !== 'init' || typeof namespace !== 'string') {
|
|
43
|
+
cal.q.push(args);
|
|
44
|
+
return;
|
|
45
|
+
}
|
|
46
|
+
const api = cal.ns[namespace] ?? createQueue();
|
|
47
|
+
cal.ns[namespace] = api;
|
|
48
|
+
api.q.push(args);
|
|
49
|
+
cal.q.push(['initNamespace', namespace]);
|
|
50
|
+
}) as CalApi;
|
|
51
|
+
cal.q = [];
|
|
52
|
+
cal.ns = {};
|
|
53
|
+
const script = doc.createElement('script');
|
|
54
|
+
script.src = scriptUrl;
|
|
55
|
+
script.async = true;
|
|
56
|
+
script.dataset.bookingCalScript = '';
|
|
57
|
+
script.addEventListener('error', () => {
|
|
58
|
+
script.dataset.bookingCalScript = SCRIPT_FAILED;
|
|
59
|
+
});
|
|
60
|
+
doc.head.appendChild(script);
|
|
61
|
+
return cal;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
function fillContactLinks(host: HTMLElement): void {
|
|
65
|
+
const { local, domain } = host.dataset;
|
|
66
|
+
if (local === undefined || domain === undefined) return;
|
|
67
|
+
const href = contactMailtoHref({ local, domain });
|
|
68
|
+
host.querySelectorAll<HTMLAnchorElement>(CONTACT_SELECTOR).forEach((link) => {
|
|
69
|
+
link.href = href;
|
|
70
|
+
if ((link.textContent ?? '').trim() === '') link.textContent = href.replace('mailto:', '');
|
|
71
|
+
});
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
function showFallback(host: HTMLElement): void {
|
|
75
|
+
host.dataset.bookingState = BookingState.Fallback;
|
|
76
|
+
fillContactLinks(host);
|
|
77
|
+
const calendar = host.querySelector<HTMLElement>(CALENDAR_SELECTOR);
|
|
78
|
+
const fallback = host.querySelector<HTMLElement>(FALLBACK_SELECTOR);
|
|
79
|
+
if (calendar !== null) calendar.hidden = true;
|
|
80
|
+
if (fallback !== null) fallback.hidden = false;
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
function mountHost(host: HTMLElement, getCal: (scriptUrl: string) => CalApi): FallbackWatch {
|
|
84
|
+
host.dataset.bookingState = BookingState.Loading;
|
|
85
|
+
const parsed = parseBookingOptions(host.dataset.bookingOptions ?? '');
|
|
86
|
+
const options = { ...parsed, namespace: resolveCalNamespace(parsed, host.id) };
|
|
87
|
+
const calendarId = host.querySelector<HTMLElement>(CALENDAR_SELECTOR)?.id ?? '';
|
|
88
|
+
const [init, ...rest] = buildCalCommands(options, `#${calendarId.replace(SELECTOR_UNSAFE_CHARS, '\\$&')}`);
|
|
89
|
+
const cal = getCal(calEmbedScriptUrl(options.origin));
|
|
90
|
+
const watch = createFallbackWatch({
|
|
91
|
+
timeoutMs: resolveBookingTimeoutMs(options.timeoutMs),
|
|
92
|
+
onFallback: () => showFallback(host),
|
|
93
|
+
onLoaded: () => {
|
|
94
|
+
host.dataset.bookingState = BookingState.Ready;
|
|
95
|
+
},
|
|
96
|
+
});
|
|
97
|
+
if (init !== undefined) cal(...init);
|
|
98
|
+
const api = cal.ns[options.namespace];
|
|
99
|
+
rest.forEach((command) => api?.(...command));
|
|
100
|
+
api?.('on', { action: 'linkReady', callback: () => watch.markLoaded() });
|
|
101
|
+
api?.('on', { action: 'linkFailed', callback: () => watch.markFailed() });
|
|
102
|
+
return watch;
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
function mountOrFallBack(host: HTMLElement, cal: (scriptUrl: string) => CalApi): FallbackWatch | null {
|
|
106
|
+
try {
|
|
107
|
+
return mountHost(host, cal);
|
|
108
|
+
} catch (error) {
|
|
109
|
+
console.warn(`BookingEmbed: host "${host.id}" shows its fallback: ${String(error)}`);
|
|
110
|
+
showFallback(host);
|
|
111
|
+
return null;
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
function watchScriptFailure(doc: Document, watches: FallbackWatch[]): void {
|
|
116
|
+
const script = doc.querySelector<HTMLScriptElement>(SCRIPT_SELECTOR);
|
|
117
|
+
if (script === null || watches.length === 0) return;
|
|
118
|
+
const failAll = (): void => watches.forEach((watch) => watch.markFailed());
|
|
119
|
+
if (script.dataset.bookingCalScript === SCRIPT_FAILED) failAll();
|
|
120
|
+
else script.addEventListener('error', failAll);
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
/** Mounts every not-yet-mounted booking host on the page; adds the Cal.com script only when one exists. */
|
|
124
|
+
export function mountBookingEmbeds(doc: Document = document, win: CalWindow = window): number {
|
|
125
|
+
const hosts = Array.from(doc.querySelectorAll<HTMLElement>(HOST_SELECTOR)).filter(
|
|
126
|
+
(host) => host.dataset.bookingState === undefined,
|
|
127
|
+
);
|
|
128
|
+
if (hosts.length === 0) return 0;
|
|
129
|
+
const watches: FallbackWatch[] = [];
|
|
130
|
+
const cal = (scriptUrl: string): CalApi => {
|
|
131
|
+
win.Cal ??= createCalStub(doc, scriptUrl);
|
|
132
|
+
return win.Cal;
|
|
133
|
+
};
|
|
134
|
+
hosts.forEach((host) => {
|
|
135
|
+
const watch = mountOrFallBack(host, cal);
|
|
136
|
+
if (watch !== null) watches.push(watch);
|
|
137
|
+
});
|
|
138
|
+
watchScriptFailure(doc, watches);
|
|
139
|
+
return hosts.length;
|
|
140
|
+
}
|
|
@@ -0,0 +1,132 @@
|
|
|
1
|
+
import { BookingTheme } from './BookingTheme';
|
|
2
|
+
import { CalLayout } from './CalLayout';
|
|
3
|
+
|
|
4
|
+
export const DEFAULT_BOOKING_TIMEOUT_MS = 8000;
|
|
5
|
+
export const DEFAULT_CAL_NAMESPACE = 'booking';
|
|
6
|
+
export const DEFAULT_CAL_ORIGIN = 'https://app.cal.com';
|
|
7
|
+
const CAL_EMBED_SCRIPT_PATH = '/embed/embed.js';
|
|
8
|
+
|
|
9
|
+
const CAL_LINK_PATTERN = /^[\w.-]+(\/[\w.-]+)*$/;
|
|
10
|
+
const CAL_VAR_PATTERN = /^cal-[a-z-]+$/;
|
|
11
|
+
const CAL_NAMESPACE_PATTERN = /^[\w-]+$/;
|
|
12
|
+
const NAMESPACE_UNSAFE_CHARS = /[^\w-]/g;
|
|
13
|
+
const HTTPS_PROTOCOL = 'https:';
|
|
14
|
+
const HEX_COLOUR_PATTERN = /^#([0-9a-f]{3}|[0-9a-f]{6}|[0-9a-f]{8})$/i;
|
|
15
|
+
|
|
16
|
+
export type CalCssVars = Record<string, string>;
|
|
17
|
+
export type CalCssVarsPerTheme = Partial<Record<BookingTheme, CalCssVars>>;
|
|
18
|
+
|
|
19
|
+
export interface BookingEmbedOptions {
|
|
20
|
+
calLink: string;
|
|
21
|
+
theme?: BookingTheme;
|
|
22
|
+
layout?: CalLayout;
|
|
23
|
+
hideEventTypeDetails?: boolean;
|
|
24
|
+
cssVarsPerTheme?: CalCssVarsPerTheme;
|
|
25
|
+
timeoutMs?: number;
|
|
26
|
+
namespace?: string;
|
|
27
|
+
origin?: string;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
export interface CalUiConfig {
|
|
31
|
+
theme: BookingTheme;
|
|
32
|
+
hideEventTypeDetails: boolean;
|
|
33
|
+
layout: CalLayout;
|
|
34
|
+
cssVarsPerTheme: CalCssVarsPerTheme;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
export type CalCommand = [string, ...unknown[]];
|
|
38
|
+
|
|
39
|
+
/** Returns the timeout in ms, or the 8 s default when the value is missing, not finite or not positive. */
|
|
40
|
+
export function resolveBookingTimeoutMs(value: number | undefined): number {
|
|
41
|
+
const isUsable = value !== undefined && Number.isFinite(value) && value > 0;
|
|
42
|
+
return isUsable ? value : DEFAULT_BOOKING_TIMEOUT_MS;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
function parseUrl(value: string): URL | null {
|
|
46
|
+
try {
|
|
47
|
+
return new URL(value);
|
|
48
|
+
} catch {
|
|
49
|
+
return null;
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
function hasNoPath(value: string, url: URL): boolean {
|
|
54
|
+
return url.protocol === HTTPS_PROTOCOL && (value === url.origin || value === `${url.origin}/`);
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
/** Returns the Cal.com origin, default app.cal.com; throws unless it is an https URL with no path. */
|
|
58
|
+
export function resolveCalOrigin(origin: string | undefined): string {
|
|
59
|
+
const value = origin ?? DEFAULT_CAL_ORIGIN;
|
|
60
|
+
const url = parseUrl(value);
|
|
61
|
+
if (url === null || !hasNoPath(value, url)) throw new Error(`BookingEmbed: "${value}" is not an https origin`);
|
|
62
|
+
return url.origin;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
/** Returns the Cal.com embed script URL on the given origin. */
|
|
66
|
+
export function calEmbedScriptUrl(origin: string | undefined): string {
|
|
67
|
+
return `${resolveCalOrigin(origin)}${CAL_EMBED_SCRIPT_PATH}`;
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
/** Returns the namespace from the options, else the host id with every non `[\w-]` character as `-`, else the default. */
|
|
71
|
+
export function resolveCalNamespace(options: BookingEmbedOptions, hostId: string): string {
|
|
72
|
+
return options.namespace ?? (hostId !== '' ? hostId.replace(NAMESPACE_UNSAFE_CHARS, '-') : DEFAULT_CAL_NAMESPACE);
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
function checkNamespace(namespace: string): string {
|
|
76
|
+
if (!CAL_NAMESPACE_PATTERN.test(namespace)) throw new Error(`BookingEmbed: "${namespace}" is not a namespace`);
|
|
77
|
+
return namespace;
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
function checkCssVars(vars: CalCssVars): CalCssVars {
|
|
81
|
+
Object.entries(vars).forEach(([name, colour]) => {
|
|
82
|
+
if (!CAL_VAR_PATTERN.test(name)) throw new Error(`BookingEmbed: "${name}" is not a Cal.com cal-* variable`);
|
|
83
|
+
if (!HEX_COLOUR_PATTERN.test(colour)) throw new Error(`BookingEmbed: colour for "${name}" must be hex`);
|
|
84
|
+
});
|
|
85
|
+
return { ...vars };
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
function checkCssVarsPerTheme(perTheme: CalCssVarsPerTheme | undefined): CalCssVarsPerTheme {
|
|
89
|
+
const checked: CalCssVarsPerTheme = {};
|
|
90
|
+
Object.entries(perTheme ?? {}).forEach(([theme, vars]) => {
|
|
91
|
+
checked[theme as BookingTheme] = checkCssVars(vars);
|
|
92
|
+
});
|
|
93
|
+
return checked;
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
/** Builds the Cal.com `ui` instruction from the options; throws on a non-hex colour or a non `cal-*` variable. */
|
|
97
|
+
export function buildCalUiConfig(options: BookingEmbedOptions): CalUiConfig {
|
|
98
|
+
return {
|
|
99
|
+
theme: options.theme ?? BookingTheme.Dark,
|
|
100
|
+
hideEventTypeDetails: options.hideEventTypeDetails ?? false,
|
|
101
|
+
layout: options.layout ?? CalLayout.Month,
|
|
102
|
+
cssVarsPerTheme: checkCssVarsPerTheme(options.cssVarsPerTheme),
|
|
103
|
+
};
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
/** Builds the ordered Cal.com calls (init, inline, ui) for one embed; throws on an unsafe link, origin or namespace. */
|
|
107
|
+
export function buildCalCommands(options: BookingEmbedOptions, elementOrSelector: string): CalCommand[] {
|
|
108
|
+
if (!CAL_LINK_PATTERN.test(options.calLink)) throw new Error(`BookingEmbed: "${options.calLink}" is not a Cal.com link`);
|
|
109
|
+
const ui = buildCalUiConfig(options);
|
|
110
|
+
return [
|
|
111
|
+
['init', checkNamespace(options.namespace ?? DEFAULT_CAL_NAMESPACE), { origin: resolveCalOrigin(options.origin) }],
|
|
112
|
+
[
|
|
113
|
+
'inline',
|
|
114
|
+
{ elementOrSelector, calLink: options.calLink, layout: ui.layout, config: { layout: ui.layout, theme: ui.theme } },
|
|
115
|
+
],
|
|
116
|
+
['ui', ui],
|
|
117
|
+
];
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
/** Checks the options and serialises them for the embed host's data attribute. */
|
|
121
|
+
export function serializeBookingOptions(options: BookingEmbedOptions): string {
|
|
122
|
+
buildCalCommands(options, '#check');
|
|
123
|
+
return JSON.stringify(options);
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
/** Parses the host's data attribute back into options; throws when it is not an options object. */
|
|
127
|
+
export function parseBookingOptions(raw: string): BookingEmbedOptions {
|
|
128
|
+
const parsed: unknown = JSON.parse(raw);
|
|
129
|
+
const hasLink = typeof parsed === 'object' && parsed !== null && typeof (parsed as BookingEmbedOptions).calLink === 'string';
|
|
130
|
+
if (!hasLink) throw new Error('BookingEmbed: options need a calLink');
|
|
131
|
+
return parsed as BookingEmbedOptions;
|
|
132
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
.tmk-sheet-head,.tmk-sheet-foot{display:none}
|
|
2
|
+
.tmk-sheet{display:contents}
|
|
3
|
+
|
|
4
|
+
@media (max-width:1023.98px){
|
|
5
|
+
.tmk-sheet{display:block;position:fixed;left:0;right:0;bottom:var(--dlz-consent-inset,0px);max-height:calc(80vh - var(--dlz-consent-inset,0px));overflow:auto;background:var(--tmk-sheet-bg,var(--paper,Canvas));border-top:2px solid var(--tmk-sheet-edge,var(--ink,CanvasText));border-radius:10px 10px 0 0;padding:12px 16px 0;transform:translateY(calc(105% + var(--dlz-consent-inset,0px)));visibility:hidden;z-index:30;transition:transform 240ms ease-out,visibility 0s linear 240ms}
|
|
6
|
+
.tmk-sheet:target{transform:none;visibility:visible;transition:transform 240ms ease-out,visibility 0s}
|
|
7
|
+
.tmk-sheet-head{display:flex;align-items:center;justify-content:space-between;gap:8px}
|
|
8
|
+
.tmk-sheet-title{font-size:17px;line-height:1.25;font-weight:700}
|
|
9
|
+
.tmk-sheet-close{min-width:44px;min-height:44px;display:inline-flex;align-items:center;justify-content:center;color:inherit}
|
|
10
|
+
.tmk-sheet-foot{display:block;position:sticky;bottom:0;background:var(--tmk-sheet-bg,var(--paper,Canvas));padding:12px 0 16px}
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
@media (prefers-reduced-motion:reduce){
|
|
14
|
+
.tmk-sheet,.tmk-sheet:target{transition:none}
|
|
15
|
+
}
|