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/tldraw.js
CHANGED
|
@@ -46,16 +46,21 @@ function createCustomShapeItem(id, bounds, content) {
|
|
|
46
46
|
|
|
47
47
|
// src/scene/link-item.ts
|
|
48
48
|
var LINK_PLUGIN_KEY = "canvuLink";
|
|
49
|
-
var
|
|
50
|
-
var
|
|
51
|
-
var
|
|
52
|
-
var
|
|
49
|
+
var DEFAULT_LINK_CARD_WIDTH = 320;
|
|
50
|
+
var DEFAULT_LINK_CARD_HEIGHT = 70;
|
|
51
|
+
var LINK_CARD_MIN_SCALE = 0.6;
|
|
52
|
+
var LINK_CARD_MAX_SCALE = 6;
|
|
53
|
+
var LINK_CARD_BORDER = "oklch(0.918 0.008 255)";
|
|
54
|
+
var LINK_CARD_BORDER_STRONG = "oklch(0.86 0.012 255)";
|
|
55
|
+
var LINK_CARD_ACCENT = "oklch(0.55 0.19 264)";
|
|
56
|
+
var LINK_CARD_ACCENT_DEEP = "oklch(0.46 0.18 264)";
|
|
57
|
+
var LINK_CARD_TITLE_COLOR = "oklch(0.26 0.022 265)";
|
|
58
|
+
var LINK_CARD_TEXT_COLOR = "oklch(0.55 0.022 265)";
|
|
53
59
|
var clamp = (value, min, max) => Math.min(max, Math.max(min, value));
|
|
54
60
|
var formatNumber = (value) => {
|
|
55
61
|
const rounded = Math.round(value * 100) / 100;
|
|
56
62
|
return Object.is(rounded, -0) ? "0" : String(rounded);
|
|
57
63
|
};
|
|
58
|
-
var escapeXmlAttribute = (value) => value.replaceAll("&", "&").replaceAll("<", "<").replaceAll(">", ">").replaceAll('"', """).replaceAll("'", "'");
|
|
59
64
|
var escapeHtmlText = (value) => value.replaceAll("&", "&").replaceAll("<", "<").replaceAll(">", ">");
|
|
60
65
|
var getLinkHostname = (href) => {
|
|
61
66
|
try {
|
|
@@ -65,49 +70,123 @@ var getLinkHostname = (href) => {
|
|
|
65
70
|
}
|
|
66
71
|
};
|
|
67
72
|
var buildLinkTextBand = (band) => {
|
|
68
|
-
const lineHeight = band.
|
|
73
|
+
const lineHeight = band.height;
|
|
69
74
|
const weight = band.fontWeight != null ? `font-weight:${band.fontWeight};` : "";
|
|
70
|
-
|
|
71
|
-
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;color:${band.color};overflow:hidden;word-break:break-word;${lineClampStyle}${weight}">${escapeHtmlText(band.text)}</div></foreignObject>`;
|
|
75
|
+
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>`;
|
|
72
76
|
};
|
|
73
|
-
|
|
77
|
+
var getLinkProtocol = (href) => {
|
|
78
|
+
try {
|
|
79
|
+
return new URL(href).protocol;
|
|
80
|
+
} catch {
|
|
81
|
+
return "";
|
|
82
|
+
}
|
|
83
|
+
};
|
|
84
|
+
var getLinkInitial = (hostname) => {
|
|
85
|
+
const first = hostname.trim().charAt(0).toUpperCase();
|
|
86
|
+
return first || "L";
|
|
87
|
+
};
|
|
88
|
+
var getStableLinkIdSuffix = (value) => {
|
|
89
|
+
let hash = 0;
|
|
90
|
+
for (const char of value) {
|
|
91
|
+
hash = hash * 31 + char.charCodeAt(0) >>> 0;
|
|
92
|
+
}
|
|
93
|
+
return hash.toString(36);
|
|
94
|
+
};
|
|
95
|
+
function buildLinkCardSvg(width, _height, link) {
|
|
74
96
|
const cardWidth = Math.max(1, width);
|
|
75
|
-
const
|
|
97
|
+
const scale = cardWidth / DEFAULT_LINK_CARD_WIDTH;
|
|
98
|
+
const contentWidth = DEFAULT_LINK_CARD_WIDTH;
|
|
99
|
+
const contentHeight = DEFAULT_LINK_CARD_HEIGHT;
|
|
76
100
|
const padding = 14;
|
|
77
|
-
const badgeSize =
|
|
78
|
-
const
|
|
79
|
-
const
|
|
101
|
+
const badgeSize = 42;
|
|
102
|
+
const gap = 13;
|
|
103
|
+
const buttonSize = 34;
|
|
104
|
+
const textX = padding + badgeSize + gap;
|
|
105
|
+
const textWidth = Math.max(1, contentWidth - textX - buttonSize - gap - padding);
|
|
80
106
|
const hostname = getLinkHostname(link.href);
|
|
81
107
|
const title = link.title?.trim() || hostname || "Link";
|
|
82
|
-
const
|
|
83
|
-
const
|
|
84
|
-
const
|
|
85
|
-
const
|
|
86
|
-
const
|
|
87
|
-
const
|
|
88
|
-
const
|
|
89
|
-
const
|
|
90
|
-
|
|
91
|
-
<image href="${escapeXmlAttribute(link.favicon)}" x="${formatNumber(padding)}" y="${formatNumber(padding)}" width="${formatNumber(badgeSize)}" height="${formatNumber(badgeSize)}" preserveAspectRatio="xMidYMid slice" clip-path="url(#canvu-link-badge)" />` : `<rect x="${formatNumber(padding)}" y="${formatNumber(padding)}" width="${formatNumber(badgeSize)}" height="${formatNumber(badgeSize)}" rx="12" fill="${LINK_CARD_ACCENT}" fill-opacity="0.1" stroke="${LINK_CARD_ACCENT}" stroke-opacity="0.3" stroke-width="1" />
|
|
92
|
-
<g transform="translate(${formatNumber(padding + badgeSize / 2)},${formatNumber(padding + badgeSize / 2)})" stroke="${LINK_CARD_ACCENT}" stroke-width="2.4" stroke-linecap="round" fill="none">
|
|
93
|
-
<path d="M-9 3 a6 6 0 0 1 0 -8 l4 -4 a6 6 0 0 1 8 8 l-2 2" />
|
|
94
|
-
<path d="M9 -3 a6 6 0 0 1 0 8 l-4 4 a6 6 0 0 1 -8 -8 l2 -2" />
|
|
95
|
-
</g>`;
|
|
96
|
-
const externalIconX = cardWidth - padding - 16;
|
|
97
|
-
const externalIcon = `<g transform="translate(${formatNumber(externalIconX)},${formatNumber(padding)})" stroke="${LINK_CARD_TEXT_COLOR}" stroke-width="1.6" stroke-linecap="round" stroke-linejoin="round" fill="none">
|
|
98
|
-
<path d="M6 1 H11 V6" />
|
|
99
|
-
<path d="M11 1 L4.5 7.5" />
|
|
100
|
-
<path d="M9 7 V10 a1 1 0 0 1 -1 1 H2 a1 1 0 0 1 -1 -1 V4 a1 1 0 0 1 1 -1 H5" />
|
|
101
|
-
</g>`;
|
|
108
|
+
const protocol = getLinkProtocol(link.href);
|
|
109
|
+
const subtitle = hostname || link.href;
|
|
110
|
+
const idSuffix = getStableLinkIdSuffix(`${hostname}:${link.href}`);
|
|
111
|
+
const gradientId = `canvu-link-favicon-gradient-${idSuffix}`;
|
|
112
|
+
const buttonX = contentWidth - padding - buttonSize;
|
|
113
|
+
const buttonY = (contentHeight - buttonSize) / 2;
|
|
114
|
+
const isSecure = protocol === "https:";
|
|
115
|
+
const subtitleX = isSecure ? textX + 13 : textX;
|
|
116
|
+
const subtitleWidth = isSecure ? textWidth - 13 : textWidth;
|
|
102
117
|
return `
|
|
103
|
-
<
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
118
|
+
<style>
|
|
119
|
+
.canvu-link-card-root .canvu-link-card { transition: transform .18s ease, filter .18s ease, stroke .18s ease; }
|
|
120
|
+
.canvu-link-card-root .canvu-link-open { opacity: 0; transform: translateX(-4px); transition: opacity .18s ease, transform .18s ease; }
|
|
121
|
+
.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}; }
|
|
122
|
+
.canvu-link-card-root:hover .canvu-link-open { opacity: 1; transform: translateX(0); }
|
|
123
|
+
</style>
|
|
124
|
+
<g class="canvu-link-card-root" transform="scale(${formatNumber(scale)})">
|
|
125
|
+
<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))" />
|
|
126
|
+
<defs>
|
|
127
|
+
<linearGradient id="${gradientId}" x1="8" y1="48" x2="48" y2="8" gradientUnits="userSpaceOnUse">
|
|
128
|
+
<stop stop-color="${LINK_CARD_ACCENT}" />
|
|
129
|
+
<stop offset="1" stop-color="${LINK_CARD_ACCENT_DEEP}" />
|
|
130
|
+
</linearGradient>
|
|
131
|
+
</defs>
|
|
132
|
+
<rect x="${formatNumber(padding)}" y="${formatNumber(padding)}" width="${formatNumber(badgeSize)}" height="${formatNumber(badgeSize)}" rx="11" fill="url(#${gradientId})" />
|
|
133
|
+
<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>
|
|
134
|
+
${buildLinkTextBand({ x: textX, y: 16, width: textWidth, height: 19, text: title, fontSize: 14.5, color: LINK_CARD_TITLE_COLOR, fontWeight: 700 })}
|
|
135
|
+
${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>` : ""}
|
|
136
|
+
${buildLinkTextBand({ x: subtitleX, y: 36, width: subtitleWidth, height: 17, text: subtitle, fontSize: 12.5, color: LINK_CARD_TEXT_COLOR })}
|
|
137
|
+
<g class="canvu-link-open" transform="translate(${formatNumber(buttonX)},${formatNumber(buttonY)})">
|
|
138
|
+
<rect width="${formatNumber(buttonSize)}" height="${formatNumber(buttonSize)}" rx="10" fill="#ffffff" stroke="${LINK_CARD_BORDER}" stroke-width="1" />
|
|
139
|
+
<g transform="translate(10,10)" stroke="${LINK_CARD_TEXT_COLOR}" stroke-width="1.8" stroke-linecap="round" stroke-linejoin="round" fill="none">
|
|
140
|
+
<path d="M8 2 H14 V8" />
|
|
141
|
+
<path d="M14 2 L7 9" />
|
|
142
|
+
<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" />
|
|
143
|
+
</g>
|
|
144
|
+
</g>
|
|
145
|
+
</g>
|
|
109
146
|
`;
|
|
110
147
|
}
|
|
148
|
+
var isCanvuLinkData = (value) => {
|
|
149
|
+
if (!value || typeof value !== "object") return false;
|
|
150
|
+
const candidate = value;
|
|
151
|
+
return typeof candidate.href === "string" && candidate.href.length > 0;
|
|
152
|
+
};
|
|
153
|
+
function getLinkData(item) {
|
|
154
|
+
const entry = item.pluginData?.[LINK_PLUGIN_KEY];
|
|
155
|
+
return isCanvuLinkData(entry) ? entry : null;
|
|
156
|
+
}
|
|
157
|
+
function rebuildLinkItemSvg(item) {
|
|
158
|
+
const link = getLinkData(item);
|
|
159
|
+
if (!link) return item;
|
|
160
|
+
const scale = clamp(
|
|
161
|
+
item.bounds.width / DEFAULT_LINK_CARD_WIDTH,
|
|
162
|
+
LINK_CARD_MIN_SCALE,
|
|
163
|
+
LINK_CARD_MAX_SCALE
|
|
164
|
+
);
|
|
165
|
+
const width = DEFAULT_LINK_CARD_WIDTH * scale;
|
|
166
|
+
const height = DEFAULT_LINK_CARD_HEIGHT * scale;
|
|
167
|
+
const bounds = {
|
|
168
|
+
...item.bounds,
|
|
169
|
+
width,
|
|
170
|
+
height
|
|
171
|
+
};
|
|
172
|
+
const customInnerSvg = buildLinkCardSvg(
|
|
173
|
+
DEFAULT_LINK_CARD_WIDTH,
|
|
174
|
+
DEFAULT_LINK_CARD_HEIGHT,
|
|
175
|
+
link
|
|
176
|
+
);
|
|
177
|
+
return {
|
|
178
|
+
...item,
|
|
179
|
+
x: bounds.x,
|
|
180
|
+
y: bounds.y,
|
|
181
|
+
bounds,
|
|
182
|
+
customIntrinsicSize: {
|
|
183
|
+
width: DEFAULT_LINK_CARD_WIDTH,
|
|
184
|
+
height: DEFAULT_LINK_CARD_HEIGHT
|
|
185
|
+
},
|
|
186
|
+
customInnerSvg,
|
|
187
|
+
childrenSvg: buildLinkCardSvg(width, height, link)
|
|
188
|
+
};
|
|
189
|
+
}
|
|
111
190
|
|
|
112
191
|
// src/scene/text-svg.ts
|
|
113
192
|
function escapeSvgTextContent(s) {
|
|
@@ -811,6 +890,9 @@ function rebuildItemSvg(item) {
|
|
|
811
890
|
)
|
|
812
891
|
};
|
|
813
892
|
}
|
|
893
|
+
if (getLinkData(item)) {
|
|
894
|
+
return rebuildLinkItemSvg(item);
|
|
895
|
+
}
|
|
814
896
|
if (k === "custom" && item.customIntrinsicSize && item.customInnerSvg) {
|
|
815
897
|
const b = normalizeRect(item.bounds);
|
|
816
898
|
return {
|