@symbo.ls/scratch 2.10.266 → 2.10.272

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/dist/cjs/index.js CHANGED
@@ -1652,11 +1652,15 @@ var applySequenceVars = (props, mediaName, options = {}) => {
1652
1652
  // src/utils/sprite.js
1653
1653
  var import_utils7 = __toESM(require_cjs3(), 1);
1654
1654
  var generateSprite = (icons) => {
1655
- let sprite = '<svg aria-hidden="true" width="0" height="0" style="position:absolute">';
1655
+ const CONFIG2 = getActiveConfig();
1656
+ let sprite = "";
1656
1657
  for (const key in icons) {
1658
+ if (CONFIG2.__svg_cache[key])
1659
+ continue;
1660
+ else
1661
+ CONFIG2.__svg_cache[key] = true;
1657
1662
  sprite += icons[key];
1658
1663
  }
1659
- sprite += "</svg>";
1660
1664
  return sprite;
1661
1665
  };
1662
1666
  var parseRootAttributes = (htmlString) => {
@@ -1684,8 +1688,8 @@ var convertSvgToSymbol = (key, code) => {
1684
1688
  "<svg",
1685
1689
  `<symbol id="${key}" xmlns="${xmlns}" viewBox="${viewBox}"`
1686
1690
  );
1687
- symbol = symbol.replace(/width="[^"]*/, "");
1688
- symbol = symbol.replace(/height="[^"]*/, "");
1691
+ symbol = symbol.replace(/width="[^"]*"/, "");
1692
+ symbol = symbol.replace(/height="[^"]*"/, "");
1689
1693
  symbol = symbol.replace("</svg", "</symbol");
1690
1694
  return symbol;
1691
1695
  };
@@ -2336,18 +2340,10 @@ var setSVG = (val, key) => {
2336
2340
  };
2337
2341
  var appendSVGSprite = (LIBRARY, options = DEF_OPTIONS) => {
2338
2342
  const CONFIG2 = getActiveConfig();
2339
- const doc = options.document || import_globals2.document;
2340
2343
  const lib = Object.keys(LIBRARY).length ? {} : CONFIG2.SVG;
2341
2344
  for (const key in LIBRARY)
2342
2345
  lib[key] = CONFIG2.SVG[key];
2343
- const SVGsprite = generateSprite(lib);
2344
- if (!doc) {
2345
- console.warn("To append SVG sprites it should be run in browser environment");
2346
- return SVGsprite;
2347
- }
2348
- const svgSpriteDOM = doc.createElement("template");
2349
- svgSpriteDOM.innerHTML = SVGsprite;
2350
- doc.body.appendChild(svgSpriteDOM.content);
2346
+ appendSVG(lib, options);
2351
2347
  };
