@galacean/effects-plugin-dom-content 2.9.0
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/LICENSE +22 -0
- package/dist/dom-content-component.d.ts +44 -0
- package/dist/dom-content-loader.d.ts +8 -0
- package/dist/dom-to-texture.d.ts +27 -0
- package/dist/index.d.ts +4 -0
- package/dist/index.js +1733 -0
- package/dist/index.js.map +1 -0
- package/dist/index.min.js +8 -0
- package/dist/index.min.js.map +1 -0
- package/dist/index.mjs +1704 -0
- package/dist/index.mjs.map +1 -0
- package/package.json +50 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
MIT LICENSE
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2019-present Ant Group Co., Ltd. https://www.antgroup.com/
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
|
6
|
+
a copy of this software and associated documentation files (the
|
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
|
11
|
+
the following conditions:
|
|
12
|
+
|
|
13
|
+
The above copyright notice and this permission notice shall be
|
|
14
|
+
included in all copies or substantial portions of the Software.
|
|
15
|
+
|
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import type { Engine, Renderer } from '@galacean/effects';
|
|
2
|
+
import { MaskableGraphic } from '@galacean/effects';
|
|
3
|
+
/** DOM 内容组件:将 HTML/CSS 渲染为纹理,自动检测并覆盖同 item 上其他 MaskableGraphic 组件纹理 */
|
|
4
|
+
export declare class DomContentComponent extends MaskableGraphic {
|
|
5
|
+
htmlContent: string;
|
|
6
|
+
contentWidth: number;
|
|
7
|
+
contentHeight: number;
|
|
8
|
+
contentScale: number;
|
|
9
|
+
/** 本组件独占持有的离屏 canvas,用于将 HTML 渲染结果转为纹理数据,onDestroy 时一并释放。 */
|
|
10
|
+
canvas: HTMLCanvasElement;
|
|
11
|
+
context: CanvasRenderingContext2D | null;
|
|
12
|
+
isDirty: boolean;
|
|
13
|
+
private rendering;
|
|
14
|
+
/** 异步任务取消标记:onDestroy 后置为 true,用于让 await 中的 updateTexture 回到同步段时立刻退出,避免泄漏纹理或写已释放的 material。 */
|
|
15
|
+
private asyncCancelled;
|
|
16
|
+
private targetComponent;
|
|
17
|
+
/** 内容版本号:每次 setContent 自增,用于丢弃过期的异步渲染结果,防止慢请求覆盖快请求。 */
|
|
18
|
+
private renderVersion;
|
|
19
|
+
/** 由本组件创建的纹理集合,仅这些纹理可被 dispose */
|
|
20
|
+
private ownedTextures;
|
|
21
|
+
/** 保存 target 组件的原始纹理,用于组件销毁时恢复 */
|
|
22
|
+
private originalTargetTexture;
|
|
23
|
+
constructor(engine: Engine);
|
|
24
|
+
setContent(html: string, width?: number, height?: number, scale?: number): void;
|
|
25
|
+
onAwake(): void;
|
|
26
|
+
onUpdate(dt: number): void;
|
|
27
|
+
render(renderer: Renderer): void;
|
|
28
|
+
onDestroy(): void;
|
|
29
|
+
/**
|
|
30
|
+
* 释放当前 renderer 上挂载的纹理(白纹理是引擎共享资源,不应释放)。
|
|
31
|
+
*/
|
|
32
|
+
private disposeOwnTexture;
|
|
33
|
+
/**
|
|
34
|
+
* 将一张 image 绘制到内部 canvas,并据此创建纹理写入到本组件 renderer / material。
|
|
35
|
+
*
|
|
36
|
+
* @param width - 纹理宽度(像素)
|
|
37
|
+
* @param height - 纹理高度(像素)
|
|
38
|
+
* @param flipY - 是否翻转 Y 轴;为 false 时通过 canvas 变换预先翻转
|
|
39
|
+
* @param drawCallback - 实际绘制回调,接收已重置变换并清空的 2D 上下文
|
|
40
|
+
*/
|
|
41
|
+
private renderImageToTexture;
|
|
42
|
+
private updateTexture;
|
|
43
|
+
private updateTargetTexture;
|
|
44
|
+
}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
export interface RenderOptions {
|
|
2
|
+
/** 自动内联 @font-face 外部字体,默认 true */
|
|
3
|
+
inlineFonts?: boolean;
|
|
4
|
+
/** 自动内联外部图片/资源 URL,默认 true */
|
|
5
|
+
inlineImages?: boolean;
|
|
6
|
+
/** 自动从宿主文档提取 CSS url(#id) 引用的 SVG 定义,默认 true */
|
|
7
|
+
extractDefs?: boolean;
|
|
8
|
+
}
|
|
9
|
+
/** 将 HTML 渲染为 Image 对象,默认自动执行内联字体/图片/提取 SVG 定义 */
|
|
10
|
+
export declare function renderDOMToImage(html: string, width: number, height: number, scale?: number, options?: RenderOptions): Promise<HTMLImageElement>;
|
|
11
|
+
/**
|
|
12
|
+
* 清理 HTML:转义危险标签,移除事件处理器和危险协议 URL 属性。
|
|
13
|
+
* 使用字符级扫描代替回溯正则,避免 ReDoS 漏洞。
|
|
14
|
+
*/
|
|
15
|
+
export declare function sanitizeSVGContent(html: string): string;
|
|
16
|
+
/**
|
|
17
|
+
* 将 HTML 中外部资源 URL 转为 base64 内联,失败时保留原 URL
|
|
18
|
+
*/
|
|
19
|
+
export declare function inlineImageSources(html: string): Promise<string>;
|
|
20
|
+
/**
|
|
21
|
+
* 将 @font-face 中的外部字体 URL 转为 base64 内联
|
|
22
|
+
*/
|
|
23
|
+
export declare function inlineFontSources(html: string): Promise<string>;
|
|
24
|
+
/**
|
|
25
|
+
* 从宿主文档提取 CSS url(#id) 引用的 SVG 定义,支持 filter/clipPath/mask/gradient/pattern/marker
|
|
26
|
+
*/
|
|
27
|
+
export declare function extractSVGDefs(html: string): string;
|
package/dist/index.d.ts
ADDED