Skip to content

Commit e1f8bd5

Browse files
committed
perf(player): use private class fields and methods
1 parent b1cb41e commit e1f8bd5

155 files changed

Lines changed: 5212 additions & 6783 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

packages/react/mangle.json

Lines changed: 0 additions & 804 deletions
This file was deleted.

packages/react/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@
4949
"rollup": "^4.0.0",
5050
"rollup-plugin-dts": "^6.0.0",
5151
"rollup-plugin-esbuild": "^6.1.0",
52+
"tslib": "^2.6.0",
5253
"type-fest": "^3.8.0",
5354
"typescript": "^5.3.0",
5455
"vidstack": "workspace:*",

packages/react/rollup.config.js

Lines changed: 10 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,8 @@ import { fileURLToPath } from 'node:url';
33

44
import { nodeResolve } from '@rollup/plugin-node-resolve';
55
import chokidar from 'chokidar';
6-
import { build, transform as esbuildTransform } from 'esbuild';
6+
import { transform as esbuildTransform } from 'esbuild';
77
import fsExtra from 'fs-extra';
8-
import { globbySync } from 'globby';
98
import { defineConfig } from 'rollup';
109
import dts from 'rollup-plugin-dts';
1110
import esbuildPlugin from 'rollup-plugin-esbuild';
@@ -15,9 +14,6 @@ import { copyPkgInfo } from '../../.scripts/copy-pkg-info.js';
1514
const MODE_WATCH = process.argv.includes('-w'),
1615
MODE_TYPES = process.argv.includes('--config-types');
1716