2352
2348
  var setIcon = (val, key) => {
2353
2349
  const CONFIG2 = getActiveConfig();
@@ -2358,18 +2354,42 @@ var setIcon = (val, key) => {
2358
2354
  };
2359
2355
  var appendIconsSprite = (LIBRARY, options = DEF_OPTIONS) => {
2360
2356
  const CONFIG2 = getActiveConfig();
2361
- const doc = options.document || import_globals2.document;
2362
2357
  const lib = Object.keys(LIBRARY).length ? {} : CONFIG2.ICONS;
2363
2358
  for (const key in LIBRARY)
2364
2359
  lib[key] = CONFIG2.ICONS[key];
2365
- const SVGsprite = generateSprite(lib);
2360
+ appendSVG(lib, options);
2361
+ };
2362
+ var createSVGSpriteElement = (options = { isRoot: true }) => {
2363
+ const svgElem = import_globals2.document.createElementNS("http://www.w3.org/2000/svg", "svg");
2364
+ if (options.isRoot) {
2365
+ svgElem.setAttribute("aria-hidden", "true");
2366
+ svgElem.setAttribute("width", "0");
2367
+ svgElem.setAttribute("height", "0");
2368
+ svgElem.setAttribute("style", "position:absolute");
2369
+ svgElem.setAttribute("id", "svgSprite");
2370
+ }
2371
+ return svgElem;
2372
+ };
2373
+ var appendSVG = (lib, options = DEF_OPTIONS) => {
2374
+ const CONFIG2 = getActiveConfig();
2375
+ const doc = options.document || import_globals2.document;
2366
2376
  if (!doc) {
2367
- console.warn("To append SVG Icon sprites it should be run in browser environment");
2368
- return SVGsprite;
2377
+ if (CONFIG2.verbose) {
2378
+ console.warn("To append SVG sprites it should be run in browser environment");
2379
+ }
2380
+ return generateSprite(lib);
2381
+ }
2382
+ const exists = doc.querySelector("#svgSprite");
2383
+ const SVGsprite = generateSprite(lib);
2384
+ if (exists) {
2385
+ const tempSVG = createSVGSpriteElement({ isRoot: false });
2386
+ tempSVG.innerHTML = SVGsprite;
2387
+ exists.append(...tempSVG.children);
2388
+ } else {
2389
+ const svgSpriteDOM = createSVGSpriteElement();
2390
+ svgSpriteDOM.innerHTML = SVGsprite;
2391
+ doc.body.prepend(svgSpriteDOM);
2369
2392
  }
2370
- const iconsSpriteDOM = doc.createElement("template");
2371
- iconsSpriteDOM.innerHTML = SVGsprite;
2372
- doc.body.appendChild(iconsSpriteDOM.content);
2373
2393
  };
2374
2394
 
2375
2395
  // src/system/reset.js
@@ -2613,6 +2633,8 @@ var set = (recivedConfig, options = SET_OPTIONS) => {
2613
2633
  CONFIG2.globalTheme = globalTheme;
2614
2634
  if (CONFIG2.verbose)
2615
2635
  console.log(CONFIG2);
2636
+ if (!CONFIG2.__svg_cache)
2637
+ CONFIG2.__svg_cache = {};
2616
2638
  const keys = Object.keys(config);
2617
2639
  keys.map((key) => setEach(key, config[key]));
2618
2640
  applyTypographySequence();
package/dist/cjs/set.js CHANGED
@@ -1380,8 +1380,8 @@ var convertSvgToSymbol = (key, code) => {
1380
1380
  "<svg",
1381
1381
  `<symbol id="${key}" xmlns="${xmlns}" viewBox="${viewBox}"`
1382
1382
  );
1383
- symbol = symbol.replace(/width="[^"]*/, "");
1384
- symbol = symbol.replace(/height="[^"]*/, "");
1383
+ symbol = symbol.replace(/width="[^"]*"/, "");
1384
+ symbol = symbol.replace(/height="[^"]*"/, "");
1385
1385
  symbol = symbol.replace("</svg", "</symbol");
1386
1386
  return symbol;
1387
1387
  };
@@ -2009,6 +2009,8 @@ var set = (recivedConfig, options = SET_OPTIONS) => {
2009
2009
  CONFIG2.globalTheme = globalTheme;
2010
2010
  if (CONFIG2.verbose)
2011
2011
  console.log(CONFIG2);
2012
+ if (!CONFIG2.__svg_cache)
2013
+ CONFIG2.__svg_cache = {};
2012
2014
  const keys = Object.keys(config);
2013
2015
  keys.map((key) => setEach(key, config[key]));
2014
2016
  applyTypographySequence();
@@ -1439,11 +1439,15 @@ var applySequenceVars = (props, mediaName, options = {}) => {
1439
1439
  // src/utils/sprite.js
1440
1440
  var import_utils7 = __toESM(require_cjs3(), 1);
1441
1441
  var generateSprite = (icons) => {
1442
- let sprite = '<svg aria-hidden="true" width="0" height="0" style="position:absolute">';
1442
+ const CONFIG2 = getActiveConfig();
1443
+ let sprite = "";
1443
1444
  for (const key in icons) {
1445
+ if (CONFIG2.__svg_cache[key])
1446
+ continue;
1447
+ else
1448
+ CONFIG2.__svg_cache[key] = true;
1444
1449
  sprite += icons[key];
1445
1450
  }
1446
- sprite += "</svg>";
1447
1451
  return sprite;
1448
1452
  };
1449
1453
  var parseRootAttributes = (htmlString) => {
@@ -1471,8 +1475,8 @@ var convertSvgToSymbol = (key, code) => {
1471
1475
  "<svg",
1472
1476
  `<symbol id="${key}" xmlns="${xmlns}" viewBox="${viewBox}"`
1473
1477
  );
1474
- symbol = symbol.replace(/width="[^"]*/, "");
1475
- symbol = symbol.replace(/height="[^"]*/, "");
1478
+ symbol = symbol.replace(/width="[^"]*"/, "");
1479
+ symbol = symbol.replace(/height="[^"]*"/, "");
1476
1480
  symbol = symbol.replace("</svg", "</symbol");
1477
1481
  return symbol;
1478
1482
  };
