@hyperframes/lint 0.8.41 → 0.8.43

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/index.js CHANGED
@@ -615,6 +615,11 @@ function buildLintContext(html, options = {}) {
615
615
  // src/rules/core.ts
616
616
  import postcss from "postcss";
617
617
  import selectorParser from "postcss-selector-parser";
618
+ import {
619
+ HTML_BODY_CSS_WIDTH_FIRST_RE,
620
+ HTML_BODY_CSS_HEIGHT_FIRST_RE,
621
+ VIEWPORT_META_SIZE_RE
622
+ } from "@hyperframes/parsers";
618
623
  function repeatedDescendantId(selector) {
619
624
  let repeated = null;
620
625
  const requiredPseudoIds = (pseudo) => {
@@ -787,6 +792,35 @@ function findVisibleMarkupCommentLeak(source) {
787
792
  }
788
793
  return null;
789
794
  }
795
+ function readHtmlBodyCssSize(source) {
796
+ const widthFirst = source.match(HTML_BODY_CSS_WIDTH_FIRST_RE);
797
+ if (widthFirst) {
798
+ const [, width = "", height = ""] = widthFirst;
799
+ return { width, height };
800
+ }
801
+ const heightFirst = source.match(HTML_BODY_CSS_HEIGHT_FIRST_RE);
802
+ if (heightFirst) {
803
+ const [, height = "", width = ""] = heightFirst;
804
+ return { width, height };
805
+ }
806
+ return null;
807
+ }
808
+ function readViewportMetaSize(source) {
809
+ const match = source.match(VIEWPORT_META_SIZE_RE);
810
+ if (!match) return null;
811
+ const [, width = "", height = ""] = match;
812
+ return { width, height };
813
+ }
814
+ function describeSizeMismatch(label, size, dataWidth, dataHeight) {
815
+ if (!size || size.width === dataWidth && size.height === dataHeight) return null;
816
+ return `${label} is ${size.width}x${size.height}`;
817
+ }
818
+ function findScaffoldSizeMismatches(source, dataWidth, dataHeight) {
819
+ return [
820
+ describeSizeMismatch("html/body CSS", readHtmlBodyCssSize(source), dataWidth, dataHeight),
821
+ describeSizeMismatch("the viewport meta", readViewportMetaSize(source), dataWidth, dataHeight)
822
+ ].filter((mismatch) => mismatch !== null);
823
+ }
790
824
  var coreRules = [
791
825
  // id_requires_css_escape
792
826
  ({ tags }) => {
@@ -831,6 +865,37 @@ var coreRules = [
831
865
  }
832
866
  return findings;
833
867
  },
868
+ // root_dimensions_mismatch
869
+ //
870
+ // Render size and the runtime's forced #root size both read the root's own
871
+ // data-width/data-height, so they stay correct. But editing only those two
872
+ // attributes — rather than scaffolding with `hyperframes init --resolution`,
873
+ // which rewrites the scaffold's other copies of the resolution too — leaves
874
+ // the `html, body` CSS and the `<meta viewport>` at the old value, and a
875
+ // stale body with `overflow: hidden` visually clips the correctly-sized
876
+ // root. `hyperframes check`'s layout audits can't see it: they measure
877
+ // against the root's own (already-correct) rect, not the body's.
878
+ //
879
+ // A sub-composition fragment has no html/body or viewport to compare
880
+ // against, which makes this top-level-only without a separate guard.
881
+ ({ rootTag, source }) => {
882
+ if (!rootTag) return [];
883
+ const dataWidth = readAttr(rootTag.raw, "data-width");
884
+ const dataHeight = readAttr(rootTag.raw, "data-height");
885
+ if (!dataWidth || !dataHeight) return [];
886
+ const mismatches = findScaffoldSizeMismatches(source, dataWidth, dataHeight);
887
+ if (mismatches.length === 0) return [];
888
+ return [
889
+ {
890
+ code: "root_dimensions_mismatch",
891
+ severity: "warning",
892
+ message: `Root composition declares data-width="${dataWidth}" data-height="${dataHeight}", but ${mismatches.join(" and ")}. The scaffolded body clips the composition at its old size.`,
893
+ elementId: readAttr(rootTag.raw, "id") || void 0,
894
+ fixHint: "update html/body CSS and the meta viewport to match, or scaffold with `hyperframes init --resolution portrait`",
895
+ snippet: truncateSnippet(rootTag.raw)
896
+ }
897
+ ];
898
+ },
834
899
  // unbalanced_style_tags
835
900
  ({ source }) => {
836
901
  let opens = 0;