@place-framework/place-block-image 1.0.4 → 1.0.5

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.
@@ -0,0 +1,18 @@
1
+ import { default as React } from 'react';
2
+ interface PlaceBlockImageProps extends React.ImgHTMLAttributes<HTMLImageElement> {
3
+ src: string;
4
+ alt: string;
5
+ imagePrefix?: string;
6
+ lazy?: boolean;
7
+ }
8
+ /**
9
+ * PlaceBlockImage — prevents layout shift using CSS custom properties.
10
+ * Import: import PlaceBlockImage from '@place-framework/place-block-image/react'
11
+ *
12
+ * Usage:
13
+ * <PlaceBlockImage src="/assets/logo.png" alt="Logo" />
14
+ * <PlaceBlockImage src="/assets/hero.jpg" alt="Hero" lazy={true} />
15
+ */
16
+ export declare const PlaceBlockImage: React.FC<PlaceBlockImageProps>;
17
+ export default PlaceBlockImage;
18
+ //# sourceMappingURL=PlaceBlockImage.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"PlaceBlockImage.d.ts","sourceRoot":"","sources":["../../src/react/PlaceBlockImage.tsx"],"names":[],"mappings":"AAEA,OAAO,KAAsC,MAAM,OAAO,CAAC;AAI3D,UAAU,oBAAqB,SAAQ,KAAK,CAAC,iBAAiB,CAAC,gBAAgB,CAAC;IAC9E,GAAG,EAAE,MAAM,CAAC;IACZ,GAAG,EAAE,MAAM,CAAC;IACZ,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,IAAI,CAAC,EAAE,OAAO,CAAC;CAChB;AAED;;;;;;;GAOG;AACH,eAAO,MAAM,eAAe,EAAE,KAAK,CAAC,EAAE,CAAC,oBAAoB,CAuC1D,CAAC;AAEF,eAAe,eAAe,CAAC"}
@@ -0,0 +1,41 @@
1
+ import { DefineComponent, ExtractPropTypes, ComponentOptionsMixin, PublicProps, ComponentProvideOptions } from 'vue';
2
+ declare const __VLS_export: DefineComponent<ExtractPropTypes<{
3
+ src: {
4
+ type: StringConstructor;
5
+ required: true;
6
+ };
7
+ alt: {
8
+ type: StringConstructor;
9
+ required: true;
10
+ };
11
+ imagePrefix: {
12
+ type: StringConstructor;
13
+ default: () => string;
14
+ };
15
+ lazy: {
16
+ type: BooleanConstructor;
17
+ default: boolean;
18
+ };
19
+ }>, {}, {}, {}, {}, ComponentOptionsMixin, ComponentOptionsMixin, {}, string, PublicProps, Readonly< ExtractPropTypes<{
20
+ src: {
21
+ type: StringConstructor;
22
+ required: true;
23
+ };
24
+ alt: {
25
+ type: StringConstructor;
26
+ required: true;
27
+ };
28
+ imagePrefix: {
29
+ type: StringConstructor;
30
+ default: () => string;
31
+ };
32
+ lazy: {
33
+ type: BooleanConstructor;
34
+ default: boolean;
35
+ };
36
+ }>> & Readonly<{}>, {
37
+ lazy: boolean;
38
+ imagePrefix: string;
39
+ }, {}, {}, {}, string, ComponentProvideOptions, true, {}, any>;
40
+ declare const _default: typeof __VLS_export;
41
+ export default _default;
@@ -0,0 +1 @@
1
+ export { default as PlaceBlockImage } from './PlaceBlockImage';
@@ -0,0 +1,8 @@
1
+ export declare const IMAGE_PREFIX = "image-";
2
+ export declare const CLASS_NAMES: {
3
+ readonly LAZY: "lazy";
4
+ readonly LOADED: "loaded";
5
+ readonly WRAPPER_SUFFIX: "wrapper";
6
+ };
7
+ export declare const getWrapperClassName: (imagePrefix: string) => string;
8
+ export declare const getImageClassName: (imagePrefix: string, filename: string) => string;
@@ -0,0 +1,61 @@
1
+ /**
2
+ * Converts any image URL or path into a CSS-safe kebab-case string.
3
+ * Used at build time by generateImageClassName() and at runtime by
4
+ * the Vue/React components to derive the CSS class from the src prop.
5
+ */
6
+ export declare const cleanImagePath: (src: string) => string;
7
+ /**
8
+ * Generate CSS class name from a file path — path-agnostic, works with any URL format.
9
+ * Matches the runtime getImageClassName logic emitted by getSharedLogic().
10
+ *
11
+ * @param filePath - Relative path from imageDir (e.g. "story/accent-orchid.png")
12
+ * @param imagePrefix - The prefix to add to the class name (e.g. "image-")
13
+ * @param outputPrefix - Optional output path prefix prepended before filePath to mirror
14
+ * the served URL (e.g. "images/" when assetModuleFilename outputs
15
+ * to "images/…" so the browser requests "/images/story/…")
16
+ * @returns The generated CSS class name (e.g. "image-images-story-accent-orchid")
17
+ */
18
+ export declare function generateImageClassName(filePath: string, imagePrefix: string, outputPrefix?: string): string;
19
+ /**
20
+ * Strips the Vite/webpack plugin's injected asset-path prefix from a src string
21
+ * so the remaining path matches what the plugin used when generating CSS classes.
22
+ *
23
+ * @param src - The raw src value (may include the asset path prefix)
24
+ * @param assetPath - The value of __PLUGIN_ASSET_PATH__ (empty string if undefined)
25
+ */
26
+ export declare function resolveAssetPath(src: string, assetPath: string): string;
27
+ /**
28
+ * Derives the per-image CSS class from a src URL, stripping the asset-path
29
+ * prefix first so the class matches what the plugin generated at build time.
30
+ *
31
+ * @param src - Raw src prop value
32
+ * @param imagePrefix - e.g. "image-"
33
+ * @param assetPath - Value of __PLUGIN_ASSET_PATH__ (pass '' if not defined)
34
+ */
35
+ export declare function getImageClass(src: string, imagePrefix: string, assetPath: string): string;
36
+ /**
37
+ * Builds the full className string for the <picture> wrapper element.
38
+ *
39
+ * @param src - Raw src prop value
40
+ * @param imagePrefix - e.g. "image-"
41
+ * @param assetPath - Value of __PLUGIN_ASSET_PATH__ (pass '' if not defined)
42
+ * @param extraClass - Any additional class(es) passed by the consumer (e.g. className prop)
43
+ */
44
+ export declare function getWrapperClass(src: string, imagePrefix: string, assetPath: string, extraClass?: string): string;
45
+ /**
46
+ * Returns the CSS class string for the <img> element based on lazy-load state.
47
+ *
48
+ * @param lazy - Whether lazy loading is enabled
49
+ * @param isLoaded - Whether the image has been loaded (intersected)
50
+ */
51
+ export declare function getLazyClass(lazy: boolean, isLoaded: boolean): string;
52
+ /**
53
+ * Creates an IntersectionObserver that fires `onIntersect` once when the given
54
+ * element enters the viewport, then automatically stops observing.
55
+ *
56
+ * @param element - The DOM element to observe
57
+ * @param onIntersect - Callback invoked when the element intersects
58
+ * @param threshold - Intersection threshold (default 0.1)
59
+ * @returns The created IntersectionObserver (call .disconnect() to clean up early)
60
+ */
61
+ export declare function createLazyObserver(element: Element, onIntersect: () => void, threshold?: number): IntersectionObserver;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@place-framework/place-block-image",
3
- "version": "1.0.4",
3
+ "version": "1.0.5",
4
4
  "description": "A utility package for generating CSS custom properties from image dimensions to prevent layout shift",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
