@valbuild/next 0.44.0 → 0.45.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.
@@ -0,0 +1,7 @@
1
+ /// <reference types="react" />
2
+ import NextImage from "next/image";
3
+ import { Image } from "@valbuild/react/stega";
4
+ export type ValImageProps = Omit<React.ComponentProps<typeof NextImage>, "src" | "srcset"> & {
5
+ src: Image;
6
+ };
7
+ export declare function ValImage(props: ValImageProps): import("react/jsx-runtime").JSX.Element;
@@ -0,0 +1,2 @@
1
+ import { ValEncodedString } from "@valbuild/react/stega";
2
+ export declare function decodeValPathOfString(encodedString: ValEncodedString): string | undefined;
@@ -13,8 +13,9 @@ export { VAL_EXTENSION, type SourceArray } from "@valbuild/core";
13
13
  export { derefPatch } from "@valbuild/core";
14
14
  export { type SelectorSource, type SelectorOf, GenericSelector, } from "@valbuild/core";
15
15
  export { ValRichText } from "@valbuild/react/internal";
16
- export { type ValEncodedString } from "@valbuild/react/stega";
16
+ export { type ValEncodedString, type Image } from "@valbuild/react/stega";
17
17
  export { ValProvider } from "./ValProvider.js";
18
+ export { ValImage } from "./ValImage.js";
18
19
  export { initVal } from "./initVal.js";
19
20
  import type { UseValType } from "./client/initValClient.js";
20
21
  import { Schema, SelectorSource } from "@valbuild/core";
@@ -1,7 +1,9 @@
1
1
  import { type ValConfig, type InitVal, type ValConstructor } from "@valbuild/core";
2
- import { ValEncodedString } from "@valbuild/react/stega";
2
+ import { raw } from "./raw.js";
3
+ import { decodeValPathOfString } from "./decodeValPathOfString.js";
3
4
  export declare const initVal: (config?: ValConfig) => InitVal & {
4
5
  val: ValConstructor & {
5
- raw: (encodedString: ValEncodedString) => string;
6
+ raw: typeof raw;
7
+ decodeValPathOfString: typeof decodeValPathOfString;
6
8
  };
7
9
  };
@@ -0,0 +1,2 @@
1
+ import { ValEncodedString } from "@valbuild/react/stega";
2
+ export declare function raw(encodedString: ValEncodedString): string;
@@ -5,7 +5,11 @@ Object.defineProperty(exports, '__esModule', { value: true });
5
5
  var core = require('@valbuild/core');
6
6
  var internal = require('@valbuild/react/internal');
7
7
  var ValNextProvider = require('./ValNextProvider-49d2bec1.cjs.dev.js');
8
+ var NextImage = require('next/image');
8
9
  var stega = require('@valbuild/react/stega');
10
+ var jsxRuntime = require('react/jsx-runtime');
11
+
12
+ function _interopDefault (e) { return e && e.__esModule ? e : { 'default': e }; }
9
13
 
