@justai/cuts 0.8.0 → 0.9.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/package.json +3 -2
- package/src/Posts.astro +3 -1
- package/src/Toolbar.astro +197 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@justai/cuts",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.9.0",
|
|
4
4
|
"description": "A persona's named parts — the page shell that holds them, and the cuts themselves.",
|
|
5
5
|
"license": "UNLICENSED",
|
|
6
6
|
"repository": {
|
|
@@ -16,7 +16,8 @@
|
|
|
16
16
|
"./Base.astro": "./src/Base.astro",
|
|
17
17
|
"./LangPicker.astro": "./src/LangPicker.astro",
|
|
18
18
|
"./BackToZone.astro": "./src/BackToZone.astro",
|
|
19
|
-
"./Posts.astro": "./src/Posts.astro"
|
|
19
|
+
"./Posts.astro": "./src/Posts.astro",
|
|
20
|
+
"./Toolbar.astro": "./src/Toolbar.astro"
|
|
20
21
|
},
|
|
21
22
|
"peerDependencies": {
|
|
22
23
|
"@justai/ui": ">=0.2.0",
|
package/src/Posts.astro
CHANGED
|
@@ -37,7 +37,9 @@ const { handle, name, footer, avatarBg } = Astro.props;
|
|
|
37
37
|
<style>
|
|
38
38
|
/* ---- POSTS cut — a conversation: ONE line descends from the post's avatar and
|
|
39
39
|
connects every comment & reply (they're all replies to the post). ---- */
|
|
40
|
-
|
|
40
|
+
/* the cut owns its own landing offset (was `#kernel, #posts { scroll-margin-top }` in each persona —
|
|
41
|
+
which orphaned once #posts moved here and carried this component's scope cid instead of the persona's). */
|
|
42
|
+
.posts { border-block-start: 1px solid var(--border); scroll-margin-top: 82px; }
|
|
41
43
|
.post { padding-block: 18px; cursor: pointer; transition: background 0.15s var(--ease-out); }
|
|
42
44
|
.post:hover { background: color-mix(in srgb, var(--text) 3.5%, transparent); }
|
|
43
45
|
.post + .post { border-block-start: 1px solid var(--border); }
|
|
@@ -0,0 +1,197 @@
|
|
|
1
|
+
---
|
|
2
|
+
// ░░ TOOLBAR cut — the persona's sticky chrome: home · section-nav · language · sign-in, plus the
|
|
3
|
+
// scroll-reactive title strip and the scroll-spy that binds the whole page together. ░░
|
|
4
|
+
//
|
|
5
|
+
// This markup + its ~40 lines of CSS + its ~80-line scroll-spy were near-identical in every persona's
|
|
6
|
+
// main component (only the kernel glyph and a couple of optional controls differed). It lives here now,
|
|
7
|
+
// once. A persona writes:
|
|
8
|
+
//
|
|
9
|
+
// <Toolbar sectionsLabel={t.chromeSections} profileLabel={t.chromeProfile}
|
|
10
|
+
// kernelLabel={t.chromeApp} postsLabel={t.chromePosts}>
|
|
11
|
+
// <svg slot="kernelIcon" .../>
|
|
12
|
+
// <LangPicker slot="langPicker" current={lang} locales={locales} ... />
|
|
13
|
+
// </Toolbar>
|
|
14
|
+
//
|
|
15
|
+
// WHAT VARIES, AND WHY IT IS A PROP vs A SLOT (the rule: zero-coupling children are internalised;
|
|
16
|
+
// data-coupled ones are slots):
|
|
17
|
+
// • BackToZone — takes no props → internalised here (the persona no longer imports it).
|
|
18
|
+
// • the three nav aria-labels — resolved strings (like every other cut: Posts, LangPicker) → props.
|
|
19
|
+
// • kernelIcon — the ONE per-persona nav glyph (⚡ / clock / globe …) → required slot.
|
|
20
|
+
// • langPicker — needs the persona's own locale data (the list must NOT live in the shared package —
|
|
21
|
+
// it bit us twice; see @justai/ui/locale) → a slot the persona fills with its <LangPicker/>.
|
|
22
|
+
// • navExtra — optional extra nav item after Posts (e.g. the timers' fullscreen button) → slot.
|
|
23
|
+
// • toolbarRight — optional right-side control before the picker (e.g. time's 24H/AM-PM toggle) → slot.
|
|
24
|
+
//
|
|
25
|
+
// CONTRACT with the page (the same three cut ids the whole shell agrees on): the scroll-spy needs a
|
|
26
|
+
// `#below` wrapper around toolbar+kernel+posts, a `<section id="kernel">` between `#profile` and
|
|
27
|
+
// `#posts`, and reads `.pname`/`.handle` from the Profile for the title strip. It touches NO kernel
|
|
28
|
+
// internals. It is also the page's REVEAL: it sets `body.ready` (the other half of @justai/core's
|
|
29
|
+
// REVEAL_CSS) — so every persona that renders a Toolbar is revealed; move it and the page stays blank.
|
|
30
|
+
interface Props {
|
|
31
|
+
sectionsLabel: string; // aria-label for the section-nav group
|
|
32
|
+
profileLabel: string; // aria/title for the Profile nav icon
|
|
33
|
+
kernelLabel: string; // aria/title for the Kernel (app) nav icon
|
|
34
|
+
postsLabel: string; // aria/title for the Posts nav icon
|
|
35
|
+
}
|
|
36
|
+
import BackToZone from "./BackToZone.astro";
|
|
37
|
+
const { sectionsLabel, profileLabel, kernelLabel, postsLabel } = Astro.props;
|
|
38
|
+
---
|
|
39
|
+
|
|
40
|
+
<header class="toolbar">
|
|
41
|
+
<div class="tb-row">
|
|
42
|
+
<div class="tb-left">
|
|
43
|
+
<BackToZone />
|
|
44
|
+
<nav class="tb-nav-group" aria-label={sectionsLabel}>
|
|
45
|
+
<a class="tb-nav" id="navProfile" href="#profile" aria-label={profileLabel} title={profileLabel}>
|
|
46
|
+
<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M20 21v-2a4 4 0 0 0-4-4H8a4 4 0 0 0-4 4v2"/><circle cx="12" cy="7" r="4"/></svg>
|
|
47
|
+
</a>
|
|
48
|
+
<a class="tb-nav" id="navKernel" href="#kernel" aria-label={kernelLabel} title={kernelLabel}>
|
|
49
|
+
<slot name="kernelIcon" />
|
|
50
|
+
</a>
|
|
51
|
+
<a class="tb-nav" id="navPosts" href="#posts" aria-label={postsLabel} title={postsLabel}>
|
|
52
|
+
<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M21 11.5a8.4 8.4 0 0 1-9 8.3 9.6 9.6 0 0 1-4-.9L3 21l1.1-5A8.4 8.4 0 1 1 21 11.5z"/></svg>
|
|
53
|
+
</a>
|
|
54
|
+
<slot name="navExtra" />
|
|
55
|
+
</nav>
|
|
56
|
+
</div>
|
|
57
|
+
<div class="tb-right">
|
|
58
|
+
<slot name="toolbarRight" />
|
|
59
|
+
<slot name="langPicker" />
|
|
60
|
+
<div data-justai-auth></div>
|
|
61
|
+
</div>
|
|
62
|
+
</div>
|
|
63
|
+
<div class="tb-title" id="tbTitle"><span class="tb-title-text" id="tbTitleText"></span></div>
|
|
64
|
+
</header>
|
|
65
|
+
<!-- justai auth — sign-in avatar menu, inherited from auth.justai.pro (the developer writes only the kernel) -->
|
|
66
|
+
<script is:inline defer src="https://auth.justai.pro/sdk.js"></script>
|
|
67
|
+
|
|
68
|
+
<style>
|
|
69
|
+
/* ---- app toolbar — sticky to the top of the active region (kernel + posts); it never
|
|
70
|
+
enters the Profile (it lives inside .below). Flat / knife-cut: a left group and a
|
|
71
|
+
right group, no rounded pills. ---- */
|
|
72
|
+
.toolbar {
|
|
73
|
+
position: sticky; top: 0; z-index: 40;
|
|
74
|
+
display: flex; flex-direction: column;
|
|
75
|
+
/* full-bleed: the bar (frosted bg + hairline) touches the contained-view edges; the
|
|
76
|
+
icons stay aligned with the body via matching inline padding. */
|
|
77
|
+
margin-inline: calc(-1 * max(16px, env(safe-area-inset-left))) calc(-1 * max(16px, env(safe-area-inset-right)));
|
|
78
|
+
padding-block: max(8px, env(safe-area-inset-top)) 8px;
|
|
79
|
+
padding-inline: max(16px, env(safe-area-inset-left)) max(16px, env(safe-area-inset-right));
|
|
80
|
+
background: color-mix(in srgb, var(--bg) 70%, transparent);
|
|
81
|
+
backdrop-filter: blur(22px) saturate(1.5);
|
|
82
|
+
-webkit-backdrop-filter: blur(22px) saturate(1.5);
|
|
83
|
+
/* a very faint hairline always; it firms up once content scrolls under the bar */
|
|
84
|
+
border-block-end: 1px solid color-mix(in srgb, var(--border) 55%, transparent);
|
|
85
|
+
transition: border-color 0.3s var(--ease-out);
|
|
86
|
+
}
|
|
87
|
+
.toolbar.stuck { border-block-end-color: var(--border); }
|
|
88
|
+
@media (min-width: 768px) { .toolbar { margin-inline: -28px; padding-inline: 28px; } }
|
|
89
|
+
/* icons row + the scroll-reactive title strip below it */
|
|
90
|
+
.tb-row { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
|
|
91
|
+
.tb-title { display: flex; align-items: center; height: 0; overflow: hidden; opacity: 0; transition: height 0.35s var(--ease-out), opacity 0.25s var(--ease-out); }
|
|
92
|
+
.tb-title.show { height: 26px; opacity: 1; }
|
|
93
|
+
.tb-title-text { font-size: var(--fs-sm); font-weight: 600; letter-spacing: -0.01em; color: var(--text); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; transition: opacity 0.16s var(--ease-out); }
|
|
94
|
+
.tb-title-text.fade { opacity: 0; }
|
|
95
|
+
/* nav lives on the left, beside the back affordance — the middle is intentionally empty */
|
|
96
|
+
.tb-left { display: flex; align-items: center; gap: 2px; min-width: 0; }
|
|
97
|
+
.tb-nav-group { display: flex; align-items: center; gap: 2px; }
|
|
98
|
+
.tb-right { display: flex; align-items: center; min-width: 0; }
|
|
99
|
+
/* icon-only section nav — current cut highlighted */
|
|
100
|
+
.tb-nav {
|
|
101
|
+
display: grid; place-items: center; width: 38px; height: 36px;
|
|
102
|
+
color: var(--text-dim);
|
|
103
|
+
transition: color 0.2s, opacity 0.2s, transform 0.2s var(--ease-spring);
|
|
104
|
+
}
|
|
105
|
+
.tb-nav:hover { color: var(--text); }
|
|
106
|
+
.tb-nav:active { transform: scale(0.9); }
|
|
107
|
+
.tb-nav.active { color: var(--accent); }
|
|
108
|
+
.tb-nav :global(svg) { width: 19px; height: 19px; }
|
|
109
|
+
</style>
|
|
110
|
+
|
|
111
|
+
<script>
|
|
112
|
+
// Land on the Kernel cut; Profile is above (scroll up), Posts below (scroll down). This is also the
|
|
113
|
+
// page's reveal (body.ready) and its scroll-spy (nav highlight + title strip + hash sync).
|
|
114
|
+
(function () {
|
|
115
|
+
const below = document.getElementById("below");
|
|
116
|
+
const kernel = document.getElementById("kernel");
|
|
117
|
+
const toolbar = document.querySelector(".toolbar");
|
|
118
|
+
const navKernel = document.getElementById("navKernel");
|
|
119
|
+
const navPosts = document.getElementById("navPosts");
|
|
120
|
+
const navProfile = document.getElementById("navProfile");
|
|
121
|
+
const profile = document.getElementById("profile");
|
|
122
|
+
const posts = document.getElementById("posts");
|
|
123
|
+
if (!below || !kernel) return;
|
|
124
|
+
if ("scrollRestoration" in history) history.scrollRestoration = "manual";
|
|
125
|
+
// update only the fragment, never clobbering the path or query (?data=, ?city= must survive a scroll)
|
|
126
|
+
const setHash = (id: string) => history.replaceState(null, "", location.pathname + location.search + "#" + id);
|
|
127
|
+
|
|
128
|
+
// Land at the top of .below (toolbar + kernel) — skip the Profile, no flash.
|
|
129
|
+
const land = () => {
|
|
130
|
+
// presentation mode (a ?data= link with present:true) owns the viewport — no landing scroll
|
|
131
|
+
if (document.body.dataset.present) return;
|
|
132
|
+
// respect a section hash on load/refresh: #posts / #profile land there; otherwise (#kernel or
|
|
133
|
+
// none) land on the Kernel. behavior:instant overrides the CSS scroll-behavior:smooth.
|
|
134
|
+
const h = location.hash;
|
|
135
|
+
if (h === "#posts" && posts) posts.scrollIntoView({ behavior: "instant", block: "start" });
|
|
136
|
+
else if (h === "#profile" && profile) profile.scrollIntoView({ behavior: "instant", block: "start" });
|
|
137
|
+
else window.scrollTo({ top: below.getBoundingClientRect().top + window.scrollY, behavior: "instant" });
|
|
138
|
+
};
|
|
139
|
+
land();
|
|
140
|
+
window.addEventListener("load", land);
|
|
141
|
+
const reveal = () => document.body.classList.add("ready");
|
|
142
|
+
requestAnimationFrame(reveal);
|
|
143
|
+
setTimeout(reveal, 500);
|
|
144
|
+
|
|
145
|
+
// Toolbar hairline appears once content scrolls under it; the nav highlights whichever
|
|
146
|
+
// cut is currently at the top of the active region (the toolbar line) — Profile (the
|
|
147
|
+
// first cut when you scroll up), App or Posts.
|
|
148
|
+
const cuts = [[profile, navProfile], [kernel, navKernel], [posts, navPosts]].filter(([el, nav]) => el && nav) as [HTMLElement, HTMLElement][];
|
|
149
|
+
// scroll-reactive title strip: the cut at the toolbar line names itself. Profile stays collapsed
|
|
150
|
+
// (its big header is the title); Kernel → app name, Posts → @handle.
|
|
151
|
+
const tbTitle = document.getElementById("tbTitle");
|
|
152
|
+
const tbTitleText = document.getElementById("tbTitleText");
|
|
153
|
+
const pname = (document.querySelector(".pname")?.textContent || "").trim();
|
|
154
|
+
const handle = (document.querySelector(".handle")?.textContent || "").trim();
|
|
155
|
+
const titleFor = (c: [HTMLElement, HTMLElement]) => (c[0] === kernel ? pname : c[0] === posts ? handle : "");
|
|
156
|
+
let lastTitleCut: [HTMLElement, HTMLElement] | null = null, titleInit = true;
|
|
157
|
+
const onScroll = () => {
|
|
158
|
+
if (toolbar) toolbar.classList.toggle("stuck", window.scrollY >= below.offsetTop - 1);
|
|
159
|
+
const line = 84; // ≥ #kernel/#posts scroll-margin-top, so anchor clicks land at/above the line and are detected
|
|
160
|
+
let current = cuts[0];
|
|
161
|
+
for (const c of cuts) if (c[0].getBoundingClientRect().top <= line) current = c;
|
|
162
|
+
for (const c of cuts) c[1].classList.toggle("active", c === current);
|
|
163
|
+
if (current !== lastTitleCut) {
|
|
164
|
+
lastTitleCut = current;
|
|
165
|
+
// scroll-linked URL: reflect the current cut in the hash (replaceState = no jump, no history spam)
|
|
166
|
+
const cid = current[0].id;
|
|
167
|
+
if (cid && "#" + cid !== location.hash) setHash(cid);
|
|
168
|
+
const t = titleFor(current);
|
|
169
|
+
if (titleInit) {
|
|
170
|
+
// first paint: snap the strip into place — no "settling into the room" animation on load/refresh
|
|
171
|
+
titleInit = false;
|
|
172
|
+
if (tbTitle) { tbTitle.style.transition = "none"; tbTitle.classList.toggle("show", !!t); }
|
|
173
|
+
if (t && tbTitleText) tbTitleText.textContent = t;
|
|
174
|
+
if (tbTitle) { void tbTitle.offsetHeight; tbTitle.style.transition = ""; }
|
|
175
|
+
} else {
|
|
176
|
+
if (tbTitle) tbTitle.classList.toggle("show", !!t);
|
|
177
|
+
if (t && tbTitleText && tbTitleText.textContent !== t) {
|
|
178
|
+
tbTitleText.classList.add("fade");
|
|
179
|
+
setTimeout(() => { tbTitleText.textContent = t; tbTitleText.classList.remove("fade"); }, 150);
|
|
180
|
+
}
|
|
181
|
+
}
|
|
182
|
+
}
|
|
183
|
+
};
|
|
184
|
+
window.addEventListener("scroll", onScroll, { passive: true });
|
|
185
|
+
onScroll();
|
|
186
|
+
// nav clicks: scroll programmatically so the sticky toolbar always pins flush. The native anchor
|
|
187
|
+
// + scroll-margin left a gap above the bar when jumping to the Kernel from the Profile (the title
|
|
188
|
+
// strip is still collapsed there, so the bar is shorter than the margin). Kernel → land at .below
|
|
189
|
+
// top (bar pins at 0); Profile/Posts → scrollIntoView.
|
|
190
|
+
cuts.forEach(([el, nav]) => nav.addEventListener("click", (e) => {
|
|
191
|
+
e.preventDefault();
|
|
192
|
+
if (el === kernel) window.scrollTo({ top: below.getBoundingClientRect().top + window.scrollY, behavior: "smooth" });
|
|
193
|
+
else el.scrollIntoView({ behavior: "smooth", block: "start" });
|
|
194
|
+
setHash(el.id);
|
|
195
|
+
}));
|
|
196
|
+
})();
|
|
197
|
+
</script>
|