@makeswift/runtime 0.2.3 → 0.2.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/Box.cjs.js +14 -14
- package/dist/Box.cjs.js.map +1 -1
- package/dist/Button.cjs.js +23 -23
- package/dist/Button.cjs.js.map +1 -1
- package/dist/Carousel.cjs.js +8 -8
- package/dist/Carousel.cjs.js.map +1 -1
- package/dist/Countdown.cjs.js +13 -13
- package/dist/Countdown.cjs.js.map +1 -1
- package/dist/Divider.cjs.js +4 -4
- package/dist/Divider.cjs.js.map +1 -1
- package/dist/Embed.cjs.js +2 -2
- package/dist/Embed.cjs.js.map +1 -1
- package/dist/Form.cjs.js +72 -72
- package/dist/Form.cjs.js.map +1 -1
- package/dist/Image.cjs2.js +10 -10
- package/dist/Image.cjs2.js.map +1 -1
- package/dist/Navigation.cjs.js +17 -17
- package/dist/Navigation.cjs.js.map +1 -1
- package/dist/Root.cjs.js +2 -2
- package/dist/Root.cjs.js.map +1 -1
- package/dist/SocialLinks.cjs.js +3 -3
- package/dist/SocialLinks.cjs.js.map +1 -1
- package/dist/Text.cjs.js +21 -21
- package/dist/Text.cjs.js.map +1 -1
- package/dist/actions.es.js +1 -1
- package/dist/components.cjs.js +18 -18
- package/dist/cssMediaRules.cjs.js +7 -7
- package/dist/cssMediaRules.cjs.js.map +1 -1
- package/dist/index.cjs.js +374 -8
- package/dist/index.cjs.js.map +1 -1
- package/dist/index.cjs2.js +10 -10
- package/dist/index.cjs2.js.map +1 -1
- package/dist/index.cjs3.js +3 -3
- package/dist/index.cjs3.js.map +1 -1
- package/dist/index.es.js +367 -12
- package/dist/index.es.js.map +1 -1
- package/dist/next.cjs.js +22 -406
- package/dist/next.cjs.js.map +1 -1
- package/dist/next.es.js +12 -392
- package/dist/next.es.js.map +1 -1
- package/dist/react-builder-preview.cjs.js +11 -11
- package/dist/react-builder-preview.cjs.js.map +1 -1
- package/dist/react-builder-preview.es.js +1 -1
- package/dist/react.cjs.js +8 -8
- package/dist/types/src/next/index.d.ts +1 -1
- package/dist/types/src/next/index.d.ts.map +1 -1
- package/dist/useBoxShadow.cjs.js +3 -3
- package/dist/useBoxShadow.cjs.js.map +1 -1
- package/dist/useMediaQuery.cjs.js +6 -6
- package/dist/useMediaQuery.cjs.js.map +1 -1
- package/package.json +2 -2
package/dist/Countdown.cjs.js
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
3
3
|
var React = require("react");
|
|
4
4
|
var styled = require("styled-components");
|
|
5
|
-
var
|
|
5
|
+
var next = require("./index.cjs.js");
|
|
6
6
|
var cssMediaRules = require("./cssMediaRules.cjs.js");
|
|
7
7
|
var jsxRuntime = require("react/jsx-runtime");
|
|
8
8
|
require("use-sync-external-store/shim/with-selector");
|
|
@@ -137,13 +137,13 @@ const Container = styled__default["default"].div.withConfig({
|
|
|
137
137
|
case "filled":
|
|
138
138
|
return styled.css`
|
|
139
139
|
font-family: '${numberFont}';
|
|
140
|
-
color: ${
|
|
141
|
-
background: ${
|
|
140
|
+
color: ${next.colorToString(numberColor)};
|
|
141
|
+
background: ${next.colorToString(blockColor)};
|
|
142
142
|
`;
|
|
143
143
|
case "filled-split":
|
|
144
144
|
return styled.css`
|
|
145
145
|
position: relative;
|
|
146
|
-
color: ${
|
|
146
|
+
color: ${next.colorToString(numberColor)};
|
|
147
147
|
font-family: '${numberFont}';
|
|
148
148
|
|
|
149
149
|
> span {
|
|
@@ -160,7 +160,7 @@ const Container = styled__default["default"].div.withConfig({
|
|
|
160
160
|
bottom: calc(50% + 1px);
|
|
161
161
|
border-top-left-radius: inherit;
|
|
162
162
|
border-top-right-radius: inherit;
|
|
163
|
-
background: ${
|
|
163
|
+
background: ${next.colorToString(blockColor)};
|
|
164
164
|
}
|
|
165
165
|
|
|
166
166
|
::after {
|
|
@@ -172,22 +172,22 @@ const Container = styled__default["default"].div.withConfig({
|
|
|
172
172
|
bottom: 0;
|
|
173
173
|
border-bottom-left-radius: inherit;
|
|
174
174
|
border-bottom-right-radius: inherit;
|
|
175
|
-
background: ${
|
|
175
|
+
background: ${next.colorToString(blockColor)};
|
|
176
176
|
}
|
|
177
177
|
`;
|
|
178
178
|
case "outline":
|
|
179
179
|
return styled.css`
|
|
180
180
|
font-family: '${numberFont}';
|
|
181
|
-
color: ${
|
|
181
|
+
color: ${next.colorToString(numberColor)};
|
|
182
182
|
background: transparent;
|
|
183
|
-
border: 2px solid ${
|
|
183
|
+
border: 2px solid ${next.colorToString(blockColor)};
|
|
184
184
|
`;
|
|
185
185
|
case "outline-split":
|
|
186
186
|
return styled.css`
|
|
187
187
|
position: relative;
|
|
188
188
|
font-family: '${numberFont}';
|
|
189
|
-
color: ${
|
|
190
|
-
border: 2px solid ${
|
|
189
|
+
color: ${next.colorToString(numberColor)};
|
|
190
|
+
border: 2px solid ${next.colorToString(blockColor)};
|
|
191
191
|
|
|
192
192
|
> span {
|
|
193
193
|
position: relative;
|
|
@@ -202,14 +202,14 @@ const Container = styled__default["default"].div.withConfig({
|
|
|
202
202
|
right: 0;
|
|
203
203
|
height: 2px;
|
|
204
204
|
margin-top: -1px;
|
|
205
|
-
background: ${
|
|
205
|
+
background: ${next.colorToString(blockColor)};
|
|
206
206
|
}
|
|
207
207
|
`;
|
|
208
208
|
default:
|
|
209
209
|
return styled.css`
|
|
210
210
|
font-family: '${numberFont}';
|
|
211
211
|
background: transparent;
|
|
212
|
-
color: ${
|
|
212
|
+
color: ${next.colorToString(numberColor)};
|
|
213
213
|
padding-top: 0;
|
|
214
214
|
padding-bottom: 0;
|
|
215
215
|
`;
|
|
@@ -227,7 +227,7 @@ const Container = styled__default["default"].div.withConfig({
|
|
|
227
227
|
alpha: 1
|
|
228
228
|
}, labelFont = "sans-serif"]) => styled.css`
|
|
229
229
|
font-family: '${labelFont}';
|
|
230
|
-
color: ${
|
|
230
|
+
color: ${next.colorToString(labelColor)};
|
|
231
231
|
`)}
|
|
232
232
|
}
|
|
233
233
|
`;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Countdown.cjs.js","sources":["../src/components/builtin/Countdown/Countdown.tsx"],"sourcesContent":["import { useState, useEffect, Ref, forwardRef } from 'react'\nimport styled, { css } from 'styled-components'\n\nimport { colorToString } from '../../utils/colorToString'\nimport { ColorValue as Color } from '../../utils/types'\nimport { cssMediaRules, cssMargin, cssWidth } from '../../utils/cssMediaRules'\nimport {\n ResponsiveValue,\n DateValue,\n ElementIDValue,\n FontValue,\n GapXValue,\n MarginValue,\n ResponsiveIconRadioGroupValue,\n TextInputValue,\n WidthValue,\n} from '../../../prop-controllers/descriptors'\nimport { ResponsiveColor } from '../../../runtimes/react/controls'\n\ntype Props = {\n id?: ElementIDValue\n date?: DateValue\n variant?: ResponsiveIconRadioGroupValue<\n 'filled' | 'filled-split' | 'outline' | 'outline-split' | 'clear'\n >\n shape?: ResponsiveIconRadioGroupValue<'pill' | 'rounded' | 'square'>\n size?: ResponsiveIconRadioGroupValue<'small' | 'medium' | 'large'>\n gap?: GapXValue\n numberFont?: FontValue\n numberColor?: ResponsiveColor | null\n blockColor?: ResponsiveColor | null\n labelFont?: FontValue\n labelColor?: ResponsiveColor | null\n width?: WidthValue\n margin?: MarginValue\n daysLabel?: TextInputValue\n hoursLabel?: TextInputValue\n minutesLabel?: TextInputValue\n secondsLabel?: TextInputValue\n}\n\nconst Block = styled.div`\n display: block;\n padding: 0.5em;\n font-size: 1em;\n`\n\nconst Label = styled.div`\n margin-top: 0.25em;\n`\n\nconst Segment = styled.div`\n flex: 1;\n text-align: center;\n`\n\nconst Container = styled.div.withConfig({\n shouldForwardProp: prop =>\n ![\n 'width',\n 'margin',\n 'variant',\n 'size',\n 'shape',\n 'gap',\n 'labelColor',\n 'numberFont',\n 'numberColor',\n 'blockColor',\n 'labelFont',\n ].includes(prop),\n})<{\n width: Props['width']\n margin: Props['margin']\n variant: Props['variant']\n size: Props['size']\n shape: Props['shape']\n gap: Props['gap']\n labelColor?: ResponsiveValue<Color> | null\n numberFont?: ResponsiveValue<string>\n numberColor?: ResponsiveValue<Color> | null\n blockColor?: ResponsiveValue<Color> | null\n labelFont?: ResponsiveValue<string>\n}>`\n display: flex;\n ${cssWidth('560px')}\n ${cssMargin()}\n ${p =>\n cssMediaRules([p.size] as const, ([size = 'medium']) => {\n switch (size) {\n case 'small':\n return css`\n font-size: 18px;\n\n ${Label} {\n font-size: 14px;\n }\n `\n case 'large':\n return css`\n font-size: 32px;\n\n ${Label} {\n font-size: 18px;\n }\n `\n default:\n return css`\n font-size: 24px;\n\n ${Label} {\n font-size: 16px;\n }\n `\n }\n })}\n\n ${Segment} {\n ${p =>\n cssMediaRules(\n [p.gap] as const,\n ([gap]) => css`\n margin: 0 ${gap == null ? 0 : `${gap.value / 2}${gap.unit}`};\n\n &:first-child {\n margin-left: 0;\n }\n\n &:last-child {\n margin-right: 0;\n }\n `,\n )}\n }\n\n ${Block} {\n ${p =>\n cssMediaRules([p.shape] as const, ([shape = 'rounded']) => {\n switch (shape) {\n case 'pill':\n return css`\n border-radius: 500px;\n `\n case 'rounded':\n return css`\n border-radius: 6px;\n `\n default:\n return css`\n border-radius: 0;\n `\n }\n })}\n ${p =>\n cssMediaRules(\n [p.variant, p.blockColor, p.numberColor, p.numberFont] as const,\n ([\n variant = 'filled',\n blockColor = { swatch: { hue: 0, saturation: 0, lightness: 0 }, alpha: 1 },\n numberColor = { swatch: { hue: 0, saturation: 0, lightness: 100 }, alpha: 1 },\n numberFont = 'sans-serif',\n ]) => {\n switch (variant) {\n case 'filled':\n return css`\n font-family: '${numberFont}';\n color: ${colorToString(numberColor)};\n background: ${colorToString(blockColor)};\n `\n case 'filled-split':\n return css`\n position: relative;\n color: ${colorToString(numberColor)};\n font-family: '${numberFont}';\n\n > span {\n position: relative;\n z-index: 1;\n }\n\n ::before {\n content: '';\n position: absolute;\n top: 0;\n left: 0;\n right: 0;\n bottom: calc(50% + 1px);\n border-top-left-radius: inherit;\n border-top-right-radius: inherit;\n background: ${colorToString(blockColor)};\n }\n\n ::after {\n content: '';\n position: absolute;\n left: 0;\n right: 0;\n top: calc(50% + 1px);\n bottom: 0;\n border-bottom-left-radius: inherit;\n border-bottom-right-radius: inherit;\n background: ${colorToString(blockColor)};\n }\n `\n case 'outline':\n return css`\n font-family: '${numberFont}';\n color: ${colorToString(numberColor)};\n background: transparent;\n border: 2px solid ${colorToString(blockColor)};\n `\n case 'outline-split':\n return css`\n position: relative;\n font-family: '${numberFont}';\n color: ${colorToString(numberColor)};\n border: 2px solid ${colorToString(blockColor)};\n\n > span {\n position: relative;\n z-index: 1;\n }\n\n ::before {\n content: '';\n position: absolute;\n top: 50%;\n left: 0;\n right: 0;\n height: 2px;\n margin-top: -1px;\n background: ${colorToString(blockColor)};\n }\n `\n default:\n return css`\n font-family: '${numberFont}';\n background: transparent;\n color: ${colorToString(numberColor)};\n padding-top: 0;\n padding-bottom: 0;\n `\n }\n },\n )}\n }\n\n ${Label} {\n ${p =>\n cssMediaRules(\n [p.labelColor, p.labelFont] as const,\n ([\n labelColor = { swatch: { hue: 0, saturation: 0, lightness: 0 }, alpha: 1 },\n labelFont = 'sans-serif',\n ]) => css`\n font-family: '${labelFont}';\n color: ${colorToString(labelColor)};\n `,\n )}\n }\n`\n\nconst getRemaining = (date: Props['date'] | undefined) => {\n if (date == null) return { days: 0, hours: 0, minutes: 0, seconds: 0 }\n\n const timeDiff = new Date(date).getTime() - Date.now()\n\n if (timeDiff <= 0) return { days: 0, hours: 0, minutes: 0, seconds: 0 }\n\n let delta = Math.abs(timeDiff) / 1000\n\n const days = Math.floor(delta / 86400)\n delta -= days * 86400\n\n const hours = Math.floor(delta / 3600) % 24\n delta -= hours * 3600\n\n const minutes = Math.floor(delta / 60) % 60\n delta -= minutes * 60\n\n const seconds = parseInt(String(delta % 60), 10)\n\n return { days, hours, minutes, seconds }\n}\n\nconst Countdown = forwardRef(function Countdown(\n {\n id,\n margin,\n width,\n date,\n variant,\n size,\n shape,\n gap,\n labelColor,\n labelFont,\n numberColor,\n numberFont,\n blockColor,\n daysLabel,\n hoursLabel,\n minutesLabel,\n secondsLabel,\n }: Props,\n ref: Ref<HTMLDivElement>,\n) {\n const [{ days, hours, minutes, seconds }, setRemaining] = useState(getRemaining(date))\n\n useEffect(() => {\n setRemaining(getRemaining(date))\n\n const intervalId = setInterval(() => {\n setRemaining(getRemaining(date))\n }, 1000)\n\n return () => clearInterval(intervalId)\n }, [date])\n\n return (\n <Container\n ref={ref}\n id={id}\n width={width}\n margin={margin}\n variant={variant}\n size={size}\n shape={shape}\n labelColor={labelColor}\n labelFont={labelFont}\n numberColor={numberColor}\n numberFont={numberFont}\n blockColor={blockColor}\n gap={gap}\n >\n <Segment>\n <Block>\n <span>{days}</span>\n </Block>\n <Label>{daysLabel == null ? 'Days' : daysLabel}</Label>\n </Segment>\n <Segment>\n <Block>\n <span>{hours}</span>\n </Block>\n <Label>{hoursLabel == null ? 'Hours' : hoursLabel}</Label>\n </Segment>\n <Segment>\n <Block>\n <span>{minutes}</span>\n </Block>\n <Label>{minutesLabel == null ? 'Minutes' : minutesLabel}</Label>\n </Segment>\n <Segment>\n <Block>\n <span>{seconds}</span>\n </Block>\n <Label>{secondsLabel == null ? 'Seconds' : secondsLabel}</Label>\n </Segment>\n </Container>\n )\n})\n\nexport default Countdown\n"],"names":["Block","styled","div","Label","Segment","Container","withConfig","shouldForwardProp","prop","includes","cssWidth","cssMargin","p","cssMediaRules","size","css","gap","value","unit","shape","variant","blockColor","numberColor","numberFont","swatch","hue","saturation","lightness","alpha","colorToString","labelColor","labelFont","getRemaining","date","days","hours","minutes","seconds","timeDiff","Date","getTime","now","delta","Math","abs","floor","parseInt","String","Countdown","forwardRef","id","margin","width","daysLabel","hoursLabel","minutesLabel","secondsLabel","ref","setRemaining","useState","useEffect","intervalId","setInterval","clearInterval","_jsxs","_jsx"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;A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U,2BAAA,KAAC,SAAD;AAAA,MAAA,UAAA,CACEC,2BAAA,IAAC,OAAD;AAAA,QACE,yCAAA,QAAA;AAAA,UAAO7B,UAAAA;AAAAA,QAAAA,CAAP;AAAA,MAAA,CAFJ,GAIE6B,2BAAA,IAAC,OAAD;AAAA,QAAA,UAAQV,gBAAgB,OAAO,YAAYA;AAAAA,MAAAA,CAJ7C,CAAA;AAAA,IAAA,CA3BF,GAiCES,2BAAA,KAAC,SAAD;AAAA,MAAA,UAAA,CACEC,2BAAA,IAAC,OAAD;AAAA,QACE,yCAAA,QAAA;AAAA,UAAO5B,UAAAA;AAAAA,QAAAA,CAAP;AAAA,MAAA,CAFJ,GAIE4B,2BAAA,IAAC,OAAD;AAAA,QAAA,UAAQT,gBAAgB,OAAO,YAAYA;AAAAA,MAAAA,CAJ7C,CAAA;AAAA,IAAA,CAjCF,CAAA;AAAA,EAAA,CADF;AA0CD,CA5E2B;;"}
|
|
1
|
+
{"version":3,"file":"Countdown.cjs.js","sources":["../src/components/builtin/Countdown/Countdown.tsx"],"sourcesContent":["import { useState, useEffect, Ref, forwardRef } from 'react'\nimport styled, { css } from 'styled-components'\n\nimport { colorToString } from '../../utils/colorToString'\nimport { ColorValue as Color } from '../../utils/types'\nimport { cssMediaRules, cssMargin, cssWidth } from '../../utils/cssMediaRules'\nimport {\n ResponsiveValue,\n DateValue,\n ElementIDValue,\n FontValue,\n GapXValue,\n MarginValue,\n ResponsiveIconRadioGroupValue,\n TextInputValue,\n WidthValue,\n} from '../../../prop-controllers/descriptors'\nimport { ResponsiveColor } from '../../../runtimes/react/controls'\n\ntype Props = {\n id?: ElementIDValue\n date?: DateValue\n variant?: ResponsiveIconRadioGroupValue<\n 'filled' | 'filled-split' | 'outline' | 'outline-split' | 'clear'\n >\n shape?: ResponsiveIconRadioGroupValue<'pill' | 'rounded' | 'square'>\n size?: ResponsiveIconRadioGroupValue<'small' | 'medium' | 'large'>\n gap?: GapXValue\n numberFont?: FontValue\n numberColor?: ResponsiveColor | null\n blockColor?: ResponsiveColor | null\n labelFont?: FontValue\n labelColor?: ResponsiveColor | null\n width?: WidthValue\n margin?: MarginValue\n daysLabel?: TextInputValue\n hoursLabel?: TextInputValue\n minutesLabel?: TextInputValue\n secondsLabel?: TextInputValue\n}\n\nconst Block = styled.div`\n display: block;\n padding: 0.5em;\n font-size: 1em;\n`\n\nconst Label = styled.div`\n margin-top: 0.25em;\n`\n\nconst Segment = styled.div`\n flex: 1;\n text-align: center;\n`\n\nconst Container = styled.div.withConfig({\n shouldForwardProp: prop =>\n ![\n 'width',\n 'margin',\n 'variant',\n 'size',\n 'shape',\n 'gap',\n 'labelColor',\n 'numberFont',\n 'numberColor',\n 'blockColor',\n 'labelFont',\n ].includes(prop),\n})<{\n width: Props['width']\n margin: Props['margin']\n variant: Props['variant']\n size: Props['size']\n shape: Props['shape']\n gap: Props['gap']\n labelColor?: ResponsiveValue<Color> | null\n numberFont?: ResponsiveValue<string>\n numberColor?: ResponsiveValue<Color> | null\n blockColor?: ResponsiveValue<Color> | null\n labelFont?: ResponsiveValue<string>\n}>`\n display: flex;\n ${cssWidth('560px')}\n ${cssMargin()}\n ${p =>\n cssMediaRules([p.size] as const, ([size = 'medium']) => {\n switch (size) {\n case 'small':\n return css`\n font-size: 18px;\n\n ${Label} {\n font-size: 14px;\n }\n `\n case 'large':\n return css`\n font-size: 32px;\n\n ${Label} {\n font-size: 18px;\n }\n `\n default:\n return css`\n font-size: 24px;\n\n ${Label} {\n font-size: 16px;\n }\n `\n }\n })}\n\n ${Segment} {\n ${p =>\n cssMediaRules(\n [p.gap] as const,\n ([gap]) => css`\n margin: 0 ${gap == null ? 0 : `${gap.value / 2}${gap.unit}`};\n\n &:first-child {\n margin-left: 0;\n }\n\n &:last-child {\n margin-right: 0;\n }\n `,\n )}\n }\n\n ${Block} {\n ${p =>\n cssMediaRules([p.shape] as const, ([shape = 'rounded']) => {\n switch (shape) {\n case 'pill':\n return css`\n border-radius: 500px;\n `\n case 'rounded':\n return css`\n border-radius: 6px;\n `\n default:\n return css`\n border-radius: 0;\n `\n }\n })}\n ${p =>\n cssMediaRules(\n [p.variant, p.blockColor, p.numberColor, p.numberFont] as const,\n ([\n variant = 'filled',\n blockColor = { swatch: { hue: 0, saturation: 0, lightness: 0 }, alpha: 1 },\n numberColor = { swatch: { hue: 0, saturation: 0, lightness: 100 }, alpha: 1 },\n numberFont = 'sans-serif',\n ]) => {\n switch (variant) {\n case 'filled':\n return css`\n font-family: '${numberFont}';\n color: ${colorToString(numberColor)};\n background: ${colorToString(blockColor)};\n `\n case 'filled-split':\n return css`\n position: relative;\n color: ${colorToString(numberColor)};\n font-family: '${numberFont}';\n\n > span {\n position: relative;\n z-index: 1;\n }\n\n ::before {\n content: '';\n position: absolute;\n top: 0;\n left: 0;\n right: 0;\n bottom: calc(50% + 1px);\n border-top-left-radius: inherit;\n border-top-right-radius: inherit;\n background: ${colorToString(blockColor)};\n }\n\n ::after {\n content: '';\n position: absolute;\n left: 0;\n right: 0;\n top: calc(50% + 1px);\n bottom: 0;\n border-bottom-left-radius: inherit;\n border-bottom-right-radius: inherit;\n background: ${colorToString(blockColor)};\n }\n `\n case 'outline':\n return css`\n font-family: '${numberFont}';\n color: ${colorToString(numberColor)};\n background: transparent;\n border: 2px solid ${colorToString(blockColor)};\n `\n case 'outline-split':\n return css`\n position: relative;\n font-family: '${numberFont}';\n color: ${colorToString(numberColor)};\n border: 2px solid ${colorToString(blockColor)};\n\n > span {\n position: relative;\n z-index: 1;\n }\n\n ::before {\n content: '';\n position: absolute;\n top: 50%;\n left: 0;\n right: 0;\n height: 2px;\n margin-top: -1px;\n background: ${colorToString(blockColor)};\n }\n `\n default:\n return css`\n font-family: '${numberFont}';\n background: transparent;\n color: ${colorToString(numberColor)};\n padding-top: 0;\n padding-bottom: 0;\n `\n }\n },\n )}\n }\n\n ${Label} {\n ${p =>\n cssMediaRules(\n [p.labelColor, p.labelFont] as const,\n ([\n labelColor = { swatch: { hue: 0, saturation: 0, lightness: 0 }, alpha: 1 },\n labelFont = 'sans-serif',\n ]) => css`\n font-family: '${labelFont}';\n color: ${colorToString(labelColor)};\n `,\n )}\n }\n`\n\nconst getRemaining = (date: Props['date'] | undefined) => {\n if (date == null) return { days: 0, hours: 0, minutes: 0, seconds: 0 }\n\n const timeDiff = new Date(date).getTime() - Date.now()\n\n if (timeDiff <= 0) return { days: 0, hours: 0, minutes: 0, seconds: 0 }\n\n let delta = Math.abs(timeDiff) / 1000\n\n const days = Math.floor(delta / 86400)\n delta -= days * 86400\n\n const hours = Math.floor(delta / 3600) % 24\n delta -= hours * 3600\n\n const minutes = Math.floor(delta / 60) % 60\n delta -= minutes * 60\n\n const seconds = parseInt(String(delta % 60), 10)\n\n return { days, hours, minutes, seconds }\n}\n\nconst Countdown = forwardRef(function Countdown(\n {\n id,\n margin,\n width,\n date,\n variant,\n size,\n shape,\n gap,\n labelColor,\n labelFont,\n numberColor,\n numberFont,\n blockColor,\n daysLabel,\n hoursLabel,\n minutesLabel,\n secondsLabel,\n }: Props,\n ref: Ref<HTMLDivElement>,\n) {\n const [{ days, hours, minutes, seconds }, setRemaining] = useState(getRemaining(date))\n\n useEffect(() => {\n setRemaining(getRemaining(date))\n\n const intervalId = setInterval(() => {\n setRemaining(getRemaining(date))\n }, 1000)\n\n return () => clearInterval(intervalId)\n }, [date])\n\n return (\n <Container\n ref={ref}\n id={id}\n width={width}\n margin={margin}\n variant={variant}\n size={size}\n shape={shape}\n labelColor={labelColor}\n labelFont={labelFont}\n numberColor={numberColor}\n numberFont={numberFont}\n blockColor={blockColor}\n gap={gap}\n >\n <Segment>\n <Block>\n <span>{days}</span>\n </Block>\n <Label>{daysLabel == null ? 'Days' : daysLabel}</Label>\n </Segment>\n <Segment>\n <Block>\n <span>{hours}</span>\n </Block>\n <Label>{hoursLabel == null ? 'Hours' : hoursLabel}</Label>\n </Segment>\n <Segment>\n <Block>\n <span>{minutes}</span>\n </Block>\n <Label>{minutesLabel == null ? 'Minutes' : minutesLabel}</Label>\n </Segment>\n <Segment>\n <Block>\n <span>{seconds}</span>\n </Block>\n <Label>{secondsLabel == null ? 'Seconds' : secondsLabel}</Label>\n </Segment>\n </Container>\n )\n})\n\nexport default Countdown\n"],"names":["Block","styled","div","Label","Segment","Container","withConfig","shouldForwardProp","prop","includes","cssWidth","cssMargin","p","cssMediaRules","size","css","gap","value","unit","shape","variant","blockColor","numberColor","numberFont","swatch","hue","saturation","lightness","alpha","colorToString","labelColor","labelFont","getRemaining","date","days","hours","minutes","seconds","timeDiff","Date","getTime","now","delta","Math","abs","floor","parseInt","String","Countdown","forwardRef","id","margin","width","daysLabel","hoursLabel","minutesLabel","secondsLabel","ref","setRemaining","useState","useEffect","intervalId","setInterval","clearInterval","_jsxs","_jsx"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAyCA,MAAMA,QAAQC,gBAAOC,WAAAA;AAAAA;AAAAA;AAAAA;AAAAA;AAMrB,MAAMC,QAAQF,gBAAOC,WAAAA;AAAAA;AAAAA;AAIrB,MAAME,UAAUH,gBAAOC,WAAAA;AAAAA;AAAAA;AAAAA;AAKvB,MAAMG,YAAYJ,gBAAAA,WAAOC,IAAII,WAAW;AAAA,EACtCC,mBAAmBC,CACjB,SAAA,CAAC,CACC,SACA,UACA,WACA,QACA,SACA,OACA,cACA,cACA,eACA,cACA,WAXD,EAYCC,SAASD,IAZV;AAFmC,CAAtB;AAAA;AAAA,IA6BdE,cAAAA,SAAS,OAAD;AAAA,IACRC,cAAY,UAAA;AAAA,IACZC,CAAAA,MACAC,4BAAc,CAACD,EAAEE,IAAH,GAAmB,CAAC,CAACA,OAAO,cAAc;AAC9CA,UAAAA;AAAAA,SACD;AACIC,aAAAA;;;cAGHZ;AAAAA;AAAAA;AAAAA;AAAAA,SAID;AACIY,aAAAA;;;cAGHZ;AAAAA;AAAAA;AAAAA;AAAAA;AAKGY,aAAAA;;;cAGHZ;AAAAA;AAAAA;AAAAA;AAAAA;AAKT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
|
var styled = require("styled-components");
|
|
5
5
|
var cssMediaRules = require("./cssMediaRules.cjs.js");
|
|
6
|
-
var
|
|
6
|
+
var next = require("./index.cjs.js");
|
|
7
7
|
var jsxRuntime = require("react/jsx-runtime");
|
|
8
8
|
require("use-sync-external-store/shim/with-selector");
|
|
9
9
|
require("./react-page.cjs.js");
|
|
@@ -76,16 +76,16 @@ const Line = styled__default["default"].div.withConfig({
|
|
|
76
76
|
return styled.css`
|
|
77
77
|
border-bottom-width: ${thickness == null ? "1px" : `${thickness.value}${thickness.unit}`};
|
|
78
78
|
border-bottom-style: ${variant};
|
|
79
|
-
border-bottom-color: ${
|
|
79
|
+
border-bottom-color: ${next.colorToString(color)};
|
|
80
80
|
`;
|
|
81
81
|
case "blended":
|
|
82
82
|
return styled.css`
|
|
83
83
|
height: ${`${thickness.value}${thickness.unit}`};
|
|
84
84
|
background: linear-gradient(
|
|
85
|
-
${["90deg",
|
|
85
|
+
${["90deg", next.colorToString({
|
|
86
86
|
swatch: color.swatch,
|
|
87
87
|
alpha: 0
|
|
88
|
-
}),
|
|
88
|
+
}), next.colorToString(color), next.colorToString({
|
|
89
89
|
swatch: color.swatch,
|
|
90
90
|
alpha: 0
|
|
91
91
|
})].join(", ")}
|
package/dist/Divider.cjs.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Divider.cjs.js","sources":["../src/components/builtin/Divider/Divider.tsx"],"sourcesContent":["import { forwardRef, Ref } from 'react'\nimport styled, { css } from 'styled-components'\n\nimport { cssMediaRules, cssMargin, cssWidth } from '../../utils/cssMediaRules'\nimport {\n ResponsiveValue,\n ElementIDValue,\n MarginValue,\n ResponsiveLengthValue,\n ResponsiveSelectValue,\n WidthValue,\n} from '../../../prop-controllers/descriptors'\nimport { colorToString } from '../../utils/colorToString'\nimport { ColorValue as Color } from '../../utils/types'\nimport { ResponsiveColor } from '../../../runtimes/react/controls'\n\ntype DividerVariant = 'solid' | 'dashed' | 'dotted' | 'blended'\n\ntype Props = {\n id?: ElementIDValue\n variant?: ResponsiveSelectValue<DividerVariant>\n thickness?: ResponsiveLengthValue\n color?: ResponsiveColor | null\n width?: WidthValue\n margin?: MarginValue\n}\n\n// IE11 has a bug with Flexbox vertical centering with min height if height is not set.\n// Wrapping it in another flex container fixes it for some reason, read more here:\n// https://stackoverflow.com/questions/19371626/flexbox-not-centering-vertically-in-ie\nconst IE11MinHeightContainer = styled.div.withConfig({\n shouldForwardProp: prop => !['width', 'margin'].includes(prop),\n})<{ width: Props['width']; margin: Props['margin'] }>`\n display: flex;\n width: 100%;\n ${cssWidth()}\n ${cssMargin()}\n`\n\nconst Container = styled.div`\n display: flex;\n flex-direction: column;\n justify-content: center;\n min-height: 40px;\n width: 100%;\n`\n\nconst Line = styled.div.withConfig({\n shouldForwardProp: prop => !['variant', 'color', 'thickness'].includes(prop),\n})<{\n variant: Props['variant']\n color?: ResponsiveValue<Color> | null\n thickness: Props['thickness']\n}>`\n ${p =>\n cssMediaRules(\n [p.variant, p.thickness, p.color] as const,\n ([\n variant = 'solid',\n thickness = { value: 1, unit: 'px' },\n color = { swatch: { hue: 0, saturation: 0, lightness: 0 }, alpha: 1 },\n ]) => {\n switch (variant) {\n case 'solid':\n case 'dashed':\n case 'dotted':\n return css`\n border-bottom-width: ${thickness == null\n ? '1px'\n : `${thickness.value}${thickness.unit}`};\n border-bottom-style: ${variant};\n border-bottom-color: ${colorToString(color)};\n `\n\n case 'blended':\n return css`\n height: ${`${thickness.value}${thickness.unit}`};\n background: linear-gradient(\n ${[\n '90deg',\n colorToString({ swatch: color.swatch, alpha: 0 }),\n colorToString(color),\n colorToString({ swatch: color.swatch, alpha: 0 }),\n ].join(', ')}\n );\n `\n\n default:\n variant as never\n throw new Error(`Invalid variant ${variant}.`)\n }\n },\n )}\n`\n\nconst Divider = forwardRef(function Divider(\n { id, variant, thickness, color, width, margin }: Props,\n ref: Ref<HTMLDivElement>,\n) {\n return (\n <IE11MinHeightContainer ref={ref} id={id} width={width} margin={margin}>\n <Container>\n {/* @ts-expect-error: HTMLDivElement `color` attribute conflicts with prop */}\n <Line variant={variant} thickness={thickness} color={color} />\n </Container>\n </IE11MinHeightContainer>\n )\n})\n\nexport default Divider\n"],"names":["IE11MinHeightContainer","styled","div","withConfig","shouldForwardProp","prop","includes","cssWidth","cssMargin","Container","Line","p","cssMediaRules","variant","thickness","color","value","unit","swatch","hue","saturation","lightness","alpha","css","colorToString","join","Error","Divider","forwardRef","id","width","margin","ref"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA8BA,MAAMA,yBAAyBC,gBAAAA,WAAOC,IAAIC,WAAW;AAAA,EACnDC,mBAAmBC,UAAQ,CAAC,CAAC,SAAS,QAAV,EAAoBC,SAASD,IAA7B;AADuB,CAAtB;AAAA;AAAA;AAAA,IAK3BE,cAAW,SAAA;AAAA,IACXC,cAAY,UAAA;AAAA;AAGhB,MAAMC,YAAYR,gBAAOC,WAAAA;AAAAA;AAAAA;AAAAA;AAAAA;AAAAA;AAAAA;AAQzB,MAAMQ,OAAOT,gBAAAA,WAAOC,IAAIC,WAAW;AAAA,EACjCC,mBAAmBC,UAAQ,CAAC,CAAC,WAAW,SAAS,WAArB,EAAkCC,SAASD,IAA3C;AADK,CAAtB;AAAA,IAOTM,CACAC,MAAAA,cAAAA,cACE,CAACD,EAAEE,SAASF,EAAEG,WAAWH,EAAEI,KAA3B,GACA,CAAC,CACCF,UAAU,SACVC,YAAY;AAAA,EAAEE,OAAO;AAAA,EAAGC,MAAM;AAAlB,GACZF,QAAQ;AAAA,EAAEG,QAAQ;AAAA,IAAEC,KAAK;AAAA,IAAGC,YAAY;AAAA,IAAGC,WAAW;AAAA,EAA9C;AAAA,EAAmDC,OAAO;AAA1D,OACJ;AACIT,UAAAA;AAAAA,SACD;AAAA,SACA;AAAA,SACA;AACIU,aAAAA;qCACkBT,aAAa,OAChC,QACC,GAAEA,UAAUE,QAAQF,UAAUG;AAAAA,qCACZJ;AAAAA,qCACAW,
|
|
1
|
+
{"version":3,"file":"Divider.cjs.js","sources":["../src/components/builtin/Divider/Divider.tsx"],"sourcesContent":["import { forwardRef, Ref } from 'react'\nimport styled, { css } from 'styled-components'\n\nimport { cssMediaRules, cssMargin, cssWidth } from '../../utils/cssMediaRules'\nimport {\n ResponsiveValue,\n ElementIDValue,\n MarginValue,\n ResponsiveLengthValue,\n ResponsiveSelectValue,\n WidthValue,\n} from '../../../prop-controllers/descriptors'\nimport { colorToString } from '../../utils/colorToString'\nimport { ColorValue as Color } from '../../utils/types'\nimport { ResponsiveColor } from '../../../runtimes/react/controls'\n\ntype DividerVariant = 'solid' | 'dashed' | 'dotted' | 'blended'\n\ntype Props = {\n id?: ElementIDValue\n variant?: ResponsiveSelectValue<DividerVariant>\n thickness?: ResponsiveLengthValue\n color?: ResponsiveColor | null\n width?: WidthValue\n margin?: MarginValue\n}\n\n// IE11 has a bug with Flexbox vertical centering with min height if height is not set.\n// Wrapping it in another flex container fixes it for some reason, read more here:\n// https://stackoverflow.com/questions/19371626/flexbox-not-centering-vertically-in-ie\nconst IE11MinHeightContainer = styled.div.withConfig({\n shouldForwardProp: prop => !['width', 'margin'].includes(prop),\n})<{ width: Props['width']; margin: Props['margin'] }>`\n display: flex;\n width: 100%;\n ${cssWidth()}\n ${cssMargin()}\n`\n\nconst Container = styled.div`\n display: flex;\n flex-direction: column;\n justify-content: center;\n min-height: 40px;\n width: 100%;\n`\n\nconst Line = styled.div.withConfig({\n shouldForwardProp: prop => !['variant', 'color', 'thickness'].includes(prop),\n})<{\n variant: Props['variant']\n color?: ResponsiveValue<Color> | null\n thickness: Props['thickness']\n}>`\n ${p =>\n cssMediaRules(\n [p.variant, p.thickness, p.color] as const,\n ([\n variant = 'solid',\n thickness = { value: 1, unit: 'px' },\n color = { swatch: { hue: 0, saturation: 0, lightness: 0 }, alpha: 1 },\n ]) => {\n switch (variant) {\n case 'solid':\n case 'dashed':\n case 'dotted':\n return css`\n border-bottom-width: ${thickness == null\n ? '1px'\n : `${thickness.value}${thickness.unit}`};\n border-bottom-style: ${variant};\n border-bottom-color: ${colorToString(color)};\n `\n\n case 'blended':\n return css`\n height: ${`${thickness.value}${thickness.unit}`};\n background: linear-gradient(\n ${[\n '90deg',\n colorToString({ swatch: color.swatch, alpha: 0 }),\n colorToString(color),\n colorToString({ swatch: color.swatch, alpha: 0 }),\n ].join(', ')}\n );\n `\n\n default:\n variant as never\n throw new Error(`Invalid variant ${variant}.`)\n }\n },\n )}\n`\n\nconst Divider = forwardRef(function Divider(\n { id, variant, thickness, color, width, margin }: Props,\n ref: Ref<HTMLDivElement>,\n) {\n return (\n <IE11MinHeightContainer ref={ref} id={id} width={width} margin={margin}>\n <Container>\n {/* @ts-expect-error: HTMLDivElement `color` attribute conflicts with prop */}\n <Line variant={variant} thickness={thickness} color={color} />\n </Container>\n </IE11MinHeightContainer>\n )\n})\n\nexport default Divider\n"],"names":["IE11MinHeightContainer","styled","div","withConfig","shouldForwardProp","prop","includes","cssWidth","cssMargin","Container","Line","p","cssMediaRules","variant","thickness","color","value","unit","swatch","hue","saturation","lightness","alpha","css","colorToString","join","Error","Divider","forwardRef","id","width","margin","ref"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA8BA,MAAMA,yBAAyBC,gBAAAA,WAAOC,IAAIC,WAAW;AAAA,EACnDC,mBAAmBC,UAAQ,CAAC,CAAC,SAAS,QAAV,EAAoBC,SAASD,IAA7B;AADuB,CAAtB;AAAA;AAAA;AAAA,IAK3BE,cAAW,SAAA;AAAA,IACXC,cAAY,UAAA;AAAA;AAGhB,MAAMC,YAAYR,gBAAOC,WAAAA;AAAAA;AAAAA;AAAAA;AAAAA;AAAAA;AAAAA;AAQzB,MAAMQ,OAAOT,gBAAAA,WAAOC,IAAIC,WAAW;AAAA,EACjCC,mBAAmBC,UAAQ,CAAC,CAAC,WAAW,SAAS,WAArB,EAAkCC,SAASD,IAA3C;AADK,CAAtB;AAAA,I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
|
package/dist/Embed.cjs.js
CHANGED
|
@@ -3,7 +3,7 @@ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
|
3
3
|
var React = require("react");
|
|
4
4
|
var styled = require("styled-components");
|
|
5
5
|
var cssMediaRules = require("./cssMediaRules.cjs.js");
|
|
6
|
-
var
|
|
6
|
+
var next = require("./index.cjs.js");
|
|
7
7
|
var jsxRuntime = require("react/jsx-runtime");
|
|
8
8
|
require("use-sync-external-store/shim/with-selector");
|
|
9
9
|
require("./react-page.cjs.js");
|
|
@@ -79,7 +79,7 @@ const Embed = React.forwardRef(function Embed2({
|
|
|
79
79
|
}, ref) {
|
|
80
80
|
const [container, setContainer] = React.useState(null);
|
|
81
81
|
const [shouldRender, setShouldRender] = React.useState(false);
|
|
82
|
-
|
|
82
|
+
next.useIsomorphicLayoutEffect(() => {
|
|
83
83
|
setShouldRender(true);
|
|
84
84
|
}, []);
|
|
85
85
|
React.useImperativeHandle(ref, () => container, [container]);
|
package/dist/Embed.cjs.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Embed.cjs.js","sources":["../src/components/builtin/Embed/Embed.tsx"],"sourcesContent":["/* eslint-env browser */\n\nimport { useState, useEffect, forwardRef, Ref, useImperativeHandle } from 'react'\nimport styled from 'styled-components'\n\nimport { cssMargin, cssWidth } from '../../utils/cssMediaRules'\nimport {\n ElementIDValue,\n MarginValue,\n TextAreaValue,\n WidthValue,\n} from '../../../prop-controllers/descriptors'\nimport { useIsomorphicLayoutEffect } from '../../hooks/useIsomorphicLayoutEffect'\n\ntype Props = {\n id?: ElementIDValue\n html?: TextAreaValue\n width?: WidthValue\n margin?: MarginValue\n}\n\nconst Container = styled.div.withConfig({\n shouldForwardProp: prop => !['width', 'margin'].includes(prop),\n})<{ width: Props['width']; margin: Props['margin'] }>`\n min-height: 15px;\n ${cssWidth()}\n ${cssMargin()}\n`\n\nconst defaultHtml = `<div style=\"padding: 24px; background-color: rgba(161, 168, 194, 0.18); overflow: hidden;\">\n<svg width=\"316\" height=\"168\" viewBox=\"0 0 316 168\" fill=\"none\" xmlns=\"http://www.w3.org/2000/svg\">\n<rect width=\"70\" height=\"8\" rx=\"2\" fill=\"#A1A8C2\" fill-opacity=\"0.5\"/>\n<rect x=\"78\" width=\"30\" height=\"8\" rx=\"2\" fill=\"#A1A8C2\" fill-opacity=\"0.25\"/>\n<rect x=\"116\" width=\"78\" height=\"8\" rx=\"2\" fill=\"#A1A8C2\" fill-opacity=\"0.25\"/>\n<rect y=\"20\" width=\"120\" height=\"8\" rx=\"2\" fill=\"#A1A8C2\" fill-opacity=\"0.5\"/>\n<rect x=\"128\" y=\"20\" width=\"30\" height=\"8\" rx=\"2\" fill=\"#A1A8C2\" fill-opacity=\"0.25\"/>\n<rect x=\"166\" y=\"20\" width=\"78\" height=\"8\" rx=\"2\" fill=\"#A1A8C2\" fill-opacity=\"0.25\"/>\n<rect y=\"60\" width=\"40\" height=\"8\" rx=\"2\" fill=\"#A1A8C2\" fill-opacity=\"0.5\"/>\n<rect x=\"20\" y=\"80\" width=\"40\" height=\"8\" rx=\"2\" fill=\"#A1A8C2\" fill-opacity=\"0.5\"/>\n<rect x=\"40\" y=\"100\" width=\"40\" height=\"8\" rx=\"2\" fill=\"#A1A8C2\" fill-opacity=\"0.5\"/>\n<rect x=\"88\" y=\"100\" width=\"110\" height=\"8\" rx=\"2\" fill=\"#A1A8C2\" fill-opacity=\"0.25\"/>\n<rect x=\"206\" y=\"100\" width=\"24\" height=\"8\" rx=\"2\" fill=\"#A1A8C2\" fill-opacity=\"0.25\"/>\n<rect x=\"238\" y=\"100\" width=\"40\" height=\"8\" rx=\"2\" fill=\"#A1A8C2\" fill-opacity=\"0.5\"/>\n<rect x=\"40\" y=\"120\" width=\"40\" height=\"8\" rx=\"2\" fill=\"#A1A8C2\" fill-opacity=\"0.5\"/>\n<rect x=\"88\" y=\"120\" width=\"50\" height=\"8\" rx=\"2\" fill=\"#A1A8C2\" fill-opacity=\"0.25\"/>\n<rect x=\"146\" y=\"120\" width=\"24\" height=\"8\" rx=\"2\" fill=\"#A1A8C2\" fill-opacity=\"0.25\"/>\n<rect x=\"178\" y=\"120\" width=\"90\" height=\"8\" rx=\"2\" fill=\"#A1A8C2\" fill-opacity=\"0.25\"/>\n<rect x=\"276\" y=\"120\" width=\"40\" height=\"8\" rx=\"2\" fill=\"#A1A8C2\" fill-opacity=\"0.5\"/>\n<rect x=\"20\" y=\"140\" width=\"40\" height=\"8\" rx=\"2\" fill=\"#A1A8C2\" fill-opacity=\"0.5\"/>\n<rect y=\"160\" width=\"40\" height=\"8\" rx=\"2\" fill=\"#A1A8C2\" fill-opacity=\"0.5\"/>\n</svg>\n</div>`\nconst SCRIPT_TAG = 'script'\n\nconst Embed = forwardRef(function Embed(\n { id, width, margin, html = defaultHtml }: Props,\n ref: Ref<HTMLDivElement | null>,\n) {\n const [container, setContainer] = useState<HTMLDivElement | null>(null)\n const [shouldRender, setShouldRender] = useState(false)\n\n useIsomorphicLayoutEffect(() => {\n setShouldRender(true)\n }, [])\n\n useImperativeHandle(ref, () => container, [container])\n\n useEffect(() => {\n // TODO: When we SSR the editor, we can remove the editor check\n // and not run this effect on the first render.\n if (!container) return\n\n const walker = container.ownerDocument.createTreeWalker(container, NodeFilter.SHOW_ELEMENT, {\n acceptNode(node: Element) {\n return node.tagName.toLowerCase() === SCRIPT_TAG\n ? NodeFilter.FILTER_ACCEPT\n : NodeFilter.FILTER_REJECT\n },\n })\n\n const nodes: Element[] = []\n\n while (walker.nextNode()) nodes.push(walker.currentNode as Element)\n\n // By default scripts appended dynamically will execute asyncrhonously. Here we ensure that\n // scripts are loaded synchronously since that's what a user usually expects with scripts in\n // embedded in HTML which usually comes from the server.\n //\n // See: https://developer.mozilla.org/en-US/docs/Web/HTML/Element/script#notes\n async function executeScriptsInOrder() {\n for (let i = 0; i < nodes.length; i++) {\n await new Promise<void>(resolve => {\n const node = nodes[i]\n const script = node.ownerDocument.createElement(SCRIPT_TAG)\n\n script.textContent = node.textContent\n Array.from(node.attributes).forEach(({ name, value }) => {\n script.setAttribute(name, value)\n })\n\n script.onload = () => resolve()\n script.onerror = () => resolve()\n\n node.parentNode?.insertBefore(script, node)\n node.parentNode?.removeChild(node)\n\n if (!script.hasAttribute('src')) resolve()\n })\n }\n }\n\n executeScriptsInOrder().catch(error => {\n // Ignore errors from user-provided code\n console.error(error)\n })\n }, [container, html])\n\n if (shouldRender === false) return null\n\n return (\n <Container\n ref={setContainer}\n id={id}\n width={width}\n margin={margin}\n dangerouslySetInnerHTML={{ __html: html }}\n />\n )\n})\n\nexport default Embed\n"],"names":["Container","styled","div","withConfig","shouldForwardProp","prop","includes","cssWidth","cssMargin","defaultHtml","SCRIPT_TAG","Embed","forwardRef","id","width","margin","html","ref","container","setContainer","useState","shouldRender","setShouldRender","useIsomorphicLayoutEffect","useImperativeHandle","useEffect","walker","ownerDocument","createTreeWalker","NodeFilter","SHOW_ELEMENT","acceptNode","node","tagName","toLowerCase","FILTER_ACCEPT","FILTER_REJECT","nodes","nextNode","push","currentNode","i","length","Promise","resolve","script","createElement","textContent","Array","from","attributes","forEach","name","value","setAttribute","onload","onerror","parentNode","insertBefore","removeChild","hasAttribute","catch","error","console","__html"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAqBA,MAAMA,YAAYC,gBAAAA,WAAOC,IAAIC,WAAW;AAAA,EACtCC,mBAAmBC,UAAQ,CAAC,CAAC,SAAS,QAAV,EAAoBC,SAASD,IAA7B;AADU,CAAtB;AAAA;AAAA,IAIdE,cAAW,SAAA;AAAA,IACXC,cAAY,UAAA;AAAA;AAGhB,MAAMC,cAAe;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAuBrB,MAAMC,aAAa;AAEbC,MAAAA,QAAQC,MAAAA,WAAW,gBACvB;AAAA,EAAEC;AAAAA,EAAIC;AAAAA,EAAOC;AAAAA,EAAQC,OAAOP;AAAAA,GAC5BQ,KACA;AACA,QAAM,CAACC,WAAWC,gBAAgBC,MAAAA,SAAgC,IAAxB;AACpC,QAAA,CAACC,cAAcC,mBAAmBF,MAAAA,SAAS,KAAD;AAEhDG,
|
|
1
|
+
{"version":3,"file":"Embed.cjs.js","sources":["../src/components/builtin/Embed/Embed.tsx"],"sourcesContent":["/* eslint-env browser */\n\nimport { useState, useEffect, forwardRef, Ref, useImperativeHandle } from 'react'\nimport styled from 'styled-components'\n\nimport { cssMargin, cssWidth } from '../../utils/cssMediaRules'\nimport {\n ElementIDValue,\n MarginValue,\n TextAreaValue,\n WidthValue,\n} from '../../../prop-controllers/descriptors'\nimport { useIsomorphicLayoutEffect } from '../../hooks/useIsomorphicLayoutEffect'\n\ntype Props = {\n id?: ElementIDValue\n html?: TextAreaValue\n width?: WidthValue\n margin?: MarginValue\n}\n\nconst Container = styled.div.withConfig({\n shouldForwardProp: prop => !['width', 'margin'].includes(prop),\n})<{ width: Props['width']; margin: Props['margin'] }>`\n min-height: 15px;\n ${cssWidth()}\n ${cssMargin()}\n`\n\nconst defaultHtml = `<div style=\"padding: 24px; background-color: rgba(161, 168, 194, 0.18); overflow: hidden;\">\n<svg width=\"316\" height=\"168\" viewBox=\"0 0 316 168\" fill=\"none\" xmlns=\"http://www.w3.org/2000/svg\">\n<rect width=\"70\" height=\"8\" rx=\"2\" fill=\"#A1A8C2\" fill-opacity=\"0.5\"/>\n<rect x=\"78\" width=\"30\" height=\"8\" rx=\"2\" fill=\"#A1A8C2\" fill-opacity=\"0.25\"/>\n<rect x=\"116\" width=\"78\" height=\"8\" rx=\"2\" fill=\"#A1A8C2\" fill-opacity=\"0.25\"/>\n<rect y=\"20\" width=\"120\" height=\"8\" rx=\"2\" fill=\"#A1A8C2\" fill-opacity=\"0.5\"/>\n<rect x=\"128\" y=\"20\" width=\"30\" height=\"8\" rx=\"2\" fill=\"#A1A8C2\" fill-opacity=\"0.25\"/>\n<rect x=\"166\" y=\"20\" width=\"78\" height=\"8\" rx=\"2\" fill=\"#A1A8C2\" fill-opacity=\"0.25\"/>\n<rect y=\"60\" width=\"40\" height=\"8\" rx=\"2\" fill=\"#A1A8C2\" fill-opacity=\"0.5\"/>\n<rect x=\"20\" y=\"80\" width=\"40\" height=\"8\" rx=\"2\" fill=\"#A1A8C2\" fill-opacity=\"0.5\"/>\n<rect x=\"40\" y=\"100\" width=\"40\" height=\"8\" rx=\"2\" fill=\"#A1A8C2\" fill-opacity=\"0.5\"/>\n<rect x=\"88\" y=\"100\" width=\"110\" height=\"8\" rx=\"2\" fill=\"#A1A8C2\" fill-opacity=\"0.25\"/>\n<rect x=\"206\" y=\"100\" width=\"24\" height=\"8\" rx=\"2\" fill=\"#A1A8C2\" fill-opacity=\"0.25\"/>\n<rect x=\"238\" y=\"100\" width=\"40\" height=\"8\" rx=\"2\" fill=\"#A1A8C2\" fill-opacity=\"0.5\"/>\n<rect x=\"40\" y=\"120\" width=\"40\" height=\"8\" rx=\"2\" fill=\"#A1A8C2\" fill-opacity=\"0.5\"/>\n<rect x=\"88\" y=\"120\" width=\"50\" height=\"8\" rx=\"2\" fill=\"#A1A8C2\" fill-opacity=\"0.25\"/>\n<rect x=\"146\" y=\"120\" width=\"24\" height=\"8\" rx=\"2\" fill=\"#A1A8C2\" fill-opacity=\"0.25\"/>\n<rect x=\"178\" y=\"120\" width=\"90\" height=\"8\" rx=\"2\" fill=\"#A1A8C2\" fill-opacity=\"0.25\"/>\n<rect x=\"276\" y=\"120\" width=\"40\" height=\"8\" rx=\"2\" fill=\"#A1A8C2\" fill-opacity=\"0.5\"/>\n<rect x=\"20\" y=\"140\" width=\"40\" height=\"8\" rx=\"2\" fill=\"#A1A8C2\" fill-opacity=\"0.5\"/>\n<rect y=\"160\" width=\"40\" height=\"8\" rx=\"2\" fill=\"#A1A8C2\" fill-opacity=\"0.5\"/>\n</svg>\n</div>`\nconst SCRIPT_TAG = 'script'\n\nconst Embed = forwardRef(function Embed(\n { id, width, margin, html = defaultHtml }: Props,\n ref: Ref<HTMLDivElement | null>,\n) {\n const [container, setContainer] = useState<HTMLDivElement | null>(null)\n const [shouldRender, setShouldRender] = useState(false)\n\n useIsomorphicLayoutEffect(() => {\n setShouldRender(true)\n }, [])\n\n useImperativeHandle(ref, () => container, [container])\n\n useEffect(() => {\n // TODO: When we SSR the editor, we can remove the editor check\n // and not run this effect on the first render.\n if (!container) return\n\n const walker = container.ownerDocument.createTreeWalker(container, NodeFilter.SHOW_ELEMENT, {\n acceptNode(node: Element) {\n return node.tagName.toLowerCase() === SCRIPT_TAG\n ? NodeFilter.FILTER_ACCEPT\n : NodeFilter.FILTER_REJECT\n },\n })\n\n const nodes: Element[] = []\n\n while (walker.nextNode()) nodes.push(walker.currentNode as Element)\n\n // By default scripts appended dynamically will execute asyncrhonously. Here we ensure that\n // scripts are loaded synchronously since that's what a user usually expects with scripts in\n // embedded in HTML which usually comes from the server.\n //\n // See: https://developer.mozilla.org/en-US/docs/Web/HTML/Element/script#notes\n async function executeScriptsInOrder() {\n for (let i = 0; i < nodes.length; i++) {\n await new Promise<void>(resolve => {\n const node = nodes[i]\n const script = node.ownerDocument.createElement(SCRIPT_TAG)\n\n script.textContent = node.textContent\n Array.from(node.attributes).forEach(({ name, value }) => {\n script.setAttribute(name, value)\n })\n\n script.onload = () => resolve()\n script.onerror = () => resolve()\n\n node.parentNode?.insertBefore(script, node)\n node.parentNode?.removeChild(node)\n\n if (!script.hasAttribute('src')) resolve()\n })\n }\n }\n\n executeScriptsInOrder().catch(error => {\n // Ignore errors from user-provided code\n console.error(error)\n })\n }, [container, html])\n\n if (shouldRender === false) return null\n\n return (\n <Container\n ref={setContainer}\n id={id}\n width={width}\n margin={margin}\n dangerouslySetInnerHTML={{ __html: html }}\n />\n )\n})\n\nexport default Embed\n"],"names":["Container","styled","div","withConfig","shouldForwardProp","prop","includes","cssWidth","cssMargin","defaultHtml","SCRIPT_TAG","Embed","forwardRef","id","width","margin","html","ref","container","setContainer","useState","shouldRender","setShouldRender","useIsomorphicLayoutEffect","useImperativeHandle","useEffect","walker","ownerDocument","createTreeWalker","NodeFilter","SHOW_ELEMENT","acceptNode","node","tagName","toLowerCase","FILTER_ACCEPT","FILTER_REJECT","nodes","nextNode","push","currentNode","i","length","Promise","resolve","script","createElement","textContent","Array","from","attributes","forEach","name","value","setAttribute","onload","onerror","parentNode","insertBefore","removeChild","hasAttribute","catch","error","console","__html"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAqBA,MAAMA,YAAYC,gBAAAA,WAAOC,IAAIC,WAAW;AAAA,EACtCC,mBAAmBC,UAAQ,CAAC,CAAC,SAAS,QAAV,EAAoBC,SAASD,IAA7B;AADU,CAAtB;AAAA;AAAA,IAIdE,cAAW,SAAA;AAAA,IACXC,cAAY,UAAA;AAAA;AAGhB,MAAMC,cAAe;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAuBrB,MAAMC,aAAa;AAEbC,MAAAA,QAAQC,MAAAA,WAAW,gBACvB;AAAA,EAAEC;AAAAA,EAAIC;AAAAA,EAAOC;AAAAA,EAAQC,OAAOP;AAAAA,GAC5BQ,KACA;AACA,QAAM,CAACC,WAAWC,gBAAgBC,MAAAA,SAAgC,IAAxB;AACpC,QAAA,CAACC,cAAcC,mBAAmBF,MAAAA,SAAS,KAAD;AAEhDG,OAAAA,0BAA0B,MAAM;AAC9BD,oBAAgB,IAAD;AAAA,EADQ,GAEtB,CAFsB,CAAA;AAIzBE,QAAAA,oBAAoBP,KAAK,MAAMC,WAAW,CAACA,SAAD,CAAvB;AAEnBO,QAAAA,UAAU,MAAM;AAGV,QAAA,CAACP;AAAW;AAEhB,UAAMQ,SAASR,UAAUS,cAAcC,iB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