@pixui-dev/pxw 0.1.35 → 0.1.36

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.
Files changed (97) hide show
  1. package/bin/pxw.js +56 -56
  2. package/bin/wpbuild.js +10 -10
  3. package/config/daemon.js +157 -157
  4. package/config/default.conf +20 -20
  5. package/config/devops.js +550 -550
  6. package/config/h5es.js +14 -14
  7. package/config/index.html +183 -183
  8. package/config/pfbs.js +259 -259
  9. package/config/util.js +143 -143
  10. package/config/webpack.js +325 -325
  11. package/lib/assets/check.html +62 -62
  12. package/lib/assets/preact.js +4354 -4354
  13. package/lib/check/main.less +62 -62
  14. package/lib/check/main.tsx +41 -41
  15. package/lib/check/tool.js +3 -3
  16. package/lib/check/util.tsx +110 -110
  17. package/lib/grpc-web/dist/ChunkParser.js +117 -117
  18. package/lib/grpc-web/dist/Code.js +58 -58
  19. package/lib/grpc-web/dist/client.js +299 -299
  20. package/lib/grpc-web/dist/debug.js +16 -16
  21. package/lib/grpc-web/dist/detach.js +7 -7
  22. package/lib/grpc-web/dist/index.js +29 -29
  23. package/lib/grpc-web/dist/invoke.js +32 -32
  24. package/lib/grpc-web/dist/message.js +3 -3
  25. package/lib/grpc-web/dist/metadata.js +5 -5
  26. package/lib/grpc-web/dist/service.js +3 -3
  27. package/lib/grpc-web/dist/transports/Transport.js +15 -15
  28. package/lib/grpc-web/dist/transports/http/fetch.js +117 -117
  29. package/lib/grpc-web/dist/transports/http/http.js +15 -15
  30. package/lib/grpc-web/dist/transports/http/xhr.js +136 -136
  31. package/lib/grpc-web/dist/transports/http/xhrUtil.js +36 -36
  32. package/lib/grpc-web/dist/transports/websocket/websocket.js +95 -95
  33. package/lib/grpc-web/dist/typings/ChunkParser.d.ts +17 -17
  34. package/lib/grpc-web/dist/typings/Code.d.ts +20 -20
  35. package/lib/grpc-web/dist/typings/client.d.ts +25 -25
  36. package/lib/grpc-web/dist/typings/debug.d.ts +1 -1
  37. package/lib/grpc-web/dist/typings/detach.d.ts +1 -1
  38. package/lib/grpc-web/dist/typings/index.d.ts +45 -45
  39. package/lib/grpc-web/dist/typings/invoke.d.ts +20 -20
  40. package/lib/grpc-web/dist/typings/message.d.ts +8 -8
  41. package/lib/grpc-web/dist/typings/metadata.d.ts +2 -2
  42. package/lib/grpc-web/dist/typings/service.d.ts +16 -16
  43. package/lib/grpc-web/dist/typings/transports/Transport.d.ts +22 -22
  44. package/lib/grpc-web/dist/typings/transports/http/fetch.d.ts +6 -6
  45. package/lib/grpc-web/dist/typings/transports/http/http.d.ts +5 -5
  46. package/lib/grpc-web/dist/typings/transports/http/xhr.d.ts +27 -27
  47. package/lib/grpc-web/dist/typings/transports/http/xhrUtil.d.ts +3 -3
  48. package/lib/grpc-web/dist/typings/transports/websocket/websocket.d.ts +2 -2
  49. package/lib/grpc-web/dist/typings/unary.d.ts +23 -23
  50. package/lib/grpc-web/dist/typings/util.d.ts +2 -2
  51. package/lib/grpc-web/dist/unary.js +44 -44
  52. package/lib/grpc-web/dist/util.js +11 -11
  53. package/lib/grpcTransport/PixHttp2Transport.ts +107 -107
  54. package/lib/grpcTransport/PixLuaTransport.ts +82 -82
  55. package/lib/h5es-types/v1.9.2/h5es.d.ts +1756 -1756
  56. package/lib/h5es-types/v3.5.0/h5es.d.ts +1851 -1851
  57. package/lib/h5es-types/v3.5.6/h5es.d.ts +1911 -1911
  58. package/lib/pi_component/tinyList/tinyList.js +483 -483
  59. package/lib/pi_component/tinyList/tinyList.tsx +517 -517
  60. package/lib/preact-router.js +395 -395
  61. package/lib/preact.js +4355 -4355
  62. package/lib/preact.tq.js +4385 -4385
  63. package/lib/react-window/src/FixedSizeGrid.js +172 -172
  64. package/lib/react-window/src/FixedSizeList.js +91 -91
  65. package/lib/react-window/src/VariableSizeGrid.js +329 -329
  66. package/lib/react-window/src/VariableSizeList.js +231 -231
  67. package/lib/react-window/src/__tests__/FixedSizeGrid.js +942 -942
  68. package/lib/react-window/src/__tests__/FixedSizeList.js +749 -749
  69. package/lib/react-window/src/__tests__/VariableSizeGrid.js +598 -598
  70. package/lib/react-window/src/__tests__/VariableSizeList.js +345 -345
  71. package/lib/react-window/src/__tests__/__snapshots__/FixedSizeGrid.js.snap +912 -912
  72. package/lib/react-window/src/__tests__/__snapshots__/FixedSizeList.js.snap +568 -568
  73. package/lib/react-window/src/__tests__/__snapshots__/VariableSizeGrid.js.snap +542 -542
  74. package/lib/react-window/src/__tests__/__snapshots__/VariableSizeList.js.snap +331 -331
  75. package/lib/react-window/src/__tests__/areEqual.js +28 -28
  76. package/lib/react-window/src/__tests__/shouldComponentUpdate.js +32 -32
  77. package/lib/react-window/src/areEqual.js +13 -13
  78. package/lib/react-window/src/createGridComponent.js +657 -657
  79. package/lib/react-window/src/createListComponent.js +574 -574
  80. package/lib/react-window/src/domHelpers.js +69 -69
  81. package/lib/react-window/src/index.js +9 -9
  82. package/lib/react-window/src/shallowDiffers.js +17 -17
  83. package/lib/react-window/src/shouldComponentUpdate.js +11 -11
  84. package/lib/react-window/src/test.js.flow +382 -382
  85. package/lib/react-window/src/timer.js +36 -36
  86. package/lib/types/dom.ts +17 -17
  87. package/lib/types/ext.d.ts +75 -75
  88. package/lib/types/preact/css.d.ts +7478 -7476
  89. package/lib/types/preact/index.d.ts +340 -340
  90. package/lib/types/preact/internal.d.ts +94 -94
  91. package/lib/types/preact/jsx.d.ts +368 -368
  92. package/lib/types/preact-router/index.d.ts +84 -84
  93. package/package.json +127 -127
  94. package/scripts/pack.js +40 -40
  95. package/scripts/postinstall.js +12 -12
  96. package/scripts/run-pxw.js +19 -19
  97. package/tsconfig.json +30 -30
