@webstudio-is/sdk-components-react 0.95.0 → 0.97.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 (128) hide show
  1. package/lib/components.js +747 -33
  2. package/lib/metas.js +3635 -33
  3. package/lib/props.js +16274 -33
  4. package/lib/types/vimeo-preview-image.d.ts +2 -2
  5. package/package.json +8 -8
  6. package/lib/__generated__/blockquote.props.js +0 -514
  7. package/lib/__generated__/body.props.js +0 -508
  8. package/lib/__generated__/bold.props.js +0 -508
  9. package/lib/__generated__/box.props.js +0 -527
  10. package/lib/__generated__/button.props.js +0 -564
  11. package/lib/__generated__/checkbox.props.js +0 -666
  12. package/lib/__generated__/code-text.props.js +0 -508
  13. package/lib/__generated__/form.props.js +0 -556
  14. package/lib/__generated__/fragment.props.js +0 -2
  15. package/lib/__generated__/heading.props.js +0 -516
  16. package/lib/__generated__/html-embed.props.js +0 -9
  17. package/lib/__generated__/image.props.js +0 -581
  18. package/lib/__generated__/input.props.js +0 -673
  19. package/lib/__generated__/italic.props.js +0 -508
  20. package/lib/__generated__/label.props.js +0 -520
  21. package/lib/__generated__/link.props.js +0 -562
  22. package/lib/__generated__/list-item.props.js +0 -508
  23. package/lib/__generated__/list.props.js +0 -534
  24. package/lib/__generated__/paragraph.props.js +0 -508
  25. package/lib/__generated__/radio-button.props.js +0 -666
  26. package/lib/__generated__/rich-text-link.props.js +0 -562
  27. package/lib/__generated__/separator.props.js +0 -508
  28. package/lib/__generated__/slot.props.js +0 -2
  29. package/lib/__generated__/span.props.js +0 -508
  30. package/lib/__generated__/subscript.props.js +0 -508
  31. package/lib/__generated__/superscript.props.js +0 -508
  32. package/lib/__generated__/text.props.js +0 -516
  33. package/lib/__generated__/textarea.props.js +0 -575
  34. package/lib/__generated__/vimeo-play-button.props.js +0 -563
  35. package/lib/__generated__/vimeo-preview-image.props.js +0 -580
  36. package/lib/__generated__/vimeo-spinner.props.js +0 -508
  37. package/lib/__generated__/vimeo.props.js +0 -665
  38. package/lib/blockquote.js +0 -12
  39. package/lib/blockquote.stories.js +0 -11
  40. package/lib/blockquote.ws.js +0 -75
  41. package/lib/body.js +0 -6
  42. package/lib/body.stories.js +0 -11
  43. package/lib/body.ws.js +0 -31
  44. package/lib/bold.js +0 -6
  45. package/lib/bold.stories.js +0 -11
  46. package/lib/bold.ws.js +0 -21
  47. package/lib/box.js +0 -12
  48. package/lib/box.stories.js +0 -11
  49. package/lib/box.ws.js +0 -44
  50. package/lib/button.js +0 -8
  51. package/lib/button.stories.js +0 -11
  52. package/lib/button.ws.js +0 -36
  53. package/lib/checkbox.js +0 -6
  54. package/lib/checkbox.ws.js +0 -57
  55. package/lib/code-text.js +0 -10
  56. package/lib/code-text.stories.js +0 -11
  57. package/lib/code-text.ws.js +0 -54
  58. package/lib/form.js +0 -6
  59. package/lib/form.stories.js +0 -11
  60. package/lib/form.ws.js +0 -63
  61. package/lib/fragment.js +0 -7
  62. package/lib/fragment.ws.js +0 -10
  63. package/lib/heading.js +0 -12
  64. package/lib/heading.stories.js +0 -11
  65. package/lib/heading.ws.js +0 -37
  66. package/lib/html-embed.js +0 -63
  67. package/lib/html-embed.stories.js +0 -11
  68. package/lib/html-embed.ws.js +0 -28
  69. package/lib/image.js +0 -74
  70. package/lib/image.stories.js +0 -7
  71. package/lib/image.ws.js +0 -48
  72. package/lib/input.js +0 -6
  73. package/lib/input.stories.js +0 -9
  74. package/lib/input.ws.js +0 -43
  75. package/lib/italic.js +0 -6
  76. package/lib/italic.stories.js +0 -11
  77. package/lib/italic.ws.js +0 -27
  78. package/lib/label.js +0 -6
  79. package/lib/label.ws.js +0 -40
  80. package/lib/link.js +0 -33
  81. package/lib/link.stories.js +0 -11
  82. package/lib/link.ws.js +0 -60
  83. package/lib/list-item.js +0 -12
  84. package/lib/list-item.stories.js +0 -11
  85. package/lib/list-item.ws.js +0 -32
  86. package/lib/list.js +0 -12
  87. package/lib/list.stories.js +0 -13
  88. package/lib/list.ws.js +0 -53
  89. package/lib/paragraph.js +0 -6
  90. package/lib/paragraph.stories.js +0 -11
  91. package/lib/paragraph.ws.js +0 -32
  92. package/lib/radio-button.js +0 -6
  93. package/lib/radio-button.ws.js +0 -58
  94. package/lib/rich-text-link.js +0 -6
  95. package/lib/rich-text-link.stories.js +0 -11
  96. package/lib/rich-text-link.ws.js +0 -9
  97. package/lib/separator.js +0 -12
  98. package/lib/separator.stories.js +0 -7
  99. package/lib/separator.ws.js +0 -50
  100. package/lib/slot.js +0 -14
  101. package/lib/slot.stories.js +0 -11
  102. package/lib/slot.ws.js +0 -14
  103. package/lib/span.js +0 -6
  104. package/lib/span.stories.js +0 -11
  105. package/lib/span.ws.js +0 -21
  106. package/lib/subscript.js +0 -6
  107. package/lib/subscript.stories.js +0 -11
  108. package/lib/subscript.ws.js +0 -21
  109. package/lib/superscript.js +0 -6
  110. package/lib/superscript.stories.js +0 -11
  111. package/lib/superscript.ws.js +0 -21
  112. package/lib/text.js +0 -12
  113. package/lib/text.stories.js +0 -11
  114. package/lib/text.ws.js +0 -37
  115. package/lib/textarea.js +0 -6
  116. package/lib/textarea.ws.js +0 -44
  117. package/lib/vimeo-play-button.js +0 -19
  118. package/lib/vimeo-play-button.stories.js +0 -11
  119. package/lib/vimeo-play-button.ws.js +0 -25
  120. package/lib/vimeo-preview-image.js +0 -21
  121. package/lib/vimeo-preview-image.stories.js +0 -11
  122. package/lib/vimeo-preview-image.ws.js +0 -19
  123. package/lib/vimeo-spinner.js +0 -18
  124. package/lib/vimeo-spinner.stories.js +0 -11
  125. package/lib/vimeo-spinner.ws.js +0 -23
  126. package/lib/vimeo.js +0 -279
  127. package/lib/vimeo.stories.js +0 -11
  128. package/lib/vimeo.ws.js +0 -327
