├── .npmignore ├── .prettierrc ├── renovate.json ├── postcss.config.js ├── .browserslistrc ├── src ├── types │ ├── shims-vue.d.ts │ ├── vue-component-wrapper.d.ts │ ├── shims-tsx.d.ts │ └── item.ts ├── utils │ ├── sanitizer.ts │ ├── getSlideCursor.ts │ ├── http.ts │ └── parser.ts ├── development.ts ├── main.ts ├── components │ ├── SlideViewer.vue │ ├── ErrorView.vue │ ├── LoadingView.vue │ ├── SlideControl.vue │ └── LoadingIndicator.vue ├── Kamishibai.vue └── DevApp.vue ├── tests └── unit │ └── utils │ └── getSlideCursor.spec.ts ├── .gitignore ├── vue.config.js ├── public └── index.html ├── jest.config.js ├── tsconfig.json ├── LICENSE ├── CHANGELOG.md ├── package.json └── README.md /.npmignore: -------------------------------------------------------------------------------- 1 | tests/ 2 | public/ 3 | -------------------------------------------------------------------------------- /.prettierrc: -------------------------------------------------------------------------------- 1 | { 2 | "semi": false, 3 | "singleQuote": true 4 | } 5 | -------------------------------------------------------------------------------- /renovate.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": [ 3 | "config:base" 4 | ] 5 | } 6 | -------------------------------------------------------------------------------- /postcss.config.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | plugins: { 3 | autoprefixer: {} 4 | } 5 | } 6 | -------------------------------------------------------------------------------- /.browserslistrc: -------------------------------------------------------------------------------- 1 | last 2 Chrome versions 2 | > 2.5% 3 | not ie <= 12 4 | Firefox >= 61 5 | Edge >= 17 6 | -------------------------------------------------------------------------------- /src/types/shims-vue.d.ts: -------------------------------------------------------------------------------- 1 | declare module '*.vue' { 2 | import Vue from 'vue' 3 | export default Vue 4 | } 5 | -------------------------------------------------------------------------------- /src/utils/sanitizer.ts: -------------------------------------------------------------------------------- 1 | import xss from 'xss' 2 | 3 | export function sanitizeAllTags(html: string): string { 4 | return xss(html) 5 | } 6 | -------------------------------------------------------------------------------- /src/types/vue-component-wrapper.d.ts: -------------------------------------------------------------------------------- 1 | declare module '@vue/web-component-wrapper' { 2 | export default function wrap(Vue: any, Component: any): any 3 | } 4 | -------------------------------------------------------------------------------- /src/utils/getSlideCursor.ts: -------------------------------------------------------------------------------- 1 | export function getSlideCursor( 2 | pageLength: number, 3 | elementWidth: number, 4 | clientX: number 5 | ) { 6 | return ~~((clientX / elementWidth) * pageLength) + 1 7 | } 8 | -------------------------------------------------------------------------------- /src/development.ts: -------------------------------------------------------------------------------- 1 | import Vue from 'vue' 2 | import DevApp from './DevApp.vue' 3 | 4 | Vue.config.productionTip = false 5 | Vue.config.errorHandler = () => { 6 | 7 | } 8 | 9 | new Vue({ 10 | render: h => h(DevApp) 11 | }).$mount('#app') 12 | -------------------------------------------------------------------------------- /src/main.ts: -------------------------------------------------------------------------------- 1 | import Vue from 'vue' 2 | const { default: wrap } = require('@vue/web-component-wrapper') 3 | const { default: Kamishibai } = require('./Kamishibai.vue?shadow') 4 | 5 | window.customElements.define('kamishibai-viewer', wrap(Vue, Kamishibai)) 6 | -------------------------------------------------------------------------------- /tests/unit/utils/getSlideCursor.spec.ts: -------------------------------------------------------------------------------- 1 | import { getSlideCursor } from "@/utils/getSlideCursor"; 2 | 3 | describe('getSlideCursor.ts', () => { 4 | test('getSlideCursor', () => { 5 | expect(getSlideCursor(20, 520, 0)).toBe(1) 6 | expect(getSlideCursor(20, 520, 519)).toBe(20) 7 | }) 8 | }) 9 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | .DS_Store 2 | node_modules 3 | /dist 4 | 5 | # local env files 6 | .env.local 7 | .env.*.local 8 | 9 | # Log files 10 | npm-debug.log* 11 | yarn-debug.log* 12 | yarn-error.log* 13 | 14 | # Editor directories and files 15 | .idea 16 | .vscode 17 | *.suo 18 | *.ntvs* 19 | *.njsproj 20 | *.sln 21 | *.sw* 22 | -------------------------------------------------------------------------------- /src/types/shims-tsx.d.ts: -------------------------------------------------------------------------------- 1 | import Vue, { VNode } from 'vue' 2 | 3 | declare global { 4 | namespace JSX { 5 | // tslint:disable no-empty-interface 6 | interface Element extends VNode {} 7 | // tslint:disable no-empty-interface 8 | interface ElementClass extends Vue {} 9 | interface IntrinsicElements { 10 | [elem: string]: any 11 | } 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /vue.config.js: -------------------------------------------------------------------------------- 1 | const pkg = require('./package.json') 2 | let baseUrl = '/' 3 | 4 | if (process.env.BUILD_TYPE === 'lib') { 5 | baseUrl = `/kamishibai-viewer/dist/${pkg.version}/` 6 | } 7 | 8 | if (process.env.BUILD_TYPE === 'app') { 9 | baseUrl = `/kamishibai-viewer/` 10 | } 11 | 12 | if (process.env.VUE_TEST === '1') { 13 | baseUrl = baseUrl.replace('/kamishibai-viewer/', '/') 14 | } 15 | 16 | module.exports = { 17 | baseUrl 18 | } 19 | -------------------------------------------------------------------------------- /public/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | Kamishibai - Web Component based Qiita slide viewer built with Vue.js(Vue CLI v3) 8 | 9 | 10 |
11 | 12 | 13 | 14 | 15 | -------------------------------------------------------------------------------- /jest.config.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | moduleFileExtensions: [ 3 | 'js', 4 | 'json', 5 | 'vue', 6 | 'ts' 7 | ], 8 | transform: { 9 | '^.+\\.vue$': 'vue-jest', 10 | '.+\\.(css|styl|less|sass|scss|svg|png|jpg|ttf|woff|woff2)$': 'jest-transform-stub', 11 | '^.+\\.tsx?$': 'ts-jest' 12 | }, 13 | moduleNameMapper: { 14 | '^@/(.*)$': '/src/$1' 15 | }, 16 | snapshotSerializers: [ 17 | 'jest-serializer-vue' 18 | ], 19 | testMatch: [ 20 | '**/tests/unit/**/*.spec.(js|jsx|ts|tsx)|**/__tests__/*.(js|jsx|ts|tsx)' 21 | ], 22 | testURL: 'http://localhost/' 23 | } 24 | -------------------------------------------------------------------------------- /src/utils/http.ts: -------------------------------------------------------------------------------- 1 | import { Item } from '../types/item' 2 | 3 | interface Option { 4 | token: string 5 | } 6 | 7 | export async function fetchItem(id: string, option?: Option) { 8 | let config = {} 9 | const token = (option || ({} as Option)).token 10 | if (token) { 11 | config = { 12 | headers: { 13 | authorization: `Bearer ${token}` 14 | } 15 | } 16 | } 17 | try { 18 | const res = await fetch(`https://qiita.com/api/v2/items/${id}`, config) 19 | const data = (await res.json()) as Item 20 | return data 21 | } catch (e) { 22 | throw new Error() 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "compilerOptions": { 3 | "target": "es5", 4 | "module": "esnext", 5 | "strict": true, 6 | "jsx": "preserve", 7 | "importHelpers": true, 8 | "moduleResolution": "node", 9 | "esModuleInterop": true, 10 | "downlevelIteration": true, 11 | "allowSyntheticDefaultImports": true, 12 | "sourceMap": true, 13 | "baseUrl": ".", 14 | "types": [ 15 | "webpack-env", 16 | "jest" 17 | ], 18 | "paths": { 19 | "@/*": [ 20 | "src/*" 21 | ] 22 | }, 23 | "lib": [ 24 | "esnext", 25 | "dom", 26 | "dom.iterable", 27 | "scripthost" 28 | ] 29 | }, 30 | "include": [ 31 | "src/**/*.ts", 32 | "src/**/*.vue", 33 | "tests/**/*.ts", 34 | ], 35 | "exclude": [ 36 | "node_modules" 37 | ] 38 | } 39 | -------------------------------------------------------------------------------- /src/components/SlideViewer.vue: -------------------------------------------------------------------------------- 1 | 6 | 7 | 33 | -------------------------------------------------------------------------------- /src/types/item.ts: -------------------------------------------------------------------------------- 1 | export interface Item { 2 | rendered_body: string 3 | body: string 4 | coediting: boolean 5 | comments_count: number 6 | created_at: string 7 | group?: null 8 | id: string 9 | likes_count: number 10 | private: boolean 11 | reactions_count: number 12 | tags?: (TagsEntity)[] | null 13 | title: string 14 | updated_at: string 15 | url: string 16 | user: User 17 | page_views_count?: null 18 | } 19 | 20 | export interface TagsEntity { 21 | name: string 22 | versions?: (null)[] | null 23 | } 24 | 25 | export interface User { 26 | description: string 27 | facebook_id: string 28 | followees_count: number 29 | followers_count: number 30 | github_login_name: string 31 | id: string 32 | items_count: number 33 | linkedin_id: string 34 | location: string 35 | name: string 36 | organization: string 37 | permanent_id: number 38 | profile_image_url: string 39 | team_only: boolean 40 | twitter_screen_name: string 41 | website_url: string 42 | } 43 | -------------------------------------------------------------------------------- /src/components/ErrorView.vue: -------------------------------------------------------------------------------- 1 | 7 | 8 | 22 | 23 | 47 | -------------------------------------------------------------------------------- /src/utils/parser.ts: -------------------------------------------------------------------------------- 1 | import { Item } from '@/types/item' 2 | import { sanitizeAllTags } from './sanitizer' 3 | 4 | export function parseItem(item: Item): string[] { 5 | const doc = new DOMParser().parseFromString(item.rendered_body, 'text/html') 6 | const elements = doc.querySelectorAll('html > body > *') 7 | const sections = [firstPage(item)] 8 | for (let el of elements) { 9 | if ( 10 | ['H1', 'H2'].includes(el.tagName) || 11 | el.classList.contains('footnotes') 12 | ) { 13 | sections.push('') 14 | } 15 | if (el.tagName === 'HR') { 16 | sections.push('') 17 | continue 18 | } 19 | sections[sections.length - 1] = `${sections[sections.length - 1]}${ 20 | el.outerHTML 21 | }` 22 | } 23 | return sections.filter(section => section) 24 | } 25 | 26 | const firstPage = (item: Item) => ` 27 |
28 |

${sanitizeAllTags(item.title)}

29 |
30 | by ${sanitizeAllTags(item.user.id)} 31 |
32 |
33 | ` 34 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2018 HANATANI Takuma (@potato4d) 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /CHANGELOG.md: -------------------------------------------------------------------------------- 1 | # Change Log 2 | 3 | All notable changes to this project will be documented in this file. See [standard-version](https://github.com/conventional-changelog/standard-version) for commit guidelines. 4 | 5 | 6 | ## [1.0.6](https://github.com/potato4d/kamishibai-viewer/compare/v1.0.5...v1.0.6) (2019-01-08) 7 | 8 | 9 | 10 | 11 | ## [1.0.5](https://github.com/potato4d/kamishibai-viewer/compare/v1.0.3...v1.0.5) (2019-01-08) 12 | 13 | 14 | 15 | 16 | ## [1.0.0](https://github.com/potato4d/kamishibai/compare/v0.1.0...v1.0.0) (2019-01-08) 17 | 18 | 19 | ## [0.1.1](https://github.com/potato4d/kamishibai/compare/v0.1.0...v0.1.1) (2018-12-26) 20 | 21 | 22 | 23 | 24 | # 0.1.0 (2018-12-26) 25 | 26 | 27 | ### Features 28 | 29 | * implement base functions ([8647b81](https://github.com/potato4d/kamishibai/commit/8647b81)) 30 | * Implement click pagination fix [#1](https://github.com/potato4d/kamishibai/issues/1) ([02692c8](https://github.com/potato4d/kamishibai/commit/02692c8)) 31 | * Implement loading and error handling ([60a77bc](https://github.com/potato4d/kamishibai/commit/60a77bc)) 32 | * Update devapp ([20a8604](https://github.com/potato4d/kamishibai/commit/20a8604)) 33 | -------------------------------------------------------------------------------- /src/components/LoadingView.vue: -------------------------------------------------------------------------------- 1 | 10 | 11 | 26 | 27 | 52 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "kamishibai-viewer", 3 | "version": "1.0.6", 4 | "main": "src/Kamishibai.vue", 5 | "repository": { 6 | "url": "potato4d/kamishibai-viewer", 7 | "type": "git" 8 | }, 9 | "scripts": { 10 | "serve": "vue-cli-service serve src/development.ts", 11 | "serve:prod": "vue-cli-service serve", 12 | "build": "cross-env BUILD_TYPE=lib VUE_CLI_CSS_SHADOW_MODE=true vue-cli-service build --dest dist/dist/1.0.6/ --target wc --name kamishibai-viewer ./src/main.ts", 13 | "build:web": "cross-env BUILD_TYPE=app vue-cli-service build --dest dist ./src/development.ts", 14 | "test:unit": "vue-cli-service test:unit", 15 | "format": "prettier './src/**/*.{ts,vue}' --write" 16 | }, 17 | "dependencies": { 18 | "@increments/qiita-slide-mode": "^0.2.1", 19 | "@vue/web-component-wrapper": "^1.2.0", 20 | "vue": "^2.5.17", 21 | "vue-awesome": "^3.2.0", 22 | "xss": "^1.0.3" 23 | }, 24 | "devDependencies": { 25 | "@types/jest": "23.3.14", 26 | "@vue/cli-plugin-typescript": "3.4.1", 27 | "@vue/cli-plugin-unit-jest": "3.4.1", 28 | "@vue/cli-service": "3.4.1", 29 | "@vue/test-utils": "1.0.0-beta.29", 30 | "cross-env": "5.2.0", 31 | "gh-pages": "2.0.1", 32 | "node-sass": "4.11.0", 33 | "prettier": "1.16.4", 34 | "sass-loader": "7.1.0", 35 | "standard-version": "4.4.0", 36 | "ts-jest": "24.0.0", 37 | "typescript": "3.3.3333", 38 | "vue-template-compiler": "2.6.7" 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Kamishibai Viewer 2 | 3 | [![Published on webcomponents.org](https://img.shields.io/badge/webcomponents.org-published-blue.svg)](https://www.webcomponents.org/element/potato4d/kamishibai-viewer) 4 | 5 | 8 | 9 | Web Component based Qiita slide viewer built with Vue.js(Vue CLI v3) 10 | 11 | [![Image from Gyazo](https://i.gyazo.com/447d26f36fd0d346464be0901ee51ddc.gif)](https://gyazo.com/447d26f36fd0d346464be0901ee51ddc) 12 | 13 | ## !! Under development !! 14 | 15 | Kamishibai is a under development library. 16 | Because breaking changes may be born, please be careful when using. 17 | 18 | ## About 19 | 20 | This is a library for embedding slides of Qiita which is a Japanese technical document sharing site. 21 | 22 | demo: https://potato4d.github.io/kamishibai-viewer/dist/1.0.0/demo.html 23 | 24 | ## Usage 25 | 26 | ※ As we are planning to publish to webcomponents.org, the URL may change! 27 | 28 | 1. Load runtime on script tag 29 | 30 | ``` 31 | 32 | 33 | ``` 34 | 35 | 2. Write custom element tag for your HTML 36 | 37 | ```html 38 | 39 | ``` 40 | 41 | 3. Done! 42 | 43 | ## Props 44 | - itemid: String 45 | - Qiita item ID 46 | - apikey?: String 47 | - Qiita personal access token 48 | 49 | ## Contributing 50 | 51 | requirements: 52 | 53 | - Node: Current LTS 54 | - Yarn: 1.12.0 or higher 55 | 56 | ### clone repository 57 | 58 | ```bash 59 | $ git clone https://github.com/potato4d/kamishibai-viewer 60 | $ cd kamishibai-viewer 61 | ``` 62 | 63 | ### Install deps 64 | 65 | ```bash 66 | $ yarn 67 | ``` 68 | 69 | ### Run development server 70 | 71 | ```bash 72 | $ yarn serve 73 | ``` 74 | 75 | ### Build 76 | 77 | ```bash 78 | $ yarn build:web # Build Development website 79 | $ yarn build # Build Web Component 80 | ``` 81 | 82 | ## LICENSE 83 | 84 | MIT @ HANATANI Takuma(@potato4d) 85 | 86 | email: mail@potato4d.me 87 | -------------------------------------------------------------------------------- /src/components/SlideControl.vue: -------------------------------------------------------------------------------- 1 | 50 | 51 | 81 | 82 | 91 | -------------------------------------------------------------------------------- /src/components/LoadingIndicator.vue: -------------------------------------------------------------------------------- 1 | 6 | 7 | 11 | 12 | 129 | -------------------------------------------------------------------------------- /src/Kamishibai.vue: -------------------------------------------------------------------------------- 1 | 29 | 30 | 111 | 112 | 134 | -------------------------------------------------------------------------------- /src/DevApp.vue: -------------------------------------------------------------------------------- 1 | 89 | 90 | 106 | 107 | 141 | --------------------------------------------------------------------------------