提交 76f708c2 编写于 作者: fxy060608's avatar fxy060608

wip(uts): compiler

上级 7d9d3614
{"version":3,"sources":["uni_modules/test-component/utssdk/app-ios/index.vue"],"sourcesContent":["\n\n\n\n\n\nimport {\n LottieAnimationView,\n LottieAnimation,\n LottieLoopMode\n} from 'Lottie'\nimport {\n URL\n} from 'Foundation'\nimport {\n UIView\n} from \"UIKit\"\nimport {\n UTSiOS\n} from \"DCloudUTSFoundation\"\n\n\n//原生提供以下属性或方法的实现 \nexport default {\n name: \"animation-view\",\n /**\n * 当播放到末尾时触发 ended 事件(自然播放结束会触发回调,循环播放结束及手动停止动画不会触发)\n */\n emits: ['bindended'],\n props: {\n /**\n * 动画资源地址,目前只支持绝对路径\n */\n \"path\": {\n type: String,\n },\n /**\n * 动画是否循环播放\n */\n \"autoplay\": {\n type: Boolean,\n },\n /**\n * 动画是否自动播放\n */\n \"loop\": {\n type: Boolean,\n },\n /**\n * 是否隐藏动画\n */\n \"hidden\": {\n type: Boolean,\n },\n /**\n * 动画操作,可取值 play、pause、stop\n */\n \"action\": {\n type: String,\n }\n\n },\n data() {\n return {\n animationView: LottieAnimationView!\n }\n },\n watch: {\n\n /// 注意: newValue 都需要强转成对应的类型\n\n \"path\": {\n handler(newValue: string, oldValue: string) {\n this.path = newValue\n if (this.autoplay) {\n this.playAnimation()\n }\n },\n immediate: false //创建时是否通过此方法更新属性,默认值为false \n },\n \"loop\": {\n handler(newValue: boolean, oldValue: boolean) {\n this.loop = newValue\n if (this.loop) {\n this.animationView.loopMode = LottieLoopMode.loop\n }\n },\n immediate: false //创建时是否通过此方法更新属性,默认值为false \n },\n \"autoplay\": {\n handler(newValue: boolean, oldValue: boolean) {\n this.autoplay = newValue\n },\n immediate: false //创建时是否通过此方法更新属性,默认值为false \n },\n \"action\": {\n handler(newValue: string, oldValue: string) {\n const action = newValue\n\n if (action == \"play\" || action == \"pause\" || action == \"stop\") {\n this.action = action\n switch (action) {\n case \"play\":\n this.playAnimation()\n break;\n case \"pause\":\n this.animationView.pause()\n break;\n case \"stop\":\n this.animationView.stop()\n break;\n default:\n break;\n }\n } else {\n // 非法入参,不管\n }\n },\n immediate: false //创建时是否通过此方法更新属性,默认值为false \n },\n\n \"hidden\": {\n handler(newValue: boolean, oldValue: boolean) {\n this.hidden = newValue\n this.animationView.isHidden = this.hidden\n },\n immediate: false //创建时是否通过此方法更新属性,默认值为false \n },\n\n },\n methods: {\n // 需要对外暴露的方法\n // 设置 RepeatMode \n setRepeatMode(repeatMode: string) {\n if (repeatMode == \"RESTART\") {\n if (this.loop) {\n this.animationView.loopMode = LottieLoopMode.loop\n } else {\n this.animationView.loopMode = LottieLoopMode.playOnce\n }\n } else if (repeatMode == \"REVERSE\") {\n if (this.loop) {\n this.animationView.loopMode = LottieLoopMode.autoReverse\n } else {\n this.animationView.loopMode = LottieLoopMode.repeatBackwards(1)\n }\n }\n },\n // 不对外暴露的方法\n // 播放动画 \n playAnimation() {\n if (this.path == null) {\n return\n }\n\n // 构建动画资源 url\n var animationUrl: URL | null\n\n if (this.path!.hasPrefix(\"http\")) {\n animationUrl = new URL(string = this.path!)\n } else {\n var filePath = UTSiOS.getResourcePath(this.path!)\n animationUrl = new URL(filePath = filePath)\n }\n\n if (animationUrl != null) {\n // 加载动画 LottieAnimation\n LottieAnimation.loadedFrom(url = animationUrl!, closure = (animation: LottieAnimation): void => {\n if (animation != null) {\n // 加载成功开始播放\n this.animationView.animation = animation\n this.animationView.play(completion = (isFinish: boolean): void => {\n if (isFinish) {\n // 播放完成回调事件\n this.fireEvent(\"bindended\")\n }\n })\n }\n })\n }\n }\n },\n created() { //创建组件,替换created \n\n },\n measure(size: UTSSize): UTSSize { //测量组件大小\n //可选实现,仅当需要原生计算组件大小时需要实现 \n return new UTSSize(100, 100);\n },\n NVBeforeLoad() { //组件将要创建,对应前端beforeMount \n //可选实现,这里可以提前做一些操作 \n },\n NVLoad(): UIView { //创建原生View,必须定义返回值类型(Android需要明确知道View类型,需特殊校验) \n // 初始化 LottieAnimationView\n this.animationView = new LottieAnimationView()\n // 默认只播放一次动画\n this.animationView.loopMode = LottieLoopMode.playOnce\n return this.animationView\n },\n NVLoaded() { //原生View已创建 \n\n /// 更新 props 中定义的属性值\n\n if (this.loop) {\n this.animationView.loopMode = LottieLoopMode.loop\n }\n\n this.animationView.isHidden = this.hidden\n\n if (this.autoplay) {\n this.playAnimation()\n }\n },\n\n NVLayouted() { //原生View布局完成 \n //可选实现,这里可以做布局后续操作 \n },\n\n NVBeforeUnload() { //原生View将释放 \n //可选实现,这里可以做释放View之前的操作 \n },\n NVUnloaded() { //原生View已释放 \n //可选实现,这里可以做释放View之后的操作 \n },\n unmounted() { //组件销毁 \n //可选实现 \n }\n}\n\n\n\n\n\n\n\n\n"],"names":[],"mappings":";AAMA;AAKA;AAGA;AAGA;;;4CA+Kc;sBA9JI;0BAMA;sBAMA;wBAMA;wBAMA;gCAMS;mCAsHb,CAEV;iCACQ,EAAA,MAAM,OAAO,KAAG,QAAQ;QAE5B,OAAO,AAAI,QAAQ,GAAG,EAAE,GAAG;IAC/B;wCACe,CAEf;4CACiB;QAEb,IAAI,CAAC,aAAa,GAAG,AAAI;QAEzB,IAAI,CAAC,aAAa,CAAC,QAAQ,GAAG,eAAe,QAAQ;QACrD,OAAO,IAAI,CAAC,aAAa;IAC7B;oCACW;QAIP,IAAI,IAAI,CAAC,IAAI;YACT,IAAI,CAAC,aAAa,CAAC,QAAQ,GAAG,eAAe,IAAI;;QAGrD,IAAI,CAAC,aAAa,CAAC,QAAQ,GAAG,IAAI,CAAC,MAAM;QAEzC,IAAI,IAAI,CAAC,QAAQ;YACb,IAAI,CAAC,aAAa;;IAE1B;sCAEa,CAEb;0CAEiB,CAEjB;sCACa,CAEb;qCACY,CAEZ;8BA7FkB,EAAA,YAAY,MAAM,EAAE;QAC9B,IAAI,cAAc;YACd,IAAI,IAAI,CAAC,IAAI;gBACT,IAAI,CAAC,aAAa,CAAC,QAAQ,GAAG,eAAe,IAAI;;;gBAEjD,IAA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,IAAI,CAAC,MAAM,GAAG;YACd,OAAQ;gBACJ,KAAK;oBACD,IAAI,CAAC,aAAa;oBAClB,KAAM;gBACV,KAAK;oBACD,IAAI,CAAC,aAAa,CAAC,KAAK;oBACxB,KAAM;gBACV,KAAK;oBACD,IAAI,CAAC,aAAa,CAAC,IAAI;oBACvB,KAAM;gBACV;oBACI,KAAM;YACd;QACJ;;uBAQiC,IAAO;SAApC,UAAmB;QACvB,IAAI,CAAC,MAAM,GAAG;QACd,IAAI,CAAC,aAAa,CAAC,QAAQ,GAAG,IAAI,CAAC,MAAM"}
\ No newline at end of file
{"version":3,"sources":["uni_modules/test-component/utssdk/app-ios/index.vue"],"sourcesContent":["\n\n\n\n\n\nimport {\n LottieAnimationView,\n LottieAnimation,\n LottieLoopMode\n} from 'Lottie'\nimport {\n URL\n} from 'Foundation'\nimport {\n UIView\n} from \"UIKit\"\nimport {\n UTSiOS\n} from \"DCloudUTSFoundation\"\n\n\n//原生提供以下属性或方法的实现 \nexport default {\n name: \"animation-view\",\n /**\n * 当播放到末尾时触发 ended 事件(自然播放结束会触发回调,循环播放结束及手动停止动画不会触发)\n */\n emits: ['bindended'],\n props: {\n /**\n * 动画资源地址,目前只支持绝对路径\n */\n \"path\": {\n type: String,\n },\n /**\n * 动画是否循环播放\n */\n \"autoplay\": {\n type: Boolean,\n },\n /**\n * 动画是否自动播放\n */\n \"loop\": {\n type: Boolean,\n },\n /**\n * 是否隐藏动画\n */\n \"hidden\": {\n type: Boolean,\n },\n /**\n * 动画操作,可取值 play、pause、stop\n */\n \"action\": {\n type: String,\n }\n\n },\n data() {\n return {\n animationView: LottieAnimationView!\n }\n },\n watch: {\n\n /// 注意: newValue 都需要强转成对应的类型\n\n \"path\": {\n handler(newValue: string, oldValue: string) {\n this.path = newValue\n if (this.autoplay) {\n this.playAnimation()\n }\n },\n immediate: false //创建时是否通过此方法更新属性,默认值为false \n },\n \"loop\": {\n handler(newValue: boolean, oldValue: boolean) {\n this.loop = newValue\n if (this.loop) {\n this.animationView.loopMode = LottieLoopMode.loop\n }\n },\n immediate: false //创建时是否通过此方法更新属性,默认值为false \n },\n \"autoplay\": {\n handler(newValue: boolean, oldValue: boolean) {\n this.autoplay = newValue\n },\n immediate: false //创建时是否通过此方法更新属性,默认值为false \n },\n \"action\": {\n handler(newValue: string, oldValue: string) {\n const action = newValue\n\n if (action == \"play\" || action == \"pause\" || action == \"stop\") {\n this.action = action\n switch (action) {\n case \"play\":\n this.playAnimation()\n break;\n case \"pause\":\n this.animationView.pause()\n break;\n case \"stop\":\n this.animationView.stop()\n break;\n default:\n break;\n }\n } else {\n // 非法入参,不管\n }\n },\n immediate: false //创建时是否通过此方法更新属性,默认值为false \n },\n\n \"hidden\": {\n handler(newValue: boolean, oldValue: boolean) {\n this.hidden = newValue\n this.animationView.isHidden = this.hidden\n },\n immediate: false //创建时是否通过此方法更新属性,默认值为false \n },\n\n },\n methods: {\n // 需要对外暴露的方法\n // 设置 RepeatMode \n setRepeatMode(repeatMode: string) {\n if (repeatMode == \"RESTART\") {\n if (this.loop) {\n this.animationView.loopMode = LottieLoopMode.loop\n } else {\n this.animationView.loopMode = LottieLoopMode.playOnce\n }\n } else if (repeatMode == \"REVERSE\") {\n if (this.loop) {\n this.animationView.loopMode = LottieLoopMode.autoReverse\n } else {\n this.animationView.loopMode = LottieLoopMode.repeatBackwards(1)\n }\n }\n },\n // 不对外暴露的方法\n // 播放动画 \n playAnimation() {\n if (this.path == null) {\n return\n }\n\n // 构建动画资源 url\n var animationUrl: URL | null\n\n if (this.path!.hasPrefix(\"http\")) {\n animationUrl = new URL(string = this.path!)\n } else {\n var filePath = UTSiOS.getResourcePath(this.path!)\n animationUrl = new URL(filePath = filePath)\n }\n\n if (animationUrl != null) {\n // 加载动画 LottieAnimation\n LottieAnimation.loadedFrom(url = animationUrl!, closure = (animation: LottieAnimation): void => {\n if (animation != null) {\n // 加载成功开始播放\n this.animationView.animation = animation\n this.animationView.play(completion = (isFinish: boolean): void => {\n if (isFinish) {\n // 播放完成回调事件\n this.fireEvent(\"bindended\")\n }\n })\n }\n })\n }\n }\n },\n created() { //创建组件,替换created \n\n },\n measure(size: UTSSize): UTSSize { //测量组件大小\n //可选实现,仅当需要原生计算组件大小时需要实现 \n return new UTSSize(100, 100);\n },\n NVBeforeLoad() { //组件将要创建,对应前端beforeMount \n //可选实现,这里可以提前做一些操作 \n },\n NVLoad(): UIView { //创建原生View,必须定义返回值类型(Android需要明确知道View类型,需特殊校验) \n // 初始化 LottieAnimationView\n this.animationView = new LottieAnimationView()\n // 默认只播放一次动画\n this.animationView.loopMode = LottieLoopMode.playOnce\n return this.animationView\n },\n NVLoaded() { //原生View已创建 \n\n /// 更新 props 中定义的属性值\n\n if (this.loop) {\n this.animationView.loopMode = LottieLoopMode.loop\n }\n\n this.animationView.isHidden = this.hidden\n\n if (this.autoplay) {\n this.playAnimation()\n }\n },\n\n NVLayouted() { //原生View布局完成 \n //可选实现,这里可以做布局后续操作 \n },\n\n NVBeforeUnload() { //原生View将释放 \n //可选实现,这里可以做释放View之前的操作 \n },\n NVUnloaded() { //原生View已释放 \n //可选实现,这里可以做释放View之后的操作 \n },\n unmounted() { //组件销毁 \n //可选实现 \n }\n}\n\n\n\n\n\n\n\n\n"],"names":[],"mappings":";AAMA;AAKA;AAGA;AAGA;;;4CA+Kc;sBA9JI;0BAMA;sBAMA;wBAMA;wBAMA;gCAMS;mCAsHb,CAEV;iCACQ,EAAA,MAAM,OAAO,KAAG,QAAQ;QAE5B,OAAO,AAAI,QAAQ,GAAG,EAAE,GAAG;IAC/B;wCACe,CAEf;4CACiB;QAEb,IAAI,CAAC,aAAa,GAAG,AAAI;QAEzB,IAAI,CAAC,aAAa,CAAC,QAAQ,GAAG,eAAe,QAAQ;QACrD,OAAO,IAAI,CAAC,aAAa;IAC7B;oCACW;QAIP,IAAI,IAAI,CAAC,IAAI;YACT,IAAI,CAAC,aAAa,CAAC,QAAQ,GAAG,eAAe,IAAI;;QAGrD,IAAI,CAAC,a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CAAC,aAAa;;;;SAMlB,UAAU,IAAO,EAAE,UAAU,IAAO;QACxC,IAAI,CAAC,IAAI,GAAG;QACZ,IAAI,IAAI,CAAC,IAAI;YACT,IAAI,CAAC,aAAa,CAAC,QAAQ,GAAG,eAAe,IAAI;;;;SAMjD,UAAU,IAAO,EAAE,UAAU,IAAO;QACxC,IAAI,CAAC,QAAQ,GAAG;;;SAKZ,UAAU,MAAM,EAAE,UAAU,MAAM;QACtC,IAAM,SAAS;QAEf,IAAI,UAAU,UAAU,UAAU,WAAW,UAAU,QAAQ;YAC3D,IAAI,CAAC,MAAM,GAAG;YACd,OAAQ;gBACJ,KAAK;oBACD,IAAI,CAAC,aAAa;oBAClB,KAAM;gBACV,KAAK;oBACD,IAAI,CAAC,aAAa,CAAC,KAAK;oBACxB,KAAM;gBACV,KAAK;oBACD,IAAI,CAAC,aAAa,CAAC,IAAI;oBACvB,KAAM;gBACV;oBACI,KAAM;YACd;QACJ;;;SAQI,UAAU,IAAO,EAAE,UAAU,IAAO;QACxC,IAAI,CAAC,MAAM,GAAG;QACd,IAAI,CAAC,aAAa,CAAC,QAAQ,GAAG,IAAI,CAAC,MAAM"}
\ No newline at end of file
......@@ -89,26 +89,26 @@ class AnimationViewComponent : UTSComponent<UIView> {
return "playAnimation";
}
public override func __$$init() {
self.__$$watch<String>("path", {
(newValue, oldValue) in
self.__$$watch("path", {
(newValue: String, oldValue: String) in
self.path = newValue;
if (self.autoplay) {
self.playAnimation();
}
});
self.__$$watch<Bool>("loop", {
(newValue, oldValue) in
self.__$$watch("loop", {
(newValue: Bool, oldValue: Bool) in
self.loop = newValue;
if (self.loop) {
self.animationView.loopMode = LottieLoopMode.loop;
}
});
self.__$$watch<Bool>("autoplay", {
(newValue, oldValue) in
self.__$$watch("autoplay", {
(newValue: Bool, oldValue: Bool) in
self.autoplay = newValue;
});
self.__$$watch<String>("action", {
(newValue, oldValue) in
self.__$$watch("action", {
(newValue: String, oldValue: String) in
var action = newValue;
if (action == "play" || action == "pause" || action == "stop") {
self.action = action;
......@@ -127,8 +127,8 @@ class AnimationViewComponent : UTSComponent<UIView> {
}
}
});
self.__$$watch<Bool>("hidden", {
(newValue, oldValue) in
self.__$$watch("hidden", {
(newValue: Bool, oldValue: Bool) in
self.hidden = newValue;
self.animationView.isHidden = self.hidden;
});
......
......@@ -5,11 +5,17 @@ import {
resolveUtsAppModule,
resolveUTSCompiler,
} from '@dcloudio/uni-cli-shared'
import { once } from '@dcloudio/uni-shared'
const UTSProxyRE = /\?uts-proxy$/
function isUTSProxy(id: string) {
return UTSProxyRE.test(id)
}
const utsModuleCaches = new Map<
string,
() => Promise<undefined | { code: string; deps: string[] }>
>()
export function uniUtsV1Plugin(): Plugin {
return {
name: 'uni:uts',
......@@ -33,16 +39,34 @@ export function uniUtsV1Plugin(): Plugin {
return ''
}
},
buildEnd() {
utsModuleCaches.clear()
},
async transform(_, id, opts) {
if (opts && opts.ssr) {
return
}
if (!isUTSProxy(id)) {
return
}
const { filename: pluginDir } = parseVueRequest(id.replace('\0', ''))
const result = await resolveUTSCompiler().compile(pluginDir)
// 当 vue 和 nvue 均引用了相同 uts 插件,解决两套编译器会编译两次 uts 插件的问题
// 通过缓存,保证同一个 uts 插件只编译一次
if (utsModuleCaches.get(pluginDir)) {
return utsModuleCaches.get(pluginDir)!().then((result) => {
if (result) {
result.deps.forEach((dep) => {
this.addWatchFile(dep)
})
return result.code
}
})
}
const compile = once(() => {
return resolveUTSCompiler().compile(pluginDir)
})
utsModuleCaches.set(pluginDir, compile)
const result = await compile()
if (result) {
result.deps.forEach((dep) => {
this.addWatchFile(dep)
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册