orc4-gpt 1.0.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.
package/README.md ADDED
File without changes
package/dist/Orca.d.ts ADDED
@@ -0,0 +1,13 @@
1
+ import { SlotConfig, OrcaConfig } from './core/types';
2
+ export declare class Orca {
3
+ private config;
4
+ private core;
5
+ private loader;
6
+ private slots;
7
+ private refresh;
8
+ private observer;
9
+ private gam;
10
+ constructor(config?: OrcaConfig);
11
+ init(): void;
12
+ registerSlot(config: SlotConfig): void;
13
+ }
@@ -0,0 +1,6 @@
1
+ export declare class OrcaCore {
2
+ private queue;
3
+ private ready;
4
+ push(fn: () => void): void;
5
+ flush(): void;
6
+ }
@@ -0,0 +1,3 @@
1
+ export declare class Scheduler {
2
+ static hybrid(callback: () => void): void;
3
+ }
@@ -0,0 +1,9 @@
1
+ export interface SlotConfig {
2
+ id: string;
3
+ path: string;
4
+ sizes: googletag.GeneralSize;
5
+ }
6
+ export interface OrcaConfig {
7
+ debug?: boolean;
8
+ lazyMargin?: string;
9
+ }
@@ -0,0 +1,170 @@
1
+ 'use strict';
2
+
3
+ class OrcaCore {
4
+ constructor() {
5
+ this.queue = [];
6
+ this.ready = false;
7
+ }
8
+ push(fn) {
9
+ if (this.ready)
10
+ fn();
11
+ else
12
+ this.queue.push(fn);
13
+ }
14
+ flush() {
15
+ this.ready = true;
16
+ this.queue.forEach(fn => fn());
17
+ this.queue = [];
18
+ }
19
+ }
20
+
21
+ class Scheduler {
22
+ static hybrid(callback) {
23
+ let triggered = false;
24
+ const run = () => {
25
+ if (triggered)
26
+ return;
27
+ triggered = true;
28
+ callback();
29
+ };
30
+ // LCP
31
+ new PerformanceObserver((entryList) => {
32
+ if (entryList.getEntries().length > 0)
33
+ run();
34
+ }).observe({ type: 'largest-contentful-paint', buffered: true });
35
+ // Idle
36
+ if ('requestIdleCallback' in window) {
37
+ window.requestIdleCallback(run, { timeout: 2000 });
38
+ }
39
+ else {
40
+ setTimeout(run, 2000);
41
+ }
42
+ // Interaction fallback
43
+ window.addEventListener('scroll', run, { once: true });
44
+ }
45
+ }
46
+
47
+ class ScriptLoader {
48
+ constructor() {
49
+ this.cache = new Map();
50
+ }
51
+ load(name, src) {
52
+ if (this.cache.has(name)) {
53
+ return this.cache.get(name);
54
+ }
55
+ const promise = new Promise((resolve) => {
56
+ const s = document.createElement('script');
57
+ s.src = src;
58
+ s.async = true;
59
+ s.onload = () => resolve();
60
+ document.head.appendChild(s);
61
+ });
62
+ this.cache.set(name, promise);
63
+ return promise;
64
+ }
65
+ }
66
+
67
+ class SlotManager {
68
+ constructor(core) {
69
+ this.core = core;
70
+ this.slots = new Map();
71
+ }
72
+ define(config) {
73
+ this.core.push(() => {
74
+ const slot = googletag
75
+ .defineSlot(config.path, config.sizes, config.id)
76
+ .addService(googletag.pubads());
77
+ this.slots.set(config.id, slot);
78
+ });
79
+ }
80
+ get(id) {
81
+ return this.slots.get(id);
82
+ }
83
+ getAll() {
84
+ return Array.from(this.slots.values());
85
+ }
86
+ }
87
+
88
+ class RefreshManager {
89
+ constructor() {
90
+ this.queue = [];
91
+ this.timer = null;
92
+ }
93
+ add(slot) {
94
+ this.queue.push(slot);
95
+ if (!this.timer) {
96
+ this.timer = window.setTimeout(() => {
97
+ googletag.pubads().refresh(this.queue);
98
+ this.queue = [];
99
+ this.timer = null;
100
+ }, 100);
101
+ }
102
+ }
103
+ }
104
+
105
+ class ViewObserver {
106
+ constructor(callback, margin = '200px') {
107
+ this.observer = new IntersectionObserver((entries) => {
108
+ entries.forEach(entry => {
109
+ if (entry.isIntersecting) {
110
+ callback(entry.target);
111
+ this.observer.unobserve(entry.target);
112
+ }
113
+ });
114
+ }, { rootMargin: margin });
115
+ }
116
+ observe(el) {
117
+ this.observer.observe(el);
118
+ }
119
+ }
120
+
121
+ class GAM {
122
+ constructor(core, loader, slots) {
123
+ this.core = core;
124
+ this.loader = loader;
125
+ this.slots = slots;
126
+ }
127
+ async init() {
128
+ await this.loader.load('gpt', 'https://securepubads.g.doubleclick.net/tag/js/gpt.js');
129
+ window.googletag = window.googletag || { cmd: [] };
130
+ window.googletag.cmd.push(() => {
131
+ googletag.pubads().disableInitialLoad();
132
+ googletag.pubads().enableSingleRequest();
133
+ googletag.enableServices();
134
+ this.core.flush();
135
+ });
136
+ }
137
+ display(id) {
138
+ this.core.push(() => {
139
+ const slot = this.slots.get(id);
140
+ if (!slot)
141
+ return;
142
+ googletag.display(id);
143
+ googletag.pubads().refresh([slot]);
144
+ });
145
+ }
146
+ }
147
+
148
+ class Orca {
149
+ constructor(config = {}) {
150
+ this.config = config;
151
+ this.core = new OrcaCore();
152
+ this.loader = new ScriptLoader();
153
+ this.slots = new SlotManager(this.core);
154
+ this.refresh = new RefreshManager();
155
+ this.gam = new GAM(this.core, this.loader, this.slots);
156
+ this.observer = new ViewObserver((el) => this.gam.display(el.id), config.lazyMargin);
157
+ }
158
+ init() {
159
+ Scheduler.hybrid(() => this.gam.init());
160
+ }
161
+ registerSlot(config) {
162
+ const el = document.getElementById(config.id);
163
+ if (!el)
164
+ return;
165
+ this.slots.define(config);
166
+ this.observer.observe(el);
167
+ }
168
+ }
169
+
170
+ exports.Orca = Orca;
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.cjs.js","sources":["../src/core/OrcaCore.ts","../src/core/Scheduler.ts","../src/services/ScriptLoader.ts","../src/services/SlotManager.ts","../src/services/RefreshManager.ts","../src/services/ViewObserver.ts","../src/modules/GAM.ts","../src/Orca.ts"],"sourcesContent":[null,null,null,null,null,null,null,null],"names":[],"mappings":";;MAAa,QAAQ,CAAA;AAArB,IAAA,WAAA,GAAA;QACU,IAAA,CAAA,KAAK,GAAsB,EAAE;QAC7B,IAAA,CAAA,KAAK,GAAG,KAAK;IAYvB;AAVE,IAAA,IAAI,CAAC,EAAc,EAAA;QACjB,IAAI,IAAI,CAAC,KAAK;AAAE,YAAA,EAAE,EAAE;;AACf,YAAA,IAAI,CAAC,KAAK,CAAC,I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AE9B,QAAA,IAAA,CAAA,GAAG,GAAG,IAAI,GAAG,CAAC,IAAI,CAAC,IAAI,EAAE,IAAI,CAAC,MAAM,EAAE,IAAI,CAAC,KAAK,CAAC;QAGvD,IAAI,CAAC,QAAQ,GAAG,IAAI,YAAY,CAC9B,CAAC,EAAE,KAAK,IAAI,CAAC,GAAG,CAAC,OAAO,CAAC,EAAE,CAAC,EAAE,CAAC,EAC/B,MAAM,CAAC,UAAU,CAClB;IACH;IAEA,IAAI,GAAA;AACF,QAAA,SAAS,CAAC,MAAM,CAAC,MAAM,IAAI,CAAC,GAAG,CAAC,IAAI,EAAE,CAAC;IACzC;AAEA,IAAA,YAAY,CAAC,MAAkB,EAAA;QAC7B,MAAM,EAAE,GAAG,QAAQ,CAAC,cAAc,CAAC,MAAM,CAAC,EAAE,CAAC;AAC7C,QAAA,IAAI,CAAC,EAAE;YAAE;AAET,QAAA,IAAI,CAAC,KAAK,CAAC,MAAM,CAAC,MAAM,CAAC;AACzB,QAAA,IAAI,CAAC,QAAQ,CAAC,OAAO,CAAC,EAAE,CAAC;IAC3B;AACD;;;;"}
@@ -0,0 +1 @@
1
+ export * from './Orca';
@@ -0,0 +1,168 @@
1
+ class OrcaCore {
2
+ constructor() {
3
+ this.queue = [];
4
+ this.ready = false;
5
+ }
6
+ push(fn) {
7
+ if (this.ready)
8
+ fn();
9
+ else
10
+ this.queue.push(fn);
11
+ }
12
+ flush() {
13
+ this.ready = true;
14
+ this.queue.forEach(fn => fn());
15
+ this.queue = [];
16
+ }
17
+ }
18
+
19
+ class Scheduler {
20
+ static hybrid(callback) {
21
+ let triggered = false;
22
+ const run = () => {
23
+ if (triggered)
24
+ return;
25
+ triggered = true;
26
+ callback();
27
+ };
28
+ // LCP
29
+ new PerformanceObserver((entryList) => {
30
+ if (entryList.getEntries().length > 0)
31
+ run();
32
+ }).observe({ type: 'largest-contentful-paint', buffered: true });
33
+ // Idle
34
+ if ('requestIdleCallback' in window) {
35
+ window.requestIdleCallback(run, { timeout: 2000 });
36
+ }
37
+ else {
38
+ setTimeout(run, 2000);
39
+ }
40
+ // Interaction fallback
41
+ window.addEventListener('scroll', run, { once: true });
42
+ }
43
+ }
44
+
45
+ class ScriptLoader {
46
+ constructor() {
47
+ this.cache = new Map();
48
+ }
49
+ load(name, src) {
50
+ if (this.cache.has(name)) {
51
+ return this.cache.get(name);
52
+ }
53
+ const promise = new Promise((resolve) => {
54
+ const s = document.createElement('script');
55
+ s.src = src;
56
+ s.async = true;
57
+ s.onload = () => resolve();
58
+ document.head.appendChild(s);
59
+ });
60
+ this.cache.set(name, promise);
61
+ return promise;
62
+ }
63
+ }
64
+
65
+ class SlotManager {
66
+ constructor(core) {
67
+ this.core = core;
68
+ this.slots = new Map();
69
+ }
70
+ define(config) {
71
+ this.core.push(() => {
72
+ const slot = googletag
73
+ .defineSlot(config.path, config.sizes, config.id)
74
+ .addService(googletag.pubads());
75
+ this.slots.set(config.id, slot);
76
+ });
77
+ }
78
+ get(id) {
79
+ return this.slots.get(id);
80
+ }
81
+ getAll() {
82
+ return Array.from(this.slots.values());
83
+ }
84
+ }
85
+
86
+ class RefreshManager {
87
+ constructor() {
88
+ this.queue = [];
89
+ this.timer = null;
90
+ }
91
+ add(slot) {
92
+ this.queue.push(slot);
93
+ if (!this.timer) {
94
+ this.timer = window.setTimeout(() => {
95
+ googletag.pubads().refresh(this.queue);
96
+ this.queue = [];
97
+ this.timer = null;
98
+ }, 100);
99
+ }
100
+ }
101
+ }
102
+
103
+ class ViewObserver {
104
+ constructor(callback, margin = '200px') {
105
+ this.observer = new IntersectionObserver((entries) => {
106
+ entries.forEach(entry => {
107
+ if (entry.isIntersecting) {
108
+ callback(entry.target);
109
+ this.observer.unobserve(entry.target);
110
+ }
111
+ });
112
+ }, { rootMargin: margin });
113
+ }
114
+ observe(el) {
115
+ this.observer.observe(el);
116
+ }
117
+ }
118
+
119
+ class GAM {
120
+ constructor(core, loader, slots) {
121
+ this.core = core;
122
+ this.loader = loader;
123
+ this.slots = slots;
124
+ }
125
+ async init() {
126
+ await this.loader.load('gpt', 'https://securepubads.g.doubleclick.net/tag/js/gpt.js');
127
+ window.googletag = window.googletag || { cmd: [] };
128
+ window.googletag.cmd.push(() => {
129
+ googletag.pubads().disableInitialLoad();
130
+ googletag.pubads().enableSingleRequest();
131
+ googletag.enableServices();
132
+ this.core.flush();
133
+ });
134
+ }
135
+ display(id) {
136
+ this.core.push(() => {
137
+ const slot = this.slots.get(id);
138
+ if (!slot)
139
+ return;
140
+ googletag.display(id);
141
+ googletag.pubads().refresh([slot]);
142
+ });
143
+ }
144
+ }
145
+
146
+ class Orca {
147
+ constructor(config = {}) {
148
+ this.config = config;
149
+ this.core = new OrcaCore();
150
+ this.loader = new ScriptLoader();
151
+ this.slots = new SlotManager(this.core);
152
+ this.refresh = new RefreshManager();
153
+ this.gam = new GAM(this.core, this.loader, this.slots);
154
+ this.observer = new ViewObserver((el) => this.gam.display(el.id), config.lazyMargin);
155
+ }
156
+ init() {
157
+ Scheduler.hybrid(() => this.gam.init());
158
+ }
159
+ registerSlot(config) {
160
+ const el = document.getElementById(config.id);
161
+ if (!el)
162
+ return;
163
+ this.slots.define(config);
164
+ this.observer.observe(el);
165
+ }
166
+ }
167
+
168
+ export { Orca };
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.esm.js","sources":["../src/core/OrcaCore.ts","../src/core/Scheduler.ts","../src/services/ScriptLoader.ts","../src/services/SlotManager.ts","../src/services/RefreshManager.ts","../src/services/ViewObserver.ts","../src/modules/GAM.ts","../src/Orca.ts"],"sourcesContent":[null,null,null,null,null,null,null,null],"names":[],"mappings":"MAAa,QAAQ,CAAA;AAArB,IAAA,WAAA,GAAA;QACU,IAAA,CAAA,KAAK,GAAsB,EAAE;QAC7B,IAAA,CAAA,KAAK,GAAG,KAAK;IAYvB;AAVE,IAAA,IAAI,CAAC,EAAc,EAAA;QACjB,IAAI,IAAI,CAAC,KAAK;AAAE,YAAA,EAAE,EAAE;;AACf,YAAA,IA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AG,IAAI,cAAc,EAAE;AAE9B,QAAA,IAAA,CAAA,GAAG,GAAG,IAAI,GAAG,CAAC,IAAI,CAAC,IAAI,EAAE,IAAI,CAAC,MAAM,EAAE,IAAI,CAAC,KAAK,CAAC;QAGvD,IAAI,CAAC,QAAQ,GAAG,IAAI,YAAY,CAC9B,CAAC,EAAE,KAAK,IAAI,CAAC,GAAG,CAAC,OAAO,CAAC,EAAE,CAAC,EAAE,CAAC,EAC/B,MAAM,CAAC,UAAU,CAClB;IACH;IAEA,IAAI,GAAA;AACF,QAAA,SAAS,CAAC,MAAM,CAAC,MAAM,IAAI,CAAC,GAAG,CAAC,IAAI,EAAE,CAAC;IACzC;AAEA,IAAA,YAAY,CAAC,MAAkB,EAAA;QAC7B,MAAM,EAAE,GAAG,QAAQ,CAAC,cAAc,CAAC,MAAM,CAAC,EAAE,CAAC;AAC7C,QAAA,IAAI,CAAC,EAAE;YAAE;AAET,QAAA,IAAI,CAAC,KAAK,CAAC,MAAM,CAAC,MAAM,CAAC;AACzB,QAAA,IAAI,CAAC,QAAQ,CAAC,OAAO,CAAC,EAAE,CAAC;IAC3B;AACD;;;;"}
@@ -0,0 +1,176 @@
1
+ (function (global, factory) {
2
+ typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports) :
3
+ typeof define === 'function' && define.amd ? define(['exports'], factory) :
4
+ (global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global.Orca = {}));
5
+ })(this, (function (exports) { 'use strict';
6
+
7
+ class OrcaCore {
8
+ constructor() {
9
+ this.queue = [];
10
+ this.ready = false;
11
+ }
12
+ push(fn) {
13
+ if (this.ready)
14
+ fn();
15
+ else
16
+ this.queue.push(fn);
17
+ }
18
+ flush() {
19
+ this.ready = true;
20
+ this.queue.forEach(fn => fn());
21
+ this.queue = [];
22
+ }
23
+ }
24
+
25
+ class Scheduler {
26
+ static hybrid(callback) {
27
+ let triggered = false;
28
+ const run = () => {
29
+ if (triggered)
30
+ return;
31
+ triggered = true;
32
+ callback();
33
+ };
34
+ // LCP
35
+ new PerformanceObserver((entryList) => {
36
+ if (entryList.getEntries().length > 0)
37
+ run();
38
+ }).observe({ type: 'largest-contentful-paint', buffered: true });
39
+ // Idle
40
+ if ('requestIdleCallback' in window) {
41
+ window.requestIdleCallback(run, { timeout: 2000 });
42
+ }
43
+ else {
44
+ setTimeout(run, 2000);
45
+ }
46
+ // Interaction fallback
47
+ window.addEventListener('scroll', run, { once: true });
48
+ }
49
+ }
50
+
51
+ class ScriptLoader {
52
+ constructor() {
53
+ this.cache = new Map();
54
+ }
55
+ load(name, src) {
56
+ if (this.cache.has(name)) {
57
+ return this.cache.get(name);
58
+ }
59
+ const promise = new Promise((resolve) => {
60
+ const s = document.createElement('script');
61
+ s.src = src;
62
+ s.async = true;
63
+ s.onload = () => resolve();
64
+ document.head.appendChild(s);
65
+ });
66
+ this.cache.set(name, promise);
67
+ return promise;
68
+ }
69
+ }
70
+
71
+ class SlotManager {
72
+ constructor(core) {
73
+ this.core = core;
74
+ this.slots = new Map();
75
+ }
76
+ define(config) {
77
+ this.core.push(() => {
78
+ const slot = googletag
79
+ .defineSlot(config.path, config.sizes, config.id)
80
+ .addService(googletag.pubads());
81
+ this.slots.set(config.id, slot);
82
+ });
83
+ }
84
+ get(id) {
85
+ return this.slots.get(id);
86
+ }
87
+ getAll() {
88
+ return Array.from(this.slots.values());
89
+ }
90
+ }
91
+
92
+ class RefreshManager {
93
+ constructor() {
94
+ this.queue = [];
95
+ this.timer = null;
96
+ }
97
+ add(slot) {
98
+ this.queue.push(slot);
99
+ if (!this.timer) {
100
+ this.timer = window.setTimeout(() => {
101
+ googletag.pubads().refresh(this.queue);
102
+ this.queue = [];
103
+ this.timer = null;
104
+ }, 100);
105
+ }
106
+ }
107
+ }
108
+
109
+ class ViewObserver {
110
+ constructor(callback, margin = '200px') {
111
+ this.observer = new IntersectionObserver((entries) => {
112
+ entries.forEach(entry => {
113
+ if (entry.isIntersecting) {
114
+ callback(entry.target);
115
+ this.observer.unobserve(entry.target);
116
+ }
117
+ });
118
+ }, { rootMargin: margin });
119
+ }
120
+ observe(el) {
121
+ this.observer.observe(el);
122
+ }
123
+ }
124
+
125
+ class GAM {
126
+ constructor(core, loader, slots) {
127
+ this.core = core;
128
+ this.loader = loader;
129
+ this.slots = slots;
130
+ }
131
+ async init() {
132
+ await this.loader.load('gpt', 'https://securepubads.g.doubleclick.net/tag/js/gpt.js');
133
+ window.googletag = window.googletag || { cmd: [] };
134
+ window.googletag.cmd.push(() => {
135
+ googletag.pubads().disableInitialLoad();
136
+ googletag.pubads().enableSingleRequest();
137
+ googletag.enableServices();
138
+ this.core.flush();
139
+ });
140
+ }
141
+ display(id) {
142
+ this.core.push(() => {
143
+ const slot = this.slots.get(id);
144
+ if (!slot)
145
+ return;
146
+ googletag.display(id);
147
+ googletag.pubads().refresh([slot]);
148
+ });
149
+ }
150
+ }
151
+
152
+ class Orca {
153
+ constructor(config = {}) {
154
+ this.config = config;
155
+ this.core = new OrcaCore();
156
+ this.loader = new ScriptLoader();
157
+ this.slots = new SlotManager(this.core);
158
+ this.refresh = new RefreshManager();
159
+ this.gam = new GAM(this.core, this.loader, this.slots);
160
+ this.observer = new ViewObserver((el) => this.gam.display(el.id), config.lazyMargin);
161
+ }
162
+ init() {
163
+ Scheduler.hybrid(() => this.gam.init());
164
+ }
165
+ registerSlot(config) {
166
+ const el = document.getElementById(config.id);
167
+ if (!el)
168
+ return;
169
+ this.slots.define(config);
170
+ this.observer.observe(el);
171
+ }
172
+ }
173
+
174
+ exports.Orca = Orca;
175
+
176
+ }));
@@ -0,0 +1,11 @@
1
+ import { OrcaCore } from '../core/OrcaCore';
2
+ import { ScriptLoader } from '../services/ScriptLoader';
3
+ import { SlotManager } from '../services/SlotManager';
4
+ export declare class GAM {
5
+ private core;
6
+ private loader;
7
+ private slots;
8
+ constructor(core: OrcaCore, loader: ScriptLoader, slots: SlotManager);
9
+ init(): Promise<void>;
10
+ display(id: string): void;
11
+ }
@@ -0,0 +1,5 @@
1
+ export declare class RefreshManager {
2
+ private queue;
3
+ private timer;
4
+ add(slot: googletag.Slot): void;
5
+ }
@@ -0,0 +1,4 @@
1
+ export declare class ScriptLoader {
2
+ private cache;
3
+ load(name: string, src: string): Promise<void>;
4
+ }
@@ -0,0 +1,10 @@
1
+ import { SlotConfig } from '../core/types';
2
+ import { OrcaCore } from '../core/OrcaCore';
3
+ export declare class SlotManager {
4
+ private core;
5
+ private slots;
6
+ constructor(core: OrcaCore);
7
+ define(config: SlotConfig): void;
8
+ get(id: string): googletag.Slot | undefined;
9
+ getAll(): googletag.Slot[];
10
+ }
@@ -0,0 +1,5 @@
1
+ export declare class ViewObserver {
2
+ private observer;
3
+ constructor(callback: (el: HTMLElement) => void, margin?: string);
4
+ observe(el: HTMLElement): void;
5
+ }
package/package.json ADDED
@@ -0,0 +1,33 @@
1
+ {
2
+ "name": "orc4-gpt",
3
+ "version": "1.0.0",
4
+ "description": "Client-side orchestration SDK for ads and third-party scripts",
5
+ "main": "dist/index.cjs.js",
6
+ "module": "dist/index.esm.js",
7
+ "types": "dist/index.d.ts",
8
+ "files": [
9
+ "dist"
10
+ ],
11
+ "scripts": {
12
+ "build": "rollup -c",
13
+ "prepublishOnly": "npm run build"
14
+ },
15
+ "keywords": [
16
+ "ads",
17
+ "google-ad-manager",
18
+ "cwv",
19
+ "performance"
20
+ ],
21
+ "author": "Doni",
22
+ "license": "MIT",
23
+ "dependencies": {
24
+ "tslib": "^2.8.1"
25
+ },
26
+ "devDependencies": {
27
+ "@rollup/plugin-typescript": "^12.3.0",
28
+ "@types/google-publisher-tag": "^1.20260202.0",
29
+ "rollup": "^4.57.1",
30
+ "typescript": "^5.9.3"
31
+ },
32
+ "type": "module"
33
+ }