canvu-react 0.4.31 → 0.4.33
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/dist/{asset-hydration-CWhld14A.d.cts → asset-hydration-BFGZ3igr.d.cts} +1 -1
- package/dist/{asset-hydration-D35mHbUP.d.ts → asset-hydration-D6Q3TJL1.d.ts} +1 -1
- package/dist/chatbot.d.cts +2 -2
- package/dist/chatbot.d.ts +2 -2
- package/dist/index.cjs +173 -102
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +2 -2
- package/dist/index.d.ts +2 -2
- package/dist/index.js +173 -102
- package/dist/index.js.map +1 -1
- package/dist/{link-item-D870_X6P.d.cts → link-item-Dncuz2d_.d.cts} +3 -3
- package/dist/{link-item-Bg5vj0RI.d.ts → link-item-voRU0Up9.d.ts} +3 -3
- package/dist/native.cjs +220 -3
- package/dist/native.cjs.map +1 -1
- package/dist/native.js +220 -3
- package/dist/native.js.map +1 -1
- package/dist/react.cjs +244 -18
- package/dist/react.cjs.map +1 -1
- package/dist/react.d.cts +6 -6
- package/dist/react.d.ts +6 -6
- package/dist/react.js +244 -18
- package/dist/react.js.map +1 -1
- package/dist/realtime.cjs.map +1 -1
- package/dist/realtime.d.cts +3 -3
- package/dist/realtime.d.ts +3 -3
- package/dist/realtime.js.map +1 -1
- package/dist/tldraw.cjs +121 -39
- package/dist/tldraw.cjs.map +1 -1
- package/dist/tldraw.js +121 -39
- package/dist/tldraw.js.map +1 -1
- package/dist/{types-Bw1SdC9v.d.cts → types-BS-YG8Hx.d.cts} +1 -1
- package/dist/{types-DeXFfs7Y.d.ts → types-UZYYwK-v.d.ts} +1 -1
- package/package.json +1 -1
package/dist/native.js
CHANGED
|
@@ -29,11 +29,156 @@ function buildCustomShapeChildrenSvg(inner, intrinsic, bounds) {
|
|
|
29
29
|
return `<g transform="scale(${sx},${sy})">${inner}</g>`;
|
|
30
30
|
}
|
|
31
31
|
|
|
32
|
+
// src/scene/link-item.ts
|
|
33
|
+
var LINK_PLUGIN_KEY = "canvuLink";
|
|
34
|
+
var DEFAULT_LINK_CARD_WIDTH = 320;
|
|
35
|
+
var DEFAULT_LINK_CARD_HEIGHT = 70;
|
|
36
|
+
var LINK_CARD_MIN_SCALE = 0.6;
|
|
37
|
+
var LINK_CARD_MAX_SCALE = 6;
|
|
38
|
+
var LINK_CARD_ASPECT = DEFAULT_LINK_CARD_WIDTH / DEFAULT_LINK_CARD_HEIGHT;
|
|
39
|
+
var LINK_CARD_BORDER = "oklch(0.918 0.008 255)";
|
|
40
|
+
var LINK_CARD_BORDER_STRONG = "oklch(0.86 0.012 255)";
|
|
41
|
+
var LINK_CARD_ACCENT = "oklch(0.55 0.19 264)";
|
|
42
|
+
var LINK_CARD_ACCENT_DEEP = "oklch(0.46 0.18 264)";
|
|
43
|
+
var LINK_CARD_TITLE_COLOR = "oklch(0.26 0.022 265)";
|
|
44
|
+
var LINK_CARD_TEXT_COLOR = "oklch(0.55 0.022 265)";
|
|
45
|
+
var clamp = (value, min, max) => Math.min(max, Math.max(min, value));
|
|
46
|
+
var formatNumber = (value) => {
|
|
47
|
+
const rounded = Math.round(value * 100) / 100;
|
|
48
|
+
return Object.is(rounded, -0) ? "0" : String(rounded);
|
|
49
|
+
};
|
|
50
|
+
var escapeHtmlText = (value) => value.replaceAll("&", "&").replaceAll("<", "<").replaceAll(">", ">");
|
|
51
|
+
var getLinkHostname = (href) => {
|
|
52
|
+
try {
|
|
53
|
+
return new URL(href).hostname.replace(/^www\./, "");
|
|
54
|
+
} catch {
|
|
55
|
+
return href;
|
|
56
|
+
}
|
|
57
|
+
};
|
|
58
|
+
var buildLinkTextBand = (band) => {
|
|
59
|
+
const lineHeight = band.height;
|
|
60
|
+
const weight = band.fontWeight != null ? `font-weight:${band.fontWeight};` : "";
|
|
61
|
+
return `<foreignObject x="${formatNumber(band.x)}" y="${formatNumber(band.y)}" width="${formatNumber(Math.max(1, band.width))}" height="${formatNumber(Math.max(1, band.height))}"><div xmlns="http://www.w3.org/1999/xhtml" style="box-sizing:border-box;width:100%;height:100%;margin:0;font-family:system-ui,sans-serif;font-size:${formatNumber(band.fontSize)}px;line-height:${formatNumber(lineHeight)}px;letter-spacing:-0.01em;color:${band.color};overflow:hidden;white-space:nowrap;text-overflow:ellipsis;${weight}">${escapeHtmlText(band.text)}</div></foreignObject>`;
|
|
62
|
+
};
|
|
63
|
+
var getLinkProtocol = (href) => {
|
|
64
|
+
try {
|
|
65
|
+
return new URL(href).protocol;
|
|
66
|
+
} catch {
|
|
67
|
+
return "";
|
|
68
|
+
}
|
|
69
|
+
};
|
|
70
|
+
var getLinkInitial = (hostname) => {
|
|
71
|
+
const first = hostname.trim().charAt(0).toUpperCase();
|
|
72
|
+
return first || "L";
|
|
73
|
+
};
|
|
74
|
+
var getStableLinkIdSuffix = (value) => {
|
|
75
|
+
let hash = 0;
|
|
76
|
+
for (const char of value) {
|
|
77
|
+
hash = hash * 31 + char.charCodeAt(0) >>> 0;
|
|
78
|
+
}
|
|
79
|
+
return hash.toString(36);
|
|
80
|
+
};
|
|
81
|
+
function buildLinkCardSvg(width, _height, link) {
|
|
82
|
+
const cardWidth = Math.max(1, width);
|
|
83
|
+
const scale = cardWidth / DEFAULT_LINK_CARD_WIDTH;
|
|
84
|
+
const contentWidth = DEFAULT_LINK_CARD_WIDTH;
|
|
85
|
+
const contentHeight = DEFAULT_LINK_CARD_HEIGHT;
|
|
86
|
+
const padding = 14;
|
|
87
|
+
const badgeSize = 42;
|
|
88
|
+
const gap = 13;
|
|
89
|
+
const buttonSize = 34;
|
|
90
|
+
const textX = padding + badgeSize + gap;
|
|
91
|
+
const textWidth = Math.max(1, contentWidth - textX - buttonSize - gap - padding);
|
|
92
|
+
const hostname = getLinkHostname(link.href);
|
|
93
|
+
const title = link.title?.trim() || hostname || "Link";
|
|
94
|
+
const protocol = getLinkProtocol(link.href);
|
|
95
|
+
const subtitle = hostname || link.href;
|
|
96
|
+
const idSuffix = getStableLinkIdSuffix(`${hostname}:${link.href}`);
|
|
97
|
+
const gradientId = `canvu-link-favicon-gradient-${idSuffix}`;
|
|
98
|
+
const buttonX = contentWidth - padding - buttonSize;
|
|
99
|
+
const buttonY = (contentHeight - buttonSize) / 2;
|
|
100
|
+
const isSecure = protocol === "https:";
|
|
101
|
+
const subtitleX = isSecure ? textX + 13 : textX;
|
|
102
|
+
const subtitleWidth = isSecure ? textWidth - 13 : textWidth;
|
|
103
|
+
return `
|
|
104
|
+
<style>
|
|
105
|
+
.canvu-link-card-root .canvu-link-card { transition: transform .18s ease, filter .18s ease, stroke .18s ease; }
|
|
106
|
+
.canvu-link-card-root .canvu-link-open { opacity: 0; transform: translateX(-4px); transition: opacity .18s ease, transform .18s ease; }
|
|
107
|
+
.canvu-link-card-root:hover .canvu-link-card { transform: translateY(-2px); filter: drop-shadow(0 4px 14px oklch(0.4 0.05 265 / .08)) drop-shadow(0 1px 3px oklch(0.4 0.05 265 / .06)); stroke: ${LINK_CARD_BORDER_STRONG}; }
|
|
108
|
+
.canvu-link-card-root:hover .canvu-link-open { opacity: 1; transform: translateX(0); }
|
|
109
|
+
</style>
|
|
110
|
+
<g class="canvu-link-card-root" transform="scale(${formatNumber(scale)})">
|
|
111
|
+
<rect class="canvu-link-card" width="${formatNumber(contentWidth)}" height="${formatNumber(contentHeight)}" rx="16" fill="#ffffff" stroke="${LINK_CARD_BORDER}" stroke-width="1" filter="drop-shadow(0 1px 2px oklch(0.4 0.03 265 / .05)) drop-shadow(0 1px 1px oklch(0.4 0.03 265 / .04))" />
|
|
112
|
+
<defs>
|
|
113
|
+
<linearGradient id="${gradientId}" x1="8" y1="48" x2="48" y2="8" gradientUnits="userSpaceOnUse">
|
|
114
|
+
<stop stop-color="${LINK_CARD_ACCENT}" />
|
|
115
|
+
<stop offset="1" stop-color="${LINK_CARD_ACCENT_DEEP}" />
|
|
116
|
+
</linearGradient>
|
|
117
|
+
</defs>
|
|
118
|
+
<rect x="${formatNumber(padding)}" y="${formatNumber(padding)}" width="${formatNumber(badgeSize)}" height="${formatNumber(badgeSize)}" rx="11" fill="url(#${gradientId})" />
|
|
119
|
+
<text x="${formatNumber(padding + badgeSize / 2)}" y="${formatNumber(padding + badgeSize / 2 + 5)}" text-anchor="middle" font-family="system-ui,sans-serif" font-size="17" font-weight="700" fill="#ffffff">${escapeHtmlText(getLinkInitial(hostname))}</text>
|
|
120
|
+
${buildLinkTextBand({ x: textX, y: 16, width: textWidth, height: 19, text: title, fontSize: 14.5, color: LINK_CARD_TITLE_COLOR, fontWeight: 700 })}
|
|
121
|
+
${isSecure ? `<g transform="translate(${formatNumber(textX)},40)" stroke="${LINK_CARD_TEXT_COLOR}" stroke-width="1.3" stroke-linecap="round" stroke-linejoin="round" fill="none"><rect x="1.5" y="4.5" width="7" height="6" rx="1" /><path d="M3 4.5 V3 a2 2 0 0 1 4 0 v1.5" /></g>` : ""}
|
|
122
|
+
${buildLinkTextBand({ x: subtitleX, y: 36, width: subtitleWidth, height: 17, text: subtitle, fontSize: 12.5, color: LINK_CARD_TEXT_COLOR })}
|
|
123
|
+
<g class="canvu-link-open" transform="translate(${formatNumber(buttonX)},${formatNumber(buttonY)})">
|
|
124
|
+
<rect width="${formatNumber(buttonSize)}" height="${formatNumber(buttonSize)}" rx="10" fill="#ffffff" stroke="${LINK_CARD_BORDER}" stroke-width="1" />
|
|
125
|
+
<g transform="translate(10,10)" stroke="${LINK_CARD_TEXT_COLOR}" stroke-width="1.8" stroke-linecap="round" stroke-linejoin="round" fill="none">
|
|
126
|
+
<path d="M8 2 H14 V8" />
|
|
127
|
+
<path d="M14 2 L7 9" />
|
|
128
|
+
<path d="M12 10 V13 a1 1 0 0 1 -1 1 H3 a1 1 0 0 1 -1 -1 V5 a1 1 0 0 1 1 -1 H6" />
|
|
129
|
+
</g>
|
|
130
|
+
</g>
|
|
131
|
+
</g>
|
|
132
|
+
`;
|
|
133
|
+
}
|
|
134
|
+
var isCanvuLinkData = (value) => {
|
|
135
|
+
if (!value || typeof value !== "object") return false;
|
|
136
|
+
const candidate = value;
|
|
137
|
+
return typeof candidate.href === "string" && candidate.href.length > 0;
|
|
138
|
+
};
|
|
139
|
+
function getLinkData(item) {
|
|
140
|
+
const entry = item.pluginData?.[LINK_PLUGIN_KEY];
|
|
141
|
+
return isCanvuLinkData(entry) ? entry : null;
|
|
142
|
+
}
|
|
143
|
+
function rebuildLinkItemSvg(item) {
|
|
144
|
+
const link = getLinkData(item);
|
|
145
|
+
if (!link) return item;
|
|
146
|
+
const scale = clamp(
|
|
147
|
+
item.bounds.width / DEFAULT_LINK_CARD_WIDTH,
|
|
148
|
+
LINK_CARD_MIN_SCALE,
|
|
149
|
+
LINK_CARD_MAX_SCALE
|
|
150
|
+
);
|
|
151
|
+
const width = DEFAULT_LINK_CARD_WIDTH * scale;
|
|
152
|
+
const height = DEFAULT_LINK_CARD_HEIGHT * scale;
|
|
153
|
+
const bounds = {
|
|
154
|
+
...item.bounds,
|
|
155
|
+
width,
|
|
156
|
+
height
|
|
157
|
+
};
|
|
158
|
+
const customInnerSvg = buildLinkCardSvg(
|
|
159
|
+
DEFAULT_LINK_CARD_WIDTH,
|
|
160
|
+
DEFAULT_LINK_CARD_HEIGHT,
|
|
161
|
+
link
|
|
162
|
+
);
|
|
163
|
+
return {
|
|
164
|
+
...item,
|
|
165
|
+
x: bounds.x,
|
|
166
|
+
y: bounds.y,
|
|
167
|
+
bounds,
|
|
168
|
+
customIntrinsicSize: {
|
|
169
|
+
width: DEFAULT_LINK_CARD_WIDTH,
|
|
170
|
+
height: DEFAULT_LINK_CARD_HEIGHT
|
|
171
|
+
},
|
|
172
|
+
customInnerSvg,
|
|
173
|
+
childrenSvg: buildLinkCardSvg(width, height, link)
|
|
174
|
+
};
|
|
175
|
+
}
|
|
176
|
+
|
|
32
177
|
// src/scene/text-svg.ts
|
|
33
178
|
function escapeSvgTextContent(s) {
|
|
34
179
|
return s.replace(/&/g, "&").replace(/</g, "<").replace(/>/g, ">");
|
|
35
180
|
}
|
|
36
|
-
function
|
|
181
|
+
function escapeHtmlText2(s) {
|
|
37
182
|
return s.replace(/&/g, "&").replace(/</g, "<").replace(/>/g, ">");
|
|
38
183
|
}
|
|
39
184
|
var DEFAULT_TEXT_FONT_SIZE = 18;
|
|
@@ -148,9 +293,9 @@ function buildTextFixedBoundsSvg(content, width, height, fillColor = "#1d1d1d",
|
|
|
148
293
|
const trimmed = content.trim();
|
|
149
294
|
const padTop = EDIT_TOP_PAD_RATIO * fontSize;
|
|
150
295
|
if (trimmed.length === 0) {
|
|
151
|
-
return `<foreignObject width="${w}" height="${h}"><div xmlns="http://www.w3.org/1999/xhtml" style="box-sizing:border-box;width:100%;height:100%;margin:0;padding:${padTop}px 4px 0 4px;font-size:${fontSize}px;line-height:${lh}px;font-family:${TEXT_FONT_FAMILY};white-space:pre-wrap;word-wrap:break-word;overflow:hidden;color:#94a3b8;font-style:italic">${
|
|
296
|
+
return `<foreignObject width="${w}" height="${h}"><div xmlns="http://www.w3.org/1999/xhtml" style="box-sizing:border-box;width:100%;height:100%;margin:0;padding:${padTop}px 4px 0 4px;font-size:${fontSize}px;line-height:${lh}px;font-family:${TEXT_FONT_FAMILY};white-space:pre-wrap;word-wrap:break-word;overflow:hidden;color:#94a3b8;font-style:italic">${escapeHtmlText2(PLACEHOLDER)}</div></foreignObject>`;
|
|
152
297
|
}
|
|
153
|
-
const body =
|
|
298
|
+
const body = escapeHtmlText2(content);
|
|
154
299
|
return `<foreignObject width="${w}" height="${h}"><div xmlns="http://www.w3.org/1999/xhtml" style="box-sizing:border-box;width:100%;height:100%;margin:0;padding:${padTop}px 4px 0 4px;font-size:${fontSize}px;line-height:${lh}px;font-family:${TEXT_FONT_FAMILY};white-space:pre-wrap;word-wrap:break-word;overflow:hidden;color:${fillColor}">${body}</div></foreignObject>`;
|
|
155
300
|
}
|
|
156
301
|
|
|
@@ -748,6 +893,9 @@ function rebuildItemSvg(item) {
|
|
|
748
893
|
)
|
|
749
894
|
};
|
|
750
895
|
}
|
|
896
|
+
if (getLinkData(item)) {
|
|
897
|
+
return rebuildLinkItemSvg(item);
|
|
898
|
+
}
|
|
751
899
|
if (k === "custom" && item.customIntrinsicSize && item.customInnerSvg) {
|
|
752
900
|
const b = normalizeRect(item.bounds);
|
|
753
901
|
return {
|
|
@@ -3710,8 +3858,77 @@ function collectEraserTargetsAtWorldPoint(items, worldX, worldY, options) {
|
|
|
3710
3858
|
}
|
|
3711
3859
|
|
|
3712
3860
|
// src/interaction/mutations.ts
|
|
3861
|
+
var LINK_CORNER_HANDLES = /* @__PURE__ */ new Set(["nw", "ne", "se", "sw"]);
|
|
3862
|
+
var clamp2 = (value, min, max) => Math.min(max, Math.max(min, value));
|
|
3863
|
+
var clampLinkResizeBounds = (startBounds, nextBounds, handle, intrinsicWidth) => {
|
|
3864
|
+
const next = normalizeRect(nextBounds);
|
|
3865
|
+
const scale = clamp2(
|
|
3866
|
+
next.width / Math.max(1e-9, intrinsicWidth),
|
|
3867
|
+
LINK_CARD_MIN_SCALE,
|
|
3868
|
+
LINK_CARD_MAX_SCALE
|
|
3869
|
+
);
|
|
3870
|
+
const width = intrinsicWidth * scale;
|
|
3871
|
+
const height = width / LINK_CARD_ASPECT;
|
|
3872
|
+
const start = normalizeRect(startBounds);
|
|
3873
|
+
const x0 = start.x;
|
|
3874
|
+
const y0 = start.y;
|
|
3875
|
+
const x1 = start.x + start.width;
|
|
3876
|
+
const y1 = start.y + start.height;
|
|
3877
|
+
switch (handle) {
|
|
3878
|
+
case "nw":
|
|
3879
|
+
return { x: x1 - width, y: y1 - height, width, height };
|
|
3880
|
+
case "ne":
|
|
3881
|
+
return { x: x0, y: y1 - height, width, height };
|
|
3882
|
+
case "sw":
|
|
3883
|
+
return { x: x1 - width, y: y0, width, height };
|
|
3884
|
+
default:
|
|
3885
|
+
return { x: x0, y: y0, width, height };
|
|
3886
|
+
}
|
|
3887
|
+
};
|
|
3713
3888
|
function computeNewBoundsForResize(item, sb, handle, currentWorld) {
|
|
3714
3889
|
const rot = getItemRotationRad(item);
|
|
3890
|
+
const link = getLinkData(item);
|
|
3891
|
+
if (link && item.customIntrinsicSize) {
|
|
3892
|
+
if (!LINK_CORNER_HANDLES.has(handle)) return sb;
|
|
3893
|
+
const intrinsicWidth = Math.max(1e-9, item.customIntrinsicSize.width);
|
|
3894
|
+
if (Math.abs(rot) < 1e-12) {
|
|
3895
|
+
const next = computeResizeBoundsFixedAspect(
|
|
3896
|
+
sb,
|
|
3897
|
+
handle,
|
|
3898
|
+
currentWorld,
|
|
3899
|
+
LINK_CARD_ASPECT
|
|
3900
|
+
);
|
|
3901
|
+
return clampLinkResizeBounds(sb, next, handle, intrinsicWidth);
|
|
3902
|
+
}
|
|
3903
|
+
const local2 = worldToItemLocal(
|
|
3904
|
+
currentWorld.x,
|
|
3905
|
+
currentWorld.y,
|
|
3906
|
+
sb.x,
|
|
3907
|
+
sb.y,
|
|
3908
|
+
sb.width,
|
|
3909
|
+
sb.height,
|
|
3910
|
+
rot
|
|
3911
|
+
);
|
|
3912
|
+
const localBounds3 = { x: 0, y: 0, width: sb.width, height: sb.height };
|
|
3913
|
+
const nextLocal = computeResizeBoundsFixedAspect(
|
|
3914
|
+
localBounds3,
|
|
3915
|
+
handle,
|
|
3916
|
+
local2,
|
|
3917
|
+
LINK_CARD_ASPECT
|
|
3918
|
+
);
|
|
3919
|
+
const clamped = clampLinkResizeBounds(
|
|
3920
|
+
localBounds3,
|
|
3921
|
+
nextLocal,
|
|
3922
|
+
handle,
|
|
3923
|
+
intrinsicWidth
|
|
3924
|
+
);
|
|
3925
|
+
return {
|
|
3926
|
+
x: sb.x + clamped.x,
|
|
3927
|
+
y: sb.y + clamped.y,
|
|
3928
|
+
width: clamped.width,
|
|
3929
|
+
height: clamped.height
|
|
3930
|
+
};
|
|
3931
|
+
}
|
|
3715
3932
|
if (Math.abs(rot) < 1e-12) {
|
|
3716
3933
|
if (item.toolKind === "image") {
|
|
3717
3934
|
let aspect;
|