宜搭+
    正在准备搜索索引...

    类 CSSBuilder

    用于链式构建 CSS 样式字符串的构建器。

    CSSBuilder 继承自 Map,以 CSS 属性名为键、属性值为值。 调用方可通过 set 方法逐步追加样式,最终调用 CSSBuilder.toString 生成 property:value; 格式的内联样式字符串。

    26.4.13

    const style = CSSBuilder.from({
    color: "#333",
    "font-size": "14px",
    })
    .set("margin", "8px")
    .toString()
    // "color:#333;font-size:14px;margin:8px;"

    层级

    • Map<string, string>
      • CSSBuilder
    索引

    构造函数

    • 参数

      • 可选entries: readonly (readonly [string, string])[] | null

      返回 CSSBuilder

    • 参数

      • 可选iterable: Iterable<readonly [string, string], any, any> | null

      返回 CSSBuilder

    属性

    "[toStringTag]": string
    size: number

    the number of elements in the Map.

    "[species]": MapConstructor

    方法

    • Returns an iterable of entries in the map.

      返回 MapIterator<[string, string]>

    • Removes all elements from the Map.

      返回 void

    • 参数

      • key: string

      返回 boolean

      true if an element in the Map existed and has been removed, or false if the element does not exist.

    • Returns an iterable of key, value pairs for every entry in the map.

      返回 MapIterator<[string, string]>

    • Executes a provided function once per each key/value pair in the Map, in insertion order.

      参数

      • callbackfn: (value: string, key: string, map: Map<string, string>) => void
      • 可选thisArg: any

      返回 void

    • Returns a specified element from the Map object. If the value that is associated to the provided key is an object, then you will get a reference to that object and any change made to that object will effectively modify it inside the Map.

      参数

      • key: string

      返回 string | undefined

      Returns the element associated with the specified key. If no element is associated with the specified key, undefined is returned.

    • 参数

      • key: string

      返回 boolean

      boolean indicating whether an element with the specified key exists or not.

    • Returns an iterable of keys in the map

      返回 MapIterator<string>

    • Adds a new element with a specified key and value to the Map. If an element with the same key already exists, the element will be updated.

      参数

      • key: string
      • value: string

      返回 this

    • 将当前构建器中所有样式转换为 CSS 字符串。

      每个样式条目将渲染为 property:value; 格式,并按键值对迭代顺序拼接。

      返回 string

      拼接后的 CSS 样式字符串。

      26.4.13

    • Returns an iterable of values in the map

      返回 MapIterator<string>

    • 从普通对象创建新的 CSSBuilder 实例。

      遍历传入对象的所有可枚举属性,将属性名与属性值作为 CSS 属性 名与值存入新的构建器。

      参数

      • source: Record<string, string>

        包含 CSS 属性键值对的对象。

      返回 CSSBuilder

      已填充样式的新 CSSBuilder 实例。

      26.4.13

      const builder = CSSBuilder.from({ padding: "4px 8px" })
      
    • Groups members of an iterable according to the return value of the passed callback.

      类型参数

      • K
      • T

      参数

      • items: Iterable<T>

        An iterable.

      • keySelector: (item: T, index: number) => K

        A callback which will be invoked for each item in items.

      返回 Map<K, T[]>