Skip to content

Commit 17c74bf

Browse files
author
古映杰
committed
try to support svg
1 parent 16d5071 commit 17c74bf

8 files changed

Lines changed: 901 additions & 473 deletions

File tree

dist/react-lite.common.js

Lines changed: 308 additions & 163 deletions
Large diffs are not rendered by default.

dist/react-lite.js

Lines changed: 308 additions & 163 deletions
Large diffs are not rendered by default.

dist/react-lite.min.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/react-lite.min.js.gz

329 Bytes
Binary file not shown.

src/configs.js

Lines changed: 254 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,15 @@
11
/*
22
key/value configs
33
*/
4-
var NS = {
5-
xlink: 'http://www.w3.org/1999/xlink',
6-
xml: 'http://www.w3.org/XML/1998/namespace',
7-
};
4+
const TRUE = true
5+
const xlink = 'http://www.w3.org/1999/xlink'
6+
const xml = 'http://www.w3.org/XML/1998/namespace'
87

9-
export let DOMNamespaces = {
10-
html: 'http://www.w3.org/1999/xhtml',
11-
mathml: 'http://www.w3.org/1998/Math/MathML',
12-
svg: 'http://www.w3.org/2000/svg',
13-
};
8+
export const SVGNamespaceURI = 'http://www.w3.org/2000/svg'
149

