@stellar-expert/ui-framework 1.9.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.
Files changed (124) hide show
  1. package/.npmrc +1 -0
  2. package/LICENSE +21 -0
  3. package/README.md +3 -0
  4. package/account/account-address.js +127 -0
  5. package/account/account-address.scss +20 -0
  6. package/account/available-balance.js +21 -0
  7. package/account/identicon.js +91 -0
  8. package/account/identicon.scss +6 -0
  9. package/account/signer-key.js +65 -0
  10. package/api/api-cache.js +5 -0
  11. package/api/explorer-api-call.js +37 -0
  12. package/api/explorer-api-hooks.js +202 -0
  13. package/api/explorer-api-paginated-list-hooks.js +439 -0
  14. package/api/explorer-batch-info-loader.js +85 -0
  15. package/api/explorer-tx-api.js +29 -0
  16. package/asset/amount.js +53 -0
  17. package/asset/asset-icon.js +34 -0
  18. package/asset/asset-issuer.js +22 -0
  19. package/asset/asset-link.js +93 -0
  20. package/asset/asset-link.scss +26 -0
  21. package/asset/asset-list-hooks.js +60 -0
  22. package/asset/asset-meta-hooks.js +78 -0
  23. package/asset/asset-selector.js +72 -0
  24. package/asset/asset-selector.scss +41 -0
  25. package/basic-styles/base.scss +53 -0
  26. package/basic-styles/form.scss +90 -0
  27. package/basic-styles/grid.scss +388 -0
  28. package/basic-styles/link.scss +17 -0
  29. package/basic-styles/lists.scss +68 -0
  30. package/basic-styles/loader.scss +22 -0
  31. package/basic-styles/responsive.scss +29 -0
  32. package/basic-styles/scrollbars.scss +19 -0
  33. package/basic-styles/spacing.scss +50 -0
  34. package/basic-styles/table.scss +104 -0
  35. package/basic-styles/themes.scss +59 -0
  36. package/basic-styles/typography.scss +191 -0
  37. package/basic-styles/variables.scss +26 -0
  38. package/claimable-balance/claimable-balance-claimants.js +12 -0
  39. package/contract/sc-val.js +70 -0
  40. package/contract/wasm-section-parser.js +159 -0
  41. package/contract/wasm-section-reader.js +79 -0
  42. package/contract/xdr-reader.js +148 -0
  43. package/controls/active-icon.scss +23 -0
  44. package/controls/button-group.js +20 -0
  45. package/controls/button-group.scss +48 -0
  46. package/controls/button.js +74 -0
  47. package/controls/button.scss +148 -0
  48. package/controls/code-block.js +35 -0
  49. package/controls/code-block.scss +74 -0
  50. package/controls/dropdown.js +281 -0
  51. package/controls/dropdown.scss +161 -0
  52. package/controls/external-link.js +5 -0
  53. package/controls/info-tooltip.js +17 -0
  54. package/controls/info-tooltip.scss +4 -0
  55. package/controls/slider.js +20 -0
  56. package/controls/slider.scss +22 -0
  57. package/controls/tabs.js +94 -0
  58. package/controls/tabs.scss +73 -0
  59. package/controls/tooltip.js +214 -0
  60. package/controls/tooltip.scss +97 -0
  61. package/controls/update-highlighter.js +28 -0
  62. package/controls/update-highlighter.scss +10 -0
  63. package/date/date-selector.js +44 -0
  64. package/date/elapsed-time.js +22 -0
  65. package/date/utc-timestamp.js +23 -0
  66. package/dex/price-dynamic.js +45 -0
  67. package/dex/price-dynamic.scss +36 -0
  68. package/directory/directory-hooks.js +89 -0
  69. package/effect/effect-description.js +289 -0
  70. package/effect/op-effects-view.js +11 -0
  71. package/effect/op-effects.scss +8 -0
  72. package/errors/error-boundary.js +98 -0
  73. package/fonts/font.scss +23 -0
  74. package/fonts/icons/config.json +1858 -0
  75. package/fonts/icons/icons-embedded.scss +644 -0
  76. package/horizon/horizon-account-helpers.js +104 -0
  77. package/horizon/horizon-client-helpers.js +52 -0
  78. package/horizon/horizon-ledger-helpers.js +36 -0
  79. package/horizon/horizon-orderbook-helpers.js +14 -0
  80. package/horizon/horizon-trades-helper.js +89 -0
  81. package/horizon/horizon-transaction-helpers.js +36 -0
  82. package/index.js +85 -0
  83. package/index.scss +16 -0
  84. package/interaction/autofocus.js +9 -0
  85. package/interaction/block-select.js +54 -0
  86. package/interaction/block-select.scss +24 -0
  87. package/interaction/copy-to-clipboard.js +19 -0
  88. package/interaction/inline-progress.js +16 -0
  89. package/interaction/qr-code.js +45 -0
  90. package/interaction/responsive.js +21 -0
  91. package/interaction/spoiler.js +40 -0
  92. package/interaction/spoiler.scss +9 -0
  93. package/interaction/theme-selector.js +11 -0
  94. package/ledger/ledger-entry-href-formatter.js +22 -0
  95. package/ledger/ledger-entry-link.js +59 -0
  96. package/meta/page-meta-tags.js +229 -0
  97. package/module/dynamic-module.js +48 -0
  98. package/package.json +41 -0
  99. package/state/on-screen-hooks.js +23 -0
  100. package/state/page-visibility-helpers.js +17 -0
  101. package/state/page-visibility-hooks.js +12 -0
  102. package/state/screen-orientation-hooks.js +16 -0
  103. package/state/state-hooks.js +77 -0
  104. package/state/stellar-network-hooks.js +45 -0
  105. package/state/theme.js +29 -0
  106. package/stellar/key-type.js +92 -0
  107. package/stellar/ledger-generic-id.js +40 -0
  108. package/stellar/signature-hint-utils.js +65 -0
  109. package/toast/toast-notification-instance.js +43 -0
  110. package/toast/toast-notification.js +46 -0
  111. package/toast/toast-notifications-block.js +55 -0
  112. package/toast/toast-notifications.scss +166 -0
  113. package/tx/op-accounting-changes.js +27 -0
  114. package/tx/op-description-view.js +925 -0
  115. package/tx/op-description.scss +98 -0
  116. package/tx/op-icon.js +93 -0
  117. package/tx/parser/op-balance-changes.js +62 -0
  118. package/tx/parser/op-descriptor.js +49 -0
  119. package/tx/parser/tx-details-parser.js +75 -0
  120. package/tx/parser/tx-matcher.js +372 -0
  121. package/tx/parser/type-filter-matcher.js +127 -0
  122. package/tx/tx-fee-effect.js +14 -0
  123. package/tx/tx-list-hooks.js +19 -0
  124. package/tx/tx-operations-list.js +105 -0
