/* * Copyright (c) 2023, Jonah Shafran * * SPDX-License-Identifier: BSD-2-Clause */ #include #include #include #include #include #include #include namespace Web::CSS { JS_DEFINE_ALLOCATOR(CSSNamespaceRule); CSSNamespaceRule::CSSNamespaceRule(JS::Realm& realm, Optional prefix, StringView namespace_uri) : CSSRule(realm) , m_namespace_uri(namespace_uri) , m_prefix(prefix.value_or(""sv)) { } JS::NonnullGCPtr CSSNamespaceRule::create(JS::Realm& realm, Optional prefix, AK::StringView namespace_uri) { return realm.heap().allocate(realm, realm, prefix, namespace_uri); } void CSSNamespaceRule::initialize(JS::Realm& realm) { Base::initialize(realm); set_prototype(&Bindings::ensure_web_prototype(realm, "CSSNamespaceRule")); } // https://www.w3.org/TR/cssom/#serialize-a-css-rule String CSSNamespaceRule::serialized() const { StringBuilder builder; // The literal string "@namespace", followed by a single SPACE (U+0020), builder.append("@namespace "sv); // followed by the serialization as an identifier of the prefix attribute (if any), if (!m_prefix.is_empty()) { serialize_an_identifier(builder, m_prefix); // followed by a single SPACE (U+0020) if there is a prefix, builder.append(" "sv); } // followed by the serialization as URL of the namespaceURI attribute, serialize_a_url(builder, m_namespace_uri); // followed the character ";" (U+003B). builder.append(";"sv); return MUST(builder.to_string()); } }