@luhtech/site-template 0.21.0 → 0.22.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/README.md +30 -0
- package/package.json +1 -1
- package/src/components/VentureMark.astro +3 -2
- package/src/layouts/SiteLayout.astro +5 -0
- package/src/lib/markReplay.ts +89 -0
package/README.md
CHANGED
|
@@ -373,6 +373,36 @@ Two bins go with it:
|
|
|
373
373
|
install chromium`. `SiteLayout` emits the web-app meta for an installable
|
|
374
374
|
site.
|
|
375
375
|
|
|
376
|
+
## An animated mark replays when clicked (0.22.0)
|
|
377
|
+
|
|
378
|
+
Every animated mark ran once on load and then sat on its last frame;
|
|
379
|
+
clicking it did nothing. `SiteLayout` now installs one replay for every
|
|
380
|
+
element on the page carrying `data-mark-replay="<group>"`:
|
|
381
|
+
|
|
382
|
+
- **Inline markup** (an `<svg>`, or a wrapper around one, animated with
|
|
383
|
+
CSS) restarts its animations in place. `VentureMark` sets
|
|
384
|
+
`data-mark-replay="venture"` on an animated mark.
|
|
385
|
+
- **An `<img>` of an animated SVG** gets a fresh `data:` URL of the
|
|
386
|
+
animated file, so the browser draws it from frame 0. Point
|
|
387
|
+
`data-mark-replay-src` at the animated file when the `<img>` shows a
|
|
388
|
+
static one at rest (Ectropy's lockup, which its reveal ends on). `data:`
|
|
389
|
+
rather than `blob:`, because a CSP like ectropy.ai's allows `data:`
|
|
390
|
+
images and not `blob:`.
|
|
391
|
+
|
|
392
|
+
A click on a mark whose link opens this same page replays it and does not
|
|
393
|
+
reload, so the nav logo (linked to `/`) replays on the landing page. From
|
|
394
|
+
any other page it is an ordinary link home. A link to another origin, or
|
|
395
|
+
one opened in a new tab, is left alone. Under
|
|
396
|
+
`prefers-reduced-motion: reduce` nothing replays.
|
|
397
|
+
|
|
398
|
+
A site opts its nav logo in on the element it passes to the `logo` slot:
|
|
399
|
+
|
|
400
|
+
```astro
|
|
401
|
+
<Fragment slot="logo">
|
|
402
|
+
<img src="/brand/x-lockup.svg" data-mark-replay="nav" data-mark-replay-src="/brand/x-mark-animated.svg" alt="X" />
|
|
403
|
+
</Fragment>
|
|
404
|
+
```
|
|
405
|
+
|
|
376
406
|
## Migrating a venture site
|
|
377
407
|
|
|
378
408
|
A migration is: author `content/site.<venture>.json` + `content/pages/*.json`
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@luhtech/site-template",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.22.0",
|
|
4
4
|
"description": "Shared Astro component library + content-instance contract for LuhTech venture marketing sites -- one template renders every site from content/page.schema.json + content/site.schema.json instances.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"license": "Apache-2.0",
|
|
@@ -10,7 +10,8 @@
|
|
|
10
10
|
// /brand/{brandRef}-mark.svg file (onerror-hidden if even that's missing)
|
|
11
11
|
// for every venture that doesn't have one yet. Not every venture needs an
|
|
12
12
|
// animated mark for this to work; it degrades honestly per-venture
|
|
13
|
-
// instead of assuming universal coverage.
|
|
13
|
+
// instead of assuming universal coverage. An animated mark replays when
|
|
14
|
+
// clicked (data-mark-replay="venture", SiteLayout's installMarkReplay, 0.22.0).
|
|
14
15
|
import { VENTURE_MARKS } from '../lib/venture-marks.generated';
|
|
15
16
|
|
|
16
17
|
export interface Props {
|
|
@@ -21,7 +22,7 @@ const { brandRef, class: className = 'h-6 w-6 mb-2' } = Astro.props;
|
|
|
21
22
|
const animated = VENTURE_MARKS[brandRef];
|
|
22
23
|
---
|
|
23
24
|
{animated ? (
|
|
24
|
-
<svg xmlns="http://www.w3.org/2000/svg" viewBox={animated.viewBox} class={className} role="img" aria-label={brandRef} set:html={animated.markup} />
|
|
25
|
+
<svg xmlns="http://www.w3.org/2000/svg" viewBox={animated.viewBox} class={className} role="img" aria-label={brandRef} data-mark-replay="venture" set:html={animated.markup} />
|
|
25
26
|
) : (
|
|
26
27
|
<img
|
|
27
28
|
src={`/brand/${brandRef}-mark.svg`}
|
|
@@ -167,6 +167,11 @@ const linkItems = nav.filter((item) => item !== ctaItem);
|
|
|
167
167
|
</div>
|
|
168
168
|
</footer>
|
|
169
169
|
<script>
|
|
170
|
+
// An animated mark replays when it is clicked: any [data-mark-replay]
|
|
171
|
+
// on the page, the nav logo and VentureMark included (0.22.0).
|
|
172
|
+
import { installMarkReplay } from '../lib/markReplay';
|
|
173
|
+
installMarkReplay();
|
|
174
|
+
|
|
170
175
|
// Mobile nav toggle. Plain click handler + classList, no
|
|
171
176
|
// framework/island needed for something this small -- matches
|
|
172
177
|
// this file's own existing no-js/reveal scripts' own approach.
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
// A venture's animated mark plays again when it is clicked (0.22.0,
|
|
2
|
+
// d-2026-10-20-st-mark-replay). L4 2026-10-20: "the logo does not animate
|
|
3
|
+
// when you click ... this applies on all svg animations per the template".
|
|
4
|
+
// Every animated mark in the pack ran once on load and then sat on its last
|
|
5
|
+
// frame: Ectropy's reveal once per browser session, luh.tech's drop-in and
|
|
6
|
+
// the VentureMark marks once per page. Clicking a mark did nothing visible.
|
|
7
|
+
//
|
|
8
|
+
// An element opts in with data-mark-replay="<group>". Two kinds of mark:
|
|
9
|
+
// - inline markup (an <svg> or a wrapper around one) whose CSS animations
|
|
10
|
+
// are restarted in place;
|
|
11
|
+
// - an <img> of an animated SVG, which a page cannot restart, so it gets
|
|
12
|
+
// a fresh data: URL of the animated file (data-mark-replay-src, else its
|
|
13
|
+
// own src). data:, not blob:, because ectropy.ai's CSP allows data: and
|
|
14
|
+
// https: images but not blob:. Each replay's URL differs by a trailing
|
|
15
|
+
// comment, so the browser draws a new image and its timeline starts at 0.
|
|
16
|
+
// A click that opens this same page replays in place and does not reload,
|
|
17
|
+
// so the nav logo (linked to "/") replays on the landing page. A click that
|
|
18
|
+
// opens any other page is an ordinary navigation (L4 2026-10-20: "logo
|
|
19
|
+
// replay only needs to happen on the landing page"). Reduced motion:
|
|
20
|
+
// nothing replays.
|
|
21
|
+
|
|
22
|
+
export const REPLAY_ATTR = 'data-mark-replay';
|
|
23
|
+
export const REPLAY_SRC_ATTR = 'data-mark-replay-src';
|
|
24
|
+
|
|
25
|
+
export type ReplayTarget = 'here' | 'next' | 'away';
|
|
26
|
+
|
|
27
|
+
/** Where a click on a mark lands: 'here' with no link or a link to this
|
|
28
|
+
* page, 'next' for another page of this site, 'away' for another origin. */
|
|
29
|
+
export function replayTarget(href: string | null | undefined, current: string): ReplayTarget {
|
|
30
|
+
if (!href) return 'here';
|
|
31
|
+
let to: URL;
|
|
32
|
+
let from: URL;
|
|
33
|
+
try {
|
|
34
|
+
from = new URL(current);
|
|
35
|
+
to = new URL(href, from);
|
|
36
|
+
} catch {
|
|
37
|
+
return 'here';
|
|
38
|
+
}
|
|
39
|
+
if (to.origin !== from.origin) return 'away';
|
|
40
|
+
const path = (u: URL) => u.pathname.replace(/\/index\.html$/, '/').replace(/(.)\/$/, '$1');
|
|
41
|
+
return path(to) === path(from) && to.search === from.search ? 'here' : 'next';
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
/** The data: URL for replay number n of an SVG's text. */
|
|
45
|
+
export function replayDataUrl(svgText: string, n: number): string {
|
|
46
|
+
return `data:image/svg+xml;charset=utf-8,${encodeURIComponent(`${svgText}<!--replay ${n}-->`)}`;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
const svgText = new Map<string, Promise<string>>();
|
|
50
|
+
let replays = 0;
|
|
51
|
+
|
|
52
|
+
/** Play one mark from its first frame. */
|
|
53
|
+
export function replayMark(el: Element): void {
|
|
54
|
+
if (el.tagName === 'IMG') {
|
|
55
|
+
const img = el as HTMLImageElement;
|
|
56
|
+
const src = img.getAttribute(REPLAY_SRC_ATTR) || img.currentSrc || img.src;
|
|
57
|
+
if (!src) return;
|
|
58
|
+
if (!svgText.has(src)) {
|
|
59
|
+
svgText.set(src, fetch(src).then((r) => (r.ok ? r.text() : Promise.reject(new Error(`${r.status}`)))));
|
|
60
|
+
}
|
|
61
|
+
const n = ++replays;
|
|
62
|
+
svgText.get(src)!.then(
|
|
63
|
+
(text) => { img.src = replayDataUrl(text, n); },
|
|
64
|
+
() => { svgText.delete(src); },
|
|
65
|
+
);
|
|
66
|
+
return;
|
|
67
|
+
}
|
|
68
|
+
if (typeof el.getAnimations === 'function') {
|
|
69
|
+
for (const a of el.getAnimations({ subtree: true })) {
|
|
70
|
+
a.cancel();
|
|
71
|
+
a.play();
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
/** Wire every [data-mark-replay] on the page: a click on one whose link
|
|
77
|
+
* opens this page replays it. */
|
|
78
|
+
export function installMarkReplay(doc: Document = document, win: Window = window): void {
|
|
79
|
+
if (win.matchMedia('(prefers-reduced-motion: reduce)').matches) return;
|
|
80
|
+
doc.addEventListener('click', (e) => {
|
|
81
|
+
const el = (e.target as Element | null)?.closest?.(`[${REPLAY_ATTR}]`);
|
|
82
|
+
if (!el) return;
|
|
83
|
+
const link = el.closest('a[href]') as HTMLAnchorElement | null;
|
|
84
|
+
if (link && (link.target === '_blank' || e.metaKey || e.ctrlKey || e.shiftKey || e.button !== 0)) return;
|
|
85
|
+
if (replayTarget(link?.getAttribute('href'), win.location.href) !== 'here') return;
|
|
86
|
+
if (link && new URL(link.href).hash === win.location.hash) e.preventDefault();
|
|
87
|
+
replayMark(el);
|
|
88
|
+
});
|
|
89
|
+
}
|