@plaidev/karte-action-sdk 1.1.176 → 1.1.177-28040266.37adb031

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.
@@ -1,8 +1,33 @@
1
- import 'svelte/easing';
2
1
  import { writable, get } from 'svelte/store';
3
2
  import { onMount as onMount$1, onDestroy as onDestroy$1, beforeUpdate as beforeUpdate$1, afterUpdate as afterUpdate$1, tick as tick$1, setContext, getContext, createEventDispatcher } from 'svelte';
4
3
  import { SvelteComponent, init, safe_not_equal, create_slot, update_slot_base, get_all_dirty_from_scope, get_slot_changes, transition_in, transition_out, append_styles, empty, insert_hydration, group_outros, check_outros, detach, component_subscribe, element, space, claim_element, children, claim_space, attr, noop, listen, null_to_empty, is_function, create_component, claim_component, mount_component, destroy_component, add_render_callback, create_in_transition, binding_callbacks, set_style, svg_element, claim_svg_element, append_hydration, destroy_each, text, claim_text, set_data, src_url_equal, HtmlTagHydration, claim_html_tag, construct_svelte_component, subscribe } from 'svelte/internal';
4
+ import 'svelte/easing';
5
+
6
+ /** @internal */
7
+ const ACTION_HOOK_LABEL = '__ACTION_HOOK__';
8
+ /** @internal */
9
+ const KARTE_ACTION_ROOT = 'karte-action-root';
10
+ /** @internal */
11
+ const KARTE_ACTION_RID = 'karte-action-rid';
12
+ /** @internal */
13
+ const KARTE_ACTION_SHORTEN_ID = 'karte-action-id';
14
+ /** @internal */
15
+ const ALL_ACTION_ID = 'KARTE_ALL_ACTION_ID';
16
+ /** @internal */
17
+ const ALL_ACTION_SHORTEN_ID = 'KARTE_ALL_ACTION_SHORTEN_ID';
18
+ // -------- The following codes are deprecated --------
19
+ /**
20
+ * 非推奨
21
+ *
22
+ * @deprecated 非推奨
23
+ *
24
+ * @internal
25
+ */
26
+ const KARTE_MODAL_ROOT = 'karte-modal-root';
5
27
 
28
+ /**
29
+ * 静的変数に関連するコードを管理する
30
+ */
6
31
  /** @internal */
