@tarve/svelte 0.7.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 +2 -2
- package/src/dom-animation.ts +89 -0
- package/src/dom.ts +50 -95
- package/src/elements.d.ts +1 -1
- package/src/events.ts +4 -1
- package/src/render.ts +11 -4
- package/src/selectors.ts +0 -7
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tarve/svelte",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.9.0",
|
|
4
4
|
"description": "Svelte 5 components in native Tarve windows",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"type": "module",
|
|
@@ -43,7 +43,7 @@
|
|
|
43
43
|
"svelte": "^5.57.2"
|
|
44
44
|
},
|
|
45
45
|
"peerDependencies": {
|
|
46
|
-
"@tarve/core": "^0.
|
|
46
|
+
"@tarve/core": "^0.9.0"
|
|
47
47
|
},
|
|
48
48
|
"engines": {
|
|
49
49
|
"bun": ">=1.4.0",
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
|
|
2
|
+
export type Keyframe = { offset: number; values: Record<string, string> };
|
|
3
|
+
|
|
4
|
+
/** Keyframes with offsets (missing ones spread evenly, as Web Animations does). */
|
|
5
|
+
export function keyframesOf(input: Record<string, string | number | null | undefined>[]): Keyframe[] {
|
|
6
|
+
const frames = input.map(frame => {
|
|
7
|
+
const values: Record<string, string> = {};
|
|
8
|
+
for (const [key, value] of Object.entries(frame)) if (key !== "offset" && key !== "easing" && key !== "composite" && value != null) values[key] = String(value);
|
|
9
|
+
return { offset: typeof frame.offset === "number" ? frame.offset : NaN, values };
|
|
10
|
+
});
|
|
11
|
+
if (frames.length === 1) frames.unshift({ offset: 0, values: { ...frames[0]!.values } });
|
|
12
|
+
frames.forEach((frame, index) => { if (Number.isNaN(frame.offset)) frame.offset = frames.length > 1 ? index / (frames.length - 1) : 0; });
|
|
13
|
+
return frames.sort((a, b) => a.offset - b.offset);
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
export const COLOR = /#([0-9a-f]{3,8})\b|rgba?\(([^)]*)\)/gi;
|
|
17
|
+
/** Colours as `rgba(r, g, b, a)`, so they interpolate as numbers. */
|
|
18
|
+
export function normalizeColors(value: string): string {
|
|
19
|
+
return value.replace(COLOR, (_match, hex: string | undefined, rgb: string | undefined) => {
|
|
20
|
+
if (rgb !== undefined) {
|
|
21
|
+
const parts = rgb.split(/[\s,/]+/).filter(Boolean).map(Number);
|
|
22
|
+
return `rgba(${parts[0] ?? 0}, ${parts[1] ?? 0}, ${parts[2] ?? 0}, ${parts[3] ?? 1})`;
|
|
23
|
+
}
|
|
24
|
+
let digits = hex!;
|
|
25
|
+
if (digits.length <= 4) digits = [...digits].map(char => char + char).join("");
|
|
26
|
+
const value = (index: number) => parseInt(digits.slice(index, index + 2), 16);
|
|
27
|
+
return `rgba(${value(0)}, ${value(2)}, ${value(4)}, ${digits.length === 8 ? value(6) / 255 : 1})`;
|
|
28
|
+
});
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
export const NUMBER = /-?\d*\.?\d+(?:e-?\d+)?/gi;
|
|
32
|
+
/** Interpolates two CSS values number by number when they share a shape; else switches halfway. */
|
|
33
|
+
export function mix(from: string, to: string, t: number): string {
|
|
34
|
+
const a = normalizeColors(from), b = normalizeColors(to);
|
|
35
|
+
const shapeA = a.replace(NUMBER, "#"), shapeB = b.replace(NUMBER, "#");
|
|
36
|
+
if (shapeA !== shapeB) return t < 0.5 ? from : to;
|
|
37
|
+
const numbersB = b.match(NUMBER) ?? [];
|
|
38
|
+
let index = 0;
|
|
39
|
+
return a.replace(NUMBER, number => {
|
|
40
|
+
const start = Number(number), end = Number(numbersB[index++]);
|
|
41
|
+
const value = start + (end - start) * t;
|
|
42
|
+
return String(Math.round(value * 1000) / 1000);
|
|
43
|
+
});
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
export function interpolateFrames(frames: Keyframe[], progress: number): Record<string, string> | undefined {
|
|
47
|
+
if (!frames.length) return undefined;
|
|
48
|
+
if (progress <= frames[0]!.offset) return frames[0]!.values;
|
|
49
|
+
for (let index = 1; index < frames.length; index++) {
|
|
50
|
+
const previous = frames[index - 1]!, next = frames[index]!;
|
|
51
|
+
if (progress > next.offset) continue;
|
|
52
|
+
const span = next.offset - previous.offset;
|
|
53
|
+
const t = span ? (progress - previous.offset) / span : 1;
|
|
54
|
+
const out: Record<string, string> = {};
|
|
55
|
+
for (const key of new Set([...Object.keys(previous.values), ...Object.keys(next.values)])) {
|
|
56
|
+
const from = previous.values[key], to = next.values[key];
|
|
57
|
+
out[key] = from === undefined ? to! : to === undefined ? from : mix(from, to, t);
|
|
58
|
+
}
|
|
59
|
+
return out;
|
|
60
|
+
}
|
|
61
|
+
return frames[frames.length - 1]!.values;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
/** A CSS timing function as a function of progress. */
|
|
65
|
+
export function easing(name: string): (t: number) => number {
|
|
66
|
+
const bezier = (x1: number, y1: number, x2: number, y2: number) => (t: number) => {
|
|
67
|
+
// Solve x(u) = t by Newton's method, then return y(u).
|
|
68
|
+
let u = t;
|
|
69
|
+
for (let index = 0; index < 8; index++) {
|
|
70
|
+
const x = 3 * x1 * u * (1 - u) ** 2 + 3 * x2 * u ** 2 * (1 - u) + u ** 3 - t;
|
|
71
|
+
const slope = 3 * x1 * (1 - u) ** 2 + 6 * (x2 - x1) * u * (1 - u) + 3 * (1 - x2) * u ** 2;
|
|
72
|
+
if (Math.abs(x) < 1e-5 || !slope) break;
|
|
73
|
+
u = Math.min(1, Math.max(0, u - x / slope));
|
|
74
|
+
}
|
|
75
|
+
return 3 * y1 * u * (1 - u) ** 2 + 3 * y2 * u ** 2 * (1 - u) + u ** 3;
|
|
76
|
+
};
|
|
77
|
+
const value = name.trim();
|
|
78
|
+
if (value === "ease") return bezier(0.25, 0.1, 0.25, 1);
|
|
79
|
+
if (value === "ease-in") return bezier(0.42, 0, 1, 1);
|
|
80
|
+
if (value === "ease-out") return bezier(0, 0, 0.58, 1);
|
|
81
|
+
if (value === "ease-in-out") return bezier(0.42, 0, 0.58, 1);
|
|
82
|
+
const cubic = /^cubic-bezier\(([^)]*)\)$/.exec(value);
|
|
83
|
+
if (cubic) { const [a = 0, b = 0, c = 1, e = 1] = cubic[1]!.split(",").map(Number); return bezier(a, b, c, e); }
|
|
84
|
+
const steps = /^steps\(\s*(\d+)\s*(?:,\s*(start|end|jump-start|jump-end))?\s*\)$/.exec(value);
|
|
85
|
+
if (steps) { const count = Number(steps[1]); const start = steps[2]?.includes("start"); return t => Math.min(1, (start ? Math.ceil(t * count) : Math.floor(t * count)) / count); }
|
|
86
|
+
if (value === "step-start") return t => (t > 0 ? 1 : 0);
|
|
87
|
+
if (value === "step-end") return t => (t >= 1 ? 1 : 0);
|
|
88
|
+
return t => t;
|
|
89
|
+
}
|
package/src/dom.ts
CHANGED
|
@@ -5,6 +5,7 @@
|
|
|
5
5
|
*/
|
|
6
6
|
|
|
7
7
|
import { matchesList, parseSelectorList, selectorMatches } from "./selectors";
|
|
8
|
+
import { keyframesOf, interpolateFrames, easing } from "./dom-animation";
|
|
8
9
|
|
|
9
10
|
export const ELEMENT_NODE = 1;
|
|
10
11
|
export const TEXT_NODE = 3;
|
|
@@ -598,94 +599,6 @@ class TClassList {
|
|
|
598
599
|
|
|
599
600
|
const HTML_NAMESPACE = "http://www.w3.org/1999/xhtml";
|
|
600
601
|
|
|
601
|
-
type Keyframe = { offset: number; values: Record<string, string> };
|
|
602
|
-
|
|
603
|
-
/** Keyframes with offsets (missing ones spread evenly, as Web Animations does). */
|
|
604
|
-
function keyframesOf(input: Record<string, string | number | null | undefined>[]): Keyframe[] {
|
|
605
|
-
const frames = input.map(frame => {
|
|
606
|
-
const values: Record<string, string> = {};
|
|
607
|
-
for (const [key, value] of Object.entries(frame)) if (key !== "offset" && key !== "easing" && key !== "composite" && value != null) values[key] = String(value);
|
|
608
|
-
return { offset: typeof frame.offset === "number" ? frame.offset : NaN, values };
|
|
609
|
-
});
|
|
610
|
-
if (frames.length === 1) frames.unshift({ offset: 0, values: { ...frames[0]!.values } });
|
|
611
|
-
frames.forEach((frame, index) => { if (Number.isNaN(frame.offset)) frame.offset = frames.length > 1 ? index / (frames.length - 1) : 0; });
|
|
612
|
-
return frames.sort((a, b) => a.offset - b.offset);
|
|
613
|
-
}
|
|
614
|
-
|
|
615
|
-
const COLOR = /#([0-9a-f]{3,8})\b|rgba?\(([^)]*)\)/gi;
|
|
616
|
-
/** Colours as `rgba(r, g, b, a)`, so they interpolate as numbers. */
|
|
617
|
-
function normalizeColors(value: string): string {
|
|
618
|
-
return value.replace(COLOR, (_match, hex: string | undefined, rgb: string | undefined) => {
|
|
619
|
-
if (rgb !== undefined) {
|
|
620
|
-
const parts = rgb.split(/[\s,/]+/).filter(Boolean).map(Number);
|
|
621
|
-
return `rgba(${parts[0] ?? 0}, ${parts[1] ?? 0}, ${parts[2] ?? 0}, ${parts[3] ?? 1})`;
|
|
622
|
-
}
|
|
623
|
-
let digits = hex!;
|
|
624
|
-
if (digits.length <= 4) digits = [...digits].map(char => char + char).join("");
|
|
625
|
-
const value = (index: number) => parseInt(digits.slice(index, index + 2), 16);
|
|
626
|
-
return `rgba(${value(0)}, ${value(2)}, ${value(4)}, ${digits.length === 8 ? value(6) / 255 : 1})`;
|
|
627
|
-
});
|
|
628
|
-
}
|
|
629
|
-
|
|
630
|
-
const NUMBER = /-?\d*\.?\d+(?:e-?\d+)?/gi;
|
|
631
|
-
/** Interpolates two CSS values number by number when they share a shape; else switches halfway. */
|
|
632
|
-
function mix(from: string, to: string, t: number): string {
|
|
633
|
-
const a = normalizeColors(from), b = normalizeColors(to);
|
|
634
|
-
const shapeA = a.replace(NUMBER, "#"), shapeB = b.replace(NUMBER, "#");
|
|
635
|
-
if (shapeA !== shapeB) return t < 0.5 ? from : to;
|
|
636
|
-
const numbersB = b.match(NUMBER) ?? [];
|
|
637
|
-
let index = 0;
|
|
638
|
-
return a.replace(NUMBER, number => {
|
|
639
|
-
const start = Number(number), end = Number(numbersB[index++]);
|
|
640
|
-
const value = start + (end - start) * t;
|
|
641
|
-
return String(Math.round(value * 1000) / 1000);
|
|
642
|
-
});
|
|
643
|
-
}
|
|
644
|
-
|
|
645
|
-
function interpolateFrames(frames: Keyframe[], progress: number): Record<string, string> | undefined {
|
|
646
|
-
if (!frames.length) return undefined;
|
|
647
|
-
if (progress <= frames[0]!.offset) return frames[0]!.values;
|
|
648
|
-
for (let index = 1; index < frames.length; index++) {
|
|
649
|
-
const previous = frames[index - 1]!, next = frames[index]!;
|
|
650
|
-
if (progress > next.offset) continue;
|
|
651
|
-
const span = next.offset - previous.offset;
|
|
652
|
-
const t = span ? (progress - previous.offset) / span : 1;
|
|
653
|
-
const out: Record<string, string> = {};
|
|
654
|
-
for (const key of new Set([...Object.keys(previous.values), ...Object.keys(next.values)])) {
|
|
655
|
-
const from = previous.values[key], to = next.values[key];
|
|
656
|
-
out[key] = from === undefined ? to! : to === undefined ? from : mix(from, to, t);
|
|
657
|
-
}
|
|
658
|
-
return out;
|
|
659
|
-
}
|
|
660
|
-
return frames[frames.length - 1]!.values;
|
|
661
|
-
}
|
|
662
|
-
|
|
663
|
-
/** A CSS timing function as a function of progress. */
|
|
664
|
-
function easing(name: string): (t: number) => number {
|
|
665
|
-
const bezier = (x1: number, y1: number, x2: number, y2: number) => (t: number) => {
|
|
666
|
-
// Solve x(u) = t by Newton's method, then return y(u).
|
|
667
|
-
let u = t;
|
|
668
|
-
for (let index = 0; index < 8; index++) {
|
|
669
|
-
const x = 3 * x1 * u * (1 - u) ** 2 + 3 * x2 * u ** 2 * (1 - u) + u ** 3 - t;
|
|
670
|
-
const slope = 3 * x1 * (1 - u) ** 2 + 6 * (x2 - x1) * u * (1 - u) + 3 * (1 - x2) * u ** 2;
|
|
671
|
-
if (Math.abs(x) < 1e-5 || !slope) break;
|
|
672
|
-
u = Math.min(1, Math.max(0, u - x / slope));
|
|
673
|
-
}
|
|
674
|
-
return 3 * y1 * u * (1 - u) ** 2 + 3 * y2 * u ** 2 * (1 - u) + u ** 3;
|
|
675
|
-
};
|
|
676
|
-
const value = name.trim();
|
|
677
|
-
if (value === "ease") return bezier(0.25, 0.1, 0.25, 1);
|
|
678
|
-
if (value === "ease-in") return bezier(0.42, 0, 1, 1);
|
|
679
|
-
if (value === "ease-out") return bezier(0, 0, 0.58, 1);
|
|
680
|
-
if (value === "ease-in-out") return bezier(0.42, 0, 0.58, 1);
|
|
681
|
-
const cubic = /^cubic-bezier\(([^)]*)\)$/.exec(value);
|
|
682
|
-
if (cubic) { const [a = 0, b = 0, c = 1, e = 1] = cubic[1]!.split(",").map(Number); return bezier(a, b, c, e); }
|
|
683
|
-
const steps = /^steps\(\s*(\d+)\s*(?:,\s*(start|end|jump-start|jump-end))?\s*\)$/.exec(value);
|
|
684
|
-
if (steps) { const count = Number(steps[1]); const start = steps[2]?.includes("start"); return t => Math.min(1, (start ? Math.ceil(t * count) : Math.floor(t * count)) / count); }
|
|
685
|
-
if (value === "step-start") return t => (t > 0 ? 1 : 0);
|
|
686
|
-
if (value === "step-end") return t => (t >= 1 ? 1 : 0);
|
|
687
|
-
return t => t;
|
|
688
|
-
}
|
|
689
602
|
const TAG_NAMES = new Map<string, [string, string]>();
|
|
690
603
|
|
|
691
604
|
const BOOLEAN_PROPS = ["disabled", "checked", "selected", "required", "readOnly", "multiple", "hidden", "open", "autofocus"] as const;
|
|
@@ -1066,11 +979,12 @@ for (const name of ["placeholder", "name", "src", "href", "alt", "title", "min",
|
|
|
1066
979
|
|
|
1067
980
|
export class THTMLElement extends TElement {}
|
|
1068
981
|
export class TSVGElement extends TElement {}
|
|
1069
|
-
let mediaHook: ((element: THTMLMediaElement, action: "play" | "pause" | "seek", value?: number) => void) | undefined;
|
|
982
|
+
let mediaHook: ((element: THTMLMediaElement, action: "play" | "pause" | "seek" | "audioTrack" | "textTrack", value?: number) => void) | undefined;
|
|
1070
983
|
/** Native playback for `<audio>`: the mount sets this to the app's media controller. */
|
|
1071
984
|
export function setMediaHook(hook: typeof mediaHook): void { mediaHook = hook; }
|
|
1072
985
|
|
|
1073
986
|
const emptyRanges = { length: 0, start: () => 0, end: () => 0 };
|
|
987
|
+
const MEDIA_ERROR_CODES: Record<string, number> = { aborted: 1, network: 2, decode: 3, format: 4 };
|
|
1074
988
|
|
|
1075
989
|
/** HTMLMediaElement over Tarve's native audio: state comes back as media events. */
|
|
1076
990
|
export class THTMLMediaElement extends THTMLElement {
|
|
@@ -1082,7 +996,6 @@ export class THTMLMediaElement extends THTMLElement {
|
|
|
1082
996
|
_mutedValue?: boolean;
|
|
1083
997
|
_seeking = false;
|
|
1084
998
|
readyState = 0;
|
|
1085
|
-
playbackRate = 1;
|
|
1086
999
|
defaultPlaybackRate = 1;
|
|
1087
1000
|
get paused(): boolean { return this._paused; }
|
|
1088
1001
|
set paused(value: boolean) { if (value) this.pause(); else void this.play(); }
|
|
@@ -1095,6 +1008,17 @@ export class THTMLMediaElement extends THTMLElement {
|
|
|
1095
1008
|
this._seeking = true;
|
|
1096
1009
|
mediaHook?.(this, "seek", this._time);
|
|
1097
1010
|
}
|
|
1011
|
+
_playbackRate = 1;
|
|
1012
|
+
/** HTMLMediaElement.playbackRate: faster or slower at the same pitch. */
|
|
1013
|
+
get playbackRate(): number { return this._playbackRate; }
|
|
1014
|
+
set playbackRate(value: number) {
|
|
1015
|
+
const rate = Number(value);
|
|
1016
|
+
if (!Number.isFinite(rate) || rate <= 0 || rate === this._playbackRate) return;
|
|
1017
|
+
this._playbackRate = rate;
|
|
1018
|
+
this._attrVersion++;
|
|
1019
|
+
touch(this);
|
|
1020
|
+
this.dispatchEvent(new TEvent("ratechange"));
|
|
1021
|
+
}
|
|
1098
1022
|
get volume(): number { return this._volume; }
|
|
1099
1023
|
set volume(value: number) {
|
|
1100
1024
|
if (this._volume === value) return;
|
|
@@ -1116,7 +1040,20 @@ export class THTMLMediaElement extends THTMLElement {
|
|
|
1116
1040
|
/** `<video>`: the picture's own size, known from `loadedmetadata` (0 before, and for `<audio>`). */
|
|
1117
1041
|
get videoWidth(): number { return this._videoWidth; }
|
|
1118
1042
|
get videoHeight(): number { return this._videoHeight; }
|
|
1119
|
-
|
|
1043
|
+
_audioTracks: { id: number; label: string; language: string; enabled: boolean }[] = [];
|
|
1044
|
+
/** HTMLMediaElement.audioTracks (Tarve: a plain list; `selectAudioTrack(id)` switches). */
|
|
1045
|
+
get audioTracks() { return this._audioTracks; }
|
|
1046
|
+
selectAudioTrack(id: number): void { mediaHook?.(this, "audioTrack", id); }
|
|
1047
|
+
_textTracks: { id: number; label: string; language: string; enabled: boolean }[] = [];
|
|
1048
|
+
_cueText = "";
|
|
1049
|
+
/** The subtitle streams inside the file (Tarve: a plain list; `selectTextTrack(id | null)` shows one). */
|
|
1050
|
+
get textTracks() { return this._textTracks; }
|
|
1051
|
+
/** The embedded subtitle text shown now. */
|
|
1052
|
+
get cueText(): string { return this._cueText; }
|
|
1053
|
+
selectTextTrack(id: number | null): void { mediaHook?.(this, "textTrack", id ?? undefined); }
|
|
1054
|
+
_buffered = 0;
|
|
1055
|
+
/** One range, from 0 to the end of what is downloaded ahead of the current time. */
|
|
1056
|
+
get buffered() { return this._buffered > 0 ? { length: 1, start: () => 0, end: () => this._buffered } : emptyRanges; }
|
|
1120
1057
|
get played() { return emptyRanges; }
|
|
1121
1058
|
get seekable() { return this._duration > 0 ? { length: 1, start: () => 0, end: () => this._duration } : emptyRanges; }
|
|
1122
1059
|
play(): Promise<void> { mediaHook?.(this, "play"); return Promise.resolve(); }
|
|
@@ -1127,8 +1064,12 @@ export class THTMLMediaElement extends THTMLElement {
|
|
|
1127
1064
|
return /audio\/(mpeg|mp3|wav|ogg|flac|aac|mp4)/.test(type) ? "maybe" : "";
|
|
1128
1065
|
}
|
|
1129
1066
|
/** A native media event: update the state and fire the DOM events a browser would. */
|
|
1130
|
-
_media(event: "loadedmetadata" | "play" | "pause" | "timeupdate" | "seeked" | "ended" | "error", info: { currentTime?: number; duration?: number | null; paused?: boolean; message?: string; videoWidth?: number; videoHeight?: number }): void {
|
|
1067
|
+
_media(event: "loadedmetadata" | "canplay" | "waiting" | "progress" | "audiotracks" | "texttracks" | "cuechange" | "play" | "pause" | "timeupdate" | "seeking" | "seeked" | "ended" | "error", info: { currentTime?: number; duration?: number | null; paused?: boolean; message?: string; code?: string; videoWidth?: number; videoHeight?: number; buffered?: number; audioTracks?: { id: number; label: string; language: string; enabled: boolean; codec?: string; playable?: boolean }[]; textTracks?: { id: number; label: string; language: string; enabled: boolean }[]; cueText?: string }): void {
|
|
1068
|
+
if (info.audioTracks) this._audioTracks = info.audioTracks;
|
|
1069
|
+
if (info.textTracks) this._textTracks = info.textTracks;
|
|
1070
|
+
if (info.cueText !== undefined) this._cueText = info.cueText;
|
|
1131
1071
|
if (info.currentTime !== undefined) this._time = info.currentTime;
|
|
1072
|
+
if (info.buffered !== undefined) this._buffered = info.buffered;
|
|
1132
1073
|
const resized = (info.videoWidth ?? this._videoWidth) !== this._videoWidth || (info.videoHeight ?? this._videoHeight) !== this._videoHeight;
|
|
1133
1074
|
if (info.videoWidth) this._videoWidth = info.videoWidth;
|
|
1134
1075
|
if (info.videoHeight) this._videoHeight = info.videoHeight;
|
|
@@ -1141,13 +1082,23 @@ export class THTMLMediaElement extends THTMLElement {
|
|
|
1141
1082
|
case "play": this._paused = false; this._ended = false; fire("play"); fire("playing"); break;
|
|
1142
1083
|
case "pause": this._paused = true; fire("pause"); break;
|
|
1143
1084
|
case "timeupdate": fire("timeupdate"); break;
|
|
1144
|
-
case "
|
|
1085
|
+
case "waiting": this.readyState = 2; fire("waiting"); break;
|
|
1086
|
+
case "canplay": { const was = this.readyState; this.readyState = 4; if (was < 3) { fire("canplay"); if (!this._paused) fire("playing"); } break; }
|
|
1087
|
+
case "progress": fire("progress"); break;
|
|
1088
|
+
case "audiotracks": fire("audiotrackschange"); break;
|
|
1089
|
+
case "texttracks": fire("texttrackschange"); break;
|
|
1090
|
+
case "cuechange": fire("cuechange"); break;
|
|
1091
|
+
case "seeking": this._seeking = true; fire("seeking"); break; case "seeked": this._seeking = false; fire("seeked"); fire("timeupdate"); break;
|
|
1145
1092
|
// A browser fires `pause` at the end only if no `pause` came before (the native
|
|
1146
1093
|
// engines may send one just ahead of `ended`).
|
|
1147
1094
|
case "ended": this._ended = true; this._paused = true; if (!wasPaused) fire("pause"); fire("ended"); break;
|
|
1148
|
-
case "error": fire("error"); break;
|
|
1095
|
+
case "error": this._error = { code: MEDIA_ERROR_CODES[info.code ?? "decode"] ?? 3, message: info.message ?? "" }; fire("error"); break;
|
|
1149
1096
|
}
|
|
1097
|
+
if (event === "loadedmetadata") this._error = null;
|
|
1150
1098
|
}
|
|
1099
|
+
_error: { code: number; message: string } | null = null;
|
|
1100
|
+
/** HTMLMediaElement.error: `code` 1 aborted, 2 network, 3 decode, 4 source not supported. */
|
|
1101
|
+
get error(): { code: number; message: string } | null { return this._error; }
|
|
1151
1102
|
}
|
|
1152
1103
|
|
|
1153
1104
|
/** DataTransfer for HTML drag and drop between elements of the app. */
|
|
@@ -1303,7 +1254,11 @@ export const windowInstance = new TWindow();
|
|
|
1303
1254
|
const VOID = new Set(["area", "base", "br", "col", "embed", "hr", "img", "input", "link", "meta", "source", "track", "wbr"]);
|
|
1304
1255
|
const ENTITIES: Record<string, string> = { amp: "&", lt: "<", gt: ">", quot: "\"", apos: "'", nbsp: "\u00a0" };
|
|
1305
1256
|
const decode = (text: string) => text.replace(/&(#x[0-9a-f]+|#\d+|[a-z]+);/gi, (match, entity: string) => {
|
|
1306
|
-
if (entity[0] === "#")
|
|
1257
|
+
if (entity[0] === "#") {
|
|
1258
|
+
const code = entity[1]?.toLowerCase() === "x" ? parseInt(entity.slice(2), 16) : parseInt(entity.slice(1), 10);
|
|
1259
|
+
// As HTML: NUL, surrogates and values past U+10FFFF become U+FFFD.
|
|
1260
|
+
return String.fromCodePoint(code > 0 && code <= 0x10ffff && (code < 0xd800 || code > 0xdfff) ? code : 0xfffd);
|
|
1261
|
+
}
|
|
1307
1262
|
return ENTITIES[entity.toLowerCase()] ?? match;
|
|
1308
1263
|
});
|
|
1309
1264
|
const escape = (text: string) => text.replace(/&/g, "&").replace(/</g, "<").replace(/>/g, ">");
|
package/src/elements.d.ts
CHANGED
|
@@ -21,7 +21,7 @@ declare module "svelte/elements" {
|
|
|
21
21
|
/** Drag the window by this element (a custom title bar, a widget body). */
|
|
22
22
|
"drag-region"?: Flag;
|
|
23
23
|
/** Make this element a window control. */
|
|
24
|
-
"window-action"?: "minimize" | "toggleMaximize" | "close" | undefined | null;
|
|
24
|
+
"window-action"?: "minimize" | "toggleMaximize" | "toggleFullscreen" | "close" | undefined | null;
|
|
25
25
|
}
|
|
26
26
|
|
|
27
27
|
export interface SvelteHTMLElements {
|
package/src/events.ts
CHANGED
|
@@ -13,7 +13,10 @@ export function connectNativeEvents(app: AppHandle): () => void {
|
|
|
13
13
|
setFocusHook(element => { if (element) app.focus(nativeIdOf(element)); });
|
|
14
14
|
setMediaHook((element, action, value) => {
|
|
15
15
|
const media = app.media(nativeIdOf(element));
|
|
16
|
-
if (action === "seek") media.seek(value ?? 0);
|
|
16
|
+
if (action === "seek") media.seek(value ?? 0);
|
|
17
|
+
else if (action === "audioTrack") media.setAudioTrack(value ?? 0);
|
|
18
|
+
else if (action === "textTrack") media.setTextTrack(value ?? null);
|
|
19
|
+
else media[action]();
|
|
17
20
|
});
|
|
18
21
|
const off = app.onEvent((event: NativeEvent) => {
|
|
19
22
|
switch (event.type) {
|
package/src/render.ts
CHANGED
|
@@ -165,9 +165,16 @@ function addMedia(element: THTMLMediaElement, out: Record<string, any>): void {
|
|
|
165
165
|
out.onPlay = (info: object) => element._media("play", info);
|
|
166
166
|
out.onPause = (info: object) => element._media("pause", info);
|
|
167
167
|
out.onTimeUpdate = (info: object) => element._media("timeupdate", info);
|
|
168
|
+
out.onSeeking = (info: object) => element._media("seeking", info);
|
|
168
169
|
out.onSeeked = (info: object) => element._media("seeked", info);
|
|
169
170
|
out.onEnded = (info: object) => element._media("ended", info);
|
|
170
|
-
out.
|
|
171
|
+
out.onWaiting = (info: object) => element._media("waiting", info);
|
|
172
|
+
out.onCanPlay = (info: object) => element._media("canplay", info);
|
|
173
|
+
out.onProgress = (info: object) => element._media("progress", info);
|
|
174
|
+
out.onAudioTracksChange = (info: object) => element._media("audiotracks", info);
|
|
175
|
+
out.onTextTracksChange = (info: object) => element._media("texttracks", info);
|
|
176
|
+
out.onCueChange = (info: object) => element._media("cuechange", info);
|
|
177
|
+
out.onError = (message: string, error: { code: string }) => element._media("error", { message, code: error?.code });
|
|
171
178
|
}
|
|
172
179
|
|
|
173
180
|
function addEvents(element: TElement, tag: string, out: Record<string, any>): void {
|
|
@@ -335,7 +342,7 @@ function withGenerated(content: Child, generated: { before?: GeneratedContent; a
|
|
|
335
342
|
/**
|
|
336
343
|
* `<titlebar>`: Tarve's custom title bar (the window drops its native frame). With
|
|
337
344
|
* children they are its content; otherwise it shows `title`. Any element can be a
|
|
338
|
-
* window control with `window-action="minimize|toggleMaximize|close"` and a drag handle with `drag-region`.
|
|
345
|
+
* window control with `window-action="minimize|toggleMaximize|toggleFullscreen|close"` and a drag handle with `drag-region`.
|
|
339
346
|
*/
|
|
340
347
|
function titleBar(element: TElement, out: Record<string, any>): VNode {
|
|
341
348
|
const flag = (name: string) => { const value = element.getAttribute(name); return value === null ? undefined : value !== "false"; };
|
|
@@ -388,13 +395,13 @@ export function build(element: TElement): VNode {
|
|
|
388
395
|
if (tag === "audio") {
|
|
389
396
|
const media = element as THTMLMediaElement;
|
|
390
397
|
settle(element);
|
|
391
|
-
return jsx("audio", { ...out, volume: media.volume, muted: media.muted, autoPlay: element.hasAttribute("autoplay"), loop: element.hasAttribute("loop"), controls: element.hasAttribute("controls") });
|
|
398
|
+
return jsx("audio", { ...out, volume: media.volume, muted: media.muted, playbackRate: media.playbackRate, autoPlay: element.hasAttribute("autoplay"), loop: element.hasAttribute("loop"), controls: element.hasAttribute("controls") });
|
|
392
399
|
}
|
|
393
400
|
if (tag === "video") {
|
|
394
401
|
// The platform decoder draws the picture; CSS object-fit picks how it fills the box.
|
|
395
402
|
const media = element as THTMLMediaElement;
|
|
396
403
|
settle(element);
|
|
397
|
-
return jsx("video", { ...out, volume: media.volume, muted: media.muted, autoPlay: element.hasAttribute("autoplay"), loop: element.hasAttribute("loop"), controls: element.hasAttribute("controls") });
|
|
404
|
+
return jsx("video", { ...out, volume: media.volume, muted: media.muted, playbackRate: media.playbackRate, autoPlay: element.hasAttribute("autoplay"), loop: element.hasAttribute("loop"), controls: element.hasAttribute("controls") });
|
|
398
405
|
}
|
|
399
406
|
if (tag === "input") {
|
|
400
407
|
const type = element.type;
|
package/src/selectors.ts
CHANGED
|
@@ -302,15 +302,8 @@ export function ruleState(selector: Selector): "hover" | "focus" | "focusVisible
|
|
|
302
302
|
return undefined;
|
|
303
303
|
}
|
|
304
304
|
|
|
305
|
-
/** Whether a selector depends on anything but the element's own tag, classes and attributes. */
|
|
306
305
|
/** Whether a selector reads an element's descendants or later siblings (`:has()`). */
|
|
307
306
|
export function usesHas(selector: Selector): boolean {
|
|
308
307
|
return selector.compounds.some(compound => compound.pseudos.some(pseudo => pseudo.kind === "has"
|
|
309
308
|
|| ((pseudo.kind === "not" || pseudo.kind === "is" || pseudo.kind === "where") && pseudo.list.some(usesHas))));
|
|
310
309
|
}
|
|
311
|
-
|
|
312
|
-
export function isContextual(selector: Selector): boolean {
|
|
313
|
-
if (selector.compounds.length > 1) return true;
|
|
314
|
-
return selector.compounds[0]!.pseudos.some(pseudo => pseudo.kind !== "state" && pseudo.kind !== "checked" && pseudo.kind !== "disabled" && pseudo.kind !== "enabled"
|
|
315
|
-
&& pseudo.kind !== "required" && pseudo.kind !== "optional");
|
|
316
|
-
}
|