@pixui-dev/pxw 0.1.20 → 0.1.21

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 (95) hide show
  1. package/bin/pxw.js +199 -199
  2. package/bin/wpbuild.js +10 -10
  3. package/config/default.conf +20 -20
  4. package/config/devops.js +372 -361
  5. package/config/h5es.js +10 -10
  6. package/config/index.html +183 -181
  7. package/config/pfbs.js +245 -245
  8. package/config/util.js +140 -140
  9. package/config/webpack.js +325 -309
  10. package/lib/assets/check.html +62 -62
  11. package/lib/assets/preact.js +4354 -4354
  12. package/lib/check/main.less +62 -62
  13. package/lib/check/main.tsx +41 -41
  14. package/lib/check/tool.js +3 -3
  15. package/lib/check/util.tsx +110 -110
  16. package/lib/grpc-web/dist/ChunkParser.js +117 -117
  17. package/lib/grpc-web/dist/Code.js +58 -58
  18. package/lib/grpc-web/dist/client.js +299 -299
  19. package/lib/grpc-web/dist/debug.js +16 -16
  20. package/lib/grpc-web/dist/detach.js +7 -7
  21. package/lib/grpc-web/dist/index.js +29 -29
  22. package/lib/grpc-web/dist/invoke.js +32 -32
  23. package/lib/grpc-web/dist/message.js +3 -3
  24. package/lib/grpc-web/dist/metadata.js +5 -5
  25. package/lib/grpc-web/dist/service.js +3 -3
  26. package/lib/grpc-web/dist/transports/Transport.js +15 -15
  27. package/lib/grpc-web/dist/transports/http/fetch.js +117 -117
  28. package/lib/grpc-web/dist/transports/http/http.js +15 -15
  29. package/lib/grpc-web/dist/transports/http/xhr.js +136 -136
  30. package/lib/grpc-web/dist/transports/http/xhrUtil.js +36 -36
  31. package/lib/grpc-web/dist/transports/websocket/websocket.js +95 -95
  32. package/lib/grpc-web/dist/typings/ChunkParser.d.ts +17 -17
  33. package/lib/grpc-web/dist/typings/Code.d.ts +20 -20
  34. package/lib/grpc-web/dist/typings/client.d.ts +25 -25
  35. package/lib/grpc-web/dist/typings/debug.d.ts +1 -1
  36. package/lib/grpc-web/dist/typings/detach.d.ts +1 -1
  37. package/lib/grpc-web/dist/typings/index.d.ts +45 -45
  38. package/lib/grpc-web/dist/typings/invoke.d.ts +20 -20
  39. package/lib/grpc-web/dist/typings/message.d.ts +8 -8
  40. package/lib/grpc-web/dist/typings/metadata.d.ts +2 -2
  41. package/lib/grpc-web/dist/typings/service.d.ts +16 -16
  42. package/lib/grpc-web/dist/typings/transports/Transport.d.ts +22 -22
  43. package/lib/grpc-web/dist/typings/transports/http/fetch.d.ts +6 -6
  44. package/lib/grpc-web/dist/typings/transports/http/http.d.ts +5 -5
  45. package/lib/grpc-web/dist/typings/transports/http/xhr.d.ts +27 -27
  46. package/lib/grpc-web/dist/typings/transports/http/xhrUtil.d.ts +3 -3
  47. package/lib/grpc-web/dist/typings/transports/websocket/websocket.d.ts +2 -2
  48. package/lib/grpc-web/dist/typings/unary.d.ts +23 -23
  49. package/lib/grpc-web/dist/typings/util.d.ts +2 -2
  50. package/lib/grpc-web/dist/unary.js +44 -44
  51. package/lib/grpc-web/dist/util.js +11 -11
  52. package/lib/grpcTransport/PixHttp2Transport.ts +107 -107
  53. package/lib/grpcTransport/PixLuaTransport.ts +82 -82
  54. package/lib/h5es-types/v1.9.2/h5es.d.ts +1698 -1698
  55. package/lib/h5es-types/v3.5.0/h5es.d.ts +1788 -1788
  56. package/lib/pi_component/tinyList/tinyList.js +483 -483
  57. package/lib/pi_component/tinyList/tinyList.tsx +517 -517
  58. package/lib/preact-router.js +395 -395
  59. package/lib/preact.js +4355 -4355
  60. package/lib/preact.tq.js +4385 -4385
  61. package/lib/react-window/src/FixedSizeGrid.js +172 -172
  62. package/lib/react-window/src/FixedSizeList.js +91 -91
  63. package/lib/react-window/src/VariableSizeGrid.js +329 -329
  64. package/lib/react-window/src/VariableSizeList.js +231 -231
  65. package/lib/react-window/src/__tests__/FixedSizeGrid.js +942 -942
  66. package/lib/react-window/src/__tests__/FixedSizeList.js +749 -749
  67. package/lib/react-window/src/__tests__/VariableSizeGrid.js +598 -598
  68. package/lib/react-window/src/__tests__/VariableSizeList.js +345 -345
  69. package/lib/react-window/src/__tests__/__snapshots__/FixedSizeGrid.js.snap +912 -912
  70. package/lib/react-window/src/__tests__/__snapshots__/FixedSizeList.js.snap +568 -568
  71. package/lib/react-window/src/__tests__/__snapshots__/VariableSizeGrid.js.snap +542 -542
  72. package/lib/react-window/src/__tests__/__snapshots__/VariableSizeList.js.snap +331 -331
  73. package/lib/react-window/src/__tests__/areEqual.js +28 -28
  74. package/lib/react-window/src/__tests__/shouldComponentUpdate.js +32 -32
  75. package/lib/react-window/src/areEqual.js +13 -13
  76. package/lib/react-window/src/createGridComponent.js +657 -657
  77. package/lib/react-window/src/createListComponent.js +574 -574
  78. package/lib/react-window/src/domHelpers.js +69 -69
  79. package/lib/react-window/src/index.js +9 -9
  80. package/lib/react-window/src/shallowDiffers.js +17 -17
  81. package/lib/react-window/src/shouldComponentUpdate.js +11 -11
  82. package/lib/react-window/src/test.js.flow +382 -382
  83. package/lib/react-window/src/timer.js +36 -36
  84. package/lib/types/dom.ts +17 -17
  85. package/lib/types/ext.d.ts +81 -81
  86. package/lib/types/preact/css.d.ts +7476 -7476
  87. package/lib/types/preact/index.d.ts +340 -340
  88. package/lib/types/preact/internal.d.ts +94 -94
  89. package/lib/types/preact/jsx.d.ts +309 -309
  90. package/lib/types/preact-router/index.d.ts +84 -84
  91. package/package.json +113 -113
  92. package/scripts/pack.js +40 -40
  93. package/scripts/postinstall.js +11 -11
  94. package/scripts/run-pxw.js +12 -12
  95. package/tsconfig.json +30 -30
