@afterpack/protection-map 0.2.6 → 1.0.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.
Files changed (2) hide show
  1. package/package.json +1 -1
  2. package/template.html +83 -29
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@afterpack/protection-map",
3
- "version": "0.2.6",
3
+ "version": "1.0.0",
4
4
  "description": "AfterPack Protection Map viewer: render protection data into a self-contained HTML report",
5
5
  "type": "module",
6
6
  "main": "./index.mjs",
package/template.html CHANGED
@@ -881,6 +881,10 @@ body.is-resizing .pane-resizer::before { transition: none; }
881
881
  .weakspot-sample { flex: 1 1 auto; min-width: 0; font-family: var(--font-mono); font-size: 11.5px; color: var(--text-primary); overflow-wrap: anywhere; white-space: pre-wrap; }
882
882
  .weakspot-body { padding: 8px 10px 10px; border-top: 1px dashed var(--border); }
883
883
  .weakspot-reason { font-size: 11px; color: var(--text-secondary); margin: 0 0 6px; }
884
+ .weakspot-times { flex: 0 0 auto; font-family: var(--font-mono); font-size: 10.5px; color: var(--text-muted); }
885
+ .weakspot-names { font-size: 11px; color: var(--text-muted); margin: 8px 0 0; }
886
+ .weakspot-names-icon { margin-right: 4px; }
887
+ .weakspots-section.is-empty.is-collapsed .weakspot-names { display: none; }
884
888
  .empty-note-ok { font-size: 11.5px; color: var(--text-muted); font-style: normal; margin: 0; }
885
889
  .empty-note-ok .ok-check { color: var(--brand); font-weight: 700; margin-right: 4px; }
886
890
 
@@ -1143,7 +1147,7 @@ details[open] > .details-summary::before { transform: rotate(90deg); }
1143
1147
  <button type="button" id="filter-all" data-filter="all" aria-pressed="true" data-tip="Every file in this build.">All</button>
1144
1148
  <button type="button" id="filter-app" data-filter="app" aria-pressed="false" data-tip="Your own code.">App</button>
1145
1149
  <button type="button" id="filter-vendor" data-filter="vendor" aria-pressed="false" data-tip="Third-party packages (node_modules)." data-doc="thirdParty">Vendor</button>
1146
- <button type="button" id="filter-weak" data-filter="weak" aria-pressed="false" data-tip="Only files with a weak spot: text still readable in your output." data-doc="lightDefault">Weak</button>
1150
+ <button type="button" id="filter-weak" data-filter="weak" aria-pressed="false" data-tip="Only files with a weak spot: a string still readable in your output." data-doc="lightDefault">Weak</button>
1147
1151
  <button type="button" id="filter-marked" data-filter="marked" aria-pressed="false" data-tip="Only files with an @afterpack directive." data-doc="directives">Marked</button>
1148
1152
  </div>
1149
1153
  <p class="tree-note" id="deeplink-note" hidden></p>
@@ -1200,7 +1204,7 @@ details[open] > .details-summary::before { transform: rotate(90deg); }
1200
1204
  <button type="button" class="rail-section-head" id="weakspots-head" aria-expanded="false" aria-controls="weakspots-list">
1201
1205
  <span class="eyebrow" id="weakspots-title">Weak spots</span>
1202
1206
  </button>
1203
- <span class="info-dot" id="weakspots-info" tabindex="0" role="img" aria-label="About weak spots" data-tip="Text from your source that is still readable in your output. Strings are worth fixing; property names usually have to stay." data-doc="lightDefault">i</span>
1207
+ <span class="info-dot" id="weakspots-info" tabindex="0" role="img" aria-label="About weak spots" data-tip="Strings from your source that are still readable in your output, each listed once. Property names usually have to stay, so they are counted here but not listed." data-doc="lightDefault">i</span>
1204
1208
  </div>
1205
1209
  <div id="weakspots-list" style="margin-top:8px"></div>
1206
1210
  </div>
@@ -1513,6 +1517,7 @@ async function afterpackInflateBase64Gzip(b64) {
1513
1517
  return key.charAt(0).toLowerCase() + key.slice(1);
1514
1518
  }
1515
1519
  function mechanismText(code) { return MECHANISM[mechanismKey(code)] || ""; }
