mirror of
https://github.com/danbulant/dribbblish-dynamic-theme
synced 2026-06-14 20:21:03 +00:00
use loadsh.defaultsDeep to deep merge options
This commit is contained in:
parent
305d70fb6d
commit
ee98ffd134
4 changed files with 25 additions and 17 deletions
|
|
@ -20,6 +20,8 @@
|
||||||
"chroma-js": "^2.1.2",
|
"chroma-js": "^2.1.2",
|
||||||
"colorthief": "^2.3.2",
|
"colorthief": "^2.3.2",
|
||||||
"jquery": "^3.6.0",
|
"jquery": "^3.6.0",
|
||||||
|
"lodash.debounce": "^4.0.8",
|
||||||
|
"lodash.defaultsdeep": "^4.6.1",
|
||||||
"markdown-it": "^12.2.0",
|
"markdown-it": "^12.2.0",
|
||||||
"markdown-it-attrs": "^4.1.0",
|
"markdown-it-attrs": "^4.1.0",
|
||||||
"moment": "^2.29.1",
|
"moment": "^2.29.1",
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
import $ from "jquery";
|
import $ from "jquery";
|
||||||
|
|
||||||
import { renderMD } from "./Util";
|
import { renderMD, defaults } from "./Util";
|
||||||
import { icons } from "./Icons";
|
import { icons } from "./Icons";
|
||||||
|
|
||||||
export default class ConfigMenu {
|
export default class ConfigMenu {
|
||||||
|
|
@ -125,7 +125,7 @@ export default class ConfigMenu {
|
||||||
parent: null
|
parent: null
|
||||||
};
|
};
|
||||||
// Set Defaults
|
// Set Defaults
|
||||||
options = { ...defaultOptions, ...options };
|
options = defaults(options, defaultOptions);
|
||||||
if (typeof options.area == "string") options.area = { name: options.area, order: 0 };
|
if (typeof options.area == "string") options.area = { name: options.area, order: 0 };
|
||||||
options.description = options.description
|
options.description = options.description
|
||||||
.split("\n")
|
.split("\n")
|
||||||
|
|
|
||||||
|
|
@ -1,3 +1,4 @@
|
||||||
|
import { defaults } from "./Util";
|
||||||
import { parseSync as parseSVG, stringify as stringifySVG } from "svgson";
|
import { parseSync as parseSVG, stringify as stringifySVG } from "svgson";
|
||||||
|
|
||||||
export default class Icons {
|
export default class Icons {
|
||||||
|
|
@ -73,7 +74,7 @@ export default class Icons {
|
||||||
fill: "currentColor",
|
fill: "currentColor",
|
||||||
base64: false
|
base64: false
|
||||||
};
|
};
|
||||||
options = { ...defaultOptions, ...options };
|
options = defaults(options, defaultOptions);
|
||||||
|
|
||||||
const svg = parseSVG(this.getRawSVG(name, options.style));
|
const svg = parseSVG(this.getRawSVG(name, options.style));
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,7 @@
|
||||||
import MarkdownIt from "markdown-it";
|
import MarkdownIt from "markdown-it";
|
||||||
import MarkdownItAttrs from "markdown-it-attrs";
|
import MarkdownItAttrs from "markdown-it-attrs";
|
||||||
|
import defaultsDeep from "lodash.defaultsdeep";
|
||||||
|
import { default as _debounce } from "lodash.debounce";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @callback waitForElCb
|
* @callback waitForElCb
|
||||||
|
|
@ -69,22 +71,25 @@ export function getRandomInt(min, max) {
|
||||||
return Math.floor(Math.random() * (max - min + 1)) + min;
|
return Math.floor(Math.random() * (max - min + 1)) + min;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @template T
|
||||||
|
* @param {T[]} arr
|
||||||
|
* @returns {T}
|
||||||
|
*/
|
||||||
export function randomFromArray(arr) {
|
export function randomFromArray(arr) {
|
||||||
return arr[Math.floor(Math.random() * arr.length)];
|
return arr[Math.floor(Math.random() * arr.length)];
|
||||||
}
|
}
|
||||||
|
|
||||||
export function debounce(func, wait, immediate) {
|
/** @type {_debounce} */
|
||||||
var timeout;
|
export function debounce(fn, wait, opts) {
|
||||||
return function () {
|
return _debounce(fn, wait, opts);
|
||||||
var context = this,
|
}
|
||||||
args = arguments;
|
|
||||||
var later = function () {
|
/**
|
||||||
timeout = null;
|
* @param {Object} options
|
||||||
if (!immediate) func.apply(context, args);
|
* @param {...Object} defaults
|
||||||
};
|
* @returns {Object}
|
||||||
var callNow = immediate && !timeout;
|
*/
|
||||||
clearTimeout(timeout);
|
export function defaults(options, ...defaults) {
|
||||||
timeout = setTimeout(later, wait);
|
return defaultsDeep(options, ...defaults);
|
||||||
if (callNow) func.apply(context, args);
|
|
||||||
};
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue