Skip to content

Commit 65618a7

Browse files
authored
0.1.1 (#38)
* feat: make live demo code better (#37) * feat: add image loader in vue image (#39) * feat: use cssparser => csscolorparser (#40) * feat: playground use 0.1.1-beta vue-skia * feat: version 0.1.1 and modified font of playground hint * feat: playground font work correctly and blink no code back issue
1 parent e793a4d commit 65618a7

File tree

15 files changed

+178
-65
lines changed

15 files changed

+178
-65
lines changed

Cargo.toml

-5
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,3 @@ members = ["soft-skia", "soft-skia-wasm"]
1414
[dependencies]
1515
png = "0.17.5"
1616
colorsys = "0.6.5"
17-
18-
[dependencies.neon]
19-
version = "0.10.1"
20-
default-features = false
21-
features = ["napi-6", "promise-api", "task-api"]

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "monorepo",
3-
"version": "0.1.0",
3+
"version": "0.1.1",
44
"private": "true",
55
"scripts": {},
66
"packageManager": "[email protected]"

soft-skia-wasm/Cargo.toml

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "soft-skia-wasm"
3-
version = "0.10.0"
3+
version = "0.11.0"
44
authors = ["meloalright <[email protected]>"]
55
edition = "2018"
66

@@ -15,7 +15,7 @@ serde = { version = "1.0", features = ["derive"] }
1515
serde-wasm-bindgen = "0.5.0"
1616
wasm-bindgen = "0.2.63"
1717
base64 = "0.21.0"
18-
cssparser = "0.29"
18+
csscolorparser = "0.7.0"
1919
soft_skia = { path = "../soft-skia" }
2020

2121
# The `console_error_panic_hook` crate provides better debugging of panics by

soft-skia-wasm/src/lib.rs

+4-11
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,7 @@ use soft_skia::shape::Rect;
1010
use soft_skia::shape::{Circle, Image, Line, PaintStyle, Points, RoundRect, Shapes, Text};
1111
use soft_skia::tree::Node;
1212
use wasm_bindgen::prelude::*;
13-
14-
use cssparser::{Color as CSSColor, Parser, ParserInput};
13+
use csscolorparser;
1514

1615
// When the `wee_alloc` feature is enabled, use `wee_alloc` as the global
1716
// allocator.
@@ -457,15 +456,9 @@ impl SoftSkiaWASM {
457456

458457
fn parse_color(color: Option<String>) -> Option<ColorU8> {
459458
if let Some(color_str) = color {
460-
let mut parser_input = ParserInput::new(&color_str);
461-
let mut parser = Parser::new(&mut parser_input);
462-
463-
if let Ok(css_color) = CSSColor::parse(&mut parser) {
464-
if let CSSColor::RGBA(rgba) = css_color {
465-
return Some(ColorU8::from_rgba(
466-
rgba.red, rgba.green, rgba.blue, rgba.alpha,
467-
));
468-
}
459+
if let Ok(css_color) = csscolorparser::parse(&color_str) {
460+
let css_rgba8 = css_color.to_rgba8();
461+
return Some(ColorU8::from_rgba(css_rgba8[0], css_rgba8[1], css_rgba8[2], css_rgba8[3]))
469462
}
470463
}
471464
None

soft-skia/Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "soft_skia"
3-
version = "0.10.0"
3+
version = "0.11.0"
44
edition = "2021"
55
description="software rasterization skia binding"
66
license = "MIT"

vue-playground/package-ci.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "vue-playground",
3-
"version": "0.10.0",
3+
"version": "0.11.0",
44
"private": true,
55
"scripts": {
66
"serve": "vue-cli-service serve",
@@ -14,7 +14,7 @@
1414
"prismjs": "^1.29.0",
1515
"vue": "^3.2.13",
1616
"vue-live": "^2.5.4",
17-
"vue-skia": "0.1.0"
17+
"vue-skia": "0.1.1"
1818
},
1919
"devDependencies": {
2020
"@types/node": "^20.5.0",

vue-playground/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "vue-playground",
3-
"version": "0.1.0",
3+
"version": "0.1.1",
44
"private": true,
55
"scripts": {
66
"serve": "vue-cli-service serve",
3.21 MB
Binary file not shown.

vue-playground/public/OFL.txt

+97
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
Copyright (c) 2010, NHN Corporation (http://www.nhncorp.com),
2+
with Reserved Font Name Nanum, Naver Nanum, NanumGothic, Naver
3+
NanumGothic, NanumMyeongjo, Naver NanumMyeongjo, NanumBrush, Naver
4+
NanumBrush, NanumPen, Naver NanumPen.
5+
6+
7+
This Font Software is licensed under the SIL Open Font License, Version 1.1.
8+
This license is copied below, and is also available with a FAQ at:
9+
https://openfontlicense.org
10+
11+
12+
-----------------------------------------------------------
13+
SIL OPEN FONT LICENSE Version 1.1 - 26 February 2007
14+
-----------------------------------------------------------
15+
16+
PREAMBLE
17+
The goals of the Open Font License (OFL) are to stimulate worldwide
18+
development of collaborative font projects, to support the font creation
19+
efforts of academic and linguistic communities, and to provide a free and
20+
open framework in which fonts may be shared and improved in partnership
21+
with others.
22+
23+
The OFL allows the licensed fonts to be used, studied, modified and
24+
redistributed freely as long as they are not sold by themselves. The
25+
fonts, including any derivative works, can be bundled, embedded,
26+
redistributed and/or sold with any software provided that any reserved
27+
names are not used by derivative works. The fonts and derivatives,
28+
however, cannot be released under any other type of license. The
29+
requirement for fonts to remain under this license does not apply
30+
to any document created using the fonts or their derivatives.
31+
32+
DEFINITIONS
33+
"Font Software" refers to the set of files released by the Copyright
34+
Holder(s) under this license and clearly marked as such. This may
35+
include source files, build scripts and documentation.
36+
37+
"Reserved Font Name" refers to any names specified as such after the
38+
copyright statement(s).
39+
40+
"Original Version" refers to the collection of Font Software components as
41+
distributed by the Copyright Holder(s).
42+
43+
"Modified Version" refers to any derivative made by adding to, deleting,
44+
or substituting -- in part or in whole -- any of the components of the
45+
Original Version, by changing formats or by porting the Font Software to a
46+
new environment.
47+
48+
"Author" refers to any designer, engineer, programmer, technical
49+
writer or other person who contributed to the Font Software.
50+
51+
PERMISSION & CONDITIONS
52+
Permission is hereby granted, free of charge, to any person obtaining
53+
a copy of the Font Software, to use, study, copy, merge, embed, modify,
54+
redistribute, and sell modified and unmodified copies of the Font
55+
Software, subject to the following conditions:
56+
57+
1) Neither the Font Software nor any of its individual components,
58+
in Original or Modified Versions, may be sold by itself.
59+
60+
2) Original or Modified Versions of the Font Software may be bundled,
61+
redistributed and/or sold with any software, provided that each copy
62+
contains the above copyright notice and this license. These can be
63+
included either as stand-alone text files, human-readable headers or
64+
in the appropriate machine-readable metadata fields within text or
65+
binary files as long as those fields can be easily viewed by the user.
66+
67+
3) No Modified Version of the Font Software may use the Reserved Font
68+
Name(s) unless explicit written permission is granted by the corresponding
69+
Copyright Holder. This restriction only applies to the primary font name as
70+
presented to the users.
71+
72+
4) The name(s) of the Copyright Holder(s) or the Author(s) of the Font
73+
Software shall not be used to promote, endorse or advertise any
74+
Modified Version, except to acknowledge the contribution(s) of the
75+
Copyright Holder(s) and the Author(s) or with their explicit written
76+
permission.
77+
78+
5) The Font Software, modified or unmodified, in part or in whole,
79+
must be distributed entirely under this license, and must not be
80+
distributed under any other license. The requirement for fonts to
81+
remain under this license does not apply to any document created
82+
using the Font Software.
83+
84+
TERMINATION
85+
This license becomes null and void if any of the above conditions are
86+
not met.
87+
88+
DISCLAIMER
89+
THE FONT SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
90+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO ANY WARRANTIES OF
91+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT
92+
OF COPYRIGHT, PATENT, TRADEMARK, OR OTHER RIGHT. IN NO EVENT SHALL THE
93+
COPYRIGHT HOLDER BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
94+
INCLUDING ANY GENERAL, SPECIAL, INDIRECT, INCIDENTAL, OR CONSEQUENTIAL
95+
DAMAGES, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
96+
FROM, OUT OF THE USE OR INABILITY TO USE THE FONT SOFTWARE OR FROM
97+
OTHER DEALINGS IN THE FONT SOFTWARE.

vue-playground/public/index.html

+6
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,12 @@
66
<meta name="viewport" content="width=device-width,initial-scale=1.0">
77
<link rel="icon" href="<%= BASE_URL %>favicon.ico">
88
<title><%= htmlWebpackPlugin.options.title %></title>
9+
<style type="text/css">
10+
@font-face {
11+
font-family: 'Nanum Pen Script';
12+
src: url('<%= BASE_URL %>NanumPenScript-Regular.ttf') format("truetype");
13+
}
14+
</style>
915
</head>
1016
<body>
1117
<noscript>

vue-playground/src/App.vue

+5-14
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,10 @@
1111
<p class="description">
1212
This super cool editor is based on <em>vue-live</em> !
1313
</p>
14-
<div class="livebox" v-if="!debug">
14+
<div class="livebox" v-if="!loading && !debug">
1515
<div class="hint">
16-
You can edit <a title="copy code to clipboard" @click="copy">this</a>
16+
You can edit
17+
<span title="copy code to clipboard" @click="copy">this</span>
1718
<span>-></span>
1819
</div>
1920
<VueLive
@@ -81,16 +82,9 @@
8182
:height="70"
8283
v-bind:blur="10"
8384
:grayscale="false"
84-
:brighten="40"
85+
:brighten="80"
8586
:invert="false"
8687
></v-image>
87-
<v-image
88-
:x="0"
89-
:y="0"
90-
:image="'https://raw.githubusercontent.com/rustq/vue-skia/main/vue-playground/src/assets/logo.png'"
91-
:width="70"
92-
:height="70"
93-
></v-image>
9488
</v-surface>
9589
</template>
9690
<github-corners
@@ -125,14 +119,10 @@ export default defineComponent({
125119
VueLive,
126120
GithubCorners,
127121
VSurface,
128-
VGroup,
129122
VRect,
130123
VCircle,
131-
VRoundRect,
132-
VLine,
133124
VPoints,
134125
VImage,
135-
VText
136126
},
137127
data() {
138128
return {
@@ -246,6 +236,7 @@ body {
246236
color: rgb(0, 161, 132);
247237
transform: rotate(-30deg);
248238
transition: transform 0.2s;
239+
user-select: none;
249240
}
250241
251242
@media (max-width: 1600px) {

vue-playground/src/code.ts

+1-8
Original file line numberDiff line numberDiff line change
@@ -23,16 +23,9 @@ export default `<v-surface :width="360" :height="360">
2323
:height="70"
2424
v-bind:blur="10"
2525
:grayscale="false"
26-
:brighten="40"
26+
:brighten="80"
2727
:invert="false"
2828
></v-image>
29-
<v-image
30-
:x="0"
31-
:y="0"
32-
:image="'https://raw.githubusercontent.com/rustq/vue-skia/main/vue-playground/src/assets/logo.png'"
33-
:width="70"
34-
:height="70"
35-
></v-image>
3629
<v-group :x="200" :y="160" color="violet" :style="'stroke'" :invertClip="true">
3730
<template #clip>
3831
<v-circle :cx="8" :cy="68" :r="40" />

vue-playground/src/loading-code.ts

+19-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
export default `<!--<template>loading</template>-->
1+
export default `<!-- The vue-skia is a skia-based 2d graphics vue rendering library. It is based on Rust to implement software rasterization to perform rendering. It takes up less memory than the native canvas, however it is still a experiment project. And it's based entirely on vue syntax. -->
22
33
44
@@ -18,4 +18,21 @@ export default `<!--<template>loading</template>-->
1818
1919
2020
21-
`
21+
22+
23+
24+
25+
26+
27+
28+
29+
30+
31+
32+
33+
34+
35+
36+
37+
38+
`;

vue-skia-framework/components/VImage.vue

+37-16
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,41 @@
66
import { defineComponent, getCurrentInstance, PropType } from "vue";
77
import { ComponentInternalInstanceWithSoftSkiaWASM } from "../type";
88
9+
class ImageLoader {
10+
static caches: { [url: string]: string } = {};
11+
12+
public static load(url: string): Promise<string> {
13+
return new Promise((resolve, reject) => {
14+
if (this.caches[url]) {
15+
return resolve(this.caches[url]);
16+
}
17+
if (url.startsWith("data:image/png;base64")) {
18+
const base64String = url.replace("data:image/png;base64,", "");
19+
this.caches[url] = base64String;
20+
return resolve(base64String);
21+
} else {
22+
fetch(url)
23+
.then((res) => res.blob())
24+
.then((blob) => {
25+
const reader = new FileReader();
26+
reader.onloadend = () => {
27+
const base64String = (reader.result as string).replace(
28+
"data:image/png;base64,",
29+
""
30+
);
31+
this.caches[url] = base64String;
32+
return resolve(base64String);
33+
};
34+
reader.readAsDataURL(blob);
35+
})
36+
.catch(e => {
37+
reject(e)
38+
});
39+
}
40+
});
41+
}
42+
}
43+
944
export default defineComponent({
1045
name: "VImage",
1146
data() {
@@ -64,25 +99,11 @@ export default defineComponent({
6499
},
65100
mounted() {
66101
const vm = getCurrentInstance() as ComponentInternalInstanceWithSoftSkiaWASM;
67-
if (this.image?.startsWith("data:image/png;base64")) {
68-
const base64String = this.image.replace("data:image/png;base64,", "")
102+
ImageLoader.load(this.image).then(base64String => {
69103
this.base64String = base64String;
70104
this.loaded = true;
71105
this.reUpdateRoot(vm);
72-
} else {
73-
fetch(this.image)
74-
.then((res) => res.blob())
75-
.then((blob) => {
76-
const reader = new FileReader();
77-
reader.onloadend = () => {
78-
const base64String = (reader.result as string).replace("data:image/png;base64,", "");
79-
this.base64String = base64String;
80-
this.loaded = true;
81-
this.reUpdateRoot(vm);
82-
};
83-
reader.readAsDataURL(blob);
84-
});
85-
}
106+
})
86107
}
87108
});
88109
</script>

vue-skia-framework/package-publish.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "vue-skia",
3-
"version": "0.1.0",
3+
"version": "0.1.1",
44
"files": [
55
"lib",
66
"type.d.ts",
@@ -13,6 +13,6 @@
1313
"main": "./main.js",
1414
"module": "./main.js",
1515
"dependencies": {
16-
"soft-skia-wasm": "0.10.0"
16+
"soft-skia-wasm": "0.11.0"
1717
}
1818
}

0 commit comments

Comments
 (0)