@c15t/dev-tools 2.0.0-rc.6 → 2.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/dist/index.cjs CHANGED
@@ -1970,6 +1970,7 @@ var __webpack_exports__ = {};
1970
1970
  createDevToolsPanel: ()=>createDevToolsPanel,
1971
1971
  createDevTools: ()=>createDevTools
1972
1972
  });
1973
+ const external_c15t_namespaceObject = require("c15t");
1973
1974
  const DEVTOOLS_STORAGE_KEY = 'c15t-devtools-position';
1974
1975
  const DRAG_THRESHOLD = 30;
1975
1976
  const VELOCITY_THRESHOLD = 0.15;
@@ -2347,7 +2348,6 @@ var __webpack_exports__ = {};
2347
2348
  }
2348
2349
  return null;
2349
2350
  }
2350
- const version = '2.0.0-rc.6';
2351
2351
  const DEVTOOLS_ICON = `<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 446 445" aria-label="c15t">
2352
2352
  <path fill="currentColor" d="M223.178.313c39.064 0 70.732 31.668 70.732 70.732-.001 39.064-31.668 70.731-70.732 70.731-12.181 0-23.642-3.079-33.649-8.502l-55.689 55.689a70.267 70.267 0 0 1 5.574 13.441h167.531c8.695-29.217 35.762-50.523 67.804-50.523 39.064 0 70.731 31.668 70.731 70.732s-31.668 70.732-70.731 70.732c-32.042 0-59.108-21.306-67.803-50.523H139.413a70.417 70.417 0 0 1-7.888 17.396l54.046 54.046c10.893-6.851 23.786-10.815 37.605-10.815 39.064 0 70.732 31.669 70.732 70.733 0 39.064-31.668 70.731-70.732 70.731s-70.732-31.667-70.732-70.731c0-10.518 2.296-20.499 6.414-29.471l-57.78-57.78c-8.972 4.117-18.952 6.414-29.47 6.414-39.063 0-70.731-31.668-70.732-70.732 0-39.064 31.669-70.732 70.733-70.732 12.18 0 23.642 3.079 33.649 8.502l55.688-55.688c-5.423-10.007-8.502-21.469-8.502-33.65 0-39.064 31.668-70.733 70.732-70.733Zm0 343.555c-16.742 0-30.314 13.572-30.314 30.314 0 16.741 13.572 30.313 30.314 30.313s30.314-13.572 30.314-30.313c0-16.742-13.572-30.314-30.314-30.314ZM71.611 192.299c-16.742 0-30.315 13.572-30.315 30.314s13.573 30.314 30.315 30.314c16.741 0 30.313-13.572 30.313-30.314 0-16.741-13.572-30.314-30.313-30.314Zm303.138 0c-16.729 0-30.294 13.551-30.315 30.275l.001.039-.001.038c.021 16.725 13.586 30.276 30.315 30.276 16.741 0 30.313-13.572 30.313-30.314 0-16.741-13.572-30.314-30.313-30.314ZM223.178 40.73c-16.742 0-30.314 13.573-30.314 30.315s13.573 30.313 30.314 30.313c16.742 0 30.313-13.572 30.314-30.313 0-16.742-13.572-30.314-30.314-30.315Z"/>
2353
2353
  </svg>`;
@@ -2764,7 +2764,7 @@ var __webpack_exports__ = {};
2764
2764
  }
2765
2765
  }));
2766
2766
  footerElement.appendChild(renderer_span({
2767
- text: `v${version}`
2767
+ text: "v2.0.0"
2768
2768
  }));
2769
2769
  }
2770
2770
  function renderErrorState(container) {
@@ -4069,7 +4069,8 @@ var __webpack_exports__ = {};
4069
4069
  'error',
4070
4070
  'consent',
4071
4071
  'network',
4072
- 'iab'
4072
+ 'iab',
4073
+ "script"
4073
4074
  ];
