rolldown_common/css/
css_view.rs1use arcstr::ArcStr;
2use oxc::span::Span;
3use oxc_index::IndexVec;
4
5use crate::{
6 ImportRecordIdx, ResolvedImportRecord, SourceMutation, types::source_mutation::ArcSourceMutation,
7};
8
9#[derive(Debug, Clone)]
10pub struct CssView {
11 pub source: ArcStr,
12 pub import_records: IndexVec<ImportRecordIdx, ResolvedImportRecord>,
13 pub record_idx_to_span: IndexVec<ImportRecordIdx, Span>,
14 pub mutations: Vec<ArcSourceMutation>,
15}
16
17#[derive(Debug, Default)]
18pub struct CssRenderer {
19 pub at_import_ranges: Vec<(usize, usize)>,
20}
21
22#[derive(Debug)]
23pub struct CssAssetNameReplacer {
24 pub span: Span,
25 pub asset_name: ArcStr,
26}
27
28impl SourceMutation for CssRenderer {
29 fn apply(&self, magic_string: &mut string_wizard::MagicString<'_>) {
30 for range in &self.at_import_ranges {
31 magic_string.remove(range.0, range.1);
32 }
33 }
34}
35
36impl SourceMutation for CssAssetNameReplacer {
37 fn apply(&self, magic_string: &mut string_wizard::MagicString<'_>) {
38 magic_string.update_with(
39 self.span.start as usize,
40 self.span.end as usize,
41 self.asset_name.clone(),
42 string_wizard::UpdateOptions { keep_original: true, overwrite: true },
43 );
44 }
45}