15-
export let propAlias = {
16-
// svg attributes alias
17-
clipPath: 'clip-path',
10+
export const propAlias = {
11+
// svg attributes alias
12+
clipPath: 'clip-path',
1813
fillOpacity: 'fill-opacity',
1914
fontFamily: 'font-family',
2015
fontSize: 'font-size',
@@ -52,18 +47,253 @@ export let propAlias = {
5247
radioGroup: 'radiogroup',
5348
spellCheck: 'spellcheck',
5449
srcDoc: 'srcdoc',
55-
srcSet: 'srcset',
50+
srcSet: 'srcset'
5651
}
5752

58-
export let attributesNS = {
59-
xlinkActuate: NS.xlink,
60-
xlinkArcrole: NS.xlink,
61-
xlinkHref: NS.xlink,
62-
xlinkRole: NS.xlink,
63-
xlinkShow: NS.xlink,
64-
xlinkTitle: NS.xlink,
65-
xlinkType: NS.xlink,
66-
xmlBase: NS.xml,
67-
xmlLang: NS.xml,
68-
xmlSpace: NS.xml,
53+
export const attributesNS = {
54+
'xlink:actuate': xlink,
55+
'xlink:arcrole': xlink,
56+
'xlink:href': xlink,
57+
'xlink:role': xlink,
58+
'xlink:show': xlink,
59+
'xlink:title': xlink,
60+
'xlink:type': xlink,
61+
'xml:base': xml,
62+
'xml:lang': xml,
63+
'xml:space': xml
64+
}
65+
66+
// those key must use be attributes
67+
export const attrbutesConfigs = {
68+
clipPath: TRUE,
69+
cx: TRUE,
70+
cy: TRUE,
71+
d: TRUE,
72+
dx: TRUE,
73+
dy: TRUE,
74+
fill: TRUE,
75+
fillOpacity: TRUE,
76+
fontFamily: TRUE,
77+
fontSize: TRUE,
78+
fx: TRUE,
79+
fy: TRUE,
80+
gradientTransform: TRUE,
81+
gradientUnits: TRUE,
82+
markerEnd: TRUE,
83+
markerMid: TRUE,
84+
markerStart: TRUE,
85+
offset: TRUE,
86+
opacity: TRUE,
87+
patternContentUnits: TRUE,
88+
patternUnits: TRUE,
89+
points: TRUE,
90+
preserveAspectRatio: TRUE,
91+
r: TRUE,
92+
rx: TRUE,
93+
ry: TRUE,
94+
spreadMethod: TRUE,
95+
stopColor: TRUE,
96+
stopOpacity: TRUE,
97+
stroke: TRUE,
98+
strokeDasharray: TRUE,
99+
strokeLinecap: TRUE,
100+
strokeOpacity: TRUE,
101+
strokeWidth: TRUE,
102+
textAnchor: TRUE,
103+
transform: TRUE,
104+
version: TRUE,
105+
viewBox: TRUE,
106+
x1: TRUE,
107+
x2: TRUE,
108+
x: TRUE,
109+
xlinkActuate: TRUE,
110+
xlinkArcrole: TRUE,
111+
xlinkHref: TRUE,
112+
xlinkRole: TRUE,
113+
xlinkShow: TRUE,
114+
xlinkTitle: TRUE,
115+
xlinkType: TRUE,
116+
xmlBase: TRUE,
117+
xmlLang: TRUE,
118+
xmlSpace: TRUE,
119+
y1: TRUE,
120+
y2: TRUE,
121+
y: TRUE,
122+
123+
/**
124+
* Standard Properties
125+
*/
126+
allowFullScreen: TRUE,
127+
allowTransparency: TRUE,
128+
capture: TRUE,
129+
charSet: TRUE,
130+
challenge: TRUE,
131+
classID: TRUE,
132+
cols: TRUE,
133+
contextMenu: TRUE,
134+
dateTime: TRUE,
135+
disabled: TRUE,
136+
form: TRUE,
137+
formAction: TRUE,
138+
formEncType: TRUE,
139+
formMethod: TRUE,
140+
formTarget: TRUE,
141+
frameBorder: TRUE,
142+
height: TRUE,
143+
hidden: TRUE,
144+
inputMode: TRUE,
145+
is: TRUE,
146+
keyParams: TRUE,
147+
keyType: TRUE,
148+
list: TRUE,
149+
manifest: TRUE,
150+
maxLength: TRUE,
151+
media: TRUE,
152+
minLength: TRUE,
153+
nonce: TRUE,
154+
role: TRUE,
155+
rows: TRUE,
156+
seamless: TRUE,
157+
size: TRUE,
158+
sizes: TRUE,
159+
srcSet: TRUE,
160+
width: TRUE,
161+
wmode: TRUE,
162+
/**
163+
* RDFa Properties
164+
*/
165+
about: TRUE,
166+
datatype: TRUE,
167+
inlist: TRUE,
168+
prefix: TRUE,
169+
// property is also supported for OpenGraph in meta tags.
170+
property: TRUE,
171+
resource: TRUE,
172+
typeof: TRUE,
173+
vocab: TRUE,
174+
/**
175+
* Non-standard Properties
176+
*/
177+
// autoCapitalize and autoCorrect are supported in Mobile Safari for
178+
// keyboard hints.
179+
autoCapitalize: TRUE,
180+
autoCorrect: TRUE,
181+
// itemProp, itemScope, itemType are for
182+
// Microdata support. See http://schema.org/docs/gs.html
183+
itemProp: TRUE,
184+
itemScope: TRUE,
185+
itemType: TRUE,
186+
// itemID and itemRef are for Microdata support as well but
187+
// only specified in the the WHATWG spec document. See
188+
// https://html.spec.whatwg.org/multipage/microdata.html#microdata-dom-api
189+
itemID: TRUE,
190+
itemRef: TRUE,
191+
// IE-only attribute that specifies security restrictions on an iframe
192+
// as an alternative to the sandbox attribute on IE<10
193+
security: TRUE,
194+
// IE-only attribute that controls focus behavior
195+
unselectable: TRUE,
196+
}
197+
198+
export const readOnlyProps = {
199+
nodeName: TRUE,
200+
nodeValue: TRUE,
201+
nodeType: TRUE,
202+
parentNode: TRUE,
203+
childNodes: TRUE,
204+
classList: TRUE,
205+
firstChild: TRUE,
206+
lastChild: TRUE,
207+
previousSibling: TRUE,
208+
previousElementSibling: TRUE,
209+
nextSibling: TRUE,
210+
nextElementSibling: TRUE,
211+
attributes: TRUE,
212+
ownerDocument: TRUE,
213+
namespaceURI: TRUE,
214+
localName: TRUE,
215+
baseURI: TRUE,
216+
prefix: TRUE,
217+
length: TRUE,
218+
specified: TRUE,
219+
tagName: TRUE,
220+
offsetTop: TRUE,
221+
offsetLeft: TRUE,
222+
offsetWidth: TRUE,
223+
offsetHeight: TRUE,
224+
offsetParent: TRUE,
225+
scrollWidth: TRUE,
226+
scrollHeight: TRUE,
227+
clientTop: TRUE,
228+
clientLeft: TRUE,
229+
clientWidth: TRUE,
230+
clientHeight: TRUE,
231+
x: TRUE,
232+
y: TRUE
233+
}
234+
235+
export const isUnitlessNumber = {
236+
animationIterationCount: TRUE,
237+
boxFlex: TRUE,
238+
boxFlexGroup: TRUE,
239+
boxOrdinalGroup: TRUE,
240+
columnCount: TRUE,
241+
flex: TRUE,
242+
flexGrow: TRUE,
243+
flexPositive: TRUE,
244+
flexShrink: TRUE,
245+
flexNegative: TRUE,
246+
flexOrder: TRUE,
247+
fontWeight: TRUE,
248+
lineClamp: TRUE,
249+
lineHeight: TRUE,
250+
opacity: TRUE,
251+
order: TRUE,
252+
orphans: TRUE,
253+
tabSize: TRUE,
254+
widows: TRUE,
255+
zIndex: TRUE,
256+
zoom: TRUE,
257+
258+
// SVG-related properties
259+
fillOpacity: TRUE,
260+
stopOpacity: TRUE,
261+
strokeDashoffset: TRUE,
262+
strokeOpacity: TRUE,
263+
strokeWidth: TRUE
264+
}
265+
266+
export let ignoreKeys = {
267+
key: TRUE,
268+
ref: TRUE,
269+
children: TRUE
270+
}
271+
272+
// use dom prop to compare new prop
273+
export let shouldUseDOMProp = {
274+
value: TRUE,
275+
checked: TRUE
276+
}
277+
278+
export let eventNameAlias = {
279+
onDoubleClick: 'ondblclick'
280+
}
281+
282+
export let notBubbleEvents = {
283+
onmouseleave: TRUE,
284+
onmouseenter: TRUE,
285+
onload: TRUE,
286+
onunload: TRUE,
287+
onscroll: TRUE,
288+
onfocus: TRUE,
289+
onblur: TRUE,
290+
onrowexit: TRUE,
291+
onbeforeunload: TRUE,
292+
onstop: TRUE,
293+
ondragdrop: TRUE,
294+
ondragenter: TRUE,
295+
ondragexit: TRUE,
296+
ondraggesture: TRUE,
297+
ondragover: TRUE,
298+
oncontextmenu: TRUE
69299
}

src/event-system.js

Lines changed: 3 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,38 +1,16 @@
11
import { updateQueue } from './Component'
2+
import { eventNameAlias, notBubbleEvents } from './configs'
23

3-
let eventNameAlias = {
4-
onDoubleClick: 'ondblclick'
5-
}
64
let getEventName = key => {
75
key = eventNameAlias[key] || key
86
return key.toLowerCase()
97
}
108

11-
let isNotBubble = true
12-
let notBubbleEvents = {
13-
onload: isNotBubble,
14-
onunload: isNotBubble,
15-
onscroll: isNotBubble,
16-
onfocus: isNotBubble,
17-
onblur: isNotBubble,
18-
onrowexit: isNotBubble,
19-
onbeforeunload: isNotBubble,
20-
onstop: isNotBubble,
21-
ondragdrop: isNotBubble,
22-
ondragenter: isNotBubble,
23-
ondragexit: isNotBubble,
24-
ondraggesture: isNotBubble,
25-
ondragover: isNotBubble,
26-
oncontextmenu: isNotBubble
27-
}
28-
299
let eventTypes = {}
30-
3110
export let addEvent = (elem, eventType, listener) => {
3211
eventType = getEventName(eventType)
33-
let isNotBubble = notBubbleEvents[eventType]
3412

35-
if (isNotBubble) {
13+
if (notBubbleEvents[eventType] === true) {
3614
elem[eventType] = listener
3715
return
3816
}
@@ -53,9 +31,7 @@ export let addEvent = (elem, eventType, listener) => {
5331

5432
export let removeEvent = (elem, eventType) => {
5533
eventType = getEventName(eventType)
56-
let isNotBubble = notBubbleEvents[eventType]
57-
58-
if (isNotBubble) {
34+
if (notBubbleEvents[eventType] === true) {
5935
elem[eventType] = null
6036
return
6137
}

0 commit comments

Comments
 (0)