eddev 0.2.0-beta.9 → 0.2.1

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 (120) hide show
  1. package/build/build-favicon.d.ts +1 -0
  2. package/build/build-favicon.js +71 -0
  3. package/build/create-serverless-dev-worker.d.ts +3 -0
  4. package/build/create-serverless-dev-worker.js +99 -0
  5. package/build/get-webpack-config.js +11 -1
  6. package/build/manifests/manifest-views.js +1 -1
  7. package/build/reporter.js +0 -109
  8. package/build/serverless/create-next-app.d.ts +2 -0
  9. package/build/serverless/create-next-app.js +243 -47
  10. package/build/state/serverless-state.d.ts +26 -0
  11. package/{config/schema.js → build/state/serverless-state.js} +0 -0
  12. package/build/workers/codegen-worker-script.js +33 -0
  13. package/{config/schema.d.ts → build/workers/serverless-worker-dev-script.d.ts} +0 -0
  14. package/build/workers/serverless-worker-dev-script.js +21 -0
  15. package/cli/build.dev.js +34 -6
  16. package/cli/build.prod.js +13 -1
  17. package/cli/cli.js +32 -17
  18. package/cli/display/components/DevCLIDisplay.d.ts +3 -0
  19. package/cli/display/components/DevCLIDisplay.js +20 -1
  20. package/cli/display/components/ServerlessDisplay.d.ts +9 -0
  21. package/cli/display/components/ServerlessDisplay.js +68 -0
  22. package/cli/preinstall.d.ts +1 -0
  23. package/cli/preinstall.js +14 -0
  24. package/components/NextRouter.js +3 -2
  25. package/config/config-schema.d.ts +17 -9
  26. package/config/config-schema.js +3 -1
  27. package/config/get-config.d.ts +39 -0
  28. package/config/get-config.js +32 -0
  29. package/config/parse-config.d.ts +8 -4
  30. package/config/print-zod-errors.d.ts +2 -0
  31. package/config/print-zod-errors.js +14 -0
  32. package/dev-ui/components/BreakpointColumnHeader.d.ts +11 -0
  33. package/dev-ui/components/BreakpointColumnHeader.js +47 -0
  34. package/dev-ui/components/BreakpointIndicator.d.ts +2 -0
  35. package/dev-ui/components/BreakpointIndicator.js +138 -0
  36. package/dev-ui/components/DevUI.d.ts +2 -0
  37. package/dev-ui/components/DevUI.js +28 -0
  38. package/dev-ui/components/Launcher.d.ts +98 -0
  39. package/dev-ui/components/Launcher.js +94 -0
  40. package/dev-ui/components/PanelWrapper.d.ts +8 -0
  41. package/dev-ui/components/PanelWrapper.js +37 -0
  42. package/dev-ui/components/ResponsiveLerpControl.d.ts +8 -0
  43. package/dev-ui/components/ResponsiveLerpControl.js +177 -0
  44. package/dev-ui/components/ResponsiveScaleEditor.d.ts +26 -0
  45. package/dev-ui/components/ResponsiveScaleEditor.js +233 -0
  46. package/dev-ui/components/atoms/Button.d.ts +47 -0
  47. package/dev-ui/components/atoms/Button.js +67 -0
  48. package/dev-ui/components/atoms/Dropdown.d.ts +13 -0
  49. package/dev-ui/components/atoms/Dropdown.js +50 -0
  50. package/dev-ui/components/atoms/NumberField.d.ts +12 -0
  51. package/dev-ui/components/atoms/NumberField.js +111 -0
  52. package/dev-ui/components/atoms/Spacer.d.ts +42 -0
  53. package/dev-ui/components/atoms/Spacer.js +8 -0
  54. package/dev-ui/components/atoms/Text.d.ts +45 -0
  55. package/dev-ui/components/atoms/Text.js +39 -0
  56. package/dev-ui/components/atoms/ToggleButton.d.ts +8 -0
  57. package/dev-ui/components/atoms/ToggleButton.js +41 -0
  58. package/dev-ui/components/atoms/Tooltip.d.ts +9 -0
  59. package/dev-ui/components/atoms/Tooltip.js +66 -0
  60. package/dev-ui/components/panels/PageDataDebugger.d.ts +2 -0
  61. package/dev-ui/components/panels/PageDataDebugger.js +30 -0
  62. package/dev-ui/components/panels/SpacingEditor.d.ts +2 -0
  63. package/dev-ui/components/panels/SpacingEditor.js +88 -0
  64. package/dev-ui/components/panels/TypographyEditor.d.ts +2 -0
  65. package/dev-ui/components/panels/TypographyEditor.js +88 -0
  66. package/dev-ui/hooks/useBreakpoint.d.ts +11 -0
  67. package/dev-ui/hooks/useBreakpoint.js +59 -0
  68. package/dev-ui/hooks/usePersistState.d.ts +1 -0
  69. package/dev-ui/hooks/usePersistState.js +36 -0
  70. package/dev-ui/hooks/useStylesheet.d.ts +4 -0
  71. package/dev-ui/hooks/useStylesheet.js +31 -0
  72. package/dev-ui/icons.d.ts +15 -0
  73. package/dev-ui/icons.js +29 -0
  74. package/dev-ui/index.d.ts +1 -0
  75. package/dev-ui/index.js +13 -0
  76. package/dev-ui/loader.d.ts +2 -0
  77. package/dev-ui/loader.js +42 -0
  78. package/dev-ui/panels.d.ts +11 -0
  79. package/dev-ui/panels.js +33 -0
  80. package/dev-ui/theme.d.ts +151 -0
  81. package/dev-ui/theme.js +50 -0
  82. package/entry/Root.d.ts +3 -1
  83. package/entry/Root.js +18 -6
  84. package/hooks/index.d.ts +1 -0
  85. package/hooks/index.js +1 -0
  86. package/{serverless/create-rpc-client.d.ts → hooks/useRPC.d.ts} +18 -18
  87. package/hooks/useRPC.js +18 -0
  88. package/package.json +15 -7
  89. package/routing/routing.js +1 -1
  90. package/serverless/define-rpc-router.d.ts +5 -1
  91. package/serverless/define-rpc-router.js +11 -3
  92. package/serverless/index.d.ts +2 -1
  93. package/serverless/index.js +3 -1
  94. package/serverless-template/_utils/PageMeta.tsx +44 -0
  95. package/serverless-template/_utils/fetch-wordpress-props.ts +14 -3
  96. package/serverless-template/_utils/fetch-wp.ts +16 -0
  97. package/serverless-template/global.d.ts +7 -1
  98. package/serverless-template/next.config.js +10 -3
  99. package/serverless-template/package.json +5 -3
  100. package/serverless-template/pages/404.tsx +12 -0
  101. package/serverless-template/pages/[...slug].tsx +7 -2
  102. package/serverless-template/pages/_app.tsx +32 -12
  103. package/serverless-template/pages/_document.tsx +19 -0
  104. package/serverless-template/pages/api/rest/{[...method].ts → [method].ts} +4 -2
  105. package/serverless-template/pages/api/trpc/[...trpc].ts +26 -0
  106. package/serverless-template/pages/index.tsx +2 -2
  107. package/style/createStitches.d.ts +71 -1
  108. package/style/createStitches.js +151 -45
  109. package/utils/getRepoName.js +13 -5
  110. package/utils/updateEnvFile.d.ts +1 -0
  111. package/utils/updateEnvFile.js +76 -0
  112. package/cli/prepare-next.d.ts +0 -0
  113. package/cli/prepare-next.js +0 -1
  114. package/entry/entry.serverless.dev.d.ts +0 -0
  115. package/entry/entry.serverless.dev.js +0 -2
  116. package/fields/ImageWell.d.ts +0 -8
  117. package/fields/ImageWell.js +0 -64
  118. package/serverless/create-rpc-client.js +0 -20
  119. package/serverless-template/package-lock.json +0 -641
  120. package/serverless-template/pages/api/hello.ts +0 -10
