bsv2 2.0.13 → 2.0.14

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 (48) hide show
  1. package/dist/bsv.bundle.js +1 -1
  2. package/dist/bsv.bundle.js.map +1 -1
  3. package/dist/bsv.cjs.js +1 -1
  4. package/dist/bsv.cjs.js.map +1 -1
  5. package/dist/bsv.module.js +1 -1
  6. package/dist/bsv.module.js.map +1 -1
  7. package/lib/bip-39.js +7 -4
  8. package/package.json +1 -1
  9. package/build/bsv.js +0 -3
  10. package/dist/bsv.min.js +0 -2
  11. package/doc/assets/anchor.js +0 -350
  12. package/doc/assets/bass-addons.css +0 -12
  13. package/doc/assets/bass.css +0 -544
  14. package/doc/assets/fonts/EOT/SourceCodePro-Bold.eot +0 -0
  15. package/doc/assets/fonts/EOT/SourceCodePro-Regular.eot +0 -0
  16. package/doc/assets/fonts/LICENSE.txt +0 -93
  17. package/doc/assets/fonts/OTF/SourceCodePro-Bold.otf +0 -0
  18. package/doc/assets/fonts/OTF/SourceCodePro-Regular.otf +0 -0
  19. package/doc/assets/fonts/TTF/SourceCodePro-Bold.ttf +0 -0
  20. package/doc/assets/fonts/TTF/SourceCodePro-Regular.ttf +0 -0
  21. package/doc/assets/fonts/WOFF/OTF/SourceCodePro-Bold.otf.woff +0 -0
  22. package/doc/assets/fonts/WOFF/OTF/SourceCodePro-Regular.otf.woff +0 -0
  23. package/doc/assets/fonts/WOFF/TTF/SourceCodePro-Bold.ttf.woff +0 -0
  24. package/doc/assets/fonts/WOFF/TTF/SourceCodePro-Regular.ttf.woff +0 -0
  25. package/doc/assets/fonts/WOFF2/OTF/SourceCodePro-Bold.otf.woff2 +0 -0
  26. package/doc/assets/fonts/WOFF2/OTF/SourceCodePro-Regular.otf.woff2 +0 -0
  27. package/doc/assets/fonts/WOFF2/TTF/SourceCodePro-Bold.ttf.woff2 +0 -0
  28. package/doc/assets/fonts/WOFF2/TTF/SourceCodePro-Regular.ttf.woff2 +0 -0
  29. package/doc/assets/fonts/source-code-pro.css +0 -23
  30. package/doc/assets/github.css +0 -123
  31. package/doc/assets/site.js +0 -168
  32. package/doc/assets/split.css +0 -15
  33. package/doc/assets/split.js +0 -784
  34. package/doc/assets/style.css +0 -147
  35. package/doc/index.html +0 -9387
  36. package/docs/block.html +0 -36
  37. package/docs/ecies.html +0 -81
  38. package/docs/index.html +0 -84
  39. package/docs/networks.html +0 -43
  40. package/docs/script.html +0 -101
  41. package/docs/transaction.html +0 -150
  42. package/docs/unspentoutput.html +0 -32
  43. package/jsdoc.json +0 -5
  44. package/lib/rabin.js +0 -300
  45. package/mkdocs.yml +0 -37
  46. package/test1.html +0 -88
  47. package/webpack.config.js_entry +0 -57
  48. package/yarn-error.log +0 -6199
