-
Notifications
You must be signed in to change notification settings - Fork 45
WIP: upgrade to latest sql.js #36
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
base: master
Are you sure you want to change the base?
Changes from all commits
e4bd4be
b0c81c4
68e7b83
a830e30
f561cab
df5835d
5333f8b
92bcbc5
c7e0b35
ebf6893
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,4 +1,3 @@ | ||
| /node_modules/ | ||
| /dist/ | ||
| node_modules/ | ||
| dist/ | ||
| *.log | ||
| play.js |
This file was deleted.
This file was deleted.
This file was deleted.
This file was deleted.
This file was deleted.
This file was deleted.
This file was deleted.
This file was deleted.
This file was deleted.
This file was deleted.
This file was deleted.
This file was deleted.
This file was deleted.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,4 @@ | ||
| node_modules | ||
| bundle.js | ||
| sql-wasm.wasm | ||
| yarn.lock |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,16 @@ | ||
| <!DOCTYPE html> | ||
| <html> | ||
| <head> | ||
| <meta charset="utf-8"> | ||
| <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1"> | ||
| <meta name="viewport" content="width=device-width,initial-scale=1.0"> | ||
| <title>anki-apkg-export demo</title> | ||
| </head> | ||
| <body> | ||
| <button id="buttonSimple">simple</button> | ||
| <button id="buttonAjax">ajax</button> | ||
| <input type="file" /> | ||
|
|
||
| <script src="/bundle.js"></script> | ||
| </body> | ||
| </html> |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,59 @@ | ||
| import AnkiExport from 'anki-apkg-export'; | ||
| import { saveAs } from 'file-saver'; | ||
| import initSqlJs from 'sql.js'; | ||
|
|
||
| (async () => { | ||
| const sql = await initSqlJs(); | ||
|
|
||
| document.querySelector('#buttonSimple').addEventListener('click', () => { | ||
| handleSimple(sql); | ||
| }); | ||
|
|
||
| document.querySelector('#buttonAjax').addEventListener('click', () => { | ||
| handleAjax(sql); | ||
| }); | ||
|
|
||
| document.querySelector('input').addEventListener('change', e => { | ||
| handleInput(sql, e.target.files[0]); | ||
| }); | ||
| })(); | ||
|
|
||
| async function handleSimple(sql) { | ||
| const apkg = new AnkiExport('deck-name', {}, sql); | ||
|
|
||
| apkg.addCard('card #1 front', 'card #1 back'); | ||
| apkg.addCard('card #2 front', 'card #2 back'); | ||
|
|
||
| const zip = await apkg.save(); | ||
| saveAs(zip, 'output.apkg'); | ||
| } | ||
|
|
||
| async function handleAjax(sql) { | ||
| const apkg = new AnkiExport('deck-name-ajax', {}, sql); | ||
|
|
||
| const response = await fetch('https://raw.githubusercontent.com/ewnd9/anki-apkg-export/39ebdd664ab23b5237eee95b7dd88c457e263a20/example/assets/anki.png'); | ||
| const myBlob = await response.blob(); | ||
|
|
||
| apkg.addMedia('anki.png', myBlob); | ||
| apkg.addCard('card #1 with image <img src="anki.png" />', 'card #1 back'); | ||
|
|
||
| const zip = await apkg.save() | ||
| saveAs(zip, 'output.apkg'); | ||
| } | ||
|
|
||
| async function handleInput(sql, file) { | ||
| const apkg = new AnkiExport('deck-name', {}, sql); | ||
| const reader = new FileReader(); | ||
|
|
||
| reader.onload = async e => { | ||
| const file = e.target.result; | ||
|
|
||
| apkg.addMedia('anki.png', file); | ||
| apkg.addCard('card #1 with image <img src="anki.png" />', 'card #1 back'); | ||
|
|
||
| const zip = await apkg.save() | ||
| saveAs(zip, 'output.apkg'); | ||
| }; | ||
|
|
||
| reader.readAsArrayBuffer(file); | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,16 @@ | ||
| { | ||
| "private": true, | ||
| "scripts": { | ||
| "build": "webpack --mode production" | ||
| }, | ||
| "dependencies": { | ||
| "anki-apkg-export": "file:../../", | ||
| "file-saver": "^2.0.2" | ||
| }, | ||
| "devDependencies": { | ||
| "copy-webpack-plugin": "^5.1.1", | ||
| "script-loader": "^0.7.2", | ||
| "webpack": "^4.41.5", | ||
| "webpack-cli": "^3.3.10" | ||
| } | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should this link to examples/browser-wasm?