Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: get rid of vite #269

Closed
wants to merge 25 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
fd41e51
chore: remove scene metadata
hkonsti Sep 3, 2024
57b8d1b
chore: set name in makeScene2d
hkonsti Sep 3, 2024
635215b
chore: import scene like normal
hkonsti Sep 3, 2024
52d5297
chore: remove project loader
hkonsti Sep 4, 2024
9b4a0a1
chore: delete meta files, redo exporter settings
hkonsti Sep 5, 2024
7ab40c9
chore: project metadata improvements
hkonsti Sep 5, 2024
73f6c3d
chore: rename, delete editorBootstrap, remove global audio file
hkonsti Sep 11, 2024
dcc1482
chore: remove asset base and cors proxy
hkonsti Sep 12, 2024
aa5c023
chore: remove player endpoint from cli
hkonsti Sep 12, 2024
945d9f1
Merge branch 'main' of github.com:redotvideo/revideo into konsti/get-…
hkonsti Sep 12, 2024
f8fa28a
chore: remove more assetBase leftovers
hkonsti Sep 12, 2024
7d3d89c
chore: delete presenter, update project and scene types
hkonsti Sep 13, 2024
9cd86f5
chore: add todos
hkonsti Sep 17, 2024
725fc6e
chore: update player
hkonsti Sep 17, 2024
7abfd3d
chore: package-lock and clean up bootstrap
hkonsti Sep 17, 2024
0898c17
chore: update player pt 1
hkonsti Sep 18, 2024
24c3664
chore: new template
hkonsti Sep 18, 2024
8426b43
chore: fix ui done
hkonsti Sep 18, 2024
4eb5fd0
chore: naming, some todos
hkonsti Sep 18, 2024
702a9e4
chore: remove some comments, update saas example
hkonsti Sep 18, 2024
eb93cff
chore: versions
hkonsti Sep 19, 2024
18fa215
chore: remove unused color code
hkonsti Sep 19, 2024
508f870
chore: fix tests
hkonsti Sep 19, 2024
0134f5a
chore: fix tests hopefully
hkonsti Sep 20, 2024
6f1113f
chore: fix final test
hkonsti Sep 22, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1,038 changes: 680 additions & 358 deletions package-lock.json

Large diffs are not rendered by default.

