@instructure/ui-position 11.7.3 → 11.7.4-pr-snapshot-1781695314229

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 (47) hide show
  1. package/CHANGELOG.md +12 -0
  2. package/LICENSE.md +1 -0
  3. package/{lib/Position/props.js → babel.config.cjs} +12 -7
  4. package/es/Position/index.js +40 -8
  5. package/es/PositionPropTypes.js +8 -0
  6. package/es/calculateElementPosition.js +108 -13
  7. package/es/index.js +6 -6
  8. package/es/mirrorHorizontalPlacement.js +4 -2
  9. package/es/mirrorPlacement.js +4 -2
  10. package/es/parsePlacement.js +1 -1
  11. package/package.json +14 -16
  12. package/src/Position/index.tsx +36 -11
  13. package/src/PositionPropTypes.ts +11 -0
  14. package/src/calculateElementPosition.ts +119 -15
  15. package/src/executeMirrorFunction.ts +1 -1
  16. package/src/index.ts +6 -6
  17. package/src/mirrorHorizontalPlacement.ts +2 -2
  18. package/src/mirrorPlacement.ts +2 -2
  19. package/src/parsePlacement.ts +1 -1
  20. package/tsconfig.build.tsbuildinfo +1 -1
  21. package/types/Position/index.d.ts +11 -7
  22. package/types/Position/index.d.ts.map +1 -1
  23. package/types/PositionPropTypes.d.ts +10 -0
  24. package/types/PositionPropTypes.d.ts.map +1 -1
  25. package/types/calculateElementPosition.d.ts +2 -2
  26. package/types/calculateElementPosition.d.ts.map +1 -1
  27. package/types/executeMirrorFunction.d.ts +1 -1
  28. package/types/executeMirrorFunction.d.ts.map +1 -1
  29. package/types/index.d.ts +6 -6
  30. package/types/index.d.ts.map +1 -1
  31. package/types/mirrorHorizontalPlacement.d.ts +1 -1
  32. package/types/mirrorHorizontalPlacement.d.ts.map +1 -1
  33. package/types/mirrorPlacement.d.ts +1 -1
  34. package/types/mirrorPlacement.d.ts.map +1 -1
  35. package/types/parsePlacement.d.ts +1 -1
  36. package/types/parsePlacement.d.ts.map +1 -1
  37. package/lib/Position/index.js +0 -249
  38. package/lib/Position/styles.js +0 -50
  39. package/lib/Position/theme.js +0 -47
  40. package/lib/PositionPropTypes.js +0 -57
  41. package/lib/calculateElementPosition.js +0 -524
  42. package/lib/executeMirrorFunction.js +0 -37
  43. package/lib/index.js +0 -47
  44. package/lib/mirrorHorizontalPlacement.js +0 -60
  45. package/lib/mirrorPlacement.js +0 -63
  46. package/lib/package.json +0 -1
  47. package/lib/parsePlacement.js +0 -12
