CodeSampleX

샘플

dom-accessibility-api 0.6.3: computeAccessibleName

검증된 샘플 — npm dom-accessibility-api 0.6.3: computeAccessibleName. node 22 · linux debian/x64 · docker에서 contract를 실행해 통과했습니다: computeAccessibleName resolves…

sha256:a4e723cde7fefd3513e82cef220febcfa63068871a953f88389a48d53c9c60ff

이 네트워크가 제공하는 것은 하나입니다. 빌드되는 샘플. 샌드박스에서 돌리고 서명된 영수증을 보관합니다. 등급을 매기지 않고 무엇도 보증하지 않습니다 — 같은 코드가 당신 환경에서 빌드되는지는 측정한 적이 없습니다. 통과한 계약 영수증을 낸 서로 다른 서명 키의 수입니다. 하나면 작성자 혼자이고, 둘 이상이면 다른 사람도 빌드했다는 뜻입니다. 키는 스스로 만드는 것이고 뒤에 등록된 신원이 없으므로, 세는 것은 사람이 아니라 키입니다. MIT-0

실행 증거

선언된 환경과 서명된 실행을 분리해 두었습니다. 이 샘플이 무엇을 어디서 실행했는지 그대로 볼 수 있습니다.

증거 기준
서명된 컨트랙트 통과
검증 영수증
1
빌드한 서명 키
1
선언된 환경 node 22.23 linux 24 · ubuntu · glibc 2.39 x64 node 22.23 javascript npm 10

검증 실행 환경

환경 컨트랙트 단계 실행일
node 22 · linux debian/x64 · docker ed25519:c1973797be207ac4 PASS compile:SKIPPED · contract:PASS · load:PASS · resolve:PASS
CONTAINER_RUN · node-typescript@1node:22@sha256:8a34c4ab3ea2…
2026-09-06

케이스

HOW
목표
verify dom-accessibility-api.computeAccessibleName in pkg:npm/dom-accessibility-api@0.6.3
패키지
심벌
  • dom-accessibility-api.computeAccessibleName
환경
node 22.23.2
생성일
2026-09-06T14:31:46Z

컨트랙트

  1. computeAccessibleName resolves accessible name from aria-label with highest precedence over text content
  2. computeAccessibleName resolves accessible name from element subtree text
  3. computeAccessibleName resolves accessible name referencing other elements via aria-labelledby
  4. computeAccessibleName resolves accessible name referencing multiple elements via space-separated aria-labelledby IDs
  5. computeAccessibleName returns empty string for elements with generic role that prohibit naming
  6. computeAccessibleName resolves accessible name from input element using aria-label

파일

  • PROMPT.md
  • csx.json
  • package-lock.json
  • package.json
  • spec.json
  • src/index.js
  • test/contract.mjs

소스 아티팩트 내려받기 (tar.gz)

소스

PROMPT.md
Clean-room public code sample — generation instructions

Write a brand-new, minimal, self-contained code sample in this clean-room directory.
Do not copy, paraphrase, or reference any existing project source. Work only from this spec.

A csx.json manifest scaffold already exists. Do not recreate it from memory. Preserve its case.goal, packages and symbols; fill its empty case.contract with exact assertions and correct its environment, commands and verifierAdapter for the files you generate.

Goal: verify dom-accessibility-api.computeAccessibleName in pkg:npm/dom-accessibility-api@0.6.3
Kind: HOW

Use EXACTLY these public packages and versions:
  - pkg:npm/dom-accessibility-api@0.6.3
Demonstrate these symbols/APIs:
  - dom-accessibility-api.computeAccessibleName

Rules:
  - One focused purpose; the smallest project that proves the goal.
  - Include a contract test (test/contract.*) that runs OFFLINE and exits 0 exactly when the goal behavior works.
  - Pin every dependency with a lockfile so resolution is reproducible.
  - No secrets, credentials, or tokens. No real URLs (only example.com or localhost). No absolute paths.
  - No personal names, emails, company names, or project identifiers of any kind.
  - No binaries and no generated output (node_modules, dist, target, venv, .git, .env).
  - Keep it under 200 files and 256KB packed.
