1
0
Fork 0
management/front/dkha-web-sz-main/node_modules/@vue/component-compiler-utils/dist/templateCompilerModules/assetUrl.js

47 lines
1.6 KiB
JavaScript
Raw Permalink Normal View History

2023-12-18 13:12:25 +08:00
"use strict";
// vue compiler module for transforming `<tag>:<attribute>` to `require`
Object.defineProperty(exports, "__esModule", { value: true });
const utils_1 = require("./utils");
const defaultOptions = {
2024-01-16 21:26:16 +08:00
audio: 'src',
2023-12-18 13:12:25 +08:00
video: ['src', 'poster'],
source: 'src',
img: 'src',
image: ['xlink:href', 'href'],
use: ['xlink:href', 'href']
};
2024-01-16 21:26:16 +08:00
exports.default = (userOptions, transformAssetUrlsOption) => {
2023-12-18 13:12:25 +08:00
const options = userOptions
? Object.assign({}, defaultOptions, userOptions)
: defaultOptions;
return {
postTransformNode: (node) => {
2024-01-16 21:26:16 +08:00
transform(node, options, transformAssetUrlsOption);
2023-12-18 13:12:25 +08:00
}
};
};
2024-01-16 21:26:16 +08:00
function transform(node, options, transformAssetUrlsOption) {
2023-12-18 13:12:25 +08:00
for (const tag in options) {
if ((tag === '*' || node.tag === tag) && node.attrs) {
const attributes = options[tag];
if (typeof attributes === 'string') {
2024-01-16 21:26:16 +08:00
node.attrs.some(attr => rewrite(attr, attributes, transformAssetUrlsOption));
2023-12-18 13:12:25 +08:00
}
else if (Array.isArray(attributes)) {
2024-01-16 21:26:16 +08:00
attributes.forEach(item => node.attrs.some(attr => rewrite(attr, item, transformAssetUrlsOption)));
2023-12-18 13:12:25 +08:00
}
}
}
}
2024-01-16 21:26:16 +08:00
function rewrite(attr, name, transformAssetUrlsOption) {
2023-12-18 13:12:25 +08:00
if (attr.name === name) {
const value = attr.value;
// only transform static URLs
if (value.charAt(0) === '"' && value.charAt(value.length - 1) === '"') {
2024-01-16 21:26:16 +08:00
attr.value = utils_1.urlToRequire(value.slice(1, -1), transformAssetUrlsOption);
2023-12-18 13:12:25 +08:00
return true;
}
}
return false;
}