@miaskiewicz/turbo-dom 0.7.0 → 0.8.0

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.
@@ -55,6 +55,14 @@ export class Storage {
55
55
  // is overridden — still stable for a given viewport. Unknown/feature-less queries
56
56
  // stay honestly `false`.
57
57
  const MQ_FEATURE = /\(\s*(min-width|max-width|min-height|max-height|orientation)\s*:\s*([^)]+?)\s*\)/g;
58
+ function evalMediaFeature(feat, val, W, H) {
59
+ if (feat === 'min-width') return W >= parseFloat(val);
60
+ if (feat === 'max-width') return W <= parseFloat(val);
61
+ if (feat === 'min-height') return H >= parseFloat(val);
62
+ if (feat === 'max-height') return H <= parseFloat(val);
63
+ // orientation: portrait iff height >= width (turbo-dom#138)
64
+ return val === (H >= W ? 'portrait' : 'landscape');
65
+ }
58
66
  function evalMediaQuery(query, win) {
59
67
  const W = (win && win.innerWidth) || 1024;
60
68
  const H = (win && win.innerHeight) || 768;
@@ -63,12 +71,7 @@ function evalMediaQuery(query, win) {
63
71
  MQ_FEATURE.lastIndex = 0;
64
72
  while ((m = MQ_FEATURE.exec(q))) {
65
73
  any = true;
66
- const feat = m[1], val = m[2].trim();
67
- if (feat === 'min-width') matched = matched && W >= parseFloat(val);
68
- else if (feat === 'max-width') matched = matched && W <= parseFloat(val);
69
- else if (feat === 'min-height') matched = matched && H >= parseFloat(val);
70
- else if (feat === 'max-height') matched = matched && H <= parseFloat(val);
71
- else matched = matched && val === (H >= W ? 'portrait' : 'landscape'); // orientation: portrait iff height >= width (turbo-dom#138)
74
+ matched = matched && evalMediaFeature(m[1], m[2].trim(), W, H);
72
75
  }
73
76
  return any && matched;
74
77
  }
Binary file
Binary file