Module: StimulusPlumbers::Themes::Schema::Icon

Extended by:
Icon
Included in:
Icon
Defined in:
lib/stimulus_plumbers/themes/schema/icon.rb

Constant Summary collapse

SVG_ATTR_DEFAULTS =
{
  xmlns:        "http://www.w3.org/2000/svg",
  fill:         "none",
  view_box:     "0 0 24 24",
  width:        "24",
  height:       "24",
  stroke:       "currentColor",
  stroke_width: 1.5
}.freeze
SVG_ATTR_NAMES =
{
  view_box:     "viewBox",
  stroke_width: "stroke-width"
}.freeze
ELEMENT_ATTRS =
{
  path:     %i[d fill fill_rule clip_rule stroke_linecap stroke_linejoin opacity].freeze,
  circle:   %i[cx cy r].freeze,
  ellipse:  %i[cx cy rx ry].freeze,
  rect:     %i[x y width height rx ry].freeze,
  line:     %i[x1 y1 x2 y2].freeze,
  polyline: %i[points].freeze,
  polygon:  %i[points].freeze
}.freeze
ELEMENT_ATTR_NAMES =
{
  fill_rule:       "fill-rule",
  clip_rule:       "clip-rule",
  stroke_width:    "stroke-width",
  stroke_linecap:  "stroke-linecap",
  stroke_linejoin: "stroke-linejoin"
}.freeze

Instance Method Summary collapse

Instance Method Details

#resolve(icon_data) ⇒ Object



42
43
44
45
46
47
48
49
50
51
52
53
54
55
# File 'lib/stimulus_plumbers/themes/schema/icon.rb', line 42

def resolve(icon_data)
  return unless icon_data.is_a?(Hash)

  elements = Array(icon_data[:elements]).filter_map do |element|
    next unless element.is_a?(Hash) && ELEMENT_ATTRS.key?(element[:tag])

    { tag: element[:tag] }.merge(resolve_element_attrs(element))
  end
  return if elements.empty?

  resolve_svg_attrs(icon_data).tap do |attrs|
    attrs[:elements] = elements
  end
end