@motionhub/remotion 0.1.0 → 0.2.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 -3
- package/index.js +39 -9
- package/package.json +2 -4
package/README.md
CHANGED
|
@@ -3,8 +3,8 @@
|
|
|
3
3
|
Use a motion from [motionhub.dev](https://motionhub.dev) in Remotion. Its React components (`motion/react/parts/`) run as they are, drawn by Remotion's frame; its tokens become Remotion values for anything you draw yourself.
|
|
4
4
|
|
|
5
5
|
```sh
|
|
6
|
-
npx @motionhub/cli get stage-light
|
|
7
|
-
npm i @motionhub/remotion
|
|
6
|
+
npx @motionhub/cli get @iamsuosi/stage-light # into ./motion
|
|
7
|
+
npm i @motionhub/remotion @motionhub/runtime
|
|
8
8
|
```
|
|
9
9
|
|
|
10
10
|
Wrap the composition once, outside every `<Sequence>`, with the motion's tokens, and use the components with props. Inside a `<Sequence>`, a component's `useTime()` starts with it.
|
|
@@ -33,7 +33,8 @@ export const Film = () => {
|
|
|
33
33
|
|
|
34
34
|
- Each component's props are in its file's `meta` (what it is for, what fits it, each parameter) and signature, and `motion/react/previews/<file>.jpg` shows it. A parameter of type `progress` runs from 0 to 1: animate it with `interpolate`.
|
|
35
35
|
- `MotionProvider` gives the components their runtime (`@motionhub/runtime`) from Remotion's frame, and sets the tokens as `--color-*`, `--font-*` and `--caption-*` on a full-frame root (`root={false}` leaves it out). A component's `<Video src>` is an `<OffthreadVideo>`: `src` is a URL or a path in `public/`.
|
|
36
|
-
-
|
|
36
|
+
- A face the motion carries in `motion/react/fonts/` (`fonts.json` names each) is loaded with `@remotion/fonts`' `loadFont`, from a copy in `public/`.
|
|
37
|
+
- `MotionFonts` loads the faces the tokens name before the first frame, from Google Fonts or, for one it lacks (LXGW WenKai), from where it is. `han` adds the Chinese, Japanese and Korean faces, every part of them (several MB each), since a part fetched only when its text is first drawn arrives too late for that frame. A face no source has is named in the console: bundle it with `@remotion/fonts`.
|
|
37
38
|
- `useMotion()` turns the tokens into Remotion values: `tokens`, `frames('light')` (a duration in frames), `ease('light')` (an `Easing.bezier`), `progress(frame, start, 'light', 'light')`, for a motion with `duration` and `easing` tokens.
|
|
38
39
|
- A component that draws in 3D imports `three`: `npm i three`.
|
|
39
40
|
- The components are imported with their `.tsx` extension; set `"allowImportingTsExtensions": true` and `"noEmit": true` in `tsconfig.json` if you type-check them, and `"resolveJsonModule": true` for `tokens.json`.
|
package/index.js
CHANGED
|
@@ -28,12 +28,32 @@ export const MotionProvider = ({tokens, root = true, children}) => {
|
|
|
28
28
|
return createElement(MotionRuntimeProvider, {value}, root ? createElement(MotionRoot, {tokens: resolved}, children) : children);
|
|
29
29
|
};
|
|
30
30
|
|
|
31
|
-
// ---- the motion's faces, from Google Fonts, before the first frame ----
|
|
31
|
+
// ---- the motion's faces, from Google Fonts (or where it has none), before the first frame ----
|
|
32
32
|
const GENERIC = /^(serif|sans-serif|monospace|cursive|fantasy|system-ui|math|emoji|ui-[a-z-]+)$/;
|
|
33
33
|
const HAN = /^(Noto (Sans|Serif) (SC|TC|JP|KR)|LXGW WenKai|Fusion Pixel.*)$/;
|
|
34
34
|
/** The family names in the tokens' font stacks */
|
|
35
35
|
export const families = (resolved) => [...new Set(Object.values(resolved?.font ?? {}).flatMap((s) => String(s).split(',').map((f) => f.trim().replace(/^["']|["']$/g, ''))))].filter((f) => f && !GENERIC.test(f));
|
|
36
|
+
/**
|
|
37
|
+
* Faces Google Fonts does not have, by family: stylesheets that split them by unicode-range, at an exact version so that a film renders the same
|
|
38
|
+
* next year. Google has only "LXGW WenKai TC", so LXGW WenKai comes from its OFL-1.1 webfont package on npm, through jsDelivr. The same table is
|
|
39
|
+
* in @motionhub/hyperframes (tests/bindings.test.mjs keeps them equal).
|
|
40
|
+
*/
|
|
41
|
+
const ELSEWHERE = {
|
|
42
|
+
'LXGW WenKai': ['regular', 'bold'].map((w) => `https://cdn.jsdelivr.net/npm/lxgw-wenkai-webfont@1.7.0/lxgwwenkai-${w}.css`),
|
|
43
|
+
};
|
|
44
|
+
/** A stylesheet from a URL, its relative `url()`s made absolute: it is set in a <style>, where they would not resolve */
|
|
45
|
+
const sheet = async (href) => {
|
|
46
|
+
const res = await fetch(href).catch(() => undefined);
|
|
47
|
+
if (!res?.ok) return undefined;
|
|
48
|
+
return (await res.text()).replace(/url\((["']?)(?![a-z]+:|\/\/|data:)([^)"']+)\1\)/gi, (_, q, path) => `url(${q}${new URL(path, href).href}${q})`);
|
|
49
|
+
};
|
|
50
|
+
/** The stylesheet texts for a family, [] when no source has it */
|
|
36
51
|
const css = async (family) => {
|
|
52
|
+
if (ELSEWHERE[family]) return (await Promise.all(ELSEWHERE[family].map(sheet))).filter(Boolean);
|
|
53
|
+
const text = await google(family);
|
|
54
|
+
return text ? [text] : [];
|
|
55
|
+
};
|
|
56
|
+
const google = async (family) => {
|
|
37
57
|
const name = encodeURIComponent(family).replace(/%20/g, '+');
|
|
38
58
|
// Google Fonts refuses a weight range a face does not span, so ask for the common ones in turn, then its default weight
|
|
39
59
|
for (const axes of [':wght@100..900', ':wght@200..900', ':wght@100..800', ':wght@200..800', ':wght@300..800', ':wght@300..700', ':wght@400..700', ':wght@400;700', '']) {
|
|
@@ -43,8 +63,8 @@ const css = async (family) => {
|
|
|
43
63
|
return undefined;
|
|
44
64
|
};
|
|
45
65
|
/**
|
|
46
|
-
* Loads the faces the tokens name, inside <MotionProvider>. Faces for Chinese, Japanese and Korean are large and load only with `han`; one
|
|
47
|
-
*
|
|
66
|
+
* Loads the faces the tokens name, inside <MotionProvider>. Faces for Chinese, Japanese and Korean are large and load only with `han`; one no source
|
|
67
|
+
* has is named in the console and left to the stack's next face (bundle it with @remotion/fonts).
|
|
48
68
|
*/
|
|
49
69
|
export const MotionFonts = ({han = false}) => {
|
|
50
70
|
const tokens = useTokens();
|
|
@@ -52,12 +72,22 @@ export const MotionFonts = ({han = false}) => {
|
|
|
52
72
|
useEffect(() => {
|
|
53
73
|
const wanted = families(tokens).filter((f) => han || !HAN.test(f));
|
|
54
74
|
Promise.all(wanted.map(async (family) => {
|
|
55
|
-
const
|
|
56
|
-
if (!
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
75
|
+
const texts = await css(family);
|
|
76
|
+
if (!texts.length) {
|
|
77
|
+
// a face a Chinese, Japanese or Korean motion is written for must not fall back unseen
|
|
78
|
+
const message = `@motionhub/remotion: no source has "${family}"; load it with @remotion/fonts`;
|
|
79
|
+
if (HAN.test(family)) console.error(message); else console.warn(message);
|
|
80
|
+
return;
|
|
81
|
+
}
|
|
82
|
+
for (const text of texts) {
|
|
83
|
+
const el = document.createElement('style');
|
|
84
|
+
el.textContent = text;
|
|
85
|
+
document.head.appendChild(el);
|
|
86
|
+
}
|
|
87
|
+
// a face split by unicode-range fetches a part only when its text is first drawn, too late for that frame: so a Chinese, Japanese or
|
|
88
|
+
// Korean face, whose text no one knows beforehand, is loaded whole; the others need only their latin part, which these loads fetch
|
|
89
|
+
if (HAN.test(family)) await Promise.all([...document.fonts].filter((f) => f.family.replace(/^["']|["']$/g, '') === family).map((f) => f.load().catch(() => undefined)));
|
|
90
|
+
else await Promise.all(['400', '700'].map((w) => document.fonts.load(`${w} 32px "${family}"`).catch(() => undefined)));
|
|
61
91
|
})).finally(() => continueRender(handle));
|
|
62
92
|
}, [handle]);
|
|
63
93
|
return null;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@motionhub/remotion",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.2.0",
|
|
4
4
|
"description": "Use a motion from motionhub.dev in Remotion: its React components as they are, and its tokens as Remotion values.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"repository": {
|
|
@@ -23,10 +23,8 @@
|
|
|
23
23
|
"index.d.ts",
|
|
24
24
|
"README.md"
|
|
25
25
|
],
|
|
26
|
-
"dependencies": {
|
|
27
|
-
"@motionhub/runtime": "0.1.0"
|
|
28
|
-
},
|
|
29
26
|
"peerDependencies": {
|
|
27
|
+
"@motionhub/runtime": "^0.3.0",
|
|
30
28
|
"react": ">=18",
|
|
31
29
|
"remotion": ">=4"
|
|
32
30
|
}
|