-
Notifications
You must be signed in to change notification settings - Fork 122
feat(web-platform): Implement __ElementAnimate PAPI #2329
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
Merged
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
581bc4c
feat(web-platform): Implement __ElementAnimate PAPI for web platform
Huxpro 172bcc2
fix(web-platform): address review feedback for __ElementAnimate PAPI
Huxpro 99ee694
test(web-platform): add e2e tests for __ElementAnimate PAPI
Huxpro e7a709a
chore: add changeset for __ElementAnimate PAPI
Huxpro c11128f
fix(web-platform): add __ElementAnimate PAPI to web-core-wasm
Huxpro 0bf1eaa
Merge branch 'main' into Huxpro/fix-background-only-new
Huxpro 12264f4
Merge branch 'main' into Huxpro/fix-background-only-new
Huxpro File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,6 @@ | ||
| --- | ||
| "@lynx-js/web-constants": patch | ||
| "@lynx-js/testing-environment": patch | ||
| --- | ||
|
|
||
| Implement `__ElementAnimate` PAPI for web platform animation lifecycle |
142 changes: 142 additions & 0 deletions
142
packages/repl/src/examples/interactivity-element-animate/main-thread.js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,142 @@ | ||
| // Demonstrates: __ElementAnimate — Web Animations API bridge | ||
| // | ||
| // __ElementAnimate(element, [operation, name, keyframes?, options?]) | ||
| // operation: 0=START, 1=PLAY, 2=PAUSE, 3=CANCEL, 4=FINISH | ||
| // | ||
| // Tap the buttons to control the animation. | ||
|
|
||
| globalThis.renderPage = function renderPage() { | ||
| const page = __CreatePage('page', 0); | ||
| const container = __CreateView(0); | ||
| __AppendElement(page, container); | ||
| __SetInlineStyles( | ||
| container, | ||
| 'padding:40px; align-items:center; gap:20px;', | ||
| ); | ||
|
|
||
| const title = __CreateText(0); | ||
| __AppendElement(container, title); | ||
| __AppendElement(title, __CreateRawText('__ElementAnimate')); | ||
| __SetInlineStyles( | ||
| title, | ||
| 'font-size:18px; font-weight:700; margin-bottom:4px;', | ||
| ); | ||
|
|
||
| const subtitle = __CreateText(0); | ||
| __AppendElement(container, subtitle); | ||
| __AppendElement( | ||
| subtitle, | ||
| __CreateRawText('Controls the Web Animations API from the main thread'), | ||
| ); | ||
| __SetInlineStyles( | ||
| subtitle, | ||
| 'font-size:13px; color:#888; margin-bottom:16px;', | ||
| ); | ||
|
|
||
| // Animated box | ||
| const box = __CreateView(0); | ||
| __AppendElement(container, box); | ||
| __SetInlineStyles( | ||
| box, | ||
| 'width:120px; height:120px; background-color:#3b82f6; border-radius:16px; margin-bottom:16px;', | ||
| ); | ||
|
|
||
| // Start a looping pulse animation | ||
| const animName = 'demo-pulse'; | ||
| __ElementAnimate(box, [ | ||
| 0, // START | ||
| animName, | ||
| [ | ||
| { opacity: 1, transform: 'scale(1)' }, | ||
| { opacity: 0.5, transform: 'scale(0.8)' }, | ||
| { opacity: 1, transform: 'scale(1)' }, | ||
| ], | ||
| { | ||
| duration: 1500, | ||
| iterationCount: 'infinite', | ||
| timingFunction: 'ease-in-out', | ||
| }, | ||
| ]); | ||
|
|
||
| // Status text | ||
| const statusRaw = __CreateRawText('Playing'); | ||
| const statusLabel = __CreateText(0); | ||
| __AppendElement(container, statusLabel); | ||
| __AppendElement(statusLabel, statusRaw); | ||
| __SetInlineStyles( | ||
| statusLabel, | ||
| 'font-size:14px; color:#666; margin-bottom:16px;', | ||
| ); | ||
|
|
||
| // Worklet handler router | ||
| const handlers = {}; | ||
| globalThis.runWorklet = function(handlerId, args) { | ||
| if (handlers[handlerId]) handlers[handlerId](...args); | ||
| }; | ||
|
|
||
| // Button row | ||
| const btnRow = __CreateView(0); | ||
| __AppendElement(container, btnRow); | ||
| __SetInlineStyles(btnRow, 'flex-direction:row; gap:10px;'); | ||
|
|
||
| function makeButton(label, handlerId) { | ||
| const btn = __CreateView(0); | ||
| __AppendElement(btnRow, btn); | ||
| __SetInlineStyles( | ||
| btn, | ||
| 'padding:8px 18px; background-color:#1e293b; border-radius:6px; align-items:center; justify-content:center;', | ||
| ); | ||
| const txt = __CreateText(0); | ||
| __AppendElement(btn, txt); | ||
| __AppendElement(txt, __CreateRawText(label)); | ||
| __SetInlineStyles(txt, 'color:#fff; font-size:13px;'); | ||
| __AddEvent(btn, 'bindEvent', 'tap', { | ||
| type: 'worklet', | ||
| value: handlerId, | ||
| }); | ||
| } | ||
|
|
||
| handlers['onPause'] = function() { | ||
| __ElementAnimate(box, [2, /* PAUSE */ animName]); | ||
| __SetAttribute(statusRaw, 'text', 'Paused'); | ||
| __FlushElementTree(); | ||
| }; | ||
|
|
||
| handlers['onPlay'] = function() { | ||
| __ElementAnimate(box, [1, /* PLAY */ animName]); | ||
| __SetAttribute(statusRaw, 'text', 'Playing'); | ||
| __FlushElementTree(); | ||
| }; | ||
|
|
||
| handlers['onCancel'] = function() { | ||
| __ElementAnimate(box, [3, /* CANCEL */ animName]); | ||
| __SetAttribute(statusRaw, 'text', 'Cancelled'); | ||
| __FlushElementTree(); | ||
| }; | ||
|
|
||
| handlers['onRestart'] = function() { | ||
| __ElementAnimate(box, [ | ||
| 0, /* START */ | ||
| animName, | ||
| [ | ||
| { opacity: 1, transform: 'scale(1)' }, | ||
| { opacity: 0.5, transform: 'scale(0.8)' }, | ||
| { opacity: 1, transform: 'scale(1)' }, | ||
| ], | ||
| { | ||
| duration: 1500, | ||
| iterationCount: 'infinite', | ||
| timingFunction: 'ease-in-out', | ||
| }, | ||
| ]); | ||
| __SetAttribute(statusRaw, 'text', 'Playing'); | ||
| __FlushElementTree(); | ||
| }; | ||
|
|
||
| makeButton('Pause', 'onPause'); | ||
| makeButton('Play', 'onPlay'); | ||
| makeButton('Cancel', 'onCancel'); | ||
| makeButton('Restart', 'onRestart'); | ||
|
|
||
| __FlushElementTree(); | ||
| }; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The testing environment hard-codes operation numbers (0..4) inside
__ElementAnimate. Since the web platform uses theAnimationOperationenum, importing and using the same enum here will prevent drift when operations are added/renumbered and make the tests more self-documenting.