@makeswift/runtime 0.0.0-a500663

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/box-model.js ADDED
@@ -0,0 +1 @@
1
+ module.exports = require('./dist/box-model.cjs')
package/components.js ADDED
@@ -0,0 +1 @@
1
+ module.exports = require('./dist/components.cjs')
package/favicon.svg ADDED
@@ -0,0 +1,15 @@
1
+ <svg width="410" height="404" viewBox="0 0 410 404" fill="none" xmlns="http://www.w3.org/2000/svg">
2
+ <path d="M399.641 59.5246L215.643 388.545C211.844 395.338 202.084 395.378 198.228 388.618L10.5817 59.5563C6.38087 52.1896 12.6802 43.2665 21.0281 44.7586L205.223 77.6824C206.398 77.8924 207.601 77.8904 208.776 77.6763L389.119 44.8058C397.439 43.2894 403.768 52.1434 399.641 59.5246Z" fill="url(#paint0_linear)"/>
3
+ <path d="M292.965 1.5744L156.801 28.2552C154.563 28.6937 152.906 30.5903 152.771 32.8664L144.395 174.33C144.198 177.662 147.258 180.248 150.51 179.498L188.42 170.749C191.967 169.931 195.172 173.055 194.443 176.622L183.18 231.775C182.422 235.487 185.907 238.661 189.532 237.56L212.947 230.446C216.577 229.344 220.065 232.527 219.297 236.242L201.398 322.875C200.278 328.294 207.486 331.249 210.492 326.603L212.5 323.5L323.454 102.072C325.312 98.3645 322.108 94.137 318.036 94.9228L279.014 102.454C275.347 103.161 272.227 99.746 273.262 96.1583L298.731 7.86689C299.767 4.27314 296.636 0.855181 292.965 1.5744Z" fill="url(#paint1_linear)"/>
4
+ <defs>
5
+ <linearGradient id="paint0_linear" x1="6.00017" y1="32.9999" x2="235" y2="344" gradientUnits="userSpaceOnUse">
6
+ <stop stop-color="#41D1FF"/>
7
+ <stop offset="1" stop-color="#BD34FE"/>
8
+ </linearGradient>
9
+ <linearGradient id="paint1_linear" x1="194.651" y1="8.81818" x2="236.076" y2="292.989" gradientUnits="userSpaceOnUse">
10
+ <stop stop-color="#FFEA83"/>
11
+ <stop offset="0.0833333" stop-color="#FFDD35"/>
12
+ <stop offset="1" stop-color="#FFA800"/>
13
+ </linearGradient>
14
+ </defs>
15
+ </svg>
package/index.html ADDED
@@ -0,0 +1,13 @@
1
+ <!DOCTYPE html>
2
+ <html lang="en">
3
+ <head>
4
+ <meta charset="UTF-8" />
5
+ <link rel="icon" type="image/svg+xml" href="favicon.svg" />
6
+ <meta name="viewport" content="width=device-width, initial-scale=1.0" />
7
+ <title>Vite App</title>
8
+ </head>
9
+ <body>
10
+ <div id="app"></div>
11
+ <script type="module" src="/src/index.ts"></script>
12
+ </body>
13
+ </html>
package/package.json ADDED
@@ -0,0 +1,100 @@
1
+ {
2
+ "name": "@makeswift/runtime",
3
+ "version": "v0.0.0-a500663",
4
+ "private": false,
5
+ "main": "dist/main.cjs",
6
+ "module": "dist/main.es",
7
+ "types": "dist/types",
8
+ "exports": {
9
+ ".": {
10
+ "import": "./dist/main.es.js",
11
+ "require": "./dist/main.cjs.js"
12
+ },
13
+ "./prop-controllers": {
14
+ "import": "./dist/prop-controllers.es.js",
15
+ "require": "./dist/prop-controllers.cjs.js"
16
+ },
17
+ "./react": {
18
+ "import": "./dist/react.es.js",
19
+ "require": "./dist/react.cjs.js"
20
+ },
21
+ "./box-model": {
22
+ "import": "./dist/box-model.es.js",
23
+ "require": "./dist/box-model.cjs.js"
24
+ },
25
+ "./components": {
26
+ "import": "./dist/components.es.js",
27
+ "require": "./dist/components.cjs.js"
28
+ }
29
+ },
30
+ "typesVersions": {
31
+ "*": {
32
+ "prop-controllers": [
33
+ "src/prop-controllers/index.ts"
34
+ ],
35
+ "react": [
36
+ "src/react.ts"
37
+ ],
38
+ "box-model": [
39
+ "src/box-model.ts"
40
+ ],
41
+ "components": [
42
+ "src/components/index.ts"
43
+ ]
44
+ }
45
+ },
46
+ "publishConfig": {
47
+ "typesVersions": {
48
+ "*": {
49
+ "prop-controllers": [
50
+ "dist/types/prop-controllers/index.d.ts"
51
+ ],
52
+ "react": [
53
+ "dist/types/react.d.ts"
54
+ ],
55
+ "box-model": [
56
+ "dist/types/box-model.d.ts"
57
+ ],
58
+ "components": [
59
+ "dist/types/components/index.d.ts"
60
+ ]
61
+ }
62
+ }
63
+ },
64
+ "scripts": {
65
+ "dev": "concurrently -k 'tsc --watch --preserveWatchOutput' 'vite build --watch'",
66
+ "build": "tsc && vite build",
67
+ "preview": "vite preview"
68
+ },
69
+ "peerDependenciesMeta": {
70
+ "react": {
71
+ "optional": true
72
+ },
73
+ "styled-components": {
74
+ "optional": true
75
+ }
76
+ },
77
+ "peerDependencies": {
78
+ "react": "^17.0.1",
79
+ "styled-components": "5.2.0"
80
+ },
81
+ "dependencies": {
82
+ "@types/slate": "^0.47.8",
83
+ "@types/styled-components": "^5.1.5",
84
+ "@types/use-sync-external-store": "^0.0.3",
85
+ "css-box-model": "^1.2.1",
86
+ "immutable": "^4.0.0-rc.12",
87
+ "ot-json0": "^1.1.0",
88
+ "polished": "3.0.3",
89
+ "redux": "^4.0.5",
90
+ "redux-thunk": "^2.3.0",
91
+ "use-sync-external-store": "^1.0.0-rc.0"
92
+ },
93
+ "devDependencies": {
94
+ "@vitejs/plugin-react": "^1.1.4",
95
+ "concurrently": "^5.3.0",
96
+ "react": "^17.0.1",
97
+ "typescript": "^4.5.5",
98
+ "vite": "^2.7.2"
99
+ }
100
+ }
@@ -0,0 +1 @@
1
+ module.exports = require('./dist/prop-controllers.cjs')
package/react.js ADDED
@@ -0,0 +1 @@
1
+ module.exports = require('./dist/react.cjs')
@@ -0,0 +1,2 @@
1
+ export { createBox, getBox, parse } from './state/modules/box-models'
2
+ export type { BoxModelHandle } from './state/modules/box-models'
@@ -0,0 +1,72 @@
1
+ import styled, { createGlobalStyle } from 'styled-components'
2
+ import { normalize } from 'polished'
3
+ import { forwardRef, Ref } from 'react'
4
+
5
+ import Placeholder from './components/Placeholder'
6
+ import {
7
+ GridValue,
8
+ BackgroundsValue,
9
+ GapXValue,
10
+ GapYValue,
11
+ } from '../../prop-controllers/descriptors'
12
+ import { Element } from '../../react'
13
+ import { cssGridItem } from '../utils/cssMediaRules'
14
+
15
+ const Normalize = createGlobalStyle`
16
+ html {
17
+ box-sizing: border-box;
18
+ }
19
+
20
+ *, *::before, *::after {
21
+ box-sizing: inherit;
22
+ }
23
+
24
+ ${normalize()}
25
+ `
26
+
27
+ const Grid = styled.div`
28
+ display: flex;
29
+ flex-wrap: wrap;
30
+ width: 100%;
31
+ `
32
+
33
+ const GridItem = styled.div`
34
+ display: flex;
35
+ align-items: flex-start;
36
+ ${cssGridItem()}
37
+ `
38
+
39
+ type Props = {
40
+ children?: GridValue
41
+ backgrounds?: BackgroundsValue
42
+ rowGap?: GapYValue
43
+ columnGap?: GapXValue
44
+ }
45
+
46
+ export default forwardRef(function Page(
47
+ { children, rowGap, columnGap }: Props,
48
+ ref: Ref<HTMLDivElement>,
49
+ ) {
50
+ return (
51
+ <>
52
+ <Normalize />
53
+ <Grid ref={ref}>
54
+ {children && children.elements.length > 0 ? (
55
+ children.elements.map((child, index) => (
56
+ <GridItem
57
+ key={child.key}
58
+ grid={children.columns}
59
+ index={index}
60
+ columnGap={columnGap}
61
+ rowGap={rowGap}
62
+ >
63
+ <Element element={child} />
64
+ </GridItem>
65
+ ))
66
+ ) : (
67
+ <Placeholder />
68
+ )}
69
+ </Grid>
70
+ </>
71
+ )
72
+ })
@@ -0,0 +1,37 @@
1
+ import { forwardRef } from 'react'
2
+ import styled from 'styled-components'
3
+
4
+ const PlaceholderBase = styled.div`
5
+ width: 100%;
6
+ background: rgba(161, 168, 194, 0.18);
7
+ height: 80px;
8
+ padding: 8px;
9
+ `
10
+
11
+ type Props = Record<string, never>
12
+
13
+ export default forwardRef<HTMLDivElement, Props>(function Placeholder(props: Props, ref) {
14
+ return (
15
+ <PlaceholderBase {...props} ref={ref}>
16
+ <svg
17
+ xmlns="http://www.w3.org/2000/svg"
18
+ width="100%"
19
+ height="100%"
20
+ style={{ overflow: 'visible' }}
21
+ >
22
+ <rect
23
+ x={0}
24
+ y={0}
25
+ width="100%"
26
+ height="100%"
27
+ strokeWidth={2}
28
+ strokeDasharray="4 2"
29
+ fill="none"
30
+ stroke="rgba(161, 168, 194, 0.40)"
31
+ rx="4"
32
+ ry="4"
33
+ />
34
+ </svg>
35
+ </PlaceholderBase>
36
+ )
37
+ })
@@ -0,0 +1 @@
1
+ export { default } from './Root'
@@ -0,0 +1 @@
1
+ export { default as Root } from './Root'
@@ -0,0 +1,15 @@
1
+ export const getIndexes = (spans: Array<Array<number>>, index: number): [number, number] => {
2
+ const flattened = spans.reduce((a, s) => a.concat(s), [])
3
+
4
+ if (index < 0 || index > flattened.length) throw new RangeError()
5
+
6
+ let remainder = index
7
+ let rowIndex = 0
8
+
9
+ while (rowIndex < spans.length - 1 && remainder >= spans[rowIndex].length) {
10
+ remainder -= spans[rowIndex].length
11
+ rowIndex += 1
12
+ }
13
+
14
+ return [rowIndex, remainder]
15
+ }
@@ -0,0 +1,91 @@
1
+ import { css, CSSObject } from 'styled-components'
2
+
3
+ import {
4
+ ResponsiveValue,
5
+ ResponsiveValueType as ExtractResponsiveValue,
6
+ Length as LengthValue,
7
+ } from '../../prop-controllers'
8
+ import {
9
+ FallbackStrategy,
10
+ getDevice,
11
+ getDeviceMediaQuery,
12
+ join as joinResponsiveValues,
13
+ } from './devices'
14
+ import { getIndexes } from './columns'
15
+
16
+ type CSSRules = ReturnType<typeof css>
17
+
18
+ export function cssMediaRules<V, A extends ReadonlyArray<ResponsiveValue<V> | null | undefined>, P>(
19
+ responsiveValues: A | ((props: P) => A),
20
+ join: (
21
+ values: { [K in keyof A]: ExtractResponsiveValue<A[K]> | undefined },
22
+ ) => CSSRules | CSSObject,
23
+ strategy?: FallbackStrategy<V>,
24
+ ): (props: P) => CSSRules {
25
+ return props =>
26
+ joinResponsiveValues(
27
+ typeof responsiveValues === 'function' ? responsiveValues(props) : responsiveValues,
28
+ join,
29
+ strategy,
30
+ ).reduce((acc, { deviceId, value }) => {
31
+ const device = getDevice(deviceId)
32
+ const mediaQuery = getDeviceMediaQuery(device)
33
+
34
+ return css`
35
+ ${acc}${mediaQuery} {
36
+ ${value}
37
+ }
38
+ `
39
+ }, css`` as CSSRules)
40
+ }
41
+
42
+ const floor = (d: number) => (v: number): number => Math.floor(10 ** d * v) / 10 ** d
43
+
44
+ export function cssGridItem(): (props: {
45
+ grid: ResponsiveValue<{ spans: Array<Array<number>>; count: number }>
46
+ index: number
47
+ columnGap?: ResponsiveValue<LengthValue>
48
+ rowGap?: ResponsiveValue<LengthValue>
49
+ }) => CSSRules {
50
+ return props => css`
51
+ display: flex;
52
+
53
+ /* TODO: A default span of 12 won't work once the column count is modifiable. */
54
+ ${cssMediaRules(
55
+ [props.grid, props.columnGap, props.rowGap] as const,
56
+ ([
57
+ { spans, count } = { spans: [[12]], count: 12 },
58
+ columnGap = { value: 0, unit: 'px' },
59
+ rowGap = { value: 0, unit: 'px' },
60
+ ]) => {
61
+ const [rowIndex, columnIndex] = getIndexes(spans, props.index)
62
+ const firstCol = columnIndex === 0
63
+ const lastCol = columnIndex === spans[rowIndex].length - 1
64
+ const span = spans[rowIndex][columnIndex]
65
+ const fraction = floor(5)(span / count)
66
+ const width = `${fraction} * (100% + ${columnGap.value}${columnGap.unit})`
67
+ const excessWidth = `${Number(firstCol) + Number(lastCol)} * ${columnGap.value}${
68
+ columnGap.unit
69
+ } / 2`
70
+ const iePrecisionError = '0.01px'
71
+ const flexBasis = `calc(${width} - ${excessWidth} - ${iePrecisionError})`
72
+ const firstRow = rowIndex === 0
73
+ const lastRow = rowIndex === spans.length - 1
74
+
75
+ return span === 0
76
+ ? { display: 'none' }
77
+ : {
78
+ flexBasis,
79
+ minWidth: flexBasis,
80
+ // NOTE: IE11 width breaks without max width
81
+ // https://github.com/philipwalton/flexbugs/issues/3
82
+ maxWidth: flexBasis,
83
+ paddingLeft: firstCol ? 0 : `${columnGap.value / 2}${columnGap.unit}`,
84
+ paddingRight: lastCol ? 0 : `${columnGap.value / 2}${columnGap.unit}`,
85
+ paddingTop: firstRow ? 0 : `${rowGap.value / 2}${rowGap.unit}`,
86
+ paddingBottom: lastRow ? 0 : `${rowGap.value / 2}${rowGap.unit}`,
87
+ }
88
+ },
89
+ )}
90
+ `
91
+ }
@@ -0,0 +1,86 @@
1
+ import type { Device as DeviceID, DeviceOverride, ResponsiveValue } from '../../prop-controllers'
2
+
3
+ export type Device = {
4
+ id: DeviceID
5
+ minWidth?: number
6
+ maxWidth?: number
7
+ }
8
+
9
+ export const DEVICES: Array<Device> = [
10
+ { id: 'desktop', minWidth: 769 },
11
+ { id: 'tablet', minWidth: 476, maxWidth: 768 },
12
+ { id: 'mobile', maxWidth: 475 },
13
+ ]
14
+
15
+ export const getDevice = (deviceId: DeviceID): Device => {
16
+ const device = DEVICES.find(({ id }) => id === deviceId)
17
+
18
+ if (device == null) throw new Error(`Unrecognized device ID: "${deviceId}".`)
19
+
20
+ return device
21
+ }
22
+
23
+ export type FallbackStrategy<V> = (
24
+ arg0: DeviceOverride<V> | undefined,
25
+ arg1: ResponsiveValue<V>,
26
+ ) => DeviceOverride<V> | undefined
27
+
28
+ function defaultStrategy<V>(
29
+ value: DeviceOverride<V> | undefined,
30
+ fallbacks: ResponsiveValue<V>,
31
+ ): DeviceOverride<V> | undefined {
32
+ return value || fallbacks[0]
33
+ }
34
+
35
+ export function findDeviceOverride<S>(
36
+ values: ResponsiveValue<S> = [],
37
+ deviceId: string,
38
+ strategy: FallbackStrategy<S> = defaultStrategy,
39
+ ): DeviceOverride<S> | undefined {
40
+ const value = values.find(({ deviceId: d }) => d === deviceId)
41
+ const fallbacks = DEVICES.slice(0, DEVICES.findIndex(d => d.id === deviceId) + 1)
42
+ .reverse()
43
+ .map(d => values.find(v => v.deviceId === d.id))
44
+ .filter((override): override is DeviceOverride<S> => Boolean(override))
45
+
46
+ return value != null || fallbacks.length > 0 ? strategy(value, fallbacks) : undefined
47
+ }
48
+
49
+ export type ExtractResponsiveValue<T> = T extends ResponsiveValue<infer V> ? V : never
50
+
51
+ export function join<V, A extends ReadonlyArray<ResponsiveValue<V> | null | undefined>, R>(
52
+ responsiveValues: A,
53
+ joinFn: (values: { [I in keyof A]: ExtractResponsiveValue<A[I]> | undefined }) => R,
54
+ strategy?: FallbackStrategy<V>,
55
+ ): ResponsiveValue<R> {
56
+ return DEVICES.map(({ id }) => id)
57
+ .map(deviceId => {
58
+ const value = joinFn(
59
+ (responsiveValues.map(responsiveValue => {
60
+ const deviceValue =
61
+ responsiveValue && findDeviceOverride(responsiveValue, deviceId, strategy)
62
+
63
+ return deviceValue == null ? undefined : deviceValue.value
64
+ }) as unknown) as { [I in keyof A]: ExtractResponsiveValue<A[I] | undefined> },
65
+ )
66
+
67
+ if (value == null) return null
68
+
69
+ return { deviceId, value }
70
+ })
71
+ .filter((override): override is DeviceOverride<R> => Boolean(override))
72
+ }
73
+
74
+ export const getDeviceMediaQuery = (device: Device): string => {
75
+ const parts = ['@media only screen']
76
+
77
+ if (device.minWidth != null) {
78
+ parts.push(`(min-width: ${device.minWidth}px)`)
79
+ }
80
+
81
+ if (device.maxWidth != null) {
82
+ parts.push(`(max-width: ${device.maxWidth}px)`)
83
+ }
84
+
85
+ return parts.join(' and ')
86
+ }
package/src/index.ts ADDED
@@ -0,0 +1,8 @@
1
+ export type { Action } from './state/actions'
2
+ export { ActionTypes, changeDocument, changeDocumentElementScrollTop } from './state/actions'
3
+ export type { Operation } from './state/modules/read-write-documents'
4
+ export type { ComponentMeta } from './state/modules/components-meta'
5
+ export type {
6
+ PropControllerDescriptor,
7
+ PropControllerDescriptorValueType,
8
+ } from './prop-controllers'