csx.json
{"case":{"caseId":"case:sha256:951aceb6804586de08ffd986379403b302f02b91ac72628c9ac0edb8d5b97553","contract":["computeAccessibleName resolves accessible name from aria-label with highest precedence over text content","computeAccessibleName resolves accessible name from element subtree text","computeAccessibleName resolves accessible name referencing other elements via aria-labelledby","computeAccessibleName resolves accessible name referencing multiple elements via space-separated aria-labelledby IDs","computeAccessibleName returns empty string for elements with generic role that prohibit naming","computeAccessibleName resolves accessible name from input element using aria-label"],"goal":"verify dom-accessibility-api.computeAccessibleName in pkg:npm/dom-accessibility-api@0.6.3","kind":"HOW","packages":["pkg:npm/dom-accessibility-api@0.6.3"],"schemaVersion":1,"symbols":["dom-accessibility-api.computeAccessibleName"]},"contractCommand":["node","test/contract.mjs"],"environment":{"arch":"x64","distro":"ubuntu","ecosystem":"npm","executionContext":"node","language":"javascript","libc":"glibc","libcVersion":"2.39","moduleSystem":"esm","os":"linux","osVersionBucket":"24","packageManager":"npm","packageManagerVersion":"10.9.8","runtime":"node","runtimeVersion":"22.23.2","schemaVersion":1},"license":"MIT-0","packages":["pkg:npm/dom-accessibility-api@0.6.3"],"schemaVersion":1,"subject":"pkg:npm/dom-accessibility-api@0.6.3","symbols":["dom-accessibility-api.computeAccessibleName"],"verifierAdapter":"node-typescript@1"}
package-lock.json
{
  "name": "sample-dom-accessibility-api",
  "version": "1.0.0",
  "lockfileVersion": 3,
  "requires": true,
  "packages": {
    "": {
      "name": "sample-dom-accessibility-api",
      "version": "1.0.0",
      "license": "MIT-0",
      "dependencies": {
        "dom-accessibility-api": "0.6.3"
      }
    },
    "node_modules/dom-accessibility-api": {
      "version": "0.6.3",
      "resolved": "https://registry.npmjs.org/dom-accessibility-api/-/dom-accessibility-api-0.6.3.tgz",
      "integrity": "sha512-7ZgogeTnjuHbo+ct10G9Ffp0mif17idi0IyWNVA/wcwcm7NPOD/WEHVP3n7n3MhXqxoIYm8d6MuZohYWIZ4T3w==",
      "license": "MIT"
    }
  }
}
package.json
{
  "name": "sample-dom-accessibility-api",
  "version": "1.0.0",
  "private": true,
  "type": "module",
  "description": "Clean-room verification for dom-accessibility-api computeAccessibleName",
  "main": "src/index.js",
  "scripts": {
    "test": "node test/contract.mjs"
  },
  "dependencies": {
    "dom-accessibility-api": "0.6.3"
  },
  "license": "MIT-0"
}
spec.json
{
  "schemaVersion": 1,
  "goal": "verify dom-accessibility-api.computeAccessibleName in pkg:npm/dom-accessibility-api@0.6.3",
  "kind": "HOW",
  "packages": [
    "pkg:npm/dom-accessibility-api@0.6.3"
  ],
  "symbols": [
    "dom-accessibility-api.computeAccessibleName"
  ]
}
src/index.js
import { computeAccessibleName } from 'dom-accessibility-api';

/**
 * Creates a lightweight DOM Element node suitable for accessibility calculations in headless environments.
 * @param {string} tagName
 * @param {Record<string, string>} [attributes={}]
 * @param {Array<string | object>} [children=[]]
 * @param {Map<string, object>} [registry]
 * @param {Record<string, string>} [styles={}]
 * @returns {object}
 */