1520
+ function isPropertyNameSpot(s) { return !!(s && (s.raw || s).severity === "propertyName"); }
1516
1521
 
1517
1522
  function classChipHtml(cls, ghost, labelOverride, noTip) {
1518
1523
  var meta = CLASS_META[cls] || { label: cls || "Protected" };
@@ -2028,16 +2033,14 @@ async function afterpackInflateBase64Gzip(b64) {
2028
2033
  }
2029
2034
 
2030
2035
  function directiveKindOf(keyword) {
2031
- return keyword === "skip" || keyword === "hardened" || keyword === "destroy"
2032
- ? keyword
2033
- : "custom";
2036
+ return keyword === "skip" ? "skip" : "custom";
2034
2037
  }
2035
2038
 
2036
2039
  function clampDirectivesToEndMarkers(source, directives) {
2037
2040
  if (!directives.length) return;
2038
2041
  var allowed = { end: true };
2039
2042
  directives.forEach(function (d) { allowed[d.keyword] = true; });
2040
- var markers = [], re = /@afterpack[ \t]+([A-Za-z][\w-]*)/g, m;
2043
+ var markers = [], re = /@afterpack[ \t]+([A-Za-z][\w.-]*)/g, m;
2041
2044
  while ((m = re.exec(source)) !== null) {
2042
2045
  if (allowed[m[1]] === true) markers.push({ start: m.index, end: m.index + m[0].length, keyword: m[1] });
2043
2046
  }
@@ -2277,8 +2280,10 @@ async function afterpackInflateBase64Gzip(b64) {
2277
2280
  var displayPath = isMachineryFile ? "(AfterPack runtime)" : (fdoc.file && fdoc.file.path) || null;
2278
2281
  var displayName = displayPath ? displayPath.split(/[\\/]+/).pop() : "(unnamed file " + (fileIdx + 1) + ")";
2279
2282
  var leakCount = (fdoc.aggregate && fdoc.aggregate.leakCount) || 0;
2280
- var weakSpotCount = spotlights.length ||
2281
- ((fdoc.aggregate && fdoc.aggregate.weakRegions) || 0);
2283
+ var propertyNameCount = spotlights.length
2284
+ ? spotlights.filter(isPropertyNameSpot).length
2285
+ : Math.max(0, ((fdoc.aggregate && fdoc.aggregate.weakRegions) || 0) - leakCount);
2286
+ var weakSpotCount = spotlights.length ? spotlights.length - propertyNameCount : leakCount;
2282
2287
 
2283
2288
  var coverage = { protected: 0, hidden: 0, renamed: 0, readable: 0, plain: 0, total: sourceLen };
2284
2289
  mergedRuns.forEach(function (run) {
@@ -2302,7 +2307,7 @@ async function afterpackInflateBase64Gzip(b64) {
2302
2307
  renamedRanges: renamedRanges, extractedRanges: extractedRanges, directives: directives, declRanges: declRanges,
2303
2308
  renamedCount: (fdoc.aggregate && fdoc.aggregate.renamedCount != null) ? fdoc.aggregate.renamedCount : renamedRanges.length,
2304
2309
  extractedCount: (fdoc.aggregate && fdoc.aggregate.extractedCount != null) ? fdoc.aggregate.extractedCount : extractedRanges.length,
2305
- leakCount: leakCount, weakSpotCount: weakSpotCount,
2310
+ leakCount: leakCount, weakSpotCount: weakSpotCount, propertyNameCount: propertyNameCount,
2306
2311
  displayPath: displayPath, displayName: displayName
2307
2312
  };
2308
2313
  }
@@ -2577,7 +2582,7 @@ async function afterpackInflateBase64Gzip(b64) {
2577
2582
  if (!any) { f.__markers = []; return f.__markers; }
2578
2583
  allowed.end = true;
2579
2584
  var out = [];
2580
- var re = /@afterpack[ \t]+([A-Za-z][\w-]*)/g;
2585
+ var re = /@afterpack[ \t]+([A-Za-z][\w.-]*)/g;
2581
2586
  var m;
2582
2587
  while ((m = re.exec(f.source)) !== null) {
2583
2588
  if (allowed[m[1]] !== true) continue;
@@ -2781,9 +2786,12 @@ async function afterpackInflateBase64Gzip(b64) {
2781
2786
  function weakBreakdown(weak, leaks) {
2782
2787
  var parts = [];
2783
2788
  if (leaks > 0) parts.push(plural(leaks, "readable string", "readable strings"));
2784
- if (weak - leaks > 0) parts.push(plural(weak - leaks, "readable property name", "readable property names"));
2789
+ if (weak - leaks > 0) parts.push(plural(weak - leaks, "readable text fragment", "readable text fragments"));
2785
2790
  return parts.join(", ");
2786
2791
  }
2792
+ function propertyNamesNote(n) {
2793
+ return n > 0 ? plural(n, "property name stays", "property names stay") + " readable, as property names usually must." : "";
2794
+ }
2787
2795
  function weakBadgeHtml(weak, leaks, scope) {
2788
2796
  if (!weak) return "";
2789
2797
  var tip = plural(weak, "weak spot", "weak spots") + " " + scope + ": " + weakBreakdown(weak, leaks) + ".";
@@ -2924,15 +2932,15 @@ async function afterpackInflateBase64Gzip(b64) {
2924
2932
  if (titleEl) titleEl.textContent = "Files (" + FILES.length + ")";
2925
2933
  var el = document.getElementById("workspace-summary");
2926
2934
  if (!el) return;
2927
- var weak = 0, leaks = 0, filesWith = 0;
2935
+ var weak = 0, leaks = 0, filesWith = 0, names = 0;
2928
2936
  FILES.forEach(function (f) {
2929
- weak += f.weakSpotCount; leaks += f.leakCount;
2937
+ weak += f.weakSpotCount; leaks += f.leakCount; names += f.propertyNameCount;
2930
2938
  if (f.weakSpotCount > 0) filesWith++;
2931
2939
  });
2932
2940
  el.textContent = weak > 0 ? plural(weak, "weak spot", "weak spots") : "";
2933
2941
  if (weak > 0) {
2934
2942
  el.setAttribute("data-tip", plural(weak, "weak spot", "weak spots") + " in " + plural(filesWith, "file", "files") + ": " +
2935
- weakBreakdown(weak, leaks) + ". The Weak filter lists these files.");
2943
+ weakBreakdown(weak, leaks) + ". The Weak filter lists these files." + (names > 0 ? " " + propertyNamesNote(names) : ""));
2936
2944
  el.setAttribute("data-doc", "lightDefault");
2937
2945
  } else {
2938
2946
  el.removeAttribute("data-tip");
@@ -3006,8 +3014,9 @@ async function afterpackInflateBase64Gzip(b64) {
3006
3014
 
3007
3015
  var leaks = file.leakCount, weak = file.weakSpotCount;
3008
3016
  rows.push({ k: "Weak spots", v: fmtNum(weak) + (leaks > 0 ? " ⚠" : ""), warn: leaks > 0, doc: "lightDefault",
3009
- tip: weak > 0 ? "Text still readable in your output: " + weakBreakdown(weak, leaks) + ". Listed below."
3010
- : "No readable text from this file was found in your output." });
3017
+ tip: (weak > 0 ? "Text still readable in your output: " + weakBreakdown(weak, leaks) + ". Listed below."
3018
+ : "No readable string from this file was found in your output.") +
3019
+ (file.propertyNameCount > 0 ? " " + propertyNamesNote(file.propertyNameCount) : "") });
3011
3020
 
3012
3021
  if (f.inflationRatio != null) {
3013
3022
  rows.push({ k: "Size", v: (f.outputSizeEstimated ? "≈" : "") + f.inflationRatio.toFixed(2) + "×", doc: "sizeBudget",
@@ -3073,11 +3082,9 @@ async function afterpackInflateBase64Gzip(b64) {
3073
3082
 
3074
3083
  var DIRECTIVE_LEGEND_META = {
3075
3084
  skip: "skip: keep this readable",
3076
- hardened: "hardened: stronger protection",
3077
- destroy: "destroy: strongest protection",
3078
- custom: "custom: its own settings, such as preset=hard"
3085
+ custom: "preset=hard, complexity=8, …: this code's own settings"
3079
3086
  };
3080
- var DIRECTIVE_LEGEND_ORDER = ["skip", "hardened", "destroy", "custom"];
3087
+ var DIRECTIVE_LEGEND_ORDER = ["skip", "custom"];
3081
3088
  function renderDirectiveLegend() {
3082
3089
  var present = {};
3083
3090
  FILES.forEach(function (f) {
@@ -3156,12 +3163,40 @@ async function afterpackInflateBase64Gzip(b64) {
3156
3163
  rail.classList.toggle("inspector-section-collapsed", !!(insp && insp.classList.contains("is-collapsed")));
3157
3164
  }
3158
3165
 
3166
+ function weakSpotGroups(file) {
3167
+ var groups = [], byKey = {};
3168
+ file.spotlights.forEach(function (s) {
3169
+ if (isPropertyNameSpot(s)) return;
3170
+ var key = (s.raw.severity || "") + "\u0000" + (s.raw.sample || "");
3171
+ var g = byKey[key];
3172
+ if (!g) {
3173
+ g = byKey[key] = { first: s, members: [] };
3174
+ groups.push(g);
3175
+ }
3176
+ g.members.push(s);
3177
+ });
3178
+ groups.forEach(function (g) {
3179
+ g.positioned = g.members.filter(function (s) { return s.positioned; });
3180
+ });
3181
+ return groups;
3182
+ }
3183
+ function propertyNamesRowHtml(file) {
3184
+ var n = file.propertyNameCount;
3185
+ if (!n) return "";
3186
+ var help = SEVERITY_HELP.propertyName;
3187
+ return '<p class="weakspot-names" data-property-names="' + n + '">' +
3188
+ '<span class="weakspot-names-icon" aria-hidden="true">' + SEVERITY_ICON.propertyName + "</span>" +
3189
+ escapeHtml(propertyNamesNote(n) + " Marked in the code, not listed here.") +
3190
+ (help ? " " + docLinkHtml(help.doc, help.label) : "") + "</p>";
3191
+ }
3192
+
3159
3193
  function renderWeakSpots(file) {
3160
3194
  var titleEl = document.getElementById("weakspots-title");
3161
3195
  var infoEl = document.getElementById("weakspots-info");
3162
3196
  var list = document.getElementById("weakspots-list");
3163
3197
  if (!titleEl || !list) return;
3164
- if (!file.spotlights.length) {
3198
+ var groups = weakSpotGroups(file);
3199
+ if (!groups.length) {
3165
3200
  titleEl.textContent = "Weak spots (0)";
3166
3201
  if (infoEl) infoEl.style.display = "none";
3167
3202
  list.style.marginTop = "0";
@@ -3169,36 +3204,46 @@ async function afterpackInflateBase64Gzip(b64) {
3169
3204
  FILES.forEach(function (f) { if (f.fileIdx !== file.fileIdx) elsewhere += f.weakSpotCount; });
3170
3205
  list.innerHTML = '<p class="empty-note-ok"><span class="ok-check">✓</span>None in this file.' +
3171
3206
  (elsewhere > 0 ? " " + escapeHtml(plural(elsewhere, "weak spot", "weak spots")) + " in other files: use the <strong>Weak</strong> filter." : "") +
3172
- "</p>";
3207
+ "</p>" + propertyNamesRowHtml(file);
3173
3208
  setWeakSpotsEmpty(true);
3174
3209
  return;
3175
3210
  }
3176
3211
  setWeakSpotsEmpty(false);
3177
- titleEl.textContent = "Weak spots (" + file.spotlights.length + ")";
3212
+ titleEl.textContent = "Weak spots (" + file.weakSpotCount + ")";
3178
3213
  if (infoEl) infoEl.style.display = "";
3179
3214
  list.style.marginTop = "8px";
3180
- list.innerHTML = file.spotlights.map(function (s) {
3215
+ list.innerHTML = groups.map(function (g) {
3216
+ var s = g.first;
3181
3217
  var sev = s.raw.severity;
3182
3218
  var icon = SEVERITY_ICON[sev] || "⚠";
3183
3219
  var why = mechanismText(s.raw.mechanism);
3184
3220
  var help = SEVERITY_HELP[sev];
3185
- var actions = (s.positioned ? '<button type="button" class="mini-btn" data-jump-spotlight="' + s.idx + '">Show in code</button>' : "") +
3221
+ var times = g.members.length;
3222
+ var jumpTo = g.positioned.length ? g.positioned[0] : null;
3223
+ var jumpAll = g.positioned.map(function (p) { return p.idx; }).join(",");
3224
+ var actions = (jumpTo ? '<button type="button" class="mini-btn" data-jump-spotlight="' + jumpTo.idx + '"' +
3225
+ (g.positioned.length > 1 ? ' data-jump-cycle="' + jumpAll + '"' : "") + ">" +
3226
+ "Show in code</button>" : "") +
3186
3227
  (help ? docLinkHtml(help.doc, help.label) : "");
3187
- return '<details class="weakspot" data-spot-idx="' + s.idx + '">' +
3228
+ return '<details class="weakspot" data-spot-idx="' + s.idx + '"' + (times > 1 ? ' data-spot-count="' + times + '"' : "") + ">" +
3188
3229
  '<summary class="weakspot-summary">' +
3189
3230
  '<span class="weakspot-sev pill pill-' + escapeAttr(sev || "") + '" title="' + escapeAttr(SEVERITY_LABEL[sev] || "Readable text") + '">' + icon + "</span>" +
3190
3231
  '<span class="weakspot-sample">' + escapeHtml(s.raw.sample || "") + "</span>" +
3232
+ (times > 1 ? '<span class="weakspot-times" title="' + escapeAttr(plural(times, "place", "places") + " in this file") + '">×' + times + "</span>" : "") +
3191
3233
  "</summary>" +
3192
3234
  '<div class="weakspot-body">' +
3193
3235
  '<p class="weakspot-reason">' + escapeHtml(SEVERITY_BODY[sev] || SEVERITY_BODY.weak) + "</p>" +
3236
+ (times > 1 ? '<p class="weakspot-reason">' + escapeHtml("It appears in " + plural(times, "place", "places") + " in this file." +
3237
+ (g.positioned.length > 1 ? " Show in code steps through them." : "")) + "</p>" : "") +
3194
3238
  (why ? '<p class="weakspot-reason">' + escapeHtml(why) + "</p>" : "") +
3195
- (s.positioned ? "" : '<p class="weakspot-reason">' + escapeHtml(INSP_COPY.noPosition) + "</p>") +
3239
+ (jumpTo ? "" : '<p class="weakspot-reason">' + escapeHtml(INSP_COPY.noPosition) + "</p>") +
3196
3240
  (actions ? '<div class="insp-actions">' + actions + "</div>" : "") +
3197
3241
  "</div>" +
3198
3242
  "</details>";
3199
- }).join("");
3243
+ }).join("") + propertyNamesRowHtml(file);
3200
3244
  }
3201
3245
 
3246
+
3202
3247
  function groupLineage(lineage) {
3203
3248
  var groups = [], byName = Object.create(null);
3204
3249
  lineage.forEach(function (step) {
@@ -3594,6 +3639,15 @@ async function afterpackInflateBase64Gzip(b64) {
3594
3639
  var dl = tokEl.dataset.declIdx == null || tokEl.dataset.declIdx === "" ? null : Number(tokEl.dataset.declIdx);
3595
3640
  selectFromRun(r, s, rn, ex, cx, dl);
3596
3641
  }
3642
+ function nextJumpIdx(btn) {
3643
+ var idx = Number(btn.dataset.jumpSpotlight);
3644
+ var cycle = (btn.dataset.jumpCycle || "").split(",").filter(Boolean).map(Number);
3645
+ if (cycle.length > 1) {
3646
+ var at = cycle.indexOf(idx);
3647
+ btn.dataset.jumpSpotlight = String(cycle[(at + 1) % cycle.length]);
3648
+ }
3649
+ return idx;
3650
+ }
3597
3651
  function jumpToSpotlight(idx) {
3598
3652
  var file = activeFile();
3599
3653
  var target = codeBody.querySelector('.tok[data-spotlight-idx="' + idx + '"]');
@@ -3979,7 +4033,7 @@ async function afterpackInflateBase64Gzip(b64) {
3979
4033
  }
3980
4034
  document.getElementById("weakspots-list").addEventListener("click", function (e) {
3981
4035
  var btn = e.target.closest("[data-jump-spotlight]");
3982
- if (btn) jumpToSpotlight(Number(btn.dataset.jumpSpotlight));
4036
+ if (btn) jumpToSpotlight(nextJumpIdx(btn));
3983
4037
  });
3984
4038
  document.getElementById("inspector").addEventListener("click", function (e) {
3985
4039
  var jump = e.target.closest("[data-select-region]");