content-security-toolkit 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.
Files changed (162) hide show
  1. package/LICENSE +9 -0
  2. package/README.md +171 -0
  3. package/dist/config/default-extensions-config.json +103 -0
  4. package/dist/core/ContentProtector.d.ts +63 -0
  5. package/dist/core/ContentProtector.js +279 -0
  6. package/dist/core/index.d.ts +1 -0
  7. package/dist/core/index.js +2 -0
  8. package/dist/core/mediator/ContentProtectionMediator.d.ts +86 -0
  9. package/dist/core/mediator/ContentProtectionMediator.js +238 -0
  10. package/dist/core/mediator/eventDataTypes.d.ts +205 -0
  11. package/dist/core/mediator/eventDataTypes.js +23 -0
  12. package/dist/core/mediator/handlers/abstractEventHandler.d.ts +67 -0
  13. package/dist/core/mediator/handlers/abstractEventHandler.js +106 -0
  14. package/dist/core/mediator/handlers/baseEventHandler.d.ts +65 -0
  15. package/dist/core/mediator/handlers/baseEventHandler.js +99 -0
  16. package/dist/core/mediator/handlers/devToolsEventHandler.d.ts +9 -0
  17. package/dist/core/mediator/handlers/devToolsEventHandler.js +95 -0
  18. package/dist/core/mediator/handlers/eventHandlerRegistry.d.ts +9 -0
  19. package/dist/core/mediator/handlers/eventHandlerRegistry.js +34 -0
  20. package/dist/core/mediator/handlers/extensionEventHandlers.d.ts +40 -0
  21. package/dist/core/mediator/handlers/extensionEventHandlers.js +140 -0
  22. package/dist/core/mediator/handlers/iFrameEventHandlers.d.ts +27 -0
  23. package/dist/core/mediator/handlers/iFrameEventHandlers.js +93 -0
  24. package/dist/core/mediator/handlers/index.d.ts +9 -0
  25. package/dist/core/mediator/handlers/index.js +34 -0
  26. package/dist/core/mediator/handlers/screenShotEventHandlers.d.ts +34 -0
  27. package/dist/core/mediator/handlers/screenShotEventHandlers.js +111 -0
  28. package/dist/core/mediator/protection-event.d.ts +94 -0
  29. package/dist/core/mediator/protection-event.js +43 -0
  30. package/dist/core/mediator/types.d.ts +105 -0
  31. package/dist/core/mediator/types.js +1 -0
  32. package/dist/index.d.ts +4 -0
  33. package/dist/index.js +5 -0
  34. package/dist/strategies/AbstractStrategy.d.ts +152 -0
  35. package/dist/strategies/AbstractStrategy.js +296 -0
  36. package/dist/strategies/AbstractStrategy.mediator.d.ts +162 -0
  37. package/dist/strategies/AbstractStrategy.mediator.js +349 -0
  38. package/dist/strategies/ClipboardStrategy.d.ts +67 -0
  39. package/dist/strategies/ClipboardStrategy.js +291 -0
  40. package/dist/strategies/ContextMenuStrategy.d.ts +60 -0
  41. package/dist/strategies/ContextMenuStrategy.js +454 -0
  42. package/dist/strategies/DevToolsStrategy copy.d.ts +85 -0
  43. package/dist/strategies/DevToolsStrategy copy.js +362 -0
  44. package/dist/strategies/DevToolsStrategy-detectorManager.d.ts +70 -0
  45. package/dist/strategies/DevToolsStrategy-detectorManager.js +309 -0
  46. package/dist/strategies/DevToolsStrategy-simple.d.ts +75 -0
  47. package/dist/strategies/DevToolsStrategy-simple.js +366 -0
  48. package/dist/strategies/DevToolsStrategy.d.ts +55 -0
  49. package/dist/strategies/DevToolsStrategy.js +314 -0
  50. package/dist/strategies/ExtensionStrategy.d.ts +66 -0
  51. package/dist/strategies/ExtensionStrategy.js +486 -0
  52. package/dist/strategies/IFrameStrategy.d.ts +49 -0
  53. package/dist/strategies/IFrameStrategy.js +255 -0
  54. package/dist/strategies/KeyboardStrategy.d.ts +35 -0
  55. package/dist/strategies/KeyboardStrategy.js +130 -0
  56. package/dist/strategies/PrintStrategy.d.ts +47 -0
  57. package/dist/strategies/PrintStrategy.js +201 -0
  58. package/dist/strategies/ScreenshotStrategy.d.ts +90 -0
  59. package/dist/strategies/ScreenshotStrategy.js +488 -0
  60. package/dist/strategies/SelectionStrategy.d.ts +49 -0
  61. package/dist/strategies/SelectionStrategy.js +216 -0
  62. package/dist/strategies/StrategyRegistry.d.ts +133 -0
  63. package/dist/strategies/StrategyRegistry.js +379 -0
  64. package/dist/strategies/WatermarkStrategy.d.ts +47 -0
  65. package/dist/strategies/WatermarkStrategy.js +273 -0
  66. package/dist/strategies/index.d.ts +9 -0
  67. package/dist/strategies/index.js +10 -0
  68. package/dist/types/index.d.ts +271 -0
  69. package/dist/types/index.js +16 -0
  70. package/dist/utils/DOMObserver.d.ts +68 -0
  71. package/dist/utils/DOMObserver.js +134 -0
  72. package/dist/utils/base/LoggableComponent.d.ts +62 -0
  73. package/dist/utils/base/LoggableComponent.js +95 -0
  74. package/dist/utils/debuggerDetector/debuggerDetectionWorker.d.ts +6 -0
  75. package/dist/utils/debuggerDetector/debuggerDetectionWorker.js +24 -0
  76. package/dist/utils/debuggerDetector/debuggerDetector.d.ts +55 -0
  77. package/dist/utils/debuggerDetector/debuggerDetector.js +158 -0
  78. package/dist/utils/debuggerDetector/firefoxDetector.d.ts +8 -0
  79. package/dist/utils/debuggerDetector/firefoxDetector.js +64 -0
  80. package/dist/utils/detection.d.ts +29 -0
  81. package/dist/utils/detection.js +267 -0
  82. package/dist/utils/detectors/AbstractDevToolsDetector.d.ts +105 -0
  83. package/dist/utils/detectors/AbstractDevToolsDetector.js +136 -0
  84. package/dist/utils/detectors/dateToStringDetector.d.ts +43 -0
  85. package/dist/utils/detectors/dateToStringDetector.js +96 -0
  86. package/dist/utils/detectors/debugLibDetector.d.ts +64 -0
  87. package/dist/utils/detectors/debugLibDetector.js +195 -0
  88. package/dist/utils/detectors/debuggerDetectionWorker.d.ts +6 -0
  89. package/dist/utils/detectors/debuggerDetectionWorker.js +24 -0
  90. package/dist/utils/detectors/debuggerDetector.d.ts +51 -0
  91. package/dist/utils/detectors/debuggerDetector.js +211 -0
  92. package/dist/utils/detectors/defineGetterDetector.d.ts +48 -0
  93. package/dist/utils/detectors/defineGetterDetector.js +150 -0
  94. package/dist/utils/detectors/detectorInterface.d.ts +36 -0
  95. package/dist/utils/detectors/detectorInterface.js +1 -0
  96. package/dist/utils/detectors/devToolsDetectorManager.d.ts +88 -0
  97. package/dist/utils/detectors/devToolsDetectorManager.js +246 -0
  98. package/dist/utils/detectors/firefoxDetector.d.ts +8 -0
  99. package/dist/utils/detectors/firefoxDetector.js +64 -0
  100. package/dist/utils/detectors/funcToStringDetector.d.ts +43 -0
  101. package/dist/utils/detectors/funcToStringDetector.js +90 -0
  102. package/dist/utils/detectors/regToStringDetector.d.ts +43 -0
  103. package/dist/utils/detectors/regToStringDetector.js +129 -0
  104. package/dist/utils/detectors/sizeDetector.d.ts +54 -0
  105. package/dist/utils/detectors/sizeDetector.js +134 -0
  106. package/dist/utils/detectors/timingDetector.d.ts +55 -0
  107. package/dist/utils/detectors/timingDetector.js +143 -0
  108. package/dist/utils/dom.d.ts +20 -0
  109. package/dist/utils/dom.js +83 -0
  110. package/dist/utils/environment.d.ts +29 -0
  111. package/dist/utils/environment.js +267 -0
  112. package/dist/utils/eventManager.d.ts +167 -0
  113. package/dist/utils/eventManager.js +556 -0
  114. package/dist/utils/index.d.ts +2 -0
  115. package/dist/utils/index.js +3 -0
  116. package/dist/utils/intervalManager.d.ts +96 -0
  117. package/dist/utils/intervalManager.js +229 -0
  118. package/dist/utils/keyboardShortcutManager/keyboardShortcutManager.d.ts +41 -0
  119. package/dist/utils/keyboardShortcutManager/keyboardShortcutManager.js +135 -0
  120. package/dist/utils/keyboardShortcutManager/keyboardShortcuts.d.ts +18 -0
  121. package/dist/utils/keyboardShortcutManager/keyboardShortcuts.js +195 -0
  122. package/dist/utils/logging/LogLevel.d.ts +21 -0
  123. package/dist/utils/logging/LogLevel.js +46 -0
  124. package/dist/utils/logging/LoggingConfig.d.ts +68 -0
  125. package/dist/utils/logging/LoggingConfig.js +64 -0
  126. package/dist/utils/logging/LoggingFactory.d.ts +22 -0
  127. package/dist/utils/logging/LoggingFactory.js +61 -0
  128. package/dist/utils/logging/LoggingService.d.ts +235 -0
  129. package/dist/utils/logging/LoggingService.js +385 -0
  130. package/dist/utils/logging/SimpleLoggingService.d.ts +39 -0
  131. package/dist/utils/logging/SimpleLoggingService.js +58 -0
  132. package/dist/utils/logging/advanced/LogLevel.d.ts +21 -0
  133. package/dist/utils/logging/advanced/LogLevel.js +46 -0
  134. package/dist/utils/logging/advanced/LoggingConfig.d.ts +68 -0
  135. package/dist/utils/logging/advanced/LoggingConfig.js +64 -0
  136. package/dist/utils/logging/advanced/LoggingFactory.d.ts +22 -0
  137. package/dist/utils/logging/advanced/LoggingFactory.js +61 -0
  138. package/dist/utils/logging/advanced/LoggingService.d.ts +235 -0
  139. package/dist/utils/logging/advanced/LoggingService.js +385 -0
  140. package/dist/utils/logging/simple/Loggable.d.ts +33 -0
  141. package/dist/utils/logging/simple/Loggable.js +1 -0
  142. package/dist/utils/logging/simple/LoggingDelegate.d.ts +42 -0
  143. package/dist/utils/logging/simple/LoggingDelegate.js +53 -0
  144. package/dist/utils/logging/simple/SimpleLoggingService.d.ts +39 -0
  145. package/dist/utils/logging/simple/SimpleLoggingService.js +58 -0
  146. package/dist/utils/orientation.d.ts +15 -0
  147. package/dist/utils/orientation.js +32 -0
  148. package/dist/utils/protectedContentManager-simple.d.ts +86 -0
  149. package/dist/utils/protectedContentManager-simple.js +180 -0
  150. package/dist/utils/protectedContentManager.d.ts +162 -0
  151. package/dist/utils/protectedContentManager.js +427 -0
  152. package/dist/utils/screenshotDetector.d.ts +72 -0
  153. package/dist/utils/screenshotDetector.js +179 -0
  154. package/dist/utils/securityOverlayManager-observer-pause.d.ts +283 -0
  155. package/dist/utils/securityOverlayManager-observer-pause.js +878 -0
  156. package/dist/utils/securityOverlayManager-simple.d.ts +197 -0
  157. package/dist/utils/securityOverlayManager-simple.js +552 -0
  158. package/dist/utils/securityOverlayManager.d.ts +260 -0
  159. package/dist/utils/securityOverlayManager.js +774 -0
  160. package/dist/utils/timeoutManager.d.ts +55 -0
  161. package/dist/utils/timeoutManager.js +121 -0
  162. package/package.json +54 -0
