import { assertNever } from "@opticss/util" ; import { HasNamespace , ValueConstant , ValueUnknown , isConstant , isUnknown , } from "./Attribute" ; export type Tag = Tagname | TagnameNS ; export interface TagnameValueChoice { oneOf : Array < string > ; } export function isTagChoice ( value ) { return ( < TagnameValueChoice > value ) . oneOf !== undefined ; } export function isTagnameValueChoice ( v ) { return Object . keys ( v ) . includes ( "oneOf" ) ; } export type TagnameValue = ValueUnknown | ValueConstant | TagnameValueChoice ; export interface SerializedTagname { namespaceURL ? : string | null ; value : TagnameValue ; } export abstract class TagnameBase implements HasNamespace { private _namespaceURL : string | null ; private _value : TagnameValue ; constructor ( namespaceURL , value ) { this . _namespaceURL = namespaceURL || null ; this . _value = value ; } get namespaceURL ( ) : string | null { return this . _namespaceURL ; } get value ( ) : TagnameValue { return this . _value ; } isStatic ( ) { if ( isConstant ( this . value ) ) { return true ; } else if ( isTagnameValueChoice ( this . value ) ) { return false ; } else if ( isUnknown ( this . value ) ) { return false ; } else { return assertNever ( this . value ) ; } } valueToString ( ) { if ( isUnknown ( this . value ) ) { return "???" ; } else if ( isConstant ( this . value ) ) { return this . value . constant ; } else if ( isTagChoice ( this . value ) ) { return this . value . oneOf . join ( "|" ) ; } else { return assertNever ( this . value ) ; } } toString ( ) { if ( this . namespaceURL === null ) { return `${ this . valueToString ( ) }` ; } else { return `${ this . namespaceURL }:${ this . valueToString ( ) }` ; } } toJSON ( ) { let result = { value : this . value , } ; if ( this . namespaceURL ) { result . namespaceURL = this . namespaceURL ; } return result ; } static fromJSON ( json ) { if ( json . namespaceURL ) { return new TagnameNS ( json . namespaceURL , json . value as ValueConstant ) ; } else { return new Tagname ( json . value as ValueConstant ) ; } } } export class TagnameNS extends TagnameBase { constructor ( namespaceURL , value ) { super ( namespaceURL , value ) ; } } export class Tagname extends TagnameBase { constructor ( value ) { super ( null , value ) ; } }