export function createMockElement(tagName, attributes = {}, children = [], registry = new Map(), styles = {}) {
  const attrs = new Map(Object.entries(attributes));
  const styleMap = new Map(Object.entries(styles));

  const mockDoc = {
    defaultView: {
      getComputedStyle: (node) => {
        if (node && node.getComputedStyle) {
          return node.getComputedStyle();
        }
        return {
          getPropertyValue: () => '',
        };
      },
    },
    getElementById: (id) => registry.get(id) ?? null,
    querySelectorAll: () => [],
  };

  const element = {
    nodeType: 1, // ELEMENT_NODE
    ELEMENT_NODE: 1,
    TEXT_NODE: 3,
    tagName: tagName.toUpperCase(),
    localName: tagName.toLowerCase(),
    ownerDocument: mockDoc,
    childNodes: [],
    getComputedStyle() {
      return {
        getPropertyValue: (prop) => styleMap.get(prop) ?? '',
      };
    },
    getAttribute(name) {
      return attrs.get(name) ?? null;
    },
    getAttributeNode(name) {
      if (!attrs.has(name)) return null;
      return { value: attrs.get(name) };
    },
    hasAttribute(name) {
      return attrs.has(name);
    },
    querySelectorAll() {
      return [];
    },
  };

  if (attributes.id) {
    registry.set(attributes.id, element);
  }

  element.childNodes = children.map((child) => {
    if (typeof child === 'string') {
      return {
        nodeType: 3, // TEXT_NODE
        ELEMENT_NODE: 1,
        TEXT_NODE: 3,
        textContent: child,
        ownerDocument: mockDoc,
        childNodes: [],
        parentNode: element,
      };
    }
    child.parentNode = element;
    return child;
  });

  return element;
}

/**
 * Computes the accessible name for a DOM element.
 * @param {object} element
 * @param {object} [options]
 * @returns {string}
 */
export function getAccessibleName(element, options) {
  return computeAccessibleName(element, options);
}

export { computeAccessibleName };
test/contract.mjs
import assert from 'node:assert/strict';
import {
  computeAccessibleName,
  createMockElement,
  getAccessibleName,
} from '../src/index.js';

// 1. computeAccessibleName resolves accessible name from aria-label with highest precedence over text content
const ariaLabelBtn = createMockElement('button', { 'aria-label': 'Close Window' }, ['X']);
assert.equal(computeAccessibleName(ariaLabelBtn), 'Close Window', 'aria-label must take precedence over text content');
assert.equal(getAccessibleName(ariaLabelBtn), 'Close Window', 'helper function returns identical result');

// 2. computeAccessibleName resolves accessible name from element subtree text
const textButton = createMockElement('button', {}, [
  createMockElement('span', {}, ['Save']),
  ' ',
  createMockElement('span', {}, ['Document']),
]);
assert.equal(computeAccessibleName(textButton), 'Save Document', 'accessible name must accumulate subtree text');

// 3. computeAccessibleName resolves accessible name referencing other elements via aria-labelledby
const registry1 = new Map();
const labelEl = createMockElement('span', { id: 'title-id' }, ['Billing Section'], registry1);
const sectionEl = createMockElement('section', { 'aria-labelledby': 'title-id' }, [], registry1);
assert.equal(computeAccessibleName(sectionEl), 'Billing Section', 'aria-labelledby must resolve referenced element text');

// 4. computeAccessibleName resolves accessible name referencing multiple elements via space-separated aria-labelledby IDs
const registry2 = new Map();
const firstPart = createMockElement('span', { id: 'part-one' }, ['Primary'], registry2);
const lastPart = createMockElement('span', { id: 'part-two' }, ['Action'], registry2);
const container = createMockElement('div', { role: 'group', 'aria-labelledby': 'part-one part-two' }, [], registry2);
assert.equal(computeAccessibleName(container), 'Primary Action', 'aria-labelledby must join multiple referenced elements');

// 5. computeAccessibleName returns empty string for elements with generic role that prohibit naming
const genericWithAriaLabel = createMockElement('div', { role: 'generic', 'aria-label': 'Forbidden Name' });
assert.equal(computeAccessibleName(genericWithAriaLabel), '', 'generic role prohibits accessible name');

// 6. computeAccessibleName resolves accessible name from input element using aria-label
const ariaLabelInput = createMockElement('input', { type: 'text', 'aria-label': 'Search Query' });
assert.equal(computeAccessibleName(ariaLabelInput), 'Search Query', 'aria-label on input must be returned');

console.log('All contract assertions passed successfully.');

오리진 시더

익명