@builder.io/sdk-react-native 0.0.1-5 → 0.0.1-52

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 (138) hide show
  1. package/CHANGELOG.md +28 -0
  2. package/README.md +15 -0
  3. package/package.json +6 -4
  4. package/src/blocks/button/button.js +31 -0
  5. package/src/blocks/{button.lite.tsx → button/button.lite.tsx} +7 -11
  6. package/src/blocks/button/component-info.js +42 -0
  7. package/src/blocks/columns/columns.js +59 -0
  8. package/src/blocks/columns/columns.lite.tsx +70 -0
  9. package/src/blocks/columns/component-info.js +218 -0
  10. package/src/blocks/custom-code/component-info.js +32 -0
  11. package/src/blocks/custom-code/custom-code.js +50 -0
  12. package/src/blocks/{custom-code.lite.tsx → custom-code/custom-code.lite.tsx} +2 -10
  13. package/src/blocks/embed/component-info.js +25 -0
  14. package/src/blocks/embed/embed.js +50 -0
  15. package/src/blocks/{embed.lite.tsx → embed/embed.lite.tsx} +2 -6
  16. package/src/blocks/form/component-info.js +263 -0
  17. package/src/blocks/form/form.js +221 -0
  18. package/src/blocks/{form.lite.tsx → form/form.lite.tsx} +24 -27
  19. package/src/blocks/fragment/component-info.js +12 -0
  20. package/src/blocks/fragment/fragment.js +8 -0
  21. package/src/blocks/fragment/fragment.lite.tsx +10 -0
  22. package/src/blocks/{image.js → image/component-info.js} +5 -23
  23. package/src/blocks/image/image.js +41 -0
  24. package/src/blocks/image/image.lite.tsx +67 -0
  25. package/src/blocks/img/component-info.js +21 -0
  26. package/src/blocks/img/img.js +36 -0
  27. package/src/blocks/{img.lite.tsx → img/img.lite.tsx} +2 -3
  28. package/src/blocks/input/component-info.js +75 -0
  29. package/src/blocks/input/input.js +36 -0
  30. package/src/blocks/{input.lite.tsx → input/input.lite.tsx} +2 -5
  31. package/src/blocks/raw-text/component-info.js +17 -0
  32. package/src/blocks/raw-text/raw-text.js +10 -0
  33. package/src/blocks/raw-text/raw-text.lite.tsx +6 -0
  34. package/src/blocks/section/component-info.js +50 -0
  35. package/src/blocks/section/section.js +31 -0
  36. package/src/blocks/{section.lite.tsx → section/section.lite.tsx} +1 -2
  37. package/src/blocks/select/component-info.js +60 -0
  38. package/src/blocks/select/select.js +36 -0
  39. package/src/blocks/{select.lite.tsx → select/select.lite.tsx} +6 -7
  40. package/src/blocks/submit-button/component-info.js +29 -0
  41. package/src/blocks/submit-button/submit-button.js +29 -0
  42. package/src/blocks/{submit-button.lite.tsx → submit-button/submit-button.lite.tsx} +1 -2
  43. package/src/blocks/symbol/component-info.js +43 -0
  44. package/src/blocks/symbol/symbol.js +68 -0
  45. package/src/blocks/symbol/symbol.lite.tsx +60 -0
  46. package/src/blocks/{text.js → text/component-info.js} +4 -10
  47. package/src/blocks/text/text.js +65 -0
  48. package/src/blocks/text/text.lite.tsx +6 -0
  49. package/src/blocks/textarea/component-info.js +48 -0
  50. package/src/blocks/textarea/textarea.js +32 -0
  51. package/src/blocks/{textarea.lite.tsx → textarea/textarea.lite.tsx} +0 -1
  52. package/src/blocks/video/component-info.js +107 -0
  53. package/src/blocks/video/video.js +33 -0
  54. package/src/blocks/{video.lite.tsx → video/video.lite.tsx} +0 -1
  55. package/src/components/error-boundary.js +25 -0
  56. package/src/components/error-boundary.lite.tsx +6 -0
  57. package/src/components/render-block/block-styles.js +29 -0
  58. package/src/components/render-block/block-styles.lite.tsx +35 -0
  59. package/src/components/render-block/render-block.helpers.js +24 -0
  60. package/src/components/render-block/render-block.js +116 -0
  61. package/src/components/render-block/render-block.lite.tsx +139 -0
  62. package/src/components/render-blocks.js +14 -7
  63. package/src/components/render-blocks.lite.tsx +18 -9
  64. package/src/components/render-content/components/render-styles.js +58 -0
  65. package/src/components/render-content/components/render-styles.lite.tsx +70 -0
  66. package/src/components/render-content/index.js +5 -0
  67. package/src/components/render-content/render-content.js +254 -0
  68. package/src/components/render-content/render-content.lite.tsx +283 -0
  69. package/src/components/render-inlined-styles.js +18 -0
  70. package/src/components/render-inlined-styles.lite.tsx +31 -0
  71. package/src/constants/builder-registered-components.js +27 -0
  72. package/src/constants/target.js +5 -0
  73. package/src/context/builder.context.js +7 -1
  74. package/src/functions/evaluate.js +17 -8
  75. package/src/functions/event-handler-name.js +8 -0
  76. package/src/functions/fast-clone.js +5 -0
  77. package/src/functions/get-block-actions.js +14 -13
  78. package/src/functions/get-block-component-options.js +17 -1
  79. package/src/functions/get-block-properties.js +7 -4
  80. package/src/functions/get-block-styles.js +31 -1
  81. package/src/functions/get-builder-search-params/fn.test.js +14 -0
  82. package/src/functions/get-builder-search-params/index.js +23 -0
  83. package/src/functions/get-content/fn.test.js +32 -0
  84. package/src/functions/get-content/index.js +139 -0
  85. package/src/functions/get-fetch.js +35 -0
  86. package/src/functions/get-global-this.js +19 -0
  87. package/src/functions/get-processed-block.js +5 -3
  88. package/src/functions/get-processed-block.test.js +13 -8
  89. package/src/functions/if-target.js +11 -2
  90. package/src/functions/is-browser.js +1 -2
  91. package/src/functions/is-editing.js +1 -1
  92. package/src/functions/is-iframe.js +1 -1
  93. package/src/functions/is-previewing.js +15 -0
  94. package/src/functions/is-react-native.js +1 -1
  95. package/src/functions/on-change.test.js +1 -2
  96. package/src/functions/previewing-model-name.js +12 -0
  97. package/src/functions/register-component.js +31 -13
  98. package/src/functions/register.js +30 -0
  99. package/src/functions/set-editor-settings.js +16 -0
  100. package/src/functions/set.test.js +1 -2
  101. package/src/functions/track.js +7 -3
  102. package/src/functions/transform-block.js +38 -0
  103. package/src/index-helpers/blocks-exports.js +19 -0
  104. package/src/index-helpers/top-of-file.js +2 -0
  105. package/src/index.js +10 -23
  106. package/src/scripts/init-editing.js +73 -47
  107. package/src/types/components.js +1 -0
  108. package/src/types/deep-partial.js +1 -0
  109. package/src/types/element.js +1 -0
  110. package/src/types/targets.js +1 -0
  111. package/src/types/typescript.js +1 -0
  112. package/index.js +0 -11
  113. package/src/blocks/button.js +0 -37
  114. package/src/blocks/columns.js +0 -47
  115. package/src/blocks/columns.lite.tsx +0 -46
  116. package/src/blocks/custom-code.js +0 -56
  117. package/src/blocks/embed.js +0 -56
  118. package/src/blocks/form.js +0 -229
  119. package/src/blocks/image.lite.tsx +0 -35
  120. package/src/blocks/img.js +0 -41
  121. package/src/blocks/input.js +0 -41
  122. package/src/blocks/raw-text.js +0 -17
  123. package/src/blocks/raw-text.lite.tsx +0 -12
  124. package/src/blocks/section.js +0 -36
  125. package/src/blocks/select.js +0 -40
  126. package/src/blocks/submit-button.js +0 -34
  127. package/src/blocks/symbol.js +0 -20
  128. package/src/blocks/symbol.lite.tsx +0 -20
  129. package/src/blocks/text.lite.tsx +0 -12
  130. package/src/blocks/textarea.js +0 -37
  131. package/src/blocks/video.js +0 -49
  132. package/src/components/render-block.js +0 -84
  133. package/src/components/render-block.lite.tsx +0 -92
  134. package/src/components/render-content.js +0 -66
  135. package/src/components/render-content.lite.tsx +0 -95
  136. package/src/functions/get-content.js +0 -103
  137. package/src/functions/get-target.js +0 -7
  138. package/src/package.json +0 -18
