Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@github/include-fragment-element

Package Overview
Dependencies
Maintainers
20
Versions
23
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@github/include-fragment-element - npm Package Compare versions

Comparing version 6.1.1 to 6.2.0

dist/bundle.js

38

dist/index.d.ts

@@ -1,34 +0,4 @@

interface CSPTrustedTypesPolicy {
createHTML: (s: string, response: Response) => CSPTrustedHTMLToStringable;
}
interface CSPTrustedHTMLToStringable {
toString: () => string;
}
export default class IncludeFragmentElement extends HTMLElement {
#private;
static setCSPTrustedTypesPolicy(policy: CSPTrustedTypesPolicy | Promise<CSPTrustedTypesPolicy> | null): void;
static get observedAttributes(): string[];
get src(): string;
set src(val: string);
get loading(): 'eager' | 'lazy';
set loading(value: 'eager' | 'lazy');
get accept(): string;
set accept(val: string);
get data(): Promise<string>;
attributeChangedCallback(attribute: string, oldVal: string | null): void;
constructor();
connectedCallback(): void;
request(): Request;
load(): Promise<string>;
fetch(request: RequestInfo): Promise<Response>;
refetch(): void;
}
declare global {
interface Window {
IncludeFragmentElement: typeof IncludeFragmentElement;
}
interface HTMLElementTagNameMap {
'include-fragment': IncludeFragmentElement;
}
}
export {};
import { IncludeFragmentElement } from './include-fragment-element.js';
export { IncludeFragmentElement };
export default IncludeFragmentElement;
export * from './include-fragment-element-define.js';

@@ -1,209 +0,4 @@

