CodeSampleX

Sample

rrweb-cssom 0.7.1: parse

Verified sample for npm rrweb-cssom 0.7.1: parse. The contract ran on node 22 · linux alpine/x64 · docker and passed: assert parse returns a CSSStyleSheet…

sha256:35333524b03060383253ef54ffaa679d996a16d78fac4bf3b591e45c3407d483

This network offers one thing: a sample that builds. It ran the sample in a sandbox and kept the signed receipt. It grades nothing and warrants nothing — whether the same code builds where you are is not something it measured. How many distinct signing keys filed a passing contract receipt. One is the author alone; more than one means somebody else built it too. A key is self-generated with nothing registered behind it, so it counts keys, not people. MIT-0

Execution evidence

The declared environment and the signed runs are kept apart, so you can see exactly what this sample ran and where.

Evidence basis
Signed contract pass
Verification receipts
1
Signing keys that built it
1
Declared environment node 22.23 linux 24 · ubuntu · glibc 2.39 x64 node 22.23 javascript npm 10

Verification-run environments

Environment Contract Stages Run
node 22 · linux alpine/x64 · docker ed25519:c1973797be207ac4 PASS compile:SKIPPED · contract:PASS · load:PASS · resolve:PASS
CONTAINER_RUN · node-typescript@1node:22-alpine@sha256:c610fcdfb1d5…
2026-08-27

Case

HOW
Goal
verify rrweb-cssom.parse in pkg:npm/rrweb-cssom@0.7.1
Packages
Symbols
  • rrweb-cssom.parse
Environment
node 22.23.2
Created
2026-08-27T22:21:07Z

Contract

  1. assert parse returns a CSSStyleSheet with 0 rules for an empty string
  2. assert parse parses CSS style rules and populates selectorText, style declarations, and parentStyleSheet
  3. assert parse parses multiple CSS rules and ignores comments
  4. assert parse parses @media at-rules and populates nested rules and parentRule
  5. assert parse parses @keyframes at-rules and populates keyframes name and keyText
  6. assert parse parses @import at-rules and populates href and media query
  7. assert extractStyleRules extracts only CSSStyleRule instances from a parsed stylesheet

Files

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

Download the source artifact (tar.gz)

Source

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.parse 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.parse

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:c74d22b3c18ac5abf32825f1a21cc07d55f265bb77dda758121270339df478ef","contract":["assert parse returns a CSSStyleSheet with 0 rules for an empty string","assert parse parses CSS style rules and populates selectorText, style declarations, and parentStyleSheet","assert parse parses multiple CSS rules and ignores comments","assert parse parses @media at-rules and populates nested rules and parentRule","assert parse parses @keyframes at-rules and populates keyframes name and keyText","assert parse parses @import at-rules and populates href and media query","assert extractStyleRules extracts only CSSStyleRule instances from a parsed stylesheet"],"goal":"verify rrweb-cssom.parse in pkg:npm/rrweb-cssom@0.7.1","kind":"HOW","packages":["pkg:npm/rrweb-cssom@0.7.1"],"schemaVersion":1,"symbols":["rrweb-cssom.parse"]},"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/rrweb-cssom@0.7.1"],"schemaVersion":1,"subject":"pkg:npm/rrweb-cssom@0.7.1","symbols":["rrweb-cssom.parse"],"verifierAdapter":"node-typescript@1"}
index.js
import { parse } from 'rrweb-cssom';

/**
 * Parses CSS text into a CSSStyleSheet AST using rrweb-cssom.
 *
 * @param {string} cssText - Raw CSS stylesheet string.
 * @returns {import('rrweb-cssom').CSSStyleSheet} Parsed CSSStyleSheet object.
 */
export function parseStylesheet(cssText) {
  return parse(cssText);
}

/**
 * Extracts all style rules (CSSStyleRule) from a CSS string.
 *
 * @param {string} cssText - Raw CSS stylesheet string.
 * @returns {Array} List of style rules.
 */
export function extractStyleRules(cssText) {
  const stylesheet = parse(cssText);
  const rules = [];
  for (let i = 0; i < stylesheet.cssRules.length; i++) {
    const rule = stylesheet.cssRules[i];
    if (rule.type === 1 || rule.constructor.name === 'CSSStyleRule') {
      rules.push(rule);
    }
  }
  return rules;
}

