tolkira 0.1.0 → 0.1.2

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.d.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  import type { ReportSummary } from './summary.js';
2
- export declare const version = "0.1.0";
2
+ export declare const version = "0.1.2";
3
3
  export declare const phase = "development";
4
4
  export type { ReportSummary, StatusCounts, SummaryScenario, SummaryStatus, SummaryStep, } from './summary.js';
5
5
  export { summarizeReport, SUMMARY_SCHEMA_VERSION } from './summary.js';
package/dist/index.js CHANGED
@@ -423,7 +423,7 @@ function parseLegacyValue(parsed, source, options = {}) {
423
423
  );
424
424
  for (const [scenarioIndex, element] of scenarios.entries()) {
425
425
  const scenarioId = nextId("scenario");
426
- const scenarioTags = mapTags(element.tags, nextId);
426
+ const scenarioTags2 = mapTags(element.tags, nextId);
427
427
  const scenarioSteps = (element.steps ?? []).filter((step) => !isHook(step));
428
428
  const stepNodes = scenarioSteps.map((step) => mapStep(step, nextId));
429
429
  const backgroundInline = backgroundSteps.length > 0 && backgroundSteps.every(
@@ -436,7 +436,7 @@ function parseLegacyValue(parsed, source, options = {}) {
436
436
  const scenario = {
437
437
  id: scenarioId,
438
438
  location: location(element.line),
439
- tags: scenarioTags,
439
+ tags: scenarioTags2,
440
440
  keyword: (element.keyword ?? "Scenario").trim() || "Scenario",
441
441
  name: element.name ?? `Scenario ${scenarioIndex + 1}`,
442
442
  description: normalizeText(element.description),
@@ -464,7 +464,7 @@ function parseLegacyValue(parsed, source, options = {}) {
464
464
  name: scenario.name,
465
465
  language: "en",
466
466
  steps: pickleSteps,
467
- tags: [...featureTags, ...scenarioTags].map((tag) => ({
467
+ tags: [...featureTags, ...scenarioTags2].map((tag) => ({
468
468
  name: tag.name,
469
469
  astNodeId: tag.id
470
470
  })),
@@ -676,6 +676,118 @@ function secondsToNanoseconds(value) {
676
676
  const seconds = Number(value);
677
677
  return Number.isFinite(seconds) && seconds > 0 ? Math.round(seconds * 1e9) : 0;
678
678
  }
679
+ function isXmlChar(code) {
680
+ return code === 9 || code === 10 || code === 13 || code >= 32 && code <= 55295 || code >= 57344 && code <= 65533 || code >= 65536 && code <= 1114111;
681
+ }
682
+ function checkEntityReferences(fragment, source, allowedNames) {
683
+ const entityPattern = /&([^;]{1,32});/g;
684
+ let match;
685
+ while ((match = entityPattern.exec(fragment)) !== null) {
686
+ const entity = match[1];
687
+ if (entity === "amp" || entity === "lt" || entity === "gt" || entity === "quot" || entity === "apos" || allowedNames.has(entity)) {
688
+ continue;
689
+ }
690
+ let code;
691
+ if (/^#\d+$/.test(entity)) {
692
+ code = Number.parseInt(entity.slice(1), 10);
693
+ } else if (/^#x[0-9a-fA-F]+$/.test(entity)) {
694
+ code = Number.parseInt(entity.slice(2), 16);
695
+ }
696
+ if (code === void 0 || !Number.isFinite(code) || !isXmlChar(code)) {
697
+ throw new Error(
698
+ `Invalid JUnit XML in ${source}: invalid entity reference &${entity};`
699
+ );
700
+ }
701
+ }
702
+ }
703
+ function assertValidEntities(content, source) {
704
+ const allowedNames = /* @__PURE__ */ new Set();
705
+ const scanTag = (start) => {
706
+ let index2 = start + 1;
707
+ let quote = "";
708
+ let valueStart = 0;
709
+ while (index2 < content.length) {
710
+ const char = content[index2];
711
+ if (quote) {
712
+ if (char === quote) {
713
+ checkEntityReferences(
714
+ content.slice(valueStart, index2),
715
+ source,
716
+ allowedNames
717
+ );
718
+ quote = "";
719
+ }
720
+ } else if (char === '"' || char === "'") {
721
+ quote = char;
722
+ valueStart = index2 + 1;
723
+ } else if (char === ">") {
724
+ return index2 + 1;
725
+ }
726
+ index2 += 1;
727
+ }
728
+ return index2;
729
+ };
730
+ const scanDoctype = (start) => {
731
+ let index2 = start + "<!DOCTYPE".length;
732
+ let quote = "";
733
+ let depth = 0;
734
+ while (index2 < content.length) {
735
+ const char = content[index2];
736
+ if (quote) {
737
+ if (char === quote) quote = "";
738
+ } else if (char === '"' || char === "'") {
739
+ quote = char;
740
+ } else if (char === "[") {
741
+ depth += 1;
742
+ } else if (char === "]") {
743
+ depth -= 1;
744
+ } else if (char === ">" && depth <= 0) {
745
+ const doctype = content.slice(start, index2 + 1);
746
+ for (const entity of doctype.matchAll(
747
+ /<!ENTITY\s+([A-Za-z_:][\w.:-]*)/g
748
+ )) {
749
+ const name = entity[1];
750
+ if (name) allowedNames.add(name);
751
+ }
752
+ return index2 + 1;
753
+ }
754
+ index2 += 1;
755
+ }
756
+ return index2;
757
+ };
758
+ let index = 0;
759
+ while (index < content.length) {
760
+ const start = content.indexOf("<", index);
761
+ if (start === -1) {
762
+ checkEntityReferences(content.slice(index), source, allowedNames);
763
+ return;
764
+ }
765
+ if (start > index) {
766
+ checkEntityReferences(
767
+ content.slice(index, start),
768
+ source,
769
+ allowedNames
770
+ );
771
+ }
772
+ if (content.startsWith("<!--", start)) {
773
+ const end = content.indexOf("-->", start + 4);
774
+ index = end === -1 ? content.length : end + 3;
775
+ } else if (content.startsWith("<![CDATA[", start)) {
776
+ const end = content.indexOf("]]>", start + 9);
777
+ index = end === -1 ? content.length : end + 3;
778
+ } else if (content.startsWith("<?", start)) {
779
+ const end = content.indexOf("?>", start + 2);
780
+ index = end === -1 ? content.length : end + 2;
781
+ } else if (content.startsWith("<!DOCTYPE", start)) {
782
+ index = scanDoctype(start);
783
+ } else if (content.startsWith("<!", start)) {
784
+ const end = content.indexOf(">", start + 2);
785
+ index = end === -1 ? content.length : end + 1;
786
+ } else {
787
+ index = scanTag(start);
788
+ }
789
+ }
790
+ }
679
791
  function collectSuites(parsed) {
680
792
  if (!isObject(parsed)) return [];
681
793
  const suites = [];
@@ -712,18 +824,21 @@ ${text}`;
712
824
  return text || attribute;
713
825
  }
714
826
  function elementFromTestcase(testcase, index) {
715
- const failure = [...asArray(testcase.failure), ...asArray(testcase.error)].find(
716
- isObject
717
- );
827
+ const failures = [
828
+ ...asArray(testcase.failure),
829
+ ...asArray(testcase.error)
830
+ ];
831
+ const failure = failures[0];
832
+ const hasFailure = failure !== void 0;
718
833
  const skipped = asArray(testcase.skipped).length > 0;
719
- const status = failure ? "failed" : skipped ? "skipped" : "passed";
834
+ const status = hasFailure ? "failed" : skipped ? "skipped" : "passed";
720
835
  const name = stringOf(testcase.name) || stringOf(testcase.classname) || `Test ${index + 1}`;
721
836
  const result = {
722
837
  status,
723
838
  duration: secondsToNanoseconds(testcase.time)
724
839
  };
725
- if (failure) {
726
- const message = failureMessage(failure);
840
+ if (hasFailure) {
841
+ const message = isObject(failure) ? failureMessage(failure) : textOf(failure).trim();
727
842
  if (message) result.error_message = message;
728
843
  }
729
844
  const embeddings = [];
@@ -770,12 +885,22 @@ function looksLikeJUnit(content) {
770
885
  return trimmed.startsWith("<") && /<testsuites?\b/i.test(trimmed);
771
886
  }
772
887
  async function parseJUnitXml(content, source) {
773
- const { XMLParser } = await import("fast-xml-parser");
888
+ const { XMLParser, XMLValidator } = await import("fast-xml-parser");
889
+ assertValidEntities(content, source);
890
+ const validation = XMLValidator.validate(content);
891
+ if (validation !== true) {
892
+ const line = Number.isFinite(validation.err.line) ? validation.err.line : 1;
893
+ const column = Number.isFinite(validation.err.col) ? validation.err.col : 1;
894
+ throw new Error(
895
+ `Invalid JUnit XML in ${source} at line ${line}, column ${column}: ${validation.err.msg}`
896
+ );
897
+ }
774
898
  const parser = new XMLParser({
775
899
  ignoreAttributes: false,
776
900
  attributeNamePrefix: "",
777
901
  parseTagValue: false,
778
902
  parseAttributeValue: false,
903
+ htmlEntities: true,
779
904
  isArray: (name) => ARRAY_TAGS.has(name)
780
905
  });
781
906
  let parsed;
@@ -2039,9 +2164,10 @@ var REPORT_CSS = `:root {
2039
2164
  html { background: var(--paper); scroll-padding-top: 4.5rem; scrollbar-gutter: stable; }
2040
2165
  body { margin: 0; color: var(--ink); background: var(--paper); font: 0.9375rem/1.55 var(--font-sans); -webkit-font-smoothing: antialiased; caret-color: var(--accent); }
2041
2166
  ::selection { background: color-mix(in oklab, var(--accent) 24%, transparent); }
2167
+ ::highlight(tolkira-search) { background-color: color-mix(in oklab, var(--accent) 42%, var(--paper)); color: var(--ink); }
2042
2168
  :focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
2043
2169
  a { color: var(--accent-text); text-underline-offset: 0.16em; }
2044
- button, input { font: inherit; }
2170
+ button, input, select { font: inherit; }
2045
2171
  button { cursor: pointer; }
2046
2172
  img, video { max-width: 100%; height: auto; }
2047
2173
  .shell { max-width: 1320px; margin: 0 auto; padding: 0 2rem 6rem; container-type: inline-size; }
@@ -2076,6 +2202,10 @@ img, video { max-width: 100%; height: auto; }
2076
2202
  .search { flex: 1 1 18.75rem; display: flex; align-items: center; gap: 0.5rem; min-height: 2.125rem; padding: 0 0.625rem; border: 1px solid var(--line-strong); border-radius: var(--radius-control); background: var(--surface-3); }
2077
2203
  .search input { width: 100%; min-height: 2rem; border: 0; outline: 0; background: transparent; color: var(--ink); font-size: 0.875rem; }
2078
2204
  .search:focus-within { outline: 2px solid var(--accent); outline-offset: 1px; }
2205
+ .tagFilter { display: flex; align-items: center; gap: 0.375rem; min-height: 2.125rem; max-width: 100%; }
2206
+ .tagFilter > span { color: var(--muted); font-size: 0.75rem; }
2207
+ .tagFilter select { max-width: 100%; min-width: 0; min-height: 1.875rem; padding: 0 1.5rem 0 0.5rem; border: 1px solid var(--line-strong); border-radius: var(--radius-control); background: var(--paper); color: var(--ink-2); font-size: 0.75rem; }
2208
+ .tagFilter select:hover { color: var(--ink); }
2079
2209
  .filters { display: flex; gap: 0.375rem; flex-wrap: wrap; }
2080
2210
  .filter { min-height: 1.875rem; padding: 0 0.5625rem; border: 1px solid var(--line-strong); border-radius: var(--radius-control); background: var(--paper); color: var(--ink-2); font-size: 0.75rem; }
2081
2211
  .filter b { margin-left: 0.25rem; font-family: var(--font-mono); font-weight: 500; font-variant-numeric: tabular-nums; }
@@ -2118,6 +2248,9 @@ details[open] > summary.scenarioButton { background: var(--accent-soft); }
2118
2248
  .rowRight { color: var(--muted); font-family: var(--font-mono); font-size: 0.75rem; text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
2119
2249
  .detailInline { padding: 0.25rem 0 1.125rem 13rem; background: var(--surface-2); border-top: 1px solid var(--line); }
2120
2250
  .detailInline h4 { margin: 0.875rem 0 0.375rem; color: var(--muted); font-size: 0.8125rem; font-weight: 600; }
2251
+ .stepsHead { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 0.5rem 0.75rem; }
2252
+ .copyFailure { min-height: 1.75rem; padding: 0 0.5625rem; border: 1px solid var(--line-strong); border-radius: var(--radius-control); background: var(--paper); color: var(--ink-2); font-size: 0.6875rem; }
2253
+ .copyFailure:hover { border-color: var(--accent); background: var(--accent-soft); color: var(--ink); }
2121
2254
  .description { margin: 0.625rem 0 0; color: var(--muted); font-size: 0.875rem; line-height: 1.55; white-space: pre-line; }
2122
2255
  .steps { list-style: none; margin: 0; padding: 0; border-top: 1px solid var(--line); }
2123
2256
  .step { display: grid; grid-template-columns: 0.875rem minmax(0, 1fr) auto; gap: 0.5rem; padding: 0.4375rem 0; border-bottom: 1px solid var(--line); font-size: 0.8125rem; }
@@ -2225,6 +2358,7 @@ details[open] > summary.scenarioButton { background: var(--accent-soft); }
2225
2358
  @media (forced-colors: active) {
2226
2359
  .chev { background-color: CanvasText; }
2227
2360
  .stepMarker { border-color: CanvasText; color: CanvasText; }
2361
+ ::highlight(tolkira-search) { background-color: Highlight; color: HighlightText; }
2228
2362
  }
2229
2363
  @media (prefers-color-scheme: dark) {
2230
2364
  :root {
@@ -2333,6 +2467,11 @@ function renderAttachment(attachment, context) {
2333
2467
  }
2334
2468
  return `<span class="fileLink">${name} (${media}, ${attachment.bytes} bytes)</span>`;
2335
2469
  }
2470
+ function scenarioTags(model) {
2471
+ return [...new Set(model.scenarios.flatMap((scenario) => scenario.tags))].sort(
2472
+ (a, b) => a.localeCompare(b)
2473
+ );
2474
+ }
2336
2475
  function renderStep(step, scenarioName) {
2337
2476
  const docString = step.docString ? `<pre class="docString">${escapeHtml(step.docString)}</pre>` : "";
2338
2477
  const table = step.dataTable ? `<div class="tableWrap" tabindex="0" role="region" aria-label="Data table for: ${escapeHtml(step.text)}"><table class="dataTable"><tbody>${step.dataTable.map(
@@ -2343,7 +2482,7 @@ function renderStep(step, scenarioName) {
2343
2482
  const error = step.message ? `<pre class="error">${escapeHtml(step.message)}</pre>` : "";
2344
2483
  const context = `${scenarioName}: ${step.keyword.trim()} ${step.text}`;
2345
2484
  const attachments = step.attachments.map((attachment) => renderAttachment(attachment, context)).join("");
2346
- return `<li class="step"><span class="stepMarker ${statusClass(step.status)}"><span aria-hidden="true">${STEP_GLYPHS[step.status]}</span><span class="sr">${statusLabel(step.status)}</span></span><div><span class="kw">${escapeHtml(step.keyword)}</span> ${escapeHtml(step.text)}${error}${docString}${table}${attachments}</div><span class="dur">${durationLabel(step.durationMs)}</span></li>`;
2485
+ return `<li class="step"${step.status === "failed" ? ' data-status="failed"' : ""}><span class="stepMarker ${statusClass(step.status)}"><span aria-hidden="true">${STEP_GLYPHS[step.status]}</span><span class="sr">${statusLabel(step.status)}</span></span><div><span class="kw">${escapeHtml(step.keyword)}</span> ${escapeHtml(step.text)}${error}${docString}${table}${attachments}</div><span class="dur">${durationLabel(step.durationMs)}</span></li>`;
2347
2486
  }
2348
2487
  function scenarioText(scenario) {
2349
2488
  return [
@@ -2364,7 +2503,8 @@ function renderScenario(scenario) {
2364
2503
  const steps = scenario.steps.map((step) => renderStep(step, scenario.name)).join("");
2365
2504
  const description = scenario.description ? `<p class="description">${escapeHtml(scenario.description)}</p>` : "";
2366
2505
  const extraAttachments = scenario.extraAttachments.length ? `<h4>Attachments</h4>${scenario.extraAttachments.map((attachment) => renderAttachment(attachment, scenario.name)).join("")}` : "";
2367
- return `<details class="scenario" data-scenario data-status="${scenario.status}" data-search="${escapeHtml(scenarioText(scenario))}" ${open ? "open" : ""}><summary class="scenarioButton"><span class="statusCell"><span class="statusText ${statusClass(scenario.status)}">${statusLabel(scenario.status)}</span></span><span class="thumbCell">${image ? `<img class="thumb" src="${escapeHtml(image.dataUri ?? "")}" alt="" loading="lazy">` : ""}</span><span class="scenarioMain"><h3 class="scenarioName">${escapeHtml(scenario.name)}</h3><span class="scenarioSub">${scenario.steps.length} step${scenario.steps.length === 1 ? "" : "s"}${scenario.tags.length ? ` <span class="tags">${scenario.tags.map((tag) => `<span class="tag">${escapeHtml(tag)}</span>`).join("")}</span>` : ""}</span></span><span class="rowRight">${durationLabel(scenario.durationMs)}${scenario.attachments.length ? `<br>${scenario.attachments.length} attachment${scenario.attachments.length === 1 ? "" : "s"}` : ""}</span><span class="chev" aria-hidden="true"></span></summary><div class="detailInline">${description}<h4>Steps</h4><ol class="steps">${steps}</ol>${extraAttachments}<div class="detailMeta"><span>Feature: ${escapeHtml(scenario.featureName)}</span><span>Attempt: ${scenario.attempt + 1}</span>${scenario.startedAt ? `<span>Started: ${dateLabel(scenario.startedAt)}</span>` : ""}${scenario.ruleName ? `<span>Rule: ${escapeHtml(scenario.ruleName)}</span>` : ""}</div></div></details>`;
2506
+ const copyFailure = scenario.status === "failed" ? '<button class="copyFailure" type="button" data-copy-failure>Copy failure</button>' : "";
2507
+ return `<details class="scenario" data-scenario data-status="${scenario.status}" data-uri="${escapeHtml(scenario.uri)}" data-tags="${escapeHtml(scenario.tags.join(" "))}" data-search="${escapeHtml(scenarioText(scenario))}" ${open ? "open" : ""}><summary class="scenarioButton"><span class="statusCell"><span class="statusText ${statusClass(scenario.status)}">${statusLabel(scenario.status)}</span></span><span class="thumbCell">${image ? `<img class="thumb" src="${escapeHtml(image.dataUri ?? "")}" alt="" loading="lazy">` : ""}</span><span class="scenarioMain"><h3 class="scenarioName">${escapeHtml(scenario.name)}</h3><span class="scenarioSub">${scenario.steps.length} step${scenario.steps.length === 1 ? "" : "s"}${scenario.tags.length ? ` <span class="tags">${scenario.tags.map((tag) => `<span class="tag">${escapeHtml(tag)}</span>`).join("")}</span>` : ""}</span></span><span class="rowRight">${durationLabel(scenario.durationMs)}${scenario.attachments.length ? `<br>${scenario.attachments.length} attachment${scenario.attachments.length === 1 ? "" : "s"}` : ""}</span><span class="chev" aria-hidden="true"></span></summary><div class="detailInline">${description}<div class="stepsHead"><h4>Steps</h4>${copyFailure}</div><ol class="steps">${steps}</ol>${extraAttachments}<div class="detailMeta"><span>Feature: ${escapeHtml(scenario.featureName)}</span><span>Attempt: ${scenario.attempt + 1}</span>${scenario.startedAt ? `<span>Started: ${dateLabel(scenario.startedAt)}</span>` : ""}${scenario.ruleName ? `<span>Rule: ${escapeHtml(scenario.ruleName)}</span>` : ""}</div></div></details>`;
2368
2508
  }
2369
2509
  function renderFeature(feature) {
2370
2510
  const passed = feature.scenarios.filter((scenario) => scenario.status === "passed").length;
@@ -2386,9 +2526,11 @@ function renderReportView(model, options) {
2386
2526
  const meta = metadataLine(options.metadata);
2387
2527
  const date = dateLabel(model.startedAt);
2388
2528
  const features = model.features.map((feature) => renderFeature(feature)).join("");
2389
- return `<div class="tabPanel" id="report-view" role="tabpanel" aria-labelledby="view-report" tabindex="0"><main class="shell"><header class="runHead"><div><p class="path">${escapeHtml(model.source)} / ${escapeHtml(options.title)}</p><h1>${escapeHtml(options.title)}</h1><p class="meta">${date ? `<span>${date}</span>` : ""}<span>${model.counts.features} feature${model.counts.features === 1 ? "" : "s"}</span><span>${model.counts.scenarios.total} scenarios</span><span>${escapeHtml(model.source)}</span>${meta}</p></div><div class="health"><div class="healthTop"><strong>${percent}%</strong><span>${passed} of ${total} passed</span></div>${statusBar(model)}${countPills(model)}</div></header><div class="toolbar"><label class="search"><span aria-hidden="true">\u2315</span><input data-search type="search" placeholder="Search scenario, feature or tag" aria-label="Search scenarios"></label><div class="filters">${displayStatuses(model).map(
2529
+ const tags = scenarioTags(model);
2530
+ const tagFilter = tags.length ? `<label class="tagFilter"><span>Tag</span><select data-tag-filter><option value="">All tags</option>${tags.map((tag) => `<option value="${escapeHtml(tag)}">${escapeHtml(tag)}</option>`).join("")}</select></label>` : "";
2531
+ return `<div class="tabPanel" id="report-view" role="tabpanel" aria-labelledby="view-report" tabindex="0"><main class="shell"><header class="runHead"><div><p class="path">${escapeHtml(model.source)} / ${escapeHtml(options.title)}</p><h1>${escapeHtml(options.title)}</h1><p class="meta">${date ? `<span>${date}</span>` : ""}<span>${model.counts.features} feature${model.counts.features === 1 ? "" : "s"}</span><span>${model.counts.scenarios.total} scenarios</span><span>${escapeHtml(model.source)}</span>${meta}</p></div><div class="health"><div class="healthTop"><strong>${percent}%</strong><span>${passed} of ${total} passed</span></div>${statusBar(model)}${countPills(model)}</div></header><div class="toolbar"><label class="search"><span aria-hidden="true">\u2315</span><input data-search type="search" placeholder="Search scenario, feature or tag" aria-label="Search scenarios"></label>${tagFilter}<div class="filters">${displayStatuses(model).map(
2390
2532
  (status) => `<button class="filter" type="button" data-status="${status}" aria-pressed="true">${statusLabel(status)} <b>${model.counts.scenarios[status]}</b></button>`
2391
- ).join("")}</div><div class="expand"><button type="button" data-expand="all">Expand all</button><button type="button" data-expand="none">Collapse all</button></div></div><p class="live sr" id="tolkira-live" role="status" aria-live="polite" data-total="${total}"></p><div id="feature-list">${features || `<div class="empty">No scenarios in this report.</div>`}</div><div class="empty" id="empty-results" hidden>No scenarios match the current search or filters.</div><p class="foot">Generated by Tolkira. Single file. No network requests. Screenshots are embedded.</p></main></div>`;
2533
+ ).join("")}</div><div class="expand"><button type="button" data-expand="all">Expand all</button><button type="button" data-expand="none">Collapse all</button></div></div><p class="live sr" id="tolkira-live" role="status" aria-live="polite" data-total="${total}"></p><p class="sr" id="tolkira-copy-live" aria-live="polite"></p><div id="feature-list">${features || `<div class="empty">No scenarios in this report.</div>`}</div><div class="empty" id="empty-results" hidden>No scenarios match the current search or filters.</div><p class="foot">Generated by Tolkira. Single file. No network requests. Screenshots are embedded.</p></main></div>`;
2392
2534
  }
2393
2535
  function renderAnalysisView(model, options, summary) {
2394
2536
  const counts = model.counts.scenarios;
@@ -2443,17 +2585,20 @@ var SCRIPT = `<script>
2443
2585
  views[next].focus();
2444
2586
  showView(views[next].getAttribute('data-view'));
2445
2587
  });
2446
- var state = { query: '', hidden: new Set() };
2588
+ var state = { query: '', hidden: new Set(), tag: '' };
2447
2589
  var scenarios = Array.prototype.slice.call(document.querySelectorAll('[data-scenario]'));
2448
2590
  var features = Array.prototype.slice.call(document.querySelectorAll('[data-feature]'));
2449
2591
  var live = document.getElementById('tolkira-live');
2450
2592
  function apply() {
2451
2593
  var query = state.query.toLowerCase();
2594
+ var tag = state.tag;
2452
2595
  var visible = 0;
2453
2596
  scenarios.forEach(function (scenario) {
2454
2597
  var status = scenario.getAttribute('data-status');
2455
2598
  var text = (scenario.getAttribute('data-search') || '').toLowerCase();
2456
- var match = !state.hidden.has(status) && (!query || text.indexOf(query) !== -1);
2599
+ var tags = ' ' + (scenario.getAttribute('data-tags') || '') + ' ';
2600
+ var tagMatch = !tag || tags.indexOf(' ' + tag + ' ') !== -1;
2601
+ var match = !state.hidden.has(status) && tagMatch && (!query || text.indexOf(query) !== -1);
2457
2602
  scenario.hidden = !match;
2458
2603
  if (match) visible += 1;
2459
2604
  });
@@ -2461,7 +2606,7 @@ var SCRIPT = `<script>
2461
2606
  var children = feature.querySelectorAll('[data-scenario]');
2462
2607
  var any = Array.prototype.some.call(children, function (child) { return !child.hidden; });
2463
2608
  feature.hidden = !any;
2464
- if (any && (query || state.hidden.size)) feature.open = true;
2609
+ if (any && (query || state.hidden.size || tag)) feature.open = true;
2465
2610
  });
2466
2611
  if (query) {
2467
2612
  scenarios.forEach(function (scenario) {
@@ -2471,12 +2616,65 @@ var SCRIPT = `<script>
2471
2616
  if (live) live.textContent = visible + ' of ' + scenarios.length + ' scenarios visible';
2472
2617
  var empty = document.getElementById('empty-results');
2473
2618
  if (empty) empty.hidden = visible !== 0;
2619
+ highlightSearch();
2620
+ }
2621
+ function clearHighlights() {
2622
+ if (typeof CSS === 'undefined' || !CSS.highlights) return;
2623
+ CSS.highlights.delete('tolkira-search');
2624
+ }
2625
+ function escapeRegex(value) {
2626
+ var out = '';
2627
+ for (var i = 0; i < value.length; i++) {
2628
+ var code = value.charCodeAt(i);
2629
+ var ch = value.charAt(i);
2630
+ var special = code === 92 || code === 94 || code === 36 || code === 46 || code === 42 || code === 43 || code === 63 || code === 40 || code === 41 || code === 91 || code === 93 || code === 123 || code === 125 || code === 124;
2631
+ out += special ? String.fromCharCode(92) + ch : ch;
2632
+ }
2633
+ return out;
2634
+ }
2635
+ function highlightSearch() {
2636
+ if (typeof CSS === 'undefined' || !CSS.highlights || typeof Highlight === 'undefined') return;
2637
+ var needle = state.query.trim();
2638
+ if (needle.length < 2) { clearHighlights(); return; }
2639
+ try {
2640
+ var pattern = new RegExp(escapeRegex(needle), 'gi');
2641
+ var ranges = [];
2642
+ scenarios.forEach(function (scenario) {
2643
+ if (scenario.hidden || !scenario.open || ranges.length >= 200) return;
2644
+ var walker = document.createTreeWalker(scenario, NodeFilter.SHOW_TEXT, null);
2645
+ var node;
2646
+ while (ranges.length < 200 && (node = walker.nextNode())) {
2647
+ var value = node.nodeValue;
2648
+ if (!value) continue;
2649
+ var parent = node.parentElement;
2650
+ if (parent && (parent.tagName === 'SCRIPT' || parent.tagName === 'STYLE')) continue;
2651
+ pattern.lastIndex = 0;
2652
+ var match;
2653
+ while (ranges.length < 200 && (match = pattern.exec(value)) !== null) {
2654
+ var range = document.createRange();
2655
+ range.setStart(node, match.index);
2656
+ range.setEnd(node, match.index + match[0].length);
2657
+ ranges.push(range);
2658
+ if (match[0].length === 0) pattern.lastIndex += 1;
2659
+ }
2660
+ }
2661
+ });
2662
+ clearHighlights();
2663
+ if (ranges.length) CSS.highlights.set('tolkira-search', new Highlight(...ranges));
2664
+ } catch (error) {
2665
+ clearHighlights();
2666
+ }
2474
2667
  }
2475
2668
  var search = document.querySelector('[data-search]');
2476
2669
  if (search) search.addEventListener('input', function () {
2477
2670
  state.query = search.value;
2478
2671
  apply();
2479
2672
  });
2673
+ var tagFilter = document.querySelector('[data-tag-filter]');
2674
+ if (tagFilter) tagFilter.addEventListener('change', function () {
2675
+ state.tag = tagFilter.value;
2676
+ apply();
2677
+ });
2480
2678
  Array.prototype.slice.call(document.querySelectorAll('button.filter[data-status]')).forEach(function (button) {
2481
2679
  button.addEventListener('click', function () {
2482
2680
  var status = button.getAttribute('data-status');
@@ -2493,6 +2691,94 @@ var SCRIPT = `<script>
2493
2691
  scenarios.forEach(function (scenario) { scenario.open = open; });
2494
2692
  });
2495
2693
  });
2694
+ var copyLive = document.getElementById('tolkira-copy-live');
2695
+ function legacyCopy(text) {
2696
+ var active = document.activeElement;
2697
+ var field = document.createElement('textarea');
2698
+ field.value = text;
2699
+ field.setAttribute('readonly', '');
2700
+ field.style.position = 'fixed';
2701
+ field.style.top = '-1000px';
2702
+ document.body.appendChild(field);
2703
+ var ok = false;
2704
+ try {
2705
+ field.select();
2706
+ ok = document.execCommand('copy');
2707
+ } catch (error) {
2708
+ ok = false;
2709
+ } finally {
2710
+ field.remove();
2711
+ if (active && typeof active.focus === 'function') active.focus();
2712
+ }
2713
+ return ok;
2714
+ }
2715
+ function writeClipboard(text, done) {
2716
+ var settled = false;
2717
+ function finish(ok) {
2718
+ if (settled) return;
2719
+ settled = true;
2720
+ done(ok);
2721
+ }
2722
+ function fallback() {
2723
+ finish(legacyCopy(text));
2724
+ }
2725
+ if (navigator.clipboard && typeof navigator.clipboard.writeText === 'function') {
2726
+ try {
2727
+ navigator.clipboard.writeText(text).then(function () { finish(true); }, fallback);
2728
+ } catch (error) {
2729
+ fallback();
2730
+ }
2731
+ } else {
2732
+ fallback();
2733
+ }
2734
+ }
2735
+ function failureText(button) {
2736
+ var scenario = button.closest('[data-scenario]');
2737
+ if (!scenario) return '';
2738
+ var feature = scenario.closest('[data-feature]');
2739
+ var featureTitle = feature ? feature.querySelector('h2') : null;
2740
+ var scenarioTitle = scenario.querySelector('.scenarioName');
2741
+ var step = scenario.querySelector('.step[data-status="failed"]');
2742
+ var keyword = step && step.querySelector('.kw') ? step.querySelector('.kw').textContent.trim() : '';
2743
+ var body = step ? step.querySelector('div') : null;
2744
+ var text = '';
2745
+ if (body) {
2746
+ Array.prototype.forEach.call(body.childNodes, function (node) {
2747
+ if (node.nodeType === 3) text += node.nodeValue;
2748
+ });
2749
+ }
2750
+ var error = step ? step.querySelector('.error') : null;
2751
+ var stepLabel = keyword === 'Hook' ? text.trim() : (keyword + ' ' + text.trim()).trim();
2752
+ var lines = [
2753
+ 'Feature: ' + (featureTitle ? featureTitle.textContent : ''),
2754
+ 'Scenario: ' + (scenarioTitle ? scenarioTitle.textContent : ''),
2755
+ 'URI: ' + (scenario.getAttribute('data-uri') || ''),
2756
+ 'Step: ' + stepLabel
2757
+ ];
2758
+ if (error && error.textContent.trim()) {
2759
+ lines.push('Error:\\n' + error.textContent.trim());
2760
+ }
2761
+ return lines.join('\\n');
2762
+ }
2763
+ Array.prototype.slice.call(document.querySelectorAll('[data-copy-failure]')).forEach(function (button) {
2764
+ var labelTimer = null;
2765
+ button.addEventListener('click', function () {
2766
+ button.focus();
2767
+ writeClipboard(failureText(button), function (ok) {
2768
+ if (labelTimer) clearTimeout(labelTimer);
2769
+ button.textContent = ok ? 'Copied' : 'Copy failed';
2770
+ if (copyLive) {
2771
+ copyLive.textContent = ok
2772
+ ? 'Failure details copied to clipboard.'
2773
+ : 'Could not copy failure details.';
2774
+ }
2775
+ labelTimer = setTimeout(function () {
2776
+ button.textContent = 'Copy failure';
2777
+ if (copyLive) copyLive.textContent = '';
2778
+ }, 2000);
2779
+ });
2780
+ });
2781
+ });
2496
2782
  var lightbox = document.getElementById('tolkira-lightbox');
2497
2783
  if (lightbox) {
2498
2784
  var lightboxImage = lightbox.querySelector('img');
@@ -2562,7 +2848,7 @@ ${csp(hashes)}
2562
2848
  }
2563
2849
 
2564
2850
  // src/index.ts
2565
- var version = "0.1.0";
2851
+ var version = "0.1.2";
2566
2852
  var phase = "development";
2567
2853
  async function generateReport(inputs, options = {}) {
2568
2854
  const envelopes = await loadEnvelopes(inputs);