@webstudio-is/react-sdk 0.7.2 → 0.8.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.
- package/lib/arg-types/utils.js +3 -8
- package/lib/cjs/arg-types/utils.cjs +88 -0
- package/lib/cjs/arg-types/utils.d.ts +10 -0
- package/lib/cjs/arg-types/utils.d.ts.map +1 -0
- package/lib/cjs/components/body.cjs +8 -0
- package/lib/cjs/components/body.d.ts +3 -0
- package/lib/cjs/components/body.d.ts.map +1 -0
- package/lib/cjs/components/body.props.json +491 -0
- package/lib/cjs/components/body.stories.cjs +11 -0
- package/lib/cjs/components/body.stories.d.ts +7 -0
- package/lib/cjs/components/body.stories.d.ts.map +1 -0
- package/lib/cjs/components/body.ws.cjs +64 -0
- package/lib/cjs/components/body.ws.d.ts +5 -0
- package/lib/cjs/components/body.ws.d.ts.map +1 -0
- package/lib/cjs/components/bold.cjs +8 -0
- package/lib/cjs/components/bold.d.ts +3 -0
- package/lib/cjs/components/bold.d.ts.map +1 -0
- package/lib/cjs/components/bold.props.json +491 -0
- package/lib/cjs/components/bold.stories.cjs +14 -0
- package/lib/cjs/components/bold.stories.d.ts +6 -0
- package/lib/cjs/components/bold.stories.d.ts.map +1 -0
- package/lib/cjs/components/bold.ws.cjs +14 -0
- package/lib/cjs/components/bold.ws.d.ts +5 -0
- package/lib/cjs/components/bold.ws.d.ts.map +1 -0
- package/lib/cjs/components/box.cjs +9 -0
- package/lib/cjs/components/box.d.ts +8 -0
- package/lib/cjs/components/box.d.ts.map +1 -0
- package/lib/cjs/components/box.props.json +508 -0
- package/lib/cjs/components/box.stories.cjs +12 -0
- package/lib/cjs/components/box.stories.d.ts +10 -0
- package/lib/cjs/components/box.stories.d.ts.map +1 -0
- package/lib/cjs/components/box.ws.cjs +21 -0
- package/lib/cjs/components/box.ws.d.ts +5 -0
- package/lib/cjs/components/box.ws.d.ts.map +1 -0
- package/lib/cjs/components/button.cjs +11 -0
- package/lib/cjs/components/button.d.ts +3 -0
- package/lib/cjs/components/button.d.ts.map +1 -0
- package/lib/cjs/components/button.props.json +547 -0
- package/lib/cjs/components/button.stories.cjs +14 -0
- package/lib/cjs/components/button.stories.d.ts +6 -0
- package/lib/cjs/components/button.stories.d.ts.map +1 -0
- package/lib/cjs/components/button.ws.cjs +15 -0
- package/lib/cjs/components/button.ws.d.ts +5 -0
- package/lib/cjs/components/button.ws.d.ts.map +1 -0
- package/lib/cjs/components/component-type.cjs +28 -0
- package/lib/cjs/components/component-type.d.ts +17 -0
- package/lib/cjs/components/component-type.d.ts.map +1 -0
- package/lib/cjs/components/form.cjs +8 -0
- package/lib/cjs/components/form.d.ts +3 -0
- package/lib/cjs/components/form.d.ts.map +1 -0
- package/lib/cjs/components/form.props.json +531 -0
- package/lib/cjs/components/form.stories.cjs +12 -0
- package/lib/cjs/components/form.stories.d.ts +6 -0
- package/lib/cjs/components/form.stories.d.ts.map +1 -0
- package/lib/cjs/components/form.ws.cjs +26 -0
- package/lib/cjs/components/form.ws.d.ts +5 -0
- package/lib/cjs/components/form.ws.d.ts.map +1 -0
- package/lib/cjs/components/heading.cjs +9 -0
- package/lib/cjs/components/heading.d.ts +8 -0
- package/lib/cjs/components/heading.d.ts.map +1 -0
- package/lib/cjs/components/heading.props.json +497 -0
- package/lib/cjs/components/heading.stories.cjs +14 -0
- package/lib/cjs/components/heading.stories.d.ts +10 -0
- package/lib/cjs/components/heading.stories.d.ts.map +1 -0
- package/lib/cjs/components/heading.ws.cjs +15 -0
- package/lib/cjs/components/heading.ws.d.ts +5 -0
- package/lib/cjs/components/heading.ws.d.ts.map +1 -0
- package/lib/cjs/components/image.cjs +40 -0
- package/lib/cjs/components/image.d.ts +3 -0
- package/lib/cjs/components/image.d.ts.map +1 -0
- package/lib/cjs/components/image.props.json +575 -0
- package/lib/cjs/components/image.stories.cjs +12 -0
- package/lib/cjs/components/image.stories.d.ts +6 -0
- package/lib/cjs/components/image.stories.d.ts.map +1 -0
- package/lib/cjs/components/image.ws.cjs +29 -0
- package/lib/cjs/components/image.ws.d.ts +5 -0
- package/lib/cjs/components/image.ws.d.ts.map +1 -0
- package/lib/cjs/components/index.cjs +36 -0
- package/lib/cjs/components/index.d.ts +16 -0
- package/lib/cjs/components/index.d.ts.map +1 -0
- package/lib/cjs/components/index.test.cjs +33 -0
- package/lib/cjs/components/index.test.d.ts +2 -0
- package/lib/cjs/components/index.test.d.ts.map +1 -0
- package/lib/cjs/components/input.cjs +8 -0
- package/lib/cjs/components/input.d.ts +3 -0
- package/lib/cjs/components/input.d.ts.map +1 -0
- package/lib/cjs/components/input.props.json +657 -0
- package/lib/cjs/components/input.stories.cjs +12 -0
- package/lib/cjs/components/input.stories.d.ts +6 -0
- package/lib/cjs/components/input.stories.d.ts.map +1 -0
- package/lib/cjs/components/input.ws.cjs +14 -0
- package/lib/cjs/components/input.ws.d.ts +5 -0
- package/lib/cjs/components/input.ws.d.ts.map +1 -0
- package/lib/cjs/components/italic.cjs +8 -0
- package/lib/cjs/components/italic.d.ts +3 -0
- package/lib/cjs/components/italic.d.ts.map +1 -0
- package/lib/cjs/components/italic.props.json +491 -0
- package/lib/cjs/components/italic.stories.cjs +14 -0
- package/lib/cjs/components/italic.stories.d.ts +6 -0
- package/lib/cjs/components/italic.stories.d.ts.map +1 -0
- package/lib/cjs/components/italic.ws.cjs +21 -0
- package/lib/cjs/components/italic.ws.d.ts +5 -0
- package/lib/cjs/components/italic.ws.d.ts.map +1 -0
- package/lib/cjs/components/link.cjs +8 -0
- package/lib/cjs/components/link.d.ts +8 -0
- package/lib/cjs/components/link.d.ts.map +1 -0
- package/lib/cjs/components/link.props.json +547 -0
- package/lib/cjs/components/link.stories.cjs +14 -0
- package/lib/cjs/components/link.stories.d.ts +10 -0
- package/lib/cjs/components/link.stories.d.ts.map +1 -0
- package/lib/cjs/components/link.ws.cjs +27 -0
- package/lib/cjs/components/link.ws.d.ts +5 -0
- package/lib/cjs/components/link.ws.d.ts.map +1 -0
- package/lib/cjs/components/meta.cjs +40 -0
- package/lib/cjs/components/meta.d.ts +7479 -0
- package/lib/cjs/components/meta.d.ts.map +1 -0
- package/lib/cjs/components/paragraph.cjs +8 -0
- package/lib/cjs/components/paragraph.d.ts +3 -0
- package/lib/cjs/components/paragraph.d.ts.map +1 -0
- package/lib/cjs/components/paragraph.props.json +491 -0
- package/lib/cjs/components/paragraph.stories.cjs +14 -0
- package/lib/cjs/components/paragraph.stories.d.ts +6 -0
- package/lib/cjs/components/paragraph.stories.d.ts.map +1 -0
- package/lib/cjs/components/paragraph.ws.cjs +15 -0
- package/lib/cjs/components/paragraph.ws.d.ts +5 -0
- package/lib/cjs/components/paragraph.ws.d.ts.map +1 -0
- package/lib/cjs/components/span.cjs +8 -0
- package/lib/cjs/components/span.d.ts +3 -0
- package/lib/cjs/components/span.d.ts.map +1 -0
- package/lib/cjs/components/span.props.json +491 -0
- package/lib/cjs/components/span.stories.cjs +14 -0
- package/lib/cjs/components/span.stories.d.ts +6 -0
- package/lib/cjs/components/span.stories.d.ts.map +1 -0
- package/lib/cjs/components/span.ws.cjs +14 -0
- package/lib/cjs/components/span.ws.d.ts +5 -0
- package/lib/cjs/components/span.ws.d.ts.map +1 -0
- package/lib/cjs/components/subscript.cjs +8 -0
- package/lib/cjs/components/subscript.d.ts +3 -0
- package/lib/cjs/components/subscript.d.ts.map +1 -0
- package/lib/cjs/components/subscript.props.json +491 -0
- package/lib/cjs/components/subscript.stories.cjs +14 -0
- package/lib/cjs/components/subscript.stories.d.ts +6 -0
- package/lib/cjs/components/subscript.stories.d.ts.map +1 -0
- package/lib/cjs/components/subscript.ws.cjs +14 -0
- package/lib/cjs/components/subscript.ws.d.ts +5 -0
- package/lib/cjs/components/subscript.ws.d.ts.map +1 -0
- package/lib/cjs/components/superscript.cjs +8 -0
- package/lib/cjs/components/superscript.d.ts +3 -0
- package/lib/cjs/components/superscript.d.ts.map +1 -0
- package/lib/cjs/components/superscript.props.json +491 -0
- package/lib/cjs/components/superscript.stories.cjs +14 -0
- package/lib/cjs/components/superscript.stories.d.ts +6 -0
- package/lib/cjs/components/superscript.stories.d.ts.map +1 -0
- package/lib/cjs/components/superscript.ws.cjs +14 -0
- package/lib/cjs/components/superscript.ws.d.ts +5 -0
- package/lib/cjs/components/superscript.ws.d.ts.map +1 -0
- package/lib/cjs/components/text-block.cjs +8 -0
- package/lib/cjs/components/text-block.d.ts +3 -0
- package/lib/cjs/components/text-block.d.ts.map +1 -0
- package/lib/cjs/components/text-block.props.json +491 -0
- package/lib/cjs/components/text-block.stories.cjs +14 -0
- package/lib/cjs/components/text-block.stories.d.ts +6 -0
- package/lib/cjs/components/text-block.stories.d.ts.map +1 -0
- package/lib/cjs/components/text-block.ws.cjs +23 -0
- package/lib/cjs/components/text-block.ws.d.ts +5 -0
- package/lib/cjs/components/text-block.ws.d.ts.map +1 -0
- package/lib/cjs/css/breakpoints.cjs +9 -0
- package/lib/cjs/css/breakpoints.d.ts +4 -0
- package/lib/cjs/css/breakpoints.d.ts.map +1 -0
- package/lib/cjs/css/categories.cjs +229 -0
- package/lib/cjs/css/categories.d.ts +408 -0
- package/lib/cjs/css/categories.d.ts.map +1 -0
- package/lib/cjs/css/get-browser-style.cjs +48 -0
- package/lib/cjs/css/get-browser-style.d.ts +3 -0
- package/lib/cjs/css/get-browser-style.d.ts.map +1 -0
- package/lib/cjs/css/index.cjs +19 -0
- package/lib/cjs/css/index.d.ts +4 -0
- package/lib/cjs/css/index.d.ts.map +1 -0
- package/lib/cjs/db/index.cjs +18 -0
- package/lib/cjs/db/index.d.ts +3 -0
- package/lib/cjs/db/index.d.ts.map +1 -0
- package/lib/cjs/db/instance.cjs +21 -0
- package/lib/cjs/db/instance.d.ts +14 -0
- package/lib/cjs/db/instance.d.ts.map +1 -0
- package/lib/cjs/db/types.cjs +2 -0
- package/lib/cjs/db/types.d.ts +17 -0
- package/lib/cjs/db/types.d.ts.map +1 -0
- package/lib/cjs/index.cjs +37 -0
- package/lib/cjs/index.d.ts +9 -0
- package/lib/cjs/index.d.ts.map +1 -0
- package/lib/cjs/pubsub/create.cjs +66 -0
- package/lib/cjs/pubsub/create.d.ts +29 -0
- package/lib/cjs/pubsub/create.d.ts.map +1 -0
- package/lib/cjs/pubsub/index.cjs +17 -0
- package/lib/cjs/pubsub/index.d.ts +2 -0
- package/lib/cjs/pubsub/index.d.ts.map +1 -0
- package/lib/cjs/remix/handle-request.server.cjs +15 -0
- package/lib/cjs/remix/handle-request.server.d.ts +3 -0
- package/lib/cjs/remix/handle-request.server.d.ts.map +1 -0
- package/lib/cjs/remix/index.cjs +18 -0
- package/lib/cjs/remix/index.d.ts +3 -0
- package/lib/cjs/remix/index.d.ts.map +1 -0
- package/lib/cjs/remix/root.cjs +13 -0
- package/lib/cjs/remix/root.d.ts +8 -0
- package/lib/cjs/remix/root.d.ts.map +1 -0
- package/lib/cjs/tree/create-elements-tree.cjs +54 -0
- package/lib/cjs/tree/create-elements-tree.d.ts +19 -0
- package/lib/cjs/tree/create-elements-tree.d.ts.map +1 -0
- package/lib/cjs/tree/index.cjs +19 -0
- package/lib/cjs/tree/index.d.ts +4 -0
- package/lib/cjs/tree/index.d.ts.map +1 -0
- package/lib/cjs/tree/root.cjs +17 -0
- package/lib/cjs/tree/root.d.ts +18 -0
- package/lib/cjs/tree/root.d.ts.map +1 -0
- package/lib/cjs/tree/session-storage-polyfill.cjs +39 -0
- package/lib/cjs/tree/session-storage-polyfill.d.ts +2 -0
- package/lib/cjs/tree/session-storage-polyfill.d.ts.map +1 -0
- package/lib/cjs/tree/wrapper-component.cjs +53 -0
- package/lib/cjs/tree/wrapper-component.d.ts +12 -0
- package/lib/cjs/tree/wrapper-component.d.ts.map +1 -0
- package/lib/cjs/user-props/all-user-props.cjs +21 -0
- package/lib/cjs/user-props/all-user-props.d.ts +8 -0
- package/lib/cjs/user-props/all-user-props.d.ts.map +1 -0
- package/lib/cjs/user-props/index.cjs +20 -0
- package/lib/cjs/user-props/index.d.ts +5 -0
- package/lib/cjs/user-props/index.d.ts.map +1 -0
- package/lib/cjs/user-props/schema.cjs +33 -0
- package/lib/cjs/user-props/schema.d.ts +72 -0
- package/lib/cjs/user-props/schema.d.ts.map +1 -0
- package/lib/cjs/user-props/types.cjs +2 -0
- package/lib/cjs/user-props/types.d.ts +13 -0
- package/lib/cjs/user-props/types.d.ts.map +1 -0
- package/lib/cjs/user-props/use-user-props.cjs +33 -0
- package/lib/cjs/user-props/use-user-props.d.ts +12 -0
- package/lib/cjs/user-props/use-user-props.d.ts.map +1 -0
- package/lib/components/body.js +4 -7
- package/lib/components/body.stories.js +5 -9
- package/lib/components/body.ws.js +5 -7
- package/lib/components/bold.js +4 -7
- package/lib/components/bold.stories.js +7 -10
- package/lib/components/bold.ws.js +5 -7
- package/lib/components/box.js +4 -7
- package/lib/components/box.stories.js +7 -10
- package/lib/components/box.ws.js +5 -7
- package/lib/components/button.js +5 -8
- package/lib/components/button.stories.js +7 -10
- package/lib/components/button.ws.js +5 -7
- package/lib/components/component-type.js +11 -14
- package/lib/components/form.js +4 -7
- package/lib/components/form.stories.js +7 -10
- package/lib/components/form.ws.js +5 -7
- package/lib/components/heading.js +4 -7
- package/lib/components/heading.stories.js +7 -10
- package/lib/components/heading.ws.js +5 -7
- package/lib/components/image.d.ts +2 -10
- package/lib/components/image.d.ts.map +1 -1
- package/lib/components/image.js +6 -21
- package/lib/components/image.stories.d.ts +2 -10
- package/lib/components/image.stories.d.ts.map +1 -1
- package/lib/components/image.stories.js +7 -10
- package/lib/components/image.ws.js +5 -7
- package/lib/components/index.js +15 -36
- package/lib/components/index.test.js +3 -28
- package/lib/components/input.js +4 -7
- package/lib/components/input.stories.js +7 -10
- package/lib/components/input.ws.js +5 -7
- package/lib/components/italic.js +4 -7
- package/lib/components/italic.stories.js +7 -10
- package/lib/components/italic.ws.d.ts.map +1 -1
- package/lib/components/italic.ws.js +12 -7
- package/lib/components/link.js +4 -7
- package/lib/components/link.stories.js +7 -10
- package/lib/components/link.ws.js +5 -7
- package/lib/components/meta.d.ts +13 -4
- package/lib/components/meta.d.ts.map +1 -1
- package/lib/components/meta.js +32 -37
- package/lib/components/paragraph.js +4 -7
- package/lib/components/paragraph.stories.js +7 -10
- package/lib/components/paragraph.ws.js +5 -7
- package/lib/components/span.js +4 -7
- package/lib/components/span.stories.js +7 -10
- package/lib/components/span.ws.js +5 -7
- package/lib/components/subscript.js +4 -7
- package/lib/components/subscript.stories.js +7 -10
- package/lib/components/subscript.ws.js +5 -7
- package/lib/components/superscript.js +4 -7
- package/lib/components/superscript.stories.js +7 -10
- package/lib/components/superscript.ws.js +5 -7
- package/lib/components/text-block.js +4 -7
- package/lib/components/text-block.stories.js +7 -10
- package/lib/components/text-block.ws.js +5 -7
- package/lib/css/breakpoints.js +1 -4
- package/lib/css/categories.js +5 -8
- package/lib/css/get-browser-style.js +7 -11
- package/lib/css/index.js +3 -19
- package/lib/db/index.js +2 -18
- package/lib/db/instance.js +8 -12
- package/lib/db/types.d.ts +6 -0
- package/lib/db/types.d.ts.map +1 -1
- package/lib/db/types.js +1 -2
- package/lib/index.js +8 -37
- package/lib/pubsub/create.js +8 -15
- package/lib/pubsub/index.js +1 -17
- package/lib/remix/handle-request.server.js +5 -9
- package/lib/remix/index.js +2 -18
- package/lib/remix/root.js +5 -9
- package/lib/tree/create-elements-tree.js +7 -11
- package/lib/tree/index.js +3 -19
- package/lib/tree/root.js +7 -11
- package/lib/tree/session-storage-polyfill.js +2 -6
- package/lib/tree/wrapper-component.js +11 -39
- package/lib/tsconfig.tsbuildinfo +1 -0
- package/lib/user-props/all-user-props.js +7 -11
- package/lib/user-props/index.js +4 -20
- package/lib/user-props/schema.d.ts +41 -4
- package/lib/user-props/schema.d.ts.map +1 -1
- package/lib/user-props/schema.js +29 -10
- package/lib/user-props/types.js +1 -2
- package/lib/user-props/use-user-props.d.ts.map +1 -1
- package/lib/user-props/use-user-props.js +7 -11
- package/package.json +16 -10
- package/lib/component-utils/image.d.ts +0 -107
- package/lib/component-utils/image.d.ts.map +0 -1
- package/lib/component-utils/image.js +0 -198
- package/lib/component-utils/image.test.d.ts +0 -2
- package/lib/component-utils/image.test.d.ts.map +0 -1
- package/lib/component-utils/image.test.js +0 -132
- package/lib/components/image-dev.stories.d.ts +0 -36
- package/lib/components/image-dev.stories.d.ts.map +0 -1
- package/lib/components/image-dev.stories.js +0 -102
|
@@ -1,35 +1,72 @@
|
|
|
1
1
|
import { z } from "zod";
|
|
2
|
-
|
|
2
|
+
import type { Asset } from "@webstudio-is/asset-uploader";
|
|
3
|
+
export declare const UserDbProps: z.ZodArray<z.ZodObject<{
|
|
3
4
|
id: z.ZodString;
|
|
4
5
|
prop: z.ZodString;
|
|
5
6
|
value: z.ZodUnion<[z.ZodString, z.ZodBoolean]>;
|
|
7
|
+
assetId: z.ZodOptional<z.ZodString>;
|
|
6
8
|
required: z.ZodOptional<z.ZodBoolean>;
|
|
7
9
|
}, "strip", z.ZodTypeAny, {
|
|
10
|
+
assetId?: string | undefined;
|
|
8
11
|
required?: boolean | undefined;
|
|
9
12
|
value: string | boolean;
|
|
10
13
|
id: string;
|
|
11
14
|
prop: string;
|
|
12
15
|
}, {
|
|
16
|
+
assetId?: string | undefined;
|
|
13
17
|
required?: boolean | undefined;
|
|
14
18
|
value: string | boolean;
|
|
15
19
|
id: string;
|
|
16
20
|
prop: string;
|
|
17
|
-
}>;
|
|
18
|
-
export declare
|
|
19
|
-
export declare const UserProps: z.ZodArray<z.ZodObject<{
|
|
21
|
+
}>, "many">;
|
|
22
|
+
export declare const UserUserProps: z.ZodArray<z.ZodEffects<z.ZodObject<{
|
|
20
23
|
id: z.ZodString;
|
|
21
24
|
prop: z.ZodString;
|
|
22
25
|
value: z.ZodUnion<[z.ZodString, z.ZodBoolean]>;
|
|
26
|
+
asset: z.ZodOptional<z.ZodObject<{
|
|
27
|
+
id: z.ZodString;
|
|
28
|
+
}, "strip", z.ZodTypeAny, {
|
|
29
|
+
id: string;
|
|
30
|
+
}, {
|
|
31
|
+
id: string;
|
|
32
|
+
}>>;
|
|
23
33
|
required: z.ZodOptional<z.ZodBoolean>;
|
|
24
34
|
}, "strip", z.ZodTypeAny, {
|
|
35
|
+
required?: boolean | undefined;
|
|
36
|
+
asset?: {
|
|
37
|
+
id: string;
|
|
38
|
+
} | undefined;
|
|
39
|
+
value: string | boolean;
|
|
40
|
+
id: string;
|
|
41
|
+
prop: string;
|
|
42
|
+
}, {
|
|
43
|
+
required?: boolean | undefined;
|
|
44
|
+
asset?: {
|
|
45
|
+
id: string;
|
|
46
|
+
} | undefined;
|
|
47
|
+
value: string | boolean;
|
|
48
|
+
id: string;
|
|
49
|
+
prop: string;
|
|
50
|
+
}>, {
|
|
51
|
+
assetId?: string | undefined;
|
|
25
52
|
required?: boolean | undefined;
|
|
26
53
|
value: string | boolean;
|
|
27
54
|
id: string;
|
|
28
55
|
prop: string;
|
|
29
56
|
}, {
|
|
30
57
|
required?: boolean | undefined;
|
|
58
|
+
asset?: {
|
|
59
|
+
id: string;
|
|
60
|
+
} | undefined;
|
|
31
61
|
value: string | boolean;
|
|
32
62
|
id: string;
|
|
33
63
|
prop: string;
|
|
34
64
|
}>, "many">;
|
|
65
|
+
export declare type UserProp = {
|
|
66
|
+
id: string;
|
|
67
|
+
prop: string;
|
|
68
|
+
value: string | boolean;
|
|
69
|
+
asset?: Asset;
|
|
70
|
+
required?: boolean | undefined;
|
|
71
|
+
};
|
|
35
72
|
//# sourceMappingURL=schema.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"schema.d.ts","sourceRoot":"","sources":["../../src/user-props/schema.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;
|
|
1
|
+
{"version":3,"file":"schema.d.ts","sourceRoot":"","sources":["../../src/user-props/schema.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AACxB,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,8BAA8B,CAAC;AAU1D,eAAO,MAAM,WAAW;;;;;;;;;;;;;;;;;;WAAsB,CAAC;AAuB/C,eAAO,MAAM,aAAa;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;WAAwB,CAAC;AAEnD,oBAAY,QAAQ,GAAG;IACrB,EAAE,EAAE,MAAM,CAAC;IACX,IAAI,EAAE,MAAM,CAAC;IACb,KAAK,EAAE,MAAM,GAAG,OAAO,CAAC;IACxB,KAAK,CAAC,EAAE,KAAK,CAAC;IACd,QAAQ,CAAC,EAAE,OAAO,GAAG,SAAS,CAAC;CAChC,CAAC"}
|
package/lib/user-props/schema.js
CHANGED
|
@@ -1,11 +1,30 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
value: zod_1.z.union([zod_1.z.string(), zod_1.z.boolean()]),
|
|
9
|
-
required: zod_1.z.optional(zod_1.z.boolean()),
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
const UserPropDb = z.object({
|
|
3
|
+
id: z.string(),
|
|
4
|
+
prop: z.string(),
|
|
5
|
+
value: z.union([z.string(), z.boolean()]),
|
|
6
|
+
assetId: z.optional(z.string()),
|
|
7
|
+
required: z.optional(z.boolean()),
|
|
10
8
|
});
|
|
11
|
-
|
|
9
|
+
export const UserDbProps = z.array(UserPropDb);
|
|
10
|
+
const UserUserProp = z
|
|
11
|
+
.object({
|
|
12
|
+
id: z.string(),
|
|
13
|
+
prop: z.string(),
|
|
14
|
+
value: z.union([z.string(), z.boolean()]),
|
|
15
|
+
// We are not interested in Props data does any other props on asset exists
|
|
16
|
+
asset: z.optional(z.object({ id: z.string() })),
|
|
17
|
+
required: z.optional(z.boolean()),
|
|
18
|
+
})
|
|
19
|
+
.transform(({ id, prop, value, asset, required }) => {
|
|
20
|
+
// Check with infer that we are transforming to UserPropDb
|
|
21
|
+
const res = {
|
|
22
|
+
id,
|
|
23
|
+
prop,
|
|
24
|
+
value,
|
|
25
|
+
assetId: asset?.id,
|
|
26
|
+
required,
|
|
27
|
+
};
|
|
28
|
+
return res;
|
|
29
|
+
});
|
|
30
|
+
export const UserUserProps = z.array(UserUserProp);
|
package/lib/user-props/types.js
CHANGED
|
@@ -1,2 +1 @@
|
|
|
1
|
-
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
1
|
+
export {};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"use-user-props.d.ts","sourceRoot":"","sources":["../../src/user-props/use-user-props.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,KAAK,QAAQ,EAAE,MAAM,OAAO,CAAC;AACtC,OAAO,EAAE,KAAK,QAAQ,EAAE,MAAM,UAAU,CAAC;AAGzC,aAAK,SAAS,GAAG;IAAE,CAAC,IAAI,EAAE,QAAQ,CAAC,MAAM,CAAC,GAAG,QAAQ,CAAC,OAAO,CAAC,CAAA;CAAE,CAAC;AAEjE;;;GAGG;AACH,eAAO,MAAM,YAAY,eAAgB,QAAQ,CAAC,IAAI,CAAC,
|
|
1
|
+
{"version":3,"file":"use-user-props.d.ts","sourceRoot":"","sources":["../../src/user-props/use-user-props.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,KAAK,QAAQ,EAAE,MAAM,OAAO,CAAC;AACtC,OAAO,EAAE,KAAK,QAAQ,EAAE,MAAM,UAAU,CAAC;AAGzC,aAAK,SAAS,GAAG;IAAE,CAAC,IAAI,EAAE,QAAQ,CAAC,MAAM,CAAC,GAAG,QAAQ,CAAC,OAAO,CAAC,CAAA;CAAE,CAAC;AAEjE;;;GAGG;AACH,eAAO,MAAM,YAAY,eAAgB,QAAQ,CAAC,IAAI,CAAC,cAwBtD,CAAC"}
|
|
@@ -1,16 +1,13 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
exports.useUserProps = void 0;
|
|
4
|
-
const react_1 = require("react");
|
|
5
|
-
const all_user_props_1 = require("./all-user-props");
|
|
1
|
+
import { useEffect, useMemo, useState } from "react";
|
|
2
|
+
import { useAllUserProps } from "./all-user-props";
|
|
6
3
|
/**
|
|
7
4
|
* User props mapped in prop:value format,
|
|
8
5
|
* up to date with props panel.
|
|
9
6
|
*/
|
|
10
|
-
const useUserProps = (instanceId) => {
|
|
11
|
-
const [allUserProps] =
|
|
7
|
+
export const useUserProps = (instanceId) => {
|
|
8
|
+
const [allUserProps] = useAllUserProps();
|
|
12
9
|
const propsData = allUserProps[instanceId];
|
|
13
|
-
const initialUserProps =
|
|
10
|
+
const initialUserProps = useMemo(() => {
|
|
14
11
|
if (propsData === undefined)
|
|
15
12
|
return {};
|
|
16
13
|
return propsData.props.reduce((props, { prop, value }) => {
|
|
@@ -18,8 +15,8 @@ const useUserProps = (instanceId) => {
|
|
|
18
15
|
return props;
|
|
19
16
|
}, {});
|
|
20
17
|
}, [propsData]);
|
|
21
|
-
const [props, setProps] =
|
|
22
|
-
|
|
18
|
+
const [props, setProps] = useState(initialUserProps);
|
|
19
|
+
useEffect(() => {
|
|
23
20
|
if (propsData == undefined)
|
|
24
21
|
return;
|
|
25
22
|
const nextProps = {};
|
|
@@ -30,4 +27,3 @@ const useUserProps = (instanceId) => {
|
|
|
30
27
|
}, [propsData]);
|
|
31
28
|
return props;
|
|
32
29
|
};
|
|
33
|
-
exports.useUserProps = useUserProps;
|
package/package.json
CHANGED
|
@@ -1,28 +1,30 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@webstudio-is/react-sdk",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.8.0",
|
|
4
4
|
"description": "Webstudio JavaScript / TypeScript API",
|
|
5
5
|
"author": "Webstudio <github@webstudio.is>",
|
|
6
6
|
"homepage": "https://webstudio.is",
|
|
7
|
+
"type": "module",
|
|
7
8
|
"scripts": {
|
|
8
9
|
"dev": "tsup --watch",
|
|
9
10
|
"build": "yarn build:lib",
|
|
10
11
|
"build:args": "tsx ./bin/generate-arg-types.ts './src/components/*.tsx !./src/**/*.stories.tsx !./src/**/*.ws.tsx'",
|
|
11
12
|
"typecheck": "tsc --noEmit",
|
|
12
|
-
"build:
|
|
13
|
-
"
|
|
13
|
+
"build:cjs": "tsc --module commonjs --outDir lib/cjs && find lib/cjs -name '*.js' | while read NAME; do mv $NAME ${NAME%.js}.cjs; done",
|
|
14
|
+
"build:lib": "rm -fr lib tsconfig.tsbuildinfo && tsc && yarn build:cjs",
|
|
15
|
+
"test": "NODE_OPTIONS=--experimental-vm-modules jest",
|
|
14
16
|
"lint": "eslint ./src --ext .ts,.tsx --max-warnings 0",
|
|
15
17
|
"checks": "yarn typecheck && yarn lint && yarn test",
|
|
16
18
|
"prepublishOnly": "yarn checks && yarn build:lib",
|
|
17
19
|
"storybook:run": "start-storybook -p 6006",
|
|
18
|
-
"storybook:build": "build-storybook"
|
|
20
|
+
"storybook:build": "build-storybook",
|
|
21
|
+
"publish-to-npm": "bash ../../bin/publish-to-npm.sh"
|
|
19
22
|
},
|
|
20
23
|
"devDependencies": {
|
|
21
|
-
"@babel/core": "^7.
|
|
24
|
+
"@babel/core": "^7.20.2",
|
|
22
25
|
"@esbuild-kit/esm-loader": "^2.4.2",
|
|
23
26
|
"@remix-run/react": "^1.2.3",
|
|
24
27
|
"@remix-run/server-runtime": "^1.2.3",
|
|
25
|
-
"remix-utils": "^4.1.0",
|
|
26
28
|
"@storybook/addon-actions": "^6.5.6",
|
|
27
29
|
"@storybook/addon-essentials": "^6.5.6",
|
|
28
30
|
"@storybook/addon-interactions": "^6.5.6",
|
|
@@ -41,6 +43,7 @@
|
|
|
41
43
|
"react": "^17.0.2",
|
|
42
44
|
"react-docgen-typescript": "^2.2.2",
|
|
43
45
|
"react-dom": "^17.0.2",
|
|
46
|
+
"remix-utils": "^4.1.0",
|
|
44
47
|
"tsup": "^6.1.3",
|
|
45
48
|
"tsx": "^3.9.0",
|
|
46
49
|
"typescript": "4.7.4",
|
|
@@ -49,25 +52,28 @@
|
|
|
49
52
|
"peerDependencies": {
|
|
50
53
|
"@remix-run/react": "^1.2.3",
|
|
51
54
|
"@remix-run/server-runtime": "^1.2.3",
|
|
52
|
-
"remix-utils": "^4.1.0",
|
|
53
55
|
"@storybook/react": "^6.5.6",
|
|
54
56
|
"react": "^17.0.2",
|
|
55
57
|
"react-dom": "^17.0.2",
|
|
58
|
+
"remix-utils": "^4.1.0",
|
|
56
59
|
"zod": "^3.19.1"
|
|
57
60
|
},
|
|
58
61
|
"dependencies": {
|
|
59
62
|
"detect-font": "^0.1.5",
|
|
60
63
|
"@webstudio-is/asset-uploader": "^*",
|
|
64
|
+
"@webstudio-is/css-data": "*",
|
|
61
65
|
"@webstudio-is/fonts": "*",
|
|
62
66
|
"@webstudio-is/icons": "*",
|
|
63
|
-
"@webstudio-is/css-data": "*",
|
|
64
67
|
"@webstudio-is/jest-config": "*",
|
|
65
68
|
"immer": "^9.0.12",
|
|
66
69
|
"mitt": "^3.0.0",
|
|
67
70
|
"react-nano-state": "^0.4.0",
|
|
68
71
|
"warn-once": "^0.1.1"
|
|
69
72
|
},
|
|
70
|
-
"
|
|
73
|
+
"exports": {
|
|
74
|
+
"import": "./lib/index.js",
|
|
75
|
+
"require": "./lib/cjs/index.cjs"
|
|
76
|
+
},
|
|
71
77
|
"types": "lib/index.d.ts",
|
|
72
78
|
"files": [
|
|
73
79
|
"lib/*",
|
|
@@ -81,7 +87,7 @@
|
|
|
81
87
|
"entry": [
|
|
82
88
|
"src/index.ts"
|
|
83
89
|
],
|
|
84
|
-
"format": "
|
|
90
|
+
"format": "esm",
|
|
85
91
|
"outDir": "lib"
|
|
86
92
|
}
|
|
87
93
|
}
|
|
@@ -1,107 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* # Responsive Image component helpers.
|
|
3
|
-
*
|
|
4
|
-
* ## Quick summary about img srcset and sizes attributes:
|
|
5
|
-
*
|
|
6
|
-
* There are 2 ways to define what image will be loaded in the img property srcset.
|
|
7
|
-
*
|
|
8
|
-
* 1. via pixel density descriptor 'x', like `srcset="photo-small.jpg 1x, photo-medium.jpg 1.5x, photo-huge.jpg 2x"`
|
|
9
|
-
* src will be selected depending on `device-pixel-ratio`.
|
|
10
|
-
*
|
|
11
|
-
* 2. via viewport width descriptor 'w' and sizes property containing source size descriptors, like
|
|
12
|
-
* `srcset="photo-small.jpg 320w, photo-medium.jpg 640w, photo-huge.jpg 1280w"`
|
|
13
|
-
* `sizes="(max-width: 600px) 400px, (max-width: 1200px) 70vw, 50vw"`
|
|
14
|
-
*
|
|
15
|
-
* The browser finds the first matching media query from source size descriptors,
|
|
16
|
-
* then use source size value to generate internally srcset
|
|
17
|
-
* with pixel density descriptors dividing width descriptor value by source size value.
|
|
18
|
-
*
|
|
19
|
-
* Using the example above for viewport width 800px.
|
|
20
|
-
* The first matching media query is (max-width: 1200px)
|
|
21
|
-
* source size value is 70vw equal to 800px * 0,7 = 560px
|
|
22
|
-
*
|
|
23
|
-
* browser internal srcset will be (we divide `w` descriptor by source size value):
|
|
24
|
-
* photo-small.jpg 320/560x, photo-medium.jpg 640/560x, photo-huge.jpg 1280/560x =>
|
|
25
|
-
* photo-small.jpg 0.57x, photo-medium.jpg 1.14x, photo-huge.jpg 2.28x
|
|
26
|
-
*
|
|
27
|
-
* Finally same rules as for pixel density descriptor 'x' are applied.
|
|
28
|
-
*
|
|
29
|
-
* ## Algorithm (without optimizations):
|
|
30
|
-
*
|
|
31
|
-
* We have a predefined array of all supported image sizes allSizes, this is the real width of an image in pixels.
|
|
32
|
-
* This is good for caching, as we can cache image with specific width and then use it for different devices.
|
|
33
|
-
*
|
|
34
|
-
* > allSizes array is a tradeoff between cache and the best possible image size you deliver to the user.
|
|
35
|
-
* > If allSizes.length is too small, you will deliver too big images to the user,
|
|
36
|
-
* > if allSizes.length is too big, you will have many caches misses.
|
|
37
|
-
*
|
|
38
|
-
* If img has a defined width property.
|
|
39
|
-
* 1. find the first value from allSizes which is greater or equal to the width property
|
|
40
|
-
* 2. use found value to generate srcset with pixel density descriptor 'x'
|
|
41
|
-
*
|
|
42
|
-
*
|
|
43
|
-
* If img has no defined width property.
|
|
44
|
-
* 1. Generate srcset = allSizes.map((w) => `${getImageSrcAtWidth(w)} ${w}w`)
|
|
45
|
-
* 2. Use sizes property, or if it is not defined use opinionated DEFAULT_SIZES = "(min-width: 1280px) 50vw, 100vw";
|
|
46
|
-
*
|
|
47
|
-
* Optimizations applied now:
|
|
48
|
-
*
|
|
49
|
-
* - If the sizes property is defined, we can exclude from `srcsets` all images
|
|
50
|
-
* which are smaller than the `smallestRatio * smallesDeviceSize`
|
|
51
|
-
*
|
|
52
|
-
* Future (not implemented) optimizations and improvements:
|
|
53
|
-
*
|
|
54
|
-
* - Knowing image size on different viewport widths we can provide nondefault sizes property
|
|
55
|
-
* - Knowledge of Image aspect-ratio would allow cropping images serverside.
|
|
56
|
-
* - Early hints for high priority images https://blog.cloudflare.com/early-hints/
|
|
57
|
-
* - Slow networks optimizations
|
|
58
|
-
* - 404 etc processing with CSS - https://bitsofco.de/styling-broken-images/ (has some opinionated issues) or js solution with custom user fallback.
|
|
59
|
-
*
|
|
60
|
-
* # Attributions
|
|
61
|
-
*
|
|
62
|
-
* The MIT License (MIT)
|
|
63
|
-
*
|
|
64
|
-
* applies to:
|
|
65
|
-
*
|
|
66
|
-
* - https://github.com/vercel/next.js, Copyright (c) 2022 Vercel, Inc.
|
|
67
|
-
*
|
|
68
|
-
* The MIT License (MIT)
|
|
69
|
-
*
|
|
70
|
-
* Copyright (c) 2022 Vercel, Inc.
|
|
71
|
-
*
|
|
72
|
-
* Permission is hereby granted, free of charge, to any person obtaining a copy of this software
|
|
73
|
-
* and associated documentation files (the "Software"), to deal in the Software without restriction,
|
|
74
|
-
* including without limitation the rights to use, copy, modify, merge, publish, distribute,
|
|
75
|
-
* sublicense, and/or sell copies of the Software, and to permit persons to whom the Software
|
|
76
|
-
* is furnished to do so, subject to the following conditions:
|
|
77
|
-
*
|
|
78
|
-
* The above copyright notice and this permission notice shall be included in all copies
|
|
79
|
-
* or substantial portions of the Software.
|
|
80
|
-
*
|
|
81
|
-
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
|
|
82
|
-
* INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
83
|
-
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
|
84
|
-
* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
|
|
85
|
-
* DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
|
|
86
|
-
* ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
87
|
-
**/
|
|
88
|
-
export declare type ImageLoader = (props: {
|
|
89
|
-
width: number;
|
|
90
|
-
quality: number;
|
|
91
|
-
src: string;
|
|
92
|
-
}) => string;
|
|
93
|
-
export declare const allSizes: number[];
|
|
94
|
-
export declare const getImageAttributes: (props: {
|
|
95
|
-
src: string | undefined;
|
|
96
|
-
srcSet: string | undefined;
|
|
97
|
-
sizes: string | undefined;
|
|
98
|
-
width: string | number | undefined;
|
|
99
|
-
quality: number | undefined;
|
|
100
|
-
loader?: ImageLoader;
|
|
101
|
-
optimize: boolean;
|
|
102
|
-
}) => {
|
|
103
|
-
src: string;
|
|
104
|
-
srcSet: string | undefined;
|
|
105
|
-
sizes: string | undefined;
|
|
106
|
-
} | null;
|
|
107
|
-
//# sourceMappingURL=image.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"image.d.ts","sourceRoot":"","sources":["../../src/component-utils/image.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;IAsFI;AAIJ,oBAAY,WAAW,GAAG,CAAC,KAAK,EAAE;IAChC,KAAK,EAAE,MAAM,CAAC;IACd,OAAO,EAAE,MAAM,CAAC;IAChB,GAAG,EAAE,MAAM,CAAC;CACb,KAAK,MAAM,CAAC;AAQb,eAAO,MAAM,QAAQ,UAAkC,CAAC;AA8HxD,eAAO,MAAM,kBAAkB,UAAW;IACxC,GAAG,EAAE,MAAM,GAAG,SAAS,CAAC;IACxB,MAAM,EAAE,MAAM,GAAG,SAAS,CAAC;IAC3B,KAAK,EAAE,MAAM,GAAG,SAAS,CAAC;IAC1B,KAAK,EAAE,MAAM,GAAG,MAAM,GAAG,SAAS,CAAC;IACnC,OAAO,EAAE,MAAM,GAAG,SAAS,CAAC;IAC5B,MAAM,CAAC,EAAE,WAAW,CAAC;IACrB,QAAQ,EAAE,OAAO,CAAC;CACnB,KAAG;IACF,GAAG,EAAE,MAAM,CAAC;IACZ,MAAM,EAAE,MAAM,GAAG,SAAS,CAAC;IAC3B,KAAK,EAAE,MAAM,GAAG,SAAS,CAAC;CAC3B,GAAG,IA2BH,CAAC"}
|
|
@@ -1,198 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
/**
|
|
3
|
-
* # Responsive Image component helpers.
|
|
4
|
-
*
|
|
5
|
-
* ## Quick summary about img srcset and sizes attributes:
|
|
6
|
-
*
|
|
7
|
-
* There are 2 ways to define what image will be loaded in the img property srcset.
|
|
8
|
-
*
|
|
9
|
-
* 1. via pixel density descriptor 'x', like `srcset="photo-small.jpg 1x, photo-medium.jpg 1.5x, photo-huge.jpg 2x"`
|
|
10
|
-
* src will be selected depending on `device-pixel-ratio`.
|
|
11
|
-
*
|
|
12
|
-
* 2. via viewport width descriptor 'w' and sizes property containing source size descriptors, like
|
|
13
|
-
* `srcset="photo-small.jpg 320w, photo-medium.jpg 640w, photo-huge.jpg 1280w"`
|
|
14
|
-
* `sizes="(max-width: 600px) 400px, (max-width: 1200px) 70vw, 50vw"`
|
|
15
|
-
*
|
|
16
|
-
* The browser finds the first matching media query from source size descriptors,
|
|
17
|
-
* then use source size value to generate internally srcset
|
|
18
|
-
* with pixel density descriptors dividing width descriptor value by source size value.
|
|
19
|
-
*
|
|
20
|
-
* Using the example above for viewport width 800px.
|
|
21
|
-
* The first matching media query is (max-width: 1200px)
|
|
22
|
-
* source size value is 70vw equal to 800px * 0,7 = 560px
|
|
23
|
-
*
|
|
24
|
-
* browser internal srcset will be (we divide `w` descriptor by source size value):
|
|
25
|
-
* photo-small.jpg 320/560x, photo-medium.jpg 640/560x, photo-huge.jpg 1280/560x =>
|
|
26
|
-
* photo-small.jpg 0.57x, photo-medium.jpg 1.14x, photo-huge.jpg 2.28x
|
|
27
|
-
*
|
|
28
|
-
* Finally same rules as for pixel density descriptor 'x' are applied.
|
|
29
|
-
*
|
|
30
|
-
* ## Algorithm (without optimizations):
|
|
31
|
-
*
|
|
32
|
-
* We have a predefined array of all supported image sizes allSizes, this is the real width of an image in pixels.
|
|
33
|
-
* This is good for caching, as we can cache image with specific width and then use it for different devices.
|
|
34
|
-
*
|
|
35
|
-
* > allSizes array is a tradeoff between cache and the best possible image size you deliver to the user.
|
|
36
|
-
* > If allSizes.length is too small, you will deliver too big images to the user,
|
|
37
|
-
* > if allSizes.length is too big, you will have many caches misses.
|
|
38
|
-
*
|
|
39
|
-
* If img has a defined width property.
|
|
40
|
-
* 1. find the first value from allSizes which is greater or equal to the width property
|
|
41
|
-
* 2. use found value to generate srcset with pixel density descriptor 'x'
|
|
42
|
-
*
|
|
43
|
-
*
|
|
44
|
-
* If img has no defined width property.
|
|
45
|
-
* 1. Generate srcset = allSizes.map((w) => `${getImageSrcAtWidth(w)} ${w}w`)
|
|
46
|
-
* 2. Use sizes property, or if it is not defined use opinionated DEFAULT_SIZES = "(min-width: 1280px) 50vw, 100vw";
|
|
47
|
-
*
|
|
48
|
-
* Optimizations applied now:
|
|
49
|
-
*
|
|
50
|
-
* - If the sizes property is defined, we can exclude from `srcsets` all images
|
|
51
|
-
* which are smaller than the `smallestRatio * smallesDeviceSize`
|
|
52
|
-
*
|
|
53
|
-
* Future (not implemented) optimizations and improvements:
|
|
54
|
-
*
|
|
55
|
-
* - Knowing image size on different viewport widths we can provide nondefault sizes property
|
|
56
|
-
* - Knowledge of Image aspect-ratio would allow cropping images serverside.
|
|
57
|
-
* - Early hints for high priority images https://blog.cloudflare.com/early-hints/
|
|
58
|
-
* - Slow networks optimizations
|
|
59
|
-
* - 404 etc processing with CSS - https://bitsofco.de/styling-broken-images/ (has some opinionated issues) or js solution with custom user fallback.
|
|
60
|
-
*
|
|
61
|
-
* # Attributions
|
|
62
|
-
*
|
|
63
|
-
* The MIT License (MIT)
|
|
64
|
-
*
|
|
65
|
-
* applies to:
|
|
66
|
-
*
|
|
67
|
-
* - https://github.com/vercel/next.js, Copyright (c) 2022 Vercel, Inc.
|
|
68
|
-
*
|
|
69
|
-
* The MIT License (MIT)
|
|
70
|
-
*
|
|
71
|
-
* Copyright (c) 2022 Vercel, Inc.
|
|
72
|
-
*
|
|
73
|
-
* Permission is hereby granted, free of charge, to any person obtaining a copy of this software
|
|
74
|
-
* and associated documentation files (the "Software"), to deal in the Software without restriction,
|
|
75
|
-
* including without limitation the rights to use, copy, modify, merge, publish, distribute,
|
|
76
|
-
* sublicense, and/or sell copies of the Software, and to permit persons to whom the Software
|
|
77
|
-
* is furnished to do so, subject to the following conditions:
|
|
78
|
-
*
|
|
79
|
-
* The above copyright notice and this permission notice shall be included in all copies
|
|
80
|
-
* or substantial portions of the Software.
|
|
81
|
-
*
|
|
82
|
-
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
|
|
83
|
-
* INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
84
|
-
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
|
85
|
-
* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
|
|
86
|
-
* DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
|
|
87
|
-
* ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
88
|
-
**/
|
|
89
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
90
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
91
|
-
};
|
|
92
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
93
|
-
exports.getImageAttributes = exports.allSizes = void 0;
|
|
94
|
-
const warn_once_1 = __importDefault(require("warn-once"));
|
|
95
|
-
/**
|
|
96
|
-
* max(...imageSizes) must be less then min(...deviceSizes)
|
|
97
|
-
**/
|
|
98
|
-
const imageSizes = [16, 32, 48, 64, 96, 128, 256, 384];
|
|
99
|
-
const deviceSizes = [640, 750, 828, 1080, 1200, 1920, 2048, 3840];
|
|
100
|
-
exports.allSizes = [...imageSizes, ...deviceSizes];
|
|
101
|
-
/**
|
|
102
|
-
* https://github.com/vercel/next.js/blob/canary/packages/next/client/image.tsx
|
|
103
|
-
**/
|
|
104
|
-
const getWidths = (width, sizes) => {
|
|
105
|
-
if (sizes) {
|
|
106
|
-
// Find all the "vw" percent sizes used in the sizes prop
|
|
107
|
-
const viewportWidthRe = /(^|\s)(1?\d?\d)vw/g;
|
|
108
|
-
const percentSizes = [];
|
|
109
|
-
for (let match; (match = viewportWidthRe.exec(sizes)); match) {
|
|
110
|
-
percentSizes.push(parseInt(match[2], 10));
|
|
111
|
-
}
|
|
112
|
-
if (percentSizes.length) {
|
|
113
|
-
// we can exclude from srcSets all images which are smaller than the smallestRatio * smallesDeviceSize
|
|
114
|
-
const smallestRatio = Math.min(...percentSizes) * 0.01;
|
|
115
|
-
return {
|
|
116
|
-
widths: exports.allSizes.filter((s) => s >= deviceSizes[0] * smallestRatio),
|
|
117
|
-
kind: "w",
|
|
118
|
-
};
|
|
119
|
-
}
|
|
120
|
-
return { widths: exports.allSizes, kind: "w" };
|
|
121
|
-
}
|
|
122
|
-
if (width == null) {
|
|
123
|
-
return { widths: deviceSizes, kind: "w" };
|
|
124
|
-
}
|
|
125
|
-
const widths = [
|
|
126
|
-
...new Set([width, width * 2].map((w) => exports.allSizes.find((p) => p >= w) || exports.allSizes[exports.allSizes.length - 1])),
|
|
127
|
-
];
|
|
128
|
-
return { widths, kind: "x" };
|
|
129
|
-
};
|
|
130
|
-
const generateImgAttrs = ({ src, width, quality, sizes, loader, }) => {
|
|
131
|
-
const { widths, kind } = getWidths(width, sizes);
|
|
132
|
-
return {
|
|
133
|
-
sizes: !sizes && kind === "w" ? "100vw" : sizes,
|
|
134
|
-
srcSet: widths
|
|
135
|
-
.map((w, i) => `${loader({ src, quality, width: w })} ${kind === "w" ? w : i + 1}${kind}`)
|
|
136
|
-
.join(", "),
|
|
137
|
-
// Must be last, to prevent Safari to load images twice
|
|
138
|
-
src: loader({
|
|
139
|
-
src,
|
|
140
|
-
quality,
|
|
141
|
-
width: widths[widths.length - 1],
|
|
142
|
-
}),
|
|
143
|
-
};
|
|
144
|
-
};
|
|
145
|
-
/**
|
|
146
|
-
* Default image loader in case of no loader provided
|
|
147
|
-
* https://developers.cloudflare.com/images/image-resizing/url-format/
|
|
148
|
-
**/
|
|
149
|
-
const cloudflareImageLoader = ({ width, src, quality }) => {
|
|
150
|
-
if (process.env.NODE_ENV !== "production") {
|
|
151
|
-
(0, warn_once_1.default)(!exports.allSizes.includes(width), "Width must be only from allowed values");
|
|
152
|
-
}
|
|
153
|
-
const options = `width=${width},quality=${quality},format=auto`;
|
|
154
|
-
// Cloudflare docs say that we don't need to urlencode the path params
|
|
155
|
-
const pathname = `/cdn-cgi/image/${options}/${src}`;
|
|
156
|
-
return pathname;
|
|
157
|
-
};
|
|
158
|
-
const getInt = (value) => {
|
|
159
|
-
if (typeof value === "number") {
|
|
160
|
-
return Math.round(value);
|
|
161
|
-
}
|
|
162
|
-
if (typeof value === "string") {
|
|
163
|
-
const vNum = Number.parseFloat(value);
|
|
164
|
-
if (!Number.isNaN(vNum)) {
|
|
165
|
-
return Math.round(vNum);
|
|
166
|
-
}
|
|
167
|
-
}
|
|
168
|
-
return undefined;
|
|
169
|
-
};
|
|
170
|
-
/**
|
|
171
|
-
* DEFAULT_SIZES Just an assumption that most images (except hero and icons) are 100% wide on mobile and 50% on desktop.
|
|
172
|
-
* For icons width are usually set explicitly so DEFAULT_SIZES is not applied.
|
|
173
|
-
* For hero images, we can allow in UI to select sizes=100vw explicitly.
|
|
174
|
-
* Anyway, the best would be to calculate this based on canvas data from different breakpoints.
|
|
175
|
-
* See ../component-utils/image for detailed description
|
|
176
|
-
**/
|
|
177
|
-
const DEFAULT_SIZES = "(min-width: 1280px) 50vw, 100vw";
|
|
178
|
-
const DEFAULT_QUALITY = 80;
|
|
179
|
-
const getImageAttributes = (props) => {
|
|
180
|
-
const width = getInt(props.width);
|
|
181
|
-
const quality = Math.max(Math.min(getInt(props.quality) ?? DEFAULT_QUALITY, 100), 0);
|
|
182
|
-
if (props.src != null && props.src != "") {
|
|
183
|
-
if (props.srcSet == null && props.optimize) {
|
|
184
|
-
const sizes = props.sizes ?? (props.width == null ? DEFAULT_SIZES : undefined);
|
|
185
|
-
const loader = props.loader ?? cloudflareImageLoader;
|
|
186
|
-
return generateImgAttrs({
|
|
187
|
-
src: props.src,
|
|
188
|
-
width,
|
|
189
|
-
quality,
|
|
190
|
-
sizes,
|
|
191
|
-
loader,
|
|
192
|
-
});
|
|
193
|
-
}
|
|
194
|
-
return { src: props.src, srcSet: props.srcSet, sizes: props.sizes };
|
|
195
|
-
}
|
|
196
|
-
return null;
|
|
197
|
-
};
|
|
198
|
-
exports.getImageAttributes = getImageAttributes;
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"image.test.d.ts","sourceRoot":"","sources":["../../src/component-utils/image.test.ts"],"names":[],"mappings":""}
|