diff --git a/.github/workflows/bundle_analysis.yml b/.github/workflows/bundle_analysis.yml
new file mode 100644
index 00000000..499830ed
--- /dev/null
+++ b/.github/workflows/bundle_analysis.yml
@@ -0,0 +1,127 @@
+name: 'Bundle Analysis'
+
+on:
+ pull_request:
+ push:
+ branches:
+ - next # change this if your default branch is named differently
+ workflow_dispatch:
+
+defaults:
+ run:
+ # change this if your nextjs app does not live at the root of the repo
+ working-directory: .
+
+jobs:
+ analyze:
+ runs-on: ubuntu-latest
+ steps:
+ - uses: actions/checkout@v2
+
+ - name: Use Node.js 14.x
+ uses: actions/setup-node@v1
+ with:
+ node-version: 14.x
+
+ - name: Cache node modules
+ uses: actions/cache@v1
+ with:
+ path: node_modules
+ key: yarn-deps-${{ hashFiles('yarn.lock') }}
+ restore-keys: |
+ yarn-deps-${{ hashFiles('yarn.lock') }}
+
+ - name: Build library
+ run: |
+ yarn install --frozen-lockfile 2>&1 | grep -v '^[warning|info]'
+ yarn build:lib
+
+ - name: Restore next build
+ uses: actions/cache@v2
+ id: restore-build-cache
+ env:
+ cache-name: cache-next-build
+ with:
+ # if you use a custom build directory, replace all instances of `.next` in this file with your build directory
+ # ex: if your app builds to `dist`, replace `.next` with `dist`
+ path: ./examples/bundle-test/.next/cache
+ # change this if you prefer a more strict cache
+ key: ${{ runner.os }}-build-${{ env.cache-name }}
+
+ - name: Build next.js app
+ working-directory: ./examples/bundle-test
+ # change this if your site requires a custom build command
+ run: yarn build
+
+ # Here's the first place where next-bundle-analysis' own script is used
+ # This step pulls the raw bundle stats for the current bundle
+ - name: Analyze bundle
+ working-directory: ./examples/bundle-test
+ run: npx -p nextjs-bundle-analysis report
+
+ - name: Upload bundle
+ uses: actions/upload-artifact@v2
+ with:
+ name: bundle
+ path: ./examples/bundle-test/.next/analyze/__bundle_analysis.json
+
+ - name: Download base branch bundle stats
+ uses: dawidd6/action-download-artifact@v2
+ if: success() && github.event.number
+ with:
+ workflow: nextjs_bundle_analysis.yml
+ branch: ${{ github.event.pull_request.base.ref }}
+ path: ./examples/bundle-test/.next/analyze/base
+
+ # And here's the second place - this runs after we have both the current and
+ # base branch bundle stats, and will compare them to determine what changed.
+ # There are two configurable arguments that come from package.json:
+ #
+ # - budget: optional, set a budget (bytes) against which size changes are measured
+ # it's set to 350kb here by default, as informed by the following piece:
+ # https://infrequently.org/2021/03/the-performance-inequality-gap/
+ #
+ # - red-status-percentage: sets the percent size increase where you get a red
+ # status indicator, defaults to 20%
+ #
+ # Either of these arguments can be changed or removed by editing the `nextBundleAnalysis`
+ # entry in your package.json file.
+ - name: Compare with base branch bundle
+ working-directory: ./examples/bundle-test
+ if: success() && github.event.number
+ run: ls -laR .next/analyze/base && npx -p nextjs-bundle-analysis compare
+
+ - name: Get comment body
+ working-directory: ./examples/bundle-test
+ id: get-comment-body
+ if: success() && github.event.number
+ run: |
+ body=$(cat .next/analyze/__bundle_analysis_comment.txt)
+ body="${body//'%'/'%25'}"
+ body="${body//$'\n'/'%0A'}"
+ body="${body//$'\r'/'%0D'}"
+ echo ::set-output name=body::$body
+
+ - name: Find Comment
+ uses: peter-evans/find-comment@v1
+ if: success() && github.event.number
+ id: fc
+ with:
+ issue-number: ${{ github.event.number }}
+ body-includes: ''
+
+ - name: Create Comment
+ uses: peter-evans/create-or-update-comment@v1.4.4
+ if: success() && github.event.number && steps.fc.outputs.comment-id == 0
+ with:
+ issue-number: ${{ github.event.number }}
+ body: ${{ steps.get-comment-body.outputs.body }}
+
+ - name: Update Comment
+ uses: peter-evans/create-or-update-comment@v1.4.4
+ if: success() && github.event.number && steps.fc.outputs.comment-id != 0
+ with:
+ issue-number: ${{ github.event.number }}
+ body: ${{ steps.get-comment-body.outputs.body }}
+ comment-id: ${{ steps.fc.outputs.comment-id }}
+ edit-mode: replace
diff --git a/examples/bundle-test/.gitignore b/examples/bundle-test/.gitignore
new file mode 100644
index 00000000..b90a368f
--- /dev/null
+++ b/examples/bundle-test/.gitignore
@@ -0,0 +1,2 @@
+node_modules
+.next
diff --git a/examples/bundle-test/next.config.js b/examples/bundle-test/next.config.js
new file mode 100644
index 00000000..def0588f
--- /dev/null
+++ b/examples/bundle-test/next.config.js
@@ -0,0 +1,13 @@
+const { remarkCodeHike } = require("@code-hike/mdx")
+const theme = require("shiki/themes/nord.json")
+
+const withMDX = require("@next/mdx")({
+ extension: /\.mdx?$/,
+ options: {
+ remarkPlugins: [[remarkCodeHike, { theme }]],
+ },
+})
+
+module.exports = withMDX({
+ pageExtensions: ["ts", "tsx", "js", "jsx", "md", "mdx"],
+})
diff --git a/examples/bundle-test/package.json b/examples/bundle-test/package.json
new file mode 100644
index 00000000..0a14efa0
--- /dev/null
+++ b/examples/bundle-test/package.json
@@ -0,0 +1,21 @@
+{
+ "name": "bundle-test",
+ "private": true,
+ "version": "0.0.0",
+ "scripts": {
+ "build": "next build"
+ },
+ "dependencies": {
+ "@code-hike/mdx": "^0.3.0",
+ "@mdx-js/loader": "^2.0.0",
+ "@next/mdx": "^12.1.0",
+ "next": "^12.1.0",
+ "react": "^17.0.2",
+ "react-dom": "^17.0.2"
+ },
+ "nextBundleAnalysis": {
+ "budget": 358400,
+ "budgetPercentIncreaseRed": 20,
+ "showDetails": true
+ }
+}
diff --git a/examples/bundle-test/pages/_app.js b/examples/bundle-test/pages/_app.js
new file mode 100644
index 00000000..d6f7b982
--- /dev/null
+++ b/examples/bundle-test/pages/_app.js
@@ -0,0 +1,7 @@
+import "@code-hike/mdx/styles"
+
+function MyApp({ Component, pageProps }) {
+ return
+}
+
+export default MyApp
diff --git a/examples/bundle-test/pages/js-page.js b/examples/bundle-test/pages/js-page.js
new file mode 100644
index 00000000..79e8a188
--- /dev/null
+++ b/examples/bundle-test/pages/js-page.js
@@ -0,0 +1,8 @@
+export default function Page() {
+ return (
+
+
Hello
+ Lorem ipsum dolor sit amet.
+
+ )
+}
diff --git a/examples/bundle-test/pages/just-code.mdx b/examples/bundle-test/pages/just-code.mdx
new file mode 100644
index 00000000..1ce8d0fd
--- /dev/null
+++ b/examples/bundle-test/pages/just-code.mdx
@@ -0,0 +1,9 @@
+# Hello world
+
+```js focus=2,4[10:13]
+function lorem(ipsum, dolor = 1) {
+ const sit = ipsum == null ? 0 : ipsum.sit
+ dolor = sit - amet(dolor)
+ return sit ? consectetur(ipsum) : []
+}
+```
diff --git a/examples/bundle-test/pages/no-ch-mdx.mdx b/examples/bundle-test/pages/no-ch-mdx.mdx
new file mode 100644
index 00000000..e93dfc81
--- /dev/null
+++ b/examples/bundle-test/pages/no-ch-mdx.mdx
@@ -0,0 +1,3 @@
+# Hello
+
+Lorem ipsum dolor sit amet.
diff --git a/examples/bundle-test/pages/scrollycoding-preview.mdx b/examples/bundle-test/pages/scrollycoding-preview.mdx
new file mode 100644
index 00000000..8b85bc81
--- /dev/null
+++ b/examples/bundle-test/pages/scrollycoding-preview.mdx
@@ -0,0 +1,154 @@
+# Scrollycoding with preview
+
+Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Praesent elementum facilisis leo vel fringilla est ullamcorper eget. At imperdiet dui accumsan sit amet nulla facilities morbi tempus. Praesent elementum facilisis leo vel fringilla. Congue mauris rhoncus aenean vel. Egestas sed tempus urna et pharetra pharetra massa massa ultricies.
+
+Consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Praesent elementum facilisis leo vel fringilla est ullamcorper eget. At imperdiet dui accumsan sit amet nulla facilities morbi tempus. Praesent elementum facilisis leo vel fringilla. Congue mauris rhoncus aenean vel. Egestas sed tempus urna et pharetra pharetra massa massa ultricies.
+
+
+
+## Step 1
+
+Lorem ipsum dolor sit amet, consectetur adipiscing something about points, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.
+
+> Nova in illis at dabat legi harundine non, ova miratur? _Quid in_ sole aer
+> ad diffusa illis voluisti fidensque coniugiale laniata curam. Aras rivus
+> eripuit, qua fistula haec partus; serpens, negat.
+
+Consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Praesent elementum facilisis leo vel fringilla est ullamcorper eget.
+
+Praesent elementum facilisis leo vel fringilla est ullamcorper eget. At imperdiet dui accumsan sit amet nulla facilities morbi tempus.
+
+```jsx src/App.js
+import { motion } from "framer-motion"
+
+export default function App() {
+ const bg = "hsl(20, 100%, 50%)"
+ return (
+
+ )
+}
+```
+
+---
+
+## Step 2
+
+Velit euismod in pellentesque massa placerat. Mi bibendum neque egestas congue quisque egestas diam in arcu. Nisi lacus sed viverra tellus in.
+
+Praesent elementum facilisis leo vel fringilla est ullamcorper eget.
+
+Id aliquet risus feugiat in ante metus dictum at tempor. Sed blandit libero volutpat sed cras. Sed odio morbi quis commodo odio aenean sed adipiscing. Velit euismod in pellentesque massa placerat. Mi bibendum neque egestas congue quisque egestas diam in arcu. Nisi lacus sed viverra tellus in. Nibh cras pulvinar mattis nunc sed. Luctus accumsan tortor posuere ac ut consequat semper viverra. Fringilla ut morbi tincidunt augue interdum velit euismod.
+
+Morbi quis commodo.
+
+```jsx src/App.js focus=1,4,6:10
+import { motion } from "framer-motion"
+
+export default function App() {
+ const bg = "hsl(110, 100%, 50%)"
+ return (
+
+ )
+}
+```
+
+---
+
+## Step 3
+
+Id aliquet risus feugiat in ante metus dictum at tempor. Sed blandit libero volutpat sed cras. Sed odio morbi quis commodo odio aenean sed adipiscing. Velit euismod in pellentesque massa placerat. Mi bibendum neque egestas congue quisque egestas diam in arcu.
+
+- Nisi lacus sed viverra tellus in
+- Nibh cras pulvinar mattis nunc sed
+- Luctus accumsan tortor posuere ac
+
+Ut consequat semper viverra. Fringilla ut morbi tincidunt augue interdum velit euismod.
+
+```jsx src/App.js focus=1,4,6:10
+import { motion } from "framer-motion"
+
+export default function App() {
+ const bg = "hsl(200, 100%, 50%)"
+ return (
+
+ )
+}
+```
+
+---
+
+## Step 4
+
+Velit euismod in pellentesque massa placerat. Mi bibendum neque egestas congue quisque egestas diam in arcu. Nisi lacus sed viverra tellus in. Venenatis cras sed felis eget velit. Consectetur libero id faucibus nisl tincidunt.
+
+Sed blandit libero volutpat sed cras.
+
+- Nisi lacus sed viverra tellus in
+- Nibh cras pulvinar mattis nunc sed
+
+Gravida in fermentum et sollicitudin ac orci phasellus egestas tellus. Volutpat consequat mauris nunc congue nisi vitae.
+
+```jsx src/App.js focus=1,4,6:10
+import { motion } from "framer-motion"
+
+export default function App() {
+ const bg = "hsl(290, 100%, 50%)"
+ return (
+
+ )
+}
+```
+
+---
+
+## Step 5
+
+Velit euismod in pellentesque massa placerat. Mi bibendum neque egestas congue quisque egestas diam in arcu. Nisi lacus sed viverra tellus in.
+
+Praesent elementum facilisis leo vel fringilla est ullamcorper eget.
+
+Id aliquet risus feugiat in ante metus dictum at tempor. Sed blandit libero volutpat sed cras. Sed odio morbi quis commodo odio aenean sed adipiscing. Velit euismod in pellentesque massa placerat.
+
+Mi bibendum neque egestas congue quisque egestas diam in arcu. Nisi lacus sed viverra tellus in. Nibh cras pulvinar mattis nunc sed. Luctus accumsan tortor posuere ac ut consequat semper viverra.
+
+- Fringilla ut morbi tincidunt augue interdum velit euismod.
+- Luctus accumsan tortor posuere ac ut consequat semper viverra.
+
+Morbi quis commodo.
+
+```jsx src/App.js focus=1,4,6:10
+import { motion } from "framer-motion"
+
+export default function App() {
+ const bg = "hsl(10, 100%, 50%)"
+ return (
+
+ )
+}
+```
+
+
+
+Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Praesent elementum facilisis leo vel fringilla est ullamcorper eget. At imperdiet dui accumsan sit amet nulla facilities morbi tempus. Praesent elementum facilisis leo vel fringilla. Congue mauris rhoncus aenean vel. Egestas sed tempus urna et pharetra pharetra massa massa ultricies.
+
+Consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Praesent elementum facilisis leo vel fringilla est ullamcorper eget. At imperdiet dui accumsan sit amet nulla facilities morbi tempus. Praesent elementum facilisis leo vel fringilla. Congue mauris rhoncus aenean vel. Egestas sed tempus urna et pharetra pharetra massa massa ultricies.
diff --git a/examples/bundle-test/pages/spotlight.mdx b/examples/bundle-test/pages/spotlight.mdx
new file mode 100644
index 00000000..cdf56055
--- /dev/null
+++ b/examples/bundle-test/pages/spotlight.mdx
@@ -0,0 +1,80 @@
+# Spotlight
+
+This is how to use the `` component. Lorem ipsum dolor sit amet consectetur adipisicing elit. Quisquam, quia! Quidem, quisquam.
+
+
+
+```js app.js
+function lorem(ipsum, dolor = 1) {
+ const sit = ipsum == null && 0
+ dolor = sit - amet(dolor)
+ return sit ? consectetur(ipsum) : []
+}
+```
+
+---
+
+Change focus
+
+```js app.js focus=2:4
+
+```
+
+---
+
+Or change the code
+
+```js app.js focus=6:10
+function lorem(ipsum, dolor = 1) {
+ const sit = ipsum == null && 0
+ dolor = sit - amet(dolor)
+ return sit ? consectetur(ipsum) : []
+}
+
+function adipiscing(...elit) {
+ console.log(elit)
+ return elit.map((ipsum) => ipsum.sit)
+}
+```
+
+---
+
+Or change the file
+
+
+
+```js app.js focus=1:4
+function adipiscing(...elit) {
+ console.log(elit)
+ return elit.map((ipsum) => ipsum.sit)
+}
+```
+
+---
+
+```css styles.css
+.lorem {
+ color: #fff;
+ padding: 10px;
+ background: #000;
+}
+```
+
+
+
+---
+
+### By the way
+
+- you can
+- put any
+- markdown
+- here
+
+👍
+
+```js app.js
+
+```
+
+
diff --git a/package.json b/package.json
index ed36d866..acfbad8c 100644
--- a/package.json
+++ b/package.json
@@ -9,6 +9,7 @@
},
"scripts": {
"build": "lerna run --stream build",
+ "build:lib": "lerna run --stream --scope @*/mdx build",
"test": "lerna run --stream test",
"dev": "lerna run --stream --scope @*/mdx dev",
"storybook": "lerna run --scope storybook start --stream",
diff --git a/packages/mdx/src/components.tsx b/packages/mdx/src/components.tsx
index ef8994a2..6a554ab2 100644
--- a/packages/mdx/src/components.tsx
+++ b/packages/mdx/src/components.tsx
@@ -27,3 +27,11 @@ export const CH = {
Slideshow,
InlineCode,
}
+
+import { MiniBrowser } from "./mini-browser"
+import { EditorSpring } from "./mini-editor"
+
+export const internal = {
+ MiniBrowser,
+ EditorSpring,
+}
diff --git a/packages/mdx/src/index.tsx b/packages/mdx/src/index.tsx
index 96046aed..63facbbb 100644
--- a/packages/mdx/src/index.tsx
+++ b/packages/mdx/src/index.tsx
@@ -1 +1,3 @@
export { remarkCodeHike } from "./mdx-plugin/plugin"
+
+export { highlight } from "./highlighter"