@@ -1,8 +1,9 @@
1
1
  const withTM = require("next-transpile-modules")
2
- const { resolve } = require("path")
2
+ const { resolve, join } = require("path")
3
3
  const { DefinePlugin } = require("webpack")
4
4
  const settings = require("./ed.config.json")
5
5
  const { getRepoName } = require("eddev/utils/getRepoName")
6
+ const { existsSync } = require("fs")
6
7
 
7
8
  module.exports = (() => {
8
9
  const cwd = process.cwd()
@@ -27,11 +28,11 @@ module.exports = (() => {
27
28
  ].filter(Boolean),
28
29
  }
29
30
  },
31
+ experimental: {},
30
32
  typescript: {
31
33
  ignoreBuildErrors: true,
32
34
  },
33
35
  webpack: (config, { buildId, dev, isServer, defaultLoaders, webpack }) => {
34
- console.log(resolve(cwd, "manifest_blocks.ts"))
35
36
  config.resolve.alias = {
36
37
  ...config.resolve.alias,
37
38
  "@manifest/views": resolve(cwd, "manifest_views.ts"),
@@ -49,14 +50,20 @@ module.exports = (() => {
49
50
  const define = config.plugins.find((plugin) => plugin instanceof DefinePlugin)
50
51
  define.definitions["process.serverless"] = "true"
51
52
  define.definitions["process.admin"] = "false"
53
+ define.definitions["process.client"] = isServer ? "false" : "true"
52
54
  define.definitions["process.dev"] = process.env.NODE_ENV === "development"
53
55
 
54
56
  const themePath =
55
57
  (settings.serverless.theme === "remote" ? process.env.SITE_URL : "") + "/wp-content/themes/" + REPO_NAME
56
58
 
57
- console.log("Theme path", themePath)
58
59
  define.definitions["process.env.themePath"] = JSON.stringify(themePath)
59
60
  define.definitions["process.themePath"] = JSON.stringify(themePath)
61
+ define.definitions["process.devUI"] = settings.devUI === "enabled"
62
+ define.definitions["process.serverlessEndpoint"] = JSON.stringify("/")
63
+
64
+ const rpcExists =
65
+ existsSync(join(process.cwd(), "apis/_rpc.ts")) || existsSync(join(process.cwd(), "apis/_rpc/index.ts"))
66
+ define.definitions["process.rpcEnabled"] = rpcExists ? "true" : "false"
60
67
  // config.plugins.push(
61
68
  // new DefinePlugin({
62
69
  // "process.serverless": "true",
@@ -8,12 +8,14 @@
8
8
  "start": "next start"
9
9
  },
10
10
  "dependencies": {
11
- "next": "12.0.10",
12
11
  "react": "17.0.2",
13
- "react-dom": "17.0.2"
12
+ "react-dom": "17.0.2",
13
+ "@trpc/next": "^9.19.0",
14
+ "@trpc/server": "^9.19.0"
14
15
  },
15
16
  "devDependencies": {
16
17
  "@types/react": "17.0.39",
17
- "typescript": "4.5.5"
18
+ "typescript": "4.5.5",
19
+ "next": "^12.1.0"
18
20
  }
19
21
  }
@@ -0,0 +1,12 @@
1
+ import { fetchWordpressProps } from "../_utils/fetch-wordpress-props"
2
+
3
+ export default function Home() {
4
+ return <div />
5
+ }
6
+
7
+ export async function getStaticProps({ params }: any) {
8
+ const result = await fetchWordpressProps("/404")
9
+ return {
10
+ props: result.data,
11
+ }
12
+ }
@@ -2,7 +2,7 @@ import { GetStaticPathsResult, GetStaticPropsContext, GetStaticPropsResult } fro
2
2
  import { fetchWordpressProps } from "../_utils/fetch-wordpress-props"
3
3
 
4
4
  export default function Home(props: any) {
5
- return <div>{JSON.stringify(props)}</div>
5
+ return <div />
6
6
  }
7
7
 
8
8
  export async function getStaticPaths(): Promise<GetStaticPathsResult> {
@@ -14,7 +14,12 @@ export async function getStaticPaths(): Promise<GetStaticPathsResult> {
14
14
 
15
15
  export async function getStaticProps({ params }: GetStaticPropsContext): Promise<GetStaticPropsResult<any>> {
16
16
  const result = await fetchWordpressProps((params?.slug as string[]).join("/"))
17
+ if (result.status === 404) {
18
+ return {
19
+ notFound: true,
20
+ }
21
+ }
17
22
  return {
18
- props: result,
23
+ props: result.data,
19
24
  }
20
25
  }
@@ -5,30 +5,50 @@ import { NextRouter } from "eddev/components/NextRouter"
5
5
  import { ServerlessAppDataProvider } from "eddev/utils/serverlessAppContext"
6
6
  import { useMemo } from "react"
7
7
  import { useRouter } from "next/router"
8
+ import { DevUILoader } from "eddev/dev-ui/loader"
9
+ import { PageMeta } from "../_utils/PageMeta"
10
+ import { withTRPC } from "@trpc/next"
8
11
 
9
- function MyApp({ Component, pageProps }: AppProps) {
10
- if (!pageProps.appData) return <div />
11
-
12
- const appData = useMemo(() => {
13
- return pageProps.appData.data
14
- }, [])
12
+ let appData: any
15
13
 
14
+ function Root({ Component, pageProps }: AppProps) {
16
15
  const route = useRouter()
17
16
 
17
+ if (!appData) appData = pageProps?.appData?.data
18
+
19
+ // const appData = useMemo(() => {
20
+ // return pageProps?.appData?.data
21
+ // }, [])
22
+
18
23
  const viewProps = pageProps?.viewData?.data
19
24
 
20
- const View = manifest[pageProps.view]
25
+ const View = manifest[pageProps.view || "404"]
21
26
 
22
- console.log("ROUTE", pageProps, route.pathname)
27
+ if (!appData) return <div />
28
+
29
+ console.log(`Could not load view named "${pageProps.view}"`)
23
30
 
24
31
  return (
25
32
  <ServerlessAppDataProvider value={appData}>
26
33
  <NextRouter data={pageProps} path={route.pathname}>
27
- <App>
28
- <View {...viewProps} />
29
- </App>
34
+ {pageProps?.meta?.head && <PageMeta {...pageProps?.meta?.head} />}
35
+ {pageProps?.meta?.footer && <PageMeta {...pageProps?.meta?.footer} />}
36
+ {process.devUI ? <DevUILoader /> : null}
37
+ <App>{View && <View {...viewProps} />}</App>
30
38
  </NextRouter>
31
39
  </ServerlessAppDataProvider>
32
40
  )
33
41
  }
34
- export default MyApp
42
+
43
+ // @ts-ignore
44
+ export default process.rpcEnabled
45
+ ? withTRPC({
46
+ config({ ctx }) {
47
+ return {
48
+ // @ts-ignore
49
+ url: process.serverlessEndpoint + "api/trpc",
50
+ }
51
+ },
52
+ ssr: false,
53
+ })(Root)
54
+ : Root
@@ -0,0 +1,19 @@
1
+ import React from "react"
2
+ import NextDocument, { Html, Head, Main, NextScript } from "next/document"
3
+ import { getCssText } from "@theme"
4
+
5
+ export default class Document extends NextDocument {
6
+ render() {
7
+ return (
8
+ <Html lang="en">
9
+ <Head>
10
+ <style id="stitches" dangerouslySetInnerHTML={{ __html: getCssText() }} />
11
+ </Head>
12
+ <body>
13
+ <Main />
14
+ <NextScript />
15
+ </body>
16
+ </Html>
17
+ )
18
+ }
19
+ }
@@ -1,3 +1,5 @@
1
+ import { fetchWP } from "../../../_utils/fetch-wp"
2
+
1
3
  const validProxyPaths = {
2
4
  "form-submit": {
3
5
  path: "/wp-json/ed/v1/gf/submit",
@@ -15,7 +17,7 @@ const validProxyPaths = {
15
17
 
16
18
  export default async function (req: any, res: any) {
17
19
  // Ensure that the request is for a proxy path
18
- const proxyPath = validProxyPaths[req.query.method[0] as keyof typeof validProxyPaths]!
20
+ const proxyPath = validProxyPaths[req.query.method as keyof typeof validProxyPaths]!
19
21
 
20
22
  if (!proxyPath) {
21
23
  return res.status(404).json({
@@ -25,7 +27,7 @@ export default async function (req: any, res: any) {
25
27
 
26
28
  const finalPath = proxyPath.path.replace("*", req.query.method.slice(1).join("/"))
27
29
 
28
- const response = await fetch(process.env.SITE_URL + finalPath, {
30
+ const response = await fetchWP(process.env.SITE_URL + finalPath, {
29
31
  method: proxyPath.method,
30
32
  headers: {
31
33
  "Content-Type": "application/json",
@@ -0,0 +1,26 @@
1
+ // @ts-ignore
2
+ import { router, createContext } from "../../../apis/_rpc"
3
+ import * as trpcNext from "@trpc/server/adapters/next"
4
+ import type { NextApiRequest, NextApiResponse } from "next"
5
+
6
+ const handler = trpcNext.createNextApiHandler({
7
+ router: router,
8
+ createContext: createContext,
9
+ })
10
+
11
+ export default function (req: NextApiRequest, res: NextApiResponse) {
12
+ // TODO: Use an origin whitelist
13
+ const origin = req.headers.origin
14
+ if (origin) {
15
+ res.setHeader("Access-Control-Allow-Origin", "*")
16
+ res.setHeader("Access-Control-Request-Method", "*")
17
+ res.setHeader("Access-Control-Request-Method", "OPTIONS, GET, POST")
18
+ res.setHeader("Access-Control-Allow-Headers", "*")
19
+ if (req.method === "OPTIONS") {
20
+ res.writeHead(200)
21
+ res.end()
22
+ return
23
+ }
24
+ }
25
+ return handler(req, res)
26
+ }
@@ -1,12 +1,12 @@
1
1
  import { fetchWordpressProps } from "../_utils/fetch-wordpress-props"
2
2
 
3
3
  export default function Home() {
4
- return <div>Test</div>
4
+ return <div />
5
5
  }
6
6
 
7
7
  export async function getStaticProps({ params }: any) {
8
8
  const result = await fetchWordpressProps("/")
9
9
  return {
10
- props: result,
10
+ props: result.data,
11
11
  }
12
12
  }
@@ -18,6 +18,12 @@ declare type TypographyConfig<Theme extends ConfigType.Theme<{}>, Media extends
18
18
  lineHeight?: ResponsiveValue<Media, Theme["lineHeights"] extends {} ? `$${Extract<keyof Theme["lineHeights"], string>}` | CSS["lineHeight"] : CSS["lineHeight"]>;
19
19
  };
20
20
  };
21
+ export declare type BreakpointArray = {
22
+ key: string;
23
+ min: string | null;
24
+ max: string | null;
25
+ }[];
26
+ export declare function parseBreakpoints(names: string[], medias: any): BreakpointArray;
21
27
  interface GridConfig<Theme extends ConfigType.Theme<{}>, Media extends ConfigType.Media<{}>> {
22
28
  columns: number;
23
29
  breakpoints: {
@@ -36,7 +42,49 @@ declare type ResponsiveScale<Media extends ConfigType.Media<{}>, T extends {}> =
36
42
  declare type ResponsiveConfig<Media extends ConfigType.Media<{}>, T extends {}> = {
37
43
  [Scale in keyof T]: ResponsiveScale<Media, T[Scale]>;
38
44
  };
39
- export declare function createStitches<Prefix extends string = "", Media extends {} = {}, Theme extends {} = {}, Responsive extends {} = {}, ThemeMap extends {} = DefaultThemeMap, Utils extends {} = {}, Typography extends {} = {}>(config: {
45
+ declare type ResponsiveAtom = {
46
+ lerpStart: boolean;
47
+ } & ({
48
+ type: "multiplier";
49
+ value: number;
50
+ } | {
51
+ type: "percent";
52
+ value: number;
53
+ } | {
54
+ type: "px";
55
+ value: number;
56
+ } | {
57
+ type: "number";
58
+ value: number;
59
+ } | {
60
+ type: "unknown";
61
+ value: string | number;
62
+ } | {
63
+ type: "undefined";
64
+ });
65
+ export declare type ResponsiveAtomCalc = ResponsiveAtom & {
66
+ defined: boolean;
67
+ breakpoint: string;
68
+ baseBreakpoint: string;
69
+ lastBreakpoint: string;
70
+ lerping?: {
71
+ fromBP: string | null;
72
+ toBP: string | null;
73
+ minMedia: number;
74
+ maxMedia: number;
75
+ minValue: number;
76
+ maxValue: number;
77
+ };
78
+ concreteValue: number | null;
79
+ };
80
+ export declare function parseResponsiveObject(breakpoints: ReturnType<typeof parseBreakpoints>, object: any): ResponsiveAtomCalc[];
81
+ export declare function getResponsiveObjectStyles(breakpoints: ReturnType<typeof parseBreakpoints>, object: any, varName: string, unit?: string): any[];
82
+ export declare function parseResponsiveTokens(theme: any, breakpoints: any): {
83
+ initialResponsive: any;
84
+ globalResponsive: any;
85
+ };
86
+ export declare function createStitches<Prefix extends string = "", Media extends {} = {}, Breakpoints extends (keyof Media)[] = [], Theme extends {} = {}, Responsive extends {} = {}, ThemeMap extends {} = DefaultThemeMap, Utils extends {} = {}, Typography extends {} = {}>(config: {
87
+ breakpoints: Breakpoints;
40
88
  prefix?: ConfigType.Prefix<Prefix>;
41
89
  media: ConfigType.Media<Media>;
42
90
  theme: ConfigType.Theme<Theme>;
@@ -55,12 +103,34 @@ export declare function createStitches<Prefix extends string = "", Media extends
55
103
  themeMap?: ConfigType.ThemeMap<ThemeMap>;
56
104
  utils: ConfigType.Utils<Utils>;
57
105
  }): {
106
+ originalConfig: {
107
+ breakpoints: Breakpoints;
108
+ prefix?: ConfigType.Prefix<Prefix> | undefined;
109
+ media: ConfigType.Media<Media>;
110
+ theme: ConfigType.Theme<Theme>;
111
+ responsive: ResponsiveConfig<Media & {
112
+ initial: string;
113
+ editor: string;
114
+ }, Responsive>;
115
+ typography: TypographyConfig<Theme, Media & {
116
+ initial: string;
117
+ editor: string;
118
+ }, Typography>;
119
+ grid: GridConfig<Theme, Media & {
120
+ initial: string;
121
+ editor: string;
122
+ }>;
123
+ themeMap?: ConfigType.ThemeMap<ThemeMap> | undefined;
124
+ utils: ConfigType.Utils<Utils>;
125
+ };
126
+ breakpoints: BreakpointArray;
58
127
  typeVariants: { [key in keyof TypographyConfig<Theme, Media & {
59
128
  initial: string;
60
129
  editor: string;
61
130
  }, Typography>]: any; };
62
131
  gridVariants: {};
63
132
  responsiveTokens: { [Scale in keyof Responsive]: { [T in keyof Responsive[Scale]]: number; }; };
133
+ responsiveGlobals: any;
64
134
  config: {
65
135
  prefix: "";
66
136
  media: {
@@ -11,7 +11,7 @@ var __assign = (this && this.__assign) || function () {
11
11
  return __assign.apply(this, arguments);
12
12
  };
13
13
  Object.defineProperty(exports, "__esModule", { value: true });
14
- exports.createStitches = void 0;
14
+ exports.createStitches = exports.parseResponsiveTokens = exports.getResponsiveObjectStyles = exports.parseResponsiveObject = exports.parseBreakpoints = void 0;
15
15
  var react_1 = require("@stitches/react");
16
16
  var typeKeyMap = {
17
17
  fontSize: "fontSizes",
@@ -20,12 +20,14 @@ var typeKeyMap = {
20
20
  letterSpacing: "letterSpacings",
21
21
  fontWeight: "fontWeights",
22
22
  };
23
- function parseBreakpoints(medias) {
23
+ function parseBreakpoints(names, medias) {
24
24
  var breakpoints = [];
25
25
  // Add an initial breakpoint
26
26
  breakpoints.push({ key: "initial", min: "0px", max: null });
27
27
  // Parse each breakpoint
28
28
  for (var key in medias) {
29
+ if (!names.includes(key))
30
+ continue;
29
31
  var media = medias[key];
30
32
  var minMatch = media.match(/min-width: ([0-9]+[a-z]+)/);
31
33
  var maxMatch = media.match(/max-width: ([0-9]+[a-z]+)/);
@@ -51,6 +53,7 @@ function parseBreakpoints(medias) {
51
53
  }
52
54
  return breakpoints;
53
55
  }
56
+ exports.parseBreakpoints = parseBreakpoints;
54
57
  var unitless = function (value) { return parseFloat(value); };
55
58
  function parseTypography(theme, breakpoints, typography) {
56
59
  var globals = {};
@@ -143,55 +146,157 @@ function parseGrid(theme, media, grid) {
143
146
  "--grid-margin": breakpoint.margin,
144
147
  "--grid-col-width": "calc((var(--grid-inner-width) - (".concat(grid.columns - 1, " * var(--grid-gutter))) / ").concat(grid.columns, ")"),
145
148
  };
146
- // for (let i = 1; i < grid.columns; i++) {
147
- // globalGrid[bpName][
148
- // `--grid-${i}-cols`
149
- // ] = `calc(var(--grid-col-width) * ${i} + var(--grid-gutter) * ${i - 1})`
150
- // }
151
149
  }
152
150
  return { gridVariants: {}, globalGrid: globalGrid };
153
151
  }
154
- function parseResponsiveObject(theme, breakpoints, object, varName, scale) {
155
- var _a;
156
- // Util for grabbing the raw value of a token, for lerping
157
- var resolveValue = function (value) {
158
- if (typeof value === "string" && value.match(/^\$[a-z0-9\-\_]+$/) && scale) {
159
- // Single scale
160
- return theme[scale][value.replace("$", "")];
152
+ function parseResponsiveValue(val) {
153
+ if (Array.isArray(val)) {
154
+ return __assign(__assign({}, parseResponsiveValue(val[0])), { lerpStart: true });
155
+ }
156
+ else if (typeof val === "string") {
157
+ if (val.match(/^x[0-9\.]+$/)) {
158
+ return {
159
+ lerpStart: false,
160
+ type: "multiplier",
161
+ value: parseFloat(val.replace(/^x/, "")),
162
+ };
161
163
  }
162
- else if (typeof value === "number") {
163
- return value + "px";
164
+ else if (val.match(/^[0-9\.]+%$/)) {
165
+ return {
166
+ lerpStart: false,
167
+ type: "percent",
168
+ value: parseFloat(val.replace(/^x/, "")),
169
+ };
164
170
  }
165
- else {
166
- return value;
171
+ else if (val.match(/^[0-9\.]+px$/)) {
172
+ return {
173
+ lerpStart: false,
174
+ type: "px",
175
+ value: parseFloat(val.replace(/px$/, "")),
176
+ };
167
177
  }
178
+ }
179
+ else if (typeof val === "number") {
180
+ return {
181
+ lerpStart: false,
182
+ type: "number",
183
+ value: val,
184
+ };
185
+ }
186
+ else if (val === undefined || val === null) {
187
+ return {
188
+ lerpStart: false,
189
+ type: "undefined",
190
+ };
191
+ }
192
+ return {
193
+ lerpStart: false,
194
+ type: "unknown",
195
+ value: val,
168
196
  };
169
- var globals = {};
170
- var initial = {};
171
- var entries = Object.entries(object);
172
- entries.forEach(function (_a, i) {
173
- var _b;
174
- var bpName = _a[0], responsiveValue = _a[1];
175
- globals[bpName] = {};
176
- if (Array.isArray(responsiveValue)) {
177
- responsiveValue = responsiveValue[0];
178
- // An array in the format [value] signifies font locking between the current breakpoint and the next defined one
179
- var minSize = (_b = breakpoints.find(function (bp) { return "@" + bp.key === bpName; })) === null || _b === void 0 ? void 0 : _b.min;
180
- var nextBreakpoint = breakpoints.find(function (bp) { var _a; return "@" + bp.key === ((_a = entries[i + 1]) === null || _a === void 0 ? void 0 : _a[0]); });
181
- if (!nextBreakpoint)
182
- throw new Error("Cannot create responsive '".concat(varName, "' at breakpoint '").concat(bpName, "', since it is the last-defined breakpoint. Your last size should be a string/number/token."));
183
- var maxSize = nextBreakpoint.min;
184
- var responsiveValue2 = object["@" + nextBreakpoint.key];
185
- if (Array.isArray(responsiveValue2))
186
- responsiveValue2 = responsiveValue2[0];
187
- var size1 = resolveValue(responsiveValue);
188
- var size2 = resolveValue(responsiveValue2);
189
- responsiveValue = "calc(".concat(size1, " + (100vw - ").concat(minSize, ") / (").concat(unitless(maxSize), " - ").concat(unitless(minSize), ") * (").concat(unitless(size2), " - ").concat(unitless(size1), "))");
190
- }
191
- globals[bpName][varName] = responsiveValue;
197
+ }
198
+ function parseResponsiveObject(breakpoints, object) {
199
+ // Breakpoint hash
200
+ var breakpointHash = {};
201
+ for (var _i = 0, breakpoints_1 = breakpoints; _i < breakpoints_1.length; _i++) {
202
+ var bp = breakpoints_1[_i];
203
+ breakpointHash[bp.key] = {
204
+ min: bp.min ? parseFloat(bp.min) : null,
205
+ max: bp.max ? parseFloat(bp.max) : null,
206
+ };
207
+ }
208
+ var result = [];
209
+ var lerpStart = "initial";
210
+ var lastDefined = "initial";
211
+ var concreteValues = {};
212
+ for (var _a = 0, breakpoints_2 = breakpoints; _a < breakpoints_2.length; _a++) {
213
+ var bp = breakpoints_2[_a];
214
+ var value = parseResponsiveValue(object["@" + bp.key]);
215
+ var defined = value.type !== "undefined";
216
+ var base = !defined || value.type === "multiplier" ? lastDefined : bp.key;
217
+ lerpStart = value.lerpStart ? bp.key : lerpStart && !defined ? lerpStart : null;
218
+ if (value.type === "px" || value.type === "number") {
219
+ concreteValues[bp.key] = value.value;
220
+ }
221
+ else if (value.type === "multiplier") {
222
+ concreteValues[bp.key] = value.value * concreteValues[base];
223
+ }
224
+ else if (value.type === "percent") {
225
+ concreteValues[bp.key] = value.value;
226
+ }
227
+ result.push(__assign(__assign({}, value), { defined: defined, breakpoint: bp.key, lastBreakpoint: lastDefined, baseBreakpoint: base, lerping: lerpStart
228
+ ? {
229
+ fromBP: lerpStart,
230
+ toBP: null,
231
+ minMedia: 0,
232
+ maxMedia: 0,
233
+ minValue: 0,
234
+ maxValue: 0,
235
+ }
236
+ : undefined, concreteValue: concreteValues[bp.key] }));
237
+ if (defined) {
238
+ lastDefined = bp.key;
239
+ }
240
+ }
241
+ var nextBreakpoints = [];
242
+ var lastBreakpoint = null;
243
+ for (var i = breakpoints.length - 1; i >= 0; i--) {
244
+ var bp = breakpoints[i];
245
+ nextBreakpoints[i] = lastBreakpoint;
246
+ if (result[i].defined) {
247
+ lastBreakpoint = bp.key;
248
+ }
249
+ }
250
+ result.forEach(function (item, i) {
251
+ if (item.lerping) {
252
+ item.lerping.toBP = nextBreakpoints[i];
253
+ }
192
254
  });
193
- return [globals, (_a = globals["@initial"]) === null || _a === void 0 ? void 0 : _a[varName]];
255
+ result.forEach(function (item, i) {
256
+ var lerp = item.lerping;
257
+ if (lerp) {
258
+ var fromBP = lerp.fromBP ? breakpointHash[lerp.fromBP] : null;
259
+ var toBP = lerp.toBP ? breakpointHash[lerp.toBP] : null;
260
+ if (!fromBP || fromBP.min === null) {
261
+ throw new Error("Cannot create responsive style for first breakpoint");
262
+ }
263
+ if (!toBP || toBP.min === null) {
264
+ throw new Error("Cannot create responsive style for last breakpoint");
265
+ }
266
+ lerp.minMedia = fromBP.min;
267
+ lerp.maxMedia = toBP.min;
268
+ lerp.minValue = item.concreteValue;
269
+ lerp.maxValue = result.find(function (o) { return o.breakpoint === lerp.toBP; }).concreteValue;
270
+ }
271
+ });
272
+ return result;
273
+ }
274
+ exports.parseResponsiveObject = parseResponsiveObject;
275
+ function getResponsiveObjectStyles(breakpoints, object, varName, unit) {
276
+ var _a, _b;
277
+ var _c;
278
+ if (unit === void 0) { unit = "px"; }
279
+ // Prescale object
280
+ object = __assign({}, object);
281
+ var parsed = parseResponsiveObject(breakpoints, object);
282
+ var globals = {};
283
+ for (var _i = 0, parsed_1 = parsed; _i < parsed_1.length; _i++) {
284
+ var atom = parsed_1[_i];
285
+ if (atom.lerpStart && atom.lerping) {
286
+ var lerp = atom.lerping;
287
+ globals["@" + atom.breakpoint] = (_a = {},
288
+ _a[varName] = "calc(".concat(lerp.minValue).concat(unit, " + (100vw - ").concat(lerp.minMedia).concat(unit, ") / (").concat(lerp.maxMedia, " - ").concat(lerp.minMedia, ") * (").concat(lerp.maxValue, " - ").concat(lerp.minValue, "))"),
289
+ _a);
290
+ }
291
+ else if (atom.concreteValue) {
292
+ globals["@" + atom.breakpoint] = (_b = {},
293
+ _b[varName] = atom.concreteValue + unit,
294
+ _b);
295
+ }
296
+ }
297
+ return [globals, (_c = globals["@initial"]) === null || _c === void 0 ? void 0 : _c[varName]];
194
298
  }
299
+ exports.getResponsiveObjectStyles = getResponsiveObjectStyles;
195
300
  // parseResponsiveTokens({'@initial': blah, '@desktop': blah}, breakpoints, )
196
301
  function parseResponsiveTokens(theme, breakpoints) {
197
302
  var globalResponsive = {
@@ -204,7 +309,7 @@ function parseResponsiveTokens(theme, breakpoints) {
204
309
  for (var key in theme[scale]) {
205
310
  var val = theme[scale][key];
206
311
  if (val && typeof val === "object") {
207
- var _a = parseResponsiveObject(theme, breakpoints, val, "--" + scale + "-" + key, scale), tokenGlobals = _a[0], initial = _a[1];
312
+ var _a = getResponsiveObjectStyles(breakpoints, val, "--" + scale + "-" + key), tokenGlobals = _a[0], initial = _a[1];
208
313
  for (var bp in tokenGlobals) {
209
314
  globalResponsive[bp] = __assign(__assign({}, globalResponsive[bp]), tokenGlobals[bp]);
210
315
  }
@@ -217,8 +322,9 @@ function parseResponsiveTokens(theme, breakpoints) {
217
322
  }
218
323
  return { initialResponsive: initialResponsive, globalResponsive: globalResponsive };
219
324
  }
325
+ exports.parseResponsiveTokens = parseResponsiveTokens;
220
326
  function createStitches(config) {
221
- var breakpoints = parseBreakpoints(config.media);
327
+ var breakpoints = parseBreakpoints(config.breakpoints, config.media);
222
328
  var _a = parseTypography(config.theme, breakpoints, config.typography), typeVariants = _a.typeVariants, globalTypography = _a.globalTypography;
223
329
  var _b = parseGrid(config.theme, config.media, config.grid), gridVariants = _b.gridVariants, globalGrid = _b.globalGrid;
224
330
  var _c = parseResponsiveTokens(config.responsive, breakpoints), initialResponsive = _c.initialResponsive, globalResponsive = _c.globalResponsive;
@@ -309,6 +415,6 @@ function createStitches(config) {
309
415
  });
310
416
  stitches.globalCss(responsiveGlobals)();
311
417
  var responsiveTokens = {};
312
- return __assign(__assign({}, stitches), { typeVariants: typeVariants, gridVariants: gridVariants, responsiveTokens: responsiveTokens });
418
+ return __assign(__assign({}, stitches), { originalConfig: config, breakpoints: breakpoints, typeVariants: typeVariants, gridVariants: gridVariants, responsiveTokens: responsiveTokens, responsiveGlobals: responsiveGlobals });
313
419
  }
314
420
  exports.createStitches = createStitches;
@@ -7,10 +7,18 @@ exports.getRepoName = void 0;
7
7
  var git_repo_name_1 = __importDefault(require("git-repo-name"));
8
8
  var path_1 = __importDefault(require("path"));
9
9
  function getRepoName(dir) {
10
- var info = git_repo_name_1.default.sync(dir);
11
- return {
12
- repoName: info || "",
13
- themeName: path_1.default.basename(dir),
14
- };
10
+ if (process.env.VERCEL) {
11
+ return {
12
+ repoName: process.env.VERCEL_GIT_REPO_SLUG,
13
+ themeName: process.env.VERCEL_GIT_REPO_SLUG,
14
+ };
15
+ }
16
+ else {
17
+ var info = git_repo_name_1.default.sync(dir);
18
+ return {
19
+ repoName: info || "",
20
+ themeName: path_1.default.basename(dir),
21
+ };
22
+ }
15
23
  }
16
24
  exports.getRepoName = getRepoName;
@@ -0,0 +1 @@
1
+ export declare function updateEnvFile(data: Record<string, string | number>, directory?: string): Promise<void>;