10
14
  function _interopNamespace(e) {
11
15
  if (e && e.__esModule) return e;
@@ -26,6 +30,7 @@ function _interopNamespace(e) {
26
30
  }
27
31
 
28
32
  var core__namespace = /*#__PURE__*/_interopNamespace(core);
33
+ var NextImage__default = /*#__PURE__*/_interopDefault(NextImage);
29
34
 
30
35
  var ValProvider = ValNextProvider.ValNextProvider;
31
36
 
@@ -82,6 +87,74 @@ function _objectSpread2(e) {
82
87
  return e;
83
88
  }
84
89
 
90
+ function _objectWithoutPropertiesLoose(source, excluded) {
91
+ if (source == null) return {};
92
+ var target = {};
93
+ var sourceKeys = Object.keys(source);
94
+ var key, i;
95
+ for (i = 0; i < sourceKeys.length; i++) {
96
+ key = sourceKeys[i];
97
+ if (excluded.indexOf(key) >= 0) continue;
98
+ target[key] = source[key];
99
+ }
100
+ return target;
101
+ }
102
+
103
+ function _objectWithoutProperties(source, excluded) {
104
+ if (source == null) return {};
105
+ var target = _objectWithoutPropertiesLoose(source, excluded);
106
+ var key, i;
107
+ if (Object.getOwnPropertySymbols) {
108
+ var sourceSymbolKeys = Object.getOwnPropertySymbols(source);
109
+ for (i = 0; i < sourceSymbolKeys.length; i++) {
110
+ key = sourceSymbolKeys[i];
111
+ if (excluded.indexOf(key) >= 0) continue;
112
+ if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue;
113
+ target[key] = source[key];
114
+ }
115
+ }
116
+ return target;
117
+ }
118
+
119
+ function raw(encodedString) {
120
+ return stega.stegaClean(encodedString);
121
+ }
122
+
123
+ function decodeValPathOfString(encodedString) {
124
+ return stega.stegaDecodeString(encodedString);
125
+ }
126
+
127
+ var _excluded = ["src", "alt", "style", "width", "height"];
128
+ function ValImage(props) {
129
+ var _src$metadata, _src$metadata2, _src$metadata3;
130
+ var src = props.src,
131
+ alt = props.alt,
132
+ style = props.style,
133
+ width = props.width,
134
+ height = props.height,
135
+ rest = _objectWithoutProperties(props, _excluded);
136
+ var valPathOfUrl = decodeValPathOfString(src.url);
137
+ var valPaths = [valPathOfUrl];
138
+ var maybeValPathOfAlt = decodeValPathOfString(alt);
139
+ if (maybeValPathOfAlt) {
140
+ valPaths.push(maybeValPathOfAlt);
141
+ }
142
+ var hotspot = (_src$metadata = src.metadata) === null || _src$metadata === void 0 ? void 0 : _src$metadata.hotspot;
143
+ var imageStyle = hotspot ? _objectSpread2(_objectSpread2({}, style), {}, {
144
+ objectPosition: "".concat(hotspot.x * 100, "% ").concat(hotspot.y * 100, "%")
145
+ }) : style;
146
+ return /*#__PURE__*/jsxRuntime.jsx(NextImage__default["default"], _objectSpread2(_objectSpread2({}, rest), {}, {
147
+ src: valPathOfUrl ? raw(src.url) : src.url,
148
+ "data-val-path": valPaths.join(","),
149
+ "data-val-attr-alt": maybeValPathOfAlt,
150
+ "data-val-attr-src": valPathOfUrl,
151
+ style: imageStyle,
152
+ alt: raw(alt),
153
+ width: width || ((_src$metadata2 = src.metadata) === null || _src$metadata2 === void 0 ? void 0 : _src$metadata2.width),
154
+ height: height || ((_src$metadata3 = src.metadata) === null || _src$metadata3 === void 0 ? void 0 : _src$metadata3.height)
155
+ }));
156
+ }
157
+
85
158
  var initVal = function initVal(config) {
86
159
  var _createValSystem = core.initVal(),
87
160
  s = _createValSystem.s,
@@ -93,9 +166,8 @@ var initVal = function initVal(config) {
93
166
  return {
94
167
  s: s,
95
168
  val: _objectSpread2(_objectSpread2({}, val), {}, {
96
- raw: function raw(encodedString) {
97
- return stega.stegaClean(encodedString);
98
- }
169
+ decodeValPathOfString: decodeValPathOfString,
170
+ raw: raw
99
171
  }),
100
172
  config: currentConfig
101
173
  };
@@ -133,5 +205,6 @@ Object.defineProperty(exports, 'ValRichText', {
133
205
  enumerable: true,
134
206
  get: function () { return internal.ValRichText; }
135
207
  });
208
+ exports.ValImage = ValImage;
136
209
  exports.ValProvider = ValProvider;
137
210
  exports.initVal = initVal;
@@ -5,7 +5,11 @@ Object.defineProperty(exports, '__esModule', { value: true });
5
5
  var core = require('@valbuild/core');
6
6
  var internal = require('@valbuild/react/internal');
7
7
  var ValNextProvider = require('./ValNextProvider-7750e412.cjs.prod.js');
8
+ var NextImage = require('next/image');
8
9
  var stega = require('@valbuild/react/stega');
10
+ var jsxRuntime = require('react/jsx-runtime');
11
+
12
+ function _interopDefault (e) { return e && e.__esModule ? e : { 'default': e }; }
9
13
 
10
14
  function _interopNamespace(e) {
11
15
  if (e && e.__esModule) return e;
@@ -26,6 +30,7 @@ function _interopNamespace(e) {
26
30
  }
27
31
 
28
32
  var core__namespace = /*#__PURE__*/_interopNamespace(core);
33
+ var NextImage__default = /*#__PURE__*/_interopDefault(NextImage);
29
34
 
30
35
  var ValProvider = ValNextProvider.ValNextProvider;
31
36
 
@@ -82,6 +87,74 @@ function _objectSpread2(e) {
82
87
  return e;
83
88
  }
84
89
 
90
+ function _objectWithoutPropertiesLoose(source, excluded) {
91
+ if (source == null) return {};
92
+ var target = {};
93
+ var sourceKeys = Object.keys(source);
94
+ var key, i;
95
+ for (i = 0; i < sourceKeys.length; i++) {
96
+ key = sourceKeys[i];
97
+ if (excluded.indexOf(key) >= 0) continue;
98
+ target[key] = source[key];
99
+ }
100
+ return target;
101
+ }
102
+
103
+ function _objectWithoutProperties(source, excluded) {
104
+ if (source == null) return {};
105
+ var target = _objectWithoutPropertiesLoose(source, excluded);
106
+ var key, i;
107
+ if (Object.getOwnPropertySymbols) {
108
+ var sourceSymbolKeys = Object.getOwnPropertySymbols(source);
109
+ for (i = 0; i < sourceSymbolKeys.length; i++) {
110
+ key = sourceSymbolKeys[i];
111
+ if (excluded.indexOf(key) >= 0) continue;
112
+ if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue;
113
+ target[key] = source[key];
114
+ }
115
+ }
116
+ return target;
117
+ }
118
+
119
+ function raw(encodedString) {
120
+ return stega.stegaClean(encodedString);
121
+ }
122
+
123
+ function decodeValPathOfString(encodedString) {
124
+ return stega.stegaDecodeString(encodedString);
125
+ }
126
+
127
+ var _excluded = ["src", "alt", "style", "width", "height"];
128
+ function ValImage(props) {
129
+ var _src$metadata, _src$metadata2, _src$metadata3;
130
+ var src = props.src,
131
+ alt = props.alt,
132
+ style = props.style,
133
+ width = props.width,
134
+ height = props.height,
135
+ rest = _objectWithoutProperties(props, _excluded);
136
+ var valPathOfUrl = decodeValPathOfString(src.url);
137
+ var valPaths = [valPathOfUrl];
138
+ var maybeValPathOfAlt = decodeValPathOfString(alt);
139
+ if (maybeValPathOfAlt) {
140
+ valPaths.push(maybeValPathOfAlt);
141
+ }
142
+ var hotspot = (_src$metadata = src.metadata) === null || _src$metadata === void 0 ? void 0 : _src$metadata.hotspot;
143
+ var imageStyle = hotspot ? _objectSpread2(_objectSpread2({}, style), {}, {
144
+ objectPosition: "".concat(hotspot.x * 100, "% ").concat(hotspot.y * 100, "%")
145
+ }) : style;
146
+ return /*#__PURE__*/jsxRuntime.jsx(NextImage__default["default"], _objectSpread2(_objectSpread2({}, rest), {}, {
147
+ src: valPathOfUrl ? raw(src.url) : src.url,
148
+ "data-val-path": valPaths.join(","),
149
+ "data-val-attr-alt": maybeValPathOfAlt,
150
+ "data-val-attr-src": valPathOfUrl,
151
+ style: imageStyle,
152
+ alt: raw(alt),
153
+ width: width || ((_src$metadata2 = src.metadata) === null || _src$metadata2 === void 0 ? void 0 : _src$metadata2.width),
154
+ height: height || ((_src$metadata3 = src.metadata) === null || _src$metadata3 === void 0 ? void 0 : _src$metadata3.height)
155
+ }));
156
+ }
157
+
85
158
  var initVal = function initVal(config) {
86
159
  var _createValSystem = core.initVal(),
87
160
  s = _createValSystem.s,
@@ -93,9 +166,8 @@ var initVal = function initVal(config) {
93
166
  return {
94
167
  s: s,
95
168
  val: _objectSpread2(_objectSpread2({}, val), {}, {
96
- raw: function raw(encodedString) {
97
- return stega.stegaClean(encodedString);
98
- }
169
+ decodeValPathOfString: decodeValPathOfString,
170
+ raw: raw
99
171
  }),
100
172
  config: currentConfig
101
173
  };
@@ -133,5 +205,6 @@ Object.defineProperty(exports, 'ValRichText', {
133
205
  enumerable: true,
134
206
  get: function () { return internal.ValRichText; }
135
207
  });
208
+ exports.ValImage = ValImage;
136
209
  exports.ValProvider = ValProvider;
137
210
  exports.initVal = initVal;
@@ -4,7 +4,9 @@ export { core as expr };
4
4
  export { FILE_REF_PROP, GenericSelector, Schema, VAL_EXTENSION, derefPatch } from '@valbuild/core';
5
5
  export { ValRichText } from '@valbuild/react/internal';
6
6
  import { ValNextProvider } from './ValNextProvider-c5c9fcb0.esm.js';
7
- import { stegaClean, autoTagJSX } from '@valbuild/react/stega';
7
+ import NextImage from 'next/image';
8
+ import { stegaClean, stegaDecodeString, autoTagJSX } from '@valbuild/react/stega';
9
+ import { jsx } from 'react/jsx-runtime';
8
10
 
9
11
  var ValProvider = ValNextProvider;
10
12
 
@@ -61,6 +63,74 @@ function _objectSpread2(e) {
61
63
  return e;
62
64
  }
63
65
 
66
+ function _objectWithoutPropertiesLoose(source, excluded) {
67
+ if (source == null) return {};
68
+ var target = {};
69
+ var sourceKeys = Object.keys(source);
70
+ var key, i;
71
+ for (i = 0; i < sourceKeys.length; i++) {
72
+ key = sourceKeys[i];
73
+ if (excluded.indexOf(key) >= 0) continue;
74
+ target[key] = source[key];
75
+ }
76
+ return target;
77
+ }
78
+
79
+ function _objectWithoutProperties(source, excluded) {
80
+ if (source == null) return {};
81
+ var target = _objectWithoutPropertiesLoose(source, excluded);
82
+ var key, i;
83
+ if (Object.getOwnPropertySymbols) {
84
+ var sourceSymbolKeys = Object.getOwnPropertySymbols(source);
85
+ for (i = 0; i < sourceSymbolKeys.length; i++) {
86
+ key = sourceSymbolKeys[i];
87
+ if (excluded.indexOf(key) >= 0) continue;
88
+ if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue;
89
+ target[key] = source[key];
90
+ }
91
+ }
92
+ return target;
93
+ }
94
+
95
+ function raw(encodedString) {
96
+ return stegaClean(encodedString);
97
+ }
98
+
99
+ function decodeValPathOfString(encodedString) {
100
+ return stegaDecodeString(encodedString);
101
+ }
102
+
103
+ var _excluded = ["src", "alt", "style", "width", "height"];
104
+ function ValImage(props) {
105
+ var _src$metadata, _src$metadata2, _src$metadata3;
106
+ var src = props.src,
107
+ alt = props.alt,
108
+ style = props.style,
109
+ width = props.width,
110
+ height = props.height,
111
+ rest = _objectWithoutProperties(props, _excluded);
112
+ var valPathOfUrl = decodeValPathOfString(src.url);
113
+ var valPaths = [valPathOfUrl];
114
+ var maybeValPathOfAlt = decodeValPathOfString(alt);
115
+ if (maybeValPathOfAlt) {
116
+ valPaths.push(maybeValPathOfAlt);
117
+ }
118
+ var hotspot = (_src$metadata = src.metadata) === null || _src$metadata === void 0 ? void 0 : _src$metadata.hotspot;
119
+ var imageStyle = hotspot ? _objectSpread2(_objectSpread2({}, style), {}, {
120
+ objectPosition: "".concat(hotspot.x * 100, "% ").concat(hotspot.y * 100, "%")
121
+ }) : style;
122
+ return /*#__PURE__*/jsx(NextImage, _objectSpread2(_objectSpread2({}, rest), {}, {
123
+ src: valPathOfUrl ? raw(src.url) : src.url,
124
+ "data-val-path": valPaths.join(","),
125
+ "data-val-attr-alt": maybeValPathOfAlt,
126
+ "data-val-attr-src": valPathOfUrl,
127
+ style: imageStyle,
128
+ alt: raw(alt),
129
+ width: width || ((_src$metadata2 = src.metadata) === null || _src$metadata2 === void 0 ? void 0 : _src$metadata2.width),
130
+ height: height || ((_src$metadata3 = src.metadata) === null || _src$metadata3 === void 0 ? void 0 : _src$metadata3.height)
131
+ }));
132
+ }
133
+
64
134
  var initVal = function initVal(config) {
65
135
  var _createValSystem = initVal$1(),
66
136
  s = _createValSystem.s,
@@ -72,9 +142,8 @@ var initVal = function initVal(config) {
72
142
  return {
73
143
  s: s,
74
144
  val: _objectSpread2(_objectSpread2({}, val), {}, {
75
- raw: function raw(encodedString) {
76
- return stegaClean(encodedString);
77
- }
145
+ decodeValPathOfString: decodeValPathOfString,
146
+ raw: raw
78
147
  }),
79
148
  config: currentConfig
80
149
  };
@@ -87,4 +156,4 @@ autoTagJSX();
87
156
 
88
157
  // Convenience types
89
158
 
90
- export { ValProvider, initVal };
159
+ export { ValImage, ValProvider, initVal };
package/package.json CHANGED
@@ -8,7 +8,7 @@
8
8
  "next",
9
9
  "react"
10
10
  ],
11
- "version": "0.44.0",
11
+ "version": "0.45.0",
12
12
  "scripts": {
13
13
  "typecheck": "tsc --noEmit",
14
14
  "test": "jest"
@@ -45,9 +45,9 @@
45
45
  "exports": true
46
46
  },
47
47
  "dependencies": {
48
- "@valbuild/core": "~0.44.0",
49
- "@valbuild/react": "~0.44.0",
50
- "@valbuild/server": "~0.44.0",
48
+ "@valbuild/core": "~0.45.0",
49
+ "@valbuild/react": "~0.45.0",
50
+ "@valbuild/server": "~0.45.0",
51
51
  "client-only": "^0.0.1",
52
52
  "server-only": "^0.0.1"
53
53
  },