@openwebf/webf 0.22.3 → 0.22.5
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/IDLBlob.js +17 -0
- package/dist/analyzer.js +578 -0
- package/dist/analyzer_original.js +467 -0
- package/dist/commands.js +704 -0
- package/dist/dart.js +300 -0
- package/dist/declaration.js +63 -0
- package/dist/generator.js +466 -0
- package/dist/logger.js +103 -0
- package/dist/react.js +283 -0
- package/dist/utils.js +127 -0
- package/dist/vue.js +159 -0
- package/package.json +11 -1
- package/src/dart.ts +138 -7
- package/templates/class.dart.tpl +7 -2
- package/templates/react.package.json.tpl +1 -1
- package/CLAUDE.md +0 -206
- package/README-zhCN.md +0 -256
- package/coverage/clover.xml +0 -1295
- package/coverage/coverage-final.json +0 -12
- package/coverage/lcov-report/IDLBlob.ts.html +0 -142
- package/coverage/lcov-report/analyzer.ts.html +0 -2158
- package/coverage/lcov-report/analyzer_original.ts.html +0 -1450
- package/coverage/lcov-report/base.css +0 -224
- package/coverage/lcov-report/block-navigation.js +0 -87
- package/coverage/lcov-report/commands.ts.html +0 -700
- package/coverage/lcov-report/dart.ts.html +0 -490
- package/coverage/lcov-report/declaration.ts.html +0 -337
- package/coverage/lcov-report/favicon.png +0 -0
- package/coverage/lcov-report/generator.ts.html +0 -1171
- package/coverage/lcov-report/index.html +0 -266
- package/coverage/lcov-report/logger.ts.html +0 -424
- package/coverage/lcov-report/prettify.css +0 -1
- package/coverage/lcov-report/prettify.js +0 -2
- package/coverage/lcov-report/react.ts.html +0 -619
- package/coverage/lcov-report/sort-arrow-sprite.png +0 -0
- package/coverage/lcov-report/sorter.js +0 -196
- package/coverage/lcov-report/utils.ts.html +0 -466
- package/coverage/lcov-report/vue.ts.html +0 -613
- package/coverage/lcov.info +0 -2149
- package/jest.config.js +0 -24
package/dist/dart.js
ADDED
|
@@ -0,0 +1,300 @@
|
|
|
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.isStringUnionType = isStringUnionType;
|
|
7
|
+
exports.getUnionStringValues = getUnionStringValues;
|
|
8
|
+
exports.generateDartClass = generateDartClass;
|
|
9
|
+
const lodash_1 = __importDefault(require("lodash"));
|
|
10
|
+
const fs_1 = __importDefault(require("fs"));
|
|
11
|
+
const path_1 = __importDefault(require("path"));
|
|
12
|
+
const declaration_1 = require("./declaration");
|
|
13
|
+
const utils_1 = require("./utils");
|
|
14
|
+
function readTemplate(name) {
|
|
15
|
+
return fs_1.default.readFileSync(path_1.default.join(__dirname, '../templates/' + name + '.tpl'), { encoding: 'utf-8' });
|
|
16
|
+
}
|
|
17
|
+
// Generate enum name from property name
|
|
18
|
+
function getEnumName(className, propName) {
|
|
19
|
+
// Remove 'Properties' or 'Bindings' suffix from className
|
|
20
|
+
const baseName = className.replace(/Properties$|Bindings$/, '');
|
|
21
|
+
// Convert to PascalCase
|
|
22
|
+
return baseName + lodash_1.default.upperFirst(lodash_1.default.camelCase(propName));
|
|
23
|
+
}
|
|
24
|
+
// Check if a type is a union of string literals
|
|
25
|
+
function isStringUnionType(type) {
|
|
26
|
+
if (!Array.isArray(type.value))
|
|
27
|
+
return false;
|
|
28
|
+
// For now, we'll consider any union type as potentially a string union
|
|
29
|
+
// and let getUnionStringValues determine if it actually contains string literals
|
|
30
|
+
return type.value.length > 1;
|
|
31
|
+
}
|
|
32
|
+
// Extract string literal values from union type
|
|
33
|
+
function getUnionStringValues(prop, blob) {
|
|
34
|
+
if (!isStringUnionType(prop.type))
|
|
35
|
+
return null;
|
|
36
|
+
// Try to get the actual string values from the source TypeScript file
|
|
37
|
+
const sourceContent = blob.raw;
|
|
38
|
+
if (!sourceContent)
|
|
39
|
+
return null;
|
|
40
|
+
// Look for the property definition in the source
|
|
41
|
+
// Need to escape special characters in property names (like value-color)
|
|
42
|
+
const escapedPropName = prop.name.replace(/[-[\]{}()*+?.,\\^$|#\s]/g, '\\$&');
|
|
43
|
+
const propPattern = new RegExp(`['"]?${escapedPropName}['"]?\\s*\\?\\s*:\\s*([^;]+);`);
|
|
44
|
+
const match = sourceContent.match(propPattern);
|
|
45
|
+
if (!match)
|
|
46
|
+
return null;
|
|
47
|
+
// Extract string literals from union type
|
|
48
|
+
const unionType = match[1];
|
|
49
|
+
const literalPattern = /'([^']+)'|"([^"]+)"/g;
|
|
50
|
+
const values = [];
|
|
51
|
+
let literalMatch;
|
|
52
|
+
while ((literalMatch = literalPattern.exec(unionType)) !== null) {
|
|
53
|
+
values.push(literalMatch[1] || literalMatch[2]);
|
|
54
|
+
}
|
|
55
|
+
return values.length > 0 ? values : null;
|
|
56
|
+
}
|
|
57
|
+
// Generate Dart enum from string values
|
|
58
|
+
function generateDartEnum(enumName, values) {
|
|
59
|
+
const enumValues = values.map(value => {
|
|
60
|
+
// Convert kebab-case to camelCase for enum values
|
|
61
|
+
const enumValue = lodash_1.default.camelCase(value);
|
|
62
|
+
return ` ${enumValue}('${value}')`;
|
|
63
|
+
}).join(',\n');
|
|
64
|
+
return `enum ${enumName} {
|
|
65
|
+
${enumValues};
|
|
66
|
+
|
|
67
|
+
final String value;
|
|
68
|
+
const ${enumName}(this.value);
|
|
69
|
+
|
|
70
|
+
static ${enumName}? parse(String? value) {
|
|
71
|
+
if (value == null) return null;
|
|
72
|
+
return ${enumName}.values.firstWhere(
|
|
73
|
+
(e) => e.value == value,
|
|
74
|
+
orElse: () => throw ArgumentError('Invalid ${enumName} value: $value'),
|
|
75
|
+
);
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
@override
|
|
79
|
+
String toString() => value;
|
|
80
|
+
}`;
|
|
81
|
+
}
|
|
82
|
+
function generateReturnType(type, enumName) {
|
|
83
|
+
if ((0, utils_1.isPointerType)(type)) {
|
|
84
|
+
const pointerType = (0, utils_1.getPointerType)(type);
|
|
85
|
+
return pointerType;
|
|
86
|
+
}
|
|
87
|
+
if (type.isArray && typeof type.value === 'object' && !Array.isArray(type.value)) {
|
|
88
|
+
return `${(0, utils_1.getPointerType)(type.value)}[]`;
|
|
89
|
+
}
|
|
90
|
+
// Handle union types (e.g., 'left' | 'center' | 'right')
|
|
91
|
+
if (Array.isArray(type.value)) {
|
|
92
|
+
// If we have an enum name, use it; otherwise fall back to String
|
|
93
|
+
return enumName || 'String';
|
|
94
|
+
}
|
|
95
|
+
// Handle when type.value is a ParameterType object (nested type)
|
|
96
|
+
if (typeof type.value === 'object' && !Array.isArray(type.value) && type.value !== null) {
|
|
97
|
+
// This might be a nested ParameterType, recurse
|
|
98
|
+
return generateReturnType(type.value, enumName);
|
|
99
|
+
}
|
|
100
|
+
switch (type.value) {
|
|
101
|
+
case declaration_1.FunctionArgumentType.int: {
|
|
102
|
+
return 'int';
|
|
103
|
+
}
|
|
104
|
+
case declaration_1.FunctionArgumentType.double: {
|
|
105
|
+
return 'double';
|
|
106
|
+
}
|
|
107
|
+
case declaration_1.FunctionArgumentType.any: {
|
|
108
|
+
return 'any';
|
|
109
|
+
}
|
|
110
|
+
case declaration_1.FunctionArgumentType.boolean: {
|
|
111
|
+
return 'bool';
|
|
112
|
+
}
|
|
113
|
+
case declaration_1.FunctionArgumentType.dom_string: {
|
|
114
|
+
return 'String';
|
|
115
|
+
}
|
|
116
|
+
case declaration_1.FunctionArgumentType.void:
|
|
117
|
+
return 'void';
|
|
118
|
+
default:
|
|
119
|
+
return 'void';
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
function generateEventHandlerType(type) {
|
|
123
|
+
if (!(0, utils_1.isPointerType)(type)) {
|
|
124
|
+
throw new Error('Event type must be an instance of Event');
|
|
125
|
+
}
|
|
126
|
+
const pointerType = (0, utils_1.getPointerType)(type);
|
|
127
|
+
if (pointerType === 'Event') {
|
|
128
|
+
return `EventHandler`;
|
|
129
|
+
}
|
|
130
|
+
if (pointerType === 'CustomEvent') {
|
|
131
|
+
return `EventHandler<CustomEvent>`;
|
|
132
|
+
}
|
|
133
|
+
throw new Error('Unknown event type: ' + pointerType);
|
|
134
|
+
}
|
|
135
|
+
function generateAttributeSetter(propName, type, enumName) {
|
|
136
|
+
// Attributes from HTML are always strings, so we need to convert them
|
|
137
|
+
// Handle enum types
|
|
138
|
+
if (enumName && Array.isArray(type.value)) {
|
|
139
|
+
return `${propName} = ${enumName}.parse(value)`;
|
|
140
|
+
}
|
|
141
|
+
switch (type.value) {
|
|
142
|
+
case declaration_1.FunctionArgumentType.boolean:
|
|
143
|
+
return `${propName} = value == 'true' || value == ''`;
|
|
144
|
+
case declaration_1.FunctionArgumentType.int:
|
|
145
|
+
return `${propName} = int.tryParse(value) ?? 0`;
|
|
146
|
+
case declaration_1.FunctionArgumentType.double:
|
|
147
|
+
return `${propName} = double.tryParse(value) ?? 0.0`;
|
|
148
|
+
default:
|
|
149
|
+
// String and other types can be assigned directly
|
|
150
|
+
return `${propName} = value`;
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
function generateAttributeGetter(propName, type, optional, enumName) {
|
|
154
|
+
// Handle enum types
|
|
155
|
+
if (enumName && Array.isArray(type.value)) {
|
|
156
|
+
return optional ? `${propName}?.value` : `${propName}.value`;
|
|
157
|
+
}
|
|
158
|
+
// Handle nullable properties - they should return null if the value is null
|
|
159
|
+
if (optional && type.value !== declaration_1.FunctionArgumentType.boolean) {
|
|
160
|
+
// For nullable properties, we need to handle null values properly
|
|
161
|
+
return `${propName}?.toString()`;
|
|
162
|
+
}
|
|
163
|
+
// For non-nullable properties (including booleans), always convert to string
|
|
164
|
+
return `${propName}.toString()`;
|
|
165
|
+
}
|
|
166
|
+
function generateAttributeDeleter(propName, type, optional) {
|
|
167
|
+
// When deleting an attribute, we should reset it to its default value
|
|
168
|
+
switch (type.value) {
|
|
169
|
+
case declaration_1.FunctionArgumentType.boolean:
|
|
170
|
+
// Booleans default to false
|
|
171
|
+
return `${propName} = false`;
|
|
172
|
+
case declaration_1.FunctionArgumentType.int:
|
|
173
|
+
// Integers default to 0
|
|
174
|
+
return `${propName} = 0`;
|
|
175
|
+
case declaration_1.FunctionArgumentType.double:
|
|
176
|
+
// Doubles default to 0.0
|
|
177
|
+
return `${propName} = 0.0`;
|
|
178
|
+
case declaration_1.FunctionArgumentType.dom_string:
|
|
179
|
+
// Strings default to empty string or null for optional
|
|
180
|
+
if (optional) {
|
|
181
|
+
return `${propName} = null`;
|
|
182
|
+
}
|
|
183
|
+
return `${propName} = ''`;
|
|
184
|
+
default:
|
|
185
|
+
// For other types, set to null if optional, otherwise empty string
|
|
186
|
+
if (optional) {
|
|
187
|
+
return `${propName} = null`;
|
|
188
|
+
}
|
|
189
|
+
return `${propName} = ''`;
|
|
190
|
+
}
|
|
191
|
+
}
|
|
192
|
+
function generateMethodDeclaration(method) {
|
|
193
|
+
var methodName = method.name;
|
|
194
|
+
var args = method.args.map(arg => {
|
|
195
|
+
var argName = arg.name;
|
|
196
|
+
var argType = generateReturnType(arg.type);
|
|
197
|
+
return `${argName}: ${argType}`;
|
|
198
|
+
}).join(', ');
|
|
199
|
+
var returnType = generateReturnType(method.returnType);
|
|
200
|
+
return `${methodName}(${args}): ${returnType};`;
|
|
201
|
+
}
|
|
202
|
+
function shouldMakeNullable(prop) {
|
|
203
|
+
// Boolean properties should never be nullable in Dart, even if optional in TypeScript
|
|
204
|
+
if (prop.type.value === declaration_1.FunctionArgumentType.boolean) {
|
|
205
|
+
return false;
|
|
206
|
+
}
|
|
207
|
+
// Other optional properties remain nullable
|
|
208
|
+
return prop.optional;
|
|
209
|
+
}
|
|
210
|
+
function generateDartClass(blob, command) {
|
|
211
|
+
const classObjects = blob.objects.filter(obj => obj instanceof declaration_1.ClassObject);
|
|
212
|
+
const classObjectDictionary = Object.fromEntries(classObjects.map(object => {
|
|
213
|
+
return [object.name, object];
|
|
214
|
+
}));
|
|
215
|
+
const properties = classObjects.filter(object => {
|
|
216
|
+
return object.name.endsWith('Properties');
|
|
217
|
+
});
|
|
218
|
+
const events = classObjects.filter(object => {
|
|
219
|
+
return object.name.endsWith('Events');
|
|
220
|
+
});
|
|
221
|
+
const others = classObjects.filter(object => {
|
|
222
|
+
return !object.name.endsWith('Properties')
|
|
223
|
+
&& !object.name.endsWith('Events');
|
|
224
|
+
});
|
|
225
|
+
const dependencies = others.map(object => {
|
|
226
|
+
const props = object.props.map(prop => {
|
|
227
|
+
if (prop.optional) {
|
|
228
|
+
return `${prop.name}?: ${generateReturnType(prop.type)};`;
|
|
229
|
+
}
|
|
230
|
+
return `${prop.name}: ${generateReturnType(prop.type)};`;
|
|
231
|
+
}).join('\n ');
|
|
232
|
+
return `
|
|
233
|
+
interface ${object.name} {
|
|
234
|
+
${props}
|
|
235
|
+
}`;
|
|
236
|
+
}).join('\n\n');
|
|
237
|
+
const componentProperties = properties.length > 0 ? properties[0] : undefined;
|
|
238
|
+
const componentEvents = events.length > 0 ? events[0] : undefined;
|
|
239
|
+
const className = (() => {
|
|
240
|
+
if (componentProperties) {
|
|
241
|
+
return componentProperties.name.replace(/Properties$/, '');
|
|
242
|
+
}
|
|
243
|
+
if (componentEvents) {
|
|
244
|
+
return componentEvents.name.replace(/Events$/, '');
|
|
245
|
+
}
|
|
246
|
+
return '';
|
|
247
|
+
})();
|
|
248
|
+
if (!className) {
|
|
249
|
+
return '';
|
|
250
|
+
}
|
|
251
|
+
// Generate enums for union types
|
|
252
|
+
const enums = [];
|
|
253
|
+
const enumMap = new Map(); // prop name -> enum name
|
|
254
|
+
if (componentProperties) {
|
|
255
|
+
for (const prop of componentProperties.props) {
|
|
256
|
+
if (isStringUnionType(prop.type)) {
|
|
257
|
+
const values = getUnionStringValues(prop, blob);
|
|
258
|
+
if (values && values.length > 0) {
|
|
259
|
+
const enumName = getEnumName(componentProperties.name, prop.name);
|
|
260
|
+
enums.push({
|
|
261
|
+
name: enumName,
|
|
262
|
+
definition: generateDartEnum(enumName, values)
|
|
263
|
+
});
|
|
264
|
+
enumMap.set(prop.name, enumName);
|
|
265
|
+
}
|
|
266
|
+
}
|
|
267
|
+
}
|
|
268
|
+
}
|
|
269
|
+
const content = lodash_1.default.template(readTemplate('class.dart'))({
|
|
270
|
+
className: className,
|
|
271
|
+
properties: componentProperties,
|
|
272
|
+
events: componentEvents,
|
|
273
|
+
classObjectDictionary,
|
|
274
|
+
dependencies,
|
|
275
|
+
blob,
|
|
276
|
+
generateReturnType: (type, propName) => {
|
|
277
|
+
// If we have a prop name, check if it has an enum
|
|
278
|
+
if (propName && enumMap.has(propName)) {
|
|
279
|
+
return enumMap.get(propName);
|
|
280
|
+
}
|
|
281
|
+
return generateReturnType(type);
|
|
282
|
+
},
|
|
283
|
+
generateMethodDeclaration,
|
|
284
|
+
generateEventHandlerType,
|
|
285
|
+
generateAttributeSetter: (propName, type) => {
|
|
286
|
+
return generateAttributeSetter(propName, type, enumMap.get(propName));
|
|
287
|
+
},
|
|
288
|
+
generateAttributeGetter: (propName, type, optional) => {
|
|
289
|
+
return generateAttributeGetter(propName, type, optional, enumMap.get(propName));
|
|
290
|
+
},
|
|
291
|
+
generateAttributeDeleter,
|
|
292
|
+
shouldMakeNullable,
|
|
293
|
+
command,
|
|
294
|
+
enums,
|
|
295
|
+
enumMap,
|
|
296
|
+
});
|
|
297
|
+
return content.split('\n').filter(str => {
|
|
298
|
+
return str.trim().length > 0;
|
|
299
|
+
}).join('\n');
|
|
300
|
+
}
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.TypeAliasObject = exports.FunctionObject = exports.ClassObject = exports.ClassObjectKind = exports.FunctionDeclaration = exports.IndexedPropertyDeclaration = exports.PropsDeclaration = exports.ParameterMode = exports.FunctionArguments = exports.FunctionArgumentType = void 0;
|
|
4
|
+
var FunctionArgumentType;
|
|
5
|
+
(function (FunctionArgumentType) {
|
|
6
|
+
// Basic types
|
|
7
|
+
FunctionArgumentType[FunctionArgumentType["dom_string"] = 0] = "dom_string";
|
|
8
|
+
FunctionArgumentType[FunctionArgumentType["object"] = 1] = "object";
|
|
9
|
+
FunctionArgumentType[FunctionArgumentType["promise"] = 2] = "promise";
|
|
10
|
+
FunctionArgumentType[FunctionArgumentType["int"] = 3] = "int";
|
|
11
|
+
FunctionArgumentType[FunctionArgumentType["double"] = 4] = "double";
|
|
12
|
+
FunctionArgumentType[FunctionArgumentType["boolean"] = 5] = "boolean";
|
|
13
|
+
FunctionArgumentType[FunctionArgumentType["function"] = 6] = "function";
|
|
14
|
+
FunctionArgumentType[FunctionArgumentType["void"] = 7] = "void";
|
|
15
|
+
FunctionArgumentType[FunctionArgumentType["any"] = 8] = "any";
|
|
16
|
+
FunctionArgumentType[FunctionArgumentType["null"] = 9] = "null";
|
|
17
|
+
FunctionArgumentType[FunctionArgumentType["undefined"] = 10] = "undefined";
|
|
18
|
+
FunctionArgumentType[FunctionArgumentType["array"] = 11] = "array";
|
|
19
|
+
FunctionArgumentType[FunctionArgumentType["js_array_proto_methods"] = 12] = "js_array_proto_methods";
|
|
20
|
+
})(FunctionArgumentType || (exports.FunctionArgumentType = FunctionArgumentType = {}));
|
|
21
|
+
class FunctionArguments {
|
|
22
|
+
}
|
|
23
|
+
exports.FunctionArguments = FunctionArguments;
|
|
24
|
+
class ParameterMode {
|
|
25
|
+
}
|
|
26
|
+
exports.ParameterMode = ParameterMode;
|
|
27
|
+
class PropsDeclaration {
|
|
28
|
+
}
|
|
29
|
+
exports.PropsDeclaration = PropsDeclaration;
|
|
30
|
+
class IndexedPropertyDeclaration extends PropsDeclaration {
|
|
31
|
+
}
|
|
32
|
+
exports.IndexedPropertyDeclaration = IndexedPropertyDeclaration;
|
|
33
|
+
class FunctionDeclaration extends PropsDeclaration {
|
|
34
|
+
constructor() {
|
|
35
|
+
super(...arguments);
|
|
36
|
+
this.args = [];
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
exports.FunctionDeclaration = FunctionDeclaration;
|
|
40
|
+
var ClassObjectKind;
|
|
41
|
+
(function (ClassObjectKind) {
|
|
42
|
+
ClassObjectKind[ClassObjectKind["interface"] = 0] = "interface";
|
|
43
|
+
ClassObjectKind[ClassObjectKind["dictionary"] = 1] = "dictionary";
|
|
44
|
+
ClassObjectKind[ClassObjectKind["mixin"] = 2] = "mixin";
|
|
45
|
+
})(ClassObjectKind || (exports.ClassObjectKind = ClassObjectKind = {}));
|
|
46
|
+
class ClassObject {
|
|
47
|
+
constructor() {
|
|
48
|
+
this.props = [];
|
|
49
|
+
this.inheritedProps = [];
|
|
50
|
+
this.methods = [];
|
|
51
|
+
this.staticMethods = [];
|
|
52
|
+
this.kind = ClassObjectKind.interface;
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
exports.ClassObject = ClassObject;
|
|
56
|
+
ClassObject.globalClassMap = Object.create(null);
|
|
57
|
+
ClassObject.globalClassRelationMap = Object.create(null);
|
|
58
|
+
class FunctionObject {
|
|
59
|
+
}
|
|
60
|
+
exports.FunctionObject = FunctionObject;
|
|
61
|
+
class TypeAliasObject {
|
|
62
|
+
}
|
|
63
|
+
exports.TypeAliasObject = TypeAliasObject;
|