CodeSampleX

샘플

rrweb-cssom 0.8.0: CSSStyleSheet

검증된 샘플 — npm rrweb-cssom 0.8.0: CSSStyleSheet. node 22 · linux debian/x64 · docker에서 contract를 실행해 통과했습니다: new CSSStyleSheet() initializes an empty…

sha256:4283abc0e3a692a469b01dc0bedf0eeb0c446534325509bbad42b9f84fb1303d

이 네트워크가 제공하는 것은 하나입니다. 빌드되는 샘플. 샌드박스에서 돌리고 서명된 영수증을 보관합니다. 등급을 매기지 않고 무엇도 보증하지 않습니다 — 같은 코드가 당신 환경에서 빌드되는지는 측정한 적이 없습니다. 통과한 계약 영수증을 낸 서로 다른 서명 키의 수입니다. 하나면 작성자 혼자이고, 둘 이상이면 다른 사람도 빌드했다는 뜻입니다. 키는 스스로 만드는 것이고 뒤에 등록된 신원이 없으므로, 세는 것은 사람이 아니라 키입니다. 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 rrweb-cssom.CSSStyleSheet in pkg:npm/rrweb-cssom@0.8.0
패키지
심벌
  • rrweb-cssom.CSSStyleSheet
환경
node 22.23.2
생성일
2026-09-06T02:54:14Z

컨트랙트

  1. new CSSStyleSheet() initializes an empty stylesheet with empty cssRules and null parentStyleSheet
  2. insertRule parses and inserts CSSStyleRule into cssRules and sets parentStyleSheet reference
  3. insertRule supports inserting CSSMediaRule at specific index maintaining rule order
  4. insertRule throws RangeError INDEX_SIZE_ERR when insert index is out of bounds or negative
  5. deleteRule removes rule at index and updates cssRules list
  6. deleteRule throws RangeError INDEX_SIZE_ERR when target index is out of bounds or negative
  7. toString serializes all rules in cssRules to newline-delimited CSS text

파일

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