18-
/** @type {Record<string, string | false>} */
19-
const MANGLE_CACHE = !MODE_TYPES ? await buildMangleCache() : {};
20-
2117
const DIRNAME = path.dirname(fileURLToPath(import.meta.url)),
2218
ROOT_DIR = path.resolve(DIRNAME, '.'),
2319
DIST_NPM_DIR = path.resolve(ROOT_DIR, 'dist-npm'),
@@ -133,6 +129,11 @@ function defineTypesBundle() {
133129
function defineNPMBundle({ dev }) {
134130
let alias = dev ? 'dev' : 'prod';
135131

132+
const target = 'es2022',
133+
supported = {
134+
'class-static-blocks': false,
135+
};
136+
136137
let input = {
137138
vidstack: 'src/index.ts',
138139
'player/vidstack-remotion': 'src/providers/remotion/index.ts',
@@ -195,11 +196,9 @@ function defineNPMBundle({ dev }) {
195196
}),
196197
esbuildPlugin({
197198
tsconfig: 'tsconfig.build.json',
198-
target: 'es2021',
199+
target,
200+
supported,
199201
platform: 'browser',
200-
mangleProps: !dev ? /^_/ : undefined,
201-
mangleCache: !dev ? MANGLE_CACHE : undefined,
202-
reserveProps: !dev ? /^__/ : undefined,
203202
define: {
204203
__DEV__: dev ? 'true' : 'false',
205204
},
@@ -209,7 +208,8 @@ function defineNPMBundle({ dev }) {
209208
transform(code, id) {
210209
if (/node_modules.*?\.js/.test(id)) {
211210
return esbuildTransform(code, {
212-
target: 'es2021',
211+
target,
212+
supported,
213213
platform: 'browser',
214214
}).then((t) => t.code);
215215
}
@@ -283,41 +283,3 @@ async function buildDefaultTheme() {
283283

284284
await fsExtra.writeFile(`${themeDir}/theme.css`, defaultStyles);
285285
}
286-
287-
export async function buildMangleCache() {
288-
let mangleCache = JSON.parse(await fsExtra.readFile('mangle.json', 'utf-8'));
289-
290-
const result = await build({
291-
entryPoints: globbySync('src/**', {
292-
ignoreFiles: ['*.test'],
293-
}),
294-
target: 'esnext',
295-
bundle: true,
296-
minify: false,
297-
mangleProps: /^_/,
298-
reserveProps: /^__/,
299-
mangleCache,
300-
write: false,
301-
outdir: 'dist-esbuild',
302-
plugins: [
303-
{
304-
name: 'externalize',
305-
setup(build) {
306-
let filter = /^[^.\/]|^\.[^.\/]|^\.\.[^\/]/;
307-
build.onResolve({ filter }, (args) =>
308-
args.path === 'vidstack' ? undefined : { path: args.path, external: true },
309-
);
310-
},
311-
},
312-
],
313-
});
314-
315-
mangleCache = {
316-
...mangleCache,
317-
...result.mangleCache,
318-
};
319-
320-
await fsExtra.writeFile('mangle.json', JSON.stringify(mangleCache, null, 2) + '\n');
321-
322-
return mangleCache;
323-
}

packages/react/src/hooks/options/use-video-quality-options.ts

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -24,23 +24,21 @@ export function useVideoQualityOptions({
2424

2525
return React.useMemo(() => {
2626
const sortedQualities = sortVideoQualities($qualities, sort === 'descending'),
27-
options = sortedQualities.map<VideoQualityOption>((_quality) => {
27+
options = sortedQualities.map<VideoQualityOption>((q) => {
2828
return {
29-
quality: _quality,
30-
label: _quality.height + 'p',
31-
value: getQualityValue(_quality),
29+
quality: q,
30+
label: q.height + 'p',
31+
value: getQualityValue(q),
3232
bitrateText:
33-
_quality.bitrate && _quality.bitrate > 0
34-
? `${(_quality.bitrate / 1000000).toFixed(2)} Mbps`
35-
: null,
33+
q.bitrate && q.bitrate > 0 ? `${(q.bitrate / 1000000).toFixed(2)} Mbps` : null,
3634
get selected() {
37-
return _quality === quality();
35+
return q === quality();
3836
},
3937
get autoSelected() {
4038
return autoQuality();
4139
},
4240
select(trigger) {
43-
const index = qualities().indexOf(_quality);
41+
const index = qualities().indexOf(q);
4442
if (index >= 0) media.remote.changeQuality(index, trigger);
4543
},
4644
};

packages/react/src/providers/remotion/layout-engine.ts

Lines changed: 38 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -3,53 +3,53 @@ import { animationFrameThrottle, createDisposalBin } from 'maverick.js/std';
33
import type { RemotionSrc } from './types';
44

55
export class RemotionLayoutEngine {
6-
protected _src: RemotionSrc | null = null;
7-
protected _viewport: HTMLElement | null = null;
8-
protected _canvas: HTMLElement | null = null;
9-
protected _container: HTMLElement | null = null;
10-
protected _disposal = createDisposalBin();
6+
#src: RemotionSrc | null = null;
7+
#viewport: HTMLElement | null = null;
8+
#canvas: HTMLElement | null = null;
9+
#container: HTMLElement | null = null;
10+
#disposal = createDisposalBin();
1111

1212
constructor() {}
1313

1414
setSrc(src: RemotionSrc | null) {
15-
this._src = src;
16-
this.setContainer(this._container);
15+
this.#src = src;
16+
this.setContainer(this.#container);
1717
}
1818

1919
setContainer(container: HTMLElement | null) {
2020
if (__SERVER__) return;
2121

22-
this._disposal.empty();
22+
this.#disposal.empty();
2323

24-
this._container = container;
25-
this._canvas = container?.parentElement ?? null;
26-
this._viewport = this._canvas?.parentElement ?? null;
24+
this.#container = container;
25+
this.#canvas = container?.parentElement ?? null;
26+
this.#viewport = this.#canvas?.parentElement ?? null;
2727

28-
if (this._src && this._viewport) {
29-
const onResize = animationFrameThrottle(this._onResize.bind(this));
28+
if (this.#src && this.#viewport) {
29+
const onResize = animationFrameThrottle(this.#onResize.bind(this));
3030

3131
onResize();
3232
const observer = new ResizeObserver(onResize);
33-
observer.observe(this._viewport);
33+
observer.observe(this.#viewport);
3434

35-
this._disposal.add(() => observer.disconnect());
35+
this.#disposal.add(() => observer.disconnect());
3636
}
3737
}
3838

3939
destroy() {
40-
this._disposal.empty();
40+
this.#disposal.empty();
4141
}
4242

43-
protected _onResize(entries?: ResizeObserverEntry[]) {
44-
if (!this._viewport || !this._src) return;
43+
#onResize(entries?: ResizeObserverEntry[]) {
44+
if (!this.#viewport || !this.#src) return;
4545

46-
const rect = this._getRect(this._viewport, entries?.[0]),
47-
scale = this._calcScale(rect),
48-
transform = this._calcTransform(rect, scale);
46+
const rect = this.#getRect(this.#viewport, entries?.[0]),
47+
scale = this.#calcScale(rect),
48+
transform = this.#calcTransform(rect, scale);
4949

50-
Object.assign(this._canvas!.style, {
51-
width: this._src.compositionWidth! * scale + 'px',
52-
height: this._src.compositionHeight! * scale + 'px',
50+
Object.assign(this.#canvas!.style, {
51+
width: this.#src.compositionWidth! * scale + 'px',
52+
height: this.#src.compositionHeight! * scale + 'px',
5353
display: 'flex',
5454
flexDirection: 'column',
5555
position: 'absolute',
@@ -58,10 +58,10 @@ export class RemotionLayoutEngine {
5858
overflow: 'hidden',
5959
});
6060

61-
Object.assign(this._container!.style, {
61+
Object.assign(this.#container!.style, {
6262
position: 'absolute',
63-
width: this._src.compositionWidth + 'px',
64-
height: this._src.compositionHeight + 'px',
63+
width: this.#src.compositionWidth + 'px',
64+
height: this.#src.compositionHeight + 'px',
6565
display: 'flex',
6666
transform: `scale(${scale})`,
6767
marginLeft: transform.x,
@@ -70,7 +70,7 @@ export class RemotionLayoutEngine {
7070
});
7171
}
7272

73-
protected _getRect(el: HTMLElement, entry?: ResizeObserverEntry): LayoutRect {
73+
#getRect(el: HTMLElement, entry?: ResizeObserverEntry): LayoutRect {
7474
const rect = el.getBoundingClientRect();
7575
if (!entry) return rect;
7676

@@ -91,23 +91,23 @@ export class RemotionLayoutEngine {
9191
};
9292
}
9393

94-
protected _calcScale(rect: LayoutRect) {
95-
if (!this._src) return 0;
94+
#calcScale(rect: LayoutRect) {
95+
if (!this.#src) return 0;
9696

97-
const heightRatio = rect.height / this._src.compositionHeight!,
98-
widthRatio = rect.width / this._src.compositionWidth!;
97+
const heightRatio = rect.height / this.#src.compositionHeight!,
98+
widthRatio = rect.width / this.#src.compositionWidth!;
9999

100100
return Math.min(heightRatio || 0, widthRatio || 0);
101101
}
102102

103-
protected _calcTransform(rect: LayoutRect, scale: number) {
104-
if (!this._src) return {};
103+
#calcTransform(rect: LayoutRect, scale: number) {
104+
if (!this.#src) return {};
105105

106106
const correction = 0 - (1 - scale) / 2,
107-
x = correction * this._src.compositionWidth!,
108-
y = correction * this._src.compositionHeight!,
109-
width = this._src.compositionWidth! * scale,
110-
height = this._src.compositionHeight! * scale,
107+
x = correction * this.#src.compositionWidth!,
108+
y = correction * this.#src.compositionHeight!,
109+
width = this.#src.compositionWidth! * scale,
110+
height = this.#src.compositionHeight! * scale,
111111
centerX = rect.width / 2 - width / 2,
112112
centerY = rect.height / 2 - height / 2;
113113

0 commit comments

Comments
 (0)