catchword 0.0.0-stage → 1.0.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/LICENSE +21 -0
- package/README.md +314 -2
- package/bin/catchword.js +8 -0
- package/bin/falcon.js +5 -0
- package/dist/cli/adb.d.ts +6 -0
- package/dist/cli/adb.js +52 -0
- package/dist/cli/audit.d.ts +4 -0
- package/dist/cli/audit.js +91 -0
- package/dist/cli/build.d.ts +13 -0
- package/dist/cli/build.js +139 -0
- package/dist/cli/clean.d.ts +1 -0
- package/dist/cli/clean.js +15 -0
- package/dist/cli/create.d.ts +4 -0
- package/dist/cli/create.js +60 -0
- package/dist/cli/dev.d.ts +10 -0
- package/dist/cli/dev.js +23 -0
- package/dist/cli/index.d.ts +3 -0
- package/dist/cli/index.js +243 -0
- package/dist/cli/native.d.ts +18 -0
- package/dist/cli/native.js +232 -0
- package/dist/cli/simulator.d.ts +8 -0
- package/dist/cli/simulator.js +77 -0
- package/dist/cli/upload.d.ts +9 -0
- package/dist/cli/upload.js +135 -0
- package/dist/cli/util.d.ts +8 -0
- package/dist/cli/util.js +43 -0
- package/dist/config.d.ts +17 -0
- package/dist/config.js +90 -0
- package/dist/index.d.ts +16 -0
- package/dist/index.js +51 -0
- package/dist/native/api.d.ts +46 -0
- package/dist/native/api.js +185 -0
- package/dist/native/build.d.ts +47 -0
- package/dist/native/build.js +407 -0
- package/dist/native/elf.d.ts +15 -0
- package/dist/native/elf.js +200 -0
- package/dist/native/types.d.ts +9 -0
- package/dist/native/types.js +91 -0
- package/dist/native/wsl.d.ts +7 -0
- package/dist/native/wsl.js +29 -0
- package/dist/plugin/app-entry.d.ts +6 -0
- package/dist/plugin/app-entry.js +115 -0
- package/dist/plugin/assets.d.ts +4 -0
- package/dist/plugin/assets.js +84 -0
- package/dist/plugin/config.d.ts +14 -0
- package/dist/plugin/config.js +80 -0
- package/dist/plugin/context.d.ts +58 -0
- package/dist/plugin/context.js +255 -0
- package/dist/plugin/fallback.d.ts +4 -0
- package/dist/plugin/fallback.js +81 -0
- package/dist/plugin/image-service.d.ts +17 -0
- package/dist/plugin/image-service.js +138 -0
- package/dist/plugin/jsapi.d.ts +6 -0
- package/dist/plugin/jsapi.js +82 -0
- package/dist/plugin/output.d.ts +4 -0
- package/dist/plugin/output.js +75 -0
- package/dist/plugin/preview.d.ts +34 -0
- package/dist/plugin/preview.js +459 -0
- package/dist/plugin/sanitize.d.ts +5 -0
- package/dist/plugin/sanitize.js +48 -0
- package/dist/plugin/security.d.ts +4 -0
- package/dist/plugin/security.js +18 -0
- package/dist/plugin/sfc.d.ts +6 -0
- package/dist/plugin/sfc.js +181 -0
- package/dist/plugin/shim.d.ts +4 -0
- package/dist/plugin/shim.js +68 -0
- package/dist/plugin/state.d.ts +31 -0
- package/dist/plugin/state.js +61 -0
- package/dist/plugin/string-table.d.ts +7 -0
- package/dist/plugin/string-table.js +324 -0
- package/dist/plugin/style.d.ts +15 -0
- package/dist/plugin/style.js +114 -0
- package/dist/plugin/template.d.ts +7 -0
- package/dist/plugin/template.js +39 -0
- package/dist/steps/manifest.d.ts +9 -0
- package/dist/steps/manifest.js +60 -0
- package/dist/steps/pack.d.ts +3 -0
- package/dist/steps/pack.js +46 -0
- package/dist/steps/qjsc.d.ts +9 -0
- package/dist/steps/qjsc.js +186 -0
- package/dist/steps/report.d.ts +2 -0
- package/dist/steps/report.js +50 -0
- package/dist/steps/security.d.ts +17 -0
- package/dist/steps/security.js +310 -0
- package/dist/types.d.ts +158 -0
- package/dist/types.js +1 -0
- package/dist/util/class-tokenize.d.ts +2 -0
- package/dist/util/class-tokenize.js +56 -0
- package/dist/util/component-name.d.ts +6 -0
- package/dist/util/component-name.js +120 -0
- package/dist/util/fs.d.ts +14 -0
- package/dist/util/fs.js +70 -0
- package/dist/util/imports.d.ts +2 -0
- package/dist/util/imports.js +173 -0
- package/dist/util/log.d.ts +8 -0
- package/dist/util/log.js +24 -0
- package/package.json +61 -4
- package/template/README.md +38 -0
- package/template/catchword.config.ts +18 -0
- package/template/native/CMakeLists.txt +33 -0
- package/template/native/README.md +34 -0
- package/template/native/api.override.json +7 -0
- package/template/native/include/jsapi_demo.h +10 -0
- package/template/native/lib/README.md +10 -0
- package/template/native/sdk/README.md +6 -0
- package/template/native/src/bridge.cpp +9 -0
- package/template/native/src/jsapi_demo.cpp +11 -0
- package/template/package.json +38 -0
- package/template/src/app.js +45 -0
- package/template/src/app.json +11 -0
- package/template/src/base-page.js +150 -0
- package/template/src/components/HelloWorld.vue +20 -0
- package/template/src/mocks/$jsapi.test.js +5 -0
- package/template/src/mocks/test-module.js +5 -0
- package/template/src/pages/index/index.vue +41 -0
- package/template/src/pages/page/page.vue +63 -0
- package/template/src/shims.d.ts +21 -0
- package/template/src/styles/base.less +23 -0
- package/template/src/styles/mixin.less +32 -0
- package/template/src/styles/var.less +15 -0
- package/template/tsconfig.json +14 -0
- package/vendor/README.md +16 -0
- package/vendor/falcon-styler/.jscsrc +31 -0
- package/vendor/falcon-styler/LICENSE +21 -0
- package/vendor/falcon-styler/README.md +124 -0
- package/vendor/falcon-styler/index.js +273 -0
- package/vendor/falcon-styler/lib/shorthand-parser.js +78 -0
- package/vendor/falcon-styler/lib/util.js +30 -0
- package/vendor/falcon-styler/lib/validator.js +846 -0
- package/vendor/falcon-styler/package.json +32 -0
- package/vendor/licenses/falcon-styler.LICENSE +21 -0
- package/vendor/licenses/weex-template-compiler.README.md +3 -0
- package/vendor/package.json +5 -0
- package/vendor/qjsc/SHA256SUMS +11 -0
- package/vendor/qjsc/bin/darwin/arm64/qjsc20200705 +0 -0
- package/vendor/qjsc/bin/darwin/x64/qjsc20200412 +0 -0
- package/vendor/qjsc/bin/darwin/x64/qjsc20200705 +0 -0
- package/vendor/qjsc/bin/darwin/x64/qjsc20200906 +0 -0
- package/vendor/qjsc/bin/darwin/x64/qjscbn20200412 +0 -0
- package/vendor/qjsc/bin/darwin/x64/qjscbn20200705 +0 -0
- package/vendor/qjsc/bin/darwin/x64/qjscbn20200906 +0 -0
- package/vendor/qjsc/bin/linux/qjsc20200705 +0 -0
- package/vendor/qjsc/bin/win32/libgcc_s_dw2-1.dll +0 -0
- package/vendor/qjsc/bin/win32/pthreadGC-3.dll +0 -0
- package/vendor/qjsc/bin/win32/qjsc20200705.exe +0 -0
- package/vendor/web/falcon-js-web.js +863 -0
- package/vendor/web/falcon-jsapi-web.js +479 -0
- package/vendor/web/falcon-vue-render.js +11323 -0
- package/vendor/web/falcon-web-boot.js +4 -0
- package/vendor/web/falcon-web-hud.js +119 -0
- package/vendor/web/falcon-web-style.js +235 -0
- package/vendor/web/vue.runtime.common.dev.js +8467 -0
- package/vendor/web/vue.runtime.common.js +5 -0
- package/vendor/weex-template-compiler/README.md +3 -0
- package/vendor/weex-template-compiler/build.js +4824 -0
- package/vendor/weex-template-compiler/index.js +17 -0
- package/vendor/weex-template-compiler/package.json +25 -0
|
@@ -0,0 +1,479 @@
|
|
|
1
|
+
(function (global) {
|
|
2
|
+
'use strict'
|
|
3
|
+
|
|
4
|
+
var CALLS = []
|
|
5
|
+
global.__FALCON_JSAPI_CALLS__ = CALLS
|
|
6
|
+
|
|
7
|
+
function record(module, method, args) {
|
|
8
|
+
if (CALLS.length >= 500) CALLS.shift()
|
|
9
|
+
var entry = { module: module, method: method, time: Date.now(), args: null }
|
|
10
|
+
try {
|
|
11
|
+
entry.args = JSON.parse(JSON.stringify(Array.prototype.slice.call(args)))
|
|
12
|
+
} catch (e) {
|
|
13
|
+
entry.args = '[unserializable]'
|
|
14
|
+
}
|
|
15
|
+
CALLS.push(entry)
|
|
16
|
+
return entry
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
var warned = {}
|
|
20
|
+
function warnOnce(key, message) {
|
|
21
|
+
if (warned[key]) return
|
|
22
|
+
warned[key] = true
|
|
23
|
+
console.warn(message)
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
function notImplemented(module, method, hint) {
|
|
27
|
+
return function () {
|
|
28
|
+
record(module, method, arguments)
|
|
29
|
+
var message =
|
|
30
|
+
'[falcon-preview] ' + module + '.' + method + ' 在浏览器预览中不可用' +
|
|
31
|
+
(hint ? ':' + hint : '')
|
|
32
|
+
console.error(message)
|
|
33
|
+
throw new Error(message)
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
var DB_PREFIX = 'falcon.dbase:'
|
|
38
|
+
|
|
39
|
+
var Dbase = {
|
|
40
|
+
available: true,
|
|
41
|
+
read: function (key) {
|
|
42
|
+
record('Dbase', 'read', arguments)
|
|
43
|
+
if (key === undefined || key === null) return null
|
|
44
|
+
try {
|
|
45
|
+
var raw = global.localStorage.getItem(DB_PREFIX + key)
|
|
46
|
+
if (raw === null) return null
|
|
47
|
+
return JSON.parse(raw)
|
|
48
|
+
} catch (e) {
|
|
49
|
+
return null
|
|
50
|
+
}
|
|
51
|
+
},
|
|
52
|
+
write: function (key, value) {
|
|
53
|
+
record('Dbase', 'write', arguments)
|
|
54
|
+
if (key === undefined || key === null) return false
|
|
55
|
+
try {
|
|
56
|
+
global.localStorage.setItem(DB_PREFIX + key, JSON.stringify(value))
|
|
57
|
+
return true
|
|
58
|
+
} catch (e) {
|
|
59
|
+
console.error('[falcon-preview] Dbase.write 失败:' + (e && e.message))
|
|
60
|
+
return false
|
|
61
|
+
}
|
|
62
|
+
},
|
|
63
|
+
remove: function (key) {
|
|
64
|
+
record('Dbase', 'remove', arguments)
|
|
65
|
+
try {
|
|
66
|
+
global.localStorage.removeItem(DB_PREFIX + key)
|
|
67
|
+
return true
|
|
68
|
+
} catch (e) {
|
|
69
|
+
return false
|
|
70
|
+
}
|
|
71
|
+
},
|
|
72
|
+
exists: function (key) {
|
|
73
|
+
record('Dbase', 'exists', arguments)
|
|
74
|
+
try {
|
|
75
|
+
return global.localStorage.getItem(DB_PREFIX + key) !== null
|
|
76
|
+
} catch (e) {
|
|
77
|
+
return false
|
|
78
|
+
}
|
|
79
|
+
},
|
|
80
|
+
keys: function () {
|
|
81
|
+
record('Dbase', 'keys', arguments)
|
|
82
|
+
var out = []
|
|
83
|
+
try {
|
|
84
|
+
for (var i = 0; i < global.localStorage.length; i++) {
|
|
85
|
+
var name = global.localStorage.key(i)
|
|
86
|
+
if (name && name.indexOf(DB_PREFIX) === 0) out.push(name.slice(DB_PREFIX.length))
|
|
87
|
+
}
|
|
88
|
+
} catch (e) {}
|
|
89
|
+
return out
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
function headersToObject(headers) {
|
|
94
|
+
var out = {}
|
|
95
|
+
try {
|
|
96
|
+
headers.forEach(function (value, name) {
|
|
97
|
+
out[name] = value
|
|
98
|
+
})
|
|
99
|
+
} catch (e) {}
|
|
100
|
+
return out
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
function throughProxy(url, headers) {
|
|
104
|
+
var base = global.__FALCON_FETCH_PROXY__
|
|
105
|
+
if (!base) return url
|
|
106
|
+
var text = String(url || '')
|
|
107
|
+
if (text.indexOf('http') !== 0) return url
|
|
108
|
+
if (text.indexOf('http://127.0.0.1') === 0 || text.indexOf('http://localhost') === 0) return url
|
|
109
|
+
if (global.location && text.indexOf(global.location.origin + '/') === 0) return url
|
|
110
|
+
var out = base + '?url=' + encodeURIComponent(text)
|
|
111
|
+
try {
|
|
112
|
+
if (headers && Object.keys(headers).length) {
|
|
113
|
+
out += '&h=' + encodeURIComponent(JSON.stringify(headers))
|
|
114
|
+
}
|
|
115
|
+
} catch (e) {}
|
|
116
|
+
return out
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
var servers = {}
|
|
120
|
+
var pendingById = {}
|
|
121
|
+
var requestSeq = 0
|
|
122
|
+
|
|
123
|
+
function parseLocalUrl(url) {
|
|
124
|
+
var text = String(url || '')
|
|
125
|
+
if (text.indexOf('http') !== 0) return null
|
|
126
|
+
var parsed = null
|
|
127
|
+
try {
|
|
128
|
+
parsed = new global.URL(text)
|
|
129
|
+
} catch (e) {
|
|
130
|
+
return null
|
|
131
|
+
}
|
|
132
|
+
if (parsed.hostname !== '127.0.0.1' && parsed.hostname !== 'localhost') return null
|
|
133
|
+
var query = {}
|
|
134
|
+
parsed.searchParams.forEach(function (value, key) {
|
|
135
|
+
query[key] = value
|
|
136
|
+
})
|
|
137
|
+
return {
|
|
138
|
+
port: Number(parsed.port),
|
|
139
|
+
path: parsed.pathname || '/',
|
|
140
|
+
query: query
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
function dispatchLocal(local, options) {
|
|
145
|
+
var server = servers[local.port]
|
|
146
|
+
if (!server || !server.running || typeof server.callback !== 'function') return null
|
|
147
|
+
var opts = options || {}
|
|
148
|
+
var id = 'req_' + ++requestSeq
|
|
149
|
+
var method = String(opts.method || 'GET').toUpperCase()
|
|
150
|
+
var headers = opts.headers || {}
|
|
151
|
+
var body = opts.body === undefined || opts.body === null ? '' : String(opts.body)
|
|
152
|
+
var event = {
|
|
153
|
+
type: 'request',
|
|
154
|
+
id: id,
|
|
155
|
+
method: method,
|
|
156
|
+
path: local.path,
|
|
157
|
+
query: local.query,
|
|
158
|
+
headers: headers,
|
|
159
|
+
body: body,
|
|
160
|
+
port: local.port
|
|
161
|
+
}
|
|
162
|
+
return new Promise(function (resolve) {
|
|
163
|
+
var timer = setTimeout(function () {
|
|
164
|
+
delete pendingById[id]
|
|
165
|
+
resolve({ ok: false, status: 504, statusText: 'Gateway Timeout', body: '', headers: {}, text: function () { return '' } })
|
|
166
|
+
}, Number(opts.localTimeout) > 0 ? Number(opts.localTimeout) : 8000)
|
|
167
|
+
pendingById[id] = {
|
|
168
|
+
resolve: function (payload) {
|
|
169
|
+
clearTimeout(timer)
|
|
170
|
+
var text = payload && payload.body !== undefined && payload.body !== null ? String(payload.body) : ''
|
|
171
|
+
resolve({
|
|
172
|
+
ok: (payload ? payload.status : 200) < 400,
|
|
173
|
+
status: payload ? payload.status : 200,
|
|
174
|
+
statusText: '',
|
|
175
|
+
headers: {},
|
|
176
|
+
body: text,
|
|
177
|
+
text: function () { return text }
|
|
178
|
+
})
|
|
179
|
+
}
|
|
180
|
+
}
|
|
181
|
+
try {
|
|
182
|
+
server.callback([event])
|
|
183
|
+
} catch (e) {
|
|
184
|
+
clearTimeout(timer)
|
|
185
|
+
delete pendingById[id]
|
|
186
|
+
resolve({ ok: false, status: 500, statusText: 'Internal Error', body: String((e && e.message) || e), headers: {}, text: function () { return String((e && e.message) || e) } })
|
|
187
|
+
}
|
|
188
|
+
})
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
var HttpServer = {
|
|
192
|
+
available: true,
|
|
193
|
+
start: function (options) {
|
|
194
|
+
record('HttpServer', 'start', arguments)
|
|
195
|
+
var opts = options || {}
|
|
196
|
+
var port = Number(opts.port) || 8090
|
|
197
|
+
var prev = servers[port]
|
|
198
|
+
servers[port] = {
|
|
199
|
+
running: true,
|
|
200
|
+
port: port,
|
|
201
|
+
bind: opts.bind || '127.0.0.1',
|
|
202
|
+
callback: prev ? prev.callback : null
|
|
203
|
+
}
|
|
204
|
+
return {
|
|
205
|
+
running: true,
|
|
206
|
+
port: port,
|
|
207
|
+
bind: servers[port].bind,
|
|
208
|
+
baseUrl: 'http://' + servers[port].bind + ':' + port
|
|
209
|
+
}
|
|
210
|
+
},
|
|
211
|
+
stop: function (options) {
|
|
212
|
+
record('HttpServer', 'stop', arguments)
|
|
213
|
+
var port = Number((options && options.port) || 0)
|
|
214
|
+
var keys = port ? [port] : Object.keys(servers)
|
|
215
|
+
keys.forEach(function (key) {
|
|
216
|
+
if (servers[key]) servers[key].running = false
|
|
217
|
+
})
|
|
218
|
+
return true
|
|
219
|
+
},
|
|
220
|
+
setEventCallback: function (callback) {
|
|
221
|
+
record('HttpServer', 'setEventCallback', arguments)
|
|
222
|
+
var ports = Object.keys(servers)
|
|
223
|
+
if (!ports.length) {
|
|
224
|
+
servers[8090] = { running: true, port: 8090, bind: '127.0.0.1', callback: callback }
|
|
225
|
+
return true
|
|
226
|
+
}
|
|
227
|
+
ports.forEach(function (key) {
|
|
228
|
+
servers[key].callback = callback
|
|
229
|
+
})
|
|
230
|
+
return true
|
|
231
|
+
},
|
|
232
|
+
getState: function () {
|
|
233
|
+
record('HttpServer', 'getState', arguments)
|
|
234
|
+
var ports = Object.keys(servers).filter(function (key) { return servers[key].running })
|
|
235
|
+
var port = ports.length ? Number(ports[0]) : 0
|
|
236
|
+
return { running: ports.length > 0, port: port, bind: '127.0.0.1' }
|
|
237
|
+
},
|
|
238
|
+
respond: function (id, status, body, mime) {
|
|
239
|
+
record('HttpServer', 'respond', arguments)
|
|
240
|
+
var entry = pendingById[id]
|
|
241
|
+
if (!entry) return false
|
|
242
|
+
delete pendingById[id]
|
|
243
|
+
entry.resolve({ status: Number(status) || 200, body: body, mime: mime })
|
|
244
|
+
return true
|
|
245
|
+
}
|
|
246
|
+
}
|
|
247
|
+
|
|
248
|
+
var Fetch = {
|
|
249
|
+
available: true,
|
|
250
|
+
fetch: function (url, options) {
|
|
251
|
+
record('Fetch', 'fetch', arguments)
|
|
252
|
+
var opts = options || {}
|
|
253
|
+
url = throughProxy(url, opts.headers)
|
|
254
|
+
var local = parseLocalUrl(url)
|
|
255
|
+
if (local) {
|
|
256
|
+
var handled = dispatchLocal(local, opts)
|
|
257
|
+
if (handled) return handled
|
|
258
|
+
}
|
|
259
|
+
var init = {
|
|
260
|
+
method: String(opts.method || 'GET').toUpperCase(),
|
|
261
|
+
headers: opts.headers || undefined,
|
|
262
|
+
body: opts.body === undefined ? undefined : opts.body
|
|
263
|
+
}
|
|
264
|
+
var controller = typeof global.AbortController === 'function' ? new global.AbortController() : null
|
|
265
|
+
if (controller) init.signal = controller.signal
|
|
266
|
+
var timer = null
|
|
267
|
+
if (opts.timeout && controller) {
|
|
268
|
+
timer = setTimeout(function () {
|
|
269
|
+
controller.abort()
|
|
270
|
+
}, Number(opts.timeout) * 1000)
|
|
271
|
+
}
|
|
272
|
+
return global
|
|
273
|
+
.fetch(url, init)
|
|
274
|
+
.then(function (res) {
|
|
275
|
+
return res.text().then(function (body) {
|
|
276
|
+
return {
|
|
277
|
+
ok: res.ok,
|
|
278
|
+
status: res.status,
|
|
279
|
+
statusText: res.statusText,
|
|
280
|
+
headers: headersToObject(res.headers),
|
|
281
|
+
body: body,
|
|
282
|
+
text: function () {
|
|
283
|
+
return body
|
|
284
|
+
}
|
|
285
|
+
}
|
|
286
|
+
})
|
|
287
|
+
})
|
|
288
|
+
.then(
|
|
289
|
+
function (res) {
|
|
290
|
+
if (timer) clearTimeout(timer)
|
|
291
|
+
return res
|
|
292
|
+
},
|
|
293
|
+
function (err) {
|
|
294
|
+
if (timer) clearTimeout(timer)
|
|
295
|
+
var message = '[falcon-preview] Fetch.fetch 失败:' + (err && err.message)
|
|
296
|
+
console.error(message)
|
|
297
|
+
throw err
|
|
298
|
+
}
|
|
299
|
+
)
|
|
300
|
+
},
|
|
301
|
+
downloadFile: function (url, targetPath, options) {
|
|
302
|
+
record('Fetch', 'downloadFile', arguments)
|
|
303
|
+
url = throughProxy(url, options && options.headers)
|
|
304
|
+
var events = []
|
|
305
|
+
var state = 'running'
|
|
306
|
+
var controller = typeof global.AbortController === 'function' ? new global.AbortController() : null
|
|
307
|
+
global
|
|
308
|
+
.fetch(url, controller ? { signal: controller.signal } : undefined)
|
|
309
|
+
.then(function (res) {
|
|
310
|
+
if (!res.ok) throw new Error('HTTP ' + res.status)
|
|
311
|
+
return res.text()
|
|
312
|
+
})
|
|
313
|
+
.then(function (body) {
|
|
314
|
+
if (state !== 'running') return
|
|
315
|
+
try {
|
|
316
|
+
global.localStorage.setItem('falcon.download:' + targetPath, body)
|
|
317
|
+
} catch (e) {}
|
|
318
|
+
state = 'done'
|
|
319
|
+
events.push({ type: 'done', path: targetPath, size: body.length })
|
|
320
|
+
})
|
|
321
|
+
.catch(function (err) {
|
|
322
|
+
if (state !== 'running') return
|
|
323
|
+
state = 'error'
|
|
324
|
+
events.push({ type: 'error', message: (err && err.message) || String(err) })
|
|
325
|
+
})
|
|
326
|
+
return {
|
|
327
|
+
poll: function () {
|
|
328
|
+
return events.splice(0, events.length)
|
|
329
|
+
},
|
|
330
|
+
abort: function () {
|
|
331
|
+
state = 'aborted'
|
|
332
|
+
if (controller) controller.abort()
|
|
333
|
+
},
|
|
334
|
+
destroy: function () {
|
|
335
|
+
state = 'aborted'
|
|
336
|
+
if (controller) controller.abort()
|
|
337
|
+
},
|
|
338
|
+
getState: function () {
|
|
339
|
+
return state
|
|
340
|
+
}
|
|
341
|
+
}
|
|
342
|
+
}
|
|
343
|
+
}
|
|
344
|
+
|
|
345
|
+
var replay = global.__FALCON_SHELL_REPLAY__ || {}
|
|
346
|
+
|
|
347
|
+
function matchReplay(command) {
|
|
348
|
+
if (!replay) return undefined
|
|
349
|
+
if (Object.prototype.hasOwnProperty.call(replay, command)) return replay[command]
|
|
350
|
+
var keys = Object.keys(replay)
|
|
351
|
+
for (var i = 0; i < keys.length; i++) {
|
|
352
|
+
if (command && command.indexOf(keys[i]) === 0) return replay[keys[i]]
|
|
353
|
+
}
|
|
354
|
+
return undefined
|
|
355
|
+
}
|
|
356
|
+
|
|
357
|
+
function shellRun(command) {
|
|
358
|
+
record('Shell', 'exec', arguments)
|
|
359
|
+
var hit = matchReplay(command)
|
|
360
|
+
if (hit !== undefined) return { code: 0, output: String(hit) }
|
|
361
|
+
throw new Error(
|
|
362
|
+
'[falcon-preview] Shell.exec 在浏览器预览中不可用。\n' +
|
|
363
|
+
' 命令: ' + command + '\n' +
|
|
364
|
+
' 需要回放时在 falcon.config.ts 里加:\n' +
|
|
365
|
+
' preview: { shell: { "' + String(command).slice(0, 40) + '": "期望输出" } }'
|
|
366
|
+
)
|
|
367
|
+
}
|
|
368
|
+
|
|
369
|
+
var Shell = {
|
|
370
|
+
available: true,
|
|
371
|
+
exec: shellRun,
|
|
372
|
+
execAsync: function (command) {
|
|
373
|
+
record('Shell', 'execAsync', arguments)
|
|
374
|
+
var hit = matchReplay(command)
|
|
375
|
+
if (hit !== undefined) return Promise.resolve({ code: 0, output: String(hit) })
|
|
376
|
+
try {
|
|
377
|
+
return Promise.resolve(shellRun(command))
|
|
378
|
+
} catch (e) {
|
|
379
|
+
return Promise.reject(e)
|
|
380
|
+
}
|
|
381
|
+
},
|
|
382
|
+
startLocalHttpServer: function () {
|
|
383
|
+
warnOnce('startLocalHttpServer', '[falcon-preview] Shell.startLocalHttpServer 在浏览器预览中不可用,返回 null')
|
|
384
|
+
record('Shell', 'startLocalHttpServer', arguments)
|
|
385
|
+
return null
|
|
386
|
+
},
|
|
387
|
+
getLocalHttpServerInfo: function () {
|
|
388
|
+
record('Shell', 'getLocalHttpServerInfo', arguments)
|
|
389
|
+
return null
|
|
390
|
+
},
|
|
391
|
+
getAbsoluteFileUrl: notImplemented('Shell', 'getAbsoluteFileUrl', '真机才有本地文件服务')
|
|
392
|
+
}
|
|
393
|
+
|
|
394
|
+
var UNIMPLEMENTED_HINTS = {
|
|
395
|
+
Files: '浏览器没有设备文件系统',
|
|
396
|
+
Spell: '输入法词典引擎在 native 侧',
|
|
397
|
+
HttpServer: '真机才有本地 HTTP 服务',
|
|
398
|
+
Camera: '设备相机由 native 驱动',
|
|
399
|
+
Video: '设备视频平面(KMS)由 native 驱动',
|
|
400
|
+
McFast: '设备多媒体加速在 native 侧'
|
|
401
|
+
}
|
|
402
|
+
|
|
403
|
+
var NATIVE_API = global.__FALCON_NATIVE_API__ || null
|
|
404
|
+
|
|
405
|
+
function nativeMethodsOf(name) {
|
|
406
|
+
if (!NATIVE_API || !NATIVE_API.modules) return null
|
|
407
|
+
for (var i = 0; i < NATIVE_API.modules.length; i++) {
|
|
408
|
+
var item = NATIVE_API.modules[i]
|
|
409
|
+
if (item && item.name === name) return item.methods || []
|
|
410
|
+
}
|
|
411
|
+
return null
|
|
412
|
+
}
|
|
413
|
+
|
|
414
|
+
function unimplementedModule(name) {
|
|
415
|
+
var hint = UNIMPLEMENTED_HINTS[name] || '该能力由 native 提供'
|
|
416
|
+
var methods = nativeMethodsOf(name)
|
|
417
|
+
var target = { available: false }
|
|
418
|
+
|
|
419
|
+
if (methods && methods.length) {
|
|
420
|
+
methods.forEach(function (method) {
|
|
421
|
+
target[method.name] = notImplemented(name, method.name, hint)
|
|
422
|
+
})
|
|
423
|
+
}
|
|
424
|
+
|
|
425
|
+
return new Proxy(target, {
|
|
426
|
+
get: function (obj, prop) {
|
|
427
|
+
if (prop in obj) return obj[prop]
|
|
428
|
+
if (typeof prop === 'symbol') return undefined
|
|
429
|
+
if (prop === 'then' || prop === 'toJSON' || prop === 'constructor') return undefined
|
|
430
|
+
if (prop === 'inspect' || prop === 'nodeType') return undefined
|
|
431
|
+
return notImplemented(name, String(prop), hint)
|
|
432
|
+
}
|
|
433
|
+
})
|
|
434
|
+
}
|
|
435
|
+
|
|
436
|
+
function fillFromContract(name, mod) {
|
|
437
|
+
var methods = nativeMethodsOf(name)
|
|
438
|
+
if (!methods) return mod
|
|
439
|
+
methods.forEach(function (method) {
|
|
440
|
+
if (typeof mod[method.name] !== 'function') {
|
|
441
|
+
mod[method.name] = notImplemented(name, method.name, '真机可用,浏览器预览未实现')
|
|
442
|
+
}
|
|
443
|
+
})
|
|
444
|
+
return mod
|
|
445
|
+
}
|
|
446
|
+
|
|
447
|
+
var jsapi = {
|
|
448
|
+
HttpServer: fillFromContract('HttpServer', HttpServer),
|
|
449
|
+
Fetch: fillFromContract('Fetch', Fetch),
|
|
450
|
+
Dbase: fillFromContract('Dbase', Dbase),
|
|
451
|
+
Datas: Dbase,
|
|
452
|
+
Shell: fillFromContract('Shell', Shell),
|
|
453
|
+
Files: unimplementedModule('Files'),
|
|
454
|
+
Spell: unimplementedModule('Spell'),
|
|
455
|
+
Camera: unimplementedModule('Camera'),
|
|
456
|
+
Video: unimplementedModule('Video'),
|
|
457
|
+
McFast: unimplementedModule('McFast')
|
|
458
|
+
}
|
|
459
|
+
|
|
460
|
+
global.__FALCON_JSAPI__ = jsapi
|
|
461
|
+
|
|
462
|
+
var reported = false
|
|
463
|
+
global.__FALCON_JSAPI_REPORT__ = function () {
|
|
464
|
+
if (reported) return
|
|
465
|
+
reported = true
|
|
466
|
+
var real = []
|
|
467
|
+
var stubs = []
|
|
468
|
+
Object.keys(jsapi).forEach(function (name) {
|
|
469
|
+
if (name === 'Datas') return
|
|
470
|
+
;(jsapi[name].available ? real : stubs).push(name)
|
|
471
|
+
})
|
|
472
|
+
console.log(
|
|
473
|
+
'%c[falcon-preview] JSAPI%c 已实现: ' + real.join(', ') +
|
|
474
|
+
' 占位(调用即抛): ' + (stubs.join(', ') || '无'),
|
|
475
|
+
'color:#8ab4f8',
|
|
476
|
+
'color:inherit'
|
|
477
|
+
)
|
|
478
|
+
}
|
|
479
|
+
})(typeof window !== 'undefined' ? window : globalThis)
|