4074
4075
  function createFilterButton(filter, active, onClick) {
4075
4076
  return createButton({
@@ -4084,6 +4085,7 @@ var __webpack_exports__ = {};
4084
4085
  if ('error' === filter) return 'error' === event.type;
4085
4086
  if ('consent' === filter) return 'consent_set' === event.type || 'consent_save' === event.type || 'consent_reset' === event.type;
4086
4087
  if ('network' === filter) return 'network' === event.type;
4088
+ if ("script" === filter) return "script" === event.type;
4087
4089
  return 'iab' === event.type;
4088
4090
  }
4089
4091
  function matchesSearch(event, query) {
@@ -4207,6 +4209,8 @@ var __webpack_exports__ = {};
4207
4209
  return '◉';
4208
4210
  case 'iab':
4209
4211
  return '◆';
4212
+ case "script":
4213
+ return '⌘';
4210
4214
  default:
4211
4215
  return '○';
4212
4216
  }
@@ -4224,6 +4228,8 @@ var __webpack_exports__ = {};
4224
4228
  return 'var(--c15t-devtools-badge-warning, #f59e0b)';
4225
4229
  case 'iab':
4226
4230
  return 'var(--c15t-devtools-badge-info, #3b82f6)';
4231
+ case "script":
4232
+ return 'var(--c15t-devtools-badge-info, #14b8a6)';
4227
4233
  default:
4228
4234
  return 'var(--c15t-text-muted)';
4229
4235
  }
@@ -5524,6 +5530,20 @@ var __webpack_exports__ = {};
5524
5530
  <polyline points="8 6 2 12 8 18"></polyline>
5525
5531
  </svg>`;
5526
5532
  const scriptsSearchByContainer = new WeakMap();
5533
+ const expandedScriptsByContainer = new WeakMap();
5534
+ const CHEVRON_DOWN_ICON = `<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">
5535
+ <polyline points="6 9 12 15 18 9"></polyline>
5536
+ </svg>`;
5537
+ const CHEVRON_RIGHT_ICON = `<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">
5538
+ <polyline points="9 18 15 12 9 6"></polyline>
5539
+ </svg>`;
5540
+ function getExpandedScripts(container) {
5541
+ const existing = expandedScriptsByContainer.get(container);
5542
+ if (existing) return existing;
5543
+ const expanded = new Set();
5544
+ expandedScriptsByContainer.set(container, expanded);
5545
+ return expanded;
5546
+ }
5527
5547
  function renderScriptsPanel(container, options) {
5528
5548
  const { getState, getEvents } = options;
5529
5549
  clearElement(container);
@@ -5585,6 +5605,10 @@ var __webpack_exports__ = {};
5585
5605
  for (const script of filteredScripts){
5586
5606
  const scriptId = script.id;
5587
5607
  const isLoaded = true === loadedScripts[scriptId];
5608
+ const scriptEvents = getScriptActivityEvents(events, scriptId);
5609
+ const latestActivity = scriptEvents[scriptEvents.length - 1];
5610
+ const expandedScripts = getExpandedScripts(container);
5611
+ const isExpanded = expandedScripts.has(scriptId);
5588
5612
  const category = script.category;
5589
5613
  const categoryDisplay = 'string' == typeof category ? category : JSON.stringify(category);
5590
5614
  let status = 'pending';
@@ -5606,7 +5630,7 @@ var __webpack_exports__ = {};
5606
5630
  text: status.charAt(0).toUpperCase() + status.slice(1),
5607
5631
  variant: statusVariant
5608
5632
  });
5609
- const row = renderer_div({
5633
+ const header = renderer_div({
5610
5634
  style: {
5611
5635
  display: 'flex',
5612
5636
  alignItems: 'center',
@@ -5645,19 +5669,57 @@ var __webpack_exports__ = {};
5645
5669
  whiteSpace: 'nowrap'
5646
5670
  },
5647
5671
  text: `Category: ${categoryDisplay}`
5648
- })
5672
+ }),
5673
+ ...latestActivity && scriptEvents.length > 0 ? [
5674
+ renderer_div({
5675
+ style: {
5676
+ fontSize: 'var(--c15t-devtools-font-size-xs)',
5677
+ color: 'var(--c15t-text-muted)',
5678
+ overflow: 'hidden',
5679
+ textOverflow: 'ellipsis',
5680
+ whiteSpace: 'nowrap'
5681
+ },
5682
+ text: `Activity: ${latestActivity.message} (${scriptEvents.length} event${1 === scriptEvents.length ? '' : 's'})`
5683
+ })
5684
+ ] : []
5649
5685
  ]
5650
5686
  }),
5651
5687
  renderer_div({
5652
5688
  style: {
5653
- flexShrink: '0'
5689
+ flexShrink: '0',
5690
+ display: 'flex',
5691
+ alignItems: 'center',
5692
+ gap: '8px'
5654
5693
  },
5655
5694
  children: [
5656
- badge
5695
+ badge,
5696
+ ...scriptEvents.length > 0 ? [
5697
+ createAccordionToggle({
5698
+ scriptId,
5699
+ isExpanded,
5700
+ onToggle: ()=>{
5701
+ if (isExpanded) expandedScripts.delete(scriptId);
5702
+ else expandedScripts.add(scriptId);
5703
+ renderScriptsPanel(container, options);
5704
+ }
5705
+ })
5706
+ ] : []
5657
5707
  ]
5658
5708
  })
5659
5709
  ]
5660
5710
  });
5711
+ const details = isExpanded && scriptEvents.length > 0 ? createScriptActivityDetails(scriptEvents) : null;
5712
+ const row = renderer_div({
5713
+ style: {
5714
+ display: 'flex',
5715
+ flexDirection: 'column',
5716
+ borderBottom: '1px solid var(--c15t-border)'
5717
+ },
5718
+ children: [
5719
+ header,
5720
+ details
5721
+ ]
5722
+ });
5661
5723
  scriptsList.appendChild(row);
5662
5724
  }
5663
5725
  const lastRow = scriptsList.lastElementChild;
@@ -5794,13 +5856,172 @@ var __webpack_exports__ = {};
5794
5856
  return 'string' == typeof url ? url : event.message;
5795
5857
  }
5796
5858
  function formatEventTime(timestamp) {
5797
- return new Date(timestamp).toLocaleTimeString('en-US', {
5798
- hour12: false,
5799
- hour: '2-digit',
5800
- minute: '2-digit',
5801
- second: '2-digit'
5859
+ const date = new Date(timestamp);
5860
+ const hours = String(date.getHours()).padStart(2, '0');
5861
+ const minutes = String(date.getMinutes()).padStart(2, '0');
5862
+ const seconds = String(date.getSeconds()).padStart(2, '0');
5863
+ const milliseconds = String(date.getMilliseconds()).padStart(3, '0');
5864
+ return `${hours}:${minutes}:${seconds}.${milliseconds}`;
5865
+ }
5866
+ function getScriptActivityEvents(events, scriptId) {
5867
+ return events.filter((event)=>{
5868
+ if ("script" !== event.type) return false;
5869
+ const data = event.data;
5870
+ if (data?.scriptId !== scriptId) return false;
5871
+ return data?.scope === 'lifecycle' || data?.scope === 'phase';
5872
+ }).sort((left, right)=>left.timestamp - right.timestamp);
5873
+ }
5874
+ function createAccordionToggle(options) {
5875
+ const { scriptId, isExpanded, onToggle } = options;
5876
+ const toggle = renderer_button({
5877
+ ariaLabel: `${isExpanded ? 'Collapse' : 'Expand'} ${scriptId} activity`,
5878
+ ariaExpanded: isExpanded ? 'true' : 'false',
5879
+ style: {
5880
+ display: 'inline-flex',
5881
+ alignItems: 'center',
5882
+ justifyContent: 'center',
5883
+ width: '24px',
5884
+ height: '24px',
5885
+ padding: '0',
5886
+ border: '1px solid var(--c15t-border)',
5887
+ borderRadius: '6px',
5888
+ background: 'transparent',
5889
+ color: 'var(--c15t-text-muted)',
5890
+ cursor: 'pointer',
5891
+ flexShrink: '0'
5892
+ },
5893
+ onClick: onToggle
5894
+ });
5895
+ toggle.innerHTML = isExpanded ? CHEVRON_DOWN_ICON : CHEVRON_RIGHT_ICON;
5896
+ return toggle;
5897
+ }
5898
+ function createScriptActivityDetails(events) {
5899
+ const groupedEvents = groupScriptActivityEvents(events.slice(-8));
5900
+ return renderer_div({
5901
+ style: {
5902
+ display: 'flex',
5903
+ flexDirection: 'column',
5904
+ gap: '6px',
5905
+ padding: '0 0 10px 0',
5906
+ marginLeft: '0'
5907
+ },
5908
+ children: groupedEvents.map(([groupName, groupEvents])=>createScriptActivityGroup(groupName, groupEvents))
5802
5909
  });
5803
5910
  }
5911
+ function createScriptActivityGroup(groupName, events) {
5912
+ return renderer_div({
5913
+ style: {
5914
+ display: 'flex',
5915
+ flexDirection: 'column',
5916
+ gap: '4px'
5917
+ },
5918
+ children: [
5919
+ renderer_span({
5920
+ style: {
5921
+ fontSize: 'var(--c15t-devtools-font-size-xs)',
5922
+ fontWeight: '600',
5923
+ color: 'var(--c15t-text)',
5924
+ textTransform: 'none'
5925
+ },
5926
+ text: groupName
5927
+ }),
5928
+ ...events.map((event)=>createScriptActivityRow(event))
5929
+ ]
5930
+ });
5931
+ }
5932
+ function createScriptActivityRow(event) {
5933
+ const data = event.data ?? {};
5934
+ const scope = 'string' == typeof data.scope ? data.scope : void 0;
5935
+ const phase = 'string' == typeof data.phase ? data.phase : void 0;
5936
+ const stepType = 'string' == typeof data.stepType ? data.stepType : void 0;
5937
+ const metadata = [
5938
+ scope,
5939
+ phase,
5940
+ stepType
5941
+ ].filter(Boolean).join(' / ');
5942
+ return renderer_div({
5943
+ style: {
5944
+ display: 'flex',
5945
+ flexDirection: 'column',
5946
+ gap: '2px',
5947
+ padding: '6px 10px',
5948
+ marginLeft: '0',
5949
+ borderLeft: '2px solid var(--c15t-border)',
5950
+ backgroundColor: 'var(--c15t-devtools-surface-secondary, rgba(127,127,127,0.06))',
5951
+ borderRadius: '0 8px 8px 0'
5952
+ },
5953
+ children: [
5954
+ renderer_div({
5955
+ style: {
5956
+ display: 'flex',
5957
+ alignItems: 'center',
5958
+ justifyContent: 'space-between',
5959
+ gap: '8px'
5960
+ },
5961
+ children: [
5962
+ renderer_span({
5963
+ style: {
5964
+ fontSize: 'var(--c15t-devtools-font-size-xs)',
5965
+ fontWeight: '600',
5966
+ color: 'var(--c15t-text)'
5967
+ },
5968
+ text: event.message
5969
+ }),
5970
+ renderer_span({
5971
+ style: {
5972
+ fontSize: 'var(--c15t-devtools-font-size-xs)',
5973
+ color: 'var(--c15t-text-muted)',
5974
+ flexShrink: '0'
5975
+ },
5976
+ text: formatEventTime(event.timestamp)
5977
+ })
5978
+ ]
5979
+ }),
5980
+ ...metadata ? [
5981
+ renderer_span({
5982
+ style: {
5983
+ fontSize: 'var(--c15t-devtools-font-size-xs)',
5984
+ color: 'var(--c15t-text-muted)'
5985
+ },
5986
+ text: metadata
5987
+ })
5988
+ ] : []
5989
+ ]
5990
+ });
5991
+ }
5992
+ function groupScriptActivityEvents(events) {
5993
+ const groups = new Map();
5994
+ for (const event of events){
5995
+ const groupName = getScriptActivityGroupName(event);
5996
+ const existing = groups.get(groupName);
5997
+ if (existing) existing.push(event);
5998
+ else groups.set(groupName, [
5999
+ event
6000
+ ]);
6001
+ }
6002
+ const orderedGroupNames = [
6003
+ 'onBeforeLoad',
6004
+ 'onLoad',
6005
+ 'onConsentChange',
6006
+ 'other'
6007
+ ];
6008
+ return orderedGroupNames.map((groupName)=>{
6009
+ const groupEvents = groups.get(groupName);
6010
+ return groupEvents ? [
6011
+ groupName,
6012
+ groupEvents
6013
+ ] : null;
6014
+ }).filter((group)=>null !== group);
6015
+ }
6016
+ function getScriptActivityGroupName(event) {
6017
+ const data = event.data ?? {};
6018
+ if ('string' == typeof data.callback) return data.callback;
6019
+ const phase = 'string' == typeof data.phase ? data.phase : '';
6020
+ if ('bootstrap' === phase || 'consent-default' === phase || 'setup' === phase || 'onBeforeLoadGranted' === phase || 'onBeforeLoadDenied' === phase) return 'onBeforeLoad';
6021
+ if ('afterLoad' === phase || 'onLoadGranted' === phase || 'onLoadDenied' === phase) return 'onLoad';
6022
+ if ('consent-update' === phase || 'onConsentChange' === phase || 'onConsentGranted' === phase || 'onConsentDenied' === phase) return 'onConsentChange';
6023
+ return 'other';
6024
+ }
5804
6025
  function scripts_truncateText(text, maxLength) {
5805
6026
  if (text.length <= maxLength) return text;
5806
6027
  return `${text.slice(0, maxLength - 3)}...`;
@@ -6378,6 +6599,7 @@ var __webpack_exports__ = {};
6378
6599
  const state = entry.store.getState();
6379
6600
  state.setCallback('onBannerFetched', entry.originalCallbacks.onBannerFetched);
6380
6601
  state.setCallback('onConsentSet', entry.originalCallbacks.onConsentSet);
6602
+ state.setCallback('onConsentChanged', entry.originalCallbacks.onConsentChanged);
6381
6603
  state.setCallback('onError', entry.originalCallbacks.onError);
6382
6604
  state.setCallback('onBeforeConsentRevocationReload', entry.originalCallbacks.onBeforeConsentRevocationReload);
6383
6605
  const blocker = state.networkBlocker;
@@ -6415,6 +6637,14 @@ var __webpack_exports__ = {};
6415
6637
  });
6416
6638
  if ('function' == typeof entry.originalCallbacks.onConsentSet) entry.originalCallbacks.onConsentSet(payload);
6417
6639
  });
6640
+ store.getState().setCallback('onConsentChanged', (payload)=>{
6641
+ emitEvent(entry, {
6642
+ type: 'consent_save',
6643
+ message: 'Consent preferences changed',
6644
+ data: payload
6645
+ });
6646
+ if ('function' == typeof entry.originalCallbacks.onConsentChanged) entry.originalCallbacks.onConsentChanged(payload);
6647
+ });
6418
6648
  store.getState().setCallback('onError', (payload)=>{
6419
6649
  const errorMessage = payload.error;
6420
6650
  emitEvent(entry, {
@@ -6555,6 +6785,25 @@ var __webpack_exports__ = {};
6555
6785
  loadedScripts: state.loadedScripts
6556
6786
  };
6557
6787
  }
6788
+ function scriptDebugEventToLogEntry(event) {
6789
+ return {
6790
+ type: "script",
6791
+ message: event.message,
6792
+ data: {
6793
+ ...event.data ?? {},
6794
+ source: event.source,
6795
+ scope: event.scope,
6796
+ action: event.action,
6797
+ scriptId: event.scriptId,
6798
+ elementId: event.elementId,
6799
+ hasConsent: event.hasConsent,
6800
+ callback: event.callback,
6801
+ phase: event.phase,
6802
+ stepType: event.stepType,
6803
+ stepIndex: event.stepIndex
6804
+ }
6805
+ };
6806
+ }
6558
6807
  function createDevTools(options = {}) {
6559
6808
  const { namespace = 'c15tStore', position = 'bottom-right', defaultOpen = false } = options;
6560
6809
  const stateManager = createStateManager({
@@ -6562,6 +6811,7 @@ var __webpack_exports__ = {};
6562
6811
  isOpen: defaultOpen
6563
6812
  });
6564
6813
  let detachInstrumentation = null;
6814
+ let detachScriptDebug = null;
6565
6815
  const storeConnector = createStoreConnector({
6566
6816
  namespace,
6567
6817
  onConnect: (_state, store)=>{
@@ -6573,6 +6823,10 @@ var __webpack_exports__ = {};
6573
6823
  stateManager.addEvent(event);
6574
6824
  }
6575
6825
  });
6826
+ detachScriptDebug?.();
6827
+ detachScriptDebug = (0, external_c15t_namespaceObject.subscribeToScriptDebugEvents)((event)=>{
6828
+ stateManager.addEvent(scriptDebugEventToLogEntry(event));
6829
+ });
6576
6830
  stateManager.setConnected(true);
6577
6831
  stateManager.addEvent({
6578
6832
  type: 'info',
@@ -6609,6 +6863,8 @@ var __webpack_exports__ = {};
6609
6863
  stateManager.setConnected(false);
6610
6864
  detachInstrumentation?.();
6611
6865
  detachInstrumentation = null;
6866
+ detachScriptDebug?.();
6867
+ detachScriptDebug = null;
6612
6868
  stateManager.addEvent({
6613
6869
  type: 'error',
6614
6870
  message: 'Disconnected from c15tStore'
@@ -6698,6 +6954,8 @@ var __webpack_exports__ = {};
6698
6954
  destroy: ()=>{
6699
6955
  detachInstrumentation?.();
6700
6956
  detachInstrumentation = null;
6957
+ detachScriptDebug?.();
6958
+ detachScriptDebug = null;
6701
6959
  panelHeightAnimator.destroy();
6702
6960
  tabsInstance?.destroy();
6703
6961
  panelInstance.destroy();
@@ -6712,6 +6970,7 @@ var __webpack_exports__ = {};
6712
6970
  function createDevToolsPanel(options) {
6713
6971
  const { namespace = 'c15tStore' } = options;
6714
6972
  let detachInstrumentation = null;
6973
+ let detachScriptDebug = null;
6715
6974
  const stateManager = createStateManager({
6716
6975
  isOpen: true
6717
6976
  });
@@ -6724,6 +6983,10 @@ var __webpack_exports__ = {};
6724
6983
  store,
6725
6984
  onEvent: (event)=>stateManager.addEvent(event)
6726
6985
  });
6986
+ detachScriptDebug?.();
6987
+ detachScriptDebug = (0, external_c15t_namespaceObject.subscribeToScriptDebugEvents)((event)=>{
6988
+ stateManager.addEvent(scriptDebugEventToLogEntry(event));
6989
+ });
6727
6990
  stateManager.setConnected(true);
6728
6991
  const persistedOverrides = loadPersistedOverrides();
6729
6992
  if (persistedOverrides) {
@@ -6740,6 +7003,8 @@ var __webpack_exports__ = {};
6740
7003
  stateManager.setConnected(false);
6741
7004
  detachInstrumentation?.();
6742
7005
  detachInstrumentation = null;
7006
+ detachScriptDebug?.();
7007
+ detachScriptDebug = null;
6743
7008
  }
6744
7009
  });
6745
7010
  const panelRenderer = createPanelRenderer({
@@ -6832,6 +7097,8 @@ var __webpack_exports__ = {};
6832
7097
  destroy: ()=>{
6833
7098
  detachInstrumentation?.();
6834
7099
  detachInstrumentation = null;
7100
+ detachScriptDebug?.();
7101
+ detachScriptDebug = null;
6835
7102
  unsubscribe();
6836
7103
  tabsInstance?.destroy();
6837
7104
  storeConnector.destroy();