@@ -49,8 +49,10 @@
49
49
  "@types/node": "^20.0.0",
50
50
  "@types/react": "^18.0.0",
51
51
  "@vitejs/plugin-vue": "^6.0.7",
52
+ "@vue/language-core": "^3.1.8",
52
53
  "typescript": "^5.0.0",
53
- "vite": "^8.0.16"
54
+ "vite": "^8.0.16",
55
+ "vite-plugin-dts": "^5.0.2"
54
56
  },
55
57
  "dependencies": {
56
58
  "glob": "^10.0.0",
@@ -0,0 +1,17 @@
1
+ {
2
+ "compilerOptions": {
3
+ "target": "ES2020",
4
+ "module": "ESNext",
5
+ "lib": ["ES2020", "DOM"],
6
+ "strict": true,
7
+ "esModuleInterop": true,
8
+ "skipLibCheck": true,
9
+ "forceConsistentCasingInFileNames": true,
10
+ "declaration": true,
11
+ "moduleResolution": "node",
12
+ "resolveJsonModule": true,
13
+ "jsx": "preserve",
14
+ "baseUrl": "."
15
+ },
16
+ "include": ["src/vue/**/*", "src/utils/**/*", "src/constants/**/*"]
17
+ }
@@ -1,10 +1,18 @@
1
1
  import { resolve } from 'path';
2
2
  import type { UserConfig } from 'vite';
3
+ import dts from 'vite-plugin-dts';
3
4
 
4
-
5
- // Builds src/react/PlaceBlockImage.tsx → dist/react/PlaceBlockImage.{js,cjs}
5
+ // Builds src/react/PlaceBlockImage.tsx → dist/react/PlaceBlockImage.{js,cjs,d.ts}
6
6
  // React and its runtime are kept external — consumers supply their own.
7
7
  export const reactConfig: UserConfig = {
8
+ plugins: [
9
+ dts({
10
+ include: ['src/react/PlaceBlockImage.tsx'],
11
+ outDirs: 'dist/react',
12
+ entryRoot: 'src/react',
13
+ tsconfigPath: './tsconfig.json',
14
+ }),
15
+ ],
8
16
  build: {
9
17
  outDir: 'dist/react',
10
18
  emptyOutDir: true,
@@ -1,12 +1,22 @@
1
1
  import vue from '@vitejs/plugin-vue';
2
2
  import { resolve } from 'path';
3
3
  import type { UserConfig } from 'vite';
4
+ import dts from 'vite-plugin-dts';
4
5
 
5
-
6
- // Builds src/vue/PlaceBlockImage.vue → dist/vue/PlaceBlockImage.{js,cjs}
6
+ // Builds src/vue/PlaceBlockImage.vue → dist/vue/PlaceBlockImage.{js,cjs,d.ts}
7
7
  // Vue and its runtime are kept external — consumers supply their own.
8
8
  export const vueConfig: UserConfig = {
9
- plugins: [vue()],
9
+ plugins: [
10
+ vue(),
11
+ dts({
12
+ outDirs: 'dist/vue',
13
+ entryRoot: 'src/vue',
14
+ tsconfigPath: './tsconfig.vue.json',
15
+ processor: 'vue',
16
+ cleanVueFileName: true,
17
+ staticImport: true,
18
+ }),
19
+ ],
10
20
  build: {
11
21
  outDir: 'dist/vue',
12
22
  emptyOutDir: true,