betobetok/ask-svg

这是一个来自 https://github.com/blade-ui-kit/blade-icons 的扩展

v0.2.4-BETA 2022-09-25 10:20 UTC

This package is auto-updated.

Last update: 2024-09-28 11:50:30 UTC


README

Tests Code Style Latest Stable Version Total Downloads

一个将 SVG 图形文件转换为 PHP 对象的包。基于 Blade UIkit

使用 svg() 函数,我们可以通过文件名检索 SVG 文件,并将其转换为 Svg 类的对象,然后对其进行操作。

$mySvg = svg('my_svg');
dd($mySvg);

svg 文件 my_svg.svg

ASK\Svg\Svg ({)#427 ▼
  #name: "svg"
  #elements: array:1 [▼
    0 => ASK\Svg\Configurators\G ({)#301 ▼
      #name: "g"
      #elements: array:37 [▶]
      #context: ASK\Svg\Svg ({)#427(})
      #transforms: ASK\Svg\Transformation ({)#424 ▼
        #transformations: array:1 [▼
          0 => array:1 [▼
            "matrix" => NumPHP\Core\NumArray ({)#423 ▶(})
          ]
        ]
      (})
      #isTransformable: true
      -attributes: array:1 [▶]
      +"g": array:37 [▶]
    (})
  ]
  #context: null
  #isTransformable: false
  -attributes: array:6 [▼
    "id" => "my_svg"
    "width" => "473"
    "height" => "477"
    "viewBox" => "0 0 473 477"
    "fill" => "none"
    "xmlns" => "http://www.w3.org/2000/svg"
  ]
  +style: ASK\Svg\Configurators\Style ({)#426 ▼
    #name: "style"
    #context: ASK\Svg\Svg ({)#427(})
    #isTransformable: false
    -attributes: []
    -classes: []
    -rules: []
  (})
  +"g": array:1 [▼
    0 => ASK\Svg\Configurators\G ({)#301 ▶(})
  ]
(})

Svg 类

 Full name: \ASK\Svg\Svg

Svg 文档

Svg 实现: \ASK\Svg\Conteiner

Svg 属性

类属性

Svg 方法

类方法

Svg :: 构造函数

Svg (string fileName, string contents, array attributes = []): mixed

返回

Svg :: getStylefromContent

从字符串内容中获取 Style 元素

public getStylefromContent(): string

返回

Svg :: removeStylefromContent

从字符串内容中移除字符串 Style

public removeStylefromContent(): self

返回

Svg :: style

获取 Style 元素

public style(): Configurators\Style

返回

Svg :: setStyle

设置 Style 元素

public setStyle(Configurators\Style style): self

返回

Svg :: replaceClasses

替换字符串内容中的类名

public replaceClasses(Configurators\Style style, string content): string

返回

Svg :: mergeSvgs

将一个或多个 Svg 合并到这个 svg 中

public mergeSvgs(Svg[] param): Svg

返回

Svg :: toHtml

实现了 Htmlable,toHtml 返回 HTML 格式的 SVG 字符串

public toHtml(): string

返回

Svg :: getAllSvgElements

获取此 svg 中所有 Svg 元素,此数组包含所有元素按顺序

public getAllSvgElements(mixed svg): array

返回

Svg :: cleanContent

cleanContent 从完整对象中移除所有字符串内容

public cleanContent(): self

返回

Svg :: getContent

获取内容值 (Conteiner 实现) //TODO 容器实现

public getContent(): mixed

返回

Svg :: setContent

设置内容值 (Conteiner 实现) //TODO 容器实现

public setContent(mixed content): self

返回

Svg :: removeSvgAttribute

移除那些仅属于 svg 元素的属性

public removeSvgAttribute(): void

返回

Svg :: getOnlySvgAttribute

获取那些仅属于 svg 元素的属性

public getOnlySvgAttribute(): array

返回

SvgElement 类

 Full name: \ASK\Svg\SvgElement

属于 svg 结构的元素

此对象表示 svg 文档中的所有元素

从 svg 父元素到内部元素或图形,如 <path>、<circle> 或 <g>,通过配置元素如 <style>、<defs> 等等

