goatdee-canvas 0.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +536 -0
- package/dist/ZHCanvasCore.js +18 -0
- package/dist/ZHCanvasCore.wasm +0 -0
- package/dist/bind/binding.d.ts +2 -0
- package/dist/bind/constant.d.ts +1 -0
- package/dist/bind/core/bitmap-image.d.ts +5 -0
- package/dist/bind/core/matrix.d.ts +45 -0
- package/dist/bind/core/scaler-context.d.ts +29 -0
- package/dist/bind/core/web-mask.d.ts +26 -0
- package/dist/bind/tgfx-module.d.ts +4 -0
- package/dist/bind/tgfx.d.ts +15 -0
- package/dist/bind/types.d.ts +133 -0
- package/dist/bind/utils/canvas.d.ts +8 -0
- package/dist/bind/utils/decorators.d.ts +3 -0
- package/dist/bind/utils/font-family.d.ts +2 -0
- package/dist/bind/utils/measure-text.d.ts +10 -0
- package/dist/bind/utils/type-utils.d.ts +1 -0
- package/dist/bind/utils/ua.d.ts +7 -0
- package/dist/index.cjs +17631 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.ts +1250 -0
- package/dist/index.js +17585 -0
- package/dist/index.js.map +1 -0
- package/dist/src/CanvasOverlay.d.ts +8 -0
- package/dist/src/OverlayItem.d.ts +51 -0
- package/dist/src/canvas-overlay/index.d.ts +9 -0
- package/dist/src/canvas-overlay/utils.d.ts +50 -0
- package/dist/src/index.d.ts +3 -0
- package/dist/src/listener.d.ts +30 -0
- package/dist/src/manager.d.ts +108 -0
- package/dist/src/services/pasteService.d.ts +4 -0
- package/dist/src/static/cursor.icon.d.ts +6 -0
- package/dist/src/types.d.ts +72 -0
- package/dist/src/utils/clipboard/core.d.ts +31 -0
- package/dist/src/utils/clipboard/index.d.ts +3 -0
- package/dist/src/utils/clipboard/read.d.ts +17 -0
- package/dist/src/utils/clipboard/transform.d.ts +10 -0
- package/dist/src/utils/clipboard.d.ts +1 -0
- package/dist/src/utils/fabricConverter.d.ts +23 -0
- package/dist/src/utils/fontLoader.d.ts +50 -0
- package/dist/src/utils/html2json/converters.d.ts +47 -0
- package/dist/src/utils/html2json/element-helpers.d.ts +60 -0
- package/dist/src/utils/html2json/index.d.ts +16 -0
- package/dist/src/utils/html2json/parsers.d.ts +47 -0
- package/dist/src/utils/html2json/renderers.d.ts +95 -0
- package/dist/src/utils/html2json/types.d.ts +104 -0
- package/dist/src/utils/html2json/utils.d.ts +68 -0
- package/dist/src/utils/imageLoader.d.ts +10 -0
- package/dist/src/utils/imageLoader.example.d.ts +17 -0
- package/dist/src/utils/imageLoader.worker.d.ts +15 -0
- package/dist/src/utils/imageUpload.d.ts +1 -0
- package/dist/src/utils/index.d.ts +7 -0
- package/dist/src/utils/safariCompatibility.d.ts +71 -0
- package/dist/src/utils/safariDataCloneFix.d.ts +32 -0
- package/dist/src/utils/styles.d.ts +4 -0
- package/dist/src/utils/utils.d.ts +23 -0
- package/dist/src/utils/viewState.d.ts +9 -0
- package/dist/wasm/ZHCanvasCore.d.ts +2 -0
- package/package.json +58 -0
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* HTML to EditorJSON Converter - Parsing Functions
|
|
3
|
+
* 包含颜色、渐变、阴影、字体等解析函数
|
|
4
|
+
*/
|
|
5
|
+
import type { LinearGradient, Shadow } from "./types";
|
|
6
|
+
/**
|
|
7
|
+
* 解析颜色值
|
|
8
|
+
* 支持: hex, rgb, rgba, hsl, hsla, CSS 变量等
|
|
9
|
+
*/
|
|
10
|
+
export declare function parseColor(color: string | null | undefined): string | undefined;
|
|
11
|
+
/**
|
|
12
|
+
* 解析 CSS 渐变
|
|
13
|
+
*/
|
|
14
|
+
export declare function parseGradient(gradient: string): string | LinearGradient | undefined;
|
|
15
|
+
/**
|
|
16
|
+
* 解析 CSS box-shadow
|
|
17
|
+
*/
|
|
18
|
+
export declare function parseShadow(shadowStr: string | null | undefined): Shadow | undefined;
|
|
19
|
+
/**
|
|
20
|
+
* 解析字体大小
|
|
21
|
+
*/
|
|
22
|
+
export declare function parseFontSize(fontSize: string | null | undefined): number | undefined;
|
|
23
|
+
/**
|
|
24
|
+
* 解析数值(带单位)
|
|
25
|
+
*/
|
|
26
|
+
export declare function parseLength(value: string | null | undefined): number;
|
|
27
|
+
/**
|
|
28
|
+
* 解析 transform 属性中的旋转角度
|
|
29
|
+
* 支持 matrix()、matrix3d() 和 rotate() 格式
|
|
30
|
+
*/
|
|
31
|
+
export declare function parseTransformAngle(transform: string | null | undefined): number | undefined;
|
|
32
|
+
/**
|
|
33
|
+
* 解析字体粗细
|
|
34
|
+
*/
|
|
35
|
+
export declare function parseFontWeight(weight: string | null | undefined): number | string | undefined;
|
|
36
|
+
/**
|
|
37
|
+
* 解析圆角
|
|
38
|
+
*/
|
|
39
|
+
export declare function parseBorderRadius(radius: string | null | undefined, width?: number, height?: number): number;
|
|
40
|
+
/**
|
|
41
|
+
* 解析行高 (line-height)
|
|
42
|
+
* @param lineHeightStr - CSS line-height 值(如 "normal", "1.2", "19.2px")
|
|
43
|
+
* @param fontSizePx - 字体大小的像素值(用于计算相对值)
|
|
44
|
+
* @param dpr - 设备像素比(用于缩放)
|
|
45
|
+
* @returns 计算后的行高值
|
|
46
|
+
*/
|
|
47
|
+
export declare function parseLineHeight(lineHeightStr: string | null | undefined, fontSizePx: number, dpr?: number): number;
|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* HTML to EditorJSON Converter - Rendering Functions
|
|
3
|
+
* 包含背景渲染、滤镜渲染、emoji 渲染、SVG 渲染等函数
|
|
4
|
+
*/
|
|
5
|
+
/**
|
|
6
|
+
* 将 SVG 元素转换为 base64 data URL
|
|
7
|
+
* 使用 encodeURIComponent 将 SVG 转换为可用于 img src 的 data URL
|
|
8
|
+
*
|
|
9
|
+
* @param element SVG 元素
|
|
10
|
+
* @param width 目标宽度
|
|
11
|
+
* @param height 目标高度
|
|
12
|
+
* @param styles 元素样式(可选)
|
|
13
|
+
* @returns base64 data URL 或 null
|
|
14
|
+
*/
|
|
15
|
+
export declare function renderSVGToBase64(element: SVGElement, width: number, height: number, styles?: CSSStyleDeclaration | null): Promise<string | null>;
|
|
16
|
+
/**
|
|
17
|
+
* 判断背景是否为复杂图案(需要转为图片)
|
|
18
|
+
* 复杂图案包括:url(), radial-gradient, conic-gradient, repeating-gradient, 或有特殊 background-size
|
|
19
|
+
*/
|
|
20
|
+
export declare function isComplexBackground(bgImage: string | null | undefined, bgSize: string | null | undefined): boolean;
|
|
21
|
+
/**
|
|
22
|
+
* 使用 html2canvas 将元素渲染为 base64 图片(通用版本)
|
|
23
|
+
* 支持自动计算 padding 以容纳 filter 效果
|
|
24
|
+
*/
|
|
25
|
+
export declare function renderElementWithHtml2Canvas(element: Element, styles: CSSStyleDeclaration, rect?: {
|
|
26
|
+
width: number;
|
|
27
|
+
height: number;
|
|
28
|
+
}): Promise<{
|
|
29
|
+
base64: string;
|
|
30
|
+
padding: number;
|
|
31
|
+
} | null>;
|
|
32
|
+
/**
|
|
33
|
+
* 将带有 filter 效果的元素渲染为 base64 图片
|
|
34
|
+
* 用于处理 blur、drop-shadow 等滤镜效果
|
|
35
|
+
* 返回 { base64, padding } 以便调整图层位置和大小
|
|
36
|
+
*/
|
|
37
|
+
export declare function renderElementWithFilterToBase64(element: Element, width: number, height: number, styles: CSSStyleDeclaration): Promise<{
|
|
38
|
+
base64: string;
|
|
39
|
+
padding: number;
|
|
40
|
+
} | null>;
|
|
41
|
+
/**
|
|
42
|
+
* 使用 Canvas 2D 渲染「仅字符+字体」的伪元素(如 Font Awesome 图标)
|
|
43
|
+
* html2canvas 对伪元素+自定义字体常得到空白图,此路径直接画字符,更稳定
|
|
44
|
+
*/
|
|
45
|
+
/**
|
|
46
|
+
* 使用 Canvas 2D 渲染图标字体
|
|
47
|
+
*/
|
|
48
|
+
/** 图标字体渲染结果:base64 为高分辨率图,宽高用实际像素,显示尺寸用 scale 控制 */
|
|
49
|
+
export type IconImageResult = {
|
|
50
|
+
base64: string;
|
|
51
|
+
padding: number;
|
|
52
|
+
actualWidth: number;
|
|
53
|
+
actualHeight: number;
|
|
54
|
+
logicalWidth: number;
|
|
55
|
+
logicalHeight: number;
|
|
56
|
+
};
|
|
57
|
+
/**
|
|
58
|
+
* 判断是否为「图标字体」
|
|
59
|
+
* 常见库:Font Awesome、Material Icons、Bootstrap Icons、Ionicons、Feather、Remix Icon、Tabler、Phosphor、Octicons 等
|
|
60
|
+
*/
|
|
61
|
+
export declare function isIconFontFamily(fontFamily: string | undefined): boolean;
|
|
62
|
+
/** 判断是否为「标签内的图标字体」:单字符 + 图标字体族,如 <span class="list-icon"></span> */
|
|
63
|
+
export declare function isIconFontText(text: string, fontFamily: string | undefined): boolean;
|
|
64
|
+
/**
|
|
65
|
+
* 将「标签内图标字符」渲染为图片,如 <span class="list-icon"></span>
|
|
66
|
+
* 使用元素的 computed 样式和 textContent 的第一个字符
|
|
67
|
+
*/
|
|
68
|
+
export declare function renderIconFontTextToImage(element: Element, doc: Document): Promise<IconImageResult | null>;
|
|
69
|
+
/**
|
|
70
|
+
* 使用 html2canvas 渲染伪元素为 base64 图片
|
|
71
|
+
* 这能够 100% 复刻浏览器的原生渲染效果,包括复杂的 filter、gradient 等
|
|
72
|
+
*/
|
|
73
|
+
export declare function renderPseudoElementWithHtml2Canvas(element: Element, pseudoElement: "::before" | "::after", rect: DOMRect, styles: CSSStyleDeclaration): Promise<{
|
|
74
|
+
base64: string;
|
|
75
|
+
padding: number;
|
|
76
|
+
actualWidth?: number;
|
|
77
|
+
actualHeight?: number;
|
|
78
|
+
logicalWidth?: number;
|
|
79
|
+
logicalHeight?: number;
|
|
80
|
+
} | null>;
|
|
81
|
+
/**
|
|
82
|
+
* 将元素的背景渲染为 base64 图片
|
|
83
|
+
* 使用 html2canvas 完美复刻复杂背景效果
|
|
84
|
+
* 注意:只渲染背景样式,不包含子元素
|
|
85
|
+
*/
|
|
86
|
+
export declare function renderBackgroundToBase64(element: Element, width: number, height: number): Promise<string | null>;
|
|
87
|
+
/**
|
|
88
|
+
* 检测文本是否主要是 emoji
|
|
89
|
+
*/
|
|
90
|
+
export declare function isEmojiText(text: string): boolean;
|
|
91
|
+
/**
|
|
92
|
+
* 将 emoji 文本渲染为 base64 图片
|
|
93
|
+
* 使用 html2canvas 确保完美渲染
|
|
94
|
+
*/
|
|
95
|
+
export declare function renderEmojiToBase64(text: string, fontSize: number, width: number, height: number, color?: string, textShadow?: string, targetDoc?: Document): Promise<string | null>;
|
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* HTML to EditorJSON Converter - Type Definitions
|
|
3
|
+
*/
|
|
4
|
+
export interface ColorStop {
|
|
5
|
+
offset: number;
|
|
6
|
+
color: string;
|
|
7
|
+
}
|
|
8
|
+
export interface LinearGradient {
|
|
9
|
+
type: "linear";
|
|
10
|
+
coords: {
|
|
11
|
+
x1: number;
|
|
12
|
+
y1: number;
|
|
13
|
+
x2: number;
|
|
14
|
+
y2: number;
|
|
15
|
+
};
|
|
16
|
+
colorStops: ColorStop[];
|
|
17
|
+
}
|
|
18
|
+
export interface Shadow {
|
|
19
|
+
blur?: number;
|
|
20
|
+
color?: string;
|
|
21
|
+
offsetX?: number;
|
|
22
|
+
offsetY?: number;
|
|
23
|
+
}
|
|
24
|
+
export interface CommonLayerFields {
|
|
25
|
+
id: string;
|
|
26
|
+
name?: string;
|
|
27
|
+
left: number;
|
|
28
|
+
top: number;
|
|
29
|
+
width: number;
|
|
30
|
+
height: number;
|
|
31
|
+
scaleX?: number;
|
|
32
|
+
scaleY?: number;
|
|
33
|
+
angle?: number;
|
|
34
|
+
strokeWidth?: number;
|
|
35
|
+
opacity?: number;
|
|
36
|
+
visible?: boolean;
|
|
37
|
+
locked?: boolean;
|
|
38
|
+
}
|
|
39
|
+
export interface TextLayer extends CommonLayerFields {
|
|
40
|
+
type: "textbox";
|
|
41
|
+
text: string;
|
|
42
|
+
fontSize?: number;
|
|
43
|
+
lineHeight?: number;
|
|
44
|
+
fontFamily?: string;
|
|
45
|
+
bold?: boolean;
|
|
46
|
+
fill?: string | LinearGradient;
|
|
47
|
+
stroke?: string;
|
|
48
|
+
shadow?: Shadow;
|
|
49
|
+
textAlign?: string;
|
|
50
|
+
charSpacing?: number;
|
|
51
|
+
underline?: boolean;
|
|
52
|
+
linethrough?: boolean;
|
|
53
|
+
}
|
|
54
|
+
export interface ImageLayer extends CommonLayerFields {
|
|
55
|
+
type: "image";
|
|
56
|
+
src: string;
|
|
57
|
+
prompt?: string;
|
|
58
|
+
objectFit?: string;
|
|
59
|
+
rx?: number;
|
|
60
|
+
ry?: number;
|
|
61
|
+
backgroundColor?: string | LinearGradient;
|
|
62
|
+
stroke?: string;
|
|
63
|
+
shadow?: Shadow;
|
|
64
|
+
}
|
|
65
|
+
export interface RectangleLayer extends CommonLayerFields {
|
|
66
|
+
type: "rectangle";
|
|
67
|
+
rx?: number;
|
|
68
|
+
ry?: number;
|
|
69
|
+
fill?: string | LinearGradient;
|
|
70
|
+
stroke?: string;
|
|
71
|
+
shadow?: Shadow;
|
|
72
|
+
}
|
|
73
|
+
export interface CircleLayer extends CommonLayerFields {
|
|
74
|
+
type: "circle";
|
|
75
|
+
radius?: number;
|
|
76
|
+
fill?: string | LinearGradient;
|
|
77
|
+
stroke?: string;
|
|
78
|
+
shadow?: Shadow;
|
|
79
|
+
}
|
|
80
|
+
export interface FrameLayer extends CommonLayerFields {
|
|
81
|
+
type: "frame";
|
|
82
|
+
backgroundColor?: string | LinearGradient;
|
|
83
|
+
objects: Layer[];
|
|
84
|
+
}
|
|
85
|
+
export interface GroupLayer extends CommonLayerFields {
|
|
86
|
+
type: "group";
|
|
87
|
+
objects: Layer[];
|
|
88
|
+
}
|
|
89
|
+
export type Layer = TextLayer | ImageLayer | RectangleLayer | CircleLayer | FrameLayer | GroupLayer;
|
|
90
|
+
export interface EditorJSON {
|
|
91
|
+
width: number;
|
|
92
|
+
height: number;
|
|
93
|
+
objects: Layer[];
|
|
94
|
+
thumb?: string;
|
|
95
|
+
}
|
|
96
|
+
export interface ElementContext {
|
|
97
|
+
containerRect: DOMRect;
|
|
98
|
+
currentTop: number;
|
|
99
|
+
cssVariables: Map<string, string>;
|
|
100
|
+
/** 当前转换所在的 document(来自 iframe.contentDocument) */
|
|
101
|
+
doc?: Document;
|
|
102
|
+
/** 当前转换所在的 window(来自 iframe.contentWindow) */
|
|
103
|
+
win?: Window;
|
|
104
|
+
}
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* HTML to EditorJSON Converter - Utility Functions
|
|
3
|
+
* 包含 UUID 生成、CSS 变量解析、图片加载等工具函数
|
|
4
|
+
*/
|
|
5
|
+
import type { Layer } from "./types";
|
|
6
|
+
/**
|
|
7
|
+
* 生成 UUID
|
|
8
|
+
*/
|
|
9
|
+
export declare function uuid(): string;
|
|
10
|
+
/**
|
|
11
|
+
* 获取元素的计算样式
|
|
12
|
+
* 使用元素所在 document 的 defaultView,以便在 iframe 内元素时使用其所在 document 的 window
|
|
13
|
+
*/
|
|
14
|
+
export declare function getComputedStyles(element: Element, pseudoElement?: string): CSSStyleDeclaration | null;
|
|
15
|
+
/**
|
|
16
|
+
* 获取元素的边界框
|
|
17
|
+
*/
|
|
18
|
+
export declare function getBoundingRect(element: Element): DOMRect | null;
|
|
19
|
+
/**
|
|
20
|
+
* 获取元素的原始尺寸(不受 transform 影响)
|
|
21
|
+
* 使用 offsetWidth/offsetHeight,这些属性返回元素的布局尺寸,不受 CSS transform 影响
|
|
22
|
+
* 返回值包含 padding 和 border,但不包含 margin
|
|
23
|
+
*/
|
|
24
|
+
export declare function getOriginalDimensions(element: Element, styles: CSSStyleDeclaration | null): {
|
|
25
|
+
width: number;
|
|
26
|
+
height: number;
|
|
27
|
+
} | null;
|
|
28
|
+
/**
|
|
29
|
+
* 提取 title 标签
|
|
30
|
+
*/
|
|
31
|
+
export declare function extractTitle(doc: Document): string;
|
|
32
|
+
/**
|
|
33
|
+
* 解析 CSS 变量
|
|
34
|
+
*/
|
|
35
|
+
export declare function extractCSSVariables(doc: Document): Map<string, string>;
|
|
36
|
+
/**
|
|
37
|
+
* 解析变量引用
|
|
38
|
+
*/
|
|
39
|
+
export declare function resolveVariable(value: string, variables: Map<string, string>): string;
|
|
40
|
+
/**
|
|
41
|
+
* 获取元素的文本内容,将 <br> 转换为换行符
|
|
42
|
+
* 注意:HTML 缩进已在 html2json 入口处统一处理,这里只需要处理 <br> 标签
|
|
43
|
+
*/
|
|
44
|
+
export declare function getTextContent(element: Element): string;
|
|
45
|
+
/**
|
|
46
|
+
* 递归替换所有图层的字体族
|
|
47
|
+
*/
|
|
48
|
+
export declare function replaceFontFamily(layers: Layer[], fontFamily: string): void;
|
|
49
|
+
/**
|
|
50
|
+
* 等待单个图片加载完成
|
|
51
|
+
*/
|
|
52
|
+
export declare function waitForImage(img: HTMLImageElement, timeout?: number): Promise<void>;
|
|
53
|
+
/**
|
|
54
|
+
* 等待容器内所有图片加载完成
|
|
55
|
+
*/
|
|
56
|
+
export declare function waitForAllImages(container: Element, timeout?: number): Promise<void>;
|
|
57
|
+
/**
|
|
58
|
+
* 判断元素是否为文本容器
|
|
59
|
+
*/
|
|
60
|
+
export declare function isTextElement(element: Element): boolean;
|
|
61
|
+
/**
|
|
62
|
+
* 判断元素是否应该被当作文本处理(即使是 div)
|
|
63
|
+
*/
|
|
64
|
+
export declare function shouldTreatAsText(element: Element): boolean;
|
|
65
|
+
/**
|
|
66
|
+
* 判断元素是否为布局容器
|
|
67
|
+
*/
|
|
68
|
+
export declare function isLayoutContainer(element: Element): boolean;
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 图片加载工具使用示例
|
|
3
|
+
* 这个文件仅用于演示,不会被打包到最终产品中
|
|
4
|
+
*/
|
|
5
|
+
declare function loadSingleImageExample(): Promise<void>;
|
|
6
|
+
declare function loadImageWithOptionsExample(): Promise<void>;
|
|
7
|
+
declare function loadMultipleImagesExample(): Promise<void>;
|
|
8
|
+
declare function cacheManagementExample(): void;
|
|
9
|
+
export declare class ImageComponent {
|
|
10
|
+
private imageData;
|
|
11
|
+
loadImage(url: string): Promise<void>;
|
|
12
|
+
private renderImage;
|
|
13
|
+
private showError;
|
|
14
|
+
destroy(): void;
|
|
15
|
+
}
|
|
16
|
+
export declare function loadImageForCanvas(canvas: HTMLCanvasElement, imageUrl: string): Promise<void>;
|
|
17
|
+
export { loadSingleImageExample, loadImageWithOptionsExample, loadMultipleImagesExample, cacheManagementExample };
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 图片加载 Worker
|
|
3
|
+
* 用于在后台线程中加载图片数据,避免阻塞主线程
|
|
4
|
+
*/
|
|
5
|
+
export interface ImageLoadMessage {
|
|
6
|
+
type: 'LOAD_IMAGE';
|
|
7
|
+
url: string;
|
|
8
|
+
id: string;
|
|
9
|
+
}
|
|
10
|
+
export interface ImageLoadResult {
|
|
11
|
+
type: 'IMAGE_LOADED' | 'IMAGE_ERROR';
|
|
12
|
+
id: string;
|
|
13
|
+
data?: Uint8Array;
|
|
14
|
+
error?: string;
|
|
15
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const uploadClipboardImage: (blob: Blob, mimeType: string, uploadAction?: string, uploadHeader?: Record<string, string>) => Promise<string | null>;
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { CanvasRef, CanvasProps } from "../types";
|
|
2
|
+
export type { CanvasRef, CanvasProps };
|
|
3
|
+
export { loadImageData } from './imageLoader';
|
|
4
|
+
export { convertFabricJSON } from './fabricConverter';
|
|
5
|
+
export type { FabricObject, ConvertedObject } from './fabricConverter';
|
|
6
|
+
export { html2json } from './html2json';
|
|
7
|
+
export { utils } from './utils';
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Safari浏览器兼容性工具
|
|
3
|
+
* 用于处理Safari浏览器中WebAssembly相关的兼容性问题
|
|
4
|
+
*/
|
|
5
|
+
/**
|
|
6
|
+
* 检测是否为Safari浏览器
|
|
7
|
+
*/
|
|
8
|
+
export declare const isSafari: () => boolean;
|
|
9
|
+
/**
|
|
10
|
+
* 检测Safari版本
|
|
11
|
+
*/
|
|
12
|
+
export declare const getSafariVersion: () => number | null;
|
|
13
|
+
/**
|
|
14
|
+
* 为Safari创建WebAssembly模块初始化配置
|
|
15
|
+
*/
|
|
16
|
+
export declare const createSafariWasmConfig: () => {
|
|
17
|
+
locateFile: (path: string) => string;
|
|
18
|
+
noInitialRun: boolean;
|
|
19
|
+
INITIAL_MEMORY: number;
|
|
20
|
+
USE_PTHREADS: number;
|
|
21
|
+
PTHREAD_POOL_SIZE: number;
|
|
22
|
+
SHARED_MEMORY: number;
|
|
23
|
+
wasmMemory: undefined;
|
|
24
|
+
onRuntimeInitialized: () => void;
|
|
25
|
+
onAbort: (what: string) => void;
|
|
26
|
+
PROXY_TO_PTHREAD: number;
|
|
27
|
+
onWorkerCreated: (worker: Worker) => void;
|
|
28
|
+
};
|
|
29
|
+
/**
|
|
30
|
+
* 创建Safari专用的WebAssembly配置(禁用多线程)
|
|
31
|
+
*/
|
|
32
|
+
export declare const createSafariNoThreadsConfig: () => {
|
|
33
|
+
locateFile: (path: string) => string;
|
|
34
|
+
USE_PTHREADS: number;
|
|
35
|
+
PTHREAD_POOL_SIZE: number;
|
|
36
|
+
SHARED_MEMORY: number;
|
|
37
|
+
PROXY_TO_PTHREAD: number;
|
|
38
|
+
INITIAL_MEMORY: number;
|
|
39
|
+
ALLOW_MEMORY_GROWTH: number;
|
|
40
|
+
noInitialRun: boolean;
|
|
41
|
+
wasmMemory: undefined;
|
|
42
|
+
onRuntimeInitialized: () => void;
|
|
43
|
+
onAbort: (what: string) => void;
|
|
44
|
+
};
|
|
45
|
+
/**
|
|
46
|
+
* 创建Safari标准配置(保持多线程但优化设置)
|
|
47
|
+
*/
|
|
48
|
+
export declare const createSafariStandardConfig: () => {
|
|
49
|
+
locateFile: (path: string) => string;
|
|
50
|
+
INITIAL_MEMORY: number;
|
|
51
|
+
ALLOW_MEMORY_GROWTH: number;
|
|
52
|
+
USE_PTHREADS: number;
|
|
53
|
+
PTHREAD_POOL_SIZE: number;
|
|
54
|
+
SHARED_MEMORY: number;
|
|
55
|
+
PROXY_TO_PTHREAD: number;
|
|
56
|
+
noInitialRun: boolean;
|
|
57
|
+
onRuntimeInitialized: () => void;
|
|
58
|
+
onAbort: (what: string) => void;
|
|
59
|
+
};
|
|
60
|
+
/**
|
|
61
|
+
* 安全地初始化WebAssembly模块(Safari兼容)
|
|
62
|
+
*/
|
|
63
|
+
export declare const safeInitializeWasm: (wasmModule: any) => Promise<any>;
|
|
64
|
+
/**
|
|
65
|
+
* 检查Safari是否支持WebAssembly多线程
|
|
66
|
+
*/
|
|
67
|
+
export declare const isSafariWebAssemblyThreadsSupported: () => boolean;
|
|
68
|
+
/**
|
|
69
|
+
* 获取Safari兼容性警告信息
|
|
70
|
+
*/
|
|
71
|
+
export declare const getSafariCompatibilityWarning: () => string | null;
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Safari DataCloneError 修复工具
|
|
3
|
+
* 专门处理Safari浏览器中的DataCloneError问题
|
|
4
|
+
*/
|
|
5
|
+
/**
|
|
6
|
+
* 安全的对象克隆函数,兼容Safari
|
|
7
|
+
*/
|
|
8
|
+
export declare const safeClone: <T>(obj: T) => T;
|
|
9
|
+
/**
|
|
10
|
+
* 检查对象是否可以被安全克隆
|
|
11
|
+
*/
|
|
12
|
+
export declare const isCloneable: (obj: any) => boolean;
|
|
13
|
+
/**
|
|
14
|
+
* 为Safari创建安全的postMessage包装器
|
|
15
|
+
*/
|
|
16
|
+
export declare const createSafePostMessage: (originalPostMessage: any) => (this: any, message: any, ...args: any[]) => any;
|
|
17
|
+
/**
|
|
18
|
+
* 修复Worker中的DataCloneError问题
|
|
19
|
+
*/
|
|
20
|
+
export declare const patchWorkerForSafari: (worker: Worker) => Worker;
|
|
21
|
+
/**
|
|
22
|
+
* 创建Safari兼容的Worker
|
|
23
|
+
*/
|
|
24
|
+
export declare const createSafariCompatibleWorker: (scriptURL: string | URL, options?: WorkerOptions) => Worker;
|
|
25
|
+
/**
|
|
26
|
+
* 修复全局postMessage以兼容Safari
|
|
27
|
+
*/
|
|
28
|
+
export declare const patchGlobalPostMessage: () => void;
|
|
29
|
+
/**
|
|
30
|
+
* 初始化Safari兼容性修复
|
|
31
|
+
*/
|
|
32
|
+
export declare const initSafariCompatibility: () => void;
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
export declare namespace utils {
|
|
2
|
+
function safeProperties(properties: any): any;
|
|
3
|
+
/**
|
|
4
|
+
* 防抖函数
|
|
5
|
+
* @param fn 函数
|
|
6
|
+
* @param delay 延迟时间
|
|
7
|
+
* @returns 防抖函数
|
|
8
|
+
*/
|
|
9
|
+
function debounce(fn: any, delay: number): (this: any, ...args: any[]) => void;
|
|
10
|
+
/**
|
|
11
|
+
* 节流函数
|
|
12
|
+
* @param fn 函数
|
|
13
|
+
* @param delay 延迟时间
|
|
14
|
+
* @returns 节流函数
|
|
15
|
+
*/
|
|
16
|
+
function throttle(fn: any, delay: number): (this: any, ...args: any[]) => void;
|
|
17
|
+
/**
|
|
18
|
+
* 将 base64 转换为 Uint8Array
|
|
19
|
+
* @param base64 base64 字符串
|
|
20
|
+
* @returns Uint8Array
|
|
21
|
+
*/
|
|
22
|
+
function base64ToUint8Array(base64: string): Uint8Array;
|
|
23
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
interface EnsureImageVisibleOptions {
|
|
2
|
+
imageWidth: number;
|
|
3
|
+
imageHeight: number;
|
|
4
|
+
imageLeft: number;
|
|
5
|
+
imageTop: number;
|
|
6
|
+
imageId: string;
|
|
7
|
+
}
|
|
8
|
+
export declare const ensureImageVisible: ({ imageWidth, imageHeight, imageLeft, imageTop, imageId, }: EnsureImageVisibleOptions) => void;
|
|
9
|
+
export {};
|
package/package.json
ADDED
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "goatdee-canvas",
|
|
3
|
+
"version": "0.0.1",
|
|
4
|
+
"description": "Goatdee Canvas",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"main": "dist/index.cjs",
|
|
7
|
+
"module": "dist/index.js",
|
|
8
|
+
"types": "dist/index.d.ts",
|
|
9
|
+
"exports": {
|
|
10
|
+
".": {
|
|
11
|
+
"import": "./dist/index.js",
|
|
12
|
+
"require": "./dist/index.cjs",
|
|
13
|
+
"types": "./dist/index.d.ts"
|
|
14
|
+
}
|
|
15
|
+
},
|
|
16
|
+
"files": [
|
|
17
|
+
"dist"
|
|
18
|
+
],
|
|
19
|
+
"scripts": {
|
|
20
|
+
"build": "cross-env THREAD_MODE=multi rollup -c",
|
|
21
|
+
"dev": "cross-env THREAD_MODE=multi rollup -c -w",
|
|
22
|
+
"clean": "rm -rf dist",
|
|
23
|
+
"type-check": "tsc --noEmit",
|
|
24
|
+
"docs:api": "typedoc"
|
|
25
|
+
},
|
|
26
|
+
"keywords": [
|
|
27
|
+
"canvas",
|
|
28
|
+
"infinite",
|
|
29
|
+
"editor",
|
|
30
|
+
"react"
|
|
31
|
+
],
|
|
32
|
+
"author": "Tencent",
|
|
33
|
+
"license": "MIT",
|
|
34
|
+
"peerDependencies": {
|
|
35
|
+
"react": ">=16.8.0",
|
|
36
|
+
"react-dom": ">=16.8.0"
|
|
37
|
+
},
|
|
38
|
+
"devDependencies": {
|
|
39
|
+
"@rollup/plugin-commonjs": "^25.0.0",
|
|
40
|
+
"@rollup/plugin-node-resolve": "^15.0.0",
|
|
41
|
+
"@types/react": "^18.0.0",
|
|
42
|
+
"@types/react-dom": "^18.0.0",
|
|
43
|
+
"cross-env": "^7.0.3",
|
|
44
|
+
"rollup": "^4.0.0",
|
|
45
|
+
"rollup-plugin-dts": "^6.0.0",
|
|
46
|
+
"rollup-plugin-peer-deps-external": "^2.2.4",
|
|
47
|
+
"tslib": "^2.0.0",
|
|
48
|
+
"typescript": "^5.0.0",
|
|
49
|
+
"typedoc": "^0.28.0",
|
|
50
|
+
"typedoc-plugin-markdown": "^4.10.0"
|
|
51
|
+
},
|
|
52
|
+
"dependencies": {
|
|
53
|
+
"alloyfinger": "^0.1.16",
|
|
54
|
+
"heic-to": "^1.3.0",
|
|
55
|
+
"html2canvas": "^1.4.1",
|
|
56
|
+
"wawoff2": "^2.0.1"
|
|
57
|
+
}
|
|
58
|
+
}
|