@symbo.ls/scratch 2.10.261 → 2.10.271

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.
@@ -280,14 +280,14 @@ var require_types = __commonJS({
280
280
  is: () => is,
281
281
  isArray: () => isArray,
282
282
  isBoolean: () => isBoolean,
283
- isDefined: () => isDefined,
283
+ isDefined: () => isDefined2,
284
284
  isFunction: () => isFunction,
285
285
  isHtmlElement: () => isHtmlElement,
286
286
  isNode: () => isNode,
287
287
  isNot: () => isNot,
288
288
  isNull: () => isNull,
289
289
  isNumber: () => isNumber,
290
- isObject: () => isObject,
290
+ isObject: () => isObject2,
291
291
  isObjectLike: () => isObjectLike,
292
292
  isString: () => isString2,
293
293
  isUndefined: () => isUndefined,
@@ -297,7 +297,7 @@ var require_types = __commonJS({
297
297
  var import_globals = require_cjs();
298
298
  var import_tags = require_cjs2();
299
299
  var isValidHtmlTag = (arg) => import_tags.HTML_TAGS.body.indexOf(arg);
300
- var isObject = (arg) => {
300
+ var isObject2 = (arg) => {
301
301
  if (arg === null)
302
302
  return false;
303
303
  return typeof arg === "object" && arg.constructor === Object;
@@ -319,8 +319,8 @@ var require_types = __commonJS({
319
319
  var isHtmlElement = (obj) => {
320
320
  return typeof import_globals.window.HTMLElement === "object" ? obj instanceof import_globals.window.HTMLElement : obj && typeof obj === "object" && obj !== null && obj.nodeType === 1 && typeof obj.nodeName === "string";
321
321
  };
322
- var isDefined = (arg) => {
323
- return isObject(arg) || isObjectLike(arg) || isString2(arg) || isNumber(arg) || isFunction(arg) || isArray(arg) || isObjectLike(arg) || isBoolean(arg) || isNull(arg);
322
+ var isDefined2 = (arg) => {
323
+ return isObject2(arg) || isObjectLike(arg) || isString2(arg) || isNumber(arg) || isFunction(arg) || isArray(arg) || isObjectLike(arg) || isBoolean(arg) || isNull(arg);
324
324
  };
325
325
  var isUndefined = (arg) => {
326
326
  return arg === void 0;
@@ -328,7 +328,7 @@ var require_types = __commonJS({
328
328
  var TYPES = {
329
329
  boolean: isBoolean,
330
330
  array: isArray,
331
- object: isObject,
331
+ object: isObject2,
332
332
  string: isString2,
333
333
  number: isNumber,
334
334
  null: isNull,
@@ -336,7 +336,7 @@ var require_types = __commonJS({
336
336
  objectLike: isObjectLike,
337
337
  node: isNode,
338
338
  htmlElement: isHtmlElement,
339
- defined: isDefined
339
+ defined: isDefined2
340
340
  };
341
341
  var is = (arg) => {
342
342
  return (...args) => {
@@ -375,10 +375,10 @@ var require_object = __commonJS({
375
375
  var object_exports = {};
376
376
  __export2(object_exports, {
377
377
  clone: () => clone,
378
- deepClone: () => deepClone,
378
+ deepClone: () => deepClone2,
379
379
  deepCloneExclude: () => deepCloneExclude,
380
380
  deepDestringify: () => deepDestringify,
381
- deepMerge: () => deepMerge,
381
+ deepMerge: () => deepMerge2,
382
382
  deepStringify: () => deepStringify,
383
383
  detachFunctionsFromObject: () => detachFunctionsFromObject,
384
384
  diff: () => diff,
@@ -423,7 +423,7 @@ var require_object = __commonJS({
423
423
  }
424
424
  return element;
425
425
  };
426
- var deepMerge = (element, extend) => {
426
+ var deepMerge2 = (element, extend) => {
427
427
  for (const e in extend) {
428
428
  const extendProp = extend[e];
429
429
  if (e === "parent" || e === "props")
@@ -431,7 +431,7 @@ var require_object = __commonJS({
431
431
  if (element[e] === void 0) {
432
432
  element[e] = extendProp;
433
433
  } else if ((0, import_types.isObjectLike)(element[e]) && (0, import_types.isObjectLike)(extendProp)) {
434
- deepMerge(element[e], extendProp);
434
+ deepMerge2(element[e], extendProp);
435
435
  } else {
436
436
  element[e] = extendProp;
437
437
  }
@@ -469,11 +469,11 @@ var require_object = __commonJS({
469
469
  return o;
470
470
  };
471
471
  var mergeArrayExclude = (arr, excl = []) => {
472
- return arr.reduce((acc, curr) => deepMerge(acc, deepCloneExclude(curr, excl)), {});
472
+ return arr.reduce((acc, curr) => deepMerge2(acc, deepCloneExclude(curr, excl)), {});
473
473
  };
474
- var deepClone = (obj) => {
474
+ var deepClone2 = (obj) => {
475
475
  if ((0, import_types.isArray)(obj)) {
476
- return obj.map(deepClone);
476
+ return obj.map(deepClone2);
477
477
  }
478
478
  const o = {};
479
479
  for (const prop in obj) {
@@ -482,9 +482,9 @@ var require_object = __commonJS({
482
482
  objProp = mergeArray(objProp);
483
483
  }
484
484
  if ((0, import_types.isArray)(objProp)) {
485
- o[prop] = objProp.map((v) => (0, import_types.isObject)(v) ? deepClone(v) : v);
485
+ o[prop] = objProp.map((v) => (0, import_types.isObject)(v) ? deepClone2(v) : v);
486
486
  } else if ((0, import_types.isObject)(objProp)) {
487
- o[prop] = deepClone(objProp);
487
+ o[prop] = deepClone2(objProp);
488
488
  } else
489
489
  o[prop] = objProp;
490
490
  }
@@ -642,14 +642,14 @@ var require_object = __commonJS({
642
642
  };
643
643
  var mergeIfExisted = (a, b) => {
644
644
  if ((0, import_types.isObjectLike)(a) && (0, import_types.isObjectLike)(b))
645
- return deepMerge(a, b);
645
+ return deepMerge2(a, b);
646
646
  return a || b;
647
647
  };
648
648
  var mergeArray = (arr) => {
649
- return arr.reduce((a, c) => deepMerge(a, deepClone(c)), {});
649
+ return arr.reduce((a, c) => deepMerge2(a, deepClone2(c)), {});
650
650
  };
651
651
  var mergeAndCloneIfArray = (obj) => {
652
- return (0, import_types.isArray)(obj) ? mergeArray(obj) : deepClone(obj);
652
+ return (0, import_types.isArray)(obj) ? mergeArray(obj) : deepClone2(obj);
653
653
  };
654
654
  var flattenRecursive = (param, prop, stack = []) => {
655
655
  const objectized = mergeAndCloneIfArray(param);
@@ -860,17 +860,241 @@ __export(sprite_exports, {
860
860
  generateSprite: () => generateSprite
861
861
  });
862
862
  module.exports = __toCommonJS(sprite_exports);
863
+ var import_utils2 = __toESM(require_cjs3(), 1);
864
+
865
+ // src/factory.js
863
866
  var import_utils = __toESM(require_cjs3(), 1);
867
+
868
+ // src/defaultConfig/index.js
869
+ var defaultConfig_exports = {};
870
+ __export(defaultConfig_exports, {
871
+ ANIMATION: () => ANIMATION,
872
+ BREAKPOINTS: () => BREAKPOINTS,
873
+ CASES: () => CASES,
874
+ COLOR: () => COLOR,
875
+ DEVICES: () => DEVICES,
876
+ DOCUMENT: () => DOCUMENT,
877
+ FONT: () => FONT,
878
+ FONT_FACE: () => FONT_FACE,
879
+ FONT_FAMILY: () => FONT_FAMILY,
880
+ FONT_FAMILY_TYPES: () => FONT_FAMILY_TYPES,
881
+ GRADIENT: () => GRADIENT,
882
+ ICONS: () => ICONS,
883
+ MEDIA: () => MEDIA,
884
+ RESET: () => RESET,
885
+ SEQUENCE: () => SEQUENCE,
886
+ SPACING: () => SPACING,
887
+ SVG: () => SVG,
888
+ SVG_DATA: () => SVG_DATA,
889
+ THEME: () => THEME,
890
+ TIMING: () => TIMING,
891
+ TYPOGRAPHY: () => TYPOGRAPHY,
892
+ UNIT: () => UNIT
893
+ });
894
+
895
+ // src/defaultConfig/sequence.js
896
+ var SEQUENCE = {
897
+ "minor-second": 1.067,
898
+ "major-second": 1.125,
899
+ "minor-third": 1.2,
900
+ "major-third": 1.25,
901
+ "perfect-fourth": 1.333,
902
+ "augmented-fourth": 1.414,
903
+ "perfect-fifth": 1.5,
904
+ "minor-sixth": 1.6,
905
+ phi: 1.618,
906
+ // golden-ratio
907
+ "major-sixth": 1.667,
908
+ "square-root-3": 1.732,
909
+ // theodorus
910
+ "minor-seventh": 1.778,
911
+ "major-seventh": 1.875,
912
+ octave: 2,
913
+ "square-root-5": 2.23,
914
+ // pythagoras
915
+ "major-tenth": 2.5,
916
+ "major-eleventh": 2.667,
917
+ "major-twelfth": 3,
918
+ pi: 3.14,
919
+ // archimedes
920
+ "double-octave": 4
921
+ };
922
+
923
+ // src/defaultConfig/unit.js
924
+ var UNIT = {
925
+ default: "em"
926
+ };
927
+
928
+ // src/defaultConfig/typography.js
929
+ var defaultProps = {
930
+ browserDefault: 16,
931
+ base: 16,
932
+ type: "font-size",
933
+ ratio: SEQUENCE["minor-third"],
934
+ range: [-3, 12],
935
+ h1Matches: 6,
936
+ lineHeight: 1.5,
937
+ unit: "em",
938
+ templates: {},
939
+ sequence: {},
940
+ scales: {},
941
+ vars: {}
942
+ };
943
+ var TYPOGRAPHY = defaultProps;
944
+
945
+ // src/defaultConfig/font.js
946
+ var FONT = {};
947
+
948
+ // src/defaultConfig/font-family.js
949
+ var FONT_FAMILY = {};
950
+ var FONT_FAMILY_TYPES = {
951
+ "sans-serif": "Helvetica, Arial, sans-serif, --system-default",
952
+ serif: "Times New Roman, Georgia, serif, --system-default",
953
+ monospace: "Courier New, monospace, --system-default"
954
+ };
955
+ var FONT_FACE = {};
956
+
957
+ // src/defaultConfig/media.js
958
+ var MEDIA = {
959
+ tv: "(min-width: 2780px)",
960
+ screenL: "(max-width: 1920px)",
961
+ "screenL<": "(min-width: 1920px)",
962
+ screenM: "(max-width: 1680px)",
963
+ "screenM<": "(min-width: 1680px)",
964
+ screenS: "(max-width: 1440px)",
965
+ "screenS<": "(min-width: 1440px)",
966
+ tabletL: "(max-width: 1366px)",
967
+ "tabletL<": "(min-width: 1366px)",
968
+ tabletM: "(max-width: 1280px)",
969
+ "tabletM<": "(min-width: 1280px)",
970
+ tabletS: "(max-width: 1024px)",
971
+ "tabletS<": "(min-width: 1024px)",
972
+ mobileL: "(max-width: 768px)",
973
+ "mobileL<": "(min-width: 768px)",
974
+ mobileM: "(max-width: 560px)",
975
+ "mobileM<": "(min-width: 560px)",
976
+ mobileS: "(max-width: 480px)",
977
+ "mobileS<": "(min-width: 480px)",
978
+ mobileXS: "(max-width: 375px)",
979
+ "mobileXS<": "(min-width: 375px)",
980
+ light: "(prefers-color-scheme: light)",
981
+ dark: "(prefers-color-scheme: dark)",
982
+ print: "print"
983
+ };
984
+
985
+ // src/defaultConfig/spacing.js
986
+ var defaultProps2 = {
987
+ base: TYPOGRAPHY.base,
988
+ type: "spacing",
989
+ ratio: SEQUENCE.phi,
990
+ range: [-5, 15],
991
+ subSequence: true,
992
+ unit: "em",
993
+ sequence: {},
994
+ scales: {},
995
+ vars: {}
996
+ };
997
+ var SPACING = defaultProps2;
998
+
999
+ // src/defaultConfig/color.js
1000
+ var COLOR = {};
1001
+ var GRADIENT = {};
1002
+
1003
+ // src/defaultConfig/theme.js
1004
+ var THEME = {};
1005
+
1006
+ // src/defaultConfig/icons.js
1007
+ var ICONS = {};
1008
+
1009
+ // src/defaultConfig/timing.js
1010
+ var defaultProps3 = {
1011
+ default: 150,
1012
+ base: 150,
1013
+ type: "timing",
1014
+ ratio: SEQUENCE["perfect-fourth"],
1015
+ range: [-3, 12],
1016
+ unit: "ms",
1017
+ sequence: {},
1018
+ scales: {},
1019
+ vars: {}
1020
+ };
1021
+ var TIMING = defaultProps3;
1022
+
1023
+ // src/defaultConfig/document.js
1024
+ var DOCUMENT = {};
1025
+
1026
+ // src/defaultConfig/responsive.js
1027
+ var BREAKPOINTS = {
1028
+ screenL: 1920,
1029
+ screenM: 1680,
1030
+ screenS: 1440,
1031
+ tabletL: 1366,
1032
+ tabletM: 1280,
1033
+ tabletS: 1024,
1034
+ mobileL: 768,
1035
+ mobileM: 560,
1036
+ mobileS: 480,
1037
+ mobileXS: 375
1038
+ };
1039
+ var DEVICES = {
1040
+ screenL: [1920, 1024],
1041
+ screenM: [1680, 1024],
1042
+ screenS: [1440, 978],
1043
+ tabletL: [1366, 926],
1044
+ tabletM: [1280, 768],
1045
+ tabletS: [1024, 768],
1046
+ mobileL: [768, 375],
1047
+ mobileM: [560, 768],
1048
+ mobileS: [480, 768],
1049
+ mobileXS: [375, 768]
1050
+ };
1051
+
1052
+ // src/defaultConfig/cases.js
1053
+ var CASES = {};
1054
+
1055
+ // src/defaultConfig/animation.js
1056
+ var ANIMATION = {};
1057
+
1058
+ // src/defaultConfig/svg.js
1059
+ var SVG = {};
1060
+ var SVG_DATA = {};
1061
+
1062
+ // src/defaultConfig/index.js
1063
+ var RESET = {};
1064
+
1065
+ // src/factory.js
1066
+ var CSS_VARS = {};
1067
+ var CONFIG = {
1068
+ verbose: false,
1069
+ useVariable: true,
1070
+ useReset: true,
1071
+ CSS_VARS,
1072
+ ...defaultConfig_exports
1073
+ };
1074
+ var cachedConfig = (0, import_utils.deepClone)(CONFIG);
1075
+ var FACTORY = {
1076
+ active: "0",
1077
+ 0: CONFIG
1078
+ };
1079
+ var getActiveConfig = (def) => {
1080
+ return FACTORY[def || FACTORY.active];
1081
+ };
1082
+
1083
+ // src/utils/sprite.js
864
1084
  var generateSprite = (icons) => {
865
- let sprite = '<svg aria-hidden="true" width="0" height="0" style="position:absolute">';
1085
+ const CONFIG2 = getActiveConfig();
1086
+ let sprite = "";
866
1087
  for (const key in icons) {
1088
+ if (CONFIG2.__svg_cache[key])
1089
+ continue;
1090
+ else
1091
+ CONFIG2.__svg_cache[key] = true;
867
1092
  sprite += icons[key];
868
1093
  }
869
- sprite += "</svg>";
870
1094
  return sprite;
871
1095
  };
872
1096
  var parseRootAttributes = (htmlString) => {
873
- if (!(0, import_utils.isString)(htmlString)) {
1097
+ if (!(0, import_utils2.isString)(htmlString)) {
874
1098
  return console.warn(`parseRootAttributes: ${htmlString} is not a string`);
875
1099
  }
876
1100
  const match = htmlString.match(/<svg\s+(.*?)>/);
@@ -894,8 +1118,8 @@ var convertSvgToSymbol = (key, code) => {
894
1118
  "<svg",
895
1119
  `<symbol id="${key}" xmlns="${xmlns}" viewBox="${viewBox}"`
896
1120
  );
897
- symbol = symbol.replace(/width="[^"]*/, "");
898
- symbol = symbol.replace(/height="[^"]*/, "");
1121
+ symbol = symbol.replace(/width="[^"]*"/, "");
1122
+ symbol = symbol.replace(/height="[^"]*"/, "");
899
1123
  symbol = symbol.replace("</svg", "</symbol");
900
1124
  return symbol;
901
1125
  };
@@ -287,7 +287,7 @@ var require_types = __commonJS({
287
287
  isNot: () => isNot,
288
288
  isNull: () => isNull,
289
289
  isNumber: () => isNumber,
290
- isObject: () => isObject,
290
+ isObject: () => isObject2,
291
291
  isObjectLike: () => isObjectLike2,
292
292
  isString: () => isString,
293
293
  isUndefined: () => isUndefined,
@@ -297,7 +297,7 @@ var require_types = __commonJS({
297
297
  var import_globals = require_cjs();
298
298
  var import_tags = require_cjs2();
299
299
  var isValidHtmlTag = (arg) => import_tags.HTML_TAGS.body.indexOf(arg);
300
- var isObject = (arg) => {
300
+ var isObject2 = (arg) => {
301
301
  if (arg === null)
302
302
  return false;
303
303
  return typeof arg === "object" && arg.constructor === Object;
@@ -320,7 +320,7 @@ var require_types = __commonJS({
320
320
  return typeof import_globals.window.HTMLElement === "object" ? obj instanceof import_globals.window.HTMLElement : obj && typeof obj === "object" && obj !== null && obj.nodeType === 1 && typeof obj.nodeName === "string";
321
321
  };
322
322
  var isDefined2 = (arg) => {
323
- return isObject(arg) || isObjectLike2(arg) || isString(arg) || isNumber(arg) || isFunction(arg) || isArray(arg) || isObjectLike2(arg) || isBoolean(arg) || isNull(arg);
323
+ return isObject2(arg) || isObjectLike2(arg) || isString(arg) || isNumber(arg) || isFunction(arg) || isArray(arg) || isObjectLike2(arg) || isBoolean(arg) || isNull(arg);
324
324
  };
325
325
  var isUndefined = (arg) => {
326
326
  return arg === void 0;
@@ -328,7 +328,7 @@ var require_types = __commonJS({
328
328
  var TYPES = {
329
329
  boolean: isBoolean,
330
330
  array: isArray,
331
- object: isObject,
331
+ object: isObject2,
332
332
  string: isString,
333
333
  number: isNumber,
334
334
  null: isNull,
@@ -378,7 +378,7 @@ var require_object = __commonJS({
378
378
  deepClone: () => deepClone2,
379
379
  deepCloneExclude: () => deepCloneExclude,
380
380
  deepDestringify: () => deepDestringify,
381
- deepMerge: () => deepMerge,
381
+ deepMerge: () => deepMerge2,
382
382
  deepStringify: () => deepStringify,
383
383
  detachFunctionsFromObject: () => detachFunctionsFromObject,
384
384
  diff: () => diff,
@@ -423,7 +423,7 @@ var require_object = __commonJS({
423
423
  }
424
424
  return element;
425
425
  };
426
- var deepMerge = (element, extend) => {
426
+ var deepMerge2 = (element, extend) => {
427
427
  for (const e in extend) {
428
428
  const extendProp = extend[e];
429
429
  if (e === "parent" || e === "props")
@@ -431,7 +431,7 @@ var require_object = __commonJS({
431
431
  if (element[e] === void 0) {
432
432
  element[e] = extendProp;
433
433
  } else if ((0, import_types.isObjectLike)(element[e]) && (0, import_types.isObjectLike)(extendProp)) {
434
- deepMerge(element[e], extendProp);
434
+ deepMerge2(element[e], extendProp);
435
435
  } else {
436
436
  element[e] = extendProp;
437
437
  }
@@ -469,7 +469,7 @@ var require_object = __commonJS({
469
469
  return o;
470
470
  };
471
471
  var mergeArrayExclude = (arr, excl = []) => {
472
- return arr.reduce((acc, curr) => deepMerge(acc, deepCloneExclude(curr, excl)), {});
472
+ return arr.reduce((acc, curr) => deepMerge2(acc, deepCloneExclude(curr, excl)), {});
473
473
  };
474
474
  var deepClone2 = (obj) => {
475
475
  if ((0, import_types.isArray)(obj)) {
@@ -642,11 +642,11 @@ var require_object = __commonJS({
642
642
  };
643
643
  var mergeIfExisted = (a, b) => {
644
644
  if ((0, import_types.isObjectLike)(a) && (0, import_types.isObjectLike)(b))
645
- return deepMerge(a, b);
645
+ return deepMerge2(a, b);
646
646
  return a || b;
647
647
  };
648
648
  var mergeArray = (arr) => {
649
- return arr.reduce((a, c) => deepMerge(a, deepClone2(c)), {});
649
+ return arr.reduce((a, c) => deepMerge2(a, deepClone2(c)), {});
650
650
  };
651
651
  var mergeAndCloneIfArray = (obj) => {
652
652
  return (0, import_types.isArray)(obj) ? mergeArray(obj) : deepClone2(obj);
@@ -1076,10 +1076,6 @@ var FACTORY = {
1076
1076
  0: CONFIG
1077
1077
  };
1078
1078
  var getActiveConfig = (def) => {
1079
- if ((0, import_utils.isDefined)(def) && !FACTORY[def]) {
1080
- FACTORY[def] = (0, import_utils.deepClone)(cachedConfig);
1081
- return FACTORY[def];
1082
- }
1083
1079
  return FACTORY[def || FACTORY.active];
1084
1080
  };
1085
1081
 
package/package.json CHANGED
@@ -2,7 +2,7 @@
2
2
  "name": "@symbo.ls/scratch",
3
3
  "description": "Φ / CSS framework and methodology.",
4
4
  "author": "symbo.ls",
5
- "version": "2.10.261",
5
+ "version": "2.10.271",
6
6
  "files": [
7
7
  "src",
8
8
  "dist"
@@ -32,5 +32,5 @@
32
32
  "peerDependencies": {
33
33
  "@emotion/css": "^11.5.0"
34
34
  },
35
- "gitHead": "39a07b63363c6c6547fe25b904fc3e713ee84284"
35
+ "gitHead": "cb6c3e1938e3e65f85daf51f2d74d46fee36ae93"
36
36
  }
package/src/factory.js CHANGED
@@ -1,6 +1,11 @@
1
1
  'use strict'
2
2
 
3
- import { deepClone, isDefined } from '@domql/utils'
3
+ import {
4
+ deepClone,
5
+ deepMerge,
6
+ isDefined,
7
+ isObject
8
+ } from '@domql/utils'
4
9
  import * as CONF from './defaultConfig'
5
10
 
6
11
  export const CSS_VARS = {}
@@ -25,14 +30,12 @@ export const activateConfig = (def) => {
25
30
  }
26
31
 
27
32
  export const getActiveConfig = (def) => {
28
- if (isDefined(def) && !FACTORY[def]) {
29
- FACTORY[def] = deepClone(cachedConfig)
30
- return FACTORY[def]
31
- }
32
33
  return FACTORY[def || FACTORY.active]
33
34
  }
34
35
 
35
- export const setActiveConfig = (def) => {
36
- FACTORY.active = FACTORY[def]
37
- return FACTORY.active
36
+ export const setActiveConfig = (newConfig) => {
37
+ if (!isObject(newConfig)) return
38
+ FACTORY.active = '1'
39
+ FACTORY['1'] = deepMerge(newConfig, deepClone(cachedConfig))
40
+ return newConfig
38
41
  }
package/src/set.js CHANGED
@@ -1,6 +1,6 @@
1
1
  'use strict'
2
2
 
3
- import { FACTORY, getActiveConfig } from './factory.js' // eslint-disable-line no-unused-vars
3
+ import { FACTORY, getActiveConfig, setActiveConfig } from './factory.js' // eslint-disable-line no-unused-vars
4
4
  import {
5
5
  setColor,
6
6
  setGradient,
@@ -94,8 +94,7 @@ export const set = (recivedConfig, options = SET_OPTIONS) => {
94
94
  } = recivedConfig
95
95
 
96
96
  if (options.newConfig) {
97
- FACTORY.active = options.newConfig
98
- CONFIG = getActiveConfig(options.newConfig)
97
+ CONFIG = setActiveConfig(options.newConfig)
99
98
  }
100
99
 
101
100
  if (verbose !== undefined) CONFIG.verbose = verbose
@@ -108,6 +107,8 @@ export const set = (recivedConfig, options = SET_OPTIONS) => {
108
107
  if (globalTheme !== undefined) CONFIG.globalTheme = globalTheme
109
108
  if (CONFIG.verbose) console.log(CONFIG)
110
109
 
110
+ if (!CONFIG.__svg_cache) CONFIG.__svg_cache = {}
111
+
111
112
  const keys = Object.keys(config)
112
113
  keys.map(key => setEach(key, config[key]))
113
114
 
@@ -13,7 +13,7 @@ export const applyReset = (reset = {}) => {
13
13
  const configTemplates = TYPOGRAPHY.templates
14
14
 
15
15
  configReset.body = {
16
- ...getMediaTheme('document', `@${CONFIG.globalTheme}`),
16
+ ...(CONFIG.useDocumentTheme ? getMediaTheme('document', `@${CONFIG.globalTheme}`) : {}),
17
17
  ...configTemplates.body
18
18
  }
19
19
  configReset.h1 = configTemplates.h1
package/src/system/svg.js CHANGED
@@ -21,20 +21,11 @@ export const setSVG = (val, key) => {
21
21
 
22
22
  export const appendSVGSprite = (LIBRARY, options = DEF_OPTIONS) => {
23
23
  const CONFIG = getActiveConfig()
24
- const doc = options.document || document
25
24
 
26
25
  const lib = Object.keys(LIBRARY).length ? {} : CONFIG.SVG
27
26
  for (const key in LIBRARY) lib[key] = CONFIG.SVG[key]
28
27
 
29
- const SVGsprite = generateSprite(lib)
30
- if (!doc) {
31
- console.warn('To append SVG sprites it should be run in browser environment')
32
- return SVGsprite
33
- }
34
-
35
- const svgSpriteDOM = doc.createElement('template')
36
- svgSpriteDOM.innerHTML = SVGsprite
37
- doc.body.appendChild(svgSpriteDOM.content)
28
+ appendSVG(lib, options)
38
29
  }
39
30
 
40
31
  export const setIcon = (val, key) => {
@@ -46,18 +37,47 @@ export const setIcon = (val, key) => {
46
37
 
47
38
  export const appendIconsSprite = (LIBRARY, options = DEF_OPTIONS) => {
48
39
  const CONFIG = getActiveConfig()
49
- const doc = options.document || document
50
40
 
51
41
  const lib = Object.keys(LIBRARY).length ? {} : CONFIG.ICONS
52
42
  for (const key in LIBRARY) lib[key] = CONFIG.ICONS[key]
53
43
 
54
- const SVGsprite = generateSprite(lib)
44
+ appendSVG(lib, options)
45
+ }
46
+
47
+ const createSVGSpriteElement = (options = { isRoot: true }) => {
48
+ const svgElem = document.createElementNS('http://www.w3.org/2000/svg', 'svg')
49
+ if (options.isRoot) {
50
+ svgElem.setAttribute('aria-hidden', 'true')
51
+ svgElem.setAttribute('width', '0')
52
+ svgElem.setAttribute('height', '0')
53
+ svgElem.setAttribute('style', 'position:absolute')
54
+ svgElem.setAttribute('id', 'svgSprite')
55
+ }
56
+ return svgElem
57
+ }
58
+
59
+ const appendSVG = (lib, options = DEF_OPTIONS) => {
60
+ const CONFIG = getActiveConfig()
61
+ const doc = options.document || document
62
+
55
63
  if (!doc) {
56
- console.warn('To append SVG Icon sprites it should be run in browser environment')
57
- return SVGsprite
64
+ if (CONFIG.verbose) {
65
+ console.warn('To append SVG sprites it should be run in browser environment')
66
+ }
67
+ return generateSprite(lib)
58
68
  }
59
69
 
60
- const iconsSpriteDOM = doc.createElement('template')
61
- iconsSpriteDOM.innerHTML = SVGsprite
62
- doc.body.appendChild(iconsSpriteDOM.content)
70
+ const exists = doc.querySelector('#svgSprite')
71
+ const SVGsprite = generateSprite(lib)
72
+
73
+ if (exists) {
74
+ const tempSVG = createSVGSpriteElement({ isRoot: false })
75
+ // const svgSpriteWithoutRoot = doc.createElement('template')
76
+ tempSVG.innerHTML = SVGsprite
77
+ exists.append(...tempSVG.children)
78
+ } else {
79
+ const svgSpriteDOM = createSVGSpriteElement()
80
+ svgSpriteDOM.innerHTML = SVGsprite
81
+ doc.body.prepend(svgSpriteDOM)
82
+ }
63
83
  }
@@ -1,17 +1,19 @@
1
1
  'use strict'
2
2
 
3
3
  import { isString } from '@domql/utils'
4
+ import { getActiveConfig } from '../factory'
4
5
 
5
6
  export const generateSprite = (icons) => {
6
- let sprite =
7
- '<svg aria-hidden="true" width="0" height="0" style="position:absolute">'
7
+ const CONFIG = getActiveConfig()
8
+
9
+ let sprite = ''
8
10
 
9
11
  for (const key in icons) {
12
+ if (CONFIG.__svg_cache[key]) continue
13
+ else CONFIG.__svg_cache[key] = true
10
14
  sprite += icons[key]
11
15
  }
12
16
 
13
- sprite += '</svg>'
14
-
15
17
  return sprite
16
18
  }
17
19
 
@@ -44,8 +46,8 @@ export const convertSvgToSymbol = (key, code) => {
44
46
  let symbol = code.replace('<svg',
45
47
  `<symbol id="${key}" xmlns="${xmlns}" viewBox="${viewBox}"`
46
48
  )
47
- symbol = symbol.replace(/width="[^"]*/, '')
48
- symbol = symbol.replace(/height="[^"]*/, '')
49
+ symbol = symbol.replace(/width="[^"]*"/, '')
50
+ symbol = symbol.replace(/height="[^"]*"/, '')
49
51
  symbol = symbol.replace('</svg', '</symbol')
50
52
  return symbol
51
53
  }