diff --git a/.editorconfig b/.editorconfig new file mode 100644 index 0000000..cbd19a9 --- /dev/null +++ b/.editorconfig @@ -0,0 +1,20 @@ +# EditorConfig is awesome: https://EditorConfig.org +root = true + +[*] +charset = utf-8 +indent_size = 2 +indent_style = tab +insert_final_newline = true +trim_trailing_whitespace = true + +[*.{yml,yaml}] +indent_style = space + +[*.{cjs,js,mjs,ts}] +block_comment_start = /* +block_comment = * +block_comment_end = */ + +[*.{markdown,md}] +trim_trailing_whitespace = false diff --git a/.github/workflows/stale.yml b/.github/workflows/stale.yml new file mode 100644 index 0000000..78fc30c --- /dev/null +++ b/.github/workflows/stale.yml @@ -0,0 +1,22 @@ +name: 'Stale issues and PR' +on: + schedule: + - cron: '30 1 * * *' + +jobs: + stale: + runs-on: ubuntu-latest + steps: + - uses: actions/stale@v4 + with: + stale-issue-label: stale + stale-pr-label: stale + stale-issue-message: 'This issue is stale because it has been open 30 days with no activity. Remove stale label or comment or this will be closed in 14 days.' + stale-pr-message: 'This PR is stale because it has been open 30 days with no activity. Remove stale label or comment or this will be closed in 14 days.' + close-issue-message: 'This issue was closed because it has been stalled for 14 days with no activity.' + close-pr-message: 'This PR was closed because it has been stalled for 14 days with no activity.' + days-before-issue-stale: 30 + days-before-pr-stale: 30 + days-before-issue-close: 14 + days-before-pr-close: 14 + exempt-issue-labels: 'bug,enhancement,stale-exempt' diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml new file mode 100644 index 0000000..3c4c7fb --- /dev/null +++ b/.github/workflows/test.yml @@ -0,0 +1,94 @@ +name: CI + +on: + push: + paths: + - '.github/**' + - 'src/**' + - 'tests/**' + - 'types/**' + - 'package.json' + - 'pnpm-lock.yaml' + pull_request: + paths: + - '.github/**' + - 'src/**' + - 'tests/**' + - 'types/**' + - 'package.json' + - 'pnpm-lock.yaml' + workflow_dispatch: + +jobs: + default: + runs-on: ${{ matrix.os }} + strategy: + fail-fast: false + matrix: + node-version: ['lts/*', '*'] + os: [macos-latest, ubuntu-latest, windows-latest] + + steps: + - uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1 + with: + fetch-depth: 10 + + - name: Install NSIS (macOS) + if: matrix.os == 'macos-latest' + run: | + brew update + brew install nsis + + - name: Install NSIS (Ubuntu) + if: matrix.os == 'ubuntu-latest' + run: | + sudo apt-get -y update + sudo apt-get -y install nsis + + - name: Install NSIS (Windows) + if: matrix.os == 'windows-latest' + shell: pwsh + run: | + [Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12 + iwr -useb get.scoop.sh -outfile 'install.ps1' + .\install.ps1 -RunAsAdmin + scoop bucket add nsis https://github.com/NSIS-Dev/scoop-nsis + scoop install nsis/nsis + + - name: Print NSIS version + run: makensis -VERSION + + - name: Print NSIS header info + run: makensis -HDRINFO + + - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 + with: + node-version: ${{ matrix.node-version }} + + - name: Enable Corepack + run: corepack enable + + - name: Get pnpm store directory + id: pnpm-cache + run: | + echo "::set-output name=pnpm_store_path::$(pnpm store path)" + + - uses: actions/cache@13aacd865c20de90d75de3b17ebe84f7a17d57d2 # v4.0.0 + name: Setup pnpm cache + with: + path: ${{ steps.pnpm-cache.outputs.pnpm_store_path }} + key: ${{ runner.os }}-pnpm-store-${{ hashFiles('**/pnpm-lock.yaml') }} + restore-keys: | + ${{ runner.os }}-pnpm-store- + + - name: Install dependencies + run: pnpm install --frozen-lockfile --strict-peer-dependencies + + - name: Lint Source + run: pnpm run --if-present lint + + - name: Build Source + run: pnpm run --if-present build + + - name: Run Tests + run: pnpm run --if-present test diff --git a/.npmrc b/.npmrc new file mode 100644 index 0000000..b6f27f1 --- /dev/null +++ b/.npmrc @@ -0,0 +1 @@ +engine-strict=true diff --git a/.vite-config/.gitignore b/.vite-config/.gitignore new file mode 100644 index 0000000..f324b9d --- /dev/null +++ b/.vite-config/.gitignore @@ -0,0 +1 @@ +*.ts.timestamp-*.mjs \ No newline at end of file diff --git a/.vite-config/iframe.ts b/.vite-config/iframe.ts new file mode 100644 index 0000000..9269279 --- /dev/null +++ b/.vite-config/iframe.ts @@ -0,0 +1,16 @@ +import { defineConfig } from 'vite'; +import { resolve } from 'node:path'; +import { svelte } from '@sveltejs/vite-plugin-svelte'; +import mkcert from 'vite-plugin-mkcert'; + +// https://vitejs.dev/config/ +export default defineConfig({ + define: { + PAGE_TYPE: JSON.stringify('iframe') + }, + plugins: [ + mkcert(), + svelte(), + ], + root: resolve(process.cwd(), 'demo'), +}); diff --git a/.vite-config/main.ts b/.vite-config/main.ts new file mode 100644 index 0000000..5f2912e --- /dev/null +++ b/.vite-config/main.ts @@ -0,0 +1,16 @@ +import { defineConfig } from 'vite'; +import { resolve } from 'node:path'; +import { svelte } from '@sveltejs/vite-plugin-svelte'; +import mkcert from 'vite-plugin-mkcert'; + +// https://vitejs.dev/config/ +export default defineConfig({ + define: { + PAGE_TYPE: JSON.stringify('main') + }, + plugins: [ + mkcert(), + svelte(), + ], + root: resolve(process.cwd(), 'demo') +}) diff --git a/.vscode/extensions.json b/.vscode/extensions.json new file mode 100644 index 0000000..bdef820 --- /dev/null +++ b/.vscode/extensions.json @@ -0,0 +1,3 @@ +{ + "recommendations": ["svelte.svelte-vscode"] +} diff --git a/README.md b/README.md new file mode 100644 index 0000000..8649a2e --- /dev/null +++ b/README.md @@ -0,0 +1,49 @@ +# svelte-crossorigin-store + +> Share your Svelte store across origins, including iFrames. + +[![License](https://img.shields.io/github/license/idleberg/svelte-crossorigin-store?color=blue&style=for-the-badge)](https://github.com/idleberg/svelte-crossorigin-store/blob/main/LICENSE) +[![Version](https://img.shields.io/npm/v/svelte-crossorigin-store?style=for-the-badge)](https://www.npmjs.org/package/svelte-crossorigin-store) +[![Build](https://img.shields.io/github/actions/workflow/status/idleberg/svelte-crossorigin-store/default.yml?style=for-the-badge)](https://github.com/idleberg/svelte-crossorigin-store/actions) + +**Features** + +- framesynchronizes across multiple origins +- supports iFrames +- tiny (<700 bytes minified, before gzip) + +## Installation + +`npm install svelte-crossorigin-store` + +## Usage + +### Import + +```svelte + + +

