@dcloudio/uni-cli-shared 3.0.0-alpha-3021320211122001 → 3.0.0-alpha-3021320211123001
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/utils.d.ts +0 -2
- package/dist/utils.js +1 -22
- package/dist/vue/index.d.ts +1 -0
- package/dist/vue/index.js +3 -0
- package/dist/vue/transforms/index.d.ts +2 -0
- package/dist/vue/transforms/index.js +5 -1
- package/dist/vue/transforms/templateTransformAssetUrl.d.ts +33 -0
- package/dist/vue/transforms/templateTransformAssetUrl.js +150 -0
- package/dist/vue/transforms/templateTransformSrcset.d.ts +4 -0
- package/dist/vue/transforms/templateTransformSrcset.js +122 -0
- package/dist/vue/transforms/templateUtils.d.ts +9 -0
- package/dist/vue/transforms/templateUtils.js +41 -0
- package/dist/vue/utils.d.ts +18 -0
- package/dist/vue/utils.js +33 -1
- package/package.json +4 -4
package/dist/utils.d.ts
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
export { default as hash } from 'hash-sum';
|
|
2
|
-
import type { SFCTemplateCompileOptions } from '@vue/compiler-sfc';
|
|
3
2
|
import { ElementNode, RootNode, TemplateChildNode } from '@vue/compiler-core';
|
|
4
3
|
export declare let isRunningWithYarnPnp: boolean;
|
|
5
4
|
export declare const isWindows: boolean;
|
|
@@ -10,4 +9,3 @@ export declare function normalizePagePath(pagePath: string, platform: UniApp.PLA
|
|
|
10
9
|
export declare function removeExt(str: string): string;
|
|
11
10
|
export declare function normalizeNodeModules(str: string): string;
|
|
12
11
|
export declare function normalizeMiniProgramFilename(filename: string, inputDir?: string): string;
|
|
13
|
-
export declare function createUniVueTransformAssetUrls(base: string): SFCTemplateCompileOptions['transformAssetUrls'];
|
package/dist/utils.js
CHANGED
|
@@ -3,7 +3,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
3
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.
|
|
6
|
+
exports.normalizeMiniProgramFilename = exports.normalizeNodeModules = exports.removeExt = exports.normalizePagePath = exports.normalizeIdentifier = exports.checkElementNodeTag = exports.normalizePath = exports.isWindows = exports.isRunningWithYarnPnp = exports.hash = void 0;
|
|
7
7
|
const fs_1 = __importDefault(require("fs"));
|
|
8
8
|
const os_1 = __importDefault(require("os"));
|
|
9
9
|
const path_1 = __importDefault(require("path"));
|
|
@@ -65,24 +65,3 @@ function normalizeMiniProgramFilename(filename, inputDir) {
|
|
|
65
65
|
return normalizeNodeModules(path_1.default.relative(inputDir, filename));
|
|
66
66
|
}
|
|
67
67
|
exports.normalizeMiniProgramFilename = normalizeMiniProgramFilename;
|
|
68
|
-
function createUniVueTransformAssetUrls(base) {
|
|
69
|
-
return {
|
|
70
|
-
base,
|
|
71
|
-
tags: {
|
|
72
|
-
audio: ['src'],
|
|
73
|
-
video: ['src', 'poster'],
|
|
74
|
-
img: ['src'],
|
|
75
|
-
image: ['src'],
|
|
76
|
-
'cover-image': ['src'],
|
|
77
|
-
// h5
|
|
78
|
-
'v-uni-audio': ['src'],
|
|
79
|
-
'v-uni-video': ['src', 'poster'],
|
|
80
|
-
'v-uni-image': ['src'],
|
|
81
|
-
'v-uni-cover-image': ['src'],
|
|
82
|
-
// nvue
|
|
83
|
-
'u-image': ['src'],
|
|
84
|
-
'u-video': ['src', 'poster'],
|
|
85
|
-
},
|
|
86
|
-
};
|
|
87
|
-
}
|
|
88
|
-
exports.createUniVueTransformAssetUrls = createUniVueTransformAssetUrls;
|
package/dist/vue/index.d.ts
CHANGED
package/dist/vue/index.js
CHANGED
|
@@ -10,5 +10,8 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
10
10
|
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
11
11
|
};
|
|
12
12
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
13
|
+
exports.isExternalUrl = void 0;
|
|
13
14
|
__exportStar(require("./transforms"), exports);
|
|
14
15
|
__exportStar(require("./utils"), exports);
|
|
16
|
+
var templateUtils_1 = require("./transforms/templateUtils");
|
|
17
|
+
Object.defineProperty(exports, "isExternalUrl", { enumerable: true, get: function () { return templateUtils_1.isExternalUrl; } });
|
|
@@ -3,6 +3,8 @@ export * from './transformPageHead';
|
|
|
3
3
|
export * from './transformComponent';
|
|
4
4
|
export * from './transformEvent';
|
|
5
5
|
export * from './transformTag';
|
|
6
|
+
export { createAssetUrlTransformWithOptions } from './templateTransformAssetUrl';
|
|
7
|
+
export { createSrcsetTransformWithOptions } from './templateTransformSrcset';
|
|
6
8
|
export { ATTR_DATASET_EVENT_OPTS, createTransformOn, defaultMatch as matchTransformOn, } from './vOn';
|
|
7
9
|
export { createTransformModel, defaultMatch as matchTransformModel, } from './vModel';
|
|
8
10
|
export declare const transformMatchMedia: import("@vue/compiler-core").NodeTransform;
|
|
@@ -10,7 +10,7 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
10
10
|
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
11
11
|
};
|
|
12
12
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
13
|
-
exports.transformComponentLink = exports.transformTapToClick = exports.transformMatchMedia = exports.matchTransformModel = exports.createTransformModel = exports.matchTransformOn = exports.createTransformOn = exports.ATTR_DATASET_EVENT_OPTS = void 0;
|
|
13
|
+
exports.transformComponentLink = exports.transformTapToClick = exports.transformMatchMedia = exports.matchTransformModel = exports.createTransformModel = exports.matchTransformOn = exports.createTransformOn = exports.ATTR_DATASET_EVENT_OPTS = exports.createSrcsetTransformWithOptions = exports.createAssetUrlTransformWithOptions = void 0;
|
|
14
14
|
const transformTag_1 = require("./transformTag");
|
|
15
15
|
const transformEvent_1 = require("./transformEvent");
|
|
16
16
|
const transformComponent_1 = require("./transformComponent");
|
|
@@ -20,6 +20,10 @@ __exportStar(require("./transformPageHead"), exports);
|
|
|
20
20
|
__exportStar(require("./transformComponent"), exports);
|
|
21
21
|
__exportStar(require("./transformEvent"), exports);
|
|
22
22
|
__exportStar(require("./transformTag"), exports);
|
|
23
|
+
var templateTransformAssetUrl_1 = require("./templateTransformAssetUrl");
|
|
24
|
+
Object.defineProperty(exports, "createAssetUrlTransformWithOptions", { enumerable: true, get: function () { return templateTransformAssetUrl_1.createAssetUrlTransformWithOptions; } });
|
|
25
|
+
var templateTransformSrcset_1 = require("./templateTransformSrcset");
|
|
26
|
+
Object.defineProperty(exports, "createSrcsetTransformWithOptions", { enumerable: true, get: function () { return templateTransformSrcset_1.createSrcsetTransformWithOptions; } });
|
|
23
27
|
var vOn_1 = require("./vOn");
|
|
24
28
|
Object.defineProperty(exports, "ATTR_DATASET_EVENT_OPTS", { enumerable: true, get: function () { return vOn_1.ATTR_DATASET_EVENT_OPTS; } });
|
|
25
29
|
Object.defineProperty(exports, "createTransformOn", { enumerable: true, get: function () { return vOn_1.createTransformOn; } });
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { NodeTransform } from '@vue/compiler-core';
|
|
2
|
+
export interface AssetURLTagConfig {
|
|
3
|
+
[name: string]: string[];
|
|
4
|
+
}
|
|
5
|
+
export interface AssetURLOptions {
|
|
6
|
+
/**
|
|
7
|
+
* If base is provided, instead of transforming relative asset urls into
|
|
8
|
+
* imports, they will be directly rewritten to absolute urls.
|
|
9
|
+
*/
|
|
10
|
+
base?: string | null;
|
|
11
|
+
/**
|
|
12
|
+
* If true, also processes absolute urls.
|
|
13
|
+
*/
|
|
14
|
+
includeAbsolute?: boolean;
|
|
15
|
+
tags?: AssetURLTagConfig;
|
|
16
|
+
}
|
|
17
|
+
export declare const defaultAssetUrlOptions: Required<AssetURLOptions>;
|
|
18
|
+
export declare const normalizeOptions: (options: AssetURLOptions | AssetURLTagConfig) => Required<AssetURLOptions>;
|
|
19
|
+
export declare const createAssetUrlTransformWithOptions: (options: Required<AssetURLOptions>) => NodeTransform;
|
|
20
|
+
/**
|
|
21
|
+
* A `@vue/compiler-core` plugin that transforms relative asset urls into
|
|
22
|
+
* either imports or absolute urls.
|
|
23
|
+
*
|
|
24
|
+
* ``` js
|
|
25
|
+
* // Before
|
|
26
|
+
* createVNode('img', { src: './logo.png' })
|
|
27
|
+
*
|
|
28
|
+
* // After
|
|
29
|
+
* import _imports_0 from './logo.png'
|
|
30
|
+
* createVNode('img', { src: _imports_0 })
|
|
31
|
+
* ```
|
|
32
|
+
*/
|
|
33
|
+
export declare const transformAssetUrl: NodeTransform;
|
|
@@ -0,0 +1,150 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.transformAssetUrl = exports.createAssetUrlTransformWithOptions = exports.normalizeOptions = exports.defaultAssetUrlOptions = void 0;
|
|
7
|
+
const path_1 = __importDefault(require("path"));
|
|
8
|
+
const compiler_core_1 = require("@vue/compiler-core");
|
|
9
|
+
const templateUtils_1 = require("./templateUtils");
|
|
10
|
+
const shared_1 = require("@vue/shared");
|
|
11
|
+
exports.defaultAssetUrlOptions = {
|
|
12
|
+
base: null,
|
|
13
|
+
includeAbsolute: false,
|
|
14
|
+
tags: {
|
|
15
|
+
video: ['src', 'poster'],
|
|
16
|
+
source: ['src'],
|
|
17
|
+
img: ['src'],
|
|
18
|
+
image: ['xlink:href', 'href'],
|
|
19
|
+
use: ['xlink:href', 'href'],
|
|
20
|
+
},
|
|
21
|
+
};
|
|
22
|
+
const normalizeOptions = (options) => {
|
|
23
|
+
if (Object.keys(options).some((key) => (0, shared_1.isArray)(options[key]))) {
|
|
24
|
+
// legacy option format which directly passes in tags config
|
|
25
|
+
return {
|
|
26
|
+
...exports.defaultAssetUrlOptions,
|
|
27
|
+
tags: options,
|
|
28
|
+
};
|
|
29
|
+
}
|
|
30
|
+
return {
|
|
31
|
+
...exports.defaultAssetUrlOptions,
|
|
32
|
+
...options,
|
|
33
|
+
};
|
|
34
|
+
};
|
|
35
|
+
exports.normalizeOptions = normalizeOptions;
|
|
36
|
+
const createAssetUrlTransformWithOptions = (options) => {
|
|
37
|
+
return (node, context) => exports.transformAssetUrl(node, context, options);
|
|
38
|
+
};
|
|
39
|
+
exports.createAssetUrlTransformWithOptions = createAssetUrlTransformWithOptions;
|
|
40
|
+
/**
|
|
41
|
+
* A `@vue/compiler-core` plugin that transforms relative asset urls into
|
|
42
|
+
* either imports or absolute urls.
|
|
43
|
+
*
|
|
44
|
+
* ``` js
|
|
45
|
+
* // Before
|
|
46
|
+
* createVNode('img', { src: './logo.png' })
|
|
47
|
+
*
|
|
48
|
+
* // After
|
|
49
|
+
* import _imports_0 from './logo.png'
|
|
50
|
+
* createVNode('img', { src: _imports_0 })
|
|
51
|
+
* ```
|
|
52
|
+
*/
|
|
53
|
+
const transformAssetUrl = (node, context, options = exports.defaultAssetUrlOptions) => {
|
|
54
|
+
if (node.type === 1 /* ELEMENT */) {
|
|
55
|
+
if (!node.props.length) {
|
|
56
|
+
return;
|
|
57
|
+
}
|
|
58
|
+
const tags = options.tags || exports.defaultAssetUrlOptions.tags;
|
|
59
|
+
const attrs = tags[node.tag];
|
|
60
|
+
const wildCardAttrs = tags['*'];
|
|
61
|
+
if (!attrs && !wildCardAttrs) {
|
|
62
|
+
return;
|
|
63
|
+
}
|
|
64
|
+
// 策略:
|
|
65
|
+
// h5 平台保留原始策略
|
|
66
|
+
// 非 h5 平台
|
|
67
|
+
// - 绝对路径 static 资源不做转换
|
|
68
|
+
// - 相对路径 static 资源转换为绝对路径
|
|
69
|
+
// - 非 static 资源转换为 import
|
|
70
|
+
const assetAttrs = (attrs || []).concat(wildCardAttrs || []);
|
|
71
|
+
node.props.forEach((attr, index) => {
|
|
72
|
+
if (attr.type !== 6 /* ATTRIBUTE */ ||
|
|
73
|
+
!assetAttrs.includes(attr.name) ||
|
|
74
|
+
!attr.value ||
|
|
75
|
+
(0, templateUtils_1.isExternalUrl)(attr.value.content) ||
|
|
76
|
+
(0, templateUtils_1.isDataUrl)(attr.value.content) ||
|
|
77
|
+
attr.value.content[0] === '#') {
|
|
78
|
+
return;
|
|
79
|
+
}
|
|
80
|
+
// fixed by xxxxxx 区分 static 资源
|
|
81
|
+
const isStaticAsset = attr.value.content.indexOf('/static/') > -1;
|
|
82
|
+
// 绝对路径的静态资源不作处理
|
|
83
|
+
if (isStaticAsset && !(0, templateUtils_1.isRelativeUrl)(attr.value.content)) {
|
|
84
|
+
return;
|
|
85
|
+
}
|
|
86
|
+
const url = (0, templateUtils_1.parseUrl)(attr.value.content);
|
|
87
|
+
if (options.base && attr.value.content[0] === '.' && isStaticAsset) {
|
|
88
|
+
// explicit base - directly rewrite relative urls into absolute url
|
|
89
|
+
// to avoid generating extra imports
|
|
90
|
+
// Allow for full hostnames provided in options.base
|
|
91
|
+
const base = (0, templateUtils_1.parseUrl)(options.base);
|
|
92
|
+
const protocol = base.protocol || '';
|
|
93
|
+
const host = base.host ? protocol + '//' + base.host : '';
|
|
94
|
+
const basePath = base.path || '/';
|
|
95
|
+
// when packaged in the browser, path will be using the posix-
|
|
96
|
+
// only version provided by rollup-plugin-node-builtins.
|
|
97
|
+
attr.value.content =
|
|
98
|
+
host +
|
|
99
|
+
(path_1.default.posix || path_1.default).join(basePath, url.path + (url.hash || ''));
|
|
100
|
+
return;
|
|
101
|
+
}
|
|
102
|
+
// otherwise, transform the url into an import.
|
|
103
|
+
// this assumes a bundler will resolve the import into the correct
|
|
104
|
+
// absolute url (e.g. webpack file-loader)
|
|
105
|
+
const exp = getImportsExpressionExp(url.path, url.hash, attr.loc, context);
|
|
106
|
+
node.props[index] = {
|
|
107
|
+
type: 7 /* DIRECTIVE */,
|
|
108
|
+
name: 'bind',
|
|
109
|
+
arg: (0, compiler_core_1.createSimpleExpression)(attr.name, true, attr.loc),
|
|
110
|
+
exp,
|
|
111
|
+
modifiers: [],
|
|
112
|
+
loc: attr.loc,
|
|
113
|
+
};
|
|
114
|
+
});
|
|
115
|
+
}
|
|
116
|
+
};
|
|
117
|
+
exports.transformAssetUrl = transformAssetUrl;
|
|
118
|
+
function getImportsExpressionExp(path, hash, loc, context) {
|
|
119
|
+
if (path) {
|
|
120
|
+
let name;
|
|
121
|
+
let exp;
|
|
122
|
+
const existingIndex = context.imports.findIndex((i) => i.path === path);
|
|
123
|
+
if (existingIndex > -1) {
|
|
124
|
+
name = `_imports_${existingIndex}`;
|
|
125
|
+
exp = context.imports[existingIndex].exp;
|
|
126
|
+
}
|
|
127
|
+
else {
|
|
128
|
+
name = `_imports_${context.imports.length}`;
|
|
129
|
+
exp = (0, compiler_core_1.createSimpleExpression)(name, false, loc, 2 /* CAN_HOIST */);
|
|
130
|
+
context.imports.push({ exp, path });
|
|
131
|
+
}
|
|
132
|
+
if (!hash) {
|
|
133
|
+
return exp;
|
|
134
|
+
}
|
|
135
|
+
const hashExp = `${name} + '${hash}'`;
|
|
136
|
+
const existingHoistIndex = context.hoists.findIndex((h) => {
|
|
137
|
+
return (h &&
|
|
138
|
+
h.type === 4 /* SIMPLE_EXPRESSION */ &&
|
|
139
|
+
!h.isStatic &&
|
|
140
|
+
h.content === hashExp);
|
|
141
|
+
});
|
|
142
|
+
if (existingHoistIndex > -1) {
|
|
143
|
+
return (0, compiler_core_1.createSimpleExpression)(`_hoisted_${existingHoistIndex + 1}`, false, loc, 2 /* CAN_HOIST */);
|
|
144
|
+
}
|
|
145
|
+
return context.hoist((0, compiler_core_1.createSimpleExpression)(hashExp, false, loc, 2 /* CAN_HOIST */));
|
|
146
|
+
}
|
|
147
|
+
else {
|
|
148
|
+
return (0, compiler_core_1.createSimpleExpression)(`''`, false, loc, 2 /* CAN_HOIST */);
|
|
149
|
+
}
|
|
150
|
+
}
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import { NodeTransform } from '@vue/compiler-core';
|
|
2
|
+
import { AssetURLOptions } from './templateTransformAssetUrl';
|
|
3
|
+
export declare const createSrcsetTransformWithOptions: (options: Required<AssetURLOptions>) => NodeTransform;
|
|
4
|
+
export declare const transformSrcset: NodeTransform;
|
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.transformSrcset = exports.createSrcsetTransformWithOptions = void 0;
|
|
7
|
+
const path_1 = __importDefault(require("path"));
|
|
8
|
+
const compiler_core_1 = require("@vue/compiler-core");
|
|
9
|
+
const templateUtils_1 = require("./templateUtils");
|
|
10
|
+
const templateTransformAssetUrl_1 = require("./templateTransformAssetUrl");
|
|
11
|
+
const srcsetTags = ['img', 'source'];
|
|
12
|
+
// http://w3c.github.io/html/semantics-embedded-content.html#ref-for-image-candidate-string-5
|
|
13
|
+
const escapedSpaceCharacters = /( |\\t|\\n|\\f|\\r)+/g;
|
|
14
|
+
const createSrcsetTransformWithOptions = (options) => {
|
|
15
|
+
return (node, context) => exports.transformSrcset(node, context, options);
|
|
16
|
+
};
|
|
17
|
+
exports.createSrcsetTransformWithOptions = createSrcsetTransformWithOptions;
|
|
18
|
+
const transformSrcset = (node, context, options = templateTransformAssetUrl_1.defaultAssetUrlOptions) => {
|
|
19
|
+
if (node.type === 1 /* ELEMENT */) {
|
|
20
|
+
if (srcsetTags.includes(node.tag) && node.props.length) {
|
|
21
|
+
node.props.forEach((attr, index) => {
|
|
22
|
+
if (attr.name === 'srcset' && attr.type === 6 /* ATTRIBUTE */) {
|
|
23
|
+
if (!attr.value)
|
|
24
|
+
return;
|
|
25
|
+
const value = attr.value.content;
|
|
26
|
+
if (!value)
|
|
27
|
+
return;
|
|
28
|
+
const imageCandidates = value
|
|
29
|
+
.split(',')
|
|
30
|
+
.map((s) => {
|
|
31
|
+
// The attribute value arrives here with all whitespace, except
|
|
32
|
+
// normal spaces, represented by escape sequences
|
|
33
|
+
const [url, descriptor] = s
|
|
34
|
+
.replace(escapedSpaceCharacters, ' ')
|
|
35
|
+
.trim()
|
|
36
|
+
.split(' ', 2);
|
|
37
|
+
return { url, descriptor };
|
|
38
|
+
});
|
|
39
|
+
// data urls contains comma after the ecoding so we need to re-merge
|
|
40
|
+
// them
|
|
41
|
+
for (let i = 0; i < imageCandidates.length; i++) {
|
|
42
|
+
const { url } = imageCandidates[i];
|
|
43
|
+
if ((0, templateUtils_1.isDataUrl)(url)) {
|
|
44
|
+
imageCandidates[i + 1].url =
|
|
45
|
+
url + ',' + imageCandidates[i + 1].url;
|
|
46
|
+
imageCandidates.splice(i, 1);
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
const hasQualifiedUrl = imageCandidates.some(({ url }) => {
|
|
50
|
+
return (!(0, templateUtils_1.isExternalUrl)(url) &&
|
|
51
|
+
!(0, templateUtils_1.isDataUrl)(url) &&
|
|
52
|
+
(options.includeAbsolute || (0, templateUtils_1.isRelativeUrl)(url)));
|
|
53
|
+
});
|
|
54
|
+
// When srcset does not contain any qualified URLs, skip transforming
|
|
55
|
+
if (!hasQualifiedUrl) {
|
|
56
|
+
return;
|
|
57
|
+
}
|
|
58
|
+
if (options.base) {
|
|
59
|
+
const base = options.base;
|
|
60
|
+
const set = [];
|
|
61
|
+
imageCandidates.forEach(({ url, descriptor }) => {
|
|
62
|
+
descriptor = descriptor ? ` ${descriptor}` : ``;
|
|
63
|
+
if ((0, templateUtils_1.isRelativeUrl)(url)) {
|
|
64
|
+
set.push((path_1.default.posix || path_1.default).join(base, url) + descriptor);
|
|
65
|
+
}
|
|
66
|
+
else {
|
|
67
|
+
set.push(url + descriptor);
|
|
68
|
+
}
|
|
69
|
+
});
|
|
70
|
+
attr.value.content = set.join(', ');
|
|
71
|
+
return;
|
|
72
|
+
}
|
|
73
|
+
const compoundExpression = (0, compiler_core_1.createCompoundExpression)([], attr.loc);
|
|
74
|
+
imageCandidates.forEach(({ url, descriptor }, index) => {
|
|
75
|
+
if (!(0, templateUtils_1.isExternalUrl)(url) &&
|
|
76
|
+
!(0, templateUtils_1.isDataUrl)(url) &&
|
|
77
|
+
(options.includeAbsolute || (0, templateUtils_1.isRelativeUrl)(url))) {
|
|
78
|
+
const { path } = (0, templateUtils_1.parseUrl)(url);
|
|
79
|
+
let exp;
|
|
80
|
+
if (path) {
|
|
81
|
+
const existingImportsIndex = context.imports.findIndex((i) => i.path === path);
|
|
82
|
+
if (existingImportsIndex > -1) {
|
|
83
|
+
exp = (0, compiler_core_1.createSimpleExpression)(`_imports_${existingImportsIndex}`, false, attr.loc, 2 /* CAN_HOIST */);
|
|
84
|
+
}
|
|
85
|
+
else {
|
|
86
|
+
exp = (0, compiler_core_1.createSimpleExpression)(`_imports_${context.imports.length}`, false, attr.loc, 2 /* CAN_HOIST */);
|
|
87
|
+
context.imports.push({ exp, path });
|
|
88
|
+
}
|
|
89
|
+
compoundExpression.children.push(exp);
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
else {
|
|
93
|
+
const exp = (0, compiler_core_1.createSimpleExpression)(`"${url}"`, false, attr.loc, 2 /* CAN_HOIST */);
|
|
94
|
+
compoundExpression.children.push(exp);
|
|
95
|
+
}
|
|
96
|
+
const isNotLast = imageCandidates.length - 1 > index;
|
|
97
|
+
if (descriptor && isNotLast) {
|
|
98
|
+
compoundExpression.children.push(` + ' ${descriptor}, ' + `);
|
|
99
|
+
}
|
|
100
|
+
else if (descriptor) {
|
|
101
|
+
compoundExpression.children.push(` + ' ${descriptor}'`);
|
|
102
|
+
}
|
|
103
|
+
else if (isNotLast) {
|
|
104
|
+
compoundExpression.children.push(` + ', ' + `);
|
|
105
|
+
}
|
|
106
|
+
});
|
|
107
|
+
const hoisted = context.hoist(compoundExpression);
|
|
108
|
+
hoisted.constType = 2 /* CAN_HOIST */;
|
|
109
|
+
node.props[index] = {
|
|
110
|
+
type: 7 /* DIRECTIVE */,
|
|
111
|
+
name: 'bind',
|
|
112
|
+
arg: (0, compiler_core_1.createSimpleExpression)('srcset', true, attr.loc),
|
|
113
|
+
exp: hoisted,
|
|
114
|
+
modifiers: [],
|
|
115
|
+
loc: attr.loc,
|
|
116
|
+
};
|
|
117
|
+
}
|
|
118
|
+
});
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
};
|
|
122
|
+
exports.transformSrcset = transformSrcset;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/// <reference types="node" />
|
|
2
|
+
import { UrlWithStringQuery } from 'url';
|
|
3
|
+
export declare function isRelativeUrl(url: string): boolean;
|
|
4
|
+
export declare function isExternalUrl(url: string): boolean;
|
|
5
|
+
export declare function isDataUrl(url: string): boolean;
|
|
6
|
+
/**
|
|
7
|
+
* Parses string url into URL object.
|
|
8
|
+
*/
|
|
9
|
+
export declare function parseUrl(url: string): UrlWithStringQuery;
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.parseUrl = exports.isDataUrl = exports.isExternalUrl = exports.isRelativeUrl = void 0;
|
|
4
|
+
const url_1 = require("url");
|
|
5
|
+
const shared_1 = require("@vue/shared");
|
|
6
|
+
function isRelativeUrl(url) {
|
|
7
|
+
const firstChar = url.charAt(0);
|
|
8
|
+
return firstChar === '.' || firstChar === '~' || firstChar === '@';
|
|
9
|
+
}
|
|
10
|
+
exports.isRelativeUrl = isRelativeUrl;
|
|
11
|
+
const externalRE = /^(https?:)?\/\//;
|
|
12
|
+
function isExternalUrl(url) {
|
|
13
|
+
return externalRE.test(url);
|
|
14
|
+
}
|
|
15
|
+
exports.isExternalUrl = isExternalUrl;
|
|
16
|
+
const dataUrlRE = /^\s*data:/i;
|
|
17
|
+
function isDataUrl(url) {
|
|
18
|
+
return dataUrlRE.test(url);
|
|
19
|
+
}
|
|
20
|
+
exports.isDataUrl = isDataUrl;
|
|
21
|
+
/**
|
|
22
|
+
* Parses string url into URL object.
|
|
23
|
+
*/
|
|
24
|
+
function parseUrl(url) {
|
|
25
|
+
const firstChar = url.charAt(0);
|
|
26
|
+
if (firstChar === '~') {
|
|
27
|
+
const secondChar = url.charAt(1);
|
|
28
|
+
url = url.slice(secondChar === '/' ? 2 : 1);
|
|
29
|
+
}
|
|
30
|
+
return parseUriParts(url);
|
|
31
|
+
}
|
|
32
|
+
exports.parseUrl = parseUrl;
|
|
33
|
+
/**
|
|
34
|
+
* vuejs/component-compiler-utils#22 Support uri fragment in transformed require
|
|
35
|
+
* @param urlString an url as a string
|
|
36
|
+
*/
|
|
37
|
+
function parseUriParts(urlString) {
|
|
38
|
+
// A TypeError is thrown if urlString is not a string
|
|
39
|
+
// @see https://nodejs.org/api/url.html#url_url_parse_urlstring_parsequerystring_slashesdenotehost
|
|
40
|
+
return (0, url_1.parse)((0, shared_1.isString)(urlString) ? urlString : '', false, true);
|
|
41
|
+
}
|
package/dist/vue/utils.d.ts
CHANGED
|
@@ -7,3 +7,21 @@ export declare function addStaticClass(node: ElementNode, clazz: string): string
|
|
|
7
7
|
export declare function createDirectiveNode(name: string, arg: string, exp: string | ExpressionNode): DirectiveNode;
|
|
8
8
|
export declare function createOnDirectiveNode(name: string, value: string): DirectiveNode;
|
|
9
9
|
export declare function createBindDirectiveNode(name: string, value: string | ExpressionNode): DirectiveNode;
|
|
10
|
+
export declare function createUniVueTransformAssetUrls(base: string): {
|
|
11
|
+
base: string;
|
|
12
|
+
includeAbsolute: boolean;
|
|
13
|
+
tags: {
|
|
14
|
+
audio: string[];
|
|
15
|
+
video: string[];
|
|
16
|
+
img: string[];
|
|
17
|
+
image: string[];
|
|
18
|
+
'cover-image': string[];
|
|
19
|
+
'v-uni-audio': string[];
|
|
20
|
+
'v-uni-video': string[];
|
|
21
|
+
'v-uni-image': string[];
|
|
22
|
+
'v-uni-cover-image': string[];
|
|
23
|
+
'u-image': string[];
|
|
24
|
+
'u-video': string[];
|
|
25
|
+
};
|
|
26
|
+
};
|
|
27
|
+
export declare function getBaseNodeTransforms(base: string): import("@vue/compiler-core").NodeTransform[];
|
package/dist/vue/utils.js
CHANGED
|
@@ -1,9 +1,11 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.createBindDirectiveNode = exports.createOnDirectiveNode = exports.createDirectiveNode = exports.addStaticClass = exports.createAttributeNode = exports.isUserComponent = exports.VUE_REF_IN_FOR = exports.VUE_REF = void 0;
|
|
3
|
+
exports.getBaseNodeTransforms = exports.createUniVueTransformAssetUrls = exports.createBindDirectiveNode = exports.createOnDirectiveNode = exports.createDirectiveNode = exports.addStaticClass = exports.createAttributeNode = exports.isUserComponent = exports.VUE_REF_IN_FOR = exports.VUE_REF = void 0;
|
|
4
4
|
const shared_1 = require("@vue/shared");
|
|
5
5
|
const uni_shared_1 = require("@dcloudio/uni-shared");
|
|
6
6
|
const compiler_core_1 = require("@vue/compiler-core");
|
|
7
|
+
const templateTransformAssetUrl_1 = require("./transforms/templateTransformAssetUrl");
|
|
8
|
+
const templateTransformSrcset_1 = require("./transforms/templateTransformSrcset");
|
|
7
9
|
exports.VUE_REF = 'r';
|
|
8
10
|
exports.VUE_REF_IN_FOR = 'r-i-f';
|
|
9
11
|
function isUserComponent(node, context) {
|
|
@@ -64,3 +66,33 @@ function createBindDirectiveNode(name, value) {
|
|
|
64
66
|
return createDirectiveNode('bind', name, value);
|
|
65
67
|
}
|
|
66
68
|
exports.createBindDirectiveNode = createBindDirectiveNode;
|
|
69
|
+
function createUniVueTransformAssetUrls(base) {
|
|
70
|
+
return {
|
|
71
|
+
base,
|
|
72
|
+
includeAbsolute: true,
|
|
73
|
+
tags: {
|
|
74
|
+
audio: ['src'],
|
|
75
|
+
video: ['src', 'poster'],
|
|
76
|
+
img: ['src'],
|
|
77
|
+
image: ['src'],
|
|
78
|
+
'cover-image': ['src'],
|
|
79
|
+
// h5
|
|
80
|
+
'v-uni-audio': ['src'],
|
|
81
|
+
'v-uni-video': ['src', 'poster'],
|
|
82
|
+
'v-uni-image': ['src'],
|
|
83
|
+
'v-uni-cover-image': ['src'],
|
|
84
|
+
// nvue
|
|
85
|
+
'u-image': ['src'],
|
|
86
|
+
'u-video': ['src', 'poster'],
|
|
87
|
+
},
|
|
88
|
+
};
|
|
89
|
+
}
|
|
90
|
+
exports.createUniVueTransformAssetUrls = createUniVueTransformAssetUrls;
|
|
91
|
+
function getBaseNodeTransforms(base) {
|
|
92
|
+
const transformAssetUrls = createUniVueTransformAssetUrls(base);
|
|
93
|
+
return [
|
|
94
|
+
(0, templateTransformAssetUrl_1.createAssetUrlTransformWithOptions)(transformAssetUrls),
|
|
95
|
+
(0, templateTransformSrcset_1.createSrcsetTransformWithOptions)(transformAssetUrls),
|
|
96
|
+
];
|
|
97
|
+
}
|
|
98
|
+
exports.getBaseNodeTransforms = getBaseNodeTransforms;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@dcloudio/uni-cli-shared",
|
|
3
|
-
"version": "3.0.0-alpha-
|
|
3
|
+
"version": "3.0.0-alpha-3021320211123001",
|
|
4
4
|
"description": "@dcloudio/uni-cli-shared",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
@@ -20,11 +20,12 @@
|
|
|
20
20
|
"dependencies": {
|
|
21
21
|
"@babel/parser": "^7.15.0",
|
|
22
22
|
"@babel/types": "^7.15.0",
|
|
23
|
-
"@dcloudio/uni-i18n": "3.0.0-alpha-
|
|
24
|
-
"@dcloudio/uni-shared": "3.0.0-alpha-
|
|
23
|
+
"@dcloudio/uni-i18n": "3.0.0-alpha-3021320211123001",
|
|
24
|
+
"@dcloudio/uni-shared": "3.0.0-alpha-3021320211123001",
|
|
25
25
|
"@rollup/pluginutils": "^4.1.1",
|
|
26
26
|
"@vue/compiler-core": "3.2.22",
|
|
27
27
|
"@vue/compiler-dom": "3.2.22",
|
|
28
|
+
"@vue/compiler-sfc": "3.2.22",
|
|
28
29
|
"@vue/shared": "3.2.22",
|
|
29
30
|
"chalk": "^4.1.1",
|
|
30
31
|
"chokidar": "^3.5.2",
|
|
@@ -58,7 +59,6 @@
|
|
|
58
59
|
"@types/mime": "^2.0.3",
|
|
59
60
|
"@types/module-alias": "^2.0.1",
|
|
60
61
|
"@types/stylus": "^0.48.36",
|
|
61
|
-
"@vue/compiler-sfc": "3.2.22",
|
|
62
62
|
"postcss": "^8.3.8"
|
|
63
63
|
}
|
|
64
64
|
}
|