@cntrl-site/sdk 1.24.5 → 1.25.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 (89) hide show
  1. package/lib/FontFaceGenerator/FontFaceGenerator.js +28 -0
  2. package/lib/ScrollPlaybackVideoManager/ScrollPlaybackVideoManager.js +221 -0
  3. package/lib/VideoDecoder/VideoDecoder.js +184 -0
  4. package/{dist → lib}/index.d.ts +0 -2
  5. package/lib/index.js +30 -0
  6. package/{dist → lib}/schemas/article/Article.schema.d.ts +12 -12
  7. package/{dist → lib}/schemas/article/ItemBase.schema.d.ts +10 -10
  8. package/{dist → lib}/schemas/article/RichTextItem.schema.d.ts +30 -30
  9. package/{dist → lib}/schemas/article/Section.schema.d.ts +3 -3
  10. package/{dist → lib}/types/keyframe/Keyframe.d.ts +1 -1
  11. package/lib/utils.js +30 -0
  12. package/package.json +9 -31
  13. package/dist/Client/Client.test.d.ts +0 -1
  14. package/dist/Client/__mock__/articleMock.d.ts +0 -2
  15. package/dist/Client/__mock__/keyframesMock.d.ts +0 -2
  16. package/dist/Client/__mock__/projectMock.d.ts +0 -2
  17. package/dist/Components/ControlSlider/ControlSlider.d.ts +0 -90
  18. package/dist/Components/ControlSlider/ControlSliderComponent.d.ts +0 -516
  19. package/dist/Components/ImageRevealSlider/ControlImageRevealSliderComponent.d.ts +0 -218
  20. package/dist/Components/ImageRevealSlider/ImageRevealSlider.d.ts +0 -38
  21. package/dist/Components/components.d.ts +0 -2
  22. package/dist/Components/helpers/RichTextRenderer/RichTextRenderer.d.ts +0 -6
  23. package/dist/Components/helpers/SvgImage/SvgImage.d.ts +0 -9
  24. package/dist/Components/utils/scalingValue.d.ts +0 -1
  25. package/dist/FontFaceGenerator/FontFaceGenerator.test.d.ts +0 -1
  26. package/dist/index.js +0 -2737
  27. package/dist/index.mjs +0 -2720
  28. package/dist/schemas/shared/FillLayer.schema.d.ts +0 -186
  29. package/dist/sdk.css +0 -1
  30. package/dist/types/component/Component.d.ts +0 -15
  31. /package/{dist → lib}/Client/Client.d.ts +0 -0
  32. /package/{dist → lib}/Client/Client.js +0 -0
  33. /package/{dist → lib}/FontFaceGenerator/FontFaceGenerator.d.ts +0 -0
  34. /package/{dist → lib}/ScrollPlaybackVideoManager/ScrollPlaybackVideoManager.d.ts +0 -0
  35. /package/{dist → lib}/VideoDecoder/VideoDecoder.d.ts +0 -0
  36. /package/{dist → lib}/cli.d.ts +0 -0
  37. /package/{dist → lib}/cli.js +0 -0
  38. /package/{dist → lib}/schemas/article/Article.schema.js +0 -0
  39. /package/{dist → lib}/schemas/article/FillLayer.schema.d.ts +0 -0
  40. /package/{dist → lib}/schemas/article/FillLayer.schema.js +0 -0
  41. /package/{dist → lib}/schemas/article/Interaction.schema.d.ts +0 -0
  42. /package/{dist → lib}/schemas/article/Interaction.schema.js +0 -0
  43. /package/{dist → lib}/schemas/article/Item.schema.d.ts +0 -0
  44. /package/{dist → lib}/schemas/article/Item.schema.js +0 -0
  45. /package/{dist → lib}/schemas/article/ItemArea.schema.d.ts +0 -0
  46. /package/{dist → lib}/schemas/article/ItemArea.schema.js +0 -0
  47. /package/{dist → lib}/schemas/article/ItemBase.schema.js +0 -0
  48. /package/{dist → lib}/schemas/article/ItemState.schema.d.ts +0 -0
  49. /package/{dist → lib}/schemas/article/ItemState.schema.js +0 -0
  50. /package/{dist → lib}/schemas/article/RichTextItem.schema.js +0 -0
  51. /package/{dist → lib}/schemas/article/Section.schema.js +0 -0
  52. /package/{dist → lib}/schemas/keyframe/Keyframes.schema.d.ts +0 -0
  53. /package/{dist → lib}/schemas/keyframe/Keyframes.schema.js +0 -0
  54. /package/{dist → lib}/schemas/project/Layout.schema.d.ts +0 -0
  55. /package/{dist → lib}/schemas/project/Layout.schema.js +0 -0
  56. /package/{dist → lib}/schemas/project/Project.schema.d.ts +0 -0
  57. /package/{dist → lib}/schemas/project/Project.schema.js +0 -0
  58. /package/{dist → lib}/types/article/Article.d.ts +0 -0
  59. /package/{dist → lib}/types/article/Article.js +0 -0
  60. /package/{dist → lib}/types/article/ArticleItemType.d.ts +0 -0
  61. /package/{dist → lib}/types/article/ArticleItemType.js +0 -0
  62. /package/{dist → lib}/types/article/CompoundSettings.d.ts +0 -0
  63. /package/{dist → lib}/types/article/CompoundSettings.js +0 -0
  64. /package/{dist → lib}/types/article/FX.d.ts +0 -0
  65. /package/{dist → lib}/types/article/FX.js +0 -0
  66. /package/{dist → lib}/types/article/Interaction.d.ts +0 -0
  67. /package/{dist → lib}/types/article/Interaction.js +0 -0
  68. /package/{dist → lib}/types/article/Item.d.ts +0 -0
  69. /package/{dist → lib}/types/article/Item.js +0 -0
  70. /package/{dist → lib}/types/article/ItemArea.d.ts +0 -0
  71. /package/{dist → lib}/types/article/ItemArea.js +0 -0
  72. /package/{dist → lib}/types/article/ItemState.d.ts +0 -0
  73. /package/{dist → lib}/types/article/ItemState.js +0 -0
  74. /package/{dist → lib}/types/article/RichText.d.ts +0 -0
  75. /package/{dist → lib}/types/article/RichText.js +0 -0
  76. /package/{dist → lib}/types/article/Section.d.ts +0 -0
  77. /package/{dist → lib}/types/article/Section.js +0 -0
  78. /package/{dist → lib}/types/keyframe/Keyframe.js +0 -0
  79. /package/{dist → lib}/types/project/Fonts.d.ts +0 -0
  80. /package/{dist → lib}/types/project/Fonts.js +0 -0
  81. /package/{dist → lib}/types/project/Layout.d.ts +0 -0
  82. /package/{dist → lib}/types/project/Layout.js +0 -0
  83. /package/{dist → lib}/types/project/Meta.d.ts +0 -0
  84. /package/{dist → lib}/types/project/Meta.js +0 -0
  85. /package/{dist → lib}/types/project/Page.d.ts +0 -0
  86. /package/{dist → lib}/types/project/Page.js +0 -0
  87. /package/{dist → lib}/types/project/Project.d.ts +0 -0
  88. /package/{dist → lib}/types/project/Project.js +0 -0
  89. /package/{dist → lib}/utils.d.ts +0 -0
