@symbo.ls/scratch 2.11.226 → 2.11.228

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.
@@ -90,6 +90,7 @@ var defaultProps = {
90
90
  h1Matches: 6,
91
91
  lineHeight: 1.5,
92
92
  subSequence: true,
93
+ mediaRegenerate: false,
93
94
  unit: "em",
94
95
  templates: {},
95
96
  sequence: {},
@@ -145,6 +146,7 @@ var defaultProps2 = {
145
146
  ratio: SEQUENCE.phi,
146
147
  range: [-5, 15],
147
148
  subSequence: true,
149
+ mediaRegenerate: false,
148
150
  unit: "em",
149
151
  sequence: {},
150
152
  scales: {},
@@ -172,6 +174,7 @@ var defaultProps3 = {
172
174
  type: "timing",
173
175
  ratio: SEQUENCE["perfect-fourth"],
174
176
  range: [-3, 12],
177
+ mediaRegenerate: false,
175
178
  unit: "ms",
176
179
  sequence: {},
177
180
  scales: {},
@@ -62,6 +62,7 @@ var defaultProps = {
62
62
  h1Matches: 6,
63
63
  lineHeight: 1.5,
64
64
  subSequence: true,
65
+ mediaRegenerate: false,
65
66
  unit: "em",
66
67
  templates: {},
67
68
  sequence: {},
@@ -77,6 +78,7 @@ var defaultProps2 = {
77
78
  ratio: SEQUENCE.phi,
78
79
  range: [-5, 15],
79
80
  subSequence: true,
81
+ mediaRegenerate: false,
80
82
  unit: "em",
81
83
  sequence: {},
82
84
  scales: {},
@@ -59,6 +59,7 @@ var defaultProps = {
59
59
  type: "timing",
60
60
  ratio: SEQUENCE["perfect-fourth"],
61
61
  range: [-3, 12],
62
+ mediaRegenerate: false,
62
63
  unit: "ms",
63
64
  sequence: {},
64
65
  scales: {},
@@ -62,6 +62,7 @@ var defaultProps = {
62
62
  h1Matches: 6,
63
63
  lineHeight: 1.5,
64
64
  subSequence: true,
65
+ mediaRegenerate: false,
65
66
  unit: "em",
66
67
  templates: {},
67
68
  sequence: {},
@@ -1392,6 +1392,7 @@ var defaultProps = {
1392
1392
  h1Matches: 6,
1393
1393
  lineHeight: 1.5,
1394
1394
  subSequence: true,
1395
+ mediaRegenerate: false,
1395
1396
  unit: "em",
1396
1397
  templates: {},
1397
1398
  sequence: {},
@@ -1447,6 +1448,7 @@ var defaultProps2 = {
1447
1448
  ratio: SEQUENCE.phi,
1448
1449
  range: [-5, 15],
1449
1450
  subSequence: true,
1451
+ mediaRegenerate: false,
1450
1452
  unit: "em",
1451
1453
  sequence: {},
1452
1454
  scales: {},
@@ -1474,6 +1476,7 @@ var defaultProps3 = {
1474
1476
  type: "timing",
1475
1477
  ratio: SEQUENCE["perfect-fourth"],
1476
1478
  range: [-3, 12],
1479
+ mediaRegenerate: false,
1477
1480
  unit: "ms",
1478
1481
  sequence: {},
1479
1482
  scales: {},
package/dist/cjs/index.js CHANGED
@@ -1378,7 +1378,9 @@ __export(src_exports, {
1378
1378
  appendIconsSprite: () => appendIconsSprite,
1379
1379
  appendSVGSprite: () => appendSVGSprite,
1380
1380
  applyDocument: () => applyDocument,
1381
+ applyGlobalVars: () => applyGlobalVars,
1381
1382
  applyHeadings: () => applyHeadings,
1383
+ applyMediaSequenceVars: () => applyMediaSequenceVars,
1382
1384
  applyReset: () => applyReset,
1383
1385
  applySequenceVars: () => applySequenceVars,
1384
1386
  applySpacingSequence: () => applySpacingSequence,
@@ -1411,6 +1413,8 @@ __export(src_exports, {
1411
1413
  getShadow: () => getShadow,
1412
1414
  getSpacingBasedOnRatio: () => getSpacingBasedOnRatio,
1413
1415
  getSpacingByKey: () => getSpacingByKey,
1416
+ getSubratio: () => getSubratio,
1417
+ getSubratioDifference: () => getSubratioDifference,
1414
1418
  getTheme: () => getTheme,
1415
1419
  getTimingByKey: () => getTimingByKey,
1416
1420
  getTimingFunction: () => getTimingFunction,
@@ -1443,7 +1447,9 @@ __export(src_exports, {
1443
1447
  setInCustomFontMedia: () => setInCustomFontMedia,
1444
1448
  setMediaTheme: () => setMediaTheme,
1445
1449
  setSVG: () => setSVG,
1450
+ setScalingVar: () => setScalingVar,
1446
1451
  setShadow: () => setShadow,
1452
+ setSubScalingVar: () => setSubScalingVar,
1447
1453
  setTheme: () => setTheme,
1448
1454
  setValue: () => setValue,
1449
1455
  setVariables: () => setVariables,
@@ -1462,6 +1468,8 @@ module.exports = __toCommonJS(src_exports);
1462
1468
  // src/utils/index.js
1463
1469
  var utils_exports = {};
1464
1470
  __export(utils_exports, {
1471
+ applyGlobalVars: () => applyGlobalVars,
1472
+ applyMediaSequenceVars: () => applyMediaSequenceVars,
1465
1473
  applySequenceVars: () => applySequenceVars,
1466
1474
  changeLightness: () => changeLightness,
1467
1475
  colorStringToRgbaArray: () => colorStringToRgbaArray,
@@ -1481,6 +1489,8 @@ __export(utils_exports, {
1481
1489
  getRgbTone: () => getRgbTone,
1482
1490
  getSequenceValue: () => getSequenceValue,
1483
1491
  getSequenceValuePropertyPair: () => getSequenceValuePropertyPair,
1492
+ getSubratio: () => getSubratio,
1493
+ getSubratioDifference: () => getSubratioDifference,
1484
1494
  hexToRgb: () => hexToRgb,
1485
1495
  hexToRgbArray: () => hexToRgbArray,
1486
1496
  hexToRgba: () => hexToRgba,
@@ -1497,6 +1507,8 @@ __export(utils_exports, {
1497
1507
  setCustomFont: () => setCustomFont,
1498
1508
  setCustomFontMedia: () => setCustomFontMedia,
1499
1509
  setInCustomFontMedia: () => setInCustomFontMedia,
1510
+ setScalingVar: () => setScalingVar,
1511
+ setSubScalingVar: () => setSubScalingVar,
1500
1512
  setVariables: () => setVariables
1501
1513
  });
1502
1514
 
@@ -1802,6 +1814,7 @@ var defaultProps = {
1802
1814
  h1Matches: 6,
1803
1815
  lineHeight: 1.5,
1804
1816
  subSequence: true,
1817
+ mediaRegenerate: false,
1805
1818
  unit: "em",
1806
1819
  templates: {},
1807
1820
  sequence: {},
@@ -1857,6 +1870,7 @@ var defaultProps2 = {
1857
1870
  ratio: SEQUENCE.phi,
1858
1871
  range: [-5, 15],
1859
1872
  subSequence: true,
1873
+ mediaRegenerate: false,
1860
1874
  unit: "em",
1861
1875
  sequence: {},
1862
1876
  scales: {},
@@ -1884,6 +1898,7 @@ var defaultProps3 = {
1884
1898
  type: "timing",
1885
1899
  ratio: SEQUENCE["perfect-fourth"],
1886
1900
  range: [-3, 12],
1901
+ mediaRegenerate: false,
1887
1902
  unit: "ms",
1888
1903
  sequence: {},
1889
1904
  scales: {},
@@ -1997,45 +2012,77 @@ var numToLetterMap = {
1997
2012
  19: "T"
1998
2013
  };
1999
2014
  var setSequenceValue = (props, sequenceProps) => {
2000
- const { key, variable, value, scaling, index } = props;
2015
+ const { key, variable, value, scaling, index, scalingVariable } = props;
2001
2016
  sequenceProps.sequence[key] = {
2002
2017
  key,
2003
2018
  decimal: ~~(value * 100) / 100,
2004
2019
  val: ~~value,
2005
2020
  scaling,
2006
2021
  index,
2022
+ scalingVariable,
2007
2023
  variable
2008
2024
  };
2009
2025
  sequenceProps.scales[key] = scaling;
2010
2026
  sequenceProps.vars[variable] = scaling + sequenceProps.unit;
2011
2027
  };
2028
+ var setScalingVar = (key, sequenceProps) => {
2029
+ const { type } = sequenceProps;
2030
+ if (key === 0)
2031
+ return "1em";
2032
+ const prefix = "--" + (type && type.replace(".", "-"));
2033
+ const ratioVar = `${prefix}-ratio`;
2034
+ if (key > 0) {
2035
+ const prevLetterKey = numToLetterMap[key - 1];
2036
+ return `calc(var(${prefix}-${prevLetterKey}) * var(${ratioVar}))`;
2037
+ }
2038
+ if (key < 0) {
2039
+ const nextLetterKey = numToLetterMap[key + 1];
2040
+ return `calc(var(${prefix}-${nextLetterKey}) / var(${ratioVar}))`;
2041
+ }
2042
+ };
2043
+ var setSubScalingVar = (index, arr, variable, sequenceProps) => {
2044
+ const { type } = sequenceProps;
2045
+ const skipMiddle = index === 2 && arr.length === 2;
2046
+ const indexMapWithLength = skipMiddle ? index + 1 : index;
2047
+ const prefix = "--" + (type && type.replace(".", "-"));
2048
+ const subRatioVarPrefix = `${prefix}-sub-ratio-`;
2049
+ return `calc(var(${variable}) * var(${subRatioVarPrefix + indexMapWithLength}))`;
2050
+ };
2051
+ var getSubratioDifference = (base, ratio) => {
2052
+ const diff = base * ratio - base;
2053
+ const subRatio = diff / 1.618;
2054
+ const first = base * ratio - subRatio;
2055
+ const second = base + subRatio;
2056
+ const middle = (first + second) / 2;
2057
+ return [first, middle, second];
2058
+ };
2059
+ var getSubratio = (base, ratio) => {
2060
+ return getSubratioDifference(base, ratio).map((v) => v / base);
2061
+ };
2012
2062
  var generateSubSequence = (props, sequenceProps) => {
2013
2063
  const { key, base, value, ratio, variable, index } = props;
2014
2064
  const next = value * ratio;
2015
- const diff = next - value;
2016
- const smallscale = diff / 1.618;
2017
- const valueRounded = ~~value;
2018
- const nextRounded = ~~next;
2019
- const diffRounded = nextRounded - valueRounded;
2020
- let arr = [];
2021
- const first = next - smallscale;
2022
- const second = value + smallscale;
2023
- const middle = (first + second) / 2;
2065
+ const diffRounded = ~~next - ~~value;
2066
+ let arr;
2067
+ const [first, middle, second] = getSubratioDifference(value, ratio);
2024
2068
  if (diffRounded > 16)
2025
2069
  arr = [first, middle, second];
2026
2070
  else
2027
2071
  arr = [first, second];
2028
- arr.map((v, k) => {
2072
+ arr.forEach((v, k) => {
2029
2073
  const scaling = ~~(v / base * 1e3) / 1e3;
2030
2074
  const newVar = variable + (k + 1);
2075
+ const newIndex = index + (k + 1) / 10;
2076
+ const scalingVariable = setSubScalingVar(k + 1, arr, variable, sequenceProps);
2031
2077
  const props2 = {
2032
2078
  key: key + (k + 1),
2033
2079
  variable: newVar,
2034
2080
  value: v,
2035
2081
  scaling,
2036
- index: index + (k + 1) / 10
2082
+ scalingVariable,
2083
+ index: newIndex
2037
2084
  };
2038
- return setSequenceValue(props2, sequenceProps);
2085
+ setSequenceValue(props2, sequenceProps);
2039
2086
  });
2040
2087
  };
2041
2088
  var switchSequenceOnNegative = (key, base, ratio) => {
@@ -2051,12 +2098,14 @@ var generateSequence = (sequenceProps) => {
2051
2098
  const value = switchSequenceOnNegative(key, base, ratio);
2052
2099
  const scaling = ~~(value / base * 100) / 100;
2053
2100
  const variable = prefix + letterKey;
2101
+ const scalingVariable = setScalingVar(key, sequenceProps);
2054
2102
  const props = {
2055
2103
  key: letterKey,
2056
2104
  variable,
2057
2105
  value,
2058
2106
  base,
2059
2107
  scaling,
2108
+ scalingVariable,
2060
2109
  ratio,
2061
2110
  index: key
2062
2111
  };
@@ -2148,35 +2197,75 @@ var setVariables = (result, key) => {
2148
2197
  CSS_VARS2[result.var] = result.value;
2149
2198
  }
2150
2199
  };
2151
- var applySequenceVars = (props, mediaName, options = {}) => {
2200
+ var applyGlobalVars = (vars, obj, options) => {
2152
2201
  const CONFIG2 = getActiveConfig();
2153
- const { UNIT: UNIT2, MEDIA: MEDIA2, TIMING: TIMING2, CSS_VARS: CSS_VARS2 } = CONFIG2;
2154
- const unit = props.unit || UNIT2.default;
2155
- const { sequence, scales } = props;
2202
+ const { UNIT: UNIT2 } = CONFIG2;
2203
+ const unit = obj.unit || UNIT2.default;
2204
+ const { base, ratio, type } = obj;
2205
+ const prefix = "--" + (type && type.replace(".", "-"));
2206
+ vars[`${prefix}-base`] = base;
2207
+ vars[`${prefix}-unit`] = unit;
2208
+ const ratioVar = `${prefix}-ratio`;
2209
+ vars[ratioVar] = ratio;
2210
+ const [first, middle, second] = getSubratio(base, ratio);
2211
+ vars[`${prefix}-sub-ratio-1`] = first;
2212
+ vars[`${prefix}-sub-ratio-2`] = middle;
2213
+ vars[`${prefix}-sub-ratio-3`] = second;
2214
+ };
2215
+ var applySequenceVars = (FACTORY2, options = {}) => {
2216
+ const CONFIG2 = getActiveConfig();
2217
+ const { UNIT: UNIT2, TIMING: TIMING2, CSS_VARS: CSS_VARS2 } = CONFIG2;
2218
+ const unit = FACTORY2.unit || UNIT2.default;
2219
+ const { mediaRegenerate, sequence, scales } = FACTORY2;
2220
+ if (!mediaRegenerate) {
2221
+ applyGlobalVars(CSS_VARS2, FACTORY2, options);
2222
+ }
2156
2223
  for (const key in sequence) {
2157
2224
  const item = sequence[key];
2158
- const value = (props.type === TIMING2.type ? sequence[key].val : scales[key]) + unit;
2159
- if (mediaName) {
2160
- const query = MEDIA2[mediaName];
2161
- if (!query) {
2162
- if (CONFIG2.verbose)
2163
- console.warn("Can't find query ", query);
2164
- }
2165
- let underMediaQuery = CSS_VARS2[`@media ${query}`];
2166
- if (!underMediaQuery)
2167
- underMediaQuery = CSS_VARS2[`@media ${query}`] = {};
2168
- underMediaQuery[item.variable] = `var(${item.variable + "_" + mediaName})`;
2169
- CSS_VARS2[item.variable + "_" + mediaName] = value;
2225
+ const value = (FACTORY2.type === TIMING2.type ? sequence[key].val : scales[key]) + unit;
2226
+ if (!mediaRegenerate) {
2227
+ CSS_VARS2[item.variable + "_default"] = value;
2228
+ CSS_VARS2[item.variable] = item.scalingVariable;
2229
+ continue;
2230
+ }
2231
+ if (options.useDefault === false) {
2232
+ CSS_VARS2[item.variable] = value;
2170
2233
  } else {
2171
- if (options.useDefault === false) {
2172
- CSS_VARS2[item.variable] = value;
2173
- } else {
2174
- CSS_VARS2[item.variable + "_default"] = value;
2175
- CSS_VARS2[item.variable] = `var(${item.variable + "_default"})`;
2176
- }
2234
+ CSS_VARS2[item.variable + "_default"] = value;
2235
+ CSS_VARS2[item.variable] = `var(${item.variable + "_default"})`;
2177
2236
  }
2178
2237
  }
2179
2238
  };
2239
+ var applyMediaSequenceVars = (FACTORY2, media, options = {}) => {
2240
+ const CONFIG2 = getActiveConfig();
2241
+ const { UNIT: UNIT2, MEDIA: MEDIA2, TIMING: TIMING2, CSS_VARS: CSS_VARS2 } = CONFIG2;
2242
+ const mediaName = media.slice(1);
2243
+ const unit = FACTORY2.unit || UNIT2.default;
2244
+ const { mediaRegenerate } = FACTORY2;
2245
+ const { sequence, scales } = FACTORY2[media];
2246
+ const query = MEDIA2[mediaName];
2247
+ if (!query && CONFIG2.verbose)
2248
+ console.warn("Can't find media query ", query);
2249
+ if (!mediaRegenerate) {
2250
+ let underMediaQuery = CSS_VARS2[`@media ${query}`];
2251
+ if (!underMediaQuery)
2252
+ underMediaQuery = CSS_VARS2[`@media ${query}`] = {};
2253
+ applyGlobalVars(underMediaQuery, FACTORY2[media], options);
2254
+ return;
2255
+ }
2256
+ for (const key in sequence) {
2257
+ const item = sequence[key];
2258
+ const value = (FACTORY2.type === TIMING2.type ? sequence[key].val : scales[key]) + unit;
2259
+ if (!query && CONFIG2.verbose)
2260
+ console.warn("Can't find query ", query);
2261
+ let underMediaQuery = CSS_VARS2[`@media ${query}`];
2262
+ if (!underMediaQuery)
2263
+ underMediaQuery = CSS_VARS2[`@media ${query}`] = {};
2264
+ underMediaQuery[item.variable] = `var(${item.variable + "_" + mediaName})`;
2265
+ CSS_VARS2[item.variable + "_" + mediaName] = value;
2266
+ }
2267
+ console.log(CSS_VARS2);
2268
+ };
2180
2269
 
2181
2270
  // src/utils/sprite.js
2182
2271
  var import_utils8 = __toESM(require_cjs2(), 1);
@@ -2654,34 +2743,50 @@ var setFontFamily = (val, key) => {
2654
2743
 
2655
2744
  // src/system/typography.js
2656
2745
  var import_utils15 = __toESM(require_cjs2(), 1);
2657
- var runThroughMedia = (props) => {
2746
+ var runThroughMedia = (FACTORY2) => {
2658
2747
  const CONFIG2 = getActiveConfig();
2659
2748
  const { TYPOGRAPHY: TYPOGRAPHY2, MEDIA: MEDIA2 } = CONFIG2;
2660
- for (const prop in props) {
2661
- const mediaProps = props[prop];
2662
- if (prop.slice(0, 1) === "@") {
2663
- const { type, base, ratio, range, subSequence, h1Matches, unit } = props;
2664
- (0, import_utils15.merge)(mediaProps, {
2665
- type,
2666
- base,
2667
- ratio,
2668
- range,
2669
- subSequence,
2670
- h1Matches,
2671
- unit,
2672
- sequence: {},
2673
- scales: {},
2674
- templates: {},
2675
- vars: {}
2676
- });
2677
- generateSequence(mediaProps);
2678
- const mediaName = prop.slice(1);
2679
- applySequenceVars(mediaProps, mediaName);
2680
- const query = MEDIA2[mediaName];
2681
- TYPOGRAPHY2.templates[`@media screen and ${query}`] = {
2682
- fontSize: mediaProps.base / TYPOGRAPHY2.browserDefault + unit
2683
- };
2749
+ for (const prop in FACTORY2) {
2750
+ const isPropMedia = prop.slice(0, 1) === "@";
2751
+ const mediaValue = FACTORY2[prop];
2752
+ if (!isPropMedia)
2753
+ continue;
2754
+ const { mediaRegenerate } = FACTORY2;
2755
+ const mediaName = prop.slice(1);
2756
+ const {
2757
+ type,
2758
+ base,
2759
+ ratio,
2760
+ range,
2761
+ subSequence,
2762
+ h1Matches,
2763
+ unit
2764
+ } = FACTORY2;
2765
+ (0, import_utils15.merge)(mediaValue, {
2766
+ type,
2767
+ base,
2768
+ ratio,
2769
+ range,
2770
+ subSequence,
2771
+ h1Matches,
2772
+ unit
2773
+ });
2774
+ const query = MEDIA2[mediaName];
2775
+ TYPOGRAPHY2.templates[`@media screen and ${query}`] = {
2776
+ fontSize: mediaValue.base / TYPOGRAPHY2.browserDefault + unit
2777
+ };
2778
+ if (!mediaRegenerate) {
2779
+ applyMediaSequenceVars(FACTORY2, prop);
2780
+ continue;
2684
2781
  }
2782
+ (0, import_utils15.merge)(mediaValue, {
2783
+ sequence: {},
2784
+ scales: {},
2785
+ templates: {},
2786
+ vars: {}
2787
+ });
2788
+ generateSequence(mediaValue);
2789
+ applyMediaSequenceVars(FACTORY2, prop);
2685
2790
  }
2686
2791
  };
2687
2792
  var applyHeadings = (props) => {
@@ -2723,28 +2828,36 @@ var getFontSizeByKey = (value) => {
2723
2828
 
2724
2829
  // src/system/spacing.js
2725
2830
  var import_utils18 = __toESM(require_cjs2(), 1);
2726
- var runThroughMedia2 = (sequenceProps) => {
2727
- for (const prop in sequenceProps) {
2728
- const mediaProps = sequenceProps[prop];
2729
- if (prop.slice(0, 1) === "@") {
2730
- const { type, base, ratio, range, subSequence, h1Matches, unit } = sequenceProps;
2731
- (0, import_utils18.merge)(mediaProps, {
2732
- type,
2733
- base,
2734
- ratio,
2735
- range,
2736
- subSequence,
2737
- h1Matches,
2738
- unit,
2739
- sequence: {},
2740
- scales: {},
2741
- templates: {},
2742
- vars: {}
2743
- });
2744
- generateSequence(mediaProps);
2745
- const mediaName = prop.slice(1);
2746
- applySequenceVars(mediaProps, mediaName);
2747
- }
2831
+ var runThroughMedia2 = (FACTORY2) => {
2832
+ for (const prop in FACTORY2) {
2833
+ const mediaProps = FACTORY2[prop];
2834
+ const isMediaName = prop.slice(0, 1) === "@";
2835
+ if (!isMediaName)
2836
+ continue;
2837
+ const {
2838
+ type,
2839
+ base,
2840
+ ratio,
2841
+ range,
2842
+ subSequence,
2843
+ h1Matches,
2844
+ unit
2845
+ } = FACTORY2;
2846
+ (0, import_utils18.merge)(mediaProps, {
2847
+ type,
2848
+ base,
2849
+ ratio,
2850
+ range,
2851
+ subSequence,
2852
+ h1Matches,
2853
+ unit,
2854
+ sequence: {},
2855
+ scales: {},
2856
+ templates: {},
2857
+ vars: {}
2858
+ });
2859
+ generateSequence(mediaProps);
2860
+ applyMediaSequenceVars(FACTORY2, prop);
2748
2861
  }
2749
2862
  };
2750
2863
  var applySpacingSequence = () => {
@@ -2819,7 +2932,7 @@ var getSpacingBasedOnRatio = (props, propertyName, val) => {
2819
2932
  unit: SPACING2.unit
2820
2933
  });
2821
2934
  }
2822
- applySequenceVars(sequenceProps, null, { useDefault: false });
2935
+ applySequenceVars(sequenceProps, { useDefault: false });
2823
2936
  return getSpacingByKey(value, propertyName, sequenceProps);
2824
2937
  }
2825
2938
  return getSpacingByKey(value, propertyName);