@seed-ship/mcp-ui-solid 3.0.5 → 4.0.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/CHANGELOG.md +115 -0
- package/README.md +253 -280
- package/dist/components/ChartJSRenderer.cjs +37 -15
- package/dist/components/ChartJSRenderer.cjs.map +1 -1
- package/dist/components/ChartJSRenderer.d.ts.map +1 -1
- package/dist/components/ChartJSRenderer.js +37 -15
- package/dist/components/ChartJSRenderer.js.map +1 -1
- package/dist/components/DataPreviewSection.cjs +172 -0
- package/dist/components/DataPreviewSection.cjs.map +1 -0
- package/dist/components/DataPreviewSection.d.ts +19 -0
- package/dist/components/DataPreviewSection.d.ts.map +1 -0
- package/dist/components/DataPreviewSection.js +172 -0
- package/dist/components/DataPreviewSection.js.map +1 -0
- package/dist/components/MapRenderer.cjs +168 -26
- package/dist/components/MapRenderer.cjs.map +1 -1
- package/dist/components/MapRenderer.d.ts +2 -2
- package/dist/components/MapRenderer.d.ts.map +1 -1
- package/dist/components/MapRenderer.js +169 -27
- package/dist/components/MapRenderer.js.map +1 -1
- package/dist/components/ScratchpadPanel.cjs +74 -0
- package/dist/components/ScratchpadPanel.cjs.map +1 -1
- package/dist/components/ScratchpadPanel.d.ts.map +1 -1
- package/dist/components/ScratchpadPanel.js +75 -1
- package/dist/components/ScratchpadPanel.js.map +1 -1
- package/dist/components/VerifiedText.cjs +166 -0
- package/dist/components/VerifiedText.cjs.map +1 -0
- package/dist/components/VerifiedText.d.ts +22 -0
- package/dist/components/VerifiedText.d.ts.map +1 -0
- package/dist/components/VerifiedText.js +166 -0
- package/dist/components/VerifiedText.js.map +1 -0
- package/dist/components/index.d.ts +4 -0
- package/dist/components/index.d.ts.map +1 -1
- package/dist/components.cjs +4 -0
- package/dist/components.cjs.map +1 -1
- package/dist/components.d.cts +4 -0
- package/dist/components.d.ts +4 -0
- package/dist/components.js +4 -0
- package/dist/components.js.map +1 -1
- package/dist/hooks/index.d.ts +2 -0
- package/dist/hooks/index.d.ts.map +1 -1
- package/dist/hooks/useDataValidator.cjs +31 -0
- package/dist/hooks/useDataValidator.cjs.map +1 -0
- package/dist/hooks/useDataValidator.d.ts +42 -0
- package/dist/hooks/useDataValidator.d.ts.map +1 -0
- package/dist/hooks/useDataValidator.js +31 -0
- package/dist/hooks/useDataValidator.js.map +1 -0
- package/dist/hooks.cjs +2 -0
- package/dist/hooks.cjs.map +1 -1
- package/dist/hooks.d.cts +2 -0
- package/dist/hooks.d.ts +2 -0
- package/dist/hooks.js +2 -0
- package/dist/hooks.js.map +1 -1
- package/dist/index.cjs +8 -0
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +9 -5
- package/dist/index.d.ts +9 -5
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +8 -0
- package/dist/index.js.map +1 -1
- package/dist/node_modules/.pnpm/@mapbox_point-geometry@1.1.0/node_modules/@mapbox/point-geometry/index.cjs +290 -0
- package/dist/node_modules/.pnpm/@mapbox_point-geometry@1.1.0/node_modules/@mapbox/point-geometry/index.cjs.map +1 -0
- package/dist/node_modules/.pnpm/@mapbox_point-geometry@1.1.0/node_modules/@mapbox/point-geometry/index.js +291 -0
- package/dist/node_modules/.pnpm/@mapbox_point-geometry@1.1.0/node_modules/@mapbox/point-geometry/index.js.map +1 -0
- package/dist/node_modules/.pnpm/@mapbox_vector-tile@2.0.4/node_modules/@mapbox/vector-tile/index.cjs +243 -0
- package/dist/node_modules/.pnpm/@mapbox_vector-tile@2.0.4/node_modules/@mapbox/vector-tile/index.cjs.map +1 -0
- package/dist/node_modules/.pnpm/@mapbox_vector-tile@2.0.4/node_modules/@mapbox/vector-tile/index.js +243 -0
- package/dist/node_modules/.pnpm/@mapbox_vector-tile@2.0.4/node_modules/@mapbox/vector-tile/index.js.map +1 -0
- package/dist/node_modules/.pnpm/color2k@2.0.3/node_modules/color2k/dist/index.exports.import.es.cjs +137 -0
- package/dist/node_modules/.pnpm/color2k@2.0.3/node_modules/color2k/dist/index.exports.import.es.cjs.map +1 -0
- package/dist/node_modules/.pnpm/color2k@2.0.3/node_modules/color2k/dist/index.exports.import.es.js +137 -0
- package/dist/node_modules/.pnpm/color2k@2.0.3/node_modules/color2k/dist/index.exports.import.es.js.map +1 -0
- package/dist/node_modules/.pnpm/pbf@4.0.1/node_modules/pbf/index.cjs +686 -0
- package/dist/node_modules/.pnpm/pbf@4.0.1/node_modules/pbf/index.cjs.map +1 -0
- package/dist/node_modules/.pnpm/pbf@4.0.1/node_modules/pbf/index.js +687 -0
- package/dist/node_modules/.pnpm/pbf@4.0.1/node_modules/pbf/index.js.map +1 -0
- package/dist/node_modules/.pnpm/pmtiles@3.2.1/node_modules/pmtiles/dist/index.cjs +1366 -0
- package/dist/node_modules/.pnpm/pmtiles@3.2.1/node_modules/pmtiles/dist/index.cjs.map +1 -0
- package/dist/node_modules/.pnpm/pmtiles@3.2.1/node_modules/pmtiles/dist/index.js +1366 -0
- package/dist/node_modules/.pnpm/pmtiles@3.2.1/node_modules/pmtiles/dist/index.js.map +1 -0
- package/dist/node_modules/.pnpm/potpack@1.0.2/node_modules/potpack/index.cjs +54 -0
- package/dist/node_modules/.pnpm/potpack@1.0.2/node_modules/potpack/index.cjs.map +1 -0
- package/dist/node_modules/.pnpm/potpack@1.0.2/node_modules/potpack/index.js +55 -0
- package/dist/node_modules/.pnpm/potpack@1.0.2/node_modules/potpack/index.js.map +1 -0
- package/dist/node_modules/.pnpm/protomaps-leaflet@4.1.1/node_modules/protomaps-leaflet/dist/esm/index.cjs +1256 -0
- package/dist/node_modules/.pnpm/protomaps-leaflet@4.1.1/node_modules/protomaps-leaflet/dist/esm/index.cjs.map +1 -0
- package/dist/node_modules/.pnpm/protomaps-leaflet@4.1.1/node_modules/protomaps-leaflet/dist/esm/index.js +1256 -0
- package/dist/node_modules/.pnpm/protomaps-leaflet@4.1.1/node_modules/protomaps-leaflet/dist/esm/index.js.map +1 -0
- package/dist/node_modules/.pnpm/quickselect@2.0.0/node_modules/quickselect/index.cjs +47 -0
- package/dist/node_modules/.pnpm/quickselect@2.0.0/node_modules/quickselect/index.cjs.map +1 -0
- package/dist/node_modules/.pnpm/quickselect@2.0.0/node_modules/quickselect/index.js +48 -0
- package/dist/node_modules/.pnpm/quickselect@2.0.0/node_modules/quickselect/index.js.map +1 -0
- package/dist/node_modules/.pnpm/rbush@3.0.1/node_modules/rbush/index.cjs +378 -0
- package/dist/node_modules/.pnpm/rbush@3.0.1/node_modules/rbush/index.cjs.map +1 -0
- package/dist/node_modules/.pnpm/rbush@3.0.1/node_modules/rbush/index.js +379 -0
- package/dist/node_modules/.pnpm/rbush@3.0.1/node_modules/rbush/index.js.map +1 -0
- package/dist/services/data-validator.cjs +85 -0
- package/dist/services/data-validator.cjs.map +1 -0
- package/dist/services/data-validator.d.ts +28 -0
- package/dist/services/data-validator.d.ts.map +1 -0
- package/dist/services/data-validator.js +85 -0
- package/dist/services/data-validator.js.map +1 -0
- package/dist/services/index.d.ts +1 -0
- package/dist/services/index.d.ts.map +1 -1
- package/dist/types/chat-bus.d.ts +88 -1
- package/dist/types/chat-bus.d.ts.map +1 -1
- package/dist/types/index.d.ts +135 -6
- package/dist/types/index.d.ts.map +1 -1
- package/dist/types.d.cts +135 -6
- package/dist/types.d.ts +135 -6
- package/package.json +5 -1
- package/src/components/ChartJSRenderer.tsx +35 -13
- package/src/components/DataPreviewSection.tsx +206 -0
- package/src/components/MapRenderer.test.tsx +94 -5
- package/src/components/MapRenderer.tsx +246 -45
- package/src/components/ScratchpadPanel.tsx +10 -2
- package/src/components/VerifiedText.tsx +187 -0
- package/src/components/index.ts +7 -0
- package/src/hooks/index.ts +7 -0
- package/src/hooks/useDataValidator.ts +68 -0
- package/src/index.ts +26 -1
- package/src/services/data-validator.test.ts +151 -0
- package/src/services/data-validator.ts +149 -0
- package/src/services/index.ts +2 -0
- package/src/types/chat-bus.ts +98 -1
- package/src/types/index.ts +145 -6
- package/tsconfig.tsbuildinfo +1 -1
|
@@ -0,0 +1,687 @@
|
|
|
1
|
+
const SHIFT_LEFT_32 = (1 << 16) * (1 << 16);
|
|
2
|
+
const SHIFT_RIGHT_32 = 1 / SHIFT_LEFT_32;
|
|
3
|
+
const TEXT_DECODER_MIN_LENGTH = 12;
|
|
4
|
+
const utf8TextDecoder = typeof TextDecoder === "undefined" ? null : new TextDecoder("utf-8");
|
|
5
|
+
const PBF_VARINT = 0;
|
|
6
|
+
const PBF_FIXED64 = 1;
|
|
7
|
+
const PBF_BYTES = 2;
|
|
8
|
+
const PBF_FIXED32 = 5;
|
|
9
|
+
class Pbf {
|
|
10
|
+
/**
|
|
11
|
+
* @param {Uint8Array | ArrayBuffer} [buf]
|
|
12
|
+
*/
|
|
13
|
+
constructor(buf = new Uint8Array(16)) {
|
|
14
|
+
this.buf = ArrayBuffer.isView(buf) ? buf : new Uint8Array(buf);
|
|
15
|
+
this.dataView = new DataView(this.buf.buffer);
|
|
16
|
+
this.pos = 0;
|
|
17
|
+
this.type = 0;
|
|
18
|
+
this.length = this.buf.length;
|
|
19
|
+
}
|
|
20
|
+
// === READING =================================================================
|
|
21
|
+
/**
|
|
22
|
+
* @template T
|
|
23
|
+
* @param {(tag: number, result: T, pbf: Pbf) => void} readField
|
|
24
|
+
* @param {T} result
|
|
25
|
+
* @param {number} [end]
|
|
26
|
+
*/
|
|
27
|
+
readFields(readField, result, end = this.length) {
|
|
28
|
+
while (this.pos < end) {
|
|
29
|
+
const val = this.readVarint(), tag = val >> 3, startPos = this.pos;
|
|
30
|
+
this.type = val & 7;
|
|
31
|
+
readField(tag, result, this);
|
|
32
|
+
if (this.pos === startPos) this.skip(val);
|
|
33
|
+
}
|
|
34
|
+
return result;
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* @template T
|
|
38
|
+
* @param {(tag: number, result: T, pbf: Pbf) => void} readField
|
|
39
|
+
* @param {T} result
|
|
40
|
+
*/
|
|
41
|
+
readMessage(readField, result) {
|
|
42
|
+
return this.readFields(readField, result, this.readVarint() + this.pos);
|
|
43
|
+
}
|
|
44
|
+
readFixed32() {
|
|
45
|
+
const val = this.dataView.getUint32(this.pos, true);
|
|
46
|
+
this.pos += 4;
|
|
47
|
+
return val;
|
|
48
|
+
}
|
|
49
|
+
readSFixed32() {
|
|
50
|
+
const val = this.dataView.getInt32(this.pos, true);
|
|
51
|
+
this.pos += 4;
|
|
52
|
+
return val;
|
|
53
|
+
}
|
|
54
|
+
// 64-bit int handling is based on github.com/dpw/node-buffer-more-ints (MIT-licensed)
|
|
55
|
+
readFixed64() {
|
|
56
|
+
const val = this.dataView.getUint32(this.pos, true) + this.dataView.getUint32(this.pos + 4, true) * SHIFT_LEFT_32;
|
|
57
|
+
this.pos += 8;
|
|
58
|
+
return val;
|
|
59
|
+
}
|
|
60
|
+
readSFixed64() {
|
|
61
|
+
const val = this.dataView.getUint32(this.pos, true) + this.dataView.getInt32(this.pos + 4, true) * SHIFT_LEFT_32;
|
|
62
|
+
this.pos += 8;
|
|
63
|
+
return val;
|
|
64
|
+
}
|
|
65
|
+
readFloat() {
|
|
66
|
+
const val = this.dataView.getFloat32(this.pos, true);
|
|
67
|
+
this.pos += 4;
|
|
68
|
+
return val;
|
|
69
|
+
}
|
|
70
|
+
readDouble() {
|
|
71
|
+
const val = this.dataView.getFloat64(this.pos, true);
|
|
72
|
+
this.pos += 8;
|
|
73
|
+
return val;
|
|
74
|
+
}
|
|
75
|
+
/**
|
|
76
|
+
* @param {boolean} [isSigned]
|
|
77
|
+
*/
|
|
78
|
+
readVarint(isSigned) {
|
|
79
|
+
const buf = this.buf;
|
|
80
|
+
let val, b;
|
|
81
|
+
b = buf[this.pos++];
|
|
82
|
+
val = b & 127;
|
|
83
|
+
if (b < 128) return val;
|
|
84
|
+
b = buf[this.pos++];
|
|
85
|
+
val |= (b & 127) << 7;
|
|
86
|
+
if (b < 128) return val;
|
|
87
|
+
b = buf[this.pos++];
|
|
88
|
+
val |= (b & 127) << 14;
|
|
89
|
+
if (b < 128) return val;
|
|
90
|
+
b = buf[this.pos++];
|
|
91
|
+
val |= (b & 127) << 21;
|
|
92
|
+
if (b < 128) return val;
|
|
93
|
+
b = buf[this.pos];
|
|
94
|
+
val |= (b & 15) << 28;
|
|
95
|
+
return readVarintRemainder(val, isSigned, this);
|
|
96
|
+
}
|
|
97
|
+
readVarint64() {
|
|
98
|
+
return this.readVarint(true);
|
|
99
|
+
}
|
|
100
|
+
readSVarint() {
|
|
101
|
+
const num = this.readVarint();
|
|
102
|
+
return num % 2 === 1 ? (num + 1) / -2 : num / 2;
|
|
103
|
+
}
|
|
104
|
+
readBoolean() {
|
|
105
|
+
return Boolean(this.readVarint());
|
|
106
|
+
}
|
|
107
|
+
readString() {
|
|
108
|
+
const end = this.readVarint() + this.pos;
|
|
109
|
+
const pos = this.pos;
|
|
110
|
+
this.pos = end;
|
|
111
|
+
if (end - pos >= TEXT_DECODER_MIN_LENGTH && utf8TextDecoder) {
|
|
112
|
+
return utf8TextDecoder.decode(this.buf.subarray(pos, end));
|
|
113
|
+
}
|
|
114
|
+
return readUtf8(this.buf, pos, end);
|
|
115
|
+
}
|
|
116
|
+
readBytes() {
|
|
117
|
+
const end = this.readVarint() + this.pos, buffer = this.buf.subarray(this.pos, end);
|
|
118
|
+
this.pos = end;
|
|
119
|
+
return buffer;
|
|
120
|
+
}
|
|
121
|
+
// verbose for performance reasons; doesn't affect gzipped size
|
|
122
|
+
/**
|
|
123
|
+
* @param {number[]} [arr]
|
|
124
|
+
* @param {boolean} [isSigned]
|
|
125
|
+
*/
|
|
126
|
+
readPackedVarint(arr = [], isSigned) {
|
|
127
|
+
const end = this.readPackedEnd();
|
|
128
|
+
while (this.pos < end) arr.push(this.readVarint(isSigned));
|
|
129
|
+
return arr;
|
|
130
|
+
}
|
|
131
|
+
/** @param {number[]} [arr] */
|
|
132
|
+
readPackedSVarint(arr = []) {
|
|
133
|
+
const end = this.readPackedEnd();
|
|
134
|
+
while (this.pos < end) arr.push(this.readSVarint());
|
|
135
|
+
return arr;
|
|
136
|
+
}
|
|
137
|
+
/** @param {boolean[]} [arr] */
|
|
138
|
+
readPackedBoolean(arr = []) {
|
|
139
|
+
const end = this.readPackedEnd();
|
|
140
|
+
while (this.pos < end) arr.push(this.readBoolean());
|
|
141
|
+
return arr;
|
|
142
|
+
}
|
|
143
|
+
/** @param {number[]} [arr] */
|
|
144
|
+
readPackedFloat(arr = []) {
|
|
145
|
+
const end = this.readPackedEnd();
|
|
146
|
+
while (this.pos < end) arr.push(this.readFloat());
|
|
147
|
+
return arr;
|
|
148
|
+
}
|
|
149
|
+
/** @param {number[]} [arr] */
|
|
150
|
+
readPackedDouble(arr = []) {
|
|
151
|
+
const end = this.readPackedEnd();
|
|
152
|
+
while (this.pos < end) arr.push(this.readDouble());
|
|
153
|
+
return arr;
|
|
154
|
+
}
|
|
155
|
+
/** @param {number[]} [arr] */
|
|
156
|
+
readPackedFixed32(arr = []) {
|
|
157
|
+
const end = this.readPackedEnd();
|
|
158
|
+
while (this.pos < end) arr.push(this.readFixed32());
|
|
159
|
+
return arr;
|
|
160
|
+
}
|
|
161
|
+
/** @param {number[]} [arr] */
|
|
162
|
+
readPackedSFixed32(arr = []) {
|
|
163
|
+
const end = this.readPackedEnd();
|
|
164
|
+
while (this.pos < end) arr.push(this.readSFixed32());
|
|
165
|
+
return arr;
|
|
166
|
+
}
|
|
167
|
+
/** @param {number[]} [arr] */
|
|
168
|
+
readPackedFixed64(arr = []) {
|
|
169
|
+
const end = this.readPackedEnd();
|
|
170
|
+
while (this.pos < end) arr.push(this.readFixed64());
|
|
171
|
+
return arr;
|
|
172
|
+
}
|
|
173
|
+
/** @param {number[]} [arr] */
|
|
174
|
+
readPackedSFixed64(arr = []) {
|
|
175
|
+
const end = this.readPackedEnd();
|
|
176
|
+
while (this.pos < end) arr.push(this.readSFixed64());
|
|
177
|
+
return arr;
|
|
178
|
+
}
|
|
179
|
+
readPackedEnd() {
|
|
180
|
+
return this.type === PBF_BYTES ? this.readVarint() + this.pos : this.pos + 1;
|
|
181
|
+
}
|
|
182
|
+
/** @param {number} val */
|
|
183
|
+
skip(val) {
|
|
184
|
+
const type = val & 7;
|
|
185
|
+
if (type === PBF_VARINT) while (this.buf[this.pos++] > 127) {
|
|
186
|
+
}
|
|
187
|
+
else if (type === PBF_BYTES) this.pos = this.readVarint() + this.pos;
|
|
188
|
+
else if (type === PBF_FIXED32) this.pos += 4;
|
|
189
|
+
else if (type === PBF_FIXED64) this.pos += 8;
|
|
190
|
+
else throw new Error(`Unimplemented type: ${type}`);
|
|
191
|
+
}
|
|
192
|
+
// === WRITING =================================================================
|
|
193
|
+
/**
|
|
194
|
+
* @param {number} tag
|
|
195
|
+
* @param {number} type
|
|
196
|
+
*/
|
|
197
|
+
writeTag(tag, type) {
|
|
198
|
+
this.writeVarint(tag << 3 | type);
|
|
199
|
+
}
|
|
200
|
+
/** @param {number} min */
|
|
201
|
+
realloc(min) {
|
|
202
|
+
let length = this.length || 16;
|
|
203
|
+
while (length < this.pos + min) length *= 2;
|
|
204
|
+
if (length !== this.length) {
|
|
205
|
+
const buf = new Uint8Array(length);
|
|
206
|
+
buf.set(this.buf);
|
|
207
|
+
this.buf = buf;
|
|
208
|
+
this.dataView = new DataView(buf.buffer);
|
|
209
|
+
this.length = length;
|
|
210
|
+
}
|
|
211
|
+
}
|
|
212
|
+
finish() {
|
|
213
|
+
this.length = this.pos;
|
|
214
|
+
this.pos = 0;
|
|
215
|
+
return this.buf.subarray(0, this.length);
|
|
216
|
+
}
|
|
217
|
+
/** @param {number} val */
|
|
218
|
+
writeFixed32(val) {
|
|
219
|
+
this.realloc(4);
|
|
220
|
+
this.dataView.setInt32(this.pos, val, true);
|
|
221
|
+
this.pos += 4;
|
|
222
|
+
}
|
|
223
|
+
/** @param {number} val */
|
|
224
|
+
writeSFixed32(val) {
|
|
225
|
+
this.realloc(4);
|
|
226
|
+
this.dataView.setInt32(this.pos, val, true);
|
|
227
|
+
this.pos += 4;
|
|
228
|
+
}
|
|
229
|
+
/** @param {number} val */
|
|
230
|
+
writeFixed64(val) {
|
|
231
|
+
this.realloc(8);
|
|
232
|
+
this.dataView.setInt32(this.pos, val & -1, true);
|
|
233
|
+
this.dataView.setInt32(this.pos + 4, Math.floor(val * SHIFT_RIGHT_32), true);
|
|
234
|
+
this.pos += 8;
|
|
235
|
+
}
|
|
236
|
+
/** @param {number} val */
|
|
237
|
+
writeSFixed64(val) {
|
|
238
|
+
this.realloc(8);
|
|
239
|
+
this.dataView.setInt32(this.pos, val & -1, true);
|
|
240
|
+
this.dataView.setInt32(this.pos + 4, Math.floor(val * SHIFT_RIGHT_32), true);
|
|
241
|
+
this.pos += 8;
|
|
242
|
+
}
|
|
243
|
+
/** @param {number} val */
|
|
244
|
+
writeVarint(val) {
|
|
245
|
+
val = +val || 0;
|
|
246
|
+
if (val > 268435455 || val < 0) {
|
|
247
|
+
writeBigVarint(val, this);
|
|
248
|
+
return;
|
|
249
|
+
}
|
|
250
|
+
this.realloc(4);
|
|
251
|
+
this.buf[this.pos++] = val & 127 | (val > 127 ? 128 : 0);
|
|
252
|
+
if (val <= 127) return;
|
|
253
|
+
this.buf[this.pos++] = (val >>>= 7) & 127 | (val > 127 ? 128 : 0);
|
|
254
|
+
if (val <= 127) return;
|
|
255
|
+
this.buf[this.pos++] = (val >>>= 7) & 127 | (val > 127 ? 128 : 0);
|
|
256
|
+
if (val <= 127) return;
|
|
257
|
+
this.buf[this.pos++] = val >>> 7 & 127;
|
|
258
|
+
}
|
|
259
|
+
/** @param {number} val */
|
|
260
|
+
writeSVarint(val) {
|
|
261
|
+
this.writeVarint(val < 0 ? -val * 2 - 1 : val * 2);
|
|
262
|
+
}
|
|
263
|
+
/** @param {boolean} val */
|
|
264
|
+
writeBoolean(val) {
|
|
265
|
+
this.writeVarint(+val);
|
|
266
|
+
}
|
|
267
|
+
/** @param {string} str */
|
|
268
|
+
writeString(str) {
|
|
269
|
+
str = String(str);
|
|
270
|
+
this.realloc(str.length * 4);
|
|
271
|
+
this.pos++;
|
|
272
|
+
const startPos = this.pos;
|
|
273
|
+
this.pos = writeUtf8(this.buf, str, this.pos);
|
|
274
|
+
const len = this.pos - startPos;
|
|
275
|
+
if (len >= 128) makeRoomForExtraLength(startPos, len, this);
|
|
276
|
+
this.pos = startPos - 1;
|
|
277
|
+
this.writeVarint(len);
|
|
278
|
+
this.pos += len;
|
|
279
|
+
}
|
|
280
|
+
/** @param {number} val */
|
|
281
|
+
writeFloat(val) {
|
|
282
|
+
this.realloc(4);
|
|
283
|
+
this.dataView.setFloat32(this.pos, val, true);
|
|
284
|
+
this.pos += 4;
|
|
285
|
+
}
|
|
286
|
+
/** @param {number} val */
|
|
287
|
+
writeDouble(val) {
|
|
288
|
+
this.realloc(8);
|
|
289
|
+
this.dataView.setFloat64(this.pos, val, true);
|
|
290
|
+
this.pos += 8;
|
|
291
|
+
}
|
|
292
|
+
/** @param {Uint8Array} buffer */
|
|
293
|
+
writeBytes(buffer) {
|
|
294
|
+
const len = buffer.length;
|
|
295
|
+
this.writeVarint(len);
|
|
296
|
+
this.realloc(len);
|
|
297
|
+
for (let i = 0; i < len; i++) this.buf[this.pos++] = buffer[i];
|
|
298
|
+
}
|
|
299
|
+
/**
|
|
300
|
+
* @template T
|
|
301
|
+
* @param {(obj: T, pbf: Pbf) => void} fn
|
|
302
|
+
* @param {T} obj
|
|
303
|
+
*/
|
|
304
|
+
writeRawMessage(fn, obj) {
|
|
305
|
+
this.pos++;
|
|
306
|
+
const startPos = this.pos;
|
|
307
|
+
fn(obj, this);
|
|
308
|
+
const len = this.pos - startPos;
|
|
309
|
+
if (len >= 128) makeRoomForExtraLength(startPos, len, this);
|
|
310
|
+
this.pos = startPos - 1;
|
|
311
|
+
this.writeVarint(len);
|
|
312
|
+
this.pos += len;
|
|
313
|
+
}
|
|
314
|
+
/**
|
|
315
|
+
* @template T
|
|
316
|
+
* @param {number} tag
|
|
317
|
+
* @param {(obj: T, pbf: Pbf) => void} fn
|
|
318
|
+
* @param {T} obj
|
|
319
|
+
*/
|
|
320
|
+
writeMessage(tag, fn, obj) {
|
|
321
|
+
this.writeTag(tag, PBF_BYTES);
|
|
322
|
+
this.writeRawMessage(fn, obj);
|
|
323
|
+
}
|
|
324
|
+
/**
|
|
325
|
+
* @param {number} tag
|
|
326
|
+
* @param {number[]} arr
|
|
327
|
+
*/
|
|
328
|
+
writePackedVarint(tag, arr) {
|
|
329
|
+
if (arr.length) this.writeMessage(tag, writePackedVarint, arr);
|
|
330
|
+
}
|
|
331
|
+
/**
|
|
332
|
+
* @param {number} tag
|
|
333
|
+
* @param {number[]} arr
|
|
334
|
+
*/
|
|
335
|
+
writePackedSVarint(tag, arr) {
|
|
336
|
+
if (arr.length) this.writeMessage(tag, writePackedSVarint, arr);
|
|
337
|
+
}
|
|
338
|
+
/**
|
|
339
|
+
* @param {number} tag
|
|
340
|
+
* @param {boolean[]} arr
|
|
341
|
+
*/
|
|
342
|
+
writePackedBoolean(tag, arr) {
|
|
343
|
+
if (arr.length) this.writeMessage(tag, writePackedBoolean, arr);
|
|
344
|
+
}
|
|
345
|
+
/**
|
|
346
|
+
* @param {number} tag
|
|
347
|
+
* @param {number[]} arr
|
|
348
|
+
*/
|
|
349
|
+
writePackedFloat(tag, arr) {
|
|
350
|
+
if (arr.length) this.writeMessage(tag, writePackedFloat, arr);
|
|
351
|
+
}
|
|
352
|
+
/**
|
|
353
|
+
* @param {number} tag
|
|
354
|
+
* @param {number[]} arr
|
|
355
|
+
*/
|
|
356
|
+
writePackedDouble(tag, arr) {
|
|
357
|
+
if (arr.length) this.writeMessage(tag, writePackedDouble, arr);
|
|
358
|
+
}
|
|
359
|
+
/**
|
|
360
|
+
* @param {number} tag
|
|
361
|
+
* @param {number[]} arr
|
|
362
|
+
*/
|
|
363
|
+
writePackedFixed32(tag, arr) {
|
|
364
|
+
if (arr.length) this.writeMessage(tag, writePackedFixed32, arr);
|
|
365
|
+
}
|
|
366
|
+
/**
|
|
367
|
+
* @param {number} tag
|
|
368
|
+
* @param {number[]} arr
|
|
369
|
+
*/
|
|
370
|
+
writePackedSFixed32(tag, arr) {
|
|
371
|
+
if (arr.length) this.writeMessage(tag, writePackedSFixed32, arr);
|
|
372
|
+
}
|
|
373
|
+
/**
|
|
374
|
+
* @param {number} tag
|
|
375
|
+
* @param {number[]} arr
|
|
376
|
+
*/
|
|
377
|
+
writePackedFixed64(tag, arr) {
|
|
378
|
+
if (arr.length) this.writeMessage(tag, writePackedFixed64, arr);
|
|
379
|
+
}
|
|
380
|
+
/**
|
|
381
|
+
* @param {number} tag
|
|
382
|
+
* @param {number[]} arr
|
|
383
|
+
*/
|
|
384
|
+
writePackedSFixed64(tag, arr) {
|
|
385
|
+
if (arr.length) this.writeMessage(tag, writePackedSFixed64, arr);
|
|
386
|
+
}
|
|
387
|
+
/**
|
|
388
|
+
* @param {number} tag
|
|
389
|
+
* @param {Uint8Array} buffer
|
|
390
|
+
*/
|
|
391
|
+
writeBytesField(tag, buffer) {
|
|
392
|
+
this.writeTag(tag, PBF_BYTES);
|
|
393
|
+
this.writeBytes(buffer);
|
|
394
|
+
}
|
|
395
|
+
/**
|
|
396
|
+
* @param {number} tag
|
|
397
|
+
* @param {number} val
|
|
398
|
+
*/
|
|
399
|
+
writeFixed32Field(tag, val) {
|
|
400
|
+
this.writeTag(tag, PBF_FIXED32);
|
|
401
|
+
this.writeFixed32(val);
|
|
402
|
+
}
|
|
403
|
+
/**
|
|
404
|
+
* @param {number} tag
|
|
405
|
+
* @param {number} val
|
|
406
|
+
*/
|
|
407
|
+
writeSFixed32Field(tag, val) {
|
|
408
|
+
this.writeTag(tag, PBF_FIXED32);
|
|
409
|
+
this.writeSFixed32(val);
|
|
410
|
+
}
|
|
411
|
+
/**
|
|
412
|
+
* @param {number} tag
|
|
413
|
+
* @param {number} val
|
|
414
|
+
*/
|
|
415
|
+
writeFixed64Field(tag, val) {
|
|
416
|
+
this.writeTag(tag, PBF_FIXED64);
|
|
417
|
+
this.writeFixed64(val);
|
|
418
|
+
}
|
|
419
|
+
/**
|
|
420
|
+
* @param {number} tag
|
|
421
|
+
* @param {number} val
|
|
422
|
+
*/
|
|
423
|
+
writeSFixed64Field(tag, val) {
|
|
424
|
+
this.writeTag(tag, PBF_FIXED64);
|
|
425
|
+
this.writeSFixed64(val);
|
|
426
|
+
}
|
|
427
|
+
/**
|
|
428
|
+
* @param {number} tag
|
|
429
|
+
* @param {number} val
|
|
430
|
+
*/
|
|
431
|
+
writeVarintField(tag, val) {
|
|
432
|
+
this.writeTag(tag, PBF_VARINT);
|
|
433
|
+
this.writeVarint(val);
|
|
434
|
+
}
|
|
435
|
+
/**
|
|
436
|
+
* @param {number} tag
|
|
437
|
+
* @param {number} val
|
|
438
|
+
*/
|
|
439
|
+
writeSVarintField(tag, val) {
|
|
440
|
+
this.writeTag(tag, PBF_VARINT);
|
|
441
|
+
this.writeSVarint(val);
|
|
442
|
+
}
|
|
443
|
+
/**
|
|
444
|
+
* @param {number} tag
|
|
445
|
+
* @param {string} str
|
|
446
|
+
*/
|
|
447
|
+
writeStringField(tag, str) {
|
|
448
|
+
this.writeTag(tag, PBF_BYTES);
|
|
449
|
+
this.writeString(str);
|
|
450
|
+
}
|
|
451
|
+
/**
|
|
452
|
+
* @param {number} tag
|
|
453
|
+
* @param {number} val
|
|
454
|
+
*/
|
|
455
|
+
writeFloatField(tag, val) {
|
|
456
|
+
this.writeTag(tag, PBF_FIXED32);
|
|
457
|
+
this.writeFloat(val);
|
|
458
|
+
}
|
|
459
|
+
/**
|
|
460
|
+
* @param {number} tag
|
|
461
|
+
* @param {number} val
|
|
462
|
+
*/
|
|
463
|
+
writeDoubleField(tag, val) {
|
|
464
|
+
this.writeTag(tag, PBF_FIXED64);
|
|
465
|
+
this.writeDouble(val);
|
|
466
|
+
}
|
|
467
|
+
/**
|
|
468
|
+
* @param {number} tag
|
|
469
|
+
* @param {boolean} val
|
|
470
|
+
*/
|
|
471
|
+
writeBooleanField(tag, val) {
|
|
472
|
+
this.writeVarintField(tag, +val);
|
|
473
|
+
}
|
|
474
|
+
}
|
|
475
|
+
function readVarintRemainder(l, s, p) {
|
|
476
|
+
const buf = p.buf;
|
|
477
|
+
let h, b;
|
|
478
|
+
b = buf[p.pos++];
|
|
479
|
+
h = (b & 112) >> 4;
|
|
480
|
+
if (b < 128) return toNum(l, h, s);
|
|
481
|
+
b = buf[p.pos++];
|
|
482
|
+
h |= (b & 127) << 3;
|
|
483
|
+
if (b < 128) return toNum(l, h, s);
|
|
484
|
+
b = buf[p.pos++];
|
|
485
|
+
h |= (b & 127) << 10;
|
|
486
|
+
if (b < 128) return toNum(l, h, s);
|
|
487
|
+
b = buf[p.pos++];
|
|
488
|
+
h |= (b & 127) << 17;
|
|
489
|
+
if (b < 128) return toNum(l, h, s);
|
|
490
|
+
b = buf[p.pos++];
|
|
491
|
+
h |= (b & 127) << 24;
|
|
492
|
+
if (b < 128) return toNum(l, h, s);
|
|
493
|
+
b = buf[p.pos++];
|
|
494
|
+
h |= (b & 1) << 31;
|
|
495
|
+
if (b < 128) return toNum(l, h, s);
|
|
496
|
+
throw new Error("Expected varint not more than 10 bytes");
|
|
497
|
+
}
|
|
498
|
+
function toNum(low, high, isSigned) {
|
|
499
|
+
return isSigned ? high * 4294967296 + (low >>> 0) : (high >>> 0) * 4294967296 + (low >>> 0);
|
|
500
|
+
}
|
|
501
|
+
function writeBigVarint(val, pbf) {
|
|
502
|
+
let low, high;
|
|
503
|
+
if (val >= 0) {
|
|
504
|
+
low = val % 4294967296 | 0;
|
|
505
|
+
high = val / 4294967296 | 0;
|
|
506
|
+
} else {
|
|
507
|
+
low = ~(-val % 4294967296);
|
|
508
|
+
high = ~(-val / 4294967296);
|
|
509
|
+
if (low ^ 4294967295) {
|
|
510
|
+
low = low + 1 | 0;
|
|
511
|
+
} else {
|
|
512
|
+
low = 0;
|
|
513
|
+
high = high + 1 | 0;
|
|
514
|
+
}
|
|
515
|
+
}
|
|
516
|
+
if (val >= 18446744073709552e3 || val < -18446744073709552e3) {
|
|
517
|
+
throw new Error("Given varint doesn't fit into 10 bytes");
|
|
518
|
+
}
|
|
519
|
+
pbf.realloc(10);
|
|
520
|
+
writeBigVarintLow(low, high, pbf);
|
|
521
|
+
writeBigVarintHigh(high, pbf);
|
|
522
|
+
}
|
|
523
|
+
function writeBigVarintLow(low, high, pbf) {
|
|
524
|
+
pbf.buf[pbf.pos++] = low & 127 | 128;
|
|
525
|
+
low >>>= 7;
|
|
526
|
+
pbf.buf[pbf.pos++] = low & 127 | 128;
|
|
527
|
+
low >>>= 7;
|
|
528
|
+
pbf.buf[pbf.pos++] = low & 127 | 128;
|
|
529
|
+
low >>>= 7;
|
|
530
|
+
pbf.buf[pbf.pos++] = low & 127 | 128;
|
|
531
|
+
low >>>= 7;
|
|
532
|
+
pbf.buf[pbf.pos] = low & 127;
|
|
533
|
+
}
|
|
534
|
+
function writeBigVarintHigh(high, pbf) {
|
|
535
|
+
const lsb = (high & 7) << 4;
|
|
536
|
+
pbf.buf[pbf.pos++] |= lsb | ((high >>>= 3) ? 128 : 0);
|
|
537
|
+
if (!high) return;
|
|
538
|
+
pbf.buf[pbf.pos++] = high & 127 | ((high >>>= 7) ? 128 : 0);
|
|
539
|
+
if (!high) return;
|
|
540
|
+
pbf.buf[pbf.pos++] = high & 127 | ((high >>>= 7) ? 128 : 0);
|
|
541
|
+
if (!high) return;
|
|
542
|
+
pbf.buf[pbf.pos++] = high & 127 | ((high >>>= 7) ? 128 : 0);
|
|
543
|
+
if (!high) return;
|
|
544
|
+
pbf.buf[pbf.pos++] = high & 127 | ((high >>>= 7) ? 128 : 0);
|
|
545
|
+
if (!high) return;
|
|
546
|
+
pbf.buf[pbf.pos++] = high & 127;
|
|
547
|
+
}
|
|
548
|
+
function makeRoomForExtraLength(startPos, len, pbf) {
|
|
549
|
+
const extraLen = len <= 16383 ? 1 : len <= 2097151 ? 2 : len <= 268435455 ? 3 : Math.floor(Math.log(len) / (Math.LN2 * 7));
|
|
550
|
+
pbf.realloc(extraLen);
|
|
551
|
+
for (let i = pbf.pos - 1; i >= startPos; i--) pbf.buf[i + extraLen] = pbf.buf[i];
|
|
552
|
+
}
|
|
553
|
+
function writePackedVarint(arr, pbf) {
|
|
554
|
+
for (let i = 0; i < arr.length; i++) pbf.writeVarint(arr[i]);
|
|
555
|
+
}
|
|
556
|
+
function writePackedSVarint(arr, pbf) {
|
|
557
|
+
for (let i = 0; i < arr.length; i++) pbf.writeSVarint(arr[i]);
|
|
558
|
+
}
|
|
559
|
+
function writePackedFloat(arr, pbf) {
|
|
560
|
+
for (let i = 0; i < arr.length; i++) pbf.writeFloat(arr[i]);
|
|
561
|
+
}
|
|
562
|
+
function writePackedDouble(arr, pbf) {
|
|
563
|
+
for (let i = 0; i < arr.length; i++) pbf.writeDouble(arr[i]);
|
|
564
|
+
}
|
|
565
|
+
function writePackedBoolean(arr, pbf) {
|
|
566
|
+
for (let i = 0; i < arr.length; i++) pbf.writeBoolean(arr[i]);
|
|
567
|
+
}
|
|
568
|
+
function writePackedFixed32(arr, pbf) {
|
|
569
|
+
for (let i = 0; i < arr.length; i++) pbf.writeFixed32(arr[i]);
|
|
570
|
+
}
|
|
571
|
+
function writePackedSFixed32(arr, pbf) {
|
|
572
|
+
for (let i = 0; i < arr.length; i++) pbf.writeSFixed32(arr[i]);
|
|
573
|
+
}
|
|
574
|
+
function writePackedFixed64(arr, pbf) {
|
|
575
|
+
for (let i = 0; i < arr.length; i++) pbf.writeFixed64(arr[i]);
|
|
576
|
+
}
|
|
577
|
+
function writePackedSFixed64(arr, pbf) {
|
|
578
|
+
for (let i = 0; i < arr.length; i++) pbf.writeSFixed64(arr[i]);
|
|
579
|
+
}
|
|
580
|
+
function readUtf8(buf, pos, end) {
|
|
581
|
+
let str = "";
|
|
582
|
+
let i = pos;
|
|
583
|
+
while (i < end) {
|
|
584
|
+
const b0 = buf[i];
|
|
585
|
+
let c = null;
|
|
586
|
+
let bytesPerSequence = b0 > 239 ? 4 : b0 > 223 ? 3 : b0 > 191 ? 2 : 1;
|
|
587
|
+
if (i + bytesPerSequence > end) break;
|
|
588
|
+
let b1, b2, b3;
|
|
589
|
+
if (bytesPerSequence === 1) {
|
|
590
|
+
if (b0 < 128) {
|
|
591
|
+
c = b0;
|
|
592
|
+
}
|
|
593
|
+
} else if (bytesPerSequence === 2) {
|
|
594
|
+
b1 = buf[i + 1];
|
|
595
|
+
if ((b1 & 192) === 128) {
|
|
596
|
+
c = (b0 & 31) << 6 | b1 & 63;
|
|
597
|
+
if (c <= 127) {
|
|
598
|
+
c = null;
|
|
599
|
+
}
|
|
600
|
+
}
|
|
601
|
+
} else if (bytesPerSequence === 3) {
|
|
602
|
+
b1 = buf[i + 1];
|
|
603
|
+
b2 = buf[i + 2];
|
|
604
|
+
if ((b1 & 192) === 128 && (b2 & 192) === 128) {
|
|
605
|
+
c = (b0 & 15) << 12 | (b1 & 63) << 6 | b2 & 63;
|
|
606
|
+
if (c <= 2047 || c >= 55296 && c <= 57343) {
|
|
607
|
+
c = null;
|
|
608
|
+
}
|
|
609
|
+
}
|
|
610
|
+
} else if (bytesPerSequence === 4) {
|
|
611
|
+
b1 = buf[i + 1];
|
|
612
|
+
b2 = buf[i + 2];
|
|
613
|
+
b3 = buf[i + 3];
|
|
614
|
+
if ((b1 & 192) === 128 && (b2 & 192) === 128 && (b3 & 192) === 128) {
|
|
615
|
+
c = (b0 & 15) << 18 | (b1 & 63) << 12 | (b2 & 63) << 6 | b3 & 63;
|
|
616
|
+
if (c <= 65535 || c >= 1114112) {
|
|
617
|
+
c = null;
|
|
618
|
+
}
|
|
619
|
+
}
|
|
620
|
+
}
|
|
621
|
+
if (c === null) {
|
|
622
|
+
c = 65533;
|
|
623
|
+
bytesPerSequence = 1;
|
|
624
|
+
} else if (c > 65535) {
|
|
625
|
+
c -= 65536;
|
|
626
|
+
str += String.fromCharCode(c >>> 10 & 1023 | 55296);
|
|
627
|
+
c = 56320 | c & 1023;
|
|
628
|
+
}
|
|
629
|
+
str += String.fromCharCode(c);
|
|
630
|
+
i += bytesPerSequence;
|
|
631
|
+
}
|
|
632
|
+
return str;
|
|
633
|
+
}
|
|
634
|
+
function writeUtf8(buf, str, pos) {
|
|
635
|
+
for (let i = 0, c, lead; i < str.length; i++) {
|
|
636
|
+
c = str.charCodeAt(i);
|
|
637
|
+
if (c > 55295 && c < 57344) {
|
|
638
|
+
if (lead) {
|
|
639
|
+
if (c < 56320) {
|
|
640
|
+
buf[pos++] = 239;
|
|
641
|
+
buf[pos++] = 191;
|
|
642
|
+
buf[pos++] = 189;
|
|
643
|
+
lead = c;
|
|
644
|
+
continue;
|
|
645
|
+
} else {
|
|
646
|
+
c = lead - 55296 << 10 | c - 56320 | 65536;
|
|
647
|
+
lead = null;
|
|
648
|
+
}
|
|
649
|
+
} else {
|
|
650
|
+
if (c > 56319 || i + 1 === str.length) {
|
|
651
|
+
buf[pos++] = 239;
|
|
652
|
+
buf[pos++] = 191;
|
|
653
|
+
buf[pos++] = 189;
|
|
654
|
+
} else {
|
|
655
|
+
lead = c;
|
|
656
|
+
}
|
|
657
|
+
continue;
|
|
658
|
+
}
|
|
659
|
+
} else if (lead) {
|
|
660
|
+
buf[pos++] = 239;
|
|
661
|
+
buf[pos++] = 191;
|
|
662
|
+
buf[pos++] = 189;
|
|
663
|
+
lead = null;
|
|
664
|
+
}
|
|
665
|
+
if (c < 128) {
|
|
666
|
+
buf[pos++] = c;
|
|
667
|
+
} else {
|
|
668
|
+
if (c < 2048) {
|
|
669
|
+
buf[pos++] = c >> 6 | 192;
|
|
670
|
+
} else {
|
|
671
|
+
if (c < 65536) {
|
|
672
|
+
buf[pos++] = c >> 12 | 224;
|
|
673
|
+
} else {
|
|
674
|
+
buf[pos++] = c >> 18 | 240;
|
|
675
|
+
buf[pos++] = c >> 12 & 63 | 128;
|
|
676
|
+
}
|
|
677
|
+
buf[pos++] = c >> 6 & 63 | 128;
|
|
678
|
+
}
|
|
679
|
+
buf[pos++] = c & 63 | 128;
|
|
680
|
+
}
|
|
681
|
+
}
|
|
682
|
+
return pos;
|
|
683
|
+
}
|
|
684
|
+
export {
|
|
685
|
+
Pbf as default
|
|
686
|
+
};
|
|
687
|
+
//# sourceMappingURL=index.js.map
|