Communitygithub.com

bardu-rgb/reels

以特定方式編寫 Remotion 標記,讓 Remotion Studio 能夠辨識程式碼結構並使其具備互動性。

reels 是什麼?

此技能提供了一套明確的準則,用於編寫 Remotion 標記,以啟用 Remotion Studio 中的完整互動編輯功能。它指導開發人員如何建構元件,使其可被點擊選取、拖放、調整大小和旋轉,並允許直接編輯 CSS 樣式、關鍵影格和緩動函數。此技能支援所有 Remotion 專案,並推薦使用 `Interactive.withSchema({wrapInSequence: true})` 來建立具有自訂時間軸的可編輯元件,同時也詳細說明了互動性綱要(`InteractivitySchema`)中各個欄位類型(如 `text-content`、`number`、`color` 等)的用法與最佳實踐。此外,它涵蓋了如何將可重複使用的元件註冊為「已連接組合」(connected compositions),如何直接將時間參數傳遞給元件而非使用單獨的 `<Sequence>`,以及如何為每個可獨立編輯的項目建立獨立的 JSX 節點。最後,它強調使用內聯 `interpolate()` 來建立動畫,並將所有 CSS 樣式保持為內聯,以確保 Studio 能正確讀取和修改。

相容平台~Claude Code~Codex CLI~Cursor
npx skills add https://github.com/bardu-rgb/reels/tree/HEAD/.agents/skills/remotion-interactivity

在你喜歡的 AI 中提問

開啟一個已預先載入此 Agent Skill 的新對話。

預覽

來自技能 README

reels preview

說明文件

透過以特定方式編寫 Remotion 標記,Remotion Studio 能夠辨識程式碼的結構並使其具備互動性:

  • 允許透過點擊選取項目
  • 允許拖放、調整大小和旋轉
  • 編輯 CSS 樣式
  • 讓關鍵影格和緩動值可編輯

如果標記對 Studio 來說過於複雜而無法使其具備互動性,那麼這些值將會變為灰色。

偏好使用具有獨立時間軸的互動元件

對自訂場景、卡片、標題以及其他可視元件,請使用 Interactive.withSchema({wrapInSequence: true}),這樣每個實例的 props 都可以被編輯。在 InteractivitySchema 中公開有意義的內容和外觀控制項。將裝飾性的實作細節保留在元件內部。

元件必須接受 style 並將其傳遞給一個視覺根元素。當變形、裁切或不透明度應影響其所有圖層時,請保持一個共享的根元素。當冗餘的內部包裝器的樣式可以移動到現有元素上而不改變佈局或動畫時,請將其扁平化。

import type React from 'react';
import {Interactive, type InteractivitySchema} from 'remotion';

type LowerThirdProps = {
  readonly children: string;
  readonly accentColor: string;
  readonly style?: React.CSSProperties;
};

const LowerThirdInner: React.FC<LowerThirdProps> = ({
  children,
  accentColor,
  style,
}) => {
  return (
    <Interactive.Div
      style={{
        position: 'absolute',
        left: 80,
        bottom: 80,
        display: 'flex',
        alignItems: 'center',
        gap: 20,
        backgroundColor: 'white',
        borderRadius: 16,
        padding: '20px 32px',
        color: 'black',
        fontFamily: 'Helvetica, Arial, sans-serif',
        fontSize: 48,
        fontWeight: 600,
        ...style,
      }}
    >
      <div
        style={{
          width: 8,
          alignSelf: 'stretch',
          borderRadius: 4,
          backgroundColor: accentColor,
        }}
      />
      {children}
    </Interactive.Div>
  );
};

const lowerThirdSchema = {
  children: {type: 'text-content', default: '', description: 'Text'},
  accentColor: {
    type: 'color',
    default: '#0b84f3',
    description: 'Accent color',
  },
} as const satisfies InteractivitySchema;

export const LowerThird = Interactive.withSchema({
  Component: LowerThirdInner,
  componentName: '<LowerThird>',
  schema: lowerThirdSchema,
  wrapInSequence: true,
});

必須在元件內部轉發注入的 style;在元件的呼叫點保持可編輯的樣式為內聯。

選擇綱要欄位

綱要中的每個鍵都是一個 prop,Studio 可以在呼叫點讀取和編輯它。不在綱要中的 props 仍然可以運作,但在 Studio 中無法編輯。鍵可以使用點記號,例如 style.color。

