uifolio 0.4.0 → 0.5.3
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 +171 -157
- package/cli/uifolio.mjs +644 -354
- package/package.json +3 -2
- package/src/components/ui/audio-player.tsx +1 -1
- package/src/components/ui/calendar.tsx +6 -6
- package/src/components/ui/choice.tsx +1 -1
- package/src/components/ui/color-picker.tsx +14 -14
- package/src/components/ui/command-menu.tsx +2 -2
- package/src/components/ui/file-upload.tsx +10 -10
- package/src/components/ui/icon-picker.tsx +13 -13
- package/src/components/ui/motion.tsx +10 -8
- package/src/components/ui/otp-input.tsx +1 -1
- package/src/components/ui/resizable.tsx +6 -6
- package/src/components/ui/rich-text-editor.tsx +8 -8
- package/src/components/ui/stories.tsx +3 -3
- package/src/components/ui/time-picker.tsx +1 -1
- package/src/components/ui/video-player.tsx +50 -50
- package/src/lib/date.ts +30 -30
- package/src/lib/uploader.ts +13 -13
- package/src/lib/use-controllable.ts +9 -9
- package/src/lib/use-hotkeys.ts +1 -1
- package/src/lib/use-theme.ts +2 -2
- package/src/lib/video.ts +12 -12
- package/src/lib/vtt.ts +1 -1
- package/src/components/ui/stories-tokens.ts +0 -18
package/src/lib/video.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
3
|
-
*
|
|
2
|
+
* Video helpers shared by the library components.
|
|
3
|
+
* No dependency: copying this file along with the component is enough.
|
|
4
4
|
*/
|
|
5
5
|
|
|
6
6
|
export type PlayerSource =
|
|
@@ -28,7 +28,7 @@ export function toSourceList(input: PlayerSource | PlayerSource[]): PlayerSource
|
|
|
28
28
|
return Array.isArray(input) ? input : [input]
|
|
29
29
|
}
|
|
30
30
|
|
|
31
|
-
/**
|
|
31
|
+
/** Stable signature, so object URLs are not recreated on every render. */
|
|
32
32
|
export function sourceSignature(input: PlayerSource | PlayerSource[]): string {
|
|
33
33
|
return toSourceList(input)
|
|
34
34
|
.map((source) => {
|
|
@@ -75,7 +75,7 @@ export function youtubeThumbnailFallback(id: string): string {
|
|
|
75
75
|
loop?: boolean
|
|
76
76
|
muted?: boolean
|
|
77
77
|
controls?: boolean
|
|
78
|
-
/**
|
|
78
|
+
/** Host page origin: the YouTube iframe API matches postMessage commands to it. */
|
|
79
79
|
origin?: string
|
|
80
80
|
playsinline?: boolean
|
|
81
81
|
}
|
|
@@ -123,7 +123,7 @@ export function buildEmbedUrl(
|
|
|
123
123
|
|
|
124
124
|
|
|
125
125
|
/* -------------------------------------------------------------------------- */
|
|
126
|
-
/*
|
|
126
|
+
/* Driving the embeds (YouTube / Vimeo) through postMessage */
|
|
127
127
|
/* -------------------------------------------------------------------------- */
|
|
128
128
|
|
|
129
129
|
export type EmbedKind = 'youtube' | 'vimeo'
|
|
@@ -132,12 +132,12 @@ export type EmbedCommand =
|
|
|
132
132
|
| { type: 'play' }
|
|
133
133
|
| { type: 'pause' }
|
|
134
134
|
| { type: 'seek'; time: number }
|
|
135
|
-
/**
|
|
135
|
+
/** Normalized volume 0–1, converted into each platform's unit. */
|
|
136
136
|
| { type: 'volume'; volume: number }
|
|
137
137
|
| { type: 'mute'; muted: boolean }
|
|
138
138
|
| { type: 'rate'; rate: number }
|
|
139
139
|
|
|
140
|
-
/** Message
|
|
140
|
+
/** Message to post into the iframe: a JSON string for YouTube, an object for Vimeo. */
|
|
141
141
|
export function embedCommand(
|
|
142
142
|
kind: EmbedKind,
|
|
143
143
|
command: EmbedCommand,
|
|
@@ -190,10 +190,10 @@ const VIMEO_EVENTS = [
|
|
|
190
190
|
'playbackratechange',
|
|
191
191
|
]
|
|
192
192
|
|
|
193
|
-
/** Messages
|
|
193
|
+
/** Messages to send to the iframe to receive its state and events. */
|
|
194
194
|
export function embedHandshake(kind: EmbedKind): Array<Record<string, unknown> | string> {
|
|
195
195
|
if (kind === 'youtube') {
|
|
196
|
-
//
|
|
196
|
+
// Starts the `infoDelivery` messages (time, duration, state).
|
|
197
197
|
return [JSON.stringify({ event: 'listening', id: 1, channel: 'widget' })]
|
|
198
198
|
}
|
|
199
199
|
return [
|
|
@@ -249,7 +249,7 @@ function parseYoutubeStatus(raw: unknown): EmbedStatus | null {
|
|
|
249
249
|
if (duration !== undefined && duration > 0) status.duration = duration
|
|
250
250
|
|
|
251
251
|
const playerState = toNumber(info.playerState)
|
|
252
|
-
// -1
|
|
252
|
+
// -1 unstarted, 0 ended, 1 playing, 2 paused, 3 buffering, 5 cued.
|
|
253
253
|
if (playerState !== undefined) status.playing = playerState === 1 || playerState === 3
|
|
254
254
|
|
|
255
255
|
const muted = info.muted
|
|
@@ -312,7 +312,7 @@ function parseVimeoStatus(raw: unknown): EmbedStatus | null {
|
|
|
312
312
|
return null
|
|
313
313
|
}
|
|
314
314
|
|
|
315
|
-
/**
|
|
315
|
+
/** Decodes a postMessage sent by the iframe and extracts the playback state. */
|
|
316
316
|
export function parseEmbedMessage(kind: EmbedKind, raw: unknown): EmbedStatus | null {
|
|
317
317
|
return kind === 'youtube' ? parseYoutubeStatus(raw) : parseVimeoStatus(raw)
|
|
318
318
|
}
|
|
@@ -335,7 +335,7 @@ export function formatTime(value: number): string {
|
|
|
335
335
|
return `${minutes}:${paddedSeconds}`
|
|
336
336
|
}
|
|
337
337
|
|
|
338
|
-
/** "16/9" | 16/9 | 1.77 | "auto" ->
|
|
338
|
+
/** "16/9" | 16/9 | 1.77 | "auto" -> CSS aspect-ratio value. */
|
|
339
339
|
export function toAspectRatio(value: string | number | undefined): string | undefined {
|
|
340
340
|
if (value == null) return undefined
|
|
341
341
|
if (typeof value === 'number') return String(value)
|
package/src/lib/vtt.ts
CHANGED
|
@@ -57,7 +57,7 @@ function cleanCueText(lines: string[]): string {
|
|
|
57
57
|
.trim()
|
|
58
58
|
}
|
|
59
59
|
|
|
60
|
-
/**
|
|
60
|
+
/** Parses a WebVTT file into cues. Tolerant: skips headers, notes, styles and invalid blocks. */
|
|
61
61
|
export function parseVtt(raw: string): VttCue[] {
|
|
62
62
|
const lines = raw
|
|
63
63
|
.replace(/^\uFEFF/, '')
|
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
const accentToScheme: Record<string, { dark: string; light: string; foreground: string; background: string }> = {
|
|
2
|
-
'#10b981': {
|
|
3
|
-
dark: '#0f172a',
|
|
4
|
-
light: '#0f172a',
|
|
5
|
-
foreground: '#f1f5f9',
|
|
6
|
-
background: '#ecfdf5',
|
|
7
|
-
},
|
|
8
|
-
default: {
|
|
9
|
-
dark: '#f8fafc',
|
|
10
|
-
light: '#0f172a',
|
|
11
|
-
foreground: '#0f172a',
|
|
12
|
-
background: '#ffffff',
|
|
13
|
-
},
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
export function accentTokens(accent: string) {
|
|
17
|
-
return accentToScheme[accent] ?? accentToScheme.default
|
|
18
|
-
}
|