@@ -0,0 +1,24 @@
1
+ import * as React from 'react';
2
+ const EMPTY_HTML_ELEMENTS = [
3
+ "area",
4
+ "base",
5
+ "br",
6
+ "col",
7
+ "embed",
8
+ "hr",
9
+ "img",
10
+ "input",
11
+ "keygen",
12
+ "link",
13
+ "meta",
14
+ "param",
15
+ "source",
16
+ "track",
17
+ "wbr"
18
+ ];
19
+ const isEmptyHtmlElement = (tagName) => {
20
+ return typeof tagName === "string" && EMPTY_HTML_ELEMENTS.includes(tagName.toLowerCase());
21
+ };
22
+ export {
23
+ isEmptyHtmlElement
24
+ };
@@ -0,0 +1,116 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __defProps = Object.defineProperties;
3
+ var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
4
+ var __getOwnPropSymbols = Object.getOwnPropertySymbols;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __propIsEnum = Object.prototype.propertyIsEnumerable;
7
+ var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
8
+ var __spreadValues = (a, b) => {
9
+ for (var prop in b || (b = {}))
10
+ if (__hasOwnProp.call(b, prop))
11
+ __defNormalProp(a, prop, b[prop]);
12
+ if (__getOwnPropSymbols)
13
+ for (var prop of __getOwnPropSymbols(b)) {
14
+ if (__propIsEnum.call(b, prop))
15
+ __defNormalProp(a, prop, b[prop]);
16
+ }
17
+ return a;
18
+ };
19
+ var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
20
+ import * as React from "react";
21
+ import { useContext } from "react";
22
+ import { TARGET } from "../../constants/target.js";
23
+ import BuilderContext from "../../context/builder.context";
24
+ import { getBlockActions } from "../../functions/get-block-actions.js";
25
+ import { getBlockComponentOptions } from "../../functions/get-block-component-options.js";
26
+ import { getBlockProperties } from "../../functions/get-block-properties.js";
27
+ import { getBlockStyles } from "../../functions/get-block-styles.js";
28
+ import { getBlockTag } from "../../functions/get-block-tag.js";
29
+ import { getProcessedBlock } from "../../functions/get-processed-block.js";
30
+ import BlockStyles from "./block-styles.js";
31
+ import { isEmptyHtmlElement } from "./render-block.helpers.js";
32
+ function RenderBlock(props) {
33
+ var _a, _b, _c, _d;
34
+ function component() {
35
+ var _a2;
36
+ const componentName = (_a2 = useBlock().component) == null ? void 0 : _a2.name;
37
+ if (!componentName) {
38
+ return null;
39
+ }
40
+ const ref = builderContext.registeredComponents[componentName];
41
+ if (!ref) {
42
+ console.warn(`
43
+ Could not find a registered component named "${componentName}".
44
+ If you registered it, is the file that registered it imported by the file that needs to render it?`);
45
+ return void 0;
46
+ } else {
47
+ return ref;
48
+ }
49
+ }
50
+ function componentInfo() {
51
+ var _a2;
52
+ return (_a2 = component == null ? void 0 : component()) == null ? void 0 : _a2.info;
53
+ }
54
+ function componentRef() {
55
+ var _a2;
56
+ return (_a2 = component == null ? void 0 : component()) == null ? void 0 : _a2.component;
57
+ }
58
+ function tagName() {
59
+ return getBlockTag(useBlock());
60
+ }
61
+ function useBlock() {
62
+ return getProcessedBlock({
63
+ block: props.block,
64
+ state: builderContext.state,
65
+ context: builderContext.context
66
+ });
67
+ }
68
+ function propertiesAndActions() {
69
+ return __spreadValues(__spreadValues({}, getBlockProperties(useBlock())), getBlockActions({
70
+ block: useBlock(),
71
+ state: builderContext.state,
72
+ context: builderContext.context
73
+ }));
74
+ }
75
+ function css() {
76
+ return getBlockStyles(useBlock());
77
+ }
78
+ function componentOptions() {
79
+ return getBlockComponentOptions(useBlock());
80
+ }
81
+ function children() {
82
+ var _a2;
83
+ return (_a2 = useBlock().children) != null ? _a2 : [];
84
+ }
85
+ function noCompRefChildren() {
86
+ return componentRef() ? [] : children();
87
+ }
88
+ const builderContext = useContext(BuilderContext);
89
+ const ComponentRefRef = componentRef();
90
+ const TagNameRef = tagName();
91
+ return /* @__PURE__ */ React.createElement(React.Fragment, null, !((_a = componentInfo == null ? void 0 : componentInfo()) == null ? void 0 : _a.noWrap) ? /* @__PURE__ */ React.createElement(React.Fragment, null, !isEmptyHtmlElement(tagName()) ? /* @__PURE__ */ React.createElement(React.Fragment, null, /* @__PURE__ */ React.createElement(TagNameRef, __spreadProps(__spreadValues({}, propertiesAndActions()), {
92
+ style: css()
93
+ }), TARGET === "vue" || TARGET === "svelte" ? /* @__PURE__ */ React.createElement(React.Fragment, null, /* @__PURE__ */ React.createElement(BlockStyles, {
94
+ block: useBlock()
95
+ })) : null, componentRef() ? /* @__PURE__ */ React.createElement(ComponentRefRef, __spreadProps(__spreadValues({}, componentOptions()), {
96
+ builderBlock: useBlock()
97
+ }), (_b = children()) == null ? void 0 : _b.map((child) => /* @__PURE__ */ React.createElement(RenderBlock, {
98
+ key: child.id,
99
+ block: child
100
+ }))) : null, (_c = noCompRefChildren()) == null ? void 0 : _c.map((child) => /* @__PURE__ */ React.createElement(RenderBlock, {
101
+ key: child.id,
102
+ block: child
103
+ })))) : /* @__PURE__ */ React.createElement(TagNameRef, __spreadProps(__spreadValues({}, propertiesAndActions()), {
104
+ style: css()
105
+ }))) : /* @__PURE__ */ React.createElement(ComponentRefRef, __spreadProps(__spreadValues({}, componentOptions()), {
106
+ attributes: propertiesAndActions(),
107
+ builderBlock: useBlock(),
108
+ style: css()
109
+ }), (_d = children()) == null ? void 0 : _d.map((child) => /* @__PURE__ */ React.createElement(RenderBlock, {
110
+ key: child.id,
111
+ block: child
112
+ }))));
113
+ }
114
+ export {
115
+ RenderBlock as default
116
+ };
@@ -0,0 +1,139 @@
1
+ import * as React from "react";
2
+ import { View, StyleSheet, Image, Text } from "react-native";
3
+ import { useContext } from "react";
4
+ import { TARGET } from "../../constants/target.js";
5
+ import BuilderContext from "../../context/builder.context";
6
+ import { getBlockActions } from "../../functions/get-block-actions.js";
7
+ import { getBlockComponentOptions } from "../../functions/get-block-component-options.js";
8
+ import { getBlockProperties } from "../../functions/get-block-properties.js";
9
+ import { getBlockStyles } from "../../functions/get-block-styles.js";
10
+ import { getBlockTag } from "../../functions/get-block-tag.js";
11
+ import { getProcessedBlock } from "../../functions/get-processed-block.js";
12
+ import BlockStyles from "./block-styles.lite";
13
+ import { isEmptyHtmlElement } from "./render-block.helpers.js";
14
+
15
+ export default function RenderBlock(props) {
16
+ function component() {
17
+ const componentName = useBlock().component?.name;
18
+
19
+ if (!componentName) {
20
+ return null;
21
+ }
22
+
23
+ const ref = builderContext.registeredComponents[componentName];
24
+
25
+ if (!ref) {
26
+ // TODO: Public doc page with more info about this message
27
+ console.warn(`
28
+ Could not find a registered component named "${componentName}".
29
+ If you registered it, is the file that registered it imported by the file that needs to render it?`);
30
+ return undefined;
31
+ } else {
32
+ return ref;
33
+ }
34
+ }
35
+
36
+ function componentInfo() {
37
+ return component?.()?.info;
38
+ }
39
+
40
+ function componentRef() {
41
+ return component?.()?.component;
42
+ }
43
+
44
+ function tagName() {
45
+ return getBlockTag(useBlock());
46
+ }
47
+
48
+ function useBlock() {
49
+ return getProcessedBlock({
50
+ block: props.block,
51
+ state: builderContext.state,
52
+ context: builderContext.context,
53
+ });
54
+ }
55
+
56
+ function propertiesAndActions() {
57
+ return {
58
+ ...getBlockProperties(useBlock()),
59
+ ...getBlockActions({
60
+ block: useBlock(),
61
+ state: builderContext.state,
62
+ context: builderContext.context,
63
+ }),
64
+ };
65
+ }
66
+
67
+ function css() {
68
+ return getBlockStyles(useBlock());
69
+ }
70
+
71
+ function componentOptions() {
72
+ return getBlockComponentOptions(useBlock());
73
+ }
74
+
75
+ function children() {
76
+ // TO-DO: When should `canHaveChildren` dictate rendering?
77
+ // This is currently commented out because some Builder components (e.g. Box) do not have `canHaveChildren: true`,
78
+ // but still receive and need to render children.
79
+ // return componentInfo?.()?.canHaveChildren ? useBlock().children : [];
80
+ return useBlock().children ?? [];
81
+ }
82
+
83
+ function noCompRefChildren() {
84
+ return componentRef() ? [] : children();
85
+ }
86
+
87
+ const builderContext = useContext(BuilderContext);
88
+
89
+ const ComponentRefRef = componentRef();
90
+ const TagNameRef = tagName();
91
+
92
+ return (
93
+ <>
94
+ {!componentInfo?.()?.noWrap ? (
95
+ <>
96
+ {!isEmptyHtmlElement(tagName()) ? (
97
+ <>
98
+ <TagNameRef {...propertiesAndActions()} style={css()}>
99
+ {TARGET === "vue" || TARGET === "svelte" ? (
100
+ <>
101
+ <BlockStyles block={useBlock()} />
102
+ </>
103
+ ) : null}
104
+
105
+ {componentRef() ? (
106
+ <ComponentRefRef
107
+ {...componentOptions()}
108
+ builderBlock={useBlock()}
109
+ >
110
+ {children()?.map((child) => (
111
+ <RenderBlock key={child.id} block={child} />
112
+ ))}
113
+ </ComponentRefRef>
114
+ ) : null}
115
+
116
+ {noCompRefChildren()?.map((child) => (
117
+ <RenderBlock key={child.id} block={child} />
118
+ ))}
119
+ </TagNameRef>
120
+ </>
121
+ ) : (
122
+ <TagNameRef {...propertiesAndActions()} style={css()} />
123
+ )}
124
+ </>
125
+ ) : (
126
+ <ComponentRefRef
127
+ {...componentOptions()}
128
+ attributes={propertiesAndActions()}
129
+ builderBlock={useBlock()}
130
+ style={css()}
131
+ >
132
+ {children()?.map((child) => (
133
+ <RenderBlock key={child.id} block={child} />
134
+ ))}
135
+ </ComponentRefRef>
136
+ )}
137
+ </>
138
+ );
139
+ }
@@ -1,9 +1,13 @@
1
1
  import * as React from "react";
