@devvit/ui-renderer 0.9.4 → 0.9.6

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.
Files changed (65) hide show
  1. package/blocks/attributes.d.ts +2 -0
  2. package/blocks/attributes.d.ts.map +1 -1
  3. package/blocks/attributes.js +42 -9
  4. package/blocks/components/devvit-blocks-renderer.d.ts +15 -0
  5. package/blocks/components/devvit-blocks-renderer.d.ts.map +1 -0
  6. package/blocks/components/devvit-blocks-renderer.js +42 -0
  7. package/blocks/components/devvit-blocks-webview.d.ts.map +1 -1
  8. package/blocks/index.d.ts.map +1 -1
  9. package/blocks/templates/index.d.ts.map +1 -1
  10. package/blocks/templates/renderAnimationBlock.d.ts +1 -0
  11. package/blocks/templates/renderAnimationBlock.d.ts.map +1 -1
  12. package/blocks/templates/renderAnimationBlock.js +1 -0
  13. package/blocks/templates/renderAvatarBlock.d.ts.map +1 -1
  14. package/blocks/templates/renderBlock.d.ts.map +1 -1
  15. package/blocks/templates/renderButtonBlock.d.ts.map +1 -1
  16. package/blocks/templates/renderButtonBlock.js +8 -4
  17. package/blocks/templates/renderContext.d.ts.map +1 -1
  18. package/blocks/templates/renderFullSnooBlock.d.ts.map +1 -1
  19. package/blocks/templates/renderIconBlock.d.ts.map +1 -1
  20. package/blocks/templates/renderIconBlock.js +16 -5
  21. package/blocks/templates/renderImageBlock.d.ts.map +1 -1
  22. package/blocks/templates/renderSpacerBlock.d.ts.map +1 -1
  23. package/blocks/templates/renderStackBlock.d.ts.map +1 -1
  24. package/blocks/templates/renderStackBlock.js +3 -1
  25. package/blocks/templates/renderTextBlock.d.ts.map +1 -1
  26. package/blocks/templates/renderTextBlock.js +5 -5
  27. package/blocks/templates/renderWebViewBlock.d.ts.map +1 -1
  28. package/blocks/templates/util.d.ts +21 -0
  29. package/blocks/templates/util.d.ts.map +1 -1
  30. package/blocks/templates/util.js +96 -7
  31. package/client/blocks.d.ts.map +1 -1
  32. package/client/devvit-animation-player.d.ts.map +1 -1
  33. package/client/devvit-custom-post.d.ts +7 -2
  34. package/client/devvit-custom-post.d.ts.map +1 -1
  35. package/client/devvit-custom-post.js +18 -29
  36. package/client/effects/devvit-effect-handler.d.ts.map +1 -1
  37. package/client/effects/form-effect-handler.d.ts.map +1 -1
  38. package/client/effects/toast-effect-handler.d.ts.map +1 -1
  39. package/client/formbuilder/components/devvit-form-selection-dropdown.d.ts.map +1 -1
  40. package/client/formbuilder/components/devvit-form-selection-dropdown.js +11 -1
  41. package/client/formbuilder/components/devvit-form-selection-list.d.ts.map +1 -1
  42. package/client/formbuilder/devvit-form-dialog.d.ts.map +1 -1
  43. package/client/formbuilder/fields/index.d.ts.map +1 -1
  44. package/client/formbuilder/fields/renderBooleanField.d.ts.map +1 -1
  45. package/client/formbuilder/fields/renderFieldLabel.d.ts.map +1 -1
  46. package/client/formbuilder/fields/renderFormFields.d.ts.map +1 -1
  47. package/client/formbuilder/fields/renderGroupField.d.ts.map +1 -1
  48. package/client/formbuilder/fields/renderHelpText.d.ts.map +1 -1
  49. package/client/formbuilder/fields/renderListField.d.ts.map +1 -1
  50. package/client/formbuilder/fields/renderNumberField.d.ts.map +1 -1
  51. package/client/formbuilder/fields/renderParagraphField.d.ts.map +1 -1
  52. package/client/formbuilder/fields/renderSelectionField.d.ts.map +1 -1
  53. package/client/formbuilder/fields/renderStringField.d.ts.map +1 -1
  54. package/client/formbuilder/index.d.ts.map +1 -1
  55. package/custom-styles.css +36 -0
  56. package/index.d.ts.map +1 -1
  57. package/package.json +43 -24
  58. package/server/blocks.d.ts.map +1 -1
  59. package/styles.d.ts.map +1 -1
  60. package/styles.js +1 -1
  61. package/types/events.d.ts.map +1 -1
  62. package/client/assets/snooBlocks.d.ts +0 -2
  63. package/client/assets/snooBlocks.d.ts.map +0 -1
  64. package/client/assets/snooBlocks.js +0 -2
  65. package/styles.css +0 -804
@@ -3,6 +3,7 @@ import { StyleInfo } from 'lit/directives/style-map.js';
3
3
  import { ButtonAppearance, ButtonSize } from '@reddit/faceplate-ui/templates/button.js';
4
4
  import { Block, BlockAlignment, BlockAvatarFacing, BlockAvatarSize, BlockBorder, BlockButtonAppearance, BlockButtonSize, BlockFullSnooSize, BlockGap, BlockIconSize, BlockImageResizeMode, BlockPadding, BlockRadius, BlockSize, BlockSpacerSize, BlockStackDirection, BlockTextOutline, BlockTextSize, BlockTextWeight, BlockType } from '@devvit/protos';
5
5
  import { RenderContext } from './templates/renderContext.js';
6
+ import { ref as clientRef } from 'lit/directives/ref.js';
6
7
  export declare function defaultClasses(type: BlockType): ClassInfo;
7
8
  export declare function stackDirectionClass(direction: BlockStackDirection, reverse: boolean | undefined): ClassInfo;
8
9
  export declare function stackChildClass(parentDirection: BlockStackDirection): ClassInfo;
@@ -29,4 +30,5 @@ export declare function fullSnooSizeClass(size: BlockFullSnooSize | undefined):
29
30
  export declare function buttonAppearance(appearance: BlockButtonAppearance | undefined): ButtonAppearance;
30
31
  export declare function buttonSize(size: BlockButtonSize | undefined): ButtonSize;
31
32
  export declare function onClickAction(block: Block, ctx: RenderContext): (() => void) | undefined;
33
+ export declare function setTextOutline(thickness: BlockTextOutline | undefined): ReturnType<typeof clientRef>;
32
34
  //# sourceMappingURL=attributes.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"attributes.d.ts","sourceRoot":"","sources":["../../src/blocks/attributes.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,6BAA6B,CAAC;AACxD,OAAO,EAAE,SAAS,EAAE,MAAM,6BAA6B,CAAC;AAExD,OAAO,EAAE,gBAAgB,EAAE,UAAU,EAAE,MAAM,0CAA0C,CAAC;AAExF,OAAO,EACL,KAAK,EAEL,cAAc,EACd,iBAAiB,EACjB,eAAe,EACf,WAAW,EAEX,qBAAqB,EACrB,eAAe,EACf,iBAAiB,EACjB,QAAQ,EAER,aAAa,EACb,oBAAoB,EACpB,YAAY,EACZ,WAAW,EACX,SAAS,EACT,eAAe,EACf,mBAAmB,EAC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AI,CAAC,GAAG,SAAS,CASxF;AAED,wBAAgB,cAAc,CAC5B,SAAS,EAAE,gBAAgB,GAAG,SAAS,GACtC,UAAU,CAAC,OAAO,SAAS,CAAC,CAqC9B"}
