@ulu/frontend 0.0.5 → 0.0.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +19 -0
- package/README.md +1 -1
- package/js/deprecated/mini-collapsible.js +1 -1
- package/js/events/index.js +4 -1
- package/js/helpers/css-breakpoint.js +11 -13
- package/js/helpers/file-save.js +4 -0
- package/js/helpers/node-data-manager.js +4 -0
- package/js/helpers/pause-youtube-video.js +4 -0
- package/js/helpers/scrollbar-width-property.js +6 -2
- package/js/index.js +0 -2
- package/js/ui/flipcard.js +5 -1
- package/js/ui/grid.js +4 -0
- package/js/ui/modals.js +4 -1
- package/js/ui/overflow-scroller-pager.js +3 -0
- package/js/ui/overflow-scroller.js +4 -1
- package/js/ui/programmatic-modal.js +3 -0
- package/js/ui/resizer.js +3 -0
- package/js/ui/slider.js +7 -4
- package/js/ui/tabs.js +3 -0
- package/js/ui/tooltip.js +3 -0
- package/js/utils/logger.js +3 -0
- package/package.json +15 -4
- package/scss/_breakpoint.scss +3 -4
- package/scss/_button.scss +4 -4
- package/scss/_color.scss +2 -2
- package/scss/_layout.scss +2 -3
- package/scss/_typography.scss +2 -2
- package/scss/_utils.scss +21 -4
- package/scss/base/_normalize.scss +1 -1
- package/scss/helpers/_units.scss +6 -5
- package/js/polyfills/element-closest.js +0 -17
- package/js/utils/array.js +0 -28
- package/js/utils/dom.js +0 -122
- package/js/utils/object.js +0 -22
- package/js/utils/performance.js +0 -43
- package/js/utils/regex.js +0 -10
- package/js/utils/string.js +0 -107
- /package/js/{waypoints → deprecated/waypoints}/README.md +0 -0
- /package/js/{waypoints → deprecated/waypoints}/anchor-menu.js +0 -0
- /package/js/{waypoints → deprecated/waypoints}/element-waypoint.js +0 -0
- /package/js/{waypoints → deprecated/waypoints}/examples/page-link-menu.md +0 -0
- /package/js/{waypoints → deprecated/waypoints}/state-in-attribute.js +0 -0
package/CHANGELOG.md
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
# Change Log
|
|
2
|
+
|
|
3
|
+
## Version 0.0.6
|
|
4
|
+
|
|
5
|
+
### SCSS
|
|
6
|
+
|
|
7
|
+
- Added utils.map-merge($map, $changes, $mode)
|
|
8
|
+
- This will allow expansion if needed and is simpler for modules to implement
|
|
9
|
+
- This is to replace utils.map-merge-or-overwrite which is deprecated now
|
|
10
|
+
- Removed IE "*zoom" clearfix property as we don't support it and it causes errors in CSS minifiers since it's not standard CSS
|
|
11
|
+
|
|
12
|
+
### JS
|
|
13
|
+
|
|
14
|
+
- Add js docs
|
|
15
|
+
- Add specific exports for JS (ie. package "exports")
|
|
16
|
+
- All utils are moved to new independent module @ulu/utils and are implemented as submodules
|
|
17
|
+
- Since these can be used outside of frontend workflow
|
|
18
|
+
- Update imports to point to new module
|
|
19
|
+
- Move old waypoints code to deprecated, no longer needed with intersectionObserver
|
package/README.md
CHANGED
|
@@ -75,7 +75,7 @@
|
|
|
75
75
|
// - Add arrow key cycler from framework collapsible module
|
|
76
76
|
|
|
77
77
|
import maintain from 'ally.js/maintain/_maintain';
|
|
78
|
-
import { hasRequiredProps } from "
|
|
78
|
+
import { hasRequiredProps } from "@ulu/utils/object.js";
|
|
79
79
|
|
|
80
80
|
const requiredProps = ['selectorContainer', 'selectorToggle', 'selectorContent'];
|
|
81
81
|
const hasRequired = hasRequiredProps(requiredProps);
|
package/js/events/index.js
CHANGED
|
@@ -1,25 +1,21 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
// Version: 1.0.6
|
|
6
|
-
|
|
7
|
-
// Description: Pass breakpoints from CSS to stylesheet, use this to attach
|
|
8
|
-
// behaviors on breakpoints
|
|
1
|
+
/**
|
|
2
|
+
* @module helpers/css-breakpoint
|
|
3
|
+
*/
|
|
9
4
|
|
|
10
|
-
|
|
5
|
+
// Pass breakpoints from CSS to stylesheet, use this to attach behaviors on breakpoints
|
|
6
|
+
import { debounce } from "@ulu/utils/performance";
|
|
7
|
+
import { removeArrayElement } from "@ulu/utils/array";
|
|
11
8
|
import { getName } from "../events/index.js";
|
|
12
|
-
import { removeArrayElement } from "../utils/array";
|
|
13
9
|
import { log, logError } from "../utils/logger.js";
|
|
14
10
|
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
*/
|
|
11
|
+
|
|
12
|
+
// Resize Handler to update breakpoints for all instances (Called after resize finished)
|
|
18
13
|
window.addEventListener(getName("pageResized"), () => {
|
|
19
14
|
CssBreakpoints.instances.forEach(i => i.update());
|
|
20
15
|
});
|
|
21
16
|
|
|
22
17
|
/**
|
|
18
|
+
* @class
|
|
23
19
|
* Class that provides method for retrieving and acting on breakpoints passed
|
|
24
20
|
* from CSS (using element psuedo content prop)
|
|
25
21
|
*/
|
|
@@ -114,6 +110,7 @@ export class CssBreakpoints {
|
|
|
114
110
|
}
|
|
115
111
|
}
|
|
116
112
|
/**
|
|
113
|
+
* @class
|
|
117
114
|
* Used to handle a breakpoints direction's handler and state
|
|
118
115
|
*/
|
|
119
116
|
class BreakpointDirection {
|
|
@@ -182,6 +179,7 @@ class BreakpointDirection {
|
|
|
182
179
|
}
|
|
183
180
|
}
|
|
184
181
|
/**
|
|
182
|
+
* @class
|
|
185
183
|
* Single breakpoint management
|
|
186
184
|
*/
|
|
187
185
|
class Breakpoint {
|
package/js/helpers/file-save.js
CHANGED
|
@@ -1,10 +1,14 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @module helpers/scrollbar-width-property
|
|
3
|
+
*/
|
|
1
4
|
|
|
2
5
|
/**
|
|
3
6
|
* Sets a CSS custom property equal to the scrollbar width
|
|
4
7
|
* @param {Node} element The element that is the child of a scrollabel container
|
|
5
8
|
* @param {Node} container The container that can be scrolled
|
|
9
|
+
* @param {Stirng} propName Custom property to set
|
|
6
10
|
*/
|
|
7
|
-
export default function addScrollbarProperty(element = document.body, container = window) {
|
|
11
|
+
export default function addScrollbarProperty(element = document.body, container = window, propName = "--scrollbar-width") {
|
|
8
12
|
const scrollbarWidth = container.innerWidth - element.clientWidth;
|
|
9
|
-
element.style.setProperty(
|
|
13
|
+
element.style.setProperty(propName, `${ scrollbarWidth }px`);
|
|
10
14
|
}
|
package/js/index.js
CHANGED
|
@@ -8,8 +8,6 @@
|
|
|
8
8
|
// - Will not include things that aren't used in every site (those would need to
|
|
9
9
|
// imported manually
|
|
10
10
|
|
|
11
|
-
import "./polyfills/element-closest.js";
|
|
12
|
-
|
|
13
11
|
export { CssBreakpoints } from "./helpers/css-breakpoint.js";
|
|
14
12
|
export * as events from "./events/index.js";
|
|
15
13
|
export * as grid from "./ui/grid.js";
|
package/js/ui/flipcard.js
CHANGED
|
@@ -1,3 +1,7 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @module ui/flipcard
|
|
3
|
+
*/
|
|
4
|
+
|
|
1
5
|
// =============================================================================
|
|
2
6
|
// Flipcard
|
|
3
7
|
// =============================================================================
|
|
@@ -6,8 +10,8 @@
|
|
|
6
10
|
|
|
7
11
|
// Changes 1.0.1 | Added allow selection
|
|
8
12
|
|
|
13
|
+
import { trimWhitespace } from "@ulu/utils/string.js";
|
|
9
14
|
import { log, logError } from "../utils/logger.js";
|
|
10
|
-
import { trimWhitespace } from "../utils/string.js";
|
|
11
15
|
const debugMode = false; // Global dev debug
|
|
12
16
|
|
|
13
17
|
export class Flipcard {
|
package/js/ui/grid.js
CHANGED
package/js/ui/modals.js
CHANGED
|
@@ -1,3 +1,6 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @module ui/modals
|
|
3
|
+
*/
|
|
1
4
|
// Version: 1.0.4
|
|
2
5
|
// Changes:
|
|
3
6
|
// 1.0.4 | The modal library has a bug with multiple modals and using a custom close handler
|
|
@@ -14,7 +17,7 @@
|
|
|
14
17
|
// interface in the future we don't need to change/update markup.
|
|
15
18
|
import MicroModal from 'micromodal';
|
|
16
19
|
import Resizer from './resizer.js';
|
|
17
|
-
import { createElementFromHtml } from '
|
|
20
|
+
import { createElementFromHtml } from '@ulu/utils/dom.js';
|
|
18
21
|
import { pauseVideos, prepVideos } from '../helpers/pause-youtube-video.js';
|
|
19
22
|
const classes = {
|
|
20
23
|
open: 'site-modal--open',
|
|
@@ -1,3 +1,6 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @module ui/overflow-scroller
|
|
3
|
+
*/
|
|
1
4
|
/**
|
|
2
5
|
* @todo - Need to have scroll handler check scroll position
|
|
3
6
|
* @todo - Determine if controls should be visible
|
|
@@ -7,8 +10,8 @@
|
|
|
7
10
|
* @todo - Document that user could use something like [https://github.com/LachlanArthur/scroll-snap-api/tree/master/src] to have it go between items
|
|
8
11
|
*
|
|
9
12
|
*/
|
|
13
|
+
import { hasRequiredProps } from '@ulu/utils/object.js';
|
|
10
14
|
import { logError } from "../utils/logger.js";
|
|
11
|
-
import { hasRequiredProps } from '../utils/object.js';
|
|
12
15
|
const requiredElements = [
|
|
13
16
|
"track",
|
|
14
17
|
"controls"
|
package/js/ui/resizer.js
CHANGED
package/js/ui/slider.js
CHANGED
|
@@ -1,3 +1,6 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @module ui/slider
|
|
3
|
+
*/
|
|
1
4
|
// =============================================================================
|
|
2
5
|
// Slider
|
|
3
6
|
// =============================================================================
|
|
@@ -25,10 +28,10 @@
|
|
|
25
28
|
// * Will Change use
|
|
26
29
|
|
|
27
30
|
import maintain from 'ally.js/maintain/_maintain';
|
|
28
|
-
import { log, logError, logWarning } from "
|
|
29
|
-
import { hasRequiredProps } from '
|
|
30
|
-
import { trimWhitespace } from "
|
|
31
|
-
import { debounce } from "
|
|
31
|
+
import { log, logError, logWarning } from "@ulu/utils/logger.js";
|
|
32
|
+
import { hasRequiredProps } from '@ulu/utils/object.js';
|
|
33
|
+
import { trimWhitespace } from "@ulu/utils/string.js";
|
|
34
|
+
import { debounce } from "@ulu/utils/performance.js";
|
|
32
35
|
const debugMode = false; // Global dev debug
|
|
33
36
|
const reduceMotion = matchMedia('(prefers-reduced-motion: reduce)').matches;
|
|
34
37
|
const eventOnce = { once: true };
|
package/js/ui/tabs.js
CHANGED
package/js/ui/tooltip.js
CHANGED
package/js/utils/logger.js
CHANGED
package/package.json
CHANGED
|
@@ -1,15 +1,21 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ulu/frontend",
|
|
3
|
-
"version": "0.0.
|
|
4
|
-
"description": "
|
|
3
|
+
"version": "0.0.7",
|
|
4
|
+
"description": "Theming library",
|
|
5
5
|
"browser": "js/index.js",
|
|
6
6
|
"main": "index.js",
|
|
7
|
+
"exports": {
|
|
8
|
+
".": "./index.js",
|
|
9
|
+
"./js/*.js": "./js/*.js"
|
|
10
|
+
},
|
|
7
11
|
"type": "module",
|
|
8
12
|
"scripts": {
|
|
9
13
|
"docs:dev": "vitepress dev docs-src",
|
|
10
14
|
"docs:build": "vitepress build docs-src",
|
|
11
|
-
"docs:
|
|
12
|
-
"docs:
|
|
15
|
+
"docs:preview": "vitepress preview docs-src",
|
|
16
|
+
"docs:update:scss": "node ./docs-src/.vitepress/sassdoc.js",
|
|
17
|
+
"docs:update:scss:debug": "node --inspect-brk ./docs-src/.vitepress/sassdoc.js",
|
|
18
|
+
"docs:build:js": "node ./docs-src/.vitepress/jsdoc.js"
|
|
13
19
|
},
|
|
14
20
|
"repository": {
|
|
15
21
|
"type": "git",
|
|
@@ -31,8 +37,13 @@
|
|
|
31
37
|
},
|
|
32
38
|
"homepage": "https://github.com/Jscherbe/frontend#readme",
|
|
33
39
|
"devDependencies": {
|
|
40
|
+
"@ulu/utils": "^0.0.4",
|
|
34
41
|
"@ulu/vitepress-auto-menus": "^0.0.3",
|
|
35
42
|
"@ulu/vitepress-sassdoc": "^0.0.6",
|
|
43
|
+
"clean-jsdoc-theme": "^4.2.17",
|
|
44
|
+
"fs-extra": "^11.2.0",
|
|
45
|
+
"jsdoc": "^4.0.2",
|
|
46
|
+
"jsdoc-to-markdown": "^8.0.0",
|
|
36
47
|
"sass": "^1.51.0",
|
|
37
48
|
"vitepress": "^1.0.0-rc.27"
|
|
38
49
|
}
|
package/scss/_breakpoint.scss
CHANGED
|
@@ -59,11 +59,10 @@ $sizes: (
|
|
|
59
59
|
/// "jumbo" : 100em
|
|
60
60
|
/// ));
|
|
61
61
|
/// @param {Map} $changes A map to merge into the breakpoints map
|
|
62
|
-
/// @param {Map} $
|
|
63
|
-
/// @param {Map} $overwrite [false] Overwrite the sizes, instead of merging changes
|
|
62
|
+
/// @param {Map} $merge-mode [null] Merge stradegy see, utils.map-merge options
|
|
64
63
|
|
|
65
|
-
@mixin set-sizes($changes, $
|
|
66
|
-
$sizes: utils.map-merge
|
|
64
|
+
@mixin set-sizes($changes, $merge-mode: null) {
|
|
65
|
+
$sizes: utils.map-merge($sizes, $changes, $merge-mode) !global;
|
|
67
66
|
}
|
|
68
67
|
|
|
69
68
|
/// Get all breakpoint sizes (ie. $sizes)
|
package/scss/_button.scss
CHANGED
|
@@ -113,11 +113,11 @@ $styles: (
|
|
|
113
113
|
@return utils.function-fallback($name, $value, $-fallbacks);
|
|
114
114
|
}
|
|
115
115
|
|
|
116
|
-
@mixin set-styles($changes, $
|
|
117
|
-
$styles: utils.map-merge
|
|
116
|
+
@mixin set-styles($changes, $merge-mode: null) {
|
|
117
|
+
$styles: utils.map-merge($styles, $changes, $merge-mode) !global;
|
|
118
118
|
}
|
|
119
|
-
@mixin set-sizes($changes, $
|
|
120
|
-
$sizes: utils.map-merge
|
|
119
|
+
@mixin set-sizes($changes, $merge-mode: null) {
|
|
120
|
+
$sizes: utils.map-merge($sizes, $changes, $merge-mode) !global;
|
|
121
121
|
}
|
|
122
122
|
|
|
123
123
|
@mixin reset() {
|
package/scss/_color.scss
CHANGED
|
@@ -115,8 +115,8 @@ $color-classes: (
|
|
|
115
115
|
/// )
|
|
116
116
|
/// ), false, true);
|
|
117
117
|
|
|
118
|
-
@mixin set-contexts($changes, $
|
|
119
|
-
$contexts: utils.map-merge
|
|
118
|
+
@mixin set-contexts($changes, $merge-mode: null) {
|
|
119
|
+
$contexts: utils.map-merge($contexts, $changes, $merge-mode) !global;
|
|
120
120
|
}
|
|
121
121
|
|
|
122
122
|
/// Get a context by name
|
package/scss/_layout.scss
CHANGED
|
@@ -51,8 +51,8 @@ $containers: (
|
|
|
51
51
|
)
|
|
52
52
|
) !default;
|
|
53
53
|
|
|
54
|
-
@mixin set-containers($changes, $
|
|
55
|
-
$containers: utils.map-merge
|
|
54
|
+
@mixin set-containers($changes, $merge-mode: null) {
|
|
55
|
+
$containers: utils.map-merge($containers, $changes, $merge-mode) !global;
|
|
56
56
|
}
|
|
57
57
|
|
|
58
58
|
@function get-container($name, $breakpoint: false) {
|
|
@@ -189,7 +189,6 @@ $containers: (
|
|
|
189
189
|
&:after {
|
|
190
190
|
clear: both;
|
|
191
191
|
}
|
|
192
|
-
*zoom: 1;
|
|
193
192
|
}
|
|
194
193
|
|
|
195
194
|
/// Removes scrollbar with CSS
|
package/scss/_typography.scss
CHANGED
|
@@ -176,8 +176,8 @@ $sizes: (
|
|
|
176
176
|
/// "small" : 0.8rem
|
|
177
177
|
/// ));
|
|
178
178
|
|
|
179
|
-
@mixin set-sizes($changes, $
|
|
180
|
-
$sizes: utils.map-merge
|
|
179
|
+
@mixin set-sizes($changes, $merge-mode: null) {
|
|
180
|
+
$sizes: utils.map-merge($sizes, $changes, $merge-mode) !global;
|
|
181
181
|
}
|
|
182
182
|
|
|
183
183
|
/// Get a size's map
|
package/scss/_utils.scss
CHANGED
|
@@ -132,16 +132,33 @@ $config: (
|
|
|
132
132
|
}
|
|
133
133
|
}
|
|
134
134
|
|
|
135
|
+
/// Reusable merge method
|
|
136
|
+
/// @param {Map} $original Source map
|
|
137
|
+
/// @param {Map} $changes Changes to merge into source map
|
|
138
|
+
/// @param {String} $mode How to merge changes (merge [defualt], deep, or overwrite)
|
|
139
|
+
/// @return {Map} New map with changes
|
|
140
|
+
|
|
141
|
+
@function map-merge($original, $changes, $mode: null) {
|
|
142
|
+
@if ($mode == "deep") {
|
|
143
|
+
@return map.deep-merge($original, $changes);
|
|
144
|
+
} @else if ($mode == "overwrite") {
|
|
145
|
+
@return $changes;
|
|
146
|
+
} @else {
|
|
147
|
+
@return map.merge($original, $changes);
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
|
|
135
151
|
/// Repeatable pattern in core
|
|
152
|
+
/// @deprecated Left in for compatability, will be removed, use map-merge with mode
|
|
136
153
|
|
|
137
154
|
@function map-merge-or-overwrite($original, $changes, $deep: false, $overwrite: false) {
|
|
155
|
+
$mode: null;
|
|
138
156
|
@if $deep {
|
|
139
|
-
|
|
157
|
+
$mode: "deep";
|
|
140
158
|
} @else if $overwrite {
|
|
141
|
-
|
|
142
|
-
} @else {
|
|
143
|
-
@return map.merge($original, $changes);
|
|
159
|
+
$mode: "overwrite";
|
|
144
160
|
}
|
|
161
|
+
@return map-merge($original, $changes, $mode);
|
|
145
162
|
}
|
|
146
163
|
|
|
147
164
|
/// Utility for providing fallbacks, the first truthy value (non false or null) will be returned
|
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|
@use "../button";
|
|
7
7
|
|
|
8
8
|
|
|
9
|
-
/// Prints the normalize stylesheet.
|
|
9
|
+
/// Prints the normalize stylesheet. Originally based on modern-normalize 1.1.0
|
|
10
10
|
/// @link https://www.npmjs.com/package/modern-normalize Modern Normalize (NPM)
|
|
11
11
|
/// @example scss
|
|
12
12
|
/// @include ulu.base-normalize-styles();
|
package/scss/helpers/_units.scss
CHANGED
|
@@ -60,11 +60,12 @@ $config: (
|
|
|
60
60
|
#{ $prefix }-#{ $side } {
|
|
61
61
|
#{ $full-prop }: units.get(1);
|
|
62
62
|
}
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
}
|
|
63
|
+
// Duplicates utilities, unnessasary
|
|
64
|
+
// @if ($isMargin) {
|
|
65
|
+
// #{ $prefix }-#{ $side }-auto {
|
|
66
|
+
// #{ $full-prop }: auto;
|
|
67
|
+
// }
|
|
68
|
+
// }
|
|
68
69
|
@each $name, $value in units.$config {
|
|
69
70
|
#{ $prefix }-#{ $side }-#{ $name } {
|
|
70
71
|
#{ $full-prop }: units.get($name);
|
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
if (!Element.prototype.matches) {
|
|
2
|
-
Element.prototype.matches =
|
|
3
|
-
Element.prototype.msMatchesSelector ||
|
|
4
|
-
Element.prototype.webkitMatchesSelector;
|
|
5
|
-
}
|
|
6
|
-
|
|
7
|
-
if (!Element.prototype.closest) {
|
|
8
|
-
Element.prototype.closest = function(s) {
|
|
9
|
-
var el = this;
|
|
10
|
-
|
|
11
|
-
do {
|
|
12
|
-
if (Element.prototype.matches.call(el, s)) return el;
|
|
13
|
-
el = el.parentElement || el.parentNode;
|
|
14
|
-
} while (el !== null && el.nodeType === 1);
|
|
15
|
-
return null;
|
|
16
|
-
};
|
|
17
|
-
}
|
package/js/utils/array.js
DELETED
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Removes an array element (modifies array)
|
|
3
|
-
* @param {Array} array Array to remove element from
|
|
4
|
-
* @param {Element} element Array element to remove
|
|
5
|
-
*/
|
|
6
|
-
export function removeArrayElement(array, element) {
|
|
7
|
-
var index = array.indexOf(element);
|
|
8
|
-
if (index > -1) {
|
|
9
|
-
array.splice(index, 1);
|
|
10
|
-
}
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
/**
|
|
14
|
-
* Searches array for first item matching test, beginning at a start index but searching the entire array
|
|
15
|
-
* @param {Array} array Array to search
|
|
16
|
-
* @param {Number} start The index in the array to start the search from
|
|
17
|
-
* @param {Function} callback A test function that is passed array item and index
|
|
18
|
-
* - Credit: (James Waddington) https://stackoverflow.com/questions/28430348/how-to-loop-through-arrays-starting-at-different-index-while-still-looping-throu
|
|
19
|
-
*/
|
|
20
|
-
export function offsetFindIndexOf(array, start = 0, callback) {
|
|
21
|
-
let found, offset;
|
|
22
|
-
for (var i = 0; i < array.length; i++) {
|
|
23
|
-
offset = (i + start) % array.length;
|
|
24
|
-
found = callback(array[offset], offset);
|
|
25
|
-
if (found) return offset;
|
|
26
|
-
}
|
|
27
|
-
return -1;
|
|
28
|
-
}
|
package/js/utils/dom.js
DELETED
|
@@ -1,122 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Returns an array of direct descendants
|
|
3
|
-
* @param {Node} element
|
|
4
|
-
* @param {String} selector
|
|
5
|
-
* @return {Array}
|
|
6
|
-
*/
|
|
7
|
-
export function getDirectDescandants(element, selector) {
|
|
8
|
-
return [...element.children].filter(child => child.matches(selector));
|
|
9
|
-
};
|
|
10
|
-
|
|
11
|
-
/**
|
|
12
|
-
* Checks if element is overflown vertically
|
|
13
|
-
* @param {Node} element
|
|
14
|
-
* @return {Boolean}
|
|
15
|
-
*/
|
|
16
|
-
export function isOverflownY(element) {
|
|
17
|
-
return element.scrollHeight > element.clientHeight;
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
/**
|
|
21
|
-
* Checks if element is overflown both vertically and horizontally
|
|
22
|
-
* @param {Node} element
|
|
23
|
-
* @return {Boolean}
|
|
24
|
-
*/
|
|
25
|
-
export function isOverflown(element) {
|
|
26
|
-
return element.scrollHeight > element.clientHeight || element.scrollWidth > element.clientWidth;
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
/**
|
|
30
|
-
* For a given element return the first parent that has scrollable overflow
|
|
31
|
-
* - Helpful for debugging position sticky
|
|
32
|
-
* @param {Node} node Node to start search for first scrollable parent
|
|
33
|
-
* @returns {Node}
|
|
34
|
-
* @example
|
|
35
|
-
* const $navcontent = document.querySelector('.nav__content');
|
|
36
|
-
* if ($navcontent) {
|
|
37
|
-
* console.log(getScrollParent($navcontent));
|
|
38
|
-
* }
|
|
39
|
-
*/
|
|
40
|
-
export function getScrollParent(node) {
|
|
41
|
-
if (node == null) {
|
|
42
|
-
return null;
|
|
43
|
-
}
|
|
44
|
-
if (node.scrollHeight > node.clientHeight) {
|
|
45
|
-
return node;
|
|
46
|
-
} else {
|
|
47
|
-
return getScrollParent(node.parentNode);
|
|
48
|
-
}
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
/**
|
|
52
|
-
* Returns reliable document height
|
|
53
|
-
* @return {number}
|
|
54
|
-
*/
|
|
55
|
-
export function documentHeight() {
|
|
56
|
-
return Math.max(
|
|
57
|
-
document.body.scrollHeight, document.documentElement.scrollHeight,
|
|
58
|
-
document.body.offsetHeight, document.documentElement.offsetHeight,
|
|
59
|
-
document.body.clientHeight, document.documentElement.clientHeight
|
|
60
|
-
);
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
/**
|
|
64
|
-
* Returns reliable window height
|
|
65
|
-
* @return {number}
|
|
66
|
-
*/
|
|
67
|
-
export function windowHeight() {
|
|
68
|
-
return Math.max(document.documentElement.clientHeight, window.innerHeight || 0);
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
/**
|
|
72
|
-
* Returns reliable window width
|
|
73
|
-
* @return {number}
|
|
74
|
-
*/
|
|
75
|
-
export function windowWidth() {
|
|
76
|
-
return Math.max(document.documentElement.clientWidth, window.innerWidth || 0);
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
/**
|
|
80
|
-
* Check browser support for position: sticky
|
|
81
|
-
* - https://stackoverflow.com/questions/60214332/dynamically-detect-if-positionsticky-is-supported-by-the-browser
|
|
82
|
-
* @return {Boolean}
|
|
83
|
-
*/
|
|
84
|
-
export function browserWithPositionSticky() {
|
|
85
|
-
var prop = 'position:';
|
|
86
|
-
var value = 'sticky';
|
|
87
|
-
var prefixes = ' -webkit- -moz- -o- -ms- '.split(' ');
|
|
88
|
-
|
|
89
|
-
var el = document.createElement('a');
|
|
90
|
-
var mStyle = el.style;
|
|
91
|
-
mStyle.cssText = prop + prefixes.join(value + ';' + prop).slice(0, - prop.length);
|
|
92
|
-
|
|
93
|
-
return mStyle.position.indexOf(value) !== -1;
|
|
94
|
-
}
|
|
95
|
-
|
|
96
|
-
/**
|
|
97
|
-
* Returns Node List from HTML markup string
|
|
98
|
-
* @param {String} markup HTML markup to create into an element
|
|
99
|
-
*/
|
|
100
|
-
export function createElementFromHtml(markup) {
|
|
101
|
-
const doc = new DOMParser().parseFromString(markup, 'text/html');
|
|
102
|
-
return doc.body.firstElementChild;
|
|
103
|
-
}
|
|
104
|
-
|
|
105
|
-
/**
|
|
106
|
-
* Creates a new element with attributes and children
|
|
107
|
-
* @param {Object} config Configuration object
|
|
108
|
-
* @param {String} config.tag Node type (ie 'div')
|
|
109
|
-
* @param {Object} config.attributes Attributes to add to the new element
|
|
110
|
-
* @param {Array} config.children Array of children to append into the new element
|
|
111
|
-
*/
|
|
112
|
-
export function composeElement(config) { // tag, attributes = {}, children
|
|
113
|
-
const { tag, attributes, children } = config;
|
|
114
|
-
const element = document.createElement(tag);
|
|
115
|
-
if (attributes) {
|
|
116
|
-
Object.entries(attributes).forEach((a, v) => element.setAttribute(a, v));
|
|
117
|
-
}
|
|
118
|
-
if (children) {
|
|
119
|
-
children.forEach(c => element.appendChild(c));
|
|
120
|
-
}
|
|
121
|
-
return element;
|
|
122
|
-
}
|
package/js/utils/object.js
DELETED
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
// Version: 1.0.0
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* Checks object has required properties
|
|
5
|
-
* @param {array.string} required Array of properties to check for
|
|
6
|
-
* @return {function} Function for user to use to test for props passed on objects
|
|
7
|
-
* @example
|
|
8
|
-
* const testProps = hasRequiredProps(["name", "date"]);
|
|
9
|
-
* if (testProps(userConfiguration)) {
|
|
10
|
-
* // Stuff
|
|
11
|
-
* }
|
|
12
|
-
*/
|
|
13
|
-
export function hasRequiredProps(required) {
|
|
14
|
-
/**
|
|
15
|
-
* Function used for testing on user end
|
|
16
|
-
* @param {object} testObject Object to test on
|
|
17
|
-
* @return {Boolean}
|
|
18
|
-
*/
|
|
19
|
-
return function(object) {
|
|
20
|
-
return required.every(value => object.hasOwnProperty(value));
|
|
21
|
-
}
|
|
22
|
-
}
|
package/js/utils/performance.js
DELETED
|
@@ -1,43 +0,0 @@
|
|
|
1
|
-
// Version: 1.0.0
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* Returns a function, that, as long as it continues to be invoked, will not be triggered
|
|
5
|
-
* @param {Function} callback Function to invoke
|
|
6
|
-
* @param {Number} wait Amount of time after (milliseconds)
|
|
7
|
-
* @param {Boolean} immediate trigger the function on the leading edge, instead of the trailing.
|
|
8
|
-
* @param {Object} valueThis Context for function
|
|
9
|
-
* @author David Walsh
|
|
10
|
-
* - https://davidwalsh.name/javascript-debounce-function
|
|
11
|
-
*/
|
|
12
|
-
export function debounce(callback, wait, immediate, valueThis) {
|
|
13
|
-
var timeout;
|
|
14
|
-
return function executedFunction() {
|
|
15
|
-
var context = valueThis || this;
|
|
16
|
-
var args = arguments;
|
|
17
|
-
var later = function() {
|
|
18
|
-
timeout = null;
|
|
19
|
-
if (!immediate) callback.apply(context, args);
|
|
20
|
-
};
|
|
21
|
-
var callNow = immediate && !timeout;
|
|
22
|
-
clearTimeout(timeout);
|
|
23
|
-
timeout = setTimeout(later, wait);
|
|
24
|
-
if (callNow) callback.apply(context, args);
|
|
25
|
-
};
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
/**
|
|
29
|
-
* Debounces function using requestAnimationFrame()
|
|
30
|
-
* @param {Function} callback Function to invoke, cancelled if called faster than RAF
|
|
31
|
-
* @param {Object} context Optional context to bind to callback
|
|
32
|
-
*/
|
|
33
|
-
export function debounceAnimationFrame(callback, context = null) {
|
|
34
|
-
let tid;
|
|
35
|
-
return function debounced() {
|
|
36
|
-
const args = arguments;
|
|
37
|
-
if (tid) window.cancelAnimationFrame(tid);
|
|
38
|
-
tid = window.requestAnimationFrame(() => {
|
|
39
|
-
tid = false;
|
|
40
|
-
callback.apply(context, args);
|
|
41
|
-
});
|
|
42
|
-
};
|
|
43
|
-
}
|
package/js/utils/regex.js
DELETED
package/js/utils/string.js
DELETED
|
@@ -1,107 +0,0 @@
|
|
|
1
|
-
import { patterns } from "./regex.js";
|
|
2
|
-
/**
|
|
3
|
-
* Will return an object with the separation details
|
|
4
|
-
* @param {[type]} string [description]
|
|
5
|
-
* @return {object} keys: value, original, unit
|
|
6
|
-
*/
|
|
7
|
-
export function separateCssUnit(original) {
|
|
8
|
-
const pattern = /(px|vw|vh|%|em|rem)/i;
|
|
9
|
-
return {
|
|
10
|
-
original,
|
|
11
|
-
value: original.replace(pattern, ""),
|
|
12
|
-
unit: original.match(pattern)[0]
|
|
13
|
-
};
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
/**
|
|
17
|
-
* Removes HTML tags from string
|
|
18
|
-
* - Note you can use document.createElement and grab textContent (but this could execute code in browser)
|
|
19
|
-
* - The method below will just use regex without creating Nodes
|
|
20
|
-
* @param {String} html HTML string to find/replace
|
|
21
|
-
*/
|
|
22
|
-
export function stripTags(html) {
|
|
23
|
-
return html.replace(patterns.htmlTag, "");
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
/**
|
|
27
|
-
*
|
|
28
|
-
* @param {String} string String to trim
|
|
29
|
-
* @returns
|
|
30
|
-
*/
|
|
31
|
-
export function trimDoubleSpaces(string) {
|
|
32
|
-
return string.replace(patterns.multiSpace, "");
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
/**
|
|
36
|
-
* Remove line breaks
|
|
37
|
-
* @param {String} string String to trim
|
|
38
|
-
* @returns {String}
|
|
39
|
-
*/
|
|
40
|
-
export function trimLineBreaks(string) {
|
|
41
|
-
return string.replace(patterns.linebreaks, "");
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
/**
|
|
45
|
-
* Designed originally to flatten style definitions
|
|
46
|
-
* @param {String} string String to trim
|
|
47
|
-
* @returns {String}
|
|
48
|
-
*/
|
|
49
|
-
export function trimWhitespace(string) {
|
|
50
|
-
return string.replace(patterns.linebreaks, "")
|
|
51
|
-
.replace(patterns.multiSpace, " ")
|
|
52
|
-
.trim();
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
/**
|
|
56
|
-
* Truncates string with ellipsis if over the max, note use framework function
|
|
57
|
-
* if you need to know the effects of the truncate process (returns an object
|
|
58
|
-
* with info instead) this function only modifies the string
|
|
59
|
-
* @param {string} string String to possibly truncate
|
|
60
|
-
* @param {number} max How many characters max?
|
|
61
|
-
* @return {string}
|
|
62
|
-
*/
|
|
63
|
-
export function truncate(string, max, overflowChar = '…') {
|
|
64
|
-
return string.length <= max ? string : string.slice(0, max) + overflowChar;
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
/**
|
|
68
|
-
* Replaces non safe characters with "-"
|
|
69
|
-
* - Does not escape characters
|
|
70
|
-
* - Used for id's and classnames or things that can't have anything but normal a-z 0-9
|
|
71
|
-
*/
|
|
72
|
-
export function urlize(string) {
|
|
73
|
-
var newString;
|
|
74
|
-
string = string.replace(/^[^-_a-zA-Z]+/, '').replace(/^-(?:[-0-9]+)/, '-');
|
|
75
|
-
newString = string && string.replace(/[^-_a-zA-Z0-9]+/g, '-');
|
|
76
|
-
return newString;
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
/**
|
|
80
|
-
* Converts date to abbreviated month date ie "Mar 7, 2018"
|
|
81
|
-
* @param {String|Date} str Date or date string (passed through date constructor)
|
|
82
|
-
* @return {String} Pretty date string
|
|
83
|
-
*/
|
|
84
|
-
export function prettyDate(str) {
|
|
85
|
-
const date = new Date(str);
|
|
86
|
-
const months = ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'];
|
|
87
|
-
return `${ months[date.getMonth()] } ${ date.getDate() }, ${ date.getFullYear() }`;
|
|
88
|
-
}
|
|
89
|
-
|
|
90
|
-
/**
|
|
91
|
-
* Generates a random string of defined length based on
|
|
92
|
-
* a string of allowed characters.
|
|
93
|
-
*
|
|
94
|
-
* @param {number} length How many random characters will be in the returned string. Defaults to 10
|
|
95
|
-
* @param {string} allowed Which characters can be used when creating the random string. Defaults to A-Z,a-z,0-9
|
|
96
|
-
* @return {string} A string of random characters
|
|
97
|
-
*/
|
|
98
|
-
export function randomString(
|
|
99
|
-
length = 10,
|
|
100
|
-
allowed = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789'
|
|
101
|
-
) {
|
|
102
|
-
let result = '';
|
|
103
|
-
for (let i = 0; i < length; i++) {
|
|
104
|
-
result += allowed.charAt(Math.floor(Math.random() * allowed.length));
|
|
105
|
-
}
|
|
106
|
-
return result;
|
|
107
|
-
}
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|