@escape-game-over/atlas 0.1.104 → 0.1.106
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/package.json +2 -1
- package/src/astro/BookingWidget.astro +38 -0
- package/src/astro/FourEscape.astro +12 -4
- package/src/booking/four-escape.ts +23 -0
- package/src/booking/widget.ts +10 -1
- package/src/index.ts +8 -1
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@escape-game-over/atlas",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.106",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "Typed, data-driven machinery for static multi-locale, multi-deployment Astro sites.",
|
|
6
6
|
"private": false,
|
|
@@ -18,6 +18,7 @@
|
|
|
18
18
|
"./client": "./src/astro/client.ts",
|
|
19
19
|
"./astro/auto-dialog": "./src/astro/AutoDialog.astro",
|
|
20
20
|
"./astro/background-video": "./src/astro/BackgroundVideo.astro",
|
|
21
|
+
"./astro/booking-widget": "./src/astro/BookingWidget.astro",
|
|
21
22
|
"./astro/consent-banner": "./src/astro/ConsentBanner.astro",
|
|
22
23
|
"./astro/document": "./src/astro/Document.astro",
|
|
23
24
|
"./astro/element": "./src/astro/AtlasElement.astro",
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
---
|
|
2
|
+
/**
|
|
3
|
+
* A booking widget, whatever its vendor: the one place that picks the
|
|
4
|
+
* vendor's component, so a site passes what its config holds and nothing
|
|
5
|
+
* else. Attributes go to that component's element.
|
|
6
|
+
*
|
|
7
|
+
* `vars` are the widget's own vendor's CSS variables, typed by the widget it
|
|
8
|
+
* is given (`BookingWidgetVars`): 4escape's for a 4escape widget. A widget
|
|
9
|
+
* whose vendor is not known where it is passed accepts any vendor's.
|
|
10
|
+
*
|
|
11
|
+
* ```astro
|
|
12
|
+
* <BookingWidget widget={settings.booking} locale={locale} vars={{ "--f-top-offset": "5.5rem" }} />
|
|
13
|
+
* ```
|
|
14
|
+
*/
|
|
15
|
+
import type { HTMLAttributes } from "astro/types";
|
|
16
|
+
import type { BookingWidget, BookingWidgetVars } from "../booking/widget.ts";
|
|
17
|
+
import FourEscape from "./FourEscape.astro";
|
|
18
|
+
|
|
19
|
+
type Props<W extends BookingWidget = BookingWidget> = HTMLAttributes<"div"> & {
|
|
20
|
+
readonly widget: W;
|
|
21
|
+
/** The page's: the widget speaks it when its vendor has it. */
|
|
22
|
+
readonly locale: string;
|
|
23
|
+
/** The widget's vendor's CSS variables, set on its widgets. */
|
|
24
|
+
readonly vars?: BookingWidgetVars<W>;
|
|
25
|
+
};
|
|
26
|
+
|
|
27
|
+
const { widget, locale, vars, ...attrs } = Astro.props;
|
|
28
|
+
---
|
|
29
|
+
|
|
30
|
+
{widget.vendor === "4escape" && (
|
|
31
|
+
<FourEscape
|
|
32
|
+
{...attrs}
|
|
33
|
+
widgetId={widget.widgetId}
|
|
34
|
+
domain={widget.domain}
|
|
35
|
+
locale={locale}
|
|
36
|
+
vars={vars}
|
|
37
|
+
/>
|
|
38
|
+
)}
|
|
@@ -8,9 +8,10 @@
|
|
|
8
8
|
* the account's language as 4escape sets it. The cart is one per page: give
|
|
9
9
|
* the second catalog on a page `cart={false}`.
|
|
10
10
|
*
|
|
11
|
-
* The widgets draw themselves, in 4escape's style
|
|
12
|
-
*
|
|
13
|
-
*
|
|
11
|
+
* The widgets draw themselves, in 4escape's style; `vars` sets 4escape's own
|
|
12
|
+
* variables on them (see `FourEscapeVars`), such as `--f-top-offset` for a
|
|
13
|
+
* fixed header. Attributes go on the element around the catalog, which is the
|
|
14
|
+
* place to give it room; the cart follows it.
|
|
14
15
|
*
|
|
15
16
|
* ```astro
|
|
16
17
|
* <FourEscape widgetId={id} domain="acme.4escape.io" locale={locale} class="my-8" />
|
|
@@ -21,23 +22,28 @@ import {
|
|
|
21
22
|
checkFourEscape,
|
|
22
23
|
FOUR_ESCAPE_SCRIPT,
|
|
23
24
|
FOUR_ESCAPE_STYLESHEET,
|
|
25
|
+
type FourEscapeVars,
|
|
24
26
|
type FourEscapeWidget,
|
|
25
27
|
fourEscapeLanguage,
|
|
26
28
|
fourEscapeSettings,
|
|
29
|
+
fourEscapeStyle,
|
|
27
30
|
} from "../booking/four-escape.ts";
|
|
28
31
|
|
|
29
32
|
type Props = HTMLAttributes<"div"> &
|
|
30
33
|
FourEscapeWidget & {
|
|
31
34
|
readonly locale: string;
|
|
32
35
|
readonly cart?: boolean;
|
|
36
|
+
/** 4escape's variables, set on both widgets. */
|
|
37
|
+
readonly vars?: FourEscapeVars;
|
|
33
38
|
};
|
|
34
39
|
|
|
35
|
-
const { widgetId, domain, locale, cart = true, ...attrs } = Astro.props;
|
|
40
|
+
const { widgetId, domain, vars, locale, cart = true, ...attrs } = Astro.props;
|
|
36
41
|
|
|
37
42
|
checkFourEscape({ widgetId, domain }, Astro.url.pathname);
|
|
38
43
|
|
|
39
44
|
const settings = fourEscapeSettings(domain);
|
|
40
45
|
const language = fourEscapeLanguage(locale);
|
|
46
|
+
const style = fourEscapeStyle(vars);
|
|
41
47
|
---
|
|
42
48
|
|
|
43
49
|
<link
|
|
@@ -51,6 +57,7 @@ const language = fourEscapeLanguage(locale);
|
|
|
51
57
|
data-widget-id={widgetId}
|
|
52
58
|
data-settings={settings}
|
|
53
59
|
data-language={language}
|
|
60
|
+
style={style}
|
|
54
61
|
></div>
|
|
55
62
|
</div>
|
|
56
63
|
{cart && (
|
|
@@ -58,6 +65,7 @@ const language = fourEscapeLanguage(locale);
|
|
|
58
65
|
class='forescape-cart'
|
|
59
66
|
data-settings={settings}
|
|
60
67
|
data-language={language}
|
|
68
|
+
style={style}
|
|
61
69
|
/>
|
|
62
70
|
)}
|
|
63
71
|
<script
|
|
@@ -25,6 +25,17 @@ export interface FourEscapeWidget {
|
|
|
25
25
|
readonly domain: string;
|
|
26
26
|
}
|
|
27
27
|
|
|
28
|
+
/**
|
|
29
|
+
* 4escape's own CSS variables, by name, as a page sets them on the widgets.
|
|
30
|
+
* Free, beyond the `--f-` prefix: 4escape documents none, and its stylesheet
|
|
31
|
+
* (`.forescape`) declares some 670. The ones that matter most:
|
|
32
|
+
*
|
|
33
|
+
* - `--f-top-offset`: the space a fixed header takes. The cart button's
|
|
34
|
+
* offset (`--f-cart-top-offset`) and the widgets' scroll margins follow it.
|
|
35
|
+
* - `--f-primary`, `--f-primary-hover`: buttons and highlights.
|
|
36
|
+
*/
|
|
37
|
+
export type FourEscapeVars = Readonly<Partial<Record<`--f-${string}`, string>>>;
|
|
38
|
+
|
|
28
39
|
/** The languages the widgets are translated into, as `data-language` takes them. */
|
|
29
40
|
export const FOUR_ESCAPE_LANGUAGES = [
|
|
30
41
|
"fr",
|
|
@@ -64,6 +75,18 @@ export function checkFourEscape(widget: FourEscapeWidget, at: string): void {
|
|
|
64
75
|
}
|
|
65
76
|
}
|
|
66
77
|
|
|
78
|
+
/**
|
|
79
|
+
* The widgets' elements' inline style, from a page's `vars`. Inline because
|
|
80
|
+
* 4escape declares its variables on those same elements, in an unlayered
|
|
81
|
+
* stylesheet: a site's own CSS loses to it, and inline does not.
|
|
82
|
+
*/
|
|
83
|
+
export function fourEscapeStyle(vars: FourEscapeVars = {}): string | undefined {
|
|
84
|
+
const declarations = Object.entries(vars).map(
|
|
85
|
+
([name, value]) => `${name}: ${value}`
|
|
86
|
+
);
|
|
87
|
+
return declarations.length > 0 ? declarations.join("; ") : undefined;
|
|
88
|
+
}
|
|
89
|
+
|
|
67
90
|
/** `data-settings` for an account: `b64.` and the settings as base64 JSON. */
|
|
68
91
|
export function fourEscapeSettings(domain: string): string {
|
|
69
92
|
return `b64.${btoa(JSON.stringify({ domain }))}`;
|
package/src/booking/widget.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { FourEscapeWidget } from "./four-escape.ts";
|
|
1
|
+
import type { FourEscapeVars, FourEscapeWidget } from "./four-escape.ts";
|
|
2
2
|
|
|
3
3
|
/**
|
|
4
4
|
* A booking widget a site embeds, by its vendor: what a site's config names,
|
|
@@ -8,3 +8,12 @@ export type BookingWidget = { readonly vendor: "4escape" } & FourEscapeWidget;
|
|
|
8
8
|
|
|
9
9
|
/** Who makes a booking widget: what `storedItems` takes for their rows. */
|
|
10
10
|
export type BookingVendor = BookingWidget["vendor"];
|
|
11
|
+
|
|
12
|
+
/** Each vendor's CSS variables, as a page sets them on its widgets. */
|
|
13
|
+
export interface BookingVendorVars {
|
|
14
|
+
readonly "4escape": FourEscapeVars;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
/** The CSS variables a widget takes: its own vendor's, and no other's. */
|
|
18
|
+
export type BookingWidgetVars<W extends BookingWidget> =
|
|
19
|
+
BookingVendorVars[W["vendor"]];
|
package/src/index.ts
CHANGED
|
@@ -61,11 +61,18 @@ export {
|
|
|
61
61
|
FOUR_ESCAPE_SCRIPT,
|
|
62
62
|
FOUR_ESCAPE_STYLESHEET,
|
|
63
63
|
type FourEscapeLanguage,
|
|
64
|
+
type FourEscapeVars,
|
|
64
65
|
type FourEscapeWidget,
|
|
65
66
|
fourEscapeLanguage,
|
|
66
67
|
fourEscapeSettings,
|
|
68
|
+
fourEscapeStyle,
|
|
67
69
|
} from "./booking/four-escape.ts";
|
|
68
|
-
export type {
|
|
70
|
+
export type {
|
|
71
|
+
BookingVendor,
|
|
72
|
+
BookingVendorVars,
|
|
73
|
+
BookingWidget,
|
|
74
|
+
BookingWidgetVars,
|
|
75
|
+
} from "./booking/widget.ts";
|
|
69
76
|
export type {
|
|
70
77
|
LanguageTag,
|
|
71
78
|
LocaleMeta,
|