@viewfly/platform-browser 0.0.1-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/LICENSE +21 -0
- package/README.md +4 -0
- package/bundles/create-app.d.ts +18 -0
- package/bundles/dom-renderer.d.ts +48 -0
- package/bundles/index.esm.js +274 -0
- package/bundles/index.js +276 -0
- package/bundles/public-api.d.ts +2 -0
- package/package.json +40 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2023 TanBo
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { Viewfly, RootNode } from '@viewfly/core';
|
|
2
|
+
/**
|
|
3
|
+
* 创建一个 Viewfly 实例
|
|
4
|
+
* @param host 应用根节点
|
|
5
|
+
* @param root 应用根节点
|
|
6
|
+
* @param autoUpdate 是否自动更新视图,默认为 true,当值为 false 时,Viewfly
|
|
7
|
+
* 只会首次渲染,直到手动调用 Renderer 类的 refresh() 方法,这在单元测试中非常有用,
|
|
8
|
+
* 我们无需等待 Viewfly 默认的异步调度,实现同步更新视图
|
|
9
|
+
* ```tsx
|
|
10
|
+
* const app = createApp(document.getElementById('app'), <App/>, false)
|
|
11
|
+
* const renderer = app.get(Renderer)
|
|
12
|
+
*
|
|
13
|
+
* // do something...
|
|
14
|
+
*
|
|
15
|
+
* renderer.refresh() // 手动更新视图
|
|
16
|
+
* ```
|
|
17
|
+
*/
|
|
18
|
+
export declare function createApp(host: HTMLElement, root: RootNode, autoUpdate?: boolean): Viewfly;
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import { NativeRenderer } from '@viewfly/core';
|
|
2
|
+
export declare class DomRenderer extends NativeRenderer<HTMLElement, Text> {
|
|
3
|
+
isSVG: RegExp;
|
|
4
|
+
xlinkNameSpace: string;
|
|
5
|
+
possibleXlinkNames: {
|
|
6
|
+
xlinkActuate: string;
|
|
7
|
+
xlinkactuate: string;
|
|
8
|
+
'xlink:actuate': string;
|
|
9
|
+
xlinkArcrole: string;
|
|
10
|
+
xlinkarcrole: string;
|
|
11
|
+
'xlink:arcrole': string;
|
|
12
|
+
xlinkHref: string;
|
|
13
|
+
xlinkhref: string;
|
|
14
|
+
'xlink:href': string;
|
|
15
|
+
xlinkRole: string;
|
|
16
|
+
xlinkrole: string;
|
|
17
|
+
'xlink:role': string;
|
|
18
|
+
xlinkShow: string;
|
|
19
|
+
xlinkshow: string;
|
|
20
|
+
'xlink:show': string;
|
|
21
|
+
xlinkTitle: string;
|
|
22
|
+
xlinktitle: string;
|
|
23
|
+
'xlink:title': string;
|
|
24
|
+
xlinkType: string;
|
|
25
|
+
xlinktype: string;
|
|
26
|
+
'xlink:type': string;
|
|
27
|
+
};
|
|
28
|
+
booleanProps: Record<string, string[]>;
|
|
29
|
+
valueProps: Record<string, string[]>;
|
|
30
|
+
createElement(name: string): HTMLElement;
|
|
31
|
+
createTextNode(textContent: string): Text;
|
|
32
|
+
appendChild(parent: HTMLElement, newChild: any): void;
|
|
33
|
+
prependChild(parent: HTMLElement, newChild: HTMLElement | Text): void;
|
|
34
|
+
insertAfter(newNode: HTMLElement | Text, ref: HTMLElement | Text): void;
|
|
35
|
+
remove(node: HTMLElement | Text): void;
|
|
36
|
+
setProperty(node: HTMLElement, key: string, value: any): void;
|
|
37
|
+
removeProperty(node: HTMLElement, key: string): void;
|
|
38
|
+
addClass(target: HTMLElement, name: string): void;
|
|
39
|
+
removeClass(target: HTMLElement, name: string): void;
|
|
40
|
+
setStyle(target: HTMLElement, key: string, value: any): void;
|
|
41
|
+
removeStyle(target: HTMLElement, key: string): void;
|
|
42
|
+
listen<T = any>(node: HTMLElement, type: string, callback: (ev: T) => any): void;
|
|
43
|
+
unListen(node: HTMLElement, type: string, callback: (ev: any) => any): void;
|
|
44
|
+
syncTextContent(target: Text, content: string): void;
|
|
45
|
+
private setXlinkAttribute;
|
|
46
|
+
private removeXlinkAttribute;
|
|
47
|
+
private insertBefore;
|
|
48
|
+
}
|
|
@@ -0,0 +1,274 @@
|
|
|
1
|
+
import { NativeRenderer, Viewfly } from '@viewfly/core';
|
|
2
|
+
import { Injectable } from '@tanbo/di';
|
|
3
|
+
|
|
4
|
+
/******************************************************************************
|
|
5
|
+
Copyright (c) Microsoft Corporation.
|
|
6
|
+
|
|
7
|
+
Permission to use, copy, modify, and/or distribute this software for any
|
|
8
|
+
purpose with or without fee is hereby granted.
|
|
9
|
+
|
|
10
|
+
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
|
|
11
|
+
REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
|
|
12
|
+
AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
|
|
13
|
+
INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
|
|
14
|
+
LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
|
|
15
|
+
OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
|
|
16
|
+
PERFORMANCE OF THIS SOFTWARE.
|
|
17
|
+
***************************************************************************** */
|
|
18
|
+
/* global Reflect, Promise */
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
function __decorate(decorators, target, key, desc) {
|
|
22
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
23
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
24
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
25
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
let DomRenderer = class DomRenderer extends NativeRenderer {
|
|
29
|
+
constructor() {
|
|
30
|
+
super(...arguments);
|
|
31
|
+
this.isSVG = new RegExp(`^(${[
|
|
32
|
+
// 'a',
|
|
33
|
+
'animate',
|
|
34
|
+
'animateMotion',
|
|
35
|
+
'animateTransform',
|
|
36
|
+
'circle',
|
|
37
|
+
'clipPath',
|
|
38
|
+
'defs',
|
|
39
|
+
'desc',
|
|
40
|
+
'ellipse',
|
|
41
|
+
'feBlend',
|
|
42
|
+
'feColorMatrix',
|
|
43
|
+
'feComponentTransfer',
|
|
44
|
+
'feComposite',
|
|
45
|
+
'feConvolveMatrix',
|
|
46
|
+
'feDiffuseLighting',
|
|
47
|
+
'feDisplacementMap',
|
|
48
|
+
'feDistantLight',
|
|
49
|
+
'feDropShadow',
|
|
50
|
+
'feFlood',
|
|
51
|
+
'feFuncA',
|
|
52
|
+
'feFuncB',
|
|
53
|
+
'feFuncG',
|
|
54
|
+
'feFuncR',
|
|
55
|
+
'feGaussianBlur',
|
|
56
|
+
'feImage',
|
|
57
|
+
'feMerge',
|
|
58
|
+
'feMergeNode',
|
|
59
|
+
'feMorphology',
|
|
60
|
+
'feOffset',
|
|
61
|
+
'fePointLight',
|
|
62
|
+
'feSpecularLighting',
|
|
63
|
+
'feSpotLight',
|
|
64
|
+
'feTile',
|
|
65
|
+
'feTurbulence',
|
|
66
|
+
'filter',
|
|
67
|
+
'foreignObject',
|
|
68
|
+
'g',
|
|
69
|
+
'image',
|
|
70
|
+
'line',
|
|
71
|
+
'linearGradient',
|
|
72
|
+
'marker',
|
|
73
|
+
'mask',
|
|
74
|
+
'metadata',
|
|
75
|
+
'mpath',
|
|
76
|
+
'path',
|
|
77
|
+
'pattern',
|
|
78
|
+
'polygon',
|
|
79
|
+
'polyline',
|
|
80
|
+
'radialGradient',
|
|
81
|
+
'rect',
|
|
82
|
+
// 'script',
|
|
83
|
+
'set',
|
|
84
|
+
'stop',
|
|
85
|
+
// 'style',
|
|
86
|
+
'svg',
|
|
87
|
+
'switch',
|
|
88
|
+
'symbol',
|
|
89
|
+
'text',
|
|
90
|
+
'textPath',
|
|
91
|
+
'title',
|
|
92
|
+
'tspan',
|
|
93
|
+
'use',
|
|
94
|
+
'view'
|
|
95
|
+
].join('|')})$`, 'i');
|
|
96
|
+
this.xlinkNameSpace = 'http://www.w3.org/1999/xlink';
|
|
97
|
+
this.possibleXlinkNames = {
|
|
98
|
+
xlinkActuate: 'xlink:actuate',
|
|
99
|
+
xlinkactuate: 'xlink:actuate',
|
|
100
|
+
'xlink:actuate': 'xlink:actuate',
|
|
101
|
+
xlinkArcrole: 'xlink:arcrole',
|
|
102
|
+
xlinkarcrole: 'xlink:arcrole',
|
|
103
|
+
'xlink:arcrole': 'xlink:arcrole',
|
|
104
|
+
xlinkHref: 'xlink:href',
|
|
105
|
+
xlinkhref: 'xlink:href',
|
|
106
|
+
'xlink:href': 'xlink:href',
|
|
107
|
+
xlinkRole: 'xlink:role',
|
|
108
|
+
xlinkrole: 'xlink:role',
|
|
109
|
+
'xlink:role': 'xlink:role',
|
|
110
|
+
xlinkShow: 'xlink:show',
|
|
111
|
+
xlinkshow: 'xlink:show',
|
|
112
|
+
'xlink:show': 'xlink:show',
|
|
113
|
+
xlinkTitle: 'xlink:title',
|
|
114
|
+
xlinktitle: 'xlink:title',
|
|
115
|
+
'xlink:title': 'xlink:title',
|
|
116
|
+
xlinkType: 'xlink:type',
|
|
117
|
+
xlinktype: 'xlink:type',
|
|
118
|
+
'xlink:type': 'xlink:type'
|
|
119
|
+
};
|
|
120
|
+
this.booleanProps = {
|
|
121
|
+
input: ['disabled', 'readonly'],
|
|
122
|
+
select: ['disabled', 'multiple'],
|
|
123
|
+
option: ['disabled', 'selected'],
|
|
124
|
+
button: ['disabled'],
|
|
125
|
+
video: ['controls', 'autoplay', 'loop', 'muted'],
|
|
126
|
+
audio: ['controls', 'autoplay', 'loop', 'muted'],
|
|
127
|
+
};
|
|
128
|
+
this.valueProps = {
|
|
129
|
+
input: ['value'],
|
|
130
|
+
option: ['value'],
|
|
131
|
+
video: ['src'],
|
|
132
|
+
audio: ['src']
|
|
133
|
+
};
|
|
134
|
+
}
|
|
135
|
+
createElement(name) {
|
|
136
|
+
if (this.isSVG.test(name)) {
|
|
137
|
+
return document.createElementNS('http://www.w3.org/2000/svg', name);
|
|
138
|
+
}
|
|
139
|
+
return document.createElement(name);
|
|
140
|
+
}
|
|
141
|
+
createTextNode(textContent) {
|
|
142
|
+
return document.createTextNode(textContent);
|
|
143
|
+
}
|
|
144
|
+
appendChild(parent, newChild) {
|
|
145
|
+
parent.appendChild(newChild);
|
|
146
|
+
}
|
|
147
|
+
prependChild(parent, newChild) {
|
|
148
|
+
if (newChild === parent.childNodes[0]) {
|
|
149
|
+
return;
|
|
150
|
+
}
|
|
151
|
+
parent.prepend(newChild);
|
|
152
|
+
}
|
|
153
|
+
insertAfter(newNode, ref) {
|
|
154
|
+
if (ref.nextSibling === newNode) {
|
|
155
|
+
return;
|
|
156
|
+
}
|
|
157
|
+
if (ref.nextSibling) {
|
|
158
|
+
this.insertBefore(newNode, ref.nextSibling);
|
|
159
|
+
}
|
|
160
|
+
else {
|
|
161
|
+
this.appendChild(ref.parentNode, newNode);
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
remove(node) {
|
|
165
|
+
node.remove();
|
|
166
|
+
}
|
|
167
|
+
setProperty(node, key, value) {
|
|
168
|
+
if (this.possibleXlinkNames[key]) {
|
|
169
|
+
this.setXlinkAttribute(node, this.possibleXlinkNames[key], value);
|
|
170
|
+
return;
|
|
171
|
+
}
|
|
172
|
+
node.setAttribute(key, value);
|
|
173
|
+
const tag = node.tagName.toLowerCase();
|
|
174
|
+
const booleanTagNames = this.booleanProps[tag];
|
|
175
|
+
const valueTagNames = this.valueProps[tag];
|
|
176
|
+
if (booleanTagNames && booleanTagNames.includes(key)) {
|
|
177
|
+
node[key] = Boolean(value);
|
|
178
|
+
}
|
|
179
|
+
if (valueTagNames && valueTagNames.includes(key)) {
|
|
180
|
+
if (node[key] === value) {
|
|
181
|
+
return;
|
|
182
|
+
}
|
|
183
|
+
node[key] = value;
|
|
184
|
+
}
|
|
185
|
+
}
|
|
186
|
+
removeProperty(node, key) {
|
|
187
|
+
if (this.possibleXlinkNames[key]) {
|
|
188
|
+
this.removeXlinkAttribute(node, this.possibleXlinkNames[key]);
|
|
189
|
+
}
|
|
190
|
+
node.removeAttribute(key);
|
|
191
|
+
const tag = node.tagName.toLowerCase();
|
|
192
|
+
const booleanTagNames = this.booleanProps[tag];
|
|
193
|
+
const valueTagNames = this.valueProps[tag];
|
|
194
|
+
if (booleanTagNames && booleanTagNames.includes(key)) {
|
|
195
|
+
node[key] = false;
|
|
196
|
+
}
|
|
197
|
+
if (valueTagNames && valueTagNames.includes(key)) {
|
|
198
|
+
node[key] = '';
|
|
199
|
+
}
|
|
200
|
+
}
|
|
201
|
+
addClass(target, name) {
|
|
202
|
+
target.classList.add(name);
|
|
203
|
+
}
|
|
204
|
+
removeClass(target, name) {
|
|
205
|
+
target.classList.remove(name);
|
|
206
|
+
}
|
|
207
|
+
setStyle(target, key, value) {
|
|
208
|
+
target.style[key] = value !== null && value !== void 0 ? value : '';
|
|
209
|
+
}
|
|
210
|
+
removeStyle(target, key) {
|
|
211
|
+
target.style[key] = '';
|
|
212
|
+
}
|
|
213
|
+
listen(node, type, callback) {
|
|
214
|
+
node.addEventListener(type, callback);
|
|
215
|
+
}
|
|
216
|
+
unListen(node, type, callback) {
|
|
217
|
+
node.removeEventListener(type, callback);
|
|
218
|
+
}
|
|
219
|
+
syncTextContent(target, content) {
|
|
220
|
+
if (target.textContent !== content) {
|
|
221
|
+
target.textContent = content;
|
|
222
|
+
}
|
|
223
|
+
}
|
|
224
|
+
setXlinkAttribute(target, key, value) {
|
|
225
|
+
target.setAttributeNS(this.xlinkNameSpace, key, value);
|
|
226
|
+
}
|
|
227
|
+
removeXlinkAttribute(target, key) {
|
|
228
|
+
target.removeAttributeNS(this.xlinkNameSpace, key);
|
|
229
|
+
}
|
|
230
|
+
insertBefore(newNode, ref) {
|
|
231
|
+
if (ref.previousSibling === newNode) {
|
|
232
|
+
return;
|
|
233
|
+
}
|
|
234
|
+
ref.parentNode.insertBefore(newNode, ref);
|
|
235
|
+
}
|
|
236
|
+
};
|
|
237
|
+
DomRenderer = __decorate([
|
|
238
|
+
Injectable()
|
|
239
|
+
], DomRenderer);
|
|
240
|
+
|
|
241
|
+
/**
|
|
242
|
+
* 创建一个 Viewfly 实例
|
|
243
|
+
* @param host 应用根节点
|
|
244
|
+
* @param root 应用根节点
|
|
245
|
+
* @param autoUpdate 是否自动更新视图,默认为 true,当值为 false 时,Viewfly
|
|
246
|
+
* 只会首次渲染,直到手动调用 Renderer 类的 refresh() 方法,这在单元测试中非常有用,
|
|
247
|
+
* 我们无需等待 Viewfly 默认的异步调度,实现同步更新视图
|
|
248
|
+
* ```tsx
|
|
249
|
+
* const app = createApp(document.getElementById('app'), <App/>, false)
|
|
250
|
+
* const renderer = app.get(Renderer)
|
|
251
|
+
*
|
|
252
|
+
* // do something...
|
|
253
|
+
*
|
|
254
|
+
* renderer.refresh() // 手动更新视图
|
|
255
|
+
* ```
|
|
256
|
+
*/
|
|
257
|
+
function createApp(host, root, autoUpdate = true) {
|
|
258
|
+
host.innerHTML = '';
|
|
259
|
+
const app = new Viewfly({
|
|
260
|
+
host,
|
|
261
|
+
root,
|
|
262
|
+
autoUpdate,
|
|
263
|
+
providers: [
|
|
264
|
+
{
|
|
265
|
+
provide: NativeRenderer,
|
|
266
|
+
useClass: DomRenderer
|
|
267
|
+
}
|
|
268
|
+
]
|
|
269
|
+
});
|
|
270
|
+
app.start();
|
|
271
|
+
return app;
|
|
272
|
+
}
|
|
273
|
+
|
|
274
|
+
export { DomRenderer, createApp };
|
package/bundles/index.js
ADDED
|
@@ -0,0 +1,276 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var core = require('@viewfly/core');
|
|
4
|
+
var di = require('@tanbo/di');
|
|
5
|
+
|
|
6
|
+
/******************************************************************************
|
|
7
|
+
Copyright (c) Microsoft Corporation.
|
|
8
|
+
|
|
9
|
+
Permission to use, copy, modify, and/or distribute this software for any
|
|
10
|
+
purpose with or without fee is hereby granted.
|
|
11
|
+
|
|
12
|
+
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
|
|
13
|
+
REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
|
|
14
|
+
AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
|
|
15
|
+
INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
|
|
16
|
+
LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
|
|
17
|
+
OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
|
|
18
|
+
PERFORMANCE OF THIS SOFTWARE.
|
|
19
|
+
***************************************************************************** */
|
|
20
|
+
/* global Reflect, Promise */
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
function __decorate(decorators, target, key, desc) {
|
|
24
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
25
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
26
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
27
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
exports.DomRenderer = class DomRenderer extends core.NativeRenderer {
|
|
31
|
+
constructor() {
|
|
32
|
+
super(...arguments);
|
|
33
|
+
this.isSVG = new RegExp(`^(${[
|
|
34
|
+
// 'a',
|
|
35
|
+
'animate',
|
|
36
|
+
'animateMotion',
|
|
37
|
+
'animateTransform',
|
|
38
|
+
'circle',
|
|
39
|
+
'clipPath',
|
|
40
|
+
'defs',
|
|
41
|
+
'desc',
|
|
42
|
+
'ellipse',
|
|
43
|
+
'feBlend',
|
|
44
|
+
'feColorMatrix',
|
|
45
|
+
'feComponentTransfer',
|
|
46
|
+
'feComposite',
|
|
47
|
+
'feConvolveMatrix',
|
|
48
|
+
'feDiffuseLighting',
|
|
49
|
+
'feDisplacementMap',
|
|
50
|
+
'feDistantLight',
|
|
51
|
+
'feDropShadow',
|
|
52
|
+
'feFlood',
|
|
53
|
+
'feFuncA',
|
|
54
|
+
'feFuncB',
|
|
55
|
+
'feFuncG',
|
|
56
|
+
'feFuncR',
|
|
57
|
+
'feGaussianBlur',
|
|
58
|
+
'feImage',
|
|
59
|
+
'feMerge',
|
|
60
|
+
'feMergeNode',
|
|
61
|
+
'feMorphology',
|
|
62
|
+
'feOffset',
|
|
63
|
+
'fePointLight',
|
|
64
|
+
'feSpecularLighting',
|
|
65
|
+
'feSpotLight',
|
|
66
|
+
'feTile',
|
|
67
|
+
'feTurbulence',
|
|
68
|
+
'filter',
|
|
69
|
+
'foreignObject',
|
|
70
|
+
'g',
|
|
71
|
+
'image',
|
|
72
|
+
'line',
|
|
73
|
+
'linearGradient',
|
|
74
|
+
'marker',
|
|
75
|
+
'mask',
|
|
76
|
+
'metadata',
|
|
77
|
+
'mpath',
|
|
78
|
+
'path',
|
|
79
|
+
'pattern',
|
|
80
|
+
'polygon',
|
|
81
|
+
'polyline',
|
|
82
|
+
'radialGradient',
|
|
83
|
+
'rect',
|
|
84
|
+
// 'script',
|
|
85
|
+
'set',
|
|
86
|
+
'stop',
|
|
87
|
+
// 'style',
|
|
88
|
+
'svg',
|
|
89
|
+
'switch',
|
|
90
|
+
'symbol',
|
|
91
|
+
'text',
|
|
92
|
+
'textPath',
|
|
93
|
+
'title',
|
|
94
|
+
'tspan',
|
|
95
|
+
'use',
|
|
96
|
+
'view'
|
|
97
|
+
].join('|')})$`, 'i');
|
|
98
|
+
this.xlinkNameSpace = 'http://www.w3.org/1999/xlink';
|
|
99
|
+
this.possibleXlinkNames = {
|
|
100
|
+
xlinkActuate: 'xlink:actuate',
|
|
101
|
+
xlinkactuate: 'xlink:actuate',
|
|
102
|
+
'xlink:actuate': 'xlink:actuate',
|
|
103
|
+
xlinkArcrole: 'xlink:arcrole',
|
|
104
|
+
xlinkarcrole: 'xlink:arcrole',
|
|
105
|
+
'xlink:arcrole': 'xlink:arcrole',
|
|
106
|
+
xlinkHref: 'xlink:href',
|
|
107
|
+
xlinkhref: 'xlink:href',
|
|
108
|
+
'xlink:href': 'xlink:href',
|
|
109
|
+
xlinkRole: 'xlink:role',
|
|
110
|
+
xlinkrole: 'xlink:role',
|
|
111
|
+
'xlink:role': 'xlink:role',
|
|
112
|
+
xlinkShow: 'xlink:show',
|
|
113
|
+
xlinkshow: 'xlink:show',
|
|
114
|
+
'xlink:show': 'xlink:show',
|
|
115
|
+
xlinkTitle: 'xlink:title',
|
|
116
|
+
xlinktitle: 'xlink:title',
|
|
117
|
+
'xlink:title': 'xlink:title',
|
|
118
|
+
xlinkType: 'xlink:type',
|
|
119
|
+
xlinktype: 'xlink:type',
|
|
120
|
+
'xlink:type': 'xlink:type'
|
|
121
|
+
};
|
|
122
|
+
this.booleanProps = {
|
|
123
|
+
input: ['disabled', 'readonly'],
|
|
124
|
+
select: ['disabled', 'multiple'],
|
|
125
|
+
option: ['disabled', 'selected'],
|
|
126
|
+
button: ['disabled'],
|
|
127
|
+
video: ['controls', 'autoplay', 'loop', 'muted'],
|
|
128
|
+
audio: ['controls', 'autoplay', 'loop', 'muted'],
|
|
129
|
+
};
|
|
130
|
+
this.valueProps = {
|
|
131
|
+
input: ['value'],
|
|
132
|
+
option: ['value'],
|
|
133
|
+
video: ['src'],
|
|
134
|
+
audio: ['src']
|
|
135
|
+
};
|
|
136
|
+
}
|
|
137
|
+
createElement(name) {
|
|
138
|
+
if (this.isSVG.test(name)) {
|
|
139
|
+
return document.createElementNS('http://www.w3.org/2000/svg', name);
|
|
140
|
+
}
|
|
141
|
+
return document.createElement(name);
|
|
142
|
+
}
|
|
143
|
+
createTextNode(textContent) {
|
|
144
|
+
return document.createTextNode(textContent);
|
|
145
|
+
}
|
|
146
|
+
appendChild(parent, newChild) {
|
|
147
|
+
parent.appendChild(newChild);
|
|
148
|
+
}
|
|
149
|
+
prependChild(parent, newChild) {
|
|
150
|
+
if (newChild === parent.childNodes[0]) {
|
|
151
|
+
return;
|
|
152
|
+
}
|
|
153
|
+
parent.prepend(newChild);
|
|
154
|
+
}
|
|
155
|
+
insertAfter(newNode, ref) {
|
|
156
|
+
if (ref.nextSibling === newNode) {
|
|
157
|
+
return;
|
|
158
|
+
}
|
|
159
|
+
if (ref.nextSibling) {
|
|
160
|
+
this.insertBefore(newNode, ref.nextSibling);
|
|
161
|
+
}
|
|
162
|
+
else {
|
|
163
|
+
this.appendChild(ref.parentNode, newNode);
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
remove(node) {
|
|
167
|
+
node.remove();
|
|
168
|
+
}
|
|
169
|
+
setProperty(node, key, value) {
|
|
170
|
+
if (this.possibleXlinkNames[key]) {
|
|
171
|
+
this.setXlinkAttribute(node, this.possibleXlinkNames[key], value);
|
|
172
|
+
return;
|
|
173
|
+
}
|
|
174
|
+
node.setAttribute(key, value);
|
|
175
|
+
const tag = node.tagName.toLowerCase();
|
|
176
|
+
const booleanTagNames = this.booleanProps[tag];
|
|
177
|
+
const valueTagNames = this.valueProps[tag];
|
|
178
|
+
if (booleanTagNames && booleanTagNames.includes(key)) {
|
|
179
|
+
node[key] = Boolean(value);
|
|
180
|
+
}
|
|
181
|
+
if (valueTagNames && valueTagNames.includes(key)) {
|
|
182
|
+
if (node[key] === value) {
|
|
183
|
+
return;
|
|
184
|
+
}
|
|
185
|
+
node[key] = value;
|
|
186
|
+
}
|
|
187
|
+
}
|
|
188
|
+
removeProperty(node, key) {
|
|
189
|
+
if (this.possibleXlinkNames[key]) {
|
|
190
|
+
this.removeXlinkAttribute(node, this.possibleXlinkNames[key]);
|
|
191
|
+
}
|
|
192
|
+
node.removeAttribute(key);
|
|
193
|
+
const tag = node.tagName.toLowerCase();
|
|
194
|
+
const booleanTagNames = this.booleanProps[tag];
|
|
195
|
+
const valueTagNames = this.valueProps[tag];
|
|
196
|
+
if (booleanTagNames && booleanTagNames.includes(key)) {
|
|
197
|
+
node[key] = false;
|
|
198
|
+
}
|
|
199
|
+
if (valueTagNames && valueTagNames.includes(key)) {
|
|
200
|
+
node[key] = '';
|
|
201
|
+
}
|
|
202
|
+
}
|
|
203
|
+
addClass(target, name) {
|
|
204
|
+
target.classList.add(name);
|
|
205
|
+
}
|
|
206
|
+
removeClass(target, name) {
|
|
207
|
+
target.classList.remove(name);
|
|
208
|
+
}
|
|
209
|
+
setStyle(target, key, value) {
|
|
210
|
+
target.style[key] = value !== null && value !== void 0 ? value : '';
|
|
211
|
+
}
|
|
212
|
+
removeStyle(target, key) {
|
|
213
|
+
target.style[key] = '';
|
|
214
|
+
}
|
|
215
|
+
listen(node, type, callback) {
|
|
216
|
+
node.addEventListener(type, callback);
|
|
217
|
+
}
|
|
218
|
+
unListen(node, type, callback) {
|
|
219
|
+
node.removeEventListener(type, callback);
|
|
220
|
+
}
|
|
221
|
+
syncTextContent(target, content) {
|
|
222
|
+
if (target.textContent !== content) {
|
|
223
|
+
target.textContent = content;
|
|
224
|
+
}
|
|
225
|
+
}
|
|
226
|
+
setXlinkAttribute(target, key, value) {
|
|
227
|
+
target.setAttributeNS(this.xlinkNameSpace, key, value);
|
|
228
|
+
}
|
|
229
|
+
removeXlinkAttribute(target, key) {
|
|
230
|
+
target.removeAttributeNS(this.xlinkNameSpace, key);
|
|
231
|
+
}
|
|
232
|
+
insertBefore(newNode, ref) {
|
|
233
|
+
if (ref.previousSibling === newNode) {
|
|
234
|
+
return;
|
|
235
|
+
}
|
|
236
|
+
ref.parentNode.insertBefore(newNode, ref);
|
|
237
|
+
}
|
|
238
|
+
};
|
|
239
|
+
exports.DomRenderer = __decorate([
|
|
240
|
+
di.Injectable()
|
|
241
|
+
], exports.DomRenderer);
|
|
242
|
+
|
|
243
|
+
/**
|
|
244
|
+
* 创建一个 Viewfly 实例
|
|
245
|
+
* @param host 应用根节点
|
|
246
|
+
* @param root 应用根节点
|
|
247
|
+
* @param autoUpdate 是否自动更新视图,默认为 true,当值为 false 时,Viewfly
|
|
248
|
+
* 只会首次渲染,直到手动调用 Renderer 类的 refresh() 方法,这在单元测试中非常有用,
|
|
249
|
+
* 我们无需等待 Viewfly 默认的异步调度,实现同步更新视图
|
|
250
|
+
* ```tsx
|
|
251
|
+
* const app = createApp(document.getElementById('app'), <App/>, false)
|
|
252
|
+
* const renderer = app.get(Renderer)
|
|
253
|
+
*
|
|
254
|
+
* // do something...
|
|
255
|
+
*
|
|
256
|
+
* renderer.refresh() // 手动更新视图
|
|
257
|
+
* ```
|
|
258
|
+
*/
|
|
259
|
+
function createApp(host, root, autoUpdate = true) {
|
|
260
|
+
host.innerHTML = '';
|
|
261
|
+
const app = new core.Viewfly({
|
|
262
|
+
host,
|
|
263
|
+
root,
|
|
264
|
+
autoUpdate,
|
|
265
|
+
providers: [
|
|
266
|
+
{
|
|
267
|
+
provide: core.NativeRenderer,
|
|
268
|
+
useClass: exports.DomRenderer
|
|
269
|
+
}
|
|
270
|
+
]
|
|
271
|
+
});
|
|
272
|
+
app.start();
|
|
273
|
+
return app;
|
|
274
|
+
}
|
|
275
|
+
|
|
276
|
+
exports.createApp = createApp;
|
package/package.json
ADDED
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@viewfly/platform-browser",
|
|
3
|
+
"version": "0.0.1-alpha.0",
|
|
4
|
+
"description": "Viewfly is a simple and easy-to-use JavaScript framework with an intuitive development experience.",
|
|
5
|
+
"main": "./bundles/index.js",
|
|
6
|
+
"module": "./bundles/index.esm.js",
|
|
7
|
+
"typings": "./bundles/public-api.d.ts",
|
|
8
|
+
"scripts": {
|
|
9
|
+
"start": "webpack-dev-server",
|
|
10
|
+
"test": "cross-env env=test jest",
|
|
11
|
+
"test-c": "cross-env env=test jest --coverage",
|
|
12
|
+
"build:lib": "rimraf bundles && rollup --config rollup.config.ts --configPlugin @rollup/plugin-typescript",
|
|
13
|
+
"publish:lib": "npm run build:lib && npm publish --access=public"
|
|
14
|
+
},
|
|
15
|
+
"license": "MIT",
|
|
16
|
+
"keywords": [],
|
|
17
|
+
"dependencies": {
|
|
18
|
+
"@tanbo/di": "^1.1.4",
|
|
19
|
+
"@viewfly/core": "^0.0.1-alpha.0",
|
|
20
|
+
"reflect-metadata": "^0.1.13"
|
|
21
|
+
},
|
|
22
|
+
"devDependencies": {
|
|
23
|
+
"@rollup/plugin-commonjs": "^23.0.2",
|
|
24
|
+
"@rollup/plugin-typescript": "^9.0.2",
|
|
25
|
+
"rimraf": "^3.0.2",
|
|
26
|
+
"rollup": "^3.2.5",
|
|
27
|
+
"tslib": "^2.4.1"
|
|
28
|
+
},
|
|
29
|
+
"author": {
|
|
30
|
+
"name": "Tanbo",
|
|
31
|
+
"email": "tanbohb@qq.com"
|
|
32
|
+
},
|
|
33
|
+
"repository": {
|
|
34
|
+
"type": "git",
|
|
35
|
+
"url": "git+https://github.com/viewfly/viewfly.git"
|
|
36
|
+
},
|
|
37
|
+
"bugs": {
|
|
38
|
+
"url": "https://github.com/viewfly/viewfly.git/issues"
|
|
39
|
+
}
|
|
40
|
+
}
|