類型用途可設置關鍵影格
text-content文字,例如標題否
number數字,可選用 min、max、step、integer是
boolean開/關切換是(按住)
colorCSS 顏色字串是
enum在 variants 之間選擇,每個變體有自己的巢狀綱要選擇性加入(按住)
array數字、顏色、列舉等的列表否
asset媒體來源,可選用 assetType否
font-familyCSS 字型家族否
font-weight字型粗細是
translate、scale、rotation-css、rotation-degrees、transform-origin變形是
uv-coordinate元素上的一個標準化 [x, y] 點是
svg-pathSVG 路徑資料是
remotion-captionsCaption[] 資料否
hidden一個值,保持在控制項之外—

每個欄位都需要一個 default 值,並且應該有一個 description,Studio 會將其顯示為標籤。 設定 keyframable: false 以顯示一個靜態控制項。

公開內容和每個實例的外觀,例如文字和強調色。\n不要為 style.translate、style.scale、style.rotate、style.transformOrigin 和 style.opacity 添加欄位:wrapInSequence: true 已經添加了它們。

要使根元素的 CSS 屬性在每個實例中可編輯,請展開內建的綱要片段:

const cardSchema = {
  ...Interactive.textSchema, // style.color, style.fontSize, style.fontWeight, ...
  ...Interactive.backgroundSchema, // style.backgroundColor
  ...Interactive.borderRadiusSchema, // style.borderRadius, ...
} as const satisfies InteractivitySchema;

也可使用:Interactive.borderSchema 和 Interactive.captionsSchema(用於接受字幕的元件)。 有關所有選項,請參閱 InteractivitySchema。

將可重用元件註冊為已連接組合

將具有自己圖層或動畫的重要場景和可重用元件註冊為獨立的組合。Studio 將這些稱為已連接組合:它們可以在自己的時間軸中開啟,同時與父影片共享相同的元件實作。

在元件內部定義所需的樣式和載入字型,使其在沒有父元件的情況下也能正常運作。請參閱 父元件獨立性。

註冊父元件所渲染的相同匯出元件參考。對於上面的範例,使用 component={LowerThird},而不是 LowerThirdInner 或內聯包裝器。 使用 wrapInSequence: true 時,連接不需要額外的 <Sequence>。

import {Composition} from 'remotion';
import {LowerThird} from './LowerThird';

export const RemotionRoot = () => (
  <Composition
    id="LowerThird"
    component={LowerThird}
    width={1280}
    height={720}
    fps={30}
    durationInFrames={30}
    defaultProps={{
      children: 'Jane Doe, Product Designer',
      accentColor: '#0b84f3',
    }}
  />
);

選擇一個唯一的 ID、具代表性的內聯預設值,以及適合預覽元件的尺寸、fps 和持續時間。註冊預設值不會自動從父實例複製 props。請參閱 已連接組合以了解註冊和提取的詳細資訊。

直接將時間參數放在元件上

避免在一個已經接受時間 props 的元件周圍加上單獨的 <Sequence>。使用 wrapInSequence: true 建立的內建互動元件和自訂元件可以直接接收 name、from、durationInFrames、trimBefore、playbackRate 和 premountFor。

<LowerThird
  name="Lower third"
  from={30}
  durationInFrames={90}
  accentColor="#0b84f3"
>
  Jane Doe, Product Designer
</LowerThird>

移除冗餘的序列時,將其時間和名稱移動到子元件。保留任何現有的子元件時間;不要覆蓋或雙重套用偏移量。 元件內部的 useCurrentFrame() 呼叫讀取其本地影格,而呼叫點的樣式表達式仍然使用呼叫者的影格。移動動畫樣式時請保留此區別。

當 <Sequence> 為多個兄弟元素提供共享時間、覆蓋 useVideoConfig() 的尺寸,或包裝一個不處理時間的元件時,請保留它。對於連續佈局,保留 <Series.Sequence>;對於過渡效果,保留 <TransitionSeries.Sequence>;直接的 from props 無法取代這些行為。

為每個可獨立編輯的項目提供其自己的 JSX 節點

Studio 編輯的是建立項目的 JSX 原始碼節點。如果多個執行時期項目來自同一個 JSX 節點,它們共享一個原始碼編輯目標。

對於每個應可獨立編輯的組合註冊、剪輯、場景、圖層或序列,請編寫一個單獨的 JSX 節點,並將其可編輯的 props 保留在該節點上。這適用於 <Composition>、<Still>、內建媒體元件、<Sequence>、<Series.Sequence>、<TransitionSeries.Sequence> 和自訂元件。

例如,像這樣編寫一個可編輯的時間軸:

<Series>
  <Series.Sequence name="Introduction" durationInFrames={90}>
    <Introduction />
  </Series.Sequence>
  <Series.Sequence name="Demo" durationInFrames={150}>
    <Demo />
  </Series.Sequence>
</Series>

