drupal-canvas 0.5.0 → 0.5.2

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/README.md CHANGED
@@ -379,6 +379,11 @@ export default function MyComponent({ photo }) {
379
379
  }
380
380
  ```
381
381
 
382
+ Drupal generates no derivative images for an image its image toolkit cannot
383
+ process, an SVG image for example. Such an image is rendered as-is, without a
384
+ `srcset`. An SVG image that specifies neither its dimensions nor a `viewBox` is
385
+ rendered without `width` and `height` too, and is then sized by the browser.
386
+
382
387
  ### Region / RegionsProvider
383
388
 
384
389
  Render Drupal Canvas global regions inside a layout component.
@@ -344,11 +344,74 @@ var $defs = {
344
344
  }
345
345
  }
346
346
  },
347
+ "document": {
348
+ "title": "document",
349
+ "type": "object",
350
+ "required": ["src"],
351
+ "properties": {
352
+ "src": {
353
+ "title": "Document URL",
354
+ "type": "string",
355
+ "format": "uri-reference",
356
+ "contentMediaType": "application/*",
357
+ "x-allowed-schemes": ["http", "https"],
358
+ "x-allowed-file-extensions": [
359
+ "rtf",
360
+ "doc",
361
+ "docx",
362
+ "ppt",
363
+ "pptx",
364
+ "xls",
365
+ "xlsx",
366
+ "pdf",
367
+ "odf",
368
+ "odg",
369
+ "odp",
370
+ "ods",
371
+ "odt",
372
+ "fodt",
373
+ "fods",
374
+ "fodp",
375
+ "fodg",
376
+ "key",
377
+ "numbers",
378
+ "pages"
379
+ ]
380
+ },
381
+ "title": {
382
+ "title": "Document title",
383
+ "type": "string"
384
+ },
385
+ "description": {
386
+ "title": "Document description",
387
+ "type": "string"
388
+ },
389
+ "filename": {
390
+ "title": "Filename",
391
+ "type": "string"
392
+ },
393
+ "filesize": {
394
+ "title": "File size",
395
+ "type": "integer",
396
+ "description": "File size in bytes"
397
+ },
398
+ "mimetype": {
399
+ "title": "MIME type",
400
+ "type": "string"
401
+ }
402
+ }
403
+ },
347
404
  "content-entity-reference": {
348
405
  "title": "Content entity reference",
349
406
  "type": "object",
350
407
  "x-allowed-entity-type-id": null
351
408
  },
409
+ "color": {
410
+ "title": "color",
411
+ "type": "string",
412
+ "$ref": "json-schema-definitions://canvas.module/color",
413
+ "$comment": "The $ref is intentionally self-referential. It acts as a named-type sentinel: downstream PHP and TypeScript code detects the URI string by equality to route to color-picker behavior. A strict resolver will see the justinrainbow/json-schema library append '#' to the URI; ComponentPluginManager::resolveJsonSchemaReferences() detects that mutation and restores the original clean URI. Do not remove the $ref. See PropShape::getWellKnownPropShapes() and JsonSchemaType::computeStorablePropShape()."
414
+ },
352
415
  "config-entity-id": {
353
416
  "title": "config entity id",
354
417
  "type": "string",
@@ -5,26 +5,25 @@ function Image(props) {
5
5
  const { src, loader } = props;
6
6
  const srcString = typeof src === "string" ? src : "default" in src ? src.default.src : src.src;
7
7
  if (!loader) {
8
+ const alternateWidths = new URLSearchParams(srcString.split("?")[1]?.split("#")[0]).get("alternateWidths");
9
+ if (!alternateWidths) return /* @__PURE__ */ jsx(NextImage, {
10
+ ...props,
11
+ loader: () => srcString,
12
+ unoptimized: true
13
+ });
8
14
  const defaultLoader = ({ width, imageProps }) => {
9
- try {
10
- let result = new URL(srcString, "https://example.com").searchParams.get("alternateWidths");
11
- if (!result) throw new Error("Responsive image generation requires an `alternateWidths` query parameter in the image URL.");
12
- result = result.replace("{width}", width.toString());
13
- if (result.includes("{height}")) {
14
- const intrinsicWidth = Number(imageProps.width);
15
- const intrinsicHeight = Number(imageProps.height);
16
- if (!intrinsicWidth || !intrinsicHeight) throw new Error("Height calculation requires intrinsic image dimensions.");
17
- const height = Math.round(width / (intrinsicWidth / intrinsicHeight));
18
- result = result.replace("{height}", height.toString());
15
+ let result = alternateWidths.replace("{width}", width.toString());
16
+ if (result.includes("{height}")) {
17
+ const intrinsicWidth = Number(imageProps.width);
18
+ const intrinsicHeight = Number(imageProps.height);
19
+ if (!intrinsicWidth || !intrinsicHeight) {
20
+ console.error("Height calculation requires intrinsic image dimensions.", { src });
21
+ return srcString;
19
22
  }
20
- return result;
21
- } catch (error) {
22
- console.error("Responsive image generation failed. To fix this:\n1. Provide a custom `loader` function, or\n2. Ensure your image `src` includes an `alternateWidths` query parameter\n Example: ?alternateWidths=/path/to/responsive/{width}/image.jpg", {
23
- src,
24
- error
25
- });
26
- return srcString;
23
+ const height = Math.round(width / (intrinsicWidth / intrinsicHeight));
24
+ result = result.replace("{height}", height.toString());
27
25
  }
26
+ return result;
28
27
  };
29
28
  return /* @__PURE__ */ jsx(NextImage, {
30
29
  ...props,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "drupal-canvas",
3
- "version": "0.5.0",
3
+ "version": "0.5.2",
4
4
  "engines": {
5
5
  "node": ">=22.19.0 <23 || >=24.5.0"
6
6
  },