@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,291 @@
1
+ const fs = require('fs');
2
+ const path = require('path');
3
+ const webpack = require('webpack');
4
+ const argv = require('yargs').argv;
5
+
6
+ const MiniCssExtractPlugin = require('mini-css-extract-plugin');
7
+
8
+ const { CleanWebpackPlugin } = require('clean-webpack-plugin');
9
+ const HtmlWebpackPlugin = require('html-webpack-plugin');
10
+ const InlineChunkHtmlPlugin = require('inline-chunk-html-plugin');
11
+
12
+ const ForkTsCheckerWebpackPlugin = require('fork-ts-checker-webpack-plugin');
13
+ const TsconfigPathsPlugin = require('tsconfig-paths-webpack-plugin');
14
+
15
+ const sveltePreprocess = require('svelte-preprocess');
16
+
17
+ const { getLocalIP, loadProjectConfig, getOrSetH5esType } = require('./util');
18
+
19
+ const pr = path.resolve;
20
+ let cwd = process.cwd();
21
+ let isPxwSelf = cwd == pr(__dirname + '/..');
22
+ let isShipping = argv.mode == 'production';
23
+ console.log('isPxwSelf:', isPxwSelf);
24
+ console.log('isShipping:', isShipping);
25
+ let rootDir = pr(__dirname + '/../');
26
+ let buildOutputPath = pr(cwd, 'dist', 'html' + (isShipping ? '-pro' : '-dev'));
27
+
28
+ function getHtmlName(v) {
29
+ switch (v.name) {
30
+ case 'app': {
31
+ return 'index.html'; // app不允许自定义
32
+ }
33
+ case 'preprocess': {
34
+ return 'preprocess.html'; // preprocess不允许自定义
35
+ }
36
+ default: {
37
+ return v.output ? `${v.output}.html` : `${v.name}.html`;
38
+ }
39
+ }
40
+ }
41
+
42
+ let projectConfig = loadProjectConfig();
43
+ ///////////////////////////////////
44
+ //所有app定义在这里
45
+ let appDef = [];
46
+ let pienv = {};
47
+ //从链接的src里读取配置
48
+ projectConfig.pages.forEach((p) => {
49
+ p.entry = `${cwd}/${p.entry}`;
50
+ p.template = `${cwd}/${p.template}`;
51
+ appDef.push(p);
52
+ });
53
+
54
+ let env = projectConfig.env;
55
+ Object.entries(env || {}).forEach(([k, v]) => {
56
+ pienv['process.env.' + k] = JSON.stringify(v);
57
+ });
58
+
59
+ if (!projectConfig.noSelfCheck && (!isShipping || process.env.withSelfcheck === 'true' || isPxwSelf)) {
60
+ appDef.push({
61
+ name: 'selfcheck',
62
+ template: __dirname + '/../lib/assets/check.html',
63
+ entry: __dirname + '/../lib/check/main.tsx',
64
+ output: 'index',
65
+ });
66
+ projectConfig.pages.push({
67
+ name: 'selfcheck',
68
+ });
69
+ }
70
+ ///////////////////////////////////
71
+
72
+ let plugins = [
73
+ new CleanWebpackPlugin({
74
+ cleanOnceBeforeBuildPatterns: ['**/*', path.join(cwd, '.build')],
75
+ }),
76
+ new ForkTsCheckerWebpackPlugin({ async: !isShipping }), //开发时异步检查,打包时同步检查以阻止错误代码
77
+ new MiniCssExtractPlugin({
78
+ filename: '[name]/[name].css',
79
+ }),
80
+ new webpack.DefinePlugin(pienv),
81
+
82
+ ...appDef.map((v) => {
83
+ return new HtmlWebpackPlugin({
84
+ minify: isShipping,
85
+ chunks: [v.name],
86
+ template: v.template,
87
+ filename: v.name + '/' + getHtmlName(v),
88
+ });
89
+ }),
90
+ ].filter((v) => !!v);
91
+
92
+ let alias = {};
93
+
94
+ //调整svelte-loader里用到的compiler,也要改用定制版本
95
+ let usePikaSvelte = projectConfig.usePikaSvelte;
96
+ if (usePikaSvelte) {
97
+ let sa = {
98
+ ['svelte']: path.resolve('./lib/pika-svelte'),
99
+ ['svelte/internal']: path.resolve('./lib/pika-svelte/internal'),
100
+ ['svelte/compiler']: path.resolve('./lib/pika-svelte/compiler'),
101
+ };
102
+ require('module-alias/').addAliases(sa);
103
+ alias = Object.assign(alias, sa);
104
+ }
105
+
106
+ let loadBabelPlugin = function (name) {
107
+ return require(name);
108
+ };
109
+ // console.debug('appDef', appDef);
110
+
111
+ module.exports = {
112
+ entry: Object.fromEntries(appDef.map((v) => [v.name, v.entry])),
113
+ output: {
114
+ path: buildOutputPath,
115
+ filename: '[name]/[name].js',
116
+ publicPath: isShipping
117
+ ? '../' //发布后都从文件系统加载,使用相对路径引用素材
118
+ : `http://${getLocalIP()[0]}/`, //开发时绑定到外部ip,方便手机访问
119
+ },
120
+
121
+ externals: {
122
+ // preact: 'window.cpreact',
123
+ // react: 'window.cpreact',
124
+ // 'preact/hooks': 'window.cpreact',
125
+ // 'preact/compat': 'window.cpreact',
126
+ // 'pxwdom': 'window.pxwdom'
127
+ csharp: 'esm globalThis.CSharp',
128
+ },
129
+
130
+ resolve: {
131
+ modules: [pr(__dirname, '../node_modules'), pr(cwd, 'node_modules')], // 搜索当前子包下的 node_modules,主工程是业务包默认不会带这些工具库
132
+ extensions: ['.js', '.jsx', '.ts', '.tsx', '.svelte'],
133
+
134
+ alias: {
135
+ src: cwd + '/src',
136
+ lib: cwd + '/lib',
137
+ ['faas-lib']: cwd + '/faas-lib',
138
+ ['preact$']: __dirname + '/../lib/preact.js',
139
+ ['preact/hooks$']: __dirname + '/../lib/preact.js',
140
+ ['preact-router$']: __dirname + '/../lib/preact-router.js',
141
+ react: __dirname + '/../lib/preact.js',
142
+ // ['react-window']: path.resolve('./lib/react-window/src'),
143
+ // ['@improbable-eng/grpc-web']: path.resolve('./lib/grpc-web/dist'),
144
+ ...alias,
145
+ },
146
+ },
147
+
148
+ module: {
149
+ rules: [
150
+ {
151
+ test: /.(js|ts)x?$/,
152
+ use: {
153
+ loader: require.resolve('babel-loader'),
154
+ options: {
155
+ presets: [[loadBabelPlugin('@babel/preset-typescript'), { allowNamespaces: true }]],
156
+ plugins: [
157
+ loadBabelPlugin('@babel/plugin-transform-flow-strip-types'),
158
+ loadBabelPlugin('@babel/plugin-syntax-jsx'),
159
+ [loadBabelPlugin('@babel/plugin-proposal-decorators'), { legacy: true }],
160
+ [loadBabelPlugin('@babel/plugin-transform-class-properties')],
161
+ [loadBabelPlugin('@babel/plugin-transform-optional-chaining')],
162
+
163
+ //这个插件将 jsx 标记转为 h 函数调用,但是在webpack打包后的代码里,import preact, { h } from 'preact' 里的 h 没了
164
+ //单个 h 成为无法识别的变量, 即使把 pragma 写成 preact.createElement 也没用,因为 preact 也被改名了
165
+ [loadBabelPlugin('@babel/plugin-transform-react-jsx'), { pragma: 'h' }],
166
+ //这个插件将 h 换成从 preact 中引入的 createElement,它知道 preact 被改名后的值
167
+ [
168
+ loadBabelPlugin('babel-plugin-jsx-pragmatic'),
169
+ {
170
+ module: 'preact',
171
+ import: 'h',
172
+ export: 'createElement',
173
+ },
174
+ ],
175
+ ],
176
+ },
177
+ },
178
+ },
179
+ {
180
+ test: /\.(png|jpg|gif|mp4|lottie)$/,
181
+ loader: require.resolve('url-loader'),
182
+ options: {
183
+ name: 'static/media/[name].[hash:8].[ext]',
184
+ limit: 1,
185
+ },
186
+ },
187
+ {
188
+ test: /\.svelte$/,
189
+ use: [
190
+ {
191
+ loader: 'svelte-loader',
192
+ options: {
193
+ compilerOptions: {
194
+ dev: !isShipping,
195
+ },
196
+ emitCss: true,
197
+ preprocess: sveltePreprocess({}),
198
+ hotReload: false,
199
+ },
200
+ },
201
+ ],
202
+ },
203
+ {
204
+ test: /\.css$/,
205
+ use: [
206
+ MiniCssExtractPlugin.loader,
207
+ {
208
+ loader: require.resolve('css-loader'),
209
+ options: {
210
+ modules: false,
211
+ },
212
+ },
213
+ ],
214
+ },
215
+ {
216
+ test: /\.less$/,
217
+ use: [
218
+ {
219
+ loader: MiniCssExtractPlugin.loader,
220
+ options: {
221
+ publicPath: '../',
222
+ },
223
+ },
224
+ {
225
+ loader: require.resolve('css-loader'),
226
+ options: {
227
+ modules: true,
228
+ esModule: false,
229
+ },
230
+ },
231
+ {
232
+ loader: require.resolve('less-loader'),
233
+ options: { javascriptEnabled: true },
234
+ },
235
+ ],
236
+ },
237
+ ],
238
+ },
239
+
240
+ optimization: {
241
+ minimize: false, // 最终发布会用pfbs转成二进制,所以源码就不用压缩了,方便阅读调试
242
+ },
243
+
244
+ devtool: 'source-map',
245
+
246
+ plugins,
247
+
248
+ //这个属性webpack打包时是不用的,是给pxw里的express做扩展用的,之所以要包在devServer这一层key里是因为webpack5会强制校验配置文件中不包含未知的key,只有这个key作为曾经的配置项被保留下来,刚好用来传递变量
249
+ devServer: {
250
+ getMiddleware: function () {
251
+ return getMiddleware;
252
+ },
253
+ },
254
+ };
255
+
256
+ var getMiddleware = function (appPort) {
257
+ const middleware = require('webpack-dev-middleware');
258
+ let h5es = require('./h5es');
259
+
260
+ process.env.mode = 'development';
261
+ let config = module.exports;
262
+
263
+ config.mode = 'development';
264
+ config.output.publicPath = `http://${getLocalIP()[0]}:${appPort}/`;
265
+ const compiler = webpack(config);
266
+ return [
267
+ (req, res, next) => {
268
+ const defaulth5esType = getOrSetH5esType();
269
+ if (req.url == '/') return res.sendFile(pr(rootDir, 'config/index.html'));
270
+ if (req.url == '/api/get-project-config') return res.json({ ...projectConfig, h5esVersions: h5es.h5esVersions, defaultH5esType: defaulth5esType });
271
+
272
+ //rewrites page's subpath /name/a/b/c to /name
273
+ for (let i = 0; i < projectConfig.pages.length; i++) {
274
+ let p = projectConfig.pages[i];
275
+ let prefix = `/${p.name}/`;
276
+ console.log('check rewrite', req.url, prefix);
277
+ if (req.url.startsWith(prefix) && req.url.indexOf('.') < 0) {
278
+ req.url = prefix;
279
+ return next();
280
+ }
281
+ }
282
+ return next();
283
+ },
284
+ middleware(compiler, {
285
+ writeToDisk: true,
286
+ mimeTypes: {
287
+ js: 'text/javascript',
288
+ },
289
+ }),
290
+ ];
291
+ };
Binary file
@@ -0,0 +1,62 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <meta charset="utf-8" />
5
+ <style>
6
+ body {
7
+ background-color: #ffffff;
8
+ display: flex;
9
+ flex-direction: column;
10
+ align-items: center;
11
+ padding: 10pt;
12
+ }
13
+ div {
14
+ display: flex;
15
+ flex-direction: column;
16
+ }
17
+
18
+ p {
19
+ font-size: 20pt;
20
+ }
21
+
22
+ .frame {
23
+ border: 2px solid #aa0000;
24
+ /*display: flex;*/
25
+ /*flex-direction: row;*/
26
+ /*justify-content: space-evenly;*/
27
+ width: 90%;
28
+ padding: 10px;
29
+ }
30
+ </style>
31
+ <script type="module">
32
+ import preact from '/preact.js';
33
+ window.cpreact = preact;
34
+ </script>
35
+ <script>
36
+ window.self = window;
37
+ let onload = () => {
38
+ console.log('onload...');
39
+ };
40
+
41
+ toggle = function () {
42
+ let div = document.getElementById('timer');
43
+ let v = div.style.visibility;
44
+ console.log('visibility', v);
45
+ div.style.visibility = v == 'hidden' ? 'visible' : 'hidden';
46
+ };
47
+ </script>
48
+ </head>
49
+
50
+ <body onload="onload();">
51
+ <div>container rendered by JSX:</div>
52
+ <div id="container" class="frame"></div>
53
+ <div style="height: 10pt"></div>
54
+ <div>content in static html:</div>
55
+ <div class="frame" onclick="toggle()" style="align-items: center">
56
+ <div style="flex-direction: row">
57
+ <img height="150" src="https://global.discourse-cdn.com/sitepoint/original/3X/b/5/b59a78e2ed76c705f3c0dcb300f3f222aefdcd99.png" />
58
+ </div>
59
+ <div id="timer">I'm a timer!</div>
60
+ </div>
61
+ </body>
62
+ </html>
Binary file