CodeSampleX

샘플

rrweb-cssom 0.7.1: CSSStyleDeclaration

검증된 샘플 — npm rrweb-cssom 0.7.1: CSSStyleDeclaration. node 22 · linux debian/x64 · docker에서 contract를 실행해 통과했습니다: CSSStyleDeclaration parses cssText…

sha256:139e6b7cc6c25ea45df1f72be3005b83e84c863ba04d8a5b9fae35f904f335d6

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

실행 증거

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

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

검증 실행 환경

환경 컨트랙트 단계 실행일
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-03

케이스

HOW
목표
verify rrweb-cssom.CSSStyleDeclaration in pkg:npm/rrweb-cssom@0.7.1
패키지
심벌
  • rrweb-cssom.CSSStyleDeclaration
생성일
2026-09-03T14:02:48Z

컨트랙트

  1. CSSStyleDeclaration parses cssText declarations into indexed properties, values, and priority
  2. CSSStyleDeclaration.getPropertyValue retrieves property values and returns empty string for missing properties
  3. CSSStyleDeclaration.getPropertyPriority returns important for important declarations and empty string otherwise
  4. CSSStyleDeclaration.setProperty adds or updates CSS properties with optional priority
  5. CSSStyleDeclaration.removeProperty removes existing property, returns old value, and updates declaration length
  6. CSSStyleDeclaration.cssText getter serializes declaration list to CSS format
  7. CSSStyleDeclaration is attached as style property on parsed CSSStyleRule instances
  8. Helper functions createStyleDeclaration and inspectStyleDeclaration provide convenient declaration creation and inspection

파일

  • PROMPT.md
  • csx.json
  • package-lock.json
  • package.json
  • spec.json
  • src/index.mjs
  • 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 rrweb-cssom.CSSStyleDeclaration in pkg:npm/rrweb-cssom@0.7.1
Kind: HOW

Use EXACTLY these public packages and versions:
  - pkg:npm/rrweb-cssom@0.7.1
Demonstrate these symbols/APIs:
  - rrweb-cssom.CSSStyleDeclaration

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:9a1ae33ded71d9f5f4ab864c751b0bdb4bb3e63fc9dc81316fdbad4f43574075","contract":["CSSStyleDeclaration parses cssText declarations into indexed properties, values, and priority","CSSStyleDeclaration.getPropertyValue retrieves property values and returns empty string for missing properties","CSSStyleDeclaration.getPropertyPriority returns important for important declarations and empty string otherwise","CSSStyleDeclaration.setProperty adds or updates CSS properties with optional priority","CSSStyleDeclaration.removeProperty removes existing property, returns old value, and updates declaration length","CSSStyleDeclaration.cssText getter serializes declaration list to CSS format","CSSStyleDeclaration is attached as style property on parsed CSSStyleRule instances","Helper functions createStyleDeclaration and inspectStyleDeclaration provide convenient declaration creation and inspection"],"goal":"verify rrweb-cssom.CSSStyleDeclaration in pkg:npm/rrweb-cssom@0.7.1","kind":"HOW","packages":["pkg:npm/rrweb-cssom@0.7.1"],"schemaVersion":1,"symbols":["rrweb-cssom.CSSStyleDeclaration"]},"contractCommand":["node","test/contract.mjs"],"environment":{"arch":"x64","distro":"ubuntu","ecosystem":"npm","libc":"glibc","libcVersion":"2.39","os":"linux","osVersionBucket":"24","packageManager":"npm","schemaVersion":1},"license":"MIT-0","packages":["pkg:npm/rrweb-cssom@0.7.1"],"schemaVersion":1,"subject":"pkg:npm/rrweb-cssom@0.7.1","symbols":["rrweb-cssom.CSSStyleDeclaration"],"verifierAdapter":"node-typescript@1"}
package-lock.json
{
  "name": "sample-rrweb-cssom",
  "version": "1.0.0",
  "lockfileVersion": 3,
  "requires": true,
  "packages": {
    "": {
      "name": "sample-rrweb-cssom",
      "version": "1.0.0",
      "license": "MIT-0",
      "dependencies": {
        "rrweb-cssom": "0.7.1"
      }
    },
    "node_modules/rrweb-cssom": {
      "version": "0.7.1",
      "resolved": "https://registry.npmjs.org/rrweb-cssom/-/rrweb-cssom-0.7.1.tgz",
      "integrity": "sha512-TrEMa7JGdVm0UThDJSx7ddw5nVm3UJS9o9CCIZ72B1vSyEZoziDqBYP3XIoi/12lKrJR8rE3jeFHMok2F/Mnsg==",
      "license": "MIT"
    }
  }
}
package.json
{
  "name": "sample-rrweb-cssom",
  "version": "1.0.0",
  "type": "module",
  "private": true,
  "license": "MIT-0",
  "scripts": {
    "test": "node test/contract.mjs"
  },
  "dependencies": {
    "rrweb-cssom": "0.7.1"
  }
}
spec.json
{
  "schemaVersion": 1,
  "goal": "verify rrweb-cssom.CSSStyleDeclaration in pkg:npm/rrweb-cssom@0.7.1",
  "kind": "HOW",
  "packages": [
    "pkg:npm/rrweb-cssom@0.7.1"
  ],
  "symbols": [
    "rrweb-cssom.CSSStyleDeclaration"
  ]
}
src/index.mjs
import { CSSStyleDeclaration, parse } from 'rrweb-cssom';

