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,119 @@
|
|
|
1
|
+
const NODE_BYTES = 1600
|
|
2
|
+
|
|
3
|
+
export function computeMemory(input) {
|
|
4
|
+
const totalMB = Number(input && input.totalMB) > 0 ? Number(input.totalMB) : 512
|
|
5
|
+
const baselineMB = Number(input && input.baselineMB) > 0 ? Number(input.baselineMB) : 176
|
|
6
|
+
const heapBytes = Number(input && input.heapBytes)
|
|
7
|
+
const domNodes = Number(input && input.domNodes) || 0
|
|
8
|
+
const hasHeap = Number.isFinite(heapBytes) && heapBytes > 0
|
|
9
|
+
const heapMB = hasHeap ? heapBytes / 1048576 : Math.round((domNodes * NODE_BYTES) / 1048576 * 10) / 10
|
|
10
|
+
const usedMB = Math.min(totalMB, Math.round((baselineMB + heapMB) * 10) / 10)
|
|
11
|
+
const peakMB = Math.max(usedMB, Math.round(((input && input.peakMB) || 0) * 10) / 10)
|
|
12
|
+
const peakHeapMB = Math.max(heapMB, Math.round(((input && input.peakHeapMB) || 0) * 10) / 10)
|
|
13
|
+
return {
|
|
14
|
+
totalMB,
|
|
15
|
+
baselineMB,
|
|
16
|
+
heapMB: Math.round(heapMB * 10) / 10,
|
|
17
|
+
heapSource: hasHeap ? 'performance.memory' : 'estimate',
|
|
18
|
+
usedMB,
|
|
19
|
+
peakMB,
|
|
20
|
+
peakHeapMB,
|
|
21
|
+
ratio: usedMB / totalMB,
|
|
22
|
+
overBudget: usedMB >= totalMB
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
function readFrame() {
|
|
27
|
+
const frame = document.querySelector('#main iframe')
|
|
28
|
+
if (!frame || !frame.contentWindow) return null
|
|
29
|
+
const win = frame.contentWindow
|
|
30
|
+
const perf = win.performance
|
|
31
|
+
const memory = perf && perf.memory ? perf.memory : null
|
|
32
|
+
const doc = win.document
|
|
33
|
+
return {
|
|
34
|
+
heapBytes: memory ? memory.usedJSHeapSize : null,
|
|
35
|
+
domNodes: doc ? doc.getElementsByTagName('*').length : 0
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
export function installMemoryHud() {
|
|
40
|
+
const win = typeof window !== 'undefined' ? window : null
|
|
41
|
+
if (!win || win.__FALCON_MEMORY_HUD__) return
|
|
42
|
+
win.__FALCON_MEMORY_HUD__ = true
|
|
43
|
+
|
|
44
|
+
const profile = win.__FALCON_PROFILE__ || {}
|
|
45
|
+
const conf = profile.memory || {}
|
|
46
|
+
if (conf.show === false) return
|
|
47
|
+
|
|
48
|
+
const doc = win.document
|
|
49
|
+
const box = doc.createElement('div')
|
|
50
|
+
box.setAttribute('data-falcon-memory-hud', '')
|
|
51
|
+
box.style.cssText = [
|
|
52
|
+
'position:fixed',
|
|
53
|
+
'left:12px',
|
|
54
|
+
'bottom:12px',
|
|
55
|
+
'z-index:2147483647',
|
|
56
|
+
'padding:8px 10px',
|
|
57
|
+
'border-radius:6px',
|
|
58
|
+
'background:rgba(12,12,16,.86)',
|
|
59
|
+
'border:1px solid #26262b',
|
|
60
|
+
'color:#c8c8d2',
|
|
61
|
+
'font:11px/1.5 ui-monospace,SFMono-Regular,Menlo,monospace',
|
|
62
|
+
'min-width:208px',
|
|
63
|
+
'pointer-events:none',
|
|
64
|
+
'user-select:none'
|
|
65
|
+
].join(';')
|
|
66
|
+
|
|
67
|
+
const head = doc.createElement('div')
|
|
68
|
+
head.style.cssText = 'display:flex;justify-content:space-between;gap:12px;color:#8e8e99'
|
|
69
|
+
const title = doc.createElement('span')
|
|
70
|
+
title.textContent = 'MEM ' + (profile.name || 'device')
|
|
71
|
+
const value = doc.createElement('span')
|
|
72
|
+
value.textContent = '--'
|
|
73
|
+
head.appendChild(title)
|
|
74
|
+
head.appendChild(value)
|
|
75
|
+
|
|
76
|
+
const track = doc.createElement('div')
|
|
77
|
+
track.style.cssText = 'margin:6px 0 4px;height:5px;border-radius:3px;background:#1e1e24;overflow:hidden'
|
|
78
|
+
const bar = doc.createElement('div')
|
|
79
|
+
bar.style.cssText = 'height:100%;width:0;background:#4ade80;transition:width .25s linear'
|
|
80
|
+
track.appendChild(bar)
|
|
81
|
+
|
|
82
|
+
const detail = doc.createElement('div')
|
|
83
|
+
detail.style.cssText = 'color:#6b6b78'
|
|
84
|
+
detail.textContent = 'heap -- · dom --'
|
|
85
|
+
|
|
86
|
+
box.appendChild(head)
|
|
87
|
+
box.appendChild(track)
|
|
88
|
+
box.appendChild(detail)
|
|
89
|
+
doc.body.appendChild(box)
|
|
90
|
+
|
|
91
|
+
let peakMB = 0
|
|
92
|
+
let peakHeapMB = 0
|
|
93
|
+
|
|
94
|
+
function paint() {
|
|
95
|
+
const frame = readFrame()
|
|
96
|
+
const state = computeMemory({
|
|
97
|
+
totalMB: conf.totalMB,
|
|
98
|
+
baselineMB: conf.baselineMB,
|
|
99
|
+
heapBytes: frame ? frame.heapBytes : null,
|
|
100
|
+
domNodes: frame ? frame.domNodes : 0,
|
|
101
|
+
peakMB: peakMB,
|
|
102
|
+
peakHeapMB: peakHeapMB
|
|
103
|
+
})
|
|
104
|
+
peakMB = state.peakMB
|
|
105
|
+
peakHeapMB = state.peakHeapMB
|
|
106
|
+
value.textContent = state.usedMB.toFixed(1) + ' / ' + state.totalMB + ' MB'
|
|
107
|
+
bar.style.width = Math.min(100, Math.round(state.ratio * 100)) + '%'
|
|
108
|
+
bar.style.background = state.ratio >= 0.9 ? '#f87171' : state.ratio >= 0.7 ? '#fbbf24' : '#4ade80'
|
|
109
|
+
detail.textContent =
|
|
110
|
+
'heap ' + state.heapMB.toFixed(1) + 'MB' +
|
|
111
|
+
(state.heapSource === 'estimate' ? '~' : '') +
|
|
112
|
+
' · 峰 ' + state.peakHeapMB.toFixed(1) + 'MB' +
|
|
113
|
+
' · dom ' + ((frame && frame.domNodes) || 0)
|
|
114
|
+
win.__FALCON_MEMORY__ = state
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
paint()
|
|
118
|
+
win.setInterval(paint, 1000)
|
|
119
|
+
}
|
|
@@ -0,0 +1,235 @@
|
|
|
1
|
+
|
|
2
|
+
const TAG_MAP = {
|
|
3
|
+
text: 'span',
|
|
4
|
+
image: 'img',
|
|
5
|
+
scroller: 'div',
|
|
6
|
+
slider: 'div',
|
|
7
|
+
seekbar: 'div',
|
|
8
|
+
cell: 'div',
|
|
9
|
+
waterfall: 'div',
|
|
10
|
+
'recycle-list': 'div'
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
const LENGTH_PROPS = new Set([
|
|
14
|
+
'width', 'height', 'minWidth', 'minHeight', 'maxWidth', 'maxHeight',
|
|
15
|
+
'top', 'right', 'bottom', 'left', 'margin', 'marginTop', 'marginRight',
|
|
16
|
+
'marginBottom', 'marginLeft', 'padding', 'paddingTop', 'paddingRight',
|
|
17
|
+
'paddingBottom', 'paddingLeft', 'borderWidth', 'borderRadius',
|
|
18
|
+
'borderTopLeftRadius', 'borderTopRightRadius', 'borderBottomLeftRadius',
|
|
19
|
+
'borderBottomRightRadius', 'fontSize', 'letterSpacing', 'wordSpacing',
|
|
20
|
+
'textIndent', 'lineHeight'
|
|
21
|
+
])
|
|
22
|
+
|
|
23
|
+
const UNITLESS_PROPS = new Set([
|
|
24
|
+
'opacity', 'zIndex', 'flex', 'flexGrow', 'flexShrink', 'order',
|
|
25
|
+
'fontWeight', 'animationIterationCount', 'aspectRatio'
|
|
26
|
+
])
|
|
27
|
+
|
|
28
|
+
const BASE_CSS = `
|
|
29
|
+
html, body { margin: 0; padding: 0; width: 100%; height: 100%; overflow: hidden; }
|
|
30
|
+
body { position: relative; }
|
|
31
|
+
[data-falcon-tag] {
|
|
32
|
+
box-sizing: border-box;
|
|
33
|
+
position: relative;
|
|
34
|
+
margin: 0;
|
|
35
|
+
padding: 0;
|
|
36
|
+
border: 0 solid black;
|
|
37
|
+
min-width: 0;
|
|
38
|
+
background-repeat: no-repeat;
|
|
39
|
+
background-position: 50% 50%;
|
|
40
|
+
background-size: 100% 100%;
|
|
41
|
+
}
|
|
42
|
+
[data-falcon-tag="div"], [data-falcon-tag="scroller"], [data-falcon-tag="slider"], [data-falcon-tag="cell"] {
|
|
43
|
+
display: flex;
|
|
44
|
+
flex-direction: column;
|
|
45
|
+
flex-shrink: 0;
|
|
46
|
+
}
|
|
47
|
+
[data-falcon-tag="text"] {
|
|
48
|
+
display: block;
|
|
49
|
+
white-space: pre-wrap;
|
|
50
|
+
word-wrap: break-word;
|
|
51
|
+
overflow: hidden;
|
|
52
|
+
flex-shrink: 0;
|
|
53
|
+
}
|
|
54
|
+
.weex-slider-wrapper { display: block !important; position: relative !important; overflow-x: hidden !important; overflow-y: auto !important; height: 100% !important; scrollbar-width: none; }
|
|
55
|
+
.weex-slider-wrapper::-webkit-scrollbar { display: none; }
|
|
56
|
+
.weex-slider-inner { display: block !important; position: static !important; transform: none !important; width: 100% !important; height: auto !important; }
|
|
57
|
+
.weex-slider-cell { display: block !important; position: static !important; float: none !important; width: 100% !important; height: 266px !important; transform: none !important; scroll-snap-align: start; }
|
|
58
|
+
.weex-scroller-wrapper { overflow: auto !important; scrollbar-width: none; -webkit-overflow-scrolling: touch; }
|
|
59
|
+
.weex-scroller-wrapper::-webkit-scrollbar { display: none; }
|
|
60
|
+
.weex-scroller-horizontal { overflow-x: auto !important; overflow-y: hidden !important; }
|
|
61
|
+
.weex-scroller-horizontal > * { flex-shrink: 0; }
|
|
62
|
+
|
|
63
|
+
[data-falcon-tag="scroller"] {
|
|
64
|
+
display: block;
|
|
65
|
+
overflow: auto;
|
|
66
|
+
-webkit-overflow-scrolling: touch;
|
|
67
|
+
scrollbar-width: none;
|
|
68
|
+
}
|
|
69
|
+
[data-falcon-tag="scroller"]::-webkit-scrollbar,
|
|
70
|
+
[data-falcon-tag="slider"]::-webkit-scrollbar { display: none; }
|
|
71
|
+
[data-falcon-tag="scroller"][scroll-direction="horizontal"] { overflow-x: auto; overflow-y: hidden; }
|
|
72
|
+
[data-falcon-tag="scroller"][scroll-direction="horizontal"] > * { flex-shrink: 0; }
|
|
73
|
+
[data-falcon-tag="slider"] {
|
|
74
|
+
display: flex;
|
|
75
|
+
overflow: auto;
|
|
76
|
+
scroll-snap-type: x mandatory;
|
|
77
|
+
scrollbar-width: none;
|
|
78
|
+
}
|
|
79
|
+
[data-falcon-tag="slider"][vertical="true"] {
|
|
80
|
+
flex-direction: column;
|
|
81
|
+
scroll-snap-type: y mandatory;
|
|
82
|
+
}
|
|
83
|
+
[data-falcon-tag="slider"] > * {
|
|
84
|
+
flex: 0 0 100%;
|
|
85
|
+
min-width: 100%;
|
|
86
|
+
scroll-snap-align: start;
|
|
87
|
+
}
|
|
88
|
+
[data-falcon-tag="slider"][vertical="true"] > * { min-height: 100%; }
|
|
89
|
+
|
|
90
|
+
[data-falcon-tag="image"] {
|
|
91
|
+
display: block;
|
|
92
|
+
flex-shrink: 0;
|
|
93
|
+
object-fit: fill;
|
|
94
|
+
}
|
|
95
|
+
`
|
|
96
|
+
|
|
97
|
+
function toKebab(name) {
|
|
98
|
+
return String(name).replace(/([A-Z])/g, '-$1').toLowerCase()
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
function toCssValue(prop, value) {
|
|
102
|
+
if (value === null || value === undefined) return ''
|
|
103
|
+
if (typeof value === 'number') {
|
|
104
|
+
if (UNITLESS_PROPS.has(prop)) return String(value)
|
|
105
|
+
return value === 0 ? '0' : value + 'px'
|
|
106
|
+
}
|
|
107
|
+
const text = String(value).trim()
|
|
108
|
+
if (!text) return ''
|
|
109
|
+
if (/^-?\d+(\.\d+)?$/.test(text)) {
|
|
110
|
+
if (UNITLESS_PROPS.has(prop)) return text
|
|
111
|
+
return text === '0' ? '0' : text + 'px'
|
|
112
|
+
}
|
|
113
|
+
if (prop === 'backgroundImage') {
|
|
114
|
+
return text.replace(/url\(\s*['"]?images\//g, 'url("/images/')
|
|
115
|
+
}
|
|
116
|
+
return text
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
function buildCss(styleMap, scopeId) {
|
|
120
|
+
const rules = new Map()
|
|
121
|
+
for (const className of Object.keys(styleMap)) {
|
|
122
|
+
const decls = styleMap[className]
|
|
123
|
+
if (!decls || typeof decls !== 'object') continue
|
|
124
|
+
for (const rawKey of Object.keys(decls)) {
|
|
125
|
+
const rawValue = decls[rawKey]
|
|
126
|
+
if (rawValue === null || rawValue === undefined || rawValue === '') continue
|
|
127
|
+
let prop = rawKey
|
|
128
|
+
let pseudo = ''
|
|
129
|
+
const colon = rawKey.indexOf(':')
|
|
130
|
+
if (colon > 0) {
|
|
131
|
+
prop = rawKey.slice(0, colon)
|
|
132
|
+
pseudo = rawKey.slice(colon)
|
|
133
|
+
}
|
|
134
|
+
const value = toCssValue(prop, rawValue)
|
|
135
|
+
if (!value) continue
|
|
136
|
+
const selector = (scopeId ? '[' + scopeId + ']' : '') + '.' + className + pseudo
|
|
137
|
+
if (!rules.has(selector)) rules.set(selector, [])
|
|
138
|
+
rules.get(selector).push(toKebab(prop) + ': ' + value)
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
const parts = []
|
|
142
|
+
rules.forEach(function (declList, selector) {
|
|
143
|
+
parts.push(selector + ' { ' + declList.join('; ') + '; }')
|
|
144
|
+
})
|
|
145
|
+
return parts.join('\n')
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
function patchCreateElement(doc) {
|
|
149
|
+
if (doc.__falconTagPatched) return
|
|
150
|
+
doc.__falconTagPatched = true
|
|
151
|
+
const original = doc.createElement.bind(doc)
|
|
152
|
+
doc.createElement = function (tagName) {
|
|
153
|
+
const raw = String(tagName).toLowerCase()
|
|
154
|
+
const mapped = TAG_MAP[raw]
|
|
155
|
+
const el = arguments.length > 1 ? original(mapped || raw, arguments[1]) : original(mapped || raw)
|
|
156
|
+
try {
|
|
157
|
+
el.setAttribute('data-falcon-tag', raw)
|
|
158
|
+
} catch (e) {}
|
|
159
|
+
return el
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
function makeWritable(instance, name) {
|
|
164
|
+
let owner = instance
|
|
165
|
+
while (owner) {
|
|
166
|
+
const desc = Object.getOwnPropertyDescriptor(owner, name)
|
|
167
|
+
if (desc) {
|
|
168
|
+
if (!desc.configurable) return false
|
|
169
|
+
const box = { has: false, value: undefined }
|
|
170
|
+
try {
|
|
171
|
+
Object.defineProperty(owner, name, {
|
|
172
|
+
configurable: true,
|
|
173
|
+
get: function () {
|
|
174
|
+
if (box.has) return box.value
|
|
175
|
+
return desc.get ? desc.get.call(this) : desc.value
|
|
176
|
+
},
|
|
177
|
+
set: function (value) {
|
|
178
|
+
box.has = true
|
|
179
|
+
box.value = value
|
|
180
|
+
}
|
|
181
|
+
})
|
|
182
|
+
return true
|
|
183
|
+
} catch (e) {
|
|
184
|
+
return false
|
|
185
|
+
}
|
|
186
|
+
}
|
|
187
|
+
owner = Object.getPrototypeOf(owner)
|
|
188
|
+
}
|
|
189
|
+
return false
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
export function installStyleBridge(Vue) {
|
|
193
|
+
const win = typeof window !== 'undefined' ? window : null
|
|
194
|
+
if (!win || win.__FALCON_STYLE_BRIDGE__) return
|
|
195
|
+
win.__FALCON_STYLE_BRIDGE__ = true
|
|
196
|
+
|
|
197
|
+
const doc = win.document
|
|
198
|
+
patchCreateElement(doc)
|
|
199
|
+
|
|
200
|
+
const navFields = [
|
|
201
|
+
"userAgent", "appVersion", "platform", "vendor", "vendorSub", "language",
|
|
202
|
+
"languages", "cookieEnabled", "hardwareConcurrency", "deviceMemory", "product"
|
|
203
|
+
]
|
|
204
|
+
for (const name of navFields) makeWritable(win.navigator, name)
|
|
205
|
+
|
|
206
|
+
const originalNamespace = Vue.config.getTagNamespace
|
|
207
|
+
Vue.config.getTagNamespace = function (tag) {
|
|
208
|
+
if (tag === "text" || tag === "image") return undefined
|
|
209
|
+
return typeof originalNamespace === "function" ? originalNamespace(tag) : undefined
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
const baseSheet = doc.createElement('style')
|
|
213
|
+
baseSheet.setAttribute('data-falcon-style-base', '')
|
|
214
|
+
baseSheet.textContent = BASE_CSS
|
|
215
|
+
doc.head.appendChild(baseSheet)
|
|
216
|
+
|
|
217
|
+
const userSheet = doc.createElement('style')
|
|
218
|
+
userSheet.setAttribute('data-falcon-style-user', '')
|
|
219
|
+
doc.head.appendChild(userSheet)
|
|
220
|
+
|
|
221
|
+
const injected = new Set()
|
|
222
|
+
|
|
223
|
+
Vue.mixin({
|
|
224
|
+
beforeCreate() {
|
|
225
|
+
const options = this.$options
|
|
226
|
+
const styleMap = options && options.style
|
|
227
|
+
if (!styleMap || typeof styleMap !== 'object') return
|
|
228
|
+
const key = (options._scopeId || '') + '|' + Object.keys(styleMap).join(',')
|
|
229
|
+
if (injected.has(key)) return
|
|
230
|
+
injected.add(key)
|
|
231
|
+
const css = buildCss(styleMap, options._scopeId || '')
|
|
232
|
+
if (css) userSheet.textContent += '\n' + css
|
|
233
|
+
}
|
|
234
|
+
})
|
|
235
|
+
}
|