2
2
  import { View, StyleSheet } from "react-native";
3
- import { isEditing } from "../functions/is-editing";
4
- import RenderBlock from "./render-block";
3
+ import { isEditing } from "../functions/is-editing.js";
4
+ import RenderBlock from "./render-block/render-block.js";
5
5
  function RenderBlocks(props) {
6
6
  var _a;
7
+ function className() {
8
+ var _a2;
9
+ return "builder-blocks" + (!((_a2 = props.blocks) == null ? void 0 : _a2.length) ? " no-blocks" : "");
10
+ }
7
11
  function onClick() {
8
12
  var _a2, _b;
9
13
  if (isEditing() && !((_a2 = props.blocks) == null ? void 0 : _a2.length)) {
@@ -29,15 +33,18 @@ function RenderBlocks(props) {
29
33
  }
30
34
  }
31
35
  return /* @__PURE__ */ React.createElement(View, {
32
- className: "builder-blocks" + (!((_a = props.blocks) == null ? void 0 : _a.length) ? " no-blocks" : ""),
33
36
  "builder-path": props.path,
34
37
  "builder-parent-id": props.parent,
35
- onClick: (event) => onClick,
36
- onMouseEnter: (event) => onMouseEnter,
38
+ dataSet: {
39
+ class: className()
40
+ },
41
+ onClick: (event) => onClick(),
42
+ onMouseEnter: (event) => onMouseEnter(),
37
43
  style: styles.view1
38
- }, props.blocks.map((block) => /* @__PURE__ */ React.createElement(RenderBlock, {
44
+ }, props.blocks ? /* @__PURE__ */ React.createElement(React.Fragment, null, (_a = props.blocks) == null ? void 0 : _a.map((block) => /* @__PURE__ */ React.createElement(RenderBlock, {
45
+ key: block.id,
39
46
  block
40
- })));
47
+ }))) : null);
41
48
  }