{$store}

+``` + +### Methods + +The created store exposes the same API methods like a writable `svelte/store`: + +- `set()` +- `update()` +- `subscribe()` + +Please refer to the [official documentation](https://svelte.dev/docs/svelte-store#writable). + +## License + +This work is licensed under [The MIT License](LICENSE) + +[dot notation]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Property_accessors#Dot_notation +[storage api]: https://developer.mozilla.org/en-US/docs/Web/API/Storage +[indexeddb api]: https://developer.mozilla.org/en-US/docs/Web/API/IndexedDB_API diff --git a/demo/index.html b/demo/index.html new file mode 100644 index 0000000..44da6aa --- /dev/null +++ b/demo/index.html @@ -0,0 +1,13 @@ + + + + + + + Demo Page + + +
+ + + diff --git a/demo/public/favicon.svg b/demo/public/favicon.svg new file mode 100644 index 0000000..6cc60e7 --- /dev/null +++ b/demo/public/favicon.svg @@ -0,0 +1 @@ +💌 \ No newline at end of file diff --git a/demo/src/App.svelte b/demo/src/App.svelte new file mode 100644 index 0000000..81df52f --- /dev/null +++ b/demo/src/App.svelte @@ -0,0 +1,45 @@ + + +{#if PAGE_TYPE === 'main'} + + + +

Demo Page

+

Change the counter in any of these origins to see the state being synched.

+
+
+ + + +
+ + + + + +