var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
};
var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
if (kind === "m") throw new TypeError("Private method is not writable");
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it");
return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
};
var _IncludeFragmentElement_instances, _IncludeFragmentElement_busy, _IncludeFragmentElement_observer, _IncludeFragmentElement_handleData, _IncludeFragmentElement_getData, _IncludeFragmentElement_getStringOrErrorData, _IncludeFragmentElement_task, _IncludeFragmentElement_fetchDataWithEvents;
const privateData = new WeakMap();
function isWildcard(accept) {
return accept && !!accept.split(',').find(x => x.match(/^\s*\*\/\*/));
}
let cspTrustedTypesPolicyPromise = null;
export default class IncludeFragmentElement extends HTMLElement {
static setCSPTrustedTypesPolicy(policy) {
cspTrustedTypesPolicyPromise = policy === null ? policy : Promise.resolve(policy);
}
static get observedAttributes() {
return ['src', 'loading'];
}
get src() {
const src = this.getAttribute('src');
if (src) {
const link = this.ownerDocument.createElement('a');
link.href = src;
return link.href;
}
else {
return '';
}
}
set src(val) {
this.setAttribute('src', val);
}
get loading() {
if (this.getAttribute('loading') === 'lazy')
return 'lazy';
return 'eager';
}
set loading(value) {
this.setAttribute('loading', value);
}
get accept() {
return this.getAttribute('accept') || '';
}
set accept(val) {
this.setAttribute('accept', val);
}
get data() {
return __classPrivateFieldGet(this, _IncludeFragmentElement_instances, "m", _IncludeFragmentElement_getStringOrErrorData).call(this);
}
attributeChangedCallback(attribute, oldVal) {
if (attribute === 'src') {
if (this.isConnected && this.loading === 'eager') {
__classPrivateFieldGet(this, _IncludeFragmentElement_instances, "m", _IncludeFragmentElement_handleData).call(this);
}
}
else if (attribute === 'loading') {
if (this.isConnected && oldVal !== 'eager' && this.loading === 'eager') {
__classPrivateFieldGet(this, _IncludeFragmentElement_instances, "m", _IncludeFragmentElement_handleData).call(this);
}
}
}
constructor() {
super();
_IncludeFragmentElement_instances.add(this);
_IncludeFragmentElement_busy.set(this, false);
_IncludeFragmentElement_observer.set(this, new IntersectionObserver(entries => {
for (const entry of entries) {
if (entry.isIntersecting) {
const { target } = entry;
__classPrivateFieldGet(this, _IncludeFragmentElement_observer, "f").unobserve(target);
if (!(target instanceof IncludeFragmentElement))
return;
if (target.loading === 'lazy') {
__classPrivateFieldGet(this, _IncludeFragmentElement_instances, "m", _IncludeFragmentElement_handleData).call(this);
}
}
}
}, {
rootMargin: '0px 0px 256px 0px',
threshold: 0.01
}));
const shadowRoot = this.attachShadow({ mode: 'open' });
const style = document.createElement('style');
style.textContent = `:host {display: block;}`;
shadowRoot.append(style, document.createElement('slot'));
}
connectedCallback() {
if (this.src && this.loading === 'eager') {
__classPrivateFieldGet(this, _IncludeFragmentElement_instances, "m", _IncludeFragmentElement_handleData).call(this);
}
if (this.loading === 'lazy') {
__classPrivateFieldGet(this, _IncludeFragmentElement_observer, "f").observe(this);
}
}
request() {
const src = this.src;
if (!src) {
throw new Error('missing src');
}
return new Request(src, {
method: 'GET',
credentials: 'same-origin',
headers: {
Accept: this.accept || 'text/html'
}
});
}
load() {
return __classPrivateFieldGet(this, _IncludeFragmentElement_instances, "m", _IncludeFragmentElement_getStringOrErrorData).call(this);
}
fetch(request) {
return fetch(request);
}
refetch() {
privateData.delete(this);
__classPrivateFieldGet(this, _IncludeFragmentElement_instances, "m", _IncludeFragmentElement_handleData).call(this);
}
}
_IncludeFragmentElement_busy = new WeakMap(), _IncludeFragmentElement_observer = new WeakMap(), _IncludeFragmentElement_instances = new WeakSet(), _IncludeFragmentElement_handleData = async function _IncludeFragmentElement_handleData() {
if (__classPrivateFieldGet(this, _IncludeFragmentElement_busy, "f"))
return;
__classPrivateFieldSet(this, _IncludeFragmentElement_busy, true, "f");
__classPrivateFieldGet(this, _IncludeFragmentElement_observer, "f").unobserve(this);
try {
const data = await __classPrivateFieldGet(this, _IncludeFragmentElement_instances, "m", _IncludeFragmentElement_getData).call(this);
if (data instanceof Error) {
throw data;
}
const dataTreatedAsString = data;
const template = document.createElement('template');
template.innerHTML = dataTreatedAsString;
const fragment = document.importNode(template.content, true);
const canceled = !this.dispatchEvent(new CustomEvent('include-fragment-replace', { cancelable: true, detail: { fragment } }));
if (canceled) {
__classPrivateFieldSet(this, _IncludeFragmentElement_busy, false, "f");
return;
}
this.replaceWith(fragment);
this.dispatchEvent(new CustomEvent('include-fragment-replaced'));
}
catch (_a) {
this.classList.add('is-error');
}
finally {
__classPrivateFieldSet(this, _IncludeFragmentElement_busy, false, "f");
}
}, _IncludeFragmentElement_getData = async function _IncludeFragmentElement_getData() {
const src = this.src;
const cachedData = privateData.get(this);
if (cachedData && cachedData.src === src) {
return cachedData.data;
}
else {
let data;
if (src) {
data = __classPrivateFieldGet(this, _IncludeFragmentElement_instances, "m", _IncludeFragmentElement_fetchDataWithEvents).call(this);
}
else {
data = Promise.reject(new Error('missing src'));
}
privateData.set(this, { src, data });
return data;
}
}, _IncludeFragmentElement_getStringOrErrorData = async function _IncludeFragmentElement_getStringOrErrorData() {
const data = await __classPrivateFieldGet(this, _IncludeFragmentElement_instances, "m", _IncludeFragmentElement_getData).call(this);
if (data instanceof Error) {
throw data;
}
return data.toString();
}, _IncludeFragmentElement_task = async function _IncludeFragmentElement_task(eventsToDispatch) {
await new Promise(resolve => setTimeout(resolve, 0));
for (const eventType of eventsToDispatch) {
this.dispatchEvent(new Event(eventType));
}
}, _IncludeFragmentElement_fetchDataWithEvents = async function _IncludeFragmentElement_fetchDataWithEvents() {
try {
await __classPrivateFieldGet(this, _IncludeFragmentElement_instances, "m", _IncludeFragmentElement_task).call(this, ['loadstart']);
const response = await this.fetch(this.request());
if (response.status !== 200) {
throw new Error(`Failed to load resource: the server responded with a status of ${response.status}`);
}
const ct = response.headers.get('Content-Type');
if (!isWildcard(this.accept) && (!ct || !ct.includes(this.accept ? this.accept : 'text/html'))) {
throw new Error(`Failed to load resource: expected ${this.accept || 'text/html'} but was ${ct}`);
}
const responseText = await response.text();
let data = responseText;
if (cspTrustedTypesPolicyPromise) {
const cspTrustedTypesPolicy = await cspTrustedTypesPolicyPromise;
data = cspTrustedTypesPolicy.createHTML(responseText, response);
}
__classPrivateFieldGet(this, _IncludeFragmentElement_instances, "m", _IncludeFragmentElement_task).call(this, ['load', 'loadend']);
return data;
}
catch (error) {
__classPrivateFieldGet(this, _IncludeFragmentElement_instances, "m", _IncludeFragmentElement_task).call(this, ['error', 'loadend']);
throw error;
}
};
if (!window.customElements.get('include-fragment')) {
window.IncludeFragmentElement = IncludeFragmentElement;
window.customElements.define('include-fragment', IncludeFragmentElement);
}
import { IncludeFragmentElement } from './include-fragment-element.js';
export { IncludeFragmentElement };
export default IncludeFragmentElement;
export * from './include-fragment-element-define.js';
{
"name": "@github/include-fragment-element",
"version": "6.1.1",
"version": "6.2.0",
"main": "dist/index.js",

@@ -13,25 +13,36 @@ "module": "dist/index.js",

],
"exports": {
".": "./dist/index.js",
"./define": "./dist/index.js",
"./include-fragment": "./dist/include-fragment-element.js",
"./include-fragment/define": "./dist/include-fragment-element-define.js"
},
"scripts": {
"clean": "rm -rf dist",
"lint": "eslint . --ext .js,.ts && tsc --noEmit",
"format": "eslint --fix . --ext .js,.ts",
"lint:fix": "eslint --fix . --ext .js,.ts",
"prebuild": "npm run clean && npm run lint && mkdir dist",
"build": "tsc",
"bundle": "esbuild --bundle dist/index.js --keep-names --outfile=dist/bundle.js --format=esm",
"build": "tsc && npm run bundle && npm run manifest",
"prepublishOnly": "npm run build",
"pretest": "npm run build",
"test": "web-test-runner",
"prepublishOnly": "npm run build",
"postpublish": "npm publish --ignore-scripts --@github:registry='https://npm.pkg.github.com'"
"postpublish": "npm publish --ignore-scripts --@github:registry='https://npm.pkg.github.com'",
"manifest": "custom-elements-manifest analize"
},
"prettier": "@github/prettier-config",
"devDependencies": {
"@github/prettier-config": "0.0.4",
"@open-wc/testing": "^3.1.7",
"@web/dev-server-esbuild": "^0.3.3",
"@web/test-runner": "^0.15.0",
"@web/test-runner-playwright": "^0.9.0",
"esbuild": "^0.15.15",
"eslint": "^8.12.0",
"eslint-plugin-github": "^4.3.6",
"typescript": "^4.3.5"
"@custom-elements-manifest/analyzer": "^0.8.3",
"@github/prettier-config": "^0.0.6",
"@open-wc/testing": "^3.1.8",
"@web/dev-server-esbuild": "^0.4.1",
"@web/test-runner": "^0.16.1",
"@web/test-runner-playwright": "^0.10.1",
"esbuild": "^0.17.19",
"eslint": "^8.42.0",
"eslint-plugin-custom-elements": "^0.0.8",
"eslint-plugin-github": "^4.8.0",
"typescript": "^5.1.3"
},
"customElements": "custom-elements.json",
"eslintIgnore": [

@@ -38,0 +49,0 @@ "dist/"

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc