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

experimental: View Animations support #4817

Merged
merged 16 commits into from
Feb 4, 2025
24 changes: 23 additions & 1 deletion .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,16 @@ jobs:
with:
submodules-ssh-key: ${{ secrets.PRIVATE_GITHUB_DEPLOY_TOKEN }}

- uses: ./.github/actions/ci-setup
- uses: pnpm/action-setup@v4

- uses: actions/setup-node@v4
with:
node-version: 20
cache: pnpm

- name: Pnpm install
run: |
pnpm install
istarkov marked this conversation as resolved.
Show resolved Hide resolved

- uses: actions/cache@v4
with:
Expand All @@ -62,6 +71,19 @@ jobs:
run: |
pnpm lint --cache --cache-strategy=content --cache-location=node_modules/.cache/eslint/.eslint-cache

- name: Cache Playwright browsers
uses: actions/cache@v4
with:
path: ~/.cache/ms-playwright
key: playwright-${{ runner.os }}-${{ hashFiles('**/package-lock.json') }}
restore-keys: |
playwright-${{ runner.os }}-

- name: Playwright init
run: |
pnpm playwright install
working-directory: packages/sdk-components-animation

- name: Test
run: |
pnpm -r test
Expand Down
7 changes: 6 additions & 1 deletion @types/scroll-timeline.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,11 @@ declare class ScrollTimeline extends AnimationTimeline {
constructor(options?: ScrollTimelineOptions);
}

interface ViewTimelineOptions {
subject?: Element | Document | null;
axis?: ScrollAxis;
}

declare class ViewTimeline extends ScrollTimeline {
constructor(options?: ScrollTimelineOptions);
constructor(options?: ViewTimelineOptions);
}
2 changes: 1 addition & 1 deletion apps/builder/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@
"type-fest": "^4.32.0",
"typescript": "5.7.3",
"vite": "^5.4.11",
"vitest": "^3.0.2"
"vitest": "^3.0.4"
},
"sideEffects": false,
"license": "AGPL-3.0-or-later"
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
"dev": "pnpm --filter='@webstudio-is/builder' dev",
"lint": "eslint \"**/*.{ts,tsx}\" --max-warnings 0",
"checks": "pnpm -r test && pnpm -r typecheck && pnpm lint",
"playwright": "pnpm -r playwright-init",
"format": "prettier --write \"**/*.{ts,tsx,md}\"",
"storybook:dev": "storybook dev -p 6006",
"storybook:build": "storybook build",
Expand Down
2 changes: 1 addition & 1 deletion packages/asset-uploader/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
"devDependencies": {
"@types/fontkit": "^2.0.7",
"@webstudio-is/tsconfig": "workspace:*",
"vitest": "^3.0.2",
"vitest": "^3.0.4",
"zod": "^3.22.4"
},
"exports": {
Expand Down
2 changes: 1 addition & 1 deletion packages/cli/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@
"ts-expect": "^1.3.0",
"vike": "^0.4.220",
"vite": "^5.4.11",
"vitest": "^3.0.2",
"vitest": "^3.0.4",
"wrangler": "^3.63.2"
}
}
2 changes: 1 addition & 1 deletion packages/css-data/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
"html-tags": "^4.0.0",
"mdn-data": "2.8.0",
"type-fest": "^4.32.0",
"vitest": "^3.0.2",
"vitest": "^3.0.4",
"zod": "^3.22.4"
},
"peerDependencies": {
Expand Down
20 changes: 20 additions & 0 deletions packages/css-data/src/__generated__/properties.ts

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

20 changes: 20 additions & 0 deletions packages/css-data/src/custom-data.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,26 @@ propertiesData["-webkit-box-orient"] = {
};
keywordValues["-webkit-box-orient"] = ["horizontal", "vertical"];

propertiesData.viewTimelineName = {
unitGroups: [],
inherited: false,
initial: {
type: "unparsed",
value: "--view-timeline",
},
mdnUrl: "https://developer.mozilla.org/en-US/docs/Web/CSS/view-timeline-name",
};
propertiesData.scrollTimelineName = {
unitGroups: [],
inherited: false,
initial: {
type: "unparsed",
value: "--scroll-timeline",
},
mdnUrl:
"https://developer.mozilla.org/en-US/docs/Web/CSS/scroll-timeline-name",
};

keywordValues.listStyleType = [
"disc",
"circle",
Expand Down
2 changes: 1 addition & 1 deletion packages/css-engine/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
"@webstudio-is/tsconfig": "workspace:*",
"react": "18.3.0-canary-14898b6a9-20240318",
"react-dom": "18.3.0-canary-14898b6a9-20240318",
"vitest": "^3.0.2"
"vitest": "^3.0.4"
},
"exports": {
"webstudio": "./src/index.ts",
Expand Down
2 changes: 2 additions & 0 deletions packages/css-engine/src/__generated__/types.ts

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 11 additions & 0 deletions packages/css-engine/src/core/prefixer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,17 @@ export const prefixStyles = (styleMap: StyleMap) => {
if (property === "backdrop-filter") {
newStyleMap.set("-webkit-backdrop-filter", value);
}

// Safari and FF do not support this property and strip it from the CSS
// For polyfill to work we need to set it as a CSS property
// https://developer.mozilla.org/en-US/docs/Web/CSS/view-timeline-name
if (
property === "view-timeline-name" ||
property === "scroll-timeline-name"
) {
newStyleMap.set(`--${property}`, value);
}

newStyleMap.set(property, value);
}
return newStyleMap;
Expand Down
2 changes: 1 addition & 1 deletion packages/design-system/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
"@webstudio-is/tsconfig": "workspace:*",
"react": "18.3.0-canary-14898b6a9-20240318",
"react-dom": "18.3.0-canary-14898b6a9-20240318",
"vitest": "^3.0.2",
"vitest": "^3.0.4",
"zod": "^3.22.4"
},
"peerDependencies": {
Expand Down
2 changes: 1 addition & 1 deletion packages/fonts/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
},
"devDependencies": {
"@webstudio-is/tsconfig": "workspace:*",
"vitest": "^3.0.2",
"vitest": "^3.0.4",
"zod": "^3.22.4"
},
"peerDependencies": {
Expand Down
2 changes: 1 addition & 1 deletion packages/http-client/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
},
"devDependencies": {
"@webstudio-is/tsconfig": "workspace:*",
"vitest": "^3.0.2"
"vitest": "^3.0.4"
},
"exports": {
"webstudio": "./src/index.ts",
Expand Down
2 changes: 1 addition & 1 deletion packages/image/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
"@webstudio-is/tsconfig": "workspace:*",
"react": "18.3.0-canary-14898b6a9-20240318",
"react-dom": "18.3.0-canary-14898b6a9-20240318",
"vitest": "^3.0.2"
"vitest": "^3.0.4"
},
"peerDependencies": {
"react": "18.3.0-canary-14898b6a9-20240318",
Expand Down
2 changes: 1 addition & 1 deletion packages/jsx-utils/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
"@webstudio-is/tsconfig": "workspace:^",
"fast-glob": "^3.3.2",
"type-fest": "^4.32.0",
"vitest": "^3.0.2"
"vitest": "^3.0.4"
},
"exports": {
".": {
Expand Down
2 changes: 1 addition & 1 deletion packages/project-build/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,6 @@
},
"devDependencies": {
"@webstudio-is/tsconfig": "workspace:*",
"vitest": "^3.0.2"
"vitest": "^3.0.4"
}
}
2 changes: 1 addition & 1 deletion packages/react-sdk/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
"react-dom": "18.3.0-canary-14898b6a9-20240318",
"strip-indent": "^4.0.0",
"type-fest": "^4.32.0",
"vitest": "^3.0.2",
"vitest": "^3.0.4",
"zod": "^3.22.4"
},
"peerDependencies": {
Expand Down
13 changes: 9 additions & 4 deletions packages/sdk-components-animation/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,9 @@
"build:args": "NODE_OPTIONS=--conditions=webstudio generate-arg-types './src/*.tsx !./src/*.stories.tsx !./src/*.ws.ts !./src/*.template.tsx !./src/*.test.{ts,tsx}' -e asChild -e modal -e defaultOpen -e defaultChecked && prettier --write \"**/*.props.ts\"",
"build:stories": "webstudio-sdk generate-stories && prettier --write \"src/__generated__/*.stories.tsx\"",
"dts": "tsc --project tsconfig.dts.json",
"typecheck": "tsc"
"typecheck": "tsc",
"test": "vitest run",
"playwright-init": "playwright install --with-deps"
},
"peerDependencies": {
"react": "18.3.0-canary-14898b6a9-20240318",
Expand All @@ -62,15 +64,18 @@
"devDependencies": {
"@types/react": "^18.2.70",
"@types/react-dom": "^18.2.25",
"@vitest/browser": "^3.0.4",
"@webstudio-is/css-data": "workspace:*",
"@webstudio-is/design-system": "workspace:*",
"@webstudio-is/generate-arg-types": "workspace:*",
"@webstudio-is/sdk-cli": "workspace:^",
"@webstudio-is/sdk-components-react": "workspace:*",
"@webstudio-is/template": "workspace:*",
"@webstudio-is/tsconfig": "workspace:*",
"@webstudio-is/css-data": "workspace:*",
"@webstudio-is/design-system": "workspace:*",
"playwright": "^1.50.1",
"react": "18.3.0-canary-14898b6a9-20240318",
"react-dom": "18.3.0-canary-14898b6a9-20240318",
"type-fest": "^4.32.0"
"type-fest": "^4.32.0",
"vitest": "^3.0.4"
}
}
2 changes: 1 addition & 1 deletion packages/sdk-components-animation/private-src
35 changes: 31 additions & 4 deletions packages/sdk-components-animation/src/shared/animation-types.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ type KeyframeEffectOptions = {
* - "start" → `calc(0% + range)`
* - "end" → `calc(100% - range)`
*/
type ScrollNamedRange = "start" | "end";
export type ScrollNamedRange = "start" | "end";

/**
* Scroll does not support https://drafts.csswg.org/scroll-animations/#named-ranges
Expand All @@ -99,15 +99,42 @@ type AnimationTiming = {
};
*/

type AnimationAxis = "block" | "inline" | "x" | "y";

type ScrollAction = {
type: "scroll";
source?: "closest" | "nearest" | "root";
axis?: "block" | "inline" | "x" | "y";
axis?: AnimationAxis;
animations: {
timing: KeyframeEffectOptions & ScrollRangeOptions;
keyframes: AnimationKeyframe[];
}[];
};

// | ViewAction | ...
export type AnimationAction = ScrollAction;
export type ViewNamedRange =
| "contain"
| "cover"
| "entry"
| "exit"
| "entry-crossing"
| "exit-crossing";

export type ViewRangeValue = [name: ViewNamedRange, value: RangeUnitValue];

type ViewRangeOptions = {
rangeStart?: ViewRangeValue | undefined;
rangeEnd?: ViewRangeValue | undefined;
istarkov marked this conversation as resolved.
Show resolved Hide resolved
};

type ViewAction = {
type: "view";
subject?: string;

axis?: AnimationAxis;
animations: {
timing: KeyframeEffectOptions & ViewRangeOptions;
keyframes: AnimationKeyframe[];
}[];
};

export type AnimationAction = ScrollAction | ViewAction;
7 changes: 1 addition & 6 deletions packages/sdk-components-animation/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,11 +1,6 @@
{
"extends": "@webstudio-is/tsconfig/base.json",
"include": [
"src",
"../../@types/**/scroll-timeline.d.ts",
"private-src/scroll.stories.tsx",
"private-src/scroll.tsx"
],
"include": ["src", "../../@types/**/scroll-timeline.d.ts", "private-src"],
"compilerOptions": {
"types": ["react/experimental", "react-dom/experimental", "@types/node"]
}
Expand Down
37 changes: 37 additions & 0 deletions packages/sdk-components-animation/vitest.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import { defineConfig } from "vitest/config";

export default defineConfig({
test: {
passWithNoTests: true,
workspace: [
{
extends: "./vitest.config.ts",
test: {
include: ["**/*.browser.{test,spec}.ts"],
name: "browser",
browser: {
provider: "playwright", // or 'webdriverio'
enabled: true,
headless: true,
screenshotFailures: false,
instances: [{ browser: "chromium" }, { browser: "firefox" }],
},
},
},
{
extends: "./vitest.config.ts",
test: {
include: ["!**/*.browser.{test,spec}.ts", "**/*.{test,spec}.ts"],

name: "unit",
environment: "node",
},
},
],
},
server: {
watch: {
ignored: [],
},
},
});
2 changes: 1 addition & 1 deletion packages/sdk-components-react/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,6 @@
"@webstudio-is/tsconfig": "workspace:*",
"react": "18.3.0-canary-14898b6a9-20240318",
"react-dom": "18.3.0-canary-14898b6a9-20240318",
"vitest": "^3.0.2"
"vitest": "^3.0.4"
}
}
Loading