tg-blog 1.0.0-alpha.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,7 @@
1
+ import { Vue } from "vue-class-component";
2
+ export default class App extends Vue {
3
+ url: string;
4
+ keyboard: string;
5
+ switchUrl(): void;
6
+ mounted(): void;
7
+ }
@@ -0,0 +1,2 @@
1
+ export declare function durationFmt(duration: number): string;
2
+ export declare function sizeFmt(size: number): string;
@@ -0,0 +1,35 @@
1
+ export type MediaType = "audio_file" | "animation" | "video_file" | "sticker" | "voice_message";
2
+ export interface Image {
3
+ url: string;
4
+ width: number;
5
+ height: number;
6
+ }
7
+ export interface TGFile {
8
+ url: string;
9
+ mime_type: string;
10
+ media_type?: MediaType;
11
+ size: number;
12
+ thumb?: string;
13
+ duration?: number;
14
+ width?: number;
15
+ height?: number;
16
+ sticker_emoji?: string;
17
+ title?: string;
18
+ performer?: string;
19
+ }
20
+ export interface Post {
21
+ id: number;
22
+ date: string;
23
+ text?: string;
24
+ forwarded_from?: string;
25
+ type?: string;
26
+ views?: string;
27
+ author?: string;
28
+ reply?: {
29
+ id: number;
30
+ text: string;
31
+ thumb?: string;
32
+ };
33
+ images?: Image[];
34
+ files?: TGFile[];
35
+ }
@@ -0,0 +1,7 @@
1
+ /**
2
+ * Initialize clickable spoilers on the page
3
+ */
4
+ export declare function initSpoilers(): void;
5
+ export declare function sanitize(html: string): any;
6
+ export declare function mdParseInline(s: string): any;
7
+ export declare function mdParse(s: string): any;
@@ -0,0 +1 @@
1
+ import '@fortawesome/fontawesome-free/css/all.min.css';
@@ -0,0 +1,15 @@
1
+ import { Vue } from 'vue-class-component';
2
+ import { TGFile } from "@/logic/models";
3
+ export default class AudioPlayer extends Vue {
4
+ audio: TGFile;
5
+ playing: HTMLAudioElement;
6
+ duration: string;
7
+ time: string;
8
+ mounted(): void;
9
+ pause(): void;
10
+ play(): void;
11
+ next(): void;
12
+ prev(): void;
13
+ unmounted(): void;
14
+ init(): void;
15
+ }
@@ -0,0 +1,13 @@
1
+ import { Vue } from 'vue-class-component';
2
+ import { TGFile } from "@/logic/models";
3
+ export default class FileView extends Vue {
4
+ f: TGFile;
5
+ hasHead: boolean;
6
+ fileThumbClick(): void;
7
+ play(): TGFile;
8
+ get shouldDisplayDetail(): boolean;
9
+ get isAudioOrVoice(): boolean;
10
+ get fileTitle(): string | undefined;
11
+ get duration(): string;
12
+ get size(): string;
13
+ }
@@ -0,0 +1,15 @@
1
+ import { Vue } from 'vue-class-component';
2
+ import { Image, Post } from "@/logic/models";
3
+ export default class PostView extends Vue {
4
+ p: Post;
5
+ postsUrl: string;
6
+ get text(): string | undefined;
7
+ getImageStyle(post: Post, i: Image): object;
8
+ clickReply(): void;
9
+ mounted(): void;
10
+ replaceUrl(url: string): string;
11
+ /**
12
+ * Initialize custom emojis
13
+ */
14
+ initEmoji(): void;
15
+ }
@@ -0,0 +1,13 @@
1
+ import { Vue } from 'vue-class-component';
2
+ import { Post, TGFile } from "@/logic/models";
3
+ export default class TgBlog extends Vue {
4
+ posts: Post[];
5
+ postsUrl: string;
6
+ audio?: TGFile;
7
+ fail: string;
8
+ get audios(): TGFile[];
9
+ audioNext(off: number): void;
10
+ replaceUrl(url: string): string;
11
+ created(): void;
12
+ updated(): void;
13
+ }
package/package.json ADDED
@@ -0,0 +1,48 @@
1
+ {
2
+ "name": "tg-blog",
3
+ "version": "1.0.0-alpha.1",
4
+ "browser": {
5
+ "./sfc": "src/"
6
+ },
7
+ "scripts": {
8
+ "dev": "vite",
9
+ "serve": "vite",
10
+ "build": "vue-tsc && vite build",
11
+ "lint": "eslint --ext .js,.vue --ignore-path .gitignore --fix src"
12
+ },
13
+ "peerDependencies": {
14
+ "@fortawesome/fontawesome-free": "^6.2.1",
15
+ "@types/marked": "^4.0.7",
16
+ "element-plus": "^2.2.26",
17
+ "linkify-urls": "^4.0.0",
18
+ "marked": "^4.2.3",
19
+ "moment": "^2.29.4",
20
+ "sanitize-html": "^2.7.3",
21
+ "url-join": "^5.0.0",
22
+ "vue": "^3.2.33"
23
+ },
24
+ "devDependencies": {
25
+ "@types/moment": "^2.13.0",
26
+ "@types/node": "^18.11.10",
27
+ "@vitejs/plugin-vue": "^3.2.0",
28
+ "sass": "^1.50.0",
29
+ "typescript": "^4.6.3",
30
+ "vite": "^3.2.4",
31
+ "vue-class-component": "^8.0.0-rc.1",
32
+ "vue-property-decorator": "^10.0.0-rc.3",
33
+ "vue-tsc": "^1.0.11",
34
+ "vue": "^3.2.33"
35
+ },
36
+ "files": [
37
+ "src",
38
+ "dist"
39
+ ],
40
+ "types": "./dist/types/main.d.ts",
41
+ "module": "./dist/tg-blog.es.js",
42
+ "exports": {
43
+ ".": {
44
+ "import": "./dist/tg-blog.es.js"
45
+ },
46
+ "./dist/style.css": "./dist/style.css"
47
+ }
48
+ }
package/src/App.vue ADDED
@@ -0,0 +1,68 @@
1
+ <template>
2
+ <TgBlog v-if="this.url" :postsUrl="url"></TgBlog>
3
+ <div v-else class="card">
4
+ <h2>Please specify demo path</h2>
5
+ Available paths:
6
+ <div><a href="/liaotalk">无聊的话</a></div>
7
+ <div><a href="/test">Testing Channel</a></div>
8
+ <div><a href="/Uekawakuyuurei">秋雲</a></div>
9
+ Or type your data url (posts.json) here:
10
+ <input v-model="keyboard">
11
+ <button @click="switchUrl">Load</button>
12
+ </div>
13
+ </template>
14
+
15
+ <script lang="ts">
16
+ import {Options, Vue} from "vue-class-component";
17
+ import TgBlog from "@/views/TgBlog.vue";
18
+ import urlJoin from "url-join";
19
+
20
+ const backendHost = "https://test-tg-data.hydev.org"
21
+
22
+ @Options({components: {TgBlog}})
23
+ export default class App extends Vue
24
+ {
25
+ url: string = null
26
+
27
+ keyboard: string = ""
28
+
29
+ switchUrl()
30
+ {
31
+ window.location.replace('/custom?url=' + encodeURIComponent(this.keyboard))
32
+ }
33
+
34
+ mounted()
35
+ {
36
+ let p = window.location.pathname
37
+ if (p == '/custom')
38
+ {
39
+ let params = (new URL(document.location.toString())).searchParams;
40
+ this.url = params.get("url")
41
+ }
42
+ else
43
+ {
44
+ while (p.startsWith('/')) p = p.substring(1)
45
+ if (p) this.url = urlJoin(backendHost, p, '/posts.json')
46
+ }
47
+ }
48
+ }
49
+ </script>
50
+
51
+ <style lang="sass">
52
+ @import "css/colors"
53
+ @import "css/global"
54
+
55
+ #app
56
+ font-family: Avenir, Helvetica, Arial, sans-serif
57
+ -webkit-font-smoothing: antialiased
58
+ -moz-osx-font-smoothing: grayscale
59
+ text-align: center
60
+ color: #2c3e50
61
+
62
+ .rlink
63
+ color: hotpink
64
+ text-decoration: none
65
+
66
+ max-width: 600px
67
+ margin: auto
68
+ </style>
@@ -0,0 +1,9 @@
1
+ $color-text-main: #70512a
2
+ $color-text-light: rgba(166, 134, 89, 0.84)
3
+ $color-text-special: #ff8373
4
+ $color-text-special-dark: #ab4343
5
+
6
+ // Lower means lighter
7
+ $color-bg-6: #ffeedb
8
+ $color-bg-5: #fff4eb
9
+ $color-bg-4: #fffcf9
@@ -0,0 +1,161 @@
1
+ @import colors
2
+
3
+ // Constants
4
+ $font: Avenir, Helvetica, Arial, sans-serif
5
+
6
+ // Container width (This is normally 50vw,
7
+ // but when it's smaller than 900px, use 100vw - 50px, because 50px is the margin)
8
+ $app-width: max(50vw, min(900px, 100vw - 50px))
9
+ $c-highlight: #ff7878
10
+
11
+ // Highlight color
12
+ .color-highlight
13
+ color: $c-highlight
14
+
15
+ // Non-selectable text
16
+ @mixin unselectable
17
+ -webkit-touch-callout: none
18
+ -webkit-user-select: none
19
+ -khtml-user-select: none
20
+ -moz-user-select: none
21
+ -ms-user-select: none
22
+ user-select: none
23
+
24
+ .unselectable
25
+ @include unselectable
26
+
27
+ @mixin undraggable
28
+ user-drag: none
29
+ -webkit-user-drag: none
30
+ @include unselectable
31
+
32
+ .undraggable
33
+ @include undraggable
34
+
35
+ img
36
+ @include undraggable
37
+
38
+ // Clickable text
39
+ .clickable:hover
40
+ cursor: pointer
41
+ @include unselectable
42
+
43
+ // Vertical flex
44
+ .fbox-v
45
+ display: flex
46
+ flex-flow: column
47
+ height: 100%
48
+
49
+ .mh0
50
+ min-height: 0
51
+
52
+ // Horizontal flex
53
+ .fbox-h
54
+ display: flex
55
+ flex-flow: row
56
+
57
+ .mw0
58
+ min-width: 0
59
+
60
+ // Flex properties
61
+ .f-no-grow
62
+ flex-grow: 0
63
+
64
+ .f-grow1
65
+ flex-grow: 1
66
+
67
+ .f-no-shrink
68
+ flex-shrink: 0
69
+
70
+ .f-shrink1
71
+ flex-shrink: 1
72
+
73
+ // Expand in the vertical direction
74
+ .f-v-expand
75
+ flex: 1 0
76
+ min-height: 0
77
+
78
+ // Expand in the horizontal direction
79
+ .f-h-expand
80
+ flex: 1 0
81
+ min-width: 0
82
+
83
+ .h100
84
+ height: 100%
85
+
86
+ .w100
87
+ width: 100%
88
+
89
+ // Vertical Flex Center
90
+ @mixin flex-vcenter
91
+ display: flex
92
+ flex-flow: column
93
+ justify-content: center
94
+
95
+ // Center both horizontally and vertically
96
+ .fbox-center
97
+ @include flex-vcenter
98
+ align-items: center
99
+
100
+ // Center vertically only
101
+ .fbox-vcenter
102
+ @include flex-vcenter
103
+
104
+ // No wrap text
105
+ .nowrap
106
+ overflow: hidden
107
+ white-space: nowrap
108
+ text-overflow: clip
109
+
110
+ .nowrap.e
111
+ text-overflow: ellipsis
112
+
113
+ .hy-card
114
+ width: 100%
115
+ height: 100%
116
+ background-color: #edf1f2
117
+ border-radius: 15px
118
+ margin: 20px 0
119
+
120
+ #page-desc
121
+ margin-bottom: 20px
122
+
123
+ .button.anim
124
+ transition: all .25s ease
125
+
126
+ .button.anim:hover
127
+ transform: translateY(-5px)
128
+ box-shadow: 0 10px 10px -5px $color-text-light
129
+ cursor: pointer
130
+
131
+ *
132
+ transition: all .25s ease
133
+
134
+ .card
135
+ width: 100%
136
+ background: #fdf9f1
137
+ border-radius: 20px
138
+ margin-bottom: 20px
139
+ padding: 10px 20px
140
+ overflow: auto
141
+ overflow-x: hidden
142
+ box-sizing: border-box
143
+ box-shadow: 0 4px 6px -1px rgb(0 0 0 / 10%), 0 2px 4px -1px rgb(0 0 0 / 6%)
144
+
145
+ .spoiler
146
+ @include unselectable
147
+ cursor: pointer
148
+ transition: all .4s ease
149
+ background-color: $color-text-light
150
+ margin: 0 1px
151
+ border-radius: 3px
152
+
153
+ span
154
+ opacity: 0
155
+
156
+ .spoiler.spoiler-visible
157
+ background-color: transparent
158
+
159
+ span
160
+ filter: blur(0)
161
+ opacity: 1
package/src/env.d.ts ADDED
@@ -0,0 +1,8 @@
1
+ /// <reference types="vite/client" />
2
+
3
+ declare module '*.vue' {
4
+ import { DefineComponent } from 'vue'
5
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any, @typescript-eslint/ban-types
6
+ const component: DefineComponent<{}, {}, any>
7
+ export default component
8
+ }
@@ -0,0 +1,19 @@
1
+ import moment from "moment";
2
+
3
+ export function durationFmt(duration: number): string
4
+ {
5
+ return moment.utc(moment.duration(duration, "seconds").asMilliseconds()).format("mm:ss")
6
+ }
7
+
8
+ export function sizeFmt(size: number): string
9
+ {
10
+ for (const unit of ["B", "KiB", "MiB", "GiB", "TiB", "PiB"])
11
+ {
12
+ if (Math.abs(size) < 1024.0)
13
+ {
14
+ return `${size.toFixed(1)} ${unit}`
15
+ }
16
+ size /= 1024.0
17
+ }
18
+ return "> 1024 PiB"
19
+ }
@@ -0,0 +1,43 @@
1
+ export type MediaType = "audio_file" | "animation" | "video_file" | "sticker" | "voice_message"
2
+
3
+ export interface Image {
4
+ url: string
5
+ width: number
6
+ height: number
7
+ }
8
+
9
+ export interface TGFile {
10
+ url: string
11
+ mime_type: string
12
+ media_type?: MediaType // If media_type is null, then it's not a media, just a regular file
13
+ size: number // Bytes
14
+ thumb?: string
15
+
16
+ duration?: number
17
+ width?: number
18
+ height?: number
19
+ sticker_emoji?: string
20
+ title?: string
21
+ performer?: string
22
+ }
23
+
24
+ export interface Post {
25
+ id: number
26
+ date: string
27
+
28
+ text?: string
29
+ forwarded_from?: string
30
+ type?: string // If type doesn't exist, it's a regular message
31
+ views?: string // Service messages have no view count
32
+ author?: string
33
+ reply?: {
34
+ id: number
35
+ text: string
36
+ thumb?: string
37
+ }
38
+ images?: Image[]
39
+ files?: TGFile[]
40
+ }
41
+ // TODO: Other files types (i.e. pdf)
42
+ // TODO: Video
43
+ // TODO: Author
@@ -0,0 +1,88 @@
1
+ import {marked} from "marked";
2
+ import sanitizeHtml from 'sanitize-html';
3
+
4
+ /**
5
+ * Initialize clickable spoilers on the page
6
+ */
7
+ export function initSpoilers()
8
+ {
9
+ const spoilers = document.querySelectorAll('.spoiler')
10
+
11
+ console.log("Spoilers initialized.")
12
+
13
+ spoilers.forEach(spoiler =>
14
+ {
15
+ // Already initialized
16
+ if (spoiler.classList.contains("spoiler-init")) return
17
+ spoiler.classList.add("spoiler-init")
18
+
19
+ // Add event listener
20
+ spoiler.addEventListener('click', () =>
21
+ {
22
+ spoiler.classList.toggle("spoiler-visible")
23
+ console.log(`Spoiler clicked: ${spoiler}`);
24
+ })
25
+ })
26
+ }
27
+
28
+ /**
29
+ * Spoiler markdown extension
30
+ */
31
+ const spoilerExtension = {
32
+ name: 'spoiler',
33
+ level: 'inline',
34
+ start(src) {
35
+ return src.match(/\|\|(?!\s)/)?.index;
36
+ },
37
+ tokenizer(src) {
38
+ const rule = /^\|\|(?!\s)([^\n]+)(?!\s)\|\|/;
39
+ const match = rule.exec(src);
40
+
41
+ if (match) {
42
+ // console.log(src, match)
43
+ return {type: 'spoiler', raw: match[0], inner: this.lexer.inlineTokens(match[1].trim())};
44
+ }
45
+ },
46
+ renderer(token) {
47
+ return `<span class="spoiler"><span>${this.parser.parseInline(token.inner)}</span></span>`;
48
+ }
49
+ };
50
+
51
+ marked.use({extensions: [spoilerExtension]})
52
+
53
+ /**
54
+ * SanitizeHTML options
55
+ */
56
+ const sanitizeOptions: sanitizeHtml.IOptions = {
57
+ allowedTags: [
58
+ "address", "article", "aside", "footer", "header", "h1", "h2", "h3", "h4",
59
+ "h5", "h6", "hgroup", "main", "nav", "section", "blockquote", "dd", "div",
60
+ "dl", "dt", "figcaption", "figure", "hr", "li", "main", "ol", "p", "pre",
61
+ "ul", "a", "abbr", "b", "bdi", "bdo", "br", "cite", "code", "data", "dfn",
62
+ "em", "i", "kbd", "mark", "q", "rb", "rp", "rt", "rtc", "ruby", "s", "samp",
63
+ "small", "span", "strong", "sub", "sup", "time", "u", "var", "wbr", "caption",
64
+ "col", "colgroup", "table", "tbody", "td", "tfoot", "th", "thead", "tr",
65
+
66
+ "img", "del"
67
+ ],
68
+ disallowedTagsMode: 'discard',
69
+ allowedAttributes: {
70
+ a: ['href', 'name', 'target'],
71
+ img: ['src', 'srcset', 'alt', 'title', 'width', 'height', 'loading'],
72
+ i: ['emoji-src', 'emoji-orig']
73
+ },
74
+ allowedClasses: {
75
+ span: ['spoiler'],
76
+ i: ['custom-emoji']
77
+ },
78
+ selfClosing: [ 'img', 'br', 'hr', 'area', 'base', 'basefont', 'input', 'link', 'meta' ],
79
+ allowedSchemes: [ 'http', 'https', 'ftp', 'mailto', 'tel' ],
80
+ allowedSchemesByTag: {},
81
+ allowedSchemesAppliedToAttributes: [ 'href', 'src', 'cite' ],
82
+ allowProtocolRelative: true,
83
+ enforceHtmlBoundary: false
84
+ }
85
+
86
+ export function sanitize(html: string) { return sanitizeHtml(html, sanitizeOptions) }
87
+ export function mdParseInline(s: string) { return sanitize(marked.parseInline(s)) }
88
+ export function mdParse(s: string) { return sanitize(marked.parse(s)) }
package/src/main.ts ADDED
@@ -0,0 +1,5 @@
1
+ import { createApp } from 'vue'
2
+ import App from './App.vue'
3
+ import '@fortawesome/fontawesome-free/css/all.min.css'
4
+
5
+ createApp(App).mount('#app')