package/lib/components.js CHANGED
@@ -1,33 +1,747 @@
1
- "use strict";
2
- export { Slot } from "./slot";
3
- export { Fragment } from "./fragment";
4
- export { HtmlEmbed } from "./html-embed";
5
- export { Body } from "./body";
6
- export { Box } from "./box";
7
- export { Text } from "./text";
8
- export { Heading } from "./heading";
9
- export { Paragraph } from "./paragraph";
10
- export { Link } from "./link";
11
- export { RichTextLink } from "./rich-text-link";
12
- export { Span } from "./span";
13
- export { Bold } from "./bold";
14
- export { Italic } from "./italic";
15
- export { Superscript } from "./superscript";
16
- export { Subscript } from "./subscript";
17
- export { Button } from "./button";
18
- export { Input } from "./input";
19
- export { Form } from "./form";
20
- export { Image } from "./image";
21
- export { Blockquote } from "./blockquote";
22
- export { List } from "./list";
23
- export { ListItem } from "./list-item";
24
- export { Separator } from "./separator";
25
- export { CodeText } from "./code-text";
26
- export { Label } from "./label";
27
- export { Textarea } from "./textarea";
28
- export { RadioButton } from "./radio-button";
29
- export { Checkbox } from "./checkbox";
30
- export { Vimeo } from "./vimeo";
31
- export { VimeoPreviewImage } from "./vimeo-preview-image";
32
- export { VimeoPlayButton } from "./vimeo-play-button";
33
- export { VimeoSpinner } from "./vimeo-spinner";
1
+ // src/slot.tsx
2
+ import { forwardRef } from "react";
3
+ import { jsx } from "react/jsx-runtime";
4
+ var Slot = forwardRef((props, ref) => {
5
+ return /* @__PURE__ */ jsx(
6
+ "div",
7
+ {
8
+ ...props,
9
+ ref,
10
+ style: { display: props.children ? "contents" : "block" }
11
+ }
12
+ );
13
+ });
14
+ Slot.displayName = "Slot";
15
+
16
+ // src/fragment.tsx
17
+ import { forwardRef as forwardRef2 } from "react";
18
+ import { jsx as jsx2 } from "react/jsx-runtime";
19
+ var Fragment = forwardRef2((props, ref) => {
20
+ return /* @__PURE__ */ jsx2("div", { ...props, ref, style: { display: "contents" } });
21
+ });
22
+ Fragment.displayName = "Fragment";
23
+
24
+ // src/html-embed.tsx
25
+ import {
26
+ forwardRef as forwardRef3,
27
+ useContext,
28
+ useEffect,
29
+ useRef
30
+ } from "react";
31
+ import { mergeRefs } from "@react-aria/utils";
32
+ import { ReactSdkContext } from "@webstudio-is/react-sdk";
33
+ import { jsx as jsx3 } from "react/jsx-runtime";
34
+ var ExecutableHtml = (props) => {
35
+ const { code, innerRef, ...rest } = props;
36
+ const containerRef = useRef(null);
37
+ useEffect(() => {
38
+ const container = containerRef.current;
39
+ if (container === null || code === void 0) {
40
+ return;
41
+ }
42
+ const range = document.createRange();
43
+ range.setStart(container, 0);
44
+ const fragment = range.createContextualFragment(code);
45
+ while (container.firstChild) {
46
+ container.removeChild(container.firstChild);
47
+ }
48
+ container.append(fragment);
49
+ }, [code]);
50
+ return /* @__PURE__ */ jsx3(
51
+ "div",
52
+ {
53
+ ...rest,
54
+ ref: mergeRefs(innerRef, containerRef),
55
+ style: { display: "contents" }
56
+ }
57
+ );
58
+ };
59
+ var InnerHtml = (props) => {
60
+ const { code, innerRef, ...rest } = props;
61
+ return /* @__PURE__ */ jsx3(
62
+ "div",
63
+ {
64
+ ...rest,
65
+ ref: innerRef,
66
+ style: { display: "contents" },
67
+ dangerouslySetInnerHTML: { __html: props.code ?? "" }
68
+ }
69
+ );
70
+ };
71
+ var Placeholder = (props) => {
72
+ const { code, innerRef, ...rest } = props;
73
+ return /* @__PURE__ */ jsx3("div", { ref: innerRef, ...rest, style: { padding: "20px" }, children: 'Open the "Settings" panel to insert HTML code' });
74
+ };
75
+ var HtmlEmbed = forwardRef3((props, ref) => {
76
+ const { renderer } = useContext(ReactSdkContext);
77
+ const { code, executeScriptOnCanvas, ...rest } = props;
78
+ if (code === void 0 || code.trim().length === 0) {
79
+ return /* @__PURE__ */ jsx3(Placeholder, { innerRef: ref, ...rest });
80
+ }
81
+ if (renderer === "canvas" && executeScriptOnCanvas === true || renderer === "preview") {
82
+ return /* @__PURE__ */ jsx3(ExecutableHtml, { innerRef: ref, code, ...rest });
83
+ }
84
+ return /* @__PURE__ */ jsx3(InnerHtml, { innerRef: ref, code, ...rest });
85
+ });
86
+ HtmlEmbed.displayName = "HtmlEmbed";
87
+
88
+ // src/body.tsx
89
+ import { forwardRef as forwardRef4 } from "react";
90
+ import { jsx as jsx4 } from "react/jsx-runtime";
91
+ var Body = forwardRef4((props, ref) => /* @__PURE__ */ jsx4("body", { ...props, ref }));
92
+ Body.displayName = "Body";
93
+
94
+ // src/box.tsx
95
+ import {
96
+ createElement,
97
+ forwardRef as forwardRef5
98
+ } from "react";
99
+ var defaultTag = "div";
100
+ var Box = forwardRef5(
101
+ ({ tag = defaultTag, ...props }, ref) => {
102
+ return createElement(tag, { ...props, ref });
103
+ }
104
+ );
105
+ Box.displayName = "Box";
106
+
107
+ // src/text.tsx
108
+ import {
109
+ createElement as createElement2,
110
+ forwardRef as forwardRef6
111
+ } from "react";
112
+ var defaultTag2 = "div";
113
+ var Text = forwardRef6(
114
+ ({ tag = defaultTag2, ...props }, ref) => {
115
+ return createElement2(tag, { ...props, ref });
116
+ }
117
+ );
118
+ Text.displayName = "Text";
119
+
120
+ // src/heading.tsx
121
+ import {
122
+ forwardRef as forwardRef7,
123
+ createElement as createElement3
124
+ } from "react";
125
+ var defaultTag3 = "h1";
126
+ var Heading = forwardRef7(
127
+ ({ tag = defaultTag3, ...props }, ref) => {
128
+ return createElement3(tag, { ...props, ref });
129
+ }
130
+ );
131
+ Heading.displayName = "Heading";
132
+
133
+ // src/paragraph.tsx
134
+ import { forwardRef as forwardRef8 } from "react";
135
+ import { jsx as jsx5 } from "react/jsx-runtime";
136
+ var Paragraph = forwardRef8((props, ref) => /* @__PURE__ */ jsx5("p", { ...props, ref }));
137
+ Paragraph.displayName = "Paragraph";
138
+
139
+ // src/link.tsx
140
+ import { forwardRef as forwardRef9, useContext as useContext2 } from "react";
141
+ import {
142
+ usePropUrl,
143
+ getInstanceIdFromComponentProps,
144
+ ReactSdkContext as ReactSdkContext2
145
+ } from "@webstudio-is/react-sdk";
146
+ import { jsx as jsx6 } from "react/jsx-runtime";
147
+ var Link = forwardRef9((props, ref) => {
148
+ const { assetBaseUrl } = useContext2(ReactSdkContext2);
149
+ const href = usePropUrl(getInstanceIdFromComponentProps(props), "href");
150
+ let url = "#";
151
+ switch (href?.type) {
152
+ case "page": {
153
+ url = href.page.path === "" ? "/" : href.page.path;
154
+ const urlTo = new URL(url, "https://any-valid.url");
155
+ url = urlTo.pathname;
156
+ if (href.hash !== void 0) {
157
+ urlTo.hash = encodeURIComponent(href.hash);
158
+ url = `${urlTo.pathname}${urlTo.hash}`;
159
+ }
160
+ break;
161
+ }
162
+ case "asset":
163
+ url = `${assetBaseUrl}${href.asset.name}`;
164
+ break;
165
+ case "string":
166
+ url = href.url;
167
+ }
168
+ return /* @__PURE__ */ jsx6("a", { ...props, href: url, ref });
169
+ });
170
+ Link.displayName = "Link";
171
+
172
+ // src/rich-text-link.tsx
173
+ import { forwardRef as forwardRef10 } from "react";
174
+ import { jsx as jsx7 } from "react/jsx-runtime";
175
+ var RichTextLink = forwardRef10((props, ref) => /* @__PURE__ */ jsx7(Link, { ...props, ref }));
176
+ RichTextLink.displayName = "RichTextLink";
177
+
178
+ // src/span.tsx
179
+ import { forwardRef as forwardRef11 } from "react";
180
+ import { jsx as jsx8 } from "react/jsx-runtime";
181
+ var Span = forwardRef11((props, ref) => /* @__PURE__ */ jsx8("span", { ...props, ref }));
182
+ Span.displayName = "Span";
183
+
184
+ // src/bold.tsx
185
+ import { forwardRef as forwardRef12 } from "react";
186
+ import { jsx as jsx9 } from "react/jsx-runtime";
187
+ var Bold = forwardRef12((props, ref) => /* @__PURE__ */ jsx9("b", { ...props, ref }));
188
+ Bold.displayName = "Bold";
189
+
190
+ // src/italic.tsx
191
+ import { forwardRef as forwardRef13 } from "react";
192
+ import { jsx as jsx10 } from "react/jsx-runtime";
193
+ var Italic = forwardRef13((props, ref) => /* @__PURE__ */ jsx10("i", { ...props, ref }));
194
+ Italic.displayName = "Italic";
195
+
196
+ // src/superscript.tsx
197
+ import { forwardRef as forwardRef14 } from "react";
198
+ import { jsx as jsx11 } from "react/jsx-runtime";
199
+ var Superscript = forwardRef14((props, ref) => /* @__PURE__ */ jsx11("sup", { ...props, ref }));
200
+ Superscript.displayName = "Bold";
201
+
202
+ // src/subscript.tsx
203
+ import { forwardRef as forwardRef15 } from "react";
204
+ import { jsx as jsx12 } from "react/jsx-runtime";
205
+ var Subscript = forwardRef15((props, ref) => /* @__PURE__ */ jsx12("sub", { ...props, ref }));
206
+ Subscript.displayName = "Subscript";
207
+
208
+ // src/button.tsx
209
+ import { forwardRef as forwardRef16 } from "react";
210
+ import { jsx as jsx13 } from "react/jsx-runtime";
211
+ var Button = forwardRef16(
212
+ ({ type = "submit", children, ...props }, ref) => /* @__PURE__ */ jsx13("button", { type, ...props, ref, children })
213
+ );
214
+ Button.displayName = "Button";
215
+
216
+ // src/input.tsx
217
+ import { forwardRef as forwardRef17 } from "react";
218
+ import { jsx as jsx14 } from "react/jsx-runtime";
219
+ var Input = forwardRef17(({ children: _children, ...props }, ref) => /* @__PURE__ */ jsx14("input", { ...props, ref }));
220
+ Input.displayName = "Input";
221
+
222
+ // src/form.tsx
223
+ import { forwardRef as forwardRef18 } from "react";
224
+ import { jsx as jsx15 } from "react/jsx-runtime";
225
+ var Form = forwardRef18(({ children, ...props }, ref) => /* @__PURE__ */ jsx15("form", { ...props, ref, children }));
226
+ Form.displayName = "Form";
227
+
228
+ // src/image.tsx
229
+ import {
230
+ forwardRef as forwardRef19,
231
+ useContext as useContext3
232
+ } from "react";
233
+ import { Image as WebstudioImage } from "@webstudio-is/image";
234
+ import {
235
+ usePropAsset,
236
+ getInstanceIdFromComponentProps as getInstanceIdFromComponentProps2,
237
+ ReactSdkContext as ReactSdkContext3
238
+ } from "@webstudio-is/react-sdk";
239
+ import { jsx as jsx16 } from "react/jsx-runtime";
240
+ var imagePlaceholderSvg = `data:image/svg+xml;base64,${btoa(`<svg
241
+ width="140"
242
+ height="140"
243
+ viewBox="0 0 600 600"
244
+ fill="none"
245
+ xmlns="http://www.w3.org/2000/svg"
246
+ >
247
+ <rect width="600" height="600" fill="#CCCCCC" />
248
+ <path
249
+ fill-rule="evenodd"
250
+ clip-rule="evenodd"
251
+ d="M450 170H150C141.716 170 135 176.716 135 185V415C135 423.284 141.716 430 150 430H450C458.284 430 465 423.284 465 415V185C465 176.716 458.284 170 450 170ZM150 145C127.909 145 110 162.909 110 185V415C110 437.091 127.909 455 150 455H450C472.091 455 490 437.091 490 415V185C490 162.909 472.091 145 450 145H150Z"
252
+ fill="#A2A2A2"
253
+ />
254
+ <path
255
+ d="M237.135 235.012C237.135 255.723 220.345 272.512 199.635 272.512C178.924 272.512 162.135 255.723 162.135 235.012C162.135 214.301 178.924 197.512 199.635 197.512C220.345 197.512 237.135 214.301 237.135 235.012Z"
256
+ fill="#A2A2A2"
257
+ />
258
+ <path
259
+ d="M160 405V367.205L221.609 306.364L256.552 338.628L358.161 234L440 316.043V405H160Z"
260
+ fill="#A2A2A2"
261
+ />
262
+ </svg>`)}`;
263
+ var Image = forwardRef19(
264
+ ({ loading = "lazy", ...props }, ref) => {
265
+ const { imageLoader } = useContext3(ReactSdkContext3);
266
+ const asset = usePropAsset(getInstanceIdFromComponentProps2(props), "src");
267
+ const src = asset?.name ?? props.src;
268
+ if (asset == null) {
269
+ return /* @__PURE__ */ jsx16(
270
+ "img",
271
+ {
272
+ loading,
273
+ ...props,
274
+ src: src || imagePlaceholderSvg,
275
+ ref
276
+ },
277
+ src
278
+ );
279
+ }
280
+ return /* @__PURE__ */ jsx16(
281
+ WebstudioImage,
282
+ {
283
+ loading,
284
+ ...props,
285
+ loader: imageLoader,
286
+ src,
287
+ ref
288
+ },
289
+ src
290
+ );
291
+ }
292
+ );
293
+ Image.displayName = "Image";
294
+
295
+ // src/blockquote.tsx
296
+ import {
297
+ forwardRef as forwardRef20,
298
+ createElement as createElement4
299
+ } from "react";
300
+ var defaultTag4 = "blockquote";
301
+ var Blockquote = forwardRef20(
302
+ (props, ref) => {
303
+ return createElement4(defaultTag4, { ...props, ref });
304
+ }
305
+ );
306
+ Blockquote.displayName = "Blockquote";
307
+
308
+ // src/list.tsx
309
+ import {
310
+ forwardRef as forwardRef21,
311
+ createElement as createElement5
312
+ } from "react";
313
+ var unorderedTag = "ul";
314
+ var orderedTag = "ol";
315
+ var List = forwardRef21(({ ordered = false, ...props }, ref) => {
316
+ const tag = ordered ? orderedTag : unorderedTag;
317
+ return createElement5(tag, { ...props, ref });
318
+ });
319
+ List.displayName = "List";
320
+
321
+ // src/list-item.tsx
322
+ import {
323
+ forwardRef as forwardRef22,
324
+ createElement as createElement6
325
+ } from "react";
326
+ var defaultTag5 = "li";
327
+ var ListItem = forwardRef22(
328
+ (props, ref) => {
329
+ return createElement6(defaultTag5, { ...props, ref });
330
+ }
331
+ );
332
+ ListItem.displayName = "ListItem";
333
+
334
+ // src/separator.tsx
335
+ import {
336
+ forwardRef as forwardRef23,
337
+ createElement as createElement7
338
+ } from "react";
339
+ var defaultTag6 = "hr";
340
+ var Separator = forwardRef23(
341
+ (props, ref) => {
342
+ return createElement7(defaultTag6, { ...props, ref });
343
+ }
344
+ );
345
+ Separator.displayName = "Separator";
346
+
347
+ // src/code-text.tsx
348
+ import {
349
+ forwardRef as forwardRef24,
350
+ createElement as createElement8
351
+ } from "react";
352
+ var defaultTag7 = "code";
353
+ var CodeText = forwardRef24((props, ref) => {
354
+ return createElement8(defaultTag7, { ...props, ref });
355
+ });
356
+ CodeText.displayName = "CodeText";
357
+
358
+ // src/label.tsx
359
+ import { forwardRef as forwardRef25 } from "react";
360
+ import { jsx as jsx17 } from "react/jsx-runtime";
361
+ var Label = forwardRef25((props, ref) => /* @__PURE__ */ jsx17("label", { ...props, ref }));
362
+ Label.displayName = "Label";
363
+
364
+ // src/textarea.tsx
365
+ import { forwardRef as forwardRef26 } from "react";
366
+ import { jsx as jsx18 } from "react/jsx-runtime";
367
+ var Textarea = forwardRef26(({ children: _children, ...props }, ref) => /* @__PURE__ */ jsx18("textarea", { ...props, ref }));
368
+ Textarea.displayName = "Textarea";
369
+
370
+ // src/radio-button.tsx
371
+ import { forwardRef as forwardRef27 } from "react";
372
+ import { jsx as jsx19 } from "react/jsx-runtime";
373
+ var RadioButton = forwardRef27(({ children: _children, ...props }, ref) => /* @__PURE__ */ jsx19("input", { ...props, type: "radio", ref }));
374
+ RadioButton.displayName = "RadioButton";
375
+
376
+ // src/checkbox.tsx
377
+ import { forwardRef as forwardRef28 } from "react";
378
+ import { jsx as jsx20 } from "react/jsx-runtime";
379
+ var Checkbox = forwardRef28(({ children: _children, ...props }, ref) => /* @__PURE__ */ jsx20("input", { ...props, type: "checkbox", ref }));
380
+ Checkbox.displayName = "Checkbox";
381
+
382
+ // src/vimeo.tsx
383
+ import { colord } from "colord";
384
+ import {
385
+ forwardRef as forwardRef29,
386
+ useState,
387
+ useRef as useRef2,
388
+ useEffect as useEffect2,
389
+ useContext as useContext4,
390
+ createContext,
391
+ useMemo
392
+ } from "react";
393
+ import { ReactSdkContext as ReactSdkContext4 } from "@webstudio-is/react-sdk";
394
+ import { shallowEqual } from "shallow-equal";
395
+ import { jsx as jsx21 } from "react/jsx-runtime";
396
+ var getUrl = (options) => {
397
+ if (options.url === void 0) {
398
+ return;
399
+ }
400
+ let url;
401
+ try {
402
+ const userUrl = new URL(options.url);
403
+ url = new URL(IFRAME_CDN);
404
+ url.pathname = `/video${userUrl.pathname}`;
405
+ } catch {
406
+ }
407
+ if (url === void 0) {
408
+ return;
409
+ }
410
+ let option;
411
+ for (option in options) {
412
+ const value = options[option];
413
+ if (option === "url" || value === void 0) {
414
+ continue;
415
+ }
416
+ url.searchParams.append(option, value.toString());
417
+ }
418
+ url.searchParams.set("autoplay", "true");
419
+ if (typeof options.color === "string") {
420
+ const color = colord(options.color).toHex().replace("#", "");
421
+ url.searchParams.set("color", color);
422
+ }
423
+ if (options.portrait) {
424
+ url.searchParams.set("title", "true");
425
+ }
426
+ if (options.byline) {
427
+ url.searchParams.set("portrait", "true");
428
+ url.searchParams.set("title", "true");
429
+ }
430
+ return url.toString();
431
+ };
432
+ var preconnect = (url) => {
433
+ const link = document.createElement("link");
434
+ link.rel = "preconnect";
435
+ link.href = url;
436
+ link.crossOrigin = "true";
437
+ document.head.append(link);
438
+ };
439
+ var warmed = false;
440
+ var PLAYER_CDN = "https://f.vimeocdn.com";
441
+ var IFRAME_CDN = "https://player.vimeo.com";
442
+ var IMAGE_CDN = "https://i.vimeocdn.com";
443
+ var warmConnections = () => {
444
+ if (warmed) {
445
+ return;
446
+ }
447
+ preconnect(PLAYER_CDN);
448
+ preconnect(IFRAME_CDN);
449
+ preconnect(IMAGE_CDN);
450
+ warmed = true;
451
+ };
452
+ var createPlayer = (parent, options, callback) => {
453
+ const url = getUrl(options);
454
+ if (url === void 0) {
455
+ return;
456
+ }
457
+ const iframe = document.createElement("iframe");
458
+ iframe.setAttribute(
459
+ "allow",
460
+ "accelerometer; autoplay; encrypted-media; gyroscope; picture-in-picture;"
461
+ );
462
+ iframe.setAttribute("frameborder", "0");
463
+ iframe.setAttribute("allowfullscreen", "true");
464
+ iframe.setAttribute("src", url);
465
+ iframe.setAttribute(
466
+ "style",
467
+ "position: absolute; width: 100%; height: 100%; opacity: 0; transition: opacity 1s;"
468
+ );
469
+ iframe.addEventListener(
470
+ "load",
471
+ () => {
472
+ iframe.style.opacity = "1";
473
+ callback();
474
+ },
475
+ { once: true }
476
+ );
477
+ parent.appendChild(iframe);
478
+ return () => {
479
+ iframe.parentElement?.removeChild(iframe);
480
+ };
481
+ };
482
+ var getVideoId = (url) => {
483
+ try {
484
+ const parsedUrl = new URL(url);
485
+ const id = parsedUrl.pathname.split("/")[1];
486
+ if (id === "" || id == null) {
487
+ return;
488
+ }
489
+ return id;
490
+ } catch {
491
+ }
492
+ };
493
+ var loadPreviewImage = async (element, videoUrl) => {
494
+ const videoId = getVideoId(videoUrl);
495
+ const apiUrl = `https://vimeo.com/api/v2/video/${videoId}.json`;
496
+ const response = (await (await fetch(apiUrl)).json())[0];
497
+ const thumbnail = response.thumbnail_large;
498
+ const imgId = thumbnail.substr(thumbnail.lastIndexOf("/") + 1).split("_")[0];
499
+ const imageUrl = new URL(IMAGE_CDN);
500
+ imageUrl.pathname = `/video/${imgId}.webp`;
501
+ imageUrl.searchParams.append("mw", "1100");
502
+ imageUrl.searchParams.append("mh", "619");
503
+ imageUrl.searchParams.append("q", "70");
504
+ return imageUrl;
505
+ };
506
+ var useVimeo = ({
507
+ options,
508
+ renderer,
509
+ showPreview
510
+ }) => {
511
+ const [playerStatus, setPlayerStatus] = useState("initial");
512
+ const elementRef = useRef2(null);
513
+ const [previewImageUrl, setPreviewImageUrl] = useState();
514
+ useEffect2(() => {
515
+ setPlayerStatus(
516
+ options.autoplay && renderer !== "canvas" ? "initialized" : "initial"
517
+ );
518
+ }, [options.autoplay, renderer]);
519
+ useEffect2(() => {
520
+ if (elementRef.current === null || playerStatus === "ready" || options.url === void 0) {
521
+ return;
522
+ }
523
+ if (showPreview) {
524
+ loadPreviewImage(elementRef.current, options.url).then(
525
+ setPreviewImageUrl
526
+ );
527
+ return;
528
+ }
529
+ setPreviewImageUrl(void 0);
530
+ }, [renderer, showPreview, options.url, playerStatus]);
531
+ const optionsRef = useRef2(options);
532
+ const stableOptions = useMemo(() => {
533
+ if (shallowEqual(options, optionsRef.current) === false) {
534
+ optionsRef.current = options;
535
+ }
536
+ return optionsRef.current;
537
+ }, [options]);
538
+ useEffect2(() => {
539
+ if (elementRef.current === null || playerStatus === "initial") {
540
+ return;
541
+ }
542
+ return createPlayer(elementRef.current, stableOptions, () => {
543
+ setPlayerStatus("ready");
544
+ });
545
+ }, [stableOptions, playerStatus]);
546
+ return { previewImageUrl, playerStatus, setPlayerStatus, elementRef };
547
+ };
548
+ var Vimeo = forwardRef29(
549
+ ({
550
+ url,
551
+ autoplay = false,
552
+ autopause = true,
553
+ backgroundMode = false,
554
+ showByline = false,
555
+ showControls = true,
556
+ doNotTrack = false,
557
+ keyboard = true,
558
+ loop = false,
559
+ muted = false,
560
+ pip = false,
561
+ playsinline = true,
562
+ showPortrait = true,
563
+ quality = "auto",
564
+ responsive = true,
565
+ speed = false,
566
+ showTitle = false,
567
+ transparent = true,
568
+ showPreview = false,
569
+ autopip,
570
+ controlsColor,
571
+ interactiveParams,
572
+ texttrack,
573
+ children,
574
+ ...rest
575
+ }, ref) => {
576
+ const { renderer } = useContext4(ReactSdkContext4);
577
+ const { previewImageUrl, playerStatus, setPlayerStatus, elementRef } = useVimeo({
578
+ renderer,
579
+ showPreview,
580
+ options: {
581
+ url,
582
+ autoplay,
583
+ autopause,
584
+ keyboard,
585
+ loop,
586
+ muted,
587
+ pip,
588
+ playsinline,
589
+ quality,
590
+ responsive,
591
+ speed,
592
+ transparent,
593
+ portrait: showPortrait,
594
+ byline: showByline,
595
+ title: showTitle,
596
+ color: controlsColor,
597
+ controls: showControls,
598
+ interactive_params: interactiveParams,
599
+ background: backgroundMode,
600
+ dnt: doNotTrack
601
+ }
602
+ });
603
+ return /* @__PURE__ */ jsx21(
604
+ VimeoContext.Provider,
605
+ {
606
+ value: {
607
+ status: playerStatus,
608
+ previewImageUrl,
609
+ onInitPlayer() {
610
+ if (renderer !== "canvas") {
611
+ setPlayerStatus("initialized");
612
+ }
613
+ }
614
+ },
615
+ children: /* @__PURE__ */ jsx21(
616
+ "div",
617
+ {
618
+ ...rest,
619
+ ref: (value) => {
620
+ elementRef.current = value;
621
+ if (ref !== null) {
622
+ typeof ref === "function" ? ref(value) : ref.current = value;
623
+ }
624
+ },
625
+ onPointerOver: () => {
626
+ if (renderer !== "canvas") {
627
+ warmConnections();
628
+ }
629
+ },
630
+ children: url === void 0 ? /* @__PURE__ */ jsx21(EmptyState, {}) : children
631
+ }
632
+ )
633
+ }
634
+ );
635
+ }
636
+ );
637
+ Vimeo.displayName = "Vimeo";
638
+ var EmptyState = () => {
639
+ return /* @__PURE__ */ jsx21(
640
+ "div",
641
+ {
642
+ style: {
643
+ display: "flex",
644
+ width: "100%",
645
+ height: "100%",
646
+ alignItems: "center",
647
+ justifyContent: "center",
648
+ fontSize: "1.2em"
649
+ },
650
+ children: 'Open the "Settings" panel and paste a video URL, e.g. https://vimeo.com/831343124.'
651
+ }
652
+ );
653
+ };
654
+ var VimeoContext = createContext({
655
+ // eslint-disable-next-line @typescript-eslint/no-empty-function
656
+ onInitPlayer: () => {
657
+ },
658
+ status: "initial"
659
+ });
660
+
661
+ // src/vimeo-preview-image.tsx
662
+ import {
663
+ forwardRef as forwardRef30,
664
+ useContext as useContext5
665
+ } from "react";
666
+ import { jsx as jsx22 } from "react/jsx-runtime";
667
+ var base64Preview = `data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAQAAAC1HAwCAAAAC0lEQVR42mNkOAMAANIAzr59FiYAAAAASUVORK5CYII=`;
668
+ var VimeoPreviewImage = forwardRef30(({ src, ...rest }, ref) => {
669
+ const vimeoContext = useContext5(VimeoContext);
670
+ return /* @__PURE__ */ jsx22(
671
+ Image,
672
+ {
673
+ ...rest,
674
+ src: String(vimeoContext.previewImageUrl ?? src ?? base64Preview),
675
+ ref
676
+ }
677
+ );
678
+ });
679
+ VimeoPreviewImage.displayName = "VimeoPreviewImage";
680
+
681
+ // src/vimeo-play-button.tsx
682
+ import {
683
+ forwardRef as forwardRef31,
684
+ useContext as useContext6
685
+ } from "react";
686
+ import { jsx as jsx23 } from "react/jsx-runtime";
687
+ var VimeoPlayButton = forwardRef31(
688
+ (props, ref) => {
689
+ const vimeoContext = useContext6(VimeoContext);
690
+ if (vimeoContext.status !== "initial") {
691
+ return null;
692
+ }
693
+ return /* @__PURE__ */ jsx23(Button, { ...props, onClick: vimeoContext.onInitPlayer, ref });
694
+ }
695
+ );
696
+ VimeoPlayButton.displayName = "VimeoPlayButton";
697
+
698
+ // src/vimeo-spinner.tsx
699
+ import {
700
+ forwardRef as forwardRef32,
701
+ useContext as useContext7
702
+ } from "react";
703
+ import { jsx as jsx24 } from "react/jsx-runtime";
704
+ var VimeoSpinner = forwardRef32(
705
+ (props, ref) => {
706
+ const vimeoContext = useContext7(VimeoContext);
707
+ if (vimeoContext.status !== "initialized") {
708
+ return null;
709
+ }
710
+ return /* @__PURE__ */ jsx24("div", { ...props, ref });
711
+ }
712
+ );
713
+ VimeoSpinner.displayName = "VimeoSpinner";
714
+ export {
715
+ Blockquote,
716
+ Body,
717
+ Bold,
718
+ Box,
719
+ Button,
720
+ Checkbox,
721
+ CodeText,
722
+ Form,
723
+ Fragment,
724
+ Heading,
725
+ HtmlEmbed,
726
+ Image,
727
+ Input,
728
+ Italic,
729
+ Label,
730
+ Link,
731
+ List,
732
+ ListItem,
733
+ Paragraph,
734
+ RadioButton,
735
+ RichTextLink,
736
+ Separator,
737
+ Slot,
738
+ Span,
739
+ Subscript,
740
+ Superscript,
741
+ Text,
742
+ Textarea,
743
+ Vimeo,
744
+ VimeoPlayButton,
745
+ VimeoPreviewImage,
746
+ VimeoSpinner
747
+ };