一個 .map() 或其他程式化迴圈會從一個 JSX 原始碼節點建立多個執行時期項目。這適用於有意作為一個模板控制的重複輸出,例如視覺化長條圖或粒子。當實例在 Studio 中需要獨立的 ID 或名稱、props、中繼資料、時間、排序、刪除或複製時,這就不合適了。

使用 Interactive 使 HTML 元素具備互動性

每個 HTML 和 SVG 元素(除了 <Img>,它已經是互動的),例如 <div>,都可以使用 Interactive 來使其具備互動性:

<Interactive.Div
  name="Greeting card"
  style={{fontSize: 80, padding: 24}}
>
  Hello
</Interactive.Div>

這允許在 Studio 中設定樣式和關鍵影格。請合理使用,如果一個元件有許多元素,時間軸可能會變得雜亂。

偏好內聯文字

如果文字是固定的且只使用一次,請直接將其寫在互動元素內部,而不是將其提取到一個常數中。

// 👍 固定副本保持可編輯
<Interactive.Div name="Title">
  Remotion Best Practices
</Interactive.Div>

僅當文字是動態或可重複使用時,才使用 prop 或變數。

為互動元素提供描述性名稱

為元素添加 name prop 以使其易於識別。 避免使用計算名稱,請對其進行硬編碼。

<>
  <Interactive.Div name="Hero title" style={{fontSize: 80}}>
    Launch day
  </Interactive.Div>
  <Img name="Avatar" src="https://remotion.media/image.jpeg" />
  <Video name="Background" src="https://remotion.media/video.mp4" />
  <Interactive.Div name="Title">
    Launch day
  </Interactive.Div>
</>

保持所有 CSS 樣式為內聯

最好的方法是直接將一個普通物件傳遞給 style - 不要參考常數、不要展開物件、不要進行數學運算。

<Interactive.Div
  style={{
    fontSize: 80,
    color: 'red',
  }}
>
  Hello World!
</Interactive.Div>
const baseStyle = useMemo(() => {
  return {
    fontSize: 12 // ❌ 不支援非內聯樣式
  }
}, []);

<Interactive.Div
  style={{
    ...baseStyle, // ❌ 不支援展開
    color: RED, // ❌ 不支援參考常數
    scale: frame * 10 // ❌ 不支援數學運算
  }}
>
  Hello World!
</Interactive.Div>

使用 interpolate() 製作動畫

將動畫編寫為對正在改變的屬性的內聯 interpolate() 呼叫。\n輸出範圍、緩動函數、外推法和 output 屬性應使用硬編碼值。

輸入範圍還可以使用直接從 useVideoConfig() 解構的 durationInFrames、fps、width 和 height。支援像 durationInFrames 這樣的裸識別碼、與數字相乘(例如 2 * fps 或 fps * 2),以及減去一個數字(例如 durationInFrames - 1)。

const {fps, durationInFrames} = useVideoConfig();

// 👍 內聯值可以標準化並設定關鍵影格
<Interactive.Div
  name="Product card"
  style={{
    color: 'white',
    fontSize: 80,
    scale: interpolate(frame, [0, fps], [0, 1], {
      easing: Easing.spring({damping: 200}),
      output: 'perceptual-scale',
      extrapolateLeft: 'clamp',
      extrapolateRight: 'clamp'
    }),
    rotate: interpolate(frame, [0, 1 * fps], ['0deg', '20deg'], {
      easing: Easing.spring({damping: 200}),
      extrapolateLeft: 'clamp',
      extrapolateRight: 'clamp'
    }),
    translate: interpolate(
      frame,
      [durationInFrames - 30, durationInFrames],
      ['0px 0px', '0px 120px'],
      {
        easing: Easing.spring({damping: 200}),
        output: 'perceptual-scale',
        extrapolateLeft: 'clamp',
        extrapolateRight: 'clamp'
      }
    ),
  }}
/>
const translateY = interpolate(frame, [0, 30], [0, 120]); // ❌ 數學運算應直接在標記中

<Interactive.Div
  name="Product card"
  style={{
    translate: translateY, // ❌ 僅支援內聯的 interpolate() 呼叫
    rotate: interpolate(frame, [start, start + 10], [0, Math.PI]), // ❌ 不能使用具有任意變數的數學運算,不能使用常數
    scale
  }}
/>

使用 useCurrentFrame() 控制動畫

將 frame 的宣告保持在內聯位置;不要在動畫屬性外部計算 frame 值。

使用 useVideoConfig() 進行響應式設計

僅將 useVideoConfig() 解構為直接的變數宣告。在 style 或動畫表達式之外與其互動會破壞可編輯性。

偏好 <Video> 和 <Audio> 的 src 屬性

始終使用 src 屬性來指定媒體來源。不要使用 data 或其他自訂屬性。

Individual skills in this repo

This repo contains 5 individual skills — each has its own dedicated page.

相關技能