rebill-web-components-sdk 1.10.13 → 1.11.0-beta.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/index-C-VTnc0I.js.map +1 -1
- package/dist/cjs/loader.cjs.js +1 -1
- package/dist/cjs/rebill-checkout.cjs.entry.js +147 -40
- package/dist/cjs/rebill-checkout.entry.cjs.js.map +1 -1
- package/dist/cjs/rebill-web-components-sdk.cjs.js +1 -1
- package/dist/collection/components/checkout/rebill-checkout.js +49 -40
- package/dist/collection/components/checkout/rebill-checkout.js.map +1 -1
- package/dist/collection/utils/index.js +2 -0
- package/dist/collection/utils/index.js.map +1 -1
- package/dist/collection/utils/resource-injector.js +118 -0
- package/dist/collection/utils/resource-injector.js.map +1 -0
- package/dist/components/p-8BpuJ_V5.js.map +1 -1
- package/dist/components/rebill-checkout.js +148 -40
- package/dist/components/rebill-checkout.js.map +1 -1
- package/dist/esm/index-BTZ7D7jU.js.map +1 -1
- package/dist/esm/loader.js +1 -1
- package/dist/esm/rebill-checkout.entry.js +147 -40
- package/dist/esm/rebill-checkout.entry.js.map +1 -1
- package/dist/esm/rebill-web-components-sdk.js +1 -1
- package/dist/rebill-web-components-sdk/p-457f405c.entry.js +2 -0
- package/dist/rebill-web-components-sdk/p-457f405c.entry.js.map +1 -0
- package/dist/rebill-web-components-sdk/p-BTZ7D7jU.js.map +1 -1
- package/dist/rebill-web-components-sdk/rebill-checkout.entry.esm.js.map +1 -1
- package/dist/rebill-web-components-sdk/rebill-web-components-sdk.esm.js +1 -1
- package/dist/types/components/checkout/rebill-checkout.d.ts +14 -0
- package/dist/types/components.d.ts +8 -0
- package/dist/types/utils/index.d.ts +1 -0
- package/dist/types/utils/resource-injector.d.ts +29 -0
- package/package.json +1 -1
- package/dist/rebill-web-components-sdk/p-4b4e2e73.entry.js +0 -2
- package/dist/rebill-web-components-sdk/p-4b4e2e73.entry.js.map +0 -1
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Utility functions for injecting custom CSS and JavaScript resources into the document
|
|
3
|
+
*/
|
|
4
|
+
/**
|
|
5
|
+
* Checks if a string is a URL (http, https, or protocol-relative)
|
|
6
|
+
*/
|
|
7
|
+
function isUrl(content) {
|
|
8
|
+
return (content.startsWith('http://') || content.startsWith('https://') || content.startsWith('//'));
|
|
9
|
+
}
|
|
10
|
+
/**
|
|
11
|
+
* Generates a unique ID for injected resources
|
|
12
|
+
*/
|
|
13
|
+
function generateResourceId(prefix) {
|
|
14
|
+
return `${prefix}-${Date.now()}-${Math.random().toString(36).substr(2, 9)}`;
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* Creates a CSS link element for loading CSS from a URL
|
|
18
|
+
*/
|
|
19
|
+
function createCssLinkElement(url, id) {
|
|
20
|
+
const linkElement = document.createElement('link');
|
|
21
|
+
linkElement.rel = 'stylesheet';
|
|
22
|
+
linkElement.href = url;
|
|
23
|
+
linkElement.id = id;
|
|
24
|
+
linkElement.setAttribute('data-rebill-injected', 'true');
|
|
25
|
+
return linkElement;
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* Creates a style element for injecting raw CSS
|
|
29
|
+
*/
|
|
30
|
+
function createStyleElement(css, id) {
|
|
31
|
+
const styleElement = document.createElement('style');
|
|
32
|
+
styleElement.id = id;
|
|
33
|
+
styleElement.setAttribute('data-rebill-injected', 'true');
|
|
34
|
+
styleElement.textContent = css;
|
|
35
|
+
return styleElement;
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* Creates a script element for loading JavaScript from a URL
|
|
39
|
+
*/
|
|
40
|
+
function createScriptLinkElement(url, id) {
|
|
41
|
+
const scriptElement = document.createElement('script');
|
|
42
|
+
scriptElement.src = url;
|
|
43
|
+
scriptElement.id = id;
|
|
44
|
+
scriptElement.setAttribute('data-rebill-injected', 'true');
|
|
45
|
+
scriptElement.async = true;
|
|
46
|
+
return scriptElement;
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* Creates a script element for injecting raw JavaScript
|
|
50
|
+
*/
|
|
51
|
+
function createScriptElement(js, id) {
|
|
52
|
+
const scriptElement = document.createElement('script');
|
|
53
|
+
scriptElement.id = id;
|
|
54
|
+
scriptElement.setAttribute('data-rebill-injected', 'true');
|
|
55
|
+
scriptElement.textContent = js;
|
|
56
|
+
return scriptElement;
|
|
57
|
+
}
|
|
58
|
+
/**
|
|
59
|
+
* Removes an injected resource element from the DOM
|
|
60
|
+
*/
|
|
61
|
+
function removeInjectedResource(element) {
|
|
62
|
+
if (!element) {
|
|
63
|
+
return;
|
|
64
|
+
}
|
|
65
|
+
try {
|
|
66
|
+
element.remove();
|
|
67
|
+
}
|
|
68
|
+
catch (error) {
|
|
69
|
+
console.warn('Error removing injected resource:', error);
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
/**
|
|
73
|
+
* Injects custom CSS into the document
|
|
74
|
+
* @param css - CSS content (raw CSS string or URL)
|
|
75
|
+
* @param existingElement - Optional existing injected element to clean up first
|
|
76
|
+
* @returns The injected element or null if no CSS was provided
|
|
77
|
+
*/
|
|
78
|
+
export function injectCSS(css, existingElement = null) {
|
|
79
|
+
if (!css) {
|
|
80
|
+
return null;
|
|
81
|
+
}
|
|
82
|
+
// Clean up existing element if provided
|
|
83
|
+
removeInjectedResource(existingElement);
|
|
84
|
+
const cssId = generateResourceId('rebill-checkout-css');
|
|
85
|
+
const element = isUrl(css) ? createCssLinkElement(css, cssId) : createStyleElement(css, cssId);
|
|
86
|
+
document.head.appendChild(element);
|
|
87
|
+
return element;
|
|
88
|
+
}
|
|
89
|
+
/**
|
|
90
|
+
* Injects custom JavaScript into the document
|
|
91
|
+
* @param js - JavaScript content (raw JS string or URL)
|
|
92
|
+
* @param existingElement - Optional existing injected element to clean up first
|
|
93
|
+
* @returns The injected element or null if no JS was provided
|
|
94
|
+
*/
|
|
95
|
+
export function injectJS(js, existingElement = null) {
|
|
96
|
+
if (!js) {
|
|
97
|
+
return null;
|
|
98
|
+
}
|
|
99
|
+
// Clean up existing element if provided
|
|
100
|
+
removeInjectedResource(existingElement);
|
|
101
|
+
const jsId = generateResourceId('rebill-checkout-js');
|
|
102
|
+
const element = isUrl(js) ? createScriptLinkElement(js, jsId) : createScriptElement(js, jsId);
|
|
103
|
+
document.head.appendChild(element);
|
|
104
|
+
return element;
|
|
105
|
+
}
|
|
106
|
+
/**
|
|
107
|
+
* Cleans up injected CSS element
|
|
108
|
+
*/
|
|
109
|
+
export function cleanupCSS(element) {
|
|
110
|
+
removeInjectedResource(element);
|
|
111
|
+
}
|
|
112
|
+
/**
|
|
113
|
+
* Cleans up injected JavaScript element
|
|
114
|
+
*/
|
|
115
|
+
export function cleanupJS(element) {
|
|
116
|
+
removeInjectedResource(element);
|
|
117
|
+
}
|
|
118
|
+
//# sourceMappingURL=resource-injector.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"resource-injector.js","sourceRoot":"","sources":["../../src/utils/resource-injector.ts"],"names":[],"mappings":"AAAA;;GAEG;AAOH;;GAEG;AACH,SAAS,KAAK,CAAC,OAAe;IAC5B,OAAO,CACL,OAAO,CAAC,UAAU,CAAC,SAAS,CAAC,IAAI,OAAO,CAAC,UAAU,CAAC,UAAU,CAAC,IAAI,OAAO,CAAC,UAAU,CAAC,IAAI,CAAC,CAC5F,CAAC;AACJ,CAAC;AAED;;GAEG;AACH,SAAS,kBAAkB,CAAC,MAAc;IACxC,OAAO,GAAG,MAAM,IAAI,IAAI,CAAC,GAAG,EAAE,IAAI,IAAI,CAAC,MAAM,EAAE,CAAC,QAAQ,CAAC,EAAE,CAAC,CAAC,MAAM,CAAC,CAAC,EAAE,CAAC,CAAC,EAAE,CAAC;AAC9E,CAAC;AAED;;GAEG;AACH,SAAS,oBAAoB,CAAC,GAAW,EAAE,EAAU;IACnD,MAAM,WAAW,GAAG,QAAQ,CAAC,aAAa,CAAC,MAAM,CAAC,CAAC;IACnD,WAAW,C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AC;IACnC,OAAO,OAAO,CAAC;AACjB,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,UAAU,CAAC,OAA2B;IACpD,sBAAsB,CAAC,OAAO,CAAC,CAAC;AAClC,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,SAAS,CAAC,OAA2B;IACnD,sBAAsB,CAAC,OAAO,CAAC,CAAC;AAClC,CAAC","sourcesContent":["/**\n * Utility functions for injecting custom CSS and JavaScript resources into the document\n */\n\nexport interface InjectedResource {\n element: HTMLElement;\n id: string;\n}\n\n/**\n * Checks if a string is a URL (http, https, or protocol-relative)\n */\nfunction isUrl(content: string): boolean {\n return (\n content.startsWith('http://') || content.startsWith('https://') || content.startsWith('//')\n );\n}\n\n/**\n * Generates a unique ID for injected resources\n */\nfunction generateResourceId(prefix: string): string {\n return `${prefix}-${Date.now()}-${Math.random().toString(36).substr(2, 9)}`;\n}\n\n/**\n * Creates a CSS link element for loading CSS from a URL\n */\nfunction createCssLinkElement(url: string, id: string): HTMLLinkElement {\n const linkElement = document.createElement('link');\n linkElement.rel = 'stylesheet';\n linkElement.href = url;\n linkElement.id = id;\n linkElement.setAttribute('data-rebill-injected', 'true');\n return linkElement;\n}\n\n/**\n * Creates a style element for injecting raw CSS\n */\nfunction createStyleElement(css: string, id: string): HTMLStyleElement {\n const styleElement = document.createElement('style');\n styleElement.id = id;\n styleElement.setAttribute('data-rebill-injected', 'true');\n styleElement.textContent = css;\n return styleElement;\n}\n\n/**\n * Creates a script element for loading JavaScript from a URL\n */\nfunction createScriptLinkElement(url: string, id: string): HTMLScriptElement {\n const scriptElement = document.createElement('script');\n scriptElement.src = url;\n scriptElement.id = id;\n scriptElement.setAttribute('data-rebill-injected', 'true');\n scriptElement.async = true;\n return scriptElement;\n}\n\n/**\n * Creates a script element for injecting raw JavaScript\n */\nfunction createScriptElement(js: string, id: string): HTMLScriptElement {\n const scriptElement = document.createElement('script');\n scriptElement.id = id;\n scriptElement.setAttribute('data-rebill-injected', 'true');\n scriptElement.textContent = js;\n return scriptElement;\n}\n\n/**\n * Removes an injected resource element from the DOM\n */\nfunction removeInjectedResource(element: HTMLElement | null): void {\n if (!element) {\n return;\n }\n\n try {\n element.remove();\n } catch (error) {\n console.warn('Error removing injected resource:', error);\n }\n}\n\n/**\n * Injects custom CSS into the document\n * @param css - CSS content (raw CSS string or URL)\n * @param existingElement - Optional existing injected element to clean up first\n * @returns The injected element or null if no CSS was provided\n */\nexport function injectCSS(\n css: string | undefined,\n existingElement: HTMLElement | null = null,\n): HTMLStyleElement | HTMLLinkElement | null {\n if (!css) {\n return null;\n }\n\n // Clean up existing element if provided\n removeInjectedResource(existingElement);\n\n const cssId = generateResourceId('rebill-checkout-css');\n const element = isUrl(css) ? createCssLinkElement(css, cssId) : createStyleElement(css, cssId);\n\n document.head.appendChild(element);\n return element;\n}\n\n/**\n * Injects custom JavaScript into the document\n * @param js - JavaScript content (raw JS string or URL)\n * @param existingElement - Optional existing injected element to clean up first\n * @returns The injected element or null if no JS was provided\n */\nexport function injectJS(\n js: string | undefined,\n existingElement: HTMLElement | null = null,\n): HTMLScriptElement | null {\n if (!js) {\n return null;\n }\n\n // Clean up existing element if provided\n removeInjectedResource(existingElement);\n\n const jsId = generateResourceId('rebill-checkout-js');\n const element = isUrl(js) ? createScriptLinkElement(js, jsId) : createScriptElement(js, jsId);\n\n document.head.appendChild(element);\n return element;\n}\n\n/**\n * Cleans up injected CSS element\n */\nexport function cleanupCSS(element: HTMLElement | null): void {\n removeInjectedResource(element);\n}\n\n/**\n * Cleans up injected JavaScript element\n */\nexport function cleanupJS(element: HTMLElement | null): void {\n removeInjectedResource(element);\n}\n"]}
|