@@ -2090,18 +2094,10 @@ var setSVG = (val, key) => {
2090
2094
  };
2091
2095
  var appendSVGSprite = (LIBRARY, options = DEF_OPTIONS) => {
2092
2096
  const CONFIG2 = getActiveConfig();
2093
- const doc = options.document || import_globals2.document;
2094
2097
  const lib = Object.keys(LIBRARY).length ? {} : CONFIG2.SVG;
2095
2098
  for (const key in LIBRARY)
2096
2099
  lib[key] = CONFIG2.SVG[key];
2097
- const SVGsprite = generateSprite(lib);
2098
- if (!doc) {
2099
- console.warn("To append SVG sprites it should be run in browser environment");
2100
- return SVGsprite;
2101
- }
2102
- const svgSpriteDOM = doc.createElement("template");
2103
- svgSpriteDOM.innerHTML = SVGsprite;
2104
- doc.body.appendChild(svgSpriteDOM.content);
2100
+ appendSVG(lib, options);
2105
2101
  };
2106
2102
  var setIcon = (val, key) => {
2107
2103
  const CONFIG2 = getActiveConfig();
@@ -2112,18 +2108,42 @@ var setIcon = (val, key) => {
2112
2108
  };
2113
2109
  var appendIconsSprite = (LIBRARY, options = DEF_OPTIONS) => {
2114
2110
  const CONFIG2 = getActiveConfig();
2115
- const doc = options.document || import_globals2.document;
2116
2111
  const lib = Object.keys(LIBRARY).length ? {} : CONFIG2.ICONS;
2117
2112
  for (const key in LIBRARY)
2118
2113
  lib[key] = CONFIG2.ICONS[key];
2119
- const SVGsprite = generateSprite(lib);
2114
+ appendSVG(lib, options);
2115
+ };
2116
+ var createSVGSpriteElement = (options = { isRoot: true }) => {
2117
+ const svgElem = import_globals2.document.createElementNS("http://www.w3.org/2000/svg", "svg");
2118
+ if (options.isRoot) {
2119
+ svgElem.setAttribute("aria-hidden", "true");
2120
+ svgElem.setAttribute("width", "0");
2121
+ svgElem.setAttribute("height", "0");
2122
+ svgElem.setAttribute("style", "position:absolute");
2123
+ svgElem.setAttribute("id", "svgSprite");
2124
+ }
2125
+ return svgElem;
2126
+ };
2127
+ var appendSVG = (lib, options = DEF_OPTIONS) => {
2128
+ const CONFIG2 = getActiveConfig();
2129
+ const doc = options.document || import_globals2.document;
2120
2130
  if (!doc) {
2121
- console.warn("To append SVG Icon sprites it should be run in browser environment");
2122
- return SVGsprite;
2131
+ if (CONFIG2.verbose) {
2132
+ console.warn("To append SVG sprites it should be run in browser environment");
2133
+ }
2134
+ return generateSprite(lib);
2135
+ }
2136
+ const exists = doc.querySelector("#svgSprite");
2137
+ const SVGsprite = generateSprite(lib);
2138
+ if (exists) {
2139
+ const tempSVG = createSVGSpriteElement({ isRoot: false });
2140
+ tempSVG.innerHTML = SVGsprite;
2141
+ exists.append(...tempSVG.children);
2142
+ } else {
2143
+ const svgSpriteDOM = createSVGSpriteElement();
2144
+ svgSpriteDOM.innerHTML = SVGsprite;
2145
+ doc.body.prepend(svgSpriteDOM);
2123
2146
  }
2124
- const iconsSpriteDOM = doc.createElement("template");
2125
- iconsSpriteDOM.innerHTML = SVGsprite;
2126
- doc.body.appendChild(iconsSpriteDOM.content);
2127
2147
  };
2128
2148
 
2129
2149
  // src/system/reset.js
@@ -1100,11 +1100,15 @@ var import_utils6 = __toESM(require_cjs3(), 1);
1100
1100
  // src/utils/sprite.js
1101
1101
  var import_utils7 = __toESM(require_cjs3(), 1);
1102
1102
  var generateSprite = (icons) => {
1103
- let sprite = '<svg aria-hidden="true" width="0" height="0" style="position:absolute">';
1103
+ const CONFIG2 = getActiveConfig();
1104
+ let sprite = "";
1104
1105
  for (const key in icons) {
1106
+ if (CONFIG2.__svg_cache[key])
1107
+ continue;
1108
+ else
1109
+ CONFIG2.__svg_cache[key] = true;
1105
1110
  sprite += icons[key];
1106
1111
  }
1107
- sprite += "</svg>";
1108
1112
  return sprite;
1109
1113
  };
1110
1114
  var parseRootAttributes = (htmlString) => {
@@ -1132,8 +1136,8 @@ var convertSvgToSymbol = (key, code) => {
1132
1136
  "<svg",
1133
1137
  `<symbol id="${key}" xmlns="${xmlns}" viewBox="${viewBox}"`
1134
1138
  );
1135
- symbol = symbol.replace(/width="[^"]*/, "");
1136
- symbol = symbol.replace(/height="[^"]*/, "");
1139
+ symbol = symbol.replace(/width="[^"]*"/, "");
1140
+ symbol = symbol.replace(/height="[^"]*"/, "");
1137
1141
  symbol = symbol.replace("</svg", "</symbol");
