MCPcopy Create free account
hub / github.com/Barrior/JParticles / generateShapeData

Function generateShapeData

src/common/shape.ts:34–101  ·  view source on GitHub ↗

* 生成形状数据 * @param shape 形状类型

(shape: ShapeType)

Source from the content-addressed store, hash-verified

32 * @param shape 形状类型
33 */
34function generateShapeData(shape: ShapeType): ShapeData {
35 if (isString(shape)) {
36 // 处理「圆形」和「三角形」
37 if (shape === 'circle' || shape === 'triangle') {
38 return { type: shape }
39 }
40
41 // 处理「星形」,默认五角星
42 if (regExp.shapeStar.test(shape as string)) {
43 const result = (shape as string).split(':')
44 return {
45 type: 'star',
46 sides: Number(result[1]) || 5,
47 dent: Number(result[2]) || 0.5,
48 }
49 }
50
51 // 处理「Base64 格式」或「HTTP 地址图片」
52 if (
53 regExp.http.test(shape as string) ||
54 regExp.imageBase64.test(shape as string)
55 ) {
56 const dataRef: ShapeData = {
57 type: 'image',
58 isImageLoaded: false,
59 }
60
61 loadImage(shape as string, (image) => {
62 dataRef.isImageLoaded = true
63 dataRef.source = image
64 })
65
66 return dataRef
67 }
68
69 // 提示错误
70 // eslint-disable-next-line no-console
71 console.warn(`Shape value of ${shape} is invalid.`)
72 }
73
74 try {
75 // 处理 CanvasImageSource 类型
76 if (
77 shape instanceof HTMLImageElement ||
78 shape instanceof HTMLVideoElement ||
79 shape instanceof HTMLCanvasElement ||
80 shape instanceof ImageBitmap ||
81 shape instanceof OffscreenCanvas
82 ) {
83 return {
84 type: 'image',
85 isImageLoaded: true,
86 source: shape,
87 }
88 }
89 } catch (_err) {
90 // eslint-disable-next-line no-console
91 console.warn(

Callers 1

getShapeDataFunction · 0.85

Calls 3

isStringFunction · 0.90
loadImageFunction · 0.90
warnMethod · 0.80

Tested by

no test coverage detected