diff --git a/.changeset/bitter-emus-camp.md b/.changeset/bitter-emus-camp.md new file mode 100644 index 0000000000..7245ea9823 --- /dev/null +++ b/.changeset/bitter-emus-camp.md @@ -0,0 +1,64 @@ +--- +"@lynx-js/web-core": minor +--- + +**This is a breaking change** + +## Architectural Upgrade: `web-core-wasm` replaces `web-core` + +This release marks a major architectural upgrade for the web platform. The experimental, WASM-powered engine formerly known as `web-core-wasm` has been fully stabilized and merged into the main branch, completely replacing the previous pure JS/TS based `web-core` implementation. This consolidation massively improves execution performance and aligns the API boundaries of the Web platform directly with other native Lynx implementations. + +### 🎉 Added Features + +- **Core API Enhancements**: Successfully exposed and supported `__QuerySelector` and `__InvokeUIMethod` methods. +- **Security & CSP Compliance**: Added a `nonce` attribute to the iframe's `srcdoc` script execution, strengthening Content Security Policy (CSP) compliance. +- **`` Parameter Enhancements**: + - Added the `browser-config` attribute and property to ``. Development environments can now supply a `BrowserConfig` object (e.g., configuring `pixelRatio`, `pixelWidth`, `pixelHeight`) allowing the `systemInfo` payload to be dynamically configured at the instance level. + +### 🔄 Changed Features + +- **Legacy JSON Backwards Compatibility**: Delivered comprehensive fixes and optimizations to deeply support legacy JSON output templates: + - Added support for lazy loading execution mode (`lazy usage`). + - Implemented the correct decoding and handling of `@keyframe` animation rules. + - Rectified rule scoping matching including scoped CSS, root selectors, and type selectors. +- **Ecosystem Migration**: Updated testing and ecosystem applications (such as `web-explorer` and `shell-project`) to migrate away from obsolete fragmented dependencies. The new WASM architecture seamlessly integrates Element APIs and CSS directly inside the core client module, requiring a much simpler initialization footprint. + + **Before (Legacy `web-core` + `web-elements`):** + ```typescript + // Required multiple imports to assemble the environment + import '@lynx-js/web-core/client'; + import type { LynxViewElement as LynxView } from '@lynx-js/web-core'; + + // Had to manually import separate elements and their CSS + import '@lynx-js/web-elements/index.css'; + import '@lynx-js/web-elements/all'; + + const lynxView = document.createElement('lynx-view') as LynxView; + // ... + ``` + + **After (New `web-core` unified architecture):** + ```typescript + // The new engine natively registers Web Components and injects fundamental CSS + import '@lynx-js/web-core/client'; + import type { LynxViewElement as LynxView } from '@lynx-js/web-core/client'; + + const lynxView = document.createElement('lynx-view') as LynxView; + // ... + ``` + _(Applications can now drop `@lynx-js/web-elements` entirely from their `package.json` dependencies)._ +- **Dependency & Boot Sequence Improvements**: Re-architected module loading pathways. Promoted `wasm-feature-detect` directly to a core dependency, and hardened the web worker count initialization assertions. +- **Initialization Optimizations**: Converted `SERVER_IN_SHADOW_CSS` initialization bounds to use compilation-time constant expressions for better optimization. + +### 🗑️ Deleted Features & Structural Deprecations + +- **`` Parameter Removals**: + - Removed the `thread-strategy` property and attribute. Historically, this permitted consumers to toggle between `'multi-thread'` and `'all-on-ui'` modes depending on how they wanted the background logic to be executed. The WASM-driven architecture enforces a consolidated concurrency model, deprecating this `` attribute entirely. + - Removed the `overrideLynxTagToHTMLTagMap` property/attribute. HTML tag overriding mechanism has been deprecated in the new engine. + - Removed the `customTemplateLoader` property handler from ``. + - Removed the `inject-head-links` property and attribute (`injectHeadLinks`), which previously was used to automatically inject `` tags from the document head into the `lynx-view` shadow root. +- **Fragmented Packages Removal**: The new cohesive WASM architecture native to `@lynx-js/web-core` handles cross-thread communication, worker boundaries, and rendering loops uniformly. Consequently, multiple obsolete packages have been completely removed from the workspace: + - `@lynx-js/web-mainthread-apis` + - `@lynx-js/web-worker-runtime` + - `@lynx-js/web-core-server` + - `@lynx-js/web-core-wasm-e2e` (transitioned into standard test suites) diff --git a/.changeset/config.json b/.changeset/config.json index 5cc58f98a6..ccd0ea37ce 100644 --- a/.changeset/config.json +++ b/.changeset/config.json @@ -10,11 +10,7 @@ "fixed": [ [ "@lynx-js/web-core", - "@lynx-js/web-core-server", - "@lynx-js/web-constants", - "@lynx-js/web-mainthread-apis", "@lynx-js/web-worker-rpc", - "@lynx-js/web-worker-runtime", "@lynx-js/web-rsbuild-server-middleware" ], [ @@ -42,7 +38,7 @@ "ignore": [ "@lynx-js/web-tests", "@lynx-js/example-react", - "@lynx-js/web-core-wasm-e2e" + "@lynx-js/web-core-e2e" ], "changedFilePatterns": [ "src/**" diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 0751487014..b2014628fc 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -129,7 +129,7 @@ jobs: export PLAYWRIGHT_JUNIT_OUTPUT_NAME=test-report.junit.xml pnpm --filter @lynx-js/web-tests run test --reporter='github,dot,junit,html' --shard=${{ matrix.shard }}/3 pnpm --filter @lynx-js/web-tests run coverage:ci - web-core-wasm-e2e: + web-core-e2e: needs: build uses: ./.github/workflows/workflow-test.yml secrets: @@ -144,7 +144,7 @@ jobs: runs-on: lynx-custom-container is-web: true web-report-name: "playwright-${{ matrix.render }}-shard${{ matrix.shard }}" - web-report-path: "packages/web-platform/web-core-wasm-e2e/playwright-report" + web-report-path: "packages/web-platform/web-core-e2e/playwright-report" codecov-flags: "e2e" run: | if [ "${{ matrix.render }}" = "SSR" ]; then @@ -152,7 +152,7 @@ jobs: fi export NODE_OPTIONS="--max-old-space-size=32768" export PLAYWRIGHT_JUNIT_OUTPUT_NAME=test-report.junit.xml - pnpm --filter @lynx-js/web-core-wasm-e2e run test --reporter='github,dot,junit,html' --shard=${{ matrix.shard }}/2 + pnpm --filter @lynx-js/web-core-e2e run test --reporter='github,dot,junit,html' --shard=${{ matrix.shard }}/2 test-api: needs: build uses: ./.github/workflows/workflow-test.yml @@ -354,7 +354,7 @@ jobs: - test-type - test-typos - test-vitest - - web-core-wasm-e2e + - web-core-e2e - website if: always() runs-on: ubuntu-latest diff --git a/.typos.toml b/.typos.toml index dd9d79bff9..5db44d85e8 100644 --- a/.typos.toml +++ b/.typos.toml @@ -14,7 +14,6 @@ extend-exclude = [ "packages/web-platform/web-tests/tests/react.spec.ts-snapshots/*", "packages/web-platform/web-tests/tests/react.spec.ts", "packages/web-platform/web-tests/tests/react/basic-element-x-overlay-ng-playground-test/index.jsx", - "packages/web-platform/offscreen-document/src/webworker/OffscreenCSSStyleDeclaration.ts", ] [default] diff --git a/AGENTS.md b/AGENTS.md index b75e866a68..129019b425 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -145,8 +145,7 @@ export NODE_OPTIONS="--max-old-space-size=32768" - `packages/web-platform/` - **Lynx for Web**: Web platform implementation - `web-core/` - Core web runtime - `web-elements/` - DOM element implementations - - `web-worker-runtime/` - Web worker support - - `web-tests/` - E2E test suite (Playwright) + - `web-core-e2e` - e2e tests - `packages/testing-library/` - Testing infrastructure - `packages/tools/` - Build and development utilities @@ -245,7 +244,7 @@ These instructions were generated through comprehensive analysis and testing of - Includes E2E test suite requiring Playwright - Many packages have complex interdependencies - Contains performance-critical rendering code -- See `packages/web-platform/web-core-wasm/AGENTS.md` for specific instructions on `web-core-wasm`. +- See `packages/web-platform/web-core/AGENTS.md` for specific instructions on `web-core`. Remember: This is a complex, multi-language monorepo. Always allow extra time for builds and tests, and follow the exact command sequences provided. diff --git a/Cargo.lock b/Cargo.lock index 27cc54838c..b67c641c44 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -3915,7 +3915,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a8145dd1593bf0fb137dbfa85b8be79ec560a447298955877804640e40c2d6ea" [[package]] -name = "web-core-wasm" +name = "web-core" version = "0.0.0" dependencies = [ "fnv", @@ -3928,15 +3928,6 @@ dependencies = [ "web_elements", ] -[[package]] -name = "web-mainthread-apis" -version = "0.0.0" -dependencies = [ - "js-sys", - "lazy_static", - "wasm-bindgen", -] - [[package]] name = "web-sys" version = "0.3.85" diff --git a/Cargo.toml b/Cargo.toml index 7f220931de..fdfb747afd 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -6,9 +6,8 @@ members = [ "packages/react/transform/crates/*", "packages/react/transform/swc-plugin-reactlynx", "packages/react/transform/swc-plugin-reactlynx-compat", - "packages/web-platform/web-core-wasm", + "packages/web-platform/web-core", "packages/web-platform/web-elements", - "packages/web-platform/web-mainthread-apis", ] [workspace.dependencies] diff --git a/packages/repl/package.json b/packages/repl/package.json index b465ca3ffc..d7f9596da1 100644 --- a/packages/repl/package.json +++ b/packages/repl/package.json @@ -27,13 +27,8 @@ "@lynx-js/lynx-core": "0.1.3", "@lynx-js/type-element-api": "0.0.3", "@lynx-js/types": "3.7.0", - "@lynx-js/web-constants": "workspace:*", "@lynx-js/web-core": "workspace:*", - "@lynx-js/web-elements": "workspace:*", - "@lynx-js/web-mainthread-apis": "workspace:*", "@lynx-js/web-platform-rsbuild-plugin": "workspace:*", - "@lynx-js/web-worker-rpc": "workspace:*", - "@lynx-js/web-worker-runtime": "workspace:*", "@rsbuild/core": "catalog:rsbuild", "@rsbuild/plugin-react": "^1.4.5", "@tailwindcss/postcss": "^4.2.1", diff --git a/packages/repl/src/App.tsx b/packages/repl/src/App.tsx index ebba5717b3..7d5349c8c1 100644 --- a/packages/repl/src/App.tsx +++ b/packages/repl/src/App.tsx @@ -3,8 +3,6 @@ // LICENSE file in the root directory of this source tree. import { useCallback, useEffect, useRef, useState } from 'react'; -import type { LynxTemplate } from '@lynx-js/web-constants'; - import { buildLynxTemplate } from './bundler/template-builder.js'; import { EditorPane } from './components/EditorPane.js'; import type { EditorPaneHandle } from './components/EditorPane.js'; @@ -89,7 +87,9 @@ export function App() { initial.sampleIndex, ); const [timingText, setTimingText] = useState(''); - const [template, setTemplate] = useState(null); + const [template, setTemplate] = useState | null>( + null, + ); const pendingTimingRef = useRef< | { css: number | null; assemble: number; t0: number; buildEnd: number } | null diff --git a/packages/repl/src/bundler/css-processor.ts b/packages/repl/src/bundler/css-processor.ts index 42f27bc96e..e1c44b908e 100644 --- a/packages/repl/src/bundler/css-processor.ts +++ b/packages/repl/src/bundler/css-processor.ts @@ -4,8 +4,6 @@ import * as csstree from 'css-tree'; -import type { CSSRule, OneInfo, StyleInfo } from '@lynx-js/web-constants'; - // --- Simplified parse (adapted from css-serializer/parse.ts) --- interface Declaration { @@ -260,7 +258,7 @@ function parseCSS(content: string): LynxStyleNode[] { function genStyleInfo( cssMap: Record, -): StyleInfo { +): unknown { return Object.fromEntries( Object.entries(cssMap).map(([cssId, nodes]) => { const contentsAtom: string[] = []; @@ -297,7 +295,7 @@ function genStyleInfo( const selectors = ((ast.children.first as csstree.Rule) .prelude as csstree.SelectorList).children .toArray() as csstree.Selector[]; - const groupedSelectors: CSSRule['sel'] = []; + const groupedSelectors: unknown[] = []; for (const selectorList of selectors) { let plainSelectors: string[] = []; let pseudoClassSelectors: string[] = []; @@ -356,7 +354,7 @@ function genStyleInfo( }); } } - const info: OneInfo = { + const info: unknown = { content: [contentsAtom.join('\n')], rules, }; diff --git a/packages/repl/src/bundler/template-builder.ts b/packages/repl/src/bundler/template-builder.ts index c6b9efd4e4..ada898f804 100644 --- a/packages/repl/src/bundler/template-builder.ts +++ b/packages/repl/src/bundler/template-builder.ts @@ -1,5 +1,4 @@ /* eslint-disable headers/header-format */ -import type { LynxTemplate, StyleInfo } from '@lynx-js/web-constants'; import { processCSS } from './css-processor.js'; import { getConsoleWrapperCode } from '../console/console-wrapper.js'; @@ -27,7 +26,7 @@ export function buildLynxTemplate( css: string, sessionId: string, ): { - template: LynxTemplate; + template: unknown; timing: { 'css-serializer': number | null; assemble: number }; } { const mainThreadWithFallback = `${mainThread} @@ -43,7 +42,7 @@ if (typeof globalThis.renderPage !== 'function') { + getBackgroundLifecycleCode() + background; - let styleInfo: StyleInfo = {}; + let styleInfo: unknown = {}; let cssSerializerTime: number | null = null; if (css.trim()) { const t = performance.now(); @@ -52,7 +51,7 @@ if (typeof globalThis.renderPage !== 'function') { } const assembleStart = performance.now(); - const template: LynxTemplate = { + const template: unknown = { lepusCode: { root: mainThreadCode }, manifest: { '/app-service.js': backgroundCode }, styleInfo, diff --git a/packages/repl/src/components/LynxPreview.tsx b/packages/repl/src/components/LynxPreview.tsx index bf7268051c..beb2bd53c2 100644 --- a/packages/repl/src/components/LynxPreview.tsx +++ b/packages/repl/src/components/LynxPreview.tsx @@ -1,12 +1,9 @@ /* eslint-disable headers/header-format, sort-imports, import/order, @typescript-eslint/no-unsafe-assignment, @typescript-eslint/no-unsafe-member-access, n/no-unsupported-features/node-builtins, @typescript-eslint/prefer-nullish-coalescing */ import { useRef, useEffect, useState, useCallback } from 'react'; -import type { LynxTemplate } from '@lynx-js/web-constants'; -import type { LynxView } from '@lynx-js/web-core'; - -let renderCounter = 0; +import type { LynxViewElement as LynxView } from '@lynx-js/web-core/client'; interface LynxPreviewProps { - template: LynxTemplate | null; + template: Record | null; isDark: boolean; onLoad?: () => void; } @@ -83,8 +80,10 @@ export function LynxPreview({ template, isDark, onLoad }: LynxPreviewProps) { setError(null); setIsLoading(true); - lynxView.customTemplateLoader = async () => template; - lynxView.url = `repl://template/v${renderCounter++}`; + const blobUrl = URL.createObjectURL( + new Blob([JSON.stringify(template)], { type: 'application/json' }), + ); + lynxView.url = blobUrl; // lynx-view has no load event. The url setter schedules teardown+boot via // queueMicrotask, so our Promise microtask (queued after) runs once the @@ -112,6 +111,7 @@ export function LynxPreview({ template, isDark, onLoad }: LynxPreviewProps) { }); return () => { + URL.revokeObjectURL(blobUrl); observer?.disconnect(); }; }, [template, onLoad]); diff --git a/packages/repl/src/components/PreviewPane.tsx b/packages/repl/src/components/PreviewPane.tsx index 1d60bdf3c1..cdbdabf079 100644 --- a/packages/repl/src/components/PreviewPane.tsx +++ b/packages/repl/src/components/PreviewPane.tsx @@ -1,6 +1,6 @@ /* eslint-disable headers/header-format, sort-imports, import/order, n/file-extension-in-import */ import { RotateCw } from 'lucide-react'; -import type { LynxTemplate } from '@lynx-js/web-constants'; +import type { LynxTemplate } from '@lynx-js/web-core/client'; import { LynxPreview } from './LynxPreview'; import { ConsolePanel } from './ConsolePanel'; import { diff --git a/packages/repl/src/index.tsx b/packages/repl/src/index.tsx index 7dfc43e122..5aeda8de09 100644 --- a/packages/repl/src/index.tsx +++ b/packages/repl/src/index.tsx @@ -2,10 +2,7 @@ // Licensed under the Apache License Version 2.0 that can be found in the // LICENSE file in the root directory of this source tree. -import '@lynx-js/web-core'; -import '@lynx-js/web-core/index.css'; -import '@lynx-js/web-elements/index.css'; -import '@lynx-js/web-elements/all'; +import '@lynx-js/web-core/client'; import './globals.css'; diff --git a/packages/web-platform/offscreen-document/CHANGELOG.md b/packages/web-platform/offscreen-document/CHANGELOG.md deleted file mode 100644 index 03c8b9fe3a..0000000000 --- a/packages/web-platform/offscreen-document/CHANGELOG.md +++ /dev/null @@ -1,72 +0,0 @@ -# @lynx-js/offscreen-document - -## 0.1.4 - -### Patch Changes - -- remove innerHTML, replace it by textContent ([#1622](https://github.com/lynx-family/lynx-stack/pull/1622)) - -## 0.1.3 - -### Patch Changes - -- feat: support to dump the css og system's style ([#1272](https://github.com/lynx-family/lynx-stack/pull/1272)) - -## 0.1.2 - -### Patch Changes - -- refactor: make the opcode be a plain array ([#1051](https://github.com/lynx-family/lynx-stack/pull/1051)) - - #1042 - -## 0.1.1 - -### Patch Changes - -- feat: add sheet.insertRule support ([#1026](https://github.com/lynx-family/lynx-stack/pull/1026)) - -- refactor: implement mts apis in closure pattern ([#1004](https://github.com/lynx-family/lynx-stack/pull/1004)) - -## 0.1.0 - -### Minor Changes - -- remove `dumpHTMLString` ([#919](https://github.com/lynx-family/lynx-stack/pull/919)) - -## 0.0.4 - -### Patch Changes - -- fix: remove all children after the innerHTML setter is called ([#850](https://github.com/lynx-family/lynx-stack/pull/850)) - -- refactor: code clean ([#897](https://github.com/lynx-family/lynx-stack/pull/897)) - - rename many internal apis to make logic be clear: - - multi-thread: startMainWorker -> prepareMainThreadAPIs -> startMainThread -> createMainThreadContext(new MainThreadRuntime) - all-on-ui: prepareMainThreadAPIs -> startMainThread -> createMainThreadContext(new MainThreadRuntime) - -- perf: improve dom operation performance ([#881](https://github.com/lynx-family/lynx-stack/pull/881)) - - - code clean for offscreen-document, cut down inheritance levels - - add `appendChild` method for OffscreenElement, improve performance for append one node - - bypass some JS getter for dumping SSR string - -## 0.0.3 - -### Patch Changes - -- feat: support OffscreenDocument.innerHTML ([#772](https://github.com/lynx-family/lynx-stack/pull/772)) - -## 0.0.2 - -### Patch Changes - -- feat: support touch events ([#641](https://github.com/lynx-family/lynx-stack/pull/641)) - -## 0.0.1 - -### Patch Changes - -- feat: support parentNode ([#625](https://github.com/lynx-family/lynx-stack/pull/625)) diff --git a/packages/web-platform/offscreen-document/Notice.txt b/packages/web-platform/offscreen-document/Notice.txt deleted file mode 100644 index 3ff8881bfd..0000000000 --- a/packages/web-platform/offscreen-document/Notice.txt +++ /dev/null @@ -1 +0,0 @@ -Copyright 2023-2024 The Lynx Authors. All rights reserved. \ No newline at end of file diff --git a/packages/web-platform/offscreen-document/README.md b/packages/web-platform/offscreen-document/README.md deleted file mode 100644 index 4b6b7a6547..0000000000 --- a/packages/web-platform/offscreen-document/README.md +++ /dev/null @@ -1,3 +0,0 @@ -# @lynx-js/offscreen-document - -Offscreen Document allows developers to use partial DOM in WebWorker diff --git a/packages/web-platform/offscreen-document/package.json b/packages/web-platform/offscreen-document/package.json deleted file mode 100644 index a395a7a7d9..0000000000 --- a/packages/web-platform/offscreen-document/package.json +++ /dev/null @@ -1,41 +0,0 @@ -{ - "name": "@lynx-js/offscreen-document", - "version": "0.1.4", - "private": false, - "description": "Offscreen Document allows developers to use particular DOM in WebWorker", - "keywords": [ - "WebWorker", - "DOM", - "lynx" - ], - "repository": { - "type": "git", - "url": "https://github.com/lynx-family/lynx-stack.git", - "directory": "packages/web-platform/offscreen-document" - }, - "license": "Apache-2.0", - "type": "module", - "exports": { - "./main": { - "types": "./dist/main/index.d.ts", - "default": "./dist/main/index.js" - }, - "./webworker": { - "types": "./dist/webworker/index.d.ts", - "default": "./dist/webworker/index.js" - }, - ".": { - "types": "./dist/index.d.ts" - } - }, - "main": "dist/index.js", - "typings": "dist/index.d.ts", - "files": [ - "dist", - "!dist/**/*.js.map", - "LICENSE.txt", - "Notice.txt", - "CHANGELOG.md", - "README.md" - ] -} diff --git a/packages/web-platform/offscreen-document/src/index.ts b/packages/web-platform/offscreen-document/src/index.ts deleted file mode 100644 index f3983c2935..0000000000 --- a/packages/web-platform/offscreen-document/src/index.ts +++ /dev/null @@ -1,6 +0,0 @@ -// Copyright 2023 The Lynx Authors. All rights reserved. -// Licensed under the Apache License Version 2.0 that can be found in the -// LICENSE file in the root directory of this source tree. -export type * from './webworker/index.js'; -export type * from './main/index.js'; -export type * from './types/index.js'; diff --git a/packages/web-platform/offscreen-document/src/main/index.ts b/packages/web-platform/offscreen-document/src/main/index.ts deleted file mode 100644 index ef7a443abf..0000000000 --- a/packages/web-platform/offscreen-document/src/main/index.ts +++ /dev/null @@ -1,4 +0,0 @@ -// Copyright 2023 The Lynx Authors. All rights reserved. -// Licensed under the Apache License Version 2.0 that can be found in the -// LICENSE file in the root directory of this source tree. -export * from './initOffscreenDocument.js'; diff --git a/packages/web-platform/offscreen-document/src/main/initOffscreenDocument.ts b/packages/web-platform/offscreen-document/src/main/initOffscreenDocument.ts deleted file mode 100644 index 2c5d227774..0000000000 --- a/packages/web-platform/offscreen-document/src/main/initOffscreenDocument.ts +++ /dev/null @@ -1,247 +0,0 @@ -// Copyright 2023 The Lynx Authors. All rights reserved. -// Licensed under the Apache License Version 2.0 that can be found in the -// LICENSE file in the root directory of this source tree. - -import { OperationType } from '../types/ElementOperation.js'; - -function emptyHandler() { - // no-op -} -const otherPropertyNames = [ - 'detail', - 'keyCode', - 'charCode', - 'elapsedTime', - 'propertyName', - 'pseudoElement', - 'animationName', - 'touches', - 'targetTouches', - 'changedTouches', - 'x', - 'y', -]; -const blockList = new Set([ - 'isTrusted', - 'target', - 'currentTarget', - 'type', - 'bubbles', - 'window', - 'self', - 'view', - 'srcElement', - 'eventPhase', -]); - -function transferToCloneable(value: any): any { - if ( - typeof value === 'string' || typeof value === 'number' - || typeof value === 'boolean' || value === null || value === undefined - ) { - return value; - } else if (value[Symbol.iterator]) { - return [...value].map(transferToCloneable); - } else if (typeof value === 'object' && !(value instanceof EventTarget)) { - const obj: Record = {}; - for (const key in value) { - if (!blockList.has(key)) { - obj[key] = transferToCloneable(value[key]); - } - } - return obj; - } -} - -export function initOffscreenDocument(options: { - shadowRoot: ShadowRoot; - onEvent: ( - eventType: string, - targetUniqueId: number, - bubbles: boolean, - otherProperties: Parameters[0], - ) => void; -}) { - const { shadowRoot, onEvent } = options; - const enabledEvents: Set = new Set(); - const uniqueIdToElement: [ - WeakRef, - ...(WeakRef | undefined)[], - ] = [new WeakRef(shadowRoot)]; - const elementToUniqueId: WeakMap = new WeakMap(); - - function _getElement( - uniqueId: number, - ): HTMLElement { - const element = uniqueIdToElement[uniqueId]?.deref(); - if (element) { - return element as HTMLElement; - } else { - throw new Error( - `[lynx-web] cannot find element with uniqueId: ${uniqueId}`, - ); - } - } - - function _eventHandler(ev: Event) { - if ( - ev.eventPhase !== Event.CAPTURING_PHASE && ev.currentTarget !== shadowRoot - ) { - return; - } - const target = ev.target as HTMLElement | null; - if (target && elementToUniqueId.has(target)) { - const targetUniqueId = elementToUniqueId.get(target)!; - const eventType = ev.type; - const otherProperties: Record = {}; - for (const propertyName of otherPropertyNames) { - if (propertyName in ev) { - // @ts-expect-error - otherProperties[propertyName] = transferToCloneable(ev[propertyName]); - } - } - onEvent(eventType, targetUniqueId, ev.bubbles, otherProperties); - } - } - - function decodeOperation(operations: (string | number)[]) { - if (operations.length === 0) { - return; - } - let offset: number = 0; - const { - CreateElement, - SetAttribute, - RemoveAttribute, - Append, - Remove, - ReplaceWith, - InsertBefore, - EnableEvent, - RemoveChild, - StyleDeclarationSetProperty, - StyleDeclarationRemoveProperty, - SetTextContent, - sheetInsertRule, - sheetRuleUpdateCssText, - } = OperationType; - let op: number | string | undefined; - while ((op = operations[offset++])) { - const uid = operations[offset++] as number; - if (op === CreateElement) { - const element = document.createElement(operations[offset++] as string); - uniqueIdToElement[uid] = new WeakRef(element); - elementToUniqueId.set(element, uid); - } else { - const target = _getElement(uid); - switch (op) { - case SetAttribute: - { - const key = operations[offset++] as string; - const value = operations[offset++] as string; - target.setAttribute(key, value); - } - break; - case RemoveAttribute: - { - target.removeAttribute(operations[offset++] as string); - } - break; - case Append: - { - const childrenLength = operations[offset++] as number; - for (let i = 0; i < childrenLength; i++) { - const id = operations[offset++] as number; - const child = _getElement(id); - target.appendChild(child); - } - } - break; - case Remove: - target.remove(); - break; - case ReplaceWith: - { - const childrenLength = operations[offset++] as number; - const newChildren: HTMLElement[] = operations.slice( - offset, - offset + childrenLength, - ).map((id) => _getElement(id as number)); - offset += childrenLength; - target.replaceWith(...newChildren); - } - break; - case InsertBefore: - { - const kid = _getElement(operations[offset++] as number); - const refUid = operations[offset++] as number; - const ref = refUid ? _getElement(refUid) : null; - target.insertBefore(kid, ref); - } - break; - case EnableEvent: - const eventType = operations[offset++] as string; - target.addEventListener( - eventType, - emptyHandler, - { passive: true }, - ); - if (!enabledEvents.has(eventType)) { - shadowRoot.addEventListener( - eventType, - _eventHandler, - { passive: true, capture: true }, - ); - enabledEvents.add(eventType); - } - break; - case RemoveChild: - { - const kid = _getElement(operations[offset++] as number); - target.removeChild(kid); - } - break; - case StyleDeclarationSetProperty: - { - target.style.setProperty( - operations[offset++] as string, - operations[offset++] as string, - operations[offset++] as string, - ); - } - break; - case StyleDeclarationRemoveProperty: - { - target.style.removeProperty(operations[offset++] as string); - } - break; - case SetTextContent: - target.textContent = operations[offset++] as string; - break; - case sheetInsertRule: - { - const index = operations[offset++] as number; - const rule = operations[offset++] as string; - (target as HTMLStyleElement).sheet!.insertRule( - rule, - index, - ); - } - break; - case sheetRuleUpdateCssText: - { - const index = operations[offset++] as number; - ((target as HTMLStyleElement).sheet! - .cssRules[index]! as CSSStyleRule).style.cssText = - operations[offset++] as string; - } - break; - } - } - } - } - - return { - decodeOperation, - }; -} diff --git a/packages/web-platform/offscreen-document/src/types/ElementOperation.ts b/packages/web-platform/offscreen-document/src/types/ElementOperation.ts deleted file mode 100644 index 8e1313bc20..0000000000 --- a/packages/web-platform/offscreen-document/src/types/ElementOperation.ts +++ /dev/null @@ -1,137 +0,0 @@ -// Copyright 2023 The Lynx Authors. All rights reserved. -// Licensed under the Apache License Version 2.0 that can be found in the -// LICENSE file in the root directory of this source tree. - -export const OperationType = { - CreateElement: 1, - SetAttribute: 2, - RemoveAttribute: 3, - Append: 4, - Remove: 5, - ReplaceWith: 6, - InsertBefore: 7, - EnableEvent: 8, - RemoveChild: 9, - StyleDeclarationSetProperty: 10, - StyleDeclarationRemoveProperty: 11, - SetTextContent: 12, - sheetInsertRule: 13, - sheetRuleUpdateCssText: 14, -} as const; - -// keep these types for opcode hint - -// type IOperationType = typeof OperationType; -// interface ElementOperationBase { -// type: IOperationType[keyof IOperationType]; -// /** -// * uniqueId -// */ -// uid: number; -// } - -// export interface CreateOperation extends ElementOperationBase { -// type: IOperationType['CreateElement']; -// tag: string; -// } - -// export interface SetAttributeOperation extends ElementOperationBase { -// type: IOperationType['SetAttribute']; -// key: string; -// value: string; -// } -// export interface RemoveAttributeOperation extends ElementOperationBase { -// type: IOperationType['RemoveAttribute']; -// key: string; -// } - -// export interface AppendOperation extends ElementOperationBase { -// type: IOperationType['Append']; -// /** -// * child uniqueId -// */ -// cid: number[]; -// } - -// export interface RemoveOperation extends ElementOperationBase { -// type: IOperationType['Remove']; -// } - -// export interface InsertBeforeOperation extends ElementOperationBase { -// type: IOperationType['InsertBefore']; -// /** -// * child uniqueId -// */ -// cid: number; -// ref?: number | undefined; -// } - -// export interface ReplaceOperation extends ElementOperationBase { -// type: IOperationType['ReplaceWith']; -// /** -// * the new element's unique id. -// */ -// nid: number[]; -// } - -// export interface EnableEventOperation extends ElementOperationBase { -// type: IOperationType['EnableEvent']; -// eventType: string; -// } - -// export interface RemoveChildOperation extends ElementOperationBase { -// type: IOperationType['RemoveChild']; -// /** -// * the child element's unique id to be removed. -// */ -// cid: number; -// } - -// export interface StyleDeclarationSetPropertyOperation -// extends ElementOperationBase -// { -// type: IOperationType['StyleDeclarationSetProperty']; -// property: string; -// value: string; -// priority: string | undefined | ''; -// } - -// export interface StyleDeclarationRemovePropertyOperation -// extends ElementOperationBase -// { -// type: IOperationType['StyleDeclarationRemoveProperty']; -// property: string; -// } - -// export interface SetTextContentOperation extends ElementOperationBase { -// type: IOperationType['SetTextContent']; -// text: string; -// } - -// export interface SheetInsertRuleOperation extends ElementOperationBase { -// type: IOperationType['sheetInsertRule']; -// rule: string; -// index: number; -// } - -// export interface SheetRuleUpdateCssTextOperation extends ElementOperationBase { -// type: IOperationType['sheetRuleUpdateCssText']; -// index: number; -// cssText: string; -// } - -// export type ElementOperation = -// | EnableEventOperation -// | ReplaceOperation -// | InsertBeforeOperation -// | CreateOperation -// | SetAttributeOperation -// | RemoveAttributeOperation -// | AppendOperation -// | RemoveOperation -// | RemoveChildOperation -// | StyleDeclarationSetPropertyOperation -// | StyleDeclarationRemovePropertyOperation -// | SetTextContentOperation -// | SheetInsertRuleOperation -// | SheetRuleUpdateCssTextOperation; diff --git a/packages/web-platform/offscreen-document/src/types/index.ts b/packages/web-platform/offscreen-document/src/types/index.ts deleted file mode 100644 index 0bf0e7c6cb..0000000000 --- a/packages/web-platform/offscreen-document/src/types/index.ts +++ /dev/null @@ -1,4 +0,0 @@ -// Copyright 2023 The Lynx Authors. All rights reserved. -// Licensed under the Apache License Version 2.0 that can be found in the -// LICENSE file in the root directory of this source tree. -export type * from './ElementOperation.js'; diff --git a/packages/web-platform/offscreen-document/src/webworker/OffscreenCSSStyleDeclaration.ts b/packages/web-platform/offscreen-document/src/webworker/OffscreenCSSStyleDeclaration.ts deleted file mode 100644 index 071c280222..0000000000 --- a/packages/web-platform/offscreen-document/src/webworker/OffscreenCSSStyleDeclaration.ts +++ /dev/null @@ -1,54 +0,0 @@ -// Copyright 2023 The Lynx Authors. All rights reserved. -// Licensed under the Apache License Version 2.0 that can be found in the -// LICENSE file in the root directory of this source tree. -import { - _attributes, - ancestorDocument, - type OffscreenElement, -} from './OffscreenElement.js'; -import { operations } from './OffscreenDocument.js'; -import { OperationType } from '../types/ElementOperation.js'; -import { uniqueId } from './OffscreenElement.js'; - -export class OffscreenCSSStyleDeclaration { - /** - * @private - */ - private readonly _parent: OffscreenElement; - - constructor(parent: OffscreenElement) { - this._parent = parent; - } - - setProperty( - property: string, - value: string, - priority?: 'important' | undefined | '', - ): void { - this._parent[ancestorDocument][operations].push( - OperationType['StyleDeclarationSetProperty'], - this._parent[uniqueId], - property, - value, - priority ?? '', - ); - const currentStyle = this._parent.getAttribute('style') ?? ''; - this._parent[_attributes].set( - 'style', - currentStyle + `${property}:${value}${priority ? ` !${priority}` : ''};`, - ); - } - - removeProperty(property: string): void { - this._parent[ancestorDocument][operations].push( - OperationType['StyleDeclarationRemoveProperty'], - this._parent[uniqueId], - property, - ); - const currentStyle = this._parent.getAttribute('style') ?? ''; - this._parent[_attributes].set( - 'style', - currentStyle + `${property}:inital;`, - ); // only for SSR - } -} diff --git a/packages/web-platform/offscreen-document/src/webworker/OffscreenDocument.ts b/packages/web-platform/offscreen-document/src/webworker/OffscreenDocument.ts deleted file mode 100644 index 6d939ccc9d..0000000000 --- a/packages/web-platform/offscreen-document/src/webworker/OffscreenDocument.ts +++ /dev/null @@ -1,128 +0,0 @@ -// Copyright 2023 The Lynx Authors. All rights reserved. -// Licensed under the Apache License Version 2.0 that can be found in the -// LICENSE file in the root directory of this source tree. -import { OperationType } from '../types/ElementOperation.js'; -import { - _attributes, - _children, - ancestorDocument, - OffscreenElement, -} from './OffscreenElement.js'; -import { - eventPhase, - OffscreenEvent, - propagationStopped, -} from './OffscreenEvent.js'; - -export const operations = Symbol('operations'); -export const enableEvent = Symbol('enableEvent'); -export const getElementByUniqueId = Symbol('getElementByUniqueId'); -export const _onEvent = Symbol('_onEvent'); -const _uniqueIdInc = Symbol('uniqueIdInc'); -const _uniqueIdToElement = Symbol('_uniqueIdToElement'); -export class OffscreenDocument extends OffscreenElement { - /** - * @private - */ - [_uniqueIdInc] = 1; - - /** - * @private - */ - [_uniqueIdToElement]: WeakRef[] = []; - - /** - * @private - */ - [operations]: (string | number)[] = []; - - /** - * @private - * @param uniqueId - * @returns - */ - [getElementByUniqueId](uniqueId: number): OffscreenElement | undefined { - return this[_uniqueIdToElement][uniqueId]?.deref(); - } - - [enableEvent]: (eventType: string, uid: number) => void; - constructor( - private _callbacks: { - onCommit: (operations: (string | number)[]) => void; - }, - ) { - const enableEventImpl: (nm: string, uid: number) => void = ( - eventType, - uid, - ) => { - this[operations].push( - OperationType.EnableEvent, - uid, - eventType, - ); - }; - super('', 0); - this[ancestorDocument] = this; - this[enableEvent] = enableEventImpl; - } - - commit(): void { - const currentOperations = this[operations]; - this[operations] = []; - this._callbacks.onCommit(currentOperations); - } - - createElement(tagName: string): OffscreenElement { - const uniqueId = this[_uniqueIdInc]++; - const element = new OffscreenElement(tagName, uniqueId); - element[ancestorDocument] = this; - this[_uniqueIdToElement][uniqueId] = new WeakRef(element); - this[operations].push( - OperationType.CreateElement, - uniqueId, - tagName, - ); - return element; - } - - [_onEvent] = ( - eventType: string, - targetUniqueId: number, - bubbles: boolean, - otherProperties: Parameters[0], - ) => { - const target = this[getElementByUniqueId](targetUniqueId); - if (target) { - const bubblePath: OffscreenElement[] = []; - let tempTarget: OffscreenElement = target; - while (tempTarget.parentElement) { - bubblePath.push(tempTarget.parentElement); - tempTarget = tempTarget.parentElement; - } - const event = new OffscreenEvent(eventType, target); - Object.assign(event, otherProperties); - // capture phase - event[eventPhase] = Event.CAPTURING_PHASE; - for (let ii = bubblePath.length - 1; ii >= 0; ii--) { - const currentPhaseTarget = bubblePath[ii]!; - currentPhaseTarget.dispatchEvent(event); - if (event[propagationStopped]) { - return; - } - } - // target phase - event[eventPhase] = Event.AT_TARGET; - target.dispatchEvent(event); - // bubble phase - if (bubbles) { - event[eventPhase] = Event.BUBBLING_PHASE; - for (const currentPhaseTarget of bubblePath) { - currentPhaseTarget.dispatchEvent(event); - if (event[propagationStopped]) { - return; - } - } - } - } - }; -} diff --git a/packages/web-platform/offscreen-document/src/webworker/OffscreenElement.ts b/packages/web-platform/offscreen-document/src/webworker/OffscreenElement.ts deleted file mode 100644 index a71774a9b2..0000000000 --- a/packages/web-platform/offscreen-document/src/webworker/OffscreenElement.ts +++ /dev/null @@ -1,296 +0,0 @@ -// Copyright 2023 The Lynx Authors. All rights reserved. -// Licensed under the Apache License Version 2.0 that can be found in the -// LICENSE file in the root directory of this source tree. -import { - enableEvent, - operations, - type OffscreenDocument, -} from './OffscreenDocument.js'; -import { OffscreenCSSStyleDeclaration } from './OffscreenCSSStyleDeclaration.js'; -import { OperationType } from '../types/ElementOperation.js'; - -export const ancestorDocument = Symbol('ancestorDocument'); -export const _attributes = Symbol('_attributes'); -export const _children = Symbol('_children'); -export const textContent = Symbol('textContent'); -export const _cssRuleContents = Symbol('_cssRuleContents'); -export const uniqueId = Symbol('uniqueId'); -const _style = Symbol('_style'); - -type OffscreenStyleSheet = { - cssRules: { style: { cssText: string } }[]; - insertRule: (rule: string, index: number) => number; -}; -export class OffscreenElement extends EventTarget { - public [textContent]: string = ''; - private [_style]?: OffscreenCSSStyleDeclaration; - private readonly [_attributes] = new Map(); - private _parentElement: OffscreenElement | null = null; - readonly [_children]: OffscreenElement[] = []; - [_cssRuleContents]?: string[]; - #sheet?: OffscreenStyleSheet; - /** - * @private - */ - readonly [uniqueId]: number; - - /** - * @private - */ - [ancestorDocument]!: OffscreenDocument; - - public readonly localName: string; - - constructor( - localName: string, - elementUniqueId: number, - ) { - super(); - this.localName = localName; - this[uniqueId] = elementUniqueId; - } - - get sheet() { - if (!this.#sheet) { - const uid = this[uniqueId]; - const ancestor = this[ancestorDocument]; - const cssRules: { style: { cssText: string } }[] = []; - this.#sheet = { - cssRules, - insertRule: (rule: string, index: number) => { - cssRules.splice(index, 0, { - style: { - set cssText(text: string) { - ancestor[operations].push( - OperationType.sheetRuleUpdateCssText, - uid, - index, - text, - ); - }, - }, - }); - if (!this[_cssRuleContents]) { - this[_cssRuleContents] = []; - } - this[_cssRuleContents].splice(index, 0, rule); - this[ancestorDocument][operations].push( - OperationType.sheetInsertRule, - uid, - index, - rule, - ); - return index; - }, - }; - } - return this.#sheet!; - } - - get tagName(): string { - return this.localName.toUpperCase(); - } - - get style(): OffscreenCSSStyleDeclaration { - if (!this[_style]) { - this[_style] = new OffscreenCSSStyleDeclaration( - this, - ); - } - return this[_style]; - } - - get children(): OffscreenElement[] { - return this[_children].slice(); - } - - get parentElement(): OffscreenElement | null { - return this._parentElement; - } - - get parentNode(): OffscreenElement | null { - return this._parentElement; - } - - get firstElementChild(): OffscreenElement | null { - return this[_children][0] ?? null; - } - - get lastElementChild(): OffscreenElement | null { - return this[_children][this[_children].length - 1] ?? null; - } - - get nextElementSibling(): OffscreenElement | null { - const parent = this._parentElement; - if (parent) { - const nextElementSiblingIndex = parent[_children].indexOf(this); - if (nextElementSiblingIndex >= 0) { - return parent[_children][nextElementSiblingIndex + 1] || null; - } - } - return null; - } - - protected _remove(): void { - if (this._parentElement) { - const currentIdx = this._parentElement[_children].indexOf(this); - this._parentElement[_children].splice(currentIdx, 1); - this._parentElement = null; - } - } - - setAttribute(qualifiedName: string, value: string): void { - this[_attributes].set(qualifiedName, value); - this[ancestorDocument][operations].push( - OperationType.SetAttribute, - this[uniqueId], - qualifiedName, - value, - ); - } - - getAttribute(qualifiedName: string): string | null { - return this[_attributes].get(qualifiedName) ?? null; - } - - removeAttribute(qualifiedName: string): void { - this[_attributes].delete(qualifiedName); - this[ancestorDocument][operations].push( - OperationType.RemoveAttribute, - this[uniqueId], - qualifiedName, - ); - } - - append(...nodes: (OffscreenElement)[]): void { - this[ancestorDocument][operations].push( - OperationType.Append, - this[uniqueId], - nodes.length, - ...nodes.map(node => node[uniqueId]), - ); - for (const node of nodes) { - node._remove(); - node._parentElement = this; - } - this[_children].push(...nodes); - } - - appendChild(node: OffscreenElement): OffscreenElement { - this[ancestorDocument][operations].push( - OperationType.Append, - this[uniqueId], - 1, - node[uniqueId], - ); - node._remove(); - node._parentElement = this; - this[_children].push(node); - return node; - } - - replaceWith(...nodes: (OffscreenElement)[]): void { - this[ancestorDocument][operations].push( - OperationType.ReplaceWith, - this[uniqueId], - nodes.length, - ...nodes.map(node => node[uniqueId]), - ); - if (this._parentElement) { - const parent = this._parentElement; - this._parentElement = null; - const currentIdx = parent[_children].indexOf(this); - parent[_children].splice(currentIdx, 1, ...nodes); - for (const node of nodes) { - node._parentElement = parent; - } - } - } - - getAttributeNames(): string[] { - return [...this[_attributes].keys()]; - } - - remove(): void { - this[ancestorDocument][operations].push( - OperationType.Remove, - this[uniqueId], - ); - this._remove(); - } - - insertBefore( - newNode: OffscreenElement, - refNode: OffscreenElement | null, - ): OffscreenElement { - newNode._remove(); - if (refNode) { - const refNodeIndex = this[_children].indexOf(refNode); - if (refNodeIndex >= 0) { - newNode._parentElement = this; - this[_children].splice(refNodeIndex, 0, newNode); - } - } else { - newNode._parentElement = this; - this[_children].push(newNode); - } - - this[ancestorDocument][operations].push( - OperationType.InsertBefore, - this[uniqueId], - newNode[uniqueId], - refNode?.[uniqueId] ?? 0, - ); - return newNode; - } - - removeChild(child: OffscreenElement | null): OffscreenElement { - if (!child) { - throw new DOMException( - 'The node to be removed is not a child of this node.', - 'NotFoundError', - ); - } - if (child._parentElement !== this) { - throw new DOMException( - 'The node to be removed is not a child of this node.', - 'NotFoundError', - ); - } - this[ancestorDocument][operations].push( - OperationType.RemoveChild, - this[uniqueId], - child![uniqueId], - ); - child._remove(); - return child; - } - - override addEventListener( - type: string, - callback: EventListenerOrEventListenerObject | null, - options?: AddEventListenerOptions | boolean, - ): void { - this[ancestorDocument][enableEvent](type, this[uniqueId]); - super.addEventListener(type, callback, options); - } - - get textContent() { - return this[textContent]; - } - - set textContent(text: string) { - this[ancestorDocument][operations].push( - OperationType.SetTextContent, - this[uniqueId], - text, - ); - for (const child of this.children) { - (child as OffscreenElement).remove(); - } - this[textContent] = text; - if (this[_cssRuleContents]) { - this[_cssRuleContents] = []; - } - } -} diff --git a/packages/web-platform/offscreen-document/src/webworker/OffscreenEvent.ts b/packages/web-platform/offscreen-document/src/webworker/OffscreenEvent.ts deleted file mode 100644 index cbf0df4bfd..0000000000 --- a/packages/web-platform/offscreen-document/src/webworker/OffscreenEvent.ts +++ /dev/null @@ -1,34 +0,0 @@ -// Copyright 2023 The Lynx Authors. All rights reserved. -// Licensed under the Apache License Version 2.0 that can be found in the -// LICENSE file in the root directory of this source tree. -import type { OffscreenElement } from './OffscreenElement.js'; - -export const propagationStopped = Symbol('propagationStopped'); -export const eventPhase = Symbol('eventPhase'); - -export class OffscreenEvent extends Event { - [eventPhase]: Event['eventPhase'] = Event.CAPTURING_PHASE; - constructor(type: string, private _target: OffscreenElement) { - super(type); - } - - override get target(): OffscreenElement { - return this._target; - } - - [propagationStopped] = false; - - override stopImmediatePropagation(): void { - this[propagationStopped] = true; - super.stopImmediatePropagation(); - } - - override stopPropagation(): void { - this[propagationStopped] = true; - super.stopPropagation(); - } - - override get eventPhase() { - return this[eventPhase]; - } -} diff --git a/packages/web-platform/offscreen-document/src/webworker/index.ts b/packages/web-platform/offscreen-document/src/webworker/index.ts deleted file mode 100644 index 43c6a705e5..0000000000 --- a/packages/web-platform/offscreen-document/src/webworker/index.ts +++ /dev/null @@ -1,15 +0,0 @@ -// Copyright 2023 The Lynx Authors. All rights reserved. -// Licensed under the Apache License Version 2.0 that can be found in the -// LICENSE file in the root directory of this source tree. -export { OffscreenDocument, _onEvent } from './OffscreenDocument.js'; -export { - _attributes, - textContent, - _children, - _cssRuleContents, - OffscreenElement, -} from './OffscreenElement.js'; -export type * from './OffscreenEvent.js'; -export type * from './OffscreenElement.js'; -export type * from './OffscreenCSSStyleDeclaration.js'; -export type * from '../types/index.js'; diff --git a/packages/web-platform/offscreen-document/tsconfig.json b/packages/web-platform/offscreen-document/tsconfig.json deleted file mode 100644 index 744c7b097a..0000000000 --- a/packages/web-platform/offscreen-document/tsconfig.json +++ /dev/null @@ -1,12 +0,0 @@ -{ - "extends": "../tsconfig.json", - "compilerOptions": { - "composite": true, - "rootDir": "./src", - "outDir": "./dist", - "lib": ["ESNext", "WebWorker", "DOM"], - "exactOptionalPropertyTypes": true, - }, - "include": ["src"], - "references": [], -} diff --git a/packages/web-platform/tsconfig.json b/packages/web-platform/tsconfig.json index 972935f3ff..445a58a64d 100644 --- a/packages/web-platform/tsconfig.json +++ b/packages/web-platform/tsconfig.json @@ -13,14 +13,9 @@ "references": [ /** packages-start */ { "path": "./playwright-fixtures/tsconfig.json" }, - { "path": "./offscreen-document/tsconfig.json" }, { "path": "./web-elements/tsconfig.json" }, - { "path": "./web-constants/tsconfig.json" }, { "path": "./web-worker-rpc/tsconfig.json" }, - { "path": "./web-mainthread-apis/tsconfig.json" }, - { "path": "./web-core-server/tsconfig.json" }, { "path": "./web-core/tsconfig.json" }, - { "path": "./web-core-wasm/tsconfig.json" }, { "path": "./web-rsbuild-plugin/tsconfig.json" }, { "path": "./web-rsbuild-server-middleware/tsconfig.json" }, /** packages-end */ diff --git a/packages/web-platform/web-constants/CHANGELOG.md b/packages/web-platform/web-constants/CHANGELOG.md deleted file mode 100644 index 47794dd52a..0000000000 --- a/packages/web-platform/web-constants/CHANGELOG.md +++ /dev/null @@ -1,930 +0,0 @@ -# @lynx-js/web-constants - -## 0.19.9 - -### Patch Changes - -- Implement `__ElementAnimate` PAPI for web platform animation lifecycle ([#2329](https://github.com/lynx-family/lynx-stack/pull/2329)) - -- Updated dependencies []: - - @lynx-js/web-worker-rpc@0.19.9 - -## 0.19.8 - -### Patch Changes - -- Updated dependencies []: - - @lynx-js/web-worker-rpc@0.19.8 - -## 0.19.7 - -### Patch Changes - -- Updated dependencies []: - - @lynx-js/web-worker-rpc@0.19.7 - -## 0.19.6 - -### Patch Changes - -- feat: add main-thread API: \_\_QuerySelector ([#2115](https://github.com/lynx-family/lynx-stack/pull/2115)) - -- fix: when a list-item is deleted from list, the deleted list-item is still showed incorrectly. ([#1092](https://github.com/lynx-family/lynx-stack/pull/1092)) - - This is because the `enqueueComponent` method does not delete the node from the Element Tree. It is only to maintain the display node on RL, and lynx web needs to delete the dom additionally. - -- feat: support main thread invoke ui method ([#2104](https://github.com/lynx-family/lynx-stack/pull/2104)) - -- feat: support lynx.reload() ([#2127](https://github.com/lynx-family/lynx-stack/pull/2127)) - -- Updated dependencies [[`f7133c1`](https://github.com/lynx-family/lynx-stack/commit/f7133c137f094063e991dfa0e993ea92177aa173)]: - - @lynx-js/web-worker-rpc@0.19.6 - -## 0.19.5 - -### Patch Changes - -- Updated dependencies [[`a91173c`](https://github.com/lynx-family/lynx-stack/commit/a91173c986ce3f358f1c11c788ca46a0529c701d)]: - - @lynx-js/web-worker-rpc@0.19.5 - -## 0.19.4 - -### Patch Changes - -- Updated dependencies [[`bba05e2`](https://github.com/lynx-family/lynx-stack/commit/bba05e2ed06cca8009ad415fd9777e8334a0887a)]: - - @lynx-js/web-worker-rpc@0.19.4 - -## 0.19.3 - -### Patch Changes - -- Updated dependencies [[`986761d`](https://github.com/lynx-family/lynx-stack/commit/986761dd1e9e631f8118faec68188f29f78e9236)]: - - @lynx-js/web-worker-rpc@0.19.3 - -## 0.19.2 - -### Patch Changes - -- Updated dependencies []: - - @lynx-js/web-worker-rpc@0.19.2 - -## 0.19.1 - -### Patch Changes - -- Updated dependencies []: - - @lynx-js/web-worker-rpc@0.19.1 - -## 0.19.0 - -### Patch Changes - -- Updated dependencies []: - - @lynx-js/web-worker-rpc@0.19.0 - -## 0.18.4 - -### Patch Changes - -- Updated dependencies []: - - @lynx-js/web-worker-rpc@0.18.4 - -## 0.18.3 - -### Patch Changes - -- feat: add \_\_GetSourceMapRelease API for nativeApp. ([#1923](https://github.com/lynx-family/lynx-stack/pull/1923)) - -- Updated dependencies []: - - @lynx-js/web-worker-rpc@0.18.3 - -## 0.18.2 - -### Patch Changes - -- Updated dependencies []: - - @lynx-js/web-worker-rpc@0.18.2 - -## 0.18.1 - -### Patch Changes - -- Updated dependencies []: - - @lynx-js/web-worker-rpc@0.18.1 - -## 0.18.0 - -### Patch Changes - -- fix: ([#1837](https://github.com/lynx-family/lynx-stack/pull/1837)) - - 1. `LynxView.updateData()` cannot trigger `dataProcessor`. - - 2. **This is a break change:** The second parameter of `LynxView.updateData()` has been changed from `UpdateDataType` to `string`, which is the `processorName` (default is `default` which will use `defaultDataProcessor`). This change is to better align with Native. The current complete type is as follows: - - ```ts - LynxView.updateData(data: Cloneable, processorName?: string | undefined, callback?: (() => void) | undefined): void - ``` - -- Updated dependencies []: - - @lynx-js/web-worker-rpc@0.18.0 - -## 0.17.2 - -### Patch Changes - -- feat: support load bts chunk from remote address ([#1834](https://github.com/lynx-family/lynx-stack/pull/1834)) - - - re-support chunk splitting - - support lynx.requireModule with a json file - - support lynx.requireModule, lynx.requireModuleAsync with a remote url - - support to add a breakpoint in chrome after reloading the web page - -- Updated dependencies []: - - @lynx-js/web-worker-rpc@0.17.2 - -## 0.17.1 - -### Patch Changes - -- Updated dependencies []: - - @lynx-js/web-worker-rpc@0.17.1 - -## 0.17.0 - -### Patch Changes - -- fix: avoid duplicate style transformation ([#1748](https://github.com/lynx-family/lynx-stack/pull/1748)) - - After this commit, we use DAG methods to handle the styleInfos - -- Updated dependencies []: - - @lynx-js/web-worker-rpc@0.17.0 - -## 0.16.1 - -### Patch Changes - -- feat: supports lazy bundle. (This feature requires `@lynx-js/lynx-core >= 0.1.3`) ([#1235](https://github.com/lynx-family/lynx-stack/pull/1235)) - -- Updated dependencies []: - - @lynx-js/web-worker-rpc@0.16.1 - -## 0.16.0 - -### Minor Changes - -- refactor: provide the mts a real globalThis ([#1589](https://github.com/lynx-family/lynx-stack/pull/1589)) - - Before this change, We create a function wrapper and a fake globalThis for Javascript code. - - This caused some issues. - - After this change, we will create an iframe for createing an isolated Javascript context. - - This means the globalThis will be the real one. - -### Patch Changes - -- refactor: add `:not([l-e-name])` at the end of selector for lazy component ([#1622](https://github.com/lynx-family/lynx-stack/pull/1622)) - -- fix: the SystemInfo in bts should be assigned to the globalThis ([#1599](https://github.com/lynx-family/lynx-stack/pull/1599)) - -- Updated dependencies [[`c1f8715`](https://github.com/lynx-family/lynx-stack/commit/c1f8715a81b2e69ff46fc363013626db4468c209)]: - - @lynx-js/web-worker-rpc@0.16.0 - -## 0.15.7 - -### Patch Changes - -- fix: globalThis is never accessible in MTS ([#1531](https://github.com/lynx-family/lynx-stack/pull/1531)) - -- Updated dependencies []: - - @lynx-js/web-worker-rpc@0.15.7 - -## 0.15.6 - -### Patch Changes - -- fix: systeminfo in mts function ([#1537](https://github.com/lynx-family/lynx-stack/pull/1537)) - -- feat: add MTS API: \_\_UpdateComponentInfo ([#1485](https://github.com/lynx-family/lynx-stack/pull/1485)) - -- fix: `__ElementFromBinary` needs to correctly apply the dataset in elementTemplate to the Element ([#1487](https://github.com/lynx-family/lynx-stack/pull/1487)) - -- fix: all attributes except `id` and `type` under ElementTemplateData are optional. ([#1483](https://github.com/lynx-family/lynx-stack/pull/1483)) - -- feat: add MTS API \_\_GetAttributeByName ([#1486](https://github.com/lynx-family/lynx-stack/pull/1486)) - -- Updated dependencies []: - - @lynx-js/web-worker-rpc@0.15.6 - -## 0.15.5 - -### Patch Changes - -- fix: load main-thread chunk in ESM format ([#1437](https://github.com/lynx-family/lynx-stack/pull/1437)) - - See [nodejs/node#59362](https://github.com/nodejs/node/issues/59362) for more details. - -- feat: support path() for `createQuerySelector` ([#1456](https://github.com/lynx-family/lynx-stack/pull/1456)) - - - Added `getPathInfo` API to `NativeApp` and its cross-thread handler for retrieving the path from a DOM node to the root. - - Implemented endpoint and handler registration in both background and UI threads. - - Implemented `nativeApp.getPathInfo()` - -- Updated dependencies []: - - @lynx-js/web-worker-rpc@0.15.5 - -## 0.15.4 - -### Patch Changes - -- feat: support `__ElementFromBinary` ([#1391](https://github.com/lynx-family/lynx-stack/pull/1391)) - -- Updated dependencies []: - - @lynx-js/web-worker-rpc@0.15.4 - -## 0.15.3 - -### Patch Changes - -- fix: improve compatibility with legacy template ([#1337](https://github.com/lynx-family/lynx-stack/pull/1337)) - - avoid "object Object" error for old version rspeedy outputs - -- Updated dependencies []: - - @lynx-js/web-worker-rpc@0.15.3 - -## 0.15.2 - -### Patch Changes - -- feat: move SSR hydrate essential info to the ssr attribute ([#1292](https://github.com/lynx-family/lynx-stack/pull/1292)) - - We found that in browser there is no simple tool to decode a base64 string - - Therefore we move the data to `ssr` attribute - - Also fix some ssr issues - -- feat: support \_\_MarkTemplateElement, \_\_MarkPartElement and \_\_GetTemplateParts for all-on-ui ([#1275](https://github.com/lynx-family/lynx-stack/pull/1275)) - -- Updated dependencies []: - - @lynx-js/web-worker-rpc@0.15.2 - -## 0.15.1 - -### Patch Changes - -- Updated dependencies []: - - @lynx-js/web-worker-rpc@0.15.1 - -## 0.15.0 - -### Minor Changes - -- refactor: move exposure system to web-core ([#1254](https://github.com/lynx-family/lynx-stack/pull/1254)) - - **THIS IS A BREAKING CHANGE** - - **You'll need to upgrade your @lynx-js/web-elements to >= 0.8.0** - - For SSR and better performance, we moved the lynx's exposure system from web-element to web-core. - - Before this commit, we create Intersection observers by creating HTMLElements. - - After this commit, we will create such Intersection observers after dom stabled. - - Also, the setInterval for exposure has been removed, now we use an on time lazy timer for such features. - -### Patch Changes - -- Updated dependencies []: - - @lynx-js/web-worker-rpc@0.15.0 - -## 0.14.2 - -### Patch Changes - -- feat: merge multiple markTiming RPC communication events together and send them together, which can effectively reduce the number of RPC communications. ([#1178](https://github.com/lynx-family/lynx-stack/pull/1178)) - -- chore: extract shared logic from web-core and web-core-server's loadTemplate into a unified generateTemplate function ([#1211](https://github.com/lynx-family/lynx-stack/pull/1211)) - -- Updated dependencies []: - - @lynx-js/web-worker-rpc@0.14.2 - -## 0.14.1 - -### Patch Changes - -- feat: support BTS API `lynx.reportError` && `__SetSourceMapRelease`, now you can use it and handle it in lynx-view error event. ([#1059](https://github.com/lynx-family/lynx-stack/pull/1059)) - -- fix: in lynx-view all-on-ui mode, the input event of input and textarea is triggered twice, and the first e.detail is a string, which does not conform to the expected data format. ([#1179](https://github.com/lynx-family/lynx-stack/pull/1179)) - -- fix: under the all-on-ui strategy, reload() will add two page elements. ([#1147](https://github.com/lynx-family/lynx-stack/pull/1147)) - -- Updated dependencies []: - - @lynx-js/web-worker-rpc@0.14.1 - -## 0.14.0 - -### Patch Changes - -- feat: add `_SetSourceMapRelease(errInfo)` MTS API. ([#1118](https://github.com/lynx-family/lynx-stack/pull/1118)) - - You can get `errInfo.release` through `e.detail.release` in the error event callback of lynx-view. - - The `_SetSourceMapRelease` function is not complete yet, because it is currently limited by the Web platform and some functions and some props such as `err.stack` do not need to be supported for the time being. - -- feat: add `_I18nResourceTranslation` api in mts && `init-i18n-resources` attr, `i18nResourceMissed` event of lynx-view. ([#1065](https://github.com/lynx-family/lynx-stack/pull/1065)) - - `init-i18n-resource` is the complete set of i18nResources that need to be maintained on the container side. Note: You need to pass this value when lynx-view is initialized. - - You can use `_I18nResourceTranslation` in MTS to get the corresponding i18nResource from `init-i18n-resources`. If it is undefined, the `i18nResourceMissed` event will be dispatched. - - ```js - // ui thread - lynxView.initI18nResources = [ - { - options: { - locale: 'en', - channel: '1', - fallback_url: '', - }, - resource: { - hello: 'hello', - lynx: 'lynx web platform1', - }, - }, - ]; - lynxView.addEventListener('i18nResourceMissed', (e) => { - console.log(e); - }); - - // mts - _I18nResourceTranslation({ - locale: 'en', - channel: '1', - fallback_url: '', - }); - ``` - -- feat: supports `lynx.getI18nResource()` and `onI18nResourceReady` event in bts. ([#1088](https://github.com/lynx-family/lynx-stack/pull/1088)) - - - `lynx.getI18nResource()` can be used to get i18nResource in bts, it has two data sources: - - the result of `_I18nResourceTranslation()` - - lynx-view `updateI18nResources(data: InitI18nResources, options: I18nResourceTranslationOptions)`, it will be matched to the correct i8nResource as a result of `lynx.getI18nResource()` - - `onI18nResourceReady` event can be used to listen `_I18nResourceTranslation` and lynx-view `updateI18nResources` execution. - -- refactor: make the opcode be a plain array ([#1051](https://github.com/lynx-family/lynx-stack/pull/1051)) - - #1042 - -- feat: add `updateI18nResources` method of lynx-view. ([#1085](https://github.com/lynx-family/lynx-stack/pull/1085)) - - Now you can use `updateI18nResources` to update i18nResources, and then use \_I18nResourceTranslation() to get the updated result. - -- Updated dependencies []: - - @lynx-js/web-worker-rpc@0.14.0 - -## 0.13.5 - -### Patch Changes - -- refactor: move some internal status to dom's attribute ([#945](https://github.com/lynx-family/lynx-stack/pull/945)) - - It's essential for SSR - -- fix: target.id is undefined ([#1016](https://github.com/lynx-family/lynx-stack/pull/1016)) - -- feat: add new pageConfig configuration: enableJSDataProcessor ([#886](https://github.com/lynx-family/lynx-stack/pull/886)) - -- refactor: move component config info to attribute ([#984](https://github.com/lynx-family/lynx-stack/pull/984)) - -- refactor: save dataset on an attribute ([#981](https://github.com/lynx-family/lynx-stack/pull/981)) - - On lynx, the `data-*` attributes have different behaviors than the HTMLElement has. - - The dataset will be treated as properties, the key will not be applied the camel-case <-> hyphenate name transformation. - - Before this commit we use it as a runtime data, but after this commit we will use encodeURI(JSON.stringify(dataset)) to encode it as a string. - -- refactor: create elements of `elementToRuntimeInfoMap` on demand ([#986](https://github.com/lynx-family/lynx-stack/pull/986)) - -- refactor: implement mts apis in closure pattern ([#1004](https://github.com/lynx-family/lynx-stack/pull/1004)) - -- Updated dependencies []: - - @lynx-js/web-worker-rpc@0.13.5 - -## 0.13.4 - -### Patch Changes - -- feat: lynx-view supports `updateGlobalProps` method, which can be used to update lynx.\_\_globalProps ([#918](https://github.com/lynx-family/lynx-stack/pull/918)) - -- feat: supports `lynx.getElementById()` && `animate()`. ([#912](https://github.com/lynx-family/lynx-stack/pull/912)) - - After this commit, you can use `lynx.getElementById()` to get the element by id, and use `element.animate()` to animate the element. - -- Updated dependencies []: - - @lynx-js/web-worker-rpc@0.13.4 - -## 0.13.3 - -### Patch Changes - -- refactor: code clean ([#897](https://github.com/lynx-family/lynx-stack/pull/897)) - - rename many internal apis to make logic be clear: - - multi-thread: startMainWorker -> prepareMainThreadAPIs -> startMainThread -> createMainThreadContext(new MainThreadRuntime) - all-on-ui: prepareMainThreadAPIs -> startMainThread -> createMainThreadContext(new MainThreadRuntime) - -- Updated dependencies []: - - @lynx-js/web-worker-rpc@0.13.3 - -## 0.13.2 - -### Patch Changes - -- fix: corrupt mainthread module cache ([#806](https://github.com/lynx-family/lynx-stack/pull/806)) - -- Updated dependencies []: - - @lynx-js/web-worker-rpc@0.13.2 - -## 0.13.1 - -### Patch Changes - -- feat: support touch events for MTS ([#641](https://github.com/lynx-family/lynx-stack/pull/641)) - - now we support - - - main-thread:bindtouchstart - - main-thread:bindtouchend - - main-thread:bindtouchmove - - main-thread:bindtouchcancel - -- Updated dependencies []: - - @lynx-js/web-worker-rpc@0.13.1 - -## 0.13.0 - -### Patch Changes - -- refactor: isolate SystemInfo ([#628](https://github.com/lynx-family/lynx-stack/pull/628)) - - Never assign `SystemInfo` on worker's self object. - -- refactor: move mainthread impl into mainthread-api packages ([#622](https://github.com/lynx-family/lynx-stack/pull/622)) - -- fix(web): css selector not work for selectors with combinator and pseudo-class on WEB ([#608](https://github.com/lynx-family/lynx-stack/pull/608)) - - like `.parent > :not([hidden]) ~ :not([hidden])` - - you will need to upgrade your `react-rsbuild-plugin` to fix this issue - -- Updated dependencies []: - - @lynx-js/web-worker-rpc@0.13.0 - -## 0.12.0 - -### Patch Changes - -- feat: fully support MTS ([#569](https://github.com/lynx-family/lynx-stack/pull/569)) - - Now use support the following usage - - - mainthread event - - mainthread ref - - runOnMainThread/runOnBackground - - ref.current.xx - -- Updated dependencies []: - - @lynx-js/web-worker-rpc@0.12.0 - -## 0.11.0 - -### Patch Changes - -- feat: support mts event handler (1/n) ([#495](https://github.com/lynx-family/lynx-stack/pull/495)) - - now the main-thread:bind handler could be invoked. The params of the handler will be implemented later. - -- feat: allow multi lynx-view to share bts worker ([#520](https://github.com/lynx-family/lynx-stack/pull/520)) - - Now we allow users to enable so-called "shared-context" feature on the Web Platform. - - Similar to the same feature for Lynx iOS/Android, this feature let multi lynx cards to share one js context. - - The `lynx.getSharedData` and `lynx.setSharedData` are also supported in this commit. - - To enable this feature, set property `lynxGroupId` or attribute `lynx-group-id` before a lynx-view starts rendering. Those card with same context id will share one web worker for the bts scripts. - -- Updated dependencies []: - - @lynx-js/web-worker-rpc@0.11.0 - -## 0.10.1 - -### Patch Changes - -- feat: onNapiModulesCall function add new param: `dispatchNapiModules`, napiModulesMap val add new param: `handleDispatch`. ([#414](https://github.com/lynx-family/lynx-stack/pull/414)) - - Now you can use them to actively communicate to napiModules (background thread) in onNapiModulesCall (ui thread). - -- Updated dependencies []: - - @lynx-js/web-worker-rpc@0.10.1 - -## 0.10.0 - -### Minor Changes - -- feat: rewrite the main thread Element PAPIs ([#343](https://github.com/lynx-family/lynx-stack/pull/343)) - - In this commit we've rewritten the main thread apis. - - The most highlighted change is that - - - Before this commit we send events directly to bts - - After this change, we send events to mts then send them to bts with some data combined. - -### Patch Changes - -- feat: The onNapiModulesCall function of lynx-view provides the fourth parameter: `lynxView`, which is the actual lynx-view DOM. ([#350](https://github.com/lynx-family/lynx-stack/pull/350)) - -- fix: publicComponentEvent args order ([#401](https://github.com/lynx-family/lynx-stack/pull/401)) - -- Updated dependencies [[`a521759`](https://github.com/lynx-family/lynx-stack/commit/a5217592f5aebea4b17860e729d523ecabb5f691)]: - - @lynx-js/web-worker-rpc@0.10.0 - -## 0.9.1 - -### Patch Changes - -- Updated dependencies []: - - @lynx-js/web-worker-rpc@0.9.1 - -## 0.9.0 - -### Minor Changes - -- refractor: remove entryId concept ([#217](https://github.com/lynx-family/lynx-stack/pull/217)) - - After the PR #198 - All contents are isolated by a shadowroot. - Therefore we don't need to add the entryId selector to avoid the lynx-view's style taking effect on the whole page. - -### Patch Changes - -- feat: `nativeModulesUrl` of lynx-view is changed to `nativeModulesMap`, and the usage is completely aligned with `napiModulesMap`. ([#220](https://github.com/lynx-family/lynx-stack/pull/220)) - - "warning: This is a breaking change." - - `nativeModulesMap` will be a map: key is module-name, value should be a esm url which export default a - function with two parameters(you never need to use `this`): - - - `NativeModules`: oriented `NativeModules`, which you can use to call - other Native-Modules. - - - `NativeModulesCall`: trigger `onNativeModulesCall`, same as the deprecated `this.nativeModulesCall`. - - example: - - ```js - const nativeModulesMap = { - CustomModule: URL.createObjectURL( - new Blob( - [ - `export default function(NativeModules, NativeModulesCall) { - return { - async getColor(data, callback) { - const color = await NativeModulesCall('getColor', data); - callback(color); - }, - } - };`, - ], - { type: 'text/javascript' }, - ), - ), - }; - lynxView.nativeModulesMap = nativeModulesMap; - ``` - - In addition, we will use Promise.all to load `nativeModules`, which will optimize performance in the case of multiple modules. - -- refactor: clean the decodeOperations implementation ([#261](https://github.com/lynx-family/lynx-stack/pull/261)) - -- refactor: remove customelement defined detecting logic ([#247](https://github.com/lynx-family/lynx-stack/pull/247)) - - Before this commit, for those element with tag without `-`, we always try to detect if the `x-${tagName}` is defined. - - After this commit, we pre-define a map(could be override by the `overrideLynxTagToHTMLTagMap`) to make that transformation for tag name. - - This change is a path to SSR and the MTS support. - -- Updated dependencies [[`53230f0`](https://github.com/lynx-family/lynx-stack/commit/53230f012216f3a627853e11d544e4be175c5b9b)]: - - @lynx-js/web-worker-rpc@0.9.0 - -## 0.8.0 - -### Minor Changes - -- refactor: remove web-elements/lazy and loadNewTag ([#123](https://github.com/lynx-family/lynx-stack/pull/123)) - - - remove @lynx-js/web-elements/lazy - - remove loadElement - - remove loadNewTag callback - - **This is a breaking change** - - Now we removed the default lazy loading preinstalled in web-core - - Please add the following statement in your web project - - ``` - import "@lynx-js/web-elements/all"; - ``` - -### Patch Changes - -- feat: `createRpcEndpoint` adds a new parameter: `hasReturnTransfer`. ([#194](https://github.com/lynx-family/lynx-stack/pull/194)) - - When `isSync`: false, `hasReturn`: true, you can add `transfer` to the callback postMessage created. - - At this time, the return value structure of register-handler is changed: `{ data: unknown; transfer: Transferable[]; } | Promise<{ data: unknown; transfer: Transferable[];}>`. - -- feat: add two prop of lynx-view about `napiLoader`: ([#173](https://github.com/lynx-family/lynx-stack/pull/173)) - - - `napiModulesMap`: [optional] the napiModule which is called in lynx-core. key is module-name, value is esm url. - - - `onNapiModulesCall`: [optional] the NapiModule value handler. - - **Warning:** This is the internal implementation of `@lynx-js/lynx-core`. In most cases, this API is not required for projects. - - 1. The `napiModulesMap` value should be a esm url which export default a function with two parameters: - - - `NapiModules`: oriented `napiModulesMap`, which you can use to call other Napi-Modules - - - `NapiModulesCall`: trigger `onNapiModulesCall` - - example: - - ```js - const color_environment = URL.createObjectURL( - new Blob( - [ - `export default function(NapiModules, NapiModulesCall) { - return { - getColor() { - NapiModules.color_methods.getColor({ color: 'green' }, color => { - console.log(color); - }); - }, - ColorEngine: class ColorEngine { - getColor(name) { - NapiModules.color_methods.getColor({ color: 'green' }, color => { - console.log(color); - }); - } - }, - }; - };`, - ], - { type: 'text/javascript' }, - ), - ); - - const color_methods = URL.createObjectURL( - new Blob( - [ - `export default function(NapiModules, NapiModulesCall) { - return { - async getColor(data, callback) { - const color = await NapiModulesCall('getColor', data); - callback(color); - }, - }; - };`, - ], - { type: 'text/javascript' }, - ), - ); - - lynxView.napiModuleMap = { - color_environment: color_environment, - color_methods: color_methods, - }; - ``` - - 2. The `onNapiModulesCall` function has three parameters: - - - `name`: the first parameter of `NapiModulesCall`, the function name - - `data`: the second parameter of `NapiModulesCall`, data - - `moduleName`: the module-name of the called napi-module - - ```js - lynxView.onNapiModulesCall = (name, data, moduleName) => { - if (name === 'getColor' && moduleName === 'color_methods') { - return data.color; - } - }; - ``` - -- Updated dependencies [[`ec4e1ce`](https://github.com/lynx-family/lynx-stack/commit/ec4e1ce0d7612d6c0701792a46c78cd52130bad4)]: - - @lynx-js/web-worker-rpc@0.8.0 - -## 0.7.1 - -### Patch Changes - -- Support NPM provenance. ([#30](https://github.com/lynx-family/lynx-stack/pull/30)) - -- fix: some valus should be updateable by global scope ([#130](https://github.com/lynx-family/lynx-stack/pull/130)) - - Now we add an allowlist to allow some identifiers could be updated by globalThis. - - For those values in the allowlist: - - ``` - globalThis.foo = 'xx'; - console.log(foo); //'xx' - ``` - -- refractor: improve some internal logic for element creating in MTS ([#71](https://github.com/lynx-family/lynx-stack/pull/71)) - -- Updated dependencies [[`c617453`](https://github.com/lynx-family/lynx-stack/commit/c617453aea967aba702967deb2916b5c883f03bb)]: - - @lynx-js/web-worker-rpc@0.7.1 - -## 0.7.0 - -### Minor Changes - -- 1abf8f0: feat(web): - - **This is a breaking change** - - 1. A new param for `lynx-view`: `nativeModulesUrl`, which allows you to pass an esm url to add a new module to `NativeModules`. And we bind the `nativeModulesCall` method to each function on the module, run `this.nativeModulesCall()` to trigger onNativeModulesCall. - - ```typescript - export type NativeModuleHandlerContext = { - nativeModulesCall: (name: string, data: Cloneable) => Promise; - }; - ``` - - a simple case: - - ```js - lynxView.nativeModules = URL.createObjectURL( - new Blob( - [ - `export default { - myNativeModules: { - async getColor(data, callback) { - // trigger onNativeModulesCall and get the result - const color = await this.nativeModulesCall('getColor', data); - // return the result to caller - callback(color); - }, - } - };`, - ], - { type: 'text/javascript' }, - ), - ); - ``` - - 2. `onNativeModulesCall` is no longer the value handler of `NativeModules.bridge.call`, it will be the value handler of all `NativeModules` modules. - - **Warning: This is a breaking change.** - - Before this commit, you listen to `NativeModules.bridge.call('getColor')` like this: - - ```js - lynxView.onNativeModulesCall = (name, data, callback) => { - if (name === 'getColor') { - callback(data.color); - } - }; - ``` - - Now you should use it like this: - - ```js - lynxView.onNativeModulesCall = (name, data, moduleName) => { - if (name === 'getColor' && moduleName === 'bridge') { - return data.color; - } - }; - ``` - - You need to use `moduleName` to determine the NativeModules-module. And you don’t need to run callback, just return the result! - -### Patch Changes - -- @lynx-js/web-worker-rpc@0.7.0 - -## 0.6.2 - -### Patch Changes - -- 0412db0: fix: The runtime wrapper parameter name is changed from `runtime` to `lynx_runtime`. - - This is because some project logic may use `runtime`, which may cause duplication of declarations. - -- 085b99e: feat: add `nativeApp.createJSObjectDestructionObserver`, it is a prerequisite for implementing mts event. - - @lynx-js/web-worker-rpc@0.6.2 - -## 0.6.1 - -### Patch Changes - -- 62b7841: feat: add lynx.requireModule in main-thread && \_\_LoadLepusChunk API. - - now the `lynx.requireModule` is available in mts. - - - @lynx-js/web-worker-rpc@0.6.1 - -## 0.6.0 - -### Minor Changes - -- e406d69: refractor: update output json format - - **This is a breaking change** - - Before this change the style info is dump in Javascript code. - - After this change the style info will be pure JSON data. - - Now we're using the css-serializer tool's output only. If you're using plugins for it, now they're enabled. - -### Patch Changes - -- @lynx-js/web-worker-rpc@0.6.0 - -## 0.5.1 - -### Patch Changes - -- c49b1fb: feat: updateData api needs to have the correct format, now you can pass a callback. -- b5ef20e: feat: updateData should also call `updatePage` in main-thread. - - @lynx-js/web-worker-rpc@0.5.1 - -## 0.5.0 - -### Minor Changes - -- 7b84edf: feat: introduce new output chunk format - - **This is a breaking change** - - After this commit, we new introduce a new output format for web platform. - - This new output file is a JSON file, includes all essential info. - - Now we'll add the chunk global scope wrapper on runtime, this will help us to provide a better backward compatibility. - - Also we have a intergrated output file cache for one session. - - Now your `output.filename` will work. - - The split-chunk feature has been temporary removed until the rspeedy team supports this feature for us. - -### Patch Changes - -- 3050faf: refractor: housekeeping -- Updated dependencies [04607bd] -- Updated dependencies [e0f0793] - - @lynx-js/web-worker-rpc@0.5.0 - -## 0.4.2 - -### Patch Changes - -- 168b4fa: feat: rename CloneableObject to Cloneable, Now its type refers to a structure that can be cloned; CloneableObject type is added, which only refers to object types that can be cloned. - -## 0.4.1 - -## 0.4.0 - -## 0.3.1 - -## 0.3.0 - -### Minor Changes - -- 267c935: feat: make cardType could be configurable - -### Patch Changes - -- 6e873bc: fix: incorrect parent component id value on publishComponentEvent - -## 0.2.0 - -## 0.1.0 - -### Minor Changes - -- 2973ba5: chore: add common constants diff --git a/packages/web-platform/web-constants/LICENSE.txt b/packages/web-platform/web-constants/LICENSE.txt deleted file mode 100644 index ce66b4c3a7..0000000000 --- a/packages/web-platform/web-constants/LICENSE.txt +++ /dev/null @@ -1,202 +0,0 @@ - - Apache License - Version 2.0, January 2004 - http://www.apache.org/licenses/ - - TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION - - 1. Definitions. - - "License" shall mean the terms and conditions for use, reproduction, - and distribution as defined by Sections 1 through 9 of this document. - - "Licensor" shall mean the copyright owner or entity authorized by - the copyright owner that is granting the License. - - "Legal Entity" shall mean the union of the acting entity and all - other entities that control, are controlled by, or are under common - control with that entity. For the purposes of this definition, - "control" means (i) the power, direct or indirect, to cause the - direction or management of such entity, whether by contract or - otherwise, or (ii) ownership of fifty percent (50%) or more of the - outstanding shares, or (iii) beneficial ownership of such entity. - - "You" (or "Your") shall mean an individual or Legal Entity - exercising permissions granted by this License. - - "Source" form shall mean the preferred form for making modifications, - including but not limited to software source code, documentation - source, and configuration files. - - "Object" form shall mean any form resulting from mechanical - transformation or translation of a Source form, including but - not limited to compiled object code, generated documentation, - and conversions to other media types. - - "Work" shall mean the work of authorship, whether in Source or - Object form, made available under the License, as indicated by a - copyright notice that is included in or attached to the work - (an example is provided in the Appendix below). - - "Derivative Works" shall mean any work, whether in Source or Object - form, that is based on (or derived from) the Work and for which the - editorial revisions, annotations, elaborations, or other modifications - represent, as a whole, an original work of authorship. For the purposes - of this License, Derivative Works shall not include works that remain - separable from, or merely link (or bind by name) to the interfaces of, - the Work and Derivative Works thereof. - - "Contribution" shall mean any work of authorship, including - the original version of the Work and any modifications or additions - to that Work or Derivative Works thereof, that is intentionally - submitted to Licensor for inclusion in the Work by the copyright owner - or by an individual or Legal Entity authorized to submit on behalf of - the copyright owner. For the purposes of this definition, "submitted" - means any form of electronic, verbal, or written communication sent - to the Licensor or its representatives, including but not limited to - communication on electronic mailing lists, source code control systems, - and issue tracking systems that are managed by, or on behalf of, the - Licensor for the purpose of discussing and improving the Work, but - excluding communication that is conspicuously marked or otherwise - designated in writing by the copyright owner as "Not a Contribution." - - "Contributor" shall mean Licensor and any individual or Legal Entity - on behalf of whom a Contribution has been received by Licensor and - subsequently incorporated within the Work. - - 2. Grant of Copyright License. Subject to the terms and conditions of - this License, each Contributor hereby grants to You a perpetual, - worldwide, non-exclusive, no-charge, royalty-free, irrevocable - copyright license to reproduce, prepare Derivative Works of, - publicly display, publicly perform, sublicense, and distribute the - Work and such Derivative Works in Source or Object form. - - 3. Grant of Patent License. Subject to the terms and conditions of - this License, each Contributor hereby grants to You a perpetual, - worldwide, non-exclusive, no-charge, royalty-free, irrevocable - (except as stated in this section) patent license to make, have made, - use, offer to sell, sell, import, and otherwise transfer the Work, - where such license applies only to those patent claims licensable - by such Contributor that are necessarily infringed by their - Contribution(s) alone or by combination of their Contribution(s) - with the Work to which such Contribution(s) was submitted. If You - institute patent litigation against any entity (including a - cross-claim or counterclaim in a lawsuit) alleging that the Work - or a Contribution incorporated within the Work constitutes direct - or contributory patent infringement, then any patent licenses - granted to You under this License for that Work shall terminate - as of the date such litigation is filed. - - 4. Redistribution. You may reproduce and distribute copies of the - Work or Derivative Works thereof in any medium, with or without - modifications, and in Source or Object form, provided that You - meet the following conditions: - - (a) You must give any other recipients of the Work or - Derivative Works a copy of this License; and - - (b) You must cause any modified files to carry prominent notices - stating that You changed the files; and - - (c) You must retain, in the Source form of any Derivative Works - that You distribute, all copyright, patent, trademark, and - attribution notices from the Source form of the Work, - excluding those notices that do not pertain to any part of - the Derivative Works; and - - (d) If the Work includes a "NOTICE" text file as part of its - distribution, then any Derivative Works that You distribute must - include a readable copy of the attribution notices contained - within such NOTICE file, excluding those notices that do not - pertain to any part of the Derivative Works, in at least one - of the following places: within a NOTICE text file distributed - as part of the Derivative Works; within the Source form or - documentation, if provided along with the Derivative Works; or, - within a display generated by the Derivative Works, if and - wherever such third-party notices normally appear. The contents - of the NOTICE file are for informational purposes only and - do not modify the License. You may add Your own attribution - notices within Derivative Works that You distribute, alongside - or as an addendum to the NOTICE text from the Work, provided - that such additional attribution notices cannot be construed - as modifying the License. - - You may add Your own copyright statement to Your modifications and - may provide additional or different license terms and conditions - for use, reproduction, or distribution of Your modifications, or - for any such Derivative Works as a whole, provided Your use, - reproduction, and distribution of the Work otherwise complies with - the conditions stated in this License. - - 5. Submission of Contributions. Unless You explicitly state otherwise, - any Contribution intentionally submitted for inclusion in the Work - by You to the Licensor shall be under the terms and conditions of - this License, without any additional terms or conditions. - Notwithstanding the above, nothing herein shall supersede or modify - the terms of any separate license agreement you may have executed - with Licensor regarding such Contributions. - - 6. Trademarks. This License does not grant permission to use the trade - names, trademarks, service marks, or product names of the Licensor, - except as required for reasonable and customary use in describing the - origin of the Work and reproducing the content of the NOTICE file. - - 7. Disclaimer of Warranty. Unless required by applicable law or - agreed to in writing, Licensor provides the Work (and each - Contributor provides its Contributions) on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or - implied, including, without limitation, any warranties or conditions - of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A - PARTICULAR PURPOSE. You are solely responsible for determining the - appropriateness of using or redistributing the Work and assume any - risks associated with Your exercise of permissions under this License. - - 8. Limitation of Liability. In no event and under no legal theory, - whether in tort (including negligence), contract, or otherwise, - unless required by applicable law (such as deliberate and grossly - negligent acts) or agreed to in writing, shall any Contributor be - liable to You for damages, including any direct, indirect, special, - incidental, or consequential damages of any character arising as a - result of this License or out of the use or inability to use the - Work (including but not limited to damages for loss of goodwill, - work stoppage, computer failure or malfunction, or any and all - other commercial damages or losses), even if such Contributor - has been advised of the possibility of such damages. - - 9. Accepting Warranty or Additional Liability. While redistributing - the Work or Derivative Works thereof, You may choose to offer, - and charge a fee for, acceptance of support, warranty, indemnity, - or other liability obligations and/or rights consistent with this - License. However, in accepting such obligations, You may act only - on Your own behalf and on Your sole responsibility, not on behalf - of any other Contributor, and only if You agree to indemnify, - defend, and hold each Contributor harmless for any liability - incurred by, or claims asserted against, such Contributor by reason - of your accepting any such warranty or additional liability. - - END OF TERMS AND CONDITIONS - - APPENDIX: How to apply the Apache License to your work. - - To apply the Apache License to your work, attach the following - boilerplate notice, with the fields enclosed by brackets "[]" - replaced with your own identifying information. (Don't include - the brackets!) The text should be enclosed in the appropriate - comment syntax for the file format. We also recommend that a - file or class name and description of purpose be included on the - same "printed page" as the copyright notice for easier - identification within third-party archives. - - Copyright 2023-2024 The Lynx Authors. - - Licensed under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. - You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software - distributed under the License is distributed on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - See the License for the specific language governing permissions and - limitations under the License. diff --git a/packages/web-platform/web-constants/Notice.txt b/packages/web-platform/web-constants/Notice.txt deleted file mode 100644 index 3ff8881bfd..0000000000 --- a/packages/web-platform/web-constants/Notice.txt +++ /dev/null @@ -1 +0,0 @@ -Copyright 2023-2024 The Lynx Authors. All rights reserved. \ No newline at end of file diff --git a/packages/web-platform/web-constants/README.md b/packages/web-platform/web-constants/README.md deleted file mode 100644 index 7d2b3955b0..0000000000 --- a/packages/web-platform/web-constants/README.md +++ /dev/null @@ -1,9 +0,0 @@ -# @lynx-js/web-constants - -A common dependency library that defines constants for the Lynx3 Web Platform. - -## Usage - -```javascript -import { cardIdAttribute, lynxViewRootDomId }'@lynx-js/web-constants'; -``` diff --git a/packages/web-platform/web-constants/package.json b/packages/web-platform/web-constants/package.json deleted file mode 100644 index 00094c26fe..0000000000 --- a/packages/web-platform/web-constants/package.json +++ /dev/null @@ -1,31 +0,0 @@ -{ - "name": "@lynx-js/web-constants", - "version": "0.19.9", - "private": false, - "description": "", - "keywords": [], - "repository": { - "type": "git", - "url": "https://github.com/lynx-family/lynx-stack.git", - "directory": "packages/web-platform/web-constants" - }, - "license": "Apache-2.0", - "type": "module", - "main": "dist/index.js", - "typings": "dist/index.d.ts", - "files": [ - "dist", - "!dist/**/*.js.map", - "LICENSE.txt", - "Notice.txt", - "CHANGELOG.md", - "README.md", - "**/*.css" - ], - "dependencies": { - "@lynx-js/web-worker-rpc": "workspace:*" - }, - "devDependencies": { - "@lynx-js/offscreen-document": "workspace:*" - } -} diff --git a/packages/web-platform/web-constants/src/constants.ts b/packages/web-platform/web-constants/src/constants.ts deleted file mode 100644 index 05e1fde7b9..0000000000 --- a/packages/web-platform/web-constants/src/constants.ts +++ /dev/null @@ -1,48 +0,0 @@ -// Copyright 2023 The Lynx Authors. All rights reserved. -// Licensed under the Apache License Version 2.0 that can be found in the -// LICENSE file in the root directory of this source tree. - -export const lynxUniqueIdAttribute = 'l-uid' as const; - -export const cssIdAttribute = 'l-css-id' as const; - -export const componentIdAttribute = 'l-comp-id' as const; - -export const parentComponentUniqueIdAttribute = 'l-p-comp-uid' as const; - -export const lynxEntryNameAttribute = 'l-e-name' as const; - -export const lynxTagAttribute = 'lynx-tag' as const; - -export const lynxDatasetAttribute = 'l-dset' as const; - -export const lynxComponentConfigAttribute = 'l-comp-cfg' as const; - -export const lynxDisposedAttribute = 'l-disposed' as const; - -export const lynxElementTemplateMarkerAttribute = 'l-template' as const; - -export const lynxPartIdAttribute = 'l-part' as const; - -export const lynxDefaultDisplayLinearAttribute = - 'lynx-default-display-linear' as const; - -export const lynxDefaultOverflowVisibleAttribute = - 'lynx-default-overflow-visible' as const; - -export const __lynx_timing_flag = '__lynx_timing_flag' as const; - -export const systemInfo = { - platform: 'web', - lynxSdkVersion: '3.0', -} as Record; - -export const inShadowRootStyles: string[] = [ - ` [lynx-default-display-linear="false"] * { - --lynx-display: flex; - --lynx-display-toggle: var(--lynx-display-flex); - }`, - `[lynx-default-overflow-visible="true"] x-view{ - overflow: visible; - }`, -]; diff --git a/packages/web-platform/web-constants/src/endpoints.ts b/packages/web-platform/web-constants/src/endpoints.ts deleted file mode 100644 index 313e53c66c..0000000000 --- a/packages/web-platform/web-constants/src/endpoints.ts +++ /dev/null @@ -1,267 +0,0 @@ -// Copyright 2023 The Lynx Authors. All rights reserved. -// Licensed under the Apache License Version 2.0 that can be found in the -// LICENSE file in the root directory of this source tree. - -import { createRpcEndpoint } from '@lynx-js/web-worker-rpc'; -import type { - ExposureWorkerEvent, - LynxCrossThreadEvent, -} from './types/EventType.js'; -import type { Cloneable, CloneableObject } from './types/Cloneable.js'; -import type { StartMainThreadContextConfig } from './types/MainThreadStartConfigs.js'; -import type { IdentifierType, InvokeCallbackRes } from './types/NativeApp.js'; -import type { ElementAnimationOptions } from './types/Element.js'; -import type { - BackMainThreadContextConfig, - LynxTemplate, - MarkTiming, -} from './types/index.js'; -import type { UpdateDataOptions } from './types/UpdateDataOptions.js'; - -export const postExposureEndpoint = createRpcEndpoint< - [{ exposures: ExposureWorkerEvent[]; disExposures: ExposureWorkerEvent[] }], - void ->( - '__postExposure', - false, - false, -); - -export const publicComponentEventEndpoint = createRpcEndpoint< - [componentId: string, hname: string, LynxCrossThreadEvent], - void ->('publicComponentEvent', false, false); - -export const publishEventEndpoint = createRpcEndpoint< - [string, LynxCrossThreadEvent], - void ->('publishEvent', false, false); - -export const postOffscreenEventEndpoint = createRpcEndpoint< - [ - eventType: string, - targetUniqueId: number, - bubbles: boolean, - Parameters[0], - ], - void ->('postOffscreenEventEndpoint', false, false); - -export const switchExposureServiceEndpoint = createRpcEndpoint< - [boolean, boolean], - void ->( - 'switchExposureServiceEndpoint', - false, - false, -); - -export const mainThreadStartEndpoint = createRpcEndpoint< - [StartMainThreadContextConfig], - void ->('mainThreadStart', false, false); - -export const updateDataEndpoint = createRpcEndpoint< - [Cloneable, UpdateDataOptions | undefined], - void ->('updateData', false, true); - -export const sendGlobalEventEndpoint = createRpcEndpoint< - [string, Cloneable[] | undefined], - void ->('sendGlobalEventEndpoint', false, false); - -export const disposeEndpoint = createRpcEndpoint< - [], - void ->('dispose', false, true); - -export const BackgroundThreadStartEndpoint = createRpcEndpoint<[ - BackMainThreadContextConfig, -], void>('start', false, true); - -/** - * Error message, info - */ -export const reportErrorEndpoint = createRpcEndpoint< - [Error, unknown, string], - void ->('reportError', false, false); - -export const flushElementTreeEndpoint = createRpcEndpoint< - [ - operations: (string | number)[], - ], - void ->('flushElementTree', false, true); - -export const callLepusMethodEndpoint = createRpcEndpoint< - [name: string, data: unknown], - void ->('callLepusMethod', false, true); - -export const multiThreadExposureChangedEndpoint = createRpcEndpoint< - [string[]], - void ->('multiThreadExposureChangedEndpoint', false, false); - -export const invokeUIMethodEndpoint = createRpcEndpoint< - [ - type: IdentifierType, - identifier: string, - component_id: string, - method: string, - params: object, - root_unique_id: number | undefined, - ], - InvokeCallbackRes ->('__invokeUIMethod', false, true); - -export const setNativePropsEndpoint = createRpcEndpoint< - [ - type: IdentifierType, - identifier: string, - component_id: string, - first_only: boolean, - native_props: object, - root_unique_id: number | undefined, - ], - void ->('__setNativeProps', false, true); - -export const getPathInfoEndpoint = createRpcEndpoint< - [ - type: IdentifierType, - identifier: string, - component_id: string, - first_only: boolean, - root_unique_id?: number | undefined, - ], - InvokeCallbackRes ->('__getPathInfo', false, true); - -export const nativeModulesCallEndpoint = createRpcEndpoint< - [name: string, data: Cloneable, moduleName: string], - any ->('nativeModulesCall', false, true); - -export const napiModulesCallEndpoint = createRpcEndpoint< - [name: string, data: Cloneable, moduleName: string], - any ->('napiModulesCall', false, true, true); - -export const getCustomSectionsEndpoint = createRpcEndpoint< - [string], - Cloneable ->('getCustomSections', false, true); - -export const markTimingEndpoint = createRpcEndpoint< - [MarkTiming[]], - void ->('markTiming', false, false); - -export const postTimingFlagsEndpoint = createRpcEndpoint< - [ - timingFlags: string[], - pipelineId: string | undefined, - ], - void ->('postTimingFlags', false, false); - -export const triggerComponentEventEndpoint = createRpcEndpoint< - [ - id: string, - params: { - eventDetail: CloneableObject; - eventOption: CloneableObject; - componentId: string; - }, - ], - void ->('__triggerComponentEvent', false, false); - -export const selectComponentEndpoint = createRpcEndpoint< - [ - componentId: string, - idSelector: string, - single: boolean, - ], - void ->('__selectComponent', false, true); - -export const dispatchLynxViewEventEndpoint = createRpcEndpoint< - [ - eventType: string, - detail: CloneableObject, - ], - void ->('dispatchLynxViewEvent', false, false); - -export const dispatchNapiModuleEndpoint = createRpcEndpoint< - [data: Cloneable], - void ->('dispatchNapiModule', false, false); -export const dispatchCoreContextOnBackgroundEndpoint = createRpcEndpoint< - [{ - type: string; - data: Cloneable; - }], - void ->('dispatchCoreContextOnBackground', false, false); - -export const dispatchJSContextOnMainThreadEndpoint = createRpcEndpoint< - [{ - type: string; - data: Cloneable; - }], - void ->('dispatchJSContextOnMainThread', false, false); - -export const triggerElementMethodEndpoint = createRpcEndpoint< - [ - method: string, - id: string, - options: ElementAnimationOptions, - ], - void ->('__triggerElementMethod', false, false); - -export const updateGlobalPropsEndpoint = createRpcEndpoint< - [Cloneable], - void ->('updateGlobalProps', false, false); - -export const updateI18nResourcesEndpoint = createRpcEndpoint< - [Cloneable], - void ->('updateI18nResources', false, false); - -export const updateI18nResourceEndpoint = createRpcEndpoint< - [Cloneable | undefined], - void ->('updateI18nResource', false, false); - -export const dispatchI18nResourceEndpoint = createRpcEndpoint< - [Cloneable], - void ->('dispatchI18nResource', false, false); - -export const queryComponentEndpoint = createRpcEndpoint< - [string], - { code: number; detail: { schema: string } } ->('queryComponent', false, true); - -export const updateBTSTemplateCacheEndpoint = createRpcEndpoint< - [/** url */ string, LynxTemplate], - void ->('updateBTSTemplateCacheEndpoint', false, true); - -export const loadTemplateMultiThread = createRpcEndpoint< - [string], - LynxTemplate ->('loadTemplateMultiThread', false, true); - -export const reloadEndpoint = createRpcEndpoint< - [], - void ->('reload', false, false); diff --git a/packages/web-platform/web-constants/src/eventName.ts b/packages/web-platform/web-constants/src/eventName.ts deleted file mode 100644 index 55b9fefe1c..0000000000 --- a/packages/web-platform/web-constants/src/eventName.ts +++ /dev/null @@ -1,34 +0,0 @@ -// Copyright 2023 The Lynx Authors. All rights reserved. -// Licensed under the Apache License Version 2.0 that can be found in the -// LICENSE file in the root directory of this source tree. -export const W3cEventNameToLynx: Record = { - click: 'tap', - lynxscroll: 'scroll', - lynxscrollend: 'scrollend', - overlaytouch: 'touch', - lynxfocus: 'focus', - lynxblur: 'blur', - lynxinput: 'input', -}; -export const LynxEventNameToW3cByTagName: Record< - string, - Record -> = { - 'X-INPUT': { - 'blur': 'lynxblur', - 'focus': 'lynxfocus', - 'input': 'lynxinput', - }, - 'X-TEXTAREA': { - 'blur': 'lynxblur', - 'focus': 'lynxfocus', - 'input': 'lynxinput', - }, -}; - -export const LynxEventNameToW3cCommon: Record = { - tap: 'click', - scroll: 'lynxscroll', - scrollend: 'lynxscrollend', - touch: 'overlaytouch', -}; diff --git a/packages/web-platform/web-constants/src/index.ts b/packages/web-platform/web-constants/src/index.ts deleted file mode 100644 index 747d30ec60..0000000000 --- a/packages/web-platform/web-constants/src/index.ts +++ /dev/null @@ -1,10 +0,0 @@ -// Copyright 2023 The Lynx Authors. All rights reserved. -// Licensed under the Apache License Version 2.0 that can be found in the -// LICENSE file in the root directory of this source tree. - -export * from './constants.js'; -export * from './eventName.js'; -export * from './endpoints.js'; -export * from './types/index.js'; -export * from './utils/index.js'; -export type * from '@lynx-js/web-worker-rpc'; diff --git a/packages/web-platform/web-constants/src/types/BackThreadStartConfigs.ts b/packages/web-platform/web-constants/src/types/BackThreadStartConfigs.ts deleted file mode 100644 index 1fdb4b2760..0000000000 --- a/packages/web-platform/web-constants/src/types/BackThreadStartConfigs.ts +++ /dev/null @@ -1,18 +0,0 @@ -// Copyright 2023 The Lynx Authors. All rights reserved. -// Licensed under the Apache License Version 2.0 that can be found in the -// LICENSE file in the root directory of this source tree. - -import type { Cloneable } from './Cloneable.js'; -import type { LynxTemplate } from './LynxModule.js'; -import type { NapiModulesMap } from './NapiModules.js'; -import type { NativeModulesMap } from './NativeModules.js'; - -export interface BackMainThreadContextConfig { - initData: unknown; - globalProps: unknown; - template: LynxTemplate; - cardType: string; - customSections: Record; - nativeModulesMap: NativeModulesMap; - napiModulesMap: NapiModulesMap; -} diff --git a/packages/web-platform/web-constants/src/types/Element.ts b/packages/web-platform/web-constants/src/types/Element.ts deleted file mode 100644 index 3e463a1e75..0000000000 --- a/packages/web-platform/web-constants/src/types/Element.ts +++ /dev/null @@ -1,49 +0,0 @@ -// Copyright 2023 The Lynx Authors. All rights reserved. -// Licensed under the Apache License Version 2.0 that can be found in the -// LICENSE file in the root directory of this source tree. - -import type { LynxEventType } from './EventType.js'; - -export interface LynxRuntimeInfo { - eventHandlerMap: Record; - componentAtIndex?: ComponentAtIndexCallback; - enqueueComponent?: EnqueueComponentCallback; -} - -export type ComponentAtIndexCallback = ( - list: HTMLElement, - listID: number, - cellIndex: number, - operationID: number, - enableReuseNotification: boolean, -) => void; - -export type EnqueueComponentCallback = ( - list: HTMLElement, - listID: number, - sign: number, -) => void; - -export const enum AnimationOperation { - START = 0, - PLAY, - PAUSE, - CANCEL, - FINISH, -} - -export interface ElementAnimationOptions { - operation: AnimationOperation; - id: string; - keyframes?: any; - timingOptions?: Record; -} diff --git a/packages/web-platform/web-constants/src/types/EventType.ts b/packages/web-platform/web-constants/src/types/EventType.ts deleted file mode 100644 index 45e7af1940..0000000000 --- a/packages/web-platform/web-constants/src/types/EventType.ts +++ /dev/null @@ -1,72 +0,0 @@ -// Copyright 2023 The Lynx Authors. All rights reserved. -// Licensed under the Apache License Version 2.0 that can be found in the -// LICENSE file in the root directory of this source tree. - -import type { Cloneable } from './Cloneable.js'; - -export type LynxEventType = - | 'bindEvent' - | 'catchEvent' - | 'capture-bind' - | 'capture-catch'; - -export interface LynxCrossThreadEventTarget { - dataset: { - [key: string]: Cloneable; - }; - id: string | null; - uniqueId: number; -} - -export interface LynxCrossThreadEvent< - T = { - [key: string]: string | number | undefined | null; - }, -> { - type: string; - timestamp: number; - target: LynxCrossThreadEventTarget; - currentTarget: LynxCrossThreadEventTarget | null; - detail: T; - [key: string]: string | number | undefined | null | {}; -} - -export interface MainThreadScriptEvent< - T = { - [key: string]: string | number | undefined | null; - }, -> extends LynxCrossThreadEvent { - target: LynxCrossThreadEventTarget & { elementRefptr: unknown }; - currentTarget: - | (LynxCrossThreadEventTarget & { elementRefptr: unknown }) - | null; -} - -export type ExposureEventDetail = { - 'exposure-id': string; - 'exposure-scene': string; - exposureID: string; - exposureScene: string; - 'unique-id': number; -}; -export type ExposureEvent = { - detail: ExposureEventDetail; -}; - -export type ExposureWorkerEvent = - & LynxCrossThreadEvent - & ExposureEventDetail; - -export type MinimalRawEventObject = { - type: string; - target: Pick | null; - currentTarget: Pick | null; - detail?: Cloneable; - isTrusted: boolean; - timeStamp: number; - propertyName?: string; // For transition events - animationName?: string; // For animation events - touches?: unknown[]; // For touch events - targetTouches?: unknown[]; // For touch events - changedTouches?: unknown[]; // For touch events -}; diff --git a/packages/web-platform/web-constants/src/types/FlushElementTreeOptions.ts b/packages/web-platform/web-constants/src/types/FlushElementTreeOptions.ts deleted file mode 100644 index 76b1bda9e4..0000000000 --- a/packages/web-platform/web-constants/src/types/FlushElementTreeOptions.ts +++ /dev/null @@ -1,5 +0,0 @@ -import type { PerformancePipelineOptions } from './Performance.js'; - -export interface FlushElementTreeOptions { - pipelineOptions?: PerformancePipelineOptions; -} diff --git a/packages/web-platform/web-constants/src/types/I18n.ts b/packages/web-platform/web-constants/src/types/I18n.ts deleted file mode 100644 index cee2251826..0000000000 --- a/packages/web-platform/web-constants/src/types/I18n.ts +++ /dev/null @@ -1,50 +0,0 @@ -import type { Cloneable } from './Cloneable.js'; - -export interface I18nResourceTranslationOptions { - locale: string; - channel: string; - fallback_url?: string; - [key: string]: Cloneable; -} - -export const getCacheI18nResourcesKey = ( - options: I18nResourceTranslationOptions, -) => { - return `${options.locale}_${options.channel}_${options.fallback_url}`; -}; - -export interface CacheI18nResources { - /** the i18nResource key currently being used by the page */ - curCacheKey: string; - /** the complete set of all requested i18nResources */ - i18nResources: Map; -} - -export type InitI18nResources = Array<{ - options: I18nResourceTranslationOptions; - resource: Record; -}>; - -export const i18nResourceMissedEventName = 'i18nResourceMissed' as const; - -// The purpose of using class is to keep the reference when reassigning -export class I18nResources { - data?: InitI18nResources; - constructor(data?: InitI18nResources) { - this.data = data; - } - setData(data: InitI18nResources) { - this.data = data; - } -} - -// The purpose of using class is to keep the reference when reassigning -export class I18nResource { - data?: Cloneable; - constructor(data?: Cloneable) { - this.data = data; - } - setData(data: Cloneable) { - this.data = data; - } -} diff --git a/packages/web-platform/web-constants/src/types/JSRealm.ts b/packages/web-platform/web-constants/src/types/JSRealm.ts deleted file mode 100644 index f188d23df8..0000000000 --- a/packages/web-platform/web-constants/src/types/JSRealm.ts +++ /dev/null @@ -1,5 +0,0 @@ -export type JSRealm = { - globalWindow: typeof globalThis; - loadScript: (url: string) => Promise; - loadScriptSync: (url: string) => unknown; -}; diff --git a/packages/web-platform/web-constants/src/types/LynxContextEventTarget.ts b/packages/web-platform/web-constants/src/types/LynxContextEventTarget.ts deleted file mode 100644 index 7830c279be..0000000000 --- a/packages/web-platform/web-constants/src/types/LynxContextEventTarget.ts +++ /dev/null @@ -1,38 +0,0 @@ -import type { Cloneable } from './Cloneable.js'; - -export const DispatchEventResult = { - // Event was not canceled by event handler or default event handler. - NotCanceled: 0, - // Event was canceled by event handler; i.e. a script handler calling - // preventDefault. - CanceledByEventHandler: 1, - // Event was canceled by the default event handler; i.e. executing the default - // action. This result should be used sparingly as it deviates from the DOM - // Event Dispatch model. Default event handlers really shouldn't be invoked - // inside of dispatch. - CanceledByDefaultEventHandler: 2, - // Event was canceled but suppressed before dispatched to event handler. This - // result should be used sparingly; and its usage likely indicates there is - // potential for a bug. Trusted events may return this code; but untrusted - // events likely should always execute the event handler the developer intends - // to execute. - CanceledBeforeDispatch: 3, -} as const; - -export type ContextCrossThreadEvent = { - type: string; - data: Cloneable; -}; -export interface LynxContextEventTarget { - onTriggerEvent?: (event: ContextCrossThreadEvent) => void; - - postMessage(message: any): void; - dispatchEvent( - event: ContextCrossThreadEvent, - ): typeof DispatchEventResult[keyof typeof DispatchEventResult]; - addEventListener(type: string, listener: (event: Event) => void): void; - removeEventListener( - type: string, - listener: (event: Event) => void, - ): void; -} diff --git a/packages/web-platform/web-constants/src/types/LynxModule.ts b/packages/web-platform/web-constants/src/types/LynxModule.ts deleted file mode 100644 index 356bb36ca5..0000000000 --- a/packages/web-platform/web-constants/src/types/LynxModule.ts +++ /dev/null @@ -1,87 +0,0 @@ -// Copyright 2023 The Lynx Authors. All rights reserved. -// Licensed under the Apache License Version 2.0 that can be found in the -// LICENSE file in the root directory of this source tree. -import type { Cloneable } from './Cloneable.js'; -import type { LynxEventType } from './EventType.js'; -import type { PageConfig } from './PageConfig.js'; -import type { StyleInfo } from './StyleInfo.js'; - -export type ElementTemplateData = { - id: string; - type: string; - idSelector?: string; - class?: string[]; - attributes?: Record; - builtinAttributes?: Record; - children?: ElementTemplateData[]; - events?: { type: LynxEventType; name: string; value: string }[]; - dataset?: Record; -}; - -export interface LynxTemplate { - styleInfo: StyleInfo; - pageConfig: PageConfig; - customSections: { - [key: string]: { - type?: 'lazy'; - content: Cloneable; - }; - }; - cardType?: string; - lepusCode: { - root: string; - [key: string]: string; - }; - manifest: { - '/app-service.js': string; - [key: string]: string; - }; - elementTemplate: Record; - version?: number; - appType: 'card' | 'lazy'; -} - -export type BTSChunkEntry = ( - postMessage: undefined, - module: { exports: unknown }, - exports: unknown, - lynxCoreInject: unknown, - Card: unknown, - setTimeout: unknown, - setInterval: unknown, - clearInterval: unknown, - clearTimeout: unknown, - NativeModules: unknown, - Component: unknown, - ReactLynx: unknown, - nativeAppId: unknown, - Behavior: unknown, - LynxJSBI: unknown, - lynx: unknown, - // BOM API - window: unknown, - document: unknown, - frames: unknown, - location: unknown, - navigator: unknown, - localStorage: unknown, - history: unknown, - Caches: unknown, - screen: unknown, - alert: unknown, - confirm: unknown, - prompt: unknown, - fetch: unknown, - XMLHttpRequest: unknown, - webkit: unknown, - Reporter: unknown, - print: unknown, - global: unknown, - // Lynx API - requestAnimationFrame: unknown, - cancelAnimationFrame: unknown, -) => unknown; - -export interface LynxJSModule { - exports?: (lynx_runtime: any) => unknown; -} diff --git a/packages/web-platform/web-constants/src/types/MainThreadGlobalThis.ts b/packages/web-platform/web-constants/src/types/MainThreadGlobalThis.ts deleted file mode 100644 index 579f3eef89..0000000000 --- a/packages/web-platform/web-constants/src/types/MainThreadGlobalThis.ts +++ /dev/null @@ -1,439 +0,0 @@ -import type { systemInfo } from '../constants.js'; -import type { Cloneable } from './Cloneable.js'; -import type { - ComponentAtIndexCallback, - EnqueueComponentCallback, -} from './Element.js'; -import type { LynxEventType } from './EventType.js'; -import type { FlushElementTreeOptions } from './FlushElementTreeOptions.js'; -import type { I18nResourceTranslationOptions } from './index.js'; -import type { MainThreadLynx } from './MainThreadLynx.js'; -import type { ProcessDataCallback } from './ProcessDataCallback.js'; -import type { UpdateDataOptions } from './UpdateDataOptions.js'; -import type { InvokeCallbackRes } from './NativeApp.js'; - -type ElementPAPIEventHandler = - | string - | { type: 'worklet'; value: unknown } - | undefined; - -export type AddEventPAPI = ( - element: HTMLElement, - eventType: LynxEventType, - eventName: string, - newEventHandler: ElementPAPIEventHandler, -) => void; - -export type GetEventPAPI = ( - element: HTMLElement, - eventName: string, - eventType: LynxEventType, -) => ElementPAPIEventHandler; - -export type GetEventsPAPI = ( - element: HTMLElement, -) => { - type: LynxEventType; - name: string; - function: ElementPAPIEventHandler; -}[]; - -export type SetEventsPAPI = ( - element: HTMLElement, - listeners: { - type: LynxEventType; - name: string; - function: ElementPAPIEventHandler; - }[], -) => void; - -export type AppendElementPAPI = ( - parent: HTMLElement, - child: HTMLElement, -) => void; - -export type ElementIsEqualPAPI = ( - left: HTMLElement | null, - right: HTMLElement | null, -) => boolean; - -export type FirstElementPAPI = ( - element: HTMLElement, -) => HTMLElement | null; - -export type GetChildrenPAPI = ( - element: HTMLElement, -) => HTMLElement[] | null; - -export type GetParentPAPI = ( - element: HTMLElement, -) => HTMLElement | null; - -export type InsertElementBeforePAPI = ( - parent: HTMLElement, - child: HTMLElement, - ref?: HTMLElement | null, -) => HTMLElement; - -export type LastElementPAPI = ( - element: HTMLElement, -) => HTMLElement | null; - -export type NextElementPAPI = ( - element: HTMLElement, -) => HTMLElement | null; - -export type RemoveElementPAPI = ( - parent: HTMLElement, - child: HTMLElement, -) => HTMLElement; - -export type ReplaceElementPAPI = ( - newElement: HTMLElement, - oldElement: HTMLElement, -) => void; - -export type ReplaceElementsPAPI = ( - parent: HTMLElement, - newChildren: HTMLElement[] | HTMLElement, - oldChildren?: HTMLElement[] | HTMLElement | null | undefined, -) => void; - -export type AddConfigPAPI = ( - element: HTMLElement, - type: string, - value: Cloneable, -) => void; - -export type AddDatasetPAPI = ( - element: HTMLElement, - key: string, - value: Cloneable, -) => void; - -export type GetDatasetPAPI = ( - element: HTMLElement, -) => Record; - -export type GetDataByKeyPAPI = ( - element: HTMLElement, - key: string, -) => Cloneable | undefined; - -export type GetAttributesPAPI = ( - element: HTMLElement, -) => Record; - -export type GetComponentIdPAPI = ( - element: HTMLElement, -) => string | null | undefined; - -export type GetElementConfigPAPI = ( - element: HTMLElement, -) => Record; - -export type GetElementUniqueIDPAPI = ( - element: HTMLElement, -) => number; - -export type GetIDPAPI = ( - element: HTMLElement, -) => string | null; - -export type GetTagPAPI = ( - element: HTMLElement, -) => string; - -export type SetConfigPAPI = ( - element: HTMLElement, - config: Record, -) => void; - -export type SetDatasetPAPI = ( - element: HTMLElement, - dataset: Record, -) => void; - -export type SetIDPAPI = ( - element: HTMLElement, - id: string | null, -) => void; - -export type UpdateComponentIDPAPI = ( - element: HTMLElement, - componentID: string, -) => void; - -export type UpdateComponentInfoPAPI = ( - element: HTMLElement, - params: { - componentID?: string; - name?: string; - path?: string; - entry?: string; - cssID?: number; - }, -) => void; - -export type GetClassesPAPI = ( - element: HTMLElement, -) => string[]; - -export type CreateViewPAPI = ( - parentComponentUniqueID: number, -) => HTMLElement; - -export type SwapElementPAPI = ( - childA: HTMLElement, - childB: HTMLElement, -) => void; - -export type UpdateListInfoAttributeValue = { - insertAction: { - position: number; - }[]; - removeAction: number[]; -}; -export type SetAttributePAPI = ( - element: HTMLElement, - key: Exclude, - value: string | null | undefined | boolean, -) => void; -export type SetAttributePAPIUpdateListInfo = ( - element: HTMLElement, - key: 'update-list-info', - value: UpdateListInfoAttributeValue | null, -) => void; - -export type UpdateListCallbacksPAPI = ( - element: HTMLElement, - componentAtIndex: ComponentAtIndexCallback, - enqueueComponent: EnqueueComponentCallback, -) => void; - -export type CreateTextPAPI = CreateViewPAPI; - -export type CreateRawTextPAPI = (text: string) => HTMLElement; - -export type CreateImagePAPI = CreateViewPAPI; - -export type CreateScrollViewPAPI = CreateViewPAPI; - -export type CreateWrapperElementPAPI = CreateViewPAPI; - -export type CreateComponentPAPI = ( - componentParentUniqueID: number, - componentID: string, - cssID: number, - entryName: string, - name: string, - path: string, - config: Record | null | undefined, - info: Record | null | undefined, -) => HTMLElement; - -export type CreateElementPAPI = ( - tagName: string, - parentComponentUniqueId: number, - info?: Record | null | undefined, -) => HTMLElement; - -export type CreatePagePAPI = ( - componentID: string, - cssID: number, - info?: Record | null | undefined, -) => HTMLElement; - -export type CreateListPAPI = ( - parentComponentUniqueId: number, - componentAtIndex: ComponentAtIndexCallback, - enqueueComponent: EnqueueComponentCallback, -) => HTMLElement; - -export type AddClassPAPI = ( - element: HTMLElement, - className: string, -) => void; - -export type SetClassesPAPI = ( - element: HTMLElement, - classNames: string | null, -) => void; - -export type AddInlineStylePAPI = ( - element: HTMLElement, - key: number | string, - value: string | number | null | undefined, -) => void; - -export type SetInlineStylesPAPI = ( - element: HTMLElement, - value: string | Record | undefined, -) => void; - -export type SetCSSIdPAPI = ( - elements: HTMLElement[], - cssId: number | null, - entryName: string | undefined, -) => void; - -export type GetPageElementPAPI = () => HTMLElement | undefined; - -export type MarkTemplateElementPAPI = ( - element: HTMLElement, -) => void; - -export type MarkPartElementPAPI = ( - element: HTMLElement, - partId: string, -) => void; - -export type GetTemplatePartsPAPI = ( - templateElement: HTMLElement, -) => Record; - -interface JSErrorInfo { - release: string; -} - -export type ElementFromBinaryPAPI = ( - templateId: string, - parentComponentUniId: number, -) => HTMLElement[]; - -export type GetAttributeByNamePAPI = ( - element: HTMLElement, - name: string, -) => string | null; - -export type QueryComponentPAPI = ( - source: string, - resultCallback?: (result: { - code: number; - data?: { - url: string; - evalResult: unknown; - }; - }) => void, -) => null; -export type InvokeUIMethodPAPI = ( - element: HTMLElement, - method: string, - params: object, - callback: (result: InvokeCallbackRes) => void, -) => void; - -export type QuerySelectorPAPI = ( - element: HTMLElement, - selector: string, -) => unknown; - -export type ElementAnimatePAPI = ( - element: HTMLElement, - args: - | [ - operation: 0, - name: string, - keyframes: Record[], - options?: Record, - ] - | [operation: 1 | 2 | 3 | 4, name: string], -) => void; - -export interface ElementPAPIs { - __ElementFromBinary: ElementFromBinaryPAPI; - - // __GetTemplateParts currently only provided by the thread-strategy = "all-on-ui" (default) - __GetTemplateParts?: GetTemplatePartsPAPI; - - __MarkPartElement: MarkPartElementPAPI; - __MarkTemplateElement: MarkTemplateElementPAPI; - __AddEvent: AddEventPAPI; - __GetEvent: GetEventPAPI; - __GetEvents: GetEventsPAPI; - __SetEvents: SetEventsPAPI; - __AppendElement: AppendElementPAPI; - __ElementIsEqual: ElementIsEqualPAPI; - __FirstElement: FirstElementPAPI; - __GetChildren: GetChildrenPAPI; - __GetParent: GetParentPAPI; - __InsertElementBefore: InsertElementBeforePAPI; - __LastElement: LastElementPAPI; - __NextElement: NextElementPAPI; - __RemoveElement: RemoveElementPAPI; - __ReplaceElement: ReplaceElementPAPI; - __ReplaceElements: ReplaceElementsPAPI; - __AddConfig: AddConfigPAPI; - __AddDataset: AddDatasetPAPI; - __GetDataset: GetDatasetPAPI; - __GetDataByKey: GetDataByKeyPAPI; - __GetAttributes: GetAttributesPAPI; - __GetComponentID: GetComponentIdPAPI; - __GetElementConfig: GetElementConfigPAPI; - __GetElementUniqueID: GetElementUniqueIDPAPI; - __GetID: GetIDPAPI; - __GetTag: GetTagPAPI; - __SetConfig: SetConfigPAPI; - __GetConfig: GetElementConfigPAPI; - __SetDataset: SetDatasetPAPI; - __SetID: SetIDPAPI; - __UpdateComponentID: UpdateComponentIDPAPI; - __UpdateComponentInfo: UpdateComponentInfoPAPI; - __GetClasses: GetClassesPAPI; - __CreateView: CreateViewPAPI; - __SwapElement: SwapElementPAPI; - __CreateText: CreateTextPAPI; - __CreateRawText: CreateRawTextPAPI; - __CreateImage: CreateImagePAPI; - __CreateScrollView: CreateScrollViewPAPI; - __CreateWrapperElement: CreateWrapperElementPAPI; - __CreateComponent: CreateComponentPAPI; - __CreateElement: CreateElementPAPI; - __CreatePage: CreatePagePAPI; - __CreateList: CreateListPAPI; - __SetAttribute: SetAttributePAPI & SetAttributePAPIUpdateListInfo; - __UpdateListCallbacks: UpdateListCallbacksPAPI; - __AddClass: AddClassPAPI; - __SetClasses: SetClassesPAPI; - __AddInlineStyle: AddInlineStylePAPI; - __SetInlineStyles: SetInlineStylesPAPI; - __SetCSSId: SetCSSIdPAPI; - __GetPageElement: GetPageElementPAPI; - __GetAttributeByName: GetAttributeByNamePAPI; - __FlushElementTree: ( - _subTree?: unknown, - options?: FlushElementTreeOptions, - ) => void; - __InvokeUIMethod: InvokeUIMethodPAPI; - __QuerySelector: QuerySelectorPAPI; - __ElementAnimate: ElementAnimatePAPI; -} - -export interface MainThreadGlobalThis extends ElementPAPIs { - __globalProps: unknown; - SystemInfo: typeof systemInfo; - globalThis?: MainThreadGlobalThis; - lynx: MainThreadLynx; - processData?: ProcessDataCallback; - ssrEncode?: () => string; - ssrHydrate?: (encodeData?: string | null) => void; - _ReportError: (error: Error, _: unknown) => void; - _SetSourceMapRelease: (errInfo: JSErrorInfo) => void; - __OnLifecycleEvent: (lifeCycleEvent: Cloneable) => void; - __LoadLepusChunk: (path: string) => boolean; - _I18nResourceTranslation: ( - options: I18nResourceTranslationOptions, - ) => unknown | undefined; - // This is an empty implementation, just to avoid business call errors - _AddEventListener: (...args: unknown[]) => void; - __QueryComponent: QueryComponentPAPI; - // DSL runtime binding - processEvalResult?: ( - exports: unknown, - schema: string, - ) => unknown; - // the following methods is assigned by the main thread user code - renderPage: ((data: unknown) => void) | undefined; - updatePage?: (data: Cloneable, options?: UpdateDataOptions) => void; - runWorklet?: (obj: unknown, event: unknown) => void; -} diff --git a/packages/web-platform/web-constants/src/types/MainThreadLynx.ts b/packages/web-platform/web-constants/src/types/MainThreadLynx.ts deleted file mode 100644 index ca8e8453f3..0000000000 --- a/packages/web-platform/web-constants/src/types/MainThreadLynx.ts +++ /dev/null @@ -1,16 +0,0 @@ -import type { systemInfo } from '../constants.js'; -import type { Cloneable } from './Cloneable.js'; -import type { LynxContextEventTarget } from './LynxContextEventTarget.js'; -export interface MainThreadLynx { - getJSContext: () => LynxContextEventTarget; - requestAnimationFrame: (cb: () => void) => number; - cancelAnimationFrame: (handler: number) => void; - __globalProps: unknown; - getCustomSectionSync: (key: string) => Cloneable; - markPipelineTiming: (pipelineId: string, timingKey: string) => void; - SystemInfo: typeof systemInfo; - setTimeout: typeof setTimeout; - clearTimeout: typeof clearTimeout; - setInterval: typeof setInterval; - clearInterval: typeof clearInterval; -} diff --git a/packages/web-platform/web-constants/src/types/MainThreadStartConfigs.ts b/packages/web-platform/web-constants/src/types/MainThreadStartConfigs.ts deleted file mode 100644 index a181712f2e..0000000000 --- a/packages/web-platform/web-constants/src/types/MainThreadStartConfigs.ts +++ /dev/null @@ -1,21 +0,0 @@ -// Copyright 2023 The Lynx Authors. All rights reserved. -// Licensed under the Apache License Version 2.0 that can be found in the -// LICENSE file in the root directory of this source tree. - -import type { Cloneable } from './Cloneable.js'; -import type { InitI18nResources } from './index.js'; -import type { LynxTemplate } from './LynxModule.js'; -import type { NapiModulesMap } from './NapiModules.js'; -import type { NativeModulesMap } from './NativeModules.js'; -import type { BrowserConfig } from './PageConfig.js'; - -export interface StartMainThreadContextConfig { - template: LynxTemplate; - initData: Cloneable; - globalProps: Cloneable; - browserConfig: BrowserConfig; - nativeModulesMap: NativeModulesMap; - napiModulesMap: NapiModulesMap; - tagMap: Record; - initI18nResources: InitI18nResources; -} diff --git a/packages/web-platform/web-constants/src/types/MarkTiming.ts b/packages/web-platform/web-constants/src/types/MarkTiming.ts deleted file mode 100644 index 96d3266cc6..0000000000 --- a/packages/web-platform/web-constants/src/types/MarkTiming.ts +++ /dev/null @@ -1,15 +0,0 @@ -// Copyright 2023 The Lynx Authors. All rights reserved. -// Licensed under the Apache License Version 2.0 that can be found in the -// LICENSE file in the root directory of this source tree. - -export interface MarkTiming { - timingKey: string; - pipelineId?: string; - timeStamp: number; -} - -export type MarkTimingInternal = ( - timingKey: string, - pipelineId?: string, - timeStamp?: number, -) => void; diff --git a/packages/web-platform/web-constants/src/types/NativeApp.ts b/packages/web-platform/web-constants/src/types/NativeApp.ts deleted file mode 100644 index c26f8e999f..0000000000 --- a/packages/web-platform/web-constants/src/types/NativeApp.ts +++ /dev/null @@ -1,237 +0,0 @@ -// Copyright 2023 The Lynx Authors. All rights reserved. -// Licensed under the Apache License Version 2.0 that can be found in the - -import type { CloneableObject } from './Cloneable.js'; -import type { I18nResource } from './I18n.js'; -import type { LynxContextEventTarget } from './LynxContextEventTarget.js'; -import type { PerformancePipelineOptions } from './Performance.js'; - -// LICENSE file in the root directory of this source tree. -export const enum IdentifierType { - ID_SELECTOR, // css selector - /** - * @deprecated - */ - REF_ID, - UNIQUE_ID, // element_id -} -export type LynxKernelInject = { - init: (opt: { tt: LynxKernelInject }) => void; - buildVersion?: string; -}; - -export interface EventEmitter { - addListener( - eventName: string, - listener: (...args: unknown[]) => void, - context?: object, - ): void; - - removeListener( - eventName: string, - listener: (...args: unknown[]) => void, - ): void; - - emit(eventName: string, data: unknown): void; - - removeAllListeners(eventName?: string): void; - - trigger(eventName: string, params: string | Record): void; - - toggle(eventName: string, ...data: unknown[]): void; -} - -export type NativeLynx = { - __globalProps: CloneableObject; - getJSModule(_moduleName: string): unknown; - getNativeApp(): NativeApp; - getCoreContext(): LynxContextEventTarget; - getCustomSectionSync(key: string): CloneableObject; - getCustomSection(key: string): Promise; -}; - -export type NativeTTObject = { - lynx: NativeLynx; - OnLifecycleEvent: (...args: unknown[]) => void; - publicComponentEvent( - componentId: string, - handlerName: string, - eventData?: unknown, - ): void; - publishEvent(handlerName: string, data?: unknown): void; - GlobalEventEmitter: EventEmitter; - lynxCoreInject: any; - updateCardData: ( - newData: Record, - options?: Record, - ) => void; - onNativeAppReady: () => void; - globalThis?: { - tt: NativeTTObject; - }; - updateGlobalProps: (newData: Record) => void; -}; - -export type BundleInitReturnObj = { - /** - * On the web platform - * @param opt - * @returns - */ - init: (opt: { - tt: NativeTTObject; - }) => unknown; - buildVersion?: string; -}; - -/** - * const enum will be shakedown in Typescript Compiler - */ -export const enum ErrorCode { - SUCCESS = 0, - UNKNOWN = 1, - NODE_NOT_FOUND = 2, - METHOD_NOT_FOUND = 3, - PARAM_INVALID = 4, - SELECTOR_NOT_SUPPORTED = 5, - NO_UI_FOR_NODE = 6, -} - -export interface InvokeCallbackRes { - code: ErrorCode; - data?: unknown; -} - -export interface NativeApp { - id: string; - - callLepusMethod( - name: string, - data: unknown, - callback: (ret: unknown) => void, - ): void; - - setTimeout: typeof setTimeout; - - setInterval: typeof setInterval; - - clearTimeout: typeof clearTimeout; - - clearInterval: typeof clearInterval; - - requestAnimationFrame: (cb: () => void) => void; - - cancelAnimationFrame: (id: number) => void; - - readScript: (sourceURL: string, entryName?: string) => string; - - loadScript: (sourceURL: string, entryName?: string) => BundleInitReturnObj; - - loadScriptAsync( - sourceURL: string, - callback: (message: string | null, exports?: BundleInitReturnObj) => void, - entryName?: string, - ): void; - nativeModuleProxy: Record; - - setNativeProps: ( - type: IdentifierType, - identifier: string, - component_id: string, - first_only: boolean, - native_props: Record, - root_unique_id: number | undefined, - ) => void; - - invokeUIMethod: ( - type: IdentifierType, - identifier: string, - component_id: string, - method: string, - params: object, - callback: (ret: InvokeCallbackRes) => void, - root_unique_id: number, - ) => void; - - getPathInfo: ( - type: IdentifierType, - identifier: string, - component_id: string, - first_only: boolean, - callback: (ret: InvokeCallbackRes) => void, - root_unique_id?: number, - ) => void; - - setCard(tt: NativeTTObject): void; - - // Timing related - generatePipelineOptions: () => PerformancePipelineOptions; - onPipelineStart: (pipeline_id: string) => void; - markPipelineTiming: (pipeline_id: string, timing_key: string) => void; - bindPipelineIdWithTimingFlag: ( - pipeline_id: string, - timing_flag: string, - ) => void; - - /** - * Support from Lynx 3.0 - */ - profileStart: (traceName: string, option?: unknown) => void; - - /** - * Support from Lynx 3.0 - */ - profileEnd: () => void; - - /*** - * Support from Lynx 3.0 - */ - profileMark: () => void; - - /** - * Support from Lynx 3.0 - */ - profileFlowId: () => number; - - /** - * Support from Lynx 2.18 - */ - isProfileRecording: () => boolean; - - triggerComponentEvent(id: string, params: { - eventDetail: CloneableObject; - eventOption: CloneableObject; - componentId: string; - }): void; - - selectComponent( - componentId: string, - idSelector: string, - single: boolean, - callback?: () => void, - ): void; - - createJSObjectDestructionObserver( - callback: (...args: unknown[]) => unknown, - ): {}; - - setSharedData(dataKey: string, dataVal: T): void; - getSharedData(dataKey: string): T | undefined; - - i18nResource: I18nResource; - - reportException: (error: Error, _: unknown) => void; - __SetSourceMapRelease: (err: Error) => void; - __GetSourceMapRelease: (url: string) => string | undefined; - - queryComponent: ( - source: string, - callback: ( - ret: { __hasReady: boolean } | { - code: number; - detail?: { schema: string }; - }, - ) => void, - ) => void; - tt: NativeTTObject | null; -} diff --git a/packages/web-platform/web-constants/src/types/PageConfig.ts b/packages/web-platform/web-constants/src/types/PageConfig.ts deleted file mode 100644 index 7c54fcd983..0000000000 --- a/packages/web-platform/web-constants/src/types/PageConfig.ts +++ /dev/null @@ -1,16 +0,0 @@ -// Copyright 2023 The Lynx Authors. All rights reserved. -// Licensed under the Apache License Version 2.0 that can be found in the -// LICENSE file in the root directory of this source tree. -export interface PageConfig { - enableCSSSelector: boolean; - enableRemoveCSSScope: boolean; - defaultDisplayLinear: boolean; - defaultOverflowVisible: boolean; - enableJSDataProcessor: boolean; -} - -export interface BrowserConfig { - pixelRatio: number; - pixelWidth: number; - pixelHeight: number; -} diff --git a/packages/web-platform/web-constants/src/types/Performance.ts b/packages/web-platform/web-constants/src/types/Performance.ts deleted file mode 100644 index 86fb994c27..0000000000 --- a/packages/web-platform/web-constants/src/types/Performance.ts +++ /dev/null @@ -1,33 +0,0 @@ -// Copyright 2024 The Lynx Authors. All rights reserved. -// Licensed under the Apache License Version 2.0 that can be found in the -// LICENSE file in the root directory of this source tree. - -export interface SetupTimingInfo { - [key: string]: unknown; -} -export interface UpdateTimingInfo { - [key: string]: unknown; -} -export interface ExtraTimingInfo { - [key: string]: unknown; -} - -export interface MetricsTimingInfo { -} -export interface TimingInfo { - extra_timing: ExtraTimingInfo; - setup_timing: SetupTimingInfo; - update_timings: { - [key: string]: UpdateTimingInfo; - }; - metrics: MetricsTimingInfo; - has_reload: boolean; - thread_strategy: number; - url: string; - [key: string]: unknown; -} - -export interface PerformancePipelineOptions { - pipelineID: string; - needTimestamps: boolean; -} diff --git a/packages/web-platform/web-constants/src/types/SSR.ts b/packages/web-platform/web-constants/src/types/SSR.ts deleted file mode 100644 index 4359761f61..0000000000 --- a/packages/web-platform/web-constants/src/types/SSR.ts +++ /dev/null @@ -1,25 +0,0 @@ -import type { AddEventPAPI } from './MainThreadGlobalThis.js'; - -export type SSREventReplayInfo = [ - number, - Parameters[1], - Parameters[2], - Parameters[3], -]; - -export type SSRDumpInfo = { - ssrEncodeData: string | null | undefined; - events: SSREventReplayInfo[]; -}; - -export interface SSRHydrateInfo extends SSRDumpInfo { - /** WeakRef */ - lynxUniqueIdToElement: WeakRef[]; - /** for cssog */ - lynxUniqueIdToStyleRulesIndex: number[]; - cardStyleElement: HTMLStyleElement | null; -} - -export type SSRDehydrateHooks = { - __AddEvent: AddEventPAPI; -}; diff --git a/packages/web-platform/web-constants/src/types/StyleInfo.ts b/packages/web-platform/web-constants/src/types/StyleInfo.ts deleted file mode 100644 index dd1736a732..0000000000 --- a/packages/web-platform/web-constants/src/types/StyleInfo.ts +++ /dev/null @@ -1,36 +0,0 @@ -// Copyright 2023 The Lynx Authors. All rights reserved. -// Licensed under the Apache License Version 2.0 that can be found in the -// LICENSE file in the root directory of this source tree. -export interface CSSRule { - sel: [ - plainSelectors: string[], - pseudoClassSelectors: string[], - pseudoElementSelectors: string[], - combinator: string[], - ...string[][], - ][]; - decl: [string, string][]; -} -export interface OneInfo { - content: string[]; - rules: CSSRule[]; - imports?: string[]; -} -export interface StyleInfo { - [cssId: string]: OneInfo; -} -export interface FlattenedOneInfo { - content: string[]; - rules: CSSRule[]; - importBy: string[]; -} -export type FlattenedStyleInfo = FlattenedOneInfo[]; - -/** - * CSS Info for Old Generation CSS System - */ -export interface CssOGInfo { - [cssId: string]: { - [className: string]: [string, string][]; - }; -} diff --git a/packages/web-platform/web-constants/src/types/TemplateLoader.ts b/packages/web-platform/web-constants/src/types/TemplateLoader.ts deleted file mode 100644 index f7a9736d61..0000000000 --- a/packages/web-platform/web-constants/src/types/TemplateLoader.ts +++ /dev/null @@ -1,3 +0,0 @@ -import type { LynxTemplate } from './LynxModule.js'; - -export type TemplateLoader = (url: string) => Promise; diff --git a/packages/web-platform/web-constants/src/types/index.ts b/packages/web-platform/web-constants/src/types/index.ts deleted file mode 100644 index 14e07f04c7..0000000000 --- a/packages/web-platform/web-constants/src/types/index.ts +++ /dev/null @@ -1,23 +0,0 @@ -export * from './StyleInfo.js'; -export * from './EventType.js'; -export * from './PageConfig.js'; -export * from './Cloneable.js'; -export * from './LynxModule.js'; -export * from './ProcessDataCallback.js'; -export * from './Performance.js'; -export * from './MainThreadStartConfigs.js'; -export * from './NativeApp.js'; -export * from './UpdateDataOptions.js'; -export * from './NativeModules.js'; -export * from './NapiModules.js'; -export * from './FlushElementTreeOptions.js'; -export * from './LynxContextEventTarget.js'; -export * from './Element.js'; -export * from './MainThreadGlobalThis.js'; -export * from './MainThreadLynx.js'; -export * from './I18n.js'; -export * from './BackThreadStartConfigs.js'; -export * from './MarkTiming.js'; -export * from './SSR.js'; -export * from './JSRealm.js'; -export * from './TemplateLoader.js'; diff --git a/packages/web-platform/web-constants/src/utils/LynxCrossThreadContext.ts b/packages/web-platform/web-constants/src/utils/LynxCrossThreadContext.ts deleted file mode 100644 index 2321fd924b..0000000000 --- a/packages/web-platform/web-constants/src/utils/LynxCrossThreadContext.ts +++ /dev/null @@ -1,38 +0,0 @@ -// Copyright 2023 The Lynx Authors. All rights reserved. -// Licensed under the Apache License Version 2.0 that can be found in the -// LICENSE file in the root directory of this source tree. - -import type { dispatchCoreContextOnBackgroundEndpoint, Rpc } from '../index.js'; -import { - DispatchEventResult, - type LynxContextEventTarget, -} from '../types/LynxContextEventTarget.js'; - -export class LynxCrossThreadContext extends EventTarget - implements LynxContextEventTarget -{ - constructor( - private _config: { - rpc: Rpc; - receiveEventEndpoint: typeof dispatchCoreContextOnBackgroundEndpoint; - sendEventEndpoint: typeof dispatchCoreContextOnBackgroundEndpoint; - }, - ) { - super(); - } - postMessage(...args: any[]) { - console.error('[lynx-web] postMessage not implemented, args:', ...args); - } - // @ts-expect-error - override dispatchEvent(event: ContextCrossThreadEvent) { - const { rpc, sendEventEndpoint } = this._config; - rpc.invoke(sendEventEndpoint, [event]); - return DispatchEventResult.CanceledBeforeDispatch; - } - __start() { - const { rpc, receiveEventEndpoint } = this._config; - rpc.registerHandler(receiveEventEndpoint, ({ type, data }) => { - super.dispatchEvent(new MessageEvent(type, { data: data ?? {} })); - }); - } -} diff --git a/packages/web-platform/web-constants/src/utils/generateTemplate.ts b/packages/web-platform/web-constants/src/utils/generateTemplate.ts deleted file mode 100644 index 55f323e6be..0000000000 --- a/packages/web-platform/web-constants/src/utils/generateTemplate.ts +++ /dev/null @@ -1,114 +0,0 @@ -// Copyright 2023 The Lynx Authors. All rights reserved. -// Licensed under the Apache License Version 2.0 that can be found in the -// LICENSE file in the root directory of this source tree. - -import type { LynxTemplate } from '../types/LynxModule.js'; - -const currentSupportedTemplateVersion = 2; -const globalDisallowedVars = ['navigator', 'postMessage', 'window']; -type templateUpgrader = (template: LynxTemplate) => LynxTemplate; -const templateUpgraders: templateUpgrader[] = [ - (template) => { - template.appType = template.appType ?? (template.lepusCode.root.startsWith( - '(function (globDynamicComponentEntry', - ) - ? 'lazy' - : 'card'); - template.version = 2; - template.lepusCode = Object.fromEntries( - Object.entries(template.lepusCode).filter(([_, content]) => - typeof content === 'string' - ), - ) as typeof template.lepusCode; - return template; - }, -]; - -const generateModuleContent = ( - fileName: string, - content: string, - eager: boolean, - appType: 'card' | 'lazy', -) => - /** - * About the `allFunctionsCalledOnLoad` directive: - * https://v8.dev/blog/preparser#pife - * https://github.com/WICG/explicit-javascript-compile-hints-file-based?tab=readme-ov-file - * https://v8.dev/blog/explicit-compile-hints - * We should ensure the MTS code is parsed eagerly to avoid runtime parse delay. - * But for BTS code, we should not do this as it would increase the memory usage. - * JavaScript Engines, like V8, already had optimizations for code starts with "(function" - * to be parsed eagerly. - */ - [ - eager ? '//# allFunctionsCalledOnLoad' : '', - '\n(function() { "use strict"; const ', - globalDisallowedVars.join('=void 0,'), - '=void 0;\n', - appType !== 'card' ? 'module.exports=\n' : '', - content, - '\n})()', - '\n//# sourceURL=', - fileName, - ].join(''); - -async function generateJavascriptUrl>( - obj: T, - createJsModuleUrl: (content: string, name: string) => Promise, - eager: boolean, - appType: 'card' | 'lazy', - templateName: string, -): Promise { - return Promise.all( - (Object.entries(obj).filter(([_, content]) => - typeof content === 'string' - ) as [string, string][]).map(async ([name, content]) => { - return [ - name, - await createJsModuleUrl( - generateModuleContent( - `${templateName}/${name.replaceAll('/', '_')}.js`, - content, - eager, - appType, - ), - `${templateName}-${name.replaceAll('/', '_')}.js`, - ), - ]; - }), - ).then( - Object.fromEntries, - ); -} - -export async function generateTemplate( - template: LynxTemplate, - createJsModuleUrl: - | ((content: string, name: string) => Promise) - | ((content: string) => string), - templateName: string, -): Promise { - template.version = template.version ?? 1; - if (template.version > currentSupportedTemplateVersion) { - throw new Error( - `Unsupported template, please upgrade your web-platform dependencies`, - ); - } - let upgrader: templateUpgrader | undefined; - while ( - template.version! < currentSupportedTemplateVersion - && (upgrader = templateUpgraders[template.version! - 1]) - ) { - template = upgrader(template); - } - return { - ...template, - lepusCode: await generateJavascriptUrl( - template.lepusCode, - createJsModuleUrl as (content: string, name: string) => Promise, - true, - template.appType!, - templateName, - ), - }; -} diff --git a/packages/web-platform/web-constants/src/utils/index.ts b/packages/web-platform/web-constants/src/utils/index.ts deleted file mode 100644 index e304bf42f8..0000000000 --- a/packages/web-platform/web-constants/src/utils/index.ts +++ /dev/null @@ -1,7 +0,0 @@ -// Copyright 2023 The Lynx Authors. All rights reserved. -// Licensed under the Apache License Version 2.0 that can be found in the -// LICENSE file in the root directory of this source tree. - -export { LynxCrossThreadContext } from './LynxCrossThreadContext.js'; -export { dispatchMarkTiming, flushMarkTiming } from './markTiming.js'; -export { generateTemplate } from './generateTemplate.js'; diff --git a/packages/web-platform/web-constants/src/utils/markTiming.ts b/packages/web-platform/web-constants/src/utils/markTiming.ts deleted file mode 100644 index 86d56b1c4a..0000000000 --- a/packages/web-platform/web-constants/src/utils/markTiming.ts +++ /dev/null @@ -1,41 +0,0 @@ -// Copyright 2023 The Lynx Authors. All rights reserved. -// Licensed under the Apache License Version 2.0 that can be found in the -// LICENSE file in the root directory of this source tree. - -import type { MarkTiming } from '../types/MarkTiming.js'; - -export const dispatchMarkTiming = ( - { timingKey, pipelineId, timeStamp, markTiming, cacheMarkTimings }: { - timingKey: string; - pipelineId?: string; - timeStamp?: number; - markTiming: (markTimings: MarkTiming[]) => void; - cacheMarkTimings: { records: MarkTiming[]; timeout: NodeJS.Timeout | null }; - }, -) => { - cacheMarkTimings.records.push({ - timingKey, - pipelineId, - timeStamp: timeStamp ?? performance.now() + performance.timeOrigin, - }); - - if (!cacheMarkTimings.timeout) { - cacheMarkTimings.timeout = setTimeout(() => { - markTiming(cacheMarkTimings.records); - cacheMarkTimings.records = []; - cacheMarkTimings.timeout = null; - }, 500); - } -}; - -export const flushMarkTiming = ( - markTiming: (markTimings: MarkTiming[]) => void, - cacheMarkTimings: { records: MarkTiming[]; timeout: NodeJS.Timeout | null }, -) => { - markTiming(cacheMarkTimings.records); - cacheMarkTimings.records = []; - if (cacheMarkTimings.timeout) { - clearTimeout(cacheMarkTimings.timeout); - cacheMarkTimings.timeout = null; - } -}; diff --git a/packages/web-platform/web-constants/tsconfig.json b/packages/web-platform/web-constants/tsconfig.json deleted file mode 100644 index bc455bddf0..0000000000 --- a/packages/web-platform/web-constants/tsconfig.json +++ /dev/null @@ -1,14 +0,0 @@ -{ - "extends": "../tsconfig.json", - "compilerOptions": { - "composite": true, - "rootDir": "./src", - "outDir": "./dist", - "lib": ["ESNext", "DOM"], - }, - "include": ["src"], - "references": [ - { "path": "../web-worker-rpc/tsconfig.json" }, - { "path": "../offscreen-document/tsconfig.json" }, - ], -} diff --git a/packages/web-platform/web-core-wasm-e2e/bench/server.bench.vitest.spec.ts b/packages/web-platform/web-core-e2e/bench/server.bench.vitest.spec.ts similarity index 95% rename from packages/web-platform/web-core-wasm-e2e/bench/server.bench.vitest.spec.ts rename to packages/web-platform/web-core-e2e/bench/server.bench.vitest.spec.ts index ea0eab273d..bc9cd4d244 100644 --- a/packages/web-platform/web-core-wasm-e2e/bench/server.bench.vitest.spec.ts +++ b/packages/web-platform/web-core-e2e/bench/server.bench.vitest.spec.ts @@ -1,7 +1,7 @@ import { bench, describe } from 'vitest'; import * as path from 'path'; import * as fs from 'fs'; -import { executeTemplate } from '@lynx-js/web-core-wasm/server'; +import { executeTemplate } from '@lynx-js/web-core/server'; import { fileURLToPath } from 'url'; const __dirname = path.dirname(fileURLToPath(import.meta.url)); diff --git a/packages/web-platform/web-core-wasm-e2e/package.json b/packages/web-platform/web-core-e2e/package.json similarity index 92% rename from packages/web-platform/web-core-wasm-e2e/package.json rename to packages/web-platform/web-core-e2e/package.json index 61609007c5..22ac20e4e8 100644 --- a/packages/web-platform/web-core-wasm-e2e/package.json +++ b/packages/web-platform/web-core-e2e/package.json @@ -1,5 +1,5 @@ { - "name": "@lynx-js/web-core-wasm-e2e", + "name": "@lynx-js/web-core-e2e", "version": "0.0.0", "private": true, "license": "Apache-2.0", @@ -21,7 +21,7 @@ "@lynx-js/react": "workspace:*", "@lynx-js/react-rsbuild-plugin": "workspace:*", "@lynx-js/rspeedy": "workspace:*", - "@lynx-js/web-core-wasm": "workspace:*", + "@lynx-js/web-core": "workspace:*", "@playwright/test": "^1.58.2", "@rsbuild/core": "catalog:rsbuild", "nyc": "^17.1.0", diff --git a/packages/web-platform/web-core-wasm-e2e/playwright.config.ts b/packages/web-platform/web-core-e2e/playwright.config.ts similarity index 100% rename from packages/web-platform/web-core-wasm-e2e/playwright.config.ts rename to packages/web-platform/web-core-e2e/playwright.config.ts diff --git a/packages/web-platform/web-core-wasm-e2e/resources/NotoSansSC-Regular.woff2 b/packages/web-platform/web-core-e2e/resources/NotoSansSC-Regular.woff2 similarity index 100% rename from packages/web-platform/web-core-wasm-e2e/resources/NotoSansSC-Regular.woff2 rename to packages/web-platform/web-core-e2e/resources/NotoSansSC-Regular.woff2 diff --git a/packages/web-platform/web-core-wasm-e2e/resources/ddee519472dd7e73eeb153e78d484db3.mp3 b/packages/web-platform/web-core-e2e/resources/ddee519472dd7e73eeb153e78d484db3.mp3 similarity index 100% rename from packages/web-platform/web-core-wasm-e2e/resources/ddee519472dd7e73eeb153e78d484db3.mp3 rename to packages/web-platform/web-core-e2e/resources/ddee519472dd7e73eeb153e78d484db3.mp3 diff --git a/packages/web-platform/web-core-wasm-e2e/resources/firefox-logo.png b/packages/web-platform/web-core-e2e/resources/firefox-logo.png similarity index 100% rename from packages/web-platform/web-core-wasm-e2e/resources/firefox-logo.png rename to packages/web-platform/web-core-e2e/resources/firefox-logo.png diff --git a/packages/web-platform/web-core-wasm-e2e/resources/font.css b/packages/web-platform/web-core-e2e/resources/font.css similarity index 100% rename from packages/web-platform/web-core-wasm-e2e/resources/font.css rename to packages/web-platform/web-core-e2e/resources/font.css diff --git a/packages/web-platform/web-core-wasm-e2e/resources/lynx-logo.jpeg b/packages/web-platform/web-core-e2e/resources/lynx-logo.jpeg similarity index 100% rename from packages/web-platform/web-core-wasm-e2e/resources/lynx-logo.jpeg rename to packages/web-platform/web-core-e2e/resources/lynx-logo.jpeg diff --git a/packages/web-platform/web-core-wasm-e2e/resources/star.png b/packages/web-platform/web-core-e2e/resources/star.png similarity index 100% rename from packages/web-platform/web-core-wasm-e2e/resources/star.png rename to packages/web-platform/web-core-e2e/resources/star.png diff --git a/packages/web-platform/web-core-wasm-e2e/resources/text.txt b/packages/web-platform/web-core-e2e/resources/text.txt similarity index 100% rename from packages/web-platform/web-core-wasm-e2e/resources/text.txt rename to packages/web-platform/web-core-e2e/resources/text.txt diff --git a/packages/web-platform/web-core-wasm-e2e/resources/web-core.main-thread.json b/packages/web-platform/web-core-e2e/resources/web-core.main-thread.json similarity index 100% rename from packages/web-platform/web-core-wasm-e2e/resources/web-core.main-thread.json rename to packages/web-platform/web-core-e2e/resources/web-core.main-thread.json diff --git a/packages/web-platform/web-core-wasm-e2e/rsbuild.config.ts b/packages/web-platform/web-core-e2e/rsbuild.config.ts similarity index 86% rename from packages/web-platform/web-core-wasm-e2e/rsbuild.config.ts rename to packages/web-platform/web-core-e2e/rsbuild.config.ts index 03221a952e..2c16f79761 100644 --- a/packages/web-platform/web-core-wasm-e2e/rsbuild.config.ts +++ b/packages/web-platform/web-core-e2e/rsbuild.config.ts @@ -47,7 +47,7 @@ export default defineConfig({ attrs: { module: 'true', src: - '/node_modules/@lynx-js/web-core-wasm/dist/client_prod/static/js/client.js', + '/node_modules/@lynx-js/web-core/dist/client_prod/static/js/client.js', }, }, { @@ -56,7 +56,7 @@ export default defineConfig({ attrs: { rel: 'stylesheet', href: - '/node_modules/@lynx-js/web-core-wasm/dist/client_prod/static/css/client.css', + '/node_modules/@lynx-js/web-core/dist/client_prod/static/css/client.css', }, }, ], diff --git a/packages/web-platform/web-core-wasm-e2e/scripts/generate-build-command.js b/packages/web-platform/web-core-e2e/scripts/generate-build-command.js similarity index 100% rename from packages/web-platform/web-core-wasm-e2e/scripts/generate-build-command.js rename to packages/web-platform/web-core-e2e/scripts/generate-build-command.js diff --git a/packages/web-platform/web-core-wasm-e2e/server-tests/__snapshots__/server-e2e.test.ts.snap b/packages/web-platform/web-core-e2e/server-tests/__snapshots__/server-e2e.test.ts.snap similarity index 99% rename from packages/web-platform/web-core-wasm-e2e/server-tests/__snapshots__/server-e2e.test.ts.snap rename to packages/web-platform/web-core-e2e/server-tests/__snapshots__/server-e2e.test.ts.snap index cb62dfabaf..13118992ad 100644 --- a/packages/web-platform/web-core-wasm-e2e/server-tests/__snapshots__/server-e2e.test.ts.snap +++ b/packages/web-platform/web-core-e2e/server-tests/__snapshots__/server-e2e.test.ts.snap @@ -1,7 +1,7 @@ // Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html exports[`executeTemplate should run lepusCode.root from basic-element-image-src.web.bundle 1`] = ` -"