2025/2/8第一次更新

This commit is contained in:
爱吃咸鱼小猫咪
2025-02-08 18:50:38 +08:00
commit d7af560866
26519 changed files with 5046029 additions and 0 deletions
@@ -0,0 +1,6 @@
import { type RootNode, type TemplateChildNode, type TransformContext } from '@vue/compiler-core';
/**
* 将direction属性转化为scroll-x和scroll-y
* 注意transformMPBuiltInTag内会讲list-view转化为scroll-view,所以此transform应该在transformMPBuiltInTag之后执行
*/
export declare const transformDirection: (node: RootNode | TemplateChildNode, context: TransformContext) => void;
@@ -0,0 +1,52 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.transformDirection = void 0;
const vite_1 = require("../../../vite");
const utils_1 = require("../../utils");
const compiler_core_1 = require("@vue/compiler-core");
/**
* 将direction属性转化为scroll-x和scroll-y
* 注意transformMPBuiltInTag内会讲list-view转化为scroll-view,所以此transform应该在transformMPBuiltInTag之后执行
*/
const transformDirection = function (node, context) {
if (!(0, vite_1.isElementNode)(node)) {
return;
}
if (node.tag !== 'scroll-view') {
return;
}
const directionPropIndex = node.props.findIndex((prop) => (0, utils_1.isPropNameEquals)(prop, 'direction'));
const scrollXPropIndex = node.props.findIndex((prop) => (0, utils_1.isPropNameEquals)(prop, 'scrollX'));
const scrollYPropIndex = node.props.findIndex((prop) => (0, utils_1.isPropNameEquals)(prop, 'scrollY'));
if (directionPropIndex === -1 ||
(scrollXPropIndex !== -1 && scrollYPropIndex !== -1)) {
node.props.push((0, utils_1.createAttributeNode)('scroll-y', 'true'));
return;
}
const directionProp = node.props[directionPropIndex];
if (directionProp.type === compiler_core_1.NodeTypes.ATTRIBUTE) {
const directionValue = directionProp.value?.content;
const scrollX = directionValue === 'horizontal' || directionValue === 'all';
const scrollY = !directionValue ||
directionValue === 'vertical' ||
directionValue === 'all';
node.props.splice(directionPropIndex, 1);
scrollX && node.props.push((0, utils_1.createAttributeNode)('scroll-x', '' + scrollX));
scrollY && node.props.push((0, utils_1.createAttributeNode)('scroll-y', '' + scrollY));
}
else if (directionProp.type === compiler_core_1.NodeTypes.DIRECTIVE) {
if (!directionProp.arg ||
!(0, compiler_core_1.isStaticExp)(directionProp.arg) ||
!directionProp.exp ||
!(0, compiler_core_1.isStaticExp)(directionProp.exp)) {
return;
}
const exp = directionProp.exp.content;
const scrollX = `(${exp}) === 'horizontal' || (${exp}) === 'all'`;
const scrollY = `!(${exp}) || (${exp}) === 'vertical' || (${exp}) === 'all'`;
node.props.splice(directionPropIndex, 1);
scrollX && node.props.push((0, utils_1.createBindDirectiveNode)('scroll-x', scrollX));
scrollY && node.props.push((0, utils_1.createBindDirectiveNode)('scroll-y', scrollY));
}
};
exports.transformDirection = transformDirection;
@@ -0,0 +1,12 @@
import { type RootNode, type TemplateChildNode, type TransformContext } from '@vue/compiler-core';
export interface TransformMPBuiltInTagOptions {
propRename?: Record<string, Record<string, string>>;
propAdd?: Record<string, {
name: string;
value: string;
}[]>;
tagRename?: Record<string, string>;
}
export declare const defaultTransformMPBuiltInTagOptions: TransformMPBuiltInTagOptions;
export declare function createMPBuiltInTagTransform(options: TransformMPBuiltInTagOptions): (node: RootNode | TemplateChildNode, context: TransformContext) => void;
export declare const transformMPBuiltInTag: (node: RootNode | TemplateChildNode, context: TransformContext) => void;
@@ -0,0 +1,94 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.transformMPBuiltInTag = exports.createMPBuiltInTagTransform = exports.defaultTransformMPBuiltInTagOptions = void 0;
const shared_1 = require("@vue/shared");
const vite_1 = require("../../../vite");
const utils_1 = require("../../utils");
const compiler_core_1 = require("@vue/compiler-core");
exports.defaultTransformMPBuiltInTagOptions = {
propRename: {
checkbox: {
// "backgroundColor": "",
// "borderColor": "",
// "activeBackgroundColor": "",
// "activeBorderColor": "",
foreColor: 'color',
},
radio: {
// "backgroundColor": "",
// "borderColor": "",
activeBackgroundColor: 'color',
// "activeBorderColor": "",
// "foreColor": ""
},
slider: {
backgroundColor: 'backgroundColor',
activeBackgroundColor: 'activeColor',
foreColor: 'block-color',
},
switch: {
// "backgroundColor": "",
activeBackgroundColor: 'color',
// "foreColor": "",
// "activeForeColor": ""
},
},
propAdd: {
canvas: [
{
name: 'type',
value: '2d',
},
],
'scroll-view': [
{
name: 'enable-flex',
value: 'true',
},
],
},
tagRename: {
'list-view': 'scroll-view',
},
};
function createMPBuiltInTagTransform(options) {
return function (node, context) {
if (!(0, vite_1.isElementNode)(node)) {
return;
}
if (options.tagRename && node.tag in options.tagRename) {
node.tag = options.tagRename[node.tag];
}
if (options.propRename && node.tag in options.propRename) {
const propMap = options.propRename[node.tag];
node.props.forEach((prop) => {
if (prop.type === compiler_core_1.NodeTypes.ATTRIBUTE) {
const propName = (0, shared_1.camelize)(prop.name);
if (propName in propMap && propMap[propName]) {
(0, utils_1.renameProp)(propMap[propName], prop);
}
}
else if (prop.type === compiler_core_1.NodeTypes.DIRECTIVE) {
if (!prop.rawName || !prop.arg || !(0, compiler_core_1.isStaticExp)(prop.arg)) {
return;
}
const propName = (0, shared_1.camelize)(prop.rawName.slice(1));
if (propName in propMap && propMap[propName]) {
(0, utils_1.renameProp)(propMap[propName], prop);
}
}
});
}
if (options.propAdd && node.tag in options.propAdd) {
const add = options.propAdd[node.tag];
add.forEach(({ name, value }) => {
if (node.props.some((item) => (0, utils_1.isPropNameEquals)(item, name))) {
return;
}
node.props.push((0, utils_1.createAttributeNode)(name, value));
});
}
};
}
exports.createMPBuiltInTagTransform = createMPBuiltInTagTransform;
exports.transformMPBuiltInTag = createMPBuiltInTagTransform(exports.defaultTransformMPBuiltInTagOptions);