@sliiu/present-renderer 0.0.0-stage → 0.1.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.
Files changed (126) hide show
  1. package/COPYRIGHT +5 -0
  2. package/LICENSE +661 -0
  3. package/THIRD-PARTY-NOTICES.md +221 -0
  4. package/dist/cjs/arrow-geom.js +38 -0
  5. package/dist/cjs/canvas-backend.js +1368 -0
  6. package/dist/cjs/cell-borders.js +25 -0
  7. package/dist/cjs/chart-canvas.js +1059 -0
  8. package/dist/cjs/chart-ex-render.js +275 -0
  9. package/dist/cjs/chart-geom.js +313 -0
  10. package/dist/cjs/chart-svg.js +1110 -0
  11. package/dist/cjs/compose.js +74 -0
  12. package/dist/cjs/effect-clip.js +652 -0
  13. package/dist/cjs/entrance-hide.js +63 -0
  14. package/dist/cjs/font-stack.js +103 -0
  15. package/dist/cjs/hit-geom.js +50 -0
  16. package/dist/cjs/hybrid-backend.js +93 -0
  17. package/dist/cjs/hybrid-segments.js +54 -0
  18. package/dist/cjs/index.js +70 -0
  19. package/dist/cjs/linked-src.js +116 -0
  20. package/dist/cjs/metafile-preview.js +142 -0
  21. package/dist/cjs/model3d-frame.js +199 -0
  22. package/dist/cjs/model3d-render.js +78 -0
  23. package/dist/cjs/morph-transition.js +57 -0
  24. package/dist/cjs/node-affine.js +79 -0
  25. package/dist/cjs/ole-render.js +291 -0
  26. package/dist/cjs/package.json +1 -0
  27. package/dist/cjs/paint-canvas.js +701 -0
  28. package/dist/cjs/paint-svg.js +674 -0
  29. package/dist/cjs/scene-node.js +762 -0
  30. package/dist/cjs/selection.js +130 -0
  31. package/dist/cjs/shape-effects.js +66 -0
  32. package/dist/cjs/shape-front.js +38 -0
  33. package/dist/cjs/stage-chrome.js +15 -0
  34. package/dist/cjs/svg-backend.js +2172 -0
  35. package/dist/cjs/text-autofit.js +48 -0
  36. package/dist/cjs/text-hit.js +284 -0
  37. package/dist/cjs/text-layout.js +408 -0
  38. package/dist/cjs/text-shared.js +238 -0
  39. package/dist/cjs/text-stacked.js +82 -0
  40. package/dist/cjs/text-warp.js +377 -0
  41. package/dist/cjs/text-wordart.js +33 -0
  42. package/dist/cjs/video-frame.js +113 -0
  43. package/dist/cjs/webgl-model3d-backend.js +285 -0
  44. package/dist/cjs/webgl-shape-backend.js +360 -0
  45. package/dist/esm/arrow-geom.js +33 -0
  46. package/dist/esm/canvas-backend.js +1363 -0
  47. package/dist/esm/cell-borders.js +21 -0
  48. package/dist/esm/chart-canvas.js +1056 -0
  49. package/dist/esm/chart-ex-render.js +261 -0
  50. package/dist/esm/chart-geom.js +296 -0
  51. package/dist/esm/chart-svg.js +1107 -0
  52. package/dist/esm/compose.js +71 -0
  53. package/dist/esm/effect-clip.js +648 -0
  54. package/dist/esm/entrance-hide.js +59 -0
  55. package/dist/esm/font-stack.js +100 -0
  56. package/dist/esm/hit-geom.js +45 -0
  57. package/dist/esm/hybrid-backend.js +89 -0
  58. package/dist/esm/hybrid-segments.js +51 -0
  59. package/dist/esm/index.js +24 -0
  60. package/dist/esm/linked-src.js +109 -0
  61. package/dist/esm/metafile-preview.js +135 -0
  62. package/dist/esm/model3d-frame.js +158 -0
  63. package/dist/esm/model3d-render.js +73 -0
  64. package/dist/esm/morph-transition.js +54 -0
  65. package/dist/esm/node-affine.js +71 -0
  66. package/dist/esm/ole-render.js +286 -0
  67. package/dist/esm/paint-canvas.js +693 -0
  68. package/dist/esm/paint-svg.js +670 -0
  69. package/dist/esm/scene-node.js +750 -0
  70. package/dist/esm/selection.js +122 -0
  71. package/dist/esm/shape-effects.js +60 -0
  72. package/dist/esm/shape-front.js +35 -0
  73. package/dist/esm/stage-chrome.js +12 -0
  74. package/dist/esm/svg-backend.js +2168 -0
  75. package/dist/esm/text-autofit.js +44 -0
  76. package/dist/esm/text-hit.js +280 -0
  77. package/dist/esm/text-layout.js +400 -0
  78. package/dist/esm/text-shared.js +221 -0
  79. package/dist/esm/text-stacked.js +78 -0
  80. package/dist/esm/text-warp.js +371 -0
  81. package/dist/esm/text-wordart.js +30 -0
  82. package/dist/esm/video-frame.js +109 -0
  83. package/dist/esm/webgl-model3d-backend.js +248 -0
  84. package/dist/esm/webgl-shape-backend.js +323 -0
  85. package/dist/types/arrow-geom.d.ts +10 -0
  86. package/dist/types/canvas-backend.d.ts +55 -0
  87. package/dist/types/cell-borders.d.ts +9 -0
  88. package/dist/types/chart-canvas.d.ts +2 -0
  89. package/dist/types/chart-ex-render.d.ts +79 -0
  90. package/dist/types/chart-geom.d.ts +112 -0
  91. package/dist/types/chart-svg.d.ts +2 -0
  92. package/dist/types/compose.d.ts +2 -0
  93. package/dist/types/effect-clip.d.ts +10 -0
  94. package/dist/types/entrance-hide.d.ts +16 -0
  95. package/dist/types/font-stack.d.ts +9 -0
  96. package/dist/types/hit-geom.d.ts +15 -0
  97. package/dist/types/hybrid-backend.d.ts +21 -0
  98. package/dist/types/hybrid-segments.d.ts +11 -0
  99. package/dist/types/index.d.ts +24 -0
  100. package/dist/types/linked-src.d.ts +13 -0
  101. package/dist/types/metafile-preview.d.ts +11 -0
  102. package/dist/types/model3d-frame.d.ts +8 -0
  103. package/dist/types/model3d-render.d.ts +4 -0
  104. package/dist/types/morph-transition.d.ts +15 -0
  105. package/dist/types/node-affine.d.ts +22 -0
  106. package/dist/types/ole-render.d.ts +7 -0
  107. package/dist/types/paint-canvas.d.ts +22 -0
  108. package/dist/types/paint-svg.d.ts +19 -0
  109. package/dist/types/scene-node.d.ts +128 -0
  110. package/dist/types/selection.d.ts +22 -0
  111. package/dist/types/shape-effects.d.ts +13 -0
  112. package/dist/types/shape-front.d.ts +4 -0
  113. package/dist/types/stage-chrome.d.ts +8 -0
  114. package/dist/types/svg-backend.d.ts +88 -0
  115. package/dist/types/text-autofit.d.ts +7 -0
  116. package/dist/types/text-hit.d.ts +7 -0
  117. package/dist/types/text-layout.d.ts +35 -0
  118. package/dist/types/text-shared.d.ts +86 -0
  119. package/dist/types/text-stacked.d.ts +11 -0
  120. package/dist/types/text-warp.d.ts +37 -0
  121. package/dist/types/text-wordart.d.ts +18 -0
  122. package/dist/types/video-frame.d.ts +2 -0
  123. package/dist/types/webgl-model3d-backend.d.ts +25 -0
  124. package/dist/types/webgl-shape-backend.d.ts +33 -0
  125. package/package.json +33 -4
  126. package/README.md +0 -3