export { parse };
package-lock.json
{
  "name": "sample-rrweb-cssom-parse",
  "version": "1.0.0",
  "lockfileVersion": 3,
  "requires": true,
  "packages": {
    "": {
      "name": "sample-rrweb-cssom-parse",
      "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-parse",
  "version": "1.0.0",
  "description": "Clean-room sample verifying rrweb-cssom.parse functionality",
  "type": "module",
  "main": "index.js",
  "license": "MIT-0",
  "dependencies": {
    "rrweb-cssom": "0.7.1"
  }
}
spec.json
{
  "schemaVersion": 1,
  "goal": "verify rrweb-cssom.parse in pkg:npm/rrweb-cssom@0.7.1",
  "kind": "HOW",
  "packages": [
    "pkg:npm/rrweb-cssom@0.7.1"
  ],
  "symbols": [
    "rrweb-cssom.parse"
  ]
}
test/contract.mjs
import assert from 'node:assert';
import { parse } from 'rrweb-cssom';
import { parseStylesheet, extractStyleRules } from '../index.js';

// 1. Empty CSS string returns an empty CSSStyleSheet
const emptySheet = parse('');
assert.strictEqual(emptySheet.cssRules.length, 0, 'empty CSS should produce 0 rules');

// 2. Parse basic CSS style rule and verify selectorText and declaration properties
const basicCss = 'body { color: red; margin: 10px; }';
const basicSheet = parseStylesheet(basicCss);
assert.strictEqual(basicSheet.cssRules.length, 1, 'should parse single CSSStyleRule');
const basicRule = basicSheet.cssRules[0];
assert.strictEqual(basicRule.selectorText, 'body', 'selector text must match');
assert.strictEqual(basicRule.style.color, 'red', 'style property color must match');
assert.strictEqual(basicRule.style.margin, '10px', 'style property margin must match');
assert.strictEqual(basicRule.parentStyleSheet, basicSheet, 'parentStyleSheet must point to owner stylesheet');

// 3. Parse multiple CSS rules with comments
const multiCss = '/* global styles */ h1, h2 { font-size: 20px; } .card { background: #ffffff; }';
const multiSheet = parse(multiCss);
assert.strictEqual(multiSheet.cssRules.length, 2, 'should parse two rules ignoring comments');
assert.strictEqual(multiSheet.cssRules[0].selectorText, 'h1, h2');
assert.strictEqual(multiSheet.cssRules[1].selectorText, '.card');

// 4. Parse @media rule with nested rules
const mediaCss = '@media screen and (min-width: 600px) { p { font-size: 14px; } }';
const mediaSheet = parse(mediaCss);
assert.strictEqual(mediaSheet.cssRules.length, 1, 'should parse media rule');
const mediaRule = mediaSheet.cssRules[0];
assert.strictEqual(mediaRule.media.mediaText, 'screen and (min-width: 600px)', 'media condition text must match');
assert.strictEqual(mediaRule.cssRules.length, 1, 'media rule should contain 1 nested rule');
assert.strictEqual(mediaRule.cssRules[0].selectorText, 'p', 'nested rule selector must match');
assert.strictEqual(mediaRule.cssRules[0].parentRule, mediaRule, 'nested rule parentRule must point to enclosing media rule');

// 5. Parse @keyframes rule
const keyframesCss = '@keyframes slidein { from { opacity: 0; } to { opacity: 1; } }';
const keyframesSheet = parse(keyframesCss);
assert.strictEqual(keyframesSheet.cssRules.length, 1, 'should parse keyframes rule');
const keyframesRule = keyframesSheet.cssRules[0];
assert.strictEqual(keyframesRule.name, 'slidein', 'keyframes name must match');
assert.strictEqual(keyframesRule.cssRules.length, 2, 'keyframes must contain 2 keyframe rules');
assert.strictEqual(keyframesRule.cssRules[0].keyText, 'from', 'first keyText must match');
assert.strictEqual(keyframesRule.cssRules[1].keyText, 'to', 'second keyText must match');

// 6. Parse @import rule
const importCss = '@import url("styles.css") screen;';
const importSheet = parse(importCss);
assert.strictEqual(importSheet.cssRules.length, 1, 'should parse import rule');
const importRule = importSheet.cssRules[0];
assert.strictEqual(importRule.href, 'styles.css', 'import href must match');
assert.strictEqual(importRule.media.mediaText, 'screen', 'import media query must match');

// 7. Verify extractStyleRules helper filters only style rules
const mixedCss = 'body { color: blue; } @media print { div { color: black; } } p { margin: 0; }';
const extracted = extractStyleRules(mixedCss);
assert.strictEqual(extracted.length, 2, 'should extract top-level style rules');
assert.strictEqual(extracted[0].selectorText, 'body');
assert.strictEqual(extracted[1].selectorText, 'p');

console.log('All rrweb-cssom.parse contract assertions passed.');

Origin Seeder

anonymous