1use turbo_rcstr::{RcStr, rcstr};
2use turbo_tasks::{ResolvedVc, Vc};
3use turbopack_core::{
4 asset::{Asset, AssetContent},
5 chunk::ChunkingContext,
6 ident::AssetIdent,
7 module::{Module, ModuleSideEffects},
8 output::OutputAsset,
9 source::Source,
10};
11use turbopack_css::embed::CssEmbed;
12
13use crate::output_asset::StaticOutputAsset;
14
15#[turbo_tasks::value]
16#[derive(Clone)]
17pub struct StaticUrlCssModule {
18 pub source: ResolvedVc<Box<dyn Source>>,
19 tag: Option<RcStr>,
20}
21
22#[turbo_tasks::value_impl]
23impl StaticUrlCssModule {
24 #[turbo_tasks::function]
25 pub fn new(source: ResolvedVc<Box<dyn Source>>, tag: Option<RcStr>) -> Vc<Self> {
26 Self::cell(StaticUrlCssModule { source, tag })
27 }
28
29 #[turbo_tasks::function]
30 fn static_output_asset(
31 &self,
32 chunking_context: ResolvedVc<Box<dyn ChunkingContext>>,
33 ) -> Vc<StaticOutputAsset> {
34 StaticOutputAsset::new(*chunking_context, *self.source, self.tag.clone())
35 }
36}
37
38#[turbo_tasks::value_impl]
39impl Module for StaticUrlCssModule {
40 #[turbo_tasks::function]
41 fn ident(&self) -> Vc<AssetIdent> {
42 let mut ident = self.source.ident().with_modifier(rcstr!("static in css"));
43 if let Some(tag) = &self.tag {
44 ident = ident.with_modifier(format!("tag {}", tag).into());
45 }
46 ident
47 }
48
49 #[turbo_tasks::function]
50 fn source(&self) -> Vc<turbopack_core::source::OptionSource> {
51 Vc::cell(Some(self.source))
52 }
53
54 #[turbo_tasks::function]
55
56 fn side_effects(self: Vc<Self>) -> Vc<ModuleSideEffects> {
57 ModuleSideEffects::SideEffectFree.cell()
58 }
59}
60
61#[turbo_tasks::value_impl]
62impl Asset for StaticUrlCssModule {
63 #[turbo_tasks::function]
64 fn content(&self) -> Vc<AssetContent> {
65 self.source.content()
66 }
67}
68
69#[turbo_tasks::value_impl]
70impl CssEmbed for StaticUrlCssModule {
71 #[turbo_tasks::function]
72 fn embedded_asset(
73 self: Vc<Self>,
74 chunking_context: Vc<Box<dyn ChunkingContext>>,
75 ) -> Vc<Box<dyn OutputAsset>> {
76 Vc::upcast(self.static_output_asset(chunking_context))
77 }
78}