1138
1142
  return symbol;
1139
1143
  };
@@ -1156,18 +1160,10 @@ var setSVG = (val, key) => {
1156
1160
  };
1157
1161
  var appendSVGSprite = (LIBRARY, options = DEF_OPTIONS) => {
1158
1162
  const CONFIG2 = getActiveConfig();
1159
- const doc = options.document || import_globals2.document;
1160
1163
  const lib = Object.keys(LIBRARY).length ? {} : CONFIG2.SVG;
1161
1164
  for (const key in LIBRARY)
1162
1165
  lib[key] = CONFIG2.SVG[key];
1163
- const SVGsprite = generateSprite(lib);
1164
- if (!doc) {
1165
- console.warn("To append SVG sprites it should be run in browser environment");
1166
- return SVGsprite;
1167
- }
1168
- const svgSpriteDOM = doc.createElement("template");
1169
- svgSpriteDOM.innerHTML = SVGsprite;
1170
- doc.body.appendChild(svgSpriteDOM.content);
1166
+ appendSVG(lib, options);
1171
1167
  };
1172
1168
  var setIcon = (val, key) => {
1173
1169
  const CONFIG2 = getActiveConfig();
@@ -1178,16 +1174,40 @@ var setIcon = (val, key) => {
1178
1174
  };
1179
1175
  var appendIconsSprite = (LIBRARY, options = DEF_OPTIONS) => {
1180
1176
  const CONFIG2 = getActiveConfig();
1181
- const doc = options.document || import_globals2.document;
1182
1177
  const lib = Object.keys(LIBRARY).length ? {} : CONFIG2.ICONS;
1183
1178
  for (const key in LIBRARY)
1184
1179
  lib[key] = CONFIG2.ICONS[key];
1185
- const SVGsprite = generateSprite(lib);
1180
+ appendSVG(lib, options);
1181
+ };
1182
+ var createSVGSpriteElement = (options = { isRoot: true }) => {
1183
+ const svgElem = import_globals2.document.createElementNS("http://www.w3.org/2000/svg", "svg");
1184
+ if (options.isRoot) {
1185
+ svgElem.setAttribute("aria-hidden", "true");
1186
+ svgElem.setAttribute("width", "0");
1187
+ svgElem.setAttribute("height", "0");
1188
+ svgElem.setAttribute("style", "position:absolute");
1189
+ svgElem.setAttribute("id", "svgSprite");
1190
+ }
1191
+ return svgElem;
1192
+ };
1193
+ var appendSVG = (lib, options = DEF_OPTIONS) => {
1194
+ const CONFIG2 = getActiveConfig();
1195
+ const doc = options.document || import_globals2.document;
1186
1196
  if (!doc) {
1187
- console.warn("To append SVG Icon sprites it should be run in browser environment");
1188
- return SVGsprite;
1197
+ if (CONFIG2.verbose) {
1198
+ console.warn("To append SVG sprites it should be run in browser environment");
1199
+ }
1200
+ return generateSprite(lib);
1201
+ }
1202
+ const exists = doc.querySelector("#svgSprite");
1203
+ const SVGsprite = generateSprite(lib);
1204
+ if (exists) {
1205
+ const tempSVG = createSVGSpriteElement({ isRoot: false });
1206
+ tempSVG.innerHTML = SVGsprite;
1207
+ exists.append(...tempSVG.children);
1208
+ } else {
1209
+ const svgSpriteDOM = createSVGSpriteElement();
1210
+ svgSpriteDOM.innerHTML = SVGsprite;
1211
+ doc.body.prepend(svgSpriteDOM);
1189
1212
  }
1190
- const iconsSpriteDOM = doc.createElement("template");
1191
- iconsSpriteDOM.innerHTML = SVGsprite;
1192
- doc.body.appendChild(iconsSpriteDOM.content);
1193
1213
  };
@@ -1517,11 +1517,15 @@ var applySequenceVars = (props, mediaName, options = {}) => {
1517
1517
  // src/utils/sprite.js
1518
1518
  var import_utils7 = __toESM(require_cjs3(), 1);
1519
1519
  var generateSprite = (icons) => {
1520
- let sprite = '<svg aria-hidden="true" width="0" height="0" style="position:absolute">';
1520
+ const CONFIG2 = getActiveConfig();
1521
+ let sprite = "";
1521
1522
  for (const key in icons) {
1523
+ if (CONFIG2.__svg_cache[key])
1524
+ continue;
1525
+ else
1526
+ CONFIG2.__svg_cache[key] = true;
1522
1527
  sprite += icons[key];
1523
1528
  }
1524
- sprite += "</svg>";
1525
1529
  return sprite;
1526
1530
  };
1527
1531
  var parseRootAttributes = (htmlString) => {
@@ -1549,8 +1553,8 @@ var convertSvgToSymbol = (key, code) => {
1549
1553
  "<svg",
1550
1554
  `<symbol id="${key}" xmlns="${xmlns}" viewBox="${viewBox}"`
1551
1555
  );
1552
- symbol = symbol.replace(/width="[^"]*/, "");
1553
- symbol = symbol.replace(/height="[^"]*/, "");
1556
+ symbol = symbol.replace(/width="[^"]*"/, "");
1557
+ symbol = symbol.replace(/height="[^"]*"/, "");
1554
1558
  symbol = symbol.replace("</svg", "</symbol");
1555
1559
  return symbol;
1556
1560
  };