3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,8 @@
"lint-staged": "^15.1.0",
"prettier": "^3.1.0",
"prettier-plugin-organize-imports": "^3.2.4",
"typescript": "^5.2.2"
"typescript": "^5.2.2",
"vitest": "^0.34.6"
},
"lint-staged": {
"*.{ts,tsx}": "eslint --fix",
Expand Down
3 changes: 1 addition & 2 deletions packages/2d/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,7 @@
"@revideo/ui": "0.5.9",
"clsx": "^2.0.0",
"jsdom": "^22.1.0",
"preact": "^10.19.2",
"vitest": "^0.34.6"
"preact": "^10.19.2"
},
"dependencies": {
"@codemirror/language": "^6.10.1",
Expand Down
51 changes: 0 additions & 51 deletions packages/2d/src/lib/components/Asset.ts

This file was deleted.

4 changes: 2 additions & 2 deletions packages/2d/src/lib/components/Audio.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {DependencyContext, PlaybackState, viaProxy} from '@revideo/core';
import {DependencyContext, PlaybackState} from '@revideo/core';
import {computed, nodeName} from '../decorators';
import {Media, MediaProps} from './Media';

Expand All @@ -24,7 +24,7 @@ export class Audio extends Media {

@computed()
protected audio(): HTMLAudioElement {
const src = viaProxy(this.fullSource());
const src = this.src();
const key = `${this.key}/${src}`;
let audio = Audio.pool[key];
if (!audio) {
Expand Down
47 changes: 28 additions & 19 deletions packages/2d/src/lib/components/Img.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,11 @@ import {
SimpleSignal,
Vector2,
useLogger,
viaProxy,
} from '@revideo/core';
import {computed, initial, nodeName, signal} from '../decorators';
import {DesiredLength} from '../partials';
import {drawImage} from '../utils';
import {Asset} from './Asset';
import {RectProps} from './Rect';
import {Rect, RectProps} from './Rect';
import imageWithoutSource from './__logs__/image-without-source.md';

export interface ImgProps extends RectProps {
Expand Down Expand Up @@ -67,7 +65,7 @@ export interface ImgProps extends RectProps {
* ```
*/
@nodeName('Img')
export class Img extends Asset {
export class Img extends Rect {
private static pool: Record<string, HTMLImageElement> = {};

static {
Expand All @@ -82,6 +80,24 @@ export class Img extends Asset {
}
}

/**
* The source of this image.
*
* @example
* Using a local image:
* ```tsx
* import image from './example.png';
* // ...
* view.add(<Img src={image} />)
* ```
* Loading an image from the internet:
* ```tsx
* view.add(<Img src="https://example.com/image.png" />)
* ```
*/
@signal()
public declare readonly src: SimpleSignal<string, this>;

/**
* The alpha value of this image.
*
Expand Down Expand Up @@ -132,39 +148,32 @@ export class Img extends Asset {

@computed()
protected image(): HTMLImageElement {
const rawSrc = this.fullSource();
let src = '';
let key = '';
if (rawSrc) {
key = viaProxy(rawSrc);
const url = new URL(key, window.location.origin);
if (url.origin === window.location.origin) {
const hash = this.view().assetHash();
url.searchParams.set('asset-hash', hash);
}
src = url.toString();
const src = this.src();
const url = new URL(src, window.location.origin);
if (url.origin === window.location.origin) {
const hash = this.view().assetHash();
url.searchParams.set('asset-hash', hash);
}

let image = Img.pool[key];
let image = Img.pool[src];
if (!image) {
image = document.createElement('img');
image.crossOrigin = 'anonymous';
image.src = src;
Img.pool[key] = image;
Img.pool[src] = image;
}

if (!image.complete) {
DependencyContext.collectPromise(
new Promise((resolve, reject) => {
image.addEventListener('load', resolve);
image.addEventListener('error', () =>
// TODO: example for error handling inside DependencyContext (this shouldn't be UI specific)
reject(
new DetailedError({
message: `Failed to load an image`,
remarks: `\
The <code>src</code> property was set to:
<pre><code>${rawSrc}</code></pre>
...which resolved to the following url:
<pre><code>${src}</code></pre>
Make sure that source is correct and that the image exists.<br/>
<a target='_blank' href='https://motioncanvas.io/docs/media#images'>Learn more</a>
Expand Down
6 changes: 3 additions & 3 deletions packages/2d/src/lib/components/Layout.ts
Original file line number Diff line number Diff line change
Expand Up @@ -962,9 +962,9 @@ export class Layout extends Node {

@computed()
protected applyFont() {
const loadingFonts = Array.from(document.fonts).filter(
font => font.status === 'loading',
);
const loadingFonts = document.fonts
? Array.from(document.fonts).filter(font => font.status === 'loading')
: [];
if (loadingFonts.length > 0) {
DependencyContext.collectPromise(
(async () => {
Expand Down
11 changes: 6 additions & 5 deletions packages/2d/src/lib/components/Media.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,9 @@ import {
isReactive,
useLogger,
useThread,
viaProxy,
} from '@revideo/core';
import {computed, initial, nodeName, signal} from '../decorators';
import {Asset} from './Asset';
import {RectProps} from './Rect';
import {Rect, RectProps} from './Rect';
import reactivePlaybackRate from './__logs__/reactive-playback-rate.md';

export interface MediaProps extends RectProps {
Expand All @@ -26,7 +24,10 @@ export interface MediaProps extends RectProps {
}

@nodeName('Media')
export abstract class Media extends Asset {
export abstract class Media extends Rect {
@signal()
public declare readonly src: SimpleSignal<string, this>;

@initial(false)
@signal()
public declare readonly loop: SimpleSignal<boolean, this>;
Expand Down Expand Up @@ -161,7 +162,7 @@ export abstract class Media extends Asset {

@computed()
protected amplify(node: HTMLMediaElement, volume: number) {
const key = `${viaProxy(this.fullSource())}/${this.key}`;
const key = `${this.src()}/${this.key}`;

if (Media.amplificationPool[key]) {
Media.amplificationPool[key].gainNode.gain.value = volume;
Expand Down
18 changes: 7 additions & 11 deletions packages/2d/src/lib/components/Rive.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,4 @@
import {
BBox,
SignalValue,
SimpleSignal,
useThread,
viaProxy,
} from '@revideo/core';
import {BBox, SignalValue, SimpleSignal, useThread} from '@revideo/core';
import RiveInitializer, {
Artboard,
File,
Expand All @@ -13,8 +7,7 @@ import RiveInitializer, {
RiveCanvas,
} from '@rive-app/canvas-advanced';
import {computed, initial, nodeName, signal} from '../decorators';
import {Asset} from './Asset';
import {RectProps} from './Rect';
import {Rect, RectProps} from './Rect';

export interface RiveProps extends RectProps {
src?: SignalValue<string>;
Expand All @@ -31,7 +24,10 @@ interface RiveInstance {
}

@nodeName('Rive')
export class Rive extends Asset {
export class Rive extends Rect {
@signal()
public declare readonly src: SimpleSignal<string, this>;

@initial(0)
@signal()
public declare readonly artboardId: SimpleSignal<number | string, this>;
Expand All @@ -57,7 +53,7 @@ export class Rive extends Asset {

@computed()
private async rive(): Promise<RiveInstance> {
const src = viaProxy(this.fullSource());
const src = this.src();
const rive = await RiveInitializer({
locateFile: () => {
return '/@rive-wasm';
Expand Down
8 changes: 0 additions & 8 deletions packages/2d/src/lib/components/TxtLeaf.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ import {
} from '../decorators';
import {Shape, ShapeProps} from './Shape';
import {Txt} from './Txt';
import {View2D} from './View2D';

export interface TxtLeafProps extends ShapeProps {
children?: string;
Expand All @@ -24,13 +23,6 @@ export interface TxtLeafProps extends ShapeProps {

@nodeName('TxtLeaf')
export class TxtLeaf extends Shape {
@lazy(() => {
const formatter = document.createElement('span');
View2D.shadowRoot.append(formatter);
return formatter;
})
protected static formatter: HTMLDivElement;

@lazy(() => {
try {
return new (Intl as any).Segmenter(undefined, {
Expand Down
5 changes: 2 additions & 3 deletions packages/2d/src/lib/components/Video.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import {
SerializedVector2,
SignalValue,
SimpleSignal,
viaProxy,
} from '@revideo/core';
import Hls from 'hls.js';
import {computed, initial, nodeName, signal} from '../decorators';
Expand Down Expand Up @@ -112,7 +111,7 @@ export class Video extends Media {

@computed()
private video(): HTMLVideoElement {
const src = viaProxy(this.fullSource());
const src = this.src();
const key = `${this.key}/${src}`;
let video = Video.pool[key];
if (!video) {
Expand Down Expand Up @@ -336,7 +335,7 @@ export class Video extends Media {
private detectFileType() {
return DependencyContext.collectPromise(
(async () => {
const src = this.fullSource();
const src = this.src();
const extension = src.split('?')[0].split('.').pop()?.toLowerCase();

if (
Expand Down
1 change: 1 addition & 0 deletions packages/2d/src/lib/components/View2D.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ export interface View2DProps extends RectProps {

@nodeName('View2D')
export class View2D extends Rect {
// TODO: scope this to individual player
@lazy(() => {
const frameID = 'revideo-2d-frame';
let frame = document.querySelector<HTMLDivElement>(`#${frameID}`);
Expand Down
6 changes: 1 addition & 5 deletions packages/2d/src/lib/components/__tests__/mockScene2D.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,12 @@ import {
PlaybackManager,
PlaybackStatus,
ThreadGeneratorFactory,
ValueDispatcher,
Vector2,
endPlayback,
endScene,
startPlayback,
startScene,
} from '@revideo/core';
import {ReadOnlyTimeEvents} from '@revideo/core/lib/scenes/timeEvents';
import {afterAll, beforeAll, beforeEach} from 'vitest';
import {Scene2D, makeScene2D} from '../../scenes';
import {View2D} from '../View2D';
Expand All @@ -26,16 +24,14 @@ export function mockScene2D() {
const playback = new PlaybackManager();
const status = new PlaybackStatus(playback);
const description = {
...makeScene2D(function* () {
...makeScene2D('scene 1', function* () {
// do nothing
}),
name: 'test',
size: new Vector2(1920, 1080),
resolutionScale: 1,
timeEventsClass: ReadOnlyTimeEvents,
playback: status,
} as unknown as FullSceneDescription<ThreadGeneratorFactory<View2D>>;
description.onReplaced = new ValueDispatcher(description);
const scene = new Scene2D(description);

beforeAll(() => {
Expand Down
1 change: 0 additions & 1 deletion packages/2d/src/lib/partials/Pattern.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ export type CanvasRepetition =
| 'repeat-y'
| 'no-repeat';

// TODO Support custom transformation matrices
export interface PatternProps {
image: CanvasImageSource;
repetition?: CanvasRepetition;
Expand Down
4 changes: 2 additions & 2 deletions packages/2d/src/lib/scenes/Scene2D.ts
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ export class Scene2D extends GeneratorScene<View2D> implements Inspectable {
...playingVideos.map(vid => ({
key: vid.key,
type: 'video' as const,
src: vid.getUrl(),
src: vid.src(),
decoder: vid.decoder(),
playbackRate:
typeof vid.playbackRate === 'function'
Expand All @@ -186,7 +186,7 @@ export class Scene2D extends GeneratorScene<View2D> implements Inspectable {
...playingAudios.map(audio => ({
key: audio.key,
type: 'audio' as const,
src: audio.fullSource(),
src: audio.src(),
playbackRate:
typeof audio.playbackRate === 'function'
? audio.playbackRate()
Expand Down
Loading
Loading