@krizaka/ui 3.73.0 → 3.75.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 +4 -10
- package/dist/{RotatingWord-COSabR2c.d.ts → RotatingWord-D3tpDLE4.d.ts} +1 -1
- package/dist/account-menu.d.ts +1 -1
- package/dist/account-menu.js +1 -1
- package/dist/account-settings.d.ts +1 -1
- package/dist/account-settings.js +1 -1
- package/dist/app-frame.d.ts +2 -5
- package/dist/avatar/defaults.d.ts +2 -2
- package/dist/avatar/defaults.js +1 -5
- package/dist/avatar/defaults.js.map +1 -1
- package/dist/{avatar-B_na7r1U.d.ts → avatar-CNV6ld8l.d.ts} +2 -2
- package/dist/avatar.d.ts +2 -2
- package/dist/avatar.js +1 -5
- package/dist/avatar.js.map +1 -1
- package/dist/blocks.css +4 -4
- package/dist/chat.js +1 -1
- package/dist/{chunk-5MPPIGCB.js → chunk-E46AEUPH.js} +1 -5
- package/dist/chunk-E46AEUPH.js.map +1 -0
- package/dist/{chunk-TISDOZH3.js → chunk-IOTY5HYG.js} +1 -5
- package/dist/chunk-IOTY5HYG.js.map +1 -0
- package/dist/chunk-PGPNYYE2.js +286 -0
- package/dist/chunk-PGPNYYE2.js.map +1 -0
- package/dist/{chunk-GRVIZTT2.js → chunk-RI3AA2E3.js} +3 -3
- package/dist/{chunk-Y5YBTHVD.js → chunk-SG3QJJXE.js} +6 -12
- package/dist/chunk-SG3QJJXE.js.map +1 -0
- package/dist/{chunk-4JO5GSSD.js → chunk-VA4NPCUQ.js} +2 -2
- package/dist/chunk-VA4NPCUQ.js.map +1 -0
- package/dist/{chunk-E4FMPPDL.js → chunk-WC3SO4CE.js} +2 -2
- package/dist/{chunk-T5NZSKWT.js → chunk-YQWYGQTV.js} +38 -41
- package/dist/chunk-YQWYGQTV.js.map +1 -0
- package/dist/{chunk-M3GEYLMR.js → chunk-ZPOVOEO3.js} +1 -2
- package/dist/collection-switcher.d.ts +1 -1
- package/dist/data-table.js +3 -3
- package/dist/{default-avatar-BL0nJFti.d.ts → default-avatar-Bh4atFDo.d.ts} +2 -2
- package/dist/elephant.d.ts +2 -2
- package/dist/elephant.js +2 -3
- package/dist/elephant.js.map +1 -1
- package/dist/engine-flow.js +29 -21
- package/dist/engine-flow.js.map +1 -1
- package/dist/entity-header.d.ts +1 -1
- package/dist/filter-bar.d.ts +9 -1
- package/dist/filter-bar.js +1 -1
- package/dist/gallery-page.js +3 -3
- package/dist/genui.js +101 -35
- package/dist/genui.js.map +1 -1
- package/dist/index.d.ts +7 -51
- package/dist/index.js +2 -12
- package/dist/index.js.map +1 -1
- package/dist/{lightbox-D5NAHFEA.js → lightbox-Q45BZ3HW.js} +3 -3
- package/dist/map.js +0 -120
- package/dist/map.js.map +1 -1
- package/dist/match-dialog.js +3 -3
- package/dist/motion.css +3 -120
- package/dist/motion.d.ts +1 -1
- package/dist/motion.js +1 -1
- package/dist/native/list.js +1 -1
- package/dist/native/list.js.map +1 -1
- package/dist/native/map.js +0 -120
- package/dist/native/map.js.map +1 -1
- package/dist/native.d.ts +7 -111
- package/dist/native.js +988 -1436
- package/dist/native.js.map +1 -1
- package/dist/nav-bar.d.ts +1 -1
- package/dist/nav-bar.js +2 -2
- package/dist/product-page.js +3 -3
- package/dist/rail-nav.d.ts +2 -5
- package/dist/shop-gallery.js +1 -1
- package/dist/site-cahier.d.ts +3 -11
- package/dist/site-cahier.js +126 -367
- package/dist/site-cahier.js.map +1 -1
- package/dist/site-footer.d.ts +1 -1
- package/dist/site-footer.js +2 -2
- package/dist/{sites-CEnywB89.d.ts → sites-CVNSirrg.d.ts} +3 -11
- package/dist/sites.d.ts +7 -15
- package/dist/sites.js +4 -10
- package/dist/sites.js.map +1 -1
- package/dist/tag-selector.js +28 -21
- package/dist/tag-selector.js.map +1 -1
- package/dist/vertical-video.js +2 -2
- package/dist/waveform.js.map +1 -1
- package/package.json +5 -109
- package/registry/account-menu.json +1 -1
- package/registry/account-settings.json +1 -1
- package/registry/achievement.json +1 -1
- package/registry/action-bar.json +1 -1
- package/registry/activity-feed.json +1 -1
- package/registry/agenda.json +1 -1
- package/registry/alert.json +1 -1
- package/registry/analysis-report.json +1 -1
- package/registry/anatomy-plate.json +1 -1
- package/registry/app-frame.json +6 -38
- package/registry/app-header.json +1 -1
- package/registry/app-shell.json +1 -1
- package/registry/argument-card.json +1 -1
- package/registry/auth-layout.json +1 -1
- package/registry/avatar.json +2 -2
- package/registry/badge.json +1 -1
- package/registry/bird-plate.json +1 -1
- package/registry/button.json +1 -1
- package/registry/captcha.json +1 -1
- package/registry/card-grid.json +1 -1
- package/registry/card.json +1 -1
- package/registry/catalogue-page.json +1 -1
- package/registry/changelog-page.json +1 -1
- package/registry/chapter.json +1 -1
- package/registry/chat.json +3 -3
- package/registry/checkbox.json +1 -1
- package/registry/chip-link.json +1 -1
- package/registry/chip-row.json +1 -1
- package/registry/chip.json +1 -1
- package/registry/choice-grid.json +1 -1
- package/registry/code-block.json +1 -1
- package/registry/collection-switcher.json +1 -1
- package/registry/combobox.json +1 -1
- package/registry/command.json +1 -1
- package/registry/comparison-table.json +1 -1
- package/registry/component-page.json +1 -1
- package/registry/confirm-button.json +1 -1
- package/registry/contact-page.json +1 -1
- package/registry/continue-prompt.json +1 -1
- package/registry/copy-button.json +1 -1
- package/registry/countdown.json +1 -1
- package/registry/cover-hero.json +1 -1
- package/registry/cta-panel.json +1 -1
- package/registry/dashboard-layout.json +1 -1
- package/registry/data-table.json +1 -1
- package/registry/date-picker.json +1 -1
- package/registry/decision-list.json +1 -1
- package/registry/description-list.json +1 -1
- package/registry/desktop-window.json +1 -1
- package/registry/detail-layout.json +1 -1
- package/registry/dialog.json +1 -1
- package/registry/docs-article-page.json +1 -1
- package/registry/docs-hub-page.json +1 -1
- package/registry/docs-layout.json +1 -1
- package/registry/docs-nav.json +1 -1
- package/registry/document-viewer.json +1 -1
- package/registry/doodle.json +1 -1
- package/registry/drop-overlay.json +1 -1
- package/registry/dropdown-menu.json +1 -1
- package/registry/elephant.json +3 -5
- package/registry/embed-facade.json +1 -1
- package/registry/empty-state.json +1 -1
- package/registry/engine-flow.json +3 -4
- package/registry/entity-header.json +1 -1
- package/registry/environment-notice.json +1 -1
- package/registry/error-page.json +1 -1
- package/registry/field.json +1 -1
- package/registry/file-upload.json +1 -1
- package/registry/filter-bar.json +2 -2
- package/registry/flock.json +1 -1
- package/registry/footnote.json +1 -1
- package/registry/force-update-screen.json +1 -1
- package/registry/form.json +1 -1
- package/registry/gallery-page.json +1 -1
- package/registry/genui.json +1 -1
- package/registry/glossary-term.json +1 -1
- package/registry/glossary.json +1 -1
- package/registry/glow-card.json +1 -1
- package/registry/goal-gauge.json +1 -1
- package/registry/grade-stamp.json +1 -1
- package/registry/image-cropper.json +1 -1
- package/registry/index.json +11 -246
- package/registry/kanban.json +1 -1
- package/registry/kbd.json +1 -1
- package/registry/kind-config-editor.json +1 -1
- package/registry/kpi-explained.json +1 -1
- package/registry/landing-page.json +1 -1
- package/registry/landscape.json +1 -1
- package/registry/language-switch.json +1 -1
- package/registry/legal-page.json +1 -1
- package/registry/link-card.json +1 -1
- package/registry/list.json +1 -1
- package/registry/loader.json +1 -1
- package/registry/longform-page.json +1 -1
- package/registry/maintenance-screen.json +1 -1
- package/registry/map.json +2 -2
- package/registry/margin-layout.json +1 -1
- package/registry/markdown.json +1 -1
- package/registry/marketing-layout.json +1 -1
- package/registry/mascot-quote.json +1 -1
- package/registry/mascot-state.json +1 -1
- package/registry/mascots.json +1 -1
- package/registry/match-dialog.json +3 -3
- package/registry/media-capture.json +1 -1
- package/registry/media-gallery.json +3 -14
- package/registry/meter.json +1 -1
- package/registry/money-input.json +1 -1
- package/registry/nav-bar.json +6 -38
- package/registry/next-actions.json +1 -1
- package/registry/notification-preferences.json +1 -1
- package/registry/number-ticker.json +1 -1
- package/registry/opening-hours.json +3 -4
- package/registry/page-header.json +1 -1
- package/registry/page-hero.json +1 -1
- package/registry/page-index.json +1 -1
- package/registry/page.json +1 -1
- package/registry/pagination.json +1 -1
- package/registry/pointer-light.json +1 -1
- package/registry/popover.json +1 -1
- package/registry/price-catalogue-editor.json +1 -1
- package/registry/pricing-page.json +1 -1
- package/registry/product-page.json +2 -6
- package/registry/profile-card.json +1 -1
- package/registry/progress.json +1 -1
- package/registry/promise-card.json +1 -1
- package/registry/promo-code-field.json +1 -1
- package/registry/proposal.json +1 -1
- package/registry/qr-code.json +1 -1
- package/registry/quota-meter.json +1 -1
- package/registry/radio-group.json +1 -1
- package/registry/rail-nav.json +6 -38
- package/registry/recipes.json +1 -1
- package/registry/retro-tv.json +2 -3
- package/registry/reviews.json +1 -1
- package/registry/router.json +1 -1
- package/registry/schema-form.json +1 -1
- package/registry/scroll-stage.json +1 -1
- package/registry/search-field.json +1 -1
- package/registry/section-backdrop.json +1 -1
- package/registry/separator.json +1 -1
- package/registry/service-card.json +1 -1
- package/registry/settings-layout.json +1 -1
- package/registry/shop-composer.json +1 -1
- package/registry/shop-gallery.json +3 -8
- package/registry/shop.json +2 -2
- package/registry/showcase.json +2 -7
- package/registry/signature.json +1 -1
- package/registry/site-cahier.json +1 -1
- package/registry/site-footer.json +6 -38
- package/registry/sites.json +3 -3
- package/registry/skeleton.json +1 -1
- package/registry/skip-link.json +1 -1
- package/registry/slider.json +1 -1
- package/registry/slot-picker.json +1 -1
- package/registry/slot.json +1 -1
- package/registry/specimen-tag.json +1 -1
- package/registry/speed-lines.json +1 -1
- package/registry/spinner.json +1 -1
- package/registry/split-view.json +1 -1
- package/registry/stage-banner.json +1 -1
- package/registry/stat.json +1 -1
- package/registry/status-chip.json +1 -1
- package/registry/status-page.json +1 -1
- package/registry/step-progress.json +1 -1
- package/registry/step-showcase.json +1 -1
- package/registry/stepper.json +1 -1
- package/registry/sticky-action.json +1 -1
- package/registry/stuck.json +1 -1
- package/registry/swipe-deck.json +4 -5
- package/registry/switch.json +1 -1
- package/registry/tabs.json +1 -1
- package/registry/tag-input.json +1 -1
- package/registry/tag-selector.json +2 -2
- package/registry/taped-photo.json +1 -1
- package/registry/terminal-replay.json +1 -1
- package/registry/text-style.json +1 -1
- package/registry/theme.json +1 -1
- package/registry/toast.json +1 -1
- package/registry/toc.json +1 -1
- package/registry/tooltip.json +1 -1
- package/registry/tree-view.json +1 -1
- package/registry/update-prompt.json +1 -1
- package/registry/upload-queue.json +1 -1
- package/registry/usage.json +1 -1
- package/registry/verified-badge.json +1 -1
- package/registry/versus-card.json +1 -1
- package/registry/vertical-video.json +2 -6
- package/registry/video-player.json +2 -7
- package/registry/video-trimmer.json +3 -4
- package/registry/virtual.json +1 -1
- package/registry/wall.json +3 -9
- package/registry/waveform.json +4 -9
- package/dist/audio-player.d.ts +0 -115
- package/dist/audio-player.js +0 -211
- package/dist/audio-player.js.map +0 -1
- package/dist/chunk-4JO5GSSD.js.map +0 -1
- package/dist/chunk-5MPPIGCB.js.map +0 -1
- package/dist/chunk-B2HS5EAH.js +0 -527
- package/dist/chunk-B2HS5EAH.js.map +0 -1
- package/dist/chunk-T5NZSKWT.js.map +0 -1
- package/dist/chunk-TISDOZH3.js.map +0 -1
- package/dist/chunk-Y5YBTHVD.js.map +0 -1
- package/dist/chunk-YKOLME7R.js +0 -126
- package/dist/chunk-YKOLME7R.js.map +0 -1
- package/dist/how-it-works-page.d.ts +0 -49
- package/dist/how-it-works-page.js +0 -28
- package/dist/how-it-works-page.js.map +0 -1
- package/dist/iso.d.ts +0 -401
- package/dist/iso.js +0 -363
- package/dist/iso.js.map +0 -1
- package/dist/marquee.d.ts +0 -34
- package/dist/marquee.js +0 -52
- package/dist/marquee.js.map +0 -1
- package/dist/media-grid.d.ts +0 -246
- package/dist/media-grid.js +0 -468
- package/dist/media-grid.js.map +0 -1
- package/dist/meta-row.d.ts +0 -55
- package/dist/meta-row.js +0 -35
- package/dist/meta-row.js.map +0 -1
- package/dist/photo-grid.d.ts +0 -123
- package/dist/photo-grid.js +0 -94
- package/dist/photo-grid.js.map +0 -1
- package/registry/audio-player.json +0 -300
- package/registry/examples/audio-player/podcast.d.ts +0 -4
- package/registry/examples/audio-player/podcast.js +0 -22
- package/registry/examples/audio-player/podcast.tsx +0 -19
- package/registry/examples/audio-player/voice-note.d.ts +0 -4
- package/registry/examples/audio-player/voice-note.js +0 -12
- package/registry/examples/audio-player/voice-note.tsx +0 -12
- package/registry/examples/how-it-works-page/orazaka.d.ts +0 -4
- package/registry/examples/how-it-works-page/orazaka.js +0 -30
- package/registry/examples/how-it-works-page/orazaka.tsx +0 -26
- package/registry/examples/iso/compose.d.ts +0 -4
- package/registry/examples/iso/compose.js +0 -22
- package/registry/examples/iso/compose.tsx +0 -19
- package/registry/examples/iso/creator-hero.d.ts +0 -4
- package/registry/examples/iso/creator-hero.js +0 -29
- package/registry/examples/iso/creator-hero.tsx +0 -23
- package/registry/examples/iso/orazaka-hero.d.ts +0 -4
- package/registry/examples/iso/orazaka-hero.js +0 -26
- package/registry/examples/iso/orazaka-hero.tsx +0 -21
- package/registry/examples/iso/still.d.ts +0 -4
- package/registry/examples/iso/still.js +0 -21
- package/registry/examples/iso/still.tsx +0 -15
- package/registry/examples/marquee/cards.d.ts +0 -4
- package/registry/examples/marquee/cards.js +0 -23
- package/registry/examples/marquee/cards.tsx +0 -21
- package/registry/examples/marquee/logos.d.ts +0 -4
- package/registry/examples/marquee/logos.js +0 -12
- package/registry/examples/marquee/logos.tsx +0 -17
- package/registry/examples/media-grid/feed.d.ts +0 -4
- package/registry/examples/media-grid/feed.js +0 -32
- package/registry/examples/media-grid/feed.tsx +0 -31
- package/registry/examples/media-grid/loading.d.ts +0 -4
- package/registry/examples/media-grid/loading.js +0 -28
- package/registry/examples/media-grid/loading.tsx +0 -25
- package/registry/examples/media-grid/uniform.d.ts +0 -4
- package/registry/examples/media-grid/uniform.js +0 -29
- package/registry/examples/media-grid/uniform.tsx +0 -26
- package/registry/examples/meta-row/native/video.d.ts +0 -4
- package/registry/examples/meta-row/native/video.dark.png +0 -0
- package/registry/examples/meta-row/native/video.js +0 -11
- package/registry/examples/meta-row/native/video.light.png +0 -0
- package/registry/examples/meta-row/native/video.tsx +0 -5
- package/registry/examples/meta-row/status.d.ts +0 -4
- package/registry/examples/meta-row/status.js +0 -12
- package/registry/examples/meta-row/status.tsx +0 -7
- package/registry/examples/meta-row/video.d.ts +0 -4
- package/registry/examples/meta-row/video.js +0 -12
- package/registry/examples/meta-row/video.tsx +0 -7
- package/registry/examples/photo-grid/native/profile-photos.d.ts +0 -4
- package/registry/examples/photo-grid/native/profile-photos.dark.png +0 -0
- package/registry/examples/photo-grid/native/profile-photos.js +0 -27
- package/registry/examples/photo-grid/native/profile-photos.light.png +0 -0
- package/registry/examples/photo-grid/native/profile-photos.tsx +0 -24
- package/registry/examples/photo-grid/profile-photos.d.ts +0 -4
- package/registry/examples/photo-grid/profile-photos.js +0 -28
- package/registry/examples/photo-grid/profile-photos.tsx +0 -25
- package/registry/how-it-works-page.json +0 -258
- package/registry/iso.json +0 -1371
- package/registry/marquee.json +0 -241
- package/registry/media-grid.json +0 -1034
- package/registry/meta-row.json +0 -218
- package/registry/photo-grid.json +0 -316
- /package/dist/{chunk-GRVIZTT2.js.map → chunk-RI3AA2E3.js.map} +0 -0
- /package/dist/{chunk-E4FMPPDL.js.map → chunk-WC3SO4CE.js.map} +0 -0
- /package/dist/{chunk-M3GEYLMR.js.map → chunk-ZPOVOEO3.js.map} +0 -0
- /package/dist/{lightbox-D5NAHFEA.js.map → lightbox-Q45BZ3HW.js.map} +0 -0
package/dist/audio-player.js
DELETED
|
@@ -1,211 +0,0 @@
|
|
|
1
|
-
"use client";
|
|
2
|
-
import {
|
|
3
|
-
clamp,
|
|
4
|
-
formatClock,
|
|
5
|
-
playSafely,
|
|
6
|
-
useInView
|
|
7
|
-
} from "./chunk-FZBWEDQI.js";
|
|
8
|
-
import {
|
|
9
|
-
PauseGlyph,
|
|
10
|
-
PlayGlyph
|
|
11
|
-
} from "./chunk-PGBF3UBX.js";
|
|
12
|
-
|
|
13
|
-
// src/audio-player/audio-player.tsx
|
|
14
|
-
import * as React from "react";
|
|
15
|
-
import { tv } from "tailwind-variants";
|
|
16
|
-
|
|
17
|
-
// src/waveform/bars.ts
|
|
18
|
-
function resamplePeaks(peaks, count) {
|
|
19
|
-
if (peaks.length === 0) return Array.from({ length: count }, () => 0.15);
|
|
20
|
-
const out = Array.from({ length: count }, (_, i) => {
|
|
21
|
-
const from = Math.floor(i / count * peaks.length);
|
|
22
|
-
const to = Math.max(from + 1, Math.floor((i + 1) / count * peaks.length));
|
|
23
|
-
return Math.max(...peaks.slice(from, to).map(Math.abs));
|
|
24
|
-
});
|
|
25
|
-
const loudest = Math.max(...out, 1e-4);
|
|
26
|
-
return out.map((v) => Math.max(0.08, v / loudest));
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
// src/audio-player/audio-player.tsx
|
|
30
|
-
import { jsx, jsxs } from "react/jsx-runtime";
|
|
31
|
-
var audioPlayer = tv({
|
|
32
|
-
slots: {
|
|
33
|
-
root: "flex w-full items-center gap-3 rounded-xl border border-border-default bg-surface-1 p-3",
|
|
34
|
-
play: "inline-flex h-11 w-11 shrink-0 items-center justify-center rounded-full bg-accent text-on-accent transition-colors hover:bg-accent-hover focus-visible:outline-hidden focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 focus-visible:ring-offset-surface-1",
|
|
35
|
-
body: "flex min-w-0 flex-1 flex-col gap-1",
|
|
36
|
-
title: "truncate text-sm font-semibold text-fg",
|
|
37
|
-
wave: "relative flex h-10 w-full cursor-pointer touch-none items-center gap-[2px] rounded-md focus-visible:outline-hidden focus-visible:ring-2 focus-visible:ring-ring",
|
|
38
|
-
bar: "min-w-[2px] flex-1 rounded-full bg-border-strong data-[played]:bg-accent",
|
|
39
|
-
meta: "flex items-center justify-between font-mono text-[11px] tabular-nums text-fg-secondary",
|
|
40
|
-
speed: "shrink-0 rounded-md px-2 py-1 text-xs font-semibold tabular-nums text-fg-secondary hover:bg-surface-3 hover:text-fg focus-visible:outline-hidden focus-visible:ring-2 focus-visible:ring-ring"
|
|
41
|
-
}
|
|
42
|
-
});
|
|
43
|
-
var audioPlayerLabels = {
|
|
44
|
-
play: "Play",
|
|
45
|
-
pause: "Pause",
|
|
46
|
-
seek: "Seek",
|
|
47
|
-
speed: (rate) => `Speed ${rate}\xD7`,
|
|
48
|
-
time: (time, duration) => `${time} of ${duration}`
|
|
49
|
-
};
|
|
50
|
-
async function computeAudioPeaks(src, count = 200, signal) {
|
|
51
|
-
const response = await fetch(src, { signal });
|
|
52
|
-
const data = await response.arrayBuffer();
|
|
53
|
-
const Context = window.AudioContext ?? window.webkitAudioContext;
|
|
54
|
-
const context = new Context();
|
|
55
|
-
try {
|
|
56
|
-
const buffer = await context.decodeAudioData(data);
|
|
57
|
-
const channel = buffer.getChannelData(0);
|
|
58
|
-
const size = Math.max(1, Math.floor(channel.length / count));
|
|
59
|
-
return Array.from({ length: count }, (_, i) => {
|
|
60
|
-
let peak = 0;
|
|
61
|
-
for (let j = i * size; j < Math.min(channel.length, (i + 1) * size); j += 1) peak = Math.max(peak, Math.abs(channel[j]));
|
|
62
|
-
return peak;
|
|
63
|
-
});
|
|
64
|
-
} finally {
|
|
65
|
-
void context.close();
|
|
66
|
-
}
|
|
67
|
-
}
|
|
68
|
-
function AudioPlayer({
|
|
69
|
-
src,
|
|
70
|
-
title,
|
|
71
|
-
peaks: given,
|
|
72
|
-
computePeaks,
|
|
73
|
-
bars = 48,
|
|
74
|
-
playbackRates = [1, 1.5, 2],
|
|
75
|
-
pauseWhenHidden = true,
|
|
76
|
-
duration: knownDuration = 0,
|
|
77
|
-
onPlayingChange,
|
|
78
|
-
labels: words,
|
|
79
|
-
className
|
|
80
|
-
}) {
|
|
81
|
-
const labels = { ...audioPlayerLabels, ...words };
|
|
82
|
-
const s = audioPlayer();
|
|
83
|
-
const audio = React.useRef(null);
|
|
84
|
-
const root = React.useRef(null);
|
|
85
|
-
const wave = React.useRef(null);
|
|
86
|
-
const dragging = React.useRef(false);
|
|
87
|
-
const [playing, setPlaying] = React.useState(false);
|
|
88
|
-
const [time, setTime] = React.useState(0);
|
|
89
|
-
const [duration, setDuration] = React.useState(knownDuration);
|
|
90
|
-
const [rate, setRate] = React.useState(playbackRates[0] ?? 1);
|
|
91
|
-
const [computed, setComputed] = React.useState(null);
|
|
92
|
-
const [wantPeaks, setWantPeaks] = React.useState(false);
|
|
93
|
-
React.useEffect(() => {
|
|
94
|
-
if (given || !computePeaks || !wantPeaks) return;
|
|
95
|
-
const controller = new AbortController();
|
|
96
|
-
computeAudioPeaks(src, 200, controller.signal).then(setComputed, () => void 0);
|
|
97
|
-
return () => controller.abort();
|
|
98
|
-
}, [given, computePeaks, wantPeaks, src]);
|
|
99
|
-
useInView(root, (visible) => !visible && audio.current && !audio.current.paused && audio.current.pause(), pauseWhenHidden);
|
|
100
|
-
const shape = React.useMemo(() => resamplePeaks(given ?? computed ?? [], bars), [given, computed, bars]);
|
|
101
|
-
const progress = duration > 0 ? time / duration : 0;
|
|
102
|
-
const seek = (to) => {
|
|
103
|
-
if (!audio.current) return;
|
|
104
|
-
const next = clamp(to, 0, duration || audio.current.duration || 0);
|
|
105
|
-
audio.current.currentTime = next;
|
|
106
|
-
setTime(next);
|
|
107
|
-
};
|
|
108
|
-
const at = (clientX) => {
|
|
109
|
-
const box = wave.current?.getBoundingClientRect();
|
|
110
|
-
return box && box.width ? (clientX - box.left) / box.width * duration : 0;
|
|
111
|
-
};
|
|
112
|
-
const toggle = () => {
|
|
113
|
-
setWantPeaks(true);
|
|
114
|
-
if (!audio.current) return;
|
|
115
|
-
if (audio.current.paused) playSafely(audio.current);
|
|
116
|
-
else audio.current.pause();
|
|
117
|
-
};
|
|
118
|
-
return /* @__PURE__ */ jsxs("div", { ref: root, role: "group", "aria-label": title, className: s.root({ className }), children: [
|
|
119
|
-
/* @__PURE__ */ jsx(
|
|
120
|
-
"audio",
|
|
121
|
-
{
|
|
122
|
-
ref: audio,
|
|
123
|
-
src,
|
|
124
|
-
preload: "metadata",
|
|
125
|
-
onPlay: () => {
|
|
126
|
-
setPlaying(true);
|
|
127
|
-
onPlayingChange?.(true);
|
|
128
|
-
},
|
|
129
|
-
onPause: () => {
|
|
130
|
-
setPlaying(false);
|
|
131
|
-
onPlayingChange?.(false);
|
|
132
|
-
},
|
|
133
|
-
onTimeUpdate: (event) => setTime(event.currentTarget.currentTime),
|
|
134
|
-
onDurationChange: (event) => Number.isFinite(event.currentTarget.duration) && setDuration(event.currentTarget.duration)
|
|
135
|
-
}
|
|
136
|
-
),
|
|
137
|
-
/* @__PURE__ */ jsx("button", { type: "button", className: s.play(), "aria-label": playing ? labels.pause : labels.play, onClick: toggle, children: playing ? /* @__PURE__ */ jsx(PauseGlyph, { className: "h-5 w-5" }) : /* @__PURE__ */ jsx(PlayGlyph, { className: "ml-0.5 h-5 w-5" }) }),
|
|
138
|
-
/* @__PURE__ */ jsxs("div", { className: s.body(), children: [
|
|
139
|
-
/* @__PURE__ */ jsx("p", { className: s.title(), "aria-hidden": true, children: title }),
|
|
140
|
-
/* @__PURE__ */ jsx(
|
|
141
|
-
"div",
|
|
142
|
-
{
|
|
143
|
-
ref: wave,
|
|
144
|
-
role: "slider",
|
|
145
|
-
tabIndex: 0,
|
|
146
|
-
"aria-label": labels.seek,
|
|
147
|
-
"aria-valuemin": 0,
|
|
148
|
-
"aria-valuemax": Math.round(duration),
|
|
149
|
-
"aria-valuenow": Math.round(time),
|
|
150
|
-
"aria-valuetext": labels.time(formatClock(time), formatClock(duration)),
|
|
151
|
-
className: s.wave(),
|
|
152
|
-
onPointerDown: (event) => {
|
|
153
|
-
dragging.current = true;
|
|
154
|
-
wave.current?.setPointerCapture?.(event.pointerId);
|
|
155
|
-
seek(at(event.clientX));
|
|
156
|
-
},
|
|
157
|
-
onPointerMove: (event) => dragging.current && seek(at(event.clientX)),
|
|
158
|
-
onPointerUp: () => {
|
|
159
|
-
dragging.current = false;
|
|
160
|
-
},
|
|
161
|
-
onKeyDown: (event) => {
|
|
162
|
-
const moves = {
|
|
163
|
-
ArrowLeft: time - 5,
|
|
164
|
-
ArrowDown: time - 5,
|
|
165
|
-
ArrowRight: time + 5,
|
|
166
|
-
ArrowUp: time + 5,
|
|
167
|
-
PageDown: time - 30,
|
|
168
|
-
PageUp: time + 30,
|
|
169
|
-
Home: 0,
|
|
170
|
-
End: duration
|
|
171
|
-
};
|
|
172
|
-
const to = moves[event.key];
|
|
173
|
-
if (to === void 0) return;
|
|
174
|
-
event.preventDefault();
|
|
175
|
-
seek(to);
|
|
176
|
-
},
|
|
177
|
-
children: shape.map((peak, i) => /* @__PURE__ */ jsx("span", { "aria-hidden": true, "data-played": (i + 0.5) / bars <= progress ? "" : void 0, className: s.bar(), style: { height: `${Math.round(peak * 100)}%` } }, i))
|
|
178
|
-
}
|
|
179
|
-
),
|
|
180
|
-
/* @__PURE__ */ jsxs("div", { className: s.meta(), "aria-hidden": true, children: [
|
|
181
|
-
/* @__PURE__ */ jsx("span", { children: formatClock(time) }),
|
|
182
|
-
/* @__PURE__ */ jsx("span", { children: formatClock(duration) })
|
|
183
|
-
] })
|
|
184
|
-
] }),
|
|
185
|
-
playbackRates.length > 1 && /* @__PURE__ */ jsxs(
|
|
186
|
-
"button",
|
|
187
|
-
{
|
|
188
|
-
type: "button",
|
|
189
|
-
className: s.speed(),
|
|
190
|
-
"aria-label": labels.speed(rate),
|
|
191
|
-
onClick: () => {
|
|
192
|
-
const next = playbackRates[(playbackRates.indexOf(rate) + 1) % playbackRates.length] ?? 1;
|
|
193
|
-
if (audio.current) audio.current.playbackRate = next;
|
|
194
|
-
setRate(next);
|
|
195
|
-
},
|
|
196
|
-
children: [
|
|
197
|
-
rate,
|
|
198
|
-
"\xD7"
|
|
199
|
-
]
|
|
200
|
-
}
|
|
201
|
-
)
|
|
202
|
-
] });
|
|
203
|
-
}
|
|
204
|
-
export {
|
|
205
|
-
AudioPlayer,
|
|
206
|
-
audioPlayer,
|
|
207
|
-
audioPlayerLabels,
|
|
208
|
-
computeAudioPeaks,
|
|
209
|
-
resamplePeaks
|
|
210
|
-
};
|
|
211
|
-
//# sourceMappingURL=audio-player.js.map
|
package/dist/audio-player.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/audio-player/audio-player.tsx","../src/waveform/bars.ts"],"sourcesContent":["// Client. An `<audio>` with a waveform you can seek on: the bars are the sound's peaks (given by the server, or\n// computed here from the file with Web Audio when `computePeaks` — once, on demand), the played part in the accent.\n// The waveform is a `slider` (arrows ± 5 s, Page keys ± 30 s, Home / End) whose value is read as a time; the play\n// button and the speed are named by props. No animation but the played part's colour, and it pauses off screen.\nimport * as React from \"react\";\nimport { tv } from \"tailwind-variants\";\n\nimport { PauseGlyph, PlayGlyph } from \"../glyphs\";\nimport { clamp, formatClock, playSafely, useInView } from \"../media\";\nimport { resamplePeaks } from \"../waveform/bars\";\n\nexport { resamplePeaks };\n\nexport const audioPlayer = tv({\n slots: {\n root: \"flex w-full items-center gap-3 rounded-xl border border-border-default bg-surface-1 p-3\",\n play:\n \"inline-flex h-11 w-11 shrink-0 items-center justify-center rounded-full bg-accent text-on-accent transition-colors hover:bg-accent-hover \" +\n \"focus-visible:outline-hidden focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 focus-visible:ring-offset-surface-1\",\n body: \"flex min-w-0 flex-1 flex-col gap-1\",\n title: \"truncate text-sm font-semibold text-fg\",\n wave:\n \"relative flex h-10 w-full cursor-pointer touch-none items-center gap-[2px] rounded-md \" +\n \"focus-visible:outline-hidden focus-visible:ring-2 focus-visible:ring-ring\",\n bar: \"min-w-[2px] flex-1 rounded-full bg-border-strong data-[played]:bg-accent\",\n meta: \"flex items-center justify-between font-mono text-[11px] tabular-nums text-fg-secondary\",\n speed:\n \"shrink-0 rounded-md px-2 py-1 text-xs font-semibold tabular-nums text-fg-secondary hover:bg-surface-3 hover:text-fg \" +\n \"focus-visible:outline-hidden focus-visible:ring-2 focus-visible:ring-ring\",\n },\n});\n\nexport type AudioPlayerLabels = {\n play: string;\n pause: string;\n /** The waveform slider (\"Seek\"). */\n seek: string;\n /** The speed button: `(rate) => \"Speed \" + rate + \"×\"`. */\n speed: (rate: number) => string;\n /** The slider's value: `(time, duration) => \"0:42 of 3:10\"`. */\n time: (time: string, duration: string) => string;\n};\n\nexport const audioPlayerLabels: AudioPlayerLabels = {\n play: \"Play\",\n pause: \"Pause\",\n seek: \"Seek\",\n speed: (rate) => `Speed ${rate}×`,\n time: (time, duration) => `${time} of ${duration}`,\n};\n\nexport type AudioPlayerProps = {\n /** The address of the sound. */\n src: string;\n /** What it is (\"Voice note — Eric, 0:42\"): shown, and the accessible name of the player. */\n title: string;\n /** The peaks, between 0 and 1, as many as you like (they are resampled to `bars`). */\n peaks?: readonly number[];\n /** Without `peaks`: fetches the file and computes them with Web Audio at the first play (same-origin or CORS). */\n computePeaks?: boolean;\n /** How many bars. Default 48. */\n bars?: number;\n /** The speeds of the speed button. Default `[1, 1.5, 2]`; `[]` hides it. */\n playbackRates?: readonly number[];\n /** Pauses when it leaves the screen. Default `true`. */\n pauseWhenHidden?: boolean;\n /** The length, in seconds, before the metadata is loaded (from the server). */\n duration?: number;\n /** Called when playback starts, pauses, ends. */\n onPlayingChange?: (playing: boolean) => void;\n /** The words, passed translated; English by default. */\n labels?: Partial<AudioPlayerLabels>;\n /** Classes merged on the root. */\n className?: string;\n};\n\n/** The peaks of a sound file, computed with Web Audio (`count` of them). */\nexport async function computeAudioPeaks(src: string, count = 200, signal?: AbortSignal): Promise<number[]> {\n const response = await fetch(src, { signal });\n const data = await response.arrayBuffer();\n const Context = window.AudioContext ?? (window as unknown as { webkitAudioContext: typeof AudioContext }).webkitAudioContext;\n const context = new Context();\n try {\n const buffer = await context.decodeAudioData(data);\n const channel = buffer.getChannelData(0);\n const size = Math.max(1, Math.floor(channel.length / count));\n return Array.from({ length: count }, (_, i) => {\n let peak = 0;\n for (let j = i * size; j < Math.min(channel.length, (i + 1) * size); j += 1) peak = Math.max(peak, Math.abs(channel[j]!));\n return peak;\n });\n } finally {\n void context.close();\n }\n}\n\n/** A sound with a seekable waveform: play / pause, time, speed — a voice note, a podcast clip, a track. */\nexport function AudioPlayer({\n src,\n title,\n peaks: given,\n computePeaks,\n bars = 48,\n playbackRates = [1, 1.5, 2],\n pauseWhenHidden = true,\n duration: knownDuration = 0,\n onPlayingChange,\n labels: words,\n className,\n}: AudioPlayerProps) {\n const labels = { ...audioPlayerLabels, ...words };\n const s = audioPlayer();\n const audio = React.useRef<HTMLAudioElement>(null);\n const root = React.useRef<HTMLDivElement>(null);\n const wave = React.useRef<HTMLDivElement>(null);\n const dragging = React.useRef(false);\n const [playing, setPlaying] = React.useState(false);\n const [time, setTime] = React.useState(0);\n const [duration, setDuration] = React.useState(knownDuration);\n const [rate, setRate] = React.useState(playbackRates[0] ?? 1);\n const [computed, setComputed] = React.useState<number[] | null>(null);\n const [wantPeaks, setWantPeaks] = React.useState(false);\n\n React.useEffect(() => {\n if (given || !computePeaks || !wantPeaks) return;\n const controller = new AbortController();\n computeAudioPeaks(src, 200, controller.signal).then(setComputed, () => undefined);\n return () => controller.abort();\n }, [given, computePeaks, wantPeaks, src]);\n\n useInView(root, (visible) => !visible && audio.current && !audio.current.paused && audio.current.pause(), pauseWhenHidden);\n\n const shape = React.useMemo(() => resamplePeaks(given ?? computed ?? [], bars), [given, computed, bars]);\n const progress = duration > 0 ? time / duration : 0;\n\n const seek = (to: number) => {\n if (!audio.current) return;\n const next = clamp(to, 0, duration || audio.current.duration || 0);\n audio.current.currentTime = next;\n setTime(next);\n };\n const at = (clientX: number) => {\n const box = wave.current?.getBoundingClientRect();\n return box && box.width ? ((clientX - box.left) / box.width) * duration : 0;\n };\n const toggle = () => {\n setWantPeaks(true);\n if (!audio.current) return;\n if (audio.current.paused) playSafely(audio.current);\n else audio.current.pause();\n };\n\n return (\n <div ref={root} role=\"group\" aria-label={title} className={s.root({ className })}>\n <audio\n ref={audio}\n src={src}\n preload=\"metadata\"\n onPlay={() => {\n setPlaying(true);\n onPlayingChange?.(true);\n }}\n onPause={() => {\n setPlaying(false);\n onPlayingChange?.(false);\n }}\n onTimeUpdate={(event) => setTime(event.currentTarget.currentTime)}\n onDurationChange={(event) => Number.isFinite(event.currentTarget.duration) && setDuration(event.currentTarget.duration)}\n />\n <button type=\"button\" className={s.play()} aria-label={playing ? labels.pause : labels.play} onClick={toggle}>\n {playing ? <PauseGlyph className=\"h-5 w-5\" /> : <PlayGlyph className=\"ml-0.5 h-5 w-5\" />}\n </button>\n <div className={s.body()}>\n <p className={s.title()} aria-hidden>\n {title}\n </p>\n <div\n ref={wave}\n role=\"slider\"\n tabIndex={0}\n aria-label={labels.seek}\n aria-valuemin={0}\n aria-valuemax={Math.round(duration)}\n aria-valuenow={Math.round(time)}\n aria-valuetext={labels.time(formatClock(time), formatClock(duration))}\n className={s.wave()}\n onPointerDown={(event) => {\n dragging.current = true;\n wave.current?.setPointerCapture?.(event.pointerId);\n seek(at(event.clientX));\n }}\n onPointerMove={(event) => dragging.current && seek(at(event.clientX))}\n onPointerUp={() => {\n dragging.current = false;\n }}\n onKeyDown={(event) => {\n const moves: Record<string, number> = {\n ArrowLeft: time - 5,\n ArrowDown: time - 5,\n ArrowRight: time + 5,\n ArrowUp: time + 5,\n PageDown: time - 30,\n PageUp: time + 30,\n Home: 0,\n End: duration,\n };\n const to = moves[event.key];\n if (to === undefined) return;\n event.preventDefault();\n seek(to);\n }}\n >\n {shape.map((peak, i) => (\n <span key={i} aria-hidden data-played={(i + 0.5) / bars <= progress ? \"\" : undefined} className={s.bar()} style={{ height: `${Math.round(peak * 100)}%` }} />\n ))}\n </div>\n <div className={s.meta()} aria-hidden>\n <span>{formatClock(time)}</span>\n <span>{formatClock(duration)}</span>\n </div>\n </div>\n {playbackRates.length > 1 && (\n <button\n type=\"button\"\n className={s.speed()}\n aria-label={labels.speed(rate)}\n onClick={() => {\n const next = playbackRates[(playbackRates.indexOf(rate) + 1) % playbackRates.length] ?? 1;\n if (audio.current) audio.current.playbackRate = next;\n setRate(next);\n }}\n >\n {rate}×\n </button>\n )}\n </div>\n );\n}\n","// The bars of a waveform, shared by AudioPlayer (the seekable one) and Waveform (the decorative one). Pure: no React.\n\n/** Resamples peaks to `count` bars (the maximum of each slice), normalised to the loudest. No peaks: a flat line at 15 %. */\nexport function resamplePeaks(peaks: readonly number[], count: number): number[] {\n if (peaks.length === 0) return Array.from({ length: count }, () => 0.15);\n const out = Array.from({ length: count }, (_, i) => {\n const from = Math.floor((i / count) * peaks.length);\n const to = Math.max(from + 1, Math.floor(((i + 1) / count) * peaks.length));\n return Math.max(...peaks.slice(from, to).map(Math.abs));\n });\n const loudest = Math.max(...out, 0.0001);\n return out.map((v) => Math.max(0.08, v / loudest));\n}\n"],"mappings":";;;;;;;;;;;;;AAIA,YAAY,WAAW;AACvB,SAAS,UAAU;;;ACFZ,SAAS,cAAc,OAA0B,OAAyB;AAC/E,MAAI,MAAM,WAAW,EAAG,QAAO,MAAM,KAAK,EAAE,QAAQ,MAAM,GAAG,MAAM,IAAI;AACvE,QAAM,MAAM,MAAM,KAAK,EAAE,QAAQ,MAAM,GAAG,CAAC,GAAG,MAAM;AAClD,UAAM,OAAO,KAAK,MAAO,IAAI,QAAS,MAAM,MAAM;AAClD,UAAM,KAAK,KAAK,IAAI,OAAO,GAAG,KAAK,OAAQ,IAAI,KAAK,QAAS,MAAM,MAAM,CAAC;AAC1E,WAAO,KAAK,IAAI,GAAG,MAAM,MAAM,MAAM,EAAE,EAAE,IAAI,KAAK,GAAG,CAAC;AAAA,EACxD,CAAC;AACD,QAAM,UAAU,KAAK,IAAI,GAAG,KAAK,IAAM;AACvC,SAAO,IAAI,IAAI,CAAC,MAAM,KAAK,IAAI,MAAM,IAAI,OAAO,CAAC;AACnD;;;AD8IM,cA8DE,YA9DF;AA7IC,IAAM,cAAc,GAAG;AAAA,EAC5B,OAAO;AAAA,IACL,MAAM;AAAA,IACN,MACE;AAAA,IAEF,MAAM;AAAA,IACN,OAAO;AAAA,IACP,MACE;A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A,QACnB,cAAY,OAAO,MAAM,IAAI;AAAA,QAC7B,SAAS,MAAM;AACb,gBAAM,OAAO,eAAe,cAAc,QAAQ,IAAI,IAAI,KAAK,cAAc,MAAM,KAAK;AACxF,cAAI,MAAM,QAAS,OAAM,QAAQ,eAAe;AAChD,kBAAQ,IAAI;AAAA,QACd;AAAA,QAEC;AAAA;AAAA,UAAK;AAAA;AAAA;AAAA,IACR;AAAA,KAEJ;AAEJ;","names":[]}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/motion/MotionObserver.tsx","../src/motion/RotatingWord.tsx"],"sourcesContent":["import { useEffect } from \"react\";\n\n/** What gets `data-offscreen` while out of view: its animations pause (motion.css). */\nconst SCOPES = \".kz-backdrop, .kz-iso, [data-motion-scope], main > section, main > header, footer\";\nconst REVEAL = \"[data-reveal]:not(.kz-in)\";\n/** How long after `load` the first screen's loops wait before they start (LCP first). */\nconst SETTLE_MS = 1200;\n\nexport interface MotionObserverProps {\n /**\n * Hold the loops of the page (`.kz-loop`, the backdrop's drift) still until the page has loaded and settled\n * (`html[data-motion=\"settling\"]` → `\"ready\"`, about 1.2 s after `load`): nothing repaints the first screen while it\n * paints.\n * @default true\n */\n settle?: boolean;\n /**\n * Pause every animation of a scope while it is off screen (`data-offscreen` on `.kz-backdrop`, `.kz-iso`,\n * `[data-motion-scope]` and the page's sections).\n * @default true\n */\n pauseOffscreen?: boolean;\n}\n\n/**\n * The Krizaka motion conductor. Mount it once at the root of the app; it renders nothing and keeps no animation frame\n * running. It reveals every `[data-reveal]` element once as it enters the viewport (including elements added later:\n * client navigation needs nothing more), pauses what is off screen, lets the first screen settle before its loops\n * start. Nothing follows the pointer (krizaka-ui#393: the spotlight and the magnetic buttons are retired). Under\n * prefers-reduced-motion everything is revealed at once.\n */\nexport function MotionObserver({ settle = true, pauseOffscreen = true }: MotionObserverProps = {}): null {\n useEffect(() => {\n const root = document.documentElement;\n const reduce = window.matchMedia(\"(prefers-reduced-motion: reduce)\").matches;\n\n let settleTimer: ReturnType<typeof setTimeout> | undefined;\n const ready = () => (settleTimer = setTimeout(() => root.setAttribute(\"data-motion\", \"ready\"), SETTLE_MS));\n if (settle && !reduce && root.getAttribute(\"data-motion\") !== \"ready\") {\n root.setAttribute(\"data-motion\", \"settling\");\n if (document.readyState === \"complete\") ready();\n else window.addEventListener(\"load\", ready, { once: true });\n } else root.setAttribute(\"data-motion\", \"ready\");\n\n const revealIo = reduce\n ? null\n : new IntersectionObserver(\n (entries) => {\n for (const entry of entries) {\n if (!entry.isIntersecting) continue;\n entry.target.classList.add(\"kz-in\");\n revealIo!.unobserve(entry.target);\n }\n },\n { rootMargin: \"0px 0px -8% 0px\", threshold: 0.12 },\n );\n const scopeIo = pauseOffscreen\n ? new IntersectionObserver(\n (entries) => {\n for (const entry of entries) entry.target.toggleAttribute(\"data-offscreen\", !entry.isIntersecting);\n },\n { rootMargin: \"120px 0px\" },\n )\n : null;\n\n const reveal = (el: Element) => (revealIo ? revealIo.observe(el) : el.classList.add(\"kz-in\"));\n const watch = (scope: ParentNode) => {\n scope.querySelectorAll(REVEAL).forEach(reveal);\n if (scopeIo) scope.querySelectorAll(SCOPES).forEach((el) => scopeIo.observe(el));\n };\n watch(document);\n const mo = new MutationObserver((records) => {\n for (const record of records)\n record.addedNodes.forEach((node) => {\n if (!(node instanceof Element)) return;\n if (node.matches(REVEAL)) reveal(node);\n if (scopeIo && node.matches(SCOPES)) scopeIo.observe(node);\n watch(node);\n });\n });\n mo.observe(document.body, { childList: true, subtree: true });\n\n return () => {\n clearTimeout(settleTimer);\n window.removeEventListener(\"load\", ready);\n revealIo?.disconnect();\n scopeIo?.disconnect();\n mo.disconnect();\n };\n }, [settle, pauseOffscreen]);\n\n return null;\n}\n","import { useEffect, useState } from \"react\";\n\nexport interface RotatingWordProps {\n /** The alternatives, passed translated; the first one is what the server renders. */\n words: readonly string[];\n /**\n * Milliseconds each word stays.\n * @default 2600\n */\n interval?: number;\n /** Classes for every word (a colour, gradient text). */\n className?: string;\n}\n\n/**\n * A word that rolls through alternatives — the Krizaka headline signature. Every word shares one grid cell from the\n * first paint, so the line keeps the width of the longest one (no layout shift); the current one rolls in. The server\n * render shows the first word; it stays put under prefers-reduced-motion and while the tab is hidden. Decorative\n * (`aria-hidden`): give the heading a stable accessible label.\n */\nexport function RotatingWord({ words, interval = 2600, className }: RotatingWordProps) {\n const [i, setI] = useState(0);\n useEffect(() => {\n if (words.length < 2 || window.matchMedia(\"(prefers-reduced-motion: reduce)\").matches) return;\n const timer = setInterval(() => {\n if (!document.hidden) setI((k) => (k + 1) % words.length);\n }, interval);\n return () => clearInterval(timer);\n }, [words.length, interval]);\n return (\n <span aria-hidden className=\"kz-rotating\">\n {words.map((word, k) => (\n <span key={word} data-active={k === i} className={className}>\n {word}\n </span>\n ))}\n </span>\n );\n}\n"],"mappings":";;;AAAA,SAAS,iBAAiB;AAG1B,IAAM,SAAS;AACf,IAAM,SAAS;AAEf,IAAM,YAAY;AAyBX,SAAS,eAAe,EAAE,SAAS,MAAM,iBAAiB,KAAK,IAAyB,CAAC,GAAS;AACvG,YAAU,MAAM;AACd,UAAM,OAAO,SAAS;AACtB,UAAM,SAAS,OAAO,WAAW,kCAAkC,EAAE;AAErE,QAAI;AACJ,UAAM,QAAQ,MAAO,cAAc,WAAW,MAAM,KAAK,aAAa,eAAe,OAAO,GAAG,SAAS;AACxG,QAAI,UAAU,CAAC,UAAU,KAAK,aAAa,aAAa,MAAM,SAAS;AACrE,WAAK,aAAa,eAAe,UAAU;AAC3C,UAAI,SAAS,eAAe,WAAY,OAAM;AAAA,UACzC,QAAO,iBAAiB,QAAQ,OAAO,EAAE,MAAM,KAAK,CAAC;AAAA,IAC5D,MAAO,MAAK,aAAa,eAAe,OAAO;AAE/C,UAAM,WAAW,SACb,OACA,IAAI;AAAA,MACF,CAAC,YAAY;AACX,mBAAW,SAAS,SAAS;AAC3B,cAAI,CAAC,MAAM,eAAgB;AAC3B,gBAAM,OAAO,UAA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OAAO,WAAW,MAAM,UAAU,GAAsB;AACrF,QAAM,CAAC,GAAG,IAAI,IAAI,SAAS,CAAC;AAC5B,EAAAA,WAAU,MAAM;AACd,QAAI,MAAM,SAAS,KAAK,OAAO,WAAW,kCAAkC,EAAE,QAAS;AACvF,UAAM,QAAQ,YAAY,MAAM;AAC9B,UAAI,CAAC,SAAS,OAAQ,MAAK,CAAC,OAAO,IAAI,KAAK,MAAM,MAAM;AAAA,IAC1D,GAAG,QAAQ;AACX,WAAO,MAAM,cAAc,KAAK;AAAA,EAClC,GAAG,CAAC,MAAM,QAAQ,QAAQ,CAAC;AAC3B,SACE,oBAAC,UAAK,eAAW,MAAC,WAAU,eACzB,gBAAM,IAAI,CAAC,MAAM,MAChB,oBAAC,UAAgB,eAAa,MAAM,GAAG,WACpC,kBADQ,IAEX,CACD,GACH;AAEJ;","names":["useEffect"]}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/avatar/avatar.tsx","../src/avatar/default-avatar.ts"],"sourcesContent":["// Client: Radix tracks the image's loading state and shows the fallback until it has loaded (or when it fails).\nimport { Avatar as AvatarPrimitive } from \"radix-ui\";\nimport * as React from \"react\";\nimport { tv, type VariantProps } from \"tailwind-variants\";\n\nimport { type DefaultAvatar, defaultAvatarUrl } from \"./default-avatar\";\n\nconst avatar = tv({\n slots: {\n root: \"relative inline-flex shrink-0 overflow-hidden rounded-full bg-surface-3 align-middle\",\n image: \"h-full w-full object-cover\",\n fallback: \"flex h-full w-full items-center justify-center font-semibold uppercase text-fg-secondary\",\n group: \"flex items-center -space-x-2 [&>*]:ring-2 [&>*]:ring-surface-0\",\n },\n variants: {\n size: {\n xs: { root: \"h-5 w-5 text-[9px]\" },\n sm: { root: \"h-8 w-8 text-xs\" },\n md: { root: \"h-10 w-10 text-sm\" },\n lg: { root: \"h-14 w-14 text-base\" },\n xl: { root: \"h-20 w-20 text-lg\" },\n },\n },\n defaultVariants: { size: \"md\" },\n});\n\nexport type AvatarSize = NonNullable<VariantProps<typeof avatar>[\"size\"]>;\n\nexport type AvatarProps = Omit<React.ComponentProps<\"span\">, \"children\"> & {\n /** The image's URL; `null` or nothing shows the `fallback`. */\n src?: string | null;\n /** The image's text alternative (the person's name); empty when a visible name sits next to the avatar. */\n alt?: string;\n /** Shown while the image loads, when it fails or when there is none: initials, an icon. */\n fallback?: React.ReactNode;\n /** The picture to show instead when `src` is missing or fails to load (an image URL). The `fallback` still covers its own loading. */\n fallbackSrc?: string;\n /**\n * The Krizaka default picture when the person has no photo (or it fails): their brand's gradient and a silhouette,\n * one of six tones from `seed` — `defaultAvatar={{ brand: \"orazaka\", seed: user.id }}`. `fallbackSrc` wins over it.\n */\n defaultAvatar?: DefaultAvatar;\n /**\n * xs · sm · md · lg · xl.\n * @default \"md\"\n */\n size?: AvatarSize;\n};\n\nexport function AvatarRoot({ src, alt = \"\", fallback, fallbackSrc, defaultAvatar, size, className, ...props }: AvatarProps) {\n const s = avatar({ size });\n const [failed, setFailed] = React.useState<string | null>(null);\n // 512 px for the big sizes, 256 for the others: sharp on a 2x screen either way.\n const backup = fallbackSrc ?? (defaultAvatar ? defaultAvatarUrl(defaultAvatar, { size: size === \"xl\" || size === \"lg\" ? 512 : 256 }) : undefined);\n const shown = src && failed !== src ? src : backup;\n return (\n <AvatarPrimitive.Root data-size={size ?? \"md\"} className={s.root({ className })} {...props}>\n {shown && (\n <AvatarPrimitive.Image\n src={shown}\n alt={alt}\n className={s.image()}\n onLoadingStatusChange={(status) => {\n if (status === \"error\" && shown === src) setFailed(src);\n }}\n />\n )}\n <AvatarPrimitive.Fallback delayMs={shown ? 300 : 0} className={s.fallback()}>\n {fallback}\n </AvatarPrimitive.Fallback>\n </AvatarPrimitive.Root>\n );\n}\n\nexport type AvatarGroupProps = React.ComponentProps<\"div\"> & {\n /** How many avatars are shown; the rest becomes a `+n` avatar. */\n max?: number;\n /** The size of the `+n` avatar (match the avatars of the group). */\n size?: AvatarSize;\n};\n\n/** Overlapping avatars; past `max`, a `+n` avatar counts the rest. */\nexport function AvatarGroup({ max, size, className, children, ...props }: AvatarGroupProps) {\n const items = React.Children.toArray(children);\n const shown = max === undefined ? items : items.slice(0, max);\n const rest = items.length - shown.length;\n return (\n <div className={avatar().group({ className })} {...props}>\n {shown}\n {rest > 0 && <AvatarRoot size={size} fallback={`+${rest}`} />}\n </div>\n );\n}\n\n/** `Avatar` (an image with a fallback) and `Avatar.Group`. */\nexport const Avatar = Object.assign(AvatarRoot, { Group: AvatarGroup });\n","// The default profile pictures of the Krizaka family: what a product shows when a person has no photo.\n// They are generated from this file (tools/export-brand.mjs renders them to SVG and WebP and uploads them to Bunny,\n// `people/defaults/v1/<brand>/…`), so the pictures and the URLs that name them cannot drift apart.\n\n/** A brand of the default avatars. `orochia`, `yasakia`, `yororis` and `kachizaka` are deprecated: paused products (2026-10-25), removed in the next major; their pictures stay served until then. */\nexport type DefaultAvatarBrand = \"krizaka\" | \"orazaka\" | \"orochia\" | \"yasakia\" | \"yororis\" | \"yomizaka\" | \"kachizaka\" | \"akinaza\";\n/**\n * What the picture is of. `person`: a neutral silhouette. `plain`: the brand's gradient alone, ready for initials.\n * `folder`, `organisation` and `shop` are the pictures of a thing that is not a person (a folder or collection, a company, a shop):\n * a glyph on the gradient, never a silhouette. The central sets of these kinds are in the Krizaka org JSON (`defaults`, `@krizaka/org`).\n */\nexport type DefaultAvatarKind = \"person\" | \"plain\" | \"folder\" | \"organisation\" | \"shop\";\n/** The kinds of entity that have a set of default pictures of their own (`plain` is a style of `person`). */\nexport type DefaultAvatarEntityKind = \"person\" | \"folder\" | \"organisation\" | \"shop\";\nexport type DefaultAvatarSize = 256 | 512;\n\nexport const DEFAULT_AVATAR_BRANDS: readonly DefaultAvatarBrand[] = [\"krizaka\", \"orazaka\", \"orochia\", \"yasakia\", \"yororis\", \"yomizaka\", \"kachizaka\", \"akinaza\"];\n/** The two styles of the legacy brand sets (`people/defaults/v1/<brand>`); the kinds of the central sets are `DEFAULT_AVATAR_ENTITY_KINDS`. */\nexport const DEFAULT_AVATAR_KINDS: readonly DefaultAvatarKind[] = [\"person\", \"plain\"];\nexport const DEFAULT_AVATAR_ENTITY_KINDS: readonly DefaultAvatarEntityKind[] = [\"person\", \"folder\", \"organisation\", \"shop\"];\nexport const DEFAULT_AVATAR_SIZES: readonly DefaultAvatarSize[] = [256, 512];\n/** How many tones each brand has: a person always gets the same one from their seed, so a list is not one colour. */\nexport const DEFAULT_AVATAR_TONES = 6;\n\n/** Where the set lives. `v1` is the set's version: a changed picture is a new version folder, never an overwrite. */\nexport const DEFAULT_AVATAR_BASE = \"https://krizaka-assets.b-cdn.net/people/defaults/v1\";\n\nexport interface DefaultAvatar {\n /** The brand of the product showing the avatar: its gradient, its hues. */\n brand: DefaultAvatarBrand;\n /** Any stable text or number of the person (their id): the same seed gives the same tone everywhere. */\n seed?: string | number;\n /** Force a tone, 1 to 6, instead of deriving it from `seed`. */\n tone?: number;\n /**\n * `person` (default): a silhouette. `plain`: the gradient alone. `folder`, `organisation`, `shop`: that thing's glyph, drawn here\n * (a data URL, no request) — a folder is never given a person.\n * @default \"person\"\n */\n kind?: DefaultAvatarKind;\n /**\n * The family's central set (`listDefaults(\"person\")` of `@krizaka/org`): when given with a `seed`, the avatar is the set's picture for that seed —\n * the same person has the same picture in every product — instead of the brand's silhouette. An empty set, or no seed, draws the silhouette.\n */\n set?: readonly DefaultAvatarPicture[];\n}\n\n/** The mark gradient of each brand (BRAND.md, `$extensions[\"com.krizaka\"].mark`) as [hue, saturation %, lightness %] and the hue spread of its tones. */\nconst BRANDS: Record<DefaultAvatarBrand, { from: [number, number, number]; to: [number, number, number]; spread: number }> = {\n krizaka: { from: [217, 92, 53], to: [217, 92, 68], spread: 14 },\n orazaka: { from: [26, 90.5, 37.1], to: [26, 92, 45], spread: 7 },\n orochia: { from: [262.1, 83.3, 57.8], to: [328.6, 85.5, 70.2], spread: 12 },\n yasakia: { from: [156, 92, 32], to: [178, 90, 32], spread: 12 },\n yororis: { from: [34, 46, 44], to: [104, 28, 42], spread: 10 },\n yomizaka: { from: [232, 50, 55], to: [248, 50, 58], spread: 10 },\n kachizaka: { from: [226, 80, 56], to: [44, 92, 33], spread: 10 },\n akinaza: { from: [140, 48, 34], to: [22, 60, 46], spread: 10 },\n};\n\n/** White on top of a stop must stay visible: a stop is darkened until the contrast reaches this (WCAG 1.4.11, non-text). */\nconst MIN_CONTRAST = 3.2;\nconst OFFSETS = [0, -1, 1, -2, 2, 3] as const;\n\nfunction hslToHex([h, s, l]: [number, number, number]): string {\n const sat = s / 100;\n const light = l / 100;\n const k = (n: number) => (n + (((h % 360) + 360) % 360) / 30) % 12;\n const a = sat * Math.min(light, 1 - light);\n const channel = (n: number) => Math.round(255 * (light - a * Math.max(-1, Math.min(k(n) - 3, 9 - k(n), 1))));\n return `#${[0, 8, 4].map((n) => channel(n).toString(16).padStart(2, \"0\")).join(\"\")}`;\n}\n\nconst channelLuminance = (v: number) => (v <= 0.03928 ? v / 12.92 : ((v + 0.055) / 1.055) ** 2.4);\nconst whiteContrast = (hex: string) => {\n const [r, g, b] = [1, 3, 5].map((i) => channelLuminance(Number.parseInt(hex.slice(i, i + 2), 16) / 255));\n return 1.05 / (0.2126 * r! + 0.7152 * g! + 0.0722 * b! + 0.05);\n};\n/** The stop, darkened one point of lightness at a time until white reads on it. */\nfunction readable([h, s, l]: [number, number, number]): string {\n let hex = hslToHex([h, s, l]);\n for (let light = l; whiteContrast(hex) < MIN_CONTRAST && light > 10; light -= 1) hex = hslToHex([h, s, light]);\n return hex;\n}\n\n/** The two stops (hex) of tone `tone` (1 to 6) of a brand. */\nexport function defaultAvatarTone(brand: DefaultAvatarBrand, tone: number): readonly [string, string] {\n const b = BRANDS[brand];\n const o = OFFSETS[(clampTone(tone) - 1) % OFFSETS.length] * b.spread;\n return [readable([b.from[0] + o, b.from[1], b.from[2]]), readable([b.to[0] + o, b.to[1], b.to[2]])];\n}\n\nconst clampTone = (tone: number) => Math.min(DEFAULT_AVATAR_TONES, Math.max(1, Math.round(tone)));\n\n/** 32-bit FNV-1a of a seed: the rule of the family's default pictures (`@krizaka/org`'s `seedHash` is the same function). */\nexport function defaultAvatarSeedHash(seed: string | number): number {\n let h = 0x811c9dc5;\n for (const ch of String(seed)) {\n h ^= ch.codePointAt(0)!;\n h = Math.imul(h, 0x01000193) >>> 0;\n }\n return h;\n}\n\n/** 1 to 6 from a seed (FNV-1a): stable across renders, devices and products. */\nexport function defaultAvatarToneOf(seed: string | number | undefined): number {\n if (seed === undefined) return 1;\n return (defaultAvatarSeedHash(seed) % DEFAULT_AVATAR_TONES) + 1;\n}\n\n/**\n * One picture of the family's central set, as `@krizaka/org` lists it (`listDefaults(\"person\")` items fit as they are): the sizes it is served in.\n * `disabled` pictures are never picked.\n */\nexport interface DefaultAvatarPicture {\n id: string;\n disabled?: boolean;\n urls: { webp: Readonly<Record<string, string>> };\n}\n\n/** The picture a seed gets from a set: `set[fnv1a(seed) mod n]` among the pictures not disabled, in the set's order — the same rule as `@krizaka/org`'s `defaultFor`. */\nexport function pickDefaultPicture<T extends DefaultAvatarPicture>(set: readonly T[], seed: string | number): T | undefined {\n const usable = set.filter((picture) => !picture.disabled);\n return usable[defaultAvatarSeedHash(seed) % usable.length];\n}\n\nconst resolveTone = (a: DefaultAvatar) => (a.tone === undefined ? defaultAvatarToneOf(a.seed) : clampTone(a.tone));\n\n/** The file name of a picture in the set: `person-3` + 256 → `person-3-256.webp`; `svg` has no size. */\nexport function defaultAvatarFile(kind: DefaultAvatarKind, tone: number, size: DefaultAvatarSize | \"svg\"): string {\n return size === \"svg\" ? `${kind}-${tone}.svg` : `${kind}-${tone}-${size}.webp`;\n}\n\n/** Linear on purpose: a `/\\/+$/` regex backtracks quadratically on a long run of slashes. */\nfunction trimTrailingSlashes(value: string): string {\n let end = value.length;\n while (end > 0 && value[end - 1] === \"/\") end--;\n return value.slice(0, end);\n}\n\n/**\n * The URL of a default avatar: `defaultAvatarUrl({ brand: \"orazaka\", seed: user.id })`.\n * @param size 256 for lists, 512 for a profile; `\"svg\"` for the vector.\n * @param base Another host or version of the set (a self-hosted copy); the default is the Krizaka CDN.\n */\nexport function defaultAvatarUrl(avatar: DefaultAvatar, { size = 256, base = DEFAULT_AVATAR_BASE }: { size?: DefaultAvatarSize | \"svg\"; base?: string } = {}): string {\n if (isGlyphKind(avatar.kind)) return defaultAvatarDataUrl(avatar);\n if (avatar.set && avatar.seed !== undefined) {\n // The size asked, as the set serves it (256 and 512; the vector has none, so it stays the brand's silhouette).\n const picked = pickDefaultPicture(avatar.set, avatar.seed)?.urls.webp[size];\n if (picked) return picked;\n }\n return `${trimTrailingSlashes(base)}/${avatar.brand}/${defaultAvatarFile(avatar.kind ?? \"person\", resolveTone(avatar), size)}`;\n}\n\nconst GLYPHS: Record<\"folder\" | \"organisation\" | \"shop\", (from: string) => string> = {\n folder: () => `<path d=\"M96 176a28 28 0 0 1 28-28h92l40 44h132a28 28 0 0 1 28 28v152a28 28 0 0 1-28 28H124a28 28 0 0 1-28-28z\" fill=\"#fff\" fill-opacity=\".92\"/>`,\n organisation: (from) =>\n `<rect x=\"136\" y=\"104\" width=\"240\" height=\"304\" rx=\"16\" fill=\"#fff\" fill-opacity=\".92\"/>${[160, 226, 292]\n .flatMap((y) => [168, 236, 304].map((x) => `<rect x=\"${x}\" y=\"${y}\" width=\"40\" height=\"40\" rx=\"6\" fill=\"${from}\"/>`))\n .join(\"\")}<rect x=\"232\" y=\"352\" width=\"48\" height=\"56\" rx=\"6\" fill=\"${from}\"/>`,\n shop: (from) =>\n `<path d=\"M112 132h288l24 84a56 56 0 0 1-112 0 56 56 0 0 1-112 0 56 56 0 0 1-112 0z\" fill=\"#fff\" fill-opacity=\".92\"/><rect x=\"136\" y=\"292\" width=\"240\" height=\"116\" rx=\"12\" fill=\"#fff\" fill-opacity=\".92\"/><rect x=\"226\" y=\"326\" width=\"60\" height=\"82\" rx=\"8\" fill=\"${from}\"/><rect x=\"156\" y=\"318\" width=\"48\" height=\"44\" rx=\"6\" fill=\"${from}\"/><rect x=\"308\" y=\"318\" width=\"48\" height=\"44\" rx=\"6\" fill=\"${from}\"/>`,\n};\n\ntype GlyphKind = keyof typeof GLYPHS;\nconst isGlyphKind = (kind: DefaultAvatarKind | undefined): kind is GlyphKind => kind === \"folder\" || kind === \"organisation\" || kind === \"shop\";\n\n/** The picture as a `data:` URL: nothing to fetch, so a folder, an organisation or a shop always has its picture (offline, in a test, before the CDN answers). */\nexport function defaultAvatarDataUrl(avatar: DefaultAvatar): string {\n return `data:image/svg+xml,${encodeURIComponent(defaultAvatarSvg(avatar))}`;\n}\n\n/** The SVG source of a default avatar, 512 × 512 and square (the Avatar clips it round). */\nexport function defaultAvatarSvg(avatar: DefaultAvatar): string {\n const [from, to] = defaultAvatarTone(avatar.brand, resolveTone(avatar));\n const kind = avatar.kind ?? \"person\";\n const person = isGlyphKind(kind)\n ? GLYPHS[kind](from)\n : kind === \"person\"\n ? `<circle cx=\"256\" cy=\"200\" r=\"86\" fill=\"#fff\" fill-opacity=\".92\"/><path d=\"M84 512c0-108 78-182 172-182s172 74 172 182z\" fill=\"#fff\" fill-opacity=\".92\"/>`\n : \"\";\n return `<svg xmlns=\"http://www.w3.org/2000/svg\" viewBox=\"0 0 512 512\" width=\"512\" height=\"512\"><defs><linearGradient id=\"g\" x1=\"0\" y1=\"0\" x2=\"1\" y2=\"1\"><stop offset=\"0\" stop-color=\"${from}\"/><stop offset=\"1\" stop-color=\"${to}\"/></linearGradient><radialGradient id=\"l\" cx=\".28\" cy=\".18\" r=\".85\"><stop offset=\"0\" stop-color=\"#fff\" stop-opacity=\".24\"/><stop offset=\"1\" stop-color=\"#fff\" stop-opacity=\"0\"/></radialGradient></defs><rect width=\"512\" height=\"512\" fill=\"url(#g)\"/><rect width=\"512\" height=\"512\" fill=\"url(#l)\"/>${person}</svg>`;\n}\n"],"mappings":";;;AACA,SAAS,UAAU,uBAAuB;AAC1C,YAAY,WAAW;AACvB,SAAS,UAA6B;;;ACmB/B,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