42
49
  const styles = StyleSheet.create({
43
50
  view1: { display: "flex", flexDirection: "column", alignItems: "stretch" }
@@ -1,10 +1,13 @@
1
1
  import * as React from "react";
2
2
  import { View, StyleSheet, Image, Text } from "react-native";
3
- import { useState, useContext } from "react";
4
- import { isEditing } from "../functions/is-editing";
5
- import RenderBlock from "./render-block.lite";
3
+ import { isEditing } from "../functions/is-editing.js";
4
+ import RenderBlock from "./render-block/render-block.lite";
6
5
 
7
6
  export default function RenderBlocks(props) {
7
+ function className() {
8
+ return "builder-blocks" + (!props.blocks?.length ? " no-blocks" : "");
9
+ }
10
+
8
11
  function onClick() {
9
12
  if (isEditing() && !props.blocks?.length) {
10
13
  window.parent?.postMessage(
@@ -37,16 +40,22 @@ export default function RenderBlocks(props) {
37
40
 
38
41
  return (
39
42
  <View
40
- className={"builder-blocks" + (!props.blocks?.length ? " no-blocks" : "")}
41
43
  builder-path={props.path}
42
44
  builder-parent-id={props.parent}
43
- onClick={(event) => onClick}
44
- onMouseEnter={(event) => onMouseEnter}
45
+ dataSet={{
46
+ class: className(),
47
+ }}
48
+ onClick={(event) => onClick()}
49
+ onMouseEnter={(event) => onMouseEnter()}
45
50
  style={styles.view1}
46
51
  >
47
- {props.blocks.map((block) => (
48
- <RenderBlock block={block} />
49
- ))}
52
+ {props.blocks ? (
53
+ <>
54
+ {props.blocks?.map((block) => (
55
+ <RenderBlock key={block.id} block={block} />
56
+ ))}
57
+ </>
58
+ ) : null}
50
59
  </View>
51
60
  );
52
61
  }
@@ -0,0 +1,58 @@
1
+ import * as React from "react";
2
+ import RenderInlinedStyles from "../../render-inlined-styles.js";
3
+ function RenderContentStyles(props) {
4
+ function getCssFromFont(font) {
5
+ var _a, _b;
6
+ const family = font.family + (font.kind && !font.kind.includes("#") ? ", " + font.kind : "");
7
+ const name = family.split(",")[0];
8
+ const url = (_b = font.fileUrl) != null ? _b : (_a = font == null ? void 0 : font.files) == null ? void 0 : _a.regular;
9
+ let str = "";
10
+ if (url && family && name) {
11
+ str += `
12
+ @font-face {
13
+ font-family: "${family}";
14
+ src: local("${name}"), url('${url}') format('woff2');
15
+ font-display: fallback;
16
+ font-weight: 400;
17
+ }
18
+ `.trim();
19
+ }
20
+ if (font.files) {
21
+ for (const weight in font.files) {
22
+ const isNumber = String(Number(weight)) === weight;
23
+ if (!isNumber) {
24
+ continue;
25
+ }
26
+ const weightUrl = font.files[weight];
27
+ if (weightUrl && weightUrl !== url) {
28
+ str += `
29
+ @font-face {
30
+ font-family: "${family}";
31
+ src: url('${weightUrl}') format('woff2');
32
+ font-display: fallback;
33
+ font-weight: ${weight};
34
+ }
35
+ `.trim();
36
+ }
37
+ }
38
+ }
39
+ return str;
40
+ }
41
+ function getFontCss({ customFonts }) {
42
+ var _a;
43
+ return ((_a = customFonts == null ? void 0 : customFonts.map((font) => getCssFromFont(font))) == null ? void 0 : _a.join(" ")) || "";
44
+ }
45
+ function injectedStyles() {
46
+ return `
47
+ ${props.cssCode || ""}
48
+ ${getFontCss({
49
+ customFonts: props.customFonts
50
+ })}`;
51
+ }
52
+ return /* @__PURE__ */ React.createElement(RenderInlinedStyles, {
53
+ styles: injectedStyles()
54
+ });
55
+ }
56
+ export {
57
+ RenderContentStyles as default
58
+ };
@@ -0,0 +1,70 @@
1
+ import * as React from "react";
2
+ import { View, StyleSheet, Image, Text } from "react-native";
3
+ import RenderInlinedStyles from "../../render-inlined-styles.lite";
4
+
5
+ export default function RenderContentStyles(props) {
6
+ function getCssFromFont(font) {
7
+ // TODO: compute what font sizes are used and only load those.......
8
+ const family =
9
+ font.family +
10
+ (font.kind && !font.kind.includes("#") ? ", " + font.kind : "");
11
+ const name = family.split(",")[0];
12
+ const url = font.fileUrl ?? font?.files?.regular;
13
+ let str = "";
14
+
15
+ if (url && family && name) {
16
+ str += `
17
+ @font-face {
18
+ font-family: "${family}";
19
+ src: local("${name}"), url('${url}') format('woff2');
20
+ font-display: fallback;
21
+ font-weight: 400;
22
+ }
23
+ `.trim();
24
+ }
25
+
26
+ if (font.files) {
27
+ for (const weight in font.files) {
28
+ const isNumber = String(Number(weight)) === weight;
29
+
30
+ if (!isNumber) {
31
+ continue;
32
+ } // TODO: maybe limit number loaded
33
+
34
+ const weightUrl = font.files[weight];
35
+
36
+ if (weightUrl && weightUrl !== url) {
37
+ str += `
38
+ @font-face {
39
+ font-family: "${family}";
40
+ src: url('${weightUrl}') format('woff2');
41
+ font-display: fallback;
42
+ font-weight: ${weight};
43
+ }
44
+ `.trim();
45
+ }
46
+ }
47
+ }
48
+
49
+ return str;
50
+ }
51
+
52
+ function getFontCss({ customFonts }) {
53
+ // TODO: flag for this
54
+ // if (!builder.allowCustomFonts) {
55
+ // return '';
56
+ // }
57
+ // TODO: separate internal data from external
58
+ return customFonts?.map((font) => getCssFromFont(font))?.join(" ") || "";
59
+ }
60
+
61
+ function injectedStyles() {
62
+ return `
63
+ ${props.cssCode || ""}
64
+ ${getFontCss({
65
+ customFonts: props.customFonts,
66
+ })}`;
67
+ }
68
+
69
+ return <RenderInlinedStyles styles={injectedStyles()} />;
70
+ }
@@ -0,0 +1,5 @@
1
+ import * as React from 'react';
2
+ import { default as default2 } from "./render-content.js";
3
+ export {
4
+ default2 as default
5
+ };