@@ -1,784 +0,0 @@
1
- /*! Split.js - v1.5.11 */
2
-
3
- (function (global, factory) {
4
- typeof exports === 'object' && typeof module !== 'undefined'
5
- ? module.exports = factory()
6
- : typeof define === 'function' && define.amd
7
- ? define(factory)
8
- : (global.Split = factory())
9
- }(this, function () {
10
- 'use strict'
11
-
12
- // The programming goals of Split.js are to deliver readable, understandable and
13
- // maintainable code, while at the same time manually optimizing for tiny minified file size,
14
- // browser compatibility without additional requirements, graceful fallback (IE8 is supported)
15
- // and very few assumptions about the user's page layout.
16
- const global = window
17
- const document = global.document
18
-
19
- // Save a couple long function names that are used frequently.
20
- // This optimization saves around 400 bytes.
21
- const addEventListener = 'addEventListener'
22
- const removeEventListener = 'removeEventListener'
23
- const getBoundingClientRect = 'getBoundingClientRect'
24
- const gutterStartDragging = '_a'
25
- const aGutterSize = '_b'
26
- const bGutterSize = '_c'
27
- const HORIZONTAL = 'horizontal'
28
- const NOOP = function () { return false }
29
-
30
- // Figure out if we're in IE8 or not. IE8 will still render correctly,
31
- // but will be static instead of draggable.
32
- const isIE8 = global.attachEvent && !global[addEventListener]
33
-
34
- // Helper function determines which prefixes of CSS calc we need.
35
- // We only need to do this once on startup, when this anonymous function is called.
36
- //
37
- // Tests -webkit, -moz and -o prefixes. Modified from StackOverflow:
38
- // http://stackoverflow.com/questions/16625140/js-feature-detection-to-detect-the-usage-of-webkit-calc-over-calc/16625167#16625167
39
- const calc = (['', '-webkit-', '-moz-', '-o-']
40
- .filter(function (prefix) {
41
- const el = document.createElement('div')
42
- el.style.cssText = 'width:' + prefix + 'calc(9px)'
43
-
44
- return !!el.style.length
45
- })
46
- .shift()) + 'calc'
47
-
48
- // Helper function checks if its argument is a string-like type
49
- const isString = function (v) { return typeof v === 'string' || v instanceof String }
50
-
51
- // Helper function allows elements and string selectors to be used
52
- // interchangeably. In either case an element is returned. This allows us to
53
- // do `Split([elem1, elem2])` as well as `Split(['#id1', '#id2'])`.
54
- const elementOrSelector = function (el) {
55
- if (isString(el)) {
56
- const ele = document.querySelector(el)
57
- if (!ele) {
58
- throw new Error(('Selector ' + el + ' did not match a DOM element'))
59
- }
60
- return ele
61
- }
62
-
63
- return el
64
- }
65
-
66
- // Helper function gets a property from the properties object, with a default fallback
67
- const getOption = function (options, propName, def) {
68
- const value = options[propName]
69
- if (value !== undefined) {
70
- return value
71
- }
72
- return def
73
- }
74
-
75
- const getGutterSize = function (gutterSize, isFirst, isLast, gutterAlign) {
76
- if (isFirst) {
77
- if (gutterAlign === 'end') {
78
- return 0
79
- }
80
- if (gutterAlign === 'center') {
81
- return gutterSize / 2
82
- }
83
- } else if (isLast) {
84
- if (gutterAlign === 'start') {
85
- return 0
86
- }
87
- if (gutterAlign === 'center') {
88
- return gutterSize / 2
89
- }
90
- }
91
-
92
- return gutterSize
93
- }
94
-
95
- // Default options
96
- const defaultGutterFn = function (i, gutterDirection) {
97
- const gut = document.createElement('div')
98
- gut.className = 'gutter gutter-' + gutterDirection
99
- return gut
100
- }
101
-
102
- const defaultElementStyleFn = function (dim, size, gutSize) {
103
- const style = {}
104
-
105
- if (!isString(size)) {
106
- if (!isIE8) {
107
- style[dim] = calc + '(' + size + '% - ' + gutSize + 'px)'
108
- } else {
109
- style[dim] = size + '%'
110
- }
111
- } else {
112
- style[dim] = size
113
- }
114
-
115
- return style
116
- }
117
-
118
- const defaultGutterStyleFn = function (dim, gutSize) {
119
- let obj
120
-
121
- return ((obj = {}, obj[dim] = (gutSize + 'px'), obj))
122
- }
123
-
124
- // The main function to initialize a split. Split.js thinks about each pair
125
- // of elements as an independant pair. Dragging the gutter between two elements
126
- // only changes the dimensions of elements in that pair. This is key to understanding
127
- // how the following functions operate, since each function is bound to a pair.
128
- //
129
- // A pair object is shaped like this:
130
- //
131
- // {
132
- // a: DOM element,
133
- // b: DOM element,
134
- // aMin: Number,
135
- // bMin: Number,
136
- // dragging: Boolean,
137
- // parent: DOM element,
138
- // direction: 'horizontal' | 'vertical'
139
- // }
140
- //
141
- // The basic sequence:
142
- //
143
- // 1. Set defaults to something sane. `options` doesn't have to be passed at all.
144
- // 2. Initialize a bunch of strings based on the direction we're splitting.
145
- // A lot of the behavior in the rest of the library is paramatized down to
146
- // rely on CSS strings and classes.
147
- // 3. Define the dragging helper functions, and a few helpers to go with them.
148
- // 4. Loop through the elements while pairing them off. Every pair gets an
149
- // `pair` object and a gutter.
150
- // 5. Actually size the pair elements, insert gutters and attach event listeners.
151
- const Split = function (idsOption, options) {
152
- if (options === void 0) options = {}
153
-
154
- let ids = idsOption
155
- let dimension
156
- let clientAxis
157
- let position
158
- let positionEnd
159
- let clientSize
160
- let elements
161
-
162
- // Allow HTMLCollection to be used as an argument when supported
163
- if (Array.from) {
164
- ids = Array.from(ids)
165
- }
166
-
167
- // All DOM elements in the split should have a common parent. We can grab
168
- // the first elements parent and hope users read the docs because the
169
- // behavior will be whacky otherwise.
170
- const firstElement = elementOrSelector(ids[0])
171
- const parent = firstElement.parentNode
172
- const parentStyle = getComputedStyle ? getComputedStyle(parent) : null
173
- const parentFlexDirection = parentStyle ? parentStyle.flexDirection : null
174
-
175
- // Set default options.sizes to equal percentages of the parent element.
176
- let sizes = getOption(options, 'sizes') || ids.map(function () { return 100 / ids.length })
177
-
178
- // Standardize minSize to an array if it isn't already. This allows minSize
179
- // to be passed as a number.
180
- const minSize = getOption(options, 'minSize', 100)
181
- const minSizes = Array.isArray(minSize) ? minSize : ids.map(function () { return minSize })
182
-
183
- // Get other options
184
- const expandToMin = getOption(options, 'expandToMin', false)
185
- const gutterSize = getOption(options, 'gutterSize', 10)
186
- const gutterAlign = getOption(options, 'gutterAlign', 'center')
187
- const snapOffset = getOption(options, 'snapOffset', 30)
188
- const dragInterval = getOption(options, 'dragInterval', 1)
189
- const direction = getOption(options, 'direction', HORIZONTAL)
190
- const cursor = getOption(
191
- options,
192
- 'cursor',
193
- direction === HORIZONTAL ? 'col-resize' : 'row-resize'
194
- )
195
- const gutter = getOption(options, 'gutter', defaultGutterFn)
196
- const elementStyle = getOption(
197
- options,
198
- 'elementStyle',
199
- defaultElementStyleFn
200
- )
201
- const gutterStyle = getOption(options, 'gutterStyle', defaultGutterStyleFn)
202
-
203
- // 2. Initialize a bunch of strings based on the direction we're splitting.
204
- // A lot of the behavior in the rest of the library is paramatized down to
205
- // rely on CSS strings and classes.
206
- if (direction === HORIZONTAL) {
207
- dimension = 'width'
208
- clientAxis = 'clientX'
209
- position = 'left'
210
- positionEnd = 'right'
211
- clientSize = 'clientWidth'
212
- } else if (direction === 'vertical') {
213
- dimension = 'height'
214
- clientAxis = 'clientY'
215
- position = 'top'
216
- positionEnd = 'bottom'
217
- clientSize = 'clientHeight'
218
- }
219
-
220
- // 3. Define the dragging helper functions, and a few helpers to go with them.
221
- // Each helper is bound to a pair object that contains its metadata. This
222
- // also makes it easy to store references to listeners that that will be
223
- // added and removed.
224
- //
225
- // Even though there are no other functions contained in them, aliasing
226
- // this to self saves 50 bytes or so since it's used so frequently.
227
- //
228
- // The pair object saves metadata like dragging state, position and
229
- // event listener references.
230
-
231
- function setElementSize (el, size, gutSize, i) {
232
- // Split.js allows setting sizes via numbers (ideally), or if you must,
233
- // by string, like '300px'. This is less than ideal, because it breaks
234
- // the fluid layout that `calc(% - px)` provides. You're on your own if you do that,
235
- // make sure you calculate the gutter size by hand.
236
- const style = elementStyle(dimension, size, gutSize, i)
237
-
238
- Object.keys(style).forEach(function (prop) {
239
- // eslint-disable-next-line no-param-reassign
240
- el.style[prop] = style[prop]
241
- })
242
- }
243
-
244
- function setGutterSize (gutterElement, gutSize, i) {
245
- const style = gutterStyle(dimension, gutSize, i)
246
-
247
- Object.keys(style).forEach(function (prop) {
248
- // eslint-disable-next-line no-param-reassign
249
- gutterElement.style[prop] = style[prop]
250
- })
251
- }
252
-
253
- function getSizes () {
254
- return elements.map(function (element) { return element.size })
255
- }
256
-
257
- // Supports touch events, but not multitouch, so only the first
258
- // finger `touches[0]` is counted.
259
- function getMousePosition (e) {
260
- if ('touches' in e) { return e.touches[0][clientAxis] }
261
- return e[clientAxis]
262
- }
263
-
264
- // Actually adjust the size of elements `a` and `b` to `offset` while dragging.
265
- // calc is used to allow calc(percentage + gutterpx) on the whole split instance,
266
- // which allows the viewport to be resized without additional logic.
267
- // Element a's size is the same as offset. b's size is total size - a size.
268
- // Both sizes are calculated from the initial parent percentage,
269
- // then the gutter size is subtracted.
270
- function adjust (offset) {
271
- const a = elements[this.a]
272
- const b = elements[this.b]
273
- const percentage = a.size + b.size
274
-
275
- a.size = (offset / this.size) * percentage
276
- b.size = percentage - (offset / this.size) * percentage
277
-
278
- setElementSize(a.element, a.size, this[aGutterSize], a.i)
279
- setElementSize(b.element, b.size, this[bGutterSize], b.i)
280
- }
281
-
282
- // drag, where all the magic happens. The logic is really quite simple:
283
- //
284
- // 1. Ignore if the pair is not dragging.
285
- // 2. Get the offset of the event.
286
- // 3. Snap offset to min if within snappable range (within min + snapOffset).
287
- // 4. Actually adjust each element in the pair to offset.
288
- //
289
- // ---------------------------------------------------------------------
290
- // | | <- a.minSize || b.minSize -> | |
291
- // | | | <- this.snapOffset || this.snapOffset -> | | |
292
- // | | | || | | |
293
- // | | | || | | |
294
- // ---------------------------------------------------------------------
295
- // | <- this.start this.size -> |
296
- function drag (e) {
297
- let offset
298
- const a = elements[this.a]
299
- const b = elements[this.b]
300
-
301
- if (!this.dragging) { return }
302
-
303
- // Get the offset of the event from the first side of the
304
- // pair `this.start`. Then offset by the initial position of the
305
- // mouse compared to the gutter size.
306
- offset =
307
- getMousePosition(e) -
308
- this.start +
309
- (this[aGutterSize] - this.dragOffset)
310
-
311
- if (dragInterval > 1) {
312
- offset = Math.round(offset / dragInterval) * dragInterval
313
- }
314
-
315
- // If within snapOffset of min or max, set offset to min or max.
316
- // snapOffset buffers a.minSize and b.minSize, so logic is opposite for both.
317
- // Include the appropriate gutter sizes to prevent overflows.
318
- if (offset <= a.minSize + snapOffset + this[aGutterSize]) {
319
- offset = a.minSize + this[aGutterSize]
320
- } else if (
321
- offset >=
322
- this.size - (b.minSize + snapOffset + this[bGutterSize])
323
- ) {
324
- offset = this.size - (b.minSize + this[bGutterSize])
325
- }
326
-
327
- // Actually adjust the size.
328
- adjust.call(this, offset)
329
-
330
- // Call the drag callback continously. Don't do anything too intensive
331
- // in this callback.
332
- getOption(options, 'onDrag', NOOP)()
333
- }
334
-
335
- // Cache some important sizes when drag starts, so we don't have to do that
336
- // continously:
337
- //
338
- // `size`: The total size of the pair. First + second + first gutter + second gutter.
339
- // `start`: The leading side of the first element.
340
- //
341
- // ------------------------------------------------
342
- // | aGutterSize -> ||| |
343
- // | ||| |
344
- // | ||| |
345
- // | ||| <- bGutterSize |
346
- // ------------------------------------------------
347
- // | <- start size -> |
348
- function calculateSizes () {
349
- // Figure out the parent size minus padding.
350
- const a = elements[this.a].element
351
- const b = elements[this.b].element
352
-
353
- const aBounds = a[getBoundingClientRect]()
354
- const bBounds = b[getBoundingClientRect]()
355
-
356
- this.size =
357
- aBounds[dimension] +
358
- bBounds[dimension] +
359
- this[aGutterSize] +
360
- this[bGutterSize]
361
- this.start = aBounds[position]
362
- this.end = aBounds[positionEnd]
363
- }
364
-
365
- function innerSize (element) {
366
- // Return nothing if getComputedStyle is not supported (< IE9)
367
- // Or if parent element has no layout yet
368
- if (!getComputedStyle) { return null }
369
-
370
- const computedStyle = getComputedStyle(element)
371
-
372
- if (!computedStyle) { return null }
373
-
374
- let size = element[clientSize]
375
-
376
- if (size === 0) { return null }
377
-
378
- if (direction === HORIZONTAL) {
379
- size -=
380
- parseFloat(computedStyle.paddingLeft) +
381
- parseFloat(computedStyle.paddingRight)
382
- } else {
383
- size -=
384
- parseFloat(computedStyle.paddingTop) +
385
- parseFloat(computedStyle.paddingBottom)
386
- }
387
-
388
- return size
389
- }
390
-
391
- // When specifying percentage sizes that are less than the computed
392
- // size of the element minus the gutter, the lesser percentages must be increased
393
- // (and decreased from the other elements) to make space for the pixels
394
- // subtracted by the gutters.
395
- function trimToMin (sizesToTrim) {
396
- // Try to get inner size of parent element.
397
- // If it's no supported, return original sizes.
398
- const parentSize = innerSize(parent)
399
- if (parentSize === null) {
400
- return sizesToTrim
401
- }
402
-
403
- if (minSizes.reduce(function (a, b) { return a + b }, 0) > parentSize) {
404
- return sizesToTrim
405
- }
406
-
407
- // Keep track of the excess pixels, the amount of pixels over the desired percentage
408
- // Also keep track of the elements with pixels to spare, to decrease after if needed
409
- let excessPixels = 0
410
- const toSpare = []
411
-
412
- const pixelSizes = sizesToTrim.map(function (size, i) {
413
- // Convert requested percentages to pixel sizes
414
- const pixelSize = (parentSize * size) / 100
415
- const elementGutterSize = getGutterSize(
416
- gutterSize,
417
- i === 0,
418
- i === sizesToTrim.length - 1,
419
- gutterAlign
420
- )
421
- const elementMinSize = minSizes[i] + elementGutterSize
422
-
423
- // If element is too smal, increase excess pixels by the difference
424
- // and mark that it has no pixels to spare
425
- if (pixelSize < elementMinSize) {
426
- excessPixels += elementMinSize - pixelSize
427
- toSpare.push(0)
428
- return elementMinSize
429
- }
430
-
431
- // Otherwise, mark the pixels it has to spare and return it's original size
432
- toSpare.push(pixelSize - elementMinSize)
433
- return pixelSize
434
- })
435
-
436
- // If nothing was adjusted, return the original sizes
437
- if (excessPixels === 0) {
438
- return sizesToTrim
439
- }
440
-
441
- return pixelSizes.map(function (pixelSize, i) {
442
- let newPixelSize = pixelSize
443
-
444
- // While there's still pixels to take, and there's enough pixels to spare,
445
- // take as many as possible up to the total excess pixels
446
- if (excessPixels > 0 && toSpare[i] - excessPixels > 0) {
447
- const takenPixels = Math.min(
448
- excessPixels,
449
- toSpare[i] - excessPixels
450
- )
451
-
452
- // Subtract the amount taken for the next iteration
453
- excessPixels -= takenPixels
454
- newPixelSize = pixelSize - takenPixels
455
- }
456
-
457
- // Return the pixel size adjusted as a percentage
458
- return (newPixelSize / parentSize) * 100
459
- })
460
- }
461
-
462
- // stopDragging is very similar to startDragging in reverse.
463
- function stopDragging () {
464
- const self = this
465
- const a = elements[self.a].element
466
- const b = elements[self.b].element
467
-
468
- if (self.dragging) {
469
- getOption(options, 'onDragEnd', NOOP)(getSizes())
470
- }
471
-
472
- self.dragging = false
473
-
474
- // Remove the stored event listeners. This is why we store them.
475
- global[removeEventListener]('mouseup', self.stop)
476
- global[removeEventListener]('touchend', self.stop)
477
- global[removeEventListener]('touchcancel', self.stop)
478
- global[removeEventListener]('mousemove', self.move)
479
- global[removeEventListener]('touchmove', self.move)
480
-
481
- // Clear bound function references
482
- self.stop = null
483
- self.move = null
484
-
485
- a[removeEventListener]('selectstart', NOOP)
486
- a[removeEventListener]('dragstart', NOOP)
487
- b[removeEventListener]('selectstart', NOOP)
488
- b[removeEventListener]('dragstart', NOOP)
489
-
490
- a.style.userSelect = ''
491
- a.style.webkitUserSelect = ''
492
- a.style.MozUserSelect = ''
493
- a.style.pointerEvents = ''
494
-
495
- b.style.userSelect = ''
496
- b.style.webkitUserSelect = ''
497
- b.style.MozUserSelect = ''
498
- b.style.pointerEvents = ''
499
-
500
- self.gutter.style.cursor = ''
501
- self.parent.style.cursor = ''
502
- document.body.style.cursor = ''
503
- }
504
-
505
- // startDragging calls `calculateSizes` to store the inital size in the pair object.
506
- // It also adds event listeners for mouse/touch events,
507
- // and prevents selection while dragging so avoid the selecting text.
508
- function startDragging (e) {
509
- // Right-clicking can't start dragging.
510
- if ('button' in e && e.button !== 0) {
511
- return
512
- }
513
-
514
- // Alias frequently used variables to save space. 200 bytes.
515
- const self = this
516
- const a = elements[self.a].element
517
- const b = elements[self.b].element
518
-
519
- // Call the onDragStart callback.
520
- if (!self.dragging) {
521
- getOption(options, 'onDragStart', NOOP)(getSizes())
522
- }
523
-
524
- // Don't actually drag the element. We emulate that in the drag function.
525
- e.preventDefault()
526
-
527
- // Set the dragging property of the pair object.
528
- self.dragging = true
529
-
530
- // Create two event listeners bound to the same pair object and store
531
- // them in the pair object.
532
- self.move = drag.bind(self)
533
- self.stop = stopDragging.bind(self)
534
-
535
- // All the binding. `window` gets the stop events in case we drag out of the elements.
536
- global[addEventListener]('mouseup', self.stop)
537
- global[addEventListener]('touchend', self.stop)
538
- global[addEventListener]('touchcancel', self.stop)
539
- global[addEventListener]('mousemove', self.move)
540
- global[addEventListener]('touchmove', self.move)
541
-
542
- // Disable selection. Disable!
543
- a[addEventListener]('selectstart', NOOP)
544
- a[addEventListener]('dragstart', NOOP)
545
- b[addEventListener]('selectstart', NOOP)
546
- b[addEventListener]('dragstart', NOOP)
547
-
548
- a.style.userSelect = 'none'
549
- a.style.webkitUserSelect = 'none'
550
- a.style.MozUserSelect = 'none'
551
- a.style.pointerEvents = 'none'
552
-
553
- b.style.userSelect = 'none'
554
- b.style.webkitUserSelect = 'none'
555
- b.style.MozUserSelect = 'none'
556
- b.style.pointerEvents = 'none'
557
-
558
- // Set the cursor at multiple levels
559
- self.gutter.style.cursor = cursor
560
- self.parent.style.cursor = cursor
561
- document.body.style.cursor = cursor
562
-
563
- // Cache the initial sizes of the pair.
564
- calculateSizes.call(self)
565
-
566
- // Determine the position of the mouse compared to the gutter
567
- self.dragOffset = getMousePosition(e) - self.end
568
- }
569
-
570
- // adjust sizes to ensure percentage is within min size and gutter.
571
- sizes = trimToMin(sizes)
572
-
573
- // 5. Create pair and element objects. Each pair has an index reference to
574
- // elements `a` and `b` of the pair (first and second elements).
575
- // Loop through the elements while pairing them off. Every pair gets a
576
- // `pair` object and a gutter.
577
- //
578
- // Basic logic:
579
- //
580
- // - Starting with the second element `i > 0`, create `pair` objects with
581
- // `a = i - 1` and `b = i`
582
- // - Set gutter sizes based on the _pair_ being first/last. The first and last
583
- // pair have gutterSize / 2, since they only have one half gutter, and not two.
584
- // - Create gutter elements and add event listeners.
585
- // - Set the size of the elements, minus the gutter sizes.
586
- //
587
- // -----------------------------------------------------------------------
588
- // | i=0 | i=1 | i=2 | i=3 |
589
- // | | | | |
590
- // | pair 0 pair 1 pair 2 |
591
- // | | | | |
592
- // -----------------------------------------------------------------------
593
- const pairs = []
594
- elements = ids.map(function (id, i) {
595
- // Create the element object.
596
- const element = {
597
- element: elementOrSelector(id),
598
- size: sizes[i],
599
- minSize: minSizes[i],
600
- i
601
- }
602
-
603
- let pair
604
-
605
- if (i > 0) {
606
- // Create the pair object with its metadata.
607
- pair = {
608
- a: i - 1,
609
- b: i,
610
- dragging: false,
611
- direction,
612
- parent
613
- }
614
-
615
- pair[aGutterSize] = getGutterSize(
616
- gutterSize,
617
- i - 1 === 0,
618
- false,
619
- gutterAlign
620
- )
621
- pair[bGutterSize] = getGutterSize(
622
- gutterSize,
623
- false,
624
- i === ids.length - 1,
625
- gutterAlign
626
- )
627
-
628
- // if the parent has a reverse flex-direction, switch the pair elements.
629
- if (
630
- parentFlexDirection === 'row-reverse' ||
631
- parentFlexDirection === 'column-reverse'
632
- ) {
633
- const temp = pair.a
634
- pair.a = pair.b
635
- pair.b = temp
636
- }
637
- }
638
-
639
- // Determine the size of the current element. IE8 is supported by
640
- // staticly assigning sizes without draggable gutters. Assigns a string
641
- // to `size`.
642
- //
643
- // IE9 and above
644
- if (!isIE8) {
645
- // Create gutter elements for each pair.
646
- if (i > 0) {
647
- const gutterElement = gutter(i, direction, element.element)
648
- setGutterSize(gutterElement, gutterSize, i)
649
-
650
- // Save bound event listener for removal later
651
- pair[gutterStartDragging] = startDragging.bind(pair)
652
-
653
- // Attach bound event listener
654
- gutterElement[addEventListener](
655
- 'mousedown',
656
- pair[gutterStartDragging]
657
- )
658
- gutterElement[addEventListener](
659
- 'touchstart',
660
- pair[gutterStartDragging]
661
- )
662
-
663
- parent.insertBefore(gutterElement, element.element)
664
-
665
- pair.gutter = gutterElement
666
- }
667
- }
668
-
669
- setElementSize(
670
- element.element,
671
- element.size,
672
- getGutterSize(
673
- gutterSize,
674
- i === 0,
675
- i === ids.length - 1,
676
- gutterAlign
677
- ),
678
- i
679
- )
680
-
681
- // After the first iteration, and we have a pair object, append it to the
682
- // list of pairs.
683
- if (i > 0) {
684
- pairs.push(pair)
685
- }
686
-
687
- return element
688
- })
689
-
690
- function adjustToMin (element) {
691
- const isLast = element.i === pairs.length
692
- const pair = isLast ? pairs[element.i - 1] : pairs[element.i]
693
-
694
- calculateSizes.call(pair)
695
-
696
- const size = isLast
697
- ? pair.size - element.minSize - pair[bGutterSize]
698
- : element.minSize + pair[aGutterSize]
699
-
700
- adjust.call(pair, size)
701
- }
702
-
703
- elements.forEach(function (element) {
704
- const computedSize = element.element[getBoundingClientRect]()[dimension]
705
-
706
- if (computedSize < element.minSize) {
707
- if (expandToMin) {
708
- adjustToMin(element)
709
- } else {
710
- // eslint-disable-next-line no-param-reassign
711
- element.minSize = computedSize
712
- }
713
- }
714
- })
715
-
716
- function setSizes (newSizes) {
717
- const trimmed = trimToMin(newSizes)
718
- trimmed.forEach(function (newSize, i) {
719
- if (i > 0) {
720
- const pair = pairs[i - 1]
721
-
722
- const a = elements[pair.a]
723
- const b = elements[pair.b]
724
-
725
- a.size = trimmed[i - 1]
726
- b.size = newSize
727
-
728
- setElementSize(a.element, a.size, pair[aGutterSize], a.i)
729
- setElementSize(b.element, b.size, pair[bGutterSize], b.i)
730
- }
731
- })
732
- }
733
-
734
- function destroy (preserveStyles, preserveGutter) {
735
- pairs.forEach(function (pair) {
736
- if (preserveGutter !== true) {
737
- pair.parent.removeChild(pair.gutter)
738
- } else {
739
- pair.gutter[removeEventListener](
740
- 'mousedown',
741
- pair[gutterStartDragging]
742
- )
743
- pair.gutter[removeEventListener](
744
- 'touchstart',
745
- pair[gutterStartDragging]
746
- )
747
- }
748
-
749
- if (preserveStyles !== true) {
750
- const style = elementStyle(
751
- dimension,
752
- pair.a.size,
753
- pair[aGutterSize]
754
- )
755
-
756
- Object.keys(style).forEach(function (prop) {
757
- elements[pair.a].element.style[prop] = ''
758
- elements[pair.b].element.style[prop] = ''
759
- })
760
- }
761
- })
762
- }
763
-
764
- if (isIE8) {
765
- return {
766
- setSizes,
767
- destroy
768
- }
769
- }
770
-
771
- return {
772
- setSizes,
773
- getSizes,
774
- collapse: function collapse (i) {
775
- adjustToMin(elements[i])
776
- },
777
- destroy,
778
- parent,
779
- pairs
780
- }
781
- }
782
-
783
- return Split
784
- }))