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