Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion .changeset/config.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
"@lynx-js/web-mainthread-apis",
"@lynx-js/web-worker-rpc",
"@lynx-js/web-worker-runtime",
"@lynx-js/web-style-transformer",
"@lynx-js/web-rsbuild-server-middleware"
],
[
Expand Down
7 changes: 7 additions & 0 deletions .changeset/long-baths-prove.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
"@lynx-js/web-core-server": patch
---

chore: minor bundle output change

the timing of loading wasm chunk has been changed
7 changes: 1 addition & 6 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 1 addition & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,7 @@ members = [
"packages/react/transform/crates/*",
"packages/react/transform/swc-plugin-reactlynx",
"packages/react/transform/swc-plugin-reactlynx-compat",
"packages/web-platform/inline-style-parser",
"packages/web-platform/web-style-transformer",
"packages/web-platform/web-mainthread-apis",
]

[workspace.dependencies]
Expand Down
4 changes: 0 additions & 4 deletions packages/web-platform/inline-style-parser/Cargo.toml

This file was deleted.

3 changes: 3 additions & 0 deletions packages/web-platform/web-core-server/rslib.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,9 @@ const config: RslibConfig = defineConfig({
output: {
wasmLoading: 'async-node',
},
experiments: {
futureDefaults: true,
},
},
},
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import {
type MainThreadGlobalThis,
} from '@lynx-js/web-constants';
import { Rpc } from '@lynx-js/web-worker-rpc';
import { prepareMainThreadAPIs } from '@lynx-js/web-mainthread-apis';
import { loadTemplate } from './utils/loadTemplate.js';
import {
_attributes,
Expand Down Expand Up @@ -164,6 +163,9 @@ export async function createLynxView(
});
});
};
const { prepareMainThreadAPIs } = await import(
'@lynx-js/web-mainthread-apis'
);
const { startMainThread } = prepareMainThreadAPIs(
backgroundThreadRpc,
offscreenDocument,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
[package]
name = "web-style-transformer"
name = "web-mainthread-apis"
version = "0.0.0"
edition = "2021"

[lib]
crate-type = ["cdylib"]

[dependencies]
inline-style-parser = { path = "../inline-style-parser" }
js-sys = { workspace = true }
lazy_static = { workspace = true }
wasm-bindgen = { workspace = true }
13 changes: 11 additions & 2 deletions packages/web-platform/web-mainthread-apis/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,25 @@
"files": [
"dist",
"binary",
"wasm",
"!dist/**/*.js.map",
"!binary/**/*.js.map",
"LICENSE.txt",
"Notice.txt",
"CHANGELOG.md",
"README.md",
"**/*.css"
],
"scripts": {
"build": "node scripts/build.js"
},
Comment thread
PupilTong marked this conversation as resolved.
"dependencies": {
"@lynx-js/web-constants": "workspace:*",
"@lynx-js/web-style-transformer": "workspace:*",
"hyphenate-style-name": "^1.1.0"
"hyphenate-style-name": "^1.1.0",
"wasm-feature-detect": "^1.8.0"
},
"devDependencies": {
"binaryen": "^125.0.0",
"fb-dotslash": "^0.5.8"
}
}
86 changes: 86 additions & 0 deletions packages/web-platform/web-mainthread-apis/scripts/build.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
// run command and dump output
import { execSync } from 'child_process';
import path from 'path';
import { fileURLToPath } from 'url';

const __dirname = path.dirname(fileURLToPath(import.meta.url));
const packageRoot = path.join(__dirname, '..');
const cargoOutput = path.join(
'..',
'..',
'..',
'target',
'wasm32-unknown-unknown',
'release',
'web_mainthread_apis.wasm',
);
const cargoOutputDebug = path.join(
'..',
'..',
'..',
'target',
'wasm32-unknown-unknown',
'debug',
'web_mainthread_apis.wasm',
);
// build the standard wasm package

function build(release, rustFlags, outName, optimizeArgs, rust_features) {
execSync(
`cargo build ${
release ? '--release' : ''
} --target wasm32-unknown-unknown ${
rust_features ? `--features ${rust_features}` : ''
}`,
{
cwd: packageRoot,
stdio: 'inherit',
env: { ...process.env, RUSTFLAGS: rustFlags },
shell: true,
},
);
execSync(
`pnpm exec dotslash ./scripts/wasm-bindgen ${
release ? '' : '--keep-debug'
} --out-dir binary --target bundler --out-name ${outName} ${
release ? cargoOutput : cargoOutputDebug
}`,
{ cwd: packageRoot, stdio: 'inherit' },
);
if (release) {
execSync(
`pnpm wasm-opt --enable-bulk-memory ${optimizeArgs} ./binary/${outName}_bg.wasm -o ./binary/${outName}_bg.wasm`,
{ cwd: packageRoot, stdio: 'inherit' },
);
}
}
/**
* https://webassembly.org/features/
* https://doc.rust-lang.org/reference/attributes/codegen.html#wasm32-or-wasm64
* https://doc.rust-lang.org/rustc/platform-support/wasm32-unknown-unknown.html
* feature | chrome | firefox | safari
* bulk-memory| 75 | 79 | 15
* sign-ext | 74 | 62 | 14.1
* simd | 91 | 89 | 16.4
* ref-types | 96 | 79 | 15
* multivalue | 85 | 78 | 13.1
* nontrapping
* float-
* to-int | 75 | 64 | 15
* mutable-
* globals | 74 | 61 | 13.1
*/

