diff --git a/.env.example b/.env.example new file mode 100644 index 0000000..6897dcc --- /dev/null +++ b/.env.example @@ -0,0 +1,4 @@ +# Copy to .env (git-ignored) to use a real Iframely API key with the demo +# pages served by `pnpm serve`. scripts/serve.mjs substitutes it into the +# demo HTML at request time; without it the pages use the TEST placeholder. +IFRAMELY_API_KEY= diff --git a/.eslintrc b/.eslintrc deleted file mode 100644 index a6f957a..0000000 --- a/.eslintrc +++ /dev/null @@ -1,51 +0,0 @@ -{ - "env": { - "browser": true, - "commonjs": true, - "es6": true, - "jest": true - }, - "extends": "eslint:recommended", - "parserOptions": { - "sourceType": "module" - }, - "globals": { - "ActiveXObject": true - }, - "rules": { - "indent": [ - "error", - 4, - { - "ignoreComments": true - } - ], - "linebreak-style": [ - "error", - "unix" - ], - "quotes": [ - "error", - "single", - { - "avoidEscape": true - } - ], - "semi": [ - "error", - "always" - ], - "no-console": [ - "warn", - { - "allow": ["warn", "error"] - } - ], - "no-empty": [ - "error", - { - "allowEmptyCatch": true - } - ] - } -} \ No newline at end of file diff --git a/.github/workflows/audit.yml b/.github/workflows/audit.yml new file mode 100644 index 0000000..2768f61 --- /dev/null +++ b/.github/workflows/audit.yml @@ -0,0 +1,47 @@ +name: Audit + +# Compares pnpm audit against the committed audit.log snapshot, so a new +# advisory fails the run until someone reviews it and refreshes the +# snapshot. Every branch audits its own lockfile: on push, and on PRs +# against the merge result. The schedule matters too: advisories change +# over time without any code changes. GitHub only runs schedules on the +# default branch, so a stale snapshot there fails that run, not your +# branch's. +on: + workflow_dispatch: + push: + branches: ['**'] + pull_request: + branches: [dev, main] + schedule: + - cron: '0 6 * * 1' # Mondays 06:00 UTC + +permissions: + contents: read + +jobs: + audit: + runs-on: ubuntu-latest + timeout-minutes: 10 + steps: + - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 + with: + persist-credentials: false + + # Keep in sync with the local pnpm version (and ci.yml). Audit + # works off pnpm-lock.yaml, no install needed. + - uses: pnpm/action-setup@ea17c68df8912ef543352723c149a84f56e3d413 # v6.1.0 + with: + version: 12.14.0 + + - uses: actions/setup-node@949feb2413d6458794dcd2491c4babbbce0c15c1 # v7.1.0 + with: + node-version-file: .node-version + + - name: Verify audit.log matches pnpm audit + run: | + pnpm audit > audit-current.log || true + if ! diff -u --strip-trailing-cr audit.log audit-current.log; then + echo "::error::audit.log is stale. The diff above shows what changed. Review the advisories, then refresh the snapshot with: pnpm audit > audit.log" + exit 1 + fi diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml new file mode 100644 index 0000000..1e8d53a --- /dev/null +++ b/.github/workflows/ci.yml @@ -0,0 +1,89 @@ +name: CI + +on: + push: + branches: [main, dev] + pull_request: + workflow_dispatch: + +permissions: + contents: read + +concurrency: + group: ${{ github.workflow }}-${{ github.ref }} + cancel-in-progress: true + +# Actions are pinned to commit SHAs; the comment names the release. + +jobs: + check: + name: Typecheck, lint, unit tests, build + runs-on: ubuntu-latest + timeout-minutes: 15 + steps: + - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 + with: + persist-credentials: false + + # Keep in sync with the local pnpm version. + - uses: pnpm/action-setup@ea17c68df8912ef543352723c149a84f56e3d413 # v6.1.0 + with: + version: 12.14.0 + + - uses: actions/setup-node@949feb2413d6458794dcd2491c4babbbce0c15c1 # v7.1.0 + with: + node-version-file: .node-version + cache: pnpm + + # Also enforces the lockfile's supply-chain policies. + - run: pnpm install --frozen-lockfile + + # Vulnerabilities: see audit.yml. + - run: pnpm typecheck + - run: pnpm lint + - run: pnpm format:check + - run: pnpm test + + - run: pnpm build + + # dist/ is committed: it must be exactly what the sources build to. + - name: Check that the committed dist/ is up to date + run: | + if [ -n "$(git status --porcelain -- dist)" ]; then + git status --short -- dist + echo "::error::dist/ is out of date. Run 'pnpm build' and commit the result." + exit 1 + fi + + - run: pnpm test:pkg + + e2e: + name: Browser tests + runs-on: ubuntu-latest + timeout-minutes: 20 + steps: + - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 + with: + persist-credentials: false + + - uses: pnpm/action-setup@ea17c68df8912ef543352723c149a84f56e3d413 # v6.1.0 + with: + version: 12.14.0 + + - uses: actions/setup-node@949feb2413d6458794dcd2491c4babbbce0c15c1 # v7.1.0 + with: + node-version-file: .node-version + cache: pnpm + + - run: pnpm install --frozen-lockfile + + - run: pnpm exec playwright install --with-deps chromium firefox webkit + + - run: pnpm test:e2e + + - if: failure() + uses: actions/upload-artifact@cf430e030ddbb5b0abf93d22962f4752f3646cd9 # v7.0.2 + with: + name: playwright-test-results + path: test-results/ + retention-days: 7 diff --git a/.gitignore b/.gitignore index 02ba458..80c5ca2 100644 --- a/.gitignore +++ b/.gitignore @@ -2,3 +2,6 @@ node_modules/ package-lock.json .npmrc +test-results/ +playwright-report/ +.env diff --git a/.node-version b/.node-version new file mode 100644 index 0000000..ca5c350 --- /dev/null +++ b/.node-version @@ -0,0 +1 @@ +24.18.0 diff --git a/CHANGELOG.md b/CHANGELOG.md new file mode 100644 index 0000000..5a1ba90 --- /dev/null +++ b/CHANGELOG.md @@ -0,0 +1,290 @@ +# Changelog + +## 2.0.0 (2026-11-24) + +The first stable release of 2.0 and the first one under the `latest` dist-tag: `npm install @iframely/embed.js` now +installs 2.x. The code is that of 2.0.0-next.6 apart from the wording of one console warning, see the end of this +entry. The entry sums up what is different for a site coming from 1.11.0. The pre-release entries below it list every +change and fix in detail. See [USAGE.md](USAGE.md) for the recipes and the [README](README.md) for self-hosting and +builds. + +### Upgrading from 1.x + +- **Script tag: replace the files.** `dist/embed.js`, `dist/embed-options.js`, `dist/options.js`, + `dist/options.i18n.*.js` and their `.min.js` versions keep their names, still auto-run on `DOMContentLoaded` and + read the same query-string parameters. The `dist/embed-autoplay*` bundles are gone. +- **npm: the package is ESM-only and does not auto-run.** Replace `require('@iframely/embed.js')` or a side-effect + import with `import { iframely } from '@iframely/embed.js'`, and call `iframely.load()` when your markup is in the + DOM, or `iframely.configure({ autorun: true })` right after the import to keep the 1.x behaviour. The exports map + has four entries: `@iframely/embed.js`, `@iframely/embed.js/options`, `@iframely/embed.js/i18n/de` and + `@iframely/embed.js/i18n/fr`; deep imports of files under `dist/` or `src/` are not part of the public API. + `require()` of these entries works on Node 22.12+. +- **Legacy browsers are not supported.** ActiveX/Flash detection, `attachEvent`, vendor-prefixed animation frame + shims and the IE stylesheet fallbacks are gone, and the bundles target Vite's "baseline widely available" set. +- **Options form.** The templates are TypeScript template literals in `src/options/renderer.ts`, so custom `.ejs` + templates are no longer picked up, and every scalar value is HTML-escaped. Element ids (and the labels' `for`) are + prefixed with the form id passed to `buildOptionsForm`, e.g. `w1-_hide` instead of `_hide`; input names are + unchanged. `iframely.optionsTranslator` exists once an i18n bundle has registered its labels. +- **Query strings** (script `src`, `data-iframely-url`): a value keeps everything after the first `=`, and a key + without a value reads as `''` instead of `"undefined"`. +- **One copy per page.** When a 1.x `embed.js` (such as the cloud script that API embed codes include) initialises + `window.iframely` first, a 2.x copy logs a console warning and does not start. Request API embed codes with + `omit_script=1` or load your copy first. +- **Renamed, with the old names still working:** `iframely.extendOptions` is `iframely.configure`, + `iframely.VERSION` is `iframely.API_VERSION` (assigning `VERSION` no longer changes the `v=` parameter), and the + `heightChanged` event is `height-changed`. The `iframely.widgets` and `iframely.events` namespaces are deprecated + in favour of `iframely.load`, `iframely.on` and `iframely.trigger`. `?cancel=0` and + `iframely.RECOVER_HREFS_ON_CANCEL = true` keep working next to the new `cancel_link` key. +- **To stay on 1.x**, pin it: `npm install @iframely/embed.js@1`. +- **Building from source** requires Node 24 and pnpm. The build is Vite 8 with TypeScript 7, oxlint and oxfmt; + webpack, ejs-loader and ESLint are removed. Consumers of the npm package are not affected. + +### New since 1.11.0 + +- An ES module build for bundlers, with TypeScript declarations, source maps and typed events (`IframelyEvents`), + config (`IframelyConfig`) and `load()` overloads. +- Server-side rendering support: importing any entry without a `window` yields an inert stub, so the module can be + imported at the top level in SvelteKit, Next.js and the like. +- `iframely.configure(options)` merges configuration from code. The `cdn` key now sets the iframe host, and a `nonce` + configured after the import reaches the default styles. +- `iframely.load(container)` builds only the embeds inside an element, document fragment or shadow root, and + `iframely.unload(container?)` removes the widgets the library built and releases their observers and timers. +- `iframely.on()` returns a function that removes the subscription, and `iframely.off(event, cb)` removes a listener. +- An `iframe-sized` event fires each time an embed reports its size and the library has applied it. +- A `cancel_link` config key (`'text'`, `'url'` or `false`) says what a cancelled embed leaves in its place. +- `iframely.LIB_VERSION` names the release that booted the page, and every bundle in `dist/` starts with a + `/*! @iframely/embed.js | MIT | ... */` banner. +- `iframely.SUPPORT_IFRAME_LOADING_ATTR` is feature-detected instead of derived from a Chrome version sniff. +- [USAGE.md](USAGE.md), a recipe guide for the script tag, bundlers, SSR frameworks and the options form; demo pages + under `demo/`; and a test suite (Vitest, Playwright in three browsers, and a check of the packed npm tarball). + +### Fixed since 1.11.0 + +- The options form no longer throws on pages without lodash: the group template compiled to an unbundled `_.escape` + call. Other options form, import widget and messaging fixes are listed under the pre-releases below. + +### Changed since 2.0.0-next.6 + +- The console warning about another copy of embed.js that initialised `window.iframely` first describes a copy + without `LIB_VERSION` as `1.x`. It used to add `or 2.0.0-next.1`, a pre-release that was never published. +- Development: Vitest 5, jsdom 31, oxfmt 0.80 and oxlint 1.95. `@types/node` is now a direct dev dependency; the + typecheck used to get it transitively. + +## 2.0.0-next.6 (2026-11-17) + +Sixth pre-release of 2.0, under the `next` dist-tag (`npm install @iframely/embed.js@next`); `latest` stays on 1.x. +The `cancel_link` config key and a `nonce` that can be configured after the import, on top of 2.0.0-next.5. + +### Added + +- A `cancel_link` config key says what a cancelled embed (no embed for the URL) leaves in its place: `'text'`, the + default and the behaviour so far, a link when the original `` had text; `'url'`, a link in any case, with the + URL as its text when there was none; `false`, nothing, for pages that render their own fallback from a `cancel` + listener and used to get the library's link next to it. It works in `configure()`, the pre-set config and the + script `src`. `?cancel=0` and `iframely.RECOVER_HREFS_ON_CANCEL = true`, the only ways to get `'url'` until now, + keep working. An unsupported value is reported with a console warning. +- USAGE.md describes what a cancelled embed leaves behind and when a `cancel` listener should render its own + fallback. +- TypeScript: `cancelWidget()` and `openHref()` are declared on `Iframely`. + +### Fixed + +- `iframely.configure({ nonce })` called after the library has booted now reaches the default styles. They were + inserted once, at boot, so with the npm module (which boots at import, before any `configure()`) a `style-src` + Content-Security-Policy blocked them and embeds lost their responsive sizing; only a nonce in the script `src` or + the pre-set config worked. The `