@cloudbase/cals 0.5.4-beta.0 → 0.5.5-alpha.0
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/lib/parser/cals/index.d.ts +0 -8
- package/lib/parser/cals/index.d.ts.map +1 -1
- package/lib/parser/cals/index.js +2 -22
- package/lib/parser/cals/utils/block/index.d.ts +0 -0
- package/lib/parser/cals/utils/block/index.d.ts.map +0 -0
- package/lib/parser/cals/utils/block/index.js +0 -0
- package/lib/parser/cals/utils/code/index.d.ts +0 -0
- package/lib/parser/cals/utils/code/index.d.ts.map +0 -0
- package/lib/parser/cals/utils/code/index.js +0 -0
- package/lib/parser/cals/utils/common.d.ts +0 -0
- package/lib/parser/cals/utils/common.d.ts.map +0 -0
- package/lib/parser/cals/utils/common.js +0 -0
- package/lib/parser/cals/utils/runtime.d.ts +0 -0
- package/lib/parser/cals/utils/runtime.d.ts.map +0 -0
- package/lib/parser/cals/utils/runtime.js +0 -0
- package/lib/parser/cals/utils/spinoff/index.d.ts +0 -0
- package/lib/parser/cals/utils/spinoff/index.d.ts.map +0 -0
- package/lib/parser/cals/utils/spinoff/index.js +0 -0
- package/lib/parser/cals/utils/style.d.ts +5 -36
- package/lib/parser/cals/utils/style.d.ts.map +1 -1
- package/lib/parser/cals/utils/style.js +70 -102
- package/lib/parser/cals/utils/template.d.ts +0 -1
- package/lib/parser/cals/utils/template.d.ts.map +1 -1
- package/lib/parser/cals/utils/template.js +2 -3
- package/lib/parser/cals/utils/version/common.d.ts +0 -0
- package/lib/parser/cals/utils/version/common.d.ts.map +0 -0
- package/lib/parser/cals/utils/version/common.js +0 -0
- package/lib/parser/cals/utils/version/config.d.ts +0 -0
- package/lib/parser/cals/utils/version/config.d.ts.map +0 -0
- package/lib/parser/cals/utils/version/config.js +0 -0
- package/lib/parser/cals/utils/version/index.d.ts +0 -0
- package/lib/parser/cals/utils/version/index.d.ts.map +0 -0
- package/lib/parser/cals/utils/version/index.js +0 -0
- package/lib/parser/cals/utils/version/parses.d.ts +0 -0
- package/lib/parser/cals/utils/version/parses.d.ts.map +0 -0
- package/lib/parser/cals/utils/version/parses.js +0 -0
- package/lib/parser/cals/utils/version/utils.d.ts +0 -0
- package/lib/parser/cals/utils/version/utils.d.ts.map +0 -0
- package/lib/parser/cals/utils/version/utils.js +0 -0
- package/lib/parser/expression/index.d.ts +0 -0
- package/lib/parser/expression/index.d.ts.map +0 -0
- package/lib/parser/expression/index.js +0 -0
- package/lib/parser/index.d.ts +1 -2
- package/lib/parser/index.d.ts.map +1 -1
- package/lib/parser/index.js +1 -7
- package/lib/types/basic/app.d.ts +0 -0
- package/lib/types/basic/app.d.ts.map +0 -0
- package/lib/types/basic/app.js +0 -0
- package/lib/types/basic/common.d.ts +0 -0
- package/lib/types/basic/common.d.ts.map +0 -0
- package/lib/types/basic/common.js +0 -0
- package/lib/types/basic/component.d.ts +0 -0
- package/lib/types/basic/component.d.ts.map +0 -0
- package/lib/types/basic/component.js +0 -0
- package/lib/types/basic/datasource.d.ts +0 -0
- package/lib/types/basic/datasource.d.ts.map +0 -0
- package/lib/types/basic/datasource.js +0 -0
- package/lib/types/index.d.ts +0 -0
- package/lib/types/index.d.ts.map +0 -0
- package/lib/types/index.js +0 -0
- package/lib/types/lcds.d.ts +0 -0
- package/lib/types/lcds.d.ts.map +0 -0
- package/lib/types/lcds.js +0 -0
- package/lib/types/platform/app.d.ts +0 -21
- package/lib/types/platform/app.d.ts.map +1 -1
- package/lib/types/platform/app.js +0 -9
- package/lib/types/platform/common.d.ts +0 -0
- package/lib/types/platform/common.d.ts.map +0 -0
- package/lib/types/platform/common.js +0 -0
- package/lib/types/platform/component.d.ts +0 -0
- package/lib/types/platform/component.d.ts.map +0 -0
- package/lib/types/platform/component.js +0 -0
- package/lib/types/platform/datasource.d.ts +0 -0
- package/lib/types/platform/datasource.d.ts.map +0 -0
- package/lib/types/platform/datasource.js +0 -0
- package/lib/types/platform/widget/form.d.ts +0 -0
- package/lib/types/platform/widget/form.d.ts.map +0 -0
- package/lib/types/platform/widget/form.js +0 -0
- package/lib/types/platform/widget/meta.d.ts +0 -0
- package/lib/types/platform/widget/meta.d.ts.map +0 -0
- package/lib/types/platform/widget/meta.js +0 -0
- package/lib/utils/CSSProperty.d.ts +0 -0
- package/lib/utils/CSSProperty.d.ts.map +0 -0
- package/lib/utils/CSSProperty.js +0 -0
- package/lib/utils/build.d.ts +0 -0
- package/lib/utils/build.d.ts.map +0 -0
- package/lib/utils/build.js +0 -0
- package/lib/utils/constant.d.ts +0 -0
- package/lib/utils/constant.d.ts.map +0 -0
- package/lib/utils/constant.js +0 -0
- package/lib/utils/dts/auto-generated.d.ts +1 -1
- package/lib/utils/dts/auto-generated.d.ts.map +1 -1
- package/lib/utils/dts/auto-generated.js +92 -1
- package/lib/utils/dts/build.js +2 -0
- package/lib/utils/dts/index.d.ts +33 -6
- package/lib/utils/dts/index.d.ts.map +1 -1
- package/lib/utils/dts/index.js +168 -39
- package/lib/utils/index.d.ts +1 -0
- package/lib/utils/index.d.ts.map +1 -1
- package/lib/utils/index.js +1 -1
- package/package.json +1 -1
- package/lib/parser/plugins/postcss-rpx2clac.d.ts +0 -18
- package/lib/parser/plugins/postcss-rpx2clac.d.ts.map +0 -1
- package/lib/parser/plugins/postcss-rpx2clac.js +0 -68
package/lib/utils/dts/index.js
CHANGED
|
@@ -48,6 +48,9 @@ var IInputDataType;
|
|
|
48
48
|
IInputDataType["compHandlerCodes"] = "compHandlerCodes";
|
|
49
49
|
IInputDataType["compPropData"] = "compPropData";
|
|
50
50
|
IInputDataType["compPropEvents"] = "compPropEvents";
|
|
51
|
+
IInputDataType["usedComponents"] = "usedComponents";
|
|
52
|
+
IInputDataType["usedWidgets"] = "usedWidgets";
|
|
53
|
+
IInputDataType["repeaterScope"] = "repeaterScope";
|
|
51
54
|
})(IInputDataType = exports.IInputDataType || (exports.IInputDataType = {}));
|
|
52
55
|
const DtsPlaceholder = {
|
|
53
56
|
[IInputDataType.globalState]: "// Global State 全局变量 - Don't touch me",
|
|
@@ -60,18 +63,24 @@ const DtsPlaceholder = {
|
|
|
60
63
|
[IInputDataType.compHandlerCodes]: "// Comp Handler 组件方法 - Don't touch me",
|
|
61
64
|
[IInputDataType.compPropData]: "// Comp Prop Data 组件属性 - Don't touch me",
|
|
62
65
|
[IInputDataType.compPropEvents]: "// Comp Prop Events 组件事件 - Don't touch me",
|
|
66
|
+
[IInputDataType.usedComponents]: "// Used Components - Don't touch me",
|
|
67
|
+
[IInputDataType.usedWidgets]: "// used widgets - Don't touch me",
|
|
68
|
+
[IInputDataType.repeaterScope]: "// repeater scope - Don't touch me"
|
|
63
69
|
};
|
|
64
70
|
const DtsInnerSign = {
|
|
65
|
-
[IInputDataType.globalState]:
|
|
66
|
-
[IInputDataType.pageState]:
|
|
67
|
-
[IInputDataType.compState]:
|
|
68
|
-
[IInputDataType.pageParams]:
|
|
69
|
-
[IInputDataType.forState]:
|
|
70
|
-
[IInputDataType.globalCommonCodes]:
|
|
71
|
-
[IInputDataType.pageHandlerCodes]:
|
|
72
|
-
[IInputDataType.compHandlerCodes]:
|
|
73
|
-
[IInputDataType.compPropData]:
|
|
74
|
-
[IInputDataType.compPropEvents]:
|
|
71
|
+
[IInputDataType.globalState]: "Global State Inner",
|
|
72
|
+
[IInputDataType.pageState]: "Page State Inner",
|
|
73
|
+
[IInputDataType.compState]: "Comp State Inner",
|
|
74
|
+
[IInputDataType.pageParams]: "Page Param Inner",
|
|
75
|
+
[IInputDataType.forState]: "Global For Inner",
|
|
76
|
+
[IInputDataType.globalCommonCodes]: "Global Common Inner",
|
|
77
|
+
[IInputDataType.pageHandlerCodes]: "Page Handler Inner",
|
|
78
|
+
[IInputDataType.compHandlerCodes]: "Comp Handler Inner",
|
|
79
|
+
[IInputDataType.compPropData]: "Comp Prop Data Inner",
|
|
80
|
+
[IInputDataType.compPropEvents]: "Comp Prop Events Inner",
|
|
81
|
+
[IInputDataType.usedComponents]: "Used Components Inner",
|
|
82
|
+
[IInputDataType.usedWidgets]: "used widgets Inner",
|
|
83
|
+
[IInputDataType.repeaterScope]: "repeater scope Inner"
|
|
75
84
|
};
|
|
76
85
|
/**
|
|
77
86
|
* 通过该类可以共享同个dts。
|
|
@@ -83,7 +92,7 @@ class WeDaDTS {
|
|
|
83
92
|
*/
|
|
84
93
|
static updateDTS(inputData = {}, options = { isCompMode: false }) {
|
|
85
94
|
return __awaiter(this, void 0, void 0, function* () {
|
|
86
|
-
WeDaDTS._dts = yield generateWeDaAppDTS(inputData, Object.assign(Object.assign({}, options), { needGlobalFormula: true, needGlobalFor: true }));
|
|
95
|
+
WeDaDTS._dts = yield generateWeDaAppDTS(inputData, Object.assign(Object.assign({}, options), { needGlobalFormula: true, needGlobalFor: true, needRepeaterScope: true }));
|
|
87
96
|
});
|
|
88
97
|
}
|
|
89
98
|
/**
|
|
@@ -103,7 +112,7 @@ class WeDaDTS {
|
|
|
103
112
|
}
|
|
104
113
|
});
|
|
105
114
|
}
|
|
106
|
-
static getDTS(options = { needGlobalFormula: false, needGlobalFor: false }) {
|
|
115
|
+
static getDTS(options = { needGlobalFormula: false, needGlobalFor: false, needRepeaterScope: false }) {
|
|
107
116
|
let resultDts = WeDaDTS._dts;
|
|
108
117
|
if (!options.needGlobalFormula) {
|
|
109
118
|
resultDts = resultDts.replace(/^\/\/ Global Formula Begin[\s\S]*^\/\/ Global Formula End$/m, '');
|
|
@@ -111,6 +120,9 @@ class WeDaDTS {
|
|
|
111
120
|
if (!options.needGlobalFor) {
|
|
112
121
|
resultDts = resultDts.replace(/^\/\/ Global For Begin[\s\S]*^\/\/ Global For End$/m, '');
|
|
113
122
|
}
|
|
123
|
+
if (!options.needRepeaterScope) {
|
|
124
|
+
resultDts = resultDts.replace(/\/\/ repeater scope Inner Begin[\s\S]*\/\/ repeater scope Inner End$/m, '');
|
|
125
|
+
}
|
|
114
126
|
return resultDts;
|
|
115
127
|
}
|
|
116
128
|
}
|
|
@@ -119,7 +131,7 @@ WeDaDTS._dts = '';
|
|
|
119
131
|
/**
|
|
120
132
|
* 生成 WeDa 应用的低码代码提示的 dts 类型声明内容
|
|
121
133
|
*/
|
|
122
|
-
function generateWeDaAppDTS(inputData = {}, options = { isCompMode: false, needGlobalFormula: false, needGlobalFor: false }) {
|
|
134
|
+
function generateWeDaAppDTS(inputData = {}, options = { isCompMode: false, needGlobalFormula: false, needGlobalFor: false, needRepeaterScope: false }) {
|
|
123
135
|
return __awaiter(this, void 0, void 0, function* () {
|
|
124
136
|
let resultDts = auto_generated_1.wedaDTS;
|
|
125
137
|
yield Promise.all(Object.keys(inputData).map((key) => __awaiter(this, void 0, void 0, function* () {
|
|
@@ -150,6 +162,10 @@ function generateWeDaAppDTS(inputData = {}, options = { isCompMode: false, needG
|
|
|
150
162
|
if (!(options === null || options === void 0 ? void 0 : options.needGlobalFor)) {
|
|
151
163
|
resultDts = resultDts.replace(/^\/\/ Global For Begin[\s\S]*^\/\/ Global For End$/m, '');
|
|
152
164
|
}
|
|
165
|
+
// 根据是否需要 Repeater 作用域来删除一些类型定义
|
|
166
|
+
if (!(options === null || options === void 0 ? void 0 : options.needRepeaterScope)) {
|
|
167
|
+
resultDts = resultDts.replace(/\/\/ repeater scope Inner Begin[\s\S]*\/\/ repeater scope Inner End$/m, '');
|
|
168
|
+
}
|
|
153
169
|
// console.log(resultDts)
|
|
154
170
|
return resultDts;
|
|
155
171
|
});
|
|
@@ -204,18 +220,86 @@ function _generateOneItemDTS(inputData, itemType) {
|
|
|
204
220
|
},
|
|
205
221
|
[IInputDataType.compPropEvents]: function (inputData) {
|
|
206
222
|
const IData = `any`;
|
|
207
|
-
return inputData
|
|
208
|
-
.map((eventName) => {
|
|
223
|
+
return inputData.map(eventName => {
|
|
209
224
|
return `function ${eventName}(data?: ${IData}): void`;
|
|
210
|
-
})
|
|
211
|
-
|
|
225
|
+
}).join('\n');
|
|
226
|
+
},
|
|
227
|
+
[IInputDataType.usedComponents]: function (inputData) {
|
|
228
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
229
|
+
const results = yield Promise.all(inputData.map((item) => __awaiter(this, void 0, void 0, function* () {
|
|
230
|
+
// 属性
|
|
231
|
+
let exportPropertiesDTS = '';
|
|
232
|
+
if (item.exportProperties) {
|
|
233
|
+
exportPropertiesDTS = yield _compile(item.exportProperties);
|
|
234
|
+
}
|
|
235
|
+
// 方法
|
|
236
|
+
let exportMethodsDTS = '';
|
|
237
|
+
if (item.exportMethods) {
|
|
238
|
+
const results = yield Promise.all(item.exportMethods.map((item) => __awaiter(this, void 0, void 0, function* () {
|
|
239
|
+
let inputDTS = '';
|
|
240
|
+
if (item.input) {
|
|
241
|
+
inputDTS = yield _compile(item.input);
|
|
242
|
+
}
|
|
243
|
+
let outputDTS = 'void';
|
|
244
|
+
if (item.output) {
|
|
245
|
+
outputDTS = yield _compile(item.output, true);
|
|
246
|
+
}
|
|
247
|
+
return `${item.name}: (${inputDTS.trim().replace(/\n/g, ',')}) => ${outputDTS}`;
|
|
248
|
+
})));
|
|
249
|
+
exportMethodsDTS = results.join('\n');
|
|
250
|
+
}
|
|
251
|
+
return `
|
|
252
|
+
declare class ${item.module + item.component} extends UserWidget {
|
|
253
|
+
get custom(): {
|
|
254
|
+
${exportPropertiesDTS}
|
|
255
|
+
|
|
256
|
+
${exportMethodsDTS}
|
|
257
|
+
};
|
|
258
|
+
|
|
259
|
+
${exportPropertiesDTS}
|
|
260
|
+
|
|
261
|
+
${exportMethodsDTS}
|
|
262
|
+
}
|
|
263
|
+
`;
|
|
264
|
+
})));
|
|
265
|
+
return results.join('\n');
|
|
266
|
+
});
|
|
267
|
+
},
|
|
268
|
+
[IInputDataType.usedWidgets]: function (inputData) {
|
|
269
|
+
return inputData.map(item => {
|
|
270
|
+
if (item.idList && item.idList.length > 0) {
|
|
271
|
+
const interfaceName = item.module + item.component;
|
|
272
|
+
return item.idList.map(id => `const ${id}: ${interfaceName}`).join('\n');
|
|
273
|
+
}
|
|
274
|
+
return '';
|
|
275
|
+
}).join('\n');
|
|
276
|
+
},
|
|
277
|
+
[IInputDataType.repeaterScope]: function (inputData) {
|
|
278
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
279
|
+
const results = yield Promise.all(inputData.map((item) => __awaiter(this, void 0, void 0, function* () {
|
|
280
|
+
let itemDataDTS = yield _compile(item.itemData, true);
|
|
281
|
+
return `
|
|
282
|
+
const ${item.currentItemAlias}: ${itemDataDTS}
|
|
283
|
+
const ${item.currentIndexAlias}: number
|
|
284
|
+
`;
|
|
285
|
+
})));
|
|
286
|
+
return results.join('\n');
|
|
287
|
+
});
|
|
212
288
|
},
|
|
213
289
|
};
|
|
214
|
-
function _compile(jsonschema) {
|
|
290
|
+
function _compile(jsonschema, isObjNeedWrapper = false) {
|
|
215
291
|
return __awaiter(this, void 0, void 0, function* () {
|
|
216
292
|
let dts = yield compile(jsonschema, 'IWeDa', { additionalProperties: false, bannerComment: '', format: false });
|
|
217
|
-
|
|
218
|
-
|
|
293
|
+
if (dts.search(/^export interface IWeDa/) >= 0) {
|
|
294
|
+
dts = dts.replace(/^export interface.*$/m, '');
|
|
295
|
+
dts = dts.substring(0, dts.length - 2);
|
|
296
|
+
if (isObjNeedWrapper) {
|
|
297
|
+
dts = `{${dts}}`;
|
|
298
|
+
}
|
|
299
|
+
}
|
|
300
|
+
else {
|
|
301
|
+
dts = dts.replace(/^export type IWeDa =/m, '');
|
|
302
|
+
}
|
|
219
303
|
return dts;
|
|
220
304
|
});
|
|
221
305
|
}
|
|
@@ -234,17 +318,60 @@ function _generateOneItemDTS(inputData, itemType) {
|
|
|
234
318
|
// 仅仅为了与 unittest 共享,外部请不要使用
|
|
235
319
|
exports.workerCode = `
|
|
236
320
|
importScripts('https://qbase.cdn-go.cn/lcap/lcap-resource-cdngo/-/release/_url/devtools/typescriptServices.min.js');
|
|
321
|
+
importScripts('https://qbase.cdn-go.cn/lcap/lcap-resource-cdngo/-/release/_url/devtools/ts-lib.min.js');
|
|
322
|
+
|
|
323
|
+
const files = {
|
|
324
|
+
"foo.ts": '',
|
|
325
|
+
"lib.d.ts": libFileMap['lib.es5.d.ts']
|
|
326
|
+
};
|
|
327
|
+
|
|
328
|
+
function createLanguageService() {
|
|
329
|
+
return ts.createLanguageService({
|
|
330
|
+
getCompilationSettings() {
|
|
331
|
+
return {};
|
|
332
|
+
},
|
|
333
|
+
getScriptFileNames() {
|
|
334
|
+
return ["foo.ts", "lib.d.ts"];
|
|
335
|
+
},
|
|
336
|
+
getScriptVersion(_fileName) {
|
|
337
|
+
// 这样可避免使用缓存
|
|
338
|
+
if (_fileName === 'foo.ts')
|
|
339
|
+
return 'v_' + Math.random();
|
|
340
|
+
return ''
|
|
341
|
+
},
|
|
342
|
+
getScriptSnapshot(fileName) {
|
|
343
|
+
if (fileName === ".ts") {
|
|
344
|
+
return ts.ScriptSnapshot.fromString("");
|
|
345
|
+
}
|
|
346
|
+
return ts.ScriptSnapshot.fromString(files[fileName] || "");
|
|
347
|
+
},
|
|
348
|
+
getCurrentDirectory: () => ".",
|
|
349
|
+
getDefaultLibFileName(options) {
|
|
350
|
+
return 'lib.d.ts'
|
|
351
|
+
},
|
|
352
|
+
fileExists: name => !!files[name],
|
|
353
|
+
readFile: name => {
|
|
354
|
+
return files[name]
|
|
355
|
+
}
|
|
356
|
+
});
|
|
357
|
+
}
|
|
358
|
+
const languageService = createLanguageService();
|
|
359
|
+
|
|
360
|
+
function transpile(code) {
|
|
361
|
+
files["foo.ts"] = code
|
|
362
|
+
const result = languageService.getEmitOutput(
|
|
363
|
+
"foo.ts",
|
|
364
|
+
/*emitOnlyDtsFiles*/ true,
|
|
365
|
+
/*forceDtsEmit*/ true
|
|
366
|
+
)
|
|
367
|
+
return result.outputFiles[0].text.trim()
|
|
368
|
+
}
|
|
237
369
|
|
|
238
|
-
ts.transpileOptionValueCompilerOptions.forEach(item => {
|
|
239
|
-
if (['emitDeclarationOnly', 'declaration'].includes(item.name)) {
|
|
240
|
-
item.transpileOptionValue = true
|
|
241
|
-
}
|
|
242
|
-
})
|
|
243
370
|
addEventListener('message', (message) => {
|
|
244
371
|
const {action, data: {id, code}} = message.data
|
|
245
372
|
switch(action) {
|
|
246
373
|
case 'dts':
|
|
247
|
-
const dts =
|
|
374
|
+
const dts = transpile(code)
|
|
248
375
|
postMessage({action: 'dts_back', data: {id, dts}})
|
|
249
376
|
break
|
|
250
377
|
default:
|
|
@@ -262,13 +389,15 @@ function TypescriptWorker() {
|
|
|
262
389
|
typescriptWorker.onmessage = function (event) {
|
|
263
390
|
const { action } = event.data;
|
|
264
391
|
if (action === 'dts_back') {
|
|
265
|
-
const { data: { id, dts }
|
|
392
|
+
const { data: { id, dts } } = event.data;
|
|
266
393
|
sendMessageCallbackFn[id] && sendMessageCallbackFn[id](dts);
|
|
267
394
|
}
|
|
268
395
|
};
|
|
269
396
|
}
|
|
270
397
|
function sendMessage(msgData, callbackFn) {
|
|
271
|
-
const id = Math.random()
|
|
398
|
+
const id = Math.random()
|
|
399
|
+
.toString(36)
|
|
400
|
+
.substring(2, 5);
|
|
272
401
|
msgData.data.id = id;
|
|
273
402
|
sendMessageCallbackFn[id] = callbackFn;
|
|
274
403
|
typescriptWorker.postMessage(msgData);
|
|
@@ -277,22 +406,22 @@ function TypescriptWorker() {
|
|
|
277
406
|
};
|
|
278
407
|
}
|
|
279
408
|
/**
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
409
|
+
* 使用:
|
|
410
|
+
* const typescriptWorker = getTypescriptWorker();
|
|
411
|
+
* typescriptWorker.sendMessage({ action: 'dts', data: { code } }, dts => {
|
|
412
|
+
*
|
|
413
|
+
* })
|
|
414
|
+
* // 以下暂未实现
|
|
415
|
+
* typescriptWorker.sendMessage({ action: 'ts', data: { code } }, ts => {
|
|
416
|
+
*
|
|
417
|
+
* })
|
|
418
|
+
*/
|
|
290
419
|
const getTypescriptWorker = TypescriptWorker();
|
|
291
420
|
/**
|
|
292
421
|
* 通过 js/ts 代码生成 dts
|
|
293
422
|
*/
|
|
294
423
|
function transpileToDTS(code) {
|
|
295
|
-
return new Promise(
|
|
424
|
+
return new Promise(resolve => {
|
|
296
425
|
const typescriptWorker = getTypescriptWorker();
|
|
297
426
|
typescriptWorker.sendMessage({ action: 'dts', data: { code } }, (dts) => {
|
|
298
427
|
resolve(dts);
|
package/lib/utils/index.d.ts
CHANGED
package/lib/utils/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/utils/index.ts"],"names":[],"mappings":"AAAA,cAAc,WAAW,CAAC;AAC1B,cAAc,gBAAgB,CAAC;AAC/B,cAAc,YAAY,CAAC;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/utils/index.ts"],"names":[],"mappings":"AAAA,cAAc,WAAW,CAAC;AAC1B,cAAc,gBAAgB,CAAC;AAC/B,cAAc,YAAY,CAAC;AAC3B,cAAc,aAAa,CAAC;AAC5B,OAAO,EAAE,gBAAgB,EAAE,MAAM,eAAe,CAAC"}
|
package/lib/utils/index.js
CHANGED
|
@@ -18,6 +18,6 @@ exports.isUnitlessNumber = void 0;
|
|
|
18
18
|
__exportStar(require("../parser"), exports);
|
|
19
19
|
__exportStar(require("../types/index"), exports);
|
|
20
20
|
__exportStar(require("./constant"), exports);
|
|
21
|
-
|
|
21
|
+
__exportStar(require("./dts/index"), exports);
|
|
22
22
|
var CSSProperty_1 = require("./CSSProperty");
|
|
23
23
|
Object.defineProperty(exports, "isUnitlessNumber", { enumerable: true, get: function () { return CSSProperty_1.isUnitlessNumber; } });
|
package/package.json
CHANGED
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
declare function Plugin(opt?: {
|
|
2
|
-
root?: string;
|
|
3
|
-
zoom?: number;
|
|
4
|
-
precision?: number;
|
|
5
|
-
outUnit?: string;
|
|
6
|
-
exclude?: string;
|
|
7
|
-
}): {
|
|
8
|
-
postcssPlugin: string;
|
|
9
|
-
Once(root: any, { result }: {
|
|
10
|
-
result: any;
|
|
11
|
-
}): void;
|
|
12
|
-
};
|
|
13
|
-
declare namespace Plugin {
|
|
14
|
-
var postcss: boolean;
|
|
15
|
-
var CALC_RPX_ROOT_VAL_NAME: string;
|
|
16
|
-
}
|
|
17
|
-
export default Plugin;
|
|
18
|
-
//# sourceMappingURL=postcss-rpx2clac.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"postcss-rpx2clac.d.ts","sourceRoot":"","sources":["../../../src/parser/plugins/postcss-rpx2clac.ts"],"names":[],"mappings":"AA+BA,iBAAS,MAAM,CAAC,GAAG,CAAC,EAAE;IAAE,IAAI,CAAC,EAAE,MAAM,CAAC;IAAC,IAAI,CAAC,EAAE,MAAM,CAAC;IAAC,SAAS,CAAC,EAAE,MAAM,CAAC;IAAC,OAAO,CAAC,EAAE,MAAM,CAAC;IAAC,OAAO,CAAC,EAAE,MAAM,CAAA;CAAE;;;;;EAqC7G;kBArCQ,MAAM;;;;AA0Cf,eAAe,MAAM,CAAC"}
|
|
@@ -1,68 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
const DEFAULT_CONFIG = {
|
|
4
|
-
root: '2',
|
|
5
|
-
/**
|
|
6
|
-
* 缩放比例
|
|
7
|
-
*/
|
|
8
|
-
zoom: 1,
|
|
9
|
-
/**
|
|
10
|
-
* 配置精度
|
|
11
|
-
*/
|
|
12
|
-
precision: 5,
|
|
13
|
-
/**
|
|
14
|
-
* 输出单位
|
|
15
|
-
*/
|
|
16
|
-
outUnit: 'px',
|
|
17
|
-
/**
|
|
18
|
-
* 配置忽略文件,正则匹配
|
|
19
|
-
*/
|
|
20
|
-
exclude: '',
|
|
21
|
-
};
|
|
22
|
-
/**
|
|
23
|
-
* https://github.com/cuth/postcss-pxtorem/blob/122649015322214f8e9d1ac852eb11c0791b634b/index.js#L56
|
|
24
|
-
*/
|
|
25
|
-
function toFixed(number, precision) {
|
|
26
|
-
const multiplier = Math.pow(10, precision + 1), wholeNumber = Math.floor(number * multiplier);
|
|
27
|
-
return (Math.round(wholeNumber / 10) * 10) / multiplier;
|
|
28
|
-
}
|
|
29
|
-
function Plugin(opt) {
|
|
30
|
-
opt = Object.assign(Object.assign({}, DEFAULT_CONFIG), (opt || {}));
|
|
31
|
-
const { root: rootValue, zoom, precision, outUnit, exclude } = opt;
|
|
32
|
-
return {
|
|
33
|
-
postcssPlugin: 'postcss-rpx2calc',
|
|
34
|
-
Once(root, { result }) {
|
|
35
|
-
if (exclude && root.source.input.file.match(exclude) !== null) {
|
|
36
|
-
result.root = root;
|
|
37
|
-
return;
|
|
38
|
-
}
|
|
39
|
-
root.walkRules(function (rule) {
|
|
40
|
-
rule.walkDecls(function (decl) {
|
|
41
|
-
if (decl.value.includes('rpx')) {
|
|
42
|
-
/**
|
|
43
|
-
* copy form
|
|
44
|
-
* https://github.com/cuth/postcss-pxtorem/blob/122649015322214f8e9d1ac852eb11c0791b634b/lib/pixel-unit-regex.js#L9
|
|
45
|
-
* 不处理 var()rpx 的情况
|
|
46
|
-
*/
|
|
47
|
-
const r2 = /"[^"]+"|'[^']+'|url\([^)]+\)|var\([^)]+\)|(\d*\.?\d+)rpx/g;
|
|
48
|
-
decl.value = decl.value.replace(r2, (str, num1) => {
|
|
49
|
-
if (num1 == undefined)
|
|
50
|
-
return str;
|
|
51
|
-
if (num1 == '0')
|
|
52
|
-
return '0';
|
|
53
|
-
const v = +num1 / zoom;
|
|
54
|
-
if (isNaN(v)) {
|
|
55
|
-
return str;
|
|
56
|
-
}
|
|
57
|
-
const value = Number.isInteger(v) ? v.toString() : toFixed(v, precision);
|
|
58
|
-
return `calc(${value}${outUnit}/${rootValue})`;
|
|
59
|
-
});
|
|
60
|
-
}
|
|
61
|
-
});
|
|
62
|
-
});
|
|
63
|
-
},
|
|
64
|
-
};
|
|
65
|
-
}
|
|
66
|
-
Plugin.postcss = true;
|
|
67
|
-
Plugin.CALC_RPX_ROOT_VAL_NAME = '--wd-rpx-radio';
|
|
68
|
-
exports.default = Plugin;
|