@spcsn/taro-runtime 0.1.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 +174 -0
- package/README.md +49 -0
- package/dist/bom/URL.d.ts +51 -0
- package/dist/bom/URL.js +188 -0
- package/dist/bom/URL.js.map +1 -0
- package/dist/bom/URLSearchParams.d.ts +1 -0
- package/dist/bom/URLSearchParams.js +103 -0
- package/dist/bom/URLSearchParams.js.map +1 -0
- package/dist/bom/document.d.ts +3 -0
- package/dist/bom/document.js +93 -0
- package/dist/bom/document.js.map +1 -0
- package/dist/bom/getComputedStyle.d.ts +4 -0
- package/dist/bom/getComputedStyle.js +9 -0
- package/dist/bom/getComputedStyle.js.map +1 -0
- package/dist/bom/history.d.ts +30 -0
- package/dist/bom/history.js +108 -0
- package/dist/bom/history.js.map +1 -0
- package/dist/bom/location.d.ts +37 -0
- package/dist/bom/location.js +200 -0
- package/dist/bom/location.js.map +1 -0
- package/dist/bom/navigator.d.ts +1 -0
- package/dist/bom/navigator.js +22 -0
- package/dist/bom/navigator.js.map +1 -0
- package/dist/bom/raf.d.ts +4 -0
- package/dist/bom/raf.js +28 -0
- package/dist/bom/raf.js.map +1 -0
- package/dist/bom/window.d.ts +23 -0
- package/dist/bom/window.js +74 -0
- package/dist/bom/window.js.map +1 -0
- package/dist/constants/index.d.ts +57 -0
- package/dist/constants/index.js +63 -0
- package/dist/constants/index.js.map +1 -0
- package/dist/current.d.ts +19 -0
- package/dist/current.js +11 -0
- package/dist/current.js.map +1 -0
- package/dist/dom/anchor-element.d.ts +13 -0
- package/dist/dom/anchor-element.js +42 -0
- package/dist/dom/anchor-element.js.map +1 -0
- package/dist/dom/class-list.d.ts +16 -0
- package/dist/dom/class-list.js +79 -0
- package/dist/dom/class-list.js.map +1 -0
- package/dist/dom/document.d.ts +21 -0
- package/dist/dom/document.js +74 -0
- package/dist/dom/document.js.map +1 -0
- package/dist/dom/element.d.ts +39 -0
- package/dist/dom/element.js +261 -0
- package/dist/dom/element.js.map +1 -0
- package/dist/dom/event-source.d.ts +7 -0
- package/dist/dom/event-source.js +18 -0
- package/dist/dom/event-source.js.map +1 -0
- package/dist/dom/event-target.d.ts +8 -0
- package/dist/dom/event-target.js +72 -0
- package/dist/dom/event-target.js.map +1 -0
- package/dist/dom/event.d.ts +24 -0
- package/dist/dom/event.js +124 -0
- package/dist/dom/event.js.map +1 -0
- package/dist/dom/form.d.ts +9 -0
- package/dist/dom/form.js +30 -0
- package/dist/dom/form.js.map +1 -0
- package/dist/dom/node.d.ts +76 -0
- package/dist/dom/node.js +213 -0
- package/dist/dom/node.js.map +1 -0
- package/dist/dom/node_types.d.ts +10 -0
- package/dist/dom/root.d.ts +16 -0
- package/dist/dom/root.js +127 -0
- package/dist/dom/root.js.map +1 -0
- package/dist/dom/style.d.ts +14 -0
- package/dist/dom/style.js +138 -0
- package/dist/dom/style.js.map +1 -0
- package/dist/dom/style_properties.d.ts +3 -0
- package/dist/dom/style_properties.js +374 -0
- package/dist/dom/style_properties.js.map +1 -0
- package/dist/dom/svg.d.ts +3 -0
- package/dist/dom/svg.js +7 -0
- package/dist/dom/svg.js.map +1 -0
- package/dist/dom/text.d.ts +14 -0
- package/dist/dom/text.js +43 -0
- package/dist/dom/text.js.map +1 -0
- package/dist/dom/transfer.d.ts +7 -0
- package/dist/dom/transfer.js +16 -0
- package/dist/dom/transfer.js.map +1 -0
- package/dist/dom/tree.d.ts +4 -0
- package/dist/dom/tree.js +31 -0
- package/dist/dom/tree.js.map +1 -0
- package/dist/dom-external/element.d.ts +3 -0
- package/dist/dom-external/index.d.ts +1 -0
- package/dist/dom-external/mutation-observer/implements.d.ts +52 -0
- package/dist/dom-external/mutation-observer/implements.js +101 -0
- package/dist/dom-external/mutation-observer/implements.js.map +1 -0
- package/dist/dom-external/mutation-observer/index.d.ts +13 -0
- package/dist/dom-external/mutation-observer/index.js +32 -0
- package/dist/dom-external/mutation-observer/index.js.map +1 -0
- package/dist/dom-external/mutation-observer/record.d.ts +24 -0
- package/dist/dom-external/node.d.ts +5 -0
- package/dist/dsl/common.d.ts +14 -0
- package/dist/dsl/common.js +278 -0
- package/dist/dsl/common.js.map +1 -0
- package/dist/dsl/instance.d.ts +92 -0
- package/dist/emitter/emitter.d.ts +4 -0
- package/dist/emitter/emitter.js +7 -0
- package/dist/emitter/emitter.js.map +1 -0
- package/dist/env.d.ts +7 -0
- package/dist/env.js +10 -0
- package/dist/env.js.map +1 -0
- package/dist/hydrate.d.ts +10 -0
- package/dist/hydrate.js +62 -0
- package/dist/hydrate.js.map +1 -0
- package/dist/index.cjs.d.ts +35 -0
- package/dist/index.cjs.js +3776 -0
- package/dist/index.cjs.js.map +1 -0
- package/dist/index.d.ts +35 -0
- package/dist/index.js +34 -0
- package/dist/interface/animate.d.ts +81 -0
- package/dist/interface/element.d.ts +4 -0
- package/dist/interface/event-target.d.ts +11 -0
- package/dist/interface/event.d.ts +15 -0
- package/dist/interface/hydrate.d.ts +30 -0
- package/dist/interface/index.d.ts +8 -0
- package/dist/interface/node.d.ts +7 -0
- package/dist/interface/options.d.ts +5 -0
- package/dist/interface/utils.d.ts +2 -0
- package/dist/next-tick.d.ts +2 -0
- package/dist/next-tick.js +35 -0
- package/dist/next-tick.js.map +1 -0
- package/dist/options.d.ts +2 -0
- package/dist/options.js +9 -0
- package/dist/options.js.map +1 -0
- package/dist/perf.d.ts +9 -0
- package/dist/perf.js +36 -0
- package/dist/perf.js.map +1 -0
- package/dist/polyfill/array.d.ts +2 -0
- package/dist/polyfill/array.js +36 -0
- package/dist/polyfill/array.js.map +1 -0
- package/dist/polyfill/index.d.ts +2 -0
- package/dist/polyfill/index.js +20 -0
- package/dist/polyfill/index.js.map +1 -0
- package/dist/polyfill/intersection-observer.d.ts +1 -0
- package/dist/polyfill/intersection-observer.js +494 -0
- package/dist/polyfill/intersection-observer.js.map +1 -0
- package/dist/polyfill/object.d.ts +3 -0
- package/dist/polyfill/object.js +63 -0
- package/dist/polyfill/object.js.map +1 -0
- package/dist/runtime.esm.d.ts +35 -0
- package/dist/runtime.esm.js +3644 -0
- package/dist/runtime.esm.js.map +1 -0
- package/dist/utils/cache.d.ts +12 -0
- package/dist/utils/cache.js +26 -0
- package/dist/utils/cache.js.map +1 -0
- package/dist/utils/index.d.ts +25 -0
- package/dist/utils/index.js +82 -0
- package/dist/utils/index.js.map +1 -0
- package/dist/utils/lodash.d.ts +2 -0
- package/dist/utils/lodash.js +33 -0
- package/dist/utils/lodash.js.map +1 -0
- package/dist/utils/router.d.ts +7 -0
- package/dist/utils/router.js +19 -0
- package/dist/utils/router.js.map +1 -0
- package/package.json +45 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,174 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2018 O2Team
|
|
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.
|
|
22
|
+
|
|
23
|
+
========================================================================
|
|
24
|
+
|
|
25
|
+
MIT (react-devtools):
|
|
26
|
+
The following files embed [react-devtools](https://github.com/facebook/react) MIT:
|
|
27
|
+
`/packages/taro-plugin-react-devtools/src/backend/index.js`
|
|
28
|
+
See `/LICENSE` for details of the license.
|
|
29
|
+
|
|
30
|
+
==================
|
|
31
|
+
|
|
32
|
+
MIT (vue-devtools):
|
|
33
|
+
The following files embed [vue-devtools](https://github.com/vuejs/devtools) MIT:
|
|
34
|
+
`/packages/taro-plugin-vue-devtools/src/backend/*`
|
|
35
|
+
See `/LICENSE` for details of the license.
|
|
36
|
+
|
|
37
|
+
==================
|
|
38
|
+
|
|
39
|
+
MIT (vite):
|
|
40
|
+
The following files embed [vite](https://github.com/vitejs/vite) MIT:
|
|
41
|
+
`/packages/taro-webpack5-prebundle/src/prebundle/scanImport.ts`,
|
|
42
|
+
`/packages/taro-webpack5-prebundle/src/prebundle/bundle.ts`,
|
|
43
|
+
`/packages/taro-webpack5-prebundle/src/h5.ts`,
|
|
44
|
+
`/packages/taro-webpack5-prebundle/src/min.ts`
|
|
45
|
+
See `/LICENSE` for details of the license.
|
|
46
|
+
|
|
47
|
+
==================
|
|
48
|
+
|
|
49
|
+
MIT (webpack):
|
|
50
|
+
The following files embed [webpack](https://github.com/webpack/webpack) MIT:
|
|
51
|
+
`/packages/taro-webpack5-prebundle/src/webpack/TaroContainerEntryModule.ts`,
|
|
52
|
+
`/packages/taro-webpack5-prebundle/src/webpack/TaroContainerPlugin.ts`,
|
|
53
|
+
`/packages/taro-webpack5-prebundle/src/webpack/TaroContainerReferencePlugin.ts`,
|
|
54
|
+
`/packages/taro-webpack5-prebundle/src/webpack/TaroModuleFederationPlugin.ts`
|
|
55
|
+
See `/LICENSE` for details of the license.
|
|
56
|
+
|
|
57
|
+
==================
|
|
58
|
+
|
|
59
|
+
MIT (sizzle):
|
|
60
|
+
The following files embed [sizzle](https://github.com/jquery/sizzle) MIT:
|
|
61
|
+
`/packages/taro-extends/src/jquery/sizzle.js`
|
|
62
|
+
See `/LICENSE.txt` for details of the license.
|
|
63
|
+
|
|
64
|
+
==================
|
|
65
|
+
|
|
66
|
+
MIT (zepto):
|
|
67
|
+
The following files embed [zepto](https://github.com/madrobby/zepto) MIT:
|
|
68
|
+
`/packages/taro-extends/src/jquery/zepto.js`,
|
|
69
|
+
`/packages/taro-extends/src/jquery/event.js`
|
|
70
|
+
See `/MIT-LICENSE` for details of the license.
|
|
71
|
+
|
|
72
|
+
==================
|
|
73
|
+
|
|
74
|
+
MIT (css-to-react-native):
|
|
75
|
+
The following files embed [css-to-react-native](https://github.com/styled-components/css-to-react-native) MIT:
|
|
76
|
+
`/packages/css-to-react-native/src/css-to-react-native/*`
|
|
77
|
+
See `/LICENSE.md` for details of the license.
|
|
78
|
+
|
|
79
|
+
==================
|
|
80
|
+
|
|
81
|
+
MIT (reactify-wc):
|
|
82
|
+
The following files embed [reactify-wc](https://github.com/BBKolton/reactify-wc) MIT:
|
|
83
|
+
`/packages/taro-components-library-react/src/component-lib/reactify-wc.ts`
|
|
84
|
+
See `/LICENSE` for details of the license.
|
|
85
|
+
|
|
86
|
+
==================
|
|
87
|
+
|
|
88
|
+
MIT (ant-design-mobile-rn):
|
|
89
|
+
The following files embed [ant-design-mobile-rn](https://github.com/ant-design/ant-design-mobile-rn) MIT:
|
|
90
|
+
`/packages/taro-components-rn/src/components/Swiper/carousel.tsx`
|
|
91
|
+
See `/LICENSE` for details of the license.
|
|
92
|
+
|
|
93
|
+
==================
|
|
94
|
+
|
|
95
|
+
MIT (react-wx-images-viewer):
|
|
96
|
+
The following files embed [react-wx-images-viewer](https://github.com/react-ld/react-wx-images-viewer) MIT:
|
|
97
|
+
`/packages/taro-h5/src/api/media/image/previewImage.ts`
|
|
98
|
+
See `/LICENSE` for details of the license.
|
|
99
|
+
|
|
100
|
+
==================
|
|
101
|
+
|
|
102
|
+
MIT (webpack-contrib/css-loader):
|
|
103
|
+
The following files embed [webpack-contrib/css-loader](https://github.com/webpack-contrib/css-loader) MIT:
|
|
104
|
+
`/packages/taro-rn-style-transformer/src/utils/index.ts`
|
|
105
|
+
See `/LICENSE` for details of the license.
|
|
106
|
+
|
|
107
|
+
==================
|
|
108
|
+
|
|
109
|
+
MIT (react-native):
|
|
110
|
+
The following files embed [react-native](https://github.com/facebook/react-native) MIT:
|
|
111
|
+
`/packages/taro-rn-style-transformer/src/transforms/StyleSheet/*`
|
|
112
|
+
See `/LICENSE` for details of the license.
|
|
113
|
+
|
|
114
|
+
==================
|
|
115
|
+
|
|
116
|
+
MIT (myrne/performance-now):
|
|
117
|
+
The following files embed [myrne/performance-now](https://github.com/myrne/performance-now) MIT:
|
|
118
|
+
`/packages/taro-runtime/src/bom/raf.ts`
|
|
119
|
+
See `/LICENSE` for details of the license.
|
|
120
|
+
|
|
121
|
+
==================
|
|
122
|
+
|
|
123
|
+
Apache (chameleon-api):
|
|
124
|
+
The following files embed [chameleon-api](https://github.com/chameleon-team/chameleon-api) Apache:
|
|
125
|
+
`/packages/taro-h5/src/api/device/clipboard.ts`
|
|
126
|
+
|
|
127
|
+
==================
|
|
128
|
+
|
|
129
|
+
MIT (uni-app):
|
|
130
|
+
The following files embed [uni-app](https://github.com/dcloudio/uni-app) MIT:
|
|
131
|
+
`/packages/taro-components-rn/src/components/Video/index.tsx`
|
|
132
|
+
See `/LICENSE` for details of the license.
|
|
133
|
+
|
|
134
|
+
==================
|
|
135
|
+
|
|
136
|
+
MIT (miniprogram-render):
|
|
137
|
+
The following files embed [miniprogram-render](https://github.com/Tencent/kbone) MIT:
|
|
138
|
+
`/packages/taro-plugin-http/src/runtime/Cookie.ts`
|
|
139
|
+
See `/LICENSE` for details of the license.
|
|
140
|
+
|
|
141
|
+
==================
|
|
142
|
+
|
|
143
|
+
MIT (stencil-ds-output-targets):
|
|
144
|
+
The following files embed [stencil-ds-output-targets](https://github.com/ionic-team/stencil-ds-output-targets/) MIT:
|
|
145
|
+
`/packages/taro-components-library-react/src/react-component-lib/utils/attachProps.ts`
|
|
146
|
+
`/packages/taro-components-library-react/src/react-component-lib/utils/case.ts`
|
|
147
|
+
`/packages/taro-components-library-react/src/react-component-lib/utils/dev.ts`
|
|
148
|
+
`/packages/taro-components-library-react/src/react-component-lib/utils/index.tsx`
|
|
149
|
+
`/packages/taro-components-library-react/src/react-component-lib/createComponent.tsx`
|
|
150
|
+
`/packages/taro-components-library-react/src/react-component-lib/createOverlayComponent.tsx`
|
|
151
|
+
`/packages/taro-components-library-react/src/react-component-lib/interfaces.ts`
|
|
152
|
+
`/packages/taro-components-library-vue3/src/vue-component-lib/utils.ts`
|
|
153
|
+
See `/LICENSE` for details of the license.
|
|
154
|
+
|
|
155
|
+
==================
|
|
156
|
+
|
|
157
|
+
MIT (weui):
|
|
158
|
+
The following files embed [weui](https://github.com/Tencent/weui) MIT:
|
|
159
|
+
`/packages/taro-components/src/components/*.scss`
|
|
160
|
+
See `/LICENSE.txt` for details of the license.
|
|
161
|
+
|
|
162
|
+
==================
|
|
163
|
+
|
|
164
|
+
Apache-2.0 (intersection-observer):
|
|
165
|
+
The following files embed [intersection-observer](https://github.com/GoogleChromeLabs/intersection-observer) Apache-2.0:
|
|
166
|
+
`/packages/taro-api/src/polyfill/intersection-observer.ts`
|
|
167
|
+
See `/LICENSE.txt` for details of the license.
|
|
168
|
+
|
|
169
|
+
==================
|
|
170
|
+
|
|
171
|
+
MIT (babel-plugin-jsx-dom-expressions):
|
|
172
|
+
The following files embed [babel-plugin-jsx-dom-expressions](https://github.com/ryansolid/dom-expressions/blob/main/packages/babel-plugin-jsx-dom-expressions) MIT:
|
|
173
|
+
`/packages/babel-plugin-transform-solid-jsx/src/*`
|
|
174
|
+
See `/LICENSE` for details of the license.
|
package/README.md
ADDED
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
# `@spcsn/taro-runtime`
|
|
2
|
+
|
|
3
|
+
Taro 运行时。在小程序端连接框架(DSL)渲染机制到小程序渲染机制,连接小程序路由和生命周期到框架对应的生命周期。在 H5/RN 端连接小程序生命周期**规范**到框架生命周期。
|
|
4
|
+
|
|
5
|
+
## 核心 API
|
|
6
|
+
|
|
7
|
+
### createReactApp()
|
|
8
|
+
|
|
9
|
+
暴露给 `@tarojs/taro-loader/app` 调用,在小程序入口文件中调用,创建一个小程序 `App` 构造函数接受的小程序应用规范对象。
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
### createVueApp()
|
|
13
|
+
|
|
14
|
+
暴露给 `@tarojs/taro-loader/app` 调用,在小程序入口文件中调用,创建一个小程序 `App` 构造函数接受的小程序应用规范对象。
|
|
15
|
+
|
|
16
|
+
### createPageConfig()
|
|
17
|
+
|
|
18
|
+
暴露给 `@tarojs/taro-loader/page` 调用,在小程序页面文件中调用,创建一个小程序 `Page` 构造函数接受的小程序页面规范对象。
|
|
19
|
+
|
|
20
|
+
### window
|
|
21
|
+
|
|
22
|
+
在小程序端模仿浏览器的 `window` 实现的对象,在浏览器环境中返回浏览器本身的 `window`。此对象通过 Webpack 的 [ProvidePlugin](https://webpack.js.org/plugins/provide-plugin/) 注入到全局对象以供第三方库调用。
|
|
23
|
+
|
|
24
|
+
### navigator
|
|
25
|
+
|
|
26
|
+
在小程序端模仿浏览器的 `navigator` 实现的对象,在浏览器环境中返回浏览器本身的 `navigator`。此对象通过 Webpack 的 [ProvidePlugin](https://webpack.js.org/plugins/provide-plugin/) 注入到全局对象以供第三方库调用。
|
|
27
|
+
|
|
28
|
+
### document
|
|
29
|
+
|
|
30
|
+
在小程序端模仿浏览器的 `document` 实现的对象,在浏览器环境中返回浏览器本身的 `document`。此对象通过 Webpack 的 [ProvidePlugin](https://webpack.js.org/plugins/provide-plugin/) 注入到全局对象以供第三方库调用。
|
|
31
|
+
|
|
32
|
+
### Current
|
|
33
|
+
|
|
34
|
+
暴露给开发者的 Taro 全局变量,目前有三个属性:
|
|
35
|
+
|
|
36
|
+
* `Current.app`,返回当前小程序应用实例,非小程序端返回小程序规范应用实例,可通过此实例调用小程序规范生命周期。
|
|
37
|
+
* `Current.page`,返回当前小程序页面实例,非小程序端返回小程序规范页面实例,可通过此实例调用小程序规范生命周期。
|
|
38
|
+
* `Current.router`,返回当前小程序路由信息,非小程序端返回小程序规范路由信息
|
|
39
|
+
|
|
40
|
+
### options
|
|
41
|
+
|
|
42
|
+
Taro 配置:
|
|
43
|
+
|
|
44
|
+
* `debug`: 开启之后会打印渲染时间
|
|
45
|
+
* `prerender`: 暴露给 `@spcsn/taro-cli` 的内部参数
|
|
46
|
+
|
|
47
|
+
### Events
|
|
48
|
+
|
|
49
|
+
[Taro 消息机制](https://docs.taro.zone/docs/apis/about/events)。
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
declare class TaroURL {
|
|
2
|
+
#private;
|
|
3
|
+
static createObjectURL(): void;
|
|
4
|
+
static revokeObjectURL(): void;
|
|
5
|
+
constructor(url: string, base?: string);
|
|
6
|
+
get protocol(): string;
|
|
7
|
+
set protocol(val: string);
|
|
8
|
+
get host(): string;
|
|
9
|
+
set host(val: string);
|
|
10
|
+
get hostname(): string;
|
|
11
|
+
set hostname(val: string);
|
|
12
|
+
get port(): string;
|
|
13
|
+
set port(val: string);
|
|
14
|
+
get pathname(): string;
|
|
15
|
+
set pathname(val: string);
|
|
16
|
+
get search(): string;
|
|
17
|
+
set search(val: string);
|
|
18
|
+
get hash(): string;
|
|
19
|
+
set hash(val: string);
|
|
20
|
+
get href(): string;
|
|
21
|
+
set href(val: string);
|
|
22
|
+
get origin(): string;
|
|
23
|
+
set origin(val: string);
|
|
24
|
+
get searchParams(): URLSearchParams;
|
|
25
|
+
toString(): string;
|
|
26
|
+
toJSON(): string;
|
|
27
|
+
_toRaw(): {
|
|
28
|
+
protocol: string;
|
|
29
|
+
port: string;
|
|
30
|
+
host: string;
|
|
31
|
+
hostname: string;
|
|
32
|
+
pathname: string;
|
|
33
|
+
hash: string;
|
|
34
|
+
search: string;
|
|
35
|
+
origin: string;
|
|
36
|
+
href: string;
|
|
37
|
+
};
|
|
38
|
+
}
|
|
39
|
+
export type { TaroURL };
|
|
40
|
+
export declare const TaroURLProvider: typeof TaroURL;
|
|
41
|
+
export declare function parseUrl(url?: string): {
|
|
42
|
+
href: string;
|
|
43
|
+
origin: string;
|
|
44
|
+
protocol: string;
|
|
45
|
+
hostname: string;
|
|
46
|
+
host: string;
|
|
47
|
+
port: string;
|
|
48
|
+
pathname: string;
|
|
49
|
+
search: string;
|
|
50
|
+
hash: string;
|
|
51
|
+
};
|
package/dist/bom/URL.js
ADDED
|
@@ -0,0 +1,188 @@
|
|
|
1
|
+
import env from "../env.js";
|
|
2
|
+
import { URLSearchParams } from "./URLSearchParams.js";
|
|
3
|
+
import { isString, isUndefined } from "@spcsn/taro-shared";
|
|
4
|
+
//#region src/bom/URL.ts
|
|
5
|
+
var TaroURL = class {
|
|
6
|
+
static createObjectURL() {
|
|
7
|
+
throw new Error("Oops, not support URL.createObjectURL() in miniprogram.");
|
|
8
|
+
}
|
|
9
|
+
static revokeObjectURL() {
|
|
10
|
+
throw new Error("Oops, not support URL.revokeObjectURL() in miniprogram.");
|
|
11
|
+
}
|
|
12
|
+
#hash = "";
|
|
13
|
+
#hostname = "";
|
|
14
|
+
#pathname = "";
|
|
15
|
+
#port = "";
|
|
16
|
+
#protocol = "";
|
|
17
|
+
#search;
|
|
18
|
+
constructor(url, base) {
|
|
19
|
+
if (!isString(url)) url = String(url);
|
|
20
|
+
const { hash, hostname, pathname, port, protocol, search } = parseUrlBase(url, base);
|
|
21
|
+
this.#hash = hash;
|
|
22
|
+
this.#hostname = hostname;
|
|
23
|
+
this.#pathname = pathname || "/";
|
|
24
|
+
this.#port = port;
|
|
25
|
+
this.#protocol = protocol;
|
|
26
|
+
this.#search = new URLSearchParams(search);
|
|
27
|
+
}
|
|
28
|
+
get protocol() {
|
|
29
|
+
return this.#protocol;
|
|
30
|
+
}
|
|
31
|
+
set protocol(val) {
|
|
32
|
+
isString(val) && (this.#protocol = val.trim());
|
|
33
|
+
}
|
|
34
|
+
get host() {
|
|
35
|
+
return this.hostname + (this.port ? ":" + this.port : "");
|
|
36
|
+
}
|
|
37
|
+
set host(val) {
|
|
38
|
+
if (val && isString(val)) {
|
|
39
|
+
val = val.trim();
|
|
40
|
+
const { hostname, port } = parseUrl(`//${val}`);
|
|
41
|
+
this.hostname = hostname;
|
|
42
|
+
this.port = port;
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
get hostname() {
|
|
46
|
+
return this.#hostname;
|
|
47
|
+
}
|
|
48
|
+
set hostname(val) {
|
|
49
|
+
val && isString(val) && (this.#hostname = val.trim());
|
|
50
|
+
}
|
|
51
|
+
get port() {
|
|
52
|
+
return this.#port;
|
|
53
|
+
}
|
|
54
|
+
set port(val) {
|
|
55
|
+
isString(val) && (this.#port = val.trim());
|
|
56
|
+
}
|
|
57
|
+
get pathname() {
|
|
58
|
+
return this.#pathname;
|
|
59
|
+
}
|
|
60
|
+
set pathname(val) {
|
|
61
|
+
if (isString(val)) {
|
|
62
|
+
val = val.trim();
|
|
63
|
+
const HEAD_REG = /^(\/|\.\/|\.\.\/)/;
|
|
64
|
+
let temp = val;
|
|
65
|
+
while (HEAD_REG.test(temp)) temp = temp.replace(HEAD_REG, "");
|
|
66
|
+
if (temp) this.#pathname = "/" + temp;
|
|
67
|
+
else this.#pathname = "/";
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
get search() {
|
|
71
|
+
const val = this.#search.toString();
|
|
72
|
+
return val.length === 0 || val.startsWith("?") ? val : `?${val}`;
|
|
73
|
+
}
|
|
74
|
+
set search(val) {
|
|
75
|
+
if (isString(val)) {
|
|
76
|
+
val = val.trim();
|
|
77
|
+
this.#search = new URLSearchParams(val);
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
get hash() {
|
|
81
|
+
return this.#hash;
|
|
82
|
+
}
|
|
83
|
+
set hash(val) {
|
|
84
|
+
if (isString(val)) {
|
|
85
|
+
val = val.trim();
|
|
86
|
+
if (val) this.#hash = val.startsWith("#") ? val : `#${val}`;
|
|
87
|
+
else this.#hash = "";
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
get href() {
|
|
91
|
+
return `${this.protocol}//${this.host}${this.pathname}${this.search}${this.hash}`;
|
|
92
|
+
}
|
|
93
|
+
set href(val) {
|
|
94
|
+
if (val && isString(val)) {
|
|
95
|
+
val = val.trim();
|
|
96
|
+
const { protocol, hostname, port, hash, search, pathname } = parseUrl(val);
|
|
97
|
+
this.protocol = protocol;
|
|
98
|
+
this.hostname = hostname;
|
|
99
|
+
this.pathname = pathname;
|
|
100
|
+
this.port = port;
|
|
101
|
+
this.hash = hash;
|
|
102
|
+
this.search = search;
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
get origin() {
|
|
106
|
+
return `${this.protocol}//${this.host}`;
|
|
107
|
+
}
|
|
108
|
+
set origin(val) {
|
|
109
|
+
if (val && isString(val)) {
|
|
110
|
+
val = val.trim();
|
|
111
|
+
const { protocol, hostname, port } = parseUrl(val);
|
|
112
|
+
this.protocol = protocol;
|
|
113
|
+
this.hostname = hostname;
|
|
114
|
+
this.port = port;
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
get searchParams() {
|
|
118
|
+
return this.#search;
|
|
119
|
+
}
|
|
120
|
+
toString() {
|
|
121
|
+
return this.href;
|
|
122
|
+
}
|
|
123
|
+
toJSON() {
|
|
124
|
+
return this.toString();
|
|
125
|
+
}
|
|
126
|
+
_toRaw() {
|
|
127
|
+
return {
|
|
128
|
+
protocol: this.protocol,
|
|
129
|
+
port: this.port,
|
|
130
|
+
host: this.host,
|
|
131
|
+
hostname: this.hostname,
|
|
132
|
+
pathname: this.pathname,
|
|
133
|
+
hash: this.hash,
|
|
134
|
+
search: this.search,
|
|
135
|
+
origin: this.origin,
|
|
136
|
+
href: this.href
|
|
137
|
+
};
|
|
138
|
+
}
|
|
139
|
+
};
|
|
140
|
+
const TaroURLProvider = process.env.TARO_PLATFORM === "web" ? env.window.URL : TaroURL;
|
|
141
|
+
function parseUrl(url = "") {
|
|
142
|
+
const result = {
|
|
143
|
+
href: "",
|
|
144
|
+
origin: "",
|
|
145
|
+
protocol: "",
|
|
146
|
+
hostname: "",
|
|
147
|
+
host: "",
|
|
148
|
+
port: "",
|
|
149
|
+
pathname: "",
|
|
150
|
+
search: "",
|
|
151
|
+
hash: ""
|
|
152
|
+
};
|
|
153
|
+
if (!url || !isString(url)) return result;
|
|
154
|
+
url = url.trim();
|
|
155
|
+
const matches = url.match(/^(([^:/?#]+):)?\/\/(([^/?#]+):(.+)@)?([^/?#:]*)(:(\d+))?([^?#]*)(\?([^#]*))?(#(.*))?/);
|
|
156
|
+
if (!matches) return result;
|
|
157
|
+
result.protocol = matches[1] || "https:";
|
|
158
|
+
result.hostname = matches[6] || "taro.com";
|
|
159
|
+
result.port = matches[8] || "";
|
|
160
|
+
result.pathname = matches[9] || "/";
|
|
161
|
+
result.search = matches[10] || "";
|
|
162
|
+
result.hash = matches[12] || "";
|
|
163
|
+
result.href = url;
|
|
164
|
+
result.origin = result.protocol + "//" + result.hostname + (result.port ? `:${result.port}` : "");
|
|
165
|
+
result.host = result.hostname + (result.port ? `:${result.port}` : "");
|
|
166
|
+
return result;
|
|
167
|
+
}
|
|
168
|
+
function parseUrlBase(url, base) {
|
|
169
|
+
const VALID_URL = /^(https?:)\/\//i;
|
|
170
|
+
let fullUrl = "";
|
|
171
|
+
let parsedBase = null;
|
|
172
|
+
if (!isUndefined(base)) {
|
|
173
|
+
base = String(base).trim();
|
|
174
|
+
if (!VALID_URL.test(base)) throw new TypeError(`Failed to construct 'URL': Invalid base URL`);
|
|
175
|
+
parsedBase = parseUrl(base);
|
|
176
|
+
}
|
|
177
|
+
url = String(url).trim();
|
|
178
|
+
if (VALID_URL.test(url)) fullUrl = url;
|
|
179
|
+
else if (parsedBase) if (url) if (url.startsWith("//")) fullUrl = parsedBase.protocol + url;
|
|
180
|
+
else fullUrl = parsedBase.origin + (url.startsWith("/") ? url : `/${url}`);
|
|
181
|
+
else fullUrl = parsedBase.href;
|
|
182
|
+
else throw new TypeError(`Failed to construct 'URL': Invalid URL`);
|
|
183
|
+
return parseUrl(fullUrl);
|
|
184
|
+
}
|
|
185
|
+
//#endregion
|
|
186
|
+
export { TaroURLProvider, parseUrl };
|
|
187
|
+
|
|
188
|
+
//# sourceMappingURL=URL.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"URL.js","names":["#hash","#hostname","#pathname","#port","#protocol","#search"],"sources":["../../src/bom/URL.ts"],"sourcesContent":["import { isString, isUndefined } from '@spcsn/taro-shared';\n\nimport env from '../env';\nimport { URLSearchParams } from './URLSearchParams';\n\nclass TaroURL {\n static createObjectURL() {\n throw new Error('Oops, not support URL.createObjectURL() in miniprogram.');\n }\n\n static revokeObjectURL() {\n throw new Error('Oops, not support URL.revokeObjectURL() in miniprogram.');\n }\n\n /* private property */\n #hash = '';\n #hostname = '';\n #pathname = '';\n #port = '';\n #protocol = '';\n #search: URLSearchParams;\n\n constructor(url: string, base?: string) {\n if (!isString(url)) url = String(url);\n\n const parseResult = parseUrlBase(url, base);\n const { hash, hostname, pathname, port, protocol, search } = parseResult;\n\n this.#hash = hash;\n this.#hostname = hostname;\n this.#pathname = pathname || '/';\n this.#port = port;\n this.#protocol = protocol;\n this.#search = new URLSearchParams(search);\n }\n\n /* public property */\n get protocol() {\n return this.#protocol;\n }\n\n set protocol(val: string) {\n isString(val) && (this.#protocol = val.trim());\n }\n\n get host() {\n return this.hostname + (this.port ? ':' + this.port : '');\n }\n\n set host(val: string) {\n if (val && isString(val)) {\n val = val.trim();\n const { hostname, port } = parseUrl(`//${val}`);\n this.hostname = hostname;\n this.port = port;\n }\n }\n\n get hostname() {\n return this.#hostname;\n }\n\n set hostname(val: string) {\n val && isString(val) && (this.#hostname = val.trim());\n }\n\n get port() {\n return this.#port;\n }\n\n set port(val: string) {\n isString(val) && (this.#port = val.trim());\n }\n\n get pathname() {\n return this.#pathname;\n }\n\n set pathname(val: string) {\n if (isString(val)) {\n val = val.trim();\n const HEAD_REG = /^(\\/|\\.\\/|\\.\\.\\/)/;\n let temp = val;\n while (HEAD_REG.test(temp)) {\n temp = temp.replace(HEAD_REG, '');\n }\n if (temp) this.#pathname = '/' + temp;\n else this.#pathname = '/';\n }\n }\n\n get search() {\n const val = this.#search.toString();\n return val.length === 0 || val.startsWith('?') ? val : `?${val}`;\n }\n\n set search(val: string) {\n if (isString(val)) {\n val = val.trim();\n this.#search = new URLSearchParams(val);\n }\n }\n\n get hash() {\n return this.#hash;\n }\n\n set hash(val: string) {\n if (isString(val)) {\n val = val.trim();\n if (val) this.#hash = val.startsWith('#') ? val : `#${val}`;\n else this.#hash = '';\n }\n }\n\n get href() {\n return `${this.protocol}//${this.host}${this.pathname}${this.search}${this.hash}`;\n }\n\n set href(val: string) {\n if (val && isString(val)) {\n val = val.trim();\n const { protocol, hostname, port, hash, search, pathname } = parseUrl(val);\n this.protocol = protocol;\n this.hostname = hostname;\n this.pathname = pathname;\n this.port = port;\n this.hash = hash;\n this.search = search;\n }\n }\n\n get origin() {\n return `${this.protocol}//${this.host}`;\n }\n\n set origin(val: string) {\n if (val && isString(val)) {\n val = val.trim();\n const { protocol, hostname, port } = parseUrl(val);\n this.protocol = protocol;\n this.hostname = hostname;\n this.port = port;\n }\n }\n\n get searchParams() {\n return this.#search;\n }\n\n // public method\n toString() {\n return this.href;\n }\n\n toJSON() {\n return this.toString();\n }\n\n // convenient for deconstructor\n _toRaw() {\n return {\n protocol: this.protocol,\n port: this.port,\n host: this.host,\n hostname: this.hostname,\n pathname: this.pathname,\n hash: this.hash,\n search: this.search,\n origin: this.origin,\n href: this.href,\n };\n }\n}\n\nexport type { TaroURL };\n\n// Note: 小程序端 vite 打包成 commonjs,const URL = xxx 会报错,所以把 URL 改为 TaroURLProvider\nexport const TaroURLProvider: typeof TaroURL = process.env.TARO_PLATFORM === 'web' ? env.window.URL : TaroURL;\n\nexport function parseUrl(url = '') {\n const result = {\n href: '',\n origin: '',\n protocol: '',\n hostname: '',\n host: '',\n port: '',\n pathname: '',\n search: '',\n hash: '',\n };\n if (!url || !isString(url)) return result;\n\n url = url.trim();\n const PATTERN = /^(([^:/?#]+):)?\\/\\/(([^/?#]+):(.+)@)?([^/?#:]*)(:(\\d+))?([^?#]*)(\\?([^#]*))?(#(.*))?/;\n const matches = url.match(PATTERN);\n\n if (!matches) return result;\n\n // TODO: username & password ?\n result.protocol = matches[1] || 'https:';\n result.hostname = matches[6] || 'taro.com';\n result.port = matches[8] || '';\n result.pathname = matches[9] || '/';\n result.search = matches[10] || '';\n result.hash = matches[12] || '';\n result.href = url;\n result.origin = result.protocol + '//' + result.hostname + (result.port ? `:${result.port}` : '');\n result.host = result.hostname + (result.port ? `:${result.port}` : '');\n\n return result;\n}\n\nfunction parseUrlBase(url: string, base?: string) {\n const VALID_URL = /^(https?:)\\/\\//i;\n\n let fullUrl = '';\n let parsedBase: ReturnType<typeof parseUrl> | null = null;\n\n if (!isUndefined(base)) {\n base = String(base).trim();\n if (!VALID_URL.test(base)) throw new TypeError(`Failed to construct 'URL': Invalid base URL`);\n parsedBase = parseUrl(base);\n }\n\n url = String(url).trim();\n\n if (VALID_URL.test(url)) {\n fullUrl = url;\n } else if (parsedBase) {\n if (url) {\n if (url.startsWith('//')) {\n fullUrl = parsedBase.protocol + url;\n } else {\n fullUrl = parsedBase.origin + (url.startsWith('/') ? url : `/${url}`);\n }\n } else {\n fullUrl = parsedBase.href;\n }\n } else {\n throw new TypeError(`Failed to construct 'URL': Invalid URL`);\n }\n\n return parseUrl(fullUrl);\n}\n"],"mappings":";;;;AAKA,IAAM,UAAN,MAAc;CACZ,OAAO,kBAAkB;EACvB,MAAM,IAAI,MAAM,yDAAyD;CAC3E;CAEA,OAAO,kBAAkB;EACvB,MAAM,IAAI,MAAM,yDAAyD;CAC3E;CAGA,QAAQ;C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GAAG,EAAE,KAAK;CAEvB,IAAI,UAAU,KAAK,GAAG,GACpB,UAAU;MACL,IAAI,YACT,IAAI,KACF,IAAI,IAAI,WAAW,IAAI,GACrB,UAAU,WAAW,WAAW;MAEhC,UAAU,WAAW,UAAU,IAAI,WAAW,GAAG,IAAI,MAAM,IAAI;MAGjE,UAAU,WAAW;MAGvB,MAAM,IAAI,UAAU,wCAAwC;CAG9D,OAAO,SAAS,OAAO;AACzB"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const URLSearchParams: any;
|
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
import env from "../env.js";
|
|
2
|
+
import { isArray } from "@spcsn/taro-shared";
|
|
3
|
+
//#region src/bom/URLSearchParams.ts
|
|
4
|
+
const findReg = /[!'()~]|%20|%00/g;
|
|
5
|
+
const plusReg = /\+/g;
|
|
6
|
+
const replaceCharMap = {
|
|
7
|
+
"!": "%21",
|
|
8
|
+
"'": "%27",
|
|
9
|
+
"(": "%28",
|
|
10
|
+
")": "%29",
|
|
11
|
+
"~": "%7E",
|
|
12
|
+
"%20": "+",
|
|
13
|
+
"%00": "\0"
|
|
14
|
+
};
|
|
15
|
+
function replacer(match) {
|
|
16
|
+
return replaceCharMap[match];
|
|
17
|
+
}
|
|
18
|
+
function appendTo(dict, name, value) {
|
|
19
|
+
const res = isArray(value) ? value.join(",") : value;
|
|
20
|
+
if (name in dict) dict[name].push(res);
|
|
21
|
+
else dict[name] = [res];
|
|
22
|
+
}
|
|
23
|
+
function addEach(value, key) {
|
|
24
|
+
appendTo(this, key, value);
|
|
25
|
+
}
|
|
26
|
+
function decode(str) {
|
|
27
|
+
return decodeURIComponent(str.replace(plusReg, " "));
|
|
28
|
+
}
|
|
29
|
+
function encode(str) {
|
|
30
|
+
return encodeURIComponent(str).replace(findReg, replacer);
|
|
31
|
+
}
|
|
32
|
+
const URLSearchParams = process.env.TARO_PLATFORM === "web" ? env.window.URLSearchParams : class {
|
|
33
|
+
#dict = Object.create(null);
|
|
34
|
+
constructor(query) {
|
|
35
|
+
query ??= "";
|
|
36
|
+
const dict = this.#dict;
|
|
37
|
+
if (typeof query === "string") {
|
|
38
|
+
if (query.charAt(0) === "?") query = query.slice(1);
|
|
39
|
+
for (let pairs = query.split("&"), i = 0, length = pairs.length; i < length; i++) {
|
|
40
|
+
const value = pairs[i];
|
|
41
|
+
const index = value.indexOf("=");
|
|
42
|
+
try {
|
|
43
|
+
if (index > -1) appendTo(dict, decode(value.slice(0, index)), decode(value.slice(index + 1)));
|
|
44
|
+
else if (value.length) appendTo(dict, decode(value), "");
|
|
45
|
+
} catch (err) {
|
|
46
|
+
console.warn(`[Taro warn] URL 参数 ${value} decode 异常`);
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
} else if (isArray(query)) for (let i = 0, length = query.length; i < length; i++) {
|
|
50
|
+
const value = query[i];
|
|
51
|
+
appendTo(dict, value[0], value[1]);
|
|
52
|
+
}
|
|
53
|
+
else if (query.forEach) query.forEach(addEach, dict);
|
|
54
|
+
else for (const key in query) appendTo(dict, key, query[key]);
|
|
55
|
+
}
|
|
56
|
+
append(name, value) {
|
|
57
|
+
appendTo(this.#dict, name, value);
|
|
58
|
+
}
|
|
59
|
+
delete(name) {
|
|
60
|
+
delete this.#dict[name];
|
|
61
|
+
}
|
|
62
|
+
get(name) {
|
|
63
|
+
const dict = this.#dict;
|
|
64
|
+
return name in dict ? dict[name][0] : null;
|
|
65
|
+
}
|
|
66
|
+
getAll(name) {
|
|
67
|
+
const dict = this.#dict;
|
|
68
|
+
return name in dict ? dict[name].slice(0) : [];
|
|
69
|
+
}
|
|
70
|
+
has(name) {
|
|
71
|
+
return name in this.#dict;
|
|
72
|
+
}
|
|
73
|
+
keys() {
|
|
74
|
+
return Object.keys(this.#dict);
|
|
75
|
+
}
|
|
76
|
+
set(name, value) {
|
|
77
|
+
this.#dict[name] = ["" + value];
|
|
78
|
+
}
|
|
79
|
+
forEach(callback, thisArg) {
|
|
80
|
+
const dict = this.#dict;
|
|
81
|
+
Object.getOwnPropertyNames(dict).forEach(function(name) {
|
|
82
|
+
dict[name].forEach(function(value) {
|
|
83
|
+
callback.call(thisArg, value, name, this);
|
|
84
|
+
}, this);
|
|
85
|
+
}, this);
|
|
86
|
+
}
|
|
87
|
+
toJSON() {
|
|
88
|
+
return {};
|
|
89
|
+
}
|
|
90
|
+
toString() {
|
|
91
|
+
const dict = this.#dict;
|
|
92
|
+
const query = [];
|
|
93
|
+
for (const key in dict) {
|
|
94
|
+
const name = encode(key);
|
|
95
|
+
for (let i = 0, value = dict[key]; i < value.length; i++) query.push(name + "=" + encode(value[i]));
|
|
96
|
+
}
|
|
97
|
+
return query.join("&");
|
|
98
|
+
}
|
|
99
|
+
};
|
|
100
|
+
//#endregion
|
|
101
|
+
export { URLSearchParams };
|
|
102
|
+
|
|
103
|
+
//# sourceMappingURL=URLSearchParams.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"URLSearchParams.js","names":["#dict"],"sources":["../../src/bom/URLSearchParams.ts"],"sourcesContent":["import { isArray } from '@spcsn/taro-shared';\n\nimport env from '../env';\n\nconst findReg = /[!'()~]|%20|%00/g;\nconst plusReg = /\\+/g;\nconst replaceCharMap = {\n '!': '%21',\n \"'\": '%27',\n '(': '%28',\n ')': '%29',\n '~': '%7E',\n '%20': '+',\n '%00': '\\x00',\n};\n\nfunction replacer(match: string) {\n return replaceCharMap[match];\n}\n\nfunction appendTo(dict: Record<string, string[]>, name: string, value: string) {\n const res = isArray(value) ? value.join(',') : value;\n if (name in dict) dict[name].push(res);\n else dict[name] = [res];\n}\n\nfunction addEach(value: string, key: string) {\n appendTo(this, key, value);\n}\n\nfunction decode(str: string) {\n return decodeURIComponent(str.replace(plusReg, ' '));\n}\n\nfunction encode(str: string) {\n return encodeURIComponent(str).replace(findReg, replacer);\n}\n\nexport const URLSearchParams =\n process.env.TARO_PLATFORM === 'web'\n ? env.window.URLSearchParams\n : class {\n #dict = Object.create(null);\n\n constructor(query) {\n query ??= '';\n\n const dict = this.#dict;\n\n if (typeof query === 'string') {\n if (query.charAt(0) === '?') {\n query = query.slice(1);\n }\n for (let pairs = query.split('&'), i = 0, length = pairs.length; i < length; i++) {\n const value = pairs[i];\n const index = value.indexOf('=');\n\n // 针对不规范的 url 参数做容错处理,如:word=你%好\n try {\n if (index > -1) {\n appendTo(dict, decode(value.slice(0, index)), decode(value.slice(index + 1)));\n } else if (value.length) {\n appendTo(dict, decode(value), '');\n }\n } catch (err) {\n if (process.env.NODE_ENV !== 'production') {\n console.warn(`[Taro warn] URL 参数 ${value} decode 异常`);\n }\n }\n }\n } else {\n if (isArray(query)) {\n for (let i = 0, length = query.length; i < length; i++) {\n const value = query[i];\n appendTo(dict, value[0], value[1]);\n }\n } else if (query.forEach) {\n query.forEach(addEach, dict);\n } else {\n for (const key in query) {\n appendTo(dict, key, query[key]);\n }\n }\n }\n }\n\n append(name: string, value: string) {\n appendTo(this.#dict, name, value);\n }\n\n delete(name: string) {\n delete this.#dict[name];\n }\n\n get(name: string) {\n const dict = this.#dict;\n return name in dict ? dict[name][0] : null;\n }\n\n getAll(name: string) {\n const dict = this.#dict;\n return name in dict ? dict[name].slice(0) : [];\n }\n\n has(name: string) {\n return name in this.#dict;\n }\n\n keys() {\n return Object.keys(this.#dict);\n }\n\n set(name: string, value: string) {\n this.#dict[name] = ['' + value];\n }\n\n forEach(callback, thisArg) {\n const dict = this.#dict;\n Object.getOwnPropertyNames(dict).forEach(function (name) {\n dict[name].forEach(function (value: string) {\n callback.call(thisArg, value, name, this);\n }, this);\n }, this);\n }\n\n toJSON() {\n return {};\n }\n\n toString() {\n const dict = this.#dict;\n const query: any[] = [];\n for (const key in dict) {\n const name = encode(key);\n for (let i = 0, value = dict[key]; i < value.length; i++) {\n query.push(name + '=' + encode(value[i]));\n }\n }\n return query.join('&');\n }\n };\n"],"mappings":";;;AAIA,MAAM,UAAU;AAChB,MAAM,UAAU;AAChB,MAAM,iBAAiB;CACrB,K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