소스 아티팩트 내려받기 (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.CSSStyleSheet in pkg:npm/rrweb-cssom@0.8.0
Kind: HOW

Use EXACTLY these public packages and versions:
  - pkg:npm/rrweb-cssom@0.8.0
Demonstrate these symbols/APIs:
  - rrweb-cssom.CSSStyleSheet
Constraints:
  - executionContext: node
Required runtime conditions:
  - ecosystem: npm
  - language: javascript
  - moduleSystem: cjs
  - packageManager: npm@10.9.8
  - runtime: node@22.23.2

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:baf85275bc5c2f0de6674ad434ca4f940be1ffa6963af6ea2ca22c7265b310b2","constraints":{"executionContext":"node"},"contract":["new CSSStyleSheet() initializes an empty stylesheet with empty cssRules and null parentStyleSheet","insertRule parses and inserts CSSStyleRule into cssRules and sets parentStyleSheet reference","insertRule supports inserting CSSMediaRule at specific index maintaining rule order","insertRule throws RangeError INDEX_SIZE_ERR when insert index is out of bounds or negative","deleteRule removes rule at index and updates cssRules list","deleteRule throws RangeError INDEX_SIZE_ERR when target index is out of bounds or negative","toString serializes all rules in cssRules to newline-delimited CSS text"],"goal":"verify rrweb-cssom.CSSStyleSheet in pkg:npm/rrweb-cssom@0.8.0","kind":"HOW","packages":["pkg:npm/rrweb-cssom@0.8.0"],"schemaVersion":1,"symbols":["rrweb-cssom.CSSStyleSheet"]},"contractCommand":["node","test/contract.js"],"environment":{"arch":"x64","distro":"ubuntu","ecosystem":"npm","executionContext":"node","language":"javascript","libc":"glibc","libcVersion":"2.39","moduleSystem":"cjs","os":"linux","osVersionBucket":"24","packageManager":"npm","packageManagerVersion":"10.9.8","runtime":"node","runtimeVersion":"22.23.2","schemaVersion":1},"license":"MIT-0","packages":["pkg:npm/rrweb-cssom@0.8.0"],"schemaVersion":1,"subject":"pkg:npm/rrweb-cssom@0.8.0","symbols":["rrweb-cssom.CSSStyleSheet"],"verifierAdapter":"node-typescript@1"}
package-lock.json
{
  "name": "verify-rrweb-cssom-cssstylesheet",
  "version": "1.0.0",
  "lockfileVersion": 3,
  "requires": true,
  "packages": {
    "": {
      "name": "verify-rrweb-cssom-cssstylesheet",
      "version": "1.0.0",
      "license": "MIT-0",
      "dependencies": {
        "rrweb-cssom": "0.8.0"
      }
    },
    "node_modules/rrweb-cssom": {
      "version": "0.8.0",
      "resolved": "https://registry.npmjs.org/rrweb-cssom/-/rrweb-cssom-0.8.0.tgz",
      "integrity": "sha512-guoltQEx+9aMf2gDZ0s62EcV8lsXR+0w8915TC3ITdn2YueuNjdAYh/levpU9nFaoChh9RUS5ZdQMrKfVEN9tw==",
      "license": "MIT"
    }
  }
}
package.json
{
  "name": "verify-rrweb-cssom-cssstylesheet",
  "version": "1.0.0",
  "private": true,
  "description": "Clean-room verification sample for rrweb-cssom.CSSStyleSheet",
  "main": "src/index.js",
  "scripts": {
    "test": "node test/contract.js"
  },
  "dependencies": {
    "rrweb-cssom": "0.8.0"
  },
  "license": "MIT-0"
}
spec.json
{
  "schemaVersion": 1,
  "goal": "verify rrweb-cssom.CSSStyleSheet in pkg:npm/rrweb-cssom@0.8.0",
  "kind": "HOW",
  "packages": [
    "pkg:npm/rrweb-cssom@0.8.0"
  ],
  "symbols": [
    "rrweb-cssom.CSSStyleSheet"
  ],
  "constraints": {
    "executionContext": "node"
  },
  "runtimeConditions": {
    "ecosystem": "npm",
    "language": "javascript",
    "moduleSystem": "cjs",
    "packageManager": "npm@10.9.8",
    "runtime": "node@22.23.2"
  }
}
src/index.js
'use strict';

const { CSSStyleSheet, CSSStyleRule, CSSMediaRule } = require('rrweb-cssom');

/**
 * Creates an empty CSSStyleSheet instance.
 * @returns {CSSStyleSheet}
 */
function createStyleSheet() {
  return new CSSStyleSheet();
}

/**
 * Adds a CSS rule to a stylesheet at the specified index.
 * @param {CSSStyleSheet} sheet
 * @param {string} ruleText
 * @param {number} [index=0]
 * @returns {number}
 */
function addRule(sheet, ruleText, index = 0) {
  return sheet.insertRule(ruleText, index);
}

/**
 * Removes a CSS rule from a stylesheet at the specified index.
 * @param {CSSStyleSheet} sheet
 * @param {number} index
 */
function removeRule(sheet, index) {
  sheet.deleteRule(index);
}

/**
 * Serializes a CSSStyleSheet to CSS text.
 * @param {CSSStyleSheet} sheet
 * @returns {string}
 */
function serializeStyleSheet(sheet) {
  return sheet.toString();
}

module.exports = {
  createStyleSheet,
  addRule,
  removeRule,
  serializeStyleSheet,
  CSSStyleSheet,
  CSSStyleRule,
  CSSMediaRule,
};
test/contract.js
'use strict';

const assert = require('node:assert');
const { CSSStyleSheet, CSSStyleRule, CSSMediaRule } = require('rrweb-cssom');
const {
  createStyleSheet,
  addRule,
  removeRule,
  serializeStyleSheet,
} = require('../src/index.js');

function testCreateEmptyStyleSheet() {
  const sheet = createStyleSheet();
  assert(sheet instanceof CSSStyleSheet, 'Instance should be CSSStyleSheet');
  assert(Array.isArray(sheet.cssRules), 'cssRules should be an array');
  assert.strictEqual(sheet.cssRules.length, 0, 'Initial cssRules should be empty');
  assert.strictEqual(sheet.parentStyleSheet, null, 'Initial parentStyleSheet should be null');
}

function testInsertRuleStyleRule() {
  const sheet = createStyleSheet();
  const index = addRule(sheet, '.card { padding: 16px; margin: 8px; }', 0);
  assert.strictEqual(index, 0, 'Insert index should be 0');
  assert.strictEqual(sheet.cssRules.length, 1, 'cssRules should contain 1 rule');

  const rule = sheet.cssRules[0];
  assert(rule instanceof CSSStyleRule, 'Rule should be CSSStyleRule');
  assert.strictEqual(rule.selectorText, '.card', 'Selector should match');
  assert.strictEqual(rule.style.getPropertyValue('padding'), '16px');
  assert.strictEqual(rule.style.getPropertyValue('margin'), '8px');
  assert.strictEqual(rule.parentStyleSheet, sheet, 'parentStyleSheet should reference stylesheet');
}

function testInsertRuleMediaRuleAndOrdering() {
  const sheet = createStyleSheet();
  sheet.insertRule('body { background: #fff; }', 0);
  sheet.insertRule('h1 { font-size: 2rem; }', 1);
  sheet.insertRule('@media (min-width: 1024px) { body { background: #eee; } }', 1);

  assert.strictEqual(sheet.cssRules.length, 3, 'Should have 3 rules after inserts');
  assert.strictEqual(sheet.cssRules[0].selectorText, 'body');
  assert(sheet.cssRules[1] instanceof CSSMediaRule, 'Second rule should be CSSMediaRule');
  assert.strictEqual(sheet.cssRules[1].media.mediaText, '(min-width: 1024px)');
  assert.strictEqual(sheet.cssRules[1].cssRules.length, 1);
  assert.strictEqual(sheet.cssRules[1].parentStyleSheet, sheet);
  assert.strictEqual(sheet.cssRules[2].selectorText, 'h1');
}

function testInsertRuleOutOfBounds() {
  const sheet = createStyleSheet();
  assert.throws(
    () => {
      sheet.insertRule('p { color: black; }', 5);
    },
    (err) => {
      return err instanceof RangeError && err.message === 'INDEX_SIZE_ERR';
    },
    'Should throw RangeError INDEX_SIZE_ERR for out-of-bounds insert index'
  );

  assert.throws(
    () => {
      sheet.insertRule('p { color: black; }', -1);
    },
    (err) => {
      return err instanceof RangeError && err.message === 'INDEX_SIZE_ERR';
    },
    'Should throw RangeError INDEX_SIZE_ERR for negative insert index'
  );
}

function testDeleteRule() {
  const sheet = createStyleSheet();
  sheet.insertRule('.item-1 { display: flex; }', 0);
  sheet.insertRule('.item-2 { display: block; }', 1);
  sheet.insertRule('.item-3 { display: none; }', 2);

  assert.strictEqual(sheet.cssRules.length, 3);
  removeRule(sheet, 1);

  assert.strictEqual(sheet.cssRules.length, 2, 'Should have 2 rules after deletion');
  assert.strictEqual(sheet.cssRules[0].selectorText, '.item-1');
  assert.strictEqual(sheet.cssRules[1].selectorText, '.item-3');
}

function testDeleteRuleOutOfBounds() {
  const sheet = createStyleSheet();
  assert.strictEqual(sheet.cssRules.length, 0);

  assert.throws(
    () => {
      removeRule(sheet, 0);
    },
    (err) => {
      return err instanceof RangeError && err.message === 'INDEX_SIZE_ERR';
    },
    'Should throw RangeError INDEX_SIZE_ERR when deleting from empty sheet'
  );

  sheet.insertRule('span { color: green; }', 0);
  assert.throws(
    () => {
      removeRule(sheet, 1);
    },
    (err) => {
      return err instanceof RangeError && err.message === 'INDEX_SIZE_ERR';
    },
    'Should throw RangeError INDEX_SIZE_ERR when deleting non-existent index'
  );

  assert.throws(
    () => {
      removeRule(sheet, -1);
    },
    (err) => {
      return err instanceof RangeError && err.message === 'INDEX_SIZE_ERR';
    },
    'Should throw RangeError INDEX_SIZE_ERR when deleting negative index'
  );
}

function testToStringSerialization() {
  const emptySheet = createStyleSheet();
  assert.strictEqual(serializeStyleSheet(emptySheet), '', 'Empty sheet toString should be empty string');

  const sheet = createStyleSheet();
  sheet.insertRule('nav { background-color: #333333; }', 0);
  sheet.insertRule('nav a { color: #ffffff; }', 1);

  const serialized = serializeStyleSheet(sheet);
  assert.strictEqual(typeof serialized, 'string');
  const expected = 'nav {background-color: #333333;}\nnav a {color: #ffffff;}\n';
  assert.strictEqual(serialized, expected, 'Serialized CSS should match inserted rules');
}

function runAll() {
  testCreateEmptyStyleSheet();
  testInsertRuleStyleRule();
  testInsertRuleMediaRuleAndOrdering();
  testInsertRuleOutOfBounds();
  testDeleteRule();
  testDeleteRuleOutOfBounds();
  testToStringSerialization();
  console.log('Contract tests passed successfully.');
}

runAll();

오리진 시더

익명