Skip to content

Commit

Permalink
0.1.1 (#38)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
meloalright authored Aug 14, 2024
1 parent e793a4d commit 65618a7
Show file tree
Hide file tree
Showing 15 changed files with 178 additions and 65 deletions.
5 changes: 0 additions & 5 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,3 @@ members = ["soft-skia", "soft-skia-wasm"]
[dependencies]
png = "0.17.5"
colorsys = "0.6.5"

[dependencies.neon]
version = "0.10.1"
default-features = false
features = ["napi-6", "promise-api", "task-api"]
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "monorepo",
"version": "0.1.0",
"version": "0.1.1",
"private": "true",
"scripts": {},
"packageManager": "[email protected]"
Expand Down
4 changes: 2 additions & 2 deletions soft-skia-wasm/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "soft-skia-wasm"
version = "0.10.0"
version = "0.11.0"
authors = ["meloalright <[email protected]>"]
edition = "2018"

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

# The `console_error_panic_hook` crate provides better debugging of panics by
Expand Down
15 changes: 4 additions & 11 deletions soft-skia-wasm/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,7 @@ use soft_skia::shape::Rect;
use soft_skia::shape::{Circle, Image, Line, PaintStyle, Points, RoundRect, Shapes, Text};
use soft_skia::tree::Node;
use wasm_bindgen::prelude::*;

use cssparser::{Color as CSSColor, Parser, ParserInput};
use csscolorparser;

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

fn parse_color(color: Option<String>) -> Option<ColorU8> {
if let Some(color_str) = color {
let mut parser_input = ParserInput::new(&color_str);
let mut parser = Parser::new(&mut parser_input);

if let Ok(css_color) = CSSColor::parse(&mut parser) {
if let CSSColor::RGBA(rgba) = css_color {
return Some(ColorU8::from_rgba(
rgba.red, rgba.green, rgba.blue, rgba.alpha,
));
}
if let Ok(css_color) = csscolorparser::parse(&color_str) {
let css_rgba8 = css_color.to_rgba8();
return Some(ColorU8::from_rgba(css_rgba8[0], css_rgba8[1], css_rgba8[2], css_rgba8[3]))
}
}
None
Expand Down
2 changes: 1 addition & 1 deletion soft-skia/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "soft_skia"
version = "0.10.0"
version = "0.11.0"
edition = "2021"
description="software rasterization skia binding"
license = "MIT"
Expand Down
4 changes: 2 additions & 2 deletions vue-playground/package-ci.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "vue-playground",
"version": "0.10.0",
"version": "0.11.0",
"private": true,
"scripts": {
"serve": "vue-cli-service serve",
Expand All @@ -14,7 +14,7 @@
"prismjs": "^1.29.0",
"vue": "^3.2.13",
"vue-live": "^2.5.4",
"vue-skia": "0.1.0"
"vue-skia": "0.1.1"
},
"devDependencies": {
"@types/node": "^20.5.0",
Expand Down
2 changes: 1 addition & 1 deletion vue-playground/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "vue-playground",
"version": "0.1.0",
"version": "0.1.1",
"private": true,
"scripts": {
"serve": "vue-cli-service serve",
Expand Down
Binary file added vue-playground/public/NanumPenScript-Regular.ttf
Binary file not shown.
97 changes: 97 additions & 0 deletions vue-playground/public/OFL.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
Copyright (c) 2010, NHN Corporation (http://www.nhncorp.com),
with Reserved Font Name Nanum, Naver Nanum, NanumGothic, Naver
NanumGothic, NanumMyeongjo, Naver NanumMyeongjo, NanumBrush, Naver
NanumBrush, NanumPen, Naver NanumPen.


This Font Software is licensed under the SIL Open Font License, Version 1.1.
This license is copied below, and is also available with a FAQ at:
https://openfontlicense.org


-----------------------------------------------------------
SIL OPEN FONT LICENSE Version 1.1 - 26 February 2007
-----------------------------------------------------------

PREAMBLE
The goals of the Open Font License (OFL) are to stimulate worldwide
development of collaborative font projects, to support the font creation
efforts of academic and linguistic communities, and to provide a free and
open framework in which fonts may be shared and improved in partnership
with others.

The OFL allows the licensed fonts to be used, studied, modified and
redistributed freely as long as they are not sold by themselves. The
fonts, including any derivative works, can be bundled, embedded,
redistributed and/or sold with any software provided that any reserved
names are not used by derivative works. The fonts and derivatives,
however, cannot be released under any other type of license. The
requirement for fonts to remain under this license does not apply
to any document created using the fonts or their derivatives.

DEFINITIONS
"Font Software" refers to the set of files released by the Copyright
Holder(s) under this license and clearly marked as such. This may
include source files, build scripts and documentation.

"Reserved Font Name" refers to any names specified as such after the
copyright statement(s).

"Original Version" refers to the collection of Font Software components as
distributed by the Copyright Holder(s).

"Modified Version" refers to any derivative made by adding to, deleting,
or substituting -- in part or in whole -- any of the components of the
Original Version, by changing formats or by porting the Font Software to a
new environment.

"Author" refers to any designer, engineer, programmer, technical
writer or other person who contributed to the Font Software.

PERMISSION & CONDITIONS
Permission is hereby granted, free of charge, to any person obtaining
a copy of the Font Software, to use, study, copy, merge, embed, modify,
redistribute, and sell modified and unmodified copies of the Font
Software, subject to the following conditions:

1) Neither the Font Software nor any of its individual components,
in Original or Modified Versions, may be sold by itself.

2) Original or Modified Versions of the Font Software may be bundled,
redistributed and/or sold with any software, provided that each copy
contains the above copyright notice and this license. These can be
included either as stand-alone text files, human-readable headers or
in the appropriate machine-readable metadata fields within text or
binary files as long as those fields can be easily viewed by the user.

3) No Modified Version of the Font Software may use the Reserved Font
Name(s) unless explicit written permission is granted by the corresponding
Copyright Holder. This restriction only applies to the primary font name as
presented to the users.

4) The name(s) of the Copyright Holder(s) or the Author(s) of the Font
Software shall not be used to promote, endorse or advertise any
Modified Version, except to acknowledge the contribution(s) of the
Copyright Holder(s) and the Author(s) or with their explicit written
permission.

5) The Font Software, modified or unmodified, in part or in whole,
must be distributed entirely under this license, and must not be
distributed under any other license. The requirement for fonts to
remain under this license does not apply to any document created
using the Font Software.

TERMINATION
This license becomes null and void if any of the above conditions are
not met.

DISCLAIMER
THE FONT SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO ANY WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT
OF COPYRIGHT, PATENT, TRADEMARK, OR OTHER RIGHT. IN NO EVENT SHALL THE
COPYRIGHT HOLDER BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
INCLUDING ANY GENERAL, SPECIAL, INDIRECT, INCIDENTAL, OR CONSEQUENTIAL
DAMAGES, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
FROM, OUT OF THE USE OR INABILITY TO USE THE FONT SOFTWARE OR FROM
OTHER DEALINGS IN THE FONT SOFTWARE.
6 changes: 6 additions & 0 deletions vue-playground/public/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,12 @@
<meta name="viewport" content="width=device-width,initial-scale=1.0">
<link rel="icon" href="<%= BASE_URL %>favicon.ico">
<title><%= htmlWebpackPlugin.options.title %></title>
<style type="text/css">
@font-face {
font-family: 'Nanum Pen Script';
src: url('<%= BASE_URL %>NanumPenScript-Regular.ttf') format("truetype");
}
</style>
</head>
<body>
<noscript>
Expand Down
19 changes: 5 additions & 14 deletions vue-playground/src/App.vue
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,10 @@
<p class="description">
This super cool editor is based on <em>vue-live</em> !
</p>
<div class="livebox" v-if="!debug">
<div class="livebox" v-if="!loading && !debug">
<div class="hint">
You can edit <a title="copy code to clipboard" @click="copy">this</a>
You can edit
<span title="copy code to clipboard" @click="copy">this</span>
<span>-></span>
</div>
<VueLive
Expand Down Expand Up @@ -81,16 +82,9 @@
:height="70"
v-bind:blur="10"
:grayscale="false"
:brighten="40"
:brighten="80"
:invert="false"
></v-image>
<v-image
:x="0"
:y="0"
:image="'https://raw.githubusercontent.com/rustq/vue-skia/main/vue-playground/src/assets/logo.png'"
:width="70"
:height="70"
></v-image>
</v-surface>
</template>
<github-corners
Expand Down Expand Up @@ -125,14 +119,10 @@ export default defineComponent({
VueLive,
GithubCorners,
VSurface,
VGroup,
VRect,
VCircle,
VRoundRect,
VLine,
VPoints,
VImage,
VText
},
data() {
return {
Expand Down Expand Up @@ -246,6 +236,7 @@ body {
color: rgb(0, 161, 132);
transform: rotate(-30deg);
transition: transform 0.2s;
user-select: none;
}
@media (max-width: 1600px) {
Expand Down
9 changes: 1 addition & 8 deletions vue-playground/src/code.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,16 +23,9 @@ export default `<v-surface :width="360" :height="360">
:height="70"
v-bind:blur="10"
:grayscale="false"
:brighten="40"
:brighten="80"
:invert="false"
></v-image>
<v-image
:x="0"
:y="0"
:image="'https://raw.githubusercontent.com/rustq/vue-skia/main/vue-playground/src/assets/logo.png'"
:width="70"
:height="70"
></v-image>
<v-group :x="200" :y="160" color="violet" :style="'stroke'" :invertClip="true">
<template #clip>
<v-circle :cx="8" :cy="68" :r="40" />
Expand Down
21 changes: 19 additions & 2 deletions vue-playground/src/loading-code.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
export default `<!--<template>loading</template>-->
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. -->
Expand All @@ -18,4 +18,21 @@ export default `<!--<template>loading</template>-->
`
`;
53 changes: 37 additions & 16 deletions vue-skia-framework/components/VImage.vue
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,41 @@
import { defineComponent, getCurrentInstance, PropType } from "vue";
import { ComponentInternalInstanceWithSoftSkiaWASM } from "../type";
class ImageLoader {
static caches: { [url: string]: string } = {};
public static load(url: string): Promise<string> {
return new Promise((resolve, reject) => {
if (this.caches[url]) {
return resolve(this.caches[url]);
}
if (url.startsWith("data:image/png;base64")) {
const base64String = url.replace("data:image/png;base64,", "");
this.caches[url] = base64String;
return resolve(base64String);
} else {
fetch(url)
.then((res) => res.blob())
.then((blob) => {
const reader = new FileReader();
reader.onloadend = () => {
const base64String = (reader.result as string).replace(
"data:image/png;base64,",
""
);
this.caches[url] = base64String;
return resolve(base64String);
};
reader.readAsDataURL(blob);
})
.catch(e => {
reject(e)
});
}
});
}
}
export default defineComponent({
name: "VImage",
data() {
Expand Down Expand Up @@ -64,25 +99,11 @@ export default defineComponent({
},
mounted() {
const vm = getCurrentInstance() as ComponentInternalInstanceWithSoftSkiaWASM;
if (this.image?.startsWith("data:image/png;base64")) {
const base64String = this.image.replace("data:image/png;base64,", "")
ImageLoader.load(this.image).then(base64String => {
this.base64String = base64String;
this.loaded = true;
this.reUpdateRoot(vm);
} else {
fetch(this.image)
.then((res) => res.blob())
.then((blob) => {
const reader = new FileReader();
reader.onloadend = () => {
const base64String = (reader.result as string).replace("data:image/png;base64,", "");
this.base64String = base64String;
this.loaded = true;
this.reUpdateRoot(vm);
};
reader.readAsDataURL(blob);
});
}
})
}
});
</script>
4 changes: 2 additions & 2 deletions vue-skia-framework/package-publish.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "vue-skia",
"version": "0.1.0",
"version": "0.1.1",
"files": [
"lib",
"type.d.ts",
Expand All @@ -13,6 +13,6 @@
"main": "./main.js",
"module": "./main.js",
"dependencies": {
"soft-skia-wasm": "0.10.0"
"soft-skia-wasm": "0.11.0"
}
}

0 comments on commit 65618a7

Please sign in to comment.