@@ -1,395 +1,395 @@
1
- import { Component, toChildArray, cloneElement, createElement } from 'preact';
2
- import {
3
- subscribers as subscribers$1,
4
- getCurrentUrl as getCurrentUrl$1,
5
- exec as exec$1,
6
- Link as Link$2,
7
- } from './preact-router';
8
-
9
- const EMPTY$1 = {};
10
- function assign(obj, props) {
11
- // eslint-disable-next-line guard-for-in
12
- for (let i in props) {
13
- obj[i] = props[i];
14
- }
15
- return obj;
16
- }
17
- function exec(url, route, opts) {
18
- // console.log('exec',url,route);
19
- if (url == route) return {};
20
- if (url.startsWith(route)) return {};
21
- let reg = /(?:\?([^#]*))?(#.*)?$/,
22
- c = url.match(reg),
23
- matches = {},
24
- ret;
25
- if (c && c[1]) {
26
- let p = c[1].split('&');
27
- for (let i = 0; i < p.length; i++) {
28
- let r = p[i].split('=');
29
- matches[decodeURIComponent(r[0])] = decodeURIComponent(
30
- r.slice(1).join('=')
31
- );
32
- }
33
- }
34
- url = segmentize(url.replace(reg, ''));
35
- route = segmentize(route || '');
36
- let max = Math.min(url.length, route.length);
37
- if (route.length > url.length) max = route.length;
38
- for (let i = 0; i < max; i++) {
39
- if (route[i] && route[i].charAt(0) === ':') {
40
- let param = route[i].replace(/(^:|[+*?]+$)/g, ''),
41
- flags = (route[i].match(/[+*?]+$/) || EMPTY$1)[0] || '',
42
- plus = ~flags.indexOf('+'),
43
- star = ~flags.indexOf('*'),
44
- val = url[i] || '';
45
- if (!val && !star && (flags.indexOf('?') < 0 || plus)) {
46
- ret = false;
47
- break;
48
- }
49
- matches[param] = decodeURIComponent(val);
50
- if (plus || star) {
51
- matches[param] = url.slice(i).map(decodeURIComponent).join('/');
52
- break;
53
- }
54
- }
55
- else if (route[i] !== url[i]) {
56
- ret = false;
57
- break;
58
- }
59
- }
60
- // console.log('exec',url,route,opts,ret);
61
- if (opts.default !== true && ret === false) return false;
62
- return matches;
63
- }
64
- function pathRankSort(a, b) {
65
- return a.rank < b.rank ? 1 : a.rank > b.rank ? -1 : a.index - b.index;
66
- }
67
-
68
- // filter out VNodes without attributes (which are unrankeable), and add `index`/`rank` properties to be used in sorting.
69
- function prepareVNodeForRanking(vnode, index) {
70
- vnode.index = index;
71
- vnode.rank = rankChild(vnode);
72
- return vnode.props;
73
- }
74
- function segmentize(url) {
75
- return url.replace(/(^\/+|\/+$)/g, '').split('/');
76
- }
77
- function rankSegment(segment) {
78
- return segment.charAt(0) == ':'
79
- ? 1 + '*+?'.indexOf(segment.charAt(segment.length - 1)) || 4
80
- : 5;
81
- }
82
- function rank(path) {
83
- return segmentize(path).map(rankSegment).join('');
84
- }
85
- function rankChild(vnode) {
86
- return vnode.props.default ? 0 : rank(vnode.props.path);
87
- }
88
-
89
- function _extends() {
90
- _extends = Object.assign
91
- ? Object.assign.bind()
92
- : function (target) {
93
- for (var i = 1; i < arguments.length; i++) {
94
- var source = arguments[i];
95
- for (var key in source) {
96
- if (Object.prototype.hasOwnProperty.call(source, key)) {
97
- target[key] = source[key];
98
- }
99
- }
100
- }
101
- return target;
102
- };
103
- return _extends.apply(this, arguments);
104
- }
105
-
106
- class Match extends Component {
107
- componentDidMount() {
108
- this.update = (url) => {
109
- this.nextUrl = url;
110
- this.setState({});
111
- };
112
- subscribers$1.push(this.update);
113
- }
114
- componentWillUnmount() {
115
- subscribers$1.splice(subscribers$1.indexOf(this.update) >>> 0, 1);
116
- }
117
- render(props) {
118
- let url = this.nextUrl || getCurrentUrl$1(),
119
- path = url.replace(/\?.+$/, '');
120
- this.nextUrl = null;
121
- // console.log('match',path,props.path);
122
- return props.children({
123
- url,
124
- path,
125
- matches: exec$1(path, props.path, {}) !== false,
126
- });
127
- }
128
- }
129
- const Link$1 = ({ activeClassName, path, ...props }) =>
130
- /*#__PURE__*/ React.createElement(
131
- Match,
132
- {
133
- path: path || props.href,
134
- },
135
- ({ matches }) => {
136
- let cls = [props.class || props.className, matches && activeClassName]
137
- .filter(Boolean)
138
- .join(' ');
139
- // console.log('link cls',activeClassName,matches,props);
140
- return /*#__PURE__*/ React.createElement(
141
- Link$2,
142
- _extends({}, props, {
143
- className: cls,
144
- })
145
- );
146
- }
147
- );
148
-
149
- let customHistory = null;
150
- const ROUTERS = [];
151
- const subscribers = [];
152
- const EMPTY = {};
153
- function setUrl(url, type = 'push') {
154
- if (customHistory && customHistory[type]) {
155
- customHistory[type](url);
156
- }
157
- else if (typeof history !== 'undefined' && history[type + 'State']) {
158
- // console.log('---------------', type);
159
- history[type + 'State'](null, null, url);
160
- }
161
- else;
162
- }
163
- function getCurrentUrl() {
164
- let url;
165
- if (customHistory && customHistory.location) {
166
- url = customHistory.location;
167
- }
168
- else if (customHistory && customHistory.getCurrentLocation) {
169
- url = customHistory.getCurrentLocation();
170
- }
171
- else {
172
- url = typeof location !== 'undefined' ? location : EMPTY;
173
- }
174
- return url.href;
175
- // return `${url.pathname || ''}${url.search || ''}`;
176
- }
177
- function route(url, replace = false) {
178
- if (typeof url !== 'string' && url.url) {
179
- replace = url.replace;
180
- url = url.url;
181
- }
182
-
183
- // only push URL into history if we can handle it
184
- if (canRoute(url)) {
185
- setUrl(url, replace ? 'replace' : 'push');
186
- }
187
- return routeTo(url);
188
- }
189
-
190
- /** Check if the given URL can be handled by any router instances. */
191
- function canRoute(url) {
192
- for (let i = ROUTERS.length; i--; ) {
193
- if (ROUTERS[i].canRoute(url)) return true;
194
- }
195
- return false;
196
- }
197
-
198
- /** Tell all router instances to handle the given URL. */
199
- function routeTo(url) {
200
- let didRoute = false;
201
- for (let i = 0; i < ROUTERS.length; i++) {
202
- if (ROUTERS[i].routeTo(url) === true) {
203
- didRoute = true;
204
- }
205
- }
206
- for (let i = subscribers.length; i--; ) {
207
- subscribers[i](url);
208
- }
209
- return didRoute;
210
- }
211
- function routeFromLink(node) {
212
- // only valid elements
213
- if (!node || !node.getAttribute) return;
214
- let href = node.getAttribute('href'),
215
- target = node.getAttribute('target');
216
-
217
- // ignore links with targets and non-path URLs
218
- if (!href || (target && !target.match(/^_?self$/i))) {
219
- console.log('bypass routeFromLink', href, target);
220
- return;
221
- }
222
-
223
- // attempt to route, if no match simply cede control to browser
224
- return route(href);
225
- }
226
- function handleLinkClick(e) {
227
- if (e.ctrlKey || e.metaKey || e.altKey || e.shiftKey || e.button !== 0) {
228
- console.log('bypass handleLinkClick', e.button);
229
- return;
230
- }
231
- routeFromLink(e.currentTarget || e.target || this);
232
- return prevent(e);
233
- }
234
- function prevent(e) {
235
- if (e) {
236
- if (e.stopImmediatePropagation) e.stopImmediatePropagation();
237
- if (e.stopPropagation) e.stopPropagation();
238
- e.preventDefault();
239
- }
240
- return false;
241
- }
242
- function delegateLinkHandler(e) {
243
- // console.log('delegateLinkHandler',e.button,e.target.nodeName);
244
- // ignore events the browser takes care of already:
245
- if (e.ctrlKey || e.metaKey || e.altKey || e.shiftKey || e.button !== 0)
246
- return;
247
- let t = e.target;
248
- do {
249
- if (String(t.nodeName).toUpperCase() === 'A' && t.getAttribute('href')) {
250
- if (t.hasAttribute('native')) return;
251
- // if link is handled by the router, prevent browser defaults
252
- if (routeFromLink(t)) {
253
- return prevent(e);
254
- }
255
- }
256
- } while ((t = t.parentNode));
257
- }
258
- let eventListenersInitialized = false;
259
- function initEventListeners() {
260
- if (eventListenersInitialized) return;
261
- if (typeof addEventListener === 'function') {
262
- if (!customHistory) {
263
- addEventListener('popstate', () => {
264
- routeTo(getCurrentUrl());
265
- });
266
- }
267
- addEventListener('click', delegateLinkHandler);
268
- }
269
- eventListenersInitialized = true;
270
- }
271
- class Router extends Component {
272
- constructor(props) {
273
- super(props);
274
- if (props.history) {
275
- customHistory = props.history;
276
- }
277
- this.state = {
278
- url: props.url || getCurrentUrl(),
279
- };
280
- initEventListeners();
281
- }
282
- shouldComponentUpdate(props) {
283
- if (props.static !== true) return true;
284
- return (
285
- props.url !== this.props.url || props.onChange !== this.props.onChange
286
- );
287
- }
288
-
289
- /** Check if the given URL can be matched against any children */
290
- canRoute(url) {
291
- const children = toChildArray(this.props.children);
292
- return this.getMatchingChildren(children, url, false).length > 0;
293
- }
294
-
295
- /** Re-render children with a new URL to match against. */
296
- routeTo(url) {
297
- this.setState({
298
- url,
299
- });
300
- const didRoute = this.canRoute(url);
301
-
302
- // trigger a manual re-route if we're not in the middle of an update:
303
- if (!this.updating) this.forceUpdate();
304
- return didRoute;
305
- }
306
- componentWillMount() {
307
- ROUTERS.push(this);
308
- this.updating = true;
309
- }
310
- componentDidMount() {
311
- if (customHistory) {
312
- this.unlisten = customHistory.listen((location) => {
313
- this.routeTo(`${location.pathname || ''}${location.search || ''}`);
314
- });
315
- }
316
- this.updating = false;
317
- }
318
- componentWillUnmount() {
319
- if (typeof this.unlisten === 'function') this.unlisten();
320
- ROUTERS.splice(ROUTERS.indexOf(this), 1);
321
- }
322
- componentWillUpdate() {
323
- this.updating = true;
324
- }
325
- componentDidUpdate() {
326
- this.updating = false;
327
- }
328
- getMatchingChildren(children, url, invoke) {
329
- return children
330
- .filter(prepareVNodeForRanking)
331
- .sort(pathRankSort)
332
- .map((vnode) => {
333
- let matches = exec(url, vnode.props.path, vnode.props);
334
- // console.log('match children1',url,JSON.stringify(matches));
335
- if (matches) {
336
- if (invoke !== false) {
337
- let newProps = {
338
- url,
339
- matches,
340
- };
341
- assign(newProps, matches);
342
- delete newProps.ref;
343
- delete newProps.key;
344
- // console.log('match children2',vnode,newProps);
345
- return cloneElement(vnode, newProps);
346
- }
347
- return vnode;
348
- }
349
- })
350
- .filter(Boolean);
351
- }
352
- render({ children, onChange }, { url }) {
353
- let active = this.getMatchingChildren(toChildArray(children), url, true);
354
- // console.log('Router render', url, active);
355
- let current = active[0] || null;
356
- let previous = this.previousUrl;
357
- if (url !== previous) {
358
- this.previousUrl = url;
359
- if (typeof onChange === 'function') {
360
- onChange({
361
- router: this,
362
- url,
363
- previous,
364
- active,
365
- current,
366
- });
367
- }
368
- }
369
- return current;
370
- }
371
- }
372
- const Link = (props) =>
373
- createElement(
374
- 'a',
375
- assign(
376
- {
377
- onClick: handleLinkClick,
378
- },
379
- props
380
- )
381
- );
382
- const Route = (props) => createElement(props.component, props);
383
-
384
- export {
385
- Link,
386
- Match,
387
- Link$1 as Mlink,
388
- Route,
389
- Router,
390
- Router as default,
391
- exec,
392
- getCurrentUrl,
393
- route,
394
- subscribers,
395
- };
1
+ import { Component, toChildArray, cloneElement, createElement } from 'preact';
2
+ import {
3
+ subscribers as subscribers$1,
4
+ getCurrentUrl as getCurrentUrl$1,
5
+ exec as exec$1,
6
+ Link as Link$2,
7
+ } from './preact-router';
8
+
9
+ const EMPTY$1 = {};
10
+ function assign(obj, props) {
11
+ // eslint-disable-next-line guard-for-in
12
+ for (let i in props) {
13
+ obj[i] = props[i];
14
+ }
15
+ return obj;
16
+ }
17
+ function exec(url, route, opts) {
18
+ // console.log('exec',url,route);
19
+ if (url == route) return {};
20
+ if (url.startsWith(route)) return {};
21
+ let reg = /(?:\?([^#]*))?(#.*)?$/,
22
+ c = url.match(reg),
23
+ matches = {},
24
+ ret;
25
+ if (c && c[1]) {
26
+ let p = c[1].split('&');
27
+ for (let i = 0; i < p.length; i++) {
28
+ let r = p[i].split('=');
29
+ matches[decodeURIComponent(r[0])] = decodeURIComponent(
30
+ r.slice(1).join('=')
31
+ );
32
+ }
33
+ }
34
+ url = segmentize(url.replace(reg, ''));
35
+ route = segmentize(route || '');
36
+ let max = Math.min(url.length, route.length);
37
+ if (route.length > url.length) max = route.length;
38
+ for (let i = 0; i < max; i++) {
39
+ if (route[i] && route[i].charAt(0) === ':') {
40
+ let param = route[i].replace(/(^:|[+*?]+$)/g, ''),
41
+ flags = (route[i].match(/[+*?]+$/) || EMPTY$1)[0] || '',
42
+ plus = ~flags.indexOf('+'),
43
+ star = ~flags.indexOf('*'),
44
+ val = url[i] || '';
45
+ if (!val && !star && (flags.indexOf('?') < 0 || plus)) {
46
+ ret = false;
47
+ break;
48
+ }
49
+ matches[param] = decodeURIComponent(val);
50
+ if (plus || star) {
51
+ matches[param] = url.slice(i).map(decodeURIComponent).join('/');
52
+ break;
53
+ }
54
+ }
55
+ else if (route[i] !== url[i]) {
56
+ ret = false;
57
+ break;
58
+ }
59
+ }
60
+ // console.log('exec',url,route,opts,ret);
61
+ if (opts.default !== true && ret === false) return false;
62
+ return matches;
63
+ }
64
+ function pathRankSort(a, b) {
65
+ return a.rank < b.rank ? 1 : a.rank > b.rank ? -1 : a.index - b.index;
66
+ }
67
+
68
+ // filter out VNodes without attributes (which are unrankeable), and add `index`/`rank` properties to be used in sorting.
69
+ function prepareVNodeForRanking(vnode, index) {
70
+ vnode.index = index;
71
+ vnode.rank = rankChild(vnode);
72
+ return vnode.props;
73
+ }
74
+ function segmentize(url) {
75
+ return url.replace(/(^\/+|\/+$)/g, '').split('/');
76
+ }
77
+ function rankSegment(segment) {
78
+ return segment.charAt(0) == ':'
79
+ ? 1 + '*+?'.indexOf(segment.charAt(segment.length - 1)) || 4
80
+ : 5;
81
+ }
82
+ function rank(path) {
83
+ return segmentize(path).map(rankSegment).join('');
84
+ }
85
+ function rankChild(vnode) {
86
+ return vnode.props.default ? 0 : rank(vnode.props.path);
87
+ }
88
+
89
+ function _extends() {
90
+ _extends = Object.assign
91
+ ? Object.assign.bind()
92
+ : function (target) {
93
+ for (var i = 1; i < arguments.length; i++) {
94
+ var source = arguments[i];
95
+ for (var key in source) {
96
+ if (Object.prototype.hasOwnProperty.call(source, key)) {
97
+ target[key] = source[key];
98
+ }
99
+ }
100
+ }
101
+ return target;
102
+ };
103
+ return _extends.apply(this, arguments);
104
+ }
105
+
106
+ class Match extends Component {
107
+ componentDidMount() {
108
+ this.update = (url) => {
109
+ this.nextUrl = url;
110
+ this.setState({});
111
+ };
112
+ subscribers$1.push(this.update);
113
+ }
114
+ componentWillUnmount() {
115
+ subscribers$1.splice(subscribers$1.indexOf(this.update) >>> 0, 1);
116
+ }
117
+ render(props) {
118
+ let url = this.nextUrl || getCurrentUrl$1(),
119
+ path = url.replace(/\?.+$/, '');
120
+ this.nextUrl = null;
121
+ // console.log('match',path,props.path);
122
+ return props.children({
123
+ url,
124
+ path,
125
+ matches: exec$1(path, props.path, {}) !== false,
126
+ });
127
+ }
128
+ }
129
+ const Link$1 = ({ activeClassName, path, ...props }) =>
130
+ /*#__PURE__*/ React.createElement(
131
+ Match,
132
+ {
133
+ path: path || props.href,
134
+ },
135
+ ({ matches }) => {
136
+ let cls = [props.class || props.className, matches && activeClassName]
137
+ .filter(Boolean)
138
+ .join(' ');
139
+ // console.log('link cls',activeClassName,matches,props);
140
+ return /*#__PURE__*/ React.createElement(
141
+ Link$2,
142
+ _extends({}, props, {
143
+ className: cls,
144
+ })
145
+ );
146
+ }
147
+ );
148
+
149
+ let customHistory = null;
150
+ const ROUTERS = [];
151
+ const subscribers = [];
152
+ const EMPTY = {};
153
+ function setUrl(url, type = 'push') {
154
+ if (customHistory && customHistory[type]) {
155
+ customHistory[type](url);
156
+ }
157
+ else if (typeof history !== 'undefined' && history[type + 'State']) {
158
+ // console.log('---------------', type);
159
+ history[type + 'State'](null, null, url);
160
+ }
161
+ else;
162
+ }
163
+ function getCurrentUrl() {
164
+ let url;
165
+ if (customHistory && customHistory.location) {
166
+ url = customHistory.location;
167
+ }
168
+ else if (customHistory && customHistory.getCurrentLocation) {
169
+ url = customHistory.getCurrentLocation();
170
+ }
171
+ else {
172
+ url = typeof location !== 'undefined' ? location : EMPTY;
173
+ }
174
+ return url.href;
175
+ // return `${url.pathname || ''}${url.search || ''}`;
176
+ }
177
+ function route(url, replace = false) {
178
+ if (typeof url !== 'string' && url.url) {
179
+ replace = url.replace;
180
+ url = url.url;
181
+ }
182
+
183
+ // only push URL into history if we can handle it
184
+ if (canRoute(url)) {
185
+ setUrl(url, replace ? 'replace' : 'push');
186
+ }
187
+ return routeTo(url);
188
+ }
189
+
190
+ /** Check if the given URL can be handled by any router instances. */
191
+ function canRoute(url) {
192
+ for (let i = ROUTERS.length; i--; ) {
193
+ if (ROUTERS[i].canRoute(url)) return true;
194
+ }
195
+ return false;
196
+ }
197
+
198
+ /** Tell all router instances to handle the given URL. */
199
+ function routeTo(url) {
200
+ let didRoute = false;
201
+ for (let i = 0; i < ROUTERS.length; i++) {
202
+ if (ROUTERS[i].routeTo(url) === true) {
203
+ didRoute = true;
204
+ }
205
+ }
206
+ for (let i = subscribers.length; i--; ) {
207
+ subscribers[i](url);
208
+ }
209
+ return didRoute;
210
+ }
211
+ function routeFromLink(node) {
212
+ // only valid elements
213
+ if (!node || !node.getAttribute) return;
214
+ let href = node.getAttribute('href'),
215
+ target = node.getAttribute('target');
216
+
217
+ // ignore links with targets and non-path URLs
218
+ if (!href || (target && !target.match(/^_?self$/i))) {
219
+ console.log('bypass routeFromLink', href, target);
220
+ return;
221
+ }
222
+
223
+ // attempt to route, if no match simply cede control to browser
224
+ return route(href);
225
+ }
226
+ function handleLinkClick(e) {
227
+ if (e.ctrlKey || e.metaKey || e.altKey || e.shiftKey || e.button !== 0) {
228
+ console.log('bypass handleLinkClick', e.button);
229
+ return;
230
+ }
231
+ routeFromLink(e.currentTarget || e.target || this);
232
+ return prevent(e);
233
+ }
234
+ function prevent(e) {
235
+ if (e) {
236
+ if (e.stopImmediatePropagation) e.stopImmediatePropagation();
237
+ if (e.stopPropagation) e.stopPropagation();
238
+ e.preventDefault();
239
+ }
240
+ return false;
241
+ }
242
+ function delegateLinkHandler(e) {
243
+ // console.log('delegateLinkHandler',e.button,e.target.nodeName);
244
+ // ignore events the browser takes care of already:
245
+ if (e.ctrlKey || e.metaKey || e.altKey || e.shiftKey || e.button !== 0)
246
+ return;
247
+ let t = e.target;
248
+ do {
249
+ if (String(t.nodeName).toUpperCase() === 'A' && t.getAttribute('href')) {
250
+ if (t.hasAttribute('native')) return;
251
+ // if link is handled by the router, prevent browser defaults
252
+ if (routeFromLink(t)) {
253
+ return prevent(e);
254
+ }
255
+ }
256
+ } while ((t = t.parentNode));
257
+ }
258
+ let eventListenersInitialized = false;
259
+ function initEventListeners() {
260
+ if (eventListenersInitialized) return;
261
+ if (typeof addEventListener === 'function') {
262
+ if (!customHistory) {
263
+ addEventListener('popstate', () => {
264
+ routeTo(getCurrentUrl());
265
+ });
266
+ }
267
+ addEventListener('click', delegateLinkHandler);
268
+ }
269
+ eventListenersInitialized = true;
270
+ }
271
+ class Router extends Component {
272
+ constructor(props) {
273
+ super(props);
274
+ if (props.history) {
275
+ customHistory = props.history;
276
+ }
277
+ this.state = {
278
+ url: props.url || getCurrentUrl(),
279
+ };
280
+ initEventListeners();
281
+ }
282
+ shouldComponentUpdate(props) {
283
+ if (props.static !== true) return true;
284
+ return (
285
+ props.url !== this.props.url || props.onChange !== this.props.onChange
286
+ );
287
+ }
288
+
289
+ /** Check if the given URL can be matched against any children */
290
+ canRoute(url) {
291
+ const children = toChildArray(this.props.children);
292
+ return this.getMatchingChildren(children, url, false).length > 0;
293
+ }
294
+
295
+ /** Re-render children with a new URL to match against. */
296
+ routeTo(url) {
297
+ this.setState({
298
+ url,
299
+ });
300
+ const didRoute = this.canRoute(url);
301
+
302
+ // trigger a manual re-route if we're not in the middle of an update:
303
+ if (!this.updating) this.forceUpdate();
304
+ return didRoute;
305
+ }
306
+ componentWillMount() {
307
+ ROUTERS.push(this);
308
+ this.updating = true;
309
+ }
310
+ componentDidMount() {
311
+ if (customHistory) {
312
+ this.unlisten = customHistory.listen((location) => {
313
+ this.routeTo(`${location.pathname || ''}${location.search || ''}`);
314
+ });
315
+ }
316
+ this.updating = false;
317
+ }
318
+ componentWillUnmount() {
319
+ if (typeof this.unlisten === 'function') this.unlisten();
320
+ ROUTERS.splice(ROUTERS.indexOf(this), 1);
321
+ }
322
+ componentWillUpdate() {
323
+ this.updating = true;
324
+ }
325
+ componentDidUpdate() {
326
+ this.updating = false;
327
+ }
328
+ getMatchingChildren(children, url, invoke) {
329
+ return children
330
+ .filter(prepareVNodeForRanking)
331
+ .sort(pathRankSort)
332
+ .map((vnode) => {
333
+ let matches = exec(url, vnode.props.path, vnode.props);
334
+ // console.log('match children1',url,JSON.stringify(matches));
335
+ if (matches) {
336
+ if (invoke !== false) {
337
+ let newProps = {
338
+ url,
339
+ matches,
340
+ };
341
+ assign(newProps, matches);
342
+ delete newProps.ref;
343
+ delete newProps.key;
344
+ // console.log('match children2',vnode,newProps);
345
+ return cloneElement(vnode, newProps);
346
+ }
347
+ return vnode;
348
+ }
349
+ })
350
+ .filter(Boolean);
351
+ }
352
+ render({ children, onChange }, { url }) {
353
+ let active = this.getMatchingChildren(toChildArray(children), url, true);
354
+ // console.log('Router render', url, active);
355
+ let current = active[0] || null;
356
+ let previous = this.previousUrl;
357
+ if (url !== previous) {
358
+ this.previousUrl = url;
359
+ if (typeof onChange === 'function') {
360
+ onChange({
361
+ router: this,
362
+ url,
363
+ previous,
364
+ active,
365
+ current,
366
+ });
367
+ }
368
+ }
369
+ return current;
370
+ }
371
+ }
372
+ const Link = (props) =>
373
+ createElement(
374
+ 'a',
375
+ assign(
376
+ {
377
+ onClick: handleLinkClick,
378
+ },
379
+ props
380
+ )
381
+ );
382
+ const Route = (props) => createElement(props.component, props);
383
+
384
+ export {
385
+ Link,
386
+ Match,
387
+ Link$1 as Mlink,
388
+ Route,
389
+ Router,
390
+ Router as default,
391
+ exec,
392
+ getCurrentUrl,
393
+ route,
394
+ subscribers,
395
+ };