Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add bespoke template #5

Merged
merged 26 commits into from
Aug 29, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
2fbbafa
Apply async template rendering
yhatt Aug 25, 2018
bb09df2
Fix test of converter
yhatt Aug 25, 2018
86cf8ef
Update folder hierarchy about template module
yhatt Aug 25, 2018
d04fad8
Bundle bespoke.js by rollup to use in template
yhatt Aug 25, 2018
b6be330
Add bespoke template
yhatt Aug 25, 2018
13f0a46
Always use bare template on PDF conversion
yhatt Aug 25, 2018
a99b0fa
Support pre-loading resources on PDF conversion
yhatt Aug 25, 2018
8afcb8b
Support wheel navigation on bespoke template
yhatt Aug 25, 2018
ee6e91b
Add bespoke cursor plugin to hide inactive cursor
yhatt Aug 25, 2018
8ef6290
Activate bespoke cursor plugin on initialize
yhatt Aug 25, 2018
6c12a32
Support progress bar on bespoke template (false by default)
yhatt Aug 26, 2018
8644f4f
Ignore to collect coverage from js extension
yhatt Aug 26, 2018
6147a91
Set default template to bespoke
yhatt Aug 26, 2018
f294a10
Prevent navigate by wheel when cursor is targeted on scrollable element
yhatt Aug 26, 2018
e64bef5
Trigger #preventDefault on navigate slide deck by wheel
yhatt Aug 26, 2018
6cab8de
Add clever touch support
yhatt Aug 26, 2018
e6cfd52
Ignore wheel event on Marp's fitting header
yhatt Aug 26, 2018
780df1c
Fix using duplicated variables
yhatt Aug 26, 2018
12e8f4d
Improve scrollable detection of bespoke navigation plugin
yhatt Aug 26, 2018
652cbaa
Suppress momentum scrolling by trackpad navigation
yhatt Aug 27, 2018
b3ffee8
Add tests of bespoke template for classes, cursor, and hash plugin
yhatt Aug 27, 2018
10c9da0
Add test of bespoke template for navigation plugin
yhatt Aug 28, 2018
8ede0b7
Add test of bespoke template for progress plugin
yhatt Aug 28, 2018
8da846f
Add test of bespoke template for touch plugin
yhatt Aug 28, 2018
5fcbc97
Update docs
yhatt Aug 28, 2018
a63d876
Stop using ts-keycode-enum in bespoke plugin to reduce bundle size
yhatt Aug 28, 2018
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
### Added

