@mdsfe/mds-ui 0.2.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 (153) hide show
  1. package/CHANGELOG.md +778 -0
  2. package/LICENSE +21 -0
  3. package/README.md +106 -0
  4. package/dist/_locale/index.js +18 -0
  5. package/dist/_locale/zh-CN.js +123 -0
  6. package/dist/_mixin/emitter.js +35 -0
  7. package/dist/_mixin/focus.js +13 -0
  8. package/dist/_mixin/locale.js +17 -0
  9. package/dist/_mixin/popper.js +192 -0
  10. package/dist/_mixin/tooltip.js +218 -0
  11. package/dist/_util/__test__/switchcase.test.js +43 -0
  12. package/dist/_util/autoprefixer.js +249 -0
  13. package/dist/_util/clickoutside.js +79 -0
  14. package/dist/_util/date.js +368 -0
  15. package/dist/_util/dateUtil.js +311 -0
  16. package/dist/_util/dom.js +240 -0
  17. package/dist/_util/getRequestAnimationFrame.js +50 -0
  18. package/dist/_util/getScroll.js +21 -0
  19. package/dist/_util/loaders/loaders.css.js +52 -0
  20. package/dist/_util/loaders/loading.js +53 -0
  21. package/dist/_util/merge.js +18 -0
  22. package/dist/_util/popper.js +1261 -0
  23. package/dist/_util/popup/index.js +232 -0
  24. package/dist/_util/popup/popup-manager.js +205 -0
  25. package/dist/_util/proptype.js +12 -0
  26. package/dist/_util/repeatClick.js +30 -0
  27. package/dist/_util/resize.js +61 -0
  28. package/dist/_util/resizeEvent.js +59 -0
  29. package/dist/_util/scrollIntoView.js +38 -0
  30. package/dist/_util/scrollbar-width.js +37 -0
  31. package/dist/_util/soda.js +54 -0
  32. package/dist/_util/switchcase.js +22 -0
  33. package/dist/_util/throttleByAnimationFrame.js +70 -0
  34. package/dist/_util/tree/node.js +412 -0
  35. package/dist/_util/tree/tree.js +410 -0
  36. package/dist/_util/util.js +166 -0
  37. package/dist/_util/vue-popper.js +213 -0
  38. package/dist/affix.js +509 -0
  39. package/dist/anchor.js +522 -0
  40. package/dist/avatar.js +437 -0
  41. package/dist/backtop.js +469 -0
  42. package/dist/badge.js +439 -0
  43. package/dist/bordershadow.js +310 -0
  44. package/dist/breadcrumb.js +434 -0
  45. package/dist/button.js +579 -0
  46. package/dist/card.js +514 -0
  47. package/dist/carousel.js +1326 -0
  48. package/dist/cascaderpanel.js +2320 -0
  49. package/dist/checkbox.js +681 -0
  50. package/dist/col.js +546 -0
  51. package/dist/collapse.js +671 -0
  52. package/dist/color.js +306 -0
  53. package/dist/datepicker.js +8089 -0
  54. package/dist/divider.js +346 -0
  55. package/dist/drawer.js +652 -0
  56. package/dist/dropdown.js +687 -0
  57. package/dist/empty.js +416 -0
  58. package/dist/font.js +306 -0
  59. package/dist/form.js +878 -0
  60. package/dist/icon.js +401 -0
  61. package/dist/index.js +1 -0
  62. package/dist/input.js +1251 -0
  63. package/dist/inputnumber.js +689 -0
  64. package/dist/layout.js +786 -0
  65. package/dist/list.js +789 -0
  66. package/dist/loading.js +430 -0
  67. package/dist/mds-ui.min.css +7 -0
  68. package/dist/mds-ui.min.js +64911 -0
  69. package/dist/menu.js +1131 -0
  70. package/dist/message.js +1016 -0
  71. package/dist/modal.js +895 -0
  72. package/dist/notification.js +818 -0
  73. package/dist/pagination.js +1213 -0
  74. package/dist/popconfirm.js +336 -0
  75. package/dist/popover.js +206 -0
  76. package/dist/progress.js +1023 -0
  77. package/dist/radio.js +760 -0
  78. package/dist/rate.js +765 -0
  79. package/dist/row.js +546 -0
  80. package/dist/select.js +4950 -0
  81. package/dist/slider.js +1411 -0
  82. package/dist/slottable.js +1414 -0
  83. package/dist/steps.js +546 -0
  84. package/dist/style/affix.css +5524 -0
  85. package/dist/style/anchor.css +5572 -0
  86. package/dist/style/avatar.css +5587 -0
  87. package/dist/style/backtop.css +34 -0
  88. package/dist/style/badge.css +5655 -0
  89. package/dist/style/bordershadow.css +5601 -0
  90. package/dist/style/breadcrumb.css +5551 -0
  91. package/dist/style/button.css +7679 -0
  92. package/dist/style/card.css +5670 -0
  93. package/dist/style/carousel.css +5731 -0
  94. package/dist/style/cascaderpanel.css +125 -0
  95. package/dist/style/checkbox.css +5700 -0
  96. package/dist/style/col.css +8121 -0
  97. package/dist/style/collapse.css +5593 -0
  98. package/dist/style/color.css +6136 -0
  99. package/dist/style/datepicker.css +5977 -0
  100. package/dist/style/divider.css +5558 -0
  101. package/dist/style/drawer.css +7979 -0
  102. package/dist/style/dropdown.css +7950 -0
  103. package/dist/style/empty.css +5563 -0
  104. package/dist/style/font.css +5559 -0
  105. package/dist/style/form.css +5662 -0
  106. package/dist/style/icon.css +5538 -0
  107. package/dist/style/input.css +6256 -0
  108. package/dist/style/inputnumber.css +5828 -0
  109. package/dist/style/layout.css +5572 -0
  110. package/dist/style/list.css +5655 -0
  111. package/dist/style/loading.css +5540 -0
  112. package/dist/style/menu.css +6183 -0
  113. package/dist/style/message.css +194 -0
  114. package/dist/style/modal.css +5637 -0
  115. package/dist/style/notification.css +5706 -0
  116. package/dist/style/pagination.css +6683 -0
  117. package/dist/style/popconfirm.css +7951 -0
  118. package/dist/style/popover.css +5727 -0
  119. package/dist/style/progress.css +5714 -0
  120. package/dist/style/radio.css +5769 -0
  121. package/dist/style/rate.css +5616 -0
  122. package/dist/style/row.css +8121 -0
  123. package/dist/style/select.css +5729 -0
  124. package/dist/style/slider.css +5594 -0
  125. package/dist/style/slottable.css +5831 -0
  126. package/dist/style/steps.css +6100 -0
  127. package/dist/style/switch.css +5624 -0
  128. package/dist/style/table.css +8392 -0
  129. package/dist/style/tabs.css +6047 -0
  130. package/dist/style/tag.css +5935 -0
  131. package/dist/style/text.css +5636 -0
  132. package/dist/style/timeline.css +5602 -0
  133. package/dist/style/timepicker.css +5904 -0
  134. package/dist/style/tooltip.css +5686 -0
  135. package/dist/style/transfer.css +101 -0
  136. package/dist/style/transition.css +1417 -0
  137. package/dist/style/tree.css +5598 -0
  138. package/dist/style/typography.css +5640 -0
  139. package/dist/style/upload.css +5834 -0
  140. package/dist/switch.js +448 -0
  141. package/dist/table.js +3809 -0
  142. package/dist/tabs.js +1273 -0
  143. package/dist/tag.js +478 -0
  144. package/dist/text.js +1100 -0
  145. package/dist/timeline.js +495 -0
  146. package/dist/timepicker.js +1567 -0
  147. package/dist/tooltip.js +179 -0
  148. package/dist/transfer.js +981 -0
  149. package/dist/transition.js +246 -0
  150. package/dist/tree.js +1866 -0
  151. package/dist/typography.js +469 -0
  152. package/dist/upload.js +1990 -0
  153. package/package.json +144 -0
