提交 0d315a3e 编写于 作者: fxy060608's avatar fxy060608

wip(uts): compiler

上级 a8b1f299
......@@ -283,12 +283,32 @@ function initUtsProxyClass({ package: pkg, class: cls, constructor: { params: co
return Reflect.get(target, name, receiver);
},
});
}
function initUtsPackageName(name, is_uni_modules) {
if (typeof plus !== 'undefined' && plus.os.name === 'Android') {
return 'uts.sdk.' + (is_uni_modules ? 'modules.' : '') + name;
}
return '';
}
function initUtsClassName(name, is_uni_modules) {
if (typeof plus === 'undefined') {
return '';
}
if (plus.os.name === 'Android') {
return 'IndexKt';
}
if (plus.os.name === 'iOS') {
return 'UTSSDK' + (is_uni_modules ? 'Modules' : '') + shared.capitalize(name);
}
return '';
}
exports.formatAppLog = formatAppLog;
exports.formatH5Log = formatH5Log;
exports.getCurrentSubNVue = getCurrentSubNVue;
exports.getSsrGlobalData = getSsrGlobalData;
exports.initUtsClassName = initUtsClassName;
exports.initUtsPackageName = initUtsPackageName;
exports.initUtsProxyClass = initUtsProxyClass;
exports.initUtsProxyFunction = initUtsProxyFunction;
exports.onAddToFavorites = onAddToFavorites;
......
......@@ -39,6 +39,10 @@ export declare function getCurrentSubNVue(): any;
export declare function getSsrGlobalData(): any;
export declare function initUtsClassName(name: string, is_uni_modules: boolean): string;
export declare function initUtsPackageName(name: string, is_uni_modules: boolean): string;
export declare function initUtsProxyClass({ package: pkg, class: cls, constructor: { params: constructorParams }, methods, props, staticProps, staticMethods, }: ProxyClassOptions): any;
export declare const initUtsProxyFunction: typeof initUtsStaticMethod;
......
import { shallowRef, ref, getCurrentInstance, isInSSRComponentSetup, injectHook } from 'vue';
import { hasOwn, isString, extend, isPlainObject } from '@vue/shared';
import { hasOwn, isString, extend, capitalize, isPlainObject } from '@vue/shared';
import { sanitise, UNI_SSR_DATA, UNI_SSR_GLOBAL_DATA, UNI_SSR, ON_SHOW, ON_HIDE, ON_LAUNCH, ON_ERROR, ON_THEME_CHANGE, ON_PAGE_NOT_FOUND, ON_UNHANDLE_REJECTION, ON_INIT, ON_LOAD, ON_READY, ON_UNLOAD, ON_RESIZE, ON_BACK_PRESS, ON_PAGE_SCROLL, ON_TAB_ITEM_TAP, ON_REACH_BOTTOM, ON_PULL_DOWN_REFRESH, ON_SAVE_EXIT_STATE, ON_SHARE_TIMELINE, ON_ADD_TO_FAVORITES, ON_SHARE_APP_MESSAGE, ON_NAVIGATION_BAR_BUTTON_TAP, ON_NAVIGATION_BAR_SEARCH_INPUT_CHANGED, ON_NAVIGATION_BAR_SEARCH_INPUT_CLICKED, ON_NAVIGATION_BAR_SEARCH_INPUT_CONFIRMED, ON_NAVIGATION_BAR_SEARCH_INPUT_FOCUS_CHANGED } from '@dcloudio/uni-shared';
function getSSRDataType() {
......@@ -251,6 +251,24 @@ function initUtsProxyClass({ package: pkg, class: cls, constructor: { params: co
return Reflect.get(target, name, receiver);
},
});
}
function initUtsPackageName(name, is_uni_modules) {
if (typeof plus !== 'undefined' && plus.os.name === 'Android') {
return 'uts.sdk.' + (is_uni_modules ? 'modules.' : '') + name;
}
return '';
}
function initUtsClassName(name, is_uni_modules) {
if (typeof plus === 'undefined') {
return '';
}
if (plus.os.name === 'Android') {
return 'IndexKt';
}
if (plus.os.name === 'iOS') {
return 'UTSSDK' + (is_uni_modules ? 'Modules' : '') + capitalize(name);
}
return '';
}
export { formatAppLog, formatH5Log, getCurrentSubNVue, getSsrGlobalData, initUtsProxyClass, initUtsProxyFunction, onAddToFavorites, onBackPress, onError, onHide, onInit, onLaunch, onLoad, onNavigationBarButtonTap, onNavigationBarSearchInputChanged, onNavigationBarSearchInputClicked, onNavigationBarSearchInputConfirmed, onNavigationBarSearchInputFocusChanged, onPageNotFound, onPageScroll, onPullDownRefresh, onReachBottom, onReady, onResize, onSaveExitState, onShareAppMessage, onShareTimeline, onShow, onTabItemTap, onThemeChange, onUnhandledRejection, onUnload, requireNativePlugin, resolveEasycom, shallowSsrRef, ssrRef };
export { formatAppLog, formatH5Log, getCurrentSubNVue, getSsrGlobalData, initUtsClassName, initUtsPackageName, initUtsProxyClass, initUtsProxyFunction, onAddToFavorites, onBackPress, onError, onHide, onInit, onLaunch, onLoad, onNavigationBarButtonTap, onNavigationBarSearchInputChanged, onNavigationBarSearchInputClicked, onNavigationBarSearchInputConfirmed, onNavigationBarSearchInputFocusChanged, onPageNotFound, onPageScroll, onPullDownRefresh, onReachBottom, onReady, onResize, onSaveExitState, onShareAppMessage, onShareTimeline, onShow, onTabItemTap, onThemeChange, onUnhandledRejection, onUnload, requireNativePlugin, resolveEasycom, shallowSsrRef, ssrRef };
......@@ -3,4 +3,9 @@ export * from './api'
export * from './hbx'
export * from './utils'
export * from './apiLifecycle'
export { initUtsProxyClass, initUtsProxyFunction } from './uts'
export {
initUtsProxyClass,
initUtsProxyFunction,
initUtsClassName,
initUtsPackageName,
} from './uts'
import { isPlainObject, hasOwn, extend } from '@vue/shared'
import { isPlainObject, hasOwn, extend, capitalize } from '@vue/shared'
declare const uni: any
declare const plus: any
let callbackId = 1
let proxy: any
const callbacks: Record<string, Function> = {}
......@@ -283,3 +284,23 @@ export function initUtsProxyClass({
},
})
}
export function initUtsPackageName(name: string, is_uni_modules: boolean) {
if (typeof plus !== 'undefined' && plus.os.name === 'Android') {
return 'uts.sdk.' + (is_uni_modules ? 'modules.' : '') + name
}
return ''
}
export function initUtsClassName(name: string, is_uni_modules: boolean) {
if (typeof plus === 'undefined') {
return ''
}
if (plus.os.name === 'Android') {
return 'IndexKt'
}
if (plus.os.name === 'iOS') {
return 'UTSSDK' + (is_uni_modules ? 'Modules' : '') + capitalize(name)
}
return ''
}
......@@ -131,23 +131,27 @@ export function resolveUtsModule(
const parts = normalizePath(id).split('/')
const parentDir = parts[parts.length - 2]
if (parentDir === 'uni_modules' || parentDir === 'utssdk') {
const index = path.resolve(id, 'index.uts')
const resolvePlatformDir = (p: typeof process.env.UNI_UTS_PLATFORM) => {
return path.resolve(id, parentDir === 'uni_modules' ? 'utssdk' : '', p)
}
// 未指定具体的平台
if (platform === 'app') {
platform = 'app-android'
}
let index = resolveUtsFile(resolvePlatformDir(platform))
if (index) {
return index
}
index = path.resolve(id, 'index.uts')
if (fs.existsSync(index)) {
return index
}
if (
parentDir === 'uni_modules' &&
!fs.existsSync(path.join(id, 'utssdk'))
) {
// uni_modules/test-plugin/utssdk不存在
return
// 如果是 android 或 ios,本平台没有,则查找一下另一个平台
if (platform === 'app-android') {
return resolveUtsFile(resolvePlatformDir('app-ios'))
} else if (platform === 'app-ios') {
return resolveUtsFile(resolvePlatformDir('app-android'))
}
const platformDir = path.resolve(
id,
parentDir === 'uni_modules' ? 'utssdk' : '',
platform
)
return resolveUtsFile(platformDir)
}
}
}
......
......@@ -2246,6 +2246,14 @@ const nvuePickerViewProps = extend({}, pickerViewProps, {
height: {
type: [Number, String],
default: 0
},
maskTopStyle: {
type: String,
default: ""
},
maskBottomStyle: {
type: String,
default: ""
}
});
var PickerView = defineComponent({
......@@ -2371,7 +2379,8 @@ var PickerViewColumn = defineComponent({
const getPickerViewColumn = inject("getPickerViewColumn");
const current = getPickerViewColumn(instance);
const indicatorStyle = computed(() => getStyle(pickerViewProps2.indicatorStyle));
const maskStyle = computed(() => getStyle(pickerViewProps2.maskStyle));
const maskTopStyle = computed(() => getStyle(pickerViewProps2.maskTopStyle));
const maskBottomStyle = computed(() => getStyle(pickerViewProps2.maskBottomStyle));
let indicatorHeight = ref(0);
indicatorHeight.value = getHeight(indicatorStyle.value);
let pickerViewHeight = ref(0);
......@@ -2445,18 +2454,17 @@ var PickerViewColumn = defineComponent({
paddingBottom: `${padding}px`
}
}, [createScrollViewChild(children)])]), createVNode("u-scalable", {
"class": "uni-picker-view-mask",
"style": maskStyle.value
"class": "uni-picker-view-mask"
}, [createVNode("u-scalable", {
"class": "uni-picker-view-mask uni-picker-view-mask-top",
"style": {
"style": extend({}, maskTopStyle.value, {
bottom: maskPosition
}
})
}, null), createVNode("u-scalable", {
"class": "uni-picker-view-mask uni-picker-view-mask-bottom",
"style": {
"style": extend({}, maskBottomStyle.value, {
top: maskPosition
}
})
}, null)]), createVNode("u-scalable", {
"ref": indicatorRef,
"class": "uni-picker-view-indicator",
......
......@@ -6344,7 +6344,8 @@ const useSwiperNavigation = (rootRef, props2, state, onSwiperDotClick, swiperCon
onMouseover: (event) => navigationHover(event, "over"),
onMouseout: (event) => navigationHover(event, "out")
};
function navigationClick(type) {
function navigationClick($event, type) {
$event.stopPropagation();
const swiperItemLength = swiperContext.value.length;
let _current = state.current;
switch (type) {
......@@ -6364,7 +6365,9 @@ const useSwiperNavigation = (rootRef, props2, state, onSwiperDotClick, swiperCon
onSwiperDotClick(_current);
}
const createNavigationSVG = () => createSvgIconVNode(ICON_PATH_BACK, props2.navigationColor, 26);
const _mouseMove = (e2) => {
let setHideNavigationTimer;
const _mousemove = (e2) => {
clearTimeout(setHideNavigationTimer);
const {
clientX,
clientY
......@@ -6377,22 +6380,29 @@ const useSwiperNavigation = (rootRef, props2, state, onSwiperDotClick, swiperCon
width,
height
} = rootRef.value.getBoundingClientRect();
let hide = false;
if (props2.vertical) {
hideNavigation.value = !(clientY - top < height / 3 || bottom - clientY < height / 3);
hide = !(clientY - top < height / 3 || bottom - clientY < height / 3);
} else {
hideNavigation.value = !(clientX - left < width / 3 || right - clientX < width / 3);
hide = !(clientX - left < width / 3 || right - clientX < width / 3);
}
if (hide) {
return setHideNavigationTimer = setTimeout(() => {
hideNavigation.value = hide;
}, 300);
}
hideNavigation.value = hide;
};
const _mouseOut = () => {
const _mouseleave = () => {
hideNavigation.value = true;
};
function swiperAddMouseEvent() {
if (rootRef.value) {
rootRef.value.removeEventListener("mousemove", _mouseMove);
rootRef.value.removeEventListener("mouseout", _mouseOut);
rootRef.value.removeEventListener("mousemove", _mousemove);
rootRef.value.removeEventListener("mouseleave", _mouseleave);
if (isNavigationAuto) {
rootRef.value.addEventListener("mousemove", _mouseMove);
rootRef.value.addEventListener("mouseout", _mouseOut);
rootRef.value.addEventListener("mousemove", _mousemove);
rootRef.value.addEventListener("mouseleave", _mouseleave);
}
}
}
......@@ -6406,12 +6416,12 @@ const useSwiperNavigation = (rootRef, props2, state, onSwiperDotClick, swiperCon
"class": ["uni-swiper-navigation uni-swiper-navigation-prev", shared.extend({
"uni-swiper-navigation-disabled": prevDisabled
}, navigationClass)],
"onClick": () => navigationClick("prev")
"onClick": (e2) => navigationClick(e2, "prev")
}, navigationAttr), [createNavigationSVG()], 16, ["onClick"]), vue.createVNode("div", vue.mergeProps({
"class": ["uni-swiper-navigation uni-swiper-navigation-next", shared.extend({
"uni-swiper-navigation-disabled": nextDisabled
}, navigationClass)],
"onClick": () => navigationClick("next")
"onClick": (e2) => navigationClick(e2, "next")
}, navigationAttr), [createNavigationSVG()], 16, ["onClick"])]);
}
return null;
......
......@@ -13339,7 +13339,8 @@ const useSwiperNavigation = (rootRef, props2, state2, onSwiperDotClick, swiperCo
onMouseover: (event) => navigationHover(event, "over"),
onMouseout: (event) => navigationHover(event, "out")
};
function navigationClick(type) {
function navigationClick($event, type) {
$event.stopPropagation();
const swiperItemLength = swiperContext.value.length;
let _current = state2.current;
switch (type) {
......@@ -13359,7 +13360,9 @@ const useSwiperNavigation = (rootRef, props2, state2, onSwiperDotClick, swiperCo
onSwiperDotClick(_current);
}
const createNavigationSVG = () => createSvgIconVNode(ICON_PATH_BACK, props2.navigationColor, 26);
const _mouseMove = (e2) => {
let setHideNavigationTimer;
const _mousemove = (e2) => {
clearTimeout(setHideNavigationTimer);
const {
clientX,
clientY
......@@ -13372,22 +13375,29 @@ const useSwiperNavigation = (rootRef, props2, state2, onSwiperDotClick, swiperCo
width,
height
} = rootRef.value.getBoundingClientRect();
let hide = false;
if (props2.vertical) {
hideNavigation.value = !(clientY - top < height / 3 || bottom - clientY < height / 3);
hide = !(clientY - top < height / 3 || bottom - clientY < height / 3);
} else {
hideNavigation.value = !(clientX - left < width / 3 || right - clientX < width / 3);
hide = !(clientX - left < width / 3 || right - clientX < width / 3);
}
if (hide) {
return setHideNavigationTimer = setTimeout(() => {
hideNavigation.value = hide;
}, 300);
}
hideNavigation.value = hide;
};
const _mouseOut = () => {
const _mouseleave = () => {
hideNavigation.value = true;
};
function swiperAddMouseEvent() {
if (rootRef.value) {
rootRef.value.removeEventListener("mousemove", _mouseMove);
rootRef.value.removeEventListener("mouseout", _mouseOut);
rootRef.value.removeEventListener("mousemove", _mousemove);
rootRef.value.removeEventListener("mouseleave", _mouseleave);
if (isNavigationAuto) {
rootRef.value.addEventListener("mousemove", _mouseMove);
rootRef.value.addEventListener("mouseout", _mouseOut);
rootRef.value.addEventListener("mousemove", _mousemove);
rootRef.value.addEventListener("mouseleave", _mouseleave);
}
}
}
......@@ -13402,12 +13412,12 @@ const useSwiperNavigation = (rootRef, props2, state2, onSwiperDotClick, swiperCo
"class": ["uni-swiper-navigation uni-swiper-navigation-prev", extend({
"uni-swiper-navigation-disabled": prevDisabled
}, navigationClass)],
"onClick": () => navigationClick("prev")
"onClick": (e2) => navigationClick(e2, "prev")
}, navigationAttr), [createNavigationSVG()], 16, ["onClick"]), createVNode("div", mergeProps({
"class": ["uni-swiper-navigation uni-swiper-navigation-next", extend({
"uni-swiper-navigation-disabled": nextDisabled
}, navigationClass)],
"onClick": () => navigationClick("next")
"onClick": (e2) => navigationClick(e2, "next")
}, navigationAttr), [createNavigationSVG()], 16, ["onClick"])]);
}
return null;
......@@ -17857,6 +17867,20 @@ var ImagePreview = /* @__PURE__ */ defineSystemComponent({
function onChange2(event) {
indexRef.value = event.detail.current;
}
const closeBtnStyle = {
position: "absolute",
"box-sizing": "border-box",
top: "0",
left: "0",
width: "60px",
height: "44px",
padding: "6px",
"line-height": "32px",
"font-size": "26px",
color: "white",
"text-align": "center",
cursor: "pointer"
};
return () => {
let _slot;
return createVNode("div", {
......@@ -17873,6 +17897,7 @@ var ImagePreview = /* @__PURE__ */ defineSystemComponent({
},
"onClick": onClick
}, [createVNode(Swiper, {
"navigation": "auto",
"current": indexRef.value,
"onChange": onChange2,
"indicator-dots": false,
......@@ -17891,7 +17916,9 @@ var ImagePreview = /* @__PURE__ */ defineSystemComponent({
}))) ? _slot : {
default: () => [_slot],
_: 1
}, 8, ["current", "onChange"])], 8, ["onClick"]);
}, 8, ["current", "onChange"]), createVNode("div", {
"style": closeBtnStyle
}, [createSvgIconVNode(ICON_PATH_CLOSE, "#ffffff", 26)], 4)], 8, ["onClick"]);
};
}
});
......
......@@ -15,6 +15,10 @@ import {
VariableDeclaration,
} from '../../types/types'
import { getCompiler } from '../utils/compiler'
import {
createResolveTypeReferenceName,
resolvePackage,
} from '../utils/compiler/utils'
export function uniUtsV1Plugin(): Plugin {
let isFirst = true
......@@ -28,6 +32,7 @@ export function uniUtsV1Plugin(): Plugin {
}
// 目前仅支持 app-android|app-ios
if (
process.env.UNI_UTS_PLATFORM !== 'app' &&
process.env.UNI_UTS_PLATFORM !== 'app-android' &&
process.env.UNI_UTS_PLATFORM !== 'app-ios'
) {
......@@ -37,12 +42,11 @@ export function uniUtsV1Plugin(): Plugin {
if (path.extname(filename) !== '.uts') {
return
}
const { compile, parsePackage, createResolveTypeReferenceName } =
getCompiler(
process.env.UNI_UTS_PLATFORM === 'app-ios' ? 'swift' : 'kotlin'
)
const pkg = parsePackage(filename)
if (!pkg.class) {
const { compile } = getCompiler(
process.env.UNI_UTS_PLATFORM === 'app-ios' ? 'swift' : 'kotlin'
)
const pkg = resolvePackage(filename)
if (!pkg) {
return
}
// 懒加载 uts 编译器
......@@ -50,11 +54,23 @@ export function uniUtsV1Plugin(): Plugin {
const { parse } = require('@dcloudio/uts')
const ast = await parse(preJs(code), { noColor: isInHBuilderX() })
code = `
import { initUtsProxyClass, initUtsProxyFunction } from '@dcloudio/uni-app'
const pkg = '${pkg.package}'
const cls = '${pkg.class}'
import { initUtsProxyClass, initUtsProxyFunction, initUtsPackageName, initUtsClassName } from '@dcloudio/uni-app'
const name = '${pkg.name}'
const is_uni_modules = ${pkg.is_uni_modules}
const pkg = initUtsPackageName(name, is_uni_modules)
const cls = initUtsClassName(name, is_uni_modules)
${genProxyCode(ast, createResolveTypeReferenceName(pkg.namespace, ast))}
`
// 平台不匹配,不走平台代码编译,仅生成js代码
if (
process.env.UNI_UTS_PLATFORM === 'app' ||
(process.env.UNI_UTS_PLATFORM === 'app-android' &&
id.includes('app-ios')) ||
(process.env.UNI_UTS_PLATFORM === 'app-ios' &&
id.includes('app-android'))
) {
return code
}
const res = await compile(id)
if (process.env.UNI_UTS_PLATFORM === 'app-android') {
if (!isFirst && res) {
......
import {
compileKotlin,
parseKotlinPackage,
createKotlinResolveTypeReferenceName,
} from './kotlin'
import {
compileSwift,
parseSwiftPackage,
createSwiftResolveTypeReferenceName,
} from './swift'
import { compileKotlin } from './kotlin'
import { compileSwift } from './swift'
export function getCompiler(type: 'kotlin' | 'swift') {
if (type === 'swift') {
return {
compile: compileSwift,
parsePackage: parseSwiftPackage,
createResolveTypeReferenceName: createSwiftResolveTypeReferenceName,
}
}
return {
compile: compileKotlin,
parsePackage: parseKotlinPackage,
createResolveTypeReferenceName: createKotlinResolveTypeReferenceName,
}
}
......@@ -27,15 +27,13 @@ export function createKotlinResolveTypeReferenceName(
return (name: string) => name
}
export function parseKotlinPackage(filename: string) {
function parseKotlinPackage(filename: string) {
const res = resolvePackage(filename)
if (!res) {
return { package: '', namespace: '', class: '' }
return { package: '' }
}
return {
package: 'uts.sdk.' + (res.is_uni_modules ? 'modules.' : '') + res.name,
namespace: '',
class: 'IndexKt',
}
}
......
import { isInHBuilderX, resolveSourceMapPath } from '@dcloudio/uni-cli-shared'
import { capitalize } from '@vue/shared'
import { Module, ModuleItem } from '../../../types/types'
import { genUTSPlatformResource, getUtsCompiler, resolvePackage } from './utils'
function resolveTypeAliasDeclNames(items: ModuleItem[]) {
const names: string[] = []
items.forEach((item) => {
if (item.type === 'TsTypeAliasDeclaration') {
names.push(item.id.value)
}
})
return names
}
export function createSwiftResolveTypeReferenceName(
namespace: string,
ast: Module
) {
const names = resolveTypeAliasDeclNames(ast.body)
return (name: string) => {
if (names.includes(name)) {
return namespace + capitalize(name)
}
return name
}
}
export function parseSwiftPackage(filename: string) {
function parseSwiftPackage(filename: string) {
const res = resolvePackage(filename)
if (!res) {
return {
package: '',
namespace: '',
class: '',
}
}
const namespace =
'UTSSDK' + (res.is_uni_modules ? 'Modules' : '') + capitalize(res.name)
return {
package: '',
namespace,
class: namespace + 'IndexSwift',
}
}
......
......@@ -2,7 +2,8 @@ import path from 'path'
import fs from 'fs-extra'
import type { parse, bundle, UtsTarget } from '@dcloudio/uts'
import { normalizePath } from '@dcloudio/uni-cli-shared'
import { camelize } from '@vue/shared'
import { camelize, capitalize } from '@vue/shared'
import { Module, ModuleItem } from '../../../types/types'
export function getUtsCompiler(): {
parse: typeof parse
......@@ -21,9 +22,11 @@ export function resolvePackage(filename: string) {
? parts.findIndex((part) => part === 'uni_modules')
: parts.findIndex((part) => part === 'utssdk')
if (index > -1) {
const name = camelize(parts[index + 1])
return {
is_uni_modules: isUniModules,
name: camelize(parts[index + 1]),
name,
namespace: 'UTSSDK' + (isUniModules ? 'Modules' : '') + capitalize(name),
}
}
}
......@@ -110,3 +113,23 @@ export function resolveUTSPlatformFile(
}
return platformFile
}
function resolveTypeAliasDeclNames(items: ModuleItem[]) {
const names: string[] = []
items.forEach((item) => {
if (item.type === 'TsTypeAliasDeclaration') {
names.push(item.id.value)
}
})
return names
}
export function createResolveTypeReferenceName(namespace: string, ast: Module) {
const names = resolveTypeAliasDeclNames(ast.body)
return (name: string) => {
if (names.includes(name)) {
return namespace + capitalize(name)
}
return name
}
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册