apex-commons 0.1.0

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.
@@ -0,0 +1 @@
1
+ const e=globalThis.console;const t=class{static decodeLicenseData(e){try{const t=window.atob(e),i=JSON.parse(t);return i.issueDate&&i.expiryDate&&i.plan?{domains:Array.isArray(i.domains)?i.domains:void 0,expiryDate:i.expiryDate,issueDate:i.issueDate,plan:i.plan,valid:!0}:null}catch{return null}}static generateLicenseKey(e,t,i="standard",a){const s={expiryDate:t,issueDate:e,plan:i};a&&a.length>0&&(s.domains=a);return`APEX-${window.btoa(JSON.stringify(s))}`}static getLicenseStatus(){return this.licenseKey?(this.validationResult||(this.validationResult=this.validateLicense(this.licenseKey)),this.validationResult):{expired:!1,valid:!1}}static isLicenseValid(){return!!this.licenseKey&&(this.validationResult||(this.validationResult=this.validateLicense(this.licenseKey)),this.validationResult.valid)}static setLicense(t){var i;this.licenseKey=t,this.validationResult=this.validateLicense(t),this.validationResult.valid||(i=`[Apex] ${this.validationResult.message}`,e.error(i))}static validateLicense(e){try{if(!e.startsWith("APEX-"))return{expired:!1,message:'Invalid license key format. License key must start with "APEX-".',valid:!1};const t=e.indexOf("-"),i=-1!==t?e.slice(t+1):"";if(!i)return{expired:!1,message:"Invalid license key format. Expected format: APEX-{encoded-data}.",valid:!1};const a=this.decodeLicenseData(i);if(!a)return{expired:!1,message:"Invalid license key. Unable to decode license data.",valid:!1};const s=new Date;if(new Date(a.expiryDate)<s)return{data:a,expired:!0,message:`License expired on ${a.expiryDate}. Please renew your license.`,valid:!1};if(a.domains&&a.domains.length>0){const e="undefined"!=typeof window?window.location.hostname:"";if(!a.domains.some((t=>e===t||e.endsWith(`.${t}`))))return{data:a,expired:!1,message:`License is not valid for this domain (${e}). Allowed domains: ${a.domains.join(", ")}.`,valid:!1}}return{data:a,expired:!1,valid:!0}}catch{return{expired:!1,message:"Invalid license key format or corrupted data.",valid:!1}}}};t.licenseKey=null,t.validationResult=null;let i=t;const a=class{static createWatermarkPattern(){const e=this.WATERMARK_TEXT;return`url("data:image/svg+xml,${encodeURIComponent(`\n <svg xmlns="http://www.w3.org/2000/svg" width="300" height="200">\n <text \n x="50%" \n y="50%" \n dominant-baseline="middle" \n text-anchor="middle"\n font-family="-apple-system, BlinkMacSystemFont, Segoe UI, Roboto, Arial, sans-serif"\n font-size="18"\n font-weight="600"\n fill="rgba(134, 134, 134, 0.1)"\n transform="rotate(-35, 100, 60)"\n >${e}</text>\n </svg>\n `.trim())}")`}static add(e){this.remove(e);const t=document.createElement("div");t.setAttribute(this.WATERMARK_ATTR,""),Object.assign(t.style,{backgroundImage:this.createWatermarkPattern(),backgroundRepeat:"repeat",bottom:"0",left:"0",msUserSelect:"none",pointerEvents:"none",position:"absolute",right:"0",top:"0",userSelect:"none",webkitUserSelect:"none",zIndex:"10000"}),"static"===getComputedStyle(e).position&&(e.style.position="relative"),e.appendChild(t)}static exists(e){return!!e.querySelector(`[${this.WATERMARK_ATTR}]`)}static remove(e){const t=e.querySelector(`[${this.WATERMARK_ATTR}]`);t&&t.remove()}};a.WATERMARK_ATTR="data-apexcharts-watermark",a.WATERMARK_TEXT="APEXCHARTS";let s=a;export{i as LicenseManager,s as Watermark};
@@ -0,0 +1 @@
1
+ !function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports):"function"==typeof define&&define.amd?define(["exports"],t):t((e="undefined"!=typeof globalThis?globalThis:e||self).ApexCommons={})}(this,(function(e){"use strict";const t=globalThis.console;const i=class{static decodeLicenseData(e){try{const t=window.atob(e),i=JSON.parse(t);return i.issueDate&&i.expiryDate&&i.plan?{domains:Array.isArray(i.domains)?i.domains:void 0,expiryDate:i.expiryDate,issueDate:i.issueDate,plan:i.plan,valid:!0}:null}catch{return null}}static generateLicenseKey(e,t,i="standard",s){const a={expiryDate:t,issueDate:e,plan:i};s&&s.length>0&&(a.domains=s);return`APEX-${window.btoa(JSON.stringify(a))}`}static getLicenseStatus(){return this.licenseKey?(this.validationResult||(this.validationResult=this.validateLicense(this.licenseKey)),this.validationResult):{expired:!1,valid:!1}}static isLicenseValid(){return!!this.licenseKey&&(this.validationResult||(this.validationResult=this.validateLicense(this.licenseKey)),this.validationResult.valid)}static setLicense(e){var i;this.licenseKey=e,this.validationResult=this.validateLicense(e),this.validationResult.valid||(i=`[Apex] ${this.validationResult.message}`,t.error(i))}static validateLicense(e){try{if(!e.startsWith("APEX-"))return{expired:!1,message:'Invalid license key format. License key must start with "APEX-".',valid:!1};const t=e.indexOf("-"),i=-1!==t?e.slice(t+1):"";if(!i)return{expired:!1,message:"Invalid license key format. Expected format: APEX-{encoded-data}.",valid:!1};const s=this.decodeLicenseData(i);if(!s)return{expired:!1,message:"Invalid license key. Unable to decode license data.",valid:!1};const a=new Date;if(new Date(s.expiryDate)<a)return{data:s,expired:!0,message:`License expired on ${s.expiryDate}. Please renew your license.`,valid:!1};if(s.domains&&s.domains.length>0){const e="undefined"!=typeof window?window.location.hostname:"";if(!s.domains.some((t=>e===t||e.endsWith(`.${t}`))))return{data:s,expired:!1,message:`License is not valid for this domain (${e}). Allowed domains: ${s.domains.join(", ")}.`,valid:!1}}return{data:s,expired:!1,valid:!0}}catch{return{expired:!1,message:"Invalid license key format or corrupted data.",valid:!1}}}};i.licenseKey=null,i.validationResult=null;let s=i;const a=class{static createWatermarkPattern(){const e=this.WATERMARK_TEXT;return`url("data:image/svg+xml,${encodeURIComponent(`\n <svg xmlns="http://www.w3.org/2000/svg" width="300" height="200">\n <text \n x="50%" \n y="50%" \n dominant-baseline="middle" \n text-anchor="middle"\n font-family="-apple-system, BlinkMacSystemFont, Segoe UI, Roboto, Arial, sans-serif"\n font-size="18"\n font-weight="600"\n fill="rgba(134, 134, 134, 0.1)"\n transform="rotate(-35, 100, 60)"\n >${e}</text>\n </svg>\n `.trim())}")`}static add(e){this.remove(e);const t=document.createElement("div");t.setAttribute(this.WATERMARK_ATTR,""),Object.assign(t.style,{backgroundImage:this.createWatermarkPattern(),backgroundRepeat:"repeat",bottom:"0",left:"0",msUserSelect:"none",pointerEvents:"none",position:"absolute",right:"0",top:"0",userSelect:"none",webkitUserSelect:"none",zIndex:"10000"}),"static"===getComputedStyle(e).position&&(e.style.position="relative"),e.appendChild(t)}static exists(e){return!!e.querySelector(`[${this.WATERMARK_ATTR}]`)}static remove(e){const t=e.querySelector(`[${this.WATERMARK_ATTR}]`);t&&t.remove()}};a.WATERMARK_ATTR="data-apexcharts-watermark",a.WATERMARK_TEXT="APEXCHARTS";let n=a;e.LicenseManager=s,e.Watermark=n,Object.defineProperty(e,Symbol.toStringTag,{value:"Module"})}));
package/index.d.ts ADDED
@@ -0,0 +1,3 @@
1
+ export { LicenseManager } from './lib/LicenseManager';
2
+ export { Watermark } from './lib/Watermark';
3
+ //# sourceMappingURL=index.d.ts.map
package/index.d.ts.map ADDED
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../libs/commons/src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,cAAc,EAAC,MAAM,sBAAsB,CAAC;AACpD,OAAO,EAAC,SAAS,EAAC,MAAM,iBAAiB,CAAC"}
@@ -0,0 +1,45 @@
1
+ interface LicenseData {
2
+ readonly domains?: readonly string[];
3
+ readonly expiryDate: string;
4
+ readonly issueDate: string;
5
+ readonly plan: string;
6
+ readonly valid: boolean;
7
+ }
8
+ interface LicenseValidationResult {
9
+ readonly data?: LicenseData;
10
+ readonly expired: boolean;
11
+ readonly message?: string;
12
+ readonly valid: boolean;
13
+ }
14
+ export declare class LicenseManager {
15
+ private static licenseKey;
16
+ private static validationResult;
17
+ /**
18
+ * Decode license data from encoded string
19
+ * This is a simple base64 + JSON approach - you can make it more sophisticated
20
+ */
21
+ private static decodeLicenseData;
22
+ /**
23
+ * Generate a license key (for your internal use)
24
+ * You would use this on your server/admin panel to generate keys for customers
25
+ */
26
+ static generateLicenseKey(issueDate: string, expiryDate: string, plan?: string, domains?: string[]): string;
27
+ /**
28
+ * Get current license validation result
29
+ */
30
+ static getLicenseStatus(): LicenseValidationResult;
31
+ /**
32
+ * Check if current license is valid
33
+ */
34
+ static isLicenseValid(): boolean;
35
+ /**
36
+ * Set the global license key
37
+ */
38
+ static setLicense(key: string): void;
39
+ /**
40
+ * Validate license key format and content
41
+ */
42
+ private static validateLicense;
43
+ }
44
+ export {};
45
+ //# sourceMappingURL=LicenseManager.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"LicenseManager.d.ts","sourceRoot":"","sources":["../../../libs/commons/src/lib/LicenseManager.ts"],"names":[],"mappings":"AAEA,UAAU,WAAW;IACnB,QAAQ,CAAC,OAAO,CAAC,EAAE,SAAS,MAAM,EAAE,CAAC;IACrC,QAAQ,CAAC,UAAU,EAAE,MAAM,CAAC;IAC5B,QAAQ,CAAC,SAAS,EAAE,MAAM,CAAC;IAC3B,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,KAAK,EAAE,OAAO,CAAC;CACzB;AAED,UAAU,uBAAuB;IAC/B,QAAQ,CAAC,IAAI,CAAC,EAAE,WAAW,CAAC;IAC5B,QAAQ,CAAC,OAAO,EAAE,OAAO,CAAC;IAC1B,QAAQ,CAAC,OAAO,CAAC,EAAE,MAAM,CAAC;IAC1B,QAAQ,CAAC,KAAK,EAAE,OAAO,CAAC;CACzB;AAED,qBAAa,cAAc;IACzB,OAAO,CAAC,MAAM,CAAC,UAAU,CAAuB;IAChD,OAAO,CAAC,MAAM,CAAC,gBAAgB,CAAwC;IAEvE;;;OAGG;IACH,OAAO,CAAC,MAAM,CAAC,iBAAiB;IAuBhC;;;OAGG;WACW,kBAAkB,CAC9B,SAAS,EAAE,MAAM,EACjB,UAAU,EAAE,MAAM,EAClB,IAAI,SAAa,EACjB,OAAO,CAAC,EAAE,MAAM,EAAE,GACjB,MAAM;IAgBT;;OAEG;WACW,gBAAgB,IAAI,uBAAuB;IAYzD;;OAEG;WACW,cAAc,IAAI,OAAO;IAYvC;;OAEG;WACW,UAAU,CAAC,GAAG,EAAE,MAAM,GAAG,IAAI;IAS3C;;OAEG;IACH,OAAO,CAAC,MAAM,CAAC,eAAe;CA2E/B"}
@@ -0,0 +1,21 @@
1
+ export declare class Watermark {
2
+ private static readonly WATERMARK_ATTR;
3
+ private static readonly WATERMARK_TEXT;
4
+ /**
5
+ * Create a repeating diagonal watermark pattern
6
+ */
7
+ private static createWatermarkPattern;
8
+ /**
9
+ * Add watermark to a container element
10
+ */
11
+ static add(container: HTMLElement): void;
12
+ /**
13
+ * Check if watermark exists in container
14
+ */
15
+ static exists(container: HTMLElement): boolean;
16
+ /**
17
+ * Remove watermark from a container element
18
+ */
19
+ static remove(container: HTMLElement): void;
20
+ }
21
+ //# sourceMappingURL=Watermark.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Watermark.d.ts","sourceRoot":"","sources":["../../../libs/commons/src/lib/Watermark.ts"],"names":[],"mappings":"AAAA,qBAAa,SAAS;IACpB,OAAO,CAAC,MAAM,CAAC,QAAQ,CAAC,cAAc,CAA+B;IACrE,OAAO,CAAC,MAAM,CAAC,QAAQ,CAAC,cAAc,CAAgB;IAEtD;;OAEG;IACH,OAAO,CAAC,MAAM,CAAC,sBAAsB;IAqBrC;;OAEG;WACW,GAAG,CAAC,SAAS,EAAE,WAAW,GAAG,IAAI;IA+B/C;;OAEG;WACW,MAAM,CAAC,SAAS,EAAE,WAAW,GAAG,OAAO;IAIrD;;OAEG;WACW,MAAM,CAAC,SAAS,EAAE,WAAW,GAAG,IAAI;CAOnD"}
@@ -0,0 +1,2 @@
1
+ export declare function logError(message: string): void;
2
+ //# sourceMappingURL=logger.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"logger.d.ts","sourceRoot":"","sources":["../../../libs/commons/src/lib/logger.ts"],"names":[],"mappings":"AAGA,wBAAgB,QAAQ,CAAC,OAAO,EAAE,MAAM,GAAG,IAAI,CAE9C"}
package/package.json ADDED
@@ -0,0 +1,21 @@
1
+ {
2
+ "name": "apex-commons",
3
+ "version": "0.1.0",
4
+ "type": "module",
5
+ "description": "Shared utilities for ApexCharts products (licensing, watermark).",
6
+ "main": "./apex-commons.min.js",
7
+ "module": "./apex-commons.es.min.js",
8
+ "types": "./index.d.ts",
9
+ "exports": {
10
+ ".": {
11
+ "import": {
12
+ "types": "./index.d.ts",
13
+ "default": "./apex-commons.es.min.js"
14
+ },
15
+ "require": {
16
+ "types": "./index.d.ts",
17
+ "default": "./apex-commons.min.js"
18
+ }
19
+ }
20
+ }
21
+ }