@@ -1,10 +1,7 @@
1
1
  import { ButtonSize } from '@reddit/faceplate-ui/templates/button.js';
2
2
  import { BlockActionType, BlockAvatarFacing, BlockAvatarSize, BlockBorderWidth, BlockButtonAppearance, BlockButtonSize, BlockFullSnooSize, BlockGap, BlockHorizontalAlignment, BlockIconSize, BlockImageResizeMode, BlockPadding, BlockRadius, BlockSpacerSize, BlockStackDirection, BlockTextOutline, BlockTextSize, BlockTextWeight, BlockType, BlockVerticalAlignment, } from '@devvit/protos';
3
- function findColor(color) {
4
- // TODO: check CSS for color var and wrap in var(--color-${background}-background)
5
- // - will need access to shadow root
6
- return color;
7
- }
3
+ import { nothing } from '@reddit/baseplate/html.js';
4
+ import { brightnessByColor, isHTMLElement, ref } from './templates/util.js';
8
5
  export function defaultClasses(type) {
9
6
  return {
10
7
  'overflow-hidden': type === BlockType.BLOCK_ROOT || type === BlockType.BLOCK_STACK,
@@ -91,7 +88,7 @@ export function alignmentClass(direction, align) {
91
88
  }
92
89
  export function backgroundStyle(background) {
93
90
  return {
94
- backgroundColor: findColor(background),
91
+ backgroundColor: background ?? '',
95
92
  };
96
93
  }
97
94
  export function borderClass(border) {
@@ -109,7 +106,7 @@ export function borderClass(border) {
109
106
  }
110
107
  export function borderStyle(border) {
111
108
  return {
112
- borderColor: border?.color, // TODO: check CSS for color var and wrap in var(--color-${border.color}-background)
109
+ borderColor: border?.color ?? '',
113
110
  };
114
111
  }
115
112
  export function radiusClass(radius) {
@@ -149,7 +146,6 @@ export function textWeightClass(weight) {
149
146
  export function textOutlineClass(outline, _textColor) {
150
147
  const thin = outline === BlockTextOutline.TEXT_OUTLINE_THIN;
151
148
  const thick = outline === BlockTextOutline.TEXT_OUTLINE_THICK;
152
- // TODO: hook into host lit element to determine final color and apply bright/dark outline
153
149
  return {
154
150
  'text-outline-thin-bright': thin,
155
151
  'text-outline-thick-bright': thick,
@@ -157,7 +153,7 @@ export function textOutlineClass(outline, _textColor) {
157
153
  }
158
154
  export function colorStyle(color) {
159
155
  return {
160
- color: findColor(color),
156
+ color: color ?? '',
161
157
  };
162
158
  }
163
159
  export function spacerSizeClass(size, stackDirection) {
@@ -285,3 +281,40 @@ export function onClickAction(block, ctx) {
285
281
  };
286
282
  }
287
283
  }
284
+ export function setTextOutline(thickness) {
285
+ let thicknessClass;
286
+ switch (thickness) {
287
+ case BlockTextOutline.TEXT_OUTLINE_THIN:
288
+ thicknessClass = 'thin';
289
+ break;
290
+ case BlockTextOutline.TEXT_OUTLINE_THICK:
291
+ thicknessClass = 'thick';
292
+ break;
293
+ default:
294
+ return nothing;
295
+ }
296
+ return ref((el) => {
297
+ if (isHTMLElement(el)) {
298
+ let retry = true;
299
+ const apply = () => {
300
+ const color = window.getComputedStyle(el).color;
301
+ if (!color && retry) {
302
+ retry = false;
303
+ window.setTimeout(() => apply(), 0);
304
+ return;
305
+ }
306
+ const brightness =
307
+ // eslint-disable-next-line @reddit/i18n-shreddit/no-unwrapped-strings
308
+ brightnessByColor(color) > 127 ? 'bright' : 'dark';
309
+ el.classList.forEach((name) => {
310
+ if (name.startsWith('text-outline-')) {
311
+ el.classList.remove(name);
312
+ }
313
+ });
314
+ el.classList.add(`text-outline-${thicknessClass}-${brightness}`);
315
+ };
316
+ apply();
317
+ window.matchMedia('(prefers-color-scheme: dark)').onchange = () => apply();
318
+ }
319
+ });
320
+ }
@@ -0,0 +1,15 @@
1
+ import { LitElement } from 'lit';
2
+ import { Block } from '@devvit/protos';
3
+ import type { RenderContext } from '../templates/renderContext.js';
4
+ export declare class DevvitBlocksRenderer extends LitElement {
5
+ block: Block | undefined;
6
+ renderContext: () => RenderContext;
7
+ static get styles(): import("lit").CSSResult[];
8
+ render(): import("@reddit/baseplate/html.js").TemplateLike;
9
+ }
10
+ declare global {
11
+ interface HTMLElementTagNameMap {
12
+ 'devvit-blocks-renderer': DevvitBlocksRenderer;
13
+ }
14
+ }
15
+ //# sourceMappingURL=devvit-blocks-renderer.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"devvit-blocks-renderer.d.ts","sourceRoot":"","sources":["../../../library/src/blocks/components/devvit-blocks-renderer.ts"],"names":[],"mappings":"AAAA,OAAO,EAAQ,UAAU,EAAE,MAAM,KAAK,CAAC;AAMvC,OAAO,EAAE,KAAK,EAAkC,MAAM,gBAAgB,CAAC;AAGvE,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,+BAA+B,CAAC;AAInE,qBAEa,oBAAqB,SAAQ,UAAU;IAElD,KAAK,EAAE,KAAK,GAAG,SAAS,CAAC;IAGzB,aAAa,EAAE,MAAM,aAAa,CAAgE;IAElG,WAAoB,MAAM,8BAEzB;IAEQ,MAAM;CAahB;AAED,OAAO,CAAC,MAAM,CAAC;IACb,UAAU,qBAAqB;QAC7B,wBAAwB,EAAE,oBAAoB,CAAC;KAChD;CACF"}
@@ -0,0 +1,42 @@
1
+ import { __decorate, __metadata } from "tslib";
2
+ import { html, LitElement } from 'lit';
3
+ import { customElement, property } from 'lit/decorators.js';
4
+ import { localized, msg } from '@lit/localize';
5
+ import { emptyState } from '@reddit/faceplate-ui/templates/empty-state.js';
6
+ import { BlockStackDirection, BlockType } from '@devvit/protos';
7
+ import { renderBlocks } from '../templates/index.js';
8
+ import { styles } from '../../styles.js';
9
+ let DevvitBlocksRenderer = class DevvitBlocksRenderer extends LitElement {
10
+ constructor() {
11
+ super(...arguments);
12
+ this.renderContext = () => ({ stackDirection: BlockStackDirection.UNRECOGNIZED });
13
+ }
14
+ static get styles() {
15
+ return [styles];
16
+ }
17
+ render() {
18
+ if (this.block && this.block.type === BlockType.BLOCK_ROOT) {
19
+ return renderBlocks(this.block, this.renderContext());
20
+ }
21
+ return html `${emptyState({
22
+ creative: html `<slot name="empty-state-image"></slot>`,
23
+ title: msg('Whoops!', { desc: 'Header for message to display when rendering fails' }),
24
+ description: msg('Something went wrong while attempting to display this content.', {
25
+ desc: 'Message for users to display when rendering fails',
26
+ }),
27
+ })}`;
28
+ }
29
+ };
30
+ __decorate([
31
+ property({ attribute: false }),
32
+ __metadata("design:type", Object)
33
+ ], DevvitBlocksRenderer.prototype, "block", void 0);
34
+ __decorate([
35
+ property({ attribute: false }),
36
+ __metadata("design:type", Function)
37
+ ], DevvitBlocksRenderer.prototype, "renderContext", void 0);
38
+ DevvitBlocksRenderer = __decorate([
39
+ localized(),
40
+ customElement('devvit-blocks-renderer')
41
+ ], DevvitBlocksRenderer);
42
+ export { DevvitBlocksRenderer };
@@ -1 +1 @@
1
- {"version":3,"file":"devvit-blocks-webview.d.ts","sourceRoot":"","sources":["../../../src/blocks/components/devvit-blocks-webview.ts"],"names":[],"mappings":""}
1
+ {"version":3,"file":"devvit-blocks-webview.d.ts","sourceRoot":"","sources":["../../../library/src/blocks/components/devvit-blocks-webview.ts"],"names":[],"mappings":""}
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/blocks/index.ts"],"names":[],"mappings":";AAEA,cAAc,sBAAsB,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../library/src/blocks/index.ts"],"names":[],"mappings":";AAEA,cAAc,sBAAsB,CAAC"}
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/blocks/templates/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,kBAAkB,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../library/src/blocks/templates/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,kBAAkB,CAAC"}
@@ -1,5 +1,6 @@
1
1
  import { Block } from '@devvit/protos';
2
2
  import { TemplateLike } from '@reddit/baseplate/html.js';
3
+ import '../../client/devvit-animation-player.js';
3
4
  import { RenderContext } from './renderContext.js';
4
5
  export declare function renderAnimationBlock(block: Block, ctx: RenderContext): TemplateLike;
5
6
  //# sourceMappingURL=renderAnimationBlock.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"renderAnimationBlock.d.ts","sourceRoot":"","sources":["../../../src/blocks/templates/renderAnimationBlock.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,gBAAgB,CAAC;AAEvC,OAAO,EAAW,YAAY,EAAE,MAAM,2BAA2B,CAAC;AAUlE,OAAO,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AAGnD,wBAAgB,oBAAoB,CAAC,KAAK,EAAE,KAAK,EAAE,GAAG,EAAE,aAAa,GAAG,YAAY,CA6BnF"}
1
+ {"version":3,"file":"renderAnimationBlock.d.ts","sourceRoot":"","sources":["../../../library/src/blocks/templates/renderAnimationBlock.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,gBAAgB,CAAC;AAEvC,OAAO,EAAW,YAAY,EAAE,MAAM,2BAA2B,CAAC;AAGlE,OAAO,yCAAyC,CAAC;AASjD,OAAO,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AAGnD,wBAAgB,oBAAoB,CAAC,KAAK,EAAE,KAAK,EAAE,GAAG,EAAE,aAAa,GAAG,YAAY,CA6BnF"}
@@ -1,5 +1,6 @@
1
1
  import { nothing } from '@reddit/baseplate/html.js';
2
2
  import { getTemplateRenderingStrategy } from '@reddit/faceplate-ui/faceplateUIConfig.js';
3
+ import '../../client/devvit-animation-player.js';
3
4
  import { defaultClasses, onClickAction, sizingClass, sizingStyle, stackChildClass, } from '../attributes.js';
4
5
  import { classMap } from './util.js';
5
6
  export function renderAnimationBlock(block, ctx) {
@@ -1 +1 @@
1
- {"version":3,"file":"renderAvatarBlock.d.ts","sourceRoot":"","sources":["../../../src/blocks/templates/renderAvatarBlock.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,gBAAgB,CAAC;AAEvC,OAAO,EAAW,YAAY,EAAE,MAAM,2BAA2B,CAAC;AAYlE,OAAO,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AAGnD,wBAAgB,iBAAiB,CAAC,KAAK,EAAE,KAAK,EAAE,GAAG,EAAE,aAAa,GAAG,YAAY,CA6BhF"}
1
+ {"version":3,"file":"renderAvatarBlock.d.ts","sourceRoot":"","sources":["../../../library/src/blocks/templates/renderAvatarBlock.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,gBAAgB,CAAC;AAEvC,OAAO,EAAW,YAAY,EAAE,MAAM,2BAA2B,CAAC;AAYlE,OAAO,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AAGnD,wBAAgB,iBAAiB,CAAC,KAAK,EAAE,KAAK,EAAE,GAAG,EAAE,aAAa,GAAG,YAAY,CA6BhF"}
@@ -1 +1 @@
1
- {"version":3,"file":"renderBlock.d.ts","sourceRoot":"","sources":["../../../src/blocks/templates/renderBlock.ts"],"names":[],"mappings":"AAAA,OAAO,EAAW,YAAY,EAAE,MAAM,2BAA2B,CAAC;AAGlE,OAAO,EAAE,KAAK,EAAkC,MAAM,gBAAgB,CAAC;AAYvE,OAAO,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AAEnD,wBAAgB,YAAY,CAAC,KAAK,EAAE,KAAK,EAAE,OAAO,GAAE,OAAO,CAAC,aAAa,CAAM,GAAG,YAAY,CAsB7F;AAED,wBAAgB,WAAW,CAAC,KAAK,EAAE,KAAK,EAAE,GAAG,EAAE,aAAa,GAAG,YAAY,CA+C1E"}
1
+ {"version":3,"file":"renderBlock.d.ts","sourceRoot":"","sources":["../../../library/src/blocks/templates/renderBlock.ts"],"names":[],"mappings":"AAAA,OAAO,EAAW,YAAY,EAAE,MAAM,2BAA2B,CAAC;AAGlE,OAAO,EAAE,KAAK,EAAkC,MAAM,gBAAgB,CAAC;AAYvE,OAAO,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AAEnD,wBAAgB,YAAY,CAAC,KAAK,EAAE,KAAK,EAAE,OAAO,GAAE,OAAO,CAAC,aAAa,CAAM,GAAG,YAAY,CAsB7F;AAED,wBAAgB,WAAW,CAAC,KAAK,EAAE,KAAK,EAAE,GAAG,EAAE,aAAa,GAAG,YAAY,CA+C1E"}
@@ -1 +1 @@
1
- {"version":3,"file":"renderButtonBlock.d.ts","sourceRoot":"","sources":["../../../src/blocks/templates/renderButtonBlock.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAgB,MAAM,2BAA2B,CAAC;AAKvE,OAAO,EAAE,KAAK,EAAE,MAAM,gBAAgB,CAAC;AAYvC,OAAO,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AAGnD,wBAAgB,iBAAiB,CAAC,KAAK,EAAE,KAAK,EAAE,GAAG,EAAE,aAAa,GAAG,YAAY,CAkChF"}
1
+ {"version":3,"file":"renderButtonBlock.d.ts","sourceRoot":"","sources":["../../../library/src/blocks/templates/renderButtonBlock.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAgB,MAAM,2BAA2B,CAAC;AAKvE,OAAO,EAAE,KAAK,EAAE,MAAM,gBAAgB,CAAC;AAYvC,OAAO,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AAGnD,wBAAgB,iBAAiB,CAAC,KAAK,EAAE,KAAK,EAAE,GAAG,EAAE,aAAa,GAAG,YAAY,CAuChF"}
@@ -1,11 +1,11 @@
1
1
  import { getTemplateRenderingStrategy } from '@reddit/faceplate-ui/faceplateUIConfig.js';
2
2
  import { button } from '@reddit/faceplate-ui/templates/button.js';
3
3
  import { styleMap } from '@reddit/faceplate-ui/templateUtils/styleMap.js';
4
- import { buttonAppearance, buttonSize, colorStyle, defaultClasses, onClickAction, sizingClass, stackChildClass, } from '../attributes.js';
5
- import { classMap } from './util.js';
4
+ import { buttonAppearance, buttonSize, colorStyle, defaultClasses, onClickAction, sizingClass, sizingStyle, stackChildClass, } from '../attributes.js';
5
+ import { classMap, resolveIcon } from './util.js';
6
6
  export function renderButtonBlock(block, ctx) {
7
7
  const { html, ifDefined } = getTemplateRenderingStrategy();
8
- // let buttonIcon = block.config?.buttonConfig?.icon;
8
+ const buttonIcon = block.config?.buttonConfig?.icon;
9
9
  const disabled = block.config?.buttonConfig?.disabled === true;
10
10
  const classes = {
11
11
  ...defaultClasses(block.type),
@@ -14,14 +14,18 @@ export function renderButtonBlock(block, ctx) {
14
14
  };
15
15
  const styles = {
16
16
  ...colorStyle(block.config?.buttonConfig?.textColor),
17
+ ...sizingStyle(block.size),
17
18
  // not available in all platforms yet
18
19
  // ...backgroundStyle(block.config?.buttonConfig?.backgroundColor),
19
20
  };
20
21
  const onClick = onClickAction(block, ctx);
22
+ const iconSvg = buttonIcon ? resolveIcon(buttonIcon) : undefined;
23
+ const icon = iconSvg ? { leadingIcon: iconSvg } : {};
24
+ // TODO: correctColor
21
25
  return html `${button({
22
26
  size: buttonSize(block.config?.buttonConfig?.buttonSize),
23
27
  appearance: buttonAppearance(block.config?.buttonConfig?.buttonAppearance),
24
- // leadingIcon: findIcon(buttonIcon),
28
+ ...icon,
25
29
  children: ifDefined(block.config?.buttonConfig?.text),
26
30
  attributes: {
27
31
  disabled,
@@ -1 +1 @@
1
- {"version":3,"file":"renderContext.d.ts","sourceRoot":"","sources":["../../../src/blocks/templates/renderContext.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,kBAAkB,EAAE,mBAAmB,EAAE,MAAM,gBAAgB,CAAC;AAEtF,MAAM,WAAW,aAAa;IAC5B,OAAO,CAAC,EAAE,kBAAkB,GAAG,SAAS,CAAC;IACzC,KAAK,CAAC,EAAE,OAAO,GAAG,SAAS,CAAC;IAC5B,cAAc,EAAE,mBAAmB,CAAC;IACpC,QAAQ,CAAC,EAAE,CAAC,CAAC,MAAM,EAAE,WAAW,KAAK,IAAI,CAAC,GAAG,SAAS,CAAC;CACxD"}
1
+ {"version":3,"file":"renderContext.d.ts","sourceRoot":"","sources":["../../../library/src/blocks/templates/renderContext.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,kBAAkB,EAAE,mBAAmB,EAAE,MAAM,gBAAgB,CAAC;AAEtF,MAAM,WAAW,aAAa;IAC5B,OAAO,CAAC,EAAE,kBAAkB,GAAG,SAAS,CAAC;IACzC,KAAK,CAAC,EAAE,OAAO,GAAG,SAAS,CAAC;IAC5B,cAAc,EAAE,mBAAmB,CAAC;IACpC,QAAQ,CAAC,EAAE,CAAC,CAAC,MAAM,EAAE,WAAW,KAAK,IAAI,CAAC,GAAG,SAAS,CAAC;CACxD"}
@@ -1 +1 @@
1
- {"version":3,"file":"renderFullSnooBlock.d.ts","sourceRoot":"","sources":["../../../src/blocks/templates/renderFullSnooBlock.ts"],"names":[],"mappings":"AAAA,OAAO,EAAW,YAAY,EAAE,MAAM,2BAA2B,CAAC;AAGlE,OAAO,EAAE,KAAK,EAAE,MAAM,gBAAgB,CAAC;AAWvC,OAAO,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AAGnD,wBAAgB,mBAAmB,CAAC,KAAK,EAAE,KAAK,EAAE,GAAG,EAAE,aAAa,GAAG,YAAY,CA6BlF"}
1
+ {"version":3,"file":"renderFullSnooBlock.d.ts","sourceRoot":"","sources":["../../../library/src/blocks/templates/renderFullSnooBlock.ts"],"names":[],"mappings":"AAAA,OAAO,EAAW,YAAY,EAAE,MAAM,2BAA2B,CAAC;AAGlE,OAAO,EAAE,KAAK,EAAE,MAAM,gBAAgB,CAAC;AAWvC,OAAO,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AAGnD,wBAAgB,mBAAmB,CAAC,KAAK,EAAE,KAAK,EAAE,GAAG,EAAE,aAAa,GAAG,YAAY,CA6BlF"}
@@ -1 +1 @@
1
- {"version":3,"file":"renderIconBlock.d.ts","sourceRoot":"","sources":["../../../src/blocks/templates/renderIconBlock.ts"],"names":[],"mappings":"AAAA,OAAO,EAAW,YAAY,EAAE,MAAM,2BAA2B,CAAC;AAGlE,OAAO,EAAE,KAAK,EAAE,MAAM,gBAAgB,CAAC;AASvC,OAAO,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AAGnD,wBAAgB,eAAe,CAAC,KAAK,EAAE,KAAK,EAAE,GAAG,EAAE,aAAa,GAAG,YAAY,CAsB9E"}
1
+ {"version":3,"file":"renderIconBlock.d.ts","sourceRoot":"","sources":["../../../library/src/blocks/templates/renderIconBlock.ts"],"names":[],"mappings":"AAAA,OAAO,EAAW,YAAY,EAAE,MAAM,2BAA2B,CAAC;AAGlE,OAAO,EAAE,KAAK,EAAE,MAAM,gBAAgB,CAAC;AAWvC,OAAO,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AAGnD,wBAAgB,eAAe,CAAC,KAAK,EAAE,KAAK,EAAE,GAAG,EAAE,aAAa,GAAG,YAAY,CAiC9E"}
@@ -1,15 +1,18 @@
1
1
  import { nothing } from '@reddit/baseplate/html.js';
2
2
  import { getTemplateRenderingStrategy } from '@reddit/faceplate-ui/faceplateUIConfig.js';
3
- import { defaultClasses, iconSizeClass, onClickAction, sizingClass, stackChildClass, } from '../attributes.js';
4
- import { classMap } from './util.js';
3
+ import { colorStyle, defaultClasses, iconSizeClass, onClickAction, sizingClass, sizingStyle, stackChildClass, } from '../attributes.js';
4
+ import { classMap, correctColor, resolveIcon } from './util.js';
5
5
  export function renderIconBlock(block, ctx) {
6
- const { html } = getTemplateRenderingStrategy();
6
+ const { html, styleMap, ifDefined } = getTemplateRenderingStrategy();
7
7
  if (!block.config?.iconConfig) {
8
8
  console.error('Invalid block: Icon missing IconConfig');
9
9
  return nothing;
10
10
  }
11
11
  const { icon, size, color } = block.config.iconConfig;
12
- // adopt `icons-all.ts` from faceplate-ui storybook
12
+ const styles = {
13
+ ...colorStyle(color),
14
+ ...sizingStyle(block.size),
15
+ };
13
16
  const classes = {
14
17
  ...defaultClasses(block.type),
15
18
  ...stackChildClass(ctx.stackDirection),
@@ -17,5 +20,13 @@ export function renderIconBlock(block, ctx) {
17
20
  ...iconSizeClass(size),
18
21
  };
19
22
  const onClick = onClickAction(block, ctx);
20
- return html `<div class="${classMap(classes)}" data-debug-block-type="icon"></div>`;
23
+ return html `<div
24
+ class="${classMap(classes)}"
25
+ style="${styleMap(styles)}"
26
+ @click="${ifDefined(onClick)}"
27
+ data-debug-block-type="icon"
28
+ ${correctColor(color, 'color')}
29
+ >
30
+ ${resolveIcon(icon)}
31
+ </div>`;
21
32
  }
@@ -1 +1 @@
1
- {"version":3,"file":"renderImageBlock.d.ts","sourceRoot":"","sources":["../../../src/blocks/templates/renderImageBlock.ts"],"names":[],"mappings":"AAAA,OAAO,EAAW,YAAY,EAAE,MAAM,2BAA2B,CAAC;AAGlE,OAAO,EAAE,KAAK,EAAE,MAAM,gBAAgB,CAAC;AAUvC,OAAO,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AAGnD,wBAAgB,gBAAgB,CAAC,KAAK,EAAE,KAAK,EAAE,GAAG,EAAE,aAAa,GAAG,YAAY,CAkC/E"}
1
+ {"version":3,"file":"renderImageBlock.d.ts","sourceRoot":"","sources":["../../../library/src/blocks/templates/renderImageBlock.ts"],"names":[],"mappings":"AAAA,OAAO,EAAW,YAAY,EAAE,MAAM,2BAA2B,CAAC;AAGlE,OAAO,EAAE,KAAK,EAAE,MAAM,gBAAgB,CAAC;AAUvC,OAAO,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AAGnD,wBAAgB,gBAAgB,CAAC,KAAK,EAAE,KAAK,EAAE,GAAG,EAAE,aAAa,GAAG,YAAY,CAkC/E"}
@@ -1 +1 @@
1
- {"version":3,"file":"renderSpacerBlock.d.ts","sourceRoot":"","sources":["../../../src/blocks/templates/renderSpacerBlock.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,2BAA2B,CAAC;AAGzD,OAAO,EAAE,KAAK,EAAE,MAAM,gBAAgB,CAAC;AASvC,OAAO,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AAGnD,wBAAgB,iBAAiB,CAAC,KAAK,EAAE,KAAK,EAAE,GAAG,EAAE,aAAa,GAAG,YAAY,CAmBhF"}
1
+ {"version":3,"file":"renderSpacerBlock.d.ts","sourceRoot":"","sources":["../../../library/src/blocks/templates/renderSpacerBlock.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,2BAA2B,CAAC;AAGzD,OAAO,EAAE,KAAK,EAAE,MAAM,gBAAgB,CAAC;AASvC,OAAO,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AAGnD,wBAAgB,iBAAiB,CAAC,KAAK,EAAE,KAAK,EAAE,GAAG,EAAE,aAAa,GAAG,YAAY,CAmBhF"}
@@ -1 +1 @@
1
- {"version":3,"file":"renderStackBlock.d.ts","sourceRoot":"","sources":["../../../src/blocks/templates/renderStackBlock.ts"],"names":[],"mappings":"AAAA,OAAO,EAAW,YAAY,EAAE,MAAM,2BAA2B,CAAC;AAGlE,OAAO,EAAE,KAAK,EAAuB,MAAM,gBAAgB,CAAC;AAiB5D,OAAO,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AAGnD,wBAAgB,gBAAgB,CAC9B,KAAK,EAAE,KAAK,EACZ,GAAG,2BAAsE,EACzE,WAAW,EAAE,CAAC,KAAK,EAAE,KAAK,EAAE,GAAG,EAAE,aAAa,KAAK,YAAY,GAC9D,YAAY,CAoEd"}
1
+ {"version":3,"file":"renderStackBlock.d.ts","sourceRoot":"","sources":["../../../library/src/blocks/templates/renderStackBlock.ts"],"names":[],"mappings":"AAAA,OAAO,EAAW,YAAY,EAAE,MAAM,2BAA2B,CAAC;AAGlE,OAAO,EAAE,KAAK,EAAuB,MAAM,gBAAgB,CAAC;AAiB5D,OAAO,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AAGnD,wBAAgB,gBAAgB,CAC9B,KAAK,EAAE,KAAK,EACZ,GAAG,2BAAsE,EACzE,WAAW,EAAE,CAAC,KAAK,EAAE,KAAK,EAAE,GAAG,EAAE,aAAa,KAAK,YAAY,GAC9D,YAAY,CAsEd"}
@@ -2,7 +2,7 @@ import { nothing } from '@reddit/baseplate/html.js';
2
2
  import { getTemplateRenderingStrategy } from '@reddit/faceplate-ui/faceplateUIConfig.js';
3
3
  import { BlockStackDirection } from '@devvit/protos';
4
4
  import { alignmentClass, backgroundStyle, borderClass, borderStyle, defaultClasses, gapClass, onClickAction, paddingClass, radiusClass, sizingClass, sizingStyle, stackChildClass, stackDirectionClass, } from '../attributes.js';
5
- import { classMap } from './util.js';
5
+ import { classMap, correctColor } from './util.js';
6
6
  export function renderStackBlock(block, ctx = { stackDirection: BlockStackDirection.UNRECOGNIZED }, renderBlock) {
7
7
  const { html, repeat, styleMap, ifDefined } = getTemplateRenderingStrategy();
8
8
  if (block.config?.stackConfig === undefined) {
@@ -49,6 +49,8 @@ export function renderStackBlock(block, ctx = { stackDirection: BlockStackDirect
49
49
  style="${styleMap(styles)}"
50
50
  @click="${ifDefined(onClick)}"
51
51
  data-debug-block-type="${blockType}"
52
+ ${correctColor(backgroundColor, 'backgroundColor')}
53
+ ${correctColor(border?.color, 'borderColor')}
52
54
  >
53
55
  ${repeat(children, (block) => renderBlock(block, newCtx))}
54
56
  </div>
@@ -1 +1 @@
1
- {"version":3,"file":"renderTextBlock.d.ts","sourceRoot":"","sources":["../../../src/blocks/templates/renderTextBlock.ts"],"names":[],"mappings":"AAAA,OAAO,EAAW,YAAY,EAAE,MAAM,2BAA2B,CAAC;AAGlE,OAAO,EAAE,KAAK,EAAkD,MAAM,gBAAgB,CAAC;AAavF,OAAO,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AAGnD,wBAAgB,eAAe,CAAC,KAAK,EAAE,KAAK,EAAE,GAAG,EAAE,aAAa,GAAG,YAAY,CA8D9E"}
1
+ {"version":3,"file":"renderTextBlock.d.ts","sourceRoot":"","sources":["../../../library/src/blocks/templates/renderTextBlock.ts"],"names":[],"mappings":"AAAA,OAAO,EAAW,YAAY,EAAE,MAAM,2BAA2B,CAAC;AAGlE,OAAO,EAAE,KAAK,EAAkD,MAAM,gBAAgB,CAAC;AAavF,OAAO,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AAGnD,wBAAgB,eAAe,CAAC,KAAK,EAAE,KAAK,EAAE,GAAG,EAAE,aAAa,GAAG,YAAY,CA6D9E"}
@@ -1,8 +1,8 @@
1
1
  import { nothing } from '@reddit/baseplate/html.js';
2
2
  import { getTemplateRenderingStrategy } from '@reddit/faceplate-ui/faceplateUIConfig.js';
3
3
  import { BlockTextSize, BlockTextStyle, BlockTextWeight } from '@devvit/protos';
4
- import { colorStyle, defaultClasses, onClickAction, sizingClass, stackChildClass, textAlignClass, textOutlineClass, textSizeClass, textWeightClass, } from '../attributes.js';
5
- import { classMap } from './util.js';
4
+ import { colorStyle, defaultClasses, onClickAction, setTextOutline, sizingClass, sizingStyle, stackChildClass, textAlignClass, textSizeClass, textWeightClass, } from '../attributes.js';
5
+ import { classMap, correctColor } from './util.js';
6
6
  export function renderTextBlock(block, ctx) {
7
7
  const { html, styleMap, ifDefined } = getTemplateRenderingStrategy();
8
8
  if (!block.config?.textConfig) {
@@ -37,6 +37,7 @@ export function renderTextBlock(block, ctx) {
37
37
  textWeight = weight ?? textWeight;
38
38
  const styles = {
39
39
  ...colorStyle(textColor),
40
+ ...sizingStyle(block.size),
40
41
  };
41
42
  const classes = {
42
43
  ...defaultClasses(block.type),
@@ -46,15 +47,14 @@ export function renderTextBlock(block, ctx) {
46
47
  ...textAlignClass(alignment),
47
48
  ...textWeightClass(textWeight),
48
49
  };
49
- if (outline !== undefined) {
50
- Object.assign(classes, textOutlineClass(outline, textColor));
51
- }
52
50
  const onClick = onClickAction(block, ctx);
53
51
  return html `<span
54
52
  class="${classMap(classes)}"
55
53
  style="${styleMap(styles)}"
56
54
  @click="${ifDefined(onClick)}"
57
55
  data-debug-block-type="text"
56
+ ${correctColor(textColor, 'color')}
57
+ ${setTextOutline(outline)}
58
58
  >${text}</span
59
59
  >`;
60
60
  }
@@ -1 +1 @@
1
- {"version":3,"file":"renderWebViewBlock.d.ts","sourceRoot":"","sources":["../../../src/blocks/templates/renderWebViewBlock.ts"],"names":[],"mappings":"AAAA,OAAO,EAAW,YAAY,EAAE,MAAM,2BAA2B,CAAC;AAGlE,OAAO,EAAE,KAAK,EAAE,MAAM,gBAAgB,CAAC;AAGvC,OAAO,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AAGnD,OAAO,wCAAwC,CAAC;AAEhD,wBAAgB,kBAAkB,CAAC,KAAK,EAAE,KAAK,EAAE,GAAG,EAAE,aAAa,GAAG,YAAY,CA2BjF"}
1
+ {"version":3,"file":"renderWebViewBlock.d.ts","sourceRoot":"","sources":["../../../library/src/blocks/templates/renderWebViewBlock.ts"],"names":[],"mappings":"AAAA,OAAO,EAAW,YAAY,EAAE,MAAM,2BAA2B,CAAC;AAGlE,OAAO,EAAE,KAAK,EAAE,MAAM,gBAAgB,CAAC;AAGvC,OAAO,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AAGnD,OAAO,wCAAwC,CAAC;AAEhD,wBAAgB,kBAAkB,CAAC,KAAK,EAAE,KAAK,EAAE,GAAG,EAAE,aAAa,GAAG,YAAY,CA2BjF"}
@@ -1,4 +1,25 @@
1
1
  import { ClassInfo, classMap as clientClassMap } from 'lit/directives/class-map.js';
2
+ import { RefOrCallback, ref as clientRef } from 'lit/directives/ref.js';
3
+ import { TemplateResult } from 'lit';
2
4
  import { UnsafeString } from '@reddit/baseplate/html.js';
3
5
  export declare function classMap(classInfo: ClassInfo, forceString?: boolean): UnsafeString | ReturnType<typeof clientClassMap>;
6
+ export declare function unsafeHTML(input: string): import("lit-html/directive.js").DirectiveResult<typeof import("lit-html/directives/unsafe-html.js").UnsafeHTMLDirective>;
7
+ export declare function ref(ref: RefOrCallback): ReturnType<typeof clientRef> | string;
8
+ /**
9
+ * Attach a ref callback to an element that ensures the assigned color is set and
10
+ * attempts to use CSS variables for colors as a fallback
11
+ *
12
+ * @param color The desired color
13
+ * @param attr The attribute name to validate
14
+ */
15
+ export declare function correctColor(color: string | undefined, attr: string): ReturnType<typeof clientRef> | string;
16
+ /**
17
+ * Borrowed from: https://gist.github.com/w3core/e3d9b5b6d69a3ba8671cc84714cca8a4?permalink_comment_id=3125287#gistcomment-3125287
18
+ * Calculate brightness value by RGB or HEX color.
19
+ * @param color (String) The color value in RGB or HEX (for example: #000000 || #000 || rgb(0,0,0) || rgba(0,0,0,0))
20
+ * @returns (Number) The brightness value (dark) 0 ... 255 (light)
21
+ */
22
+ export declare function brightnessByColor(color: string): number;
23
+ export declare function isHTMLElement(el: HTMLElement | Element | undefined): el is HTMLElement;
24
+ export declare function resolveIcon(name: string): TemplateResult;
4
25
  //# sourceMappingURL=util.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"util.d.ts","sourceRoot":"","sources":["../../../src/blocks/templates/util.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,QAAQ,IAAI,cAAc,EAAE,MAAM,6BAA6B,CAAC;AACpF,OAAO,EAAU,YAAY,EAAE,MAAM,2BAA2B,CAAC;AAGjE,wBAAgB,QAAQ,CACtB,SAAS,EAAE,SAAS,EACpB,WAAW,CAAC,EAAE,OAAO,GACpB,YAAY,GAAG,UAAU,CAAC,OAAO,cAAc,CAAC,CAgBlD"}
1
+ {"version":3,"file":"util.d.ts","sourceRoot":"","sources":["../../../library/src/blocks/templates/util.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,QAAQ,IAAI,cAAc,EAAE,MAAM,6BAA6B,CAAC;AAEpF,OAAO,EAAE,aAAa,EAAE,GAAG,IAAI,SAAS,EAAE,MAAM,uBAAuB,CAAC;AACxE,OAAO,EAAE,cAAc,EAAE,MAAM,KAAK,CAAC;AAErC,OAAO,EAA2C,YAAY,EAAE,MAAM,2BAA2B,CAAC;AAKlG,wBAAgB,QAAQ,CACtB,SAAS,EAAE,SAAS,EACpB,WAAW,CAAC,EAAE,OAAO,GACpB,YAAY,GAAG,UAAU,CAAC,OAAO,cAAc,CAAC,CAWlD;AAED,wBAAgB,UAAU,CAAC,KAAK,EAAE,MAAM,4HAMvC;AAED,wBAAgB,GAAG,CAAC,GAAG,EAAE,aAAa,GAAG,UAAU,CAAC,OAAO,SAAS,CAAC,GAAG,MAAM,CAM7E;AAED;;;;;;GAMG;AACH,wBAAgB,YAAY,CAC1B,KAAK,EAAE,MAAM,GAAG,SAAS,EACzB,IAAI,EAAE,MAAM,GACX,UAAU,CAAC,OAAO,SAAS,CAAC,GAAG,MAAM,CAevC;AAED;;;;;GAKG;AACH,wBAAgB,iBAAiB,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,CA4BvD;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,CAYxD"}
@@ -1,17 +1,106 @@
1
1
  import { classMap as clientClassMap } from 'lit/directives/class-map.js';
2
- import { unsafe } from '@reddit/baseplate/html.js';
2
+ import { unsafeHTML as clientUnsafeHTML } from 'lit/directives/unsafe-html.js';
3
+ import { ref as clientRef } from 'lit/directives/ref.js';
4
+ import { unsafeHTML as serverUnsafeHTML } from '@reddit/baseplate/html.js';
3
5
  import { getTemplateRenderingStrategy } from '@reddit/faceplate-ui/faceplateUIConfig.js';
6
+ import faceplateIcons from '@reddit/faceplate-ui/svgs/svg-manifest.js';
4
7
  export function classMap(classInfo, forceString) {
5
8
  const { getType } = getTemplateRenderingStrategy();
6
9
  if (getType() === 'client' && forceString !== true) {
7
10
  return clientClassMap(classInfo);
8
11
  }
9
- let result = '';
10
- for (const name in classInfo) {
11
- if (classInfo[name]) {
12
- result += `${name} `;
12
+ const result = Object.keys(classInfo)
13
+ .filter((className) => classInfo[className])
14
+ .join(' ');
15
+ return serverUnsafeHTML(result);
16
+ }
17
+ export function unsafeHTML(input) {
18
+ const { getType } = getTemplateRenderingStrategy();
19
+ if (getType() === 'client') {
20
+ return clientUnsafeHTML(input);
21
+ }
22
+ return serverUnsafeHTML(input);
23
+ }
24
+ export function ref(ref) {
25
+ const { getType } = getTemplateRenderingStrategy();
26
+ if (getType() === 'client') {
27
+ return clientRef(ref);
28
+ }
29
+ return '';
30
+ }
31
+ /**
32
+ * Attach a ref callback to an element that ensures the assigned color is set and
33
+ * attempts to use CSS variables for colors as a fallback
34
+ *
35
+ * @param color The desired color
36
+ * @param attr The attribute name to validate
37
+ */
38
+ export function correctColor(color, attr) {
39
+ return ref((el) => {
40
+ if (isHTMLElement(el)) {
41
+ if (color && el.style.getPropertyValue(attr) !== color) {
42
+ // try to fall back on a color variable if setting it outright didn't work
43
+ el.style.setProperty(attr, `var(--color-${color})`);
44
+ if (el.style.getPropertyValue(attr) === '') {
45
+ // unset to ensure an old color doesn't stick around if the element was reused
46
+ el.style.setProperty(attr, '');
47
+ }
48
+ }
49
+ else {
50
+ el.style.setProperty(attr, '');
51
+ }
52
+ }
53
+ });
54
+ }
55
+ /**
56
+ * Borrowed from: https://gist.github.com/w3core/e3d9b5b6d69a3ba8671cc84714cca8a4?permalink_comment_id=3125287#gistcomment-3125287
57
+ * Calculate brightness value by RGB or HEX color.
58
+ * @param color (String) The color value in RGB or HEX (for example: #000000 || #000 || rgb(0,0,0) || rgba(0,0,0,0))
59
+ * @returns (Number) The brightness value (dark) 0 ... 255 (light)
60
+ */
61
+ export function brightnessByColor(color) {
62
+ const isHEX = color.indexOf('#') === 0;
63
+ const isRGB = color.indexOf('rgb') === 0;
64
+ let r;
65
+ let g;
66
+ let b;
67
+ if (isHEX) {
68
+ const hasFullSpec = color.length == 7;
69
+ const m = color.substring(1).match(hasFullSpec ? /(\S{2})/g : /(\S)/g);
70
+ if (m) {
71
+ r = parseInt(m[0] + (hasFullSpec ? '' : m[0]), 16);
72
+ g = parseInt(m[1] + (hasFullSpec ? '' : m[1]), 16);
73
+ b = parseInt(m[2] + (hasFullSpec ? '' : m[2]), 16);
74
+ }
75
+ }
76
+ if (isRGB) {
77
+ // eslint-disable-next-line security/detect-unsafe-regex
78
+ const m = color.match(/(\d+){3}/g);
79
+ if (m) {
80
+ r = parseInt(m[0]);
81
+ g = parseInt(m[1]);
82
+ b = parseInt(m[2]);
13
83
  }
14
84
  }
15
- // eslint-disable-next-line @reddit/no-unsafe/no-unsafe-function-usage
16
- return unsafe(result);
85
+ if (r !== undefined && g !== undefined && b !== undefined) {
86
+ return (r * 299 + g * 587 + b * 114) / 1000;
87
+ }
88
+ return 0;
89
+ }
90
+ export function isHTMLElement(el) {
91
+ return el?.style !== undefined;
92
+ }
93
+ export function resolveIcon(name) {
94
+ const { html } = getTemplateRenderingStrategy();
95
+ const fill = name.match(/-fill$/) !== null;
96
+ // clean up icon name
97
+ const iconName = name.replace(/^icon-/, '').replace(/-(fill|outline)$/, '');
98
+ // eslint-disable-next-line @reddit/i18n-shreddit/no-unwrapped-strings
99
+ const icon = faceplateIcons[iconName][fill ? 'fill' : 'outline'];
100
+ if (icon) {
101
+ return html `${unsafeHTML(icon)}`;
102
+ }
103
+ else {
104
+ return html ``;
105
+ }
17
106
  }
@@ -1 +1 @@
1
- {"version":3,"file":"blocks.d.ts","sourceRoot":"","sources":["../../src/client/blocks.ts"],"names":[],"mappings":"AAAA,OAAO,kEAAkE,CAAC;AAC1E,cAAc,oBAAoB,CAAC"}
1
+ {"version":3,"file":"blocks.d.ts","sourceRoot":"","sources":["../../library/src/client/blocks.ts"],"names":[],"mappings":"AAAA,OAAO,kEAAkE,CAAC;AAC1E,cAAc,oBAAoB,CAAC"}
@@ -1 +1 @@
1
- {"version":3,"file":"devvit-animation-player.d.ts","sourceRoot":"","sources":["../../src/client/devvit-animation-player.ts"],"names":[],"mappings":"AAAA,OAAO,EAAQ,UAAU,EAAE,MAAM,KAAK,CAAC;AAEvC,OAAO,EAAE,kBAAkB,EAAE,MAAM,gBAAgB,CAAC;AAEpD,OAAO,4BAA4B,CAAC;AAEpC;;GAEG;AACH,qBACa,qBAAsB,SAAQ,UAAU;IACvB,GAAG,EAAE,MAAM,CAAM;IACjB,IAAI,CAAC,EAAE,kBAAkB,CAAC;IAE7C,MAAM;CAQhB"}
1
+ {"version":3,"file":"devvit-animation-player.d.ts","sourceRoot":"","sources":["../../library/src/client/devvit-animation-player.ts"],"names":[],"mappings":"AAAA,OAAO,EAAQ,UAAU,EAAE,MAAM,KAAK,CAAC;AAEvC,OAAO,EAAE,kBAAkB,EAAE,MAAM,gBAAgB,CAAC;AAEpD,OAAO,4BAA4B,CAAC;AAEpC;;GAEG;AACH,qBACa,qBAAsB,SAAQ,UAAU;IACvB,GAAG,EAAE,MAAM,CAAM;IACjB,IAAI,CAAC,EAAE,kBAAkB,CAAC;IAE7C,MAAM;CAQhB"}
@@ -4,6 +4,7 @@ import type { Metadata } from '@devvit/protos';
4
4
  import { Block, RenderPostResponse } from '@devvit/protos';
5
5
  import type { ActorRef } from '@devvit/runtimes/common/runtime/ActorRef.js';
6
6
  import './devvit-animation-player.js';
7
+ import '../blocks/components/devvit-blocks-renderer.js';
7
8
  declare global {
8
9
  interface HTMLElementTagNameMap {
9
10
  'devvit-custom-post': DevvitCustomPost;
@@ -16,10 +17,14 @@ export declare class DevvitCustomPost extends LitElement {
16
17
  postId?: string;
17
18
  renderResponse?: RenderPostResponse;
18
19
  rootBlock?: Block;
19
- static get styles(): import("lit").CSSResult[];
20
20
  connectedCallback(): void;
21
21
  disconnectedCallback(): void;
22
22
  protected willUpdate(changedProperties: PropertyValues): void;
23
- render(): import("@reddit/baseplate/html.js").TemplateLike;
23
+ render(): import("lit-html").TemplateResult<1>;
24
+ }
25
+ declare global {
26
+ interface HTMLElementTagNameMap {
27
+ 'devvit-custom-post': DevvitCustomPost;
28
+ }
24
29
  }
25
30
  //# sourceMappingURL=devvit-custom-post.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"devvit-custom-post.d.ts","sourceRoot":"","sources":["../../src/client/devvit-custom-post.ts"],"names":[],"mappings":"AAAA,OAAO,EAAQ,UAAU,EAAE,cAAc,EAAE,MAAM,KAAK,CAAC;AAKvD,OAAO,kEAAkE,CAAC;AAI1E,OAAO,KAAK,EAMV,QAAQ,EAIT,MAAM,gBAAgB,CAAC;AACxB,OAAO,EACL,KAAK,EAML,kBAAkB,EAEnB,MAAM,gBAAgB,CAAC;AACxB,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,6CAA6C,CAAC;AAM5E,OAAO,8BAA8B,CAAC;AAEtC,OAAO,CAAC,MAAM,CAAC;IACb,UAAU,qBAAqB;QAC7B,oBAAoB,EAAE,gBAAgB,CAAC;KACxC;CACF;AASD,qBAEa,gBAAiB,SAAQ,UAAU;;IAE9C,QAAQ,CAAC,EAAE,QAAQ,CAAC;IAGpB,QAAQ,CAAC,EAAE,QAAQ,CAAC;IAGpB,MAAM,CAAC,EAAE,MAAM,CAAC;IAGhB,cAAc,CAAC,EAAE,kBAAkB,CAAC;IAGpC,SAAS,CAAC,EAAE,KAAK,CAAC;IAalB,WAAoB,MAAM,8BAEzB;IAMQ,iBAAiB;IAKjB,oBAAoB;cAQV,UAAU,CAAC,iBAAiB,EAAE,cAAc;IAatD,MAAM;CAqGhB"}
1
+ {"version":3,"file":"devvit-custom-post.d.ts","sourceRoot":"","sources":["../../library/src/client/devvit-custom-post.ts"],"names":[],"mappings":"AAAA,OAAO,EAAQ,UAAU,EAAE,cAAc,EAAE,MAAM,KAAK,CAAC;AAIvD,OAAO,kEAAkE,CAAC;AAG1E,OAAO,KAAK,EAMV,QAAQ,EAIT,MAAM,gBAAgB,CAAC;AACxB,OAAO,EACL,KAAK,EAKL,kBAAkB,EAEnB,MAAM,gBAAgB,CAAC;AACxB,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,6CAA6C,CAAC;AAI5E,OAAO,8BAA8B,CAAC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