diff --git a/packages/uni-core/src/helpers/animation.ts b/packages/uni-components/src/helpers/animation.ts similarity index 100% rename from packages/uni-core/src/helpers/animation.ts rename to packages/uni-components/src/helpers/animation.ts diff --git a/packages/uni-components/src/helpers/component.ts b/packages/uni-components/src/helpers/component.ts index 30e33024f694baa2170372becc7e9a231eee55af..4c54857d3cb317c99a71d1631bb69475aa990b4d 100644 --- a/packages/uni-components/src/helpers/component.ts +++ b/packages/uni-components/src/helpers/component.ts @@ -1,4 +1,5 @@ import { ComponentOptions, defineComponent } from 'vue' +import animation from './animation' /** * 内置组件(对外,比如view) * @param options @@ -8,6 +9,12 @@ export const defineBuiltInComponent: typeof defineComponent = ( options: any ) => { // TODO 可能会补充特殊标记 + if (!options.props || typeof options.props.animation === 'undefined') { + // 补充内置组件animation + typeof options.mixins !== 'undefined' + ? options.mixins.push(animation) + : (options.mixins = [animation]) + } return defineSystemComponent(options) } /** diff --git a/packages/uni-core/src/view/plugin/index.ts b/packages/uni-core/src/view/plugin/index.ts index 63ee919b32a90a5dd91d3a841a7c68ea1b727195..f639533180c1bc5337df312e90b9bbd96334283d 100644 --- a/packages/uni-core/src/view/plugin/index.ts +++ b/packages/uni-core/src/view/plugin/index.ts @@ -1,6 +1,5 @@ import { App } from 'vue' -import animation from '../../helpers/animation' import { initLongPress } from './longPress' import { initAppConfig } from './appConfig' import { initCostomDataset } from '@dcloudio/uni-shared' @@ -14,7 +13,6 @@ export function initView(app: App) { initLongPress() } initAppConfig(app._context.config) - app.mixin(animation) // TODO wxs,behaviors } diff --git a/packages/uni-h5/dist/uni-h5.cjs.js b/packages/uni-h5/dist/uni-h5.cjs.js index f1ca8925c5d493c8dfe217fa45f91cd5b4c96447..bd929539eccbfc0b228a509430992754d52cf5d7 100644 --- a/packages/uni-h5/dist/uni-h5.cjs.js +++ b/packages/uni-h5/dist/uni-h5.cjs.js @@ -1039,7 +1039,119 @@ function _sfc_render$8(_ctx, _cache, $props, $setup, $data, $options) { ], 16, ["id", "controls"]); } _sfc_main$8.render = _sfc_render$8; +function converPx(value) { + if (/^-?\d+[ur]px$/i.test(value)) { + return value.replace(/(^-?\d+)[ur]px$/i, (text, num) => { + return `${uni.upx2px(parseFloat(num))}px`; + }); + } else if (/^-?[\d\.]+$/.test(value)) { + return `${value}px`; + } + return value || ""; +} +function converType(type) { + return type.replace(/[A-Z]/g, (text) => { + return `-${text.toLowerCase()}`; + }).replace("webkit", "-webkit"); +} +function getStyle(action) { + const animateTypes1 = [ + "matrix", + "matrix3d", + "scale", + "scale3d", + "rotate3d", + "skew", + "translate", + "translate3d" + ]; + const animateTypes2 = [ + "scaleX", + "scaleY", + "scaleZ", + "rotate", + "rotateX", + "rotateY", + "rotateZ", + "skewX", + "skewY", + "translateX", + "translateY", + "translateZ" + ]; + const animateTypes3 = ["opacity", "background-color"]; + const animateTypes4 = ["width", "height", "left", "right", "top", "bottom"]; + const animates = action.animates; + const option = action.option; + const transition = option.transition; + const style = {}; + const transform = []; + animates.forEach((animate) => { + let type = animate.type; + let args = [...animate.args]; + if (animateTypes1.concat(animateTypes2).includes(type)) { + if (type.startsWith("rotate") || type.startsWith("skew")) { + args = args.map((value) => parseFloat(value) + "deg"); + } else if (type.startsWith("translate")) { + args = args.map(converPx); + } + if (animateTypes2.indexOf(type) >= 0) { + args.length = 1; + } + transform.push(`${type}(${args.join(",")})`); + } else if (animateTypes3.concat(animateTypes4).includes(args[0])) { + type = args[0]; + const value = args[1]; + style[type] = animateTypes4.includes(type) ? converPx(value) : value; + } + }); + style.transform = style.webkitTransform = transform.join(" "); + style.transition = style.webkitTransition = Object.keys(style).map((type) => `${converType(type)} ${transition.duration}ms ${transition.timingFunction} ${transition.delay}ms`).join(","); + style.transformOrigin = style.webkitTransformOrigin = option.transformOrigin; + return style; +} +function startAnimation(context) { + const animation2 = context.animation; + if (!animation2 || !animation2.actions || !animation2.actions.length) { + return; + } + let index2 = 0; + const actions = animation2.actions; + const length = animation2.actions.length; + function animate() { + const action = actions[index2]; + const transition = action.option.transition; + const style = getStyle(action); + Object.keys(style).forEach((key) => { + context.$el.style[key] = style[key]; + }); + index2 += 1; + if (index2 < length) { + setTimeout(animate, transition.duration + transition.delay); + } + } + setTimeout(() => { + animate(); + }, 0); +} +var animation = { + props: ["animation"], + watch: { + animation: { + deep: true, + handler() { + startAnimation(this); + } + } + }, + mounted() { + startAnimation(this); + } +}; const defineBuiltInComponent = (options) => { + if (!options.props || typeof options.props.animation === "undefined") { + typeof options.mixins !== "undefined" ? options.mixins.push(animation) : options.mixins = [animation]; + } return defineSystemComponent(options); }; const defineSystemComponent = (options) => { @@ -4620,13 +4732,13 @@ function createAnimation(scroll, onScroll, onEnd) { id: 0, cancelled: false }; - function startAnimation(state2, scroll2, onScroll2, onEnd2) { + function startAnimation2(state2, scroll2, onScroll2, onEnd2) { if (!state2 || !state2.cancelled) { onScroll2(scroll2); const isDone = scroll2.done(); if (!isDone) { if (!state2.cancelled) { - state2.id = requestAnimationFrame(startAnimation.bind(null, state2, scroll2, onScroll2, onEnd2)); + state2.id = requestAnimationFrame(startAnimation2.bind(null, state2, scroll2, onScroll2, onEnd2)); } } if (isDone && onEnd2) { @@ -4642,7 +4754,7 @@ function createAnimation(scroll, onScroll, onEnd) { state2.cancelled = true; } } - startAnimation(state, scroll, onScroll, onEnd); + startAnimation2(state, scroll, onScroll, onEnd); return { cancel: cancel.bind(null, state), model: scroll diff --git a/packages/uni-h5/dist/uni-h5.es.js b/packages/uni-h5/dist/uni-h5.es.js index 5f6f145bd5c9ca5ec3e1536cdffda8caf3f9fd88..a9cfeaa5a8231ffd9f205c34261bf5fd8b14c6ba 100644 --- a/packages/uni-h5/dist/uni-h5.es.js +++ b/packages/uni-h5/dist/uni-h5.es.js @@ -250,115 +250,6 @@ function initBridge(namespace) { }); } const ViewJSBridge = /* @__PURE__ */ initBridge("view"); -function converPx(value) { - if (/^-?\d+[ur]px$/i.test(value)) { - return value.replace(/(^-?\d+)[ur]px$/i, (text2, num) => { - return `${uni.upx2px(parseFloat(num))}px`; - }); - } else if (/^-?[\d\.]+$/.test(value)) { - return `${value}px`; - } - return value || ""; -} -function converType(type) { - return type.replace(/[A-Z]/g, (text2) => { - return `-${text2.toLowerCase()}`; - }).replace("webkit", "-webkit"); -} -function getStyle(action) { - const animateTypes1 = [ - "matrix", - "matrix3d", - "scale", - "scale3d", - "rotate3d", - "skew", - "translate", - "translate3d" - ]; - const animateTypes2 = [ - "scaleX", - "scaleY", - "scaleZ", - "rotate", - "rotateX", - "rotateY", - "rotateZ", - "skewX", - "skewY", - "translateX", - "translateY", - "translateZ" - ]; - const animateTypes3 = ["opacity", "background-color"]; - const animateTypes4 = ["width", "height", "left", "right", "top", "bottom"]; - const animates = action.animates; - const option = action.option; - const transition = option.transition; - const style = {}; - const transform = []; - animates.forEach((animate) => { - let type = animate.type; - let args = [...animate.args]; - if (animateTypes1.concat(animateTypes2).includes(type)) { - if (type.startsWith("rotate") || type.startsWith("skew")) { - args = args.map((value) => parseFloat(value) + "deg"); - } else if (type.startsWith("translate")) { - args = args.map(converPx); - } - if (animateTypes2.indexOf(type) >= 0) { - args.length = 1; - } - transform.push(`${type}(${args.join(",")})`); - } else if (animateTypes3.concat(animateTypes4).includes(args[0])) { - type = args[0]; - const value = args[1]; - style[type] = animateTypes4.includes(type) ? converPx(value) : value; - } - }); - style.transform = style.webkitTransform = transform.join(" "); - style.transition = style.webkitTransition = Object.keys(style).map((type) => `${converType(type)} ${transition.duration}ms ${transition.timingFunction} ${transition.delay}ms`).join(","); - style.transformOrigin = style.webkitTransformOrigin = option.transformOrigin; - return style; -} -function startAnimation(context) { - const animation2 = context.animation; - if (!animation2 || !animation2.actions || !animation2.actions.length) { - return; - } - let index2 = 0; - const actions = animation2.actions; - const length = animation2.actions.length; - function animate() { - const action = actions[index2]; - const transition = action.option.transition; - const style = getStyle(action); - Object.keys(style).forEach((key) => { - context.$el.style[key] = style[key]; - }); - index2 += 1; - if (index2 < length) { - setTimeout(animate, transition.duration + transition.delay); - } - } - setTimeout(() => { - animate(); - }, 0); -} -var animation = { - props: ["animation"], - watch: { - animation: { - deep: true, - handler() { - startAnimation(this); - } - } - }, - mounted() { - startAnimation(this); - } -}; const LONGPRESS_TIMEOUT = 350; const LONGPRESS_THRESHOLD = 10; const passiveOptions$2 = passive(true); @@ -1082,7 +973,6 @@ function initView(app) { initLongPress(); } initAppConfig$1(app._context.config); - app.mixin(animation); } const ServiceJSBridge = /* @__PURE__ */ extend(initBridge("service"), { invokeOnCallback(name, res) { @@ -2090,7 +1980,119 @@ function _sfc_render$8(_ctx, _cache, $props, $setup, $data, $options) { ], 16, ["id", "controls"]); } _sfc_main$8.render = _sfc_render$8; +function converPx(value) { + if (/^-?\d+[ur]px$/i.test(value)) { + return value.replace(/(^-?\d+)[ur]px$/i, (text2, num) => { + return `${uni.upx2px(parseFloat(num))}px`; + }); + } else if (/^-?[\d\.]+$/.test(value)) { + return `${value}px`; + } + return value || ""; +} +function converType(type) { + return type.replace(/[A-Z]/g, (text2) => { + return `-${text2.toLowerCase()}`; + }).replace("webkit", "-webkit"); +} +function getStyle(action) { + const animateTypes1 = [ + "matrix", + "matrix3d", + "scale", + "scale3d", + "rotate3d", + "skew", + "translate", + "translate3d" + ]; + const animateTypes2 = [ + "scaleX", + "scaleY", + "scaleZ", + "rotate", + "rotateX", + "rotateY", + "rotateZ", + "skewX", + "skewY", + "translateX", + "translateY", + "translateZ" + ]; + const animateTypes3 = ["opacity", "background-color"]; + const animateTypes4 = ["width", "height", "left", "right", "top", "bottom"]; + const animates = action.animates; + const option = action.option; + const transition = option.transition; + const style = {}; + const transform = []; + animates.forEach((animate) => { + let type = animate.type; + let args = [...animate.args]; + if (animateTypes1.concat(animateTypes2).includes(type)) { + if (type.startsWith("rotate") || type.startsWith("skew")) { + args = args.map((value) => parseFloat(value) + "deg"); + } else if (type.startsWith("translate")) { + args = args.map(converPx); + } + if (animateTypes2.indexOf(type) >= 0) { + args.length = 1; + } + transform.push(`${type}(${args.join(",")})`); + } else if (animateTypes3.concat(animateTypes4).includes(args[0])) { + type = args[0]; + const value = args[1]; + style[type] = animateTypes4.includes(type) ? converPx(value) : value; + } + }); + style.transform = style.webkitTransform = transform.join(" "); + style.transition = style.webkitTransition = Object.keys(style).map((type) => `${converType(type)} ${transition.duration}ms ${transition.timingFunction} ${transition.delay}ms`).join(","); + style.transformOrigin = style.webkitTransformOrigin = option.transformOrigin; + return style; +} +function startAnimation(context) { + const animation2 = context.animation; + if (!animation2 || !animation2.actions || !animation2.actions.length) { + return; + } + let index2 = 0; + const actions = animation2.actions; + const length = animation2.actions.length; + function animate() { + const action = actions[index2]; + const transition = action.option.transition; + const style = getStyle(action); + Object.keys(style).forEach((key) => { + context.$el.style[key] = style[key]; + }); + index2 += 1; + if (index2 < length) { + setTimeout(animate, transition.duration + transition.delay); + } + } + setTimeout(() => { + animate(); + }, 0); +} +var animation = { + props: ["animation"], + watch: { + animation: { + deep: true, + handler() { + startAnimation(this); + } + } + }, + mounted() { + startAnimation(this); + } +}; const defineBuiltInComponent = (options) => { + if (!options.props || typeof options.props.animation === "undefined") { + typeof options.mixins !== "undefined" ? options.mixins.push(animation) : options.mixins = [animation]; + } return defineSystemComponent(options); }; const defineSystemComponent = (options) => {