build(
true,
'-C target_feature=+bulk-memory,+sign-ext,+simd128,+reference-types,+nontrapping-fptoint,+mutable-globals',
'standard',
'--enable-bulk-memory-opt --enable-sign-ext --enable-simd --enable-reference-types --enable-nontrapping-float-to-int --enable-mutable-globals',
);
build(
true,
'-C target_feature=+bulk-memory -C strip=symbols',
'legacy',
'',
Comment thread
PupilTong marked this conversation as resolved.
);
build(false, '', 'debug', '');
1 change: 1 addition & 0 deletions packages/web-platform/web-mainthread-apis/src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
mod style;
Comment thread
PupilTong marked this conversation as resolved.
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ mod tests {
use super::*;
use parse_inline_style::{parse_inline_style, Transformer};

#[derive(Debug, PartialEq)]
#[derive(PartialEq)]
struct Declaration {
name_start: usize,
name_end: usize,
Expand Down Expand Up @@ -502,7 +502,7 @@ mod tests {

#[test]
fn test_character_classification_macros() {
use crate::char_code_definitions::*;
use super::char_code_definitions::*;

// Test digit classification
assert!(is_digit(b'0'));
Expand Down Expand Up @@ -585,7 +585,7 @@ mod tests {

#[test]
fn test_char_code_category() {
use crate::char_code_definitions::*;
use super::char_code_definitions::*;

// Test basic categories
assert_eq!(char_code_category(0x0020), WHITE_SPACE_CATEGORY); // SPACE
Expand All @@ -602,7 +602,7 @@ mod tests {

#[test]
fn test_utility_functions() {
use crate::utils::*;
use super::utils::*;

// Test cmp_str function
let test_str: &[u8] = b"hello";
Expand Down Expand Up @@ -707,7 +707,7 @@ mod tests {

#[test]
fn test_tokenizer_specific_cases() {
use crate::tokenize::{self, Parser};
use super::tokenize::{self, Parser};

struct TokenCollector {
tokens: Vec<(u8, usize, usize)>,
Expand Down Expand Up @@ -800,8 +800,8 @@ mod tests {

#[test]
fn test_string_tokenizer_edge_cases() {
use crate::tokenize::{tokenize, Parser};
use crate::types::*;
use super::tokenize::{tokenize, Parser};
use super::types::*;

struct TokenCollector {
tokens: Vec<(u8, usize, usize)>,
Expand Down Expand Up @@ -856,8 +856,8 @@ mod tests {

#[test]
fn test_url_tokenizer_edge_cases() {
use crate::tokenize::{tokenize, Parser};
use crate::types::*;
use super::tokenize::{tokenize, Parser};
use super::types::*;

struct TokenCollector {
tokens: Vec<(u8, usize, usize)>,
Expand Down Expand Up @@ -936,8 +936,8 @@ mod tests {

#[test]
fn test_numeric_tokenizer_edge_cases() {
use crate::tokenize::{tokenize, Parser};
use crate::types::*;
use super::tokenize::{tokenize, Parser};
use super::types::*;

struct TokenCollector {
tokens: Vec<(u8, usize, usize)>,
Expand Down Expand Up @@ -1048,8 +1048,8 @@ mod tests {

#[test]
fn test_comment_tokenizer() {
use crate::tokenize::{tokenize, Parser};
use crate::types::*;
use super::tokenize::{tokenize, Parser};
use super::types::*;

struct TokenCollector {
tokens: Vec<(u8, usize, usize)>,
Expand Down Expand Up @@ -1097,8 +1097,8 @@ mod tests {

#[test]
fn test_additional_edge_cases() {
use crate::char_code_definitions::*;
use crate::utils::*;
use super::char_code_definitions::*;
use super::utils::*;

// Test cmp_char macro
let source: &[u8] = "Hello".as_bytes();
Expand Down Expand Up @@ -1146,9 +1146,9 @@ mod tests {

#[test]
fn test_remaining_coverage_gaps() {
use crate::char_code_definitions::*;
use crate::tokenize::{tokenize, Parser};
use crate::utils::*;
use super::char_code_definitions::*;
use super::tokenize::{tokenize, Parser};
use super::utils::*;

struct TokenCollector {
tokens: Vec<(u8, usize, usize)>,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use crate::{
use super::{
char_code_definitions::{get_char_code, is_white_space},
tokenize::{self, Parser},
types::*,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
use crate::*;
use crate::{char_code_definitions::*, types::*, utils::*};
use super::{
char_code_definitions::{self, *},
types::*,
utils::*,
};

/*
* this code forked from css-tree
Expand Down Expand Up @@ -536,7 +539,7 @@ pub fn tokenize<T: Parser>(source: &[u8], parser: &mut T) {

#[cfg(test)]
mod test {
use crate::tokenize::*;
use super::*;

struct TokenStreamRecorder {
tokens: Vec<(u8, usize, usize)>,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use crate::char_code_definitions::*;
use super::char_code_definitions::*;

pub fn cmp_str(test_str: &[u8], start: usize, end: usize, reference_str: &[u8]) -> bool {
if (end - start) != reference_str.len() {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use wasm_bindgen::prelude::*;

pub mod transformer;
mod inline_style_parser;
mod transformer;

#[wasm_bindgen]
pub fn transform_raw_u16_inline_style_ptr(str: &str) -> Option<String> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,7 @@ pub fn get_replace_rule_value(

#[cfg(test)]
mod tests {
use crate::transformer::rules::{get_rename_rule_value, get_replace_rule_value};
use super::{get_rename_rule_value, get_replace_rule_value};

#[test]
fn test_rename_rule_flex_direction() {
Expand Down
Loading
Loading