@ggui-ai/ui-gen 0.19.0 → 0.20.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.
@@ -528,6 +528,46 @@ function runRootWidthCap(input) {
528
528
  )
529
529
  ];
530
530
  }
531
+ var LABEL_SPECIAL_CHAR = /[^a-z0-9\s]/i;
532
+ var normText = (s) => s.toLowerCase().replace(/\s+/g, " ").trim();
533
+ var alnumText = (s) => s.toLowerCase().replace(/[^a-z0-9]/g, "");
534
+ function visibleText(sourceCode) {
535
+ const jsx = (sourceCode.match(/>([^<>]*)</g) ?? []).map((m2) => m2.slice(1, -1).replace(/\{[^}]*\}/g, " ")).join(" ");
536
+ let attrs = "";
537
+ const attrRx = /\b(?:aria-label|placeholder|title|alt)\s*=\s*(?:"([^"]*)"|'([^']*)')/gi;
538
+ let m;
539
+ while ((m = attrRx.exec(sourceCode)) !== null) attrs += " " + (m[1] ?? m[2] ?? "");
540
+ return jsx + " " + attrs;
541
+ }
542
+ function findDroppedActionLabels(sourceCode, contract) {
543
+ const actionSpec = contract?.actionSpec;
544
+ if (actionSpec === void 0) return [];
545
+ if (/\.label\b/.test(sourceCode)) return [];
546
+ const vis = visibleText(sourceCode);
547
+ const normVis = normText(vis);
548
+ const alnumVis = alnumText(vis);
549
+ const out = [];
550
+ for (const [name, entry] of Object.entries(actionSpec)) {
551
+ const label = entry.label;
552
+ if (typeof label !== "string" || label.length === 0 || label === name) continue;
553
+ if (!LABEL_SPECIAL_CHAR.test(label)) continue;
554
+ if (alnumText(label).length < 3) continue;
555
+ if (normVis.includes(normText(label))) continue;
556
+ if (alnumVis.includes(alnumText(label))) out.push({ name, label });
557
+ }
558
+ return out;
559
+ }
560
+ function runActionLabelDropped(input) {
561
+ if (input.compiledCode === null) return [];
562
+ return findDroppedActionLabels(input.sourceCode, input.contract).map(
563
+ ({ name, label }) => mkIssue(
564
+ "universal.action_label_dropped",
565
+ `The action "${name}" declares label "${label}", but the rendered control appears to drop its "${label.replace(/[a-z0-9\s]/gi, "").trim()}": the label's words are in the generated source, the full label is not \u2014 a transcription drop (ggui#1190).`,
566
+ `Render the label EXACTLY as the contract states it \u2014 button text should be the verbatim \`actionSpec.${name}.label\`, or render it from data (\`{x.label}\`), never a re-typed copy that drops "&", "/", "+", etc.`,
567
+ "warn"
568
+ )
569
+ );
570
+ }
531
571
  var UNIVERSAL_CHECKS = [
532
572
  {
533
573
  id: "universal.icon_name_known",
@@ -553,6 +593,12 @@ var UNIVERSAL_CHECKS = [
553
593
  values: ALL_RENDER_VALUES,
554
594
  run: runRootWidthCap
555
595
  },
596
+ {
597
+ id: "universal.action_label_dropped",
598
+ axis: "render",
599
+ values: ALL_RENDER_VALUES,
600
+ run: runActionLabelDropped
601
+ },
556
602
  {
557
603
  id: "universal.terminal_action_unguarded",
558
604
  axis: "render",