@@ -0,0 +1,59 @@
1
+ :root {
2
+ --color-primary: #{$color-primary};
3
+ --color-highlight: #08b5e5;
4
+ --color-dimmed: #999;
5
+ --color-alert: #dc3545;
6
+ --color-success: #28a745;
7
+ --color-warning: #b27100;
8
+ --color-price-up: #00ba00;
9
+ --color-price-down: #df0000;
10
+ --color-modal-bg: rgba(0, 0, 0, .2);
11
+ }
12
+
13
+ :root[data-theme=day] {
14
+ --color-bg: #fff;
15
+ --color-dashboard-bg: #f5f5f5;
16
+ --color-alt-bg: #f2fcff;
17
+ --color-alt-border: #e8e8e8;
18
+ --color-text: #333;
19
+ --color-contrast-border: #d8dadb;
20
+ --color-border-shadow: rgba(189, 191, 192, .1);
21
+ --color-backdrop: rgba(0, 0, 0, .35);
22
+ --color-alert-bg: #f4d5d8;
23
+ --color-warning-bg: #ebdbbf;
24
+ --color-success-bg: #d0ecd6;
25
+ }
26
+
27
+ :root[data-theme=night] {
28
+ --color-bg: #1b414a;
29
+ --color-dashboard-bg: #272c2e;
30
+ --color-alt-bg: #12363f;
31
+ --color-alt-border: #2f464c;
32
+ --color-text: #eee;
33
+ --color-contrast-border: #535759;
34
+ --color-border-shadow: rgba(176, 185, 189, 0.1);
35
+ --color-backdrop: rgba(0, 0, 0, 0.25);
36
+ --color-alert-bg: #553d49;
37
+ --color-warning-bg: #484f34;
38
+ --color-success-bg: #1b5340;
39
+ }
40
+
41
+ .color-primary {
42
+ color: var(--color-primary);
43
+ }
44
+
45
+ .color-success {
46
+ color: var(--color-success);
47
+ }
48
+
49
+ .color-warning {
50
+ color: var(--color-warning);
51
+ }
52
+
53
+ .color-danger {
54
+ color: var(--color-alert);
55
+ }
56
+
57
+ .color-alt-bg {
58
+ color: var(--color-alt-bg);
59
+ }
@@ -0,0 +1,191 @@
1
+ b,
2
+ strong {
3
+ font-weight: bold;
4
+ }
5
+
6
+ p {
7
+ margin-top: 0;
8
+ text-align: justify;
9
+ }
10
+
11
+ h1,
12
+ h2,
13
+ h3,
14
+ h4 {
15
+ font-family: $font-face-header;
16
+ font-weight: 300;
17
+ letter-spacing: $header-letter-spacing;
18
+ margin-bottom: 0.5em;
19
+ margin-top: 0.5em;
20
+ }
21
+
22
+ h1 {
23
+ font-size: 3rem;
24
+ line-height: 1.2;
25
+ }
26
+
27
+ h2 {
28
+ font-size: 2.4rem;
29
+ line-height: 1.3;
30
+ }
31
+
32
+ h3 {
33
+ font-size: 2rem;
34
+ line-height: 1.3;
35
+ }
36
+
37
+ h4 {
38
+ font-size: 1.8rem;
39
+ letter-spacing: -0.08rem;
40
+ line-height: 1.35;
41
+ }
42
+
43
+ code {
44
+ font-family: $font-face-mono;
45
+ background: var(--color-alt-bg);
46
+ padding: 0 3px;
47
+ border-radius: $border-radius-input;
48
+ }
49
+
50
+ .text-small {
51
+ font-size: 0.85*$font-size-base !important;
52
+ }
53
+
54
+ .text-tiny {
55
+ font-size: 0.75*$font-size-base !important;
56
+ }
57
+
58
+ .text-large {
59
+ font-size: 1.125*$font-size-base !important;
60
+ }
61
+
62
+ .text-huge {
63
+ font-size: 1.25*$font-size-base !important;
64
+ }
65
+
66
+ .text-left {
67
+ text-align: left !important;
68
+ }
69
+
70
+ .text-right {
71
+ text-align: right !important;
72
+ }
73
+
74
+ .text-center {
75
+ text-align: center !important;
76
+ }
77
+
78
+ .text-justify {
79
+ text-align: justify !important;
80
+ }
81
+
82
+ .condensed {
83
+ letter-spacing: -0.045em;
84
+ }
85
+
86
+ .nowrap {
87
+ white-space: nowrap;
88
+ }
89
+
90
+ .word-break {
91
+ word-break: break-all;
92
+ }
93
+
94
+ .text-overflow {
95
+ max-width: 100%;
96
+ text-overflow: ellipsis;
97
+ overflow: hidden;
98
+ }
99
+
100
+ .vtop {
101
+ vertical-align: top;
102
+ }
103
+
104
+ .text-active {
105
+ color: var(--color-primary);
106
+ }
107
+
108
+ .dimmed,
109
+ .label {
110
+ color: var(--color-dimmed);
111
+ }
112
+
113
+ .text-monospace {
114
+ font-family: $font-face-mono;
115
+ }
116
+
117
+ .details {
118
+ color: var(--color-dimmed);
119
+ font-size: 0.9em;
120
+ }
121
+
122
+ .error,
123
+ .alert {
124
+ color: var(--color-alert);
125
+ background: var(--color-alert-bg);
126
+ }
127
+
128
+ .color-warning {
129
+ color: var(--color-warning);
130
+ }
131
+
132
+ .warning {
133
+ color: var(--color-warning);
134
+ background: var(--color-warning-bg);
135
+ }
136
+
137
+ .color-success {
138
+ color: var(--color-success);
139
+ }
140
+
141
+ .success {
142
+ color: var(--color-success);
143
+ background: var(--color-success-bg);
144
+ }
145
+
146
+ .trend-up {
147
+ color: var(--color-price-up);
148
+ }
149
+
150
+ .trend-down {
151
+ color: var(--color-price-down);
152
+ }
153
+
154
+ hr {
155
+ border: none;
156
+ border-bottom: 1px solid var(--color-contrast-border);
157
+
158
+ &.flare {
159
+ border: none;
160
+ font-size: $font-size-base;
161
+ margin: 1rem auto;
162
+ width: 100%;
163
+ max-width: 90vw;
164
+ height: 0;
165
+ border-bottom: 1px solid;
166
+ border-image: linear-gradient(to right, transparent 2%, var(--color-highlight) 15%, var(--color-highlight) 85%, transparent 98%);
167
+ border-image-slice: 1;
168
+
169
+ &.double-space {
170
+ margin-bottom: $space-double;
171
+ }
172
+
173
+ &[title] {
174
+ display: flex;
175
+ justify-content: center;
176
+ overflow: visible;
177
+ margin: 3rem 0;
178
+
179
+ &:after {
180
+ content: attr(title);
181
+ display: table;
182
+ background-color: var(--color-bg);
183
+ margin: -0.8em 0;
184
+ padding: 0 0.5em;
185
+ text-align: center;
186
+ font-size: 0.85*$font-size-base;
187
+ color: var(--color-dimmed);
188
+ }
189
+ }
190
+ }
191
+ }
@@ -0,0 +1,26 @@
1
+ //fonts
2
+ $font-face-primary: ClearSans, sans-serif !default;
3
+ $font-face-header: 'Roboto Condensed', Arial, Helvetica, sans-serif !default;
4
+ $font-face-mono: Consolas, 'Liberation Mono', Menlo, Courier, monospace !default;
5
+
6
+ $font-size-base: 1.6rem !default;
7
+ $font-weight-base: 300 !default;
8
+ $font-line-height-base: 1.4285 !default;
9
+ $header-letter-spacing: -0.02em !default;
10
+
11
+ //borders
12
+ $border-radius-input: 0.3rem !default;
13
+
14
+ //spacing
15
+ $space-standard: 2rem !default;
16
+ $space-micro: 1rem !default;
17
+ $space-nano: 0.5rem !default;
18
+ $space-double: 4rem !default;
19
+
20
+ $container-padding: $space-standard !default;
21
+
22
+ //responsive breakpoints
23
+ $responsive-mobile-browser-width: 992px;
24
+
25
+ //basic color
26
+ $color-primary: #0691B7 !default;
@@ -0,0 +1,12 @@
1
+ import React from 'react'
2
+ import {xdrParseClaimant} from '@stellar-expert/claimable-balance-utils'
3
+ import {AccountAddress} from '../account/account-address'
4
+
5
+ export const ClaimableBalanceClaimants = React.memo(function ClaimableBalanceClaimants({claimants}) {
6
+ const parsed = claimants.map(xdrParseClaimant)
7
+ return <>
8
+ {parsed.map((c, i) => <span key={i + c.destination}>{i > 0 && ', '}
9
+ <AccountAddress account={c.destination}/> {c.predicate}
10
+ </span>)}
11
+ </>
12
+ })
@@ -0,0 +1,70 @@
1
+ import React from 'react'
2
+ import {xdr, scValToBigInt} from '@stellar/stellar-base'
3
+ import {xdrParserUtils} from '@stellar-expert/tx-meta-effects-parser'
4
+ import {shortenString} from '@stellar-expert/formatter'
5
+ import {AccountAddress} from '../account/account-address'
6
+
7
+ export function ScVal({value, nested = false}) {
8
+ if (!nested)
9
+ return <code className="sc-val"><ScVal value={value} nested/></code>
10
+ if (!value)
11
+ return 'void'
12
+ if (typeof value === 'string') {
13
+ value = xdr.ScVal.fromXDR(value, 'base64')
14
+ }
15
+ if (value instanceof Array)
16
+ return <>[{value.map((v, i) => <React.Fragment key={i}>{i > 0 && ', '}<ScVal value={v} nested/></React.Fragment>)}]</>
17
+ switch (value._arm) {
18
+ case 'vec':
19
+ return <>[{value._value.map((v, i) => <React.Fragment key={i}>{i > 0 && ', '}<ScVal value={v} nested/></React.Fragment>)}]</>
20
+ case 'map':
21
+ return <>&#123;
22
+ {value._value.map((kv, i) =>
23
+ <React.Fragment key={i}>{i > 0 && ', '}<ScVal value={kv.key()} nested/>: <ScVal value={kv.val()} nested/></React.Fragment>)}
24
+ &#125;</>
25
+ case 'b':
26
+ return <>{value._value}<ScValType type="bool"/></>
27
+ case 'i32':
28
+ case 'u32':
29
+ return <>{value._value}<ScValType type={value._arm}/></>
30
+ case 'i256':
31
+ case 'u256':
32
+ case 'i128':
33
+ case 'u128':
34
+ case 'i64':
35
+ case 'u64':
36
+ case 'timepoint':
37
+ case 'duration':
38
+ return <>{scValToBigInt(value).toString()}<ScValType type={value._arm}/></>
39
+ case 'address':
40
+ switch (value._value._arm) {
41
+ case 'accountId':
42
+ return <AccountAddress account={xdrParserUtils.xdrParseAccountAddress(value._value.value())}/>
43
+ case 'contractId':
44
+ return <AccountAddress account={xdrParserUtils.xdrParseContractAddress(value._value.value())}/>
45
+ }
46
+ return <span className="dimmed">(unsupported address)</span>
47
+ case 'bytes':
48
+ const asBytes = value._value.toString('base64')
49
+ return <><span className="condensed">{shortenString(asBytes, 86)}</span><ScValType type="bytes"/></>
50
+ case 'str':
51
+ case 'sym':
52
+ return <>"{value._value.toString()}"<ScValType type={value._arm}/></>
53
+ case 'nonceKey':
54
+ return <>{value._value.nonce()._value.toString()}<ScValType type="nonce"/></>
55
+ case 'instance':
56
+ return <>{value._value.executable.wasmHash().toString('hex')}<ScValType type="wasm"/></>
57
+ case 'error':
58
+ return <><span className="condensed">{shortenString(value.toXDR('base64'), 50)}</span><ScValType type="error"/></>
59
+ case 'contractId':
60
+ return <AccountAddress account={xdrParserUtils.xdrParseContractAddress(value._value)}/>
61
+ default:
62
+ if (value.switch().name === 'scvVoid')
63
+ return 'void'
64
+ return <span className="dimmed">(unknown)</span>
65
+ }
66
+ }
67
+
68
+ const ScValType = React.memo(function ({type}) {
69
+ return <sub className="dimmed text-tiny" style={{padding: '0 0.2em'}}>{type}</sub>
70
+ })
@@ -0,0 +1,159 @@
1
+ import xdr from '@stellar/stellar-base'
2
+ import {XdrReader} from './xdr-reader'
3
+ import {WasmSectionReader} from './wasm-section-reader'
4
+
5
+ /**
6
+ * Parse contract metadata from WASM sections
7
+ * @param {Buffer} rawWasm
8
+ * @return {{}}
9
+ */
10
+ export function parseContractMetadata(rawWasm) {
11
+ const wasmSectionReader = new WasmSectionReader(rawWasm)
12
+ const sections = wasmSectionReader.readCustomSections()
13
+ const res = {}
14
+ for (const section of sections) {
15
+ switch (section.name) {
16
+ case 'contractenvmetav0':
17
+ res.interfaceVersion = xdr.ScEnvMetaEntry.fromXDR(section.contents).value().toString()
18
+ break
19
+ case 'contractmetav0':
20
+ Object.assign(res, parseContractMeta(parseEntries(section.contents, xdr.ScMetaEntry)))
21
+ break
22
+ case 'contractspecv0':
23
+ Object.assign(res, parseSpec(parseEntries(section.contents, xdr.ScSpecEntry)))
24
+ break
25
+ }
26
+ }
27
+ return res
28
+ }
29
+
30
+ function parseEntries(buffer, xdrContract) {
31
+ const reader = new XdrReader(buffer)
32
+ const entries = []
33
+ while (!reader.eof) {
34
+ entries.push(xdrContract.read(reader))
35
+ }
36
+ return entries
37
+ }
38
+
39
+ function parseContractMeta(meta) {
40
+ const res = {}
41
+ for (const {_value} of meta) {
42
+ const key = _value.key().toString()
43
+ const val = _value.val().toString()
44
+ switch (key) {
45
+ case 'rsver':
46
+ res.rustVersion = val
47
+ break
48
+ case 'rssdkver':
49
+ res.sdkVersion = val
50
+ break
51
+ }
52
+ }
53
+ return res
54
+ }
55
+
56
+ function parseSpec(entries) {
57
+ const res = {}
58
+
59
+ function addSpec(key, descriptor) {
60
+ let spec = res[key]
61
+ if (spec === undefined) {
62
+ spec = res[key] = []
63
+ }
64
+ spec.push(descriptor)
65
+ }
66
+
67
+ for (const spec of entries) {
68
+ const value = spec.value()
69
+ switch (spec._arm) {
70
+ case 'functionV0':
71
+ addSpec('functions', {
72
+ name: value.name().toString(),
73
+ inputs: value.inputs().map(parseParameter),
74
+ outputs: value.outputs().map(parseParameterType)
75
+ })
76
+ break
77
+ case 'udtStructV0':
78
+ addSpec('structs', {
79
+ name: parseStructName(value),
80
+ fields: value.fields().map(parseParameter)
81
+ })
82
+ break
83
+ case 'udtUnionV0':
84
+ addSpec('unions', {
85
+ name: parseStructName(value),
86
+ cases: value.cases().reduce((agg, c) => {
87
+ const value = c.value()
88
+ const caseType = {
89
+ name: value.name().toString()
90
+ }
91
+ if (value.type) {
92
+ caseType.type = value.type().map(parseParameterType)
93
+ }
94
+ agg[c.switch().name.replace('scSpecUdtUnionCase', '')] = caseType
95
+ return agg
96
+ }, {})
97
+ })
98
+ break
99
+ case 'udtEnumV0':
100
+ addSpec('enums', {
101
+ name: parseStructName(value),
102
+ cases: value.cases().reduce((agg, c) => {
103
+ const value = c.value()
104
+ agg[value.name().toString()] = value.value() //TODO: check
105
+ return agg
106
+ }, {})
107
+ })
108
+ break
109
+ case 'udtErrorEnumV0':
110
+ addSpec('errors', {
111
+ name: parseStructName(value),
112
+ cases: value.cases().map(c => ({
113
+ name: c.name().toString(),
114
+ value: c.value()
115
+ }))
116
+ })
117
+ break
118
+ }
119
+ }
120
+ return res
121
+ }
122
+
123
+ function parseStructName(value) {
124
+ let structName = value.name().toString()
125
+ const lib = value.lib()
126
+ if (lib.length) {
127
+ structName += ':' + lib.toString()
128
+ }
129
+ return structName
130
+ }
131
+
132
+ function parseParameterType(type) {
133
+ const typeName = type.switch().name
134
+ switch (typeName) {
135
+ case 'scSpecTypeOption':
136
+ return `option<${parseParameterType(type.valueType())}>`
137
+ case 'scSpecTypeBytesN':
138
+ return `bytesn<${type.value().n()}>`
139
+ case 'scSpecTypeVec':
140
+ return `vec<${parseParameterType(type.value().elementType())}>`
141
+ case 'scSpecTypeMap':
142
+ return `map<${parseParameterType(type.value().keyType())},${parseParameter(type.value().valueType())}>`
143
+ case 'scSpecTypeResult':
144
+ return `result<${parseParameterType(type.value().okType())},${parseParameter(type.value().errorType())}>`
145
+ case 'scSpecTypeTuple':
146
+ return `tuple<${type.value().valueTypes().map(parseParameterType).join()}>`
147
+ case 'scSpecTypeUdt':
148
+ return `udt<${type.value().name()}>`
149
+ default:
150
+ return typeName.replace('scSpecType', '').toLowerCase()
151
+ }
152
+ }
153
+
154
+ function parseParameter(param) {
155
+ return {
156
+ name: param.name().toString(),
157
+ type: parseParameterType(param.type())
158
+ }
159
+ }
@@ -0,0 +1,79 @@
1
+ /**
2
+ * Minimalistic WASM metadata reader
3
+ */
4
+ export class WasmSectionReader {
5
+ constructor(data) {
6
+ this.data = data
7
+ }
8
+
9
+ /**
10
+ * @type {Buffer}
11
+ * @private
12
+ */
13
+ data
14
+ /**
15
+ * Current reader position
16
+ * @type {number}
17
+ * @private
18
+ */
19
+ pointer = 8
20
+
21
+ /**
22
+ * Read custom metadata sections from raw WASM
23
+ * @return {{name: string, contents: Buffer}[]}
24
+ */
25
+ readCustomSections() {
26
+ const sections = []
27
+ while (this.pointer < this.data.length) {
28
+ const sectionType = this.readUint8()
29
+ let length = this.readVarUint32()
30
+ if (sectionType === 0) { //accumulate only custom sections
31
+ const sectionStart = this.pointer
32
+ const name = this.readString()
33
+ length -= this.pointer - sectionStart
34
+ sections.push({
35
+ name,
36
+ contents: this.data.subarray(this.pointer, this.pointer + length)
37
+ })
38
+ }
39
+ this.pointer += length
40
+ }
41
+ return sections
42
+ }
43
+
44
+ /**
45
+ * @return {number}
46
+ * @private
47
+ */
48
+ readUint8() {
49
+ return this.data.readUint8(this.pointer++)
50
+ }
51
+
52
+ /**
53
+ * @return {number}
54
+ * @private
55
+ */
56
+ readVarUint32() {
57
+ let result = 0
58
+ let shift = 0
59
+ while (true) {
60
+ let byte = this.readUint8()
61
+ result |= (byte & 0x7f) << shift
62
+ shift += 7
63
+ if ((byte & 0x80) === 0)
64
+ break
65
+ }
66
+ return result >>> 0
67
+ }
68
+
69
+ /**
70
+ * @return {string}
71
+ * @private
72
+ */
73
+ readString() {
74
+ const length = this.readVarUint32()
75
+ const contents = this.data.subarray(this.pointer, this.pointer + length)
76
+ this.pointer += length
77
+ return contents.toString('utf-8')
78
+ }
79
+ }