@pixelfiddler/react 0.1.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/LICENSE +21 -0
- package/README.md +1 -0
- package/dist/index.cjs +61 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +38 -0
- package/dist/index.d.ts +38 -0
- package/dist/index.js +58 -0
- package/dist/index.js.map +1 -0
- package/package.json +76 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 PixelFiddler
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
TBD
|
package/dist/index.cjs
ADDED
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var react = require('react');
|
|
4
|
+
var core = require('@pixelfiddler/core');
|
|
5
|
+
var jsxRuntime = require('react/jsx-runtime');
|
|
6
|
+
|
|
7
|
+
// src/components/pixel-fiddle-image.tsx
|
|
8
|
+
var PixelFiddlerContext = react.createContext(null);
|
|
9
|
+
function PixelFiddlerProvider({ children, config }) {
|
|
10
|
+
return /* @__PURE__ */ jsxRuntime.jsx(PixelFiddlerContext.Provider, { value: { config }, children });
|
|
11
|
+
}
|
|
12
|
+
function PixelFiddleImage({
|
|
13
|
+
src,
|
|
14
|
+
sizes,
|
|
15
|
+
width,
|
|
16
|
+
transformations,
|
|
17
|
+
config: configProp,
|
|
18
|
+
deviceBreakpoints,
|
|
19
|
+
imageBreakpoints,
|
|
20
|
+
responsive = true,
|
|
21
|
+
...imgProps
|
|
22
|
+
}) {
|
|
23
|
+
const context = react.useContext(PixelFiddlerContext);
|
|
24
|
+
const config = configProp ?? context?.config;
|
|
25
|
+
const imageAttrs = react.useMemo(() => {
|
|
26
|
+
const urlConfig = {
|
|
27
|
+
...config,
|
|
28
|
+
baseUrl: src
|
|
29
|
+
};
|
|
30
|
+
if (responsive && (sizes || width)) {
|
|
31
|
+
return core.createResponsiveAttributes(urlConfig, {
|
|
32
|
+
...sizes && { sizes },
|
|
33
|
+
...width && { width },
|
|
34
|
+
...deviceBreakpoints && { deviceBreakpoints },
|
|
35
|
+
...imageBreakpoints && { imageBreakpoints },
|
|
36
|
+
...transformations && { transformations }
|
|
37
|
+
});
|
|
38
|
+
}
|
|
39
|
+
if (!transformations || Object.keys(transformations).length === 0) {
|
|
40
|
+
return { src };
|
|
41
|
+
}
|
|
42
|
+
return {
|
|
43
|
+
src: core.buildTransformationUrl(urlConfig, transformations)
|
|
44
|
+
};
|
|
45
|
+
}, [src, sizes, width, transformations, deviceBreakpoints, imageBreakpoints, responsive]);
|
|
46
|
+
return /* @__PURE__ */ jsxRuntime.jsx(
|
|
47
|
+
"img",
|
|
48
|
+
{
|
|
49
|
+
src: imageAttrs.src,
|
|
50
|
+
srcSet: imageAttrs.srcSet,
|
|
51
|
+
sizes: imageAttrs.sizes,
|
|
52
|
+
width: imageAttrs.width ?? width,
|
|
53
|
+
...imgProps
|
|
54
|
+
}
|
|
55
|
+
);
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
exports.PixelFiddleImage = PixelFiddleImage;
|
|
59
|
+
exports.PixelFiddlerProvider = PixelFiddlerProvider;
|
|
60
|
+
//# sourceMappingURL=index.cjs.map
|
|
61
|
+
//# sourceMappingURL=index.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/provider/pixel-fiddler-context.tsx","../src/components/pixel-fiddle-image.tsx"],"names":["createContext","jsx","useContext","useMemo","createResponsiveAttributes","buildTransformationUrl"],"mappings":";;;;;;;AAOO,IAAM,mBAAA,GAAsBA,oBAA+C,IAAI,CAAA;AAO/E,SAAS,oBAAA,CAAqB,EAAE,QAAA,EAAU,MAAA,EAAO,EAA8B;AACpF,EAAA,uBACEC,cAAA,CAAC,oBAAoB,QAAA,EAApB,EAA6B,OAAO,EAAC,MAAA,IACnC,QAAA,EACH,CAAA;AAEJ;ACYO,SAAS,gBAAA,CAAiB;AAAA,EAC/B,GAAA;AAAA,EACA,KAAA;AAAA,EACA,KAAA;AAAA,EACA,eAAA;AAAA,EACA,MAAA,EAAQ,UAAA;AAAA,EACR,iBAAA;AAAA,EACA,gBAAA;AAAA,EACA,UAAA,GAAa,IAAA;AAAA,EACb,GAAG;AACL,CAAA,EAA2B;AACzB,EAAA,MAAM,OAAA,GAAUC,iBAAW,mBAAmB,CAAA;AAC9C,EAAA,MAAM,MAAA,GAAS,cAAc,OAAA,EAAS,MAAA;AAEtC,EAAA,MAAM,UAAA,GAAaC,cAAQ,MAAM;AAC/B,IAAA,MAAM,SAAA,GAA8B;AAAA,MAClC,GAAG,MAAA;AAAA,MACH,OAAA,EAAS;AAAA,KACX;AAEA,IAAA,IAAI,UAAA,KAAe,SAAS,KAAA,CAAA,EAAQ;AAClC,MAAA,OAAOC,gCAA2B,SAAA,EAAW;AAAA,QAC3C,GAAI,KAAA,IAAS,EAAE,KAAA,EAAM;AAAA,QACrB,GAAI,KAAA,IAAS,EAAE,KAAA,EAAM;AAAA,QACrB,GAAI,iBAAA,IAAqB,EAAE,iBAAA,EAAkB;AAAA,QAC7C,GAAI,gBAAA,IAAoB,EAAE,gBAAA,EAAiB;AAAA,QAC3C,GAAI,eAAA,IAAmB,EAAE,eAAA;AAAgB,OAC1C,CAAA;AAAA,IACH;AAEA,IAAA,IAAI,CAAC,eAAA,IAAmB,MAAA,CAAO,KAAK,eAAe,CAAA,CAAE,WAAW,CAAA,EAAG;AACjE,MAAA,OAAO,EAAE,GAAA,EAAI;AAAA,IACf;AAEA,IAAA,OAAO;AAAA,MACL,GAAA,EAAKC,2BAAA,CAAuB,SAAA,EAAW,eAAe;AAAA,KACxD;AAAA,EACF,CAAA,EAAG,CAAC,GAAA,EAAK,KAAA,EAAO,OAAO,eAAA,EAAiB,iBAAA,EAAmB,gBAAA,EAAkB,UAAU,CAAC,CAAA;AAExF,EAAA,uBACEJ,cAAAA;AAAA,IAAC,KAAA;AAAA,IAAA;AAAA,MACC,KAAK,UAAA,CAAW,GAAA;AAAA,MAChB,QAAQ,UAAA,CAAW,MAAA;AAAA,MACnB,OAAO,UAAA,CAAW,KAAA;AAAA,MAClB,KAAA,EAAO,WAAW,KAAA,IAAS,KAAA;AAAA,MAC1B,GAAG;AAAA;AAAA,GACN;AAEJ","file":"index.cjs","sourcesContent":["import { createContext, type ReactNode } from 'react';\nimport type { PixelFiddlerConfig } from '@pixelfiddler/core';\n\nexport interface PixelFiddlerContextValue {\n config: PixelFiddlerConfig;\n}\n\nexport const PixelFiddlerContext = createContext<PixelFiddlerContextValue | null>(null);\n\nexport interface PixelFiddlerProviderProps {\n children: ReactNode;\n config: PixelFiddlerConfig;\n}\n\nexport function PixelFiddlerProvider({ children, config }: PixelFiddlerProviderProps) {\n return (\n <PixelFiddlerContext.Provider value={{config}}>\n {children}\n </PixelFiddlerContext.Provider>\n );\n}\n","import { useMemo, ImgHTMLAttributes, useContext } from 'react';\nimport {\n buildTransformationUrl,\n createResponsiveAttributes,\n TransformationOptions,\n UrlBuilderConfig,\n} from '@pixelfiddler/core';\nimport { PixelFiddlerContext } from '../provider/pixel-fiddler-context';\n\nexport interface PixelFiddlerImageProps\n extends Omit<ImgHTMLAttributes<HTMLImageElement>, 'src' | 'width' | 'height' | 'sizes'> {\n /** Base URL of the image (without transformations) */\n src: string;\n /**\n * The sizes attribute for responsive images (e.g., \"100vw\", \"(max-width: 768px) 100vw, 50vw\").\n * When provided, generates width descriptors (`w`) for fluid layouts.\n */\n sizes?: string;\n /** Display width in CSS pixels. When provided without `sizes`, generates DPR descriptors (`x`). */\n width?: number;\n /** Transformation options to apply */\n transformations?: TransformationOptions;\n /** Override the provider config for this image */\n config?: UrlBuilderConfig;\n /** Custom device breakpoints for responsive srcset */\n deviceBreakpoints?: number[];\n /** Custom image breakpoints for smaller images */\n imageBreakpoints?: number[];\n /** Enables automatic srcSet generation (default: true) */\n responsive?: boolean;\n}\n\nexport function PixelFiddleImage({\n src,\n sizes,\n width,\n transformations,\n config: configProp,\n deviceBreakpoints,\n imageBreakpoints,\n responsive = true,\n ...imgProps\n}: PixelFiddlerImageProps) {\n const context = useContext(PixelFiddlerContext);\n const config = configProp ?? context?.config;\n\n const imageAttrs = useMemo(() => {\n const urlConfig: UrlBuilderConfig = {\n ...config,\n baseUrl: src,\n };\n\n if (responsive && (sizes || width)) {\n return createResponsiveAttributes(urlConfig, {\n ...(sizes && { sizes }),\n ...(width && { width }),\n ...(deviceBreakpoints && { deviceBreakpoints }),\n ...(imageBreakpoints && { imageBreakpoints }),\n ...(transformations && { transformations }),\n });\n }\n\n if (!transformations || Object.keys(transformations).length === 0) {\n return { src };\n }\n\n return {\n src: buildTransformationUrl(urlConfig, transformations),\n };\n }, [src, sizes, width, transformations, deviceBreakpoints, imageBreakpoints, responsive]);\n\n return (\n <img\n src={imageAttrs.src}\n srcSet={imageAttrs.srcSet}\n sizes={imageAttrs.sizes}\n width={imageAttrs.width ?? width}\n {...imgProps}\n />\n );\n}\n"]}
|
package/dist/index.d.cts
ADDED
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import * as react_jsx_runtime from 'react/jsx-runtime';
|
|
2
|
+
import { ImgHTMLAttributes, ReactNode } from 'react';
|
|
3
|
+
import { TransformationOptions, UrlBuilderConfig, PixelFiddlerConfig } from '@pixelfiddler/core';
|
|
4
|
+
export { BorderOptions, CropOptions, EffectOptions, FormatOptions, PixelFiddlerConfig, ResizeOptions, TextOptions, TransformationOptions, WatermarkOptions } from '@pixelfiddler/core';
|
|
5
|
+
|
|
6
|
+
interface PixelFiddlerImageProps extends Omit<ImgHTMLAttributes<HTMLImageElement>, 'src' | 'width' | 'height' | 'sizes'> {
|
|
7
|
+
/** Base URL of the image (without transformations) */
|
|
8
|
+
src: string;
|
|
9
|
+
/**
|
|
10
|
+
* The sizes attribute for responsive images (e.g., "100vw", "(max-width: 768px) 100vw, 50vw").
|
|
11
|
+
* When provided, generates width descriptors (`w`) for fluid layouts.
|
|
12
|
+
*/
|
|
13
|
+
sizes?: string;
|
|
14
|
+
/** Display width in CSS pixels. When provided without `sizes`, generates DPR descriptors (`x`). */
|
|
15
|
+
width?: number;
|
|
16
|
+
/** Transformation options to apply */
|
|
17
|
+
transformations?: TransformationOptions;
|
|
18
|
+
/** Override the provider config for this image */
|
|
19
|
+
config?: UrlBuilderConfig;
|
|
20
|
+
/** Custom device breakpoints for responsive srcset */
|
|
21
|
+
deviceBreakpoints?: number[];
|
|
22
|
+
/** Custom image breakpoints for smaller images */
|
|
23
|
+
imageBreakpoints?: number[];
|
|
24
|
+
/** Enables automatic srcSet generation (default: true) */
|
|
25
|
+
responsive?: boolean;
|
|
26
|
+
}
|
|
27
|
+
declare function PixelFiddleImage({ src, sizes, width, transformations, config: configProp, deviceBreakpoints, imageBreakpoints, responsive, ...imgProps }: PixelFiddlerImageProps): react_jsx_runtime.JSX.Element;
|
|
28
|
+
|
|
29
|
+
interface PixelFiddlerContextValue {
|
|
30
|
+
config: PixelFiddlerConfig;
|
|
31
|
+
}
|
|
32
|
+
interface PixelFiddlerProviderProps {
|
|
33
|
+
children: ReactNode;
|
|
34
|
+
config: PixelFiddlerConfig;
|
|
35
|
+
}
|
|
36
|
+
declare function PixelFiddlerProvider({ children, config }: PixelFiddlerProviderProps): react_jsx_runtime.JSX.Element;
|
|
37
|
+
|
|
38
|
+
export { PixelFiddleImage, type PixelFiddlerContextValue, type PixelFiddlerImageProps, PixelFiddlerProvider };
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import * as react_jsx_runtime from 'react/jsx-runtime';
|
|
2
|
+
import { ImgHTMLAttributes, ReactNode } from 'react';
|
|
3
|
+
import { TransformationOptions, UrlBuilderConfig, PixelFiddlerConfig } from '@pixelfiddler/core';
|
|
4
|
+
export { BorderOptions, CropOptions, EffectOptions, FormatOptions, PixelFiddlerConfig, ResizeOptions, TextOptions, TransformationOptions, WatermarkOptions } from '@pixelfiddler/core';
|
|
5
|
+
|
|
6
|
+
interface PixelFiddlerImageProps extends Omit<ImgHTMLAttributes<HTMLImageElement>, 'src' | 'width' | 'height' | 'sizes'> {
|
|
7
|
+
/** Base URL of the image (without transformations) */
|
|
8
|
+
src: string;
|
|
9
|
+
/**
|
|
10
|
+
* The sizes attribute for responsive images (e.g., "100vw", "(max-width: 768px) 100vw, 50vw").
|
|
11
|
+
* When provided, generates width descriptors (`w`) for fluid layouts.
|
|
12
|
+
*/
|
|
13
|
+
sizes?: string;
|
|
14
|
+
/** Display width in CSS pixels. When provided without `sizes`, generates DPR descriptors (`x`). */
|
|
15
|
+
width?: number;
|
|
16
|
+
/** Transformation options to apply */
|
|
17
|
+
transformations?: TransformationOptions;
|
|
18
|
+
/** Override the provider config for this image */
|
|
19
|
+
config?: UrlBuilderConfig;
|
|
20
|
+
/** Custom device breakpoints for responsive srcset */
|
|
21
|
+
deviceBreakpoints?: number[];
|
|
22
|
+
/** Custom image breakpoints for smaller images */
|
|
23
|
+
imageBreakpoints?: number[];
|
|
24
|
+
/** Enables automatic srcSet generation (default: true) */
|
|
25
|
+
responsive?: boolean;
|
|
26
|
+
}
|
|
27
|
+
declare function PixelFiddleImage({ src, sizes, width, transformations, config: configProp, deviceBreakpoints, imageBreakpoints, responsive, ...imgProps }: PixelFiddlerImageProps): react_jsx_runtime.JSX.Element;
|
|
28
|
+
|
|
29
|
+
interface PixelFiddlerContextValue {
|
|
30
|
+
config: PixelFiddlerConfig;
|
|
31
|
+
}
|
|
32
|
+
interface PixelFiddlerProviderProps {
|
|
33
|
+
children: ReactNode;
|
|
34
|
+
config: PixelFiddlerConfig;
|
|
35
|
+
}
|
|
36
|
+
declare function PixelFiddlerProvider({ children, config }: PixelFiddlerProviderProps): react_jsx_runtime.JSX.Element;
|
|
37
|
+
|
|
38
|
+
export { PixelFiddleImage, type PixelFiddlerContextValue, type PixelFiddlerImageProps, PixelFiddlerProvider };
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import { createContext, useContext, useMemo } from 'react';
|
|
2
|
+
import { createResponsiveAttributes, buildTransformationUrl } from '@pixelfiddler/core';
|
|
3
|
+
import { jsx } from 'react/jsx-runtime';
|
|
4
|
+
|
|
5
|
+
// src/components/pixel-fiddle-image.tsx
|
|
6
|
+
var PixelFiddlerContext = createContext(null);
|
|
7
|
+
function PixelFiddlerProvider({ children, config }) {
|
|
8
|
+
return /* @__PURE__ */ jsx(PixelFiddlerContext.Provider, { value: { config }, children });
|
|
9
|
+
}
|
|
10
|
+
function PixelFiddleImage({
|
|
11
|
+
src,
|
|
12
|
+
sizes,
|
|
13
|
+
width,
|
|
14
|
+
transformations,
|
|
15
|
+
config: configProp,
|
|
16
|
+
deviceBreakpoints,
|
|
17
|
+
imageBreakpoints,
|
|
18
|
+
responsive = true,
|
|
19
|
+
...imgProps
|
|
20
|
+
}) {
|
|
21
|
+
const context = useContext(PixelFiddlerContext);
|
|
22
|
+
const config = configProp ?? context?.config;
|
|
23
|
+
const imageAttrs = useMemo(() => {
|
|
24
|
+
const urlConfig = {
|
|
25
|
+
...config,
|
|
26
|
+
baseUrl: src
|
|
27
|
+
};
|
|
28
|
+
if (responsive && (sizes || width)) {
|
|
29
|
+
return createResponsiveAttributes(urlConfig, {
|
|
30
|
+
...sizes && { sizes },
|
|
31
|
+
...width && { width },
|
|
32
|
+
...deviceBreakpoints && { deviceBreakpoints },
|
|
33
|
+
...imageBreakpoints && { imageBreakpoints },
|
|
34
|
+
...transformations && { transformations }
|
|
35
|
+
});
|
|
36
|
+
}
|
|
37
|
+
if (!transformations || Object.keys(transformations).length === 0) {
|
|
38
|
+
return { src };
|
|
39
|
+
}
|
|
40
|
+
return {
|
|
41
|
+
src: buildTransformationUrl(urlConfig, transformations)
|
|
42
|
+
};
|
|
43
|
+
}, [src, sizes, width, transformations, deviceBreakpoints, imageBreakpoints, responsive]);
|
|
44
|
+
return /* @__PURE__ */ jsx(
|
|
45
|
+
"img",
|
|
46
|
+
{
|
|
47
|
+
src: imageAttrs.src,
|
|
48
|
+
srcSet: imageAttrs.srcSet,
|
|
49
|
+
sizes: imageAttrs.sizes,
|
|
50
|
+
width: imageAttrs.width ?? width,
|
|
51
|
+
...imgProps
|
|
52
|
+
}
|
|
53
|
+
);
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
export { PixelFiddleImage, PixelFiddlerProvider };
|
|
57
|
+
//# sourceMappingURL=index.js.map
|
|
58
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/provider/pixel-fiddler-context.tsx","../src/components/pixel-fiddle-image.tsx"],"names":["jsx"],"mappings":";;;;;AAOO,IAAM,mBAAA,GAAsB,cAA+C,IAAI,CAAA;AAO/E,SAAS,oBAAA,CAAqB,EAAE,QAAA,EAAU,MAAA,EAAO,EAA8B;AACpF,EAAA,uBACE,GAAA,CAAC,oBAAoB,QAAA,EAApB,EAA6B,OAAO,EAAC,MAAA,IACnC,QAAA,EACH,CAAA;AAEJ;ACYO,SAAS,gBAAA,CAAiB;AAAA,EAC/B,GAAA;AAAA,EACA,KAAA;AAAA,EACA,KAAA;AAAA,EACA,eAAA;AAAA,EACA,MAAA,EAAQ,UAAA;AAAA,EACR,iBAAA;AAAA,EACA,gBAAA;AAAA,EACA,UAAA,GAAa,IAAA;AAAA,EACb,GAAG;AACL,CAAA,EAA2B;AACzB,EAAA,MAAM,OAAA,GAAU,WAAW,mBAAmB,CAAA;AAC9C,EAAA,MAAM,MAAA,GAAS,cAAc,OAAA,EAAS,MAAA;AAEtC,EAAA,MAAM,UAAA,GAAa,QAAQ,MAAM;AAC/B,IAAA,MAAM,SAAA,GAA8B;AAAA,MAClC,GAAG,MAAA;AAAA,MACH,OAAA,EAAS;AAAA,KACX;AAEA,IAAA,IAAI,UAAA,KAAe,SAAS,KAAA,CAAA,EAAQ;AAClC,MAAA,OAAO,2BAA2B,SAAA,EAAW;AAAA,QAC3C,GAAI,KAAA,IAAS,EAAE,KAAA,EAAM;AAAA,QACrB,GAAI,KAAA,IAAS,EAAE,KAAA,EAAM;AAAA,QACrB,GAAI,iBAAA,IAAqB,EAAE,iBAAA,EAAkB;AAAA,QAC7C,GAAI,gBAAA,IAAoB,EAAE,gBAAA,EAAiB;AAAA,QAC3C,GAAI,eAAA,IAAmB,EAAE,eAAA;AAAgB,OAC1C,CAAA;AAAA,IACH;AAEA,IAAA,IAAI,CAAC,eAAA,IAAmB,MAAA,CAAO,KAAK,eAAe,CAAA,CAAE,WAAW,CAAA,EAAG;AACjE,MAAA,OAAO,EAAE,GAAA,EAAI;AAAA,IACf;AAEA,IAAA,OAAO;AAAA,MACL,GAAA,EAAK,sBAAA,CAAuB,SAAA,EAAW,eAAe;AAAA,KACxD;AAAA,EACF,CAAA,EAAG,CAAC,GAAA,EAAK,KAAA,EAAO,OAAO,eAAA,EAAiB,iBAAA,EAAmB,gBAAA,EAAkB,UAAU,CAAC,CAAA;AAExF,EAAA,uBACEA,GAAAA;AAAA,IAAC,KAAA;AAAA,IAAA;AAAA,MACC,KAAK,UAAA,CAAW,GAAA;AAAA,MAChB,QAAQ,UAAA,CAAW,MAAA;AAAA,MACnB,OAAO,UAAA,CAAW,KAAA;AAAA,MAClB,KAAA,EAAO,WAAW,KAAA,IAAS,KAAA;AAAA,MAC1B,GAAG;AAAA;AAAA,GACN;AAEJ","file":"index.js","sourcesContent":["import { createContext, type ReactNode } from 'react';\nimport type { PixelFiddlerConfig } from '@pixelfiddler/core';\n\nexport interface PixelFiddlerContextValue {\n config: PixelFiddlerConfig;\n}\n\nexport const PixelFiddlerContext = createContext<PixelFiddlerContextValue | null>(null);\n\nexport interface PixelFiddlerProviderProps {\n children: ReactNode;\n config: PixelFiddlerConfig;\n}\n\nexport function PixelFiddlerProvider({ children, config }: PixelFiddlerProviderProps) {\n return (\n <PixelFiddlerContext.Provider value={{config}}>\n {children}\n </PixelFiddlerContext.Provider>\n );\n}\n","import { useMemo, ImgHTMLAttributes, useContext } from 'react';\nimport {\n buildTransformationUrl,\n createResponsiveAttributes,\n TransformationOptions,\n UrlBuilderConfig,\n} from '@pixelfiddler/core';\nimport { PixelFiddlerContext } from '../provider/pixel-fiddler-context';\n\nexport interface PixelFiddlerImageProps\n extends Omit<ImgHTMLAttributes<HTMLImageElement>, 'src' | 'width' | 'height' | 'sizes'> {\n /** Base URL of the image (without transformations) */\n src: string;\n /**\n * The sizes attribute for responsive images (e.g., \"100vw\", \"(max-width: 768px) 100vw, 50vw\").\n * When provided, generates width descriptors (`w`) for fluid layouts.\n */\n sizes?: string;\n /** Display width in CSS pixels. When provided without `sizes`, generates DPR descriptors (`x`). */\n width?: number;\n /** Transformation options to apply */\n transformations?: TransformationOptions;\n /** Override the provider config for this image */\n config?: UrlBuilderConfig;\n /** Custom device breakpoints for responsive srcset */\n deviceBreakpoints?: number[];\n /** Custom image breakpoints for smaller images */\n imageBreakpoints?: number[];\n /** Enables automatic srcSet generation (default: true) */\n responsive?: boolean;\n}\n\nexport function PixelFiddleImage({\n src,\n sizes,\n width,\n transformations,\n config: configProp,\n deviceBreakpoints,\n imageBreakpoints,\n responsive = true,\n ...imgProps\n}: PixelFiddlerImageProps) {\n const context = useContext(PixelFiddlerContext);\n const config = configProp ?? context?.config;\n\n const imageAttrs = useMemo(() => {\n const urlConfig: UrlBuilderConfig = {\n ...config,\n baseUrl: src,\n };\n\n if (responsive && (sizes || width)) {\n return createResponsiveAttributes(urlConfig, {\n ...(sizes && { sizes }),\n ...(width && { width }),\n ...(deviceBreakpoints && { deviceBreakpoints }),\n ...(imageBreakpoints && { imageBreakpoints }),\n ...(transformations && { transformations }),\n });\n }\n\n if (!transformations || Object.keys(transformations).length === 0) {\n return { src };\n }\n\n return {\n src: buildTransformationUrl(urlConfig, transformations),\n };\n }, [src, sizes, width, transformations, deviceBreakpoints, imageBreakpoints, responsive]);\n\n return (\n <img\n src={imageAttrs.src}\n srcSet={imageAttrs.srcSet}\n sizes={imageAttrs.sizes}\n width={imageAttrs.width ?? width}\n {...imgProps}\n />\n );\n}\n"]}
|
package/package.json
ADDED
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@pixelfiddler/react",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "React components for PixelFiddler image transformation SDK",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"main": "./dist/index.cjs",
|
|
7
|
+
"module": "./dist/index.js",
|
|
8
|
+
"types": "./dist/index.d.ts",
|
|
9
|
+
"exports": {
|
|
10
|
+
".": {
|
|
11
|
+
"import": {
|
|
12
|
+
"types": "./dist/index.d.ts",
|
|
13
|
+
"default": "./dist/index.js"
|
|
14
|
+
},
|
|
15
|
+
"require": {
|
|
16
|
+
"types": "./dist/index.d.cts",
|
|
17
|
+
"default": "./dist/index.cjs"
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
},
|
|
21
|
+
"files": [
|
|
22
|
+
"dist"
|
|
23
|
+
],
|
|
24
|
+
"dependencies": {
|
|
25
|
+
"@pixelfiddler/core": "0.1.1"
|
|
26
|
+
},
|
|
27
|
+
"peerDependencies": {
|
|
28
|
+
"react": ">=18.0.0"
|
|
29
|
+
},
|
|
30
|
+
"devDependencies": {
|
|
31
|
+
"@types/react": "^18.2.0",
|
|
32
|
+
"@vitest/coverage-v8": "^4.0.18",
|
|
33
|
+
"react": "^18.2.0",
|
|
34
|
+
"tsup": "^8.0.1",
|
|
35
|
+
"typescript": "^5.3.3",
|
|
36
|
+
"vitest": "^4.0.18",
|
|
37
|
+
"@testing-library/react": "^16.3.2"
|
|
38
|
+
},
|
|
39
|
+
"keywords": [
|
|
40
|
+
"pixelfiddler",
|
|
41
|
+
"react",
|
|
42
|
+
"image",
|
|
43
|
+
"transformation",
|
|
44
|
+
"cdn",
|
|
45
|
+
"optimization",
|
|
46
|
+
"component"
|
|
47
|
+
],
|
|
48
|
+
"license": "MIT",
|
|
49
|
+
"author": "PixelFiddler",
|
|
50
|
+
"homepage": "https://pixel-fiddler.com",
|
|
51
|
+
"bugs": {
|
|
52
|
+
"url": "https://github.com/pixel-fiddler/js-sdk/issues"
|
|
53
|
+
},
|
|
54
|
+
"repository": {
|
|
55
|
+
"type": "git",
|
|
56
|
+
"url": "git+https://github.com/pixel-fiddler/js-sdk.git",
|
|
57
|
+
"directory": "packages/react"
|
|
58
|
+
},
|
|
59
|
+
"publishConfig": {
|
|
60
|
+
"access": "public"
|
|
61
|
+
},
|
|
62
|
+
"engines": {
|
|
63
|
+
"node": ">=18"
|
|
64
|
+
},
|
|
65
|
+
"sideEffects": false,
|
|
66
|
+
"scripts": {
|
|
67
|
+
"build": "tsup",
|
|
68
|
+
"dev": "tsup --watch",
|
|
69
|
+
"test": "vitest run",
|
|
70
|
+
"test:watch": "vitest",
|
|
71
|
+
"test:coverage": "vitest run --coverage",
|
|
72
|
+
"typecheck": "tsc --noEmit",
|
|
73
|
+
"lint": "eslint src --ext .ts,.tsx",
|
|
74
|
+
"clean": "rm -rf dist coverage"
|
|
75
|
+
}
|
|
76
|
+
}
|