@@ -0,0 +1,349 @@
1
+ import { eventManager } from "../utils/eventManager";
2
+ import { isBrowser } from "../utils/detection";
3
+ import { ProtectionEventType } from "../core/mediator/protection-event";
4
+ /**
5
+ * Error types for protection strategies
6
+ */
7
+ export var StrategyErrorType;
8
+ (function (StrategyErrorType) {
9
+ StrategyErrorType["INITIALIZATION"] = "initialization";
10
+ StrategyErrorType["APPLICATION"] = "application";
11
+ StrategyErrorType["REMOVAL"] = "removal";
12
+ StrategyErrorType["EVENT_HANDLING"] = "event_handling";
13
+ StrategyErrorType["OPTION_UPDATE"] = "option_update";
14
+ StrategyErrorType["UNKNOWN"] = "unknown";
15
+ })(StrategyErrorType || (StrategyErrorType = {}));
16
+ /**
17
+ * Custom error class for protection strategies
18
+ */
19
+ export class StrategyError extends Error {
20
+ /**
21
+ * Create a new StrategyError
22
+ * @param strategyName Name of the strategy where the error occurred
23
+ * @param errorType Type of error that occurred
24
+ * @param message Error message
25
+ * @param originalError Original error that was caught (if any)
26
+ */
27
+ constructor(strategyName, errorType, message, originalError) {
28
+ super(`[${strategyName}] ${message}${originalError instanceof Error ? `: ${originalError.message}` : ""}`);
29
+ this.strategyName = strategyName;
30
+ this.errorType = errorType;
31
+ this.originalError = originalError;
32
+ this.name = "StrategyError";
33
+ // Maintain the stack trace
34
+ if (Error.captureStackTrace) {
35
+ Error.captureStackTrace(this, StrategyError);
36
+ }
37
+ }
38
+ }
39
+ /**
40
+ * Abstract base class for protection strategies
41
+ * Implements common functionality to reduce duplication
42
+ */
43
+ export class AbstractStrategy {
44
+ /**
45
+ * Create a new strategy
46
+ * @param strategyName Unique name for the strategy
47
+ * @param debugMode Enable debug mode for troubleshooting
48
+ */
49
+ constructor(strategyName, debugMode = false) {
50
+ this.mediator = null;
51
+ this.subscriptionIds = []; // For tracking event subscriptions
52
+ this.isAppliedFlag = false;
53
+ this.debugMode = false;
54
+ this.eventIds = [];
55
+ this.STRATEGY_NAME = strategyName;
56
+ this.debugMode = debugMode;
57
+ }
58
+ /**
59
+ * Set the mediator for this strategy
60
+ * This connects the strategy to the event system
61
+ * @param mediator The protection mediator instance
62
+ */
63
+ setMediator(mediator) {
64
+ if (this.mediator === mediator)
65
+ return; // Avoid redundant setup
66
+ // Clean up any existing subscriptions if we're changing mediators
67
+ if (this.mediator && this.subscriptionIds.length > 0) {
68
+ this.subscriptionIds.forEach((id) => this.mediator?.unsubscribe(id));
69
+ this.subscriptionIds = [];
70
+ }
71
+ this.mediator = mediator;
72
+ this.log(`Connected to mediator`);
73
+ // Base class doesn't subscribe to any events by default
74
+ // Specific strategies will override this method to add their subscriptions
75
+ }
76
+ /**
77
+ * Helper method for subscribing to events
78
+ * Tracks subscription IDs for cleanup
79
+ */
80
+ subscribe(eventType, handler, options) {
81
+ if (!this.mediator) {
82
+ this.warn(`Cannot subscribe to ${eventType} - no mediator set`);
83
+ return "";
84
+ }
85
+ const id = this.mediator.subscribe(eventType, handler, {
86
+ ...options,
87
+ context: this.STRATEGY_NAME, // Always include strategy name as context
88
+ });
89
+ if (id) {
90
+ this.subscriptionIds.push(id);
91
+ }
92
+ return id;
93
+ }
94
+ /**
95
+ * Helper method for publishing events
96
+ */
97
+ publishEvent(eventType, data) {
98
+ if (!this.mediator) {
99
+ this.warn(`Cannot publish ${eventType} - no mediator set`);
100
+ return;
101
+ }
102
+ this.mediator.publish({
103
+ type: eventType,
104
+ source: this.STRATEGY_NAME,
105
+ timestamp: Date.now(),
106
+ data: data, // Explicit type assertion
107
+ });
108
+ }
109
+ /**
110
+ * Remove the protection strategy
111
+ * Can be overridden by subclasses for custom cleanup
112
+ */
113
+ remove() {
114
+ try {
115
+ if (!this.isAppliedFlag) {
116
+ this.log("Protection not applied");
117
+ return;
118
+ }
119
+ // Unsubscribe from all events
120
+ if (this.mediator && this.subscriptionIds.length > 0) {
121
+ this.subscriptionIds.forEach((id) => {
122
+ this.mediator?.unsubscribe(id);
123
+ });
124
+ this.subscriptionIds = [];
125
+ this.log("Unsubscribed from all events");
126
+ }
127
+ if (isBrowser()) {
128
+ // Remove all event listeners using EventManager
129
+ const removedCount = this.removeEventsByOwner();
130
+ // Clear the event IDs array
131
+ this.eventIds = [];
132
+ this.isAppliedFlag = false;
133
+ this.log(`Protection removed (${removedCount} events)`);
134
+ // Publish event that strategy was removed
135
+ this.publishEvent(ProtectionEventType.STRATEGY_REMOVED);
136
+ }
137
+ }
138
+ catch (error) {
139
+ this.handleError(StrategyErrorType.REMOVAL, "Failed to remove protection", error);
140
+ }
141
+ }
142
+ /**
143
+ * Check if the strategy is currently applied
144
+ */
145
+ isApplied() {
146
+ return this.isAppliedFlag;
147
+ }
148
+ /**
149
+ * Update strategy options
150
+ * Should be implemented by subclasses that support options
151
+ */
152
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
153
+ updateOptions(options) {
154
+ try {
155
+ // Default implementation just logs that the method is not implemented
156
+ this.log("Method updateOptions not implemented");
157
+ }
158
+ catch (error) {
159
+ this.handleError(StrategyErrorType.OPTION_UPDATE, "Failed to update options", error);
160
+ }
161
+ }
162
+ /**
163
+ * Get the debug mode status
164
+ */
165
+ isDebugEnabled() {
166
+ return this.debugMode;
167
+ }
168
+ /**
169
+ * Set debug mode
170
+ */
171
+ setDebugMode(enabled) {
172
+ this.debugMode = enabled;
173
+ this.log(`Debug mode ${enabled ? "enabled" : "disabled"}`);
174
+ }
175
+ /**
176
+ * Handle an error that occurred in the strategy
177
+ * @param errorType Type of error
178
+ * @param message Error message
179
+ * @param originalError Original error that was caught
180
+ */
181
+ handleError(errorType, message, originalError) {
182
+ const error = new StrategyError(this.STRATEGY_NAME, errorType, message, originalError);
183
+ if (this.debugMode) {
184
+ console.error(error);
185
+ if (error.originalError instanceof Error && error.originalError.stack) {
186
+ console.error("Original stack:", error.originalError.stack);
187
+ }
188
+ }
189
+ else {
190
+ console.error(error.message);
191
+ }
192
+ }
193
+ /**
194
+ * Log a debug message if debug mode is enabled
195
+ * @param message Message to log
196
+ * @param args Additional arguments to log
197
+ */
198
+ log(message, ...args) {
199
+ if (this.debugMode) {
200
+ console.log(`${this.STRATEGY_NAME}: ${message}`, ...args);
201
+ }
202
+ }
203
+ /**
204
+ * Log a warning message
205
+ * @param message Warning message
206
+ * @param args Additional arguments to log
207
+ */
208
+ warn(message, ...args) {
209
+ if (this.debugMode) {
210
+ console.warn(`${this.STRATEGY_NAME}: ${message}`, ...args);
211
+ }
212
+ else {
213
+ // In non-debug mode, only log the message without args for brevity
214
+ console.warn(`${this.STRATEGY_NAME}: ${message}`);
215
+ }
216
+ }
217
+ /**
218
+ * Log an error message
219
+ * @param message Error message
220
+ * @param args Additional arguments to log
221
+ */
222
+ error(message, ...args) {
223
+ console.error(`${this.STRATEGY_NAME}: ${message}`, ...args);
224
+ }
225
+ /**
226
+ * Execute a function with error handling
227
+ * @param operation Name of the operation for error reporting
228
+ * @param errorType Type of error for categorization
229
+ * @param fn Function to execute
230
+ * @returns The result of the function or undefined if an error occurred
231
+ */
232
+ safeExecute(operation, errorType, fn) {
233
+ try {
234
+ return fn();
235
+ }
236
+ catch (error) {
237
+ this.handleError(errorType, `Error during ${operation}`, error);
238
+ return undefined;
239
+ }
240
+ }
241
+ /**
242
+ * Execute an async function with error handling
243
+ * @param operation Name of the operation for error reporting
244
+ * @param errorType Type of error for categorization
245
+ * @param fn Async function to execute
246
+ * @returns Promise resolving to the result of the function or undefined if an error occurred
247
+ */
248
+ async safeExecuteAsync(operation, errorType, fn) {
249
+ try {
250
+ return await fn();
251
+ }
252
+ catch (error) {
253
+ this.handleError(errorType, `Error during ${operation}`, error);
254
+ return undefined;
255
+ }
256
+ }
257
+ /**
258
+ * Register an event with the EventManager
259
+ * @param target The target element, document, or window
260
+ * @param eventType The type of event (e.g., "click", "keydown")
261
+ * @param handler The event handler function
262
+ * @param options Additional options for the event listener
263
+ * @returns The ID of the registered event
264
+ */
265
+ registerEvent(target, eventType, handler, options) {
266
+ if (!target || !isBrowser())
267
+ return "";
268
+ try {
269
+ // Create a wrapped handler that includes error handling
270
+ const wrappedHandler = (event) => {
271
+ try {
272
+ return handler(event);
273
+ }
274
+ catch (error) {
275
+ this.handleError(StrategyErrorType.EVENT_HANDLING, `Error handling ${eventType} event`, error);
276
+ }
277
+ };
278
+ // Pass all options including priority to the eventManager
279
+ const eventId = eventManager.addEventListener(target, eventType, wrappedHandler, this.STRATEGY_NAME, options);
280
+ if (eventId) {
281
+ this.eventIds.push(eventId);
282
+ this.log(`Registered ${eventType} event (ID: ${eventId})`);
283
+ }
284
+ return eventId;
285
+ }
286
+ catch (error) {
287
+ this.handleError(StrategyErrorType.EVENT_HANDLING, `Failed to register ${eventType} event`, error);
288
+ return "";
289
+ }
290
+ }
291
+ /**
292
+ * Remove all event listeners for this strategy
293
+ * @returns The number of events removed
294
+ */
295
+ removeEventsByOwner() {
296
+ try {
297
+ const removedCount = eventManager.removeEventsByOwner(this.STRATEGY_NAME);
298
+ if (removedCount > 0) {
299
+ this.log(`Removed ${removedCount} events by owner ID`);
300
+ }
301
+ return removedCount;
302
+ }
303
+ catch (error) {
304
+ this.handleError(StrategyErrorType.REMOVAL, "Failed to remove events by owner", error);
305
+ return 0;
306
+ }
307
+ }
308
+ /**
309
+ * Remove all event listeners for a specific target
310
+ * @param target The target to remove events from
311
+ * @returns The number of events removed
312
+ */
313
+ removeAllEventsForTarget(target) {
314
+ if (!target || !isBrowser())
315
+ return 0;
316
+ try {
317
+ const removedCount = eventManager.removeAllEventsForTarget(target);
318
+ if (removedCount > 0) {
319
+ this.log(`Removed ${removedCount} events from target`);
320
+ }
321
+ return removedCount;
322
+ }
323
+ catch (error) {
324
+ this.handleError(StrategyErrorType.REMOVAL, "Failed to remove events for target", error);
325
+ return 0;
326
+ }
327
+ }
328
+ /**
329
+ * Remove event listeners by CSS selector
330
+ * @param selector CSS selector to match elements
331
+ * @param eventType Type of event to remove
332
+ * @returns The number of events removed
333
+ */
334
+ removeEventsBySelector(selector, eventType) {
335
+ if (!isBrowser())
336
+ return 0;
337
+ try {
338
+ const removedCount = eventManager.removeEventsBySelector(selector, eventType, this.STRATEGY_NAME);
339
+ if (removedCount > 0) {
340
+ this.log(`Removed ${removedCount} ${eventType} events via selector "${selector}"`);
341
+ }
342
+ return removedCount;
343
+ }
344
+ catch (error) {
345
+ this.handleError(StrategyErrorType.REMOVAL, `Failed to remove events by selector "${selector}"`, error);
346
+ return 0;
347
+ }
348
+ }
349
+ }
@@ -0,0 +1,67 @@
1
+ import { AbstractStrategy } from "./AbstractStrategy";
2
+ import type { ClipboardOptions } from "../types";
3
+ import type { CustomEventHandlers } from "../types";
4
+ /**
5
+ * Strategy to prevent copying content via clipboard operations
6
+ * Blocks copy, cut, and optionally paste operations
7
+ */
8
+ export declare class ClipboardStrategy extends AbstractStrategy {
9
+ private options;
10
+ private targetElement;
11
+ private customHandler?;
12
+ private originalClipboardWriteText;
13
+ private originalClipboardReadText;
14
+ private originalExecCommand;
15
+ /**
16
+ * Create a new ClipboardStrategy
17
+ * @param options Configuration options
18
+ * @param targetElement Target element to protect (defaults to document.body)
19
+ * @param customHandler Custom handler for clipboard events
20
+ * @param debugMode Enable debug mode for troubleshooting
21
+ */
22
+ constructor(options?: ClipboardOptions, targetElement?: HTMLElement | null, customHandler?: CustomEventHandlers["onClipboardAttempt"], debugMode?: boolean);
23
+ /**
24
+ * Apply clipboard protection
25
+ */
26
+ apply(): void;
27
+ /**
28
+ * Remove clipboard protection
29
+ */
30
+ remove(): void;
31
+ /**
32
+ * Update clipboard protection options
33
+ * @param options New options to apply
34
+ */
35
+ updateOptions(options: Partial<ClipboardOptions>): void;
36
+ /**
37
+ * Handle copy event
38
+ * @param event Copy event
39
+ */
40
+ private handleCopy;
41
+ /**
42
+ * Handle cut event
43
+ * @param event Cut event
44
+ */
45
+ private handleCut;
46
+ /**
47
+ * Handle paste event
48
+ * @param event Paste event
49
+ */
50
+ private handlePaste;
51
+ /**
52
+ * Intercept the Clipboard API to prevent programmatic access
53
+ */
54
+ private interceptClipboardAPI;
55
+ /**
56
+ * Restore original Clipboard API methods
57
+ */
58
+ private restoreClipboardAPI;
59
+ /**
60
+ * Intercept document.execCommand to prevent clipboard operations
61
+ */
62
+ private interceptExecCommand;
63
+ /**
64
+ * Restore original document.execCommand
65
+ */
66
+ private restoreExecCommand;
67
+ }