@devvit/ui-renderer 0.10.15-next-2024-02-14-907fed6d4.0 → 0.10.15-next-2024-02-15-f7c48ffbb.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.
@@ -1 +1 @@
1
- {"version":3,"file":"renderImageBlock.d.ts","sourceRoot":"","sources":["../../../library/src/blocks/templates/renderImageBlock.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,KAAK,EAAE,MAAM,gBAAgB,CAAC;AASvC,OAAO,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AACnD,OAAO,EAAyD,YAAY,EAAE,MAAM,WAAW,CAAC;AAKhG,wBAAgB,gBAAgB,CAAC,KAAK,EAAE,KAAK,EAAE,GAAG,EAAE,aAAa,GAAG,YAAY,CA0D/E"}
1
+ {"version":3,"file":"renderImageBlock.d.ts","sourceRoot":"","sources":["../../../library/src/blocks/templates/renderImageBlock.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,KAAK,EAAE,MAAM,gBAAgB,CAAC;AASvC,OAAO,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AACnD,OAAO,EAA6B,YAAY,EAAE,MAAM,WAAW,CAAC;AASpE,wBAAgB,gBAAgB,CAAC,KAAK,EAAE,KAAK,EAAE,GAAG,EAAE,aAAa,GAAG,YAAY,CA0D/E"}
@@ -1,8 +1,8 @@
1
1
  import { nothing } from 'lit';
2
2
  import { getTemplateRenderingStrategy } from '@reddit/faceplate-ui/faceplateUIConfig.js';
3
3
  import { defaultClasses, defaultStyles, imageClasses, imageStyle, onClickAction, } from '../attributes.js';
4
- import { classMap, isDataUrl, isValidImageURL, sanitizeDataUrl } from './util.js';
5
- import { VerifiedPublicImageHosts } from './constants.js';
4
+ import { classMap, sanitizeDataUrl } from './util.js';
5
+ import { VerifiedPublicImageHosts, isDataUrl, isValidImageURL, } from '@devvit/shared-types/imageUtil.js';
6
6
  const FALLBACK_IMG_URL = 'https://i.redd.it/p1vmc5ulmpib1.png';
7
7
  export function renderImageBlock(block, ctx) {
8
8
  const { html, styleMap, ifDefined } = getTemplateRenderingStrategy();
@@ -16,19 +16,10 @@ export declare function resolveIcon(name: string): TemplateResult;
16
16
  * @param styleInfo
17
17
  */
18
18
  export declare function sanitizeStyleInfo(styleInfo: StyleInfo): StyleInfo;
19
- export declare function isDataUrl(input: string): boolean;
20
- export declare function parseDataUrl(dataUrl: string): {
21
- mimeType: string | undefined;
22
- charset: string | undefined;
23
- isBase64: boolean;
24
- data: string;
25
- } | null;
26
19
  /**
27
20
  * Only supports SVG elements!
28
21
  */
29
22
  export declare function sanitizeDataUrl(dataUrl: string): string | undefined;
30
- export declare function isAcceptableDataUrl(maybeDataUrl: string): boolean;
31
- export declare function isValidImageURL(imageUrl: string): boolean;
32
23
  /**
33
24
  * Returns a BlockSizes object either directly from the block or constructs
34
25
  * one from the legacy `size` field
@@ -1 +1 @@
1
- {"version":3,"file":"util.d.ts","sourceRoot":"","sources":["../../../library/src/blocks/templates/util.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,cAAc,EAAE,MAAM,KAAK,CAAC;AAC9C,OAAO,KAAK,EAAE,cAAc,EAAE,eAAe,EAAE,MAAM,kBAAkB,CAAC;AACxE,OAAO,EAAE,SAAS,EAAE,QAAQ,IAAI,cAAc,EAAE,MAAM,6BAA6B,CAAC;AACpF,OAAO,EAAE,GAAG,IAAI,SAAS,EAAE,aAAa,EAAE,MAAM,uBAAuB,CAAC;AACxE,OAAO,EAAE,SAAS,EAAE,MAAM,6BAA6B,CAAC;AAGxD,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,gCAAgC,CAAC;AAKnE,OAAO,EACL,KAAK,EACL,UAAU,EACV,UAAU,EACV,0BAA0B,EAC1B,aAAa,EACd,MAAM,gBAAgB,CAAC;AAGxB,MAAM,MAAM,YAAY,GAAG,cAAc,GAAG,OAAO,OAAO,CAAC;AAE3D,wBAAgB,QAAQ,CACtB,SAAS,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C,OAAO,SAAS,CAAC,GAAG,MAAM,CAM7E;AAED,wBAAgB,aAAa,CAAC,EAAE,EAAE,WAAW,GAAG,OAAO,GAAG,SAAS,GAAG,EAAE,IAAI,WAAW,CAEtF;AAED,wBAAgB,WAAW,CAAC,IAAI,EAAE,MAAM,GAAG,cAAc,CAiBxD;AAED;;;GAGG;AACH,wBAAgB,iBAAiB,CAAC,SAAS,EAAE,SAAS,GAAG,SAAS,CASjE;AAED;;GAEG;AACH,wBAAgB,eAAe,CAAC,OAAO,EAAE,MAAM,GAAG,MAAM,GAAG,SAAS,CAmDnE;AAED;;;;GAIG;AACH,wBAAgB,QAAQ,CAAC,KAAK,EAAE,KAAK,GAAG,UAAU,GAAG,SAAS,CA2B7D;AAED,wBAAgB,cAAc,CAC5B,KAAK,EAAE,0BAA0B,GAAG,SAAS,EAC7C,QAAQ,GAAE,aAAa,GAAG,SAAqB,GAC9C,MAAM,GAAG,SAAS,CAKpB;AAED,wBAAgB,YAAY,CAAC,IAAI,EAAE,aAAa,GAAG,SAAS,GAAG,MAAM,CAUpE;AAED;;;;;;;;;GASG;AACH,wBAAgB,aAAa,CAC3B,MAAM,EAAE,UAAU,GAAG,SAAS,EAC9B,WAAW,CAAC,EAAE,MAAM,GAAG,SAAS,GAC/B,CAAC,KAAK,CAAC,EAAE,MAAM,GAAG,SAAS,EAAE,IAAI,CAAC,EAAE,MAAM,GAAG,SAAS,CAAC,CAIzD"}
@@ -4,9 +4,9 @@ import { unsafeHTML as clientUnsafeHTML } from 'lit/directives/unsafe-html.js';
4
4
  import { unsafeHTML as serverUnsafeHTML } from '@reddit/baseplate/html/html.js';
5
5
  import { getTemplateRenderingStrategy } from '@reddit/faceplate-ui/faceplateUIConfig.js';
6
6
  import faceplateIcons from '@reddit/faceplate-ui/svgs/svg-manifest.js';
7
- import { REDD_IT, VerifiedImageHosts } from './constants.js';
8
7
  import { BlockSizeUnit, } from '@devvit/protos';
9
8
  import { sanitizeSvg } from '@devvit/shared-types/sanitizeSvg.js';
9
+ import { parseDataUrl, isAcceptableDataUrlMimeType } from '@devvit/shared-types/imageUtil.js';
10
10
  export function classMap(classInfo, forceString) {
11
11
  const { getType } = getTemplateRenderingStrategy();
12
12
  if (getType() === 'client' && forceString !== true) {
@@ -73,30 +73,6 @@ export function sanitizeStyleInfo(styleInfo) {
73
73
  }
74
74
  return styleInfo;
75
75
  }
76
- const DATA_URL_REGEX =
77
- // eslint-disable-next-line security/detect-unsafe-regex
78
- /^data:([a-zA-Z]+\/[a-zA-Z0-9.+_-]+)?(;charset=[a-zA-Z0-9._+-]+)?(;base64)?,(.*)/;
79
- function preprocessDataUrl(input) {
80
- /**
81
- * This can be submitted to us as multi-line and that will break the parser
82
- * so we remove all newlines here
83
- */
84
- return input.trim().replace(/[\r\n]+/g, '');
85
- }
86
- export function isDataUrl(input) {
87
- return !!preprocessDataUrl(input).match(DATA_URL_REGEX);
88
- }
89
- export function parseDataUrl(dataUrl) {
90
- const matches = DATA_URL_REGEX.exec(preprocessDataUrl(dataUrl));
91
- if (!matches)
92
- return null;
93
- return {
94
- mimeType: matches[1],
95
- charset: matches[2]?.split('=')[1], // Extract charset without ';charset='
96
- isBase64: !!matches[3],
97
- data: matches[4].trim(),
98
- };
99
- }
100
76
  /**
101
77
  * Only supports SVG elements!
102
78
  */
@@ -148,31 +124,6 @@ export function sanitizeDataUrl(dataUrl) {
148
124
  return undefined;
149
125
  }
150
126
  }
151
- function isAcceptableDataUrlMimeType(mimeType) {
152
- // https://developer.mozilla.org/en-US/docs/Web/HTTP/Basics_of_HTTP/MIME_types#image_types
153
- const ACCEPTABLE_MIME_TYPES = ['image/svg+xml'];
154
- return ACCEPTABLE_MIME_TYPES.includes(mimeType);
155
- }
156
- export function isAcceptableDataUrl(maybeDataUrl) {
157
- const parsedDataUrl = parseDataUrl(maybeDataUrl);
158
- if (!parsedDataUrl?.mimeType)
159
- return false;
160
- return isAcceptableDataUrlMimeType(parsedDataUrl.mimeType);
161
- }
162
- export function isValidImageURL(imageUrl) {
163
- try {
164
- if (isAcceptableDataUrl(imageUrl))
165
- return true;
166
- // The second "base" param helps to handle relative paths to local files
167
- // https://developer.mozilla.org/en-US/docs/Web/API/URL/URL#parameters
168
- const hostName = new URL(imageUrl, `https://i.${REDD_IT}`)?.hostname;
169
- const tld = hostName.split('.').slice(-2).join('.');
170
- return Boolean(tld) && VerifiedImageHosts.includes(tld);
171
- }
172
- catch (_) {
173
- return false;
174
- }
175
- }
176
127
  /**
177
128
  * Returns a BlockSizes object either directly from the block or constructs
178
129
  * one from the legacy `size` field
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@devvit/ui-renderer",
3
- "version": "0.10.15-next-2024-02-14-907fed6d4.0",
3
+ "version": "0.10.15-next-2024-02-15-f7c48ffbb.0",
4
4
  "license": "BSD-3-Clause",
5
5
  "repository": {
6
6
  "type": "git",
@@ -54,10 +54,10 @@
54
54
  },
55
55
  "types": "./index.d.ts",
56
56
  "dependencies": {
57
- "@devvit/protos": "0.10.15-next-2024-02-14-907fed6d4.0",
58
- "@devvit/runtime-lite": "0.10.15-next-2024-02-14-907fed6d4.0",
59
- "@devvit/runtimes": "0.10.15-next-2024-02-14-907fed6d4.0",
60
- "@devvit/shared-types": "0.10.15-next-2024-02-14-907fed6d4.0",
57
+ "@devvit/protos": "0.10.15-next-2024-02-15-f7c48ffbb.0",
58
+ "@devvit/runtime-lite": "0.10.15-next-2024-02-15-f7c48ffbb.0",
59
+ "@devvit/runtimes": "0.10.15-next-2024-02-15-f7c48ffbb.0",
60
+ "@devvit/shared-types": "0.10.15-next-2024-02-15-f7c48ffbb.0",
61
61
  "@dotlottie/player-component": "2.7.2",
62
62
  "p-queue": "7.3.4",
63
63
  "rxjs": "7.5.7"
@@ -84,7 +84,7 @@
84
84
  "devDependencies": {
85
85
  "@devvit/eslint-config": "0.10.14",
86
86
  "@devvit/repo-tools": "0.10.14",
87
- "@devvit/tsconfig": "0.10.15-next-2024-02-14-907fed6d4.0",
87
+ "@devvit/tsconfig": "0.10.15-next-2024-02-15-f7c48ffbb.0",
88
88
  "@lit-labs/ssr": "^2.2.3",
89
89
  "@lit/localize": "0.11.4",
90
90
  "@open-wc/testing-helpers": "2.3.0",
@@ -116,5 +116,5 @@
116
116
  "directory": "dist"
117
117
  },
118
118
  "source": "./src/index.ts",
119
- "gitHead": "285cceeb37015a6859c3770be4e4e02be3f34570"
119
+ "gitHead": "3f84c335d9c69b040e20a5b29c74a3533fe31164"
120
120
  }
@@ -1,7 +0,0 @@
1
- export declare const REDD_IT = "redd.it";
2
- export declare const REDDIT_STATIC = "redditstatic.com";
3
- export declare const REDDIT_MEDIA = "redditmedia.com";
4
- export declare const SNOO_DEV = "snoo.dev";
5
- export declare const VerifiedPublicImageHosts: string[];
6
- export declare const VerifiedImageHosts: string[];
7
- //# sourceMappingURL=constants.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"constants.d.ts","sourceRoot":"","sources":["../../../library/src/blocks/templates/constants.ts"],"names":[],"mappings":"AACA,eAAO,MAAM,OAAO,YAAY,CAAC;AACjC,eAAO,MAAM,aAAa,qBAAqB,CAAC;AAChD,eAAO,MAAM,YAAY,oBAAoB,CAAC;AAC9C,eAAO,MAAM,QAAQ,aAAa,CAAC;AAEnC,eAAO,MAAM,wBAAwB,UAAyC,CAAC;AAC/E,eAAO,MAAM,kBAAkB,UAAmD,CAAC"}
@@ -1,7 +0,0 @@
1
- // Only the following domains are approved: redd.it, redditstatic.com, redditmedia.com, or snoo.dev
2
- export const REDD_IT = 'redd.it';
3
- export const REDDIT_STATIC = 'redditstatic.com';
4
- export const REDDIT_MEDIA = 'redditmedia.com';
5
- export const SNOO_DEV = 'snoo.dev';
6
- export const VerifiedPublicImageHosts = [REDD_IT, REDDIT_STATIC, REDDIT_MEDIA];
7
- export const VerifiedImageHosts = [SNOO_DEV, REDD_IT, REDDIT_STATIC, REDDIT_MEDIA];