@@ -1,63 +1,63 @@
1
- @baseColor: #6dffa7;
2
- @spinColor: spin(@baseColor, 150);
3
-
4
- .bottomTabBtn{
5
- font-size:25px;
6
- color: black;
7
- }
8
- .bottomTabBtnActive{
9
- font-size:30px;
10
- color: red;
11
- }
12
-
13
- .btn{
14
- border: 1px solid black;
15
- padding: 10px;
16
- border-radius: 0.5rem;
17
- justify-content: center;
18
- cursor: pointer;
19
- &:hover {
20
- background-color: rgb(173, 120, 220);
21
- }
22
- }
23
-
24
-
25
- .title {
26
- font-size: 1.2em;
27
- vertical-align: middle;
28
- //margin-top: 10px;
29
- color: @spinColor;
30
- }
31
-
32
- .wp95{
33
- width: 95%;
34
- }
35
-
36
- .redFont{
37
- color: red;
38
- display: inline-block;
39
- }
40
-
41
- .flexrow{
42
- display: flex;
43
- flex-direction: row;
44
- justify-content: space-evenly;
45
- width: 100%;
46
- // font-size: 35px;
47
- color: @spinColor
48
- }
49
-
50
- @keyframes App-logo-spin {
51
- from {
52
- transform: rotate(0deg);
53
- }
54
- to {
55
- transform: rotate(360deg);
56
- }
57
- }
58
-
59
-
60
- .bkimage{
61
- font-size: 30px;
62
- background-image: url(../assets/border.png);
1
+ @baseColor: #6dffa7;
2
+ @spinColor: spin(@baseColor, 150);
3
+
4
+ .bottomTabBtn{
5
+ font-size:25px;
6
+ color: black;
7
+ }
8
+ .bottomTabBtnActive{
9
+ font-size:30px;
10
+ color: red;
11
+ }
12
+
13
+ .btn{
14
+ border: 1px solid black;
15
+ padding: 10px;
16
+ border-radius: 0.5rem;
17
+ justify-content: center;
18
+ cursor: pointer;
19
+ &:hover {
20
+ background-color: rgb(173, 120, 220);
21
+ }
22
+ }
23
+
24
+
25
+ .title {
26
+ font-size: 1.2em;
27
+ vertical-align: middle;
28
+ //margin-top: 10px;
29
+ color: @spinColor;
30
+ }
31
+
32
+ .wp95{
33
+ width: 95%;
34
+ }
35
+
36
+ .redFont{
37
+ color: red;
38
+ display: inline-block;
39
+ }
40
+
41
+ .flexrow{
42
+ display: flex;
43
+ flex-direction: row;
44
+ justify-content: space-evenly;
45
+ width: 100%;
46
+ // font-size: 35px;
47
+ color: @spinColor
48
+ }
49
+
50
+ @keyframes App-logo-spin {
51
+ from {
52
+ transform: rotate(0deg);
53
+ }
54
+ to {
55
+ transform: rotate(360deg);
56
+ }
57
+ }
58
+
59
+
60
+ .bkimage{
61
+ font-size: 30px;
62
+ background-image: url(../assets/border.png);
63
63
  }
@@ -1,41 +1,41 @@
1
- import { render } from '../types/dom';
2
- import { getView } from './util';
3
- import { hello } from './tool';
4
-
5
- let renderJSX = () => {
6
- let v = getView();
7
- render(v, document.getElementById('container')!);
8
- };
9
-
10
- let setTimer = () => {
11
- let div = document.getElementById('timer');
12
- let x = 1;
13
- setInterval(() => {
14
- div!.innerHTML = `prove this page is not refresh: time:${x++}`;
15
- }, 100);
16
- };
17
-
18
- renderJSX();
19
- setTimer();
20
- hello();
21
-
22
- window.onerror = (evt) => {
23
- let e = evt as ErrorEvent;
24
- console.log('!!! onerror', e.message);
25
- };
26
-
27
- // if (module.hot) {
28
- // console.log('setup hot reload!');
29
- // // prettier-ignore
30
- // module.hot.accept([
31
- // './util.tsx',
32
- // ], (): void => {
33
- // console.log('***** accept App hot update 1*******');
34
- // renderJSX();
35
- // console.log('***** accept App hot update 2*******');
36
- // });
37
- // }
38
-
39
- if (false) {
40
- throw new Error('throw an error');
41
- }
1
+ import { render } from '../types/dom';
2
+ import { getView } from './util';
3
+ import { hello } from './tool';
4
+
5
+ let renderJSX = () => {
6
+ let v = getView();
7
+ render(v, document.getElementById('container')!);
8
+ };
9
+
10
+ let setTimer = () => {
11
+ let div = document.getElementById('timer');
12
+ let x = 1;
13
+ setInterval(() => {
14
+ div!.innerHTML = `prove this page is not refresh: time:${x++}`;
15
+ }, 100);
16
+ };
17
+
18
+ renderJSX();
19
+ setTimer();
20
+ hello();
21
+
22
+ window.onerror = (evt) => {
23
+ let e = evt as ErrorEvent;
24
+ console.log('!!! onerror', e.message);
25
+ };
26
+
27
+ // if (module.hot) {
28
+ // console.log('setup hot reload!');
29
+ // // prettier-ignore
30
+ // module.hot.accept([
31
+ // './util.tsx',
32
+ // ], (): void => {
33
+ // console.log('***** accept App hot update 1*******');
34
+ // renderJSX();
35
+ // console.log('***** accept App hot update 2*******');
36
+ // });
37
+ // }
38
+
39
+ if (false) {
40
+ throw new Error('throw an error');
41
+ }
package/lib/check/tool.js CHANGED
@@ -1,3 +1,3 @@
1
- export let hello = () => {
2
- return 'hello world';
3
- };
1
+ export let hello = () => {
2
+ return 'hello world';
3
+ };
@@ -1,110 +1,110 @@
1
- import { h, Component } from 'preact';
2
- import { Router, Link } from 'preact-router';
3
- import css from './main.less';
4
- import pix from '../assets/pixui.png';
5
- import preact from '../assets/preact.png';
6
- import border from '../assets/border.png';
7
-
8
- type State = {
9
- value: number;
10
- };
11
- class Counter extends Component<any, State> {
12
- state = {
13
- value: 0,
14
- };
15
-
16
- increment = () => {
17
- this.setState((prev) => ({ value: prev.value + 1 }));
18
- };
19
-
20
- render(props, state) {
21
- return (
22
- <div
23
- style={{
24
- display: 'flex',
25
- flexDirection: 'row',
26
- // color: '#f93f00',
27
- backgroundColor: state.value % 2 ? '#992288' : '#33ff54',
28
- }}
29
- >
30
- Counter: {state.value}
31
- <div style={{ width: '20px' }} />
32
- <div onClick={this.increment}>Increment</div>
33
- </div>
34
- );
35
- }
36
- }
37
-
38
- let wp = (p) => (p ? `/selfcheck/${p}` : '/selfcheck');
39
-
40
- class Title extends Component<any, { title: string }> {
41
- state = {
42
- title: 'hello,pixui',
43
- };
44
-
45
- render(props, state) {
46
- return (
47
- <div
48
- style={{
49
- display: 'flex',
50
- flexDirection: 'column',
51
- backgroundColor: '#f98833',
52
- }}
53
- >
54
- title: {state.title}
55
- <Link href={wp('')}>back home</Link>
56
- </div>
57
- );
58
- }
59
- }
60
-
61
- let makeError1 = () => {
62
- throw new Error('throw an error');
63
- };
64
-
65
- let makeError2 = (p?: any) => {
66
- let b = p.name;
67
- };
68
- let makeError3 = async () => {
69
- return JSON.parse('sdf={]');
70
- };
71
-
72
- export const getView = () => {
73
- return (
74
- <div style={{ width: '99%' }}>
75
- {/* <Counter /> */}
76
- <Router>
77
- <Counter loggedIn={true} path={wp('')} />
78
- <Title path={wp('hi')} />
79
- </Router>
80
- <Link href={wp('hi')}>Profile</Link>
81
- <div className={css.flexrow}>
82
- <img
83
- src={preact}
84
- width={200}
85
- height={200}
86
- onClick={() => {
87
- console.log('click preact...');
88
- makeError2();
89
- }}
90
- ></img>
91
- <img src={pix} width={200} height={200}></img>
92
- <div style={{ border: '1px solid black', width: 200, height: 200 }}>
93
- <video autoPlay={true} loop={true} src={'https://www.runoob.com/try/demo_source/mov_bbb.mp4'} style={{ width: 200, height: 200 }} />
94
- </div>
95
- </div>
96
- <div style={{ alignItems: 'center', margin: 10, fontSize: 30 }}>
97
- <div onClick={(e) => console.log('click', e)}>PixUI is an embeddable h5-like ui engine</div>
98
- <text style={{ display: 'flex', flexDirection: 'row' }}>
99
- <div style={{ color: 'red' }}>CP</div>react is a preact written by c++
100
- </text>
101
- <div>with webpack and typescript workflow</div>
102
- </div>
103
- <div className={css.flexrow} style={{ fontSize: 40 }}>
104
- <div>easy </div>
105
- <div>beautiful</div>
106
- <div>crossplatform</div>
107
- </div>
108
- </div>
109
- );
110
- };
1
+ import { h, Component } from 'preact';
2
+ import { Router, Link } from 'preact-router';
3
+ import css from './main.less';
4
+ import pix from '../assets/pixui.png';
5
+ import preact from '../assets/preact.png';
6
+ import border from '../assets/border.png';
7
+
8
+ type State = {
9
+ value: number;
10
+ };
11
+ class Counter extends Component<any, State> {
12
+ state = {
13
+ value: 0,
14
+ };
15
+
16
+ increment = () => {
17
+ this.setState((prev) => ({ value: prev.value + 1 }));
18
+ };
19
+
20
+ render(props, state) {
21
+ return (
22
+ <div
23
+ style={{
24
+ display: 'flex',
25
+ flexDirection: 'row',
26
+ // color: '#f93f00',
27
+ backgroundColor: state.value % 2 ? '#992288' : '#33ff54',
28
+ }}
29
+ >
30
+ Counter: {state.value}
31
+ <div style={{ width: '20px' }} />
32
+ <div onClick={this.increment}>Increment</div>
33
+ </div>
34
+ );
35
+ }
36
+ }
37
+
38
+ let wp = (p) => (p ? `/selfcheck/${p}` : '/selfcheck');
39
+
40
+ class Title extends Component<any, { title: string }> {
41
+ state = {
42
+ title: 'hello,pixui',
43
+ };
44
+
45
+ render(props, state) {
46
+ return (
47
+ <div
48
+ style={{
49
+ display: 'flex',
50
+ flexDirection: 'column',
51
+ backgroundColor: '#f98833',
52
+ }}
53
+ >
54
+ title: {state.title}
55
+ <Link href={wp('')}>back home</Link>
56
+ </div>
57
+ );
58
+ }
59
+ }
60
+
61
+ let makeError1 = () => {
62
+ throw new Error('throw an error');
63
+ };
64
+
65
+ let makeError2 = (p?: any) => {
66
+ let b = p.name;
67
+ };
68
+ let makeError3 = async () => {
69
+ return JSON.parse('sdf={]');
70
+ };
71
+
72
+ export const getView = () => {
73
+ return (
74
+ <div style={{ width: '99%' }}>
75
+ {/* <Counter /> */}
76
+ <Router>
77
+ <Counter loggedIn={true} path={wp('')} />
78
+ <Title path={wp('hi')} />
79
+ </Router>
80
+ <Link href={wp('hi')}>Profile</Link>
81
+ <div className={css.flexrow}>
82
+ <img
83
+ src={preact}
84
+ width={200}
85
+ height={200}
86
+ onClick={() => {
87
+ console.log('click preact...');
88
+ makeError2();
89
+ }}
90
+ ></img>
91
+ <img src={pix} width={200} height={200}></img>
92
+ <div style={{ border: '1px solid black', width: 200, height: 200 }}>
93
+ <video autoPlay={true} loop={true} src={'https://www.runoob.com/try/demo_source/mov_bbb.mp4'} style={{ width: 200, height: 200 }} />
94
+ </div>
95
+ </div>
96
+ <div style={{ alignItems: 'center', margin: 10, fontSize: 30 }}>
97
+ <div onClick={(e) => console.log('click', e)}>PixUI is an embeddable h5-like ui engine</div>
98
+ <text style={{ display: 'flex', flexDirection: 'row' }}>
99
+ <div style={{ color: 'red' }}>CP</div>react is a preact written by c++
100
+ </text>
101
+ <div>with webpack and typescript workflow</div>
102
+ </div>
103
+ <div className={css.flexrow} style={{ fontSize: 40 }}>
104
+ <div>easy </div>
105
+ <div>beautiful</div>
106
+ <div>crossplatform</div>
107
+ </div>
108
+ </div>
109
+ );
110
+ };
@@ -1,117 +1,117 @@
1
- 'use strict';
2
- Object.defineProperty(exports, '__esModule', { value: true });
3
- var metadata_1 = require('./metadata');
4
- var HEADER_SIZE = 5;
5
- var isAllowedControlChars = function (char) {
6
- return char === 0x9 || char === 0xa || char === 0xd;
7
- };
8
- function isValidHeaderAscii(val) {
9
- return isAllowedControlChars(val) || (val >= 0x20 && val <= 0x7e);
10
- }
11
- function decodeASCII(input) {
12
- for (var i = 0; i !== input.length; ++i) {
13
- if (!isValidHeaderAscii(input[i])) {
14
- throw new Error('Metadata is not valid (printable) ASCII');
15
- }
16
- }
17
- return String.fromCharCode.apply(String, Array.prototype.slice.call(input));
18
- }
19
- exports.decodeASCII = decodeASCII;
20
- function encodeASCII(input) {
21
- var encoded = new Uint8Array(input.length);
22
- for (var i = 0; i !== input.length; ++i) {
23
- var charCode = input.charCodeAt(i);
24
- if (!isValidHeaderAscii(charCode)) {
25
- throw new Error('Metadata contains invalid ASCII');
26
- }
27
- encoded[i] = charCode;
28
- }
29
- return encoded;
30
- }
31
- exports.encodeASCII = encodeASCII;
32
- function isTrailerHeader(headerView) {
33
- return (headerView.getUint8(0) & 0x80) === 0x80;
34
- }
35
- function parseTrailerData(msgData) {
36
- return new metadata_1.Metadata(decodeASCII(msgData));
37
- }
38
- function readLengthFromHeader(headerView) {
39
- return headerView.getUint32(1, false);
40
- }
41
- function hasEnoughBytes(buffer, position, byteCount) {
42
- return buffer.byteLength - position >= byteCount;
43
- }
44
- function sliceUint8Array(buffer, from, to) {
45
- if (buffer.slice) {
46
- return buffer.slice(from, to);
47
- }
48
- var end = buffer.length;
49
- if (to !== undefined) {
50
- end = to;
51
- }
52
- var num = end - from;
53
- var array = new Uint8Array(num);
54
- var arrayIndex = 0;
55
- for (var i = from; i < end; i++) {
56
- array[arrayIndex++] = buffer[i];
57
- }
58
- return array;
59
- }
60
- var ChunkType;
61
- (function (ChunkType) {
62
- ChunkType[(ChunkType['MESSAGE'] = 1)] = 'MESSAGE';
63
- ChunkType[(ChunkType['TRAILERS'] = 2)] = 'TRAILERS';
64
- })((ChunkType = exports.ChunkType || (exports.ChunkType = {})));
65
- var ChunkParser = (function () {
66
- function ChunkParser() {
67
- this.buffer = null;
68
- this.position = 0;
69
- }
70
- ChunkParser.prototype.parse = function (bytes, flush) {
71
- if (bytes.length === 0 && flush) {
72
- return [];
73
- }
74
- var chunkData = [];
75
- if (this.buffer == null) {
76
- this.buffer = bytes;
77
- this.position = 0;
78
- }
79
- else if (this.position === this.buffer.byteLength) {
80
- this.buffer = bytes;
81
- this.position = 0;
82
- }
83
- else {
84
- var remaining = this.buffer.byteLength - this.position;
85
- var newBuf = new Uint8Array(remaining + bytes.byteLength);
86
- var fromExisting = sliceUint8Array(this.buffer, this.position);
87
- newBuf.set(fromExisting, 0);
88
- var latestDataBuf = new Uint8Array(bytes);
89
- newBuf.set(latestDataBuf, remaining);
90
- this.buffer = newBuf;
91
- this.position = 0;
92
- }
93
- while (true) {
94
- if (!hasEnoughBytes(this.buffer, this.position, HEADER_SIZE)) {
95
- return chunkData;
96
- }
97
- var headerBuffer = sliceUint8Array(this.buffer, this.position, this.position + HEADER_SIZE);
98
- var headerView = new DataView(headerBuffer.buffer, headerBuffer.byteOffset, headerBuffer.byteLength);
99
- var msgLength = readLengthFromHeader(headerView);
100
- if (!hasEnoughBytes(this.buffer, this.position, HEADER_SIZE + msgLength)) {
101
- return chunkData;
102
- }
103
- var messageData = sliceUint8Array(this.buffer, this.position + HEADER_SIZE, this.position + HEADER_SIZE + msgLength);
104
- this.position += HEADER_SIZE + msgLength;
105
- if (isTrailerHeader(headerView)) {
106
- chunkData.push({ chunkType: ChunkType.TRAILERS, trailers: parseTrailerData(messageData) });
107
- return chunkData;
108
- }
109
- else {
110
- chunkData.push({ chunkType: ChunkType.MESSAGE, data: messageData });
111
- }
112
- }
113
- };
114
- return ChunkParser;
115
- })();
116
- exports.ChunkParser = ChunkParser;
117
- //# sourceMappingURL=ChunkParser.js.map
1
+ 'use strict';
2
+ Object.defineProperty(exports, '__esModule', { value: true });
3
+ var metadata_1 = require('./metadata');
4
+ var HEADER_SIZE = 5;
5
+ var isAllowedControlChars = function (char) {
6
+ return char === 0x9 || char === 0xa || char === 0xd;
7
+ };
8
+ function isValidHeaderAscii(val) {
9
+ return isAllowedControlChars(val) || (val >= 0x20 && val <= 0x7e);
10
+ }
11
+ function decodeASCII(input) {
12
+ for (var i = 0; i !== input.length; ++i) {
13
+ if (!isValidHeaderAscii(input[i])) {
14
+ throw new Error('Metadata is not valid (printable) ASCII');
15
+ }
16
+ }
17
+ return String.fromCharCode.apply(String, Array.prototype.slice.call(input));
18
+ }
19
+ exports.decodeASCII = decodeASCII;
20
+ function encodeASCII(input) {
21
+ var encoded = new Uint8Array(input.length);
22
+ for (var i = 0; i !== input.length; ++i) {
23
+ var charCode = input.charCodeAt(i);
24
+ if (!isValidHeaderAscii(charCode)) {
25
+ throw new Error('Metadata contains invalid ASCII');
26
+ }
27
+ encoded[i] = charCode;
28
+ }
29
+ return encoded;
30
+ }
31
+ exports.encodeASCII = encodeASCII;
32
+ function isTrailerHeader(headerView) {
33
+ return (headerView.getUint8(0) & 0x80) === 0x80;
34
+ }
35
+ function parseTrailerData(msgData) {
36
+ return new metadata_1.Metadata(decodeASCII(msgData));
37
+ }
38
+ function readLengthFromHeader(headerView) {
39
+ return headerView.getUint32(1, false);
40
+ }
41
+ function hasEnoughBytes(buffer, position, byteCount) {
42
+ return buffer.byteLength - position >= byteCount;
43
+ }
44
+ function sliceUint8Array(buffer, from, to) {
45
+ if (buffer.slice) {
46
+ return buffer.slice(from, to);
47
+ }
48
+ var end = buffer.length;
49
+ if (to !== undefined) {
50
+ end = to;
51
+ }
52
+ var num = end - from;
53
+ var array = new Uint8Array(num);
54
+ var arrayIndex = 0;
55
+ for (var i = from; i < end; i++) {
56
+ array[arrayIndex++] = buffer[i];
57
+ }
58
+ return array;
59
+ }
60
+ var ChunkType;
61
+ (function (ChunkType) {
62
+ ChunkType[(ChunkType['MESSAGE'] = 1)] = 'MESSAGE';
63
+ ChunkType[(ChunkType['TRAILERS'] = 2)] = 'TRAILERS';
64
+ })((ChunkType = exports.ChunkType || (exports.ChunkType = {})));
65
+ var ChunkParser = (function () {
66
+ function ChunkParser() {
67
+ this.buffer = null;
68
+ this.position = 0;
69
+ }
70
+ ChunkParser.prototype.parse = function (bytes, flush) {
71
+ if (bytes.length === 0 && flush) {
72
+ return [];
73
+ }
74
+ var chunkData = [];
75
+ if (this.buffer == null) {
76
+ this.buffer = bytes;
77
+ this.position = 0;
78
+ }
79
+ else if (this.position === this.buffer.byteLength) {
80
+ this.buffer = bytes;
81
+ this.position = 0;
82
+ }
83
+ else {
84
+ var remaining = this.buffer.byteLength - this.position;
85
+ var newBuf = new Uint8Array(remaining + bytes.byteLength);
86
+ var fromExisting = sliceUint8Array(this.buffer, this.position);
87
+ newBuf.set(fromExisting, 0);
88
+ var latestDataBuf = new Uint8Array(bytes);
89
+ newBuf.set(latestDataBuf, remaining);
90
+ this.buffer = newBuf;
91
+ this.position = 0;
92
+ }
93
+ while (true) {
94
+ if (!hasEnoughBytes(this.buffer, this.position, HEADER_SIZE)) {
95
+ return chunkData;
96
+ }
97
+ var headerBuffer = sliceUint8Array(this.buffer, this.position, this.position + HEADER_SIZE);
98
+ var headerView = new DataView(headerBuffer.buffer, headerBuffer.byteOffset, headerBuffer.byteLength);
99
+ var msgLength = readLengthFromHeader(headerView);
100
+ if (!hasEnoughBytes(this.buffer, this.position, HEADER_SIZE + msgLength)) {
101
+ return chunkData;
102
+ }
103
+ var messageData = sliceUint8Array(this.buffer, this.position + HEADER_SIZE, this.position + HEADER_SIZE + msgLength);
104
+ this.position += HEADER_SIZE + msgLength;
105
+ if (isTrailerHeader(headerView)) {
106
+ chunkData.push({ chunkType: ChunkType.TRAILERS, trailers: parseTrailerData(messageData) });
107
+ return chunkData;
108
+ }
109
+ else {
110
+ chunkData.push({ chunkType: ChunkType.MESSAGE, data: messageData });
111
+ }
112
+ }
113
+ };
114
+ return ChunkParser;
115
+ })();
116
+ exports.ChunkParser = ChunkParser;
117
+ //# sourceMappingURL=ChunkParser.js.map