@@ -1,524 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.calculateElementPosition = calculateElementPosition;
7
- exports.default = void 0;
8
- exports.parsePlacement = parsePlacement;
9
- var _getBoundingClientRect = require("@instructure/ui-dom-utils/lib/getBoundingClientRect.js");
10
- var _getScrollParents = require("@instructure/ui-dom-utils/lib/getScrollParents.js");
11
- var _getOffsetParents = require("@instructure/ui-dom-utils/lib/getOffsetParents.js");
12
- var _canUseDOM = require("@instructure/ui-dom-utils/lib/canUseDOM.js");
13
- var _findDOMNode = require("@instructure/ui-dom-utils/lib/findDOMNode.js");
14
- var _ownerDocument = require("@instructure/ui-dom-utils/lib/ownerDocument.js");
15
- var _ownerWindow = require("@instructure/ui-dom-utils/lib/ownerWindow.js");
16
- var _mirrorPlacement = require("./mirrorPlacement");
17
- /*
18
- * The MIT License (MIT)
19
- *
20
- * Copyright (c) 2015 - present Instructure, Inc.
21
- *
22
- * Permission is hereby granted, free of charge, to any person obtaining a copy
23
- * of this software and associated documentation files (the "Software"), to deal
24
- * in the Software without restriction, including without limitation the rights
25
- * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
26
- * copies of the Software, and to permit persons to whom the Software is
27
- * furnished to do so, subject to the following conditions:
28
- *
29
- * The above copyright notice and this permission notice shall be included in all
30
- * copies or substantial portions of the Software.
31
- *
32
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
33
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
34
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
35
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
36
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
37
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
38
- * SOFTWARE.
39
- */
40
-
41
- // @ts-expect-error will be needed for fix in the `offsetToPx` method
42
-
43
- /**
44
- * ---
45
- * category: utilities/position
46
- * ---
47
- *
48
- * Calculate the coordinates to attach an element
49
- * to a designated target with specified constraints
50
- * @module
51
- * @param element - component or DOM node
52
- * @param target - the target DOM node
53
- * @param options - constraints for the positioning
54
- * @param options.placement - designates where the element will be attached
55
- * ('top', 'bottom', 'left', 'right', 'top left' etc.)
56
- * @param options.container - DOM node where the element is contained
57
- * @param options.over - whether or not you want the element to position over the target
58
- * @param options.constrain - if the element should be constrained to 'window',
59
- * 'scroll-parent', 'parent', or 'none'
60
- * @param options.offsetX - the horizontal offset for the positioned element
61
- * @param options.offsetY - the vertical offset for the positioned element
62
- * @returns object containing style with the calculated position in the 'transform'
63
- * property
64
- */
65
- function calculateElementPosition(element, target, options = {}) {
66
- if (!element || options.placement === 'offscreen') {
67
- // hide offscreen content at the bottom of the DOM from screenreaders
68
- // unless content is contained somewhere else
69
- const hide = !options.container && element;
70
- return {
71
- placement: options.placement,
72
- style: {
73
- left: '-9999em',
74
- overflow: 'hidden',
75
- position: 'absolute',
76
- top: 0,
77
- display: hide ? 'none' : null
78
- }
79
- };
80
- }
81
- const pos = new PositionData(element, target, options);
82
- return {
83
- placement: pos.placement,
84
- style: pos.style
85
- };
86
- }
87
- class PositionedElement {
88
- constructor(element, placement, offset = {
89
- top: 0,
90
- left: 0
91
- }) {
92
- this.node = (0, _findDOMNode.findDOMNode)(element);
93
- if (typeof placement === 'string') {
94
- this.placement = parsePlacement(placement);
95
- } else if (Array.isArray(placement)) {
96
- this.placement = placement;
97
- } else {
98
- this.placement = ['bottom', 'center'];
99
- }
100
- this.rect = (0, _getBoundingClientRect.getBoundingClientRect)(this.node);
101
- this._offset = offsetToPx(offset, this.size, this.node);
102
- }
103
- node;
104
- placement;
105
- rect;
106
- _offset;
107
- get width() {
108
- return this.rect.width;
109
- }
110
- get height() {
111
- return this.rect.height;
112
- }
113
- get size() {
114
- return {
115
- width: this.width,
116
- height: this.height
117
- };
118
- }
119
- get position() {
120
- return {
121
- top: this.rect.top,
122
- left: this.rect.left
123
- };
124
- }
125
- get hasVerticalPlacement() {
126
- return ['top', 'bottom'].indexOf(this.placement[0]) >= 0;
127
- }
128
- get hasHorizontalPlacement() {
129
- return ['start', 'end'].indexOf(this.placement[0]) >= 0;
130
- }
131
- get shouldStretchVertically() {
132
- return this.placement[1] === 'stretch' && this.hasVerticalPlacement;
133
- }
134
- get shouldStretchHorizontally() {
135
- return this.placement[1] === 'stretch' && this.hasHorizontalPlacement;
136
- }
137
- get mirroredPlacement() {
138
- return (0, _mirrorPlacement.mirrorPlacement)(this.placement);
139
- }
140
- calculateOffset(placement) {
141
- const offsetMap = {
142
- top: 0,
143
- start: 0,
144
- center: '50%',
145
- bottom: '100%',
146
- end: '100%',
147
- stretch: 0
148
- };
149
- let [first, second] = placement;
150
- if (['start', 'end'].indexOf(first) >= 0) {
151
- ;
152
- [first, second] = [second, first];
153
- }
154
- let top = 0;
155
- let left = 0;
156
- if (typeof offsetMap[first] !== 'undefined') {
157
- top = offsetMap[first];
158
- }
159
- if (typeof offsetMap[second] !== 'undefined') {
160
- left = offsetMap[second];
161
- }
162
- return addOffsets([offsetToPx({
163
- top,
164
- left
165
- }, this.size, this.node), parseOffset(this._offset, this.placement)]);
166
- }
167
- get scrollParentsOffset() {
168
- const parents = (0, _getScrollParents.getScrollParents)(this.node);
169
- let offsetY = 0;
170
- let offsetX = 0;
171
- for (let i = 1; i < parents.length; i++) {
172
- const parent = parents[i];
173
- const child = parents[i - 1];
174
- if (parent) {
175
- offsetY = offsetY + (this.normalizeScrollTop(parent) - this.normalizeScrollTop(child));
176
- offsetX = offsetX + (parent.scrollLeft - child.scrollLeft);
177
- }
178
- }
179
- return {
180
- top: offsetY,
181
- left: offsetX
182
- };
183
- }
184
- get positionedParentsOffset() {
185
- // If the element container is within a positioned
186
- // element, it will position absolutely with respect to that
187
- // ancestor. We calculate the offset between the child and
188
- // positioned parent so we can negate that distance
189
- const parents = (0, _getOffsetParents.getOffsetParents)(this.node);
190
- const doc = (0, _ownerDocument.ownerDocument)(this.node);
191
-
192
- // If there is more than one parent, the offset on the
193
- // documentElement should be calculated appropriately.
194
- // Otherwise we need to explictly account for that offset
195
- let offsetY = parents.length > 1 ? 0 : (0, _getBoundingClientRect.getBoundingClientRect)(doc?.documentElement).top;
196
- let offsetX = 0;
197
- let scrollY = 0;
198
- for (let i = 1; i < parents.length; i++) {
199
- const parent = (0, _getBoundingClientRect.getBoundingClientRect)(parents[i]);
200
- const child = (0, _getBoundingClientRect.getBoundingClientRect)(parents[i - 1]);
201
- offsetY = offsetY + (child.top - parent.top);
202
- offsetX = offsetX + (child.left - parent.left);
203
- if (parents[i] === doc?.body) {
204
- // accounts for any margin on body
205
- offsetY = offsetY + parent.top;
206
- offsetX = offsetX + parent.left;
207
- }
208
- scrollY = scrollY + this.normalizeScrollTop(parents[i]);
209
- }
210
- // Account for any scrolling on positioned parents
211
- // Without this, unnecessary scroll offset could be applied
212
- // to our target element
213
- offsetY = offsetY + scrollY;
214
- return {
215
- top: offsetY,
216
- left: offsetX
217
- };
218
- }
219
- normalizeScrollTop(element) {
220
- // Account for cross browser differences with scrollTop attribute on the
221
- // body element https://bugs.chromium.org/p/chromium/issues/detail?id=766938
222
- return (0, _ownerDocument.ownerDocument)(this.node)?.body === element ? 0 : element.scrollTop;
223
- }
224
- }
225
- class PositionData {
226
- constructor(element, target, options) {
227
- this.options = options || {};
228
- const {
229
- container,
230
- constrain,
231
- placement,
232
- over
233
- } = this.options;
234
- if (!element || placement === 'offscreen') return;
235
- this.container = container || (0, _ownerDocument.ownerDocument)(element)?.body;
236
- this.element = new PositionedElement(element, placement, {
237
- top: this.options.offsetY,
238
- left: this.options.offsetX
239
- });
240
- this.target = new PositionedElement(target || this.container, over ? this.element.placement : this.element.mirroredPlacement);
241
- if (constrain === 'window') {
242
- this.constrainTo((0, _ownerWindow.ownerWindow)(element));
243
- } else if (constrain === 'scroll-parent') {
244
- this.constrainTo((0, _getScrollParents.getScrollParents)(this.target.node)[0]);
245
- } else if (constrain === 'parent') {
246
- this.constrainTo(this.container);
247
- } else if (typeof constrain === 'function') {
248
- this.constrainTo((0, _findDOMNode.findDOMNode)(constrain.call(null)));
249
- } else if (typeof constrain === 'object') {
250
- this.constrainTo((0, _findDOMNode.findDOMNode)(constrain));
251
- }
252
- }
253
- options;
254
- container;
255
- element;
256
- target;
257
- get offset() {
258
- const {
259
- top,
260
- left
261
- } = this.target.calculateOffset(this.element.placement);
262
- const offset = addOffsets([this.element.calculateOffset(this.target.placement), this.element.scrollParentsOffset, this.element.positionedParentsOffset]);
263
- return {
264
- top: top - offset.top,
265
- left: left - offset.left
266
- };
267
- }
268
- get placement() {
269
- return formatPlacement(this.element.placement);
270
- }
271
- get minWidth() {
272
- return this.element.shouldStretchVertically ? this.target.width : null;
273
- }
274
- get minHeight() {
275
- return this.element.shouldStretchHorizontally ? this.target.height : null;
276
- }
277
- get position() {
278
- const win = (0, _ownerWindow.ownerWindow)(this.target.node);
279
- let {
280
- left,
281
- top
282
- } = addOffsets([this.target.position, this.offset]);
283
- if (_canUseDOM.canUseDOM && win?.matchMedia) {
284
- const retina = win.matchMedia('only screen and (min-resolution: 1.3dppx)').matches || win.matchMedia('only screen and (-webkit-min-device-pixel-ratio: 1.3)').matches;
285
- if (!retina) {
286
- left = Math.round(left);
287
- top = Math.round(top);
288
- }
289
- }
290
- return {
291
- left,
292
- top
293
- };
294
- }
295
- get style() {
296
- // when rendered offscreen first, element has no dimension on first calculation,
297
- // so we hide it offscreen until measurements are completed
298
- const {
299
- width,
300
- height
301
- } = this.element.size;
302
- const elementNotFullyRendered = width === 0 && height === 0;
303
- return {
304
- top: 0,
305
- left: elementNotFullyRendered ? '-9999em' : 0,
306
- minWidth: this.minWidth,
307
- minHeight: this.minHeight,
308
- position: 'absolute',
309
- transform: `translateX(${this.position.left}px) translateY(${this.position.top}px) translateZ(0)`
310
- };
311
- }
312
- overflow(element) {
313
- const parentWindow = (0, _ownerWindow.ownerWindow)(element);
314
- const elementBounds = (0, _getBoundingClientRect.getBoundingClientRect)(element);
315
- const windowBounds = (0, _getBoundingClientRect.getBoundingClientRect)(parentWindow);
316
- const offsets = addOffsets([this.target.position, this.offset]);
317
- const parentOffset = {
318
- top: this.element.positionedParentsOffset.top + this.element.scrollParentsOffset.top,
319
- left: this.element.positionedParentsOffset.left + this.element.scrollParentsOffset.left
320
- };
321
- let left = offsets.left + parentOffset.left;
322
- let right = offsets.left + this.element.width + parentOffset.left;
323
- let top = offsets.top + parentOffset.top;
324
- let bottom = offsets.top + this.element.height + parentOffset.top;
325
-
326
- // adjust for vertical placements
327
- if (this.element.placement[0] === 'bottom') {
328
- top -= this.element.height + this.target.height;
329
- } else if (this.element.placement[0] === 'top') {
330
- bottom += this.element.height + this.target.height;
331
- }
332
- if (this.element.placement[1] === 'start') {
333
- left -= this.element.width - this.target.width;
334
- } else if (this.element.placement[1] === 'end') {
335
- right += this.element.width - this.target.width;
336
- }
337
-
338
- // adjust for horizontal placements
339
- if (this.element.placement[1] === 'top') {
340
- top -= this.element.height - this.target.height;
341
- } else if (this.element.placement[1] === 'bottom') {
342
- bottom += this.element.height - this.target.height;
343
- }
344
- if (this.element.placement[0] === 'end') {
345
- left -= this.element.width + this.target.width;
346
- } else if (this.element.placement[0] === 'start') {
347
- right += this.element.width + this.target.width;
348
- }
349
- const bounds = element === parentWindow ? elementBounds : {
350
- top: windowBounds.top + elementBounds.top,
351
- bottom: elementBounds.top + elementBounds.height,
352
- left: windowBounds.left + elementBounds.left,
353
- right: elementBounds.left + elementBounds.width
354
- };
355
- return {
356
- top: top < bounds.top ? bounds.top - top : 0,
357
- bottom: bottom > bounds.bottom ? bottom - bounds.bottom : 0,
358
- left: left < bounds.left ? bounds.left - left : 0,
359
- right: right > bounds.right ? right - bounds.right : 0
360
- };
361
- }
362
- constrainTo(element) {
363
- if (!element) return;
364
- const overflow = this.overflow(element);
365
- const oob = {
366
- top: overflow.top > 0,
367
- bottom: overflow.bottom > 0,
368
- left: overflow.left > 0,
369
- right: overflow.right > 0
370
- };
371
- if (this.element.hasVerticalPlacement) {
372
- if (this.element.placement[1] !== 'stretch') {
373
- if (oob.left && oob.right) {
374
- this.element.placement[1] = 'center';
375
- this.target.placement[1] = 'center';
376
- } else if (oob.left) {
377
- this.element.placement[1] = 'start';
378
- this.target.placement[1] = 'start';
379
- } else if (oob.right) {
380
- this.element.placement[1] = 'end';
381
- this.target.placement[1] = 'end';
382
- }
383
- }
384
- if (oob.top && oob.bottom) {
385
- // if top and bottom bounds broken
386
- if (overflow.bottom < overflow.top) {
387
- // more room on bottom, position below
388
- this.element.placement[0] = 'bottom';
389
- this.target.placement[0] = 'top';
390
- } else if (overflow.bottom > overflow.top) {
391
- // more room on top, position above
392
- this.element.placement[0] = 'top';
393
- this.target.placement[0] = 'bottom';
394
- }
395
- } else if (oob.top) {
396
- // if top bound broken, position below
397
- this.element.placement[0] = 'bottom';
398
- this.target.placement[0] = 'top';
399
- } else if (oob.bottom) {
400
- // if bottom bound broken, position above
401
- this.element.placement[0] = 'top';
402
- this.target.placement[0] = 'bottom';
403
- }
404
- } else if (this.element.hasHorizontalPlacement) {
405
- if (oob.top && oob.bottom) {
406
- this.element.placement[1] = 'center';
407
- this.target.placement[1] = 'center';
408
- } else if (oob.top) {
409
- this.element.placement[1] = 'top';
410
- this.target.placement[1] = 'top';
411
- } else if (oob.bottom) {
412
- this.element.placement[1] = 'bottom';
413
- this.target.placement[1] = 'bottom';
414
- }
415
- if (oob.left && oob.right) {
416
- // if left and right bounds broken
417
- if (overflow.left > overflow.right) {
418
- // more room at end, position after
419
- this.element.placement[0] = 'end';
420
- this.target.placement[0] = 'start';
421
- } else if (overflow.left < overflow.right) {
422
- // more room at start, position before
423
- this.element.placement[0] = 'start';
424
- this.target.placement[0] = 'end';
425
- }
426
- } else {
427
- if (oob.left) {
428
- this.element.placement[0] = 'end';
429
- this.target.placement[0] = 'start';
430
- } else if (oob.right) {
431
- this.element.placement[0] = 'start';
432
- this.target.placement[0] = 'end';
433
- }
434
- }
435
- }
436
- }
437
- }
438
- function addOffsets(offsets) {
439
- return offsets.reduce((sum, offset) => {
440
- return {
441
- top: sum.top + offset.top,
442
- left: sum.left + offset.left
443
- };
444
- }, {
445
- top: 0,
446
- left: 0
447
- });
448
- }
449
- function parseOffset(offset, placement) {
450
- let {
451
- top,
452
- left
453
- } = offset;
454
- if (typeof left === 'string') {
455
- left = parseFloat(left);
456
- }
457
- if (typeof top === 'string') {
458
- top = parseFloat(top);
459
- }
460
- if (placement[0] === 'bottom') {
461
- top = 0 - top;
462
- }
463
- if (placement[0] === 'end') {
464
- left = 0 - left;
465
- }
466
- return {
467
- top,
468
- left
469
- };
470
- }
471
- function offsetToPx(offset, size,
472
- // @ts-expect-error will be needed for the TODO below
473
- node) {
474
- let {
475
- left,
476
- top
477
- } = offset;
478
- if (typeof left === 'string') {
479
- if (left.indexOf('%') !== -1) {
480
- left = parseFloat(left) / 100 * size.width;
481
- } else {
482
- // TODO this fixes INSTUI-3505, but it is a breaking change, so uncomment it in V9 with the appropriate release notes
483
- // left = px(left, node)
484
- }
485
- }
486
- if (typeof top === 'string') {
487
- if (top.indexOf('%') !== -1) {
488
- top = parseFloat(top) / 100 * size.height;
489
- } else {
490
- // TODO this fixes INSTUI-3505, but it is a breaking change, so uncomment it in V9 with the appropriate release notes
491
- // top = px(top, node)
492
- }
493
- }
494
- return {
495
- top,
496
- left
497
- };
498
- }
499
- function sortPlacement(placement) {
500
- let [first, second] = placement;
501
- if (first === 'center') {
502
- ;
503
- [first, second] = [second, first];
504
- }
505
- return [first, second];
506
- }
507
-
508
- /**
509
- * Returns the following:
510
- * - When the input is just 1 element, then `[input, 'center']`, else:
511
- * - if the first element is `center`, it reverses the order
512
- * - otherwise, it just returns the split input as an array
513
- */
514
- function parsePlacement(placement) {
515
- let parsed = placement.split(' ');
516
- if (parsed.length === 1) {
517
- parsed = [placement, 'center'];
518
- }
519
- return sortPlacement(parsed);
520
- }
521
- function formatPlacement(placement) {
522
- return placement.join(' ');
523
- }
524
- var _default = exports.default = calculateElementPosition;
@@ -1,37 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.default = void 0;
7
- exports.executeMirrorFunction = executeMirrorFunction;
8
- /*
9
- * The MIT License (MIT)
10
- *
11
- * Copyright (c) 2015 - present Instructure, Inc.
12
- *
13
- * Permission is hereby granted, free of charge, to any person obtaining a copy
14
- * of this software and associated documentation files (the "Software"), to deal
15
- * in the Software without restriction, including without limitation the rights
16
- * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
17
- * copies of the Software, and to permit persons to whom the Software is
18
- * furnished to do so, subject to the following conditions:
19
- *
20
- * The above copyright notice and this permission notice shall be included in all
21
- * copies or substantial portions of the Software.
22
- *
23
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
24
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
25
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
26
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
27
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
28
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
29
- * SOFTWARE.
30
- */
31
-
32
- function executeMirrorFunction(placement, mirrorFunction, delimiter) {
33
- const [first, second] = Array.isArray(placement) ? placement : placement.split(' ');
34
- const result = mirrorFunction(first, second).filter(value => value);
35
- return delimiter ? result.join(delimiter) : result;
36
- }
37
- var _default = exports.default = executeMirrorFunction;
package/lib/index.js DELETED
@@ -1,47 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- Object.defineProperty(exports, "Position", {
7
- enumerable: true,
8
- get: function () {
9
- return _Position.Position;
10
- }
11
- });
12
- Object.defineProperty(exports, "calculateElementPosition", {
13
- enumerable: true,
14
- get: function () {
15
- return _calculateElementPosition.calculateElementPosition;
16
- }
17
- });
18
- Object.defineProperty(exports, "executeMirrorFunction", {
19
- enumerable: true,
20
- get: function () {
21
- return _executeMirrorFunction.executeMirrorFunction;
22
- }
23
- });
24
- Object.defineProperty(exports, "mirrorHorizontalPlacement", {
25
- enumerable: true,
26
- get: function () {
27
- return _mirrorHorizontalPlacement.mirrorHorizontalPlacement;
28
- }
29
- });
30
- Object.defineProperty(exports, "mirrorPlacement", {
31
- enumerable: true,
32
- get: function () {
33
- return _mirrorPlacement.mirrorPlacement;
34
- }
35
- });
36
- Object.defineProperty(exports, "parsePlacement", {
37
- enumerable: true,
38
- get: function () {
39
- return _parsePlacement.parsePlacement;
40
- }
41
- });
42
- var _Position = require("./Position");
43
- var _calculateElementPosition = require("./calculateElementPosition");
44
- var _executeMirrorFunction = require("./executeMirrorFunction");
45
- var _mirrorHorizontalPlacement = require("./mirrorHorizontalPlacement");
46
- var _mirrorPlacement = require("./mirrorPlacement");
47
- var _parsePlacement = require("./parsePlacement");
@@ -1,60 +0,0 @@
1
- "use strict";
2
-
3
- var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
4
- Object.defineProperty(exports, "__esModule", {
5
- value: true
6
- });
7
- exports.default = void 0;
8
- exports.mirrorHorizontalPlacement = mirrorHorizontalPlacement;
9
- var _PositionPropTypes = require("./PositionPropTypes");
10
- var _executeMirrorFunction = _interopRequireDefault(require("./executeMirrorFunction"));
11
- /*
12
- * The MIT License (MIT)
13
- *
14
- * Copyright (c) 2015 - present Instructure, Inc.
15
- *
16
- * Permission is hereby granted, free of charge, to any person obtaining a copy
17
- * of this software and associated documentation files (the "Software"), to deal
18
- * in the Software without restriction, including without limitation the rights
19
- * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
20
- * copies of the Software, and to permit persons to whom the Software is
21
- * furnished to do so, subject to the following conditions:
22
- *
23
- * The above copyright notice and this permission notice shall be included in all
24
- * copies or substantial portions of the Software.
25
- *
26
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
27
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
28
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
29
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
30
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
31
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
32
- * SOFTWARE.
33
- */
34
-
35
- /**
36
- * Given a string or array of one or two placement values, mirrors the placement
37
- * horizontally.
38
- *
39
- * Examples
40
- * ```js
41
- * mirrorHorizontalPlacement('top start') // input
42
- * ['top', 'end'] // output
43
- *
44
- * mirrorPlacement('top start', ' ') // input
45
- * 'top end' //output
46
- * ```
47
- *
48
- * @param {string|Array} placement - a string of the form '`<value>` `<value>`' or array [`<value>`, `<value>`]
49
- * @param {string} delimiter - when provided, a value with which the result array will be joined
50
- * @returns {string|Array} - an array of values or, if the delimiter was supplied, a string of
51
- * delimiter separated values
52
- */
53
- function mirrorHorizontalPlacement(placement, delimiter) {
54
- return (0, _executeMirrorFunction.default)(placement, (first, second) => {
55
- return [first, second].map(value => {
56
- return value === 'start' || value === 'end' ? _PositionPropTypes.mirrorMap[value] : value;
57
- });
58
- }, delimiter);
59
- }
60
- var _default = exports.default = mirrorHorizontalPlacement;