@@ -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
  };
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.266",
5
+ "version": "2.10.272",
6
6
  "files": [
7
7
  "src",
8
8
  "dist"
@@ -17,7 +17,7 @@
17
17
  "source": "src/index.js",
18
18
  "publishConfig": {},
19
19
  "scripts": {
20
- "copy:package:cjs": "cp ../../.build/package-cjs.json dist/cjs/package.json",
20
+ "copy:package:cjs": "cp ../../build/package-cjs.json dist/cjs/package.json",
21
21
  "build:esm": "npx esbuild ./src/*.js ./src/**/*.js --target=es2020 --format=esm --outdir=dist/esm",
22
22
  "build:cjs": "npx esbuild ./src/*.js ./src/**/*.js --target=node16 --format=cjs --outdir=dist/cjs --bundle",
23
23
  "build:iife": "npx esbuild ./src/index.js --target=es2020 --format=iife --outdir=dist/iife --bundle --minify",
@@ -32,5 +32,5 @@
32
32
  "peerDependencies": {
33
33
  "@emotion/css": "^11.5.0"
34
34
  },
35
- "gitHead": "e153db0a5e05e4655b5093d694b09fc1e8c4ec0b"
35
+ "gitHead": "297618a17a7a449fb3af9aca3b1e638769f888a7"
36
36
  }
package/src/set.js CHANGED
@@ -107,6 +107,8 @@ export const set = (recivedConfig, options = SET_OPTIONS) => {
107
107
  if (globalTheme !== undefined) CONFIG.globalTheme = globalTheme
108
108
  if (CONFIG.verbose) console.log(CONFIG)
109
109
 
110
+ if (!CONFIG.__svg_cache) CONFIG.__svg_cache = {}
111
+
110
112
  const keys = Object.keys(config)
111
113
  keys.map(key => setEach(key, config[key]))
112
114
 
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
  }