所有元素都可以通过属性 $elements 按顺序访问,也可以通过具有元素名称的属性中的数组访问

例如

  • $svg->g 返回所有 <g> 元素
  • $svg->elements[0] 返回 <svg></svg> 中的第一个元素
  • $svg->g[0]->elements[0] 返回 <g></g> 中的第一个元素

SvgElement 实现: \Illuminate\Contracts\Support\Htmlable

SvgElement 属性

类属性

SvgElement 方法

类方法

SvgElement :: 构造函数

SvgElement (string name, string contents, array attributes = [], SvgElement context = null): mixed

返回

SvgElement :: makeTransformable

使此元素可变换

public makeTransformable(): void

返回

SvgElement :: makeUntransformable

使此元素不可变换

public makeUntransformable(): void

返回

SvgElement :: name

获取或设置元素的名称

public name(string arg = &#039;&#039;): string|self

返回

SvgElement :: id

获取或设置元素在 attributes 属性中的 id 属性

public id(string arg = &#039;&#039;): string|self

返回

SvgElement :: transform

设置或获取元素的变换对象

public transform(mixed arg = null): Transformation|string

返回

SvgElement :: contents

获取元素的字符串内容

  • 此方法类似于 toHtml,但只获取内容的字符串,不包含标签字符串
public contents(): string

返回

SvgElement :: removeContents

从对象中移除字符串 Contents 属性

public removeContents(): self

返回

SvgElement :: setContents

在对象中设置字符串 Contents 属性

public setContents(string contents): self

返回

SvgElement :: getContext

获取属性Context,即此元素的父SVG元素

public getContext(): SvgElement|null

返回

SvgElement :: getAllElements

从字符串内容获取所有元素,此方法将找到的所有元素作为SvgElement对象,并按元素名称放入属性中

public getAllElements(): void

返回

SvgElement :: setElement

在此对象中设置一个新元素

public setElement(string name, mixed element): void

返回

SvgElement :: mergeAttributes

合并字符串标签中包含的属性与数组属性

public mergeAttributes(string tag, array attributes): array

返回

SvgElement :: removeComents

从字符串内容中删除注释

public removeComents(): self

返回

SvgElement :: toHtml

实现了Htmlable接口,toHtml返回SVG元素的HTML格式的字符串

public toHtml(): string

返回

SvgElement :: removeId

删除属性Id

public removeId(): self

返回

SvgElement :: toArray

toArray

public toArray(): void

返回

SvgElement :: serialize

public serialize(mixed data): mixed

返回

SvgElement :: unserialize

public unserialize(mixed data): mixed

返回

SvgElement :: findFirstGroupElement

查找第一个具有名称$element的group元素,并返回新的对应SvgElement实例,如果未找到则返回null

public findFirstGroupElement(string element): SvgElement|null

返回

SvgElement :: findFirstElement

返回元素数组中的第一个元素,如果未找到则返回null

public findFirstElement(string elementName): SvgElement|null

返回

SvgElement :: findFirstNonGroupElement

查找第一个具有名称$element的非group元素,并返回新的对应SvgElement实例,如果未找到则返回null

public findFirstNonGroupElement(string element): SvgElement|null

返回

SvgElement :: getElementAttributes

从字符串标签获取元素的属性(参数为空)

public getElementAttributes(string tag): array

返回

SvgElement :: getTransformations

获取元素的变换,并创建相应的变换对象

public getTransformations(): void

返回

SvgElement :: getElementById

通过其id查找元素并返回它,如果未找到则返回null

public getElementById(string id): SvgElement|null

返回

SvgElement :: getStartPointById

通过其Id获取Shape元素的起始位置点并返回它,如果未找到则返回null

public getStartPointById(string id): \NumPHP\Core\NumArray|null

返回

SvgElement :: hasContext

如果元素有内容则返回true,否则返回false

public hasContext(): void

返回

抽象类Shape

 Full name: \ASK\Svg\Shapes\Shape

创建SVG文档中形状的元素

Shape属性

类属性

Shape方法

类方法

Shape :: 构造函数

Shape (string contents, array attributes = [], SvgElement context = null): mixed

返回

Shape :: getStartPosition

获取元素的起始位置

public getStartPosition(): void

返回

Shape :: renderAttributes

renderAttributes返回一个包含HTML格式的属性的字符串(重载自RenderAttributes方法)

protected renderAttributes(): string

返回

Shape :: toHtml

(重载自SvgElement方法)

public toHtml(): string

返回

类Circle

 Full name: \ASK\Svg\Shapes\Circle

SVG文档中的圆形元素

Circle继承自类:Shape

Circle属性

类属性

方法

类方法

Circle :: 构造函数

Circle (string contents, array attributes = [], SvgElement context = null): mixed

返回

Circle :: center

获取圆的中心

public center(): \NumPHP\Core\NumArray

返回

Circle :: diameter

获取圆的直径

public diameter(): float

返回

Circle :: radius

获取圆的半径

public radio(): float

返回

Circle :: area

获取圆的面积

public area(): float

返回

类Ellipse

 Full name: \ASK\Svg\Shapes\Ellipse

SVG文档中的椭圆形元素

Ellipse继承自类:Shape

Ellipse属性

类属性

方法

类方法

Ellipse :: 构造函数

Ellipse (string contents, array attributes = [], SvgElement context = null): mixed

返回

Ellipse :: center

获取椭圆的中心

public center(): \NumPHP\Core\NumArray

返回

Ellipse :: radiusX

获取椭圆的x半径

public radioX(): float

返回

Ellipse :: radiusY

获取椭圆的y半径

public radioY(): float

返回

Ellipse :: area

获取椭圆的面积

public area(): float

返回

类Line

 Full name: \ASK\Svg\Shapes\Line

SVG文档中的线元素

Line继承自类:Shape

Line属性

类属性

方法

类方法

Line :: 构造函数

Line (string contents, array attributes = [], SvgElement context = null): mixed

返回

Line :: length

获取线的长度

public long(): float

返回

类Path

 Full name: \ASK\Svg\Shapes\Path

SVG文档中的路径元素

Path继承自类:Shape

Path属性

类属性

方法

类方法

Path :: 构造函数

Path (string contents, array attributes = [], SvgElement context = null): mixed

返回

Path :: toHtml

(重载自SvgElement方法)

public toHtml(): string

返回

Path :: content

content获取SVG元素的字符串内容,用于在HTML文档中打印

public content(): string

返回

Path :: getExistingComands

getExistingComands从字符串的d属性中获取现有命令

public getExistingComands(string d): array

返回

路径 :: 渲染属性

renderAttributes返回一个包含HTML格式的属性的字符串(重载自RenderAttributes方法)

protected renderAttributes(): string

返回

类 Polygon

 Full name: \ASK\Svg\Shapes\Polygon

svg 文档中的一个多边形元素

Polygon 继承自类: Shape

多边形属性

类属性

方法

类方法

多边形 :: 构造函数

Polygon (string contents, array attributes = [], SvgElement context = null): mixed

返回

多边形 :: toHtml

(重载自SvgElement方法)

public toHtml(): string

返回

多边形 :: getPoints

从字符串中获取点数组

public getPoints(string points): array

返回

类 Polyline

 Full name: \ASK\Svg\Shapes\Polyline

svg 文档中的一个折线元素

Polyline 继承自类: Shape

折线属性

类属性

方法

类方法

折线 :: 构造函数

Polyline (string contents, array attributes = [], SvgElement context = null): mixed

返回

折线 :: toHtml

(重载自SvgElement方法)

public toHtml(): string

返回

折线 :: getPoints

从字符串中获取点数组

public getPoints(string points): array

返回

类 Rect

 Full name: \ASK\Svg\Shapes\Rect

svg 文档中的一个矩形元素

Rect 继承自类: Shape

矩形属性

类属性

方法

类方法

矩形 :: 构造函数

Rect (string contents, array attributes = [], SvgElement context = null): mixed

返回

矩形 :: center

获取矩形的中心

public center(): \NumPHP\Core\NumArray

返回

矩形 :: area

获取矩形的面积

public area(): float

返回

类 Text

 Full name: \ASK\Svg\Shapes\Text

svg 文档中的一个文本元素

Text 继承自类: Shape

文本属性

类属性

方法

类方法

文本 :: 构造函数

Text (string contents, array attributes = [], SvgElement context = null): mixed

返回

抽象类 Command

 Full name: \ASK\Svg\DCommands\Command

svg 路径 d 属性中的一个命令

对于 <path> 节点,有五种行命令。

  • M - 移动
  • L - 直线
  • H - 水平
  • V - 垂直
  • Z - 闭合

还有五个弧命令。

  • C - 三次贝塞尔曲线
  • Q - 二次贝塞尔曲线
  • S - 简化的三次贝塞尔曲线
  • T - 联合多个二次贝塞尔曲线
  • A -

每个命令都包含一个 $coordinates 数组,其中包含每个点的所有参数,以及上一个命令的引用。

Command 实现: \Illuminate\Contracts\Support\Htmlable

命令属性

类属性

命令方法

类方法

命令 :: 构造函数

Command (string type, array parameters = [], ?DCommands\Command prev = null): mixed

返回

命令 :: 初始化

初始化是一个为特定类型的命令配置的方法

public initialization(mixed parameters): void

返回

命令 :: getComand

getComand

返回命令的名称。如果是绝对命令则为大写,如果是相对命令则为小写

public getComand(): string

返回

命令 :: setEndPoint

setEndPoint 设置命令列表中终点坐标的值,可以是绝对值或相对值

public setEndPoint(array relativePoint, array absolutePoint): void

返回

命令 :: toHtml

public toHtml(): mixed

返回

命令 :: getEndPoint

getEndPoint 返回一个包含终点 x 和 y 值的数组。如果将 "absolute" 参数设置为 true,则返回终点的绝对值,否则返回相对值

public getEndPoint(bool absolute = true): array

返回

命令 :: resetNext

resetNext

public resetNext(): void

返回

命令 :: getLastMComand

getLastMComand 返回 "d" 属性中的最后一个 M 命令

public getLastMComand(): DCommands\Command|null

返回

命令 :: getPoint

getPoint 返回包含第 n 个点的 x 和 y 参数的数组,如果将 "absolute" 参数设置为 true,则返回绝对值,否则返回相对值

public getPoint(int n = null, bool absolute = false): array

返回

命令 :: getDinstance

getDinstance 获取两点之间的距离,如果未提供第二个参数,则返回点的绝对距离

public getDinstance(array fromPoint, array toPoint = []): array

返回

类 A

 Full name: \ASK\Svg\DCommands\A

svg 路径 d 属性中的一个 "a" 命令

弧是圆或椭圆的一部分。对于给定的 x 半径和 y 半径,有两个椭圆可以连接任何两点(最后终点和 (x, y))。沿着这两个圆中的任何一个,都有两种可能的路径可以连接这些点(大圆或小圆),因此在任何情况下,都有四种可能的弧可供选择。

因此,弧需要七个参数:A rx ry x-axis-rotation large-arc-flag sweep-flag x y

a rx ry x-axis-rotation large-arc-flag sweep-flag dx dy

除了其他命令之外,a 命令还有一个额外的 getCenter 方法

A 继承自类: Command

A 属性

类属性

方法

类方法

A :: 初始化

初始化是一个为特定类型的命令配置的方法

public initialization(mixed parameters): void

返回

A :: getCenter

getCenter 获取第 n 个弧的中心

public getCenter(int n = null): array

返回

类 C

 Full name: \ASK\Svg\DCommands\C

在 SVG 路径的 d 属性中的命令 "c"

三次曲线 C 是稍微复杂一些的曲线。三次贝塞尔曲线需要为每个点输入两个控制点。因此,要创建一个三次贝塞尔曲线,需要指定三组坐标。

C x1 y1, x2 y2, x y c dx1 dy1, dx2 dy2, dx dy

C 继承自类: Command

C 属性

类属性

方法

类方法

C :: 初始化

初始化是一个为特定类型的命令配置的方法

public initialization(mixed parameters): void

返回

类 H

 Full name: \ASK\Svg\DCommands\H

在 SVG 路径的 d 属性中的命令 "h"

一个命令绘制一条水平线,此命令只接受一个参数,因为它们只在一个方向上移动。

H x h dx

H 继承自类: Command

H 属性

类属性

方法

类方法

H :: 初始化

初始化是一个为特定类型的命令配置的方法

public initialization(mixed parameters): void

返回

H :: getX

getX

public getX(): float

返回

H :: setX

setX 设置 x 的值

public setX(float x): self

返回

类 L

 Full name: \ASK\Svg\DCommands\L

在 SVG 路径的 d 属性中的命令 "h"

L x y l dx dy

L 继承自类: Command

L 属性

类属性

方法

类方法

L :: 初始化

初始化是一个为特定类型的命令配置的方法

public initialization(mixed parameters): void

返回

类 M

 Full name: \ASK\Svg\DCommands\M

在 SVG 路径的 d 属性中的命令 "m"

M x y m dx dy

M 继承自类: Command

M 属性

类属性

方法

类方法

M :: 初始化

初始化是一个为特定类型的命令配置的方法

public initialization(mixed parameters): void

返回

M :: getMDinstance

getMDinstance 获取最后一个 m 点和参数点之间的距离

public getMDinstance(array toPoint = []): array

返回

M :: getX

获取 x 的值

public getX(): float

返回

M :: setX

setX 设置 x 的值

public setX(float x): self

返回

M :: getY

获取 y 的值

public getY(): float

返回

M :: setY

setY 设置 y 的值

public setY(float y): self

返回

类 Q

 Full name: \ASK\Svg\DCommands\Q

在 SVG 路径的 d 属性中的命令 "q"

Q x1 y1, x y q dx1 dy1, dx dy

Q 继承自类: Command

Q 属性

类属性

方法

类方法

Q :: 初始化

初始化是一个为特定类型的命令配置的方法

public initialization(mixed parameters): void

返回

类 S

 Full name: \ASK\Svg\DCommands\S

在 SVG 路径的 d 属性中的命令 "s"

S x2 y2, x y s dx2 dy2, dx dy

S 继承自类: Command

S 属性

类属性

方法

类方法

S :: 初始化

初始化是一个为特定类型的命令配置的方法

public initialization(mixed parameters): void

返回

类 T

 Full name: \ASK\Svg\DCommands\T

在 SVG 路径的 d 属性中的命令 "t"

T x y t dx dy

T 继承自类: Command

T 属性

类属性

方法

类方法

T :: 初始化

初始化是一个为特定类型的命令配置的方法

public initialization(mixed parameters): void

返回

类 V

 Full name: \ASK\Svg\DCommands\V

在 SVG 路径的 d 属性中的命令 "v"

V y v dy

V 继承自类: Command

V 属性

类属性

方法

类方法

V :: 初始化

初始化是一个为特定类型的命令配置的方法

public initialization(mixed parameters): void

返回

V :: getY

getY

public getY(): float

返回

V :: setY

setY

public setY(float y): self

返回

类 Z

 Full name: \ASK\Svg\DCommands\Z

在 SVG 路径的 d 属性中的命令 "z"

Z 继承自类: Command

Z 属性

类属性

方法

类方法

Z :: 初始化

初始化是一个为特定类型的命令配置的方法

public initialization(mixed parameters): void

返回

Z :: getPoint

getPoint 返回包含第 n 个点的 x 和 y 参数的数组,如果将 "absolute" 参数设置为 true,则返回绝对值,否则返回相对值

public getPoint(mixed n = null, mixed absolute = true): array

返回

字母顺序列表

本文件为公共领域。可用于任何目的,包括商业应用。署名虽好,但非必需。不对任何内容提供保证,包括其正确性、有用性或安全性。

作者:Alberto Solorzano Kraemer( alberto.kraemer@gmail.com,@betobetok )

此文档于2022年3月25日自动从源代码注释生成,使用了phpDocumentorcvuorinen/phpdoc-markdown-public