@@ -0,0 +1,1261 @@
1
+ 'use strict';
2
+
3
+ exports.__esModule = true;
4
+
5
+ var _getOwnPropertyDescriptor = require('babel-runtime/core-js/object/get-own-property-descriptor');
6
+
7
+ var _getOwnPropertyDescriptor2 = _interopRequireDefault(_getOwnPropertyDescriptor);
8
+
9
+ var _keys = require('babel-runtime/core-js/object/keys');
10
+
11
+ var _keys2 = _interopRequireDefault(_keys);
12
+
13
+ var _assign = require('babel-runtime/core-js/object/assign');
14
+
15
+ var _assign2 = _interopRequireDefault(_assign);
16
+
17
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
18
+
19
+ /**
20
+ * @fileOverview Kickass library to create and place poppers near their reference elements.
21
+ * @version {{version}}
22
+ * @license
23
+ * Copyright (c) 2016 Federico Zivolo and contributors
24
+ *
25
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
26
+ * of this software and associated documentation files (the "Software"), to deal
27
+ * in the Software without restriction, including without limitation the rights
28
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
29
+ * copies of the Software, and to permit persons to whom the Software is
30
+ * furnished to do so, subject to the following conditions:
31
+ *
32
+ * The above copyright notice and this permission notice shall be included in all
33
+ * copies or substantial portions of the Software.
34
+ *
35
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
36
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
37
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
38
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
39
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
40
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
41
+ * SOFTWARE.
42
+ */
43
+
44
+ //
45
+ // Cross module loader
46
+ // Supported: Node, AMD, Browser globals
47
+ //
48
+ function createPopper() {
49
+ 'use strict';
50
+
51
+ var root = window;
52
+ // default options
53
+ var DEFAULTS = {
54
+ // placement of the popper
55
+ placement: 'bottom',
56
+
57
+ gpuAcceleration: true,
58
+
59
+ // shift popper from its origin by the given amount of pixels (can be negative)
60
+ offset: 0,
61
+
62
+ // the element which will act as boundary of the popper
63
+ boundariesElement: 'viewport',
64
+
65
+ // amount of pixel used to define a minimum distance between the boundaries and the popper
66
+ boundariesPadding: 5,
67
+
68
+ // popper will try to prevent overflow following this order,
69
+ // by default, then, it could overflow on the left and on top of the boundariesElement
70
+ preventOverflowOrder: ['left', 'right', 'top', 'bottom'],
71
+
72
+ // the behavior used by flip to change the placement of the popper
73
+ flipBehavior: 'flip',
74
+
75
+ arrowElement: '[x-arrow]',
76
+
77
+ arrowOffset: 0,
78
+
79
+ // list of functions used to modify the offsets before they are applied to the popper
80
+ modifiers: ['shift', 'offset', 'preventOverflow', 'keepTogether', 'arrow', 'flip', 'applyStyle'],
81
+
82
+ modifiersIgnored: [],
83
+
84
+ forceAbsolute: false
85
+
86
+ /**
87
+ * Create a new Popper.js instance
88
+ * @constructor Popper
89
+ * @param {HTMLElement} reference - The reference element used to position the popper
90
+ * @param {HTMLElement|Object} popper
91
+ * The HTML element used as popper, or a configuration used to generate the popper.
92
+ * @param {String} [popper.tagName='div'] The tag name of the generated popper.
93
+ * @param {Array} [popper.classNames=['popper']] Array of classes to apply to the generated popper.
94
+ * @param {Array} [popper.attributes] Array of attributes to apply, specify `attr:value` to assign a value to it.
95
+ * @param {HTMLElement|String} [popper.parent=window.document.body] The parent element, given as HTMLElement or as query string.
96
+ * @param {String} [popper.content=''] The content of the popper, it can be text, html, or node if it is not text, set `contentType` to `html` or `node`.
97
+ * @param {String} [popper.contentType='text'] If `html`, the `content` will be parsed as HTML. If `node`, it will be appended as-is.
98
+ * @param {String} [popper.arrowTagName='div'] Same as `popper.tagName` but for the arrow element.
99
+ * @param {Array} [popper.arrowClassNames='popper__arrow'] Same as `popper.classNames` but for the arrow element.
100
+ * @param {String} [popper.arrowAttributes=['x-arrow']] Same as `popper.attributes` but for the arrow element.
101
+ * @param {Object} options
102
+ * @param {String} [options.placement=bottom]
103
+ * Placement of the popper accepted values: `top(-start, -end), right(-start, -end), bottom(-start, -right),
104
+ * left(-start, -end)`
105
+ *
106
+ * @param {HTMLElement|String} [options.arrowElement='[x-arrow]']
107
+ * The DOM Node used as arrow for the popper, or a CSS selector used to get the DOM node. It must be child of
108
+ * its parent Popper. Popper.js will apply to the given element the style required to align the arrow with its
109
+ * reference element.
110
+ * By default, it will look for a child node of the popper with the `x-arrow` attribute.
111
+ *
112
+ * @param {Boolean} [options.gpuAcceleration=true]
113
+ * When this property is set to true, the popper position will be applied using CSS3 translate3d, allowing the
114
+ * browser to use the GPU to accelerate the rendering.
115
+ * If set to false, the popper will be placed using `top` and `left` properties, not using the GPU.
116
+ *
117
+ * @param {Number} [options.offset=0]
118
+ * Amount of pixels the popper will be shifted (can be negative).
119
+ *
120
+ * @param {String|Element} [options.boundariesElement='viewport']
121
+ * The element which will define the boundaries of the popper position, the popper will never be placed outside
122
+ * of the defined boundaries (except if `keepTogether` is enabled)
123
+ *
124
+ * @param {Number} [options.boundariesPadding=5]
125
+ * Additional padding for the boundaries
126
+ *
127
+ * @param {Array} [options.preventOverflowOrder=['left', 'right', 'top', 'bottom']]
128
+ * Order used when Popper.js tries to avoid overflows from the boundaries, they will be checked in order,
129
+ * this means that the last ones will never overflow
130
+ *
131
+ * @param {String|Array} [options.flipBehavior='flip']
132
+ * The behavior used by the `flip` modifier to change the placement of the popper when the latter is trying to
133
+ * overlap its reference element. Defining `flip` as value, the placement will be flipped on
134
+ * its axis (`right - left`, `top - bottom`).
135
+ * You can even pass an array of placements (eg: `['right', 'left', 'top']` ) to manually specify
136
+ * how alter the placement when a flip is needed. (eg. in the above example, it would first flip from right to left,
137
+ * then, if even in its new placement, the popper is overlapping its reference element, it will be moved to top)
138
+ *
139
+ * @param {Array} [options.modifiers=[ 'shift', 'offset', 'preventOverflow', 'keepTogether', 'arrow', 'flip', 'applyStyle']]
140
+ * List of functions used to modify the data before they are applied to the popper, add your custom functions
141
+ * to this array to edit the offsets and placement.
142
+ * The function should reflect the @params and @returns of preventOverflow
143
+ *
144
+ * @param {Array} [options.modifiersIgnored=[]]
145
+ * Put here any built-in modifier name you want to exclude from the modifiers list
146
+ * The function should reflect the @params and @returns of preventOverflow
147
+ *
148
+ * @param {Boolean} [options.removeOnDestroy=false]
149
+ * Set to true if you want to automatically remove the popper when you call the `destroy` method.
150
+ */
151
+ };function Popper(reference, popper, options) {
152
+ this._reference = reference.jquery ? reference[0] : reference;
153
+ this.state = {};
154
+
155
+ // if the popper variable is a configuration object, parse it to generate an HTMLElement
156
+ // generate a default popper if is not defined
157
+ var isNotDefined = typeof popper === 'undefined' || popper === null;
158
+ var isConfig = popper && Object.prototype.toString.call(popper) === '[object Object]';
159
+ if (isNotDefined || isConfig) {
160
+ this._popper = this.parse(isConfig ? popper : {});
161
+ } else {
162
+ // otherwise, use the given HTMLElement as popper
163
+ this._popper = popper.jquery ? popper[0] : popper;
164
+ }
165
+
166
+ // with {} we create a new object with the options inside it
167
+ this._options = (0, _assign2.default)({}, DEFAULTS, options);
168
+
169
+ // refactoring modifiers' list
170
+ this._options.modifiers = this._options.modifiers.map(function (modifier) {
171
+ // remove ignored modifiers
172
+ if (this._options.modifiersIgnored.indexOf(modifier) !== -1) return;
173
+
174
+ // set the x-placement attribute before everything else because it could be used to add margins to the popper
175
+ // margins needs to be calculated to get the correct popper offsets
176
+ if (modifier === 'applyStyle') {
177
+ this._popper.setAttribute('x-placement', this._options.placement);
178
+ }
179
+
180
+ // return predefined modifier identified by string or keep the custom one
181
+ return this.modifiers[modifier] || modifier;
182
+ }.bind(this));
183
+
184
+ // make sure to apply the popper position before any computation
185
+ this.state.position = this._getPosition(this._popper, this._reference);
186
+ setStyle(this._popper, { position: this.state.position, top: 0 });
187
+
188
+ // fire the first update to position the popper in the right place
189
+ this.update();
190
+
191
+ // setup event listeners, they will take care of update the position in specific situations
192
+ this._setupEventListeners();
193
+ return this;
194
+ }
195
+
196
+ //
197
+ // Methods
198
+ //
199
+ /**
200
+ * Destroy the popper
201
+ * @method
202
+ * @memberof Popper
203
+ */
204
+ Popper.prototype.destroy = function () {
205
+ this._popper.removeAttribute('x-placement');
206
+ this._popper.style.left = '';
207
+ this._popper.style.position = '';
208
+ this._popper.style.top = '';
209
+ this._popper.style[getSupportedPropertyName('transform')] = '';
210
+ this._removeEventListeners();
211
+
212
+ // remove the popper if user explicity asked for the deletion on destroy
213
+ if (this._options.removeOnDestroy) {
214
+ this._popper.remove();
215
+ }
216
+ return this;
217
+ };
218
+
219
+ /**
220
+ * Updates the position of the popper, computing the new offsets and applying the new style
221
+ * @method
222
+ * @memberof Popper
223
+ */
224
+ Popper.prototype.update = function () {
225
+ var data = { instance: this, styles: {}
226
+
227
+ // store placement inside the data object, modifiers will be able to edit `placement` if needed
228
+ // and refer to _originalPlacement to know the original value
229
+ };data.placement = this._options.placement;
230
+ data._originalPlacement = this._options.placement;
231
+
232
+ // compute the popper and reference offsets and put them inside data.offsets
233
+ data.offsets = this._getOffsets(this._popper, this._reference, data.placement);
234
+
235
+ // get boundaries
236
+ data.boundaries = this._getBoundaries(data, this._options.boundariesPadding, this._options.boundariesElement);
237
+
238
+ data = this.runModifiers(data, this._options.modifiers);
239
+
240
+ if (typeof this.state.updateCallback === 'function') {
241
+ this.state.updateCallback(data);
242
+ }
243
+ };
244
+
245
+ /**
246
+ * If a function is passed, it will be executed after the initialization of popper with as first argument the Popper instance.
247
+ * @method
248
+ * @memberof Popper
249
+ * @param {Function} callback
250
+ */
251
+ Popper.prototype.onCreate = function (callback) {
252
+ // the createCallbacks return as first argument the popper instance
253
+
254
+ /* eslint standard/no-callback-literal: 0 */
255
+ callback(this);
256
+ return this;
257
+ };
258
+
259
+ /**
260
+ * If a function is passed, it will be executed after each update of popper with as first argument the set of coordinates and informations
261
+ * used to style popper and its arrow.
262
+ * NOTE: it doesn't get fired on the first call of the `Popper.update()` method inside the `Popper` constructor!
263
+ * @method
264
+ * @memberof Popper
265
+ * @param {Function} callback
266
+ */
267
+ Popper.prototype.onUpdate = function (callback) {
268
+ this.state.updateCallback = callback;
269
+ return this;
270
+ };
271
+
272
+ /**
273
+ * Helper used to generate poppers from a configuration file
274
+ * @method
275
+ * @memberof Popper
276
+ * @param config {Object} configuration
277
+ * @returns {HTMLElement} popper
278
+ */
279
+ Popper.prototype.parse = function (config) {
280
+ var defaultConfig = {
281
+ tagName: 'div',
282
+ classNames: ['popper'],
283
+ attributes: [],
284
+ parent: root.document.body,
285
+ content: '',
286
+ contentType: 'text',
287
+ arrowTagName: 'div',
288
+ arrowClassNames: ['popper__arrow'],
289
+ arrowAttributes: ['x-arrow']
290
+ };
291
+ config = (0, _assign2.default)({}, defaultConfig, config);
292
+
293
+ var d = root.document;
294
+
295
+ var popper = d.createElement(config.tagName);
296
+ addClassNames(popper, config.classNames);
297
+ addAttributes(popper, config.attributes);
298
+ if (config.contentType === 'node') {
299
+ popper.appendChild(config.content.jquery ? config.content[0] : config.content);
300
+ } else if (config.contentType === 'html') {
301
+ popper.innerHTML = config.content;
302
+ } else {
303
+ popper.textContent = config.content;
304
+ }
305
+
306
+ if (config.arrowTagName) {
307
+ var arrow = d.createElement(config.arrowTagName);
308
+ addClassNames(arrow, config.arrowClassNames);
309
+ addAttributes(arrow, config.arrowAttributes);
310
+ popper.appendChild(arrow);
311
+ }
312
+
313
+ var parent = config.parent.jquery ? config.parent[0] : config.parent;
314
+
315
+ // if the given parent is a string, use it to match an element
316
+ // if more than one element is matched, the first one will be used as parent
317
+ // if no elements are matched, the script will throw an error
318
+ if (typeof parent === 'string') {
319
+ parent = d.querySelectorAll(config.parent);
320
+ if (parent.length > 1) {
321
+ console.warn('WARNING: the given `parent` query(' + config.parent + ') matched more than one element, the first one will be used');
322
+ }
323
+ if (parent.length === 0) {
324
+ throw new Error('ERROR: the given parent doesn\'t exists!');
325
+ }
326
+ parent = parent[0];
327
+ }
328
+ // if the given parent is a DOM nodes list or an array of nodes with more than one element,
329
+ // the first one will be used as parent
330
+ if (parent.length > 1 && parent instanceof Element === false) {
331
+ console.warn('WARNING: you have passed as parent a list of elements, the first one will be used');
332
+ parent = parent[0];
333
+ }
334
+
335
+ // append the generated popper to its parent
336
+ parent.appendChild(popper);
337
+
338
+ return popper;
339
+
340
+ /**
341
+ * Adds class names to the given element
342
+ * @function
343
+ * @ignore
344
+ * @param {HTMLElement} target
345
+ * @param {Array} classes
346
+ */
347
+ function addClassNames(element, classNames) {
348
+ classNames.forEach(function (className) {
349
+ element.classList.add(className);
350
+ });
351
+ }
352
+
353
+ /**
354
+ * Adds attributes to the given element
355
+ * @function
356
+ * @ignore
357
+ * @param {HTMLElement} target
358
+ * @param {Array} attributes
359
+ * @example
360
+ * addAttributes(element, [ 'data-info:foobar' ])
361
+ */
362
+ function addAttributes(element, attributes) {
363
+ attributes.forEach(function (attribute) {
364
+ element.setAttribute(attribute.split(':')[0], attribute.split(':')[1] || '');
365
+ });
366
+ }
367
+ };
368
+
369
+ /**
370
+ * Helper used to get the position which will be applied to the popper
371
+ * @method
372
+ * @memberof Popper
373
+ * @param config {HTMLElement} popper element
374
+ * @param reference {HTMLElement} reference element
375
+ * @returns {String} position
376
+ */
377
+ Popper.prototype._getPosition = function (popper, reference) {
378
+ var container = getOffsetParent(reference);
379
+
380
+ if (this._options.forceAbsolute) {
381
+ return 'absolute';
382
+ }
383
+
384
+ // Decide if the popper will be fixed
385
+ // If the reference element is inside a fixed context, the popper will be fixed as well to allow them to scroll together
386
+ var isParentFixed = isFixed(reference, container);
387
+ return isParentFixed ? 'fixed' : 'absolute';
388
+ };
389
+
390
+ /**
391
+ * Get offsets to the popper
392
+ * @method
393
+ * @memberof Popper
394
+ * @access private
395
+ * @param {Element} popper - the popper element
396
+ * @param {Element} reference - the reference element (the popper will be relative to this)
397
+ * @returns {Object} An object containing the offsets which will be applied to the popper
398
+ */
399
+ Popper.prototype._getOffsets = function (popper, reference, placement) {
400
+ placement = placement.split('-')[0];
401
+ var popperOffsets = {};
402
+
403
+ popperOffsets.position = this.state.position;
404
+ var isParentFixed = popperOffsets.position === 'fixed';
405
+
406
+ //
407
+ // Get reference element position
408
+ //
409
+ var referenceOffsets = getOffsetRectRelativeToCustomParent(reference, getOffsetParent(popper), isParentFixed);
410
+
411
+ //
412
+ // Get popper sizes
413
+ //
414
+ var popperRect = getOuterSizes(popper);
415
+
416
+ //
417
+ // Compute offsets of popper
418
+ //
419
+
420
+ // depending by the popper placement we have to compute its offsets slightly differently
421
+ if (['right', 'left'].indexOf(placement) !== -1) {
422
+ popperOffsets.top = referenceOffsets.top + referenceOffsets.height / 2 - popperRect.height / 2;
423
+ if (placement === 'left') {
424
+ popperOffsets.left = referenceOffsets.left - popperRect.width;
425
+ } else {
426
+ popperOffsets.left = referenceOffsets.right;
427
+ }
428
+ } else {
429
+ popperOffsets.left = referenceOffsets.left + referenceOffsets.width / 2 - popperRect.width / 2;
430
+ if (placement === 'top') {
431
+ popperOffsets.top = referenceOffsets.top - popperRect.height;
432
+ } else {
433
+ popperOffsets.top = referenceOffsets.bottom;
434
+ }
435
+ }
436
+
437
+ // Add width and height to our offsets object
438
+ popperOffsets.width = popperRect.width;
439
+ popperOffsets.height = popperRect.height;
440
+
441
+ return {
442
+ popper: popperOffsets,
443
+ reference: referenceOffsets
444
+ };
445
+ };
446
+
447
+ /**
448
+ * Setup needed event listeners used to update the popper position
449
+ * @method
450
+ * @memberof Popper
451
+ * @access private
452
+ */
453
+ Popper.prototype._setupEventListeners = function () {
454
+ // NOTE: 1 DOM access here
455
+ this.state.updateBound = this.update.bind(this);
456
+ root.addEventListener('resize', this.state.updateBound);
457
+ // if the boundariesElement is window we don't need to listen for the scroll event
458
+ if (this._options.boundariesElement !== 'window') {
459
+ var target = getScrollParent(this._reference);
460
+ // here it could be both `body` or `documentElement` thanks to Firefox, we then check both
461
+ if (target === root.document.body || target === root.document.documentElement) {
462
+ target = root;
463
+ }
464
+ target.addEventListener('scroll', this.state.updateBound);
465
+ this.state.scrollTarget = target;
466
+ }
467
+ };
468
+
469
+ /**
470
+ * Remove event listeners used to update the popper position
471
+ * @method
472
+ * @memberof Popper
473
+ * @access private
474
+ */
475
+ Popper.prototype._removeEventListeners = function () {
476
+ // NOTE: 1 DOM access here
477
+ root.removeEventListener('resize', this.state.updateBound);
478
+ if (this._options.boundariesElement !== 'window' && this.state.scrollTarget) {
479
+ this.state.scrollTarget.removeEventListener('scroll', this.state.updateBound);
480
+ this.state.scrollTarget = null;
481
+ }
482
+ this.state.updateBound = null;
483
+ };
484
+
485
+ /**
486
+ * Computed the boundaries limits and return them
487
+ * @method
488
+ * @memberof Popper
489
+ * @access private
490
+ * @param {Object} data - Object containing the property "offsets" generated by `_getOffsets`
491
+ * @param {Number} padding - Boundaries padding
492
+ * @param {Element} boundariesElement - Element used to define the boundaries
493
+ * @returns {Object} Coordinates of the boundaries
494
+ */
495
+ Popper.prototype._getBoundaries = function (data, padding, boundariesElement) {
496
+ // NOTE: 1 DOM access here
497
+ var boundaries = {};
498
+ var width, height;
499
+ if (boundariesElement === 'window') {
500
+ var body = root.document.body;
501
+ var html = root.document.documentElement;
502
+
503
+ height = Math.max(body.scrollHeight, body.offsetHeight, html.clientHeight, html.scrollHeight, html.offsetHeight);
504
+ width = Math.max(body.scrollWidth, body.offsetWidth, html.clientWidth, html.scrollWidth, html.offsetWidth);
505
+
506
+ boundaries = {
507
+ top: 0,
508
+ right: width,
509
+ bottom: height,
510
+ left: 0
511
+ };
512
+ } else if (boundariesElement === 'viewport') {
513
+ var offsetParent = getOffsetParent(this._popper);
514
+ var scrollParent = getScrollParent(this._popper);
515
+ var offsetParentRect = getOffsetRect(offsetParent);
516
+
517
+ // Thanks the fucking native API, `document.body.scrollTop` & `document.documentElement.scrollTop`
518
+ var getScrollTopValue = function getScrollTopValue(element) {
519
+ return element === document.body ? Math.max(document.documentElement.scrollTop, document.body.scrollTop) : element.scrollTop;
520
+ };
521
+ var getScrollLeftValue = function getScrollLeftValue(element) {
522
+ return element === document.body ? Math.max(document.documentElement.scrollLeft, document.body.scrollLeft) : element.scrollLeft;
523
+ };
524
+
525
+ // if the popper is fixed we don't have to substract scrolling from the boundaries
526
+ var scrollTop = data.offsets.popper.position === 'fixed' ? 0 : getScrollTopValue(scrollParent);
527
+ var scrollLeft = data.offsets.popper.position === 'fixed' ? 0 : getScrollLeftValue(scrollParent);
528
+
529
+ boundaries = {
530
+ top: 0 - (offsetParentRect.top - scrollTop),
531
+ right: root.document.documentElement.clientWidth - (offsetParentRect.left - scrollLeft),
532
+ bottom: root.document.documentElement.clientHeight - (offsetParentRect.top - scrollTop),
533
+ left: 0 - (offsetParentRect.left - scrollLeft)
534
+ };
535
+ } else {
536
+ if (getOffsetParent(this._popper) === boundariesElement) {
537
+ boundaries = {
538
+ top: 0,
539
+ left: 0,
540
+ right: boundariesElement.clientWidth,
541
+ bottom: boundariesElement.clientHeight
542
+ };
543
+ } else {
544
+ boundaries = getOffsetRect(boundariesElement);
545
+ }
546
+ }
547
+ boundaries.left += padding;
548
+ boundaries.right -= padding;
549
+ boundaries.top = boundaries.top + padding;
550
+ boundaries.bottom = boundaries.bottom - padding;
551
+ return boundaries;
552
+ };
553
+
554
+ /**
555
+ * Loop trough the list of modifiers and run them in order, each of them will then edit the data object
556
+ * @method
557
+ * @memberof Popper
558
+ * @access public
559
+ * @param {Object} data
560
+ * @param {Array} modifiers
561
+ * @param {Function} ends
562
+ */
563
+ Popper.prototype.runModifiers = function (data, modifiers, ends) {
564
+ var modifiersToRun = modifiers.slice();
565
+ if (ends !== undefined) {
566
+ modifiersToRun = this._options.modifiers.slice(0, getArrayKeyIndex(this._options.modifiers, ends));
567
+ }
568
+
569
+ modifiersToRun.forEach(function (modifier) {
570
+ if (isFunction(modifier)) {
571
+ data = modifier.call(this, data);
572
+ }
573
+ }.bind(this));
574
+
575
+ return data;
576
+ };
577
+
578
+ /**
579
+ * Helper used to know if the given modifier depends from another one.
580
+ * @method
581
+ * @memberof Popper
582
+ * @param {String} requesting - name of requesting modifier
583
+ * @param {String} requested - name of requested modifier
584
+ * @returns {Boolean}
585
+ */
586
+ Popper.prototype.isModifierRequired = function (requesting, requested) {
587
+ var index = getArrayKeyIndex(this._options.modifiers, requesting);
588
+ return !!this._options.modifiers.slice(0, index).filter(function (modifier) {
589
+ return modifier === requested;
590
+ }).length;
591
+ };
592
+
593
+ //
594
+ // Modifiers
595
+ //
596
+
597
+ /**
598
+ * Modifiers list
599
+ * @namespace Popper.modifiers
600
+ * @memberof Popper
601
+ * @type {Object}
602
+ */
603
+ Popper.prototype.modifiers = {};
604
+
605
+ /**
606
+ * Apply the computed styles to the popper element
607
+ * @method
608
+ * @memberof Popper.modifiers
609
+ * @argument {Object} data - The data object generated by `update` method
610
+ * @returns {Object} The same data object
611
+ */
612
+ Popper.prototype.modifiers.applyStyle = function (data) {
613
+ // apply the final offsets to the popper
614
+ // NOTE: 1 DOM access here
615
+ var styles = {
616
+ position: data.offsets.popper.position
617
+
618
+ // round top and left to avoid blurry text
619
+ };var left = Math.round(data.offsets.popper.left);
620
+ var top = Math.round(data.offsets.popper.top);
621
+
622
+ // if gpuAcceleration is set to true and transform is supported, we use `translate3d` to apply the position to the popper
623
+ // we automatically use the supported prefixed version if needed
624
+ var prefixedProperty;
625
+ if (this._options.gpuAcceleration && (prefixedProperty = getSupportedPropertyName('transform'))) {
626
+ styles[prefixedProperty] = 'translate3d(' + left + 'px, ' + top + 'px, 0)';
627
+ styles.top = 0;
628
+ styles.left = 0;
629
+ } else {
630
+ // othwerise, we use the standard `left` and `top` properties
631
+ styles.left = left;
632
+ styles.top = top;
633
+ }
634
+
635
+ // any property present in `data.styles` will be applied to the popper,
636
+ // in this way we can make the 3rd party modifiers add custom styles to it
637
+ // Be aware, modifiers could override the properties defined in the previous
638
+ // lines of this modifier!
639
+ (0, _assign2.default)(styles, data.styles);
640
+
641
+ setStyle(this._popper, styles);
642
+
643
+ // set an attribute which will be useful to style the tooltip (use it to properly position its arrow)
644
+ // NOTE: 1 DOM access here
645
+ this._popper.setAttribute('x-placement', data.placement);
646
+
647
+ // if the arrow modifier is required and the arrow style has been computed, apply the arrow style
648
+ if (this.isModifierRequired(this.modifiers.applyStyle, this.modifiers.arrow) && data.offsets.arrow) {
649
+ setStyle(data.arrowElement, data.offsets.arrow);
650
+ }
651
+
652
+ return data;
653
+ };
654
+
655
+ /**
656
+ * Modifier used to shift the popper on the start or end of its reference element side
657
+ * @method
658
+ * @memberof Popper.modifiers
659
+ * @argument {Object} data - The data object generated by `update` method
660
+ * @returns {Object} The data object, properly modified
661
+ */
662
+ Popper.prototype.modifiers.shift = function (data) {
663
+ var placement = data.placement;
664
+ var basePlacement = placement.split('-')[0];
665
+ var shiftVariation = placement.split('-')[1];
666
+
667
+ // if shift shiftVariation is specified, run the modifier
668
+ if (shiftVariation) {
669
+ var reference = data.offsets.reference;
670
+ var popper = getPopperClientRect(data.offsets.popper);
671
+
672
+ var shiftOffsets = {
673
+ y: {
674
+ start: { top: reference.top },
675
+ end: { top: reference.top + reference.height - popper.height }
676
+ },
677
+ x: {
678
+ start: { left: reference.left },
679
+ end: { left: reference.left + reference.width - popper.width }
680
+ }
681
+ };
682
+
683
+ var axis = ['bottom', 'top'].indexOf(basePlacement) !== -1 ? 'x' : 'y';
684
+
685
+ data.offsets.popper = (0, _assign2.default)(popper, shiftOffsets[axis][shiftVariation]);
686
+ }
687
+
688
+ return data;
689
+ };
690
+
691
+ /**
692
+ * Modifier used to make sure the popper does not overflows from it's boundaries
693
+ * @method
694
+ * @memberof Popper.modifiers
695
+ * @argument {Object} data - The data object generated by `update` method
696
+ * @returns {Object} The data object, properly modified
697
+ */
698
+ Popper.prototype.modifiers.preventOverflow = function (data) {
699
+ var order = this._options.preventOverflowOrder;
700
+ var popper = getPopperClientRect(data.offsets.popper);
701
+
702
+ var check = {
703
+ left: function left() {
704
+ var left = popper.left;
705
+ if (popper.left < data.boundaries.left) {
706
+ left = Math.max(popper.left, data.boundaries.left);
707
+ }
708
+ return { left: left };
709
+ },
710
+ right: function right() {
711
+ var left = popper.left;
712
+ if (popper.right > data.boundaries.right) {
713
+ left = Math.min(popper.left, data.boundaries.right - popper.width);
714
+ }
715
+ return { left: left };
716
+ },
717
+ top: function top() {
718
+ var top = popper.top;
719
+ if (popper.top < data.boundaries.top) {
720
+ top = Math.max(popper.top, data.boundaries.top);
721
+ }
722
+ return { top: top };
723
+ },
724
+ bottom: function bottom() {
725
+ var top = popper.top;
726
+ if (popper.bottom > data.boundaries.bottom) {
727
+ top = Math.min(popper.top, data.boundaries.bottom - popper.height);
728
+ }
729
+ return { top: top };
730
+ }
731
+ };
732
+
733
+ order.forEach(function (direction) {
734
+ data.offsets.popper = (0, _assign2.default)(popper, check[direction]());
735
+ });
736
+
737
+ return data;
738
+ };
739
+
740
+ /**
741
+ * Modifier used to make sure the popper is always near its reference
742
+ * @method
743
+ * @memberof Popper.modifiers
744
+ * @argument {Object} data - The data object generated by _update method
745
+ * @returns {Object} The data object, properly modified
746
+ */
747
+ Popper.prototype.modifiers.keepTogether = function (data) {
748
+ var popper = getPopperClientRect(data.offsets.popper);
749
+ var reference = data.offsets.reference;
750
+ var f = Math.floor;
751
+
752
+ if (popper.right < f(reference.left)) {
753
+ data.offsets.popper.left = f(reference.left) - popper.width;
754
+ }
755
+ if (popper.left > f(reference.right)) {
756
+ data.offsets.popper.left = f(reference.right);
757
+ }
758
+ if (popper.bottom < f(reference.top)) {
759
+ data.offsets.popper.top = f(reference.top) - popper.height;
760
+ }
761
+ if (popper.top > f(reference.bottom)) {
762
+ data.offsets.popper.top = f(reference.bottom);
763
+ }
764
+
765
+ return data;
766
+ };
767
+
768
+ /**
769
+ * Modifier used to flip the placement of the popper when the latter is starting overlapping its reference element.
770
+ * Requires the `preventOverflow` modifier before it in order to work.
771
+ * **NOTE:** This modifier will run all its previous modifiers everytime it tries to flip the popper!
772
+ * @method
773
+ * @memberof Popper.modifiers
774
+ * @argument {Object} data - The data object generated by _update method
775
+ * @returns {Object} The data object, properly modified
776
+ */
777
+ Popper.prototype.modifiers.flip = function (data) {
778
+ // check if preventOverflow is in the list of modifiers before the flip modifier.
779
+ // otherwise flip would not work as expected.
780
+ if (!this.isModifierRequired(this.modifiers.flip, this.modifiers.preventOverflow)) {
781
+ console.warn('WARNING: preventOverflow modifier is required by flip modifier in order to work, be sure to include it before flip!');
782
+ return data;
783
+ }
784
+
785
+ if (data.flipped && data.placement === data._originalPlacement) {
786
+ // seems like flip is trying to loop, probably there's not enough space on any of the flippable sides
787
+ return data;
788
+ }
789
+
790
+ var placement = data.placement.split('-')[0];
791
+ var placementOpposite = getOppositePlacement(placement);
792
+ var variation = data.placement.split('-')[1] || '';
793
+
794
+ var flipOrder = [];
795
+ if (this._options.flipBehavior === 'flip') {
796
+ flipOrder = [placement, placementOpposite];
797
+ } else {
798
+ flipOrder = this._options.flipBehavior;
799
+ }
800
+
801
+ flipOrder.forEach(function (step, index) {
802
+ if (placement !== step || flipOrder.length === index + 1) {
803
+ return;
804
+ }
805
+
806
+ placement = data.placement.split('-')[0];
807
+ placementOpposite = getOppositePlacement(placement);
808
+
809
+ var popperOffsets = getPopperClientRect(data.offsets.popper);
810
+
811
+ // this boolean is used to distinguish right and bottom from top and left
812
+ // they need different computations to get flipped
813
+ var a = ['right', 'bottom'].indexOf(placement) !== -1;
814
+
815
+ // using Math.floor because the reference offsets may contain decimals we are not going to consider here
816
+ if (a && Math.floor(data.offsets.reference[placement]) > Math.floor(popperOffsets[placementOpposite]) || !a && Math.floor(data.offsets.reference[placement]) < Math.floor(popperOffsets[placementOpposite])) {
817
+ // we'll use this boolean to detect any flip loop
818
+ data.flipped = true;
819
+ data.placement = flipOrder[index + 1];
820
+ if (variation) {
821
+ data.placement += '-' + variation;
822
+ }
823
+ data.offsets.popper = this._getOffsets(this._popper, this._reference, data.placement).popper;
824
+
825
+ data = this.runModifiers(data, this._options.modifiers, this._flip);
826
+ }
827
+ }.bind(this));
828
+ return data;
829
+ };
830
+
831
+ /**
832
+ * Modifier used to add an offset to the popper, useful if you more granularity positioning your popper.
833
+ * The offsets will shift the popper on the side of its reference element.
834
+ * @method
835
+ * @memberof Popper.modifiers
836
+ * @argument {Object} data - The data object generated by _update method
837
+ * @returns {Object} The data object, properly modified
838
+ */
839
+ Popper.prototype.modifiers.offset = function (data) {
840
+ var offset = this._options.offset;
841
+ var popper = data.offsets.popper;
842
+
843
+ if (data.placement.indexOf('left') !== -1) {
844
+ popper.top -= offset;
845
+ } else if (data.placement.indexOf('right') !== -1) {
846
+ popper.top += offset;
847
+ } else if (data.placement.indexOf('top') !== -1) {
848
+ popper.left -= offset;
849
+ } else if (data.placement.indexOf('bottom') !== -1) {
850
+ popper.left += offset;
851
+ }
852
+ return data;
853
+ };
854
+
855
+ /**
856
+ * Modifier used to move the arrows on the edge of the popper to make sure them are always between the popper and the reference element
857
+ * It will use the CSS outer size of the arrow element to know how many pixels of conjuction are needed
858
+ * @method
859
+ * @memberof Popper.modifiers
860
+ * @argument {Object} data - The data object generated by _update method
861
+ * @returns {Object} The data object, properly modified
862
+ */
863
+ Popper.prototype.modifiers.arrow = function (data) {
864
+ var arrow = this._options.arrowElement;
865
+ // debug arrow set with height 0px
866
+ var arrowOffset = this._options.arrowOffset;
867
+
868
+ // if the arrowElement is a string, suppose it's a CSS selector
869
+ if (typeof arrow === 'string') {
870
+ arrow = this._popper.querySelector(arrow);
871
+ }
872
+
873
+ // if arrow element is not found, don't run the modifier
874
+ if (!arrow) {
875
+ return data;
876
+ }
877
+
878
+ // the arrow element must be child of its popper
879
+ if (!this._popper.contains(arrow)) {
880
+ console.warn('WARNING: `arrowElement` must be child of its popper element!');
881
+ return data;
882
+ }
883
+
884
+ // arrow depends on keepTogether in order to work
885
+ if (!this.isModifierRequired(this.modifiers.arrow, this.modifiers.keepTogether)) {
886
+ console.warn('WARNING: keepTogether modifier is required by arrow modifier in order to work, be sure to include it before arrow!');
887
+ return data;
888
+ }
889
+
890
+ var arrowStyle = {};
891
+ var placement = data.placement.split('-')[0];
892
+ var popper = getPopperClientRect(data.offsets.popper);
893
+ var reference = data.offsets.reference;
894
+ var isVertical = ['left', 'right'].indexOf(placement) !== -1;
895
+
896
+ var len = isVertical ? 'height' : 'width';
897
+ var side = isVertical ? 'top' : 'left';
898
+ // var translate = isVertical ? 'translateY' : 'translateX'
899
+ var altSide = isVertical ? 'left' : 'top';
900
+ var opSide = isVertical ? 'bottom' : 'right';
901
+ var arrowSize = getOuterSizes(arrow)[len];
902
+
903
+ //
904
+ // extends keepTogether behavior making sure the popper and its reference have enough pixels in conjuction
905
+ //
906
+
907
+ // top/left side
908
+ if (reference[opSide] - arrowSize < popper[side]) {
909
+ data.offsets.popper[side] -= popper[side] - (reference[opSide] - arrowSize);
910
+ }
911
+ // bottom/right side
912
+ if (reference[side] + arrowSize > popper[opSide]) {
913
+ data.offsets.popper[side] += reference[side] + arrowSize - popper[opSide];
914
+ }
915
+
916
+ // compute center of the popper
917
+ var center = reference[side] + (arrowOffset || reference[len] / 2 - arrowSize / 2);
918
+
919
+ var sideValue = center - popper[side];
920
+
921
+ // prevent arrow from being placed not contiguously to its popper
922
+ sideValue = Math.max(Math.min(popper[len] - arrowSize - 8, sideValue), 8);
923
+ arrowStyle[side] = sideValue;
924
+ arrowStyle[altSide] = ''; // make sure to remove any old style from the arrow
925
+
926
+ data.offsets.arrow = arrowStyle;
927
+ data.arrowElement = arrow;
928
+
929
+ return data;
930
+ };
931
+
932
+ //
933
+ // Helpers
934
+ //
935
+
936
+ /**
937
+ * Get the outer sizes of the given element (offset size + margins)
938
+ * @function
939
+ * @ignore
940
+ * @argument {Element} element
941
+ * @returns {Object} object containing width and height properties
942
+ */
943
+ function getOuterSizes(element) {
944
+ // NOTE: 1 DOM access here
945
+ var _display = element.style.display;
946
+ var _visibility = element.style.visibility;
947
+ element.style.display = 'block';
948
+ element.style.visibility = 'hidden';
949
+
950
+ // original method
951
+ var styles = root.getComputedStyle(element);
952
+ var x = parseFloat(styles.marginTop) + parseFloat(styles.marginBottom);
953
+ var y = parseFloat(styles.marginLeft) + parseFloat(styles.marginRight);
954
+ var result = { width: element.offsetWidth + y, height: element.offsetHeight + x
955
+
956
+ // reset element styles
957
+ };element.style.display = _display;
958
+ element.style.visibility = _visibility;
959
+ return result;
960
+ }
961
+
962
+ /**
963
+ * Get the opposite placement of the given one/
964
+ * @function
965
+ * @ignore
966
+ * @argument {String} placement
967
+ * @returns {String} flipped placement
968
+ */
969
+ function getOppositePlacement(placement) {
970
+ var hash = { left: 'right', right: 'left', bottom: 'top', top: 'bottom' };
971
+ return placement.replace(/left|right|bottom|top/g, function (matched) {
972
+ return hash[matched];
973
+ });
974
+ }
975
+
976
+ /**
977
+ * Given the popper offsets, generate an output similar to getBoundingClientRect
978
+ * @function
979
+ * @ignore
980
+ * @argument {Object} popperOffsets
981
+ * @returns {Object} ClientRect like output
982
+ */
983
+ function getPopperClientRect(popperOffsets) {
984
+ var offsets = (0, _assign2.default)({}, popperOffsets);
985
+ offsets.right = offsets.left + offsets.width;
986
+ offsets.bottom = offsets.top + offsets.height;
987
+ return offsets;
988
+ }
989
+
990
+ /**
991
+ * Given an array and the key to find, returns its index
992
+ * @function
993
+ * @ignore
994
+ * @argument {Array} arr
995
+ * @argument keyToFind
996
+ * @returns index or null
997
+ */
998
+ function getArrayKeyIndex(arr, keyToFind) {
999
+ var i = 0;
1000
+ var key;
1001
+ for (key in arr) {
1002
+ if (arr[key] === keyToFind) {
1003
+ return i;
1004
+ }
1005
+ i++;
1006
+ }
1007
+ return null;
1008
+ }
1009
+
1010
+ /**
1011
+ * Get CSS computed property of the given element
1012
+ * @function
1013
+ * @ignore
1014
+ * @argument {Eement} element
1015
+ * @argument {String} property
1016
+ */
1017
+ function getStyleComputedProperty(element, property) {
1018
+ // NOTE: 1 DOM access here
1019
+ var css = root.getComputedStyle(element, null);
1020
+ return css[property];
1021
+ }
1022
+
1023
+ /**
1024
+ * Returns the offset parent of the given element
1025
+ * @function
1026
+ * @ignore
1027
+ * @argument {Element} element
1028
+ * @returns {Element} offset parent
1029
+ */
1030
+ function getOffsetParent(element) {
1031
+ // NOTE: 1 DOM access here
1032
+ var offsetParent = element.offsetParent;
1033
+ return offsetParent === root.document.body || !offsetParent ? root.document.documentElement : offsetParent;
1034
+ }
1035
+
1036
+ /**
1037
+ * Returns the scrolling parent of the given element
1038
+ * @function
1039
+ * @ignore
1040
+ * @argument {Element} element
1041
+ * @returns {Element} offset parent
1042
+ */
1043
+ function getScrollParent(element) {
1044
+ var parent = element.parentNode;
1045
+
1046
+ if (!parent) {
1047
+ return element;
1048
+ }
1049
+
1050
+ if (parent === root.document) {
1051
+ // Firefox puts the scrollTOp value on `documentElement` instead of `body`, we then check which of them is
1052
+ // greater than 0 and return the proper element
1053
+ if (root.document.body.scrollTop || root.document.body.scrollLeft) {
1054
+ return root.document.body;
1055
+ } else {
1056
+ return root.document.documentElement;
1057
+ }
1058
+ }
1059
+
1060
+ // Firefox want us to check `-x` and `-y` variations as well
1061
+ if (['scroll', 'auto'].indexOf(getStyleComputedProperty(parent, 'overflow')) !== -1 || ['scroll', 'auto'].indexOf(getStyleComputedProperty(parent, 'overflow-x')) !== -1 || ['scroll', 'auto'].indexOf(getStyleComputedProperty(parent, 'overflow-y')) !== -1) {
1062
+ // If the detected scrollParent is body, we perform an additional check on its parentNode
1063
+ // in this way we'll get body if the browser is Chrome-ish, or documentElement otherwise
1064
+ // fixes issue #65
1065
+ return parent;
1066
+ }
1067
+ return getScrollParent(element.parentNode);
1068
+ }
1069
+
1070
+ /**
1071
+ * Check if the given element is fixed or is inside a fixed parent
1072
+ * @function
1073
+ * @ignore
1074
+ * @argument {Element} element
1075
+ * @argument {Element} customContainer
1076
+ * @returns {Boolean} answer to "isFixed?"
1077
+ */
1078
+ function isFixed(element) {
1079
+ if (element === root.document.body) {
1080
+ return false;
1081
+ }
1082
+ if (getStyleComputedProperty(element, 'position') === 'fixed') {
1083
+ return true;
1084
+ }
1085
+ return element.parentNode ? isFixed(element.parentNode) : element;
1086
+ }
1087
+
1088
+ /**
1089
+ * Set the style to the given popper
1090
+ * @function
1091
+ * @ignore
1092
+ * @argument {Element} element - Element to apply the style to
1093
+ * @argument {Object} styles - Object with a list of properties and values which will be applied to the element
1094
+ */
1095
+ function setStyle(element, styles) {
1096
+ function isNumeric(n) {
1097
+ return n !== '' && !isNaN(parseFloat(n)) && isFinite(n);
1098
+ }
1099
+ (0, _keys2.default)(styles).forEach(function (prop) {
1100
+ var unit = '';
1101
+ // add unit if the value is numeric and is one of the following
1102
+ if (['width', 'height', 'top', 'right', 'bottom', 'left'].indexOf(prop) !== -1 && isNumeric(styles[prop])) {
1103
+ unit = 'px';
1104
+ }
1105
+ element.style[prop] = styles[prop] + unit;
1106
+ });
1107
+ }
1108
+
1109
+ /**
1110
+ * Check if the given variable is a function
1111
+ * @function
1112
+ * @ignore
1113
+ * @argument {*} functionToCheck - variable to check
1114
+ * @returns {Boolean} answer to: is a function?
1115
+ */
1116
+ function isFunction(functionToCheck) {
1117
+ var getType = {};
1118
+ return functionToCheck && getType.toString.call(functionToCheck) === '[object Function]';
1119
+ }
1120
+
1121
+ /**
1122
+ * Get the position of the given element, relative to its offset parent
1123
+ * @function
1124
+ * @ignore
1125
+ * @param {Element} element
1126
+ * @return {Object} position - Coordinates of the element and its `scrollTop`
1127
+ */
1128
+ function getOffsetRect(element) {
1129
+ var elementRect = {
1130
+ width: element.offsetWidth,
1131
+ height: element.offsetHeight,
1132
+ left: element.offsetLeft,
1133
+ top: element.offsetTop
1134
+ };
1135
+
1136
+ elementRect.right = elementRect.left + elementRect.width;
1137
+ elementRect.bottom = elementRect.top + elementRect.height;
1138
+
1139
+ // position
1140
+ return elementRect;
1141
+ }
1142
+
1143
+ /**
1144
+ * Get bounding client rect of given element
1145
+ * @function
1146
+ * @ignore
1147
+ * @param {HTMLElement} element
1148
+ * @return {Object} client rect
1149
+ */
1150
+ function getBoundingClientRect(element) {
1151
+ var rect = element.getBoundingClientRect();
1152
+
1153
+ // whether the IE version is lower than 11
1154
+ var isIE = navigator.userAgent.indexOf('MSIE') !== -1;
1155
+
1156
+ // fix ie document bounding top always 0 bug
1157
+ var rectTop = isIE && element.tagName === 'HTML' ? -element.scrollTop : rect.top;
1158
+
1159
+ return {
1160
+ left: rect.left,
1161
+ top: rectTop,
1162
+ right: rect.right,
1163
+ bottom: rect.bottom,
1164
+ width: rect.right - rect.left,
1165
+ height: rect.bottom - rectTop
1166
+ };
1167
+ }
1168
+
1169
+ /**
1170
+ * Given an element and one of its parents, return the offset
1171
+ * @function
1172
+ * @ignore
1173
+ * @param {HTMLElement} element
1174
+ * @param {HTMLElement} parent
1175
+ * @return {Object} rect
1176
+ */
1177
+ function getOffsetRectRelativeToCustomParent(element, parent, fixed) {
1178
+ var elementRect = getBoundingClientRect(element);
1179
+ var parentRect = getBoundingClientRect(parent);
1180
+
1181
+ if (fixed) {
1182
+ var scrollParent = getScrollParent(parent);
1183
+ parentRect.top += scrollParent.scrollTop;
1184
+ parentRect.bottom += scrollParent.scrollTop;
1185
+ parentRect.left += scrollParent.scrollLeft;
1186
+ parentRect.right += scrollParent.scrollLeft;
1187
+ }
1188
+
1189
+ var rect = {
1190
+ top: elementRect.top - parentRect.top,
1191
+ left: elementRect.left - parentRect.left,
1192
+ bottom: elementRect.top - parentRect.top + elementRect.height,
1193
+ right: elementRect.left - parentRect.left + elementRect.width,
1194
+ width: elementRect.width,
1195
+ height: elementRect.height
1196
+ };
1197
+ return rect;
1198
+ }
1199
+
1200
+ /**
1201
+ * Get the prefixed supported property name
1202
+ * @function
1203
+ * @ignore
1204
+ * @argument {String} property (camelCase)
1205
+ * @returns {String} prefixed property (camelCase)
1206
+ */
1207
+ function getSupportedPropertyName(property) {
1208
+ var prefixes = ['', 'ms', 'webkit', 'moz', 'o'];
1209
+
1210
+ for (var i = 0; i < prefixes.length; i++) {
1211
+ var toCheck = prefixes[i] ? prefixes[i] + property.charAt(0).toUpperCase() + property.slice(1) : property;
1212
+ if (typeof root.document.body.style[toCheck] !== 'undefined') {
1213
+ return toCheck;
1214
+ }
1215
+ }
1216
+ return null;
1217
+ }
1218
+
1219
+ /**
1220
+ * The Object.assign() method is used to copy the values of all enumerable own properties from one or more source
1221
+ * objects to a target object. It will return the target object.
1222
+ * This polyfill doesn't support symbol properties, since ES5 doesn't have symbols anyway
1223
+ * Source: https://developer.mozilla.org/en/docs/Web/JavaScript/Reference/Global_Objects/Object/assign
1224
+ * @function
1225
+ * @ignore
1226
+ */
1227
+ if (!_assign2.default) {
1228
+ Object.defineProperty(Object, 'assign', {
1229
+ enumerable: false,
1230
+ configurable: true,
1231
+ writable: true,
1232
+ value: function value(target) {
1233
+ if (target === undefined || target === null) {
1234
+ throw new TypeError('Cannot convert first argument to object');
1235
+ }
1236
+
1237
+ var to = Object(target);
1238
+ for (var i = 1; i < arguments.length; i++) {
1239
+ var nextSource = arguments[i];
1240
+ if (nextSource === undefined || nextSource === null) {
1241
+ continue;
1242
+ }
1243
+ nextSource = Object(nextSource);
1244
+
1245
+ var keysArray = (0, _keys2.default)(nextSource);
1246
+ for (var nextIndex = 0, len = keysArray.length; nextIndex < len; nextIndex++) {
1247
+ var nextKey = keysArray[nextIndex];
1248
+ var desc = (0, _getOwnPropertyDescriptor2.default)(nextSource, nextKey);
1249
+ if (desc !== undefined && desc.enumerable) {
1250
+ to[nextKey] = nextSource[nextKey];
1251
+ }
1252
+ }
1253
+ }
1254
+ return to;
1255
+ }
1256
+ });
1257
+ }
1258
+ return Popper;
1259
+ }
1260
+
1261
+ exports.default = createPopper();