@@ -0,0 +1,130 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.Selection = void 0;
4
+ exports.nodeWorldBBox = nodeWorldBBox;
5
+ exports.hitTest = hitTest;
6
+ exports.pointInNode = pointInNode;
7
+ exports.attachPointerSelection = attachPointerSelection;
8
+ class Selection {
9
+ ids = new Set();
10
+ listeners = new Set();
11
+ get() {
12
+ return [...this.ids];
13
+ }
14
+ has(id) {
15
+ return this.ids.has(id);
16
+ }
17
+ set(ids) {
18
+ this.ids = new Set(ids);
19
+ this.fire();
20
+ }
21
+ add(id) {
22
+ this.ids.add(id);
23
+ this.fire();
24
+ }
25
+ remove(id) {
26
+ this.ids.delete(id);
27
+ this.fire();
28
+ }
29
+ toggle(id) {
30
+ if (this.ids.has(id))
31
+ this.ids.delete(id);
32
+ else
33
+ this.ids.add(id);
34
+ this.fire();
35
+ }
36
+ clear() {
37
+ if (this.ids.size === 0)
38
+ return;
39
+ this.ids.clear();
40
+ this.fire();
41
+ }
42
+ on(fn) {
43
+ this.listeners.add(fn);
44
+ return () => this.listeners.delete(fn);
45
+ }
46
+ fire() {
47
+ for (const l of this.listeners)
48
+ l(this.ids);
49
+ }
50
+ }
51
+ exports.Selection = Selection;
52
+ function nodeWorldBBox(node) {
53
+ const b = node.shape.bbox;
54
+ const cx = b.x + b.w / 2;
55
+ const cy = b.y + b.h / 2;
56
+ const flipX = node.shape.transform?.scaleX ?? 1;
57
+ const flipY = node.shape.transform?.scaleY ?? 1;
58
+ const sx = node.scale * node.scaleX * node.widthScale * (flipX < 0 ? -1 : 1);
59
+ const sy = node.scale * node.scaleY * node.heightScale * (flipY < 0 ? -1 : 1);
60
+ return {
61
+ x: b.x + node.tx + (1 - sx) * (cx - b.x),
62
+ y: b.y + node.ty + (1 - sy) * (cy - b.y),
63
+ w: b.w * sx,
64
+ h: b.h * sy,
65
+ };
66
+ }
67
+ function hitTest(scene, x, y, opts = {}) {
68
+ let result = null;
69
+ const visit = (node) => {
70
+ if (node.shape.kind !== "group") {
71
+ if (opts.ignoreLocked && node.shape.locked)
72
+ return;
73
+ if (pointInNode(node, x, y))
74
+ result = node;
75
+ }
76
+ for (const c of node.children)
77
+ visit(c);
78
+ };
79
+ visit(scene.root);
80
+ return result;
81
+ }
82
+ function pointInNode(node, x, y) {
83
+ const b = node.shape.bbox;
84
+ const cx = b.x + b.w / 2;
85
+ const cy = b.y + b.h / 2;
86
+ let lx = x - node.tx;
87
+ let ly = y - node.ty;
88
+ const flipX = node.shape.transform?.scaleX ?? 1;
89
+ const flipY = node.shape.transform?.scaleY ?? 1;
90
+ const sx = node.scale * node.scaleX * node.widthScale * (flipX < 0 ? -1 : 1);
91
+ const sy = node.scale * node.scaleY * node.heightScale * (flipY < 0 ? -1 : 1);
92
+ if (sx !== 1)
93
+ lx = (lx - cx) / sx + cx;
94
+ if (sy !== 1)
95
+ ly = (ly - cy) / sy + cy;
96
+ if (node.rotation !== 0) {
97
+ const a = (-node.rotation * Math.PI) / 180;
98
+ const dx = lx - cx;
99
+ const dy = ly - cy;
100
+ lx = cx + dx * Math.cos(a) - dy * Math.sin(a);
101
+ ly = cy + dx * Math.sin(a) + dy * Math.cos(a);
102
+ }
103
+ if (node.shape.kind === "ellipse") {
104
+ const rx = b.w / 2;
105
+ const ry = b.h / 2;
106
+ const dx = (lx - cx) / rx;
107
+ const dy = (ly - cy) / ry;
108
+ return dx * dx + dy * dy <= 1;
109
+ }
110
+ return lx >= b.x && lx <= b.x + b.w && ly >= b.y && ly <= b.y + b.h;
111
+ }
112
+ function attachPointerSelection(hostEl, scene, selection) {
113
+ const onClick = (e) => {
114
+ const rect = hostEl.getBoundingClientRect();
115
+ const sx = (e.clientX - rect.left) * (scene.width / rect.width);
116
+ const sy = (e.clientY - rect.top) * (scene.height / rect.height);
117
+ const hit = hitTest(scene, sx, sy);
118
+ if (!hit) {
119
+ if (!e.shiftKey)
120
+ selection.clear();
121
+ return;
122
+ }
123
+ if (e.shiftKey)
124
+ selection.toggle(hit.id);
125
+ else
126
+ selection.set([hit.id]);
127
+ };
128
+ hostEl.addEventListener("pointerdown", onClick);
129
+ return () => hostEl.removeEventListener("pointerdown", onClick);
130
+ }
@@ -0,0 +1,66 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.collectShapeEffects = collectShapeEffects;
4
+ exports.hasAnyEffect = hasAnyEffect;
5
+ exports.effectHexWithAlpha = effectHexWithAlpha;
6
+ exports.cssFilterForEffects = cssFilterForEffects;
7
+ const EMPTY = { outer: [], glow: [] };
8
+ function collectShapeEffects(s) {
9
+ const list = s.effects && s.effects.length ? s.effects : s.shadow ? [s.shadow] : undefined;
10
+ if (!list)
11
+ return EMPTY;
12
+ const out = { outer: [], glow: [] };
13
+ for (const fx of list) {
14
+ switch (fx.kind) {
15
+ case "outer":
16
+ out.outer.push(fx);
17
+ break;
18
+ case "inner":
19
+ if (!out.inner)
20
+ out.inner = fx;
21
+ break;
22
+ case "glow":
23
+ out.glow.push(fx);
24
+ break;
25
+ case "softEdge":
26
+ if (!out.softEdge)
27
+ out.softEdge = fx;
28
+ break;
29
+ case "reflection":
30
+ if (!out.reflection)
31
+ out.reflection = fx;
32
+ break;
33
+ default:
34
+ // blur/duotone/alphaMod 等位图效果由 paint-canvas 的图像通道处理,不在此列。
35
+ break;
36
+ }
37
+ }
38
+ return out;
39
+ }
40
+ function hasAnyEffect(fx) {
41
+ return fx.outer.length > 0 || fx.glow.length > 0 || !!fx.inner || !!fx.softEdge || !!fx.reflection;
42
+ }
43
+ function effectHexWithAlpha(color, alpha) {
44
+ if (alpha >= 1)
45
+ return color;
46
+ if (/^#([0-9a-f]{6})$/i.test(color)) {
47
+ const a = Math.round(Math.max(0, Math.min(1, alpha)) * 255)
48
+ .toString(16)
49
+ .padStart(2, "0");
50
+ return color + a;
51
+ }
52
+ return color;
53
+ }
54
+ /** outer shadow + glow 的 CSS filter 链(SVG style.filter / Canvas ctx.filter 通用)。 */
55
+ function cssFilterForEffects(fx) {
56
+ const parts = [];
57
+ for (const sh of fx.outer) {
58
+ parts.push(`drop-shadow(${sh.dx}px ${sh.dy}px ${sh.blur}px ${effectHexWithAlpha(sh.color, sh.alpha)})`);
59
+ }
60
+ for (const g of fx.glow) {
61
+ const c = effectHexWithAlpha(g.color, g.alpha);
62
+ parts.push(`drop-shadow(0 0 ${g.radius}px ${c})`);
63
+ parts.push(`drop-shadow(0 0 ${g.radius}px ${c})`);
64
+ }
65
+ return parts.join(" ");
66
+ }
@@ -0,0 +1,38 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.shapeFrontImageSrc = shapeFrontImageSrc;
4
+ const canvas_backend_1 = require("./canvas-backend");
5
+ const cache = new Map();
6
+ /** 文字 3D 的正面:字形画进 PNG,再贴到挤出体上。非文字返回 undefined。 */
7
+ function shapeFrontImageSrc(scene, shape) {
8
+ if (shape.kind !== "text" || typeof document === "undefined")
9
+ return undefined;
10
+ const key = JSON.stringify({
11
+ id: shape.id,
12
+ w: Math.round(shape.bbox.w),
13
+ h: Math.round(shape.bbox.h),
14
+ p: shape.paragraphs,
15
+ f: shape.fill ?? null,
16
+ i: shape.insets ?? null,
17
+ });
18
+ const hit = cache.get(key);
19
+ if (hit)
20
+ return hit;
21
+ const canvas = (0, canvas_backend_1.rasterizeShapeFront)(scene, shape.id);
22
+ if (!canvas)
23
+ return undefined;
24
+ let url;
25
+ try {
26
+ url = canvas.toDataURL("image/png");
27
+ }
28
+ catch {
29
+ return undefined;
30
+ }
31
+ cache.set(key, url);
32
+ if (cache.size > 40) {
33
+ const oldest = cache.keys().next().value;
34
+ if (oldest)
35
+ cache.delete(oldest);
36
+ }
37
+ return url;
38
+ }
@@ -0,0 +1,15 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.stageChromeBackground = stageChromeBackground;
4
+ /**
5
+ * CSS background for the stage / hybrid wrapper chrome around the scene.
6
+ * When the slide has a painted background, createScene injects a full-slide
7
+ * __bg_* shape — a second opaque underlay would show through image alpha or
8
+ * mask gradient edges. Use white only when the slide has no background paint.
9
+ */
10
+ function stageChromeBackground(slide) {
11
+ const bg = slide?.background;
12
+ if (!bg || bg.kind === "none")
13
+ return "#ffffff";
14
+ return "transparent";
15
+ }