@brimsites/brimjs 0.0.0-stage → 1.0.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/LICENSE +110 -0
- package/README.md +22 -2
- package/bin/brim.js +5 -0
- package/dist/cli.js +3802 -0
- package/editor-dist/editor.css +1 -0
- package/editor-dist/editor.js +91 -0
- package/package.json +71 -3
- package/skills/brim-convert/SKILL.md +256 -0
- package/skills/brim-hosting/SKILL.md +221 -0
- package/src/astro-shim.d.ts +5 -0
- package/src/auth/accounts.ts +341 -0
- package/src/auth/password.ts +34 -0
- package/src/auth/permissions.ts +44 -0
- package/src/blocks/accordion/Accordion.astro +48 -0
- package/src/blocks/accordion/accordion.css +63 -0
- package/src/blocks/analytics/Analytics.astro +45 -0
- package/src/blocks/analytics/ConsentBanner.astro +41 -0
- package/src/blocks/analytics/analytics.client.ts +125 -0
- package/src/blocks/analytics/analytics.css +51 -0
- package/src/blocks/analytics/consent.ts +51 -0
- package/src/blocks/button/Button.astro +64 -0
- package/src/blocks/button/button.css +100 -0
- package/src/blocks/carousel/Carousel.astro +140 -0
- package/src/blocks/carousel/carousel.client.ts +153 -0
- package/src/blocks/carousel/carousel.css +181 -0
- package/src/blocks/data/icons.ts +285 -0
- package/src/blocks/data/image-shapes.ts +91 -0
- package/src/blocks/data/social-icons.ts +41 -0
- package/src/blocks/data/social-networks.ts +256 -0
- package/src/blocks/divider/Divider.astro +27 -0
- package/src/blocks/divider/divider.css +17 -0
- package/src/blocks/form/Captcha.astro +27 -0
- package/src/blocks/form/Form.astro +250 -0
- package/src/blocks/form/FormField.astro +138 -0
- package/src/blocks/form/Newsletter.astro +80 -0
- package/src/blocks/form/form.client.ts +339 -0
- package/src/blocks/form/form.css +271 -0
- package/src/blocks/gallery/ImageGallery.astro +126 -0
- package/src/blocks/gallery/gallery.css +43 -0
- package/src/blocks/gallery/lightbox.client.ts +178 -0
- package/src/blocks/gallery/lightbox.css +134 -0
- package/src/blocks/icon/Icon.astro +41 -0
- package/src/blocks/icon/icon.css +16 -0
- package/src/blocks/image/Image.astro +158 -0
- package/src/blocks/image/image.css +42 -0
- package/src/blocks/images.ts +64 -0
- package/src/blocks/in-editor.client.ts +8 -0
- package/src/blocks/listing/Listing.astro +288 -0
- package/src/blocks/listing/ListingCards.astro +48 -0
- package/src/blocks/listing/listing.css +136 -0
- package/src/blocks/listing/query.ts +363 -0
- package/src/blocks/map/Map.astro +75 -0
- package/src/blocks/map/map.css +32 -0
- package/src/blocks/schemas/accordion.ts +118 -0
- package/src/blocks/schemas/button.ts +78 -0
- package/src/blocks/schemas/carousel.ts +133 -0
- package/src/blocks/schemas/divider.ts +29 -0
- package/src/blocks/schemas/form-field-types.ts +29 -0
- package/src/blocks/schemas/form.ts +350 -0
- package/src/blocks/schemas/icon.ts +24 -0
- package/src/blocks/schemas/image-gallery.ts +54 -0
- package/src/blocks/schemas/image.ts +87 -0
- package/src/blocks/schemas/index.ts +33 -0
- package/src/blocks/schemas/listing.ts +14 -0
- package/src/blocks/schemas/map.ts +81 -0
- package/src/blocks/schemas/newsletter.ts +324 -0
- package/src/blocks/schemas/social-media.ts +348 -0
- package/src/blocks/schemas/text.ts +151 -0
- package/src/blocks/schemas/video.ts +57 -0
- package/src/blocks/search/Search.astro +147 -0
- package/src/blocks/search/search.css +69 -0
- package/src/blocks/search/state.ts +28 -0
- package/src/blocks/settings.ts +94 -0
- package/src/blocks/social/SocialMedia.astro +102 -0
- package/src/blocks/social/social-links.ts +16 -0
- package/src/blocks/social/social.css +31 -0
- package/src/blocks/theme.ts +35 -0
- package/src/blocks/types.ts +52 -0
- package/src/blocks/video/Video.astro +90 -0
- package/src/blocks/video/video-source.ts +77 -0
- package/src/blocks/video/video.client.ts +43 -0
- package/src/blocks/video/video.css +29 -0
- package/src/check.ts +1119 -0
- package/src/cli.ts +493 -0
- package/src/components/Blocks.astro +68 -0
- package/src/components/Field.astro +61 -0
- package/src/components/Footer.astro +36 -0
- package/src/components/Link.astro +18 -0
- package/src/components/MobileMenu.astro +77 -0
- package/src/components/Navbar.astro +42 -0
- package/src/components/RichText.astro +32 -0
- package/src/components/Seo.astro +202 -0
- package/src/components/Setting.astro +46 -0
- package/src/components/Shared.astro +17 -0
- package/src/components/Text.astro +91 -0
- package/src/components/blocks.css +86 -0
- package/src/components/index.ts +27 -0
- package/src/components/mobile-menu.client.ts +21 -0
- package/src/components/mobile-menu.css +52 -0
- package/src/components/text.css +48 -0
- package/src/config.ts +413 -0
- package/src/content/block-layout.ts +63 -0
- package/src/content/block-values.ts +48 -0
- package/src/content/content-check.ts +174 -0
- package/src/content/content-types.ts +408 -0
- package/src/content/drafts.ts +115 -0
- package/src/content/feed.ts +237 -0
- package/src/content/field-types.ts +107 -0
- package/src/content/history.ts +140 -0
- package/src/content/ids.ts +50 -0
- package/src/content/image-size.ts +212 -0
- package/src/content/image-sizes.ts +126 -0
- package/src/content/item-fields.ts +110 -0
- package/src/content/item-head.ts +126 -0
- package/src/content/item-image.ts +26 -0
- package/src/content/item-path.ts +122 -0
- package/src/content/items.ts +580 -0
- package/src/content/language-scopes.ts +40 -0
- package/src/content/media.ts +271 -0
- package/src/content/menus.ts +51 -0
- package/src/content/page-templates.ts +52 -0
- package/src/content/redirects.ts +112 -0
- package/src/content/references.ts +165 -0
- package/src/content/rich-text.ts +63 -0
- package/src/content/search.ts +167 -0
- package/src/content/seed.ts +229 -0
- package/src/content/site-settings.ts +111 -0
- package/src/content/sitemap.ts +143 -0
- package/src/content/store.ts +225 -0
- package/src/content/tags.ts +67 -0
- package/src/content/text-default.ts +139 -0
- package/src/content/types.ts +137 -0
- package/src/content/validate.ts +253 -0
- package/src/content/validation-error.ts +2 -0
- package/src/db/cached.ts +140 -0
- package/src/db/database.ts +15 -0
- package/src/db/libsql.ts +29 -0
- package/src/db/schema.ts +189 -0
- package/src/db/url.ts +44 -0
- package/src/editor/client/BlockSettings.tsx +1063 -0
- package/src/editor/client/Chrome.tsx +284 -0
- package/src/editor/client/ContentBrowser.tsx +1299 -0
- package/src/editor/client/Editor.tsx +1756 -0
- package/src/editor/client/HistoryPanel.tsx +114 -0
- package/src/editor/client/ImagesWidget.tsx +113 -0
- package/src/editor/client/Inspector.tsx +127 -0
- package/src/editor/client/ItemForm.tsx +535 -0
- package/src/editor/client/LinkWidget.tsx +440 -0
- package/src/editor/client/ListingPanel.tsx +99 -0
- package/src/editor/client/Login.tsx +338 -0
- package/src/editor/client/Menu.tsx +64 -0
- package/src/editor/client/PageSettings.tsx +270 -0
- package/src/editor/client/RedirectsSettings.tsx +130 -0
- package/src/editor/client/Resize.tsx +204 -0
- package/src/editor/client/Sidebar.tsx +51 -0
- package/src/editor/client/SiteMap.tsx +568 -0
- package/src/editor/client/SiteSettings.tsx +409 -0
- package/src/editor/client/TextTools.tsx +391 -0
- package/src/editor/client/Toolbar.tsx +449 -0
- package/src/editor/client/VideoUpload.tsx +251 -0
- package/src/editor/client/api.ts +417 -0
- package/src/editor/client/brand.ts +20 -0
- package/src/editor/client/connection.ts +98 -0
- package/src/editor/client/context.ts +19 -0
- package/src/editor/client/css.d.ts +2 -0
- package/src/editor/client/editor.css +4656 -0
- package/src/editor/client/fields.tsx +812 -0
- package/src/editor/client/icons.tsx +174 -0
- package/src/editor/client/keys.ts +15 -0
- package/src/editor/client/kinds.ts +289 -0
- package/src/editor/client/languages.ts +32 -0
- package/src/editor/client/main.tsx +100 -0
- package/src/editor/client/responses.ts +26 -0
- package/src/editor/client/rich-text.ts +326 -0
- package/src/editor/client/site-tree.ts +239 -0
- package/src/editor/client/theme.ts +55 -0
- package/src/editor/client/tsconfig.json +18 -0
- package/src/editor/client/tus.ts +137 -0
- package/src/editor/client/use-rect.ts +50 -0
- package/src/editor/client/widgets.tsx +1218 -0
- package/src/forms/captcha.ts +83 -0
- package/src/forms/define.ts +166 -0
- package/src/forms/fields.ts +197 -0
- package/src/forms/file-types.ts +108 -0
- package/src/forms/files.ts +216 -0
- package/src/forms/form-page.ts +9 -0
- package/src/forms/handler.ts +622 -0
- package/src/forms/spec.ts +89 -0
- package/src/forms/store.ts +96 -0
- package/src/forms/work.ts +50 -0
- package/src/icons/library.ts +144 -0
- package/src/icons/load.ts +63 -0
- package/src/index.ts +99 -0
- package/src/init.ts +257 -0
- package/src/integration.ts +469 -0
- package/src/mail/mailer.ts +197 -0
- package/src/mail/notify.ts +272 -0
- package/src/mail/settings.ts +173 -0
- package/src/mail/templates.ts +191 -0
- package/src/mcp/page-nodes.ts +209 -0
- package/src/mcp/server.ts +111 -0
- package/src/mcp/tools.ts +637 -0
- package/src/runtime/TemplatePage.astro +39 -0
- package/src/runtime/TemplatePageStatic.astro +13 -0
- package/src/runtime/admin-route.ts +80 -0
- package/src/runtime/connect.ts +53 -0
- package/src/runtime/content.ts +188 -0
- package/src/runtime/context.ts +131 -0
- package/src/runtime/form-files.ts +18 -0
- package/src/runtime/forms-route.ts +33 -0
- package/src/runtime/forms.ts +28 -0
- package/src/runtime/icons.ts +5 -0
- package/src/runtime/media.ts +175 -0
- package/src/runtime/middleware.ts +186 -0
- package/src/runtime/nav.ts +13 -0
- package/src/runtime/query-reads.ts +49 -0
- package/src/runtime/query-store.ts +16 -0
- package/src/runtime/request-state.ts +69 -0
- package/src/runtime/robots.ts +29 -0
- package/src/runtime/rss-static.ts +16 -0
- package/src/runtime/rss.ts +29 -0
- package/src/runtime/server.ts +29 -0
- package/src/runtime/sitemap.ts +34 -0
- package/src/runtime/template-paths.ts +34 -0
- package/src/runtime/uploads-route.ts +13 -0
- package/src/seed-cli.ts +253 -0
- package/src/server/auth.ts +31 -0
- package/src/server/fetch-image.ts +219 -0
- package/src/server/handler.ts +2106 -0
- package/src/server/http.ts +162 -0
- package/src/server/locales.ts +73 -0
- package/src/server/node.ts +57 -0
- package/src/server/query-params.ts +249 -0
- package/src/server/rate-limit.ts +72 -0
- package/src/server/video-host.ts +162 -0
- package/src/starter.ts +70 -0
- package/src/version.ts +4 -0
- package/src/virtual.d.ts +65 -0
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
/* The search of the whole site. Layout and plain text; the look belongs to the site. */
|
|
2
|
+
/* In the `brim` layer: any CSS of the site wins over it, whatever its selectors. */
|
|
3
|
+
@layer brim {
|
|
4
|
+
.brim-search__box {
|
|
5
|
+
display: flex;
|
|
6
|
+
flex-wrap: wrap;
|
|
7
|
+
align-items: flex-end;
|
|
8
|
+
gap: 0.5rem;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
.brim-search__label {
|
|
12
|
+
display: flex;
|
|
13
|
+
flex: 1 1 16rem;
|
|
14
|
+
flex-direction: column;
|
|
15
|
+
gap: 0.375rem;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
.brim-search__label input {
|
|
19
|
+
width: 100%;
|
|
20
|
+
padding: 0.65rem 0.75rem;
|
|
21
|
+
border: 1px solid var(--brim-theme-light2, #e4e4e7);
|
|
22
|
+
border-radius: var(--brim-theme-radius, 0.5rem);
|
|
23
|
+
background: var(--brim-theme-background, #ffffff);
|
|
24
|
+
color: inherit;
|
|
25
|
+
font: inherit;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
.brim-search__count {
|
|
29
|
+
margin: 1.5rem 0 0;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
.brim-search__results {
|
|
33
|
+
display: flex;
|
|
34
|
+
flex-direction: column;
|
|
35
|
+
gap: 1.5rem;
|
|
36
|
+
margin: 1.5rem 0 0;
|
|
37
|
+
padding: 0;
|
|
38
|
+
list-style: none;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
.brim-search__result {
|
|
42
|
+
display: flex;
|
|
43
|
+
flex-direction: column;
|
|
44
|
+
gap: 0.25rem;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
.brim-search__type {
|
|
48
|
+
font-size: 0.8em;
|
|
49
|
+
letter-spacing: 0.04em;
|
|
50
|
+
text-transform: uppercase;
|
|
51
|
+
opacity: 0.65;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
.brim-search__title {
|
|
55
|
+
font-size: 1.15em;
|
|
56
|
+
font-weight: 600;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
.brim-search__excerpt {
|
|
60
|
+
margin: 0;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
.brim-search__pages {
|
|
64
|
+
display: flex;
|
|
65
|
+
flex-wrap: wrap;
|
|
66
|
+
gap: 0.75rem;
|
|
67
|
+
margin-top: 2rem;
|
|
68
|
+
}
|
|
69
|
+
}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import type { ContentItem } from "../../runtime/content.ts";
|
|
2
|
+
|
|
3
|
+
/** One item a site search found, as its markup draws it. */
|
|
4
|
+
export interface SearchResult {
|
|
5
|
+
item: ContentItem;
|
|
6
|
+
/** Key of the item's content type, and the name of one of its items (`Article`). */
|
|
7
|
+
type: string;
|
|
8
|
+
typeLabel: string;
|
|
9
|
+
title: string;
|
|
10
|
+
/** The address of the item's page. */
|
|
11
|
+
url: string;
|
|
12
|
+
/** The sentence the words were found in, as plain text. */
|
|
13
|
+
excerpt: string;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
/** What a `<Search>` function child gets: the words, one page of results and the way to the others. */
|
|
17
|
+
export interface SearchState {
|
|
18
|
+
/** The words searched for, as typed; "" before anything is asked. */
|
|
19
|
+
query: string;
|
|
20
|
+
/** The address parameter of the words, the `name` of the site's own search box. */
|
|
21
|
+
param: string;
|
|
22
|
+
results: SearchResult[];
|
|
23
|
+
/** How many items were found, over every page. */
|
|
24
|
+
total: number;
|
|
25
|
+
page: number;
|
|
26
|
+
pageCount: number;
|
|
27
|
+
pageHref: (page: number) => string;
|
|
28
|
+
}
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
import { ValidationError } from "../content/validation-error.ts";
|
|
2
|
+
import type { BlockDefinition, SchemaProperty } from "./types.ts";
|
|
3
|
+
|
|
4
|
+
const MAX_STRING = 20_000;
|
|
5
|
+
const MAX_JSON_NODES = 5_000;
|
|
6
|
+
const MAX_JSON_DEPTH = 10;
|
|
7
|
+
const LINK_SCHEMES = ["http:", "https:", "mailto:", "tel:"];
|
|
8
|
+
|
|
9
|
+
/** The settings a block renders with: its defaults, then what the page's code passes, then what the owner saved. */
|
|
10
|
+
export function resolveSettings(
|
|
11
|
+
definition: BlockDefinition,
|
|
12
|
+
source: Record<string, unknown>,
|
|
13
|
+
stored: Record<string, unknown> | undefined,
|
|
14
|
+
): Record<string, unknown> {
|
|
15
|
+
const fromSource = Object.fromEntries(Object.entries(source).filter(([, value]) => value !== undefined));
|
|
16
|
+
return { ...definition.defaults, ...fromSource, ...stored };
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* Turns untrusted input into block settings. Only settings the block declares are kept,
|
|
21
|
+
* each checked against its declared type. Throws `ValidationError`.
|
|
22
|
+
*/
|
|
23
|
+
export function parseSettings(definition: BlockDefinition, input: unknown): Record<string, unknown> {
|
|
24
|
+
if (typeof input !== "object" || input === null || Array.isArray(input)) {
|
|
25
|
+
throw new ValidationError('"value" must be an object.');
|
|
26
|
+
}
|
|
27
|
+
const budget = { nodes: MAX_JSON_NODES };
|
|
28
|
+
const settings: Record<string, unknown> = {};
|
|
29
|
+
|
|
30
|
+
for (const [name, value] of Object.entries(input)) {
|
|
31
|
+
const property = definition.schema.properties[name];
|
|
32
|
+
if (property) settings[name] = checkProperty(name, property, value, budget);
|
|
33
|
+
// Companion values a widget keeps next to its property, such as a link's "open in new tab".
|
|
34
|
+
else if (Object.hasOwn(definition.defaults, name)) settings[name] = plainJson(name, value, 0, budget);
|
|
35
|
+
}
|
|
36
|
+
return settings;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
function checkProperty(name: string, property: SchemaProperty, value: unknown, budget: { nodes: number }): unknown {
|
|
40
|
+
if (property.type === "boolean") {
|
|
41
|
+
if (typeof value !== "boolean") throw new ValidationError(`"${name}" must be true or false.`);
|
|
42
|
+
return value;
|
|
43
|
+
}
|
|
44
|
+
if (property.type === "number" || property.type === "integer") {
|
|
45
|
+
if (typeof value !== "number" || !Number.isFinite(value)) throw new ValidationError(`"${name}" must be a number.`);
|
|
46
|
+
const minimum = property.min ?? property.minimum;
|
|
47
|
+
const maximum = property.max ?? property.maximum;
|
|
48
|
+
if (minimum !== undefined && value < minimum) throw new ValidationError(`"${name}" is too small.`);
|
|
49
|
+
if (maximum !== undefined && value > maximum) throw new ValidationError(`"${name}" is too large.`);
|
|
50
|
+
return value;
|
|
51
|
+
}
|
|
52
|
+
if (property.type === "string") {
|
|
53
|
+
if (typeof value !== "string") throw new ValidationError(`"${name}" must be text.`);
|
|
54
|
+
if (value.length > MAX_STRING) throw new ValidationError(`"${name}" is too long.`);
|
|
55
|
+
if (property.widget === "url") return linkAddress(name, value);
|
|
56
|
+
return property.widget === "image" ? imageAddress(name, value) : value;
|
|
57
|
+
}
|
|
58
|
+
return plainJson(name, value, 0, budget);
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
/** Empty, a site path, an in-page anchor or a normal link. Rejects `javascript:` and the like. */
|
|
62
|
+
function linkAddress(name: string, value: string): string {
|
|
63
|
+
const address = value.trim();
|
|
64
|
+
if (address === "" || address.startsWith("#") || (address.startsWith("/") && !address.startsWith("//")))
|
|
65
|
+
return address;
|
|
66
|
+
const scheme = URL.canParse(address) ? new URL(address).protocol : "";
|
|
67
|
+
if (!LINK_SCHEMES.includes(scheme)) throw new ValidationError(`"${name}" is not an allowed address.`);
|
|
68
|
+
return address;
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
/** Empty, a path on the site, or a web address. */
|
|
72
|
+
function imageAddress(name: string, value: string): string {
|
|
73
|
+
const address = value.trim();
|
|
74
|
+
if (address === "" || (address.startsWith("/") && !address.startsWith("//"))) return address;
|
|
75
|
+
const scheme = URL.canParse(address) ? new URL(address).protocol : "";
|
|
76
|
+
if (scheme !== "http:" && scheme !== "https:")
|
|
77
|
+
throw new ValidationError(`"${name}" is not an allowed image address.`);
|
|
78
|
+
return address;
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
/** Accepts nested lists and objects of plain values, within a size budget. */
|
|
82
|
+
function plainJson(name: string, value: unknown, depth: number, budget: { nodes: number }): unknown {
|
|
83
|
+
if (--budget.nodes < 0 || depth > MAX_JSON_DEPTH) throw new ValidationError(`"${name}" is too large.`);
|
|
84
|
+
if (value === null || typeof value === "boolean") return value;
|
|
85
|
+
if (typeof value === "number" && Number.isFinite(value)) return value;
|
|
86
|
+
if (typeof value === "string" && value.length <= MAX_STRING) return value;
|
|
87
|
+
if (Array.isArray(value)) return value.map((entry) => plainJson(name, entry, depth + 1, budget));
|
|
88
|
+
if (typeof value === "object") {
|
|
89
|
+
return Object.fromEntries(
|
|
90
|
+
Object.entries(value).map(([key, entry]) => [key, plainJson(name, entry, depth + 1, budget)]),
|
|
91
|
+
);
|
|
92
|
+
}
|
|
93
|
+
throw new ValidationError(`"${name}" has a value that cannot be saved.`);
|
|
94
|
+
}
|
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
---
|
|
2
|
+
import "./social.css";
|
|
3
|
+
import type { NodeScope } from "../../runtime/context.ts";
|
|
4
|
+
import { SOCIAL_ICONS } from "../data/social-icons.ts";
|
|
5
|
+
import { SOCIAL_NETWORKS, normalizeSocialNetworkProfileUrl, orderSocialNetworks } from "../data/social-networks.ts";
|
|
6
|
+
import { socialMedia } from "../schemas/social-media.ts";
|
|
7
|
+
import type { SocialLink, SocialMediaValue } from "./social-links.ts";
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* Icons that share the current page (`mode="share"`) or link to the site's own profiles (`mode="profile"`). The
|
|
11
|
+
* owner turns networks on and off, orders them and types the profile links; their look is the site's. Start the
|
|
12
|
+
* profiles with `profiles={{ instagram: "https://instagram.com/acme", email: "hello@acme.ro" }}`, and draw them
|
|
13
|
+
* with a function if Brim's plain row of icons does not suit:
|
|
14
|
+
*
|
|
15
|
+
* <SocialMedia nodeId="footer-social" mode="profile" profiles={profiles}>
|
|
16
|
+
* {({ links }) => links.map((link) => <a href={link.href} aria-label={link.label}>{link.label}</a>)}
|
|
17
|
+
* </SocialMedia>
|
|
18
|
+
*/
|
|
19
|
+
interface Props {
|
|
20
|
+
nodeId: string;
|
|
21
|
+
scope?: NodeScope;
|
|
22
|
+
mode?: "share" | "profile";
|
|
23
|
+
shareText?: string;
|
|
24
|
+
openInNewTab?: boolean;
|
|
25
|
+
/** Starting profile links by network, in the order they are shown. */
|
|
26
|
+
profiles?: Partial<Record<string, string>>;
|
|
27
|
+
[setting: string]: unknown;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
const { nodeId, scope = "site", profiles, ...source } = Astro.props;
|
|
31
|
+
/** An email address or phone number given as it is written becomes a `mailto:` or `tel:` link. */
|
|
32
|
+
const plainAddress = (network: string, value: string): string =>
|
|
33
|
+
network === "email" && !value.includes(":")
|
|
34
|
+
? `mailto:${value}`
|
|
35
|
+
: network === "phone" && !value.includes(":")
|
|
36
|
+
? `tel:${value.replace(/\s+/g, "")}`
|
|
37
|
+
: value;
|
|
38
|
+
// The profiles given in code start as networks turned on, first and in their order; the others stay as they were.
|
|
39
|
+
const starting = profiles
|
|
40
|
+
? {
|
|
41
|
+
networkOrder: [...Object.keys(profiles), ...SOCIAL_NETWORKS.map((network) => network.key)].filter(
|
|
42
|
+
(key, index, keys) => keys.indexOf(key) === index,
|
|
43
|
+
),
|
|
44
|
+
...Object.fromEntries(
|
|
45
|
+
Object.entries(profiles).flatMap(([key, url]) => [
|
|
46
|
+
[`${key}Url`, plainAddress(key, url ?? "")],
|
|
47
|
+
[`${key}Enabled`, true],
|
|
48
|
+
]),
|
|
49
|
+
),
|
|
50
|
+
}
|
|
51
|
+
: {};
|
|
52
|
+
const settings = Astro.locals.brim.settings(socialMedia, nodeId, scope, { ...starting, ...source });
|
|
53
|
+
|
|
54
|
+
// Sharing needs the page's public address, which only exists once `site` is set in the Astro config.
|
|
55
|
+
const pageUrl = Astro.site ? new URL(Astro.url.pathname, Astro.site).href : Astro.url.href;
|
|
56
|
+
const shareText = String(settings.shareText ?? "");
|
|
57
|
+
const sharing = settings.mode !== "profile";
|
|
58
|
+
const newTab = sharing || settings.openInNewTab !== false;
|
|
59
|
+
|
|
60
|
+
const links: SocialLink[] = orderSocialNetworks(SOCIAL_NETWORKS, settings.networkOrder)
|
|
61
|
+
.filter((network) => settings[`${network.key}Enabled`] !== false)
|
|
62
|
+
.flatMap((network) => {
|
|
63
|
+
const href = sharing
|
|
64
|
+
? network.share?.({ url: pageUrl, title: shareText, text: shareText })
|
|
65
|
+
: normalizeSocialNetworkProfileUrl(network.key, settings[network.profileField]);
|
|
66
|
+
if (!href) return [];
|
|
67
|
+
return [
|
|
68
|
+
{
|
|
69
|
+
network: network.key,
|
|
70
|
+
label: sharing ? `Share on ${network.label}` : network.label,
|
|
71
|
+
href,
|
|
72
|
+
icon: SOCIAL_ICONS[network.icon],
|
|
73
|
+
newTab: newTab && !/^(mailto|tel):/i.test(href),
|
|
74
|
+
},
|
|
75
|
+
];
|
|
76
|
+
});
|
|
77
|
+
const drawn = Astro.slots.has("default");
|
|
78
|
+
const content = drawn ? await Astro.slots.render("default", [{ links } satisfies SocialMediaValue]) : undefined;
|
|
79
|
+
const Tag = drawn ? "div" : "ul";
|
|
80
|
+
---
|
|
81
|
+
|
|
82
|
+
<Tag class={drawn ? undefined : "brim-social"} {...Astro.locals.brim.marker("social-media", nodeId, scope, settings)}>
|
|
83
|
+
{drawn ? (
|
|
84
|
+
<Fragment set:html={content} />
|
|
85
|
+
) : (
|
|
86
|
+
links.map((link) => (
|
|
87
|
+
<li>
|
|
88
|
+
<a
|
|
89
|
+
href={link.href}
|
|
90
|
+
target={link.newTab ? "_blank" : undefined}
|
|
91
|
+
rel={link.newTab ? "noopener noreferrer" : undefined}
|
|
92
|
+
aria-label={link.label}
|
|
93
|
+
>
|
|
94
|
+
<svg viewBox="0 0 24 24" fill="currentColor" aria-hidden="true" set:html={link.icon} />
|
|
95
|
+
</a>
|
|
96
|
+
</li>
|
|
97
|
+
))
|
|
98
|
+
)}
|
|
99
|
+
{links.length === 0 && Astro.locals.brim.editing && (
|
|
100
|
+
<span>No networks to show yet. Select this block to add them.</span>
|
|
101
|
+
)}
|
|
102
|
+
</Tag>
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/** One icon of a `SocialMedia`, as its function gets it. */
|
|
2
|
+
export interface SocialLink {
|
|
3
|
+
/** `instagram`, `facebook`, `email`… */
|
|
4
|
+
network: string;
|
|
5
|
+
/** What it is called: `Instagram`, or "Share on Facebook" for a share link. */
|
|
6
|
+
label: string;
|
|
7
|
+
href: string;
|
|
8
|
+
/** The icon's drawing, for `<svg viewBox="0 0 24 24" fill="currentColor" set:html={link.icon} />`. */
|
|
9
|
+
icon: string;
|
|
10
|
+
/** Whether it opens in a new tab: profiles unless turned off, share links always. */
|
|
11
|
+
newTab: boolean;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
export interface SocialMediaValue {
|
|
15
|
+
links: SocialLink[];
|
|
16
|
+
}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
/* The row of icons Brim draws when the site draws none: they take the text colour around them. */
|
|
2
|
+
/* In the `brim` layer: any CSS of the site wins over it, whatever its selectors. */
|
|
3
|
+
@layer brim {
|
|
4
|
+
.brim-social {
|
|
5
|
+
display: flex;
|
|
6
|
+
flex-wrap: wrap;
|
|
7
|
+
gap: 0.5rem;
|
|
8
|
+
margin: 0;
|
|
9
|
+
padding: 0;
|
|
10
|
+
list-style: none;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
.brim-social a {
|
|
14
|
+
display: inline-flex;
|
|
15
|
+
align-items: center;
|
|
16
|
+
justify-content: center;
|
|
17
|
+
width: 2.5rem;
|
|
18
|
+
height: 2.5rem;
|
|
19
|
+
color: inherit;
|
|
20
|
+
transition: opacity 0.15s;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
.brim-social a:hover {
|
|
24
|
+
opacity: 0.75;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
.brim-social svg {
|
|
28
|
+
width: 1.25rem;
|
|
29
|
+
height: 1.25rem;
|
|
30
|
+
}
|
|
31
|
+
}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Named colors BrimCMS offered in color settings. A site sets them as `--brim-theme-<name>`;
|
|
3
|
+
* the values here are what shows until it does.
|
|
4
|
+
*/
|
|
5
|
+
export const THEME_COLOR_DEFAULTS: Record<string, string> = {
|
|
6
|
+
background: "#ffffff",
|
|
7
|
+
light1: "#f4f4f5",
|
|
8
|
+
light2: "#e4e4e7",
|
|
9
|
+
accent: "#2563eb",
|
|
10
|
+
primary: "#1e1e1d",
|
|
11
|
+
dark1: "#3f3f46",
|
|
12
|
+
dark2: "#0a0a0a",
|
|
13
|
+
};
|
|
14
|
+
|
|
15
|
+
const HEX_COLOR = /^#(?:[0-9a-f]{3}|[0-9a-f]{6}|[0-9a-f]{8})$/i;
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* Turns a color setting into CSS: a theme color by name, a custom hex color, or the surrounding
|
|
19
|
+
* text color for `auto` and anything unexpected, so a saved value can never inject other CSS.
|
|
20
|
+
*/
|
|
21
|
+
export function themeColor(value: unknown): string {
|
|
22
|
+
if (typeof value !== "string") return "currentColor";
|
|
23
|
+
if (Object.hasOwn(THEME_COLOR_DEFAULTS, value)) return `var(--brim-theme-${value}, ${THEME_COLOR_DEFAULTS[value]})`;
|
|
24
|
+
return HEX_COLOR.test(value) ? value : "currentColor";
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
/** BrimCMS stored some texts as HTML. Here they are shown as plain text, so nothing saved can run as markup. */
|
|
28
|
+
export function plainText(value: unknown): string {
|
|
29
|
+
return typeof value === "string"
|
|
30
|
+
? value
|
|
31
|
+
.replace(/<\/(p|div|h[1-6]|li)>/gi, "\n")
|
|
32
|
+
.replace(/<[^>]*>/g, "")
|
|
33
|
+
.trim()
|
|
34
|
+
: "";
|
|
35
|
+
}
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A block is a ready-made component with settings the owner can change.
|
|
3
|
+
* Its settings are described by a schema: the inspector builds its form from it
|
|
4
|
+
* and the server checks saved values against it.
|
|
5
|
+
*/
|
|
6
|
+
export interface BlockDefinition {
|
|
7
|
+
type: string;
|
|
8
|
+
label: string;
|
|
9
|
+
description: string;
|
|
10
|
+
schema: BlockSchema;
|
|
11
|
+
/** The settings a new block starts with. */
|
|
12
|
+
defaults: Record<string, unknown>;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
export interface BlockSchema {
|
|
16
|
+
/** Sections of the inspector, in order. A property listed in no fieldset is not shown. */
|
|
17
|
+
fieldsets: Fieldset[];
|
|
18
|
+
properties: Record<string, SchemaProperty>;
|
|
19
|
+
required?: string[];
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
export interface Fieldset {
|
|
23
|
+
id: string;
|
|
24
|
+
title: string;
|
|
25
|
+
fields: string[];
|
|
26
|
+
[extra: string]: unknown;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
export interface SchemaOption {
|
|
30
|
+
value: unknown;
|
|
31
|
+
label: string;
|
|
32
|
+
[extra: string]: unknown;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
/** One setting. `widget` picks the control; without it the control follows `type`. */
|
|
36
|
+
export interface SchemaProperty {
|
|
37
|
+
title?: string;
|
|
38
|
+
description?: string;
|
|
39
|
+
type?: string;
|
|
40
|
+
widget?: string;
|
|
41
|
+
default?: unknown;
|
|
42
|
+
options?: readonly SchemaOption[];
|
|
43
|
+
/** Bounds of a number. BrimCMS wrote them both ways; `min`/`max` are the common one. */
|
|
44
|
+
min?: number;
|
|
45
|
+
max?: number;
|
|
46
|
+
minimum?: number;
|
|
47
|
+
maximum?: number;
|
|
48
|
+
step?: number;
|
|
49
|
+
/** Shown only while these other settings have these values. */
|
|
50
|
+
showWhen?: Record<string, unknown>;
|
|
51
|
+
[extra: string]: unknown;
|
|
52
|
+
}
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
---
|
|
2
|
+
import { defaultScope } from "../../runtime/request-state.ts";
|
|
3
|
+
import "./video.css";
|
|
4
|
+
import type { NodeScope } from "../../runtime/context.ts";
|
|
5
|
+
import { video } from "../schemas/video.ts";
|
|
6
|
+
import { videoSource } from "./video-source.ts";
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* A video from YouTube, Vimeo, a video file or an HLS stream: the owner picks it and how it plays; its size and
|
|
10
|
+
* shape are the site's. Brim draws it 16:9 at the width it is given. `bare` draws only the `<video>` (or the
|
|
11
|
+
* player's `<iframe>`), with every attribute the code gives it, for a site whose CSS styles it: a background video
|
|
12
|
+
* is `<Video bare nodeId="hero-video" url="/hero.mp4" autoplay loop controls={false} class="hero__video" />`.
|
|
13
|
+
*/
|
|
14
|
+
interface Props {
|
|
15
|
+
nodeId: string;
|
|
16
|
+
/** A YouTube or Vimeo link, or the address of a video file or of an HLS stream (`.m3u8`). */
|
|
17
|
+
url: string;
|
|
18
|
+
scope?: NodeScope;
|
|
19
|
+
posterUrl?: string;
|
|
20
|
+
autoplay?: boolean;
|
|
21
|
+
loop?: boolean;
|
|
22
|
+
muted?: boolean;
|
|
23
|
+
controls?: boolean;
|
|
24
|
+
/** Only the video element, with the attributes below, and no frame. */
|
|
25
|
+
bare?: boolean;
|
|
26
|
+
/** With `bare`, any other attribute goes on the element as it is. */
|
|
27
|
+
[attribute: string]: unknown;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
const SETTINGS = new Set(Object.keys(video.schema.properties));
|
|
31
|
+
const { nodeId, scope = defaultScope(), bare = false, ...rest } = Astro.props;
|
|
32
|
+
const source = Object.fromEntries(Object.entries(rest).filter(([name]) => SETTINGS.has(name)));
|
|
33
|
+
const attributes = Object.fromEntries(Object.entries(rest).filter(([name]) => !SETTINGS.has(name)));
|
|
34
|
+
const settings = Astro.locals.brim.settings(video, nodeId, scope, source);
|
|
35
|
+
|
|
36
|
+
const playback = {
|
|
37
|
+
autoplay: settings.autoplay === true,
|
|
38
|
+
loop: settings.loop === true,
|
|
39
|
+
// Browsers only start a video by themselves when it is silent.
|
|
40
|
+
muted: settings.muted !== false || settings.autoplay === true,
|
|
41
|
+
controls: settings.controls !== false,
|
|
42
|
+
};
|
|
43
|
+
const media = videoSource(settings.url, playback);
|
|
44
|
+
const poster = typeof settings.posterUrl === "string" && settings.posterUrl ? settings.posterUrl : undefined;
|
|
45
|
+
const marker = Astro.locals.brim.marker("video", nodeId, scope, settings);
|
|
46
|
+
// Bare, the player itself carries the site's attributes and the editor's marker; framed, Brim's frame does.
|
|
47
|
+
const Frame = bare ? Fragment : "div";
|
|
48
|
+
const frame = bare
|
|
49
|
+
? {}
|
|
50
|
+
: { ...attributes, class: ["brim-video", attributes.class].filter(Boolean).join(" "), ...marker };
|
|
51
|
+
const player = bare ? { ...attributes, ...marker } : {};
|
|
52
|
+
---
|
|
53
|
+
|
|
54
|
+
<Frame {...frame}>
|
|
55
|
+
{media.kind === "embed" && (
|
|
56
|
+
<iframe
|
|
57
|
+
{...player}
|
|
58
|
+
src={media.src}
|
|
59
|
+
title="Video"
|
|
60
|
+
loading="lazy"
|
|
61
|
+
allow="autoplay; encrypted-media; picture-in-picture; fullscreen"
|
|
62
|
+
allowfullscreen
|
|
63
|
+
referrerpolicy="strict-origin-when-cross-origin"
|
|
64
|
+
/>
|
|
65
|
+
)}
|
|
66
|
+
{(media.kind === "file" || media.kind === "hls") && (
|
|
67
|
+
<video
|
|
68
|
+
{...player}
|
|
69
|
+
src={media.src}
|
|
70
|
+
data-brim-hls={media.kind === "hls" ? media.src : undefined}
|
|
71
|
+
poster={poster}
|
|
72
|
+
autoplay={playback.autoplay}
|
|
73
|
+
loop={playback.loop}
|
|
74
|
+
muted={playback.muted}
|
|
75
|
+
controls={playback.controls}
|
|
76
|
+
playsinline
|
|
77
|
+
preload="metadata"
|
|
78
|
+
/>
|
|
79
|
+
)}
|
|
80
|
+
{media.kind === "none" && Astro.locals.brim.editing && (
|
|
81
|
+
<p class="brim-video__empty" {...player}>
|
|
82
|
+
No video yet. Select this block to add one.
|
|
83
|
+
</p>
|
|
84
|
+
)}
|
|
85
|
+
</Frame>
|
|
86
|
+
|
|
87
|
+
{/* Only a page with an HLS video gets the script; it loads hls.js only where the browser needs it. */}
|
|
88
|
+
{media.kind === "hls" && <script>
|
|
89
|
+
import "./video.client.ts";
|
|
90
|
+
</script>}
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
export type VideoSource =
|
|
2
|
+
| { kind: "embed"; src: string }
|
|
3
|
+
| { kind: "file"; src: string }
|
|
4
|
+
/** An HLS stream (`.m3u8`): played by the browser where it can, otherwise through hls.js. */
|
|
5
|
+
| { kind: "hls"; src: string }
|
|
6
|
+
| { kind: "none" };
|
|
7
|
+
|
|
8
|
+
const YOUTUBE_ID = /(?:youtube\.com\/(?:watch\?(?:.*&)?v=|embed\/|shorts\/)|youtu\.be\/)([\w-]{11})/;
|
|
9
|
+
const VIMEO_ID = /vimeo\.com\/(?:video\/)?(\d+)/;
|
|
10
|
+
|
|
11
|
+
export interface Playback {
|
|
12
|
+
autoplay: boolean;
|
|
13
|
+
loop: boolean;
|
|
14
|
+
muted: boolean;
|
|
15
|
+
controls: boolean;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
/** Whether an address is played through YouTube or Vimeo rather than as a video file. */
|
|
19
|
+
export function isEmbeddedVideo(url: string): boolean {
|
|
20
|
+
return YOUTUBE_ID.test(url) || VIMEO_ID.test(url);
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* Works out how to play an address: YouTube and Vimeo links become their embeddable players,
|
|
25
|
+
* an address ending in `.m3u8` is an HLS stream, anything else on the site or the web is a video file.
|
|
26
|
+
*/
|
|
27
|
+
export function videoSource(url: unknown, playback: Playback): VideoSource {
|
|
28
|
+
if (typeof url !== "string" || url.trim() === "") return { kind: "none" };
|
|
29
|
+
const flag = (on: boolean): string => (on ? "1" : "0");
|
|
30
|
+
|
|
31
|
+
const youtube = url.match(YOUTUBE_ID)?.[1];
|
|
32
|
+
if (youtube) {
|
|
33
|
+
const query = new URLSearchParams({
|
|
34
|
+
autoplay: flag(playback.autoplay),
|
|
35
|
+
mute: flag(playback.muted),
|
|
36
|
+
controls: flag(playback.controls),
|
|
37
|
+
loop: flag(playback.loop),
|
|
38
|
+
// YouTube only loops a video that is also its own playlist.
|
|
39
|
+
...(playback.loop && { playlist: youtube }),
|
|
40
|
+
});
|
|
41
|
+
return { kind: "embed", src: `https://www.youtube-nocookie.com/embed/${youtube}?${query}` };
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
const vimeo = url.match(VIMEO_ID)?.[1];
|
|
45
|
+
if (vimeo) {
|
|
46
|
+
const query = new URLSearchParams({
|
|
47
|
+
autoplay: flag(playback.autoplay),
|
|
48
|
+
muted: flag(playback.muted),
|
|
49
|
+
controls: flag(playback.controls),
|
|
50
|
+
loop: flag(playback.loop),
|
|
51
|
+
});
|
|
52
|
+
return { kind: "embed", src: `https://player.vimeo.com/video/${vimeo}?${query}` };
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
const isFile = /^https?:\/\//i.test(url) || (url.startsWith("/") && !url.startsWith("//"));
|
|
56
|
+
if (!isFile) return { kind: "none" };
|
|
57
|
+
return isHlsAddress(url) ? { kind: "hls", src: url } : { kind: "file", src: url };
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
/** An address whose path ends in `.m3u8`, whatever comes after `?` or `#`. */
|
|
61
|
+
export function isHlsAddress(url: string): boolean {
|
|
62
|
+
return /\.m3u8$/i.test(url.trim().split(/[?#]/, 1)[0] ?? "");
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
/**
|
|
66
|
+
* Which quality of an HLS stream to start on: the smallest one at least as tall as the player on this screen
|
|
67
|
+
* (counting at most two device pixels to one CSS pixel), else the tallest. `-1` when the stream lists none.
|
|
68
|
+
*/
|
|
69
|
+
export function startLevel(heights: number[], playerHeight: number, pixelRatio: number): number {
|
|
70
|
+
if (heights.length === 0) return -1;
|
|
71
|
+
const wanted = playerHeight * Math.min(Math.max(pixelRatio || 1, 1), 2);
|
|
72
|
+
let best = -1;
|
|
73
|
+
heights.forEach((height, index) => {
|
|
74
|
+
if (height >= wanted && (best === -1 || height < (heights[best] ?? Number.POSITIVE_INFINITY))) best = index;
|
|
75
|
+
});
|
|
76
|
+
return best !== -1 ? best : heights.indexOf(Math.max(...heights));
|
|
77
|
+
}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Plays HLS streams (`.m3u8`) in the video block through hls.js, fetched only when such a video is on the page.
|
|
3
|
+
* A browser's own HLS player starts on the first quality the stream lists, often the smallest, so its first
|
|
4
|
+
* seconds are blurry; hls.js starts on the quality that fits the player as it is drawn, and never fetches one
|
|
5
|
+
* larger than it. Where hls.js cannot play (an iPhone has no MediaSource), the `src` already on the element plays
|
|
6
|
+
* by itself. Autoplay, loop, muted, controls and the poster stay the element's own attributes.
|
|
7
|
+
*/
|
|
8
|
+
import { startLevel } from "./video-source.ts";
|
|
9
|
+
|
|
10
|
+
const HLS_TYPE = "application/vnd.apple.mpegurl";
|
|
11
|
+
|
|
12
|
+
async function attach(video: HTMLVideoElement): Promise<void> {
|
|
13
|
+
const source = video.dataset.brimHls;
|
|
14
|
+
if (!source || video.dataset.brimHlsReady !== undefined) return;
|
|
15
|
+
video.dataset.brimHlsReady = "";
|
|
16
|
+
const native = video.canPlayType(HLS_TYPE) !== "";
|
|
17
|
+
if (native && typeof MediaSource === "undefined") return;
|
|
18
|
+
|
|
19
|
+
const { default: Hls } = await import("hls.js");
|
|
20
|
+
if (!Hls.isSupported()) return;
|
|
21
|
+
if (native) {
|
|
22
|
+
// The browser's own player has started on the stream, from its smallest quality: hls.js takes over.
|
|
23
|
+
video.removeAttribute("src");
|
|
24
|
+
video.load();
|
|
25
|
+
}
|
|
26
|
+
const player = new Hls({ capLevelToPlayerSize: true });
|
|
27
|
+
player.once(Hls.Events.MANIFEST_PARSED, (_event, data) => {
|
|
28
|
+
const heights = data.levels.map((level) => level.height);
|
|
29
|
+
const level = startLevel(heights, video.getBoundingClientRect().height || 720, window.devicePixelRatio);
|
|
30
|
+
if (level !== -1) player.startLevel = level;
|
|
31
|
+
if (video.autoplay) void video.play().catch(() => undefined);
|
|
32
|
+
});
|
|
33
|
+
player.loadSource(new URL(source, location.href).href);
|
|
34
|
+
player.attachMedia(video);
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
function attachAll(): void {
|
|
38
|
+
for (const video of document.querySelectorAll<HTMLVideoElement>("video[data-brim-hls]")) void attach(video);
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
attachAll();
|
|
42
|
+
// Pages swapped in by Astro's view transitions bring new videos without running this file again.
|
|
43
|
+
document.addEventListener("astro:page-load", attachAll);
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
/* The frame Brim draws for a video the site does not style itself: 16:9, as wide as it is given. */
|
|
2
|
+
/* In the `brim` layer: any CSS of the site wins over it, whatever its selectors. */
|
|
3
|
+
@layer brim {
|
|
4
|
+
.brim-video {
|
|
5
|
+
position: relative;
|
|
6
|
+
width: 100%;
|
|
7
|
+
aspect-ratio: 16 / 9;
|
|
8
|
+
overflow: hidden;
|
|
9
|
+
border-radius: var(--brim-theme-radius, 0.5rem);
|
|
10
|
+
background: var(--brim-theme-dark2, #0a0a0a);
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
.brim-video :is(iframe, video) {
|
|
14
|
+
display: block;
|
|
15
|
+
width: 100%;
|
|
16
|
+
height: 100%;
|
|
17
|
+
border: 0;
|
|
18
|
+
object-fit: cover;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
.brim-video__empty {
|
|
22
|
+
display: flex;
|
|
23
|
+
align-items: center;
|
|
24
|
+
justify-content: center;
|
|
25
|
+
height: 100%;
|
|
26
|
+
margin: 0;
|
|
27
|
+
color: var(--brim-theme-background, #ffffff);
|
|
28
|
+
}
|
|
29
|
+
}
|