/**
 * Creates a CSSStyleDeclaration instance optionally initialized with cssText.
 * @param {string} [cssText=''] Optional CSS declaration string.
 * @returns {CSSStyleDeclaration} Initialized style declaration instance.
 */
export function createStyleDeclaration(cssText = '') {
  const style = new CSSStyleDeclaration();
  if (cssText) {
    style.cssText = cssText;
  }
  return style;
}

/**
 * Inspects all declarations in a CSSStyleDeclaration instance.
 * @param {CSSStyleDeclaration} style
 * @returns {Record<string, { value: string, priority: string }>}
 */
export function inspectStyleDeclaration(style) {
  const result = {};
  for (let i = 0; i < style.length; i++) {
    const prop = style[i];
    result[prop] = {
      value: style.getPropertyValue(prop),
      priority: style.getPropertyPriority(prop),
    };
  }
  return result;
}

export { CSSStyleDeclaration, parse };
export default CSSStyleDeclaration;
test/contract.mjs
import assert from 'node:assert/strict';
import { CSSStyleDeclaration, parse } from 'rrweb-cssom';
import { createStyleDeclaration, inspectStyleDeclaration } from '../src/index.mjs';

// CSSStyleDeclaration parses cssText declarations into indexed properties, values, and priority
{
  const style = new CSSStyleDeclaration();
  style.cssText = 'color: red; background-color: blue !important; font-size: 14px;';
  assert.equal(style.length, 3);
  assert.equal(style[0], 'color');
  assert.equal(style[1], 'background-color');
  assert.equal(style[2], 'font-size');
  assert.equal(style.getPropertyValue('color'), 'red');
  assert.equal(style.getPropertyValue('background-color'), 'blue');
  assert.equal(style.getPropertyPriority('background-color'), 'important');
  assert.equal(style.getPropertyPriority('color'), '');
}

// CSSStyleDeclaration.getPropertyValue retrieves property values and returns empty string for missing properties
{
  const style = new CSSStyleDeclaration();
  style.cssText = 'display: flex; margin-top: 10px;';
  assert.equal(style.getPropertyValue('display'), 'flex');
  assert.equal(style.getPropertyValue('margin-top'), '10px');
  assert.equal(style.getPropertyValue('non-existent-prop'), '');
}

// CSSStyleDeclaration.getPropertyPriority returns important for important declarations and empty string otherwise
{
  const style = new CSSStyleDeclaration();
  style.cssText = 'color: red !important; width: 100px;';
  assert.equal(style.getPropertyPriority('color'), 'important');
  assert.equal(style.getPropertyPriority('width'), '');
}

// CSSStyleDeclaration.setProperty adds or updates CSS properties with optional priority
{
  const style = new CSSStyleDeclaration();
  style.setProperty('margin', '10px');
  assert.equal(style.getPropertyValue('margin'), '10px');
  assert.equal(style.length, 1);
  assert.equal(style[0], 'margin');

  style.setProperty('opacity', '0.5', 'important');
  assert.equal(style.getPropertyValue('opacity'), '0.5');
  assert.equal(style.getPropertyPriority('opacity'), 'important');
  assert.equal(style.length, 2);

  style.setProperty('margin', '20px');
  assert.equal(style.getPropertyValue('margin'), '20px');
}

// CSSStyleDeclaration.removeProperty removes existing property, returns old value, and updates declaration length
{
  const style = new CSSStyleDeclaration();
  style.cssText = 'color: red; padding: 5px;';
  assert.equal(style.length, 2);

  const removed = style.removeProperty('color');
  assert.equal(removed, 'red');
  assert.equal(style.getPropertyValue('color'), '');
  assert.equal(style.length, 1);
  assert.equal(style[0], 'padding');

  const missing = style.removeProperty('non-existent');
  assert.equal(missing, '');
  assert.equal(style.length, 1);
}

// CSSStyleDeclaration.cssText getter serializes declaration list to CSS format
{
  const style = new CSSStyleDeclaration();
  style.setProperty('color', 'red');
  style.setProperty('font-weight', 'bold', 'important');
  assert.equal(style.cssText, 'color: red; font-weight: bold !important;');
}

// CSSStyleDeclaration is attached as style property on parsed CSSStyleRule instances
{
  const stylesheet = parse('.card { color: #fff; padding: 8px !important; }');
  assert.equal(stylesheet.cssRules.length, 1);
  const rule = stylesheet.cssRules[0];
  assert.equal(rule.style instanceof CSSStyleDeclaration, true);
  assert.equal(rule.style.parentRule, rule);
  assert.equal(rule.style.getPropertyValue('color'), '#fff');
  assert.equal(rule.style.getPropertyPriority('padding'), 'important');
  assert.equal(rule.style.length, 2);
}

// Helper functions createStyleDeclaration and inspectStyleDeclaration provide convenient declaration creation and inspection
{
  const emptyStyle = createStyleDeclaration();
  assert.equal(emptyStyle instanceof CSSStyleDeclaration, true);
  assert.equal(emptyStyle.length, 0);

  const initialStyle = createStyleDeclaration('border: 1px solid black; opacity: 1 !important;');
  assert.equal(initialStyle.getPropertyValue('border'), '1px solid black');
  assert.equal(initialStyle.getPropertyPriority('opacity'), 'important');

  const inspected = inspectStyleDeclaration(initialStyle);
  assert.deepEqual(inspected, {
    border: { value: '1px solid black', priority: '' },
    opacity: { value: '1', priority: 'important' },
  });
}

console.log('Contract tests passed successfully.');

오리진 시더

익명