@pixui-dev/pxw 0.1.16

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 (128) hide show
  1. package/bin/pxw.js +217 -0
  2. package/bin/wpbuild.js +10 -0
  3. package/config/default.conf +21 -0
  4. package/config/devops.js +358 -0
  5. package/config/h5es.js +10 -0
  6. package/config/index.html +181 -0
  7. package/config/pfbs.js +207 -0
  8. package/config/testhelp.js +0 -0
  9. package/config/util.js +140 -0
  10. package/config/webpack.js +291 -0
  11. package/lib/assets/border.png +0 -0
  12. package/lib/assets/check.html +62 -0
  13. package/lib/assets/pixui.png +0 -0
  14. package/lib/assets/preact.js +4354 -0
  15. package/lib/assets/preact.png +0 -0
  16. package/lib/check/main.less +63 -0
  17. package/lib/check/main.tsx +41 -0
  18. package/lib/check/tool.js +3 -0
  19. package/lib/check/util.tsx +110 -0
  20. package/lib/grpc-web/dist/ChunkParser.js +117 -0
  21. package/lib/grpc-web/dist/ChunkParser.js.map +1 -0
  22. package/lib/grpc-web/dist/Code.js +58 -0
  23. package/lib/grpc-web/dist/Code.js.map +1 -0
  24. package/lib/grpc-web/dist/client.js +299 -0
  25. package/lib/grpc-web/dist/client.js.map +1 -0
  26. package/lib/grpc-web/dist/debug.js +16 -0
  27. package/lib/grpc-web/dist/debug.js.map +1 -0
  28. package/lib/grpc-web/dist/detach.js +7 -0
  29. package/lib/grpc-web/dist/detach.js.map +1 -0
  30. package/lib/grpc-web/dist/index.js +29 -0
  31. package/lib/grpc-web/dist/index.js.map +1 -0
  32. package/lib/grpc-web/dist/invoke.js +32 -0
  33. package/lib/grpc-web/dist/invoke.js.map +1 -0
  34. package/lib/grpc-web/dist/message.js +3 -0
  35. package/lib/grpc-web/dist/message.js.map +1 -0
  36. package/lib/grpc-web/dist/metadata.js +5 -0
  37. package/lib/grpc-web/dist/metadata.js.map +1 -0
  38. package/lib/grpc-web/dist/service.js +3 -0
  39. package/lib/grpc-web/dist/service.js.map +1 -0
  40. package/lib/grpc-web/dist/transports/Transport.js +15 -0
  41. package/lib/grpc-web/dist/transports/Transport.js.map +1 -0
  42. package/lib/grpc-web/dist/transports/http/fetch.js +117 -0
  43. package/lib/grpc-web/dist/transports/http/fetch.js.map +1 -0
  44. package/lib/grpc-web/dist/transports/http/http.js +15 -0
  45. package/lib/grpc-web/dist/transports/http/http.js.map +1 -0
  46. package/lib/grpc-web/dist/transports/http/xhr.js +136 -0
  47. package/lib/grpc-web/dist/transports/http/xhr.js.map +1 -0
  48. package/lib/grpc-web/dist/transports/http/xhrUtil.js +36 -0
  49. package/lib/grpc-web/dist/transports/http/xhrUtil.js.map +1 -0
  50. package/lib/grpc-web/dist/transports/websocket/websocket.js +95 -0
  51. package/lib/grpc-web/dist/transports/websocket/websocket.js.map +1 -0
  52. package/lib/grpc-web/dist/typings/ChunkParser.d.ts +17 -0
  53. package/lib/grpc-web/dist/typings/Code.d.ts +20 -0
  54. package/lib/grpc-web/dist/typings/client.d.ts +25 -0
  55. package/lib/grpc-web/dist/typings/debug.d.ts +1 -0
  56. package/lib/grpc-web/dist/typings/detach.d.ts +1 -0
  57. package/lib/grpc-web/dist/typings/index.d.ts +45 -0
  58. package/lib/grpc-web/dist/typings/invoke.d.ts +20 -0
  59. package/lib/grpc-web/dist/typings/message.d.ts +8 -0
  60. package/lib/grpc-web/dist/typings/metadata.d.ts +2 -0
  61. package/lib/grpc-web/dist/typings/service.d.ts +16 -0
  62. package/lib/grpc-web/dist/typings/transports/Transport.d.ts +22 -0
  63. package/lib/grpc-web/dist/typings/transports/http/fetch.d.ts +6 -0
  64. package/lib/grpc-web/dist/typings/transports/http/http.d.ts +5 -0
  65. package/lib/grpc-web/dist/typings/transports/http/xhr.d.ts +27 -0
  66. package/lib/grpc-web/dist/typings/transports/http/xhrUtil.d.ts +3 -0
  67. package/lib/grpc-web/dist/typings/transports/websocket/websocket.d.ts +2 -0
  68. package/lib/grpc-web/dist/typings/unary.d.ts +23 -0
  69. package/lib/grpc-web/dist/typings/util.d.ts +2 -0
  70. package/lib/grpc-web/dist/unary.js +44 -0
  71. package/lib/grpc-web/dist/unary.js.map +1 -0
  72. package/lib/grpc-web/dist/util.js +11 -0
  73. package/lib/grpc-web/dist/util.js.map +1 -0
  74. package/lib/grpcTransport/PixHttp2Transport.ts +107 -0
  75. package/lib/grpcTransport/PixLuaTransport.ts +82 -0
  76. package/lib/h5es-types/v1.9.2/h5es.d.ts +1698 -0
  77. package/lib/h5es-types/v3.5.0/h5es.d.ts +1788 -0
  78. package/lib/pi_component/tinyList/tinyList.js +483 -0
  79. package/lib/pi_component/tinyList/tinyList.tsx +517 -0
  80. package/lib/pika-svelte/compiler.js +29829 -0
  81. package/lib/pika-svelte/easing/index.js +158 -0
  82. package/lib/pika-svelte/index.js +72 -0
  83. package/lib/pika-svelte/internal/index.js +1926 -0
  84. package/lib/pika-svelte/motion/index.js +210 -0
  85. package/lib/pika-svelte/package.json +145 -0
  86. package/lib/pika-svelte/register.js +57 -0
  87. package/lib/pika-svelte/rollup.config.js +126 -0
  88. package/lib/pika-svelte/store/index.js +123 -0
  89. package/lib/pika-svelte/transition/index.js +185 -0
  90. package/lib/preact-router.js +395 -0
  91. package/lib/preact.js +4355 -0
  92. package/lib/preact.tq.js +4385 -0
  93. package/lib/react-window/src/FixedSizeGrid.js +172 -0
  94. package/lib/react-window/src/FixedSizeList.js +91 -0
  95. package/lib/react-window/src/VariableSizeGrid.js +329 -0
  96. package/lib/react-window/src/VariableSizeList.js +231 -0
  97. package/lib/react-window/src/__tests__/FixedSizeGrid.js +942 -0
  98. package/lib/react-window/src/__tests__/FixedSizeList.js +749 -0
  99. package/lib/react-window/src/__tests__/VariableSizeGrid.js +598 -0
  100. package/lib/react-window/src/__tests__/VariableSizeList.js +345 -0
  101. package/lib/react-window/src/__tests__/__snapshots__/FixedSizeGrid.js.snap +912 -0
  102. package/lib/react-window/src/__tests__/__snapshots__/FixedSizeList.js.snap +568 -0
  103. package/lib/react-window/src/__tests__/__snapshots__/VariableSizeGrid.js.snap +542 -0
  104. package/lib/react-window/src/__tests__/__snapshots__/VariableSizeList.js.snap +331 -0
  105. package/lib/react-window/src/__tests__/areEqual.js +28 -0
  106. package/lib/react-window/src/__tests__/shouldComponentUpdate.js +32 -0
  107. package/lib/react-window/src/areEqual.js +13 -0
  108. package/lib/react-window/src/createGridComponent.js +657 -0
  109. package/lib/react-window/src/createListComponent.js +574 -0
  110. package/lib/react-window/src/domHelpers.js +69 -0
  111. package/lib/react-window/src/index.js +9 -0
  112. package/lib/react-window/src/shallowDiffers.js +17 -0
  113. package/lib/react-window/src/shouldComponentUpdate.js +11 -0
  114. package/lib/react-window/src/test.js.flow +382 -0
  115. package/lib/react-window/src/timer.js +36 -0
  116. package/lib/svelte-tab/Tab.svelte +31 -0
  117. package/lib/svelte-tab/TabList.svelte +10 -0
  118. package/lib/svelte-tab/TabPanel.svelte +13 -0
  119. package/lib/svelte-tab/Tabs.svelte +68 -0
  120. package/lib/svelte-tab/tabs.js +4 -0
  121. package/lib/types/css.d.ts +7476 -0
  122. package/lib/types/dom.ts +17 -0
  123. package/lib/types/ext.d.ts +81 -0
  124. package/lib/types/internal.d.ts +94 -0
  125. package/lib/types/jsx.d.ts +309 -0
  126. package/lib/types/preact.d.ts +340 -0
  127. package/package.json +111 -0
  128. package/tsconfig.json +30 -0
