Skip to content

armgit / anime

Public Imported from GitHub
0

JavaScript animation engine

Prevents conflict with other CSS.registerProperty #1000

Julian Garnieraf68737a8112
diff --git a/lib/anime.esm.js b/lib/anime.esm.js
index 020c2cf5..532bfb2a 100644
--- a/lib/anime.esm.js
+++ b/lib/anime.esm.js
@@ -3826,6 +3826,7 @@ const validIndividualTransforms = [...transformsShorthands, ...validTransforms.f
let transformsPropertiesRegistered = isBrowser && (isUnd(CSS) || !Object.hasOwnProperty.call(CSS, 'registerProperty'));
const registerTransformsProperties = () => {
+ if (transformsPropertiesRegistered) return;
validTransforms.forEach(t => {
const isSkew = stringStartsWith(t, 'skew');
const isScale = stringStartsWith(t, 'scale');
@@ -3833,13 +3834,14 @@ const registerTransformsProperties = () => {
const isTranslate = stringStartsWith(t, 'translate');
const isAngle = isRotate || isSkew;
const syntax = isAngle ? '<angle>' : isScale ? "<number>" : isTranslate ? "<length-percentage>" : "*";
- CSS.registerProperty({
- name: '--' + t,
- syntax,
- inherits: false,
- initialValue: isTranslate ? '0px' : isAngle ? '0deg' : isScale ? '1' : '0',
- });
- });
+ try {
+ CSS.registerProperty({
+ name: '--' + t,
+ syntax,
+ inherits: false,
+ initialValue: isTranslate ? '0px' : isAngle ? '0deg' : isScale ? '1' : '0',
+ });
+ } catch {} });
transformsPropertiesRegistered = true;
};
@@ -3954,7 +3956,7 @@ class WAAPIAnimation {
if (globals.scope) globals.scope.revertibles.push(this);
- if (!transformsPropertiesRegistered) registerTransformsProperties();
+ registerTransformsProperties();
const parsedTargets = registerTargets(targets);
const targetsLength = parsedTargets.length;
diff --git a/src/waapi.js b/src/waapi.js
index d50bccfa..1bb73380 100644
--- a/src/waapi.js
+++ b/src/waapi.js
@@ -172,6 +172,7 @@ const validIndividualTransforms = [...transformsShorthands, ...validTransforms.f
let transformsPropertiesRegistered = isBrowser && (isUnd(CSS) || !Object.hasOwnProperty.call(CSS, 'registerProperty'));
const registerTransformsProperties = () => {
+ if (transformsPropertiesRegistered) return;
validTransforms.forEach(t => {
const isSkew = stringStartsWith(t, 'skew');
const isScale = stringStartsWith(t, 'scale');
@@ -179,12 +180,14 @@ const registerTransformsProperties = () => {
const isTranslate = stringStartsWith(t, 'translate');
const isAngle = isRotate || isSkew;
const syntax = isAngle ? '<angle>' : isScale ? "<number>" : isTranslate ? "<length-percentage>" : "*";
- CSS.registerProperty({
- name: '--' + t,
- syntax,
- inherits: false,
- initialValue: isTranslate ? '0px' : isAngle ? '0deg' : isScale ? '1' : '0',
- });
+ try {
+ CSS.registerProperty({
+ name: '--' + t,
+ syntax,
+ inherits: false,
+ initialValue: isTranslate ? '0px' : isAngle ? '0deg' : isScale ? '1' : '0',
+ });
+ } catch {};
});
transformsPropertiesRegistered = true;
}
@@ -301,7 +304,7 @@ export class WAAPIAnimation {
if (globals.scope) globals.scope.revertibles.push(this);
- if (!transformsPropertiesRegistered) registerTransformsProperties();
+ registerTransformsProperties();
const parsedTargets = registerTargets(targets);
const targetsLength = parsedTargets.length;
diff --git a/tests/suites/waapi.test.js b/tests/suites/waapi.test.js
index afcb26a9..d4b68866 100644
--- a/tests/suites/waapi.test.js
+++ b/tests/suites/waapi.test.js
@@ -11,6 +11,26 @@ import {
suite('WAAPI', () => {
+ // Test fore
+
+ CSS.registerProperty({
+ name: '--translateX',
+ syntax: '<length-percentage>',
+ inherits: false,
+ initialValue: '0px'
+ });
+
+ test('Calling registerProperty on transforms should not conflict with the built-in one', resolve => {
+ waapi.animate('#target-id', {
+ scale: 1.5,
+ duration: 10,
+ onComplete: self => {
+ expect(self.completed).to.equal(true);
+ resolve();
+ }
+ })
+ });
+
test('Animate multiple elements', resolve => {
const targets = utils.$('.target-class');
const animation = waapi.animate(targets, {
diff --git a/types/index.js b/types/index.js
index 316d02a4..cc4294e0 100644
--- a/types/index.js
+++ b/types/index.js
@@ -3227,6 +3227,8 @@ const validIndividualTransforms = [...transformsShorthands, ...validTransforms.f
// Setting it to true in case CSS.registerProperty is not supported will automatically skip the registration and fallback to no animation
let transformsPropertiesRegistered = isBrowser && (isUnd(CSS) || !Object.hasOwnProperty.call(CSS, 'registerProperty'));
const registerTransformsProperties = () => {
+ if (transformsPropertiesRegistered)
+ return;
validTransforms.forEach(t => {
const isSkew = stringStartsWith(t, 'skew');
const isScale = stringStartsWith(t, 'scale');
@@ -3234,12 +3236,15 @@ const registerTransformsProperties = () => {
const isTranslate = stringStartsWith(t, 'translate');
const isAngle = isRotate || isSkew;
const syntax = isAngle ? '<angle>' : isScale ? "<number>" : isTranslate ? "<length-percentage>" : "*";
- CSS.registerProperty({
- name: '--' + t,
- syntax,
- inherits: false,
- initialValue: isTranslate ? '0px' : isAngle ? '0deg' : isScale ? '1' : '0',
- });
+ try {
+ CSS.registerProperty({
+ name: '--' + t,
+ syntax,
+ inherits: false,
+ initialValue: isTranslate ? '0px' : isAngle ? '0deg' : isScale ? '1' : '0',
+ });
+ }
+ catch { }
});
transformsPropertiesRegistered = true;
};
@@ -3357,8 +3362,7 @@ class WAAPIAnimation {
constructor(targets, params) {
if (globals.scope)
globals.scope.revertibles.push(this);
- if (!transformsPropertiesRegistered)
- registerTransformsProperties();
+ registerTransformsProperties();
const parsedTargets = registerTargets(targets);
const targetsLength = parsedTargets.length;
if (!targetsLength) {