7
32
  const PropTypes = [
8
33
  'BooleanKeyword',
@@ -247,21 +272,10 @@ const NOOP = (_args) => { }; // eslint-disable-line @typescript-eslint/no-unused
247
272
  const isPreview = () => {
248
273
  return true;
249
274
  };
275
+ // prettier-ignore
250
276
  /** @internal */
251
- const handleFocus = (node) => (e) => {
252
- if (node) {
253
- // trap focus
254
- const nodes = node.querySelectorAll('*');
255
- const tabbable = Array.from(nodes).filter((n) => n.tabIndex >= 0);
256
- let index = tabbable.indexOf(document.activeElement);
257
- if (index === -1 && e.shiftKey)
258
- index = 0;
259
- index += tabbable.length + (e.shiftKey ? -1 : 1);
260
- index %= tabbable.length;
261
- tabbable[index].focus();
262
- e.preventDefault();
263
- }
264
- };
277
+ const actionId = ALL_ACTION_ID
278
+ ;
265
279
  /** @internal */
266
280
  const setPreviousFocus = () => {
267
281
  const previously_focused = typeof document !== 'undefined' && document.activeElement;
@@ -445,6 +459,23 @@ function hasSuffix(value, suffix) {
445
459
  function getGoogleFontsParam() {
446
460
  return 'family=' + Fonts.map(font => font.replace(/ /g, '+')).join('&family=');
447
461
  }
462
+ /** @internal */
463
+ const h = (type, props, ...children) => {
464
+ const el = document.createElement(type);
465
+ for (const key of Object.keys(props)) {
466
+ const v = props[key];
467
+ if (key === 'style') {
468
+ Object.assign(el.style, v);
469
+ }
470
+ else {
471
+ el.setAttribute(key, v);
472
+ }
473
+ }
474
+ for (const child of children) {
475
+ el.appendChild(child);
476
+ }
477
+ return el;
478
+ };
448
479
 
449
480
  /**
450
481
  * Store to handle action setting
@@ -807,385 +838,109 @@ function resetVariables() {
807
838
  */
808
839
  const formData = writable({});
809
840
 
810
- function isEmpty(value) {
811
- if (Array.isArray(value)) {
812
- return value.length === 0;
813
- }
814
- else {
815
- return !value;
816
- }
817
- }
841
+ /**
842
+ * アクションのログの記録の管理
843
+ */
844
+ const MESSAGES_LIMIT = 1000;
845
+ const EVENTS_LIMIT = 1000;
846
+ // 実行ログ
847
+ let logs = [];
848
+ // KARTEイベント
849
+ let events = [];
818
850
  /** @internal */
819
- function registerInput({ name, statePath, validator = () => true, initialValue, }) {
820
- const writableValue = {
821
- subscribe(run) {
822
- return formData.subscribe(formData => {
823
- run(formData[name]?.value);
824
- });
825
- },
826
- set(value) {
827
- formData.update(prev => ({
828
- ...prev,
829
- [name]: {
830
- statePath,
831
- value,
832
- isValid: validator(value),
833
- },
834
- }));
835
- },
836
- update(updater) {
837
- formData.update(prev => {
838
- const prevValue = prev[name]?.value;
839
- return {
840
- ...prev,
841
- [name]: {
842
- statePath,
843
- value: updater(prevValue),
844
- isValid: validator(prevValue),
845
- },
846
- };
847
- });
848
- },
849
- };
850
- if (isEmpty(get(writableValue))) {
851
- writableValue.set(initialValue);
852
- }
853
- return writableValue;
851
+ function getLogs() {
852
+ return logs;
854
853
  }
855
854
  /** @internal */
856
- const getValuesAreValidReader = statePath => ({
857
- subscribe(callback) {
858
- return formData.subscribe(formData => {
859
- const valuesAreValid = Object.entries(formData)
860
- .filter(([_, { statePath: s }]) => s === statePath) // eslint-disable-line @typescript-eslint/no-unused-vars
861
- .every(([_, { isValid }]) => isValid); // eslint-disable-line @typescript-eslint/no-unused-vars
862
- callback(valuesAreValid);
863
- });
855
+ function getEvents() {
856
+ return events;
857
+ }
858
+ // iframe内の場合は親windowを参照する
859
+ function w(w) {
860
+ return w.parent === w ? w : w.parent;
861
+ }
862
+ /**
863
+ * ログを送信する関数群
864
+ *
865
+ * @internal
866
+ */
867
+ const logger = {
868
+ info: (...messages) => {
869
+ const log = cloneToJson({ level: 'info', messages, date: new Date() });
870
+ w(window).postMessage({ type: 'KARTE-ACTION-LOGGER', detail: { method: 'log', log } }, '*');
864
871
  },
865
- });
866
- function formDataToEventValues(campaignId, formData) {
867
- const questions = [];
868
- const answersMap = {};
869
- Object.entries(formData).forEach(([name, dataItem]) => {
870
- questions.push(name);
871
- const value = dataItem.value;
872
- const answerKey = `question_${name}`;
873
- if (Array.isArray(value)) {
874
- answersMap[answerKey] = {
875
- choices: value,
876
- };
872
+ log: (...messages) => {
873
+ const log = cloneToJson({ level: 'info', messages, date: new Date() });
874
+ w(window).postMessage({ type: 'KARTE-ACTION-LOGGER', detail: { method: 'log', log } }, '*');
875
+ },
876
+ error: (...messages) => {
877
+ const log = cloneToJson({ level: 'error', messages, date: new Date() });
878
+ w(window).postMessage({ type: 'KARTE-ACTION-LOGGER', detail: { method: 'log', log } }, '*');
879
+ },
880
+ warn: (...messages) => {
881
+ const log = cloneToJson({ level: 'warn', messages, date: new Date() });
882
+ w(window).postMessage({ type: 'KARTE-ACTION-LOGGER', detail: { method: 'log', log } }, '*');
883
+ },
884
+ system: (...messages) => {
885
+ const log = cloneToJson({ level: 'system', messages, date: new Date() });
886
+ w(window).postMessage({ type: 'KARTE-ACTION-LOGGER', detail: { method: 'log', log } }, '*');
887
+ },
888
+ event: (name, values) => {
889
+ const event = values ? { name, values, date: new Date() } : { name, date: new Date() };
890
+ w(window).postMessage({
891
+ type: 'KARTE-ACTION-LOGGER',
892
+ detail: { method: 'event', event, values: values },
893
+ }, '*');
894
+ },
895
+ clear: () => {
896
+ w(window).postMessage({ type: 'KARTE-ACTION-LOGGER', detail: { method: 'clear' } }, '*');
897
+ },
898
+ clearEvents: () => {
899
+ w(window).postMessage({ type: 'KARTE-ACTION-LOGGER', detail: { method: 'clearEvents' } }, '*');
900
+ },
901
+ };
902
+ /**
903
+ * メッセージを実行ログに表示する
904
+ *
905
+ * @internal
906
+ */
907
+ function listenLogger() {
908
+ const handler = (event) => {
909
+ const { type, detail } = event.data;
910
+ if (event.origin !== location.origin) {
911
+ return;
877
912
  }
878
- else if (typeof value === 'string') {
879
- answersMap[answerKey] = {
880
- free_answer: value,
881
- };
913
+ if (type !== 'KARTE-ACTION-LOGGER') {
914
+ return;
915
+ }
916
+ if (detail.method === 'clear') {
917
+ logs = [];
918
+ }
919
+ else if (detail.method === 'clearEvents') {
920
+ events = [];
921
+ }
922
+ else if (detail.method === 'log') {
923
+ if (MESSAGES_LIMIT <= logs.length) {
924
+ logs.shift();
925
+ }
926
+ const { level, messages } = detail.log;
927
+ const log = { level, messages, date: new Date() };
928
+ logs.push(log);
929
+ }
930
+ else if (detail.method === 'event') {
931
+ if (EVENTS_LIMIT <= events.length) {
932
+ events.shift();
933
+ }
934
+ const { name, values } = detail.event;
935
+ const karteEvent = values
936
+ ? { name, values, date: new Date() }
937
+ : { name, date: new Date() };
938
+ events.push(karteEvent);
882
939
  }
883
- });
884
- return {
885
- [campaignId]: {
886
- questions,
887
- ...answersMap,
888
- },
889
- };
890
- }
891
- /** @internal */
892
- function submit() {
893
- const systemConfig = getSystem();
894
- const campaignId = systemConfig.campaignId;
895
- if (campaignId) {
896
- const formData$1 = get(formData);
897
- const values = formDataToEventValues(campaignId, formData$1);
898
- return values;
899
- }
900
- {
901
- const formData$1 = get(formData);
902
- const values = formDataToEventValues('mock', formData$1);
903
- console.log('values: ', values);
904
- return values;
905
- }
906
- }
907
-
908
- /** @internal */
909
- const ALL_ACTION_ID = 'KARTE_ALL_ACTION_ID';
910
- /** @internal */
911
- const ALL_ACTION_SHORTEN_ID = 'KARTE_ALL_ACTION_SHORTEN_ID';
912
- // prettier-ignore
913
- /** @internal */
914
- const actionId = ALL_ACTION_ID
915
- ;
916
- /** @internal */
917
- const ACTION_SHOW_EVENT = `KARTE-ACTION-SHOW-${actionId}`;
918
- /** @internal */
919
- const ACTION_CLOSE_EVENT = `KARTE-ACTION-CLOSE-${actionId}`;
920
- /** @internal */
921
- const ACTION_DESTROY_EVENT = `KARTE-ACTION-DESTROY-${actionId}`;
922
- /** @internal */
923
- const ACTION_CHANGE_STATE_EVENT = `KARTE-ACTION-CHANGE-STATE-${actionId}`;
924
- /** @internal */
925
- const handleState = (event) => {
926
- if (event.detail.actionId === actionId || event.detail.actionId === ALL_ACTION_ID) {
927
- send_event('_message_state_changed', { state: event.detail.to });
928
- setState$1(event.detail.to, { disableInPreview: event.detail.disableInPreview });
929
- }
930
- };
931
- /** @internal */
932
- const initialize = (setting) => {
933
- const newSetting = setSetting(setting);
934
- if (newSetting.initialState) {
935
- setState$1(newSetting.initialState);
936
- }
937
- setOpened(true);
938
- setClosed(false); // deprecated
939
- return () => finalize();
940
- };
941
- /** @internal */
942
- const finalize = () => {
943
- resetSetting();
944
- };
945
- /** @internal */
946
- const send_event = (event_name, values) => {
947
- const setting = getSetting();
948
- setting?.send?.(event_name, values);
949
- };
950
- function _moveTo(to) {
951
- window.dispatchEvent(new CustomEvent(ACTION_CHANGE_STATE_EVENT, { detail: { to, actionId } }));
952
- }
953
- /** @internal */
954
- const moveTo = (to) => () => {
955
- _moveTo(to);
956
- };
957
- /** @internal */
958
- const linkTo = (to, targetBlank = true) => () => {
959
- send_event('message_click', { url: to, state: getState$1() });
960
- if (targetBlank) {
961
- window.open(to);
962
- }
963
- else {
964
- location.href = to;
965
- }
966
- };
967
- /** @internal */
968
- const closeApp = (trigger) => () => {
969
- window.dispatchEvent(new CustomEvent(ACTION_CLOSE_EVENT, { detail: { trigger } }));
970
- };
971
- /** @internal */
972
- const runScript = (handlerName) => () => {
973
- const handlers = getEventHandlers();
974
- const handler = handlers[handlerName];
975
- if (!handler)
976
- return;
977
- try {
978
- handler();
979
- }
980
- catch (e) {
981
- console.warn('Failed to run custom handler', handlerName, e);
982
- }
983
- };
984
- /** @internal */
985
- const submitForm = (to) => () => {
986
- const values = submit();
987
- send_event('_answer_question', values);
988
- _moveTo(to);
989
- };
990
- /** @internal */
991
- const execOnClickOperation = (onClickOperation) => {
992
- if (onClickOperation.operation === 'linkTo') {
993
- linkTo(...onClickOperation.args)();
994
- }
995
- else if (onClickOperation.operation === 'moveTo') {
996
- moveTo(...onClickOperation.args)();
997
- }
998
- else if (onClickOperation.operation === 'closeApp') {
999
- closeApp(onClickOperation.args[0] || 'button')();
1000
- }
1001
- else if (onClickOperation.operation === 'runScript') {
1002
- runScript(onClickOperation.args[0])();
1003
- }
1004
- else if (onClickOperation.operation === 'submitForm') {
1005
- submitForm(onClickOperation.args[0])();
1006
- }
1007
- };
1008
- /** @internal */
1009
- const haveFunction = (onClickOperation) => {
1010
- return onClickOperation.operation !== 'none';
1011
- };
1012
- /**
1013
- * The function to activate svelte animation.
1014
- *
1015
- * @param node - A target node of animation. This argument is passed by svelte, by default.
1016
- * @param customAnimationOptions - A custom animation option object
1017
- *
1018
- * @see {@link https://svelte.dev/docs#template-syntax-element-directives-transition-fn-custom-transition-functions| Custom transition functions} for detail documentation
1019
- *
1020
- * @internal
1021
- */
1022
- function customAnimation(node, { transform, animationStyle, delay = 0, duration = 1000 }) {
1023
- {
1024
- return {};
1025
- }
1026
- }
1027
- /**
1028
- * ES Modules に対応していない JavaScript をページに読み込む
1029
- *
1030
- * @param src - JavaScript ファイルのリンク URL
1031
- *
1032
- * @public
1033
- */
1034
- async function loadGlobalScript(src) {
1035
- return new Promise((resolve, reject) => {
1036
- const script = document.createElement('script');
1037
- script.src = src;
1038
- document.body.appendChild(script);
1039
- script.addEventListener('load', () => resolve(script));
1040
- script.addEventListener('error', () => reject(script));
1041
- });
1042
- }
1043
- /**
1044
- * グローバル CSS をページに適用する
1045
- *
1046
- * @param css - CSS
1047
- *
1048
- * @public
1049
- */
1050
- async function applyGlobalCss(css) {
1051
- return new Promise((resolve, reject) => {
1052
- const style = document.createElement('style');
1053
- style.textContent = css;
1054
- document.body.appendChild(style);
1055
- style.addEventListener('load', () => resolve(style));
1056
- style.addEventListener('error', () => reject(style));
1057
- });
1058
- }
1059
- /**
1060
- * style ファイルをページに読み込む
1061
- *
1062
- * @param href - style ファイルのリンク URL
1063
- *
1064
- * @public
1065
- */
1066
- async function loadGlobalStyle(href) {
1067
- return new Promise((resolve, reject) => {
1068
- const link = document.createElement('link');
1069
- link.rel = 'stylesheet';
1070
- link.href = href;
1071
- document.body.appendChild(link);
1072
- link.addEventListener('load', () => resolve(link));
1073
- link.addEventListener('error', () => reject(link));
1074
- });
1075
- }
1076
- // @internal
1077
- function getCssVariables(data) {
1078
- return Object.entries(data)
1079
- .filter(([key, value]) => {
1080
- return ['string', 'number'].includes(typeof value) && key.startsWith('--');
1081
- })
1082
- .map(([key, value]) => `${key}:${value}`)
1083
- .join(';');
1084
- }
1085
-
1086
- /**
1087
- * アクションのログの記録の管理
1088
- */
1089
- const MESSAGES_LIMIT = 1000;
1090
- const EVENTS_LIMIT = 1000;
1091
- // 実行ログ
1092
- let logs = [];
1093
- // KARTEイベント
1094
- let events = [];
1095
- /** @internal */
1096
- function getLogs() {
1097
- return logs;
1098
- }
1099
- /** @internal */
1100
- function getEvents() {
1101
- return events;
1102
- }
1103
- // iframe内の場合は親windowを参照する
1104
- function w(w) {
1105
- return w.parent === w ? w : w.parent;
1106
- }
1107
- /**
1108
- * ログを送信する関数群
1109
- *
1110
- * @internal
1111
- */
1112
- const logger = {
1113
- info: (...messages) => {
1114
- const log = cloneToJson({ level: 'info', messages, date: new Date() });
1115
- w(window).postMessage({ type: 'KARTE-ACTION-LOGGER', detail: { method: 'log', log } }, '*');
1116
- },
1117
- log: (...messages) => {
1118
- const log = cloneToJson({ level: 'info', messages, date: new Date() });
1119
- w(window).postMessage({ type: 'KARTE-ACTION-LOGGER', detail: { method: 'log', log } }, '*');
1120
- },
1121
- error: (...messages) => {
1122
- const log = cloneToJson({ level: 'error', messages, date: new Date() });
1123
- w(window).postMessage({ type: 'KARTE-ACTION-LOGGER', detail: { method: 'log', log } }, '*');
1124
- },
1125
- warn: (...messages) => {
1126
- const log = cloneToJson({ level: 'warn', messages, date: new Date() });
1127
- w(window).postMessage({ type: 'KARTE-ACTION-LOGGER', detail: { method: 'log', log } }, '*');
1128
- },
1129
- system: (...messages) => {
1130
- const log = cloneToJson({ level: 'system', messages, date: new Date() });
1131
- w(window).postMessage({ type: 'KARTE-ACTION-LOGGER', detail: { method: 'log', log } }, '*');
1132
- },
1133
- event: (name, values) => {
1134
- const event = values ? { name, values, date: new Date() } : { name, date: new Date() };
1135
- w(window).postMessage({
1136
- type: 'KARTE-ACTION-LOGGER',
1137
- detail: { method: 'event', event, values: values },
1138
- }, '*');
1139
- },
1140
- clear: () => {
1141
- w(window).postMessage({ type: 'KARTE-ACTION-LOGGER', detail: { method: 'clear' } }, '*');
1142
- },
1143
- clearEvents: () => {
1144
- w(window).postMessage({ type: 'KARTE-ACTION-LOGGER', detail: { method: 'clearEvents' } }, '*');
1145
- },
1146
- };
1147
- /**
1148
- * メッセージを実行ログに表示する
1149
- *
1150
- * @internal
1151
- */
1152
- function listenLogger() {
1153
- const handler = (event) => {
1154
- const { type, detail } = event.data;
1155
- if (event.origin !== location.origin) {
1156
- return;
1157
- }
1158
- if (type !== 'KARTE-ACTION-LOGGER') {
1159
- return;
1160
- }
1161
- if (detail.method === 'clear') {
1162
- logs = [];
1163
- }
1164
- else if (detail.method === 'clearEvents') {
1165
- events = [];
1166
- }
1167
- else if (detail.method === 'log') {
1168
- if (MESSAGES_LIMIT <= logs.length) {
1169
- logs.shift();
1170
- }
1171
- const { level, messages } = detail.log;
1172
- const log = { level, messages, date: new Date() };
1173
- logs.push(log);
1174
- }
1175
- else if (detail.method === 'event') {
1176
- if (EVENTS_LIMIT <= events.length) {
1177
- events.shift();
1178
- }
1179
- const { name, values } = detail.event;
1180
- const karteEvent = values
1181
- ? { name, values, date: new Date() }
1182
- : { name, date: new Date() };
1183
- events.push(karteEvent);
1184
- }
1185
- };
1186
- window.addEventListener('message', handler, false);
1187
- return () => {
1188
- window.removeEventListener('message', handler, false);
940
+ };
941
+ window.addEventListener('message', handler, false);
942
+ return () => {
943
+ window.removeEventListener('message', handler, false);
1189
944
  };
1190
945
  }
1191
946
  const { info, log, error, warn } = console;
@@ -1229,6 +984,9 @@ function cloneToJson(data) {
1229
984
  }
1230
985
  }
1231
986
 
987
+ /**
988
+ * モーダル(ポップアップ)のロジックを管理する
989
+ */
1232
990
  function doPresent({ direction, deltaRate }, downFn, upFn, condition = false) {
1233
991
  if (direction === 'down' && deltaRate > 0) {
1234
992
  downFn();
@@ -1321,6 +1079,23 @@ function showOnTime(props, show = NOOP) {
1321
1079
  : null;
1322
1080
  }
1323
1081
 
1082
+ /** @internal */
1083
+ const ACTION_DESTROY_EVENT = `KARTE-ACTION-DESTROY-${actionId}`;
1084
+ /** @internal */
1085
+ const ACTION_SHOW_EVENT = `KARTE-ACTION-SHOW-${actionId}`;
1086
+ /** @internal */
1087
+ const ACTION_CLOSE_EVENT = `KARTE-ACTION-CLOSE-${actionId}`;
1088
+ /** @internal */
1089
+ const ACTION_CHANGE_STATE_EVENT = `KARTE-ACTION-CHANGE-STATE-${actionId}`;
1090
+ /** @internal */
1091
+ const send_event = (event_name, values) => {
1092
+ const setting = getSetting();
1093
+ setting?.send?.(event_name, values);
1094
+ };
1095
+
1096
+ /**
1097
+ * アクションテーブルに関連するコードの管理
1098
+ */
1324
1099
  const DEFAULT_COLLECTION_ENDPOINT = typeof __FLYER_GEN_COLLECTION_API_ENDPOINT__ === 'string'
1325
1100
  ? __FLYER_GEN_COLLECTION_API_ENDPOINT__
1326
1101
  : 'https://t.karte.io/collection';
@@ -1413,83 +1188,34 @@ const loadActionTable = async (config, api_key, endpoint) => {
1413
1188
  }, {});
1414
1189
  };
1415
1190
 
1416
- /** @internal */
1417
- const ACTION_HOOK_LABEL = '__ACTION_HOOK__';
1418
- /**
1419
- * アクションが作成 (create) される前にフックする関数
1420
- *
1421
- * @param fn - 呼び出されるフック関数
1422
- *
1423
- * @public
1424
- */
1425
- function onCreate(fn) {
1426
- let { onCreateHandlers } = getInternalHandlers();
1427
- if (!onCreateHandlers) {
1428
- onCreateHandlers = [];
1429
- }
1430
- onCreateHandlers.push(fn);
1431
- setInternalHandlers({ onCreateHandlers });
1432
- }
1433
- /**
1434
- * アクションが表示 (show) された後にフックする関数
1435
- *
1436
- * @param fn - 呼び出されるフック関数
1437
- *
1438
- * @public
1439
- */
1440
- function onShow(fn) {
1441
- let { onShowHandlers } = getInternalHandlers();
1442
- if (!onShowHandlers) {
1443
- onShowHandlers = [];
1444
- }
1445
- onShowHandlers.push(fn);
1446
- setInternalHandlers({ onShowHandlers });
1447
- }
1448
1191
  /**
1449
- * アクションがクローズ (close) される前にフックする関数
1192
+ * Edgeが起動するアクションに関連するコードを管理する
1450
1193
  *
1451
- * @param fn - 呼び出されるフック関数
1194
+ * アクションのCreate, Destroyの状態はここで管理する。
1452
1195
  *
1453
- * @public
1196
+ * FIXME: モーダルなどの機能ごとのコードを分離したい
1454
1197
  */
1455
- function onClose(fn) {
1456
- let { onCloseHandlers } = getInternalHandlers();
1457
- if (!onCloseHandlers) {
1458
- onCloseHandlers = [];
1459
- }
1460
- onCloseHandlers.push(fn);
1461
- setInternalHandlers({ onCloseHandlers });
1462
- }
1463
- /**
1464
- * アクションが破棄 (destroy) される前にフックする関数
1465
- *
1466
- * @param fn - 呼び出されるフック関数
1467
- *
1468
- * @public
1469
- */
1470
- function onDestroy(fn) {
1471
- let { onDestroyHandlers } = getInternalHandlers();
1472
- if (!onDestroyHandlers) {
1473
- onDestroyHandlers = [];
1198
+ /** @internal */
1199
+ const handleState = (event) => {
1200
+ if (event.detail.actionId === actionId || event.detail.actionId === ALL_ACTION_ID) {
1201
+ send_event('_message_state_changed', { state: event.detail.to });
1202
+ setState$1(event.detail.to, { disableInPreview: event.detail.disableInPreview });
1474
1203
  }
1475
- onDestroyHandlers.push(fn);
1476
- setInternalHandlers({ onDestroyHandlers });
1477
- }
1478
- /**
1479
- * アクションのステートが変更された (changeState) 後にフックする関数
1480
- *
1481
- * @param fn - 呼び出されるフック関数
1482
- *
1483
- * @public
1484
- */
1485
- function onChangeState(fn) {
1486
- let { onChangeStateHandlers } = getInternalHandlers();
1487
- if (!onChangeStateHandlers) {
1488
- onChangeStateHandlers = [];
1204
+ };
1205
+ /** @internal */
1206
+ const initialize = (setting) => {
1207
+ const newSetting = setSetting(setting);
1208
+ if (newSetting.initialState) {
1209
+ setState$1(newSetting.initialState);
1489
1210
  }
1490
- onChangeStateHandlers.push(fn);
1491
- setInternalHandlers({ onChangeStateHandlers });
1492
- }
1211
+ setOpened(true);
1212
+ setClosed(false); // deprecated
1213
+ return () => finalize();
1214
+ };
1215
+ /** @internal */
1216
+ const finalize = () => {
1217
+ resetSetting();
1218
+ };
1493
1219
  /**
1494
1220
  * アクションを作成する
1495
1221
  *
@@ -1681,6 +1407,29 @@ function create(App, options = {
1681
1407
  };
1682
1408
  return appCleanup;
1683
1409
  }
1410
+ /** @internal */
1411
+ function ensureActionRoot(useShadow = true) {
1412
+ const systemConfig = getSystem();
1413
+ const rootAttrs = {
1414
+ class: `${KARTE_ACTION_ROOT} ${KARTE_MODAL_ROOT}`,
1415
+ [`data-${KARTE_ACTION_RID}`]: actionId,
1416
+ [`data-${KARTE_ACTION_SHORTEN_ID}`]: systemConfig.shortenId
1417
+ ? systemConfig.shortenId
1418
+ : ALL_ACTION_SHORTEN_ID,
1419
+ };
1420
+ let el = document.querySelector(`.${KARTE_MODAL_ROOT}[data-${KARTE_ACTION_RID}='${actionId}']`);
1421
+ if (el == null) {
1422
+ el = h('div', rootAttrs);
1423
+ document.body.appendChild(el);
1424
+ }
1425
+ const isShadow = !!document.body.attachShadow && useShadow;
1426
+ if (isShadow) {
1427
+ return el.shadowRoot ?? el.attachShadow({ mode: 'open' });
1428
+ }
1429
+ else {
1430
+ return el;
1431
+ }
1432
+ }
1684
1433
  /**
1685
1434
  * Dispatch the event to destroy KARTE action
1686
1435
  *
@@ -1700,71 +1449,111 @@ function destroyAction() {
1700
1449
  dispatchDestroyEvent();
1701
1450
  }
1702
1451
  /**
1703
- * アクションを表示する
1452
+ * アクションが作成 (create) される前にフックする関数
1453
+ *
1454
+ * @param fn - 呼び出されるフック関数
1704
1455
  *
1705
1456
  * @public
1706
1457
  */
1707
- function showAction() {
1708
- const event = new CustomEvent(ACTION_SHOW_EVENT, { detail: { trigger: 'custom' } });
1709
- window.dispatchEvent(event);
1458
+ function onCreate(fn) {
1459
+ let { onCreateHandlers } = getInternalHandlers();
1460
+ if (!onCreateHandlers) {
1461
+ onCreateHandlers = [];
1462
+ }
1463
+ onCreateHandlers.push(fn);
1464
+ setInternalHandlers({ onCreateHandlers });
1465
+ }
1466
+ /**
1467
+ * アクションが破棄 (destroy) される前にフックする関数
1468
+ *
1469
+ * @param fn - 呼び出されるフック関数
1470
+ *
1471
+ * @public
1472
+ */
1473
+ function onDestroy(fn) {
1474
+ let { onDestroyHandlers } = getInternalHandlers();
1475
+ if (!onDestroyHandlers) {
1476
+ onDestroyHandlers = [];
1477
+ }
1478
+ onDestroyHandlers.push(fn);
1479
+ setInternalHandlers({ onDestroyHandlers });
1480
+ }
1481
+ /**
1482
+ * 非推奨
1483
+ *
1484
+ * @deprecated 非推奨
1485
+ *
1486
+ * @internal
1487
+ */
1488
+ const showModal = create;
1489
+ /**
1490
+ * 非推奨
1491
+ *
1492
+ * @deprecated 非推奨
1493
+ *
1494
+ * @internal
1495
+ */
1496
+ const ensureModalRoot = ensureActionRoot;
1497
+ /**
1498
+ * 非推奨
1499
+ *
1500
+ * @deprecated 非推奨
1501
+ *
1502
+ * @internal
1503
+ */
1504
+ function createApp(App, options = {
1505
+ send: () => { },
1506
+ publish: () => { },
1507
+ props: {},
1508
+ variables: {},
1509
+ localVariablesQuery: undefined,
1510
+ }) {
1511
+ let app = null;
1512
+ const close = () => {
1513
+ if (app) {
1514
+ app.$destroy();
1515
+ app = null;
1516
+ }
1517
+ };
1518
+ const appArgs = {
1519
+ target: null,
1520
+ props: {
1521
+ send: options.send,
1522
+ publish: options.publish,
1523
+ close,
1524
+ data: {
1525
+ ...options.props,
1526
+ ...options.variables,
1527
+ },
1528
+ },
1529
+ };
1530
+ {
1531
+ const win = ensureModalRoot(false);
1532
+ appArgs.target = win;
1533
+ appArgs.hydrate = true;
1534
+ }
1535
+ return {
1536
+ close,
1537
+ show: () => {
1538
+ if (app) {
1539
+ return;
1540
+ }
1541
+ options.send('message_open');
1542
+ app = new App(appArgs);
1543
+ },
1544
+ };
1710
1545
  }
1711
1546
  /**
1712
- * アクションを閉じる
1547
+ * 非推奨
1713
1548
  *
1714
- * @param trigger - 閉じた時のトリガー。デフォルト `'none'`
1549
+ * @deprecated 非推奨
1715
1550
  *
1716
- * @public
1551
+ * @internal
1717
1552
  */
1718
- function closeAction(trigger = 'none') {
1719
- const event = new CustomEvent(ACTION_CLOSE_EVENT, { detail: { trigger } });
1720
- window.dispatchEvent(event);
1721
- }
1722
- /** @internal */
1723
- const KARTE_ACTION_ROOT = 'karte-action-root';
1724
- /** @internal */
1725
- const KARTE_ACTION_RID = 'karte-action-rid';
1726
- /** @internal */
1727
- const KARTE_ACTION_SHORTEN_ID = 'karte-action-id';
1728
- /** @internal */
1729
- function ensureActionRoot(useShadow = true) {
1730
- const systemConfig = getSystem();
1731
- const rootAttrs = {
1732
- class: `${KARTE_ACTION_ROOT} ${KARTE_MODAL_ROOT}`,
1733
- [`data-${KARTE_ACTION_RID}`]: actionId,
1734
- [`data-${KARTE_ACTION_SHORTEN_ID}`]: systemConfig.shortenId
1735
- ? systemConfig.shortenId
1736
- : ALL_ACTION_SHORTEN_ID,
1737
- };
1738
- let el = document.querySelector(`.${KARTE_MODAL_ROOT}[data-${KARTE_ACTION_RID}='${actionId}']`);
1739
- if (el == null) {
1740
- el = h('div', rootAttrs);
1741
- document.body.appendChild(el);
1742
- }
1743
- const isShadow = !!document.body.attachShadow && useShadow;
1744
- if (isShadow) {
1745
- return el.shadowRoot ?? el.attachShadow({ mode: 'open' });
1746
- }
1747
- else {
1748
- return el;
1749
- }
1553
+ function destroy() {
1554
+ setDestroyed(true);
1555
+ dispatchDestroyEvent();
1750
1556
  }
1751
- /** @internal */
1752
- const h = (type, props, ...children) => {
1753
- const el = document.createElement(type);
1754
- for (const key of Object.keys(props)) {
1755
- const v = props[key];
1756
- if (key === 'style') {
1757
- Object.assign(el.style, v);
1758
- }
1759
- else {
1760
- el.setAttribute(key, v);
1761
- }
1762
- }
1763
- for (const child of children) {
1764
- el.appendChild(child);
1765
- }
1766
- return el;
1767
- };
1768
1557
  /**
1769
1558
  * 非推奨
1770
1559
  *
@@ -1797,19 +1586,129 @@ function createFog({ color = '#000', opacity = '50%', zIndex = 999, onclick, })
1797
1586
  root.appendChild(fog);
1798
1587
  return { fog, close };
1799
1588
  }
1589
+
1800
1590
  /**
1801
- * アクションのルートの DOM 要素を取得する
1591
+ * スクリプト接客が利用するコードの管理
1592
+ */
1593
+ /**
1594
+ * ES Modules に対応していない JavaScript をページに読み込む
1802
1595
  *
1803
- * @returns アクションがルートの DOM 要素 を持つ場合は DOM 要素を返します。ない場合は `null` を返します
1596
+ * @param src - JavaScript ファイルのリンク URL
1804
1597
  *
1805
1598
  * @public
1806
1599
  */
1807
- function getActionRoot() {
1808
- const root = document.querySelector(`.${KARTE_ACTION_ROOT}[data-${KARTE_ACTION_RID}='${actionId}']`);
1809
- if (!root?.shadowRoot) {
1810
- return null;
1600
+ async function loadGlobalScript(src) {
1601
+ return new Promise((resolve, reject) => {
1602
+ const script = document.createElement('script');
1603
+ script.src = src;
1604
+ document.body.appendChild(script);
1605
+ script.addEventListener('load', () => resolve(script));
1606
+ script.addEventListener('error', () => reject(script));
1607
+ });
1608
+ }
1609
+ /**
1610
+ * グローバル CSS をページに適用する
1611
+ *
1612
+ * @param css - CSS
1613
+ *
1614
+ * @public
1615
+ */
1616
+ async function applyGlobalCss(css) {
1617
+ return new Promise((resolve, reject) => {
1618
+ const style = document.createElement('style');
1619
+ style.textContent = css;
1620
+ document.body.appendChild(style);
1621
+ style.addEventListener('load', () => resolve(style));
1622
+ style.addEventListener('error', () => reject(style));
1623
+ });
1624
+ }
1625
+ /**
1626
+ * style ファイルをページに読み込む
1627
+ *
1628
+ * @param href - style ファイルのリンク URL
1629
+ *
1630
+ * @public
1631
+ */
1632
+ async function loadGlobalStyle(href) {
1633
+ return new Promise((resolve, reject) => {
1634
+ const link = document.createElement('link');
1635
+ link.rel = 'stylesheet';
1636
+ link.href = href;
1637
+ document.body.appendChild(link);
1638
+ link.addEventListener('load', () => resolve(link));
1639
+ link.addEventListener('error', () => reject(link));
1640
+ });
1641
+ }
1642
+
1643
+ /**
1644
+ * モーダル(ポップアップ)に関連するコードの管理
1645
+ *
1646
+ * アクションのShow, Close, ChangeStateの状態はここで管理する。
1647
+ */
1648
+ /**
1649
+ * アクションが表示 (show) された後にフックする関数
1650
+ *
1651
+ * @param fn - 呼び出されるフック関数
1652
+ *
1653
+ * @public
1654
+ */
1655
+ function onShow(fn) {
1656
+ let { onShowHandlers } = getInternalHandlers();
1657
+ if (!onShowHandlers) {
1658
+ onShowHandlers = [];
1811
1659
  }
1812
- return root.shadowRoot;
1660
+ onShowHandlers.push(fn);
1661
+ setInternalHandlers({ onShowHandlers });
1662
+ }
1663
+ /**
1664
+ * アクションがクローズ (close) される前にフックする関数
1665
+ *
1666
+ * @param fn - 呼び出されるフック関数
1667
+ *
1668
+ * @public
1669
+ */
1670
+ function onClose(fn) {
1671
+ let { onCloseHandlers } = getInternalHandlers();
1672
+ if (!onCloseHandlers) {
1673
+ onCloseHandlers = [];
1674
+ }
1675
+ onCloseHandlers.push(fn);
1676
+ setInternalHandlers({ onCloseHandlers });
1677
+ }
1678
+ /**
1679
+ * アクションのステートが変更された (changeState) 後にフックする関数
1680
+ *
1681
+ * @param fn - 呼び出されるフック関数
1682
+ *
1683
+ * @public
1684
+ */
1685
+ function onChangeState(fn) {
1686
+ let { onChangeStateHandlers } = getInternalHandlers();
1687
+ if (!onChangeStateHandlers) {
1688
+ onChangeStateHandlers = [];
1689
+ }
1690
+ onChangeStateHandlers.push(fn);
1691
+ setInternalHandlers({ onChangeStateHandlers });
1692
+ }
1693
+ /**
1694
+ * アクションを表示する
1695
+ *
1696
+ * @public
1697
+ */
1698
+ function showAction() {
1699
+ const event = new CustomEvent(ACTION_SHOW_EVENT, { detail: { trigger: 'custom' } });
1700
+ window.dispatchEvent(event);
1701
+ }
1702
+ /**
1703
+ * アクションを閉じる
1704
+ *
1705
+ * @param trigger - 閉じた時のトリガー。デフォルト `'none'`
1706
+ *
1707
+ * @public
1708
+ */
1709
+ function closeAction(trigger = 'none') {
1710
+ const event = new CustomEvent(ACTION_CLOSE_EVENT, { detail: { trigger } });
1711
+ window.dispatchEvent(event);
1813
1712
  }
1814
1713
  /**
1815
1714
  * アクションに CSS を適用する
@@ -1824,7 +1723,7 @@ async function applyCss(css) {
1824
1723
  return new Promise((resolve, reject) => {
1825
1724
  const style = document.createElement('style');
1826
1725
  style.textContent = css;
1827
- const shadowRoot = getActionShadowRoot();
1726
+ const shadowRoot = getActionRoot();
1828
1727
  if (!shadowRoot)
1829
1728
  return;
1830
1729
  shadowRoot.append(style);
@@ -1863,7 +1762,7 @@ async function fixFontFaceIssue(href, cssRules) {
1863
1762
  * @public
1864
1763
  */
1865
1764
  async function loadStyle(href) {
1866
- const sr = getActionShadowRoot();
1765
+ const sr = getActionRoot();
1867
1766
  if (!sr)
1868
1767
  return;
1869
1768
  let cssRules = '';
@@ -1871,117 +1770,51 @@ async function loadStyle(href) {
1871
1770
  const res = await fetch(href);
1872
1771
  cssRules = await res.text();
1873
1772
  }
1874
- catch (e) {
1875
- // pass
1876
- }
1877
- if (!cssRules)
1878
- return;
1879
- // Chromeのバグで、Shadow Rootの@font-faceを絶対パスで指定する必要がある
1880
- // @see https://stackoverflow.com/a/63717709
1881
- const [rules, fontFaceRules] = await fixFontFaceIssue(href, cssRules);
1882
- const css = new CSSStyleSheet();
1883
- // @ts-ignore
1884
- await css.replace(rules);
1885
- const fontFaceCss = new CSSStyleSheet();
1886
- // @ts-ignore
1887
- await fontFaceCss.replace(fontFaceRules);
1888
- // @ts-ignore
1889
- sr.adoptedStyleSheets = [...sr.adoptedStyleSheets, css, fontFaceCss];
1890
- // Chromeのバグで、ページとShadow Rootの両方に、@font-faceを設定する必要がある
1891
- // @see https://stackoverflow.com/a/63717709
1892
- // @ts-ignore
1893
- document.adoptedStyleSheets = [...document.adoptedStyleSheets, css, fontFaceCss];
1894
- }
1895
- // -------- The following codes are deprecated --------
1896
- /**
1897
- * 非推奨
1898
- *
1899
- * @deprecated 非推奨
1900
- *
1901
- * @internal
1902
- */
1903
- const showModal = create;
1904
- /**
1905
- * 非推奨
1906
- *
1907
- * @deprecated 非推奨
1908
- *
1909
- * @internal
1910
- */
1911
- const KARTE_MODAL_ROOT = 'karte-modal-root';
1912
- /**
1913
- * 非推奨
1914
- *
1915
- * @deprecated 非推奨
1916
- *
1917
- * @internal
1918
- */
1919
- const ensureModalRoot = ensureActionRoot;
1920
- /**
1921
- * 非推奨
1922
- *
1923
- * @deprecated 非推奨
1924
- *
1925
- * @internal
1926
- */
1927
- const show = showAction;
1928
- /**
1929
- * 非推奨
1930
- *
1931
- * @deprecated 非推奨
1932
- *
1933
- * @internal
1934
- */
1935
- const close = closeAction;
1773
+ catch (e) {
1774
+ // pass
1775
+ }
1776
+ if (!cssRules)
1777
+ return;
1778
+ // Chromeのバグで、Shadow Rootの@font-faceを絶対パスで指定する必要がある
1779
+ // @see https://stackoverflow.com/a/63717709
1780
+ const [rules, fontFaceRules] = await fixFontFaceIssue(href, cssRules);
1781
+ const css = new CSSStyleSheet();
1782
+ // @ts-ignore
1783
+ await css.replace(rules);
1784
+ const fontFaceCss = new CSSStyleSheet();
1785
+ // @ts-ignore
1786
+ await fontFaceCss.replace(fontFaceRules);
1787
+ // @ts-ignore
1788
+ sr.adoptedStyleSheets = [...sr.adoptedStyleSheets, css, fontFaceCss];
1789
+ // Chromeのバグで、ページとShadow Rootの両方に、@font-faceを設定する必要がある
1790
+ // @see https://stackoverflow.com/a/63717709
1791
+ // @ts-ignore
1792
+ document.adoptedStyleSheets = [...document.adoptedStyleSheets, css, fontFaceCss];
1793
+ }
1794
+ // @internal
1795
+ function getCssVariables(data) {
1796
+ return Object.entries(data)
1797
+ .filter(([key, value]) => {
1798
+ return ['string', 'number'].includes(typeof value) && key.startsWith('--');
1799
+ })
1800
+ .map(([key, value]) => `${key}:${value}`)
1801
+ .join(';');
1802
+ }
1936
1803
  /**
1937
- * 非推奨
1804
+ * アクションのルートの DOM 要素を取得する
1938
1805
  *
1939
- * @deprecated 非推奨
1806
+ * @returns アクションがルートの DOM 要素 を持つ場合は DOM 要素を返します。ない場合は `null` を返します
1940
1807
  *
1941
- * @internal
1808
+ * @public
1942
1809
  */
1943
- function createApp(App, options = {
1944
- send: () => { },
1945
- publish: () => { },
1946
- props: {},
1947
- variables: {},
1948
- localVariablesQuery: undefined,
1949
- }) {
1950
- let app = null;
1951
- const close = () => {
1952
- if (app) {
1953
- app.$destroy();
1954
- app = null;
1955
- }
1956
- };
1957
- const appArgs = {
1958
- target: null,
1959
- props: {
1960
- send: options.send,
1961
- publish: options.publish,
1962
- close,
1963
- data: {
1964
- ...options.props,
1965
- ...options.variables,
1966
- },
1967
- },
1968
- };
1969
- {
1970
- const win = ensureModalRoot(false);
1971
- appArgs.target = win;
1972
- appArgs.hydrate = true;
1810
+ function getActionRoot() {
1811
+ const root = document.querySelector(`.${KARTE_ACTION_ROOT}[data-${KARTE_ACTION_RID}='${actionId}']`);
1812
+ if (!root?.shadowRoot) {
1813
+ return null;
1973
1814
  }
1974
- return {
1975
- close,
1976
- show: () => {
1977
- if (app) {
1978
- return;
1979
- }
1980
- options.send('message_open');
1981
- app = new App(appArgs);
1982
- },
1983
- };
1815
+ return root.shadowRoot;
1984
1816
  }
1817
+ // -------- The following codes are deprecated --------
1985
1818
  /**
1986
1819
  * 非推奨
1987
1820
  *
@@ -1989,13 +1822,7 @@ function createApp(App, options = {
1989
1822
  *
1990
1823
  * @internal
1991
1824
  */
1992
- function getActionShadowRoot() {
1993
- const root = document.querySelector(`.${KARTE_ACTION_ROOT}[data-${KARTE_ACTION_RID}='${actionId}']`);
1994
- if (!root?.shadowRoot) {
1995
- return null;
1996
- }
1997
- return root.shadowRoot;
1998
- }
1825
+ const show = showAction;
1999
1826
  /**
2000
1827
  * 非推奨
2001
1828
  *
@@ -2003,13 +1830,10 @@ function getActionShadowRoot() {
2003
1830
  *
2004
1831
  * @internal
2005
1832
  */
2006
- function destroy() {
2007
- setDestroyed(true);
2008
- dispatchDestroyEvent();
2009
- }
1833
+ const close = closeAction;
2010
1834
 
2011
1835
  /**
2012
- * Widget API 互換のインターフェース
1836
+ * エディタv1のWidget API 互換のインターフェース
2013
1837
  */
2014
1838
  const STORE_LS_KEY_PREFIX = 'krt___';
2015
1839
  const valCallbacks = {};
@@ -2543,6 +2367,185 @@ class StateItem extends SvelteComponent {
2543
2367
  }
2544
2368
  }
2545
2369
 
2370
+ function isEmpty(value) {
2371
+ if (Array.isArray(value)) {
2372
+ return value.length === 0;
2373
+ }
2374
+ else {
2375
+ return !value;
2376
+ }
2377
+ }
2378
+ /** @internal */
2379
+ function registerInput({ name, statePath, validator = () => true, initialValue, }) {
2380
+ const writableValue = {
2381
+ subscribe(run) {
2382
+ return formData.subscribe(formData => {
2383
+ run(formData[name]?.value);
2384
+ });
2385
+ },
2386
+ set(value) {
2387
+ formData.update(prev => ({
2388
+ ...prev,
2389
+ [name]: {
2390
+ statePath,
2391
+ value,
2392
+ isValid: validator(value),
2393
+ },
2394
+ }));
2395
+ },
2396
+ update(updater) {
2397
+ formData.update(prev => {
2398
+ const prevValue = prev[name]?.value;
2399
+ return {
2400
+ ...prev,
2401
+ [name]: {
2402
+ statePath,
2403
+ value: updater(prevValue),
2404
+ isValid: validator(prevValue),
2405
+ },
2406
+ };
2407
+ });
2408
+ },
2409
+ };
2410
+ if (isEmpty(get(writableValue))) {
2411
+ writableValue.set(initialValue);
2412
+ }
2413
+ return writableValue;
2414
+ }
2415
+ /** @internal */
2416
+ const getValuesAreValidReader = statePath => ({
2417
+ subscribe(callback) {
2418
+ return formData.subscribe(formData => {
2419
+ const valuesAreValid = Object.entries(formData)
2420
+ .filter(([_, { statePath: s }]) => s === statePath) // eslint-disable-line @typescript-eslint/no-unused-vars
2421
+ .every(([_, { isValid }]) => isValid); // eslint-disable-line @typescript-eslint/no-unused-vars
2422
+ callback(valuesAreValid);
2423
+ });
2424
+ },
2425
+ });
2426
+ function formDataToEventValues(campaignId, formData) {
2427
+ const questions = [];
2428
+ const answersMap = {};
2429
+ Object.entries(formData).forEach(([name, dataItem]) => {
2430
+ questions.push(name);
2431
+ const value = dataItem.value;
2432
+ const answerKey = `question_${name}`;
2433
+ if (Array.isArray(value)) {
2434
+ answersMap[answerKey] = {
2435
+ choices: value,
2436
+ };
2437
+ }
2438
+ else if (typeof value === 'string') {
2439
+ answersMap[answerKey] = {
2440
+ free_answer: value,
2441
+ };
2442
+ }
2443
+ });
2444
+ return {
2445
+ [campaignId]: {
2446
+ questions,
2447
+ ...answersMap,
2448
+ },
2449
+ };
2450
+ }
2451
+ /** @internal */
2452
+ function submit() {
2453
+ const systemConfig = getSystem();
2454
+ const campaignId = systemConfig.campaignId;
2455
+ if (campaignId) {
2456
+ const formData$1 = get(formData);
2457
+ const values = formDataToEventValues(campaignId, formData$1);
2458
+ return values;
2459
+ }
2460
+ {
2461
+ const formData$1 = get(formData);
2462
+ const values = formDataToEventValues('mock', formData$1);
2463
+ console.log('values: ', values);
2464
+ return values;
2465
+ }
2466
+ }
2467
+
2468
+ /**
2469
+ * モーダル(ポップアップ)のコンポーネントが利用するコードの管理
2470
+ */
2471
+ function _moveTo(to) {
2472
+ window.dispatchEvent(new CustomEvent(ACTION_CHANGE_STATE_EVENT, { detail: { to, actionId } }));
2473
+ }
2474
+ /** @internal */
2475
+ const moveTo = (to) => () => {
2476
+ _moveTo(to);
2477
+ };
2478
+ /** @internal */
2479
+ const linkTo = (to, targetBlank = true) => () => {
2480
+ send_event('message_click', { url: to, state: getState$1() });
2481
+ if (targetBlank) {
2482
+ window.open(to);
2483
+ }
2484
+ else {
2485
+ location.href = to;
2486
+ }
2487
+ };
2488
+ /** @internal */
2489
+ const closeApp = (trigger) => () => {
2490
+ window.dispatchEvent(new CustomEvent(ACTION_CLOSE_EVENT, { detail: { trigger } }));
2491
+ };
2492
+ /** @internal */
2493
+ const runScript = (handlerName) => () => {
2494
+ const handlers = getEventHandlers();
2495
+ const handler = handlers[handlerName];
2496
+ if (!handler)
2497
+ return;
2498
+ try {
2499
+ handler();
2500
+ }
2501
+ catch (e) {
2502
+ console.warn('Failed to run custom handler', handlerName, e);
2503
+ }
2504
+ };
2505
+ /** @internal */
2506
+ const submitForm = (to) => () => {
2507
+ const values = submit();
2508
+ send_event('_answer_question', values);
2509
+ _moveTo(to);
2510
+ };
2511
+ /** @internal */
2512
+ const execOnClickOperation = (onClickOperation) => {
2513
+ if (onClickOperation.operation === 'linkTo') {
2514
+ linkTo(...onClickOperation.args)();
2515
+ }
2516
+ else if (onClickOperation.operation === 'moveTo') {
2517
+ moveTo(...onClickOperation.args)();
2518
+ }
2519
+ else if (onClickOperation.operation === 'closeApp') {
2520
+ closeApp(onClickOperation.args[0] || 'button')();
2521
+ }
2522
+ else if (onClickOperation.operation === 'runScript') {
2523
+ runScript(onClickOperation.args[0])();
2524
+ }
2525
+ else if (onClickOperation.operation === 'submitForm') {
2526
+ submitForm(onClickOperation.args[0])();
2527
+ }
2528
+ };
2529
+ /** @internal */
2530
+ const haveFunction = (onClickOperation) => {
2531
+ return onClickOperation.operation !== 'none';
2532
+ };
2533
+ /**
2534
+ * The function to activate svelte animation.
2535
+ *
2536
+ * @param node - A target node of animation. This argument is passed by svelte, by default.
2537
+ * @param customAnimationOptions - A custom animation option object
2538
+ *
2539
+ * @see {@link https://svelte.dev/docs#template-syntax-element-directives-transition-fn-custom-transition-functions| Custom transition functions} for detail documentation
2540
+ *
2541
+ * @internal
2542
+ */
2543
+ function customAnimation(node, { transform, animationStyle, delay = 0, duration = 1000 }) {
2544
+ {
2545
+ return {};
2546
+ }
2547
+ }
2548
+
2546
2549
  /* src/components/BackgroundOverray.svelte generated by Svelte v3.53.1 */
2547
2550
 
2548
2551
  function add_css$s(target) {
@@ -2650,8 +2653,8 @@ function add_css$r(target) {
2650
2653
  append_styles(target, "svelte-1tg0tf", ".button.svelte-1tg0tf{display:block;text-decoration:none;color:inherit;border:none;background:none;margin:0;padding:0}.button.svelte-1tg0tf:link,.button.svelte-1tg0tf:visited,.button.svelte-1tg0tf:active,.button.svelte-1tg0tf:hover{color:inherit}");
2651
2654
  }
2652
2655
 
2653
- // (48:0) {:else}
2654
- function create_else_block$2(ctx) {
2656
+ // (49:0) {:else}
2657
+ function create_else_block$3(ctx) {
2655
2658
  let button;
2656
2659
  let current;
2657
2660
  let mounted;
@@ -2728,7 +2731,7 @@ function create_else_block$2(ctx) {
2728
2731
  };
2729
2732
  }
2730
2733
 
2731
- // (44:39)
2734
+ // (45:39)
2732
2735
  function create_if_block_2(ctx) {
2733
2736
  let div;
2734
2737
  let current;
@@ -2797,7 +2800,7 @@ function create_if_block_2(ctx) {
2797
2800
  };
2798
2801
  }
2799
2802
 
2800
- // (40:41)
2803
+ // (41:41)
2801
2804
  function create_if_block_1$2(ctx) {
2802
2805
  let a;
2803
2806
  let a_href_value;
@@ -2893,7 +2896,7 @@ function create_if_block_1$2(ctx) {
2893
2896
  };
2894
2897
  }
2895
2898
 
2896
- // (36:0) {#if disabled}
2899
+ // (37:0) {#if disabled}
2897
2900
  function create_if_block$6(ctx) {
2898
2901
  let div;
2899
2902
  let current;
@@ -2967,7 +2970,7 @@ function create_fragment$u(ctx) {
2967
2970
  let if_block;
2968
2971
  let if_block_anchor;
2969
2972
  let current;
2970
- const if_block_creators = [create_if_block$6, create_if_block_1$2, create_if_block_2, create_else_block$2];
2973
+ const if_block_creators = [create_if_block$6, create_if_block_1$2, create_if_block_2, create_else_block$3];
2971
2974
  const if_blocks = [];
2972
2975
 
2973
2976
  function select_block_type(ctx, dirty) {
@@ -3136,7 +3139,7 @@ function add_css$q(target) {
3136
3139
  append_styles(target, "svelte-yyiwdt", ".modal.svelte-yyiwdt{position:fixed;box-sizing:border-box;z-index:2147483647;display:flex}.modal.svelte-yyiwdt > .button{flex:auto;display:flex}.close.svelte-yyiwdt{position:absolute;top:0;right:0}.close.svelte-yyiwdt > .button{position:absolute;display:flex;justify-content:center;align-items:center;background-color:transparent;border:none;cursor:pointer;padding:0;transition:all 0.25s}.close.svelte-yyiwdt > .button:hover{transform:rotate(90deg)}.modal-content.svelte-yyiwdt{flex:auto;display:flex;justify-content:center;align-items:center}");
3137
3140
  }
3138
3141
 
3139
- // (144:0) {#if visible}
3142
+ // (145:0) {#if visible}
3140
3143
  function create_if_block$5(ctx) {
3141
3144
  let div;
3142
3145
  let button;
@@ -3231,7 +3234,7 @@ function create_if_block$5(ctx) {
3231
3234
  };
3232
3235
  }
3233
3236
 
3234
- // (161:6) {#if closable}
3237
+ // (162:6) {#if closable}
3235
3238
  function create_if_block_1$1(ctx) {
3236
3239
  let div;
3237
3240
  let button;
@@ -3303,7 +3306,7 @@ function create_if_block_1$1(ctx) {
3303
3306
  };
3304
3307
  }
3305
3308
 
3306
- // (163:10) <Button onClick={onClose} style={_closeStyle} eventName={closeEventName} eventValue={closeEventValue}>
3309
+ // (164:10) <Button onClick={onClose} style={_closeStyle} eventName={closeEventName} eventValue={closeEventValue}>
3307
3310
  function create_default_slot_1$1(ctx) {
3308
3311
  let svg;
3309
3312
  let path;
@@ -3360,7 +3363,7 @@ function create_default_slot_1$1(ctx) {
3360
3363
  };
3361
3364
  }
3362
3365
 
3363
- // (160:4) <Button {onClick} eventName={clickEventName} eventValue={clickEventValue}>
3366
+ // (161:4) <Button {onClick} eventName={clickEventName} eventValue={clickEventValue}>
3364
3367
  function create_default_slot$6(ctx) {
3365
3368
  let t;
3366
3369
  let div;
@@ -3474,7 +3477,7 @@ function create_fragment$t(ctx) {
3474
3477
 
3475
3478
  backgroundoverray = new BackgroundOverray({
3476
3479
  props: {
3477
- backgroundOverray: /*backgroundOverray*/ ctx[11]
3480
+ backgroundOverray: /*backgroundOverray*/ ctx[10]
3478
3481
  }
3479
3482
  });
3480
3483
 
@@ -3515,7 +3518,7 @@ function create_fragment$t(ctx) {
3515
3518
  p(new_ctx, [dirty]) {
3516
3519
  ctx = new_ctx;
3517
3520
  const backgroundoverray_changes = {};
3518
- if (dirty & /*backgroundOverray*/ 2048) backgroundoverray_changes.backgroundOverray = /*backgroundOverray*/ ctx[11];
3521
+ if (dirty & /*backgroundOverray*/ 1024) backgroundoverray_changes.backgroundOverray = /*backgroundOverray*/ ctx[10];
3519
3522
  backgroundoverray.$set(backgroundoverray_changes);
3520
3523
 
3521
3524
  if (/*visible*/ ctx[12]) {
@@ -3603,7 +3606,7 @@ function instance$t($$self, $$props, $$invalidate) {
3603
3606
  function div_binding($$value) {
3604
3607
  binding_callbacks[$$value ? 'unshift' : 'push'](() => {
3605
3608
  modal = $$value;
3606
- $$invalidate(10, modal);
3609
+ $$invalidate(11, modal);
3607
3610
  });
3608
3611
  }
3609
3612
 
@@ -3641,7 +3644,7 @@ function instance$t($$self, $$props, $$invalidate) {
3641
3644
  if ($$self.$$.dirty & /*placement*/ 2097152) {
3642
3645
  {
3643
3646
  {
3644
- $$invalidate(11, backgroundOverray = false);
3647
+ $$invalidate(10, backgroundOverray = false);
3645
3648
  }
3646
3649
  }
3647
3650
  }
@@ -3695,12 +3698,12 @@ function instance$t($$self, $$props, $$invalidate) {
3695
3698
  $$invalidate(14, marginStyle = getMarginStyle(overwriteMargin));
3696
3699
  }
3697
3700
 
3698
- if ($$self.$$.dirty & /*close, modal*/ 16778240) {
3699
- $$invalidate(13, handle_keydown = handleKeydown({ Escape: close, Tab: handleFocus(modal) }));
3701
+ if ($$self.$$.dirty & /*close*/ 16777216) {
3702
+ $$invalidate(13, handle_keydown = handleKeydown({ Escape: close }));
3700
3703
  }
3701
3704
  };
3702
3705
 
3703
- $$invalidate(10, modal = null);
3706
+ $$invalidate(11, modal = null);
3704
3707
 
3705
3708
  // svelteコンポーネントのアニメーションを発火させるためにマウント時にvisibleをtrueにする。
3706
3709
  $$invalidate(12, visible = false);
@@ -3716,8 +3719,8 @@ function instance$t($$self, $$props, $$invalidate) {
3716
3719
  closeEventValue,
3717
3720
  closeButtonColor,
3718
3721
  _closeStyle,
3719
- modal,
3720
3722
  backgroundOverray,
3723
+ modal,
3721
3724
  visible,
3722
3725
  handle_keydown,
3723
3726
  marginStyle,
@@ -4068,7 +4071,7 @@ function get_each_context$6(ctx, list, i) {
4068
4071
  }
4069
4072
 
4070
4073
  // (13:2) {:else}
4071
- function create_else_block$1(ctx) {
4074
+ function create_else_block$2(ctx) {
4072
4075
  let t_value = /*item*/ ctx[2] + "";
4073
4076
  let t;
4074
4077
 
@@ -4121,7 +4124,7 @@ function create_each_block$6(ctx) {
4121
4124
  if (dirty & /*items*/ 1) show_if = null;
4122
4125
  if (show_if == null) show_if = !!/*item*/ ctx[2].match(regexp);
4123
4126
  if (show_if) return create_if_block$4;
4124
- return create_else_block$1;
4127
+ return create_else_block$2;
4125
4128
  }
4126
4129
 
4127
4130
  let current_block_type = select_block_type(ctx, -1);
@@ -4254,159 +4257,163 @@ class RenderText extends SvelteComponent {
4254
4257
  /* src/components/TextElement.svelte generated by Svelte v3.53.1 */
4255
4258
 
4256
4259
  function add_css$o(target) {
4257
- append_styles(target, "svelte-13cs3g2", ".text-element-wrapper.svelte-13cs3g2.svelte-13cs3g2{position:relative;height:100%}.text-element.svelte-13cs3g2.svelte-13cs3g2{display:flex;position:relative;width:100%;height:100%;box-sizing:border-box;white-space:pre-wrap;overflow:auto}.text-element-inner.svelte-13cs3g2.svelte-13cs3g2{width:100%;height:auto}.text-direction-vertical.svelte-13cs3g2.svelte-13cs3g2{writing-mode:vertical-rl}.text-direction-vertical.svelte-13cs3g2 .text-element-inner.svelte-13cs3g2{width:auto;height:100%}.tooltip.svelte-13cs3g2.svelte-13cs3g2{display:none;position:absolute;bottom:-40px;left:50%;transform:translateX(-50%);color:#fff;background-color:#3d4948;white-space:nowrap;padding:4px 8px 4px 8px;border-radius:4px;font-size:12px;z-index:2147483647}.tooltip.svelte-13cs3g2.svelte-13cs3g2:before{content:'';position:absolute;top:-13px;left:50%;margin-left:-7px;border:7px solid transparent;border-bottom:7px solid #3d4948}.tooltip.show.svelte-13cs3g2.svelte-13cs3g2{display:block}.tooltip-error.svelte-13cs3g2.svelte-13cs3g2{background-color:#c00}.tooltip-error.svelte-13cs3g2.svelte-13cs3g2:before{border-bottom:7px solid #c00}");
4260
+ append_styles(target, "svelte-600oh0", ".text-element-wrapper.svelte-600oh0.svelte-600oh0{position:relative;height:100%}.text-element.svelte-600oh0.svelte-600oh0{display:flex;position:relative;width:100%;height:100%;box-sizing:border-box;white-space:pre-wrap;overflow:auto;margin:0px;padding:0px}.text-link-element.svelte-600oh0.svelte-600oh0{text-decoration:none;color:inherit}.text-element-inner.svelte-600oh0.svelte-600oh0{width:100%;height:auto}.text-direction-vertical.svelte-600oh0.svelte-600oh0{writing-mode:vertical-rl}.text-direction-vertical.svelte-600oh0 .text-element-inner.svelte-600oh0{width:auto;height:100%}.tooltip.svelte-600oh0.svelte-600oh0{display:none;position:absolute;bottom:-40px;left:50%;transform:translateX(-50%);color:#fff;background-color:#3d4948;white-space:nowrap;padding:4px 8px 4px 8px;border-radius:4px;font-size:12px;z-index:2147483647}.tooltip.svelte-600oh0.svelte-600oh0:before{content:'';position:absolute;top:-13px;left:50%;margin-left:-7px;border:7px solid transparent;border-bottom:7px solid #3d4948}.tooltip.show.svelte-600oh0.svelte-600oh0{display:block}.tooltip-error.svelte-600oh0.svelte-600oh0{background-color:#c00}.tooltip-error.svelte-600oh0.svelte-600oh0:before{border-bottom:7px solid #c00}");
4258
4261
  }
4259
4262
 
4260
- // (58:2) {#if enableCopy}
4261
- function create_if_block$3(ctx) {
4262
- let div0;
4263
- let t0;
4264
- let t1;
4263
+ // (78:2) {:else}
4264
+ function create_else_block$1(ctx) {
4265
4265
  let div1;
4266
- let t2;
4266
+ let div0;
4267
+ let rendertext;
4268
+ let div1_class_value;
4269
+ let current;
4270
+ rendertext = new RenderText({ props: { text: /*text*/ ctx[0] } });
4267
4271
 
4268
4272
  return {
4269
4273
  c() {
4270
- div0 = element("div");
4271
- t0 = text("コピーしました");
4272
- t1 = space();
4273
4274
  div1 = element("div");
4274
- t2 = text("コピーできませんでした");
4275
+ div0 = element("div");
4276
+ create_component(rendertext.$$.fragment);
4275
4277
  this.h();
4276
4278
  },
4277
4279
  l(nodes) {
4278
- div0 = claim_element(nodes, "DIV", { class: true });
4280
+ div1 = claim_element(nodes, "DIV", { class: true, style: true });
4281
+ var div1_nodes = children(div1);
4282
+ div0 = claim_element(div1_nodes, "DIV", { class: true });
4279
4283
  var div0_nodes = children(div0);
4280
- t0 = claim_text(div0_nodes, "コピーしました");
4284
+ claim_component(rendertext.$$.fragment, div0_nodes);
4281
4285
  div0_nodes.forEach(detach);
4282
- t1 = claim_space(nodes);
4283
- div1 = claim_element(nodes, "DIV", { class: true });
4284
- var div1_nodes = children(div1);
4285
- t2 = claim_text(div1_nodes, "コピーできませんでした");
4286
4286
  div1_nodes.forEach(detach);
4287
4287
  this.h();
4288
4288
  },
4289
4289
  h() {
4290
- attr(div0, "class", "tooltip svelte-13cs3g2");
4291
- attr(div1, "class", "tooltip tooltip-error svelte-13cs3g2");
4290
+ attr(div0, "class", "text-element-inner svelte-600oh0");
4291
+ attr(div1, "class", div1_class_value = "" + (null_to_empty(`text-element text-direction-${/*textDirection*/ ctx[1]}`) + " svelte-600oh0"));
4292
+ attr(div1, "style", /*style*/ ctx[5]);
4292
4293
  },
4293
4294
  m(target, anchor) {
4294
- insert_hydration(target, div0, anchor);
4295
- append_hydration(div0, t0);
4296
- /*div0_binding*/ ctx[9](div0);
4297
- insert_hydration(target, t1, anchor);
4298
4295
  insert_hydration(target, div1, anchor);
4299
- append_hydration(div1, t2);
4300
- /*div1_binding*/ ctx[10](div1);
4296
+ append_hydration(div1, div0);
4297
+ mount_component(rendertext, div0, null);
4298
+ current = true;
4299
+ },
4300
+ p(ctx, dirty) {
4301
+ const rendertext_changes = {};
4302
+ if (dirty & /*text*/ 1) rendertext_changes.text = /*text*/ ctx[0];
4303
+ rendertext.$set(rendertext_changes);
4304
+
4305
+ if (!current || dirty & /*textDirection*/ 2 && div1_class_value !== (div1_class_value = "" + (null_to_empty(`text-element text-direction-${/*textDirection*/ ctx[1]}`) + " svelte-600oh0"))) {
4306
+ attr(div1, "class", div1_class_value);
4307
+ }
4308
+
4309
+ if (!current || dirty & /*style*/ 32) {
4310
+ attr(div1, "style", /*style*/ ctx[5]);
4311
+ }
4312
+ },
4313
+ i(local) {
4314
+ if (current) return;
4315
+ transition_in(rendertext.$$.fragment, local);
4316
+ current = true;
4317
+ },
4318
+ o(local) {
4319
+ transition_out(rendertext.$$.fragment, local);
4320
+ current = false;
4301
4321
  },
4302
- p: noop,
4303
4322
  d(detaching) {
4304
- if (detaching) detach(div0);
4305
- /*div0_binding*/ ctx[9](null);
4306
- if (detaching) detach(t1);
4307
4323
  if (detaching) detach(div1);
4308
- /*div1_binding*/ ctx[10](null);
4324
+ destroy_component(rendertext);
4309
4325
  }
4310
4326
  };
4311
4327
  }
4312
4328
 
4313
- function create_fragment$p(ctx) {
4314
- let div2;
4315
- let link;
4316
- let link_href_value;
4317
- let t0;
4318
- let div1;
4329
+ // (69:2) {#if enableCopy}
4330
+ function create_if_block$3(ctx) {
4331
+ let a;
4319
4332
  let div0;
4320
4333
  let rendertext;
4321
- let div1_class_value;
4334
+ let a_class_value;
4335
+ let t0;
4336
+ let div1;
4322
4337
  let t1;
4338
+ let t2;
4339
+ let div2;
4340
+ let t3;
4323
4341
  let current;
4324
4342
  let mounted;
4325
4343
  let dispose;
4326
4344
  rendertext = new RenderText({ props: { text: /*text*/ ctx[0] } });
4327
- let if_block = /*enableCopy*/ ctx[1] && create_if_block$3(ctx);
4328
4345
 
4329
4346
  return {
4330
4347
  c() {
4331
- div2 = element("div");
4332
- link = element("link");
4333
- t0 = space();
4334
- div1 = element("div");
4348
+ a = element("a");
4335
4349
  div0 = element("div");
4336
4350
  create_component(rendertext.$$.fragment);
4337
- t1 = space();
4338
- if (if_block) if_block.c();
4351
+ t0 = space();
4352
+ div1 = element("div");
4353
+ t1 = text("コピーしました");
4354
+ t2 = space();
4355
+ div2 = element("div");
4356
+ t3 = text("コピーできませんでした");
4339
4357
  this.h();
4340
4358
  },
4341
4359
  l(nodes) {
4342
- div2 = claim_element(nodes, "DIV", { class: true });
4343
- var div2_nodes = children(div2);
4344
- link = claim_element(div2_nodes, "LINK", { href: true, rel: true });
4345
- t0 = claim_space(div2_nodes);
4346
- div1 = claim_element(div2_nodes, "DIV", { class: true, style: true });
4347
- var div1_nodes = children(div1);
4348
- div0 = claim_element(div1_nodes, "DIV", { class: true });
4360
+ a = claim_element(nodes, "A", { href: true, class: true, style: true });
4361
+ var a_nodes = children(a);
4362
+ div0 = claim_element(a_nodes, "DIV", { class: true });
4349
4363
  var div0_nodes = children(div0);
4350
4364
  claim_component(rendertext.$$.fragment, div0_nodes);
4351
4365
  div0_nodes.forEach(detach);
4366
+ a_nodes.forEach(detach);
4367
+ t0 = claim_space(nodes);
4368
+ div1 = claim_element(nodes, "DIV", { class: true });
4369
+ var div1_nodes = children(div1);
4370
+ t1 = claim_text(div1_nodes, "コピーしました");
4352
4371
  div1_nodes.forEach(detach);
4353
- t1 = claim_space(div2_nodes);
4354
- if (if_block) if_block.l(div2_nodes);
4372
+ t2 = claim_space(nodes);
4373
+ div2 = claim_element(nodes, "DIV", { class: true });
4374
+ var div2_nodes = children(div2);
4375
+ t3 = claim_text(div2_nodes, "コピーできませんでした");
4355
4376
  div2_nodes.forEach(detach);
4356
4377
  this.h();
4357
4378
  },
4358
4379
  h() {
4359
- attr(link, "href", link_href_value = `https://fonts.googleapis.com/css2?${getGoogleFontsParam()}&display=swap&text=${/*text*/ ctx[0]}`);
4360
- attr(link, "rel", "stylesheet");
4361
- attr(div0, "class", "text-element-inner svelte-13cs3g2");
4362
- attr(div1, "class", div1_class_value = "" + (null_to_empty(`text-element text-direction-${/*textDirection*/ ctx[2]}`) + " svelte-13cs3g2"));
4363
- attr(div1, "style", /*style*/ ctx[5]);
4364
- attr(div2, "class", "text-element-wrapper svelte-13cs3g2");
4380
+ attr(div0, "class", "text-element-inner svelte-600oh0");
4381
+ attr(a, "href", '');
4382
+ attr(a, "class", a_class_value = "" + (null_to_empty(`text-element text-link-element text-direction-${/*textDirection*/ ctx[1]}`) + " svelte-600oh0"));
4383
+ attr(a, "style", /*style*/ ctx[5]);
4384
+ attr(div1, "class", "tooltip svelte-600oh0");
4385
+ attr(div2, "class", "tooltip tooltip-error svelte-600oh0");
4365
4386
  },
4366
4387
  m(target, anchor) {
4367
- insert_hydration(target, div2, anchor);
4368
- append_hydration(div2, link);
4369
- append_hydration(div2, t0);
4370
- append_hydration(div2, div1);
4371
- append_hydration(div1, div0);
4388
+ insert_hydration(target, a, anchor);
4389
+ append_hydration(a, div0);
4372
4390
  mount_component(rendertext, div0, null);
4373
- append_hydration(div2, t1);
4374
- if (if_block) if_block.m(div2, null);
4391
+ insert_hydration(target, t0, anchor);
4392
+ insert_hydration(target, div1, anchor);
4393
+ append_hydration(div1, t1);
4394
+ /*div1_binding*/ ctx[10](div1);
4395
+ insert_hydration(target, t2, anchor);
4396
+ insert_hydration(target, div2, anchor);
4397
+ append_hydration(div2, t3);
4398
+ /*div2_binding*/ ctx[11](div2);
4375
4399
  current = true;
4376
4400
 
4377
4401
  if (!mounted) {
4378
- dispose = listen(div1, "click", /*click*/ ctx[6]);
4402
+ dispose = listen(a, "click", /*onCopy*/ ctx[6]);
4379
4403
  mounted = true;
4380
4404
  }
4381
4405
  },
4382
- p(ctx, [dirty]) {
4383
- if (!current || dirty & /*text*/ 1 && link_href_value !== (link_href_value = `https://fonts.googleapis.com/css2?${getGoogleFontsParam()}&display=swap&text=${/*text*/ ctx[0]}`)) {
4384
- attr(link, "href", link_href_value);
4385
- }
4386
-
4406
+ p(ctx, dirty) {
4387
4407
  const rendertext_changes = {};
4388
4408
  if (dirty & /*text*/ 1) rendertext_changes.text = /*text*/ ctx[0];
4389
4409
  rendertext.$set(rendertext_changes);
4390
4410
 
4391
- if (!current || dirty & /*textDirection*/ 4 && div1_class_value !== (div1_class_value = "" + (null_to_empty(`text-element text-direction-${/*textDirection*/ ctx[2]}`) + " svelte-13cs3g2"))) {
4392
- attr(div1, "class", div1_class_value);
4411
+ if (!current || dirty & /*textDirection*/ 2 && a_class_value !== (a_class_value = "" + (null_to_empty(`text-element text-link-element text-direction-${/*textDirection*/ ctx[1]}`) + " svelte-600oh0"))) {
4412
+ attr(a, "class", a_class_value);
4393
4413
  }
4394
4414
 
4395
4415
  if (!current || dirty & /*style*/ 32) {
4396
- attr(div1, "style", /*style*/ ctx[5]);
4397
- }
4398
-
4399
- if (/*enableCopy*/ ctx[1]) {
4400
- if (if_block) {
4401
- if_block.p(ctx, dirty);
4402
- } else {
4403
- if_block = create_if_block$3(ctx);
4404
- if_block.c();
4405
- if_block.m(div2, null);
4406
- }
4407
- } else if (if_block) {
4408
- if_block.d(1);
4409
- if_block = null;
4416
+ attr(a, "style", /*style*/ ctx[5]);
4410
4417
  }
4411
4418
  },
4412
4419
  i(local) {
@@ -4419,53 +4426,159 @@ function create_fragment$p(ctx) {
4419
4426
  current = false;
4420
4427
  },
4421
4428
  d(detaching) {
4422
- if (detaching) detach(div2);
4429
+ if (detaching) detach(a);
4423
4430
  destroy_component(rendertext);
4424
- if (if_block) if_block.d();
4431
+ if (detaching) detach(t0);
4432
+ if (detaching) detach(div1);
4433
+ /*div1_binding*/ ctx[10](null);
4434
+ if (detaching) detach(t2);
4435
+ if (detaching) detach(div2);
4436
+ /*div2_binding*/ ctx[11](null);
4425
4437
  mounted = false;
4426
4438
  dispose();
4427
4439
  }
4428
4440
  };
4429
4441
  }
4430
4442
 
4443
+ function create_fragment$p(ctx) {
4444
+ let div;
4445
+ let link;
4446
+ let link_href_value;
4447
+ let t;
4448
+ let current_block_type_index;
4449
+ let if_block;
4450
+ let current;
4451
+ const if_block_creators = [create_if_block$3, create_else_block$1];
4452
+ const if_blocks = [];
4453
+
4454
+ function select_block_type(ctx, dirty) {
4455
+ if (/*enableCopy*/ ctx[2]) return 0;
4456
+ return 1;
4457
+ }
4458
+
4459
+ current_block_type_index = select_block_type(ctx);
4460
+ if_block = if_blocks[current_block_type_index] = if_block_creators[current_block_type_index](ctx);
4461
+
4462
+ return {
4463
+ c() {
4464
+ div = element("div");
4465
+ link = element("link");
4466
+ t = space();
4467
+ if_block.c();
4468
+ this.h();
4469
+ },
4470
+ l(nodes) {
4471
+ div = claim_element(nodes, "DIV", { class: true });
4472
+ var div_nodes = children(div);
4473
+ link = claim_element(div_nodes, "LINK", { href: true, rel: true });
4474
+ t = claim_space(div_nodes);
4475
+ if_block.l(div_nodes);
4476
+ div_nodes.forEach(detach);
4477
+ this.h();
4478
+ },
4479
+ h() {
4480
+ attr(link, "href", link_href_value = `https://fonts.googleapis.com/css2?${getGoogleFontsParam()}&display=swap&text=${/*text*/ ctx[0]}`);
4481
+ attr(link, "rel", "stylesheet");
4482
+ attr(div, "class", "text-element-wrapper svelte-600oh0");
4483
+ },
4484
+ m(target, anchor) {
4485
+ insert_hydration(target, div, anchor);
4486
+ append_hydration(div, link);
4487
+ append_hydration(div, t);
4488
+ if_blocks[current_block_type_index].m(div, null);
4489
+ current = true;
4490
+ },
4491
+ p(ctx, [dirty]) {
4492
+ if (!current || dirty & /*text*/ 1 && link_href_value !== (link_href_value = `https://fonts.googleapis.com/css2?${getGoogleFontsParam()}&display=swap&text=${/*text*/ ctx[0]}`)) {
4493
+ attr(link, "href", link_href_value);
4494
+ }
4495
+
4496
+ let previous_block_index = current_block_type_index;
4497
+ current_block_type_index = select_block_type(ctx);
4498
+
4499
+ if (current_block_type_index === previous_block_index) {
4500
+ if_blocks[current_block_type_index].p(ctx, dirty);
4501
+ } else {
4502
+ group_outros();
4503
+
4504
+ transition_out(if_blocks[previous_block_index], 1, 1, () => {
4505
+ if_blocks[previous_block_index] = null;
4506
+ });
4507
+
4508
+ check_outros();
4509
+ if_block = if_blocks[current_block_type_index];
4510
+
4511
+ if (!if_block) {
4512
+ if_block = if_blocks[current_block_type_index] = if_block_creators[current_block_type_index](ctx);
4513
+ if_block.c();
4514
+ } else {
4515
+ if_block.p(ctx, dirty);
4516
+ }
4517
+
4518
+ transition_in(if_block, 1);
4519
+ if_block.m(div, null);
4520
+ }
4521
+ },
4522
+ i(local) {
4523
+ if (current) return;
4524
+ transition_in(if_block);
4525
+ current = true;
4526
+ },
4527
+ o(local) {
4528
+ transition_out(if_block);
4529
+ current = false;
4530
+ },
4531
+ d(detaching) {
4532
+ if (detaching) detach(div);
4533
+ if_blocks[current_block_type_index].d();
4534
+ }
4535
+ };
4536
+ }
4537
+
4431
4538
  function instance$p($$self, $$props, $$invalidate) {
4432
4539
  let style;
4433
4540
  let { text = 'サンプルSample' } = $$props;
4541
+ let { _textStyle = 'font-size:12px; line-height: 1.5;' } = $$props;
4542
+ let { textDirection = 'horizontal' } = $$props;
4543
+ let { _style = '' } = $$props;
4434
4544
  let { enableCopy = false } = $$props;
4545
+ let { eventName = '' } = $$props;
4546
+ let eventValue = undefined;
4435
4547
  let tooltipEl;
4436
4548
  let tooltipErrorEl;
4437
4549
 
4438
- const click = async () => {
4439
- if (enableCopy) {
4440
- try {
4441
- await navigator.clipboard.writeText(text);
4442
- tooltipEl.classList.add('show');
4443
- } catch(err) {
4444
- tooltipErrorEl.classList.add('show');
4445
- }
4446
-
4447
- setTimeout(
4448
- () => {
4449
- tooltipEl.classList.remove('show');
4450
- tooltipErrorEl.classList.remove('show');
4451
- },
4452
- 1000
4453
- );
4550
+ const onCopy = async e => {
4551
+ e.preventDefault();
4552
+
4553
+ try {
4554
+ await navigator.clipboard.writeText(text);
4555
+
4556
+ if (eventName) {
4557
+ send_event(eventName, eventValue);
4558
+ }
4559
+
4560
+ tooltipEl.classList.add('show');
4561
+ } catch(err) {
4562
+ tooltipErrorEl.classList.add('show');
4454
4563
  }
4455
- };
4456
4564
 
4457
- let { _textStyle = 'font-size:12px; line-height: 1.5;' } = $$props;
4458
- let { textDirection = 'horizontal' } = $$props;
4459
- let { _style = '' } = $$props;
4565
+ setTimeout(
4566
+ () => {
4567
+ tooltipEl.classList.remove('show');
4568
+ tooltipErrorEl.classList.remove('show');
4569
+ },
4570
+ 1000
4571
+ );
4572
+ };
4460
4573
 
4461
- function div0_binding($$value) {
4574
+ function div1_binding($$value) {
4462
4575
  binding_callbacks[$$value ? 'unshift' : 'push'](() => {
4463
4576
  tooltipEl = $$value;
4464
4577
  $$invalidate(3, tooltipEl);
4465
4578
  });
4466
4579
  }
4467
4580
 
4468
- function div1_binding($$value) {
4581
+ function div2_binding($$value) {
4469
4582
  binding_callbacks[$$value ? 'unshift' : 'push'](() => {
4470
4583
  tooltipErrorEl = $$value;
4471
4584
  $$invalidate(4, tooltipErrorEl);
@@ -4474,10 +4587,11 @@ function instance$p($$self, $$props, $$invalidate) {
4474
4587
 
4475
4588
  $$self.$$set = $$props => {
4476
4589
  if ('text' in $$props) $$invalidate(0, text = $$props.text);
4477
- if ('enableCopy' in $$props) $$invalidate(1, enableCopy = $$props.enableCopy);
4478
4590
  if ('_textStyle' in $$props) $$invalidate(7, _textStyle = $$props._textStyle);
4479
- if ('textDirection' in $$props) $$invalidate(2, textDirection = $$props.textDirection);
4591
+ if ('textDirection' in $$props) $$invalidate(1, textDirection = $$props.textDirection);
4480
4592
  if ('_style' in $$props) $$invalidate(8, _style = $$props._style);
4593
+ if ('enableCopy' in $$props) $$invalidate(2, enableCopy = $$props.enableCopy);
4594
+ if ('eventName' in $$props) $$invalidate(9, eventName = $$props.eventName);
4481
4595
  };
4482
4596
 
4483
4597
  $$self.$$.update = () => {
@@ -4488,16 +4602,17 @@ function instance$p($$self, $$props, $$invalidate) {
4488
4602
 
4489
4603
  return [
4490
4604
  text,
4491
- enableCopy,
4492
4605
  textDirection,
4606
+ enableCopy,
4493
4607
  tooltipEl,
4494
4608
  tooltipErrorEl,
4495
4609
  style,
4496
- click,
4610
+ onCopy,
4497
4611
  _textStyle,
4498
4612
  _style,
4499
- div0_binding,
4500
- div1_binding
4613
+ eventName,
4614
+ div1_binding,
4615
+ div2_binding
4501
4616
  ];
4502
4617
  }
4503
4618
 
@@ -4513,10 +4628,11 @@ class TextElement extends SvelteComponent {
4513
4628
  safe_not_equal,
4514
4629
  {
4515
4630
  text: 0,
4516
- enableCopy: 1,
4517
4631
  _textStyle: 7,
4518
- textDirection: 2,
4519
- _style: 8
4632
+ textDirection: 1,
4633
+ _style: 8,
4634
+ enableCopy: 2,
4635
+ eventName: 9
4520
4636
  },
4521
4637
  add_css$o
4522
4638
  );