CodeSampleX

Exemplo

rrweb-cssom 0.7.1: parse

Amostra verificada para npm rrweb-cssom 0.7.1: parse. O contrato rodou em node 22 · linux alpine/x64 · docker e passou: assert parse returns a CSSStyleSheet…

sha256:35333524b03060383253ef54ffaa679d996a16d78fac4bf3b591e45c3407d483

Esta rede oferece uma coisa: uma amostra que compila. Ela a executou em um sandbox e guardou o recibo assinado. Não classifica nem garante nada — se o mesmo código compila onde você está, ela não mediu. Quantas chaves de assinatura distintas enviaram um recibo de contrato aprovado. Uma é só o autor; mais de uma significa que outra pessoa também o compilou. Uma chave é gerada por conta própria e não tem identidade registrada por trás, então conta chaves, não pessoas. MIT-0

Evidência de execução

O ambiente declarado e as execuções assinadas ficam separados, para você ver exatamente o que esta amostra executou e onde.

Base da evidência
Contrato assinado aprovado
Recibos de verificação
1
Chaves de assinatura que o compilaram
1
Ambiente declarado node 22.23 linux 24 · ubuntu · glibc 2.39 x64 node 22.23 javascript npm 10

Ambientes das execuções de verificação

Ambiente Contrato Etapas Execução
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

Caso

HOW
Objetivo
verify rrweb-cssom.parse in pkg:npm/rrweb-cssom@0.7.1
Pacotes
Símbolos
  • rrweb-cssom.parse
Ambiente
node 22.23.2
Criado
2026-08-27T22:21:07Z

Contrato

  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

Arquivos

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

Baixar o artefato de código-fonte (tar.gz)

Código-fonte

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.');

Seeder de origem

anônimo