- Support conversion from standard input ([#4](https://github.com/marp-team/marp-cli/pull/4))
- Add `bespoke` HTML template for ready to presentation ([#5](https://github.com/marp-team/marp-cli/pull/5))

### Fixed

Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -57,13 +57,13 @@ Under construction.

- [x] Add `marp` bin
- [x] Convert to plain HTML (includes style)
- [ ] Split into HTML and CSS
- [ ] Import external theme file(s)
- [x] Select theme by option
- [ ] Support configuration file (like `.marprc`)
- [ ] Watch mode
- [ ] Server mode
- [x] HTML templates
- [ ] Template that has ready to actual presentation powered by [Bespoke](https://github.com/bespokejs/bespoke)
- [x] Template that has ready to actual presentation powered by [Bespoke](https://github.com/bespokejs/bespoke)
- [ ] Select engine to use any Marpit based module
- [x] Export PDF directly by using [Puppeteer](https://github.com/GoogleChrome/puppeteer)

Expand Down
2 changes: 1 addition & 1 deletion jest.config.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
module.exports = {
collectCoverageFrom: ['src/**/*.{j,t}s'],
collectCoverageFrom: ['src/**/*.ts'],
coveragePathIgnorePatterns: ['/node_modules/', '.*\\.d\\.ts'],
coverageThreshold: { global: { lines: 95 } },
transform: {
Expand Down
3 changes: 3 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,8 @@
"@types/puppeteer": "^1.6.0",
"@types/yargs": "^11.1.1",
"autoprefixer": "^9.1.2",
"bespoke": "^1.1.0",
"bespoke-keys": "^1.1.0",
"codecov": "^3.0.4",
"cssnano": "^4.0.5",
"jest": "^23.5.0",
Expand All @@ -74,6 +76,7 @@
"stylelint-config-standard": "^18.2.0",
"stylelint-scss": "^3.3.0",
"ts-jest": "^23.1.4",
"ts-keycode-enum": "^1.0.6",
"tslint": "^5.11.0",
"tslint-config-airbnb": "^5.10.0",
"tslint-config-prettier": "^1.15.0",
Expand Down
60 changes: 33 additions & 27 deletions rollup.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,35 +11,41 @@ import typescript from 'typescript'
import { minify } from 'uglify-es'
import { dependencies } from './package.json'

const external = [
...Object.keys(dependencies),
'fs',
'path',
'chrome-launcher/dist/chrome-finder',
'yargs/yargs',
]

const plugins = [
json({ preferConst: true }),
nodeResolve({ jsnext: true }),
commonjs(),
typescriptPlugin({
resolveJsonModule: false, // JSON has already resolved by rollup-plugin-json
typescript,
}),
postcss({
inject: false,
plugins: [autoprefixer(), cssnano({ preset: 'default' })],
}),
pugPlugin(),
!process.env.ROLLUP_WATCH && uglify({}, minify),
]

export default [
{
external: [
...Object.keys(dependencies),
'fs',
'path',
'chrome-launcher/dist/chrome-finder',
'yargs/yargs',
],
external,
plugins,
input: 'src/templates/bespoke.js',
output: { file: 'lib/bespoke.js', format: 'iife' },
},
{
external,
plugins,
input: 'src/marp-cli.ts',
output: {
exports: 'named',
file: 'lib/marp-cli.js',
format: 'cjs',
},
plugins: [
json({ preferConst: true }),
nodeResolve({ jsnext: true }),
commonjs(),
typescriptPlugin({
resolveJsonModule: false, // JSON has already resolved by rollup-plugin-json
typescript,
}),
postcss({
inject: false,
plugins: [autoprefixer(), cssnano({ preset: 'default' })],
}),
pugPlugin(),
!process.env.ROLLUP_WATCH && uglify({}, minify),
],
output: { exports: 'named', file: 'lib/marp-cli.js', format: 'cjs' },
},
]
8 changes: 4 additions & 4 deletions src/converter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import * as chromeFinder from 'chrome-launcher/dist/chrome-finder'
import puppeteer, { PDFOptions } from 'puppeteer-core'
import { error } from './error'
import { File } from './file'
import templates, { TemplateResult } from './templates'
import templates, { TemplateResult } from './templates/'

export enum ConvertType {
html = 'html',
Expand Down Expand Up @@ -41,13 +41,13 @@ export class Converter {
return template
}

convert(markdown: string): TemplateResult {
async convert(markdown: string): Promise<TemplateResult> {
let additionals = ''

if (this.options.theme)
additionals += `\n<!-- theme: ${JSON.stringify(this.options.theme)} -->`

return this.template({
return await this.template({
lang: this.options.lang,
readyScript: this.options.readyScript,
renderer: tplOpts =>
Expand All @@ -57,7 +57,7 @@ export class Converter {

async convertFile(file: File): Promise<ConvertResult> {
const buffer = await file.load()
const template = this.convert(buffer.toString())
const template = await this.convert(buffer.toString())
const newFile = file.convert(this.options.output, this.options.type)

newFile.buffer = await (async () => {
Expand Down
3 changes: 2 additions & 1 deletion src/marp-cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ export default async function(argv: string[] = []): Promise<number> {
type: 'boolean',
},
template: {
default: 'bespoke',
describe: 'Template name',
group: OptionGroup.Converter,
choices: Object.keys(templates),
Expand All @@ -80,7 +81,7 @@ export default async function(argv: string[] = []): Promise<number> {
options: {},
output: args.output,
readyScript: await MarpReadyScript.bundled(),
template: args.template || 'bare',
template: args.template,
theme: args.theme,
type:
args.pdf || `${args.output}`.toLowerCase().endsWith('.pdf')
Expand Down
38 changes: 0 additions & 38 deletions src/templates.ts

This file was deleted.

21 changes: 0 additions & 21 deletions src/templates/bare.scss

This file was deleted.

2 changes: 1 addition & 1 deletion src/templates/bare.pug → src/templates/bare/bare.pug
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ html(lang=lang)
meta(charset="UTF-8")
meta(name="viewport", content="width=device-width, initial-scale=1.0")
meta(http-equiv="X-UA-Compatible", content="ie=edge")
style!= bare.css
style(media="screen")!= bare.css
style!= css
body
!= html
Expand Down
19 changes: 19 additions & 0 deletions src/templates/bare/bare.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
html,
body {
background: #000;
height: 100%;
margin: 0;
overflow: auto;
scroll-snap-type: y mandatory;

/* older spec */
scroll-snap-type: mandatory;
scroll-snap-points-y: repeat(100%);
}

body > svg {
display: block;
height: 100%;
scroll-snap-align: center center;
width: 100%;
}
3 changes: 3 additions & 0 deletions src/templates/bespoke.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import bespoke from './bespoke/bespoke'

bespoke()
16 changes: 16 additions & 0 deletions src/templates/bespoke/bespoke.pug
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
doctype
html(lang=lang)
head
meta(charset="UTF-8")
meta(name="viewport", content="width=device-width, initial-scale=1.0")
meta(http-equiv="X-UA-Compatible", content="ie=edge")
style!= bespoke.css
style!= css
body
if progress
.bespoke-progress-parent
.bespoke-progress-bar

!= html
!= readyScript
script(defer)!= bespoke.js
65 changes: 65 additions & 0 deletions src/templates/bespoke/bespoke.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
$progressHeight: 5px;

@media screen {
html,
body {
background: #000;
height: 100%;
margin: 0;
overflow: hidden;
}

.bespoke-marp-parent {
bottom: 0;
left: 0;
position: absolute;
right: 0;
top: 0;

&.bespoke-marp-cursor-inactive {
cursor: none;
}
}

svg.bespoke-marp-slide {
height: 100%;
left: 0;
pointer-events: none;
position: absolute;
top: 0;
width: 100%;
z-index: -1;

&.bespoke-marp-active {
pointer-events: auto;
z-index: 0;
}
}

.bespoke-progress-parent {
background: #222;
display: flex;
height: $progressHeight;
width: 100%;

& + .bespoke-marp-parent {
top: $progressHeight;
}

.bespoke-progress-bar {
flex: 0 0 0;
background: #0288d1;
transition: flex-basis 0.2s cubic-bezier(0, 1, 1, 1);
}
}
}

@media print {
.bespoke-progress-parent {
display: none;
}

.bespoke-marp-parent {
top: 0;
}
}
18 changes: 18 additions & 0 deletions src/templates/bespoke/bespoke.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import bespoke from 'bespoke'
import bespokeClasses from './classes'
import bespokeCursor from './cursor'
import bespokeHash from './hash'
import bespokeNavigation from './navigation'
import bespokeProgress from './progress'
import bespokeTouch from './touch'

export default function() {
return bespoke.from(document.getElementById('presentation'), [
bespokeClasses,
bespokeCursor(),
bespokeHash({ history: false }),
bespokeNavigation(),
bespokeProgress,
bespokeTouch(),
])
}
11 changes: 11 additions & 0 deletions src/templates/bespoke/classes.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
// Based on https://github.com/bespokejs/bespoke-classes

export default function bespokeClasses(deck) {
deck.parent.classList.add('bespoke-marp-parent')
deck.slides.map(element => element.classList.add('bespoke-marp-slide'))

deck.on('activate', e => {
deck.slides.map(element => element.classList.remove('bespoke-marp-active'))
e.slide.classList.add('bespoke-marp-active')
})
}
20 changes: 20 additions & 0 deletions src/templates/bespoke/cursor.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
export default function bespokeCursor(timeout = 2000) {
return deck => {
let activeTimer

function activate() {
if (activeTimer) clearTimeout(activeTimer)

activeTimer = setTimeout(() => {
deck.parent.classList.add('bespoke-marp-cursor-inactive')
}, timeout)

deck.parent.classList.remove('bespoke-marp-cursor-inactive')
}

document.addEventListener('mousedown', activate)
document.addEventListener('mousemove', activate)

setTimeout(activate, 0)
}
}
Loading