package/dist/index.mjs DELETED
@@ -1,2720 +0,0 @@
1
- import fetch$1 from "isomorphic-fetch";
2
- import { URL } from "url";
3
- import { z } from "zod";
4
- import UAParser from "ua-parser-js";
5
- import * as MP4Box from "mp4box";
6
- import { jsx, Fragment, jsxs } from "react/jsx-runtime";
7
- import { useState, useEffect, useRef, useMemo } from "react";
8
- import { Splide, SplideSlide } from "@splidejs/react-splide";
9
- import cn from "classnames";
10
- var SectionHeightMode = /* @__PURE__ */ ((SectionHeightMode2) => {
11
- SectionHeightMode2["ControlUnits"] = "control-units";
12
- SectionHeightMode2["ViewportHeightUnits"] = "viewport-height-units";
13
- return SectionHeightMode2;
14
- })(SectionHeightMode || {});
15
- const ColorPointSchema = z.object({
16
- id: z.string(),
17
- value: z.string(),
18
- position: z.number()
19
- });
20
- const FillLayerSchema = z.discriminatedUnion("type", [
21
- z.object({
22
- id: z.string(),
23
- type: z.literal("solid"),
24
- value: z.string(),
25
- blendMode: z.string()
26
- }),
27
- z.object({
28
- id: z.string(),
29
- type: z.literal("linear-gradient"),
30
- colors: z.array(ColorPointSchema),
31
- start: z.tuple([z.number(), z.number()]),
32
- end: z.tuple([z.number(), z.number()]),
33
- angle: z.number(),
34
- blendMode: z.string()
35
- }),
36
- z.object({
37
- id: z.string(),
38
- type: z.literal("radial-gradient"),
39
- colors: z.array(ColorPointSchema),
40
- center: z.tuple([z.number(), z.number()]),
41
- diameter: z.number(),
42
- angle: z.number(),
43
- blendMode: z.string()
44
- }),
45
- z.object({
46
- id: z.string(),
47
- type: z.literal("conic-gradient"),
48
- colors: z.array(ColorPointSchema),
49
- center: z.tuple([z.number(), z.number()]),
50
- angle: z.number(),
51
- blendMode: z.string()
52
- }),
53
- z.object({
54
- id: z.string(),
55
- type: z.literal("image"),
56
- src: z.string(),
57
- behavior: z.string(),
58
- backgroundSize: z.number(),
59
- opacity: z.number(),
60
- blendMode: z.string(),
61
- rotation: z.number().optional()
62
- })
63
- ]);
64
- const TransitionSchema = z.object({
65
- timing: z.string(),
66
- duration: z.number(),
67
- delay: z.number()
68
- });
69
- const getStateParamsSchema = (schema) => {
70
- return z.object({
71
- value: schema,
72
- in: TransitionSchema,
73
- out: TransitionSchema
74
- }).optional();
75
- };
76
- const ItemStateBaseSchema = z.object({
77
- width: getStateParamsSchema(z.number()),
78
- height: getStateParamsSchema(z.number()),
79
- angle: getStateParamsSchema(z.number()),
80
- top: getStateParamsSchema(z.number()),
81
- left: getStateParamsSchema(z.number()),
82
- scale: getStateParamsSchema(z.number()),
83
- blur: getStateParamsSchema(z.number())
84
- });
85
- const MediaStateParamsSchema = z.object({
86
- opacity: getStateParamsSchema(z.number()),
87
- radius: getStateParamsSchema(z.number()),
88
- strokeWidth: getStateParamsSchema(z.number()),
89
- strokeFill: getStateParamsSchema(z.array(FillLayerSchema))
90
- }).merge(ItemStateBaseSchema);
91
- const RectangleStateParamsSchema = z.object({
92
- strokeWidth: getStateParamsSchema(z.number()),
93
- radius: getStateParamsSchema(z.number()),
94
- fill: getStateParamsSchema(z.array(FillLayerSchema)),
95
- strokeFill: getStateParamsSchema(z.array(FillLayerSchema)),
96
- backdropBlur: getStateParamsSchema(z.number())
97
- }).merge(ItemStateBaseSchema);
98
- const CustomItemStateParamsSchema = ItemStateBaseSchema;
99
- const EmbedStateParamsSchema = z.object({
100
- radius: getStateParamsSchema(z.number()),
101
- opacity: getStateParamsSchema(z.number().nonnegative())
102
- }).merge(ItemStateBaseSchema);
103
- const RichTextStateParamsSchema = z.object({
104
- color: getStateParamsSchema(z.string()),
105
- letterSpacing: getStateParamsSchema(z.number()),
106
- wordSpacing: getStateParamsSchema(z.number())
107
- }).merge(ItemStateBaseSchema);
108
- const GroupStateParamsSchema = z.object({
109
- opacity: getStateParamsSchema(z.number().nonnegative()),
110
- blur: getStateParamsSchema(z.number().nonnegative())
111
- }).merge(ItemStateBaseSchema);
112
- const CompoundStateParamsSchema = z.object({
113
- opacity: getStateParamsSchema(z.number().nonnegative())
114
- }).merge(ItemStateBaseSchema);
115
- const CodeEmbedStateParamsSchema = z.object({
116
- opacity: getStateParamsSchema(z.number().nonnegative())
117
- }).merge(ItemStateBaseSchema);
118
- const ComponentStateParamsSchema = z.object({
119
- opacity: getStateParamsSchema(z.number().nonnegative())
120
- }).merge(ItemStateBaseSchema);
121
- z.union([
122
- EmbedStateParamsSchema,
123
- MediaStateParamsSchema,
124
- RectangleStateParamsSchema,
125
- RichTextStateParamsSchema,
126
- CustomItemStateParamsSchema,
127
- GroupStateParamsSchema,
128
- CompoundStateParamsSchema,
129
- CodeEmbedStateParamsSchema,
130
- ComponentStateParamsSchema
131
- ]);
132
- var TextAlign = /* @__PURE__ */ ((TextAlign2) => {
133
- TextAlign2["Left"] = "left";
134
- TextAlign2["Right"] = "right";
135
- TextAlign2["Center"] = "center";
136
- TextAlign2["Justify"] = "justify";
137
- return TextAlign2;
138
- })(TextAlign || {});
139
- var TextTransform = /* @__PURE__ */ ((TextTransform2) => {
140
- TextTransform2["None"] = "none";
141
- TextTransform2["Uppercase"] = "uppercase";
142
- TextTransform2["Lowercase"] = "lowercase";
143
- return TextTransform2;
144
- })(TextTransform || {});
145
- var VerticalAlign = /* @__PURE__ */ ((VerticalAlign2) => {
146
- VerticalAlign2["Super"] = "super";
147
- VerticalAlign2["Sub"] = "sub";
148
- VerticalAlign2["Unset"] = "unset";
149
- return VerticalAlign2;
150
- })(VerticalAlign || {});
151
- var TextDecoration = /* @__PURE__ */ ((TextDecoration2) => {
152
- TextDecoration2["Underline"] = "underline";
153
- TextDecoration2["None"] = "none";
154
- return TextDecoration2;
155
- })(TextDecoration || {});
156
- var AnchorSide = /* @__PURE__ */ ((AnchorSide2) => {
157
- AnchorSide2["Top"] = "top";
158
- AnchorSide2["Bottom"] = "bottom";
159
- AnchorSide2["Center"] = "center";
160
- return AnchorSide2;
161
- })(AnchorSide || {});
162
- var PositionType = /* @__PURE__ */ ((PositionType2) => {
163
- PositionType2["SectionBased"] = "section-based";
164
- PositionType2["ScreenBased"] = "screen-based";
165
- return PositionType2;
166
- })(PositionType || {});
167
- var AreaAnchor = /* @__PURE__ */ ((AreaAnchor2) => {
168
- AreaAnchor2["TopLeft"] = "top-left";
169
- AreaAnchor2["TopCenter"] = "top-center";
170
- AreaAnchor2["TopRight"] = "top-right";
171
- AreaAnchor2["MiddleLeft"] = "middle-left";
172
- AreaAnchor2["MiddleCenter"] = "middle-center";
173
- AreaAnchor2["MiddleRight"] = "middle-right";
174
- AreaAnchor2["BottomLeft"] = "bottom-left";
175
- AreaAnchor2["BottomCenter"] = "bottom-center";
176
- AreaAnchor2["BottomRight"] = "bottom-right";
177
- return AreaAnchor2;
178
- })(AreaAnchor || {});
179
- var DimensionMode = /* @__PURE__ */ ((DimensionMode2) => {
180
- DimensionMode2["ControlUnits"] = "control-units";
181
- DimensionMode2["Relative"] = "relative";
182
- return DimensionMode2;
183
- })(DimensionMode || {});
184
- const ItemAreaSchema = z.object({
185
- top: z.number(),
186
- left: z.number(),
187
- width: z.number(),
188
- height: z.number(),
189
- zIndex: z.number(),
190
- angle: z.number(),
191
- anchorSide: z.nativeEnum(AnchorSide).optional(),
192
- scale: z.number().nonnegative(),
193
- positionType: z.nativeEnum(PositionType),
194
- scaleAnchor: z.nativeEnum(AreaAnchor)
195
- });
196
- const Link = z.object({
197
- url: z.string().min(1),
198
- target: z.string().min(1)
199
- });
200
- const CompoundSettingsSchema = z.object({
201
- positionAnchor: z.nativeEnum(AreaAnchor),
202
- widthMode: z.nativeEnum(DimensionMode),
203
- heightMode: z.nativeEnum(DimensionMode)
204
- });
205
- const ItemBaseSchema = z.object({
206
- id: z.string().min(1),
207
- area: z.record(ItemAreaSchema),
208
- hidden: z.record(z.boolean()),
209
- link: Link.optional(),
210
- compoundSettings: z.record(CompoundSettingsSchema).optional(),
211
- layoutParams: z.record(z.any()).optional()
212
- });
213
- var ArticleItemType = /* @__PURE__ */ ((ArticleItemType2) => {
214
- ArticleItemType2["Image"] = "image";
215
- ArticleItemType2["RichText"] = "richtext";
216
- ArticleItemType2["Video"] = "video";
217
- ArticleItemType2["Rectangle"] = "rectangle";
218
- ArticleItemType2["VimeoEmbed"] = "vimeo-embed";
219
- ArticleItemType2["YoutubeEmbed"] = "youtube-embed";
220
- ArticleItemType2["Custom"] = "custom";
221
- ArticleItemType2["Group"] = "group";
222
- ArticleItemType2["CodeEmbed"] = "code-embed";
223
- ArticleItemType2["Compound"] = "compound";
224
- ArticleItemType2["Component"] = "component";
225
- return ArticleItemType2;
226
- })(ArticleItemType || {});
227
- const pointerEvents$1 = z.enum(["never", "when_visible", "always"]).optional();
228
- const RichTextEntitySchema = z.object({
229
- start: z.number().nonnegative(),
230
- end: z.number().nonnegative(),
231
- type: z.string(),
232
- data: z.any().optional()
233
- });
234
- const RichTextStyleSchema = z.object({
235
- start: z.number().nonnegative(),
236
- end: z.number().nonnegative(),
237
- style: z.string().min(1),
238
- value: z.string().optional()
239
- });
240
- const RichTextBlockSchema = z.lazy(() => z.object({
241
- start: z.number().nonnegative(),
242
- end: z.number().nonnegative(),
243
- type: z.string().min(1),
244
- entities: z.array(RichTextEntitySchema).optional(),
245
- children: z.array(RichTextBlockSchema).optional(),
246
- data: z.any().optional()
247
- }));
248
- const RichTextItemSchema = ItemBaseSchema.extend({
249
- type: z.literal(ArticleItemType.RichText),
250
- commonParams: z.object({
251
- text: z.string(),
252
- blocks: z.array(RichTextBlockSchema).optional(),
253
- pointerEvents: pointerEvents$1
254
- }),
255
- sticky: z.record(
256
- z.object({
257
- from: z.number(),
258
- to: z.number().optional()
259
- }).nullable()
260
- ),
261
- layoutParams: z.record(
262
- z.object({
263
- rangeStyles: z.array(RichTextStyleSchema).optional(),
264
- textAlign: z.nativeEnum(TextAlign),
265
- sizing: z.string(),
266
- blur: z.number(),
267
- fontSize: z.number(),
268
- lineHeight: z.number(),
269
- letterSpacing: z.number(),
270
- wordSpacing: z.number(),
271
- textTransform: z.nativeEnum(TextTransform),
272
- verticalAlign: z.nativeEnum(VerticalAlign),
273
- color: z.string(),
274
- typeFace: z.string(),
275
- fontStyle: z.string(),
276
- fontWeight: z.number(),
277
- fontVariant: z.string(),
278
- isDraggable: z.boolean().optional()
279
- })
280
- ),
281
- state: z.record(RichTextStateParamsSchema)
282
- });
283
- const pointerEvents = z.enum(["never", "when_visible", "always"]).optional();
284
- const FXControlSchema = z.discriminatedUnion("type", [
285
- z.object({
286
- type: z.literal("float"),
287
- shaderParam: z.string(),
288
- value: z.number()
289
- }),
290
- z.object({
291
- type: z.literal("int"),
292
- shaderParam: z.string(),
293
- value: z.number()
294
- }),
295
- z.object({
296
- type: z.literal("vec2"),
297
- shaderParam: z.string(),
298
- value: z.tuple([z.number(), z.number()])
299
- })
300
- ]);
301
- const FXParams = z.object({
302
- url: z.string().min(1),
303
- hasGLEffect: z.boolean().optional(),
304
- fragmentShader: z.string().nullable(),
305
- FXControls: z.array(FXControlSchema).optional()
306
- });
307
- const ImageItemSchema = ItemBaseSchema.extend({
308
- type: z.literal(ArticleItemType.Image),
309
- commonParams: z.object({
310
- pointerEvents
311
- }).merge(FXParams),
312
- sticky: z.record(
313
- z.object({
314
- from: z.number(),
315
- to: z.number().optional()
316
- }).nullable()
317
- ),
318
- layoutParams: z.record(
319
- z.object({
320
- opacity: z.number().nonnegative(),
321
- radius: z.number(),
322
- strokeWidth: z.number(),
323
- strokeFill: z.array(FillLayerSchema),
324
- blur: z.number(),
325
- isDraggable: z.boolean().optional()
326
- })
327
- ),
328
- state: z.record(MediaStateParamsSchema)
329
- });
330
- const VideoItemSchema = ItemBaseSchema.extend({
331
- type: z.literal(ArticleItemType.Video),
332
- commonParams: z.object({
333
- coverUrl: z.string().nullable(),
334
- pointerEvents
335
- }).merge(FXParams),
336
- sticky: z.record(
337
- z.object({
338
- from: z.number(),
339
- to: z.number().optional()
340
- }).nullable()
341
- ),
342
- layoutParams: z.record(
343
- z.object({
344
- scrollPlayback: z.object({
345
- from: z.number(),
346
- to: z.number()
347
- }).nullable(),
348
- opacity: z.number().nonnegative(),
349
- radius: z.number(),
350
- strokeWidth: z.number(),
351
- strokeFill: z.array(FillLayerSchema),
352
- blur: z.number(),
353
- isDraggable: z.boolean().optional(),
354
- play: z.enum(["on-hover", "on-click", "auto"]),
355
- muted: z.boolean(),
356
- controls: z.boolean()
357
- })
358
- ),
359
- state: z.record(MediaStateParamsSchema)
360
- });
361
- const RectangleItemSchema = ItemBaseSchema.extend({
362
- type: z.literal(ArticleItemType.Rectangle),
363
- commonParams: z.object({
364
- ratioLock: z.boolean(),
365
- pointerEvents
366
- }),
367
- sticky: z.record(
368
- z.object({
369
- from: z.number(),
370
- to: z.number().optional()
371
- }).nullable()
372
- ),
373
- layoutParams: z.record(
374
- z.object({
375
- radius: z.number(),
376
- strokeWidth: z.number(),
377
- fill: z.array(FillLayerSchema),
378
- strokeFill: z.array(FillLayerSchema),
379
- blur: z.number(),
380
- backdropBlur: z.number(),
381
- blurMode: z.enum(["default", "backdrop"]),
382
- isDraggable: z.boolean().optional()
383
- })
384
- ),
385
- state: z.record(RectangleStateParamsSchema)
386
- });
387
- const CustomItemSchema = ItemBaseSchema.extend({
388
- type: z.literal(ArticleItemType.Custom),
389
- commonParams: z.object({
390
- name: z.string(),
391
- pointerEvents
392
- }),
393
- sticky: z.record(
394
- z.object({
395
- from: z.number(),
396
- to: z.number().optional()
397
- }).nullable()
398
- ),
399
- layoutParams: z.record(z.object({
400
- isDraggable: z.boolean().optional()
401
- })),
402
- state: z.record(CustomItemStateParamsSchema)
403
- });
404
- const VimeoEmbedItemSchema = ItemBaseSchema.extend({
405
- type: z.literal(ArticleItemType.VimeoEmbed),
406
- commonParams: z.object({
407
- url: z.string().min(1),
408
- coverUrl: z.string().nullable(),
409
- ratioLock: z.boolean(),
410
- pointerEvents
411
- }),
412
- sticky: z.record(
413
- z.object({
414
- from: z.number(),
415
- to: z.number().optional()
416
- }).nullable()
417
- ),
418
- layoutParams: z.record(
419
- z.object({
420
- radius: z.number(),
421
- blur: z.number(),
422
- opacity: z.number().nonnegative(),
423
- play: z.union([z.literal("on-hover"), z.literal("on-click"), z.literal("auto")]),
424
- controls: z.boolean(),
425
- loop: z.boolean(),
426
- muted: z.boolean(),
427
- pictureInPicture: z.boolean()
428
- })
429
- ),
430
- state: z.record(EmbedStateParamsSchema)
431
- });
432
- const YoutubeEmbedItemSchema = ItemBaseSchema.extend({
433
- type: z.literal(ArticleItemType.YoutubeEmbed),
434
- commonParams: z.object({
435
- url: z.string().min(1),
436
- coverUrl: z.string().nullable(),
437
- pointerEvents
438
- }),
439
- sticky: z.record(
440
- z.object({
441
- from: z.number(),
442
- to: z.number().optional()
443
- }).nullable()
444
- ),
445
- layoutParams: z.record(
446
- z.object({
447
- radius: z.number(),
448
- blur: z.number(),
449
- opacity: z.number().nonnegative(),
450
- play: z.enum(["on-hover", "on-click", "auto"]),
451
- controls: z.boolean(),
452
- loop: z.boolean()
453
- })
454
- ),
455
- state: z.record(EmbedStateParamsSchema)
456
- });
457
- const CodeEmbedItemSchema = ItemBaseSchema.extend({
458
- type: z.literal(ArticleItemType.CodeEmbed),
459
- commonParams: z.object({
460
- html: z.string(),
461
- scale: z.boolean(),
462
- iframe: z.boolean(),
463
- pointerEvents
464
- }),
465
- sticky: z.record(
466
- z.object({
467
- from: z.number(),
468
- to: z.number().optional()
469
- }).nullable()
470
- ),
471
- layoutParams: z.record(
472
- z.object({
473
- areaAnchor: z.nativeEnum(AreaAnchor),
474
- opacity: z.number().nonnegative(),
475
- blur: z.number(),
476
- isDraggable: z.boolean().optional()
477
- })
478
- ),
479
- state: z.record(CodeEmbedStateParamsSchema)
480
- });
481
- const ComponentItemSchema = ItemBaseSchema.extend({
482
- type: z.literal(ArticleItemType.Component),
483
- commonParams: z.object({
484
- componentId: z.string(),
485
- content: z.any().optional()
486
- }),
487
- sticky: z.record(
488
- z.object({
489
- from: z.number(),
490
- to: z.number().optional()
491
- }).nullable()
492
- ),
493
- layoutParams: z.record(z.object({
494
- parameters: z.any().optional(),
495
- opacity: z.number().nonnegative(),
496
- blur: z.number()
497
- })),
498
- state: z.record(ComponentStateParamsSchema)
499
- });
500
- const ItemSchema = z.lazy(() => z.discriminatedUnion("type", [
501
- ImageItemSchema,
502
- VideoItemSchema,
503
- RectangleItemSchema,
504
- CustomItemSchema,
505
- RichTextItemSchema,
506
- VimeoEmbedItemSchema,
507
- YoutubeEmbedItemSchema,
508
- CodeEmbedItemSchema,
509
- ComponentItemSchema,
510
- ItemBaseSchema.extend({
511
- type: z.literal(ArticleItemType.Group),
512
- commonParams: z.object({
513
- pointerEvents
514
- }),
515
- items: z.array(ItemSchema),
516
- sticky: z.record(
517
- z.object({
518
- from: z.number(),
519
- to: z.number().optional()
520
- }).nullable()
521
- ),
522
- layoutParams: z.record(
523
- z.object({
524
- opacity: z.number().nonnegative(),
525
- blur: z.number()
526
- })
527
- ),
528
- state: z.record(GroupStateParamsSchema)
529
- }),
530
- ItemBaseSchema.extend({
531
- type: z.literal(ArticleItemType.Compound),
532
- commonParams: z.object({
533
- overflow: z.enum(["hidden", "visible"]),
534
- pointerEvents
535
- }),
536
- items: z.array(ItemSchema),
537
- sticky: z.record(
538
- z.object({
539
- from: z.number(),
540
- to: z.number().optional()
541
- }).nullable()
542
- ),
543
- layoutParams: z.record(
544
- z.object({
545
- opacity: z.number().nonnegative()
546
- })
547
- ),
548
- state: z.record(CompoundStateParamsSchema)
549
- })
550
- ]));
551
- const SectionHeightSchema = z.object({
552
- mode: z.nativeEnum(SectionHeightMode),
553
- units: z.number().nonnegative(),
554
- vhUnits: z.number().nonnegative().optional()
555
- });
556
- const SectionVideoSchema = z.object({
557
- url: z.string(),
558
- size: z.string(),
559
- type: z.literal("video"),
560
- play: z.enum(["on-click", "auto"]),
561
- coverUrl: z.string().nullable(),
562
- position: z.string(),
563
- offsetX: z.number().nullable()
564
- });
565
- const SectionImageSchema = z.object({
566
- url: z.string(),
567
- type: z.literal("image"),
568
- size: z.string(),
569
- position: z.string(),
570
- offsetX: z.number().nullable()
571
- });
572
- const SectionMediaSchema = z.discriminatedUnion("type", [SectionVideoSchema, SectionImageSchema]);
573
- const SectionSchema = z.object({
574
- id: z.string().min(1),
575
- items: z.array(ItemSchema),
576
- name: z.string().optional(),
577
- height: z.record(SectionHeightSchema),
578
- position: z.record(z.number()),
579
- hidden: z.record(z.boolean()),
580
- color: z.record(z.nullable(z.string())),
581
- media: z.record(SectionMediaSchema).optional()
582
- });
583
- const ItemTriggerSchema = z.object({
584
- itemId: z.string(),
585
- type: z.enum(["hover-in", "hover-out", "click"]),
586
- from: z.string(),
587
- to: z.string()
588
- });
589
- const ScrollTriggerSchema = z.object({
590
- position: z.number(),
591
- from: z.string(),
592
- to: z.string(),
593
- isReverse: z.boolean()
594
- });
595
- const VideoInteractionActionSchema = z.object({
596
- type: z.enum(["play", "pause"]),
597
- itemId: z.string()
598
- });
599
- const StateSchema = z.object({
600
- id: z.string(),
601
- actions: z.array(VideoInteractionActionSchema).optional()
602
- });
603
- const InteractionSchema = z.object({
604
- id: z.string(),
605
- triggers: z.array(z.union([ItemTriggerSchema, ScrollTriggerSchema])),
606
- states: z.array(StateSchema),
607
- startStateId: z.string()
608
- });
609
- const ArticleSchema = z.object({
610
- id: z.string().min(1),
611
- sections: z.array(SectionSchema),
612
- interactions: z.record(z.array(InteractionSchema))
613
- });
614
- const LayoutSchema = z.object({
615
- id: z.string(),
616
- title: z.string(),
617
- startsWith: z.number().nonnegative(),
618
- exemplary: z.number().positive()
619
- });
620
- var FontFileTypes = /* @__PURE__ */ ((FontFileTypes2) => {
621
- FontFileTypes2["OTF"] = "otf";
622
- FontFileTypes2["TTF"] = "ttf";
623
- FontFileTypes2["WOFF"] = "woff";
624
- FontFileTypes2["WOFF2"] = "woff2";
625
- FontFileTypes2["EOT"] = "eot";
626
- return FontFileTypes2;
627
- })(FontFileTypes || {});
628
- const ProjectSchema = z.object({
629
- id: z.string().min(1),
630
- html: z.object({
631
- head: z.string(),
632
- afterBodyOpen: z.string(),
633
- beforeBodyClose: z.string()
634
- }),
635
- meta: z.object({
636
- title: z.string().optional(),
637
- description: z.string().optional(),
638
- opengraphThumbnail: z.string().optional(),
639
- keywords: z.string().optional(),
640
- favicon: z.string().optional()
641
- }),
642
- layouts: z.array(LayoutSchema),
643
- pages: z.array(z.object({
644
- title: z.string(),
645
- articleId: z.string().min(1),
646
- slug: z.string(),
647
- meta: z.object({
648
- title: z.string().optional(),
649
- description: z.string().optional(),
650
- opengraphThumbnail: z.string().optional(),
651
- keywords: z.string().optional(),
652
- enabled: z.boolean()
653
- }).optional(),
654
- id: z.string().min(1)
655
- })),
656
- fonts: z.object({
657
- google: z.string(),
658
- adobe: z.string(),
659
- custom: z.array(z.object({
660
- name: z.string().min(1),
661
- style: z.string().min(1),
662
- weight: z.number(),
663
- files: z.array(
664
- z.object({
665
- type: z.nativeEnum(FontFileTypes),
666
- url: z.string()
667
- })
668
- )
669
- }))
670
- })
671
- });
672
- var KeyframeType = /* @__PURE__ */ ((KeyframeType2) => {
673
- KeyframeType2["Dimensions"] = "dimensions";
674
- KeyframeType2["Position"] = "position";
675
- KeyframeType2["Rotation"] = "rotation";
676
- KeyframeType2["BorderRadius"] = "border-radius";
677
- KeyframeType2["BorderWidth"] = "border-width";
678
- KeyframeType2["Opacity"] = "opacity";
679
- KeyframeType2["Scale"] = "scale";
680
- KeyframeType2["TextColor"] = "text-color";
681
- KeyframeType2["LetterSpacing"] = "letter-spacing";
682
- KeyframeType2["WordSpacing"] = "word-spacing";
683
- KeyframeType2["Blur"] = "blur";
684
- KeyframeType2["BackdropBlur"] = "backdrop-blur";
685
- KeyframeType2["FXParams"] = "fx-params";
686
- KeyframeType2["BorderFill"] = "border-fill";
687
- KeyframeType2["Fill"] = "fill";
688
- return KeyframeType2;
689
- })(KeyframeType || {});
690
- const KeyframesBaseSchema = z.object({
691
- id: z.string().min(1),
692
- layoutId: z.string().min(1),
693
- itemId: z.string().min(1),
694
- position: z.number()
695
- });
696
- const DimensionsKeyframeSchema = KeyframesBaseSchema.extend({
697
- type: z.literal(KeyframeType.Dimensions),
698
- value: z.object({
699
- width: z.number().nonnegative(),
700
- height: z.number().nonnegative()
701
- })
702
- });
703
- const PositionKeyframeSchema = KeyframesBaseSchema.extend({
704
- type: z.literal(KeyframeType.Position),
705
- value: z.object({
706
- top: z.number(),
707
- left: z.number()
708
- })
709
- });
710
- const RotationKeyframeSchema = KeyframesBaseSchema.extend({
711
- type: z.literal(KeyframeType.Rotation),
712
- value: z.object({
713
- angle: z.number()
714
- })
715
- });
716
- const BorderRadiusKeyframeSchema = KeyframesBaseSchema.extend({
717
- type: z.literal(KeyframeType.BorderRadius),
718
- value: z.object({
719
- radius: z.number().nonnegative()
720
- })
721
- });
722
- const BorderWidthKeyframeSchema = KeyframesBaseSchema.extend({
723
- type: z.literal(KeyframeType.BorderWidth),
724
- value: z.object({
725
- borderWidth: z.number().nonnegative()
726
- })
727
- });
728
- const BorderFillKeyframeSchema = KeyframesBaseSchema.extend({
729
- type: z.literal(KeyframeType.BorderFill),
730
- value: z.array(FillLayerSchema)
731
- });
732
- const OpacityKeyframeSchema = KeyframesBaseSchema.extend({
733
- type: z.literal(KeyframeType.Opacity),
734
- value: z.object({
735
- opacity: z.number().nonnegative()
736
- })
737
- });
738
- const ScaleKeyframeSchema = KeyframesBaseSchema.extend({
739
- type: z.literal(KeyframeType.Scale),
740
- value: z.object({
741
- scale: z.number().nonnegative()
742
- })
743
- });
744
- const BlurKeyframeSchema = KeyframesBaseSchema.extend({
745
- type: z.literal(KeyframeType.Blur),
746
- value: z.object({
747
- blur: z.number()
748
- })
749
- });
750
- const BackdropBlurKeyframeSchema = KeyframesBaseSchema.extend({
751
- type: z.literal(KeyframeType.BackdropBlur),
752
- value: z.object({
753
- backdropBlur: z.number()
754
- })
755
- });
756
- const TextColorKeyframeSchema = KeyframesBaseSchema.extend({
757
- type: z.literal(KeyframeType.TextColor),
758
- value: z.object({
759
- color: z.string()
760
- })
761
- });
762
- const LetterSpacingKeyframeSchema = KeyframesBaseSchema.extend({
763
- type: z.literal(KeyframeType.LetterSpacing),
764
- value: z.object({
765
- letterSpacing: z.number()
766
- })
767
- });
768
- const WordSpacingKeyframeSchema = KeyframesBaseSchema.extend({
769
- type: z.literal(KeyframeType.WordSpacing),
770
- value: z.object({
771
- wordSpacing: z.number()
772
- })
773
- });
774
- const FXParamsKeyframeSchema = KeyframesBaseSchema.extend({
775
- type: z.literal(KeyframeType.FXParams),
776
- value: z.record(z.string(), z.number())
777
- });
778
- const FillKeyframeSchema = KeyframesBaseSchema.extend({
779
- type: z.literal(KeyframeType.Fill),
780
- value: z.array(FillLayerSchema)
781
- });
782
- const KeyframeSchema = z.discriminatedUnion("type", [
783
- DimensionsKeyframeSchema,
784
- PositionKeyframeSchema,
785
- RotationKeyframeSchema,
786
- BorderRadiusKeyframeSchema,
787
- BorderWidthKeyframeSchema,
788
- BorderFillKeyframeSchema,
789
- OpacityKeyframeSchema,
790
- ScaleKeyframeSchema,
791
- BlurKeyframeSchema,
792
- BackdropBlurKeyframeSchema,
793
- TextColorKeyframeSchema,
794
- LetterSpacingKeyframeSchema,
795
- WordSpacingKeyframeSchema,
796
- FXParamsKeyframeSchema,
797
- FillKeyframeSchema
798
- ]);
799
- const KeyframesSchema = z.array(KeyframeSchema);
800
- class Client {
801
- constructor(APIUrl, fetchImpl = fetch$1) {
802
- this.fetchImpl = fetchImpl;
803
- this.url = new URL(APIUrl);
804
- if (!this.url.username) {
805
- throw new Error("Project ID is missing in the URL.");
806
- }
807
- if (!this.url.password) {
808
- throw new Error("API key is missing in the URL.");
809
- }
810
- }
811
- static getPageMeta(projectMeta, pageMeta) {
812
- return pageMeta.enabled ? {
813
- title: pageMeta.title ? pageMeta.title : projectMeta.title ?? "",
814
- description: pageMeta.description ? pageMeta.description : projectMeta.description ?? "",
815
- keywords: pageMeta.keywords ? pageMeta.keywords : projectMeta.keywords ?? "",
816
- opengraphThumbnail: pageMeta.opengraphThumbnail ? pageMeta.opengraphThumbnail : projectMeta.opengraphThumbnail ?? "",
817
- favicon: projectMeta.favicon ?? ""
818
- } : projectMeta;
819
- }
820
- async getPageData(pageSlug, buildMode = "default") {
821
- try {
822
- const project = await this.fetchProject(buildMode);
823
- const articleId = this.findArticleIdByPageSlug(pageSlug, project.pages);
824
- const { article, keyframes } = await this.fetchArticle(articleId, buildMode);
825
- const page = project.pages.find((page2) => page2.slug === pageSlug);
826
- const meta = Client.getPageMeta(project.meta, page == null ? void 0 : page.meta);
827
- return {
828
- project,
829
- article,
830
- keyframes,
831
- meta
832
- };
833
- } catch (e) {
834
- throw e;
835
- }
836
- }
837
- async getProjectPagesPaths() {
838
- try {
839
- const { pages } = await this.fetchProject();
840
- return pages.map((p) => p.slug);
841
- } catch (e) {
842
- throw e;
843
- }
844
- }
845
- async getLayouts() {
846
- try {
847
- const { layouts } = await this.fetchProject();
848
- return layouts;
849
- } catch (e) {
850
- throw e;
851
- }
852
- }
853
- async fetchProject(buildMode = "default") {
854
- const { username: projectId, password: apiKey, origin } = this.url;
855
- const url = new URL(`/projects/${projectId}?buildMode=${buildMode}`, origin);
856
- const response = await this.fetchImpl(url.href, {
857
- headers: {
858
- Authorization: `Bearer ${apiKey}`
859
- }
860
- });
861
- if (!response.ok) {
862
- throw new Error(`Failed to fetch project with id #${projectId}: ${response.statusText}`);
863
- }
864
- const data = await response.json();
865
- const project = ProjectSchema.parse(data);
866
- return project;
867
- }
868
- async fetchArticle(articleId, buildMode = "default") {
869
- const { username: projectId, password: apiKey, origin } = this.url;
870
- const url = new URL(`/projects/${projectId}/articles/${articleId}?buildMode=${buildMode}`, origin);
871
- const response = await this.fetchImpl(url.href, {
872
- headers: {
873
- Authorization: `Bearer ${apiKey}`
874
- }
875
- });
876
- if (!response.ok) {
877
- throw new Error(`Failed to fetch article with id #${articleId}: ${response.statusText}`);
878
- }
879
- const data = await response.json();
880
- const article = ArticleSchema.parse(data.article);
881
- const keyframes = KeyframesSchema.parse(data.keyframes);
882
- return { article, keyframes };
883
- }
884
- findArticleIdByPageSlug(slug, pages) {
885
- const { username: projectId } = this.url;
886
- const page = pages.find((page2) => page2.slug === slug);
887
- if (!page) {
888
- throw new Error(`Page with a slug ${slug} was not found in project with id #${projectId}`);
889
- }
890
- return page.articleId;
891
- }
892
- }
893
- const FILE_TYPES_MAP = {
894
- ttf: "truetype",
895
- otf: "opentype"
896
- };
897
- class FontFaceGenerator {
898
- constructor(fonts) {
899
- this.fonts = fonts;
900
- }
901
- generate() {
902
- return this.fonts.map((font) => {
903
- const eotFile = font.files.find((file) => file.type === "eot");
904
- const otherFiles = font.files.filter((file) => file.type !== "eot").map((file) => `url('${file.url}') format('${FILE_TYPES_MAP[file.type] || file.type}')`);
905
- return `
906
- @font-face {
907
- font-family: "${font.name}";
908
- font-weight: ${font.weight};
909
- font-style: ${font.style};
910
- ${eotFile ? `src: url('${eotFile.url}');
911
- ` : ""}src: ${otherFiles.join(", ")};
912
- }`;
913
- }).join("\n");
914
- }
915
- }
916
- function getLayoutStyles(layouts, layoutValues, mapToStyles) {
917
- const mediaQueries = layouts.sort((a, b) => a.startsWith - b.startsWith).reduce(
918
- (acc, layout) => {
919
- const values = layoutValues.map((lv) => lv[layout.id]);
920
- return `
921
- ${acc}
922
- ${layout.startsWith !== 0 ? `@media (min-width: ${layout.startsWith}px) {${mapToStyles(values, layout.exemplary)}}` : `${mapToStyles(values, layout.exemplary)}`}`;
923
- },
924
- ""
925
- );
926
- return mediaQueries;
927
- }
928
- function getLayoutMediaQuery(layoutId, layouts) {
929
- const sorted = layouts.slice().sort((a, b) => a.startsWith - b.startsWith);
930
- const layoutIndex = sorted.findIndex((l) => l.id === layoutId);
931
- if (layoutIndex === -1) {
932
- throw new Error(`No layout was found by the given id #${layoutId}`);
933
- }
934
- const current = sorted[layoutIndex];
935
- const next = sorted[layoutIndex + 1];
936
- if (!next) {
937
- return `@media (min-width: ${current.startsWith}px)`;
938
- }
939
- return `@media (min-width: ${current.startsWith}px) and (max-width: ${next.startsWith - 1}px)`;
940
- }
941
- class Writer {
942
- constructor(size) {
943
- this.data = new Uint8Array(size);
944
- this.idx = 0;
945
- this.size = size;
946
- }
947
- getData() {
948
- if (this.idx !== this.size) throw new Error("Mismatch between size reserved and sized used");
949
- return this.data.slice(0, this.idx);
950
- }
951
- writeUint8(value) {
952
- this.data.set([value], this.idx);
953
- this.idx += 1;
954
- }
955
- writeUint16(value) {
956
- const arr = new Uint16Array(1);
957
- arr[0] = value;
958
- const buffer = new Uint8Array(arr.buffer);
959
- this.data.set([buffer[1], buffer[0]], this.idx);
960
- this.idx += 2;
961
- }
962
- writeUint8Array(value) {
963
- this.data.set(value, this.idx);
964
- this.idx += value.length;
965
- }
966
- }
967
- const getExtradata = (avccBox) => {
968
- let i;
969
- let size = 7;
970
- for (i = 0; i < avccBox.SPS.length; i += 1) {
971
- size += 2 + avccBox.SPS[i].length;
972
- }
973
- for (i = 0; i < avccBox.PPS.length; i += 1) {
974
- size += 2 + avccBox.PPS[i].length;
975
- }
976
- const writer = new Writer(size);
977
- writer.writeUint8(avccBox.configurationVersion);
978
- writer.writeUint8(avccBox.AVCProfileIndication);
979
- writer.writeUint8(avccBox.profile_compatibility);
980
- writer.writeUint8(avccBox.AVCLevelIndication);
981
- writer.writeUint8(avccBox.lengthSizeMinusOne + (63 << 2));
982
- writer.writeUint8(avccBox.nb_SPS_nalus + (7 << 5));
983
- for (i = 0; i < avccBox.SPS.length; i += 1) {
984
- writer.writeUint16(avccBox.SPS[i].length);
985
- writer.writeUint8Array(avccBox.SPS[i].nalu);
986
- }
987
- writer.writeUint8(avccBox.nb_PPS_nalus);
988
- for (i = 0; i < avccBox.PPS.length; i += 1) {
989
- writer.writeUint16(avccBox.PPS[i].length);
990
- writer.writeUint8Array(avccBox.PPS[i].nalu);
991
- }
992
- return writer.getData();
993
- };
994
- const decodeVideo = (src, emitFrame, { VideoDecoder: VideoDecoder2, EncodedVideoChunk: EncodedVideoChunk2, debug }) => new Promise((resolve, reject) => {
995
- if (debug) console.info("Decoding video from", src);
996
- try {
997
- const mp4boxfile = MP4Box.createFile();
998
- let codec;
999
- const decoder = new VideoDecoder2({
1000
- output: (frame) => {
1001
- createImageBitmap(frame, { resizeQuality: "low" }).then((bitmap) => {
1002
- emitFrame(bitmap);
1003
- frame.close();
1004
- if (decoder.decodeQueueSize <= 0) {
1005
- setTimeout(() => {
1006
- if (decoder.state !== "closed") {
1007
- decoder.close();
1008
- resolve();
1009
- }
1010
- }, 500);
1011
- }
1012
- });
1013
- },
1014
- error: (e) => {
1015
- console.error(e);
1016
- reject(e);
1017
- }
1018
- });
1019
- mp4boxfile.onReady = (info) => {
1020
- if (info && info.videoTracks && info.videoTracks[0]) {
1021
- [{ codec }] = info.videoTracks;
1022
- if (debug) console.info("Video with codec:", codec);
1023
- const avccBox = mp4boxfile.moov.traks[0].mdia.minf.stbl.stsd.entries[0].avcC;
1024
- const extradata = getExtradata(avccBox);
1025
- decoder.configure({ codec, description: extradata });
1026
- mp4boxfile.setExtractionOptions(info.videoTracks[0].id);
1027
- mp4boxfile.start();
1028
- } else reject(new Error("URL provided is not a valid mp4 video file."));
1029
- };
1030
- mp4boxfile.onSamples = (track_id, ref, samples) => {
1031
- for (let i = 0; i < samples.length; i += 1) {
1032
- const sample = samples[i];
1033
- const type = sample.is_sync ? "key" : "delta";
1034
- const chunk = new EncodedVideoChunk2({
1035
- type,
1036
- timestamp: sample.cts,
1037
- duration: sample.duration,
1038
- data: sample.data
1039
- });
1040
- decoder.decode(chunk);
1041
- }
1042
- };
1043
- fetch(src).then((res) => {
1044
- const reader = res.body.getReader();
1045
- let offset = 0;
1046
- function appendBuffers({ done, value }) {
1047
- if (done) {
1048
- mp4boxfile.flush();
1049
- return null;
1050
- }
1051
- const buf = value.buffer;
1052
- buf.fileStart = offset;
1053
- offset += buf.byteLength;
1054
- mp4boxfile.appendBuffer(buf);
1055
- return reader.read().then(appendBuffers);
1056
- }
1057
- return reader.read().then(appendBuffers);
1058
- });
1059
- } catch (e) {
1060
- reject(e);
1061
- }
1062
- });
1063
- const videoDecoder = (src, emitFrame, debug) => {
1064
- if (typeof VideoDecoder === "function" && typeof EncodedVideoChunk === "function") {
1065
- if (debug)
1066
- console.info("WebCodecs is natively supported, using native version...");
1067
- return decodeVideo(src, emitFrame, {
1068
- VideoDecoder,
1069
- EncodedVideoChunk,
1070
- debug
1071
- });
1072
- }
1073
- if (debug) console.info("WebCodecs is not available in this browser.");
1074
- return Promise.resolve();
1075
- };
1076
- class ScrollPlaybackVideoManager {
1077
- constructor(options) {
1078
- this.currentTime = 0;
1079
- this.targetTime = 0;
1080
- this.canvas = null;
1081
- this.context = null;
1082
- this.frames = [];
1083
- this.frameRate = 0;
1084
- this.transitioning = false;
1085
- this.debug = false;
1086
- this.frameThreshold = 0.1;
1087
- this.transitionSpeed = 10;
1088
- this.useWebCodecs = true;
1089
- this.resize = () => {
1090
- if (this.debug) console.info("ScrollVideo resizing...");
1091
- if (this.canvas) {
1092
- this.setCoverStyle(this.canvas);
1093
- } else if (this.video) {
1094
- this.setCoverStyle(this.video);
1095
- }
1096
- this.paintCanvasFrame(Math.floor(this.currentTime * this.frameRate));
1097
- };
1098
- this.decodeVideo = () => {
1099
- if (!this.video) return;
1100
- if (this.useWebCodecs && this.video.src) {
1101
- videoDecoder(
1102
- this.video.src,
1103
- (frame) => {
1104
- this.frames.push(frame);
1105
- },
1106
- this.debug
1107
- ).then(() => {
1108
- if (!this.video || !this.container) return;
1109
- if (this.frames.length === 0) {
1110
- if (this.debug) console.error("No frames were received from webCodecs");
1111
- return;
1112
- }
1113
- this.frameRate = this.frames.length / this.video.duration;
1114
- if (this.debug) console.info("Received", this.frames.length, "frames");
1115
- this.canvas = document.createElement("canvas");
1116
- this.context = this.canvas.getContext("2d");
1117
- this.video.style.display = "none";
1118
- this.container.appendChild(this.canvas);
1119
- this.paintCanvasFrame(Math.floor(this.currentTime * this.frameRate));
1120
- }).catch(() => {
1121
- if (this.debug) console.error("Error encountered while decoding video");
1122
- this.frames = [];
1123
- this.video.load();
1124
- });
1125
- }
1126
- };
1127
- this.resizeObserver = new ResizeObserver(() => {
1128
- this.resize();
1129
- });
1130
- const {
1131
- src,
1132
- videoContainer
1133
- } = options;
1134
- if (typeof document !== "object") {
1135
- console.error("ScrollVideo must be initiated in a DOM context");
1136
- return;
1137
- }
1138
- if (!videoContainer) {
1139
- console.error("scrollVideoContainer must be a valid DOM object");
1140
- return;
1141
- }
1142
- if (!src) {
1143
- console.error("Must provide valid video src to ScrollVideo");
1144
- return;
1145
- }
1146
- this.container = typeof videoContainer === "string" ? document.getElementById(videoContainer) : videoContainer;
1147
- this.resizeObserver.observe(this.container);
1148
- this.video = document.createElement("video");
1149
- this.video.src = src;
1150
- this.video.preload = "auto";
1151
- this.video.tabIndex = 0;
1152
- this.video.playsInline = true;
1153
- this.video.muted = true;
1154
- this.video.pause();
1155
- this.video.load();
1156
- this.container.appendChild(this.video);
1157
- const browserEngine = new UAParser().getEngine();
1158
- this.isSafari = browserEngine.name === "WebKit";
1159
- if (this.debug && this.isSafari) console.info("Safari browser detected");
1160
- this.video.addEventListener("loadedmetadata", () => this.setTargetTimePercent(0, true), { once: true });
1161
- this.video.addEventListener("progress", this.resize);
1162
- this.decodeVideo();
1163
- }
1164
- setCoverStyle(el) {
1165
- if (el && this.container) {
1166
- el.style.position = "absolute";
1167
- el.style.top = "50%";
1168
- el.style.left = "50%";
1169
- el.style.transform = "translate(-50%, -50%)";
1170
- const { width: containerWidth, height: containerHeight } = this.container.getBoundingClientRect();
1171
- const width = el.videoWidth || el.width;
1172
- const height = el.videoHeight || el.height;
1173
- if (containerWidth / containerHeight > width / height) {
1174
- el.style.width = "100%";
1175
- el.style.height = "auto";
1176
- } else {
1177
- el.style.height = "100%";
1178
- el.style.width = "auto";
1179
- }
1180
- }
1181
- }
1182
- paintCanvasFrame(frameNum) {
1183
- if (this.canvas) {
1184
- const frameIdx = Math.min(frameNum, this.frames.length - 1);
1185
- const currFrame = this.frames[frameIdx];
1186
- if (currFrame && this.container) {
1187
- if (this.debug) console.info("Painting frame", frameIdx);
1188
- this.canvas.width = currFrame.width;
1189
- this.canvas.height = currFrame.height;
1190
- const { width, height } = this.container.getBoundingClientRect();
1191
- this.resetCanvasDimensions(width, height, currFrame.width, currFrame.height);
1192
- this.context.drawImage(currFrame, 0, 0, currFrame.width, currFrame.height);
1193
- }
1194
- }
1195
- }
1196
- transitionToTargetTime(jump) {
1197
- if (!this.video) return;
1198
- if (this.debug) console.info("Transitioning targetTime:", this.targetTime, "currentTime:", this.currentTime);
1199
- if (isNaN(this.targetTime) || Math.abs(this.currentTime - this.targetTime) < this.frameThreshold) {
1200
- this.video.pause();
1201
- this.transitioning = false;
1202
- return;
1203
- }
1204
- if (this.targetTime > this.video.duration) {
1205
- this.targetTime = this.video.duration;
1206
- }
1207
- if (this.targetTime < 0) {
1208
- this.targetTime = 0;
1209
- }
1210
- const transitionForward = this.targetTime - this.currentTime;
1211
- if (this.canvas) {
1212
- this.currentTime += transitionForward / (256 / this.transitionSpeed);
1213
- if (jump) {
1214
- this.currentTime = this.targetTime;
1215
- }
1216
- this.paintCanvasFrame(Math.floor(this.currentTime * this.frameRate));
1217
- } else if (jump || this.isSafari || this.targetTime - this.currentTime < 0) {
1218
- this.video.pause();
1219
- this.currentTime += transitionForward / (64 / this.transitionSpeed);
1220
- if (jump) {
1221
- this.currentTime = this.targetTime;
1222
- }
1223
- this.video.currentTime = this.currentTime;
1224
- } else {
1225
- const playbackRate = Math.max(Math.min(transitionForward * 4, this.transitionSpeed, 16), 1);
1226
- if (this.debug) console.info("ScrollVideo playbackRate:", playbackRate);
1227
- if (!isNaN(playbackRate)) {
1228
- this.video.playbackRate = playbackRate;
1229
- this.video.play();
1230
- }
1231
- this.currentTime = this.video.currentTime;
1232
- }
1233
- if (typeof requestAnimationFrame === "function") {
1234
- requestAnimationFrame(() => this.transitionToTargetTime(jump));
1235
- }
1236
- }
1237
- resetCanvasDimensions(w, h, frameW, frameH) {
1238
- if (!this.canvas) return;
1239
- if (w / h > frameW / frameH) {
1240
- this.canvas.style.width = "100%";
1241
- this.canvas.style.height = "auto";
1242
- } else {
1243
- this.canvas.style.height = "100%";
1244
- this.canvas.style.width = "auto";
1245
- }
1246
- }
1247
- setTargetTimePercent(setPercentage, jump = true) {
1248
- if (!this.video) return;
1249
- this.targetTime = Math.max(Math.min(setPercentage, 1), 0) * (this.frames.length && this.frameRate ? this.frames.length / this.frameRate : this.video.duration);
1250
- if (!jump && Math.abs(this.currentTime - this.targetTime) < this.frameThreshold) return;
1251
- if (!jump && this.transitioning) return;
1252
- if (!this.canvas && !this.video.paused) this.video.play();
1253
- this.transitioning = true;
1254
- this.transitionToTargetTime(jump);
1255
- }
1256
- destroy() {
1257
- var _a;
1258
- this.resizeObserver.unobserve(this.container);
1259
- (_a = this.video) == null ? void 0 : _a.removeEventListener("progress", this.resize);
1260
- if (this.debug) console.info("Destroying ScrollVideo");
1261
- if (this.container) this.container.innerHTML = "";
1262
- }
1263
- }
1264
- const wrapper = "ControlSlider-module__wrapper___sHEkd";
1265
- const sliderItem = "ControlSlider-module__sliderItem___QQSkR";
1266
- const sliderImage = "ControlSlider-module__sliderImage___9hRl-";
1267
- const arrow = "ControlSlider-module__arrow___05ghY";
1268
- const arrowVertical = "ControlSlider-module__arrowVertical___tBfVN";
1269
- const nextArrow = "ControlSlider-module__nextArrow___-30Yc";
1270
- const arrowInner = "ControlSlider-module__arrowInner___aEra3";
1271
- const arrowIcon = "ControlSlider-module__arrowIcon___S4ztF";
1272
- const arrowImg = "ControlSlider-module__arrowImg___2dwJW";
1273
- const mirror = "ControlSlider-module__mirror___brd6U";
1274
- const pagination = "ControlSlider-module__pagination___bicLF";
1275
- const paginationInner = "ControlSlider-module__paginationInner___bT-P-";
1276
- const paginationVertical = "ControlSlider-module__paginationVertical___zYqKw";
1277
- const paginationItem = "ControlSlider-module__paginationItem___nTRbk";
1278
- const dot = "ControlSlider-module__dot___p1Qun";
1279
- const activeDot = "ControlSlider-module__activeDot___LHFaj";
1280
- const paginationInsideBottom = "ControlSlider-module__paginationInsideBottom___R3FWn";
1281
- const paginationInsideTop = "ControlSlider-module__paginationInsideTop___V-qb-";
1282
- const paginationOutsideBottom = "ControlSlider-module__paginationOutsideBottom___14w8D";
1283
- const paginationOutsideTop = "ControlSlider-module__paginationOutsideTop___SCLqB";
1284
- const paginationInsideLeft = "ControlSlider-module__paginationInsideLeft___yOBRZ";
1285
- const paginationInsideRight = "ControlSlider-module__paginationInsideRight___Rtt3o";
1286
- const paginationOutsideLeft = "ControlSlider-module__paginationOutsideLeft___lahaw";
1287
- const paginationOutsideRight = "ControlSlider-module__paginationOutsideRight___EtuQa";
1288
- const imgWrapper = "ControlSlider-module__imgWrapper___UjEgB";
1289
- const captionBlock = "ControlSlider-module__captionBlock___dJ6-j";
1290
- const captionTextWrapper = "ControlSlider-module__captionTextWrapper___HFlpf";
1291
- const captionText = "ControlSlider-module__captionText___uGBVc";
1292
- const active = "ControlSlider-module__active___WZK4G";
1293
- const withPointerEvents = "ControlSlider-module__withPointerEvents___t-18M";
1294
- const topLeftAlignment = "ControlSlider-module__topLeftAlignment___zjnGM";
1295
- const topCenterAlignment = "ControlSlider-module__topCenterAlignment___gD1xW";
1296
- const topRightAlignment = "ControlSlider-module__topRightAlignment___NMapS";
1297
- const middleLeftAlignment = "ControlSlider-module__middleLeftAlignment___OnUrY";
1298
- const middleCenterAlignment = "ControlSlider-module__middleCenterAlignment___Tdkl0";
1299
- const middleRightAlignment = "ControlSlider-module__middleRightAlignment___wEbfX";
1300
- const bottomLeftAlignment = "ControlSlider-module__bottomLeftAlignment___cTP2-";
1301
- const bottomCenterAlignment = "ControlSlider-module__bottomCenterAlignment___c54fB";
1302
- const bottomRightAlignment = "ControlSlider-module__bottomRightAlignment___kEwrz";
1303
- const clickOverlay = "ControlSlider-module__clickOverlay___DZA28";
1304
- const contain = "ControlSlider-module__contain___pLyq7";
1305
- const cover = "ControlSlider-module__cover___KdDat";
1306
- const styles$3 = {
1307
- wrapper,
1308
- sliderItem,
1309
- sliderImage,
1310
- arrow,
1311
- arrowVertical,
1312
- nextArrow,
1313
- arrowInner,
1314
- arrowIcon,
1315
- arrowImg,
1316
- mirror,
1317
- pagination,
1318
- paginationInner,
1319
- paginationVertical,
1320
- paginationItem,
1321
- dot,
1322
- activeDot,
1323
- paginationInsideBottom,
1324
- paginationInsideTop,
1325
- paginationOutsideBottom,
1326
- paginationOutsideTop,
1327
- paginationInsideLeft,
1328
- paginationInsideRight,
1329
- paginationOutsideLeft,
1330
- paginationOutsideRight,
1331
- imgWrapper,
1332
- captionBlock,
1333
- captionTextWrapper,
1334
- captionText,
1335
- active,
1336
- withPointerEvents,
1337
- topLeftAlignment,
1338
- topCenterAlignment,
1339
- topRightAlignment,
1340
- middleLeftAlignment,
1341
- middleCenterAlignment,
1342
- middleRightAlignment,
1343
- bottomLeftAlignment,
1344
- bottomCenterAlignment,
1345
- bottomRightAlignment,
1346
- clickOverlay,
1347
- contain,
1348
- cover
1349
- };
1350
- const link$1 = "RichTextRenderer-module__link___BWeZ2";
1351
- const styles$2 = {
1352
- link: link$1
1353
- };
1354
- const RichTextRenderer = ({ content }) => {
1355
- const getChildren = (children) => {
1356
- return children.map((child, i) => {
1357
- if (child.type === "link") {
1358
- return /* @__PURE__ */ jsx("a", { className: styles$2.link, href: child.value, target: child.target, children: getChildren(child.children) }, i);
1359
- }
1360
- return /* @__PURE__ */ jsx("span", { style: getLeafCss(child), children: child.text }, i);
1361
- });
1362
- };
1363
- return /* @__PURE__ */ jsx(Fragment, { children: content.map((block, i) => {
1364
- const children = block.children;
1365
- return /* @__PURE__ */ jsx("div", { children: getChildren(children) }, i);
1366
- }) });
1367
- };
1368
- function getLeafCss(leaf) {
1369
- return {
1370
- ...leaf.fontFamily && { fontFamily: leaf.fontFamily },
1371
- ...leaf.fontWeight && { fontWeight: leaf.fontWeight },
1372
- ...leaf.fontStyle && { fontStyle: leaf.fontStyle },
1373
- ...leaf.textDecoration && { textDecoration: leaf.textDecoration },
1374
- ...leaf.textTransform && { textTransform: leaf.textTransform },
1375
- ...leaf.fontVariant && { fontVariant: leaf.fontVariant },
1376
- ...leaf.verticalAlign && {
1377
- verticalAlign: leaf.verticalAlign,
1378
- lineHeight: "0px"
1379
- }
1380
- };
1381
- }
1382
- function scalingValue(value, isEditor = false) {
1383
- return isEditor ? `calc(var(--cntrl-article-width) * ${value})` : `${value * 100}vw`;
1384
- }
1385
- const svg = "SvgImage-module__svg___q3xE-";
1386
- const img = "SvgImage-module__img___VsTm-";
1387
- const styles$1 = {
1388
- svg,
1389
- img
1390
- };
1391
- const SvgImage = ({ url, fill = "#000000", hoverFill = "#CCCCCC", className = "" }) => {
1392
- const [supportsMask, setSupportsMask] = useState(true);
1393
- useEffect(() => {
1394
- if (typeof window !== "undefined" && window.CSS) {
1395
- const supported = CSS.supports("mask-image", 'url("")') || CSS.supports("-webkit-mask-image", 'url("")');
1396
- setSupportsMask(supported);
1397
- }
1398
- }, []);
1399
- if (!url.endsWith(".svg") || !supportsMask) {
1400
- return /* @__PURE__ */ jsx("img", { src: url, alt: "", className: cn(styles$1.img, className) });
1401
- }
1402
- return /* @__PURE__ */ jsx(
1403
- "span",
1404
- {
1405
- "data-supports-mask": supportsMask,
1406
- className: cn(styles$1.svg, className),
1407
- style: {
1408
- "--svg": `url(${url})`,
1409
- "--fill": fill,
1410
- "--hover-fill": hoverFill
1411
- }
1412
- }
1413
- );
1414
- };
1415
- const alignmentClassName = {
1416
- "top-left": styles$3.topLeftAlignment,
1417
- "top-center": styles$3.topCenterAlignment,
1418
- "top-right": styles$3.topRightAlignment,
1419
- "middle-left": styles$3.middleLeftAlignment,
1420
- "middle-center": styles$3.middleCenterAlignment,
1421
- "middle-right": styles$3.middleRightAlignment,
1422
- "bottom-left": styles$3.bottomLeftAlignment,
1423
- "bottom-center": styles$3.bottomCenterAlignment,
1424
- "bottom-right": styles$3.bottomRightAlignment
1425
- };
1426
- function ControlSlider({ settings, content, styles: sliderStyles, isEditor }) {
1427
- const [sliderRef, setSliderRef] = useState(null);
1428
- const { widthSettings, fontSettings, letterSpacing, textAlign, wordSpacing, fontSizeLineHeight, textAppearance, color } = sliderStyles.caption;
1429
- const [sliderDimensions, setSliderDimensions] = useState(void 0);
1430
- const [wrapperRef, setWrapperRef] = useState(null);
1431
- const [currentSlideIndex, setCurrentSlideIndex] = useState(0);
1432
- const [key, setKey] = useState(0);
1433
- const { direction, transition, controls, pagination: pagination2, caption, triggers } = settings;
1434
- const prevSliderTypeRef = useRef(transition.type);
1435
- const { x: controlsOffsetX, y: controlsOffsetY } = settings.controls.offset;
1436
- const handleArrowClick = (dir) => {
1437
- if (sliderRef) {
1438
- sliderRef.go(dir);
1439
- }
1440
- };
1441
- useEffect(() => {
1442
- if (!wrapperRef) return;
1443
- const observer = new ResizeObserver((entries) => {
1444
- if (!sliderRef) return;
1445
- const [wrapper2] = entries;
1446
- setSliderDimensions({
1447
- width: Math.round(wrapper2.contentRect.width),
1448
- height: Math.round(wrapper2.contentRect.height)
1449
- });
1450
- });
1451
- observer.observe(wrapperRef);
1452
- return () => observer.unobserve(wrapperRef);
1453
- }, [wrapperRef]);
1454
- useEffect(() => {
1455
- if (!sliderRef || prevSliderTypeRef.current === transition.type) return;
1456
- setKey((prev) => prev + 1);
1457
- prevSliderTypeRef.current = transition.type;
1458
- }, [transition.type]);
1459
- return /* @__PURE__ */ jsx("div", { className: cn(styles$3.wrapper, { [styles$3.editor]: isEditor }), ref: setWrapperRef, children: /* @__PURE__ */ jsxs(
1460
- "div",
1461
- {
1462
- className: styles$3.sliderInner,
1463
- style: {
1464
- width: sliderDimensions ? sliderDimensions.width : "100%",
1465
- height: sliderDimensions ? sliderDimensions.height : "100%",
1466
- backgroundColor: transition.backgroundColor && transition.type === "fade in" ? transition.backgroundColor : "transparent"
1467
- },
1468
- children: [
1469
- settings.caption.isActive && /* @__PURE__ */ jsx(
1470
- "div",
1471
- {
1472
- className: cn(styles$3.captionBlock),
1473
- children: /* @__PURE__ */ jsx(
1474
- "div",
1475
- {
1476
- className: styles$3.captionTextWrapper,
1477
- children: content.map((item, index) => /* @__PURE__ */ jsx(
1478
- "div",
1479
- {
1480
- className: cn(styles$3.captionText, alignmentClassName[caption.alignment], {
1481
- [styles$3.withPointerEvents]: index === currentSlideIndex && isEditor,
1482
- [styles$3.active]: index === currentSlideIndex
1483
- }),
1484
- style: {
1485
- fontFamily: fontSettings.fontFamily,
1486
- fontWeight: fontSettings.fontWeight,
1487
- fontStyle: fontSettings.fontStyle,
1488
- width: widthSettings.sizing === "auto" ? "max-content" : scalingValue(widthSettings.width, isEditor),
1489
- letterSpacing: scalingValue(letterSpacing, isEditor),
1490
- wordSpacing: scalingValue(wordSpacing, isEditor),
1491
- textAlign,
1492
- fontSize: scalingValue(fontSizeLineHeight.fontSize, isEditor),
1493
- lineHeight: scalingValue(fontSizeLineHeight.lineHeight, isEditor),
1494
- textTransform: textAppearance.textTransform ?? "none",
1495
- textDecoration: textAppearance.textDecoration ?? "none",
1496
- fontVariant: textAppearance.fontVariant ?? "normal",
1497
- color,
1498
- transitionDuration: transition.duration ? `${Math.round(parseInt(transition.duration) / 2)}ms` : "500ms"
1499
- },
1500
- children: /* @__PURE__ */ jsx(
1501
- "div",
1502
- {
1503
- "data-styles": "caption",
1504
- className: styles$3.captionTextInner,
1505
- style: {
1506
- "--link-hover-color": caption.hover,
1507
- position: "relative",
1508
- top: scalingValue(caption.offset.y, isEditor),
1509
- left: scalingValue(caption.offset.x, isEditor)
1510
- },
1511
- children: /* @__PURE__ */ jsx(RichTextRenderer, { content: item.imageCaption })
1512
- }
1513
- )
1514
- },
1515
- index
1516
- ))
1517
- }
1518
- )
1519
- }
1520
- ),
1521
- /* @__PURE__ */ jsx(
1522
- Splide,
1523
- {
1524
- onMove: (e) => {
1525
- setCurrentSlideIndex(e.index);
1526
- },
1527
- ref: setSliderRef,
1528
- options: {
1529
- arrows: false,
1530
- speed: transition.duration ? parseInt(transition.duration) : 500,
1531
- autoplay: isEditor ? false : triggers.autoPlay !== null,
1532
- ...triggers.autoPlay !== null && {
1533
- interval: parseInt(triggers.autoPlay) * 1e3
1534
- },
1535
- direction: direction === "horiz" || transition.type === "fade in" ? "ltr" : "ttb",
1536
- pagination: false,
1537
- drag: triggers.triggersList.drag,
1538
- perPage: 1,
1539
- width: sliderDimensions ? sliderDimensions.width : "100%",
1540
- height: sliderDimensions ? sliderDimensions.height : "100%",
1541
- type: transition.type === "fade in" ? "fade" : "loop",
1542
- rewind: true
1543
- },
1544
- children: content.map((item, index) => /* @__PURE__ */ jsx(SplideSlide, { children: /* @__PURE__ */ jsx(
1545
- "div",
1546
- {
1547
- className: styles$3.sliderItem,
1548
- children: /* @__PURE__ */ jsx(
1549
- "div",
1550
- {
1551
- className: styles$3.imgWrapper,
1552
- children: /* @__PURE__ */ jsx(
1553
- "img",
1554
- {
1555
- className: cn(styles$3.sliderImage, {
1556
- [styles$3.contain]: item.image.objectFit === "contain",
1557
- [styles$3.cover]: item.image.objectFit === "cover"
1558
- }),
1559
- src: item.image.url,
1560
- alt: item.image.name ?? ""
1561
- }
1562
- )
1563
- }
1564
- )
1565
- }
1566
- ) }, index))
1567
- },
1568
- key
1569
- ),
1570
- controls.isActive && /* @__PURE__ */ jsxs(Fragment, { children: [
1571
- /* @__PURE__ */ jsx(
1572
- "div",
1573
- {
1574
- className: cn(styles$3.arrow, {
1575
- [styles$3.arrowVertical]: direction === "vert"
1576
- }),
1577
- style: {
1578
- color: controls.color,
1579
- ["--arrow-hover-color"]: controls.hover
1580
- },
1581
- children: /* @__PURE__ */ jsxs(
1582
- "button",
1583
- {
1584
- onClick: () => {
1585
- handleArrowClick("-1");
1586
- },
1587
- className: styles$3.arrowInner,
1588
- style: {
1589
- transform: `translate(${scalingValue(controlsOffsetX, isEditor)}, ${scalingValue(controlsOffsetY * (direction === "horiz" ? 1 : -1), isEditor)}) scale(${settings.controls.scale / 100}) rotate(${direction === "horiz" ? "0deg" : "90deg"})`
1590
- },
1591
- children: [
1592
- controls.arrowsImgUrl && /* @__PURE__ */ jsx(
1593
- SvgImage,
1594
- {
1595
- url: controls.arrowsImgUrl,
1596
- fill: controls.color,
1597
- hoverFill: controls.hover,
1598
- className: cn(styles$3.arrowImg, styles$3.mirror)
1599
- }
1600
- ),
1601
- !controls.arrowsImgUrl && /* @__PURE__ */ jsx(ArrowIcon, { color: controls.color, className: cn(styles$3.arrowIcon, styles$3.arrowImg, styles$3.mirror) })
1602
- ]
1603
- }
1604
- )
1605
- }
1606
- ),
1607
- /* @__PURE__ */ jsx(
1608
- "div",
1609
- {
1610
- className: cn(styles$3.arrow, styles$3.nextArrow, {
1611
- [styles$3.arrowVertical]: direction === "vert"
1612
- }),
1613
- style: {
1614
- color: controls.color,
1615
- ["--arrow-hover-color"]: controls.hover
1616
- },
1617
- children: /* @__PURE__ */ jsxs(
1618
- "button",
1619
- {
1620
- className: styles$3.arrowInner,
1621
- onClick: () => handleArrowClick("+1"),
1622
- style: {
1623
- transform: `translate(${scalingValue(controlsOffsetX * (direction === "horiz" ? -1 : 1), isEditor)}, ${scalingValue(controlsOffsetY, isEditor)}) scale(${settings.controls.scale / 100}) rotate(${direction === "horiz" ? "0deg" : "90deg"})`
1624
- },
1625
- children: [
1626
- controls.arrowsImgUrl && /* @__PURE__ */ jsx(
1627
- SvgImage,
1628
- {
1629
- url: controls.arrowsImgUrl,
1630
- fill: controls.color,
1631
- hoverFill: controls.hover,
1632
- className: styles$3.arrowImg
1633
- }
1634
- ),
1635
- !controls.arrowsImgUrl && /* @__PURE__ */ jsx(ArrowIcon, { color: controls.color, className: cn(styles$3.arrowIcon, styles$3.arrowImg) })
1636
- ]
1637
- }
1638
- )
1639
- }
1640
- )
1641
- ] }),
1642
- triggers.triggersList.click && /* @__PURE__ */ jsx(
1643
- "div",
1644
- {
1645
- className: styles$3.clickOverlay,
1646
- onClick: () => {
1647
- if (sliderRef) {
1648
- sliderRef.go("+1");
1649
- }
1650
- }
1651
- }
1652
- ),
1653
- pagination2.isActive && /* @__PURE__ */ jsx(
1654
- "div",
1655
- {
1656
- className: cn(styles$3.pagination, {
1657
- [styles$3.paginationInsideBottom]: pagination2.position === "inside-1" && direction === "horiz",
1658
- [styles$3.paginationInsideTop]: pagination2.position === "inside-2" && direction === "horiz",
1659
- [styles$3.paginationOutsideBottom]: pagination2.position === "outside-1" && direction === "horiz",
1660
- [styles$3.paginationOutsideTop]: pagination2.position === "outside-2" && direction === "horiz",
1661
- [styles$3.paginationInsideLeft]: pagination2.position === "inside-1" && direction === "vert",
1662
- [styles$3.paginationInsideRight]: pagination2.position === "inside-2" && direction === "vert",
1663
- [styles$3.paginationOutsideLeft]: pagination2.position === "outside-1" && direction === "vert",
1664
- [styles$3.paginationOutsideRight]: pagination2.position === "outside-2" && direction === "vert",
1665
- [styles$3.paginationVertical]: direction === "vert"
1666
- }),
1667
- children: /* @__PURE__ */ jsx(
1668
- "div",
1669
- {
1670
- className: styles$3.paginationInner,
1671
- style: {
1672
- backgroundColor: pagination2.colors[2],
1673
- transform: `scale(${pagination2.scale / 100}) translate(${scalingValue(pagination2.offset.x, isEditor)}, ${scalingValue(pagination2.offset.y, isEditor)}) rotate(${direction === "horiz" ? "0deg" : "90deg"})`
1674
- },
1675
- children: content.map((_, index) => /* @__PURE__ */ jsx(
1676
- "button",
1677
- {
1678
- onClick: () => {
1679
- if (sliderRef) {
1680
- sliderRef.go(index);
1681
- }
1682
- },
1683
- className: cn(styles$3.paginationItem),
1684
- children: /* @__PURE__ */ jsx(
1685
- "div",
1686
- {
1687
- className: cn(styles$3.dot, {
1688
- [styles$3.activeDot]: index === currentSlideIndex
1689
- }),
1690
- style: {
1691
- backgroundColor: index === currentSlideIndex ? pagination2.colors[0] : pagination2.colors[1],
1692
- ["--pagination-hover-color"]: pagination2.hover
1693
- }
1694
- }
1695
- )
1696
- },
1697
- index
1698
- ))
1699
- }
1700
- )
1701
- }
1702
- )
1703
- ]
1704
- }
1705
- ) });
1706
- }
1707
- function ArrowIcon({ color, className }) {
1708
- return /* @__PURE__ */ jsx("svg", { viewBox: "0 0 10 18", className, children: /* @__PURE__ */ jsx("g", { id: "Symbols", stroke: "none", strokeWidth: "1", fillRule: "evenodd", children: /* @__PURE__ */ jsx("path", { d: "M-3.70710678,4.29289322 C-3.34662282,3.93240926 -2.77939176,3.90467972 -2.38710056,4.20970461 L-2.29289322,4.29289322 L5,11.585 L12.2928932,4.29289322 C12.6533772,3.93240926 13.2206082,3.90467972 13.6128994,4.20970461 L13.7071068,4.29289322 C14.0675907,4.65337718 14.0953203,5.22060824 13.7902954,5.61289944 L13.7071068,5.70710678 L5.70710678,13.7071068 C5.34662282,14.0675907 4.77939176,14.0953203 4.38710056,13.7902954 L4.29289322,13.7071068 L-3.70710678,5.70710678 C-4.09763107,5.31658249 -4.09763107,4.68341751 -3.70710678,4.29289322 Z", id: "Shape-Copy", fill: color, transform: "translate(5, 9) rotate(-90) translate(-5, -9)" }) }) });
1709
- }
1710
- const ControlSliderComponent = {
1711
- element: ControlSlider,
1712
- id: "control-slider",
1713
- name: "Slider",
1714
- preview: {
1715
- type: "video",
1716
- url: "https://cdn.cntrl.site/projects/01JJKT02AWY2FGN2QJ7A173RNZ/articles-assets/01K7EQ4ME6CP4KX7TJ4HPAXFEW.mp4"
1717
- },
1718
- defaultSize: {
1719
- width: 400,
1720
- height: 400
1721
- },
1722
- schema: {
1723
- type: "object",
1724
- properties: {
1725
- settings: {
1726
- layoutBased: true,
1727
- type: "object",
1728
- properties: {
1729
- triggers: {
1730
- name: "triggers",
1731
- icon: "target",
1732
- tooltip: "Triggers",
1733
- type: "object",
1734
- properties: {
1735
- triggersList: {
1736
- type: "object",
1737
- display: {
1738
- type: "toggle-ratio-group"
1739
- },
1740
- properties: {
1741
- click: {
1742
- type: "boolean"
1743
- },
1744
- drag: {
1745
- type: "boolean"
1746
- }
1747
- }
1748
- },
1749
- autoPlay: {
1750
- type: ["string", "null"],
1751
- label: "Auto",
1752
- display: {
1753
- type: "step-selector"
1754
- },
1755
- enum: [null, "1s", "2s", "3s", "4s", "5s"]
1756
- }
1757
- }
1758
- },
1759
- direction: {
1760
- name: "direction",
1761
- icon: "horizontal-resize",
1762
- tooltip: "Direction",
1763
- type: "string",
1764
- display: {
1765
- type: "ratio-group"
1766
- },
1767
- enum: ["horiz", "vert"]
1768
- },
1769
- transition: {
1770
- name: "transit",
1771
- icon: "transition",
1772
- tooltip: "Transition",
1773
- type: "object",
1774
- properties: {
1775
- type: {
1776
- type: "string",
1777
- display: {
1778
- type: "ratio-group"
1779
- },
1780
- enum: ["slide", "fade in"]
1781
- },
1782
- backgroundColor: {
1783
- type: ["string", "null"],
1784
- name: "BG Color",
1785
- display: {
1786
- visible: false,
1787
- type: "settings-color-picker",
1788
- format: "single"
1789
- }
1790
- },
1791
- duration: {
1792
- type: "string",
1793
- label: "hourglass-icon",
1794
- display: {
1795
- type: "step-selector"
1796
- },
1797
- enum: ["100ms", "250ms", "500ms", "1000ms", "1500ms", "2000ms"]
1798
- }
1799
- }
1800
- },
1801
- controls: {
1802
- name: "controls",
1803
- icon: "controls",
1804
- tooltip: "Controls",
1805
- type: "object",
1806
- properties: {
1807
- isActive: {
1808
- type: "boolean",
1809
- display: {
1810
- type: "setting-toggle"
1811
- }
1812
- },
1813
- arrowsImgUrl: {
1814
- type: ["string", "null"],
1815
- display: {
1816
- type: "settings-image-input"
1817
- }
1818
- },
1819
- offset: {
1820
- type: "object",
1821
- display: {
1822
- type: "offset-controls"
1823
- },
1824
- properties: {
1825
- x: {
1826
- type: "number"
1827
- },
1828
- y: {
1829
- type: "number"
1830
- }
1831
- }
1832
- },
1833
- scale: {
1834
- type: "number",
1835
- name: "scale",
1836
- min: 50,
1837
- max: 600,
1838
- display: {
1839
- type: "range-control"
1840
- }
1841
- },
1842
- color: {
1843
- name: "color",
1844
- type: "string",
1845
- display: {
1846
- type: "settings-color-picker",
1847
- format: "single"
1848
- }
1849
- },
1850
- hover: {
1851
- name: "hover",
1852
- type: "string",
1853
- display: {
1854
- type: "settings-color-picker",
1855
- format: "single"
1856
- }
1857
- }
1858
- }
1859
- },
1860
- pagination: {
1861
- name: "nav",
1862
- icon: "pagination",
1863
- tooltip: "Navigation",
1864
- type: "object",
1865
- properties: {
1866
- isActive: {
1867
- type: "boolean",
1868
- display: {
1869
- type: "setting-toggle"
1870
- }
1871
- },
1872
- position: {
1873
- name: "nav position",
1874
- display: {
1875
- type: "socket",
1876
- direction: "horizontal"
1877
- },
1878
- type: "string",
1879
- enum: ["outside-1", "outside-2", "inside-1", "inside-2"]
1880
- },
1881
- offset: {
1882
- type: "object",
1883
- display: {
1884
- type: "offset-controls"
1885
- },
1886
- properties: {
1887
- x: {
1888
- type: "number"
1889
- },
1890
- y: {
1891
- type: "number"
1892
- }
1893
- }
1894
- },
1895
- scale: {
1896
- type: "number",
1897
- name: "scale",
1898
- min: 10,
1899
- max: 400,
1900
- display: {
1901
- type: "range-control"
1902
- }
1903
- },
1904
- colors: {
1905
- display: {
1906
- type: "settings-color-picker",
1907
- format: "multiple"
1908
- },
1909
- name: "color",
1910
- type: "array",
1911
- items: {
1912
- type: "string"
1913
- }
1914
- },
1915
- hover: {
1916
- name: "hover",
1917
- type: "string",
1918
- display: {
1919
- type: "settings-color-picker",
1920
- format: "single"
1921
- }
1922
- }
1923
- }
1924
- },
1925
- caption: {
1926
- name: "Caption",
1927
- icon: "text-icon",
1928
- tooltip: "Caption",
1929
- type: "object",
1930
- properties: {
1931
- isActive: {
1932
- type: "boolean",
1933
- display: {
1934
- type: "setting-toggle"
1935
- }
1936
- },
1937
- alignment: {
1938
- name: "Alignment",
1939
- type: "string",
1940
- display: {
1941
- type: "align-grid"
1942
- },
1943
- enum: ["top-left", "top-center", "top-right", "middle-left", "middle-center", "middle-right", "bottom-left", "bottom-center", "bottom-right"]
1944
- },
1945
- offset: {
1946
- type: "object",
1947
- display: {
1948
- type: "offset-controls"
1949
- },
1950
- properties: {
1951
- x: {
1952
- type: "number"
1953
- },
1954
- y: {
1955
- type: "number"
1956
- }
1957
- }
1958
- },
1959
- hover: {
1960
- name: "hover",
1961
- type: "string",
1962
- display: {
1963
- type: "settings-color-picker",
1964
- format: "single"
1965
- }
1966
- }
1967
- }
1968
- }
1969
- },
1970
- default: {
1971
- triggers: {
1972
- triggersList: {
1973
- click: false,
1974
- drag: true
1975
- },
1976
- autoPlay: null
1977
- },
1978
- controls: {
1979
- isActive: true,
1980
- arrowsImgUrl: null,
1981
- offset: {
1982
- x: 0,
1983
- y: 0
1984
- },
1985
- scale: 100,
1986
- color: "#000000",
1987
- hover: "#cccccc"
1988
- },
1989
- transition: {
1990
- type: "slide",
1991
- duration: "500ms",
1992
- backgroundColor: null
1993
- },
1994
- pagination: {
1995
- isActive: true,
1996
- scale: 50,
1997
- position: "outside-1",
1998
- offset: {
1999
- x: 0,
2000
- y: 0
2001
- },
2002
- colors: ["#cccccc", "#cccccc", "#000000"],
2003
- hover: "#cccccc"
2004
- },
2005
- direction: "horiz",
2006
- caption: {
2007
- offset: {
2008
- x: 0,
2009
- y: 0
2010
- },
2011
- isActive: true,
2012
- alignment: "middle-center",
2013
- hover: "#cccccc"
2014
- }
2015
- },
2016
- displayRules: [
2017
- {
2018
- if: {
2019
- name: "direction",
2020
- value: "vert"
2021
- },
2022
- then: {
2023
- name: "properties.pagination.properties.position.display.direction",
2024
- value: "vertical"
2025
- }
2026
- },
2027
- {
2028
- if: {
2029
- name: "transition.type",
2030
- value: "fade in"
2031
- },
2032
- then: {
2033
- name: "properties.transition.properties.backgroundColor.display.visible",
2034
- value: true
2035
- }
2036
- }
2037
- ]
2038
- },
2039
- content: {
2040
- layoutBased: false,
2041
- type: "array",
2042
- settings: {
2043
- addItemFromFileExplorer: true
2044
- },
2045
- items: {
2046
- type: "object",
2047
- properties: {
2048
- image: {
2049
- type: "object",
2050
- display: {
2051
- type: "media-input",
2052
- minWidth: 48,
2053
- defaultWidth: 108,
2054
- maxWidth: 108
2055
- },
2056
- properties: {
2057
- url: {
2058
- type: "string"
2059
- },
2060
- name: {
2061
- type: "string"
2062
- },
2063
- objectFit: {
2064
- type: "string",
2065
- enum: ["cover", "contain"]
2066
- }
2067
- },
2068
- required: ["url", "name"]
2069
- },
2070
- imageCaption: {
2071
- display: {
2072
- type: "rich-text",
2073
- placeholder: "Add Caption...",
2074
- minWidth: 100,
2075
- defaultWidth: 300,
2076
- maxWidth: 500
2077
- }
2078
- }
2079
- },
2080
- required: ["image"]
2081
- },
2082
- default: [
2083
- {
2084
- image: {
2085
- objectFit: "cover",
2086
- url: "https://cdn.cntrl.site/projects/01JJKT02AWY2FGN2QJ7A173RNZ/articles-assets/01K7ERMHNP08T27H1649S67NZV.png",
2087
- name: "Slider-1.png"
2088
- },
2089
- imageCaption: [
2090
- {
2091
- type: "paragraph",
2092
- children: [{ text: "" }]
2093
- }
2094
- ]
2095
- },
2096
- {
2097
- image: {
2098
- objectFit: "cover",
2099
- url: "https://cdn.cntrl.site/projects/01JJKT02AWY2FGN2QJ7A173RNZ/articles-assets/01K7ERMTZA3RYMXKF0M095D6JD.png",
2100
- name: "Slider-2.png"
2101
- },
2102
- imageCaption: [
2103
- {
2104
- type: "paragraph",
2105
- children: [{ text: "" }]
2106
- }
2107
- ]
2108
- },
2109
- {
2110
- image: {
2111
- objectFit: "cover",
2112
- url: "https://cdn.cntrl.site/projects/01JJKT02AWY2FGN2QJ7A173RNZ/articles-assets/01K7ERMVSCMPVJBG2WF5KJZYHZ.png",
2113
- name: "Slider-3.png"
2114
- },
2115
- imageCaption: [
2116
- {
2117
- type: "paragraph",
2118
- children: [{ text: "" }]
2119
- }
2120
- ]
2121
- }
2122
- ]
2123
- },
2124
- styles: {
2125
- layoutBased: true,
2126
- type: "object",
2127
- properties: {
2128
- caption: {
2129
- dataName: "caption",
2130
- type: "object",
2131
- properties: {
2132
- fontSettings: {
2133
- type: "object",
2134
- display: {
2135
- type: "font-settings"
2136
- },
2137
- properties: {
2138
- fontFamily: {
2139
- type: "string"
2140
- },
2141
- fontWeight: {
2142
- type: "number"
2143
- },
2144
- fontStyle: {
2145
- type: "string"
2146
- }
2147
- }
2148
- },
2149
- widthSettings: {
2150
- display: {
2151
- type: "text-width-control"
2152
- },
2153
- type: "object",
2154
- properties: {
2155
- width: {
2156
- type: "number"
2157
- },
2158
- sizing: {
2159
- type: "string",
2160
- enum: ["auto", "manual"]
2161
- }
2162
- }
2163
- },
2164
- fontSizeLineHeight: {
2165
- type: "object",
2166
- display: {
2167
- type: "font-size-line-height"
2168
- },
2169
- properties: {
2170
- fontSize: {
2171
- type: "number"
2172
- },
2173
- lineHeight: {
2174
- type: "number"
2175
- }
2176
- }
2177
- },
2178
- letterSpacing: {
2179
- display: {
2180
- type: "letter-spacing-input"
2181
- },
2182
- type: "number"
2183
- },
2184
- wordSpacing: {
2185
- display: {
2186
- type: "word-spacing-input"
2187
- },
2188
- type: "number"
2189
- },
2190
- textAlign: {
2191
- display: {
2192
- type: "text-align-control"
2193
- },
2194
- type: "string",
2195
- enum: ["left", "center", "right", "justify"]
2196
- },
2197
- textAppearance: {
2198
- display: {
2199
- type: "text-appearance"
2200
- },
2201
- properties: {
2202
- textTransform: {
2203
- type: "string",
2204
- enum: ["none", "uppercase", "lowercase", "capitalize"]
2205
- },
2206
- textDecoration: {
2207
- type: "string",
2208
- enum: ["none", "underline"]
2209
- },
2210
- fontVariant: {
2211
- type: "string",
2212
- enum: ["normal", "small-caps"]
2213
- }
2214
- }
2215
- },
2216
- color: {
2217
- display: {
2218
- type: "style-panel-color-picker"
2219
- },
2220
- type: "string"
2221
- }
2222
- }
2223
- }
2224
- },
2225
- default: {
2226
- caption: {
2227
- widthSettings: {
2228
- width: 0.13,
2229
- sizing: "auto"
2230
- },
2231
- fontSettings: {
2232
- fontFamily: "Arial",
2233
- fontWeight: 400,
2234
- fontStyle: "normal"
2235
- },
2236
- fontSizeLineHeight: {
2237
- fontSize: 0.02,
2238
- lineHeight: 0.02
2239
- },
2240
- letterSpacing: 0,
2241
- wordSpacing: 0,
2242
- textAlign: "left",
2243
- textAppearance: {
2244
- textTransform: "none",
2245
- textDecoration: "none",
2246
- fontVariant: "normal"
2247
- },
2248
- color: "#000000"
2249
- }
2250
- }
2251
- }
2252
- },
2253
- required: ["settings", "content", "styles"]
2254
- }
2255
- };
2256
- const imageRevealSlider = "ImageRevealSlider-module__imageRevealSlider___UE5Ob";
2257
- const image = "ImageRevealSlider-module__image___Qjt-e";
2258
- const link = "ImageRevealSlider-module__link___N-iLG";
2259
- const styles = {
2260
- imageRevealSlider,
2261
- image,
2262
- link
2263
- };
2264
- function isMouseOverImage(mouseX, mouseY, placedImages) {
2265
- for (const img2 of placedImages) {
2266
- const imgEl = new Image();
2267
- imgEl.src = img2.url;
2268
- const imgWidth = img2.width ? Number.parseFloat(img2.width) : imgEl.naturalWidth;
2269
- const imgHeight = imgEl.naturalHeight / imgEl.naturalWidth * imgWidth;
2270
- const halfW = imgWidth / 2;
2271
- const halfH = imgHeight / 2;
2272
- if (mouseX >= img2.x - halfW && mouseX <= img2.x + halfW && mouseY >= img2.y - halfH && mouseY <= img2.y + halfH) {
2273
- return true;
2274
- }
2275
- }
2276
- return false;
2277
- }
2278
- function getImageSize(url) {
2279
- return new Promise((resolve) => {
2280
- const img2 = new Image();
2281
- img2.src = url;
2282
- img2.onload = () => {
2283
- resolve({ width: img2.naturalWidth, height: img2.naturalHeight });
2284
- };
2285
- });
2286
- }
2287
- async function calculateImageWidthHeight(imgUrl, sizeType, customWidth, randomRange) {
2288
- let width;
2289
- let height;
2290
- if (sizeType === "custom") {
2291
- width = customWidth;
2292
- const size = await getImageSize(imgUrl);
2293
- height = size.height / size.width * width;
2294
- } else if (sizeType === "random") {
2295
- width = Math.random() * (randomRange.max - randomRange.min) + randomRange.min;
2296
- const size = await getImageSize(imgUrl);
2297
- height = size.height / size.width * width;
2298
- } else {
2299
- const size = await getImageSize(imgUrl);
2300
- width = size.width;
2301
- height = size.height;
2302
- }
2303
- return { width, height, finalWidth: `${width}px` };
2304
- }
2305
- function ImageRevealSlider({ settings, content, isEditor }) {
2306
- const divRef = useRef(null);
2307
- const [placedImages, setPlacedImages] = useState([]);
2308
- const [counter, setCounter] = useState(0);
2309
- const imageIdCounter = useRef(0);
2310
- const defaultImageCount = 1;
2311
- const { sizeType, imageWidth: customWidth, randomRangeImageWidth: randomRange } = settings.imageSize;
2312
- const { revealPosition, visible, target } = settings.position;
2313
- const { cursorType, defaultCursor, hoverCursor } = settings.cursor;
2314
- const createNewImage = async (imgData, containerWidth, containerHeight, position = {}) => {
2315
- const { width, height, finalWidth } = await calculateImageWidthHeight(
2316
- imgData.image.url,
2317
- sizeType,
2318
- customWidth,
2319
- randomRange
2320
- );
2321
- let x = 0, y = 0;
2322
- if (revealPosition === "same") {
2323
- x = containerWidth / 2;
2324
- y = containerHeight / 2;
2325
- } else {
2326
- x = position.x ?? Math.random() * containerWidth;
2327
- y = position.y ?? Math.random() * containerHeight;
2328
- }
2329
- const adjustedX = Math.min(Math.max(x, width / 2), containerWidth - width / 2);
2330
- const adjustedY = Math.min(Math.max(y, height / 2), containerHeight - height / 2);
2331
- return {
2332
- id: imageIdCounter.current++,
2333
- url: imgData.image.url,
2334
- link: imgData.link,
2335
- name: imgData.image.name,
2336
- x: adjustedX,
2337
- y: adjustedY,
2338
- width: finalWidth
2339
- };
2340
- };
2341
- const defaultContentUrls = useMemo(() => {
2342
- const defaultContentLength = Math.min(content.length, defaultImageCount);
2343
- return content.filter((_, i) => i < defaultContentLength).map((c) => c.image.url).join("-");
2344
- }, [content]);
2345
- useEffect(() => {
2346
- if (!divRef.current || content.length === 0) return;
2347
- const rect = divRef.current.getBoundingClientRect();
2348
- const containerWidth = rect.width;
2349
- const containerHeight = rect.height;
2350
- const defaultPlaced = [];
2351
- const placeImages = async () => {
2352
- for (let i = 0; i < defaultImageCount && i < content.length; i++) {
2353
- const imgData = content[i];
2354
- const newImg = await createNewImage(imgData, containerWidth, containerHeight);
2355
- defaultPlaced.push(newImg);
2356
- }
2357
- setPlacedImages(defaultPlaced);
2358
- setCounter(defaultImageCount % content.length);
2359
- };
2360
- placeImages();
2361
- }, [defaultContentUrls, sizeType, customWidth, randomRange, revealPosition]);
2362
- useEffect(() => {
2363
- if (visible === "last One") {
2364
- setPlacedImages((prev) => prev.length > 0 ? [prev[prev.length - 1]] : []);
2365
- }
2366
- }, [visible]);
2367
- const handleClick = async (e) => {
2368
- if (!divRef.current) return;
2369
- const rect = divRef.current.getBoundingClientRect();
2370
- const clickX = e.clientX - rect.left;
2371
- const clickY = e.clientY - rect.top;
2372
- if (target === "image" && !isMouseOverImage(clickX, clickY, placedImages)) return;
2373
- let x = 0, y = 0;
2374
- if (revealPosition === "on Click") {
2375
- x = clickX;
2376
- y = clickY;
2377
- } else if (revealPosition === "same") {
2378
- x = rect.width / 2;
2379
- y = rect.height / 2;
2380
- } else {
2381
- x = Math.random() * rect.width;
2382
- y = Math.random() * rect.height;
2383
- }
2384
- const imgData = content[counter];
2385
- const newImage = await createNewImage(imgData, rect.width, rect.height, { x, y });
2386
- setPlacedImages((prev) => visible === "all" ? [...prev, newImage] : [newImage]);
2387
- setCounter((prev) => prev >= content.length - 1 ? 0 : prev + 1);
2388
- };
2389
- return /* @__PURE__ */ jsx(
2390
- "div",
2391
- {
2392
- ref: divRef,
2393
- onClick: handleClick,
2394
- className: styles.imageRevealSlider,
2395
- style: { cursor: cursorType !== "system" && defaultCursor ? `url(${target === "area" ? hoverCursor : defaultCursor}), auto` : "default" },
2396
- children: placedImages.map((img2) => /* @__PURE__ */ jsx(
2397
- "div",
2398
- {
2399
- className: styles.wrapper,
2400
- style: {
2401
- top: `${img2.y}px`,
2402
- left: `${img2.x}px`,
2403
- position: "absolute",
2404
- transform: "translate(-50%, -50%)",
2405
- width: img2.width ?? "auto",
2406
- height: "auto",
2407
- cursor: cursorType !== "system" && hoverCursor ? `url(${hoverCursor}), auto` : "default"
2408
- },
2409
- children: target === "area" && img2.link ? /* @__PURE__ */ jsx("a", { href: img2.link, target: "_blank", className: styles.link, children: /* @__PURE__ */ jsx(
2410
- "img",
2411
- {
2412
- src: img2.url,
2413
- alt: img2.name,
2414
- className: styles.image
2415
- },
2416
- img2.id
2417
- ) }) : /* @__PURE__ */ jsx(
2418
- "img",
2419
- {
2420
- src: img2.url,
2421
- alt: img2.name,
2422
- className: styles.image
2423
- },
2424
- img2.id
2425
- )
2426
- },
2427
- img2.id
2428
- ))
2429
- }
2430
- );
2431
- }
2432
- const ControlImageRevealSliderComponent = {
2433
- element: ImageRevealSlider,
2434
- id: "control-image-reveal",
2435
- name: "Click Gallery",
2436
- preview: {
2437
- type: "video",
2438
- url: "https://cdn.cntrl.site/projects/01JJKT02AWY2FGN2QJ7A173RNZ/articles-assets/01K7EQ3WSW43JG5YMC8B2HTPKT.mp4"
2439
- },
2440
- defaultSize: {
2441
- width: 700,
2442
- height: 400
2443
- },
2444
- schema: {
2445
- type: "object",
2446
- properties: {
2447
- settings: {
2448
- layoutBased: true,
2449
- type: "object",
2450
- properties: {
2451
- imageSize: {
2452
- name: "IMG SIZE",
2453
- icon: "size",
2454
- tooltip: "IMG SIZE",
2455
- type: "object",
2456
- properties: {
2457
- sizeType: {
2458
- name: "sizeType",
2459
- type: "string",
2460
- display: {
2461
- type: "ratio-group"
2462
- },
2463
- enum: ["as Is", "custom", "random"]
2464
- },
2465
- imageWidth: {
2466
- type: "number",
2467
- label: "W",
2468
- display: {
2469
- type: "numeric-input",
2470
- visible: false
2471
- }
2472
- },
2473
- randomRangeImageWidth: {
2474
- type: "object",
2475
- display: {
2476
- type: "random-range-controls",
2477
- visible: false
2478
- },
2479
- properties: {
2480
- min: {
2481
- type: "number"
2482
- },
2483
- max: {
2484
- type: "number"
2485
- }
2486
- }
2487
- }
2488
- }
2489
- },
2490
- cursor: {
2491
- name: "cursor",
2492
- icon: "cursor",
2493
- tooltip: "cursor",
2494
- type: "object",
2495
- properties: {
2496
- cursorType: {
2497
- name: "cursorType",
2498
- type: "string",
2499
- display: {
2500
- type: "ratio-group"
2501
- },
2502
- enum: ["system", "custom"]
2503
- },
2504
- defaultCursor: {
2505
- type: ["string", "null"],
2506
- display: {
2507
- type: "settings-image-input",
2508
- title: "Default",
2509
- visible: false
2510
- }
2511
- },
2512
- hoverCursor: {
2513
- type: ["string", "null"],
2514
- display: {
2515
- type: "settings-image-input",
2516
- title: "Hover",
2517
- visible: false
2518
- }
2519
- }
2520
- }
2521
- },
2522
- position: {
2523
- name: "position",
2524
- icon: "transition",
2525
- tooltip: "Position",
2526
- type: "object",
2527
- properties: {
2528
- revealPosition: {
2529
- type: "string",
2530
- display: {
2531
- type: "ratio-group"
2532
- },
2533
- enum: ["random", "same", "on Click"]
2534
- },
2535
- visible: {
2536
- type: "string",
2537
- display: {
2538
- type: "ratio-group"
2539
- },
2540
- enum: ["all", "last One"]
2541
- },
2542
- target: {
2543
- type: "string",
2544
- display: {
2545
- type: "ratio-group"
2546
- },
2547
- enum: ["area", "image"]
2548
- }
2549
- }
2550
- }
2551
- },
2552
- default: {
2553
- imageSize: {
2554
- sizeType: "custom",
2555
- imageWidth: 500,
2556
- randomRangeImageWidth: {
2557
- min: 100,
2558
- max: 1e3
2559
- }
2560
- },
2561
- cursor: {
2562
- cursorType: "system",
2563
- defaultCursor: null,
2564
- hoverCursor: null
2565
- },
2566
- position: {
2567
- revealPosition: "random",
2568
- visible: "all",
2569
- target: "area"
2570
- }
2571
- },
2572
- displayRules: [
2573
- {
2574
- if: {
2575
- name: "imageSize.sizeType",
2576
- value: "custom"
2577
- },
2578
- then: {
2579
- name: "properties.imageSize.properties.imageWidth.display.visible",
2580
- value: true
2581
- }
2582
- },
2583
- {
2584
- if: {
2585
- name: "imageSize.sizeType",
2586
- value: "random"
2587
- },
2588
- then: {
2589
- name: "properties.imageSize.properties.randomRangeImageWidth.display.visible",
2590
- value: true
2591
- }
2592
- },
2593
- {
2594
- if: [
2595
- { name: "position.target", value: "image" },
2596
- { name: "cursor.cursorType", value: "custom" }
2597
- ],
2598
- then: {
2599
- name: "properties.cursor.properties.defaultCursor.display.visible",
2600
- value: true
2601
- }
2602
- },
2603
- {
2604
- if: {
2605
- name: "cursor.cursorType",
2606
- value: "custom"
2607
- },
2608
- then: {
2609
- name: "properties.cursor.properties.hoverCursor.display.visible",
2610
- value: true
2611
- }
2612
- }
2613
- ]
2614
- },
2615
- content: {
2616
- layoutBased: false,
2617
- type: "array",
2618
- settings: {
2619
- addItemFromFileExplorer: true
2620
- },
2621
- items: {
2622
- type: "object",
2623
- properties: {
2624
- image: {
2625
- type: "object",
2626
- display: {
2627
- type: "media-input",
2628
- isObjectFitEditable: false,
2629
- minWidth: 48,
2630
- defaultWidth: 108,
2631
- maxWidth: 108
2632
- },
2633
- properties: {
2634
- url: {
2635
- type: "string"
2636
- },
2637
- name: {
2638
- type: "string"
2639
- },
2640
- objectFit: {
2641
- type: "string",
2642
- enum: ["cover", "contain"]
2643
- }
2644
- },
2645
- required: ["url", "name"]
2646
- },
2647
- link: {
2648
- type: "string",
2649
- display: {
2650
- type: "text-input",
2651
- placeholder: "Enter link...",
2652
- minWidth: 100,
2653
- defaultWidth: 300,
2654
- maxWidth: 500
2655
- }
2656
- }
2657
- },
2658
- required: ["image"]
2659
- },
2660
- default: [
2661
- {
2662
- image: {
2663
- objectFit: "cover",
2664
- url: "https://cdn.cntrl.site/projects/01JJKT02AWY2FGN2QJ7A173RNZ/articles-assets/01K7ERQK9211QXBE9W284ZNKB8.png",
2665
- name: "Slider-1.png"
2666
- },
2667
- link: ""
2668
- },
2669
- {
2670
- image: {
2671
- objectFit: "cover",
2672
- url: "https://cdn.cntrl.site/projects/01JJKT02AWY2FGN2QJ7A173RNZ/articles-assets/01K7ERQMFT72JD18WKP0Q2DVAT.png",
2673
- name: "Slider-2.png"
2674
- },
2675
- link: ""
2676
- },
2677
- {
2678
- image: {
2679
- objectFit: "cover",
2680
- url: "https://cdn.cntrl.site/projects/01JJKT02AWY2FGN2QJ7A173RNZ/articles-assets/01K7ERQNEVRXPSRX5K1YTMJQY9.png",
2681
- name: "Slider-3.png"
2682
- },
2683
- link: ""
2684
- },
2685
- {
2686
- image: {
2687
- objectFit: "cover",
2688
- url: "https://cdn.cntrl.site/projects/01JJKT02AWY2FGN2QJ7A173RNZ/articles-assets/01K7ERQP84JKRDT7WNWDQZR4Y9.png",
2689
- name: "Slider-4.png"
2690
- },
2691
- link: ""
2692
- }
2693
- ]
2694
- }
2695
- }
2696
- }
2697
- };
2698
- const components = [
2699
- ControlSliderComponent,
2700
- ControlImageRevealSliderComponent
2701
- ];
2702
- export {
2703
- AnchorSide,
2704
- AreaAnchor,
2705
- ArticleItemType,
2706
- Client as CntrlClient,
2707
- DimensionMode,
2708
- FontFaceGenerator,
2709
- KeyframeType,
2710
- PositionType,
2711
- ScrollPlaybackVideoManager,
2712
- SectionHeightMode,
2713
- TextAlign,
2714
- TextDecoration,
2715
- TextTransform,
2716
- VerticalAlign,
2717
- components,
2718
- getLayoutMediaQuery,
2719
- getLayoutStyles
2720
- };