diff --git a/package.json b/package.json index 82b65b0..653af57 100644 --- a/package.json +++ b/package.json @@ -19,7 +19,6 @@ "@fullhuman/postcss-purgecss": "^1.3.0", "autoprefixer": "^9.6.0", "babel-loader": "^8.0.6", - "babel-plugin-prismjs": "^1.1.1", "babel-polyfill": "^6.26.0", "cross-env": "^6.0.3", "css-loader": "^2.1.1", diff --git a/src/index.js b/src/index.js index 62d1b53..ec44b80 100644 --- a/src/index.js +++ b/src/index.js @@ -1,17 +1,7 @@ -import './style.css' - -import Prism from 'prismjs' - -import 'prismjs/themes/prism-coy.css' -import 'prismjs/components/prism-bash' -import 'prismjs/components/prism-javascript' - -import 'prismjs/plugins/line-numbers/prism-line-numbers' -import 'prismjs/plugins/line-numbers/prism-line-numbers.css' +import Prism from './prism' import './prism.css' - -Prism.highlightAll(); +import './style.css' window.displayMailChimpStatus = function (data) { if (!data.result || !data.msg) return diff --git a/src/pages/docs.html b/src/pages/docs.html index 6afb5c9..f451b82 100644 --- a/src/pages/docs.html +++ b/src/pages/docs.html @@ -4,7 +4,7 @@ @@ -16,29 +16,35 @@

Getting Started

Create a free Userbase account

-

First you need a Userbase account. You will be able to create a free account when Userbase gets launched. No credit card required.

+

First you need a Userbase developer account. You will be able to create a free account when Userbase gets launched. No credit card required.

Install the SDK

Then you need to include the Userbase SDK into your web app.

You can either include the SDK with a <script> tag:

-    <script type="text/javascript"
-  src="https://userbase-public.s3-us-west-2.amazonaws.com/userbase-js/userbase.js">
-</script>
+    
   

Or else you can include the SDK into your build pipeline:

-    npm --install --save userbase-js
+    
+    npm --install --save userbase-js
+    
   

Set the Application ID

From your Userbase account, create a new App and get the Application ID. Then you just need to configure the Userbase SDK to use it:

-    userbase.configure({ appId: 'a43ae910-fc89-43fe-a7a3-a11a53b49325' })
+    
   

And you're all set.

@@ -52,7 +58,7 @@

You can use Userbase through a simple JavaScript SDK in the browser. The following is the complete set of Userbase APIs that let you create user accounts, handle logins, and persist user data.

-

Users

+

Users

Use these APIs to create user accounts, handle logins and logouts, and resume sessions when a user returns to your web app.

-

Data

+

Data

Use these APIs to store and retrieve user data. All data handled by these APIs is highly-durable, immediately consistent, and end-to-end encrypted.

-
\ No newline at end of file +
+ +
+ +

Tutorial

+ +

+ In this tutorial we will build a simple to-do web app. Even if the web app you're + building has nothing to do with to-dos, the techniques we'll cover can be + applied to make many other kinds of web apps. +

+ +

+ With just 199 lines code inside a single static HTML file we will create an + end-to-end encrypted web application with: +

+ + + +

You can see a live demo of what we'll building here.

+ +

Prerequisites

+ +

You'll need to be familiar with HTML and JavaScript. Beyond the basics of JavaScript, you will need to be familiar with DOM manipulation, events, and Promises.

+ + +

What's in a name?

+ +

+ The reason we are calling our application "Ugly To-Do" is because we aren't + going to apply any styling but solely focus on core functionality. You can think + of this tutorial as a sort of "hello world" for Userbase, a demonstration of the + core functionality in the simplest way possible. +

+ +

+ In a real project you'll likely want a more sophisticated approach: for instance, you may use React to control the DOM or a module bundler to package your application from multiple files, and at the very + least you'll want to display better error messages and add some styling. +

+ +

+ We are working on a collection of tutorials and sample applications that will + show you how to do all these things with Userbase and more. You can subscribe to our mailing list to get updates on these and more. +

+ +

Setting up

+ +

Let's get setup to build our application. Open up a new file in your favorite editor:

+ +
+    
+      code ulgy-todo.html
+    
+  
+ +

And add some boilerplate HTML:

+ +
+
+      
+        <!DOCTYPE html>
+        <html lang="en">
+        <head>
+          <meta charset="UTF-8">
+          <title>Ugly To-Do</title>
+        </head>
+
+        <body>
+          <!-- application code -->
+          <script type="text/javascript">
+          </script>
+        </body>
+        </html>
+      
+    
+
+ +

+ Now open up this file in a web browser of your choosing. At this point all + you'll see is a blank page. As we add functionality throughout the tutorial, you + can reload the app by refreshing this page to see changes. +

+ +

Creating a developer account

+ +

To complete this tutorial, you'll need to create a Userbase developer account, and then create an app from within your account. Take not of the Application ID of your app.

+ +

+ We are now ready to start building the application. We'll start by implementing + functionality to sign up and sign in users and then implement to-do + functionality. +

+ +

Installing the SDK

+ + To use the Userbase SDK in our app, we'll load it from a CDN with a <script> tag in the head of + our page: + +
+
+      
+    
+
+ + The Userbase SDK will now be accessible via the global userbase variable. + +

Configuring the SDK

+ +

+ Before doing anything with the Userbase SDK, we need to configure it with our + Application ID (make sure to replace 'YOUR_APP_ID' with the Application ID of the Userbase App you created earlier): +

+ +
+
+      
+  
+
+ +

+ Now anything we do with the client (e.g. sign in a user, persist data) will + happen within the context of the app whose ID we specified. +

+ +

Letting new users create an account

+ +

+ Any actions that our users take will need to take place within an authenticated session. + We'll start off by adding a way to for new users to create an account with our app. +

+ +

First, we'll add a sign up form:

+ +
+
+      
+      <body>
+        <!-- Auth View -->
+        <div id="auth-view">
+          <h1>Create an account</h1>
+          <form id="signup-form">
+            <input id="create-account-username" type="email" required placeholder="Email">
+            <input id="create-account-password" type="password" required placeholder="Password">
+            <input type="submit" value="Create an account">
+          </form>
+          <div id="create-account-error"></div>
+        </div>
+
+        <!-- application code -->
+        <script type="text/javascript"></script>
+      </body>
+    
+    
+
+ +

Then, we'll add code to handle the form submissions:

+ +
+
+      
+      <!-- application code -->
+      <script type="text/javascript">
+        function handleSignUp(e) {
+          e.preventDefault()
+  
+          const username = document.getElementById('create-account-username').value
+          const password = document.getElementById('create-account-password').value
+  
+          userbase.signUp(username, password)
+            .then((session) => alert('You signed up!'))
+            .catch((e) => document.getElementById('create-account-error').innerHTML = e)
+        }
+  
+        document.getElementById('signup-form').addEventListener('submit', handleSignUp)
+      </script>
+      
+    
+
+ +

+ Whenever a submit event is triggered on our sign up form, handleSignUp will be called. +

+ +

+ The first thing we do in handleSignUp is call preventDefault() on the + submit event. This will prevent the page from submitting to the server. +

+ +

+ Next we get the values of the username and password inputs and call + userbase.signUp(username, password) which will request a new account to be created with the Userbase service. A Promise is returned that either resolves + with a new session object, in which case we fire an alert (for now), or rejects + with an error, in which case we display the error message. +

+ +

+ Go ahead and reload the web app in your browser. Enter a username and password + in the form under "Sign Up" and submit. You'll get an alert saying "You signed + up!". +

+ +

+ Now try signing up for another account using the same username and you'll see an + error message displayed under the form (since an account already exists with + this username). +

+ +

+ We'll come back in a bit and change this function to do something more + interesting than just sending an alert when an user successfully signs up. +

+ +

Letting users log in

+ +

Now that users can create accounts, let's give them the ability to sign in.

+ +

+ First, we'll add a "Login" form to the page above our "Create Account" + form: +

+ +
+    
+    <body>
+      <!-- Auth View -->
+      <div id="auth-view">
+        <h1>Login</h1>
+        <form id="login-form"> 
+          <input id="login-username" type="email" required placeholder="Email">
+          <input id="login-password" type="password" required placeholder="Password">
+          <input type="submit" value="Sign in">
+        </form>
+        <div id="login-error"></div>
+
+        <h1>Create an account</h1>
+        <form id="signup-form">
+    
+  
+ +

Then, we'll add code to handle the form submission:

+ +
+    
+    <!-- application code -->
+    <script type="text/javascript">
+      function handleLogin(e) {
+        e.preventDefault()
+
+        const username = document.getElementById('login-username').value
+        const password = document.getElementById('login-password').value
+
+        userbase.signIn(username, password)
+          .then((session) => alert('You signed in!'))
+          .catch((e) => document.getElementById('login-error').innerHTML = e)
+      }
+
+      function handleSignUp(e) {
+        e.preventDefault()
+
+    ...
+
+    </script>
+
+    
+  
+ +

And finally, bind the login form within our login handler:

+ +
+    
+    <!-- application code -->
+    <script type="text/javascript">
+
+    ...
+
+        .catch((e) => document.getElementById('create-account-error').innerHTML = e)
+      }
+
+      document.getElementById('login-form').addEventListener('submit', handleLogin)
+      document.getElementById('signup-form').addEventListener('submit', handleSignUp)
+    </script>
+    </body>
+    
+  
+ +

You'll notice this looks very similar to the sign up code above.

+ +

+ We define a function, handleLogin, to handle form submissions. The function + prevents the default form behavior, extracts the input values from the DOM, and + calls userbase.signIn(username, password). This will attempt to sign in the user with the Userbase service, handling a success with an alert and a failure + by displaying the error. +

+ +

+ Reload the app and you'll now see a "Sign In" form. Enter the username and + password you used to create an account in the step above and submit the form. + You'll get an alert saying "You signed in!" +

+ +

+ Try submitting the form again with incorrect credentials and you'll see an error + message displayed under the form. +

+ +

Showing the to-do view

+ +

+ After a r is signed in, we'll want to hide the authentication forms, indicate + to the user they are logged in, and display their to-do list. +

+ +

First, we'll add a new container to the body:

+ +
+    
+    </div>
+
+    <!-- To-dos View -->
+    <div id="todo-view">
+      <div id="username"></div>
+
+      <h1>To-Do List</h1>
+    </div>
+
+    <!-- application code -->
+    <script type="text/javascript">
+      function handleLogin(e) {
+
+    ...
+
+    </script>
+    
+  
+ +

Then, we'll add function to display this view and initially make it hidden:

+ +
+
+      
+      function showTodos(username) {
+        document.getElementById('auth-view').style.display = 'none'
+        document.getElementById('todo-view').style.display = 'block'
+        document.getElementById('username').innerHTML = username
+      }
+      
+      document.getElementById('login-form').addEventListener('submit', handleLogin)
+      document.getElementById('signup-form').addEventListener('submit', handleSignUp)
+      
+      document.getElementById('todo-view').style.display = 'none'
+      
+    
+
+ +

+ Now that we have a function to show a view for signed in users, let's change + handleLogin to call this function when it succeed: +

+ +
+    
+    function handleLogin(e) {
+      e.preventDefault()
+
+      const password = document.getElementById('login-password').value
+
+      userbase.signIn(username, password)
+        .then((session) => showTodos(session.username))
+        .catch((e) => document.getElementById('login-error').innerHTML = e)
+    }
+    
+  
+ +

And we do the same thing for handleSignUp:

+ +
+    
+    function handleSignUp(e) {
+      e.preventDefault()
+
+      const password = document.getElementById('create-account-password').value
+
+      userbase.signUp(username, password)
+        .then((session) => showTodos(session.username))
+        .catch((e) => document.getElementById('create-account-error').innerHTML = e)
+    }
+    
+  
+ +

+ Reload the app and sign in using your username and password. You'll see the + authentication view disappear and your username show up along with "To-Do List". +

+ +

Using to the database

+ +

+ Each time a new session is started, we need to establish a connection with the + database that will hold that user's to-dos. +

+ +

+ First, let's add a couple elements for showing a loading indicator and error + messages: +

+ +
+    
+  
+ +

Then, we'll change showTodos to open a new database with the Userbase service:

+ +
+    
+    function showTodos(username) {
+      document.getElementById('auth-view').style.display = 'none'
+      document.getElementById('todo-view').style.display = 'block'
+        
+      // reset the todos view
+      document.getElementById('username').innerHTML = username
+      document.getElementById('db-loading').style.display = 'block'
+      document.getElementById('db-error').innerText = ''
+
+      userbase.openDatabase('todos', handleDatabaseChange)
+        .then(() => {
+          document.getElementById('db-loading').style.display = 'none'
+        })
+        .catch((e) => {
+          document.getElementById('db-loading').style.display = 'none'
+          document.getElementById('db-error').innerText = e
+        })
+    }
+
+    function handleDatabaseChange(items) {
+      const todosList = document.getElementById('todos')
+
+      if (items.length === 0) {
+        todosList.innerText = "Empty"
+      } else {
+        // render to-dos, not yet implemented
+      }
+    }
+
+    document.getElementById('login-form').addEventListener('submit', handleLogin)
+    document.getElementById('signup-form').addEventListener('submit', handleSignUp)
+    
+  
+ +

+ We change showTodos to make a call to userbase.openDatabase('todos', + handleDatabaseChange), 'todos' being the name of the database we want to open + and handleDatabaseChange being a callback for receiving changes to data in the + database. The Userbase service will attempt to open the user's database by the + name of 'todos' (creating it if it doesn't already exist). After the 'todos' + database is opened, and whenever data changes in the database, our callback + function handleDatabaseChanges will be called. A Promise is returned that will + either resolve if the database was successfully opened, in which case we hide + the loading indicator, or otherwise reject, in which case we display the error + message. +

+ +

+ We add a function handleDatabaseChange for receiving changes to the database. + We check to see if there are any items in the database and if it's empty we display + this in the to-dos container. We'll implement the other case in the next step. +

+ +

+ Reload the app and sign in. You'll see the "Loading to-dos..." as a connection + to the database is established followed by "Empty" indicating there are + currently no to-dos. +

+ + +

Display the to-dos

+ +

+ If the database has items in it, we'll want to render those under to-do list. + Let's implement that case in handleDatabaseChange: +

+ +
+    
+  
+ +

Adding to-dos

+ +

Let's add a form for creating new to-dos:

+ + + +

Then, add code to handle form submissions:

+ +
+    
+    <!-- application code -->
+    <script type="text/javascript">
+    ...
+
+      function addTodoHandler(e) {
+        e.preventDefault()
+
+        const todo = document.getElementById('add-todo').value
+
+        userbase.insert('todos', { 'todo': todo }, Date.now())
+          .then(() => document.getElementById('add-todo').value = '')
+          .catch((e) => document.getElementById('add-todo-error').innerHTML = e)
+      }
+
+      document.getElementById('login-form').addEventListener('submit', handleLogin)
+      document.getElementById('signup-form').addEventListener('submit', handleSignUp)
+
+      document.getElementById('add-todo-form').addEventListener('submit', addTodoHandler)
+      document.getElementById('todo-view').style.display = 'none'
+      
+    </script>
+    
+  
+ +

+ In addTodoHandler we first call preventDefault() to stop the default form + behavior, pull the to-do text from the input, and then call userbase.insert + with the database name, object we want the persist, and the current time. This + will return a Promise that will resolve if the data is successfully persisted to + the database, in which case we clear the form input, or reject if the insert + failed, in which case we display the error message below the form. +

+ +

Updating to-dos

+ +

Let's modify how we are rendering a to-do so we can mark a to-do as completed:

+ +
+    
+    // render all the to-do items
+    for (let i = 0; i < items.length; i++) {
+
+      // build the todo checkbox
+      const todoBox = document.createElement('input')
+      todoBox.type = 'checkbox'
+      todoBox.id = items[i].itemId
+      todoBox.checked = items[i].record.complete ? true : false
+      todoBox.onclick = (e) => {
+        e.preventDefault()
+        userbase.update('todos', { 
+          'todo': items[i].record.todo, 
+          'complete': !items[i].record.complete 
+        }, items[i].itemId)
+        .catch((e) => document.getElementById('add-todo-error').innerHTML = e)
+      }
+
+      // build the todo label
+      const todoLabel = document.createElement('label')
+      todoLabel.innerHTML = items[i].record.todo
+
+    ...
+
+      // append the todo item to the list
+      const todoItem = document.createElement('div')
+      todoItem.appendChild(todoBox)
+      todoItem.appendChild(todoLabel)
+      todosList.appendChild(todoItem)
+    }
+    
+  
+ +

Deleting to-dos

+ +

Let's create a button for deleting a to-do:

+ +
+    
+    // render all the to-do items
+    for (let i = 0; i < items.length; i++) {
+
+      // build the todo delete button
+      const todoDelete = document.createElement('button')
+      todoDelete.innerHTML = 'X'
+      todoDelete.style.display = 'inline-block'
+      todoDelete.onclick = () => {
+        userbase.delete('todos', items[i].itemId)
+          .catch((e) => document.getElementById('add-todo-error').innerHTML = e)
+      }
+
+      // build the todo checkbox
+      const todoBox = document.createElement('input')
+      todoBox.type = 'checkbox'
+    
+  
+ +

And append the delete button to to-do element:

+ +
+    
+    // append the todo item to the list
+    const todoItem = document.createElement('div')
+    todoItem.appendChild(todoDelete)
+    todoItem.appendChild(todoBox)
+    todoItem.appendChild(todoLabel)
+    todosList.appendChild(todoItem)
+    
+  
+ +

Polishing up

+ +

Before we wrap up, let's add two final pieces of account functionality: user logout and automatic login for users who already have a session.

+ +

Signing out users

+ +

First, add a logout button along with a container for displaying error messages:

+ + + +

Then, add code to handle click events and log out the user:

+ +
+    
+    <!-- application code -->
+    <script type="text/javascript">
+    
+    ...
+
+        .catch((e) => document.getElementById('create-account-error').innerHTML = e)
+      }
+
+      function handleLogout() {
+        userbase.signOut()
+          .then(() => showAuth())
+          .catch((e) => document.getElementById('logout-error').innerText = e)
+      }
+
+      function showTodos(username) {
+        document.getElementById('auth-view').style.display = 'none'
+        document.getElementById('todo-view').style.display = 'block'
+
+    ...
+
+      function showAuth() {
+        document.getElementById('todo-view').style.display = 'none'
+        document.getElementById('auth-view').style.display = 'block'
+        document.getElementById('login-username').value = ''
+        document.getElementById('login-password').value = ''
+        document.getElementById('login-error').innerText = ''
+        document.getElementById('create-account-username').value = ''
+        document.getElementById('create-account-password').value = ''
+        document.getElementById('create-account-error').innerText = ''
+      }
+
+      function handleDatabaseChange(items) {
+        const todosList = document.getElementById('todos')
+
+    ...
+
+      document.getElementById('login-form').addEventListener('submit', handleLogin)
+      document.getElementById('signup-form').addEventListener('submit', handleSignUp)
+      document.getElementById('add-todo-form').addEventListener('submit', addTodoHandler)
+      document.getElementById('logout-button').addEventListener('click', handleLogout)
+      document.getElementById('todo-view').style.display = 'none'
+    </script>
+    
+  
+ +

The logout function calls userbase.signOut which sends a request to end the user's session to the Userbase service. A Promise is returned that either resolves if the user was signed out successfully, in which case we hide the to-do view and show the account view using showAuth, or rejects with an error, in which case we display the error message.

+ +

Automatically resuming a session

+ +

Whenever a new session is created, either by signing up or signing in a user, the Userbase client will store information about the session in browser storage to allow for the session to be resumed when the user returns after having navigating away, whether by closing the page or otherwise.

+ +

Let's modify our app to automatically sign in a user when the page loads. We'll add a view that indicates we are signing in the user:

+ +

Add add a view to show when initializing:

+ +
+    
+    </head>
+ 
+    <body>
+      <!-- Init View -->
+      <div id="init-view">Signing you in...</div>
+
+      <!-- Auth View -->
+      <div id="auth-view">
+      <h1>Login</h1>
+    
+  
+ +

In order to automatically resume a session if one is available, we add the following to our application code:

+ +
+    
+    <!-- application code -->
+    <script type="text/javascript">
+    
+    ...
+    
+      document.getElementById('login-form').addEventListener('submit', handleLogin)
+      document.getElementById('signup-form').addEventListener('submit', handleSignUp)
+      document.getElementById('add-todo-form').addEventListener('submit', addTodoHandler)
+      document.getElementById('logout-button').addEventListener('click', handleLogout)
+
+      document.getElementById('todo-view').style.display = 'none'
+      document.getElementById('auth-view').style.display = 'none'
+
+      userbase.signInWithSession()
+        .then((session) => showTodos(session.username))
+        .catch(() => showAuth())
+        .then(() => document.getElementById('init-view').style.display = 'none')
+
+    </script>
+    
+  
+ +

+ We hide the auth view initially, as we'll now only show it if an existing + session can't be resumed. +

+ +

+ We make a call to userbase.signInWithSession to attempt to sign in the user + using an existing session as soon as our app loads. +

+ +

+ This function looks for a previous session in browser storage and if one is + found tries to sign in the user automatically with the Userbase service. It + returns a Promise that will resolve with a new session if the user was able to + be signed in or otherwise reject with ann error message? indicating the reason + for failure. +

+ +

+ A failure could be due to either no previous session, the user had + signed out, or their session expired. In our simple app we'll just send the user + to the sign in page regardless of the reason. +

+
\ No newline at end of file diff --git a/src/prism.css b/src/prism.css index 158be0e..309e1e6 100644 --- a/src/prism.css +++ b/src/prism.css @@ -1,20 +1,355 @@ -pre[class*="language-"]:before, pre[class*="language-"]:after { - content: normal; +/* PrismJS 1.17.1 +https://prismjs.com/download.html#themes=prism-coy&languages=markup+css+clike+javascript&plugins=line-highlight+toolbar+unescaped-markup+normalize-whitespace+copy-to-clipboard */ +/** + * prism.js Coy theme for JavaScript, CoffeeScript, CSS and HTML + * Based on https://github.com/tshedor/workshop-wp-theme (Example: http://workshop.kansan.com/category/sessions/basics or http://workshop.timshedor.com/category/sessions/basics); + * @author Tim Shedor + */ + +code[class*="language-"], +pre[class*="language-"] { + color: black; + background: none; + font-family: Consolas, Monaco, 'Andale Mono', 'Ubuntu Mono', monospace; + font-size: 1em; + text-align: left; + white-space: pre; + word-spacing: normal; + word-break: normal; + word-wrap: normal; + line-height: 1.5; + + -moz-tab-size: 4; + -o-tab-size: 4; + tab-size: 4; + + -webkit-hyphens: none; + -moz-hyphens: none; + -ms-hyphens: none; + hyphens: none; } -pre[class*="language-"], :not(pre) > code[class*="language-"], pre[class*="language-"] { - margin: 0; - line-height: 0.6em; +/* Code blocks */ +pre[class*="language-"] { + position: relative; + margin: .5em 0; + overflow: visible; + padding: 0; +} +pre[class*="language-"]>code { + position: relative; + border-left: 10px solid #358ccb; + box-shadow: -1px 0px 0px 0px #358ccb, 0px 0px 0px 1px #dfdfdf; + background-color: #fdfdfd; + background-image: linear-gradient(transparent 50%, rgba(69, 142, 209, 0.04) 50%); + background-size: 3em 3em; + background-origin: content-box; + background-attachment: local; } code[class*="language"] { - padding-top: 1em; - padding-bottom: 1em; + max-height: inherit; + height: inherit; + padding: 0 1em; + display: block; + overflow: auto; +} + +/* Margin bottom to accommodate shadow */ +:not(pre) > code[class*="language-"], +pre[class*="language-"] { + background-color: #fdfdfd; + -webkit-box-sizing: border-box; + -moz-box-sizing: border-box; + box-sizing: border-box; + margin-bottom: 1em; +} + +/* Inline code */ +:not(pre) > code[class*="language-"] { + position: relative; + padding: .2em; + border-radius: 0.3em; + color: #c92c2c; + border: 1px solid rgba(0, 0, 0, 0.1); + display: inline; + white-space: normal; +} + +pre[class*="language-"]:before, +pre[class*="language-"]:after { + content: ''; + z-index: -2; + display: block; + position: absolute; + bottom: 0.75em; + left: 0.18em; + width: 40%; + height: 20%; + max-height: 13em; + box-shadow: 0px 13px 8px #979797; + -webkit-transform: rotate(-2deg); + -moz-transform: rotate(-2deg); + -ms-transform: rotate(-2deg); + -o-transform: rotate(-2deg); + transform: rotate(-2deg); +} + +:not(pre) > code[class*="language-"]:after, +pre[class*="language-"]:after { + right: 0.75em; + left: auto; + -webkit-transform: rotate(2deg); + -moz-transform: rotate(2deg); + -ms-transform: rotate(2deg); + -o-transform: rotate(2deg); + transform: rotate(2deg); +} + +.token.comment, +.token.block-comment, +.token.prolog, +.token.doctype, +.token.cdata { + color: #7D8B99; +} + +.token.punctuation { + color: #5F6364; +} + +.token.property, +.token.tag, +.token.boolean, +.token.number, +.token.function-name, +.token.constant, +.token.symbol, +.token.deleted { + color: #c92c2c; +} + +.token.selector, +.token.attr-name, +.token.string, +.token.char, +.token.function, +.token.builtin, +.token.inserted { + color: #2f9c0a; +} + +.token.operator, +.token.entity, +.token.url, +.token.variable { + color: #a67f59; + background: rgba(255, 255, 255, 0.5); +} + +.token.atrule, +.token.attr-value, +.token.keyword, +.token.class-name { + color: #1990b8; +} + +.token.regex, +.token.important { + color: #e90; +} + +.language-css .token.string, +.style .token.string { + color: #a67f59; + background: rgba(255, 255, 255, 0.5); +} + +.token.important { + font-weight: normal; +} + +.token.bold { + font-weight: bold; +} +.token.italic { + font-style: italic; +} + +.token.entity { + cursor: help; +} + +.namespace { + opacity: .7; +} + +@media screen and (max-width: 767px) { + pre[class*="language-"]:before, + pre[class*="language-"]:after { + bottom: 14px; + box-shadow: none; + } + +} + +/* Plugin styles */ +.token.tab:not(:empty):before, +.token.cr:before, +.token.lf:before { + color: #e0d7d1; +} + +/* Plugin styles: Line Numbers */ +pre[class*="language-"].line-numbers.line-numbers { + padding-left: 0; +} + +pre[class*="language-"].line-numbers.line-numbers code { + padding-left: 3.8em; +} + +pre[class*="language-"].line-numbers.line-numbers .line-numbers-rows { + left: 0; +} + +/* Plugin styles: Line Highlight */ +pre[class*="language-"][data-line] { + padding-top: 0; + padding-bottom: 0; + padding-left: 0; +} +pre[data-line] code { + position: relative; + padding-left: 4em; +} +pre .line-highlight { + margin-top: 0; +} + +pre[data-line] { + position: relative; + padding: 1em 0 1em 3em; +} + +.line-highlight { + position: absolute; + left: 0; + right: 0; + padding: inherit 0; + margin-top: 1em; /* Same as .prism’s padding-top */ + + background: hsla(24, 20%, 50%,.08); + background: linear-gradient(to right, hsla(24, 20%, 50%,.1) 70%, hsla(24, 20%, 50%,0)); + + pointer-events: none; + + line-height: inherit; + white-space: pre; +} + + .line-highlight:before, + .line-highlight[data-end]:after { + content: attr(data-start); + position: absolute; + top: .4em; + left: .6em; + min-width: 1em; + padding: 0 .5em; + background-color: hsla(24, 20%, 50%,.4); + color: hsl(24, 20%, 95%); + font: bold 65%/1.5 sans-serif; + text-align: center; + vertical-align: .3em; + border-radius: 999px; + text-shadow: none; + box-shadow: 0 1px white; + } + + .line-highlight[data-end]:after { + content: attr(data-end); + top: auto; + bottom: .4em; + } + +.line-numbers .line-highlight:before, +.line-numbers .line-highlight:after { + content: none; +} + +div.code-toolbar { + position: relative; +} + +div.code-toolbar > .toolbar { + position: absolute; + top: .3em; + right: .2em; + transition: opacity 0.3s ease-in-out; + opacity: 0; +} + +div.code-toolbar:hover > .toolbar { + opacity: 1; +} + +/* Separate line b/c rules are thrown out if selector is invalid. + IE11 and old Edge versions don't support :focus-within. */ +div.code-toolbar:focus-within > .toolbar { + opacity: 1; +} + +div.code-toolbar > .toolbar .toolbar-item { + display: inline-block; +} + +div.code-toolbar > .toolbar a { + cursor: pointer; +} + +div.code-toolbar > .toolbar button { + background: none; + border: 0; + color: inherit; + font: inherit; + line-height: normal; + overflow: visible; + padding: 0; + -webkit-user-select: none; /* for button */ + -moz-user-select: none; + -ms-user-select: none; +} + +div.code-toolbar > .toolbar a, +div.code-toolbar > .toolbar button, +div.code-toolbar > .toolbar span { + color: #bbb; + font-size: .8em; + padding: 0 .5em; + background: #f5f2f0; + background: rgba(224, 224, 224, 0.2); + box-shadow: 0 2px 0 0 rgba(0,0,0,0.2); + border-radius: .5em; +} + +div.code-toolbar > .toolbar a:hover, +div.code-toolbar > .toolbar a:focus, +div.code-toolbar > .toolbar button:hover, +div.code-toolbar > .toolbar button:focus, +div.code-toolbar > .toolbar span:hover, +div.code-toolbar > .toolbar span:focus { + color: inherit; + text-decoration: none; +} + +/* Fallback, in case JS does not run, to ensure the code is at least visible */ +[class*='lang-'] script[type='text/plain'], +[class*='language-'] script[type='text/plain'], +script[type='text/plain'][class*='lang-'], +script[type='text/plain'][class*='language-'] { + display: block; + font: 100% Consolas, Monaco, monospace; + white-space: pre; + overflow: auto; } -pre[class*="language-"]>code { - background-color: #f6f6f6; - box-shadow: none; - background-image: none; - font-size: 0.7em; -} \ No newline at end of file diff --git a/src/prism.js b/src/prism.js new file mode 100644 index 0000000..86ed868 --- /dev/null +++ b/src/prism.js @@ -0,0 +1,12 @@ +/* PrismJS 1.17.1 +https://prismjs.com/download.html#themes=prism-coy&languages=markup+css+clike+javascript&plugins=line-highlight+toolbar+unescaped-markup+normalize-whitespace+copy-to-clipboard */ +var _self="undefined"!=typeof window?window:"undefined"!=typeof WorkerGlobalScope&&self instanceof WorkerGlobalScope?self:{},Prism=function(u){var c=/\blang(?:uage)?-([\w-]+)\b/i,r=0;var _={manual:u.Prism&&u.Prism.manual,disableWorkerMessageHandler:u.Prism&&u.Prism.disableWorkerMessageHandler,util:{encode:function(e){return e instanceof L?new L(e.type,_.util.encode(e.content),e.alias):Array.isArray(e)?e.map(_.util.encode):e.replace(/&/g,"&").replace(/e.length)return;if(!(k instanceof L)){if(d&&y!=r.length-1){if(c.lastIndex=v,!(O=c.exec(e)))break;for(var b=O.index+(f&&O[1]?O[1].length:0),w=O.index+O[0].length,A=y,P=v,x=r.length;A"+n.content+""},!u.document)return u.addEventListener&&(_.disableWorkerMessageHandler||u.addEventListener("message",function(e){var r=JSON.parse(e.data),n=r.language,t=r.code,a=r.immediateClose;u.postMessage(_.highlight(t,_.languages[n],n)),a&&u.close()},!1)),_;var e=_.util.currentScript();if(e&&(_.filename=e.src,e.hasAttribute("data-manual")&&(_.manual=!0)),!_.manual){function n(){_.manual||_.highlightAll()}var t=document.readyState;"loading"===t||"interactive"===t&&e.defer?document.addEventListener("DOMContentLoaded",n):window.requestAnimationFrame?window.requestAnimationFrame(n):window.setTimeout(n,16)}return _}(_self);"undefined"!=typeof module&&module.exports&&(module.exports=Prism),"undefined"!=typeof global&&(global.Prism=Prism); +Prism.languages.markup={comment://,prolog:/<\?[\s\S]+?\?>/,doctype:{pattern:/"'[\]]|"[^"]*"|'[^']*')+(?:\[(?:(?!)*\]\s*)?>/i,greedy:!0},cdata://i,tag:{pattern:/<\/?(?!\d)[^\s>\/=$<%]+(?:\s(?:\s*[^\s>\/=]+(?:\s*=\s*(?:"[^"]*"|'[^']*'|[^\s'">=]+(?=[\s>]))|(?=[\s/>])))+)?\s*\/?>/i,greedy:!0,inside:{tag:{pattern:/^<\/?[^\s>\/]+/i,inside:{punctuation:/^<\/?/,namespace:/^[^\s>\/:]+:/}},"attr-value":{pattern:/=\s*(?:"[^"]*"|'[^']*'|[^\s'">=]+)/i,inside:{punctuation:[/^=/,{pattern:/^(\s*)["']|["']$/,lookbehind:!0}]}},punctuation:/\/?>/,"attr-name":{pattern:/[^\s>\/]+/,inside:{namespace:/^[^\s>\/:]+:/}}}},entity:/&#?[\da-z]{1,8};/i},Prism.languages.markup.tag.inside["attr-value"].inside.entity=Prism.languages.markup.entity,Prism.hooks.add("wrap",function(a){"entity"===a.type&&(a.attributes.title=a.content.replace(/&/,"&"))}),Object.defineProperty(Prism.languages.markup.tag,"addInlined",{value:function(a,e){var s={};s["language-"+e]={pattern:/(^$)/i,lookbehind:!0,inside:Prism.languages[e]},s.cdata=/^$/i;var n={"included-cdata":{pattern://i,inside:s}};n["language-"+e]={pattern:/[\s\S]+/,inside:Prism.languages[e]};var t={};t[a]={pattern:RegExp("(<__[\\s\\S]*?>)(?:\\s*|[\\s\\S])*?(?=<\\/__>)".replace(/__/g,a),"i"),lookbehind:!0,greedy:!0,inside:n},Prism.languages.insertBefore("markup","cdata",t)}}),Prism.languages.xml=Prism.languages.extend("markup",{}),Prism.languages.html=Prism.languages.markup,Prism.languages.mathml=Prism.languages.markup,Prism.languages.svg=Prism.languages.markup; +!function(s){var t=/("|')(?:\\(?:\r\n|[\s\S])|(?!\1)[^\\\r\n])*\1/;s.languages.css={comment:/\/\*[\s\S]*?\*\//,atrule:{pattern:/@[\w-]+[\s\S]*?(?:;|(?=\s*\{))/,inside:{rule:/@[\w-]+/}},url:{pattern:RegExp("url\\((?:"+t.source+"|[^\n\r()]*)\\)","i"),inside:{function:/^url/i,punctuation:/^\(|\)$/}},selector:RegExp("[^{}\\s](?:[^{};\"']|"+t.source+")*?(?=\\s*\\{)"),string:{pattern:t,greedy:!0},property:/[-_a-z\xA0-\uFFFF][-\w\xA0-\uFFFF]*(?=\s*:)/i,important:/!important\b/i,function:/[-a-z0-9]+(?=\()/i,punctuation:/[(){};:,]/},s.languages.css.atrule.inside.rest=s.languages.css;var e=s.languages.markup;e&&(e.tag.addInlined("style","css"),s.languages.insertBefore("inside","attr-value",{"style-attr":{pattern:/\s*style=("|')(?:\\[\s\S]|(?!\1)[^\\])*\1/i,inside:{"attr-name":{pattern:/^\s*style/i,inside:e.tag.inside},punctuation:/^\s*=\s*['"]|['"]\s*$/,"attr-value":{pattern:/.+/i,inside:s.languages.css}},alias:"language-css"}},e.tag))}(Prism); +Prism.languages.clike={comment:[{pattern:/(^|[^\\])\/\*[\s\S]*?(?:\*\/|$)/,lookbehind:!0},{pattern:/(^|[^\\:])\/\/.*/,lookbehind:!0,greedy:!0}],string:{pattern:/(["'])(?:\\(?:\r\n|[\s\S])|(?!\1)[^\\\r\n])*\1/,greedy:!0},"class-name":{pattern:/(\b(?:class|interface|extends|implements|trait|instanceof|new)\s+|\bcatch\s+\()[\w.\\]+/i,lookbehind:!0,inside:{punctuation:/[.\\]/}},keyword:/\b(?:if|else|while|do|for|return|in|instanceof|function|new|try|throw|catch|finally|null|break|continue)\b/,boolean:/\b(?:true|false)\b/,function:/\w+(?=\()/,number:/\b0x[\da-f]+\b|(?:\b\d+\.?\d*|\B\.\d+)(?:e[+-]?\d+)?/i,operator:/[<>]=?|[!=]=?=?|--?|\+\+?|&&?|\|\|?|[?*/~^%]/,punctuation:/[{}[\];(),.:]/}; +Prism.languages.javascript=Prism.languages.extend("clike",{"class-name":[Prism.languages.clike["class-name"],{pattern:/(^|[^$\w\xA0-\uFFFF])[_$A-Z\xA0-\uFFFF][$\w\xA0-\uFFFF]*(?=\.(?:prototype|constructor))/,lookbehind:!0}],keyword:[{pattern:/((?:^|})\s*)(?:catch|finally)\b/,lookbehind:!0},{pattern:/(^|[^.])\b(?:as|async(?=\s*(?:function\b|\(|[$\w\xA0-\uFFFF]|$))|await|break|case|class|const|continue|debugger|default|delete|do|else|enum|export|extends|for|from|function|get|if|implements|import|in|instanceof|interface|let|new|null|of|package|private|protected|public|return|set|static|super|switch|this|throw|try|typeof|undefined|var|void|while|with|yield)\b/,lookbehind:!0}],number:/\b(?:(?:0[xX](?:[\dA-Fa-f](?:_[\dA-Fa-f])?)+|0[bB](?:[01](?:_[01])?)+|0[oO](?:[0-7](?:_[0-7])?)+)n?|(?:\d(?:_\d)?)+n|NaN|Infinity)\b|(?:\b(?:\d(?:_\d)?)+\.?(?:\d(?:_\d)?)*|\B\.(?:\d(?:_\d)?)+)(?:[Ee][+-]?(?:\d(?:_\d)?)+)?/,function:/#?[_$a-zA-Z\xA0-\uFFFF][$\w\xA0-\uFFFF]*(?=\s*(?:\.\s*(?:apply|bind|call)\s*)?\()/,operator:/--|\+\+|\*\*=?|=>|&&|\|\||[!=]==|<<=?|>>>?=?|[-+*/%&|^!=<>]=?|\.{3}|\?[.?]?|[~:]/}),Prism.languages.javascript["class-name"][0].pattern=/(\b(?:class|interface|extends|implements|instanceof|new)\s+)[\w.\\]+/,Prism.languages.insertBefore("javascript","keyword",{regex:{pattern:/((?:^|[^$\w\xA0-\uFFFF."'\])\s])\s*)\/(?:\[(?:[^\]\\\r\n]|\\.)*]|\\.|[^/\\\[\r\n])+\/[gimyus]{0,6}(?=\s*(?:$|[\r\n,.;})\]]))/,lookbehind:!0,greedy:!0},"function-variable":{pattern:/#?[_$a-zA-Z\xA0-\uFFFF][$\w\xA0-\uFFFF]*(?=\s*[=:]\s*(?:async\s*)?(?:\bfunction\b|(?:\((?:[^()]|\([^()]*\))*\)|[_$a-zA-Z\xA0-\uFFFF][$\w\xA0-\uFFFF]*)\s*=>))/,alias:"function"},parameter:[{pattern:/(function(?:\s+[_$A-Za-z\xA0-\uFFFF][$\w\xA0-\uFFFF]*)?\s*\(\s*)(?!\s)(?:[^()]|\([^()]*\))+?(?=\s*\))/,lookbehind:!0,inside:Prism.languages.javascript},{pattern:/[_$a-z\xA0-\uFFFF][$\w\xA0-\uFFFF]*(?=\s*=>)/i,inside:Prism.languages.javascript},{pattern:/(\(\s*)(?!\s)(?:[^()]|\([^()]*\))+?(?=\s*\)\s*=>)/,lookbehind:!0,inside:Prism.languages.javascript},{pattern:/((?:\b|\s|^)(?!(?:as|async|await|break|case|catch|class|const|continue|debugger|default|delete|do|else|enum|export|extends|finally|for|from|function|get|if|implements|import|in|instanceof|interface|let|new|null|of|package|private|protected|public|return|set|static|super|switch|this|throw|try|typeof|undefined|var|void|while|with|yield)(?![$\w\xA0-\uFFFF]))(?:[_$A-Za-z\xA0-\uFFFF][$\w\xA0-\uFFFF]*\s*)\(\s*)(?!\s)(?:[^()]|\([^()]*\))+?(?=\s*\)\s*\{)/,lookbehind:!0,inside:Prism.languages.javascript}],constant:/\b[A-Z](?:[A-Z_]|\dx?)*\b/}),Prism.languages.insertBefore("javascript","string",{"template-string":{pattern:/`(?:\\[\s\S]|\${(?:[^{}]|{(?:[^{}]|{[^}]*})*})+}|(?!\${)[^\\`])*`/,greedy:!0,inside:{"template-punctuation":{pattern:/^`|`$/,alias:"string"},interpolation:{pattern:/((?:^|[^\\])(?:\\{2})*)\${(?:[^{}]|{(?:[^{}]|{[^}]*})*})+}/,lookbehind:!0,inside:{"interpolation-punctuation":{pattern:/^\${|}$/,alias:"punctuation"},rest:Prism.languages.javascript}},string:/[\s\S]+/}}}),Prism.languages.markup&&Prism.languages.markup.tag.addInlined("script","javascript"),Prism.languages.js=Prism.languages.javascript; +!function(){if("undefined"!=typeof self&&self.Prism&&self.document&&document.querySelector){var t,n=function(){if(void 0===t){var e=document.createElement("div");e.style.fontSize="13px",e.style.lineHeight="1.5",e.style.padding=0,e.style.border=0,e.innerHTML=" 
 ",document.body.appendChild(e),t=38===e.offsetHeight,document.body.removeChild(e)}return t},a=0;Prism.hooks.add("before-sanity-check",function(e){var t=e.element.parentNode,n=t&&t.getAttribute("data-line");if(t&&n&&/pre/i.test(t.nodeName)){var i=0;r(".line-highlight",t).forEach(function(e){i+=e.textContent.length,e.parentNode.removeChild(e)}),i&&/^( \n)+$/.test(e.code.slice(-i))&&(e.code=e.code.slice(0,-i))}}),Prism.hooks.add("complete",function e(t){var n=t.element.parentNode,i=n&&n.getAttribute("data-line");if(n&&i&&/pre/i.test(n.nodeName)){clearTimeout(a);var r=Prism.plugins.lineNumbers,o=t.plugins&&t.plugins.lineNumbers;if(l(n,"line-numbers")&&r&&!o)Prism.hooks.add("line-numbers",e);else s(n,i)(),a=setTimeout(u,1)}}),window.addEventListener("hashchange",u),window.addEventListener("resize",function(){var t=[];r("pre[data-line]").forEach(function(e){t.push(s(e))}),t.forEach(i)})}function r(e,t){return Array.prototype.slice.call((t||document).querySelectorAll(e))}function l(e,t){return t=" "+t+" ",-1<(" "+e.className+" ").replace(/[\n\t]/g," ").indexOf(t)}function i(e){e()}function s(u,e,d){var t=(e="string"==typeof e?e:u.getAttribute("data-line")).replace(/\s+/g,"").split(","),c=+u.getAttribute("data-line-offset")||0,f=(n()?parseInt:parseFloat)(getComputedStyle(u).lineHeight),h=l(u,"line-numbers"),p=h?u:u.querySelector("code")||u,m=[];return t.forEach(function(e){var t=e.split("-"),n=+t[0],i=+t[1]||n,r=u.querySelector('.line-highlight[data-range="'+e+'"]')||document.createElement("div");if(m.push(function(){r.setAttribute("aria-hidden","true"),r.setAttribute("data-range",e),r.className=(d||"")+" line-highlight"}),h&&Prism.plugins.lineNumbers){var o=Prism.plugins.lineNumbers.getLine(u,n),a=Prism.plugins.lineNumbers.getLine(u,i);if(o){var l=o.offsetTop+"px";m.push(function(){r.style.top=l})}if(a){var s=a.offsetTop-o.offsetTop+a.offsetHeight+"px";m.push(function(){r.style.height=s})}}else m.push(function(){r.setAttribute("data-start",n),n|>)/gi,"<\/script>"),e.textContent=t.code,a.appendChild(e),t.element.parentNode.replaceChild(a,t.element),void(t.element=e)}var a=t.element.parentNode;!t.code&&a&&"pre"==a.nodeName.toLowerCase()&&t.element.childNodes.length&&"#comment"==t.element.childNodes[0].nodeName&&(t.element.textContent=t.code=t.element.childNodes[0].textContent)})); +!function(){var i=Object.assign||function(e,n){for(var t in n)n.hasOwnProperty(t)&&(e[t]=n[t]);return e};function e(e){this.defaults=i({},e)}function l(e){for(var n=0,t=0;t code[class*="language-"], pre[class*="language-"] { + line-height: 24px; + font-size: 16px; +} + +code[class*="language"] { + padding-top: 16px; + padding-bottom: 16px; + margin-top: 1em; + margin-bottom: 1em; +} + +pre[class*="language-"]>code { + background-color: #f6f6f6; + box-shadow: none; + background-image: none; +} + +.line-highlight:before, .line-highlight[data-end]:after { + content: normal; +} + +pre[data-line] code { + padding-left: 1em; +} + +pre .line-highlight { + margin-top: 16px; + background-image: none; + background-color: rgba(0, 255, 0, 0.12); +} + +.token.operator, .token.entity, .token.url, .token.variable { + color: #ff8000; + background: none; +} + @tailwind utilities; diff --git a/src/template.html b/src/template.html index 3f5c4a0..39ef1d5 100644 --- a/src/template.html +++ b/src/template.html @@ -8,7 +8,7 @@ -
+