@lynx-js/web-mainthread-apis 0.19.8 → 0.19.9

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/CHANGELOG.md CHANGED
@@ -1,5 +1,12 @@
1
1
  # @lynx-js/web-mainthread-apis
2
2
 
3
+ ## 0.19.9
4
+
5
+ ### Patch Changes
6
+
7
+ - Updated dependencies [[`2efecc2`](https://github.com/lynx-family/lynx-stack/commit/2efecc252c746831e7566e3c81fd7b04a45c5dbf)]:
8
+ - @lynx-js/web-constants@0.19.9
9
+
3
10
  ## 0.19.8
4
11
 
5
12
  ### Patch Changes
@@ -1,7 +1,7 @@
1
1
  // Copyright 2023 The Lynx Authors. All rights reserved.
2
2
  // Licensed under the Apache License Version 2.0 that can be found in the
3
3
  // LICENSE file in the root directory of this source tree.
4
- import { lynxUniqueIdAttribute, systemInfo, parentComponentUniqueIdAttribute, componentIdAttribute, LynxEventNameToW3cByTagName, LynxEventNameToW3cCommon, lynxTagAttribute, W3cEventNameToLynx, cssIdAttribute, lynxDefaultDisplayLinearAttribute, __lynx_timing_flag, lynxDisposedAttribute, lynxEntryNameAttribute, ErrorCode, } from '@lynx-js/web-constants';
4
+ import { lynxUniqueIdAttribute, systemInfo, parentComponentUniqueIdAttribute, componentIdAttribute, LynxEventNameToW3cByTagName, LynxEventNameToW3cCommon, lynxTagAttribute, W3cEventNameToLynx, cssIdAttribute, lynxDefaultDisplayLinearAttribute, __lynx_timing_flag, lynxDisposedAttribute, lynxEntryNameAttribute, ErrorCode, AnimationOperation, } from '@lynx-js/web-constants';
5
5
  import { createMainThreadLynx } from './createMainThreadLynx.js';
6
6
  import { __AddClass, __AddConfig, __AddDataset, __AddInlineStyle, __AppendElement, __ElementIsEqual, __FirstElement, __GetAttributes, __GetChildren, __GetClasses, __GetComponentID, __GetDataByKey, __GetDataset, __GetElementConfig, __GetElementUniqueID, __GetID, __GetParent, __GetTag, __GetTemplateParts, __InsertElementBefore, __LastElement, __MarkPartElement, __MarkTemplateElement, __NextElement, __RemoveElement, __ReplaceElement, __ReplaceElements, __SetClasses, __SetConfig, __SetCSSId, __SetDataset, __SetID, __SetInlineStyles, __UpdateComponentID, __UpdateComponentInfo, __GetAttributeByName, } from './pureElementPAPIs.js';
7
7
  import { createCrossThreadEvent } from './utils/createCrossThreadEvent.js';
@@ -470,6 +470,61 @@ export function createMainThreadGlobalThis(config) {
470
470
  }
471
471
  return el;
472
472
  };
473
+ const animationMap = new Map();
474
+ const mapTimingOptions = (options) => {
475
+ if (!options)
476
+ return undefined;
477
+ const result = {};
478
+ if ('duration' in options)
479
+ result.duration = Number(options['duration']);
480
+ if ('delay' in options)
481
+ result.delay = Number(options['delay']);
482
+ if ('direction' in options) {
483
+ result.direction = options['direction'];
484
+ }
485
+ if ('iterationCount' in options) {
486
+ result.iterations = options['iterationCount'] === 'infinite'
487
+ ? Infinity
488
+ : Number(options['iterationCount']);
489
+ }
490
+ if ('fillMode' in options)
491
+ result.fill = options['fillMode'];
492
+ if ('timingFunction' in options) {
493
+ result.easing = options['timingFunction'];
494
+ }
495
+ return result;
496
+ };
497
+ const __ElementAnimate = (element, args) => {
498
+ const [operation, name] = args;
499
+ switch (operation) {
500
+ case AnimationOperation.START: {
501
+ const keyframes = args[2];
502
+ const options = args[3];
503
+ animationMap.get(name)?.cancel();
504
+ const animation = element.animate(keyframes, mapTimingOptions(options));
505
+ animation.oncancel = animation.onfinish = () => {
506
+ if (animationMap.get(name) === animation) {
507
+ animationMap.delete(name);
508
+ }
509
+ };
510
+ animationMap.set(name, animation);
511
+ break;
512
+ }
513
+ case AnimationOperation.PLAY:
514
+ animationMap.get(name)?.play();
515
+ break;
516
+ case AnimationOperation.PAUSE:
517
+ animationMap.get(name)?.pause();
518
+ break;
519
+ case AnimationOperation.CANCEL:
520
+ animationMap.get(name)?.cancel();
521
+ animationMap.delete(name);
522
+ break;
523
+ case AnimationOperation.FINISH:
524
+ animationMap.get(name)?.finish();
525
+ break;
526
+ }
527
+ };
473
528
  const __GetPageElement = () => {
474
529
  return pageElement;
475
530
  };
@@ -616,6 +671,7 @@ export function createMainThreadGlobalThis(config) {
616
671
  renderPage: undefined,
617
672
  __InvokeUIMethod,
618
673
  __QuerySelector,
674
+ __ElementAnimate,
619
675
  };
620
676
  Object.assign(mtsRealm.globalWindow, mtsGlobalThis);
621
677
  Object.defineProperty(mtsRealm.globalWindow, 'renderPage', {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lynx-js/web-mainthread-apis",
3
- "version": "0.19.8",
3
+ "version": "0.19.9",
4
4
  "private": false,
5
5
  "description": "",
6
6
  "keywords": [],
@@ -28,7 +28,7 @@
28
28
  "dependencies": {
29
29
  "hyphenate-style-name": "^1.1.0",
30
30
  "wasm-feature-detect": "^1.8.0",
31
- "@lynx-js/web-constants": "0.19.8"
31
+ "@lynx-js/web-constants": "0.19.9"
32
32
  },
33
33
  "devDependencies": {
34
34
  "binaryen": "^125.0.0",