@@ -0,0 +1,185 @@
1
+ 'use strict';
2
+
3
+ Object.defineProperty(exports, '__esModule', { value: true });
4
+
5
+ var easing = require('../easing/index.js');
6
+ var internal = require('../internal/index.js');
7
+
8
+ /*! *****************************************************************************
9
+ Copyright (c) Microsoft Corporation.
10
+
11
+ Permission to use, copy, modify, and/or distribute this software for any
12
+ purpose with or without fee is hereby granted.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
15
+ REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
16
+ AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
17
+ INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
18
+ LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
19
+ OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
20
+ PERFORMANCE OF THIS SOFTWARE.
21
+ ***************************************************************************** */
22
+
23
+ function __rest(s, e) {
24
+ var t = {};
25
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0) t[p] = s[p];
26
+ if (s != null && typeof Object.getOwnPropertySymbols === 'function')
27
+ for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
28
+ if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i])) t[p[i]] = s[p[i]];
29
+ }
30
+ return t;
31
+ }
32
+
33
+ function blur(node, { delay = 0, duration = 400, easing: easing$1 = easing.cubicInOut, amount = 5, opacity = 0 } = {}) {
34
+ const style = getComputedStyle(node);
35
+ const target_opacity = +style.opacity;
36
+ const f = style.filter === 'none' ? '' : style.filter;
37
+ const od = target_opacity * (1 - opacity);
38
+ return {
39
+ delay,
40
+ duration,
41
+ easing: easing$1,
42
+ css: (_t, u) => `opacity: ${target_opacity - od * u}; filter: ${f} blur(${u * amount}px);`,
43
+ };
44
+ }
45
+ function fade(node, { delay = 0, duration = 400, easing: easing$1 = easing.linear } = {}) {
46
+ const o = +getComputedStyle(node).opacity;
47
+ return {
48
+ delay,
49
+ duration,
50
+ easing: easing$1,
51
+ css: (t) => `opacity: ${t * o}`,
52
+ };
53
+ }
54
+ function fly(node, { delay = 0, duration = 400, easing: easing$1 = easing.cubicOut, x = 0, y = 0, opacity = 0 } = {}) {
55
+ const style = getComputedStyle(node);
56
+ const target_opacity = +style.opacity;
57
+ const transform = style.transform === 'none' ? '' : style.transform;
58
+ const od = target_opacity * (1 - opacity);
59
+ return {
60
+ delay,
61
+ duration,
62
+ easing: easing$1,
63
+ css: (t, u) => `
64
+ transform: ${transform} translate(${(1 - t) * x}px, ${(1 - t) * y}px);
65
+ opacity: ${target_opacity - od * u}`,
66
+ };
67
+ }
68
+ function slide(node, { delay = 0, duration = 400, easing: easing$1 = easing.cubicOut } = {}) {
69
+ const style = getComputedStyle(node);
70
+ const opacity = +style.opacity;
71
+ const height = parseFloat(style.height);
72
+ const padding_top = parseFloat(style.paddingTop);
73
+ const padding_bottom = parseFloat(style.paddingBottom);
74
+ const margin_top = parseFloat(style.marginTop);
75
+ const margin_bottom = parseFloat(style.marginBottom);
76
+ const border_top_width = parseFloat(style.borderTopWidth);
77
+ const border_bottom_width = parseFloat(style.borderBottomWidth);
78
+ return {
79
+ delay,
80
+ duration,
81
+ easing: easing$1,
82
+ css: (t) =>
83
+ 'overflow: hidden;' +
84
+ `opacity: ${Math.min(t * 20, 1) * opacity};` +
85
+ `height: ${t * height}px;` +
86
+ `padding-top: ${t * padding_top}px;` +
87
+ `padding-bottom: ${t * padding_bottom}px;` +
88
+ `margin-top: ${t * margin_top}px;` +
89
+ `margin-bottom: ${t * margin_bottom}px;` +
90
+ `border-top-width: ${t * border_top_width}px;` +
91
+ `border-bottom-width: ${t * border_bottom_width}px;`,
92
+ };
93
+ }
94
+ function scale(node, { delay = 0, duration = 400, easing: easing$1 = easing.cubicOut, start = 0, opacity = 0 } = {}) {
95
+ const style = getComputedStyle(node);
96
+ const target_opacity = +style.opacity;
97
+ const transform = style.transform === 'none' ? '' : style.transform;
98
+ const sd = 1 - start;
99
+ const od = target_opacity * (1 - opacity);
100
+ return {
101
+ delay,
102
+ duration,
103
+ easing: easing$1,
104
+ css: (_t, u) => `
105
+ transform: ${transform} scale(${1 - sd * u});
106
+ opacity: ${target_opacity - od * u}
107
+ `,
108
+ };
109
+ }
110
+ function draw(node, { delay = 0, speed, duration, easing: easing$1 = easing.cubicInOut } = {}) {
111
+ const len = node.getTotalLength();
112
+ if (duration === undefined) {
113
+ if (speed === undefined) {
114
+ duration = 800;
115
+ }
116
+ else {
117
+ duration = len / speed;
118
+ }
119
+ }
120
+ else if (typeof duration === 'function') {
121
+ duration = duration(len);
122
+ }
123
+ return {
124
+ delay,
125
+ duration,
126
+ easing: easing$1,
127
+ css: (t, u) => `stroke-dasharray: ${t * len} ${u * len}`,
128
+ };
129
+ }
130
+ function crossfade(_a) {
131
+ var { fallback } = _a,
132
+ defaults = __rest(_a, ['fallback']);
133
+ const to_receive = new Map();
134
+ const to_send = new Map();
135
+ function crossfade(from, node, params) {
136
+ const { delay = 0, duration = (d) => Math.sqrt(d) * 30, easing: easing$1 = easing.cubicOut } = internal.assign(internal.assign({}, defaults), params);
137
+ const to = node.getBoundingClientRect();
138
+ const dx = from.left - to.left;
139
+ const dy = from.top - to.top;
140
+ const dw = from.width / to.width;
141
+ const dh = from.height / to.height;
142
+ const d = Math.sqrt(dx * dx + dy * dy);
143
+ const style = getComputedStyle(node);
144
+ const transform = style.transform === 'none' ? '' : style.transform;
145
+ const opacity = +style.opacity;
146
+ return {
147
+ delay,
148
+ duration: internal.is_function(duration) ? duration(d) : duration,
149
+ easing: easing$1,
150
+ css: (t, u) => `
151
+ opacity: ${t * opacity};
152
+ transform-origin: top left;
153
+ transform: ${transform} translate(${u * dx}px,${u * dy}px) scale(${t + (1 - t) * dw}, ${t + (1 - t) * dh});
154
+ `,
155
+ };
156
+ }
157
+ function transition(items, counterparts, intro) {
158
+ return (node, params) => {
159
+ items.set(params.key, {
160
+ rect: node.getBoundingClientRect(),
161
+ });
162
+ return () => {
163
+ if (counterparts.has(params.key)) {
164
+ const { rect } = counterparts.get(params.key);
165
+ counterparts.delete(params.key);
166
+ return crossfade(rect, node, params);
167
+ }
168
+ // if the node is disappearing altogether
169
+ // (i.e. wasn't claimed by the other list)
170
+ // then we need to supply an outro
171
+ items.delete(params.key);
172
+ return fallback && fallback(node, params, intro);
173
+ };
174
+ };
175
+ }
176
+ return [transition(to_send, to_receive, false), transition(to_receive, to_send, true)];
177
+ }
178
+
179
+ exports.blur = blur;
180
+ exports.crossfade = crossfade;
181
+ exports.draw = draw;
182
+ exports.fade = fade;
183
+ exports.fly = fly;
184
+ exports.scale = scale;
185
+ exports.slide = slide;
@@ -0,0 +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
+ };